diff options
author | Jan Holesovsky <kendy@suse.cz> | 2010-08-25 17:45:26 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2010-08-26 12:54:52 +0200 |
commit | ce6e6931094056dbc30e675b55404b1b77066cc8 (patch) | |
tree | 4e21ff3a91dfa1663a3dfaeaf7e041cf7f95a449 /fpicker | |
parent | 98b7a3b0b8da3e9ff2d79decd3f5bb98b82cbef2 (diff) |
fpicker-kde-dialog.diff: Out-of-process implementation of KDE3 fpicker.
Diffstat (limited to 'fpicker')
-rw-r--r-- | fpicker/source/unx/kde/kdecommandthread.cxx | 174 | ||||
-rw-r--r-- | fpicker/source/unx/kde/kdecommandthread.hxx | 94 | ||||
-rw-r--r-- | fpicker/source/unx/kde/kdefilepicker.cxx | 596 | ||||
-rw-r--r-- | fpicker/source/unx/kde/kdefilepicker.hxx | 113 | ||||
-rw-r--r-- | fpicker/source/unx/kde/kdefpmain.cxx | 76 | ||||
-rw-r--r-- | fpicker/source/unx/kde/kdemodalityfilter.cxx | 66 | ||||
-rw-r--r-- | fpicker/source/unx/kde/kdemodalityfilter.hxx | 45 | ||||
-rw-r--r-- | fpicker/source/unx/kde/makefile.mk | 75 |
8 files changed, 1239 insertions, 0 deletions
diff --git a/fpicker/source/unx/kde/kdecommandthread.cxx b/fpicker/source/unx/kde/kdecommandthread.cxx new file mode 100644 index 000000000000..43e2a68ac8b0 --- /dev/null +++ b/fpicker/source/unx/kde/kdecommandthread.cxx @@ -0,0 +1,174 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2010 Novell, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <kdecommandthread.hxx> + +#include <qstringlist.h> + +#include <kapplication.h> + +#include <iostream> + +////////////////////////////////////////////////////////////////////////// +// CommandEvent +////////////////////////////////////////////////////////////////////////// + +CommandEvent::CommandEvent( const QString &qCommand, QStringList *pStringList ) + : QCustomEvent( TypeId, pStringList ), + m_eCommand( Unknown ) +{ + struct { + const char *pName; + CommandEventType eType; + } *pIdx, pMapping[] = + { + { "appendControl", AppendControl }, + { "enableControl", EnableControl }, + { "getValue", GetValue }, + { "setValue", SetValue }, + { "appendFilter", AppendFilter }, + { "appendFilterGroup", AppendFilterGroup }, + { "getCurrentFilter", GetCurrentFilter }, + { "setCurrentFilter", SetCurrentFilter }, + { "getDirectory", GetDirectory }, + { "setDirectory", SetDirectory }, + { "getFiles", GetFiles }, + { "setTitle", SetTitle }, + { "setType", SetType }, + { "setDefaultName", SetDefaultName }, + { "setMultiSelection", SetMultiSelection }, + { "exec", Exec }, + { 0, Unknown } + }; + + for ( pIdx = pMapping; pIdx->pName && qCommand != pIdx->pName; ++pIdx ) + ; + + m_eCommand = pIdx->eType; +} + +////////////////////////////////////////////////////////////////////////// +// CommandThread +////////////////////////////////////////////////////////////////////////// + +CommandThread::CommandThread( QWidget *pObject ) + : m_pObject( pObject ) +{ +} + +CommandThread::~CommandThread() +{ +} + +void CommandThread::run() +{ + QTextIStream qStream( stdin ); + qStream.setEncoding( QTextStream::UnicodeUTF8 ); + + QString qLine; + bool bQuit = false; + while ( !bQuit && !qStream.atEnd() ) + { + qLine = qStream.readLine(); + handleCommand( qLine, bQuit ); + } +} + +void CommandThread::handleCommand( const QString &rString, bool &bQuit ) +{ + QMutexLocker qMutexLocker( &m_aMutex ); + +#if OSL_DEBUG_LEVEL > 0 + ::std::cerr << "kdefilepicker received: " << rString.latin1() << ::std::endl; +#endif + + bQuit = false; + QStringList *pTokens = tokenize( rString ); + + if ( !pTokens ) + return; + if ( pTokens->empty() ) + { + delete pTokens, pTokens = NULL; + return; + } + + QString qCommand = pTokens->front(); + pTokens->pop_front(); + + if ( qCommand == "exit" ) + { + bQuit = true; + kapp->exit(); + kapp->wakeUpGuiThread(); + } + else + kapp->postEvent( m_pObject, new CommandEvent( qCommand, pTokens ) ); +} + +QStringList* CommandThread::tokenize( const QString &rString ) +{ + // Commands look like: + // command arg1 arg2 arg3 ... + // Args may be enclosed in '"', if they contain spaces. + + QStringList *pList = new QStringList(); + + QString qBuffer; + qBuffer.reserve( 1024 ); + + const QChar *pUnicode = rString.unicode(); + const QChar *pEnd = pUnicode + rString.length(); + bool bQuoted = false; + + for ( ; pUnicode != pEnd; ++pUnicode ) + { + if ( *pUnicode == '\\' ) + { + ++pUnicode; + if ( pUnicode != pEnd ) + { + if ( *pUnicode == 'n' ) + qBuffer.append( '\n' ); + else + qBuffer.append( *pUnicode ); + } + } + else if ( *pUnicode == '"' ) + bQuoted = !bQuoted; + else if ( *pUnicode == ' ' && !bQuoted ) + { + pList->push_back( qBuffer ); + qBuffer.setLength( 0 ); + } + else + qBuffer.append( *pUnicode ); + } + pList->push_back( qBuffer ); + + return pList; +} diff --git a/fpicker/source/unx/kde/kdecommandthread.hxx b/fpicker/source/unx/kde/kdecommandthread.hxx new file mode 100644 index 000000000000..bfb0570ecd7c --- /dev/null +++ b/fpicker/source/unx/kde/kdecommandthread.hxx @@ -0,0 +1,94 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2010 Novell, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _KDECOMMANDTHREAD_HXX_ +#define _KDECOMMANDTHREAD_HXX_ + +#include <qevent.h> +#include <qmutex.h> +#include <qthread.h> + +class CommandEvent : public QCustomEvent +{ +public: + enum CommandEventType { + Unknown = 0, + + AppendControl, + EnableControl, + GetValue, + SetValue, + + AppendFilter, + AppendFilterGroup, + UpdateFilters, + GetCurrentFilter, + SetCurrentFilter, + + GetDirectory, + SetDirectory, + + GetFiles, + + SetTitle, + SetType, + SetDefaultName, + SetMultiSelection, + + Exec + }; + static const QEvent::Type TypeId = (QEvent::Type) ( (int) QEvent::User + 42 /*random magic value*/ ); + +protected: + CommandEventType m_eCommand; + +public: + CommandEvent( const QString &qCommand, QStringList *pStringList ); + + CommandEventType command() const { return m_eCommand; } + QStringList* stringList() { return static_cast< QStringList* >( data() ); } +}; + +class CommandThread : public QThread +{ +protected: + QObject *m_pObject; + + QMutex m_aMutex; + +public: + CommandThread( QWidget *pObject ); + virtual ~CommandThread(); + + virtual void run(); + +protected: + void handleCommand( const QString &rString, bool &bQuit ); + QStringList* tokenize( const QString &rString ); +}; + +#endif // _KDECOMMANDTHREAD_HXX_ diff --git a/fpicker/source/unx/kde/kdefilepicker.cxx b/fpicker/source/unx/kde/kdefilepicker.cxx new file mode 100644 index 000000000000..eea0c7aaa7d8 --- /dev/null +++ b/fpicker/source/unx/kde/kdefilepicker.cxx @@ -0,0 +1,596 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2010 Novell, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <kdecommandthread.hxx> +#include <kdefilepicker.hxx> + +#include <qcheckbox.h> +#include <qcombobox.h> +#include <qgrid.h> +#include <qhbox.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qobjectlist.h> +#include <qpushbutton.h> +#include <qvbox.h> + +#ifdef QT_NO_EMIT +#define emit +#endif + +#include <kdiroperator.h> +#include <kfiledialog.h> +#include <kfilefiltercombo.h> +#include <klocale.h> +#include <kmessagebox.h> + +#include <algorithm> +#include <iostream> + +////////////////////////////////////////////////////////////////////////// +// FileDialog +////////////////////////////////////////////////////////////////////////// + +FileDialog::FileDialog( const QString &startDir, const QString &filter, + QWidget *parent, const char *name ) + : KFileDialog( startDir, filter, parent, name, true, m_pCustomWidget = new QVBox() ), + m_pCombosAndButtons( new QHBox( m_pCustomWidget ) ), + m_pLabels( new QVBox( m_pCombosAndButtons ) ), + m_pComboBoxes( new QVBox( m_pCombosAndButtons ) ), + m_pPushButtons( new QVBox( m_pCombosAndButtons ) ), + m_pCheckBoxes( new QGrid( 2, m_pCustomWidget ) ), + m_bIsSave( false ), + m_bCanNotifySelection( true ) +{ + connect( this, SIGNAL( fileHighlighted( const QString & ) ), + this, SLOT( fileHighlightedCommand( const QString & ) ) ); + + connect( this, SIGNAL( selectionChanged() ), + this, SLOT( selectionChangedCommand() ) ); + + m_pCustomWidget->setSpacing( KDialog::spacingHint() ); + m_pCombosAndButtons->setSpacing( KDialog::spacingHint() ); + + updateCustomWidgetLayout(); +} + +FileDialog::~FileDialog() +{ +} + +void FileDialog::resizeEvent( QResizeEvent *pEvent ) +{ + KFileDialog::resizeEvent( pEvent ); + + updateCustomWidgetLayout(); +} + +void FileDialog::showEvent( QShowEvent *pEvent ) +{ + KFileDialog::showEvent( pEvent ); + + updateCustomWidgetLayout(); +} + +void FileDialog::updateCustomWidgetLayout() +{ + QPoint qReferencePoint = filterWidget->mapTo( this, QPoint( 0, 0 ) ); + QPoint qCustomPoint = m_pCustomWidget->mapTo( this, QPoint( 0, 0 ) ); + + int nLeft = qReferencePoint.x() - qCustomPoint.x(); + int nRight = m_pCustomWidget->width() - filterWidget->width() - nLeft; + + nLeft -= KDialog::spacingHint(); + nRight -= KDialog::spacingHint(); + m_pLabels->setFixedWidth( ( nLeft > 0 )? nLeft: 80 ); + // FIXME The following call sets the width of m_pPushButtons all right, + // but it also increases the width of m_pComboBoxes rapidly. Can we do + // anything about it? + m_pPushButtons->setFixedWidth( ( nRight > 0 )? nRight: 100 ); +} + +void FileDialog::customEvent( QCustomEvent *pEvent ) +{ + if ( pEvent && pEvent->type() == CommandEvent::TypeId ) + { + CommandEvent *pCommandEvent = static_cast< CommandEvent* >( pEvent ); + QStringList *pStringList = pCommandEvent->stringList(); + + int nListSize = -1; + if ( pStringList ) + nListSize = pStringList->size(); + + switch ( pCommandEvent->command() ) + { + case CommandEvent::AppendControl: + if ( nListSize >= 3 ) + { + appendControl( (*pStringList)[0], (*pStringList)[1], (*pStringList)[2] ); + } + break; + case CommandEvent::EnableControl: + if ( nListSize >= 2 ) + { + enableControl( (*pStringList)[0], (*pStringList)[1] ); + } + break; + case CommandEvent::GetValue: + if ( nListSize >= 2 ) + { + getValue( (*pStringList)[0], (*pStringList)[1] ); + } + break; + case CommandEvent::SetValue: + if ( nListSize >= 2 ) + { + QStringList qStringList = (*pStringList); + qStringList.pop_front(); + qStringList.pop_front(); + + setValue( (*pStringList)[0], (*pStringList)[1], qStringList ); + } + break; + case CommandEvent::AppendFilter: + if ( nListSize >= 2 ) + { + appendFilter( (*pStringList)[0], (*pStringList)[1] ); + + // update the filters widget + setFilter( filters() ); + } + break; + case CommandEvent::AppendFilterGroup: + if ( nListSize >= 1 ) + { + QStringList::const_iterator it = pStringList->begin(); + ++it; // We ignore the filter group name + + while ( it != pStringList->end() ) + { + QString qTitle = *it; + ++it; + if ( it != pStringList->end() ) + { + appendFilter( qTitle, (*it) ); + ++it; + } + } + + // update the filters widget + setFilter( filters() ); + } + break; + case CommandEvent::GetCurrentFilter: + { + QString qCurrentFilter = filterWidget->currentText(); + sendCommand( "currentFilter " + escapeString( qCurrentFilter ) ); + } + break; + case CommandEvent::SetCurrentFilter: + if ( nListSize >= 1 ) + { + static_cast< FileFilterComboHack* >( filterWidget )->setCurrentFilter( pStringList->front() ); + } + break; + case CommandEvent::GetDirectory: + { + QString qDirectory = baseURL().url(); + if ( qDirectory.startsWith( "file:/" ) && qDirectory.mid( 6, 1 ) != "/" ) + qDirectory.replace( "file:/", "file:///" ); + sendCommand( "currentDirectory " + escapeString( qDirectory ) ); + } + break; + case CommandEvent::SetDirectory: + if ( nListSize >= 1 ) + { + setURL( pStringList->front() ); + } + break; + case CommandEvent::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 ) + { + qString.append( " " ); + QString qUrlStr = (*it).url(); + if ( qUrlStr.startsWith( "file:/" ) && qUrlStr.mid( 6, 1 ) != "/" ) + qUrlStr.replace( "file:/", "file:///" ); + appendEscaped( qString, addExtension( qUrlStr ) ); + } + } + else + { + // we have to return the selected files anyway + const KFileItemList *pItems = ops->selectedItems(); + for ( KFileItemListIterator it( *pItems ); it.current(); ++it ) + { + qString.append( " " ); + QString qUrlStr = (*it)->url().url(); + if ( qUrlStr.startsWith( "file:/" ) && qUrlStr.mid( 6, 1 ) != "/" ) + qUrlStr.replace( "file:/", "file:///" ); + appendEscaped( qString, addExtension( qUrlStr ) ); + } + } + + sendCommand( qString ); + setCanNotifySelection( true ); + } + break; + case CommandEvent::SetTitle: + if ( nListSize >= 1 ) + { + setCaption( pStringList->front() ); + } + break; + case CommandEvent::SetType: + if ( nListSize >= 1 ) + { + QString qType( pStringList->front() ); + if ( qType == "open" ) + { + setIsSave( false ); + setCaption( i18n( "Open" ) ); + } + else if ( qType == "save" ) + { + setIsSave( true ); + setCaption( i18n( "Save As" ) ); + } + } + break; + case CommandEvent::SetDefaultName: + if ( nListSize >= 1 ) + { + setKeepLocation( true ); + setSelection( pStringList->front() ); + } + break; + case CommandEvent::SetMultiSelection: + if ( nListSize >= 1 ) + { + if ( pStringList->front() == "true" ) + setMode( KFile::Files ); + else + setMode( KFile::File ); + } + break; + case CommandEvent::Exec: + { + filterWidget->setEditable( false ); + QString qSelectedURL; + do { + setCanNotifySelection( true ); + exec(); + qSelectedURL = addExtension( selectedURL().url() ); + } while ( isSave() && + result() == QDialog::Accepted && + ( qSelectedURL.startsWith( "file:" ) && QFile::exists( qSelectedURL.mid( 5 ) ) ) && + KMessageBox::warningYesNo( 0, + i18n( "A file named \"%1\" already exists. " + "Are you sure you want to overwrite it?" ).arg( qSelectedURL ), + i18n( "Overwrite File?" ), + i18n( "Overwrite" ), KStdGuiItem::cancel() ) != KMessageBox::Yes ); + + if ( result() == QDialog::Accepted ) + sendCommand( "accept" ); + else + sendCommand( "reject" ); + } + break; + default: + break; + } + + // FIXME Some cleanup of pEvent? delete something, etc.? + } +} + +void FileDialog::appendControl( const QString &rId, const QString &rType, const QString &rTitle ) +{ + QString qLabel( rTitle ); + qLabel.replace( '~', '&' ); + + if ( rType == "checkbox" ) + { + QCheckBox *pCheckBox = new QCheckBox( qLabel, m_pCheckBoxes, rId.utf8() ); + + pCheckBox->setEnabled( true ); + pCheckBox->setChecked( false ); + } + else if ( rType == "listbox" ) + { + QLabel *pComboLabel = new QLabel( qLabel, m_pLabels ); + QComboBox *pComboBox = new QComboBox( m_pComboBoxes, rId.utf8() ); + + pComboLabel->setBuddy( pComboBox ); + pComboBox->setEnabled( true ); + } + else if ( rType == "pushbutton" ) + { + QPushButton *pPushButton = new QPushButton( qLabel, m_pPushButtons, rId.utf8() ); + pPushButton->setEnabled( true ); + } +} + +QWidget* FileDialog::findControl( const QString &rId ) const +{ + QObjectList *pList = m_pCustomWidget->queryList(); + QCString qName( rId.utf8() ); + QObjectList::const_iterator it = pList->begin(); + + for ( ; it != pList->end() && qName != (*it)->name(); ++it ) + ; + + QWidget *pWidget = NULL; + if ( it != pList->end() ) + pWidget = static_cast< QWidget* >( *it ); + + delete pList; + + return pWidget; +} + +void FileDialog::enableControl( const QString &rId, const QString &rValue ) +{ + QWidget *pWidget = findControl( rId ); + + if ( pWidget ) + pWidget->setEnabled( rValue.lower() == "true" ); +} + +void FileDialog::getValue( const QString &rId, const QString &rAction ) +{ + QWidget *pWidget = findControl( rId ); + QString qString; + qString.reserve( 1024 ); + qString.append( "value" ); + + if ( pWidget ) + { + QCString qClassName = pWidget->className(); + if ( qClassName == "QCheckBox" ) + { + QCheckBox *pCheckBox = static_cast< QCheckBox* >( pWidget ); + + if ( pCheckBox->isChecked() ) + qString.append( " bool true" ); + else + qString.append( " bool false" ); + } + else if ( qClassName == "QComboBox" ) + { + QComboBox *pComboBox = static_cast< QComboBox* >( pWidget ); + if ( rAction == "getItems" ) + { + qString.append( " stringList" ); + for ( int nIdx = 0; nIdx < pComboBox->count(); ++nIdx ) + { + qString.append( ' ' ); + appendEscaped( qString, pComboBox->text( nIdx ) ); + } + } + else if ( rAction == "getSelectedItem" ) + { + qString.append( " string " ); + appendEscaped( qString, pComboBox->currentText() ); + } + else if ( rAction == "getSelectedItemIndex" ) + { + qString.append( " int " ); + qString.append( QString().setNum( pComboBox->currentItem() ) ); + } + // TODO getHelpURL + } + // TODO push button + } + + sendCommand( qString ); +} + +void FileDialog::setValue( const QString &rId, const QString &rAction, const QStringList &rValue ) +{ + QWidget *pWidget = findControl( rId ); + + if ( pWidget ) + { + QCString qClassName = pWidget->className(); + if ( qClassName == "QCheckBox" ) + { + QCheckBox *pCheckBox = static_cast< QCheckBox* >( pWidget ); + + bool bValue = ( !rValue.isEmpty() ) && ( rValue.front().lower() == "true" ); + pCheckBox->setChecked( bValue ); + } + else if ( qClassName == "QComboBox" ) + { + QComboBox *pComboBox = static_cast< QComboBox* >( pWidget ); + if ( rAction == "addItem" ) + { + if ( !rValue.isEmpty() ) + pComboBox->insertItem( rValue.front() ); + } + else if ( rAction == "addItems" ) + { + pComboBox->insertStringList( rValue ); + } + else if ( rAction == "deleteItem" ) + { + if ( !rValue.isEmpty() ) + pComboBox->removeItem( rValue.front().toInt() ); + } + else if ( rAction == "deleteItems" ) + { + pComboBox->clear(); + } + else if ( rAction == "setSelectedItem" ) + { + if ( !rValue.isEmpty() ) + pComboBox->setCurrentItem( rValue.front().toInt() ); + } + // FIXME setHelpURL is ignored + } + // TODO push button + } +} + +void FileDialog::appendFilter( const QString &rTitle, const QString &rFilter ) +{ + // Filters are separated by ';' + QString qFilter( rFilter ); + qFilter.replace( QChar( ';' ), QChar( ' ' ) ).replace( "*.*", "*" ); + + m_aFilters.push_back( qMakePair( rTitle, qFilter ) ); +} + +QString FileDialog::filters() const +{ + QString qString, qTmp; + bool bFirstFilter = true; + + for ( FilterList::const_iterator it = m_aFilters.begin(); it != m_aFilters.end(); ++it ) + { + if ( bFirstFilter ) + bFirstFilter = false; + else + qString.append( '\n' ); + + qString.append( (*it).second ); + qString.append( '|' ); + + qTmp = (*it).first; + qString.append( qTmp.replace( '/', "\\/" ) ); + } + + return qString; +} + +QString FileDialog::addExtension( const QString &rFileName ) const +{ + if ( !isSave() ) + return rFileName; + + QString qExtension; + + QWidget *pExtensionWidget = findControl( "100" ); // CHECKBOX_AUTOEXTENSION + QCheckBox *pExtensionCB = pExtensionWidget? static_cast< QCheckBox* >( pExtensionWidget->qt_cast( "QCheckBox" ) ): NULL; + if ( pExtensionCB && pExtensionCB->isChecked() ) + { + // FIXME: qFilter can be a MIME; we ignore it now... + QStringList qFilterList = QStringList::split( " ", currentFilter() ); + for ( QStringList::const_iterator it = qFilterList.begin(); + qExtension.isEmpty() && it != qFilterList.end(); + ++it ) + { + int nUnwanted = (*it).findRev( '*' ); + if ( nUnwanted < 0 ) + nUnwanted = (*it).findRev( '?' ); + else + nUnwanted = ::std::max( nUnwanted, (*it).find( '?', nUnwanted ) ); + + int nIdx = (*it).find( '.', ::std::max( nUnwanted, 0 ) ); + if ( nIdx >= 0 ) + qExtension = (*it).mid( nIdx ).lower(); + } + } + + if ( qExtension.isEmpty() || qExtension == "." || rFileName.endsWith( qExtension ) ) + return rFileName; + else + return rFileName + qExtension; +} + +void FileDialog::fileHighlightedCommand( const QString & ) +{ + if ( canNotifySelection() ) + { + sendCommand( "fileSelectionChanged" ); + setCanNotifySelection( false ); + } +} + +void FileDialog::selectionChangedCommand() +{ + if ( canNotifySelection() ) + { + sendCommand( "fileSelectionChanged" ); + setCanNotifySelection( false ); + } +} + +void FileDialog::sendCommand( const QString &rCommand ) +{ +#if OSL_DEBUG_LEVEL > 0 + ::std::cerr << "kdefilepicker sent: " << rCommand.latin1() << ::std::endl; +#endif + + //m_aOutputStream << rCommand << endl; + ::std::cout << rCommand.utf8() << ::std::endl; +} + +void FileDialog::appendEscaped( QString &rBuffer, const QString &rString ) +{ + const QChar *pUnicode = rString.unicode(); + const QChar *pEnd = pUnicode + rString.length(); + + rBuffer.append( '"' ); + for ( ; pUnicode != pEnd; ++pUnicode ) + { + if ( *pUnicode == '\\' ) + rBuffer.append( "\\\\" ); + else if ( *pUnicode == '"' ) + rBuffer.append( "\\\"" ); + else if ( *pUnicode == '\n' ) + rBuffer.append( "\\\n" ); + else + rBuffer.append( *pUnicode ); + } + rBuffer.append( '"' ); +} + +QString FileDialog::escapeString( const QString &rString ) +{ + QString qString; + qString.reserve( 2*rString.length() + 2 ); // every char escaped + quotes + + appendEscaped( qString, rString ); + + return qString; +} + + +void FileFilterComboHack::setCurrentFilter( const QString& filter ) +{ + setCurrentText( filter ); + filterChanged(); +} diff --git a/fpicker/source/unx/kde/kdefilepicker.hxx b/fpicker/source/unx/kde/kdefilepicker.hxx new file mode 100644 index 000000000000..000db70e3da1 --- /dev/null +++ b/fpicker/source/unx/kde/kdefilepicker.hxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2010 Novell, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _KDEFILEPICKER_HXX_ +#define _KDEFILEPICKER_HXX_ + +#include <kfiledialog.h> +#include <kfilefiltercombo.h> + +class QGrid; +class QHBox; +class QVBox; + +class FileDialog : public KFileDialog +{ + Q_OBJECT + +protected: + typedef QPair< QString, QString > FilterEntry; + typedef QValueList< FilterEntry > FilterList; + + QVBox *m_pCustomWidget; + QHBox *m_pCombosAndButtons; + + QVBox *m_pLabels; + QVBox *m_pComboBoxes; + QVBox *m_pPushButtons; + + QGrid *m_pCheckBoxes; + + FilterList m_aFilters; + + /** Are we a "Save As" dialog? + * + * We cannot use KFileDialog::setOperationMode() here, because then + * it automatically adds an "Automatically select filename extension" + * check box, and completely destroys the dialog's layout + * (custom list boxes are under this check box, which looks ugly). + */ + bool m_bIsSave; + + bool m_bCanNotifySelection; + +public: + FileDialog( const QString &startDir, const QString &filter, + QWidget *parent, const char *name ); + virtual ~FileDialog(); + +protected: + virtual void resizeEvent( QResizeEvent *pEvent ); + virtual void showEvent( QShowEvent *pEvent ); + void updateCustomWidgetLayout(); + + virtual void customEvent( QCustomEvent *pEvent ); + +protected: + void appendControl( const QString &rId, const QString &rType, const QString &rTitle ); + QWidget* findControl( const QString &rId ) const; + void enableControl( const QString &rId, const QString &rValue ); + void getValue( const QString &rId, const QString &rAction ); + void setValue( const QString &rId, const QString &rAction, const QStringList &rValue ); + + void appendFilter( const QString &rTitle, const QString &rFilter ); + QString filters() const; + QString addExtension( const QString &rFileName ) const; + + void setIsSave( bool bIsSave ) { m_bIsSave = bIsSave; } + bool isSave( void ) const { return m_bIsSave; } + + void setCanNotifySelection( bool bCanNotifySelection ) { m_bCanNotifySelection = bCanNotifySelection; } + bool canNotifySelection( void ) const { return m_bCanNotifySelection; } + +protected slots: + void fileHighlightedCommand( const QString & ); + void selectionChangedCommand(); + +protected: + void sendCommand( const QString &rCommand ); + void appendEscaped( QString &rBuffer, const QString &rString ); + QString escapeString( const QString &rString ); +}; + +class FileFilterComboHack : public KFileFilterCombo +{ +public: + void setCurrentFilter( const QString& filter ); +}; + +#endif // _KDEFILEPICKER_HXX_ diff --git a/fpicker/source/unx/kde/kdefpmain.cxx b/fpicker/source/unx/kde/kdefpmain.cxx new file mode 100644 index 000000000000..30c832bc613b --- /dev/null +++ b/fpicker/source/unx/kde/kdefpmain.cxx @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2010 Novell, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <kdemodalityfilter.hxx> +#include <kdefilepicker.hxx> +#include <kdecommandthread.hxx> + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kcmdlineargs.h> + +#include <iostream> +#include <stdlib.h> + +////////////////////////////////////////////////////////////////////////// +// Main +////////////////////////////////////////////////////////////////////////// + +int main( int argc, char* argv[] ) +{ + // we fake the name of the application to have "OpenOffice.org" in the + // title + KAboutData qAboutData( "kdefilepicker", I18N_NOOP( "OpenOffice.org" ), + "0.1", I18N_NOOP( "kdefilepicker is an implementation of the KDE file dialog for OpenOffice.org." ), + KAboutData::License_LGPL, + "(c) 2004, Jan Holesovsky" ); + qAboutData.addAuthor( "Jan Holesovsky", I18N_NOOP("Original author and current maintainer"), "kendy@openoffice.org" ); + + // Let the user see that this does something... + ::std::cerr << "kdefilepicker, an implementation of KDE file dialog for OOo." << ::std::endl + << "Type 'exit' and press Enter to finish." << ::std::endl; + + KCmdLineArgs::init( argc, argv, &qAboutData ); + + KLocale::setMainCatalogue( "kdialog" ); + + KApplication kApplication; + //ModalityFilter qFilter( /*winid*/ 79691780 ); + + FileDialog aFileDialog( NULL, QString(), NULL, "kdefiledialog" ); + + CommandThread qCommandThread( &aFileDialog ); + qCommandThread.start(); + + kApplication.exec(); + + qCommandThread.wait(); + + ::std::cout << "exited" << ::std::endl; + + return 0; +} diff --git a/fpicker/source/unx/kde/kdemodalityfilter.cxx b/fpicker/source/unx/kde/kdemodalityfilter.cxx new file mode 100644 index 000000000000..c214bca001e8 --- /dev/null +++ b/fpicker/source/unx/kde/kdemodalityfilter.cxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2010 Novell, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <kdemodalityfilter.hxx> + +#include <kapplication.h> +#include <kdialogbase.h> + +#include <netwm.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +////////////////////////////////////////////////////////////////////////// +// Modality filter +////////////////////////////////////////////////////////////////////////// + +ModalityFilter::ModalityFilter( WId nWinId ) + : m_nWinId( nWinId ) +{ + kapp->installEventFilter( this ); +} + +ModalityFilter::~ModalityFilter() +{ + kapp->removeEventFilter( this ); +} + +bool ModalityFilter::eventFilter( QObject *pObject, QEvent *pEvent ) +{ + if ( pObject->isWidgetType() && pEvent->type() == QEvent::Show ) + { + KDialogBase* pDlg = ::qt_cast< KDialogBase* >( pObject ); + if ( pDlg != NULL && m_nWinId != 0 ) + { + XSetTransientForHint( qt_xdisplay(), pDlg->winId(), m_nWinId ); + NETWinInfo aInfo( qt_xdisplay(), pDlg->winId(), qt_xrootwin(), NET::WMState ); + aInfo.setState( NET::Modal, NET::Modal ); + m_nWinId = 0; + } + } + return false; +} diff --git a/fpicker/source/unx/kde/kdemodalityfilter.hxx b/fpicker/source/unx/kde/kdemodalityfilter.hxx new file mode 100644 index 000000000000..66b795364ba5 --- /dev/null +++ b/fpicker/source/unx/kde/kdemodalityfilter.hxx @@ -0,0 +1,45 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2010 Novell, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _KDEMODALITYFILTER_HXX_ +#define _KDEMODALITYFILTER_HXX_ + +#include <qobject.h> + +class ModalityFilter : public QObject +{ +private: + WId m_nWinId; + +public: + ModalityFilter( WId nWinId ); + virtual ~ModalityFilter(); + + virtual bool eventFilter( QObject *pObject, QEvent *pEvent ); +}; + +#endif // _KDEMODALITYFILTER_HXX_ diff --git a/fpicker/source/unx/kde/makefile.mk b/fpicker/source/unx/kde/makefile.mk new file mode 100644 index 000000000000..11f846bd3891 --- /dev/null +++ b/fpicker/source/unx/kde/makefile.mk @@ -0,0 +1,75 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2010 Novell, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=fpicker +TARGET=kdefilepicker +LIBTARGET=NO +ENABLE_EXCEPTIONS=TRUE +#COMP1TYPELIST=$(TARGET) +#COMPRDB=$(SOLARBINDIR)$/types.rdb + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# ------------------------------------------------------------------ + +.IF "$(GUIBASE)" != "unx" || "$(ENABLE_KDE)" != "TRUE" + +dummy: + @echo "Nothing to build. GUIBASE == $(GUIBASE), ENABLE_KDE is not set" + +.ELSE # we build for KDE + +CFLAGS+= $(KDE_CFLAGS) + +# --- Files -------------------------------------------------------- + +SLOFILES =\ + $(SLO)$/kdecommandthread.obj \ + $(SLO)$/kdefilepicker.obj \ + $(SLO)$/kdefilepicker.moc.obj \ + $(SLO)$/kdefpmain.obj \ + $(SLO)$/kdemodalityfilter.obj + +APP1TARGET=$(TARGET) +APP1OBJS=$(SLOFILES) +APP1STDLIBS=\ + $(SALLIB) \ + $(KDE_LIBS) -lkio + + +.ENDIF # "$(GUIBASE)" != "unx" || "$(ENABLE_KDE)" != "TRUE" + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +$(MISC)$/kdefilepicker.moc.cxx : kdefilepicker.hxx + $(MOC) $< -o $@ |