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