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