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() ...@@ -100,34 +100,29 @@ OUString SAL_CALL UnxFilePickerCommandThread::getDirectory()
return m_aGetDirectory; return m_aGetDirectory;
} }
uno::Sequence< OUString > SAL_CALL UnxFilePickerCommandThread::getFiles() uno::Sequence< OUString > SAL_CALL UnxFilePickerCommandThread::getSelectedFiles()
{ {
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
sal_Int32 nSize = m_aGetFiles.size(); sal_Int32 nSize = m_aGetFiles.size();
uno::Sequence< OUString > aFiles( ( nSize > 1 )? nSize + 1: nSize ); uno::Sequence< OUString > aFiles( nSize );
if ( nSize == 1 ) size_t nIdx = 0;
aFiles[0] = m_aGetFiles.front(); for ( ::std::list< OUString >::const_iterator it = m_aGetFiles.begin();
else if ( nSize > 1 ) it != m_aGetFiles.end(); ++it, ++nIdx )
{ {
// First entry in the sequence must be the dirname, the others are the aFiles[nIdx] = *it;
// filenames, so we have to rearrange the list... }
OUString aFront = m_aGetFiles.front();
sal_Int32 nLastSlash = aFront.lastIndexOf( '/' );
aFiles[0] = ( nLastSlash >= 0 )? aFront.copy( 0, nLastSlash ): OUString(); return aFiles;
++nLastSlash; }
uno::Sequence< OUString > SAL_CALL UnxFilePickerCommandThread::getFiles()
{
::osl::MutexGuard aGuard( m_aMutex );
sal_Int32 nIdx = 1; uno::Sequence< OUString > aFiles = getSelectedFiles();
for ( ::std::list< OUString >::const_iterator it = m_aGetFiles.begin(); if (aFiles.getLength() > 1)
it != m_aGetFiles.end(); ++it, ++nIdx ) aFiles.realloc(1); // we just want the first entry here
{
sal_Int32 nLength = (*it).getLength() - nLastSlash;
aFiles[nIdx] = ( nLength >= 0 )? (*it).copy( nLastSlash, nLength ): OUString();
}
}
return aFiles; return aFiles;
} }
......
...@@ -109,6 +109,7 @@ public: ...@@ -109,6 +109,7 @@ public:
OUString SAL_CALL getDirectory(); OUString SAL_CALL getDirectory();
::osl::Condition& SAL_CALL getFilesCondition() { return m_aGetFilesCondition; } ::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(); ::com::sun::star::uno::Sequence< OUString > SAL_CALL getFiles();
::osl::Condition& SAL_CALL getValueCondition() { return m_aGetValueCondition; } ::osl::Condition& SAL_CALL getValueCondition() { return m_aGetValueCondition; }
......
...@@ -57,6 +57,7 @@ KDECommandEvent::KDECommandEvent( const QString &qCommand, QStringList *pStringL ...@@ -57,6 +57,7 @@ KDECommandEvent::KDECommandEvent( const QString &qCommand, QStringList *pStringL
{ "getDirectory", GetDirectory }, { "getDirectory", GetDirectory },
{ "setDirectory", SetDirectory }, { "setDirectory", SetDirectory },
{ "getFiles", GetFiles }, { "getFiles", GetFiles },
{ "getSelectedFiles", GetSelectedFiles },
{ "setTitle", SetTitle }, { "setTitle", SetTitle },
{ "setType", SetType }, { "setType", SetType },
{ "setDefaultName", SetDefaultName }, { "setDefaultName", SetDefaultName },
......
...@@ -60,6 +60,7 @@ public: ...@@ -60,6 +60,7 @@ public:
SetDirectory, SetDirectory,
GetFiles, GetFiles,
GetSelectedFiles,
SetTitle, SetTitle,
SetType, SetType,
......
...@@ -320,6 +320,37 @@ void KDEFileDialog::customEvent( QCustomEvent *pEvent ) ...@@ -320,6 +320,37 @@ void KDEFileDialog::customEvent( QCustomEvent *pEvent )
} }
break; break;
case KDECommandEvent::GetFiles: 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 qString;
qString.reserve( 1024 ); 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