Update ooo320-m1
[ooovba.git] / fpicker / source / unx / kde4 / KDE4FilePicker.cxx
blob6c8825b775939a2eb81d6913db11799c5688e55e
1 /*************************************************************************
2 * The Contents of this file are made available subject to the terms of
3 * either of the following licenses
5 * - GNU Lesser General Public License Version 2.1
6 * - Sun Industry Standards Source License Version 1.1
8 * Sun Microsystems Inc., October, 2000
10 * GNU Lesser General Public License Version 2.1
11 * =============================================
12 * Copyright 2000 by Sun Microsystems, Inc.
13 * 901 San Antonio Road, Palo Alto, CA 94303, USA
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License version 2.1, as published by the Free Software Foundation.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
30 * Sun Industry Standards Source License Version 1.1
31 * =================================================
32 * The contents of this file are subject to the Sun Industry Standards
33 * Source License Version 1.1 (the "License"); You may not use this file
34 * except in compliance with the License. You may obtain a copy of the
35 * License at http://www.openoffice.org/license.html.
37 * Software provided under this License is provided on an "AS IS" basis,
38 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
39 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
40 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
41 * See the License for the specific provisions governing your rights and
42 * obligations concerning the Software.
44 * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
46 * Copyright: 2000 by Sun Microsystems, Inc.
48 * All Rights Reserved.
50 * Contributor(s): Jan Holesovsky <kendy@openoffice.org>
53 ************************************************************************/
55 //////////////////////////////////////////////////////////////////////////
56 // includes
57 //////////////////////////////////////////////////////////////////////////
59 #include <com/sun/star/lang/DisposedException.hpp>
60 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
61 #include <cppuhelper/interfacecontainer.h>
62 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
63 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
64 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
65 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
66 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
68 #include <svtools/svtools.hrc>
70 #include <vos/mutex.hxx>
72 #include <vcl/svapp.hxx>
73 #include <vcl/sysdata.hxx>
74 #include <vcl/syswin.hxx>
76 #include "KDE4FilePicker.hxx"
77 #include "FPServiceInfo.hxx"
79 /* ********* Hack, but needed because of conflicting types... */
80 #define Region QtXRegion
82 //kde has an enum that uses this...OO does too
83 #undef SETTINGS_MOUSE
85 #include <kfiledialog.h>
86 #include <kwindowsystem.h>
87 #include <kapplication.h>
88 #include <kfilefiltercombo.h>
90 #include <QWidget>
91 #include <QCheckBox>
92 #include <QGridLayout>
94 #undef Region
96 using namespace ::com::sun::star;
98 using namespace ::com::sun::star::ui::dialogs;
99 using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
101 using namespace ::com::sun::star;
102 using namespace ::com::sun::star::ui::dialogs;
103 using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
104 using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
105 using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
106 using namespace ::com::sun::star::lang;
107 using namespace ::com::sun::star::beans;
108 using namespace ::com::sun::star::uno;
110 //////////////////////////////////////////////////////////////////////////
111 // helper functions
112 //////////////////////////////////////////////////////////////////////////
114 #include <QDebug>
116 namespace
118 // controling event notifications
119 const bool STARTUP_SUSPENDED = true;
120 const bool STARTUP_ALIVE = false;
122 uno::Sequence<rtl::OUString> SAL_CALL FilePicker_getSupportedServiceNames()
124 uno::Sequence<rtl::OUString> aRet(3);
125 aRet[0] = rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.FilePicker");
126 aRet[1] = rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.SystemFilePicker");
127 aRet[2] = rtl::OUString::createFromAscii("com.sun.star.ui.dialogs.KDE4FilePicker");
128 return aRet;
132 rtl::OUString toOUString(const QString& s)
134 // QString stores UTF16, just like OUString
135 return rtl::OUString(reinterpret_cast<const sal_Unicode*>(s.data()), s.length());
138 QString toQString(const rtl::OUString& s)
140 return QString::fromUtf16(s.getStr(), s.getLength());
143 //////////////////////////////////////////////////////////////////////////
144 // KDE4FilePicker
145 //////////////////////////////////////////////////////////////////////////
147 KDE4FilePicker::KDE4FilePicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr )
148 : cppu::WeakComponentImplHelper8<
149 XFilterManager,
150 XFilterGroupManager,
151 XFilePickerControlAccess,
152 XFilePickerNotifier,
153 // TODO XFilePreview,
154 lang::XInitialization,
155 util::XCancellable,
156 lang::XEventListener,
157 lang::XServiceInfo>( _helperMutex ),
158 m_xServiceMgr( xServiceMgr ),
159 _resMgr( CREATEVERSIONRESMGR( fps_office ) )
161 _extraControls = new QWidget();
162 _layout = new QGridLayout(_extraControls);
164 _dialog = new KFileDialog(KUrl("~"), QString(""), 0, _extraControls);
165 _dialog->setMode(KFile::File | KFile::LocalOnly);
167 //default mode
168 _dialog->setOperationMode(KFileDialog::Opening);
170 _dialog->setStyleSheet("color: black;");
173 KDE4FilePicker::~KDE4FilePicker()
175 delete _resMgr;
176 delete _dialog;
179 void SAL_CALL KDE4FilePicker::addFilePickerListener( const uno::Reference<XFilePickerListener>& xListener )
180 throw( uno::RuntimeException )
182 ::vos::OGuard aGuard( Application::GetSolarMutex() );
183 m_xListener = xListener;
186 void SAL_CALL KDE4FilePicker::removeFilePickerListener( const uno::Reference<XFilePickerListener>& )
187 throw( uno::RuntimeException )
189 ::vos::OGuard aGuard( Application::GetSolarMutex() );
190 m_xListener.clear();
193 void SAL_CALL KDE4FilePicker::setTitle( const rtl::OUString &title )
194 throw( uno::RuntimeException )
196 _dialog->setCaption(toQString(title));
199 sal_Int16 SAL_CALL KDE4FilePicker::execute()
200 throw( uno::RuntimeException )
202 //get the window id of the main OO window to set it for the dialog as a parent
203 Window *pParentWin = Application::GetDefDialogParent();
204 if ( pParentWin )
206 const SystemEnvData* pSysData = ((SystemWindow *)pParentWin)->GetSystemData();
207 if ( pSysData )
209 KWindowSystem::setMainWindow( _dialog, pSysData->aWindow); // unx only
213 _dialog->clearFilter();
214 _dialog->setFilter(_filter);
216 //block and wait for user input
217 if (_dialog->exec() == KFileDialog::Accepted)
218 return ExecutableDialogResults::OK;
220 return ExecutableDialogResults::CANCEL;
223 void SAL_CALL KDE4FilePicker::setMultiSelectionMode( sal_Bool multiSelect )
224 throw( uno::RuntimeException )
226 if (multiSelect)
227 _dialog->setMode(KFile::Files | KFile::LocalOnly);
228 else
229 _dialog->setMode(KFile::File | KFile::LocalOnly);
232 void SAL_CALL KDE4FilePicker::setDefaultName( const ::rtl::OUString &name )
233 throw( uno::RuntimeException )
235 const QString url = toQString(name);
236 _dialog->setSelection(url);
239 void SAL_CALL KDE4FilePicker::setDisplayDirectory( const rtl::OUString &dir )
240 throw( uno::RuntimeException )
242 const QString url = toQString(dir);
243 _dialog->setUrl(KUrl(url));
246 rtl::OUString SAL_CALL KDE4FilePicker::getDisplayDirectory()
247 throw( uno::RuntimeException )
249 QString dir = _dialog->baseUrl().url();
250 return toOUString(dir);
253 uno::Sequence< ::rtl::OUString > SAL_CALL KDE4FilePicker::getFiles()
254 throw( uno::RuntimeException )
256 QStringList rawFiles = _dialog->selectedFiles();
257 QStringList files;
259 // check if we need to add an extension
260 QString extension = "";
261 if ( _dialog->operationMode() == KFileDialog::Saving )
263 QCheckBox *cb = dynamic_cast<QCheckBox*> (
264 _customWidgets[ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION ]);
266 if (cb->isChecked())
268 extension = _dialog->currentFilter(); // assuming filter value is like this *.ext
269 extension.replace("*","");
273 // Workaround for the double click selection KDE4 bug
274 // kde file picker returns the file and directories for selectedFiles()
275 // when a file is double clicked
276 // make a true list of files
277 const QString dir = "file://" + KUrl(rawFiles[0]).directory();
279 bool singleFile = true;
280 if (rawFiles.size() > 1)
282 singleFile = false;
283 //for multi file sequences, oo expects the first param to be the directory
284 //can't treat all cases like multi file because in some instances (inserting image)
285 //oo WANTS only one entry in the final list
286 files.append(dir);
289 for (USHORT i = 0; i < rawFiles.size(); ++i)
291 // if the raw file is not the base directory (see above kde bug)
292 // we add the file to list of avail files
293 if ((dir + "/") != ("file://" + rawFiles[i]))
295 QString filename = KUrl(rawFiles[i]).fileName();
297 if (singleFile)
298 filename.prepend(dir + "/");
300 //prevent extension append if we already have one
301 if (filename.endsWith(extension))
302 files.append(filename);
303 else
304 files.append(filename + extension);
308 // add all files and leading directory to outgoing OO sequence
309 uno::Sequence< ::rtl::OUString > seq(files.size());
310 for (int i = 0; i < files.size(); ++i)
311 seq[i] = toOUString(files[i]);
313 return seq;
316 void SAL_CALL KDE4FilePicker::appendFilter( const ::rtl::OUString &title, const ::rtl::OUString &filter )
317 throw( lang::IllegalArgumentException, uno::RuntimeException )
319 QString t = toQString(title);
320 QString f = toQString(filter);
322 if (!_filter.isNull())
323 _filter.append("\n");
325 //add to hash map for reverse lookup in getCurrentFilter
326 _filters.insert(f, t);
328 // '/' meed to be escaped to else they are assumed to be mime types by kfiledialog
329 //see the docs
330 t.replace("/", "\\/");
332 // openoffice gives us filters separated by ';' qt dialogs just want space separated
333 f.replace(";", " ");
335 _filter.append(QString("%1|%2").arg(f).arg(t));
338 void SAL_CALL KDE4FilePicker::setCurrentFilter( const rtl::OUString &title )
339 throw( lang::IllegalArgumentException, uno::RuntimeException )
341 QString t = toQString(title);
342 t.replace("/", "\\/");
343 _dialog->filterWidget()->setCurrentFilter(t);
346 rtl::OUString SAL_CALL KDE4FilePicker::getCurrentFilter()
347 throw( uno::RuntimeException )
349 QString filter = _filters[_dialog->currentFilter()];
351 //default if not found
352 if (filter.isNull())
353 filter = "ODF Text Document (.odt)";
355 return toOUString(filter);
358 void SAL_CALL KDE4FilePicker::appendFilterGroup( const rtl::OUString& , const uno::Sequence<beans::StringPair>& filters)
359 throw( lang::IllegalArgumentException, uno::RuntimeException )
361 if (!_filter.isNull())
362 _filter.append(QString("\n"));
364 const USHORT length = filters.getLength();
365 for (USHORT i = 0; i < length; ++i)
367 beans::StringPair aPair = filters[i];
369 _filter.append(QString("%1|%2").arg(
370 toQString(aPair.Second).replace(";", " ")).arg(
371 toQString(aPair.First).replace("/","\\/")));
373 if (i != length - 1)
374 _filter.append('\n');
378 void SAL_CALL KDE4FilePicker::setValue( sal_Int16 controlId, sal_Int16, const uno::Any &value )
379 throw( uno::RuntimeException )
381 QWidget* widget = _customWidgets[controlId];
383 if (widget)
385 switch (controlId)
387 case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
388 case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
389 case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
390 case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
391 case ExtendedFilePickerElementIds::CHECKBOX_LINK:
392 case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
393 case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
395 QCheckBox* cb = dynamic_cast<QCheckBox*>(widget);
396 cb->setChecked(value.getValue());
397 break;
399 case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
400 case ExtendedFilePickerElementIds::LISTBOX_VERSION:
401 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
402 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
403 case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
404 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
405 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
406 case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
407 break;
412 uno::Any SAL_CALL KDE4FilePicker::getValue( sal_Int16 controlId, sal_Int16 )
413 throw( uno::RuntimeException )
415 uno::Any res(false);
417 QWidget* widget = _customWidgets[controlId];
419 if (widget)
421 switch (controlId)
423 case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
424 case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
425 case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
426 case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
427 case ExtendedFilePickerElementIds::CHECKBOX_LINK:
428 case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
429 case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
431 QCheckBox* cb = dynamic_cast<QCheckBox*>(widget);
432 res = uno::Any(cb->isChecked());
433 break;
435 case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
436 case ExtendedFilePickerElementIds::LISTBOX_VERSION:
437 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
438 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
439 case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
440 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
441 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
442 case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
443 break;
447 return res;
450 void SAL_CALL KDE4FilePicker::enableControl( sal_Int16 controlId, sal_Bool enable )
451 throw( uno::RuntimeException )
453 QWidget* widget = _customWidgets[controlId];
455 if (widget)
457 widget->setEnabled(enable);
461 void SAL_CALL KDE4FilePicker::setLabel( sal_Int16 controlId, const ::rtl::OUString &label )
462 throw( uno::RuntimeException )
464 QWidget* widget = _customWidgets[controlId];
466 if (widget)
468 switch (controlId)
470 case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
471 case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
472 case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
473 case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
474 case ExtendedFilePickerElementIds::CHECKBOX_LINK:
475 case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
476 case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
478 QCheckBox* cb = dynamic_cast<QCheckBox*>(widget);
479 cb->setText(toQString(label));
480 break;
482 case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
483 case ExtendedFilePickerElementIds::LISTBOX_VERSION:
484 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
485 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
486 case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
487 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
488 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
489 case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
490 break;
495 rtl::OUString SAL_CALL KDE4FilePicker::getLabel(sal_Int16 controlId)
496 throw ( uno::RuntimeException )
498 QWidget* widget = _customWidgets[controlId];
499 QString label;
501 if (widget)
503 switch (controlId)
505 case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
506 case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
507 case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
508 case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
509 case ExtendedFilePickerElementIds::CHECKBOX_LINK:
510 case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
511 case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
513 QCheckBox* cb = dynamic_cast<QCheckBox*>(widget);
514 label = cb->text();
515 break;
517 case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
518 case ExtendedFilePickerElementIds::LISTBOX_VERSION:
519 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
520 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
521 case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
522 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
523 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
524 case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
525 break;
528 return toOUString(label);
531 void KDE4FilePicker::addCustomControl(sal_Int16 controlId)
533 QWidget* widget = 0;
534 sal_Int32 resId = -1;
536 switch (controlId)
538 case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
539 resId = STR_SVT_FILEPICKER_AUTO_EXTENSION;
540 break;
541 case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
542 resId = STR_SVT_FILEPICKER_PASSWORD;
543 break;
544 case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
545 resId = STR_SVT_FILEPICKER_FILTER_OPTIONS;
546 break;
547 case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
548 resId = STR_SVT_FILEPICKER_READONLY;
549 break;
550 case ExtendedFilePickerElementIds::CHECKBOX_LINK:
551 resId = STR_SVT_FILEPICKER_INSERT_AS_LINK;
552 break;
553 case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
554 resId = STR_SVT_FILEPICKER_SHOW_PREVIEW;
555 break;
556 case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
557 resId = STR_SVT_FILEPICKER_SELECTION;
558 break;
559 case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
560 resId = STR_SVT_FILEPICKER_PLAY;
561 break;
562 case ExtendedFilePickerElementIds::LISTBOX_VERSION:
563 resId = STR_SVT_FILEPICKER_VERSION;
564 break;
565 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
566 resId = STR_SVT_FILEPICKER_TEMPLATES;
567 break;
568 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
569 resId = STR_SVT_FILEPICKER_IMAGE_TEMPLATE;
570 break;
571 case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
572 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
573 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
574 case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
575 break;
578 switch (controlId)
580 case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION:
581 case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD:
582 case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS:
583 case ExtendedFilePickerElementIds::CHECKBOX_READONLY:
584 case ExtendedFilePickerElementIds::CHECKBOX_LINK:
585 case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
586 case ExtendedFilePickerElementIds::CHECKBOX_SELECTION:
588 QString label;
590 if (_resMgr && resId != -1)
592 rtl::OUString s = String(ResId( resId, *_resMgr ));
593 label = toQString(s);
594 label.replace("~", "&");
597 widget = new QCheckBox(label, _extraControls);
599 break;
601 case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY:
602 case ExtendedFilePickerElementIds::LISTBOX_VERSION:
603 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE:
604 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE:
605 case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL:
606 case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL:
607 case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL:
608 case ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR:
609 break;
612 if (widget)
614 _layout->addWidget(widget);
615 _customWidgets.insert(controlId, widget);
619 void SAL_CALL KDE4FilePicker::initialize( const uno::Sequence<uno::Any> &args )
620 throw( uno::Exception, uno::RuntimeException )
622 _filter.clear();
623 _filters.clear();
625 // parameter checking
626 uno::Any arg;
627 if (args.getLength() == 0)
629 throw lang::IllegalArgumentException(
630 rtl::OUString::createFromAscii( "no arguments" ),
631 static_cast< XFilePicker* >( this ), 1 );
634 arg = args[0];
636 if (( arg.getValueType() != ::getCppuType((sal_Int16*)0)) &&
637 ( arg.getValueType() != ::getCppuType((sal_Int8*)0)))
639 throw lang::IllegalArgumentException(
640 rtl::OUString::createFromAscii( "invalid argument type" ),
641 static_cast< XFilePicker* >( this ), 1 );
644 sal_Int16 templateId = -1;
645 arg >>= templateId;
647 //default is opening
648 KFileDialog::OperationMode operationMode = KFileDialog::Opening;
650 switch ( templateId )
652 case FILEOPEN_SIMPLE:
653 break;
655 case FILESAVE_SIMPLE:
656 operationMode = KFileDialog::Saving;
657 break;
659 case FILESAVE_AUTOEXTENSION:
660 operationMode = KFileDialog::Saving;
661 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION );
662 break;
664 case FILESAVE_AUTOEXTENSION_PASSWORD:
666 operationMode = KFileDialog::Saving;
667 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION );
668 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD );
669 break;
671 case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
673 operationMode = KFileDialog::Saving;
674 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION );
675 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD );
676 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS );
677 break;
679 case FILESAVE_AUTOEXTENSION_SELECTION:
680 operationMode = KFileDialog::Saving;
681 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION );
682 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_SELECTION );
683 break;
685 case FILESAVE_AUTOEXTENSION_TEMPLATE:
686 operationMode = KFileDialog::Saving;
687 addCustomControl( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE );
688 break;
690 case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
691 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_LINK );
692 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW );
693 addCustomControl( ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE );
694 break;
696 case FILEOPEN_PLAY:
697 addCustomControl( ExtendedFilePickerElementIds::PUSHBUTTON_PLAY );
698 break;
700 case FILEOPEN_READONLY_VERSION:
701 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_READONLY );
702 addCustomControl( ExtendedFilePickerElementIds::LISTBOX_VERSION );
703 break;
705 case FILEOPEN_LINK_PREVIEW:
706 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_LINK );
707 addCustomControl( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW );
708 break;
710 default:
711 throw lang::IllegalArgumentException(
712 rtl::OUString::createFromAscii( "Unknown template" ),
713 static_cast< XFilePicker* >( this ),
714 1 );
717 _dialog->setOperationMode(operationMode);
720 void SAL_CALL KDE4FilePicker::cancel()
721 throw ( uno::RuntimeException )
726 void SAL_CALL KDE4FilePicker::disposing( const lang::EventObject &rEvent )
727 throw( uno::RuntimeException )
729 uno::Reference<XFilePickerListener> xFilePickerListener( rEvent.Source, uno::UNO_QUERY );
731 if ( xFilePickerListener.is() )
733 removeFilePickerListener( xFilePickerListener );
737 rtl::OUString SAL_CALL KDE4FilePicker::getImplementationName()
738 throw( uno::RuntimeException )
740 return rtl::OUString::createFromAscii( FILE_PICKER_IMPL_NAME );
743 sal_Bool SAL_CALL KDE4FilePicker::supportsService( const rtl::OUString& ServiceName )
744 throw( uno::RuntimeException )
746 uno::Sequence< ::rtl::OUString > SupportedServicesNames = FilePicker_getSupportedServiceNames();
748 for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
750 if ( SupportedServicesNames[n].compareTo( ServiceName ) == 0 )
751 return sal_True;
754 return sal_False;
757 uno::Sequence< ::rtl::OUString > SAL_CALL KDE4FilePicker::getSupportedServiceNames()
758 throw( uno::RuntimeException )
760 return FilePicker_getSupportedServiceNames();