Update ooo320-m1
[ooovba.git] / applied_patches / 0357-kde4_fpicker_fixes.diff
blob456796cb354fc0549af9bd9b2a15118f2db079a9
1 diff --git fpicker/source/unx/kde4/KDE4FPEntry.cxx fpicker/source/unx/kde4/KDE4FPEntry.cxx
2 index 9a75688..805e6cf 100644
3 --- fpicker/source/unx/kde4/KDE4FPEntry.cxx
4 +++ fpicker/source/unx/kde4/KDE4FPEntry.cxx
5 @@ -84,12 +84,12 @@ static Reference< XInterface > SAL_CALL createInstance( const Reference< XMultiS
6 // the three uno functions that will be exported
7 extern "C"
9 - void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
10 + void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** )
12 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
15 - sal_Bool SAL_CALL component_writeInfo( void* pServiceManager, void* pRegistryKey )
16 + sal_Bool SAL_CALL component_writeInfo( void*, void* pRegistryKey )
18 sal_Bool bRetVal = sal_True;
20 @@ -110,7 +110,7 @@ extern "C"
21 return bRetVal;
24 - void* SAL_CALL component_getFactory( const sal_Char* pImplName, uno_Interface* pSrvManager, uno_Interface* pRegistryKey )
25 + void* SAL_CALL component_getFactory( const sal_Char* pImplName, uno_Interface* pSrvManager, uno_Interface* )
27 void* pRet = 0;
29 diff --git fpicker/source/unx/kde4/KDE4FilePicker.cxx fpicker/source/unx/kde4/KDE4FilePicker.cxx
30 index b5cd83d..6c6db9e 100644
31 --- fpicker/source/unx/kde4/KDE4FilePicker.cxx
32 +++ fpicker/source/unx/kde4/KDE4FilePicker.cxx
33 @@ -118,6 +118,8 @@ using namespace ::com::sun::star::uno;
34 // helper functions
35 //////////////////////////////////////////////////////////////////////////
37 +#include <QDebug>
39 namespace
41 // controling event notifications
42 @@ -166,7 +168,7 @@ KDE4FilePicker::KDE4FilePicker( const uno::Reference<lang::XMultiServiceFactory>
44 _layout = new QGridLayout(_extraControls);
46 - _dialog = new KFileDialog(KUrl(""), QString(""), 0, _extraControls);
47 + _dialog = new KFileDialog(KUrl("~"), QString(""), 0, _extraControls);
48 _dialog->setMode(KFile::File | KFile::LocalOnly);
50 //default mode
51 @@ -213,21 +215,19 @@ sal_Int16 SAL_CALL KDE4FilePicker::execute()
55 + _dialog->clearFilter();
56 _dialog->setFilter(_filter);
58 _dialog->exec();
60 //nasty hack to get a local qt event loop going to process the dialog
61 //otherwise the dialog returns immediately
62 while (_dialog->isVisible())
63 - {
64 kapp->processEvents(QEventLoop::WaitForMoreEvents);
65 - }
67 //block and wait for user input
68 if (_dialog->result() == KFileDialog::Accepted)
69 - {
70 return ExecutableDialogResults::OK;
71 - }
73 return ExecutableDialogResults::CANCEL;
75 @@ -236,13 +236,9 @@ void SAL_CALL KDE4FilePicker::setMultiSelectionMode( sal_Bool multiSelect )
76 throw( uno::RuntimeException )
78 if (multiSelect)
79 - {
80 _dialog->setMode(KFile::Files | KFile::LocalOnly);
81 - }
82 else
83 - {
84 _dialog->setMode(KFile::File | KFile::LocalOnly);
85 - }
88 void SAL_CALL KDE4FilePicker::setDefaultName( const ::rtl::OUString &name )
89 @@ -256,7 +252,7 @@ void SAL_CALL KDE4FilePicker::setDisplayDirectory( const rtl::OUString &dir )
90 throw( uno::RuntimeException )
92 const QString url = toQString(dir);
93 - _dialog->setStartDir(KUrl(url));
94 + _dialog->setUrl(KUrl(url));
97 rtl::OUString SAL_CALL KDE4FilePicker::getDisplayDirectory()
98 @@ -269,16 +265,54 @@ rtl::OUString SAL_CALL KDE4FilePicker::getDisplayDirectory()
99 uno::Sequence< ::rtl::OUString > SAL_CALL KDE4FilePicker::getFiles()
100 throw( uno::RuntimeException )
102 - QStringList files = _dialog->selectedFiles();
103 + QStringList rawFiles = _dialog->selectedFiles();
104 + QStringList files;
106 - uno::Sequence< ::rtl::OUString > seq(files.size());
107 + // check if we need to add an extension
108 + QString extension = "";
109 + if ( _dialog->operationMode() == KFileDialog::Saving )
111 + QCheckBox *cb = dynamic_cast<QCheckBox*> (
112 + _customWidgets[ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION ]);
114 + if (cb->isChecked())
116 + extension = _dialog->currentFilter(); // assuming filter value is like this *.ext
117 + extension.replace("*","");
121 + // Workaround for the double click selection KDE4 bug
122 + // kde file picker returns the file and directories for selectedFiles()
123 + // when a file is double clicked
124 + // make a true list of files
125 + const QString dir = "file://" + KUrl(rawFiles[0]).directory();
127 - for (int i=0 ; i<files.size() ; ++i)
128 + // by appending the dir, we make OO treat all opens like multifile opens
129 + // this makes the code for adding the the OO sequence simpler
130 + files.append(dir);
132 + for (USHORT i = 0; i < rawFiles.size(); ++i)
134 - const QString fileName = "file:" + files[i];
135 - seq[i] = toOUString(fileName);
136 + // if the raw file is not the base directory (see above kde bug)
137 + // we add the file to list of avail files
138 + if ((dir + "/") != ("file://" + rawFiles[i]))
140 + const QString filename = KUrl(rawFiles[i]).fileName();
142 + //prevent extension append if we already have one
143 + if (filename.endsWith(extension))
144 + files.append(filename);
145 + else
146 + files.append(filename + extension);
150 + // add all files and leading directory to outgoing OO sequence
151 + uno::Sequence< ::rtl::OUString > seq(files.size());
152 + for (int i = 0; i < files.size(); ++i)
153 + seq[i] = toOUString(files[i]);
155 return seq;
158 @@ -289,9 +323,7 @@ void SAL_CALL KDE4FilePicker::appendFilter( const ::rtl::OUString &title, const
159 QString f = toQString(filter);
161 if (!_filter.isNull())
163 _filter.append("\n");
166 //add to hash map for reverse lookup in getCurrentFilter
167 _filters.insert(f, t);
168 @@ -318,17 +350,31 @@ rtl::OUString SAL_CALL KDE4FilePicker::getCurrentFilter()
170 //default if not found
171 if (filter.isNull())
173 filter = "ODF Text Document (.odt)";
176 return toOUString(filter);
179 -void SAL_CALL KDE4FilePicker::appendFilterGroup( const rtl::OUString&, const uno::Sequence<beans::StringPair>& )
180 +void SAL_CALL KDE4FilePicker::appendFilterGroup( const rtl::OUString&, const uno::Sequence<beans::StringPair>&)
181 throw( lang::IllegalArgumentException, uno::RuntimeException )
183 - //TODO
185 + //TODO ... don't really like this behavior... Shtylman
186 +#if 0
187 + if (!_filter.isNull())
188 + _filter.append(QString("\n"));
190 + for (USHORT i = 0; i < filters.getLength(); ++i)
192 + beans::StringPair aPair = filters[i];
194 + _filter.append(QString("%1|%2").arg(
195 + toQString(aPair.Second).replace(";", " ")).arg(
196 + toQString(aPair.First).replace("/","\\/") + "\n" ));
199 + if (filters.getLength() > 0)
200 + _filter.append(QString("*.*|*.*"));
201 +#endif
204 void SAL_CALL KDE4FilePicker::setValue( sal_Int16 controlId, sal_Int16, const uno::Any &value )