Kaydet (Commit) a274cbff authored tarafından Luboš Luňák's avatar Luboš Luňák

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 673be8e7),
so allow at least that subset.

Change-Id: I2334764317ffc1e20d234e863b60bcc06d17fde0
üst 3d5fb88c
......@@ -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 $@
......
......@@ -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: */
......@@ -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: */
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