-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 | |||
@@ -67,560 +67,561 @@ namespace Internal { | |||
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 | { |