xref: /trunk/main/fpicker/source/unx/kde4/KDE4FilePicker.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 //////////////////////////////////////////////////////////////////////////
29 // includes
30 //////////////////////////////////////////////////////////////////////////
31 
32 #include <com/sun/star/lang/DisposedException.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <cppuhelper/interfacecontainer.h>
35 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
36 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
37 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
38 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
39 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
40 
41 #include <svtools/svtools.hrc>
42 
43 #include <vos/mutex.hxx>
44 
45 #include <vcl/svapp.hxx>
46 #include <vcl/sysdata.hxx>
47 #include <vcl/syswin.hxx>
48 
49 #include "osl/file.h"
50 
51 #include "KDE4FilePicker.hxx"
52 #include "FPServiceInfo.hxx"
53 
54 /* ********* Hack, but needed because of conflicting types... */
55 #define Region QtXRegion
56 
57 //kde has an enum that uses this...OO does too
58 #undef SETTINGS_MOUSE
59 
60 #include <kfiledialog.h>
61 #include <kwindowsystem.h>
62 #include <kapplication.h>
63 #include <kfilefiltercombo.h>
64 
65 #include <QWidget>
66 #include <QCheckBox>
67 #include <QGridLayout>
68 
69 #undef Region
70 
71 using namespace ::com::sun::star;
72 
73 using namespace ::com::sun::star::ui::dialogs;
74 using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
75 
76 using namespace ::com::sun::star;
77 using namespace ::com::sun::star::ui::dialogs;
78 using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
79 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
80 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
81 using namespace ::com::sun::star::lang;
82 using namespace ::com::sun::star::beans;
83 using namespace ::com::sun::star::uno;
84 
85 //////////////////////////////////////////////////////////////////////////
86 // helper functions
87 //////////////////////////////////////////////////////////////////////////
88 
89 #include <QDebug>
90 
91 namespace
92 {
93     // controling event notifications
94     const bool STARTUP_SUSPENDED = true;
95     const bool STARTUP_ALIVE     = false;
96 
97     uno::Sequence<rtl::OUString> SAL_CALL FilePicker_getSupportedServiceNames()
98     {
99         uno::Sequence<rtl::OUString> aRet(3);
100         aRet[0] = rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.FilePicker");
101         aRet[1] = rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.SystemFilePicker");
102         aRet[2] = rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.KDE4FilePicker");
103         return aRet;
104     }
105 }
106 
107 rtl::OUString toOUString(const QString& s)
108 {
109     // QString stores UTF16, just like OUString
110     return rtl::OUString(reinterpret_cast<const sal_Unicode*>(s.data()), s.length());
111 }
112 
113 QString toQString(const rtl::OUString& s)
114 {
115     return QString::fromUtf16(s.getStr(), s.getLength());
116 }
117 
118 //////////////////////////////////////////////////////////////////////////
119 // KDE4FilePicker
120 //////////////////////////////////////////////////////////////////////////
121 
122 KDE4FilePicker::KDE4FilePicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr )
123     : cppu::WeakComponentImplHelper8<
124           XFilterManager,
125           XFilterGroupManager,
126           XFilePickerControlAccess,
127           XFilePickerNotifier,
128 // TODO   XFilePreview,
129           lang::XInitialization,
130           util::XCancellable,
131           lang::XEventListener,
132           lang::XServiceInfo>( _helperMutex ),
133           m_xServiceMgr( xServiceMgr ),
134           _resMgr( CREATEVERSIONRESMGR( fps_office ) )
135 {
136     _extraControls = new QWidget();
137     _layout = new QGridLayout(_extraControls);
138 
139     _dialog = new KFileDialog(KUrl("~"), QString(""), 0, _extraControls);
140     _dialog->setMode(KFile::File | KFile::LocalOnly);
141 
142     //default mode
143     _dialog->setOperationMode(KFileDialog::Opening);
144 }
145 
146 KDE4FilePicker::~KDE4FilePicker()
147 {
148     delete _resMgr;
149     delete _dialog;
150 }
151 
152 void SAL_CALL KDE4FilePicker::addFilePickerListener( const uno::Reference<XFilePickerListener>& xListener )
153     throw( uno::RuntimeException )
154 {
155     ::vos::OGuard aGuard( Application::GetSolarMutex() );
156     m_xListener = xListener;
157 }
158 
159 void SAL_CALL KDE4FilePicker::removeFilePickerListener( const uno::Reference<XFilePickerListener>& )
160     throw( uno::RuntimeException )
161 {
162     ::vos::OGuard aGuard( Application::GetSolarMutex() );
163     m_xListener.clear();
164 }
165 
166 void SAL_CALL KDE4FilePicker::setTitle( const rtl::OUString &title )
167     throw( uno::RuntimeException )
168 {
169     _dialog->setCaption(toQString(title));
170 }
171 
172 sal_Int16 SAL_CALL KDE4FilePicker::execute()
173     throw( uno::RuntimeException )
174 {
175     //get the window id of the main OO window to set it for the dialog as a parent
176     Window *pParentWin = Application::GetDefDialogParent();
177     if ( pParentWin )
178     {
179         const SystemEnvData* pSysData = ((SystemWindow *)pParentWin)->GetSystemData();
180         if ( pSysData )
181         {
182             KWindowSystem::setMainWindow( _dialog, pSysData->aWindow); // unx only
183         }
184     }
185 
186     _dialog->clearFilter();
187     _dialog->setFilter(_filter);
188     _dialog->filterWidget()->setEditable(false);
189 
190     //block and wait for user input
191     if (_dialog->exec() == KFileDialog::Accepted)
192         return ExecutableDialogResults::OK;
193 
194     return ExecutableDialogResults::CANCEL;
195 }
196 
197 void SAL_CALL KDE4FilePicker::setMultiSelectionMode( sal_Bool multiSelect )
198     throw( uno::RuntimeException )
199 {
200     if (multiSelect)
201         _dialog->setMode(KFile::Files | KFile::LocalOnly);
202     else
203         _dialog->setMode(KFile::File | KFile::LocalOnly);
204 }
205 
206 void SAL_CALL KDE4FilePicker::setDefaultName( const ::rtl::OUString &name )
207     throw( uno::RuntimeException )
208 {
209     const QString url = toQString(name);
210     _dialog->setSelection(url);
211 }
212 
213 void SAL_CALL KDE4FilePicker::setDisplayDirectory( const rtl::OUString &dir )
214     throw( uno::RuntimeException )
215 {
216     const QString url = toQString(dir);
217     _dialog->setUrl(KUrl(url));
218 }
219 
220 rtl::OUString SAL_CALL KDE4FilePicker::getDisplayDirectory()
221     throw( uno::RuntimeException )
222 {
223     QString dir = _dialog->baseUrl().url();
224     return toOUString(dir);
225 }
226 
227 uno::Sequence< ::rtl::OUString > SAL_CALL KDE4FilePicker::getFiles()
228     throw( uno::RuntimeException )
229 {
230     QStringList rawFiles = _dialog->selectedFiles();
231     QStringList files;
232 
233     // check if we need to add an extension
234     QString extension = "";
235     if ( _dialog->operationMode() == KFileDialog::Saving )
236     {
237         QCheckBox *cb = dynamic_cast<QCheckBox*> (
238             _customWidgets[ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION ]);
239 
240         if (cb && cb->isChecked())
241         {
242             extension = _dialog->currentFilter(); // assuming filter value is like this *.ext
243             extension.replace("*","");
244         }
245     }
246 
247     // Workaround for the double click selection KDE4 bug
248     // kde file picker returns the file and directories for selectedFiles()
249     // when a file is double clicked
250     // make a true list of files
251     const QString dir = KUrl(rawFiles[0]).directory();
252 
253     bool singleFile = true;
254     if (rawFiles.size() > 1)
255     {
256         singleFile = false;
257         //for multi file sequences, oo expects the first param to be the directory
258         //can't treat all cases like multi file because in some instances (inserting image)
259         //oo WANTS only one entry in the final list
260         files.append(dir);
261     }
262 
263     for (sal_uInt16 i = 0; i < rawFiles.size(); ++i)
264     {
265         // if the raw file is not the base directory (see above kde bug)
266         // we add the file to list of avail files
267         if ((dir + "/") != ( rawFiles[i]))
268         {
269             QString filename = KUrl(rawFiles[i]).fileName();
270 
271             if (singleFile)
272                 filename.prepend(dir + "/");
273 
274             //prevent extension append if we already have one
275             if (filename.endsWith(extension))
276                 files.append(filename);
277             else
278                 files.append(filename + extension);
279         }
280     }
281 
282     // add all files and leading directory to outgoing OO sequence
283     uno::Sequence< ::rtl::OUString > seq(files.size());
284     for (int i = 0; i < files.size(); ++i)
285     {
286         rtl::OUString aFile(toOUString(files[i])), aURL;
287         osl_getFileURLFromSystemPath(aFile.pData, &aURL.pData );
288         seq[i] = aURL;
289     }
290 
291     return seq;
292 }
293 
294 void SAL_CALL KDE4FilePicker::appendFilter( const ::rtl::OUString &title, const ::rtl::OUString &filter )
295     throw( lang::IllegalArgumentException, uno::RuntimeException )
296 {
297     QString t = toQString(title);
298     QString f = toQString(filter);
299 
300     if (!_filter.isNull())
301         _filter.append("\n");
302 
303     //add to hash map for reverse lookup in getCurrentFilter
304     _filters.insert(f, t);
305 
306     // '/' meed to be escaped to else they are assumed to be mime types by kfiledialog
307     //see the docs
308     t.replace("/", "\\/");
309 
310     // openoffice gives us filters separated by ';' qt dialogs just want space separated
311     f.replace(";", " ");
312 
313     _filter.append(QString("%1|%2").arg(f).arg(t));
314 }
315 
316 void SAL_CALL KDE4FilePicker::setCurrentFilter( const rtl::OUString &title )
317     throw( lang::IllegalArgumentException, uno::RuntimeException )
318 {
319     QString t = toQString(title);
320     t.replace("/", "\\/");
321     _dialog->filterWidget()->setCurrentFilter(t);
322 }
323 
324 rtl::OUString SAL_CALL KDE4FilePicker::getCurrentFilter()
325     throw( uno::RuntimeException )
326 {
327     QString filter = _filters[_dialog->currentFilter()];
328 
329     //default if not found
330     if (filter.isNull())
331         filter = "ODF Text Document (.odt)";
332 
333     return toOUString(filter);
334 }
335 
336 void SAL_CALL KDE4FilePicker::appendFilterGroup( const rtl::OUString& , const uno::Sequence<beans::StringPair>& filters)
337     throw( lang::IllegalArgumentException, uno::RuntimeException )
338 {
339     if (!_filter.isNull())
340         _filter.append(QString("\n"));
341 
342     const sal_uInt16 length = filters.getLength();
343     for (sal_uInt16 i = 0; i < length; ++i)
344     {
345         beans::StringPair aPair = filters[i];
346 
347         _filter.append(QString("%1|%2").arg(
348             toQString(aPair.Second).replace(";", " ")).arg(
349             toQString(aPair.First).replace("/","\\/")));
350 
351         if (i != length - 1)
352             _filter.append('\n');
353     }
354 }
355 
356 void SAL_CALL KDE4FilePicker::setValue( sal_Int16 controlId, sal_Int16, const uno::Any &value )
357     throw( uno::RuntimeException )
358 {
359     QWidget* widget = _customWidgets[controlId];
360 
361     if (widget)
362     {
363         switch (controlId)
364         {
365             case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
366             case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
367             case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
368             case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
369             case ExtendedFilePickerElementIds::CHECKBOX_LINK:
370             case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
371             case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
372             {
373                 QCheckBox* cb = dynamic_cast<QCheckBox*>(widget);
374                 cb->setChecked(value.getValue());
375                 break;
376             }
377             case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
378             case ExtendedFilePickerElementIds::LISTBOX_VERSION:
379             case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
380             case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
381             case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
382             case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
383             case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
384             case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
385                 break;
386         }
387     }
388 }
389 
390 uno::Any SAL_CALL KDE4FilePicker::getValue( sal_Int16 controlId, sal_Int16 )
391     throw( uno::RuntimeException )
392 {
393     uno::Any res(false);
394 
395     QWidget* widget = _customWidgets[controlId];
396 
397     if (widget)
398     {
399         switch (controlId)
400         {
401             case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
402             case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
403             case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
404             case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
405             case ExtendedFilePickerElementIds::CHECKBOX_LINK:
406             case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
407             case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
408             {
409                 QCheckBox* cb = dynamic_cast<QCheckBox*>(widget);
410                 res = uno::Any(cb->isChecked());
411                 break;
412             }
413             case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
414             case ExtendedFilePickerElementIds::LISTBOX_VERSION:
415             case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
416             case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
417             case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
418             case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
419             case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
420             case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
421                 break;
422         }
423     }
424 
425     return res;
426 }
427 
428 void SAL_CALL KDE4FilePicker::enableControl( sal_Int16 controlId, sal_Bool enable )
429     throw( uno::RuntimeException )
430 {
431     QWidget* widget = _customWidgets[controlId];
432 
433     if (widget)
434     {
435         widget->setEnabled(enable);
436     }
437 }
438 
439 void SAL_CALL KDE4FilePicker::setLabel( sal_Int16 controlId, const ::rtl::OUString &label )
440     throw( uno::RuntimeException )
441 {
442     QWidget* widget = _customWidgets[controlId];
443 
444     if (widget)
445     {
446         switch (controlId)
447         {
448             case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
449             case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
450             case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
451             case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
452             case ExtendedFilePickerElementIds::CHECKBOX_LINK:
453             case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
454             case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
455             {
456                 QCheckBox* cb = dynamic_cast<QCheckBox*>(widget);
457                 cb->setText(toQString(label));
458                 break;
459             }
460             case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
461             case ExtendedFilePickerElementIds::LISTBOX_VERSION:
462             case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
463             case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
464             case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
465             case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
466             case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
467             case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
468                 break;
469         }
470     }
471 }
472 
473 rtl::OUString SAL_CALL KDE4FilePicker::getLabel(sal_Int16 controlId)
474     throw ( uno::RuntimeException )
475 {
476     QWidget* widget = _customWidgets[controlId];
477     QString label;
478 
479     if (widget)
480     {
481         switch (controlId)
482         {
483             case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
484             case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
485             case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
486             case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
487             case ExtendedFilePickerElementIds::CHECKBOX_LINK:
488             case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
489             case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
490             {
491                 QCheckBox* cb = dynamic_cast<QCheckBox*>(widget);
492                 label = cb->text();
493                 break;
494             }
495             case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
496             case ExtendedFilePickerElementIds::LISTBOX_VERSION:
497             case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
498             case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
499             case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
500             case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
501             case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
502             case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
503                 break;
504         }
505     }
506     return toOUString(label);
507 }
508 
509 void KDE4FilePicker::addCustomControl(sal_Int16 controlId)
510 {
511     QWidget* widget = 0;
512     sal_Int32 resId = -1;
513 
514     switch (controlId)
515     {
516         case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
517             resId = STR_SVT_FILEPICKER_AUTO_EXTENSION;
518             break;
519         case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
520             resId = STR_SVT_FILEPICKER_PASSWORD;
521             break;
522         case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
523             resId = STR_SVT_FILEPICKER_FILTER_OPTIONS;
524             break;
525         case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
526             resId = STR_SVT_FILEPICKER_READONLY;
527             break;
528         case ExtendedFilePickerElementIds::CHECKBOX_LINK:
529             resId = STR_SVT_FILEPICKER_INSERT_AS_LINK;
530             break;
531         case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
532             resId = STR_SVT_FILEPICKER_SHOW_PREVIEW;
533             break;
534         case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
535             resId = STR_SVT_FILEPICKER_SELECTION;
536             break;
537         case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
538             resId = STR_SVT_FILEPICKER_PLAY;
539             break;
540         case ExtendedFilePickerElementIds::LISTBOX_VERSION:
541             resId = STR_SVT_FILEPICKER_VERSION;
542             break;
543         case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
544             resId = STR_SVT_FILEPICKER_TEMPLATES;
545             break;
546         case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
547             resId = STR_SVT_FILEPICKER_IMAGE_TEMPLATE;
548             break;
549         case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
550         case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
551         case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
552         case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
553             break;
554     }
555 
556     switch (controlId)
557     {
558         case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
559         case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
560         case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
561         case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
562         case ExtendedFilePickerElementIds::CHECKBOX_LINK:
563         case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
564         case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
565         {
566             QString label;
567 
568             if (_resMgr && resId != -1)
569             {
570                 rtl::OUString s = String(ResId( resId, *_resMgr ));
571                 label = toQString(s);
572                 label.replace("~", "&");
573             }
574 
575             widget = new QCheckBox(label, _extraControls);
576 
577             break;
578         }
579         case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
580         case ExtendedFilePickerElementIds::LISTBOX_VERSION:
581         case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
582         case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
583         case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
584         case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
585         case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
586         case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
587             break;
588     }
589 
590     if (widget)
591     {
592         _layout->addWidget(widget);
593         _customWidgets.insert(controlId, widget);
594     }
595 }
596 
597 void SAL_CALL KDE4FilePicker::initialize( const uno::Sequence<uno::Any> &args )
598     throw( uno::Exception, uno::RuntimeException )
599 {
600     _filter.clear();
601     _filters.clear();
602 
603     // parameter checking
604     uno::Any arg;
605     if (args.getLength() == 0)
606     {
607         throw lang::IllegalArgumentException(
608                 rtl::OUString::createFromAscii( "no arguments" ),
609                 static_cast< XFilePicker* >( this ), 1 );
610     }
611 
612     arg = args[0];
613 
614     if (( arg.getValueType() != ::getCppuType((sal_Int16*)0)) &&
615         ( arg.getValueType() != ::getCppuType((sal_Int8*)0)))
616     {
617         throw lang::IllegalArgumentException(
618                 rtl::OUString::createFromAscii( "invalid argument type" ),
619                 static_cast< XFilePicker* >( this ), 1 );
620     }
621 
622     sal_Int16 templateId = -1;
623     arg >>= templateId;
624 
625     //default is opening
626     KFileDialog::OperationMode operationMode = KFileDialog::Opening;
627 
628     switch ( templateId )
629     {
630         case FILEOPEN_SIMPLE:
631             break;
632 
633         case FILESAVE_SIMPLE:
634             operationMode = KFileDialog::Saving;
635             break;
636 
637         case FILESAVE_AUTOEXTENSION:
638             operationMode = KFileDialog::Saving;
639             //addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION );
640             break;
641 
642         case FILESAVE_AUTOEXTENSION_PASSWORD:
643         {
644             operationMode = KFileDialog::Saving;
645             //addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION );
646             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD );
647             break;
648         }
649         case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
650         {
651             operationMode = KFileDialog::Saving;
652             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION );
653             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD );
654             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS );
655             break;
656         }
657         case FILESAVE_AUTOEXTENSION_SELECTION:
658             operationMode = KFileDialog::Saving;
659             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION );
660             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_SELECTION );
661             break;
662 
663         case FILESAVE_AUTOEXTENSION_TEMPLATE:
664             operationMode = KFileDialog::Saving;
665             addCustomControl( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE );
666             break;
667 
668         case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
669             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_LINK );
670             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW );
671             addCustomControl( ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE );
672             break;
673 
674         case FILEOPEN_PLAY:
675             addCustomControl( ExtendedFilePickerElementIds::PUSHBUTTON_PLAY );
676             break;
677 
678         case FILEOPEN_READONLY_VERSION:
679             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_READONLY );
680             addCustomControl( ExtendedFilePickerElementIds::LISTBOX_VERSION );
681             break;
682 
683         case FILEOPEN_LINK_PREVIEW:
684             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_LINK );
685             addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW );
686             break;
687 
688         default:
689             throw lang::IllegalArgumentException(
690                     rtl::OUString::createFromAscii( "Unknown template" ),
691                     static_cast< XFilePicker* >( this ),
692                     1 );
693     }
694 
695     _dialog->setOperationMode(operationMode);
696     _dialog->setConfirmOverwrite(true);
697 }
698 
699 void SAL_CALL KDE4FilePicker::cancel()
700     throw ( uno::RuntimeException )
701 {
702 
703 }
704 
705 void SAL_CALL KDE4FilePicker::disposing( const lang::EventObject &rEvent )
706     throw( uno::RuntimeException )
707 {
708     uno::Reference<XFilePickerListener> xFilePickerListener( rEvent.Source, uno::UNO_QUERY );
709 
710     if ( xFilePickerListener.is() )
711     {
712         removeFilePickerListener( xFilePickerListener );
713     }
714 }
715 
716 rtl::OUString SAL_CALL KDE4FilePicker::getImplementationName()
717     throw( uno::RuntimeException )
718 {
719     return rtl::OUString::createFromAscii( FILE_PICKER_IMPL_NAME );
720 }
721 
722 sal_Bool SAL_CALL KDE4FilePicker::supportsService( const rtl::OUString& ServiceName )
723     throw( uno::RuntimeException )
724 {
725     uno::Sequence< ::rtl::OUString > SupportedServicesNames = FilePicker_getSupportedServiceNames();
726 
727     for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
728     {
729         if ( SupportedServicesNames[n].compareTo( ServiceName ) == 0 )
730             return sal_True;
731     }
732 
733     return sal_False;
734 }
735 
736 uno::Sequence< ::rtl::OUString > SAL_CALL KDE4FilePicker::getSupportedServiceNames()
737     throw( uno::RuntimeException )
738 {
739     return FilePicker_getSupportedServiceNames();
740 }
741