-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp index f3e7501..a30bd8b 100644 --- a/libopie2/opieui/fileselector/ofileselector.cpp +++ b/libopie2/opieui/fileselector/ofileselector.cpp | |||
@@ -1,1251 +1,1252 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> | 4 | Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* hacky but we need to get FileSelector::filter */ | 31 | /* hacky but we need to get FileSelector::filter */ |
32 | #define private public | 32 | #define private public |
33 | #include <qpe/fileselector.h> | 33 | #include <qpe/fileselector.h> |
34 | #undef private | 34 | #undef private |
35 | 35 | ||
36 | #include "ofileselector_p.h" | 36 | #include "ofileselector_p.h" |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | #include <opie2/odebug.h> | 39 | #include <opie2/odebug.h> |
40 | #include <opie2/ofileselector.h> | 40 | #include <opie2/ofileselector.h> |
41 | #include <opie2/oresource.h> | 41 | #include <opie2/oresource.h> |
42 | 42 | ||
43 | #include <qpe/qpeapplication.h> | 43 | #include <qpe/qpeapplication.h> |
44 | #include <qpe/mimetype.h> | 44 | #include <qpe/mimetype.h> |
45 | #include <qpe/storage.h> | 45 | #include <qpe/storage.h> |
46 | 46 | ||
47 | /* QT */ | 47 | /* QT */ |
48 | #include <qcombobox.h> | 48 | #include <qcombobox.h> |
49 | #include <qdir.h> | 49 | #include <qdir.h> |
50 | #include <qhbox.h> | 50 | #include <qhbox.h> |
51 | #include <qheader.h> | 51 | #include <qheader.h> |
52 | #include <qlabel.h> | 52 | #include <qlabel.h> |
53 | #include <qlayout.h> | 53 | #include <qlayout.h> |
54 | #include <qlineedit.h> | 54 | #include <qlineedit.h> |
55 | #include <qlistview.h> | 55 | #include <qlistview.h> |
56 | #include <qpopupmenu.h> | 56 | #include <qpopupmenu.h> |
57 | #include <qwidgetstack.h> | 57 | #include <qwidgetstack.h> |
58 | #include <qregexp.h> | 58 | #include <qregexp.h> |
59 | #include <qobjectlist.h> | 59 | #include <qobjectlist.h> |
60 | 60 | ||
61 | using namespace Opie::Ui::Internal; | 61 | using namespace Opie::Ui::Internal; |
62 | 62 | ||
63 | namespace Opie { | 63 | namespace Opie { |
64 | namespace Ui { | 64 | namespace Ui { |
65 | namespace Internal { | 65 | namespace Internal { |
66 | /* | 66 | /* |
67 | * Create a path by adding a '/'/QDir::seperator in between | 67 | * Create a path by adding a '/'/QDir::seperator in between |
68 | * base and ending, but only if base is not empty | 68 | * base and ending, but only if base is not empty |
69 | */ | 69 | */ |
70 | static inline QString createNewPath(const QString& base, const QString &ending) { | 70 | static inline QString createNewPath(const QString& base, const QString &ending) { |
71 | return base == QString::fromLatin1("/") ? | 71 | return base == QString::fromLatin1("/") ? |
72 | base + ending : base + "/" + ending; | 72 | base + ending : base + "/" + ending; |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | OFileViewInterface::OFileViewInterface( OFileSelector* _selector ) | 76 | OFileViewInterface::OFileViewInterface( OFileSelector* _selector ) |
77 | : m_selector( _selector ) | 77 | : m_selector( _selector ) |
78 | { | 78 | { |
79 | selector()->registerView( this ); | 79 | selector()->registerView( this ); |
80 | } | 80 | } |
81 | 81 | ||
82 | OFileViewInterface::~OFileViewInterface() | 82 | OFileViewInterface::~OFileViewInterface() |
83 | {} | 83 | {} |
84 | 84 | ||
85 | QString OFileViewInterface::name()const | 85 | QString OFileViewInterface::name()const |
86 | { | 86 | { |
87 | return m_name; | 87 | return m_name; |
88 | } | 88 | } |
89 | 89 | ||
90 | void OFileViewInterface::setName( const QString& name ) | 90 | void OFileViewInterface::setName( const QString& name ) |
91 | { | 91 | { |
92 | m_name = name; | 92 | m_name = name; |
93 | } | 93 | } |
94 | 94 | ||
95 | OFileSelector* OFileViewInterface::selector()const | 95 | OFileSelector* OFileViewInterface::selector()const |
96 | { | 96 | { |
97 | return m_selector; | 97 | return m_selector; |
98 | } | 98 | } |
99 | 99 | ||
100 | DocLnk OFileViewInterface::selectedDocument()const | 100 | DocLnk OFileViewInterface::selectedDocument()const |
101 | { | 101 | { |
102 | return DocLnk( selectedName() ); | 102 | return DocLnk( selectedName() ); |
103 | } | 103 | } |
104 | 104 | ||
105 | bool OFileViewInterface::showNew()const | 105 | bool OFileViewInterface::showNew()const |
106 | { | 106 | { |
107 | return selector()->showNew(); | 107 | return selector()->showNew(); |
108 | } | 108 | } |
109 | 109 | ||
110 | bool OFileViewInterface::showClose()const | 110 | bool OFileViewInterface::showClose()const |
111 | { | 111 | { |
112 | return selector()->showClose(); | 112 | return selector()->showClose(); |
113 | } | 113 | } |
114 | 114 | ||
115 | MimeTypes OFileViewInterface::mimeTypes()const | 115 | MimeTypes OFileViewInterface::mimeTypes()const |
116 | { | 116 | { |
117 | return selector()->mimeTypes(); | 117 | return selector()->mimeTypes(); |
118 | } | 118 | } |
119 | 119 | ||
120 | QStringList OFileViewInterface::currentMimeType()const | 120 | QStringList OFileViewInterface::currentMimeType()const |
121 | { | 121 | { |
122 | return selector()->currentMimeType(); | 122 | return selector()->currentMimeType(); |
123 | } | 123 | } |
124 | 124 | ||
125 | void OFileViewInterface::activate( const QString& ) | 125 | void OFileViewInterface::activate( const QString& ) |
126 | { | 126 | { |
127 | // not implemented here | 127 | // not implemented here |
128 | } | 128 | } |
129 | 129 | ||
130 | void OFileViewInterface::ok() | 130 | void OFileViewInterface::ok() |
131 | { | 131 | { |
132 | emit selector()->ok(); | 132 | emit selector()->ok(); |
133 | } | 133 | } |
134 | 134 | ||
135 | void OFileViewInterface::cancel() | 135 | void OFileViewInterface::cancel() |
136 | { | 136 | { |
137 | emit selector()->cancel(); | 137 | emit selector()->cancel(); |
138 | } | 138 | } |
139 | 139 | ||
140 | void OFileViewInterface::closeMe() | 140 | void OFileViewInterface::closeMe() |
141 | { | 141 | { |
142 | emit selector()->closeMe(); | 142 | emit selector()->closeMe(); |
143 | } | 143 | } |
144 | 144 | ||
145 | void OFileViewInterface::fileSelected( const QString& str) | 145 | void OFileViewInterface::fileSelected( const QString& str) |
146 | { | 146 | { |
147 | emit selector()->fileSelected( str); | 147 | emit selector()->fileSelected( str); |
148 | } | 148 | } |
149 | 149 | ||
150 | void OFileViewInterface::fileSelected( const DocLnk& lnk) | 150 | void OFileViewInterface::fileSelected( const DocLnk& lnk) |
151 | { | 151 | { |
152 | emit selector()->fileSelected( lnk ); | 152 | emit selector()->fileSelected( lnk ); |
153 | } | 153 | } |
154 | 154 | ||
155 | void OFileViewInterface::setCurrentFileName( const QString& str ) | 155 | void OFileViewInterface::setCurrentFileName( const QString& str ) |
156 | { | 156 | { |
157 | selector()->m_lneEdit->setText( str ); | 157 | selector()->m_lneEdit->setText( str ); |
158 | } | 158 | } |
159 | 159 | ||
160 | QString OFileViewInterface::currentFileName()const | 160 | QString OFileViewInterface::currentFileName()const |
161 | { | 161 | { |
162 | return selector()->m_lneEdit->text(); | 162 | return selector()->m_lneEdit->text(); |
163 | } | 163 | } |
164 | 164 | ||
165 | QString OFileViewInterface::startDirectory()const | 165 | QString OFileViewInterface::startDirectory()const |
166 | { | 166 | { |
167 | return selector()->m_startDir; | 167 | return selector()->m_startDir; |
168 | } | 168 | } |
169 | 169 | ||
170 | bool OFileViewInterface::allItem( const QString& item )const | 170 | bool OFileViewInterface::allItem( const QString& item )const |
171 | { | 171 | { |
172 | return selector()->m_allList.contains( item ); | 172 | return selector()->m_allList.contains( item ); |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) | 176 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) |
177 | :OFileViewInterface( selector ) | 177 | :OFileViewInterface( selector ) |
178 | { | 178 | { |
179 | m_selector = 0; | 179 | m_selector = 0; |
180 | setName( QObject::tr("Documents") ); | 180 | setName( QObject::tr("Documents") ); |
181 | } | 181 | } |
182 | 182 | ||
183 | ODocumentFileView::~ODocumentFileView() | 183 | ODocumentFileView::~ODocumentFileView() |
184 | { | 184 | { |
185 | } | 185 | } |
186 | 186 | ||
187 | QString ODocumentFileView::selectedName()const | 187 | QString ODocumentFileView::selectedName()const |
188 | { | 188 | { |
189 | if (!m_selector) | 189 | if (!m_selector) |
190 | return QString::null; | 190 | return QString::null; |
191 | 191 | ||
192 | return m_selector->selectedDocument().file(); | 192 | return m_selector->selectedDocument().file(); |
193 | } | 193 | } |
194 | 194 | ||
195 | QString ODocumentFileView::selectedPath()const | 195 | QString ODocumentFileView::selectedPath()const |
196 | { | 196 | { |
197 | return QPEApplication::documentDir(); | 197 | return QPEApplication::documentDir(); |
198 | } | 198 | } |
199 | 199 | ||
200 | QString ODocumentFileView::directory()const | 200 | QString ODocumentFileView::directory()const |
201 | { | 201 | { |
202 | return selectedPath(); | 202 | return selectedPath(); |
203 | } | 203 | } |
204 | 204 | ||
205 | void ODocumentFileView::reread() | 205 | void ODocumentFileView::reread() |
206 | { | 206 | { |
207 | if (!m_selector) | 207 | if (!m_selector) |
208 | return; | 208 | return; |
209 | 209 | ||
210 | m_selector->setNewVisible( showNew() ); | 210 | m_selector->setNewVisible( showNew() ); |
211 | m_selector->setCloseVisible( showClose() ); | 211 | m_selector->setCloseVisible( showClose() ); |
212 | m_selector->filter = currentMimeType().join(";"); | 212 | m_selector->filter = currentMimeType().join(";"); |
213 | m_selector->reread(); | 213 | m_selector->reread(); |
214 | } | 214 | } |
215 | 215 | ||
216 | int ODocumentFileView::fileCount()const | 216 | int ODocumentFileView::fileCount()const |
217 | { | 217 | { |
218 | if (!m_selector) | 218 | if (!m_selector) |
219 | return -1; | 219 | return -1; |
220 | 220 | ||
221 | return m_selector->fileCount(); | 221 | return m_selector->fileCount(); |
222 | } | 222 | } |
223 | 223 | ||
224 | DocLnk ODocumentFileView::selectedDocument()const | 224 | DocLnk ODocumentFileView::selectedDocument()const |
225 | { | 225 | { |
226 | if (!m_selector) | 226 | if (!m_selector) |
227 | return DocLnk(); | 227 | return DocLnk(); |
228 | 228 | ||
229 | return m_selector->selectedDocument(); | 229 | return m_selector->selectedDocument(); |
230 | } | 230 | } |
231 | 231 | ||
232 | QWidget* ODocumentFileView::widget( QWidget* parent ) | 232 | QWidget* ODocumentFileView::widget( QWidget* parent ) |
233 | { | 233 | { |
234 | if (!m_selector ) | 234 | if (!m_selector ) |
235 | { | 235 | { |
236 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); | 236 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); |
237 | QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ), | 237 | QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ), |
238 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); | 238 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); |
239 | QObject::connect(m_selector, SIGNAL(closeMe() ), | 239 | QObject::connect(m_selector, SIGNAL(closeMe() ), |
240 | selector(), SIGNAL(closeMe() ) ); | 240 | selector(), SIGNAL(closeMe() ) ); |
241 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ), | 241 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ), |
242 | selector(), SIGNAL(newSelected(const DocLnk&) ) ); | 242 | selector(), SIGNAL(newSelected(const DocLnk&) ) ); |
243 | } | 243 | } |
244 | 244 | ||
245 | return m_selector; | 245 | return m_selector; |
246 | } | 246 | } |
247 | 247 | ||
248 | /* | 248 | /* |
249 | * This is the file system view used | 249 | * This is the file system view used |
250 | * we use a QListView + QListViewItems for it | 250 | * we use a QListView + QListViewItems for it |
251 | */ | 251 | */ |
252 | 252 | ||
253 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, | 253 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, |
254 | const QString& path, const QString& date, | 254 | const QString& path, const QString& date, |
255 | const QString& size, const QString& dir, | 255 | const QString& size, const QString& dir, |
256 | bool isLocked, bool isDir ) | 256 | bool isLocked, bool isDir ) |
257 | : QListViewItem( view ), m_dir(dir), m_isDir(isDir), m_locked(isLocked) | 257 | : QListViewItem( view ), m_dir(dir), m_isDir(isDir), m_locked(isLocked) |
258 | { | 258 | { |
259 | setPixmap(0, pixmap ); | 259 | setPixmap(0, pixmap ); |
260 | setText(1, path ); | 260 | setText(1, path ); |
261 | setText(2, size ); | 261 | setText(2, size ); |
262 | setText(3, date ); | 262 | setText(3, date ); |
263 | } | 263 | } |
264 | 264 | ||
265 | OFileSelectorItem::~OFileSelectorItem() | 265 | OFileSelectorItem::~OFileSelectorItem() |
266 | { | 266 | { |
267 | } | 267 | } |
268 | 268 | ||
269 | bool OFileSelectorItem::isLocked()const | 269 | bool OFileSelectorItem::isLocked()const |
270 | { | 270 | { |
271 | return m_locked; | 271 | return m_locked; |
272 | } | 272 | } |
273 | 273 | ||
274 | QString OFileSelectorItem::directory()const | 274 | QString OFileSelectorItem::directory()const |
275 | { | 275 | { |
276 | return m_dir; | 276 | return m_dir; |
277 | } | 277 | } |
278 | 278 | ||
279 | bool OFileSelectorItem::isDir()const | 279 | bool OFileSelectorItem::isDir()const |
280 | { | 280 | { |
281 | return m_isDir; | 281 | return m_isDir; |
282 | } | 282 | } |
283 | 283 | ||
284 | QString OFileSelectorItem::path()const | 284 | QString OFileSelectorItem::path()const |
285 | { | 285 | { |
286 | return text( 1 ); | 286 | return text( 1 ); |
287 | } | 287 | } |
288 | 288 | ||
289 | QString OFileSelectorItem::key( int id, bool )const | 289 | QString OFileSelectorItem::key( int id, bool )const |
290 | { | 290 | { |
291 | QString ke; | 291 | QString ke; |
292 | 292 | ||
293 | /* | 293 | /* |
294 | * id = 0 ||id == 1 : Sort By Name but Directories at Top | 294 | * id = 0 ||id == 1 : Sort By Name but Directories at Top |
295 | * id = 2 : Sort By Size: Prepend '0' to the key | 295 | * id = 2 : Sort By Size: Prepend '0' to the key |
296 | */ | 296 | */ |
297 | if( id == 0 || id == 1 ) | 297 | if( id == 0 || id == 1 ) |
298 | { // name | 298 | { // name |
299 | if( m_isDir ) | 299 | if( m_isDir ) |
300 | { | 300 | { |
301 | ke.append("0" ); | 301 | ke.append("0" ); |
302 | ke.append( text(1) ); | 302 | ke.append( text(1) ); |
303 | } | 303 | } |
304 | else | 304 | else |
305 | { | 305 | { |
306 | ke.append("1" ); | 306 | ke.append("1" ); |
307 | ke.append( text(1) ); | 307 | ke.append( text(1) ); |
308 | } | 308 | } |
309 | return ke; | 309 | return ke; |
310 | }else if(id == 2) { | 310 | }else if(id == 2) { |
311 | return text(2).rightJustify(20, '0'); | 311 | return text(2).rightJustify(20, '0'); |
312 | }else | 312 | }else |
313 | return text( id ); | 313 | return text( id ); |
314 | 314 | ||
315 | } | 315 | } |
316 | 316 | ||
317 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel) | 317 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel) |
318 | :QWidget( parent ), m_sel( sel ) | 318 | :QWidget( parent ), m_sel( sel ) |
319 | { | 319 | { |
320 | m_all = false; | 320 | m_all = false; |
321 | QVBoxLayout* lay = new QVBoxLayout( this ); | 321 | QVBoxLayout* lay = new QVBoxLayout( this ); |
322 | m_currentDir = startDir; | 322 | m_currentDir = startDir; |
323 | bool bigicons = qApp->desktop()->size().width()>330; | ||
323 | 324 | ||
324 | /* | 325 | /* |
325 | * now we add a special bar | 326 | * now we add a special bar |
326 | * One Button For Up | 327 | * One Button For Up |
327 | * Home | 328 | * Home |
328 | * Doc | 329 | * Doc |
329 | * And a dropdown menu with FileSystems | 330 | * And a dropdown menu with FileSystems |
330 | * FUTURE: one to change dir with lineedit | 331 | * FUTURE: one to change dir with lineedit |
331 | * Bookmarks | 332 | * Bookmarks |
332 | * Create Dir | 333 | * Create Dir |
333 | */ | 334 | */ |
334 | QHBox* box = new QHBox(this ); | 335 | QHBox* box = new QHBox(this ); |
335 | box->setBackgroundMode( PaletteButton ); | 336 | box->setBackgroundMode( PaletteButton ); |
336 | box->setSpacing( 0 ); | 337 | box->setSpacing( 0 ); |
337 | 338 | ||
338 | QToolButton *btn = new QToolButton( box ); | 339 | QToolButton *btn = new QToolButton( box ); |
339 | btn->setUsesBigPixmap( true ); | 340 | btn->setUsesBigPixmap(bigicons); |
340 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "up", Opie::Core::OResource::SmallIcon ) ); | 341 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "up", Opie::Core::OResource::SmallIcon ) ); |
341 | connect(btn, SIGNAL(clicked() ), | 342 | connect(btn, SIGNAL(clicked() ), |
342 | this, SLOT( cdUP() ) ); | 343 | this, SLOT( cdUP() ) ); |
343 | 344 | ||
344 | btn = new QToolButton( box ); | 345 | btn = new QToolButton( box ); |
345 | btn->setUsesBigPixmap( true ); | 346 | btn->setUsesBigPixmap(bigicons); |
346 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "home", Opie::Core::OResource::SmallIcon ) ); | 347 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "home", Opie::Core::OResource::SmallIcon ) ); |
347 | connect(btn, SIGNAL(clicked() ), | 348 | connect(btn, SIGNAL(clicked() ), |
348 | this, SLOT( cdHome() ) ); | 349 | this, SLOT( cdHome() ) ); |
349 | 350 | ||
350 | btn = new QToolButton( box ); | 351 | btn = new QToolButton( box ); |
351 | btn->setUsesBigPixmap( true ); | 352 | btn->setUsesBigPixmap(bigicons); |
352 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "DocsIcon", Opie::Core::OResource::SmallIcon ) ); | 353 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "DocsIcon", Opie::Core::OResource::SmallIcon ) ); |
353 | connect(btn, SIGNAL(clicked() ), | 354 | connect(btn, SIGNAL(clicked() ), |
354 | this, SLOT(cdDoc() ) ); | 355 | this, SLOT(cdDoc() ) ); |
355 | 356 | ||
356 | m_btnNew = new QToolButton( box ); | 357 | m_btnNew = new QToolButton( box ); |
357 | m_btnNew->setUsesBigPixmap( true ); | 358 | m_btnNew->setUsesBigPixmap(bigicons); |
358 | m_btnNew->setPixmap( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ) ); | 359 | m_btnNew->setPixmap( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ) ); |
359 | connect(m_btnNew, SIGNAL(clicked() ), | 360 | connect(m_btnNew, SIGNAL(clicked() ), |
360 | this, SLOT(slotNew() ) ); | 361 | this, SLOT(slotNew() ) ); |
361 | 362 | ||
362 | 363 | ||
363 | m_btnClose = new QToolButton( box ); | 364 | m_btnClose = new QToolButton( box ); |
364 | m_btnClose->setUsesBigPixmap( true ); | 365 | m_btnClose->setUsesBigPixmap(bigicons); |
365 | m_btnClose->setPixmap( Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ) ); | 366 | m_btnClose->setPixmap( Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ) ); |
366 | connect(m_btnClose, SIGNAL(clicked() ), | 367 | connect(m_btnClose, SIGNAL(clicked() ), |
367 | selector(), SIGNAL(closeMe() ) ); | 368 | selector(), SIGNAL(closeMe() ) ); |
368 | 369 | ||
369 | btn = new QToolButton( box ); | 370 | btn = new QToolButton( box ); |
370 | btn->setUsesBigPixmap( true ); | 371 | btn->setUsesBigPixmap(bigicons); |
371 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ) ); | 372 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ) ); |
372 | 373 | ||
373 | m_fsButton = btn; | 374 | m_fsButton = btn; |
374 | /* let's fill device parts */ | 375 | /* let's fill device parts */ |
375 | QPopupMenu* pop = new QPopupMenu(this); | 376 | QPopupMenu* pop = new QPopupMenu(this); |
376 | connect(pop, SIGNAL( activated(int) ), | 377 | connect(pop, SIGNAL( activated(int) ), |
377 | this, SLOT(slotFSActivated(int) ) ); | 378 | this, SLOT(slotFSActivated(int) ) ); |
378 | 379 | ||
379 | StorageInfo storage; | 380 | StorageInfo storage; |
380 | const QList<FileSystem> &fs = storage.fileSystems(); | 381 | const QList<FileSystem> &fs = storage.fileSystems(); |
381 | QListIterator<FileSystem> it(fs); | 382 | QListIterator<FileSystem> it(fs); |
382 | for ( ; it.current(); ++it ) | 383 | for ( ; it.current(); ++it ) |
383 | { | 384 | { |
384 | const QString disk = (*it)->name(); | 385 | const QString disk = (*it)->name(); |
385 | const QString path = (*it)->path(); | 386 | const QString path = (*it)->path(); |
386 | m_dev.insert( disk, path ); | 387 | m_dev.insert( disk, path ); |
387 | pop->insertItem( disk ); | 388 | pop->insertItem( disk ); |
388 | } | 389 | } |
389 | m_fsPop = pop; | 390 | m_fsPop = pop; |
390 | 391 | ||
391 | connect(btn,SIGNAL(pressed()),this,SLOT(slotFSpressed())); | 392 | connect(btn,SIGNAL(pressed()),this,SLOT(slotFSpressed())); |
392 | 393 | ||
393 | lay->addWidget( box ); | 394 | lay->addWidget( box ); |
394 | 395 | ||
395 | m_view = new QListView( this ); | 396 | m_view = new QListView( this ); |
396 | 397 | ||
397 | m_view->installEventFilter(this); | 398 | m_view->installEventFilter(this); |
398 | 399 | ||
399 | QPEApplication::setStylusOperation( m_view->viewport(), | 400 | QPEApplication::setStylusOperation( m_view->viewport(), |
400 | QPEApplication::RightOnHold); | 401 | QPEApplication::RightOnHold); |
401 | m_view->addColumn(" " ); | 402 | m_view->addColumn(" " ); |
402 | m_view->addColumn(tr("Name"), 135 ); | 403 | m_view->addColumn(tr("Name"), 135 ); |
403 | m_view->addColumn(tr("Size"), -1 ); | 404 | m_view->addColumn(tr("Size"), -1 ); |
404 | m_view->addColumn(tr("Date"), 60 ); | 405 | m_view->addColumn(tr("Date"), 60 ); |
405 | m_view->addColumn(tr("Mime Type"), -1 ); | 406 | m_view->addColumn(tr("Mime Type"), -1 ); |
406 | 407 | ||
407 | 408 | ||
408 | m_view->setSorting( 1 ); | 409 | m_view->setSorting( 1 ); |
409 | m_view->setAllColumnsShowFocus( TRUE ); | 410 | m_view->setAllColumnsShowFocus( TRUE ); |
410 | 411 | ||
411 | lay->addWidget( m_view, 1000 ); | 412 | lay->addWidget( m_view, 1000 ); |
412 | connectSlots(); | 413 | connectSlots(); |
413 | } | 414 | } |
414 | 415 | ||
415 | void OFileViewFileListView::slotFSpressed() | 416 | void OFileViewFileListView::slotFSpressed() |
416 | { | 417 | { |
417 | m_fsPop->exec(QPoint( QCursor::pos().x(), QCursor::pos().y())); | 418 | m_fsPop->exec(QPoint( QCursor::pos().x(), QCursor::pos().y())); |
418 | m_fsButton->setDown(false); | 419 | m_fsButton->setDown(false); |
419 | } | 420 | } |
420 | 421 | ||
421 | OFileViewFileListView::~OFileViewFileListView() | 422 | OFileViewFileListView::~OFileViewFileListView() |
422 | { | 423 | { |
423 | } | 424 | } |
424 | 425 | ||
425 | void OFileViewFileListView::slotNew() | 426 | void OFileViewFileListView::slotNew() |
426 | { | 427 | { |
427 | DocLnk lnk; | 428 | DocLnk lnk; |
428 | emit selector()->newSelected( lnk ); | 429 | emit selector()->newSelected( lnk ); |
429 | } | 430 | } |
430 | 431 | ||
431 | OFileSelectorItem* OFileViewFileListView::currentItem()const | 432 | OFileSelectorItem* OFileViewFileListView::currentItem()const |
432 | { | 433 | { |
433 | QListViewItem* item = m_view->currentItem(); | 434 | QListViewItem* item = m_view->currentItem(); |
434 | if (!item ) | 435 | if (!item ) |
435 | return 0l; | 436 | return 0l; |
436 | 437 | ||
437 | return static_cast<OFileSelectorItem*>(item); | 438 | return static_cast<OFileSelectorItem*>(item); |
438 | } | 439 | } |
439 | 440 | ||
440 | void OFileViewFileListView::reread( bool all ) | 441 | void OFileViewFileListView::reread( bool all ) |
441 | { | 442 | { |
442 | m_view->clear(); | 443 | m_view->clear(); |
443 | 444 | ||
444 | if (selector()->showClose() ) | 445 | if (selector()->showClose() ) |
445 | m_btnClose->show(); | 446 | m_btnClose->show(); |
446 | else | 447 | else |
447 | m_btnClose->hide(); | 448 | m_btnClose->hide(); |
448 | 449 | ||
449 | if (selector()->showNew() ) | 450 | if (selector()->showNew() ) |
450 | m_btnNew->show(); | 451 | m_btnNew->show(); |
451 | else | 452 | else |
452 | m_btnNew->hide(); | 453 | m_btnNew->hide(); |
453 | 454 | ||
454 | m_mimes = selector()->currentMimeType(); | 455 | m_mimes = selector()->currentMimeType(); |
455 | m_all = all; | 456 | m_all = all; |
456 | 457 | ||
457 | QDir dir( m_currentDir ); | 458 | QDir dir( m_currentDir ); |
458 | if (!dir.exists() ) | 459 | if (!dir.exists() ) |
459 | return; | 460 | return; |
460 | 461 | ||
461 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); | 462 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); |
462 | int filter; | 463 | int filter; |
463 | filter = QDir::Dirs; | 464 | filter = QDir::Dirs; |
464 | if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR ) | 465 | if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR ) |
465 | filter = filter | QDir::Files | QDir::All; | 466 | filter = filter | QDir::Files | QDir::All; |
466 | 467 | ||
467 | if ( m_all ) | 468 | if ( m_all ) |
468 | filter = filter | QDir::Hidden; | 469 | filter = filter | QDir::Hidden; |
469 | 470 | ||
470 | dir.setFilter( filter ); | 471 | dir.setFilter( filter ); |
471 | 472 | ||
472 | // now go through all files | 473 | // now go through all files |
473 | const QFileInfoList *list = dir.entryInfoList(); | 474 | const QFileInfoList *list = dir.entryInfoList(); |
474 | if (!list) | 475 | if (!list) |
475 | { | 476 | { |
476 | cdUP(); | 477 | cdUP(); |
477 | return; | 478 | return; |
478 | } | 479 | } |
479 | 480 | ||
480 | QFileInfoListIterator it( *list ); | 481 | QFileInfoListIterator it( *list ); |
481 | QFileInfo *fi; | 482 | QFileInfo *fi; |
482 | while( (fi=it.current() ) ) | 483 | while( (fi=it.current() ) ) |
483 | { | 484 | { |
484 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) | 485 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) |
485 | { | 486 | { |
486 | ++it; | 487 | ++it; |
487 | continue; | 488 | continue; |
488 | } | 489 | } |
489 | 490 | ||
490 | /* | 491 | /* |
491 | * It is a symlink we try to resolve it now but don't let us attack by DOS | 492 | * It is a symlink we try to resolve it now but don't let us attack by DOS |
492 | * | 493 | * |
493 | */ | 494 | */ |
494 | if( fi->isSymLink() ) | 495 | if( fi->isSymLink() ) |
495 | { | 496 | { |
496 | QString file = createNewPath(fi->dirPath( true ),fi->readLink()); | 497 | QString file = createNewPath(fi->dirPath( true ),fi->readLink()); |
497 | for( int i = 0; i<=4; i++) | 498 | for( int i = 0; i<=4; i++) |
498 | { // 5 tries to prevent dos | 499 | { // 5 tries to prevent dos |
499 | QFileInfo info( file ); | 500 | QFileInfo info( file ); |
500 | if( !info.exists() ) | 501 | if( !info.exists() ) |
501 | { | 502 | { |
502 | addSymlink( fi, TRUE ); | 503 | addSymlink( fi, TRUE ); |
503 | break; | 504 | break; |
504 | } | 505 | } |
505 | else if( info.isDir() ) | 506 | else if( info.isDir() ) |
506 | { | 507 | { |
507 | addDir( fi, TRUE ); | 508 | addDir( fi, TRUE ); |
508 | break; | 509 | break; |
509 | } | 510 | } |
510 | else if( info.isFile() ) | 511 | else if( info.isFile() ) |
511 | { | 512 | { |
512 | addFile( fi, TRUE ); | 513 | addFile( fi, TRUE ); |
513 | break; | 514 | break; |
514 | } | 515 | } |
515 | else if( info.isSymLink() ) | 516 | else if( info.isSymLink() ) |
516 | { | 517 | { |
517 | file = createNewPath(info.dirPath(true ),info.readLink()); | 518 | file = createNewPath(info.dirPath(true ),info.readLink()); |
518 | break; | 519 | break; |
519 | } | 520 | } |
520 | else if( i == 4) | 521 | else if( i == 4) |
521 | { // couldn't resolve symlink add it as symlink | 522 | { // couldn't resolve symlink add it as symlink |
522 | addSymlink( fi ); | 523 | addSymlink( fi ); |
523 | } | 524 | } |
524 | } // off for loop for symlink resolving | 525 | } // off for loop for symlink resolving |
525 | } | 526 | } |
526 | else if( fi->isDir() ) | 527 | else if( fi->isDir() ) |
527 | addDir( fi ); | 528 | addDir( fi ); |
528 | else if( fi->isFile() ) | 529 | else if( fi->isFile() ) |
529 | addFile( fi ); | 530 | addFile( fi ); |
530 | 531 | ||
531 | ++it; | 532 | ++it; |
532 | } // of while loop | 533 | } // of while loop |
533 | m_view->sort(); | 534 | m_view->sort(); |
534 | 535 | ||
535 | } | 536 | } |
536 | int OFileViewFileListView::fileCount()const | 537 | int OFileViewFileListView::fileCount()const |
537 | { | 538 | { |
538 | return m_view->childCount(); | 539 | return m_view->childCount(); |
539 | } | 540 | } |
540 | 541 | ||
541 | QString OFileViewFileListView::currentDir()const | 542 | QString OFileViewFileListView::currentDir()const |
542 | { | 543 | { |
543 | return m_currentDir; | 544 | return m_currentDir; |
544 | } | 545 | } |
545 | 546 | ||
546 | OFileSelector* OFileViewFileListView::selector() | 547 | OFileSelector* OFileViewFileListView::selector() |
547 | { | 548 | { |
548 | return m_sel; | 549 | return m_sel; |
549 | } | 550 | } |
550 | 551 | ||
551 | bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) | 552 | bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) |
552 | { | 553 | { |
553 | if ( e->type() == QEvent::KeyPress ) | 554 | if ( e->type() == QEvent::KeyPress ) |
554 | { | 555 | { |
555 | QKeyEvent *k = (QKeyEvent *)e; | 556 | QKeyEvent *k = (QKeyEvent *)e; |
556 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) | 557 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) |
557 | { | 558 | { |
558 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); | 559 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); |
559 | return true; | 560 | return true; |
560 | } | 561 | } |
561 | } | 562 | } |
562 | return false; | 563 | return false; |
563 | } | 564 | } |
564 | 565 | ||
565 | void OFileViewFileListView::connectSlots() | 566 | void OFileViewFileListView::connectSlots() |
566 | { | 567 | { |
567 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), | 568 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), |
568 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); | 569 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); |
569 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), | 570 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), |
570 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); | 571 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); |
571 | } | 572 | } |
572 | 573 | ||
573 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) | 574 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) |
574 | { | 575 | { |
575 | if (!item) | 576 | if (!item) |
576 | return; | 577 | return; |
577 | #if 0 | 578 | #if 0 |
578 | 579 | ||
579 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 580 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
580 | 581 | ||
581 | if (!sel->isDir() ) | 582 | if (!sel->isDir() ) |
582 | { | 583 | { |
583 | selector()->m_lneEdit->setText( sel->text(1) ); | 584 | selector()->m_lneEdit->setText( sel->text(1) ); |
584 | // if in fileselector mode we will emit selected | 585 | // if in fileselector mode we will emit selected |
585 | if ( selector()->mode() == OFileSelector::FileSelector ) | 586 | if ( selector()->mode() == OFileSelector::FileSelector ) |
586 | { | 587 | { |
587 | odebug << "slot Current Changed" << oendl; | 588 | odebug << "slot Current Changed" << oendl; |
588 | QStringList str = QStringList::split("->", sel->text(1) ); | 589 | QStringList str = QStringList::split("->", sel->text(1) ); |
589 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); | 590 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
590 | emit selector()->fileSelected( path ); | 591 | emit selector()->fileSelected( path ); |
591 | DocLnk lnk( path ); | 592 | DocLnk lnk( path ); |
592 | emit selector()->fileSelected( lnk ); | 593 | emit selector()->fileSelected( lnk ); |
593 | } | 594 | } |
594 | } | 595 | } |
595 | #endif | 596 | #endif |
596 | } | 597 | } |
597 | 598 | ||
598 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) | 599 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) |
599 | { | 600 | { |
600 | if (!item || ( button != Qt::LeftButton) ) | 601 | if (!item || ( button != Qt::LeftButton) ) |
601 | return; | 602 | return; |
602 | 603 | ||
603 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 604 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
604 | if (!sel->isLocked() ) | 605 | if (!sel->isLocked() ) |
605 | { | 606 | { |
606 | QStringList str = QStringList::split("->", sel->text(1) ); | 607 | QStringList str = QStringList::split("->", sel->text(1) ); |
607 | if (sel->isDir() ) | 608 | if (sel->isDir() ) |
608 | { | 609 | { |
609 | m_currentDir = createNewPath(sel->directory(),str[0].stripWhiteSpace()); | 610 | m_currentDir = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
610 | emit selector()->dirSelected( m_currentDir ); | 611 | emit selector()->dirSelected( m_currentDir ); |
611 | reread( m_all ); | 612 | reread( m_all ); |
612 | } | 613 | } |
613 | else | 614 | else |
614 | { // file | 615 | { // file |
615 | odebug << "slot Clicked" << oendl; | 616 | odebug << "slot Clicked" << oendl; |
616 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); | 617 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); |
617 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); | 618 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
618 | emit selector()->fileSelected( path ); | 619 | emit selector()->fileSelected( path ); |
619 | DocLnk lnk( path ); | 620 | DocLnk lnk( path ); |
620 | emit selector()->fileSelected( lnk ); | 621 | emit selector()->fileSelected( lnk ); |
621 | } | 622 | } |
622 | } // not locked | 623 | } // not locked |
623 | } | 624 | } |
624 | 625 | ||
625 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) | 626 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) |
626 | { | 627 | { |
627 | MimeType type( info->absFilePath() ); | 628 | MimeType type( info->absFilePath() ); |
628 | if (!compliesMime( type.id() ) ) | 629 | if (!compliesMime( type.id() ) ) |
629 | return; | 630 | return; |
630 | 631 | ||
631 | QPixmap pix = type.pixmap(); | 632 | QPixmap pix = type.pixmap(); |
632 | QString dir, name; bool locked; | 633 | QString dir, name; bool locked; |
633 | if ( pix.isNull() ) | 634 | if ( pix.isNull() ) |
634 | { | 635 | { |
635 | QWMatrix matrix; | 636 | QWMatrix matrix; |
636 | QPixmap pixer( Opie::Core::OResource::loadPixmap( "UnknownDocument" ) ); | 637 | QPixmap pixer( Opie::Core::OResource::loadPixmap( "UnknownDocument" ) ); |
637 | matrix.scale( .4, .4 ); | 638 | matrix.scale( .4, .4 ); |
638 | pix = pixer.xForm( matrix ); | 639 | pix = pixer.xForm( matrix ); |
639 | } | 640 | } |
640 | dir = info->dirPath( true ); | 641 | dir = info->dirPath( true ); |
641 | locked = false; | 642 | locked = false; |
642 | if ( symlink ) | 643 | if ( symlink ) |
643 | name = info->fileName() + " -> " + createNewPath(info->dirPath(),info->readLink()); | 644 | name = info->fileName() + " -> " + createNewPath(info->dirPath(),info->readLink()); |
644 | else | 645 | else |
645 | { | 646 | { |
646 | name = info->fileName(); | 647 | name = info->fileName(); |
647 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || | 648 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || |
648 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) | 649 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) |
649 | { | 650 | { |
650 | locked = true; | 651 | locked = true; |
651 | pix = Opie::Core::OResource::loadPixmap( "locked" ); | 652 | pix = Opie::Core::OResource::loadPixmap( "locked" ); |
652 | } | 653 | } |
653 | } | 654 | } |
654 | (void)new OFileSelectorItem( m_view, pix, name, | 655 | (void)new OFileSelectorItem( m_view, pix, name, |
655 | info->lastModified().toString(), QString::number( info->size() ), | 656 | info->lastModified().toString(), QString::number( info->size() ), |
656 | dir, locked ); | 657 | dir, locked ); |
657 | } | 658 | } |
658 | 659 | ||
659 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) | 660 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) |
660 | { | 661 | { |
661 | bool locked = false; QString name; QPixmap pix; | 662 | bool locked = false; QString name; QPixmap pix; |
662 | 663 | ||
663 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || | 664 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || |
664 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) | 665 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) |
665 | { | 666 | { |
666 | locked = true; | 667 | locked = true; |
667 | if ( symlink ) | 668 | if ( symlink ) |
668 | pix = Opie::Core::OResource::loadPixmap( "opie/symlink" ); | 669 | pix = Opie::Core::OResource::loadPixmap( "opie/symlink" ); |
669 | else | 670 | else |
670 | pix = Opie::Core::OResource::loadPixmap( "lockedfolder" ); | 671 | pix = Opie::Core::OResource::loadPixmap( "lockedfolder" ); |
671 | } | 672 | } |
672 | else | 673 | else |
673 | pix = symlink ? Opie::Core::OResource::loadPixmap( "opie/symlink" ) : Opie::Core::OResource::loadPixmap( "folder" ); | 674 | pix = symlink ? Opie::Core::OResource::loadPixmap( "opie/symlink" ) : Opie::Core::OResource::loadPixmap( "folder" ); |
674 | 675 | ||
675 | name = symlink ? info->fileName() + " -> " + createNewPath(info->dirPath(true),info->readLink()) : | 676 | name = symlink ? info->fileName() + " -> " + createNewPath(info->dirPath(true),info->readLink()) : |
676 | info->fileName(); | 677 | info->fileName(); |
677 | 678 | ||
678 | (void)new OFileSelectorItem( m_view, pix, name, | 679 | (void)new OFileSelectorItem( m_view, pix, name, |
679 | info->lastModified().toString(), | 680 | info->lastModified().toString(), |
680 | QString::number( info->size() ), | 681 | QString::number( info->size() ), |
681 | info->dirPath( true ), locked, true ); | 682 | info->dirPath( true ), locked, true ); |
682 | 683 | ||
683 | 684 | ||
684 | } | 685 | } |
685 | 686 | ||
686 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) | 687 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) |
687 | { | 688 | { |
688 | } | 689 | } |
689 | 690 | ||
690 | void OFileViewFileListView::cdUP() | 691 | void OFileViewFileListView::cdUP() |
691 | { | 692 | { |
692 | QDir dir( m_currentDir ); | 693 | QDir dir( m_currentDir ); |
693 | dir.cdUp(); | 694 | dir.cdUp(); |
694 | 695 | ||
695 | if (!dir.exists() ) | 696 | if (!dir.exists() ) |
696 | m_currentDir = "/"; | 697 | m_currentDir = "/"; |
697 | else | 698 | else |
698 | m_currentDir = dir.absPath(); | 699 | m_currentDir = dir.absPath(); |
699 | 700 | ||
700 | emit selector()->dirSelected( m_currentDir ); | 701 | emit selector()->dirSelected( m_currentDir ); |
701 | reread( m_all ); | 702 | reread( m_all ); |
702 | } | 703 | } |
703 | 704 | ||
704 | void OFileViewFileListView::cdHome() | 705 | void OFileViewFileListView::cdHome() |
705 | { | 706 | { |
706 | m_currentDir = QDir::homeDirPath(); | 707 | m_currentDir = QDir::homeDirPath(); |
707 | emit selector()->dirSelected( m_currentDir ); | 708 | emit selector()->dirSelected( m_currentDir ); |
708 | reread( m_all ); | 709 | reread( m_all ); |
709 | } | 710 | } |
710 | 711 | ||
711 | void OFileViewFileListView::cdDoc() | 712 | void OFileViewFileListView::cdDoc() |
712 | { | 713 | { |
713 | m_currentDir = QPEApplication::documentDir(); | 714 | m_currentDir = QPEApplication::documentDir(); |
714 | emit selector()->dirSelected( m_currentDir ); | 715 | emit selector()->dirSelected( m_currentDir ); |
715 | reread( m_all ); | 716 | reread( m_all ); |
716 | } | 717 | } |
717 | 718 | ||
718 | void OFileViewFileListView::changeDir( const QString& dir ) | 719 | void OFileViewFileListView::changeDir( const QString& dir ) |
719 | { | 720 | { |
720 | m_currentDir = dir; | 721 | m_currentDir = dir; |
721 | emit selector()->dirSelected( m_currentDir ); | 722 | emit selector()->dirSelected( m_currentDir ); |
722 | reread( m_all ); | 723 | reread( m_all ); |
723 | } | 724 | } |
724 | 725 | ||
725 | void OFileViewFileListView::slotFSActivated( int id ) | 726 | void OFileViewFileListView::slotFSActivated( int id ) |
726 | { | 727 | { |
727 | changeDir ( m_dev[m_fsPop->text(id)] ); | 728 | changeDir ( m_dev[m_fsPop->text(id)] ); |
728 | } | 729 | } |
729 | 730 | ||
730 | /* check if the mimetype in mime | 731 | /* check if the mimetype in mime |
731 | * complies with the one which is current | 732 | * complies with the one which is current |
732 | */ | 733 | */ |
733 | /* | 734 | /* |
734 | * We've the mimetype of the file | 735 | * We've the mimetype of the file |
735 | * We need to get the stringlist of the current mimetype | 736 | * We need to get the stringlist of the current mimetype |
736 | * | 737 | * |
737 | * mime = image@slashjpeg | 738 | * mime = image@slashjpeg |
738 | * QStringList = 'image@slash*' | 739 | * QStringList = 'image@slash*' |
739 | * or QStringList = image/jpeg;image/png;application/x-ogg | 740 | * or QStringList = image/jpeg;image/png;application/x-ogg |
740 | * or QStringList = application/x-ogg;image@slash*; | 741 | * or QStringList = application/x-ogg;image@slash*; |
741 | * with all these mime filters it should get acceptes | 742 | * with all these mime filters it should get acceptes |
742 | * to do so we need to look if mime is contained inside | 743 | * to do so we need to look if mime is contained inside |
743 | * the stringlist | 744 | * the stringlist |
744 | * if it's contained return true | 745 | * if it's contained return true |
745 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' | 746 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' |
746 | * is contained in the mimefilter and then we will | 747 | * is contained in the mimefilter and then we will |
747 | * look if both are equal until the '/' | 748 | * look if both are equal until the '/' |
748 | */ | 749 | */ |
749 | 750 | ||
750 | bool OFileViewFileListView::compliesMime( const QString& str) | 751 | bool OFileViewFileListView::compliesMime( const QString& str) |
751 | { | 752 | { |
752 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) | 753 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) |
753 | return true; | 754 | return true; |
754 | 755 | ||
755 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) | 756 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) |
756 | { | 757 | { |
757 | QRegExp reg( (*it) ); | 758 | QRegExp reg( (*it) ); |
758 | reg.setWildcard( true ); | 759 | reg.setWildcard( true ); |
759 | if ( str.find( reg ) != -1 ) | 760 | if ( str.find( reg ) != -1 ) |
760 | return true; | 761 | return true; |
761 | 762 | ||
762 | } | 763 | } |
763 | return false; | 764 | return false; |
764 | } | 765 | } |
765 | /* | 766 | /* |
766 | * The listView giving access to the file system! | 767 | * The listView giving access to the file system! |
767 | */ | 768 | */ |
768 | 769 | ||
769 | class OFileViewFileSystem : public OFileViewInterface | 770 | class OFileViewFileSystem : public OFileViewInterface |
770 | { | 771 | { |
771 | public: | 772 | public: |
772 | OFileViewFileSystem( OFileSelector* ); | 773 | OFileViewFileSystem( OFileSelector* ); |
773 | ~OFileViewFileSystem(); | 774 | ~OFileViewFileSystem(); |
774 | 775 | ||
775 | QString selectedName() const; | 776 | QString selectedName() const; |
776 | QString selectedPath() const; | 777 | QString selectedPath() const; |
777 | 778 | ||
778 | QString directory()const; | 779 | QString directory()const; |
779 | void reread(); | 780 | void reread(); |
780 | int fileCount()const; | 781 | int fileCount()const; |
781 | 782 | ||
782 | QWidget* widget( QWidget* parent ); | 783 | QWidget* widget( QWidget* parent ); |
783 | void activate( const QString& ); | 784 | void activate( const QString& ); |
784 | private: | 785 | private: |
785 | OFileViewFileListView* m_view; | 786 | OFileViewFileListView* m_view; |
786 | bool m_all : 1; | 787 | bool m_all : 1; |
787 | }; | 788 | }; |
788 | 789 | ||
789 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) | 790 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) |
790 | : OFileViewInterface( sel ) | 791 | : OFileViewInterface( sel ) |
791 | { | 792 | { |
792 | m_view = 0; | 793 | m_view = 0; |
793 | m_all = false; | 794 | m_all = false; |
794 | } | 795 | } |
795 | 796 | ||
796 | OFileViewFileSystem::~OFileViewFileSystem() | 797 | OFileViewFileSystem::~OFileViewFileSystem() |
797 | { | 798 | { |
798 | } | 799 | } |
799 | 800 | ||
800 | QString OFileViewFileSystem::selectedName()const | 801 | QString OFileViewFileSystem::selectedName()const |
801 | { | 802 | { |
802 | if (!m_view ) | 803 | if (!m_view ) |
803 | return QString::null; | 804 | return QString::null; |
804 | 805 | ||
805 | QString cFN=currentFileName(); | 806 | QString cFN=currentFileName(); |
806 | if (cFN.startsWith("/")) return cFN; | 807 | if (cFN.startsWith("/")) return cFN; |
807 | return createNewPath(m_view->currentDir(),cFN); | 808 | return createNewPath(m_view->currentDir(),cFN); |
808 | } | 809 | } |
809 | 810 | ||
810 | QString OFileViewFileSystem::selectedPath()const | 811 | QString OFileViewFileSystem::selectedPath()const |
811 | { | 812 | { |
812 | return QString::null; | 813 | return QString::null; |
813 | } | 814 | } |
814 | 815 | ||
815 | QString OFileViewFileSystem::directory()const | 816 | QString OFileViewFileSystem::directory()const |
816 | { | 817 | { |
817 | if (!m_view) | 818 | if (!m_view) |
818 | return QString::null; | 819 | return QString::null; |
819 | 820 | ||
820 | OFileSelectorItem* item = m_view->currentItem(); | 821 | OFileSelectorItem* item = m_view->currentItem(); |
821 | if (!item ) | 822 | if (!item ) |
822 | return QString::null; | 823 | return QString::null; |
823 | 824 | ||
824 | return QDir(item->directory() ).absPath(); | 825 | return QDir(item->directory() ).absPath(); |
825 | } | 826 | } |
826 | 827 | ||
827 | void OFileViewFileSystem::reread() | 828 | void OFileViewFileSystem::reread() |
828 | { | 829 | { |
829 | if (!m_view) | 830 | if (!m_view) |
830 | return; | 831 | return; |
831 | 832 | ||
832 | m_view->reread( m_all ); | 833 | m_view->reread( m_all ); |
833 | } | 834 | } |
834 | 835 | ||
835 | int OFileViewFileSystem::fileCount()const | 836 | int OFileViewFileSystem::fileCount()const |
836 | { | 837 | { |
837 | if (!m_view ) | 838 | if (!m_view ) |
838 | return -1; | 839 | return -1; |
839 | return m_view->fileCount(); | 840 | return m_view->fileCount(); |
840 | } | 841 | } |
841 | 842 | ||
842 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) | 843 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) |
843 | { | 844 | { |
844 | if (!m_view ) | 845 | if (!m_view ) |
845 | { | 846 | { |
846 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); | 847 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); |
847 | } | 848 | } |
848 | return m_view; | 849 | return m_view; |
849 | } | 850 | } |
850 | 851 | ||
851 | void OFileViewFileSystem::activate( const QString& str ) | 852 | void OFileViewFileSystem::activate( const QString& str ) |
852 | { | 853 | { |
853 | m_all = allItem( str ); | 854 | m_all = allItem( str ); |
854 | } | 855 | } |
855 | 856 | ||
856 | 857 | ||
857 | } | 858 | } |
858 | /* Selector */ | 859 | /* Selector */ |
859 | /** | 860 | /** |
860 | * @short new and complete c'tor | 861 | * @short new and complete c'tor |
861 | * | 862 | * |
862 | * Create a OFileSelector to let the user select a file. It can | 863 | * Create a OFileSelector to let the user select a file. It can |
863 | * either be used to open a file, select a save name in a dir or | 864 | * either be used to open a file, select a save name in a dir or |
864 | * as a dropin for the FileSelector. | 865 | * as a dropin for the FileSelector. |
865 | * | 866 | * |
866 | * <pre> | 867 | * <pre> |
867 | * QMap<QString, QStringList> mimeTypes; | 868 | * QMap<QString, QStringList> mimeTypes; |
868 | * QStringList types; | 869 | * QStringList types; |
869 | * types << "text@slash* "; | 870 | * types << "text@slash* "; |
870 | * types << "audio@slash*"; | 871 | * types << "audio@slash*"; |
871 | * mimeTypes.insert( tr("Audio and Text"), types ); | 872 | * mimeTypes.insert( tr("Audio and Text"), types ); |
872 | * mimeTypes.insert( tr("All"), "*@slash*); | 873 | * mimeTypes.insert( tr("All"), "*@slash*); |
873 | * | 874 | * |
874 | * now you could create your fileselector | 875 | * now you could create your fileselector |
875 | * </pre> | 876 | * </pre> |
876 | * | 877 | * |
877 | * | 878 | * |
878 | * @param parent the parent of this widget | 879 | * @param parent the parent of this widget |
879 | * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) | 880 | * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) |
880 | * @param sel The selector to be used | 881 | * @param sel The selector to be used |
881 | * @param dirName The name of the dir to start int | 882 | * @param dirName The name of the dir to start int |
882 | * @param fileName The fileName placed in the fileselector lineedit | 883 | * @param fileName The fileName placed in the fileselector lineedit |
883 | * @param mimetypes The MimeType map of used mimetypes | 884 | * @param mimetypes The MimeType map of used mimetypes |
884 | * @param showNew Show a New Button. Most likely to be used in the FileSelector view. | 885 | * @param showNew Show a New Button. Most likely to be used in the FileSelector view. |
885 | * @param showClose Show a Close Button. Most likely to be used in FileSelector view. | 886 | * @param showClose Show a Close Button. Most likely to be used in FileSelector view. |
886 | * | 887 | * |
887 | */ | 888 | */ |
888 | OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, | 889 | OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, |
889 | const QString& dirName, const QString& fileName, | 890 | const QString& dirName, const QString& fileName, |
890 | const MimeTypes& mimetypes, | 891 | const MimeTypes& mimetypes, |
891 | bool showNew, bool showClose) | 892 | bool showNew, bool showClose) |
892 | :QWidget( parent, "OFileSelector" ) | 893 | :QWidget( parent, "OFileSelector" ) |
893 | { | 894 | { |
894 | m_current = 0; | 895 | m_current = 0; |
895 | m_shNew = showNew; | 896 | m_shNew = showNew; |
896 | m_shClose = showClose; | 897 | m_shClose = showClose; |
897 | m_mimeType = mimetypes; | 898 | m_mimeType = mimetypes; |
898 | m_startDir = dirName; | 899 | m_startDir = dirName; |
899 | 900 | ||
900 | m_mode = mode; | 901 | m_mode = mode; |
901 | m_selector = sel; | 902 | m_selector = sel; |
902 | 903 | ||
903 | m_allList = QStringList(); | 904 | m_allList = QStringList(); |
904 | 905 | ||
905 | initUI(); | 906 | initUI(); |
906 | m_lneEdit->setText( fileName ); | 907 | m_lneEdit->setText( fileName ); |
907 | initMime(); | 908 | initMime(); |
908 | initViews(); | 909 | initViews(); |
909 | 910 | ||
910 | QString str; | 911 | QString str; |
911 | switch ( m_selector ) | 912 | switch ( m_selector ) |
912 | { | 913 | { |
913 | default: | 914 | default: |
914 | case Normal: | 915 | case Normal: |
915 | if ( m_mode == DIRECTORYSELECTOR ) | 916 | if ( m_mode == DIRECTORYSELECTOR ) |
916 | str = QObject::tr("Directories"); | 917 | str = QObject::tr("Directories"); |
917 | else | 918 | else |
918 | str = QObject::tr("Documents"); | 919 | str = QObject::tr("Documents"); |
919 | m_cmbView->setCurrentItem( 0 ); | 920 | m_cmbView->setCurrentItem( 0 ); |
920 | break; | 921 | break; |
921 | case Extended: | 922 | case Extended: |
922 | if ( m_mode == DIRECTORYSELECTOR ) | 923 | if ( m_mode == DIRECTORYSELECTOR ) |
923 | { | 924 | { |
924 | str = QObject::tr("Directories"); | 925 | str = QObject::tr("Directories"); |
925 | m_cmbView->setCurrentItem( 0 ); | 926 | m_cmbView->setCurrentItem( 0 ); |
926 | } else { | 927 | } else { |
927 | str = QObject::tr("Files"); | 928 | str = QObject::tr("Files"); |
928 | m_cmbView->setCurrentItem( 1 ); | 929 | m_cmbView->setCurrentItem( 1 ); |
929 | } | 930 | } |
930 | break; | 931 | break; |
931 | case ExtendedAll: | 932 | case ExtendedAll: |
932 | if ( m_mode == DIRECTORYSELECTOR ) | 933 | if ( m_mode == DIRECTORYSELECTOR ) |
933 | { | 934 | { |
934 | str = QObject::tr("All Directories"); | 935 | str = QObject::tr("All Directories"); |
935 | m_cmbView->setCurrentItem( 1 ); | 936 | m_cmbView->setCurrentItem( 1 ); |
936 | } else { | 937 | } else { |
937 | str = QObject::tr("All Files"); | 938 | str = QObject::tr("All Files"); |
938 | m_cmbView->setCurrentItem( 2 ); | 939 | m_cmbView->setCurrentItem( 2 ); |
939 | } | 940 | } |
940 | break; | 941 | break; |
941 | } | 942 | } |
942 | slotViewChange( str ); | 943 | slotViewChange( str ); |
943 | 944 | ||
944 | } | 945 | } |
945 | 946 | ||
946 | 947 | ||
947 | /** | 948 | /** |
948 | * This a convience c'tor to just substitute the use of FileSelector | 949 | * This a convience c'tor to just substitute the use of FileSelector |
949 | */ | 950 | */ |
950 | OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, | 951 | OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, |
951 | bool showNew, bool showClose ) | 952 | bool showNew, bool showClose ) |
952 | : QWidget( parent, name ) | 953 | : QWidget( parent, name ) |
953 | { | 954 | { |
954 | m_current = 0; | 955 | m_current = 0; |
955 | m_shNew = showNew; | 956 | m_shNew = showNew; |
956 | m_shClose = showClose; | 957 | m_shClose = showClose; |
957 | m_startDir = QPEApplication::documentDir(); | 958 | m_startDir = QPEApplication::documentDir(); |
958 | 959 | ||
959 | if (!mimeFilter.isEmpty() ) | 960 | if (!mimeFilter.isEmpty() ) |
960 | m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); | 961 | m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); |
961 | 962 | ||
962 | m_mode = OFileSelector::FileSelector; | 963 | m_mode = OFileSelector::FileSelector; |
963 | m_selector = OFileSelector::Normal; | 964 | m_selector = OFileSelector::Normal; |
964 | 965 | ||
965 | initUI(); | 966 | initUI(); |
966 | initMime(); | 967 | initMime(); |
967 | initViews(); | 968 | initViews(); |
968 | m_cmbView->setCurrentItem( 0 ); | 969 | m_cmbView->setCurrentItem( 0 ); |
969 | slotViewChange( QObject::tr("Documents") ); | 970 | slotViewChange( QObject::tr("Documents") ); |
970 | } | 971 | } |
971 | 972 | ||
972 | /* | 973 | /* |
973 | * INIT UI will set up the basic GUI | 974 | * INIT UI will set up the basic GUI |
974 | * Layout: Simple VBoxLayout | 975 | * Layout: Simple VBoxLayout |
975 | * On top a WidgetStack containing the Views... | 976 | * On top a WidgetStack containing the Views... |
976 | * - List View | 977 | * - List View |
977 | * - Document View | 978 | * - Document View |
978 | * Below we will have a Label + LineEdit | 979 | * Below we will have a Label + LineEdit |
979 | * Below we will have two ComoBoxes one for choosing the view one for | 980 | * Below we will have two ComoBoxes one for choosing the view one for |
980 | * choosing the mimetype | 981 | * choosing the mimetype |
981 | */ | 982 | */ |
982 | void OFileSelector::initUI() | 983 | void OFileSelector::initUI() |
983 | { | 984 | { |
984 | QVBoxLayout* lay = new QVBoxLayout( this ); | 985 | QVBoxLayout* lay = new QVBoxLayout( this ); |
985 | 986 | ||
986 | m_stack = new QWidgetStack( this ); | 987 | m_stack = new QWidgetStack( this ); |
987 | lay->addWidget( m_stack, 1000 ); | 988 | lay->addWidget( m_stack, 1000 ); |
988 | 989 | ||
989 | m_nameBox = new QHBox( this ); | 990 | m_nameBox = new QHBox( this ); |
990 | (void)new QLabel( tr("Name:"), m_nameBox ); | 991 | (void)new QLabel( tr("Name:"), m_nameBox ); |
991 | m_lneEdit = new QLineEdit( m_nameBox ); | 992 | m_lneEdit = new QLineEdit( m_nameBox ); |
992 | m_lneEdit ->installEventFilter(this); | 993 | m_lneEdit ->installEventFilter(this); |
993 | lay->addWidget( m_nameBox ); | 994 | lay->addWidget( m_nameBox ); |
994 | 995 | ||
995 | m_cmbBox = new QHBox( this ); | 996 | m_cmbBox = new QHBox( this ); |
996 | m_cmbView = new QComboBox( m_cmbBox ); | 997 | m_cmbView = new QComboBox( m_cmbBox ); |
997 | m_cmbMime = new QComboBox( m_cmbBox ); | 998 | m_cmbMime = new QComboBox( m_cmbBox ); |
998 | lay->addWidget( m_cmbBox ); | 999 | lay->addWidget( m_cmbBox ); |
999 | } | 1000 | } |
1000 | 1001 | ||
1001 | /* | 1002 | /* |
1002 | * This will make sure that the return key in the name edit causes dialogs to close | 1003 | * This will make sure that the return key in the name edit causes dialogs to close |
1003 | */ | 1004 | */ |
1004 | 1005 | ||
1005 | bool OFileSelector::eventFilter (QObject *, QEvent *e) | 1006 | bool OFileSelector::eventFilter (QObject *, QEvent *e) |
1006 | { | 1007 | { |
1007 | if ( e->type() == QEvent::KeyPress ) | 1008 | if ( e->type() == QEvent::KeyPress ) |
1008 | { | 1009 | { |
1009 | QKeyEvent *k = (QKeyEvent *)e; | 1010 | QKeyEvent *k = (QKeyEvent *)e; |
1010 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) | 1011 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) |
1011 | { | 1012 | { |
1012 | emit ok(); | 1013 | emit ok(); |
1013 | return true; | 1014 | return true; |
1014 | } | 1015 | } |
1015 | } | 1016 | } |
1016 | return false; | 1017 | return false; |
1017 | } | 1018 | } |
1018 | 1019 | ||
1019 | /* | 1020 | /* |
1020 | * This will insert the MimeTypes into the Combo Box | 1021 | * This will insert the MimeTypes into the Combo Box |
1021 | * And also connect the changed signal | 1022 | * And also connect the changed signal |
1022 | * | 1023 | * |
1023 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes | 1024 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes |
1024 | */ | 1025 | */ |
1025 | void OFileSelector::initMime() | 1026 | void OFileSelector::initMime() |
1026 | { | 1027 | { |
1027 | MimeTypes::Iterator it; | 1028 | MimeTypes::Iterator it; |
1028 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) | 1029 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) |
1029 | { | 1030 | { |
1030 | m_cmbMime->insertItem( it.key() ); | 1031 | m_cmbMime->insertItem( it.key() ); |
1031 | } | 1032 | } |
1032 | m_cmbMime->setCurrentItem( 0 ); | 1033 | m_cmbMime->setCurrentItem( 0 ); |
1033 | 1034 | ||
1034 | connect( m_cmbMime, SIGNAL(activated(int) ), | 1035 | connect( m_cmbMime, SIGNAL(activated(int) ), |
1035 | this, SLOT(slotMimeTypeChanged() ) ); | 1036 | this, SLOT(slotMimeTypeChanged() ) ); |
1036 | 1037 | ||
1037 | } | 1038 | } |
1038 | 1039 | ||
1039 | void OFileSelector::initViews() | 1040 | void OFileSelector::initViews() |
1040 | { | 1041 | { |
1041 | if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) | 1042 | if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) |
1042 | { | 1043 | { |
1043 | m_cmbView->insertItem( QObject::tr("Directories") ); | 1044 | m_cmbView->insertItem( QObject::tr("Directories") ); |
1044 | m_cmbView->insertItem( QObject::tr("All Directories") ); | 1045 | m_cmbView->insertItem( QObject::tr("All Directories") ); |
1045 | } else { | 1046 | } else { |
1046 | m_cmbView->insertItem( QObject::tr("Documents") ); | 1047 | m_cmbView->insertItem( QObject::tr("Documents") ); |
1047 | m_cmbView->insertItem( QObject::tr("Files") ); | 1048 | m_cmbView->insertItem( QObject::tr("Files") ); |
1048 | m_cmbView->insertItem( QObject::tr("All Files") ); | 1049 | m_cmbView->insertItem( QObject::tr("All Files") ); |
1049 | } | 1050 | } |
1050 | 1051 | ||
1051 | connect(m_cmbView, SIGNAL(activated(const QString&) ), | 1052 | connect(m_cmbView, SIGNAL(activated(const QString&) ), |
1052 | this, SLOT(slotViewChange(const QString&) ) ); | 1053 | this, SLOT(slotViewChange(const QString&) ) ); |
1053 | 1054 | ||
1054 | /* see above why add both */ | 1055 | /* see above why add both */ |
1055 | OFileViewInterface* in = new OFileViewFileSystem( this ); | 1056 | OFileViewInterface* in = new OFileViewFileSystem( this ); |
1056 | 1057 | ||
1057 | if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) | 1058 | if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) |
1058 | { | 1059 | { |
1059 | m_views.insert( QObject::tr("Directories"), in ); | 1060 | m_views.insert( QObject::tr("Directories"), in ); |
1060 | m_views.insert( QObject::tr("All Directories"), in ); | 1061 | m_views.insert( QObject::tr("All Directories"), in ); |
1061 | m_allList.append( QObject::tr("All Directories") ); | 1062 | m_allList.append( QObject::tr("All Directories") ); |
1062 | } else { | 1063 | } else { |
1063 | m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); | 1064 | m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); |
1064 | m_views.insert( QObject::tr("Files"), in ); | 1065 | m_views.insert( QObject::tr("Files"), in ); |
1065 | m_views.insert( QObject::tr("All Files"), in ); | 1066 | m_views.insert( QObject::tr("All Files"), in ); |
1066 | m_allList.append( QObject::tr("All Files") ); | 1067 | m_allList.append( QObject::tr("All Files") ); |
1067 | } | 1068 | } |
1068 | } | 1069 | } |
1069 | 1070 | ||
1070 | void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) { | 1071 | void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) { |
1071 | m_viewsPtr.append( iface ); | 1072 | m_viewsPtr.append( iface ); |
1072 | } | 1073 | } |
1073 | 1074 | ||
1074 | 1075 | ||
1075 | /** | 1076 | /** |
1076 | * d'tor | 1077 | * d'tor |
1077 | */ | 1078 | */ |
1078 | OFileSelector::~OFileSelector() | 1079 | OFileSelector::~OFileSelector() |
1079 | { | 1080 | { |
1080 | m_viewsPtr.setAutoDelete( true ); | 1081 | m_viewsPtr.setAutoDelete( true ); |
1081 | m_viewsPtr.clear(); | 1082 | m_viewsPtr.clear(); |
1082 | } | 1083 | } |
1083 | 1084 | ||
1084 | 1085 | ||
1085 | 1086 | ||
1086 | /** | 1087 | /** |
1087 | * Convience function for the fileselector | 1088 | * Convience function for the fileselector |
1088 | * make sure to delete the DocLnk | 1089 | * make sure to delete the DocLnk |
1089 | * | 1090 | * |
1090 | * @see DocLnk | 1091 | * @see DocLnk |
1091 | * @todo remove in ODP | 1092 | * @todo remove in ODP |
1092 | */ | 1093 | */ |
1093 | const DocLnk* OFileSelector::selected() | 1094 | const DocLnk* OFileSelector::selected() |
1094 | { | 1095 | { |
1095 | DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); | 1096 | DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); |
1096 | return lnk; | 1097 | return lnk; |
1097 | } | 1098 | } |
1098 | 1099 | ||
1099 | /** | 1100 | /** |
1100 | * | 1101 | * |
1101 | * @return the name of the selected file | 1102 | * @return the name of the selected file |
1102 | */ | 1103 | */ |
1103 | QString OFileSelector::selectedName()const | 1104 | QString OFileSelector::selectedName()const |
1104 | { | 1105 | { |
1105 | return currentView()->selectedName(); | 1106 | return currentView()->selectedName(); |
1106 | } | 1107 | } |
1107 | 1108 | ||
1108 | 1109 | ||
1109 | /** | 1110 | /** |
1110 | * @return the selected path | 1111 | * @return the selected path |
1111 | */ | 1112 | */ |
1112 | QString OFileSelector::selectedPath()const | 1113 | QString OFileSelector::selectedPath()const |
1113 | { | 1114 | { |
1114 | return currentView()->selectedPath(); | 1115 | return currentView()->selectedPath(); |
1115 | } | 1116 | } |
1116 | 1117 | ||
1117 | /** | 1118 | /** |
1118 | * @return the directory name | 1119 | * @return the directory name |
1119 | */ | 1120 | */ |
1120 | QString OFileSelector::directory()const | 1121 | QString OFileSelector::directory()const |
1121 | { | 1122 | { |
1122 | return currentView()->directory(); | 1123 | return currentView()->directory(); |
1123 | } | 1124 | } |
1124 | 1125 | ||
1125 | /** | 1126 | /** |
1126 | * @return a DocLnk for the selected document | 1127 | * @return a DocLnk for the selected document |
1127 | */ | 1128 | */ |
1128 | DocLnk OFileSelector::selectedDocument()const | 1129 | DocLnk OFileSelector::selectedDocument()const |
1129 | { | 1130 | { |
1130 | return currentView()->selectedDocument(); | 1131 | return currentView()->selectedDocument(); |
1131 | } | 1132 | } |
1132 | 1133 | ||
1133 | /** | 1134 | /** |
1134 | * @return the number of items for the current view | 1135 | * @return the number of items for the current view |
1135 | */ | 1136 | */ |
1136 | int OFileSelector::fileCount()const | 1137 | int OFileSelector::fileCount()const |
1137 | { | 1138 | { |
1138 | return currentView()->fileCount(); | 1139 | return currentView()->fileCount(); |
1139 | } | 1140 | } |
1140 | 1141 | ||
1141 | /** | 1142 | /** |
1142 | * @return reparse the file content | 1143 | * @return reparse the file content |
1143 | */ | 1144 | */ |
1144 | void OFileSelector::reread() | 1145 | void OFileSelector::reread() |
1145 | { | 1146 | { |
1146 | return currentView()->reread(); | 1147 | return currentView()->reread(); |
1147 | } | 1148 | } |
1148 | 1149 | ||
1149 | OFileViewInterface* OFileSelector::currentView()const | 1150 | OFileViewInterface* OFileSelector::currentView()const |
1150 | { | 1151 | { |
1151 | return m_current; | 1152 | return m_current; |
1152 | } | 1153 | } |
1153 | 1154 | ||
1154 | bool OFileSelector::showNew()const | 1155 | bool OFileSelector::showNew()const |
1155 | { | 1156 | { |
1156 | return m_shNew; | 1157 | return m_shNew; |
1157 | } | 1158 | } |
1158 | 1159 | ||
1159 | bool OFileSelector::showClose()const | 1160 | bool OFileSelector::showClose()const |
1160 | { | 1161 | { |
1161 | return m_shClose; | 1162 | return m_shClose; |
1162 | } | 1163 | } |
1163 | 1164 | ||
1164 | MimeTypes OFileSelector::mimeTypes()const | 1165 | MimeTypes OFileSelector::mimeTypes()const |
1165 | { | 1166 | { |
1166 | return m_mimeType; | 1167 | return m_mimeType; |
1167 | } | 1168 | } |
1168 | 1169 | ||
1169 | /** | 1170 | /** |
1170 | * @return the Mode of the OFileSelector | 1171 | * @return the Mode of the OFileSelector |
1171 | */ | 1172 | */ |
1172 | int OFileSelector::mode()const | 1173 | int OFileSelector::mode()const |
1173 | { | 1174 | { |
1174 | return m_mode; | 1175 | return m_mode; |
1175 | } | 1176 | } |
1176 | 1177 | ||
1177 | 1178 | ||
1178 | /** | 1179 | /** |
1179 | * @return the Selector of the OFileSelector | 1180 | * @return the Selector of the OFileSelector |
1180 | */ | 1181 | */ |
1181 | int OFileSelector::selector()const | 1182 | int OFileSelector::selector()const |
1182 | { | 1183 | { |
1183 | return m_selector; | 1184 | return m_selector; |
1184 | } | 1185 | } |
1185 | 1186 | ||
1186 | QStringList OFileSelector::currentMimeType()const | 1187 | QStringList OFileSelector::currentMimeType()const |
1187 | { | 1188 | { |
1188 | return m_mimeType[m_cmbMime->currentText()]; | 1189 | return m_mimeType[m_cmbMime->currentText()]; |
1189 | } | 1190 | } |
1190 | 1191 | ||
1191 | void OFileSelector::slotMimeTypeChanged() | 1192 | void OFileSelector::slotMimeTypeChanged() |
1192 | { | 1193 | { |
1193 | reread(); | 1194 | reread(); |
1194 | } | 1195 | } |
1195 | 1196 | ||
1196 | void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) | 1197 | void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) |
1197 | { | 1198 | { |
1198 | m_lneEdit->setText( lnk.name() ); | 1199 | m_lneEdit->setText( lnk.name() ); |
1199 | emit fileSelected( lnk ); | 1200 | emit fileSelected( lnk ); |
1200 | emit fileSelected( lnk.name() ); | 1201 | emit fileSelected( lnk.name() ); |
1201 | } | 1202 | } |
1202 | 1203 | ||
1203 | void OFileSelector::slotFileBridge( const QString& str) | 1204 | void OFileSelector::slotFileBridge( const QString& str) |
1204 | { | 1205 | { |
1205 | DocLnk lnk( str ); | 1206 | DocLnk lnk( str ); |
1206 | emit fileSelected( lnk ); | 1207 | emit fileSelected( lnk ); |
1207 | } | 1208 | } |
1208 | 1209 | ||
1209 | void OFileSelector::slotViewChange( const QString& view ) | 1210 | void OFileSelector::slotViewChange( const QString& view ) |
1210 | { | 1211 | { |
1211 | OFileViewInterface* interface = m_views[view]; | 1212 | OFileViewInterface* interface = m_views[view]; |
1212 | if (!interface) | 1213 | if (!interface) |
1213 | return; | 1214 | return; |
1214 | 1215 | ||
1215 | if (m_current) | 1216 | if (m_current) |
1216 | m_stack->removeWidget( m_current->widget( m_stack ) ); | 1217 | m_stack->removeWidget( m_current->widget( m_stack ) ); |
1217 | 1218 | ||
1218 | static int id = 1; | 1219 | static int id = 1; |
1219 | 1220 | ||
1220 | m_stack->addWidget( interface->widget(m_stack), id ); | 1221 | m_stack->addWidget( interface->widget(m_stack), id ); |
1221 | m_stack->raiseWidget( id ); | 1222 | m_stack->raiseWidget( id ); |
1222 | 1223 | ||
1223 | interface->activate( view ); | 1224 | interface->activate( view ); |
1224 | interface->reread(); | 1225 | interface->reread(); |
1225 | m_current = interface; | 1226 | m_current = interface; |
1226 | 1227 | ||
1227 | id++; | 1228 | id++; |
1228 | } | 1229 | } |
1229 | 1230 | ||
1230 | void OFileSelector::setNewVisible( bool b ) | 1231 | void OFileSelector::setNewVisible( bool b ) |
1231 | { | 1232 | { |
1232 | m_shNew = b; | 1233 | m_shNew = b; |
1233 | currentView()->reread(); | 1234 | currentView()->reread(); |
1234 | } | 1235 | } |
1235 | 1236 | ||
1236 | void OFileSelector::setCloseVisible( bool b ) | 1237 | void OFileSelector::setCloseVisible( bool b ) |
1237 | { | 1238 | { |
1238 | m_shClose = b; | 1239 | m_shClose = b; |
1239 | currentView()->reread(); | 1240 | currentView()->reread(); |
1240 | } | 1241 | } |
1241 | 1242 | ||
1242 | void OFileSelector::setNameVisible( bool b ) | 1243 | void OFileSelector::setNameVisible( bool b ) |
1243 | { | 1244 | { |
1244 | if ( b ) | 1245 | if ( b ) |
1245 | m_nameBox->show(); | 1246 | m_nameBox->show(); |
1246 | else | 1247 | else |
1247 | m_nameBox->hide(); | 1248 | m_nameBox->hide(); |
1248 | } | 1249 | } |
1249 | 1250 | ||
1250 | } | 1251 | } |
1251 | } | 1252 | } |