-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp index f3e7501..a30bd8b 100644 --- a/libopie2/opieui/fileselector/ofileselector.cpp +++ b/libopie2/opieui/fileselector/ofileselector.cpp | |||
@@ -1,882 +1,883 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> | 4 | Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* hacky but we need to get FileSelector::filter */ | 31 | /* hacky but we need to get FileSelector::filter */ |
32 | #define private public | 32 | #define private public |
33 | #include <qpe/fileselector.h> | 33 | #include <qpe/fileselector.h> |
34 | #undef private | 34 | #undef private |
35 | 35 | ||
36 | #include "ofileselector_p.h" | 36 | #include "ofileselector_p.h" |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | #include <opie2/odebug.h> | 39 | #include <opie2/odebug.h> |
40 | #include <opie2/ofileselector.h> | 40 | #include <opie2/ofileselector.h> |
41 | #include <opie2/oresource.h> | 41 | #include <opie2/oresource.h> |
42 | 42 | ||
43 | #include <qpe/qpeapplication.h> | 43 | #include <qpe/qpeapplication.h> |
44 | #include <qpe/mimetype.h> | 44 | #include <qpe/mimetype.h> |
45 | #include <qpe/storage.h> | 45 | #include <qpe/storage.h> |
46 | 46 | ||
47 | /* QT */ | 47 | /* QT */ |
48 | #include <qcombobox.h> | 48 | #include <qcombobox.h> |
49 | #include <qdir.h> | 49 | #include <qdir.h> |
50 | #include <qhbox.h> | 50 | #include <qhbox.h> |
51 | #include <qheader.h> | 51 | #include <qheader.h> |
52 | #include <qlabel.h> | 52 | #include <qlabel.h> |
53 | #include <qlayout.h> | 53 | #include <qlayout.h> |
54 | #include <qlineedit.h> | 54 | #include <qlineedit.h> |
55 | #include <qlistview.h> | 55 | #include <qlistview.h> |
56 | #include <qpopupmenu.h> | 56 | #include <qpopupmenu.h> |
57 | #include <qwidgetstack.h> | 57 | #include <qwidgetstack.h> |
58 | #include <qregexp.h> | 58 | #include <qregexp.h> |
59 | #include <qobjectlist.h> | 59 | #include <qobjectlist.h> |
60 | 60 | ||
61 | using namespace Opie::Ui::Internal; | 61 | using namespace Opie::Ui::Internal; |
62 | 62 | ||
63 | namespace Opie { | 63 | namespace Opie { |
64 | namespace Ui { | 64 | namespace Ui { |
65 | namespace Internal { | 65 | namespace Internal { |
66 | /* | 66 | /* |
67 | * Create a path by adding a '/'/QDir::seperator in between | 67 | * Create a path by adding a '/'/QDir::seperator in between |
68 | * base and ending, but only if base is not empty | 68 | * base and ending, but only if base is not empty |
69 | */ | 69 | */ |
70 | static inline QString createNewPath(const QString& base, const QString &ending) { | 70 | static inline QString createNewPath(const QString& base, const QString &ending) { |
71 | return base == QString::fromLatin1("/") ? | 71 | return base == QString::fromLatin1("/") ? |
72 | base + ending : base + "/" + ending; | 72 | base + ending : base + "/" + ending; |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | OFileViewInterface::OFileViewInterface( OFileSelector* _selector ) | 76 | OFileViewInterface::OFileViewInterface( OFileSelector* _selector ) |
77 | : m_selector( _selector ) | 77 | : m_selector( _selector ) |
78 | { | 78 | { |
79 | selector()->registerView( this ); | 79 | selector()->registerView( this ); |
80 | } | 80 | } |
81 | 81 | ||
82 | OFileViewInterface::~OFileViewInterface() | 82 | OFileViewInterface::~OFileViewInterface() |
83 | {} | 83 | {} |
84 | 84 | ||
85 | QString OFileViewInterface::name()const | 85 | QString OFileViewInterface::name()const |
86 | { | 86 | { |
87 | return m_name; | 87 | return m_name; |
88 | } | 88 | } |
89 | 89 | ||
90 | void OFileViewInterface::setName( const QString& name ) | 90 | void OFileViewInterface::setName( const QString& name ) |
91 | { | 91 | { |
92 | m_name = name; | 92 | m_name = name; |
93 | } | 93 | } |
94 | 94 | ||
95 | OFileSelector* OFileViewInterface::selector()const | 95 | OFileSelector* OFileViewInterface::selector()const |
96 | { | 96 | { |
97 | return m_selector; | 97 | return m_selector; |
98 | } | 98 | } |
99 | 99 | ||
100 | DocLnk OFileViewInterface::selectedDocument()const | 100 | DocLnk OFileViewInterface::selectedDocument()const |
101 | { | 101 | { |
102 | return DocLnk( selectedName() ); | 102 | return DocLnk( selectedName() ); |
103 | } | 103 | } |
104 | 104 | ||
105 | bool OFileViewInterface::showNew()const | 105 | bool OFileViewInterface::showNew()const |
106 | { | 106 | { |
107 | return selector()->showNew(); | 107 | return selector()->showNew(); |
108 | } | 108 | } |
109 | 109 | ||
110 | bool OFileViewInterface::showClose()const | 110 | bool OFileViewInterface::showClose()const |
111 | { | 111 | { |
112 | return selector()->showClose(); | 112 | return selector()->showClose(); |
113 | } | 113 | } |
114 | 114 | ||
115 | MimeTypes OFileViewInterface::mimeTypes()const | 115 | MimeTypes OFileViewInterface::mimeTypes()const |
116 | { | 116 | { |
117 | return selector()->mimeTypes(); | 117 | return selector()->mimeTypes(); |
118 | } | 118 | } |
119 | 119 | ||
120 | QStringList OFileViewInterface::currentMimeType()const | 120 | QStringList OFileViewInterface::currentMimeType()const |
121 | { | 121 | { |
122 | return selector()->currentMimeType(); | 122 | return selector()->currentMimeType(); |
123 | } | 123 | } |
124 | 124 | ||
125 | void OFileViewInterface::activate( const QString& ) | 125 | void OFileViewInterface::activate( const QString& ) |
126 | { | 126 | { |
127 | // not implemented here | 127 | // not implemented here |
128 | } | 128 | } |
129 | 129 | ||
130 | void OFileViewInterface::ok() | 130 | void OFileViewInterface::ok() |
131 | { | 131 | { |
132 | emit selector()->ok(); | 132 | emit selector()->ok(); |
133 | } | 133 | } |
134 | 134 | ||
135 | void OFileViewInterface::cancel() | 135 | void OFileViewInterface::cancel() |
136 | { | 136 | { |
137 | emit selector()->cancel(); | 137 | emit selector()->cancel(); |
138 | } | 138 | } |
139 | 139 | ||
140 | void OFileViewInterface::closeMe() | 140 | void OFileViewInterface::closeMe() |
141 | { | 141 | { |
142 | emit selector()->closeMe(); | 142 | emit selector()->closeMe(); |
143 | } | 143 | } |
144 | 144 | ||
145 | void OFileViewInterface::fileSelected( const QString& str) | 145 | void OFileViewInterface::fileSelected( const QString& str) |
146 | { | 146 | { |
147 | emit selector()->fileSelected( str); | 147 | emit selector()->fileSelected( str); |
148 | } | 148 | } |
149 | 149 | ||
150 | void OFileViewInterface::fileSelected( const DocLnk& lnk) | 150 | void OFileViewInterface::fileSelected( const DocLnk& lnk) |
151 | { | 151 | { |
152 | emit selector()->fileSelected( lnk ); | 152 | emit selector()->fileSelected( lnk ); |
153 | } | 153 | } |
154 | 154 | ||
155 | void OFileViewInterface::setCurrentFileName( const QString& str ) | 155 | void OFileViewInterface::setCurrentFileName( const QString& str ) |
156 | { | 156 | { |
157 | selector()->m_lneEdit->setText( str ); | 157 | selector()->m_lneEdit->setText( str ); |
158 | } | 158 | } |
159 | 159 | ||
160 | QString OFileViewInterface::currentFileName()const | 160 | QString OFileViewInterface::currentFileName()const |
161 | { | 161 | { |
162 | return selector()->m_lneEdit->text(); | 162 | return selector()->m_lneEdit->text(); |
163 | } | 163 | } |
164 | 164 | ||
165 | QString OFileViewInterface::startDirectory()const | 165 | QString OFileViewInterface::startDirectory()const |
166 | { | 166 | { |
167 | return selector()->m_startDir; | 167 | return selector()->m_startDir; |
168 | } | 168 | } |
169 | 169 | ||
170 | bool OFileViewInterface::allItem( const QString& item )const | 170 | bool OFileViewInterface::allItem( const QString& item )const |
171 | { | 171 | { |
172 | return selector()->m_allList.contains( item ); | 172 | return selector()->m_allList.contains( item ); |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) | 176 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) |
177 | :OFileViewInterface( selector ) | 177 | :OFileViewInterface( selector ) |
178 | { | 178 | { |
179 | m_selector = 0; | 179 | m_selector = 0; |
180 | setName( QObject::tr("Documents") ); | 180 | setName( QObject::tr("Documents") ); |
181 | } | 181 | } |
182 | 182 | ||
183 | ODocumentFileView::~ODocumentFileView() | 183 | ODocumentFileView::~ODocumentFileView() |
184 | { | 184 | { |
185 | } | 185 | } |
186 | 186 | ||
187 | QString ODocumentFileView::selectedName()const | 187 | QString ODocumentFileView::selectedName()const |
188 | { | 188 | { |
189 | if (!m_selector) | 189 | if (!m_selector) |
190 | return QString::null; | 190 | return QString::null; |
191 | 191 | ||
192 | return m_selector->selectedDocument().file(); | 192 | return m_selector->selectedDocument().file(); |
193 | } | 193 | } |
194 | 194 | ||
195 | QString ODocumentFileView::selectedPath()const | 195 | QString ODocumentFileView::selectedPath()const |
196 | { | 196 | { |
197 | return QPEApplication::documentDir(); | 197 | return QPEApplication::documentDir(); |
198 | } | 198 | } |
199 | 199 | ||
200 | QString ODocumentFileView::directory()const | 200 | QString ODocumentFileView::directory()const |
201 | { | 201 | { |
202 | return selectedPath(); | 202 | return selectedPath(); |
203 | } | 203 | } |
204 | 204 | ||
205 | void ODocumentFileView::reread() | 205 | void ODocumentFileView::reread() |
206 | { | 206 | { |
207 | if (!m_selector) | 207 | if (!m_selector) |
208 | return; | 208 | return; |
209 | 209 | ||
210 | m_selector->setNewVisible( showNew() ); | 210 | m_selector->setNewVisible( showNew() ); |
211 | m_selector->setCloseVisible( showClose() ); | 211 | m_selector->setCloseVisible( showClose() ); |
212 | m_selector->filter = currentMimeType().join(";"); | 212 | m_selector->filter = currentMimeType().join(";"); |
213 | m_selector->reread(); | 213 | m_selector->reread(); |
214 | } | 214 | } |
215 | 215 | ||
216 | int ODocumentFileView::fileCount()const | 216 | int ODocumentFileView::fileCount()const |
217 | { | 217 | { |
218 | if (!m_selector) | 218 | if (!m_selector) |
219 | return -1; | 219 | return -1; |
220 | 220 | ||
221 | return m_selector->fileCount(); | 221 | return m_selector->fileCount(); |
222 | } | 222 | } |
223 | 223 | ||
224 | DocLnk ODocumentFileView::selectedDocument()const | 224 | DocLnk ODocumentFileView::selectedDocument()const |
225 | { | 225 | { |
226 | if (!m_selector) | 226 | if (!m_selector) |
227 | return DocLnk(); | 227 | return DocLnk(); |
228 | 228 | ||
229 | return m_selector->selectedDocument(); | 229 | return m_selector->selectedDocument(); |
230 | } | 230 | } |
231 | 231 | ||
232 | QWidget* ODocumentFileView::widget( QWidget* parent ) | 232 | QWidget* ODocumentFileView::widget( QWidget* parent ) |
233 | { | 233 | { |
234 | if (!m_selector ) | 234 | if (!m_selector ) |
235 | { | 235 | { |
236 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); | 236 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); |
237 | QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ), | 237 | QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ), |
238 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); | 238 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); |
239 | QObject::connect(m_selector, SIGNAL(closeMe() ), | 239 | QObject::connect(m_selector, SIGNAL(closeMe() ), |
240 | selector(), SIGNAL(closeMe() ) ); | 240 | selector(), SIGNAL(closeMe() ) ); |
241 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ), | 241 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ), |
242 | selector(), SIGNAL(newSelected(const DocLnk&) ) ); | 242 | selector(), SIGNAL(newSelected(const DocLnk&) ) ); |
243 | } | 243 | } |
244 | 244 | ||
245 | return m_selector; | 245 | return m_selector; |
246 | } | 246 | } |
247 | 247 | ||
248 | /* | 248 | /* |
249 | * This is the file system view used | 249 | * This is the file system view used |
250 | * we use a QListView + QListViewItems for it | 250 | * we use a QListView + QListViewItems for it |
251 | */ | 251 | */ |
252 | 252 | ||
253 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, | 253 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, |
254 | const QString& path, const QString& date, | 254 | const QString& path, const QString& date, |
255 | const QString& size, const QString& dir, | 255 | const QString& size, const QString& dir, |
256 | bool isLocked, bool isDir ) | 256 | bool isLocked, bool isDir ) |
257 | : QListViewItem( view ), m_dir(dir), m_isDir(isDir), m_locked(isLocked) | 257 | : QListViewItem( view ), m_dir(dir), m_isDir(isDir), m_locked(isLocked) |
258 | { | 258 | { |
259 | setPixmap(0, pixmap ); | 259 | setPixmap(0, pixmap ); |
260 | setText(1, path ); | 260 | setText(1, path ); |
261 | setText(2, size ); | 261 | setText(2, size ); |
262 | setText(3, date ); | 262 | setText(3, date ); |
263 | } | 263 | } |
264 | 264 | ||
265 | OFileSelectorItem::~OFileSelectorItem() | 265 | OFileSelectorItem::~OFileSelectorItem() |
266 | { | 266 | { |
267 | } | 267 | } |
268 | 268 | ||
269 | bool OFileSelectorItem::isLocked()const | 269 | bool OFileSelectorItem::isLocked()const |
270 | { | 270 | { |
271 | return m_locked; | 271 | return m_locked; |
272 | } | 272 | } |
273 | 273 | ||
274 | QString OFileSelectorItem::directory()const | 274 | QString OFileSelectorItem::directory()const |
275 | { | 275 | { |
276 | return m_dir; | 276 | return m_dir; |
277 | } | 277 | } |
278 | 278 | ||
279 | bool OFileSelectorItem::isDir()const | 279 | bool OFileSelectorItem::isDir()const |
280 | { | 280 | { |
281 | return m_isDir; | 281 | return m_isDir; |
282 | } | 282 | } |
283 | 283 | ||
284 | QString OFileSelectorItem::path()const | 284 | QString OFileSelectorItem::path()const |
285 | { | 285 | { |
286 | return text( 1 ); | 286 | return text( 1 ); |
287 | } | 287 | } |
288 | 288 | ||
289 | QString OFileSelectorItem::key( int id, bool )const | 289 | QString OFileSelectorItem::key( int id, bool )const |
290 | { | 290 | { |
291 | QString ke; | 291 | QString ke; |
292 | 292 | ||
293 | /* | 293 | /* |
294 | * id = 0 ||id == 1 : Sort By Name but Directories at Top | 294 | * id = 0 ||id == 1 : Sort By Name but Directories at Top |
295 | * id = 2 : Sort By Size: Prepend '0' to the key | 295 | * id = 2 : Sort By Size: Prepend '0' to the key |
296 | */ | 296 | */ |
297 | if( id == 0 || id == 1 ) | 297 | if( id == 0 || id == 1 ) |
298 | { // name | 298 | { // name |
299 | if( m_isDir ) | 299 | if( m_isDir ) |
300 | { | 300 | { |
301 | ke.append("0" ); | 301 | ke.append("0" ); |
302 | ke.append( text(1) ); | 302 | ke.append( text(1) ); |
303 | } | 303 | } |
304 | else | 304 | else |
305 | { | 305 | { |
306 | ke.append("1" ); | 306 | ke.append("1" ); |
307 | ke.append( text(1) ); | 307 | ke.append( text(1) ); |
308 | } | 308 | } |
309 | return ke; | 309 | return ke; |
310 | }else if(id == 2) { | 310 | }else if(id == 2) { |
311 | return text(2).rightJustify(20, '0'); | 311 | return text(2).rightJustify(20, '0'); |
312 | }else | 312 | }else |
313 | return text( id ); | 313 | return text( id ); |
314 | 314 | ||
315 | } | 315 | } |
316 | 316 | ||
317 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel) | 317 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel) |
318 | :QWidget( parent ), m_sel( sel ) | 318 | :QWidget( parent ), m_sel( sel ) |
319 | { | 319 | { |
320 | m_all = false; | 320 | m_all = false; |
321 | QVBoxLayout* lay = new QVBoxLayout( this ); | 321 | QVBoxLayout* lay = new QVBoxLayout( this ); |
322 | m_currentDir = startDir; | 322 | m_currentDir = startDir; |
323 | bool bigicons = qApp->desktop()->size().width()>330; | ||
323 | 324 | ||
324 | /* | 325 | /* |
325 | * now we add a special bar | 326 | * now we add a special bar |
326 | * One Button For Up | 327 | * One Button For Up |
327 | * Home | 328 | * Home |
328 | * Doc | 329 | * Doc |
329 | * And a dropdown menu with FileSystems | 330 | * And a dropdown menu with FileSystems |
330 | * FUTURE: one to change dir with lineedit | 331 | * FUTURE: one to change dir with lineedit |
331 | * Bookmarks | 332 | * Bookmarks |
332 | * Create Dir | 333 | * Create Dir |
333 | */ | 334 | */ |
334 | QHBox* box = new QHBox(this ); | 335 | QHBox* box = new QHBox(this ); |
335 | box->setBackgroundMode( PaletteButton ); | 336 | box->setBackgroundMode( PaletteButton ); |
336 | box->setSpacing( 0 ); | 337 | box->setSpacing( 0 ); |
337 | 338 | ||
338 | QToolButton *btn = new QToolButton( box ); | 339 | QToolButton *btn = new QToolButton( box ); |
339 | btn->setUsesBigPixmap( true ); | 340 | btn->setUsesBigPixmap(bigicons); |
340 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "up", Opie::Core::OResource::SmallIcon ) ); | 341 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "up", Opie::Core::OResource::SmallIcon ) ); |
341 | connect(btn, SIGNAL(clicked() ), | 342 | connect(btn, SIGNAL(clicked() ), |
342 | this, SLOT( cdUP() ) ); | 343 | this, SLOT( cdUP() ) ); |
343 | 344 | ||
344 | btn = new QToolButton( box ); | 345 | btn = new QToolButton( box ); |
345 | btn->setUsesBigPixmap( true ); | 346 | btn->setUsesBigPixmap(bigicons); |
346 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "home", Opie::Core::OResource::SmallIcon ) ); | 347 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "home", Opie::Core::OResource::SmallIcon ) ); |
347 | connect(btn, SIGNAL(clicked() ), | 348 | connect(btn, SIGNAL(clicked() ), |
348 | this, SLOT( cdHome() ) ); | 349 | this, SLOT( cdHome() ) ); |
349 | 350 | ||
350 | btn = new QToolButton( box ); | 351 | btn = new QToolButton( box ); |
351 | btn->setUsesBigPixmap( true ); | 352 | btn->setUsesBigPixmap(bigicons); |
352 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "DocsIcon", Opie::Core::OResource::SmallIcon ) ); | 353 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "DocsIcon", Opie::Core::OResource::SmallIcon ) ); |
353 | connect(btn, SIGNAL(clicked() ), | 354 | connect(btn, SIGNAL(clicked() ), |
354 | this, SLOT(cdDoc() ) ); | 355 | this, SLOT(cdDoc() ) ); |
355 | 356 | ||
356 | m_btnNew = new QToolButton( box ); | 357 | m_btnNew = new QToolButton( box ); |
357 | m_btnNew->setUsesBigPixmap( true ); | 358 | m_btnNew->setUsesBigPixmap(bigicons); |
358 | m_btnNew->setPixmap( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ) ); | 359 | m_btnNew->setPixmap( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ) ); |
359 | connect(m_btnNew, SIGNAL(clicked() ), | 360 | connect(m_btnNew, SIGNAL(clicked() ), |
360 | this, SLOT(slotNew() ) ); | 361 | this, SLOT(slotNew() ) ); |
361 | 362 | ||
362 | 363 | ||
363 | m_btnClose = new QToolButton( box ); | 364 | m_btnClose = new QToolButton( box ); |
364 | m_btnClose->setUsesBigPixmap( true ); | 365 | m_btnClose->setUsesBigPixmap(bigicons); |
365 | m_btnClose->setPixmap( Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ) ); | 366 | m_btnClose->setPixmap( Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ) ); |
366 | connect(m_btnClose, SIGNAL(clicked() ), | 367 | connect(m_btnClose, SIGNAL(clicked() ), |
367 | selector(), SIGNAL(closeMe() ) ); | 368 | selector(), SIGNAL(closeMe() ) ); |
368 | 369 | ||
369 | btn = new QToolButton( box ); | 370 | btn = new QToolButton( box ); |
370 | btn->setUsesBigPixmap( true ); | 371 | btn->setUsesBigPixmap(bigicons); |
371 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ) ); | 372 | btn->setPixmap( Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ) ); |
372 | 373 | ||
373 | m_fsButton = btn; | 374 | m_fsButton = btn; |
374 | /* let's fill device parts */ | 375 | /* let's fill device parts */ |
375 | QPopupMenu* pop = new QPopupMenu(this); | 376 | QPopupMenu* pop = new QPopupMenu(this); |
376 | connect(pop, SIGNAL( activated(int) ), | 377 | connect(pop, SIGNAL( activated(int) ), |
377 | this, SLOT(slotFSActivated(int) ) ); | 378 | this, SLOT(slotFSActivated(int) ) ); |
378 | 379 | ||
379 | StorageInfo storage; | 380 | StorageInfo storage; |
380 | const QList<FileSystem> &fs = storage.fileSystems(); | 381 | const QList<FileSystem> &fs = storage.fileSystems(); |
381 | QListIterator<FileSystem> it(fs); | 382 | QListIterator<FileSystem> it(fs); |
382 | for ( ; it.current(); ++it ) | 383 | for ( ; it.current(); ++it ) |
383 | { | 384 | { |
384 | const QString disk = (*it)->name(); | 385 | const QString disk = (*it)->name(); |
385 | const QString path = (*it)->path(); | 386 | const QString path = (*it)->path(); |
386 | m_dev.insert( disk, path ); | 387 | m_dev.insert( disk, path ); |
387 | pop->insertItem( disk ); | 388 | pop->insertItem( disk ); |
388 | } | 389 | } |
389 | m_fsPop = pop; | 390 | m_fsPop = pop; |
390 | 391 | ||
391 | connect(btn,SIGNAL(pressed()),this,SLOT(slotFSpressed())); | 392 | connect(btn,SIGNAL(pressed()),this,SLOT(slotFSpressed())); |
392 | 393 | ||
393 | lay->addWidget( box ); | 394 | lay->addWidget( box ); |
394 | 395 | ||
395 | m_view = new QListView( this ); | 396 | m_view = new QListView( this ); |
396 | 397 | ||
397 | m_view->installEventFilter(this); | 398 | m_view->installEventFilter(this); |
398 | 399 | ||
399 | QPEApplication::setStylusOperation( m_view->viewport(), | 400 | QPEApplication::setStylusOperation( m_view->viewport(), |
400 | QPEApplication::RightOnHold); | 401 | QPEApplication::RightOnHold); |
401 | m_view->addColumn(" " ); | 402 | m_view->addColumn(" " ); |
402 | m_view->addColumn(tr("Name"), 135 ); | 403 | m_view->addColumn(tr("Name"), 135 ); |
403 | m_view->addColumn(tr("Size"), -1 ); | 404 | m_view->addColumn(tr("Size"), -1 ); |
404 | m_view->addColumn(tr("Date"), 60 ); | 405 | m_view->addColumn(tr("Date"), 60 ); |
405 | m_view->addColumn(tr("Mime Type"), -1 ); | 406 | m_view->addColumn(tr("Mime Type"), -1 ); |
406 | 407 | ||
407 | 408 | ||
408 | m_view->setSorting( 1 ); | 409 | m_view->setSorting( 1 ); |
409 | m_view->setAllColumnsShowFocus( TRUE ); | 410 | m_view->setAllColumnsShowFocus( TRUE ); |
410 | 411 | ||
411 | lay->addWidget( m_view, 1000 ); | 412 | lay->addWidget( m_view, 1000 ); |
412 | connectSlots(); | 413 | connectSlots(); |
413 | } | 414 | } |
414 | 415 | ||
415 | void OFileViewFileListView::slotFSpressed() | 416 | void OFileViewFileListView::slotFSpressed() |
416 | { | 417 | { |
417 | m_fsPop->exec(QPoint( QCursor::pos().x(), QCursor::pos().y())); | 418 | m_fsPop->exec(QPoint( QCursor::pos().x(), QCursor::pos().y())); |
418 | m_fsButton->setDown(false); | 419 | m_fsButton->setDown(false); |
419 | } | 420 | } |
420 | 421 | ||
421 | OFileViewFileListView::~OFileViewFileListView() | 422 | OFileViewFileListView::~OFileViewFileListView() |
422 | { | 423 | { |
423 | } | 424 | } |
424 | 425 | ||
425 | void OFileViewFileListView::slotNew() | 426 | void OFileViewFileListView::slotNew() |
426 | { | 427 | { |
427 | DocLnk lnk; | 428 | DocLnk lnk; |
428 | emit selector()->newSelected( lnk ); | 429 | emit selector()->newSelected( lnk ); |
429 | } | 430 | } |
430 | 431 | ||
431 | OFileSelectorItem* OFileViewFileListView::currentItem()const | 432 | OFileSelectorItem* OFileViewFileListView::currentItem()const |
432 | { | 433 | { |
433 | QListViewItem* item = m_view->currentItem(); | 434 | QListViewItem* item = m_view->currentItem(); |
434 | if (!item ) | 435 | if (!item ) |
435 | return 0l; | 436 | return 0l; |
436 | 437 | ||
437 | return static_cast<OFileSelectorItem*>(item); | 438 | return static_cast<OFileSelectorItem*>(item); |
438 | } | 439 | } |
439 | 440 | ||
440 | void OFileViewFileListView::reread( bool all ) | 441 | void OFileViewFileListView::reread( bool all ) |
441 | { | 442 | { |
442 | m_view->clear(); | 443 | m_view->clear(); |
443 | 444 | ||
444 | if (selector()->showClose() ) | 445 | if (selector()->showClose() ) |
445 | m_btnClose->show(); | 446 | m_btnClose->show(); |
446 | else | 447 | else |
447 | m_btnClose->hide(); | 448 | m_btnClose->hide(); |
448 | 449 | ||
449 | if (selector()->showNew() ) | 450 | if (selector()->showNew() ) |
450 | m_btnNew->show(); | 451 | m_btnNew->show(); |
451 | else | 452 | else |
452 | m_btnNew->hide(); | 453 | m_btnNew->hide(); |
453 | 454 | ||
454 | m_mimes = selector()->currentMimeType(); | 455 | m_mimes = selector()->currentMimeType(); |
455 | m_all = all; | 456 | m_all = all; |
456 | 457 | ||
457 | QDir dir( m_currentDir ); | 458 | QDir dir( m_currentDir ); |
458 | if (!dir.exists() ) | 459 | if (!dir.exists() ) |
459 | return; | 460 | return; |
460 | 461 | ||
461 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); | 462 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); |
462 | int filter; | 463 | int filter; |
463 | filter = QDir::Dirs; | 464 | filter = QDir::Dirs; |
464 | if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR ) | 465 | if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR ) |
465 | filter = filter | QDir::Files | QDir::All; | 466 | filter = filter | QDir::Files | QDir::All; |
466 | 467 | ||
467 | if ( m_all ) | 468 | if ( m_all ) |
468 | filter = filter | QDir::Hidden; | 469 | filter = filter | QDir::Hidden; |
469 | 470 | ||
470 | dir.setFilter( filter ); | 471 | dir.setFilter( filter ); |
471 | 472 | ||
472 | // now go through all files | 473 | // now go through all files |
473 | const QFileInfoList *list = dir.entryInfoList(); | 474 | const QFileInfoList *list = dir.entryInfoList(); |
474 | if (!list) | 475 | if (!list) |
475 | { | 476 | { |
476 | cdUP(); | 477 | cdUP(); |
477 | return; | 478 | return; |
478 | } | 479 | } |
479 | 480 | ||
480 | QFileInfoListIterator it( *list ); | 481 | QFileInfoListIterator it( *list ); |
481 | QFileInfo *fi; | 482 | QFileInfo *fi; |
482 | while( (fi=it.current() ) ) | 483 | while( (fi=it.current() ) ) |
483 | { | 484 | { |
484 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) | 485 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) |
485 | { | 486 | { |
486 | ++it; | 487 | ++it; |
487 | continue; | 488 | continue; |
488 | } | 489 | } |
489 | 490 | ||
490 | /* | 491 | /* |
491 | * It is a symlink we try to resolve it now but don't let us attack by DOS | 492 | * It is a symlink we try to resolve it now but don't let us attack by DOS |
492 | * | 493 | * |
493 | */ | 494 | */ |
494 | if( fi->isSymLink() ) | 495 | if( fi->isSymLink() ) |
495 | { | 496 | { |
496 | QString file = createNewPath(fi->dirPath( true ),fi->readLink()); | 497 | QString file = createNewPath(fi->dirPath( true ),fi->readLink()); |
497 | for( int i = 0; i<=4; i++) | 498 | for( int i = 0; i<=4; i++) |
498 | { // 5 tries to prevent dos | 499 | { // 5 tries to prevent dos |
499 | QFileInfo info( file ); | 500 | QFileInfo info( file ); |
500 | if( !info.exists() ) | 501 | if( !info.exists() ) |
501 | { | 502 | { |
502 | addSymlink( fi, TRUE ); | 503 | addSymlink( fi, TRUE ); |
503 | break; | 504 | break; |
504 | } | 505 | } |
505 | else if( info.isDir() ) | 506 | else if( info.isDir() ) |
506 | { | 507 | { |
507 | addDir( fi, TRUE ); | 508 | addDir( fi, TRUE ); |
508 | break; | 509 | break; |
509 | } | 510 | } |
510 | else if( info.isFile() ) | 511 | else if( info.isFile() ) |
511 | { | 512 | { |
512 | addFile( fi, TRUE ); | 513 | addFile( fi, TRUE ); |
513 | break; | 514 | break; |
514 | } | 515 | } |
515 | else if( info.isSymLink() ) | 516 | else if( info.isSymLink() ) |
516 | { | 517 | { |
517 | file = createNewPath(info.dirPath(true ),info.readLink()); | 518 | file = createNewPath(info.dirPath(true ),info.readLink()); |
518 | break; | 519 | break; |
519 | } | 520 | } |
520 | else if( i == 4) | 521 | else if( i == 4) |
521 | { // couldn't resolve symlink add it as symlink | 522 | { // couldn't resolve symlink add it as symlink |
522 | addSymlink( fi ); | 523 | addSymlink( fi ); |
523 | } | 524 | } |
524 | } // off for loop for symlink resolving | 525 | } // off for loop for symlink resolving |
525 | } | 526 | } |
526 | else if( fi->isDir() ) | 527 | else if( fi->isDir() ) |
527 | addDir( fi ); | 528 | addDir( fi ); |
528 | else if( fi->isFile() ) | 529 | else if( fi->isFile() ) |
529 | addFile( fi ); | 530 | addFile( fi ); |
530 | 531 | ||
531 | ++it; | 532 | ++it; |
532 | } // of while loop | 533 | } // of while loop |
533 | m_view->sort(); | 534 | m_view->sort(); |
534 | 535 | ||
535 | } | 536 | } |
536 | int OFileViewFileListView::fileCount()const | 537 | int OFileViewFileListView::fileCount()const |
537 | { | 538 | { |
538 | return m_view->childCount(); | 539 | return m_view->childCount(); |
539 | } | 540 | } |
540 | 541 | ||
541 | QString OFileViewFileListView::currentDir()const | 542 | QString OFileViewFileListView::currentDir()const |
542 | { | 543 | { |
543 | return m_currentDir; | 544 | return m_currentDir; |
544 | } | 545 | } |
545 | 546 | ||
546 | OFileSelector* OFileViewFileListView::selector() | 547 | OFileSelector* OFileViewFileListView::selector() |
547 | { | 548 | { |
548 | return m_sel; | 549 | return m_sel; |
549 | } | 550 | } |
550 | 551 | ||
551 | bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) | 552 | bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) |
552 | { | 553 | { |
553 | if ( e->type() == QEvent::KeyPress ) | 554 | if ( e->type() == QEvent::KeyPress ) |
554 | { | 555 | { |
555 | QKeyEvent *k = (QKeyEvent *)e; | 556 | QKeyEvent *k = (QKeyEvent *)e; |
556 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) | 557 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) |
557 | { | 558 | { |
558 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); | 559 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); |
559 | return true; | 560 | return true; |
560 | } | 561 | } |
561 | } | 562 | } |
562 | return false; | 563 | return false; |
563 | } | 564 | } |
564 | 565 | ||
565 | void OFileViewFileListView::connectSlots() | 566 | void OFileViewFileListView::connectSlots() |
566 | { | 567 | { |
567 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), | 568 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), |
568 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); | 569 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); |
569 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), | 570 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), |
570 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); | 571 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); |
571 | } | 572 | } |
572 | 573 | ||
573 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) | 574 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) |
574 | { | 575 | { |
575 | if (!item) | 576 | if (!item) |
576 | return; | 577 | return; |
577 | #if 0 | 578 | #if 0 |
578 | 579 | ||
579 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 580 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
580 | 581 | ||
581 | if (!sel->isDir() ) | 582 | if (!sel->isDir() ) |
582 | { | 583 | { |
583 | selector()->m_lneEdit->setText( sel->text(1) ); | 584 | selector()->m_lneEdit->setText( sel->text(1) ); |
584 | // if in fileselector mode we will emit selected | 585 | // if in fileselector mode we will emit selected |
585 | if ( selector()->mode() == OFileSelector::FileSelector ) | 586 | if ( selector()->mode() == OFileSelector::FileSelector ) |
586 | { | 587 | { |
587 | odebug << "slot Current Changed" << oendl; | 588 | odebug << "slot Current Changed" << oendl; |
588 | QStringList str = QStringList::split("->", sel->text(1) ); | 589 | QStringList str = QStringList::split("->", sel->text(1) ); |
589 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); | 590 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
590 | emit selector()->fileSelected( path ); | 591 | emit selector()->fileSelected( path ); |
591 | DocLnk lnk( path ); | 592 | DocLnk lnk( path ); |
592 | emit selector()->fileSelected( lnk ); | 593 | emit selector()->fileSelected( lnk ); |
593 | } | 594 | } |
594 | } | 595 | } |
595 | #endif | 596 | #endif |
596 | } | 597 | } |
597 | 598 | ||
598 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) | 599 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) |
599 | { | 600 | { |
600 | if (!item || ( button != Qt::LeftButton) ) | 601 | if (!item || ( button != Qt::LeftButton) ) |
601 | return; | 602 | return; |
602 | 603 | ||
603 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 604 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
604 | if (!sel->isLocked() ) | 605 | if (!sel->isLocked() ) |
605 | { | 606 | { |
606 | QStringList str = QStringList::split("->", sel->text(1) ); | 607 | QStringList str = QStringList::split("->", sel->text(1) ); |
607 | if (sel->isDir() ) | 608 | if (sel->isDir() ) |
608 | { | 609 | { |
609 | m_currentDir = createNewPath(sel->directory(),str[0].stripWhiteSpace()); | 610 | m_currentDir = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
610 | emit selector()->dirSelected( m_currentDir ); | 611 | emit selector()->dirSelected( m_currentDir ); |
611 | reread( m_all ); | 612 | reread( m_all ); |
612 | } | 613 | } |
613 | else | 614 | else |
614 | { // file | 615 | { // file |
615 | odebug << "slot Clicked" << oendl; | 616 | odebug << "slot Clicked" << oendl; |
616 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); | 617 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); |
617 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); | 618 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
618 | emit selector()->fileSelected( path ); | 619 | emit selector()->fileSelected( path ); |
619 | DocLnk lnk( path ); | 620 | DocLnk lnk( path ); |
620 | emit selector()->fileSelected( lnk ); | 621 | emit selector()->fileSelected( lnk ); |
621 | } | 622 | } |
622 | } // not locked | 623 | } // not locked |
623 | } | 624 | } |
624 | 625 | ||
625 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) | 626 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) |
626 | { | 627 | { |
627 | MimeType type( info->absFilePath() ); | 628 | MimeType type( info->absFilePath() ); |
628 | if (!compliesMime( type.id() ) ) | 629 | if (!compliesMime( type.id() ) ) |
629 | return; | 630 | return; |
630 | 631 | ||
631 | QPixmap pix = type.pixmap(); | 632 | QPixmap pix = type.pixmap(); |
632 | QString dir, name; bool locked; | 633 | QString dir, name; bool locked; |
633 | if ( pix.isNull() ) | 634 | if ( pix.isNull() ) |
634 | { | 635 | { |
635 | QWMatrix matrix; | 636 | QWMatrix matrix; |
636 | QPixmap pixer( Opie::Core::OResource::loadPixmap( "UnknownDocument" ) ); | 637 | QPixmap pixer( Opie::Core::OResource::loadPixmap( "UnknownDocument" ) ); |
637 | matrix.scale( .4, .4 ); | 638 | matrix.scale( .4, .4 ); |
638 | pix = pixer.xForm( matrix ); | 639 | pix = pixer.xForm( matrix ); |
639 | } | 640 | } |
640 | dir = info->dirPath( true ); | 641 | dir = info->dirPath( true ); |
641 | locked = false; | 642 | locked = false; |
642 | if ( symlink ) | 643 | if ( symlink ) |
643 | name = info->fileName() + " -> " + createNewPath(info->dirPath(),info->readLink()); | 644 | name = info->fileName() + " -> " + createNewPath(info->dirPath(),info->readLink()); |
644 | else | 645 | else |
645 | { | 646 | { |
646 | name = info->fileName(); | 647 | name = info->fileName(); |
647 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || | 648 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || |
648 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) | 649 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) |
649 | { | 650 | { |
650 | locked = true; | 651 | locked = true; |
651 | pix = Opie::Core::OResource::loadPixmap( "locked" ); | 652 | pix = Opie::Core::OResource::loadPixmap( "locked" ); |
652 | } | 653 | } |
653 | } | 654 | } |
654 | (void)new OFileSelectorItem( m_view, pix, name, | 655 | (void)new OFileSelectorItem( m_view, pix, name, |
655 | info->lastModified().toString(), QString::number( info->size() ), | 656 | info->lastModified().toString(), QString::number( info->size() ), |
656 | dir, locked ); | 657 | dir, locked ); |
657 | } | 658 | } |
658 | 659 | ||
659 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) | 660 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) |
660 | { | 661 | { |
661 | bool locked = false; QString name; QPixmap pix; | 662 | bool locked = false; QString name; QPixmap pix; |
662 | 663 | ||
663 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || | 664 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || |
664 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) | 665 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) |
665 | { | 666 | { |
666 | locked = true; | 667 | locked = true; |
667 | if ( symlink ) | 668 | if ( symlink ) |
668 | pix = Opie::Core::OResource::loadPixmap( "opie/symlink" ); | 669 | pix = Opie::Core::OResource::loadPixmap( "opie/symlink" ); |
669 | else | 670 | else |
670 | pix = Opie::Core::OResource::loadPixmap( "lockedfolder" ); | 671 | pix = Opie::Core::OResource::loadPixmap( "lockedfolder" ); |
671 | } | 672 | } |
672 | else | 673 | else |
673 | pix = symlink ? Opie::Core::OResource::loadPixmap( "opie/symlink" ) : Opie::Core::OResource::loadPixmap( "folder" ); | 674 | pix = symlink ? Opie::Core::OResource::loadPixmap( "opie/symlink" ) : Opie::Core::OResource::loadPixmap( "folder" ); |
674 | 675 | ||
675 | name = symlink ? info->fileName() + " -> " + createNewPath(info->dirPath(true),info->readLink()) : | 676 | name = symlink ? info->fileName() + " -> " + createNewPath(info->dirPath(true),info->readLink()) : |
676 | info->fileName(); | 677 | info->fileName(); |
677 | 678 | ||
678 | (void)new OFileSelectorItem( m_view, pix, name, | 679 | (void)new OFileSelectorItem( m_view, pix, name, |
679 | info->lastModified().toString(), | 680 | info->lastModified().toString(), |
680 | QString::number( info->size() ), | 681 | QString::number( info->size() ), |
681 | info->dirPath( true ), locked, true ); | 682 | info->dirPath( true ), locked, true ); |
682 | 683 | ||
683 | 684 | ||
684 | } | 685 | } |
685 | 686 | ||
686 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) | 687 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) |
687 | { | 688 | { |
688 | } | 689 | } |
689 | 690 | ||
690 | void OFileViewFileListView::cdUP() | 691 | void OFileViewFileListView::cdUP() |
691 | { | 692 | { |
692 | QDir dir( m_currentDir ); | 693 | QDir dir( m_currentDir ); |
693 | dir.cdUp(); | 694 | dir.cdUp(); |
694 | 695 | ||
695 | if (!dir.exists() ) | 696 | if (!dir.exists() ) |
696 | m_currentDir = "/"; | 697 | m_currentDir = "/"; |
697 | else | 698 | else |
698 | m_currentDir = dir.absPath(); | 699 | m_currentDir = dir.absPath(); |
699 | 700 | ||
700 | emit selector()->dirSelected( m_currentDir ); | 701 | emit selector()->dirSelected( m_currentDir ); |
701 | reread( m_all ); | 702 | reread( m_all ); |
702 | } | 703 | } |
703 | 704 | ||
704 | void OFileViewFileListView::cdHome() | 705 | void OFileViewFileListView::cdHome() |
705 | { | 706 | { |
706 | m_currentDir = QDir::homeDirPath(); | 707 | m_currentDir = QDir::homeDirPath(); |
707 | emit selector()->dirSelected( m_currentDir ); | 708 | emit selector()->dirSelected( m_currentDir ); |
708 | reread( m_all ); | 709 | reread( m_all ); |
709 | } | 710 | } |
710 | 711 | ||
711 | void OFileViewFileListView::cdDoc() | 712 | void OFileViewFileListView::cdDoc() |
712 | { | 713 | { |
713 | m_currentDir = QPEApplication::documentDir(); | 714 | m_currentDir = QPEApplication::documentDir(); |
714 | emit selector()->dirSelected( m_currentDir ); | 715 | emit selector()->dirSelected( m_currentDir ); |
715 | reread( m_all ); | 716 | reread( m_all ); |
716 | } | 717 | } |
717 | 718 | ||
718 | void OFileViewFileListView::changeDir( const QString& dir ) | 719 | void OFileViewFileListView::changeDir( const QString& dir ) |
719 | { | 720 | { |
720 | m_currentDir = dir; | 721 | m_currentDir = dir; |
721 | emit selector()->dirSelected( m_currentDir ); | 722 | emit selector()->dirSelected( m_currentDir ); |
722 | reread( m_all ); | 723 | reread( m_all ); |
723 | } | 724 | } |
724 | 725 | ||
725 | void OFileViewFileListView::slotFSActivated( int id ) | 726 | void OFileViewFileListView::slotFSActivated( int id ) |
726 | { | 727 | { |
727 | changeDir ( m_dev[m_fsPop->text(id)] ); | 728 | changeDir ( m_dev[m_fsPop->text(id)] ); |
728 | } | 729 | } |
729 | 730 | ||
730 | /* check if the mimetype in mime | 731 | /* check if the mimetype in mime |
731 | * complies with the one which is current | 732 | * complies with the one which is current |
732 | */ | 733 | */ |
733 | /* | 734 | /* |
734 | * We've the mimetype of the file | 735 | * We've the mimetype of the file |
735 | * We need to get the stringlist of the current mimetype | 736 | * We need to get the stringlist of the current mimetype |
736 | * | 737 | * |
737 | * mime = image@slashjpeg | 738 | * mime = image@slashjpeg |
738 | * QStringList = 'image@slash*' | 739 | * QStringList = 'image@slash*' |
739 | * or QStringList = image/jpeg;image/png;application/x-ogg | 740 | * or QStringList = image/jpeg;image/png;application/x-ogg |
740 | * or QStringList = application/x-ogg;image@slash*; | 741 | * or QStringList = application/x-ogg;image@slash*; |
741 | * with all these mime filters it should get acceptes | 742 | * with all these mime filters it should get acceptes |
742 | * to do so we need to look if mime is contained inside | 743 | * to do so we need to look if mime is contained inside |
743 | * the stringlist | 744 | * the stringlist |
744 | * if it's contained return true | 745 | * if it's contained return true |
745 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' | 746 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' |
746 | * is contained in the mimefilter and then we will | 747 | * is contained in the mimefilter and then we will |
747 | * look if both are equal until the '/' | 748 | * look if both are equal until the '/' |
748 | */ | 749 | */ |
749 | 750 | ||
750 | bool OFileViewFileListView::compliesMime( const QString& str) | 751 | bool OFileViewFileListView::compliesMime( const QString& str) |
751 | { | 752 | { |
752 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) | 753 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) |
753 | return true; | 754 | return true; |
754 | 755 | ||
755 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) | 756 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) |
756 | { | 757 | { |
757 | QRegExp reg( (*it) ); | 758 | QRegExp reg( (*it) ); |
758 | reg.setWildcard( true ); | 759 | reg.setWildcard( true ); |
759 | if ( str.find( reg ) != -1 ) | 760 | if ( str.find( reg ) != -1 ) |
760 | return true; | 761 | return true; |
761 | 762 | ||
762 | } | 763 | } |
763 | return false; | 764 | return false; |
764 | } | 765 | } |
765 | /* | 766 | /* |
766 | * The listView giving access to the file system! | 767 | * The listView giving access to the file system! |
767 | */ | 768 | */ |
768 | 769 | ||
769 | class OFileViewFileSystem : public OFileViewInterface | 770 | class OFileViewFileSystem : public OFileViewInterface |
770 | { | 771 | { |
771 | public: | 772 | public: |
772 | OFileViewFileSystem( OFileSelector* ); | 773 | OFileViewFileSystem( OFileSelector* ); |
773 | ~OFileViewFileSystem(); | 774 | ~OFileViewFileSystem(); |
774 | 775 | ||
775 | QString selectedName() const; | 776 | QString selectedName() const; |
776 | QString selectedPath() const; | 777 | QString selectedPath() const; |
777 | 778 | ||
778 | QString directory()const; | 779 | QString directory()const; |
779 | void reread(); | 780 | void reread(); |
780 | int fileCount()const; | 781 | int fileCount()const; |
781 | 782 | ||
782 | QWidget* widget( QWidget* parent ); | 783 | QWidget* widget( QWidget* parent ); |
783 | void activate( const QString& ); | 784 | void activate( const QString& ); |
784 | private: | 785 | private: |
785 | OFileViewFileListView* m_view; | 786 | OFileViewFileListView* m_view; |
786 | bool m_all : 1; | 787 | bool m_all : 1; |
787 | }; | 788 | }; |
788 | 789 | ||
789 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) | 790 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) |
790 | : OFileViewInterface( sel ) | 791 | : OFileViewInterface( sel ) |
791 | { | 792 | { |
792 | m_view = 0; | 793 | m_view = 0; |
793 | m_all = false; | 794 | m_all = false; |
794 | } | 795 | } |
795 | 796 | ||
796 | OFileViewFileSystem::~OFileViewFileSystem() | 797 | OFileViewFileSystem::~OFileViewFileSystem() |
797 | { | 798 | { |
798 | } | 799 | } |
799 | 800 | ||
800 | QString OFileViewFileSystem::selectedName()const | 801 | QString OFileViewFileSystem::selectedName()const |
801 | { | 802 | { |
802 | if (!m_view ) | 803 | if (!m_view ) |
803 | return QString::null; | 804 | return QString::null; |
804 | 805 | ||
805 | QString cFN=currentFileName(); | 806 | QString cFN=currentFileName(); |
806 | if (cFN.startsWith("/")) return cFN; | 807 | if (cFN.startsWith("/")) return cFN; |
807 | return createNewPath(m_view->currentDir(),cFN); | 808 | return createNewPath(m_view->currentDir(),cFN); |
808 | } | 809 | } |
809 | 810 | ||
810 | QString OFileViewFileSystem::selectedPath()const | 811 | QString OFileViewFileSystem::selectedPath()const |
811 | { | 812 | { |
812 | return QString::null; | 813 | return QString::null; |
813 | } | 814 | } |
814 | 815 | ||
815 | QString OFileViewFileSystem::directory()const | 816 | QString OFileViewFileSystem::directory()const |
816 | { | 817 | { |
817 | if (!m_view) | 818 | if (!m_view) |
818 | return QString::null; | 819 | return QString::null; |
819 | 820 | ||
820 | OFileSelectorItem* item = m_view->currentItem(); | 821 | OFileSelectorItem* item = m_view->currentItem(); |
821 | if (!item ) | 822 | if (!item ) |
822 | return QString::null; | 823 | return QString::null; |
823 | 824 | ||
824 | return QDir(item->directory() ).absPath(); | 825 | return QDir(item->directory() ).absPath(); |
825 | } | 826 | } |
826 | 827 | ||
827 | void OFileViewFileSystem::reread() | 828 | void OFileViewFileSystem::reread() |
828 | { | 829 | { |
829 | if (!m_view) | 830 | if (!m_view) |
830 | return; | 831 | return; |
831 | 832 | ||
832 | m_view->reread( m_all ); | 833 | m_view->reread( m_all ); |
833 | } | 834 | } |
834 | 835 | ||
835 | int OFileViewFileSystem::fileCount()const | 836 | int OFileViewFileSystem::fileCount()const |
836 | { | 837 | { |
837 | if (!m_view ) | 838 | if (!m_view ) |
838 | return -1; | 839 | return -1; |
839 | return m_view->fileCount(); | 840 | return m_view->fileCount(); |
840 | } | 841 | } |
841 | 842 | ||
842 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) | 843 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) |
843 | { | 844 | { |
844 | if (!m_view ) | 845 | if (!m_view ) |
845 | { | 846 | { |
846 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); | 847 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); |
847 | } | 848 | } |
848 | return m_view; | 849 | return m_view; |
849 | } | 850 | } |
850 | 851 | ||
851 | void OFileViewFileSystem::activate( const QString& str ) | 852 | void OFileViewFileSystem::activate( const QString& str ) |
852 | { | 853 | { |
853 | m_all = allItem( str ); | 854 | m_all = allItem( str ); |
854 | } | 855 | } |
855 | 856 | ||
856 | 857 | ||
857 | } | 858 | } |
858 | /* Selector */ | 859 | /* Selector */ |
859 | /** | 860 | /** |
860 | * @short new and complete c'tor | 861 | * @short new and complete c'tor |
861 | * | 862 | * |
862 | * Create a OFileSelector to let the user select a file. It can | 863 | * Create a OFileSelector to let the user select a file. It can |
863 | * either be used to open a file, select a save name in a dir or | 864 | * either be used to open a file, select a save name in a dir or |
864 | * as a dropin for the FileSelector. | 865 | * as a dropin for the FileSelector. |
865 | * | 866 | * |
866 | * <pre> | 867 | * <pre> |
867 | * QMap<QString, QStringList> mimeTypes; | 868 | * QMap<QString, QStringList> mimeTypes; |
868 | * QStringList types; | 869 | * QStringList types; |
869 | * types << "text@slash* "; | 870 | * types << "text@slash* "; |
870 | * types << "audio@slash*"; | 871 | * types << "audio@slash*"; |
871 | * mimeTypes.insert( tr("Audio and Text"), types ); | 872 | * mimeTypes.insert( tr("Audio and Text"), types ); |
872 | * mimeTypes.insert( tr("All"), "*@slash*); | 873 | * mimeTypes.insert( tr("All"), "*@slash*); |
873 | * | 874 | * |
874 | * now you could create your fileselector | 875 | * now you could create your fileselector |
875 | * </pre> | 876 | * </pre> |
876 | * | 877 | * |
877 | * | 878 | * |
878 | * @param parent the parent of this widget | 879 | * @param parent the parent of this widget |
879 | * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) | 880 | * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) |
880 | * @param sel The selector to be used | 881 | * @param sel The selector to be used |
881 | * @param dirName The name of the dir to start int | 882 | * @param dirName The name of the dir to start int |
882 | * @param fileName The fileName placed in the fileselector lineedit | 883 | * @param fileName The fileName placed in the fileselector lineedit |