diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2013-06-12 17:10:48 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2013-06-12 17:14:11 +0200 |
commit | a274cbff7c138e110eba65f117df8d9cae3c4427 (patch) | |
tree | 697eb96471bb2ed63a23fd7e1ddd21692ff34ca5 /vcl | |
parent | 3d5fb88cc0aa8ee6be6cec5ce0255f1412368519 (diff) |
allow at least some KDE protocols in KFileDialog
Although LO doesn't support all KIO protocols, it supports at least
a subset (as can be see also in 673be8e76856c6bc39f448f3374db4ae84258952),
so allow at least that subset.
Change-Id: I2334764317ffc1e20d234e863b60bcc06d17fde0
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/CustomTarget_kde4_moc.mk | 7 | ||||
-rw-r--r-- | vcl/unx/kde4/KDE4FilePicker.cxx | 59 | ||||
-rw-r--r-- | vcl/unx/kde4/KDE4FilePicker.hxx | 10 |
3 files changed, 68 insertions, 8 deletions
diff --git a/vcl/CustomTarget_kde4_moc.mk b/vcl/CustomTarget_kde4_moc.mk index 679cfbfe922f..0846b0b7f261 100644 --- a/vcl/CustomTarget_kde4_moc.mk +++ b/vcl/CustomTarget_kde4_moc.mk @@ -10,10 +10,11 @@ $(eval $(call gb_CustomTarget_CustomTarget,vcl/unx/kde4)) $(call gb_CustomTarget_get_target,vcl/unx/kde4) : \ - $(call gb_CustomTarget_get_workdir,vcl/unx/kde4)/KDEXLib.moc + $(call gb_CustomTarget_get_workdir,vcl/unx/kde4)/KDEXLib.moc \ + $(call gb_CustomTarget_get_workdir,vcl/unx/kde4)/KDE4FilePicker.moc -$(call gb_CustomTarget_get_workdir,vcl/unx/kde4)/KDEXLib.moc : \ - $(SRCDIR)/vcl/unx/kde4/KDEXLib.hxx \ +$(call gb_CustomTarget_get_workdir,vcl/unx/kde4)/%.moc : \ + $(SRCDIR)/vcl/unx/kde4/%.hxx \ | $(call gb_CustomTarget_get_workdir,vcl/unx/kde4)/.dir $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),MOC,1) $(MOC4) $< -o $@ diff --git a/vcl/unx/kde4/KDE4FilePicker.cxx b/vcl/unx/kde4/KDE4FilePicker.cxx index 01493d067965..e76c7523edc5 100644 --- a/vcl/unx/kde4/KDE4FilePicker.cxx +++ b/vcl/unx/kde4/KDE4FilePicker.cxx @@ -45,6 +45,10 @@ #include <kwindowsystem.h> #include <kapplication.h> #include <kfilefiltercombo.h> +#include <kfilewidget.h> +#include <kdiroperator.h> +#include <kservicetypetrader.h> +#include <kmessagebox.h> #include <qclipboard.h> #include <QWidget> @@ -62,6 +66,17 @@ using namespace ::com::sun::star::lang; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; +// The dialog should check whether LO also supports the protocol +// provided by KIO, and KFileWidget::dirOperator() is only 4.3+ . +// Moreover it's only in this somewhat internal KFileWidget class, +// which may not necessarily be what KFileDialog::fileWidget() returns, +// but that's hopefully not a problem in practice. +#if KDE_VERSION_MAJOR == 4 && KDE_VERSION_MINOR >= 2 +#define ALLOW_REMOTE_URLS 1 +#else +#define ALLOW_REMOTE_URLS 0 +#endif + ////////////////////////////////////////////////////////////////////////// // helper functions ////////////////////////////////////////////////////////////////////////// @@ -102,13 +117,24 @@ QString toQString(const OUString& s) KDE4FilePicker::KDE4FilePicker( const uno::Reference<uno::XComponentContext>& ) : KDE4FilePicker_Base(_helperMutex) , _resMgr( ResMgr::CreateResMgr("fps_office") ) + , allowRemoteUrls( false ) { _extraControls = new QWidget(); _layout = new QGridLayout(_extraControls); _dialog = new KFileDialog(KUrl("~"), QString(""), 0, _extraControls); - _dialog->setMode(KFile::File | KFile::LocalOnly); +#if ALLOW_REMOTE_URLS + if( KFileWidget* fileWidget = dynamic_cast< KFileWidget* >( _dialog->fileWidget())) + { + allowRemoteUrls = true; + // Use finishedLoading signal rather than e.g. urlEntered, because if there's a problem + // such as the URL being mistyped, there's no way to prevent two message boxes about it, + // one from us and one from KDE code. + connect( fileWidget->dirOperator(), SIGNAL( finishedLoading()), SLOT( checkProtocol())); + } +#endif + setMultiSelectionMode( false ); //default mode _dialog->setOperationMode(KFileDialog::Opening); } @@ -188,10 +214,20 @@ sal_Int16 SAL_CALL KDE4FilePicker::execute() void SAL_CALL KDE4FilePicker::setMultiSelectionMode( sal_Bool multiSelect ) throw( uno::RuntimeException ) { - if (multiSelect) - _dialog->setMode(KFile::Files | KFile::LocalOnly); + if( allowRemoteUrls ) + { + if (multiSelect) + _dialog->setMode(KFile::Files); + else + _dialog->setMode(KFile::File); + } else - _dialog->setMode(KFile::File | KFile::LocalOnly); + { + if (multiSelect) + _dialog->setMode(KFile::Files | KFile::LocalOnly); + else + _dialog->setMode(KFile::File | KFile::LocalOnly); + } } void SAL_CALL KDE4FilePicker::setDefaultName( const OUString &name ) @@ -688,4 +724,19 @@ uno::Sequence< OUString > SAL_CALL KDE4FilePicker::getSupportedServiceNames() return FilePicker_getSupportedServiceNames(); } +void KDE4FilePicker::checkProtocol() +{ + // There's no libreoffice.desktop :(, so find a matching one. + KService::List services = KServiceTypeTrader::self()->query( "Application", "Exec =~ 'libreoffice %U'" ); + QStringList protocols; + if( !services.isEmpty()) + protocols = services[ 0 ]->property( "X-KDE-Protocols" ).toStringList(); + if( protocols.isEmpty()) // incorrect (developer?) installation ? + protocols << "file" << "http"; + if( !protocols.contains( _dialog->baseUrl().protocol()) && !protocols.contains( "KIO" )) + KMessageBox::error( _dialog, KIO::buildErrorString( KIO::ERR_UNSUPPORTED_PROTOCOL, _dialog->baseUrl().protocol())); +} + +#include "KDE4FilePicker.moc" + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/kde4/KDE4FilePicker.hxx b/vcl/unx/kde4/KDE4FilePicker.hxx index 01eb8084c81d..5ac37d03f884 100644 --- a/vcl/unx/kde4/KDE4FilePicker.hxx +++ b/vcl/unx/kde4/KDE4FilePicker.hxx @@ -33,6 +33,7 @@ #include <rtl/ustrbuf.hxx> +#include <QObject> #include <QString> #include <QHash> @@ -52,8 +53,10 @@ typedef ::cppu::WeakComponentImplHelper5 > KDE4FilePicker_Base; class KDE4FilePicker - : public KDE4FilePicker_Base + : public QObject + , public KDE4FilePicker_Base { + Q_OBJECT protected: ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener > m_xListener; @@ -77,6 +80,8 @@ protected: //layout for extra custom controls QLayout* _layout; + bool allowRemoteUrls; + public: KDE4FilePicker( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& ); virtual ~KDE4FilePicker(); @@ -160,6 +165,9 @@ private: //add a custom control widget to the file dialog void addCustomControl(sal_Int16 controlId); +private Q_SLOTS: + void checkProtocol(); + }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |