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