1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #pragma once
25 
26 #include <cppuhelper/compbase8.hxx>
27 
28 #include <com/sun/star/lang/XInitialization.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
31 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
32 #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
33 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
34 //#include <com/sun/star/ui/dialogs/XFilePreview.hpp>
35 #include <com/sun/star/util/XCancellable.hpp>
36 
37 #include <osl/conditn.hxx>
38 #include <osl/mutex.hxx>
39 
40 #include <rtl/ustrbuf.hxx>
41 
42 #include <QString>
43 #include <QHash>
44 
45 class KFileDialog;
46 class QWidget;
47 class QLayout;
48 
49 class ResMgr;
50 
51 class KDE4FilePicker :
52     public cppu::WeakComponentImplHelper8<
53         ::com::sun::star::ui::dialogs::XFilterManager,
54         ::com::sun::star::ui::dialogs::XFilterGroupManager,
55         ::com::sun::star::ui::dialogs::XFilePickerControlAccess,
56         ::com::sun::star::ui::dialogs::XFilePickerNotifier,
57 // TODO ::com::sun::star::ui::dialogs::XFilePreview,
58         ::com::sun::star::lang::XInitialization,
59         ::com::sun::star::util::XCancellable,
60         ::com::sun::star::lang::XEventListener,
61         ::com::sun::star::lang::XServiceInfo >
62 {
63 protected:
64     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceMgr;   // to instanciate own services
65 
66 	::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener > m_xListener;
67 
68     ResMgr *_resMgr;
69 
70 	//the dialog to display
71 	KFileDialog* _dialog;
72 
73 	osl::Mutex _helperMutex;
74 
75 	//running filter string to add to dialog
76 	QString _filter;
77 
78 	//filter for reverse lookup of filter text
79 	QHash<QString, QString> _filters;
80 
81 	//mapping of SAL control ID's to created custom controls
82 	QHash<sal_Int16, QWidget*> _customWidgets;
83 
84 	//widget to contain extra custom controls
85 	QWidget* _extraControls;
86 
87 	//layout for extra custom controls
88 	QLayout* _layout;
89 
90 public:
91     KDE4FilePicker( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceMgr );
92     virtual ~KDE4FilePicker();
93 
94     // XFilePickerNotifier
95 
96     virtual void SAL_CALL addFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener ) throw( ::com::sun::star::uno::RuntimeException );
97     virtual void SAL_CALL removeFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener ) throw( ::com::sun::star::uno::RuntimeException );
98 
99     // XExecutableDialog functions
100 
101     virtual void SAL_CALL setTitle( const ::rtl::OUString &rTitle ) throw( ::com::sun::star::uno::RuntimeException );
102     virtual sal_Int16 SAL_CALL execute() throw( ::com::sun::star::uno::RuntimeException );
103 
104     // XFilePicker functions
105 
106     virtual void SAL_CALL setMultiSelectionMode( sal_Bool bMode ) throw( ::com::sun::star::uno::RuntimeException );
107     virtual void SAL_CALL setDefaultName( const ::rtl::OUString &rName ) throw( ::com::sun::star::uno::RuntimeException );
108     virtual void SAL_CALL setDisplayDirectory( const ::rtl::OUString &rDirectory ) throw( ::com::sun::star::uno::RuntimeException );
109     virtual ::rtl::OUString SAL_CALL getDisplayDirectory() throw( ::com::sun::star::uno::RuntimeException );
110     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFiles() throw( ::com::sun::star::uno::RuntimeException );
111 
112     // XFilterManager functions
113 
114     virtual void SAL_CALL appendFilter( const ::rtl::OUString &rTitle, const ::rtl::OUString &rFilter ) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
115     virtual void SAL_CALL setCurrentFilter( const ::rtl::OUString &rTitle ) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
116     virtual ::rtl::OUString SAL_CALL getCurrentFilter() throw( ::com::sun::star::uno::RuntimeException );
117 
118     // XFilterGroupManager functions
119 
120     virtual void SAL_CALL appendFilterGroup( const ::rtl::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);
121 
122     // XFilePickerControlAccess functions
123 
124     virtual void SAL_CALL setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const ::com::sun::star::uno::Any &rValue ) throw (::com::sun::star::uno::RuntimeException);
125     virtual ::com::sun::star::uno::Any SAL_CALL getValue( sal_Int16 nControlId, sal_Int16 nControlAction ) throw (::com::sun::star::uno::RuntimeException);
126     virtual void SAL_CALL enableControl( sal_Int16 nControlId, sal_Bool bEnable ) throw( ::com::sun::star::uno::RuntimeException );
127     virtual void SAL_CALL setLabel( sal_Int16 nControlId, const ::rtl::OUString &rLabel ) throw (::com::sun::star::uno::RuntimeException);
128     virtual ::rtl::OUString SAL_CALL getLabel( sal_Int16 nControlId ) throw (::com::sun::star::uno::RuntimeException);
129 
130     /* TODO XFilePreview
131 
132     virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats(  ) throw (::com::sun::star::uno::RuntimeException);
133     virtual sal_Int32 SAL_CALL  getTargetColorDepth(  ) throw (::com::sun::star::uno::RuntimeException);
134     virtual sal_Int32 SAL_CALL  getAvailableWidth(  ) throw (::com::sun::star::uno::RuntimeException);
135     virtual sal_Int32 SAL_CALL  getAvailableHeight(  ) throw (::com::sun::star::uno::RuntimeException);
136     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);
137     virtual sal_Bool SAL_CALL   setShowState( sal_Bool bShowState ) throw (::com::sun::star::uno::RuntimeException);
138     virtual sal_Bool SAL_CALL   getShowState(  ) throw (::com::sun::star::uno::RuntimeException);
139     */
140 
141     // XInitialization
142 
143     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 );
144 
145     // XCancellable
146 
147     virtual void SAL_CALL cancel( ) throw( ::com::sun::star::uno::RuntimeException );
148 
149     // XEventListener
150 
151     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject &rEvent ) throw( ::com::sun::star::uno::RuntimeException );
152 
153     // XServiceInfo
154 
155     virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
156     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString &rServiceName ) throw( ::com::sun::star::uno::RuntimeException );
157     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException );
158 
159 private:
160     // prevent copy and assignment
161     KDE4FilePicker( const KDE4FilePicker& );
162     KDE4FilePicker& operator=( const KDE4FilePicker& );
163 
164 	//add a custom control widget to the file dialog
165 	void addCustomControl(sal_Int16 controlId);
166 
167 };
168