Files
libreoffice/cui/source/dialogs/multipat.cxx

339 lines
11 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: clarify Option->Language UI option Patch contributed by Herbert Duerr http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117709#: add missing string resource Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172348 cws mba34issues01: #i117716#: fix missing resources my removing unused code Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172345 re-add Crystal, Tango, Oxygen icon theme listings. correct method signature Patch contributed by Jean-Louis 'Hans' Fuchs http://svn.apache.org/viewvc?view=revision&revision=1306725 i#119063 - correct serf integration Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1300521 i#119036 - adapt serf integration -- use transfer-encoding 'chunked' on HTTPS -- switch transfer-encoding between 'chunked' and none on 413 HTTP status code -- refactoring -- improve user experience of certification dialog - only shown once Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1299727 118569: Use whole certification chain for verification. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1295493 serf integration: improve credential input handling Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1294557 warning-free ucb/source/ucp/webdav Patch contributed by Pavel Janik http://svn.apache.org/viewvc?view=revision&revision=1294086 some refactoring to PROPPATCH and PROPFIND requests Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1293281 i#118569: Replace neon with serf Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1292832 http://svn.apache.org/viewvc?view=revision&revision=1292794 remove OS/2 conditionals for now. re-enable webdav unit tests.
2012-10-04 11:25:41 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2009-10-31 00:36:06 +01:00
#include <tools/urlobj.hxx>
#include <vcl/msgbox.hxx>
#include <sfx2/filedlghelper.hxx>
#include "multipat.hxx"
#include <dialmgr.hxx>
2009-10-31 00:36:06 +01:00
#include <cuires.hrc>
2009-10-31 00:36:06 +01:00
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
2009-10-31 00:36:06 +01:00
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/ui/dialogs/FolderPicker.hpp>
2009-10-31 00:36:06 +01:00
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#include <unotools/localfilehelper.hxx>
#include <unotools/pathoptions.hxx>
#include "svtools/treelistentry.hxx"
2009-10-31 00:36:06 +01:00
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::uno;
IMPL_LINK_NOARG(SvxMultiPathDialog, SelectHdl_Impl)
2009-10-31 00:36:06 +01:00
{
sal_uLong nCount = m_pRadioLB->GetEntryCount();
bool bIsSelected = m_pRadioLB->FirstSelected() != NULL;
bool bEnable = nCount > 1;
m_pDelBtn->Enable(bEnable && bIsSelected);
2009-10-31 00:36:06 +01:00
return 0;
}
IMPL_LINK_NOARG(SvxPathSelectDialog, SelectHdl_Impl)
{
sal_uLong nCount = m_pPathLB->GetEntryCount();
bool bIsSelected = m_pPathLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND;
bool bEnable = nCount > 1;
m_pDelBtn->Enable(bEnable && bIsSelected);
return 0;
}
2009-10-31 00:36:06 +01:00
IMPL_LINK( SvxMultiPathDialog, CheckHdl_Impl, svx::SvxRadioButtonListBox *, pBox )
{
SvTreeListEntry* pEntry =
pBox ? pBox->GetEntry( pBox->GetCurMousePoint() ) : m_pRadioLB->FirstSelected();
2009-10-31 00:36:06 +01:00
if ( pEntry )
m_pRadioLB->HandleEntryChecked( pEntry );
2009-10-31 00:36:06 +01:00
return 0;
}
IMPL_LINK_NOARG(SvxMultiPathDialog, AddHdl_Impl)
2009-10-31 00:36:06 +01:00
{
Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
Reference < XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);
2009-10-31 00:36:06 +01:00
if ( xFolderPicker->execute() == ExecutableDialogResults::OK )
{
INetURLObject aPath( xFolderPicker->getDirectory() );
aPath.removeFinalSlash();
OUString aURL = aPath.GetMainURL( INetURLObject::NO_DECODE );
OUString sInsPath;
2009-10-31 00:36:06 +01:00
::utl::LocalFileHelper::ConvertURLToSystemPath( aURL, sInsPath );
sal_uLong nPos = m_pRadioLB->GetEntryPos( sInsPath, 1 );
if ( 0xffffffff == nPos ) //See svtools/source/contnr/svtabbx.cxx SvTabListBox::GetEntryPos
2009-10-31 00:36:06 +01:00
{
OUString sNewEntry( '\t' );
sNewEntry += sInsPath;
SvTreeListEntry* pEntry = m_pRadioLB->InsertEntry( sNewEntry );
OUString* pData = new OUString( aURL );
pEntry->SetUserData( pData );
2009-10-31 00:36:06 +01:00
}
else
{
OUString sMsg( CUI_RES( RID_MULTIPATH_DBL_ERR ) );
sMsg = sMsg.replaceFirst( "%1", sInsPath );
InfoBox( this, sMsg ).Execute();
2009-10-31 00:36:06 +01:00
}
2009-10-31 00:36:06 +01:00
SelectHdl_Impl( NULL );
}
return 0;
}
IMPL_LINK_NOARG(SvxPathSelectDialog, AddHdl_Impl)
2009-10-31 00:36:06 +01:00
{
Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
Reference < XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);
if ( xFolderPicker->execute() == ExecutableDialogResults::OK )
2009-10-31 00:36:06 +01:00
{
INetURLObject aPath( xFolderPicker->getDirectory() );
aPath.removeFinalSlash();
OUString aURL = aPath.GetMainURL( INetURLObject::NO_DECODE );
OUString sInsPath;
::utl::LocalFileHelper::ConvertURLToSystemPath( aURL, sInsPath );
if ( LISTBOX_ENTRY_NOTFOUND != m_pPathLB->GetEntryPos( sInsPath ) )
2009-10-31 00:36:06 +01:00
{
OUString sMsg( CUI_RES( RID_MULTIPATH_DBL_ERR ) );
sMsg = sMsg.replaceFirst( "%1", sInsPath );
InfoBox( this, sMsg ).Execute();
2009-10-31 00:36:06 +01:00
}
else
{
sal_uInt16 nPos = m_pPathLB->InsertEntry( sInsPath, LISTBOX_APPEND );
m_pPathLB->SetEntryData( nPos, new OUString( aURL ) );
}
SelectHdl_Impl( NULL );
2009-10-31 00:36:06 +01:00
}
return 0;
}
2009-10-31 00:36:06 +01:00
IMPL_LINK_NOARG(SvxMultiPathDialog, DelHdl_Impl)
{
SvTreeListEntry* pEntry = m_pRadioLB->FirstSelected();
delete static_cast<OUString*>(pEntry->GetUserData());
bool bChecked = m_pRadioLB->GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED;
sal_uLong nPos = m_pRadioLB->GetEntryPos( pEntry );
m_pRadioLB->RemoveEntry( pEntry );
sal_uLong nCnt = m_pRadioLB->GetEntryCount();
if ( nCnt )
{
nCnt--;
if ( nPos > nCnt )
nPos = nCnt;
pEntry = m_pRadioLB->GetEntry( nPos );
if ( bChecked )
2009-10-31 00:36:06 +01:00
{
m_pRadioLB->SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
m_pRadioLB->HandleEntryChecked( pEntry );
2009-10-31 00:36:06 +01:00
}
else
m_pRadioLB->Select( pEntry );
2009-10-31 00:36:06 +01:00
}
2009-10-31 00:36:06 +01:00
SelectHdl_Impl( NULL );
return 0;
}
IMPL_LINK_NOARG(SvxPathSelectDialog, DelHdl_Impl)
{
sal_uInt16 nPos = m_pPathLB->GetSelectEntryPos();
m_pPathLB->RemoveEntry( nPos );
sal_uInt16 nCnt = m_pPathLB->GetEntryCount();
if ( nCnt )
{
nCnt--;
2009-10-31 00:36:06 +01:00
if ( nPos > nCnt )
nPos = nCnt;
m_pPathLB->SelectEntryPos( nPos );
}
SelectHdl_Impl( NULL );
return 0;
}
2009-10-31 00:36:06 +01:00
SvxMultiPathDialog::SvxMultiPathDialog(vcl::Window* pParent)
: ModalDialog(pParent, "MultiPathDialog", "cui/ui/multipathdialog.ui")
2009-10-31 00:36:06 +01:00
{
get(m_pAddBtn, "add");
get(m_pDelBtn, "delete");
SvSimpleTableContainer* pRadioLBContainer = get<SvSimpleTableContainer>("paths");
Size aSize(LogicToPixel(Size(195, 77), MAP_APPFONT));
pRadioLBContainer->set_width_request(aSize.Width());
pRadioLBContainer->set_height_request(aSize.Height());
m_pRadioLB = new svx::SvxRadioButtonListBox(*pRadioLBContainer, 0);
2009-10-31 00:36:06 +01:00
static long aStaticTabs[]= { 2, 0, 12 };
m_pRadioLB->SvSimpleTable::SetTabs( aStaticTabs );
OUString sHeader(get<FixedText>("pathlist")->GetText());
m_pRadioLB->SetQuickHelpText( sHeader );
sHeader = "\t" + sHeader;
m_pRadioLB->InsertHeaderEntry( sHeader, HEADERBAR_APPEND, HIB_LEFT );
2009-10-31 00:36:06 +01:00
m_pRadioLB->SetSelectHdl( LINK( this, SvxMultiPathDialog, SelectHdl_Impl ) );
m_pRadioLB->SetCheckButtonHdl( LINK( this, SvxMultiPathDialog, CheckHdl_Impl ) );
m_pAddBtn->SetClickHdl( LINK( this, SvxMultiPathDialog, AddHdl_Impl ) );
m_pDelBtn->SetClickHdl( LINK( this, SvxMultiPathDialog, DelHdl_Impl ) );
2009-10-31 00:36:06 +01:00
SelectHdl_Impl( NULL );
m_pRadioLB->ShowTable();
}
SvxPathSelectDialog::SvxPathSelectDialog(vcl::Window* pParent)
: ModalDialog(pParent, "SelectPathDialog", "cui/ui/selectpathdialog.ui")
{
get(m_pAddBtn, "add");
get(m_pDelBtn, "delete");
get(m_pPathLB, "paths");
Size aSize(LogicToPixel(Size(189, 80), MAP_APPFONT));
m_pPathLB->set_width_request(aSize.Width());
m_pPathLB->set_height_request(aSize.Height());
m_pPathLB->SetSelectHdl( LINK( this, SvxPathSelectDialog, SelectHdl_Impl ) );
m_pAddBtn->SetClickHdl( LINK( this, SvxPathSelectDialog, AddHdl_Impl ) );
m_pDelBtn->SetClickHdl( LINK( this, SvxPathSelectDialog, DelHdl_Impl ) );
SelectHdl_Impl( NULL );
2009-10-31 00:36:06 +01:00
}
SvxMultiPathDialog::~SvxMultiPathDialog()
{
sal_uInt16 nPos = (sal_uInt16)m_pRadioLB->GetEntryCount();
2009-10-31 00:36:06 +01:00
while ( nPos-- )
{
SvTreeListEntry* pEntry = m_pRadioLB->GetEntry( nPos );
delete static_cast<OUString*>(pEntry->GetUserData());
2009-10-31 00:36:06 +01:00
}
delete m_pRadioLB;
}
SvxPathSelectDialog::~SvxPathSelectDialog()
{
sal_uInt16 nPos = m_pPathLB->GetEntryCount();
while ( nPos-- )
delete static_cast<OUString*>(m_pPathLB->GetEntryData(nPos));
2009-10-31 00:36:06 +01:00
}
OUString SvxMultiPathDialog::GetPath() const
2009-10-31 00:36:06 +01:00
{
OUString sNewPath;
sal_Unicode cDelim = SVT_SEARCHPATH_DELIMITER;
2009-10-31 00:36:06 +01:00
OUString sWritable;
for ( sal_uInt16 i = 0; i < m_pRadioLB->GetEntryCount(); ++i )
2009-10-31 00:36:06 +01:00
{
SvTreeListEntry* pEntry = m_pRadioLB->GetEntry(i);
if ( m_pRadioLB->GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED )
sWritable = *static_cast<OUString*>(pEntry->GetUserData());
else
2009-10-31 00:36:06 +01:00
{
if ( !sNewPath.isEmpty() )
sNewPath += OUString(cDelim);
sNewPath += *static_cast<OUString*>(pEntry->GetUserData());
2009-10-31 00:36:06 +01:00
}
}
if ( !sNewPath.isEmpty() )
sNewPath += OUString(cDelim);
sNewPath += sWritable;
2009-10-31 00:36:06 +01:00
return sNewPath;
}
OUString SvxPathSelectDialog::GetPath() const
{
OUString sNewPath;
sal_Unicode cDelim = SVT_SEARCHPATH_DELIMITER;
for ( sal_uInt16 i = 0; i < m_pPathLB->GetEntryCount(); ++i )
{
if ( !sNewPath.isEmpty() )
sNewPath += OUString(cDelim);
sNewPath += *static_cast<OUString*>(m_pPathLB->GetEntryData(i));
}
return sNewPath;
}
2009-10-31 00:36:06 +01:00
void SvxMultiPathDialog::SetPath( const OUString& rPath )
2009-10-31 00:36:06 +01:00
{
sal_Unicode cDelim = SVT_SEARCHPATH_DELIMITER;
sal_uInt16 nCount = comphelper::string::getTokenCount(rPath, cDelim);
2009-10-31 00:36:06 +01:00
for ( sal_uInt16 i = 0; i < nCount; ++i )
2009-10-31 00:36:06 +01:00
{
OUString sPath = rPath.getToken( i, cDelim );
OUString sSystemPath;
bool bIsSystemPath =
2009-10-31 00:36:06 +01:00
::utl::LocalFileHelper::ConvertURLToSystemPath( sPath, sSystemPath );
OUString sEntry( '\t' );
sEntry += (bIsSystemPath ? sSystemPath : OUString(sPath));
SvTreeListEntry* pEntry = m_pRadioLB->InsertEntry( sEntry );
OUString* pURL = new OUString( sPath );
pEntry->SetUserData( pURL );
2009-10-31 00:36:06 +01:00
}
if (nCount > 0)
2009-10-31 00:36:06 +01:00
{
SvTreeListEntry* pEntry = m_pRadioLB->GetEntry( nCount - 1 );
2009-10-31 00:36:06 +01:00
if ( pEntry )
{
m_pRadioLB->SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
m_pRadioLB->HandleEntryChecked( pEntry );
2009-10-31 00:36:06 +01:00
}
}
SelectHdl_Impl( NULL );
}
void SvxPathSelectDialog::SetPath(const OUString& rPath)
2009-10-31 00:36:06 +01:00
{
sal_Unicode cDelim = SVT_SEARCHPATH_DELIMITER;
sal_uInt16 nPos, nCount = comphelper::string::getTokenCount(rPath, cDelim);
2009-10-31 00:36:06 +01:00
for ( sal_uInt16 i = 0; i < nCount; ++i )
{
OUString sPath = rPath.getToken( i, cDelim );
OUString sSystemPath;
bool bIsSystemPath =
::utl::LocalFileHelper::ConvertURLToSystemPath( sPath, sSystemPath );
2009-10-31 00:36:06 +01:00
if ( bIsSystemPath )
nPos = m_pPathLB->InsertEntry( sSystemPath, LISTBOX_APPEND );
else
nPos = m_pPathLB->InsertEntry( sPath, LISTBOX_APPEND );
m_pPathLB->SetEntryData( nPos, new OUString( sPath ) );
}
2009-10-31 00:36:06 +01:00
SelectHdl_Impl( NULL );
2009-10-31 00:36:06 +01:00
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */