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