Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / unx / kde4 / KDE4FilePicker.hxx
blobff3a8602b44a4840a99ed86c6607fff5a111aa09
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <cppuhelper/compbase5.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
27 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
28 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <osl/conditn.hxx>
32 #include <osl/mutex.hxx>
34 #include <rtl/ustrbuf.hxx>
36 #include <QObject>
37 #include <QString>
38 #include <QHash>
40 class KFileDialog;
41 class QWidget;
42 class QLayout;
44 typedef ::cppu::WeakComponentImplHelper5
45 < ::com::sun::star::ui::dialogs::XFilePicker2
46 , ::com::sun::star::ui::dialogs::XFilePicker3
47 , ::com::sun::star::ui::dialogs::XFilePickerControlAccess
48 // TODO ::com::sun::star::ui::dialogs::XFilePreview
49 , ::com::sun::star::lang::XInitialization
50 , ::com::sun::star::lang::XServiceInfo
51 > KDE4FilePicker_Base;
53 class KDE4FilePicker
54 : public QObject
55 , public KDE4FilePicker_Base
57 Q_OBJECT
58 protected:
60 ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener > m_xListener;
62 //the dialog to display
63 KFileDialog* _dialog;
65 osl::Mutex _helperMutex;
67 //running filter string to add to dialog
68 QString _filter;
69 // string to set the current filter
70 QString _currentFilter;
72 //mapping of SAL control ID's to created custom controls
73 QHash<sal_Int16, QWidget*> _customWidgets;
75 //widget to contain extra custom controls
76 QWidget* _extraControls;
78 //layout for extra custom controls
79 QLayout* _layout;
81 bool allowRemoteUrls;
83 public:
84 KDE4FilePicker( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& );
85 virtual ~KDE4FilePicker();
87 // XFilePickerNotifier
88 virtual void SAL_CALL addFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
89 virtual void SAL_CALL removeFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
91 // XExecutableDialog functions
92 virtual void SAL_CALL setTitle( const OUString &rTitle ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
93 virtual sal_Int16 SAL_CALL execute() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
95 // XFilePicker functions
96 virtual void SAL_CALL setMultiSelectionMode( sal_Bool bMode ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
97 virtual void SAL_CALL setDefaultName( const OUString &rName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
98 virtual void SAL_CALL setDisplayDirectory( const OUString &rDirectory ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
99 virtual OUString SAL_CALL getDisplayDirectory() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
100 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getFiles() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
102 // XFilterManager functions
103 virtual void SAL_CALL appendFilter( const OUString &rTitle, const OUString &rFilter ) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
104 virtual void SAL_CALL setCurrentFilter( const OUString &rTitle ) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
105 virtual OUString SAL_CALL getCurrentFilter() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
107 // XFilterGroupManager functions
108 virtual void SAL_CALL appendFilterGroup( const OUString &rGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > &rFilters ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
110 // XFilePickerControlAccess functions
111 virtual void SAL_CALL setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const ::com::sun::star::uno::Any &rValue ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
112 virtual ::com::sun::star::uno::Any SAL_CALL getValue( sal_Int16 nControlId, sal_Int16 nControlAction ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 virtual void SAL_CALL enableControl( sal_Int16 nControlId, sal_Bool bEnable ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
114 virtual void SAL_CALL setLabel( sal_Int16 nControlId, const OUString &rLabel ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
115 virtual OUString SAL_CALL getLabel( sal_Int16 nControlId ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
117 /* TODO XFilePreview
119 virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats( ) throw (::com::sun::star::uno::RuntimeException);
120 virtual sal_Int32 SAL_CALL getTargetColorDepth( ) throw (::com::sun::star::uno::RuntimeException);
121 virtual sal_Int32 SAL_CALL getAvailableWidth( ) throw (::com::sun::star::uno::RuntimeException);
122 virtual sal_Int32 SAL_CALL getAvailableHeight( ) throw (::com::sun::star::uno::RuntimeException);
123 virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const ::com::sun::star::uno::Any &rImage ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
124 virtual sal_Bool SAL_CALL setShowState( sal_Bool bShowState ) throw (::com::sun::star::uno::RuntimeException);
125 virtual sal_Bool SAL_CALL getShowState( ) throw (::com::sun::star::uno::RuntimeException);
128 // XFilePicker2 functions
129 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSelectedFiles()
130 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
132 // XInitialization
133 virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > &rArguments ) throw( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
135 // XCancellable
136 virtual void SAL_CALL cancel( ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
138 // XEventListener
139 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject &rEvent ) throw( ::com::sun::star::uno::RuntimeException );
140 using cppu::WeakComponentImplHelperBase::disposing;
142 // XServiceInfo
143 virtual OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
144 virtual sal_Bool SAL_CALL supportsService( const OUString &rServiceName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
145 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
147 private Q_SLOTS:
148 // XExecutableDialog functions
149 void setTitleSlot( const OUString &rTitle ) throw( ::com::sun::star::uno::RuntimeException ) { return setTitle( rTitle ); }
150 sal_Int16 executeSlot() throw( ::com::sun::star::uno::RuntimeException ) { return execute(); }
152 // XFilePicker functions
153 void setMultiSelectionModeSlot( bool bMode ) throw( ::com::sun::star::uno::RuntimeException ) { return setMultiSelectionMode( bMode ); }
154 void setDefaultNameSlot( const OUString &rName ) throw( ::com::sun::star::uno::RuntimeException ) { return setDefaultName( rName ); }
155 void setDisplayDirectorySlot( const OUString &rDirectory ) throw( ::com::sun::star::uno::RuntimeException ) { return setDisplayDirectory( rDirectory ); }
156 OUString getDisplayDirectorySlot() throw( ::com::sun::star::uno::RuntimeException ) { return getDisplayDirectory(); }
157 ::com::sun::star::uno::Sequence< OUString > getFilesSlot() throw( ::com::sun::star::uno::RuntimeException ) { return getFiles(); }
159 // XFilterManager functions
160 void appendFilterSlot( const OUString &rTitle, const OUString &rFilter ) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ) { return appendFilter( rTitle, rFilter ); }
161 void setCurrentFilterSlot( const OUString &rTitle ) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ) { return setCurrentFilter( rTitle ); }
162 OUString getCurrentFilterSlot() throw( ::com::sun::star::uno::RuntimeException ) { return getCurrentFilter(); }
164 // XFilterGroupManager functions
165 void appendFilterGroupSlot( const OUString &rGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > &rFilters ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) { return appendFilterGroup( rGroupTitle, rFilters ); }
167 // XFilePickerControlAccess functions
168 void setValueSlot( sal_Int16 nControlId, sal_Int16 nControlAction, const ::com::sun::star::uno::Any &rValue ) throw (::com::sun::star::uno::RuntimeException) { return setValue( nControlId, nControlAction, rValue ); }
169 ::com::sun::star::uno::Any getValueSlot( sal_Int16 nControlId, sal_Int16 nControlAction ) throw (::com::sun::star::uno::RuntimeException) { return getValue( nControlId, nControlAction ); }
170 void enableControlSlot( sal_Int16 nControlId, bool bEnable ) throw( ::com::sun::star::uno::RuntimeException ) { return enableControl( nControlId, bEnable ); }
171 void setLabelSlot( sal_Int16 nControlId, const OUString &rLabel ) throw (::com::sun::star::uno::RuntimeException) { return setLabel( nControlId, rLabel ); }
172 OUString getLabelSlot( sal_Int16 nControlId ) throw (::com::sun::star::uno::RuntimeException) { return getLabel( nControlId ); }
174 // XFilePicker2 functions
175 ::com::sun::star::uno::Sequence< OUString > getSelectedFilesSlot() throw (::com::sun::star::uno::RuntimeException) { return getSelectedFiles(); }
177 // XInitialization
178 void initializeSlot( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > &rArguments ) throw( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException ) { return initialize( rArguments ); }
180 Q_SIGNALS:
181 // XExecutableDialog functions
182 void setTitleSignal( const OUString &rTitle );
183 sal_Int16 executeSignal();
185 // XFilePicker functions
186 void setMultiSelectionModeSignal( bool bMode );
187 void setDefaultNameSignal( const OUString &rName );
188 void setDisplayDirectorySignal( const OUString &rDirectory );
189 OUString getDisplayDirectorySignal();
190 ::com::sun::star::uno::Sequence< OUString > getFilesSignal();
192 // XFilterManager functions
193 void appendFilterSignal( const OUString &rTitle, const OUString &rFilter );
194 void setCurrentFilterSignal( const OUString &rTitle );
195 OUString getCurrentFilterSignal();
197 // XFilterGroupManager functions
198 void appendFilterGroupSignal( const OUString &rGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > &rFilters );
200 // XFilePickerControlAccess functions
201 void setValueSignal( sal_Int16 nControlId, sal_Int16 nControlAction, const ::com::sun::star::uno::Any &rValue );
202 ::com::sun::star::uno::Any getValueSignal( sal_Int16 nControlId, sal_Int16 nControlAction );
203 void enableControlSignal( sal_Int16 nControlId, bool bEnable );
204 void setLabelSignal( sal_Int16 nControlId, const OUString &rLabel );
205 OUString getLabelSignal( sal_Int16 nControlId );
207 // XFilePicker2 functions
208 ::com::sun::star::uno::Sequence< OUString > getSelectedFilesSignal() ;
210 // XInitialization
211 void initializeSignal( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > &rArguments );
213 // Destructor proxy
214 void cleanupProxySignal();
216 // KDE protocol lookup
217 void checkProtocolSignal();
219 private:
220 KDE4FilePicker( const KDE4FilePicker& ) SAL_DELETED_FUNCTION;
221 KDE4FilePicker& operator=( const KDE4FilePicker& ) SAL_DELETED_FUNCTION;
223 //add a custom control widget to the file dialog
224 void addCustomControl(sal_Int16 controlId);
226 static QString getResString( sal_Int16 aRedId );
228 private Q_SLOTS:
229 void cleanupProxy();
230 void checkProtocol();
232 // emit XFilePickerListener controlStateChanged event
233 void filterChanged(const QString &filter);
234 // emit XFilePickerListener fileSelectionChanged event
235 void selectionChanged();
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */