Kaydet (Commit) fb1e645e authored tarafından Julien Nabet's avatar Julien Nabet Kaydeden (comit) Michael Stahl

getFiles refactoring: kde part

1) kdecommandthread part
before:
getFiles retrieves all files with:
First element = path only of the files
other elements = file names (without path)

after:
Add getSelectedFiles which retrieves all files with their url
getFiles uses getSelectedFiles and truncates to 1 entry if more than 1 entry

2) kdefilepicker part
before:
getFiles case retrieves all files with names including path

after:
add getSelectedFiles case which retrieves all files with names including path
change getFiles to retrieve only the first file (with path)

See http://nabble.documentfoundation.org/Dev-f1639786.html for discussion

Change-Id: I73cf00e7c03a1f2379f4628b5d7f12418029cca1
Reviewed-on: https://gerrit.libreoffice.org/17064Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst 013f84d0
......@@ -100,34 +100,29 @@ OUString SAL_CALL UnxFilePickerCommandThread::getDirectory()
return m_aGetDirectory;
}
uno::Sequence< OUString > SAL_CALL UnxFilePickerCommandThread::getFiles()
uno::Sequence< OUString > SAL_CALL UnxFilePickerCommandThread::getSelectedFiles()
{
::osl::MutexGuard aGuard( m_aMutex );
sal_Int32 nSize = m_aGetFiles.size();
uno::Sequence< OUString > aFiles( ( nSize > 1 )? nSize + 1: nSize );
uno::Sequence< OUString > aFiles( nSize );
if ( nSize == 1 )
aFiles[0] = m_aGetFiles.front();
else if ( nSize > 1 )
size_t nIdx = 0;
for ( ::std::list< OUString >::const_iterator it = m_aGetFiles.begin();
it != m_aGetFiles.end(); ++it, ++nIdx )
{
// First entry in the sequence must be the dirname, the others are the
// filenames, so we have to rearrange the list...
OUString aFront = m_aGetFiles.front();
sal_Int32 nLastSlash = aFront.lastIndexOf( '/' );
aFiles[nIdx] = *it;
}
aFiles[0] = ( nLastSlash >= 0 )? aFront.copy( 0, nLastSlash ): OUString();
++nLastSlash;
return aFiles;
}
uno::Sequence< OUString > SAL_CALL UnxFilePickerCommandThread::getFiles()
{
::osl::MutexGuard aGuard( m_aMutex );
sal_Int32 nIdx = 1;
for ( ::std::list< OUString >::const_iterator it = m_aGetFiles.begin();
it != m_aGetFiles.end(); ++it, ++nIdx )
{
sal_Int32 nLength = (*it).getLength() - nLastSlash;
aFiles[nIdx] = ( nLength >= 0 )? (*it).copy( nLastSlash, nLength ): OUString();
}
}
uno::Sequence< OUString > aFiles = getSelectedFiles();
if (aFiles.getLength() > 1)
aFiles.realloc(1); // we just want the first entry here
return aFiles;
}
......
......@@ -109,6 +109,7 @@ public:
OUString SAL_CALL getDirectory();
::osl::Condition& SAL_CALL getFilesCondition() { return m_aGetFilesCondition; }
::com::sun::star::uno::Sequence< OUString > SAL_CALL getSelectedFiles();
::com::sun::star::uno::Sequence< OUString > SAL_CALL getFiles();
::osl::Condition& SAL_CALL getValueCondition() { return m_aGetValueCondition; }
......
......@@ -57,6 +57,7 @@ KDECommandEvent::KDECommandEvent( const QString &qCommand, QStringList *pStringL
{ "getDirectory", GetDirectory },
{ "setDirectory", SetDirectory },
{ "getFiles", GetFiles },
{ "getSelectedFiles", GetSelectedFiles },
{ "setTitle", SetTitle },
{ "setType", SetType },
{ "setDefaultName", SetDefaultName },
......
......@@ -60,6 +60,7 @@ public:
SetDirectory,
GetFiles,
GetSelectedFiles,
SetTitle,
SetType,
......
......@@ -320,6 +320,37 @@ void KDEFileDialog::customEvent( QCustomEvent *pEvent )
}
break;
case KDECommandEvent::GetFiles:
{
QString qString;
qString.reserve( 1024 );
qString.append( "files" );
if ( result() == QDialog::Accepted )
{
KURL::List qList( selectedURLs() );
for ( KURL::List::const_iterator it = qList.begin(); it != qList.end(); ++it )
{
appendURL( qString, (*it) );
break; // we just want the first element
}
}
else
{
// we have to return the selected files anyway
const KFileItemList *pItems = ops->selectedItems();
for ( KFileItemListIterator it( *pItems ); it.current(); ++it )
{
appendURL( qString, (*it)->url() );
break; // we just want the first element
}
}
sendCommand( qString );
setCanNotifySelection( true );
}
break;
case KDECommandEvent::GetSelectedFiles:
{
QString qString;
qString.reserve( 1024 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment