-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp index eaf5eeb..10dff07 100644 --- a/noncore/unsupported/filebrowser/filebrowser.cpp +++ b/noncore/unsupported/filebrowser/filebrowser.cpp | |||
@@ -1,157 +1,159 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "inlineedit.h" | 21 | #include "inlineedit.h" |
22 | #include "filebrowser.h" | 22 | #include "filebrowser.h" |
23 | #include "filePermissions.h" | 23 | #include "filePermissions.h" |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/global.h> | 25 | #include <qpe/global.h> |
26 | #include <qpe/mimetype.h> | 26 | #include <qpe/mimetype.h> |
27 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
28 | 28 | ||
29 | #include <qcopchannel_qws.h> | 29 | #include <qcopchannel_qws.h> |
30 | #include <qcopenvelope_qws.h> | ||
31 | |||
30 | #include <qmessagebox.h> | 32 | #include <qmessagebox.h> |
31 | #include <qdir.h> | 33 | #include <qdir.h> |
32 | #include <qregexp.h> | 34 | #include <qregexp.h> |
33 | #include <qheader.h> | 35 | #include <qheader.h> |
34 | #include <qpe/qpetoolbar.h> | 36 | #include <qpe/qpetoolbar.h> |
35 | #include <qpopupmenu.h> | 37 | #include <qpopupmenu.h> |
36 | #include <qpe/qpemenubar.h> | 38 | #include <qpe/qpemenubar.h> |
37 | #include <qaction.h> | 39 | #include <qaction.h> |
38 | #include <qstringlist.h> | 40 | #include <qstringlist.h> |
39 | #include <qcursor.h> | 41 | #include <qcursor.h> |
40 | #include <qmultilineedit.h> | 42 | #include <qmultilineedit.h> |
41 | #include <qfont.h> | 43 | #include <qfont.h> |
42 | 44 | ||
43 | #include <unistd.h> | 45 | #include <unistd.h> |
44 | #include <stdlib.h> | 46 | #include <stdlib.h> |
45 | #include <sys/stat.h> | 47 | #include <sys/stat.h> |
46 | 48 | ||
47 | // | 49 | // |
48 | // FileItem | 50 | // FileItem |
49 | // | 51 | // |
50 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) | 52 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) |
51 | : QListViewItem( parent ), | 53 | : QListViewItem( parent ), |
52 | fileInfo( fi ) | 54 | fileInfo( fi ) |
53 | { | 55 | { |
54 | QDate d = fi.lastModified().date(); | 56 | QDate d = fi.lastModified().date(); |
55 | 57 | ||
56 | setText( 0, fi.fileName() ); | 58 | setText( 0, fi.fileName() ); |
57 | setText( 1, sizeString( fi.size() ) + " " ); | 59 | setText( 1, sizeString( fi.size() ) + " " ); |
58 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); | 60 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); |
59 | 61 | ||
60 | MimeType mt(fi.filePath()); | 62 | MimeType mt(fi.filePath()); |
61 | 63 | ||
62 | if( fi.isDir() ) | 64 | if( fi.isDir() ) |
63 | setText( 3, "directory" ); | 65 | setText( 3, "directory" ); |
64 | else if( isLib() ) | 66 | else if( isLib() ) |
65 | setText( 3, "library" ); | 67 | setText( 3, "library" ); |
66 | else | 68 | else |
67 | setText( 3, mt.description() ); | 69 | setText( 3, mt.description() ); |
68 | 70 | ||
69 | QPixmap pm; | 71 | QPixmap pm; |
70 | if( fi.isDir() ){ | 72 | if( fi.isDir() ){ |
71 | if( !QDir( fi.filePath() ).isReadable() ) | 73 | if( !QDir( fi.filePath() ).isReadable() ) |
72 | pm = Resource::loadPixmap( "lockedfolder" ); | 74 | pm = Resource::loadPixmap( "lockedfolder" ); |
73 | else | 75 | else |
74 | pm = Resource::loadPixmap( "folder" ); | 76 | pm = Resource::loadPixmap( "folder" ); |
75 | } | 77 | } |
76 | else if( !fi.isReadable() ) | 78 | else if( !fi.isReadable() ) |
77 | pm = Resource::loadPixmap( "locked" ); | 79 | pm = Resource::loadPixmap( "locked" ); |
78 | else if( isLib() ) | 80 | else if( isLib() ) |
79 | pm = Resource::loadPixmap( "library" ); | 81 | pm = Resource::loadPixmap( "library" ); |
80 | else | 82 | else |
81 | pm = mt.pixmap(); | 83 | pm = mt.pixmap(); |
82 | if ( pm.isNull() ) | 84 | if ( pm.isNull() ) |
83 | pm = Resource::loadPixmap("UnknownDocument-14"); | 85 | pm = Resource::loadPixmap("UnknownDocument-14"); |
84 | setPixmap(0,pm); | 86 | setPixmap(0,pm); |
85 | } | 87 | } |
86 | 88 | ||
87 | QString FileItem::sizeString( unsigned int s ) | 89 | QString FileItem::sizeString( unsigned int s ) |
88 | { | 90 | { |
89 | double size = s; | 91 | double size = s; |
90 | 92 | ||
91 | if ( size > 1024 * 1024 * 1024 ) | 93 | if ( size > 1024 * 1024 * 1024 ) |
92 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; | 94 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; |
93 | else if ( size > 1024 * 1024 ) | 95 | else if ( size > 1024 * 1024 ) |
94 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; | 96 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; |
95 | else if ( size > 1024 ) | 97 | else if ( size > 1024 ) |
96 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; | 98 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; |
97 | else | 99 | else |
98 | return QString::number( size ) + "B"; | 100 | return QString::number( size ) + "B"; |
99 | } | 101 | } |
100 | 102 | ||
101 | QString FileItem::key( int column, bool ascending ) const | 103 | QString FileItem::key( int column, bool ascending ) const |
102 | { | 104 | { |
103 | QString tmp; | 105 | QString tmp; |
104 | 106 | ||
105 | ascending = ascending; | 107 | ascending = ascending; |
106 | 108 | ||
107 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name | 109 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name |
108 | // We want the directories to appear at the top of the list | 110 | // We want the directories to appear at the top of the list |
109 | tmp = (char) 0; | 111 | tmp = (char) 0; |
110 | return (tmp + text( column ).lower()); | 112 | return (tmp + text( column ).lower()); |
111 | } | 113 | } |
112 | else if( column == 2 ) { // Sort by date | 114 | else if( column == 2 ) { // Sort by date |
113 | QDateTime epoch( QDate( 1980, 1, 1 ) ); | 115 | QDateTime epoch( QDate( 1980, 1, 1 ) ); |
114 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); | 116 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); |
115 | return tmp; | 117 | return tmp; |
116 | } | 118 | } |
117 | else if( column == 1 ) { // Sort by size | 119 | else if( column == 1 ) { // Sort by size |
118 | return tmp.sprintf( "%08d", fileInfo.size() ); | 120 | return tmp.sprintf( "%08d", fileInfo.size() ); |
119 | } | 121 | } |
120 | 122 | ||
121 | return text( column ).lower(); | 123 | return text( column ).lower(); |
122 | } | 124 | } |
123 | 125 | ||
124 | bool FileItem::isLib() | 126 | bool FileItem::isLib() |
125 | { | 127 | { |
126 | // This is of course not foolproof | 128 | // This is of course not foolproof |
127 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && | 129 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && |
128 | ( fileInfo.extension().contains( "so" ) || | 130 | ( fileInfo.extension().contains( "so" ) || |
129 | fileInfo.extension().contains( "a" ) ) ) | 131 | fileInfo.extension().contains( "a" ) ) ) |
130 | return TRUE; | 132 | return TRUE; |
131 | else | 133 | else |
132 | return FALSE; | 134 | return FALSE; |
133 | } | 135 | } |
134 | 136 | ||
135 | int FileItem::launch() | 137 | int FileItem::launch() |
136 | { | 138 | { |
137 | DocLnk doc( fileInfo.filePath(), FALSE ); | 139 | DocLnk doc( fileInfo.filePath(), FALSE ); |
138 | doc.execute(); | 140 | doc.execute(); |
139 | listView()->clearSelection(); | 141 | listView()->clearSelection(); |
140 | return 1; | 142 | return 1; |
141 | } | 143 | } |
142 | 144 | ||
143 | bool FileItem::rename( const QString & name ) | 145 | bool FileItem::rename( const QString & name ) |
144 | { | 146 | { |
145 | QString oldpath, newpath; | 147 | QString oldpath, newpath; |
146 | 148 | ||
147 | if ( name.isEmpty() ) | 149 | if ( name.isEmpty() ) |
148 | return FALSE; | 150 | return FALSE; |
149 | 151 | ||
150 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) | 152 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) |
151 | return FALSE; | 153 | return FALSE; |
152 | 154 | ||
153 | oldpath = fileInfo.filePath(); | 155 | oldpath = fileInfo.filePath(); |
154 | newpath = fileInfo.dirPath() + "/" + name; | 156 | newpath = fileInfo.dirPath() + "/" + name; |
155 | 157 | ||
156 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) | 158 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) |
157 | return FALSE; | 159 | return FALSE; |
@@ -421,257 +423,259 @@ void FileView::cut() | |||
421 | // ##### a better inmplementation might be to rename the CUT file | 423 | // ##### a better inmplementation might be to rename the CUT file |
422 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. | 424 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. |
423 | QString cmd, dest, basename, cd = "/tmp/qpemoving"; | 425 | QString cmd, dest, basename, cd = "/tmp/qpemoving"; |
424 | QStringList newflist; | 426 | QStringList newflist; |
425 | newflist.clear(); | 427 | newflist.clear(); |
426 | 428 | ||
427 | cmd = "rm -rf " + cd; | 429 | cmd = "rm -rf " + cd; |
428 | system ( (const char *) cmd ); | 430 | system ( (const char *) cmd ); |
429 | cmd = "mkdir " + cd; | 431 | cmd = "mkdir " + cd; |
430 | system( (const char *) cmd ); | 432 | system( (const char *) cmd ); |
431 | 433 | ||
432 | // get the names of the files to cut | 434 | // get the names of the files to cut |
433 | FileItem * item; | 435 | FileItem * item; |
434 | 436 | ||
435 | if((item = (FileItem *) firstChild()) == 0) return; | 437 | if((item = (FileItem *) firstChild()) == 0) return; |
436 | 438 | ||
437 | flist.clear(); | 439 | flist.clear(); |
438 | while( item ){ | 440 | while( item ){ |
439 | if( item->isSelected() /*&& !item->isDir()*/ ){ | 441 | if( item->isSelected() /*&& !item->isDir()*/ ){ |
440 | flist += item->getFilePath(); | 442 | flist += item->getFilePath(); |
441 | } | 443 | } |
442 | item = (FileItem *) item->nextSibling(); | 444 | item = (FileItem *) item->nextSibling(); |
443 | } | 445 | } |
444 | 446 | ||
445 | // move these files into a tmp dir | 447 | // move these files into a tmp dir |
446 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { | 448 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { |
447 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); | 449 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); |
448 | 450 | ||
449 | dest = cd + "/" + basename; | 451 | dest = cd + "/" + basename; |
450 | 452 | ||
451 | newflist += dest; | 453 | newflist += dest; |
452 | 454 | ||
453 | cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; | 455 | cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; |
454 | err = system( (const char *) cmd ); | 456 | err = system( (const char *) cmd ); |
455 | 457 | ||
456 | if ( err != 0 ) { | 458 | if ( err != 0 ) { |
457 | QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), | 459 | QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), |
458 | tr("Ok") ); | 460 | tr("Ok") ); |
459 | break; | 461 | break; |
460 | } else { | 462 | } else { |
461 | updateDir(); | 463 | updateDir(); |
462 | QListViewItem * im = firstChild(); | 464 | QListViewItem * im = firstChild(); |
463 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); | 465 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); |
464 | 466 | ||
465 | while( im ){ | 467 | while( im ){ |
466 | if( im->text(0) == basename ){ | 468 | if( im->text(0) == basename ){ |
467 | setCurrentItem( im ); | 469 | setCurrentItem( im ); |
468 | ensureItemVisible( im ); | 470 | ensureItemVisible( im ); |
469 | break; | 471 | break; |
470 | } | 472 | } |
471 | im = im->nextSibling(); | 473 | im = im->nextSibling(); |
472 | } | 474 | } |
473 | } | 475 | } |
474 | } | 476 | } |
475 | 477 | ||
476 | // update the filelist to point to tmp dir so paste works nicely | 478 | // update the filelist to point to tmp dir so paste works nicely |
477 | flist = newflist; | 479 | flist = newflist; |
478 | } | 480 | } |
479 | 481 | ||
480 | void FileView::del() | 482 | void FileView::del() |
481 | { | 483 | { |
482 | FileItem * i; | 484 | FileItem * i; |
483 | QStringList fl; | 485 | QStringList fl; |
484 | QString cmd; | 486 | QString cmd; |
485 | int err; | 487 | int err; |
486 | 488 | ||
487 | if((i = (FileItem *) firstChild()) == 0) return; | 489 | if((i = (FileItem *) firstChild()) == 0) return; |
488 | 490 | ||
489 | while( i ){ | 491 | while( i ){ |
490 | if( i->isSelected() ){ | 492 | if( i->isSelected() ){ |
491 | fl += i->getFilePath(); | 493 | fl += i->getFilePath(); |
492 | } | 494 | } |
493 | i = (FileItem *) i->nextSibling(); | 495 | i = (FileItem *) i->nextSibling(); |
494 | } | 496 | } |
495 | if( fl.count() < 1 ) return; | 497 | if( fl.count() < 1 ) return; |
496 | 498 | ||
497 | if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), | 499 | if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), |
498 | tr("Yes"), tr("No") ) == 0) | 500 | tr("Yes"), tr("No") ) == 0) |
499 | { | 501 | { |
500 | // | 502 | // |
501 | // Dependant upon the "rm" command - will probably have to be replaced | 503 | // Dependant upon the "rm" command - will probably have to be replaced |
502 | // | 504 | // |
503 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { | 505 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { |
504 | cmd = "/bin/rm -rf \"" + (*it) + "\""; | 506 | cmd = "/bin/rm -rf \"" + (*it) + "\""; |
505 | err = system( (const char *) cmd ); | 507 | err = system( (const char *) cmd ); |
506 | if ( err != 0 ) { | 508 | if ( err != 0 ) { |
507 | QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), | 509 | QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), |
508 | tr("Ok") ); | 510 | tr("Ok") ); |
509 | break; | 511 | break; |
510 | } | 512 | } |
511 | } | 513 | } |
512 | updateDir(); | 514 | updateDir(); |
513 | } | 515 | } |
514 | } | 516 | } |
515 | 517 | ||
516 | void FileView::newFolder() | 518 | void FileView::newFolder() |
517 | { | 519 | { |
518 | int t = 1; | 520 | int t = 1; |
519 | FileItem * i; | 521 | FileItem * i; |
520 | QString nd = currentDir + "/NewFolder"; | 522 | QString nd = currentDir + "/NewFolder"; |
521 | 523 | ||
522 | while( QFile( nd ).exists() ){ | 524 | while( QFile( nd ).exists() ){ |
523 | nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); | 525 | nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); |
524 | } | 526 | } |
525 | 527 | ||
526 | if( mkdir( (const char *) nd, 0777 ) != 0){ | 528 | if( mkdir( (const char *) nd, 0777 ) != 0){ |
527 | QMessageBox::warning( this, tr( "New folder" ), | 529 | QMessageBox::warning( this, tr( "New folder" ), |
528 | tr( "Folder creation failed!" ), | 530 | tr( "Folder creation failed!" ), |
529 | tr( "Ok" ) ); | 531 | tr( "Ok" ) ); |
530 | return; | 532 | return; |
531 | } | 533 | } |
532 | updateDir(); | 534 | updateDir(); |
533 | 535 | ||
534 | if((i = (FileItem *) firstChild()) == 0) return; | 536 | if((i = (FileItem *) firstChild()) == 0) return; |
535 | 537 | ||
536 | while( i ){ | 538 | while( i ){ |
537 | if( i->isDir() && ( i->getFilePath() == nd ) ){ | 539 | if( i->isDir() && ( i->getFilePath() == nd ) ){ |
538 | setCurrentItem( i ); | 540 | setCurrentItem( i ); |
539 | rename(); | 541 | rename(); |
540 | break; | 542 | break; |
541 | } | 543 | } |
542 | i = (FileItem *) i->nextSibling(); | 544 | i = (FileItem *) i->nextSibling(); |
543 | } | 545 | } |
544 | } | 546 | } |
545 | 547 | ||
546 | void FileView::viewAsText() | 548 | void FileView::viewAsText() |
547 | { | 549 | { |
548 | FileItem * i = (FileItem *) currentItem(); | 550 | FileItem * i = (FileItem *) currentItem(); |
549 | Global::execute( "textedit -f ", i->getFilePath() ); | 551 | QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); |
552 | e << i->getFilePath(); | ||
553 | // Global::execute( "textedit -f ", i->getFilePath() ); | ||
550 | } | 554 | } |
551 | 555 | ||
552 | void FileView::itemClicked( QListViewItem * i) | 556 | void FileView::itemClicked( QListViewItem * i) |
553 | { | 557 | { |
554 | FileItem * t = (FileItem *) i; | 558 | FileItem * t = (FileItem *) i; |
555 | 559 | ||
556 | if( t == NULL ) return; | 560 | if( t == NULL ) return; |
557 | if( t->isDir() ){ | 561 | if( t->isDir() ){ |
558 | setDir( t->getFilePath() ); | 562 | setDir( t->getFilePath() ); |
559 | } | 563 | } |
560 | } | 564 | } |
561 | 565 | ||
562 | void FileView::itemDblClicked( QListViewItem * i) | 566 | void FileView::itemDblClicked( QListViewItem * i) |
563 | { | 567 | { |
564 | FileItem * t = (FileItem *) i; | 568 | FileItem * t = (FileItem *) i; |
565 | 569 | ||
566 | if(t == NULL) return; | 570 | if(t == NULL) return; |
567 | if(t->launch() == -1){ | 571 | if(t->launch() == -1){ |
568 | QMessageBox::warning( this, tr( "Launch Application" ), | 572 | QMessageBox::warning( this, tr( "Launch Application" ), |
569 | tr( "Launch failed!" ), tr( "Ok" ) ); | 573 | tr( "Launch failed!" ), tr( "Ok" ) ); |
570 | } | 574 | } |
571 | } | 575 | } |
572 | 576 | ||
573 | void FileView::parentDir() | 577 | void FileView::parentDir() |
574 | { | 578 | { |
575 | setDir( currentDir + "./.." ); | 579 | setDir( currentDir + "./.." ); |
576 | } | 580 | } |
577 | 581 | ||
578 | void FileView::lastDir() | 582 | void FileView::lastDir() |
579 | { | 583 | { |
580 | if( dirHistory.count() == 0 ) return; | 584 | if( dirHistory.count() == 0 ) return; |
581 | 585 | ||
582 | QString newDir = dirHistory.last(); | 586 | QString newDir = dirHistory.last(); |
583 | dirHistory.remove( dirHistory.last() ); | 587 | dirHistory.remove( dirHistory.last() ); |
584 | generateDir( newDir ); | 588 | generateDir( newDir ); |
585 | } | 589 | } |
586 | 590 | ||
587 | void FileView::contentsMousePressEvent( QMouseEvent * e ) | 591 | void FileView::contentsMousePressEvent( QMouseEvent * e ) |
588 | { | 592 | { |
589 | QListView::contentsMousePressEvent( e ); | 593 | QListView::contentsMousePressEvent( e ); |
590 | menuTimer.start( 750, TRUE ); | 594 | menuTimer.start( 750, TRUE ); |
591 | } | 595 | } |
592 | 596 | ||
593 | void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) | 597 | void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) |
594 | { | 598 | { |
595 | QListView::contentsMouseReleaseEvent( e ); | 599 | QListView::contentsMouseReleaseEvent( e ); |
596 | menuTimer.stop(); | 600 | menuTimer.stop(); |
597 | } | 601 | } |
598 | 602 | ||
599 | void FileView::cancelMenuTimer() | 603 | void FileView::cancelMenuTimer() |
600 | { | 604 | { |
601 | if( menuTimer.isActive() ) | 605 | if( menuTimer.isActive() ) |
602 | menuTimer.stop(); | 606 | menuTimer.stop(); |
603 | } | 607 | } |
604 | 608 | ||
605 | void FileView::addToDocuments() | 609 | void FileView::addToDocuments() |
606 | { | 610 | { |
607 | FileItem * i = (FileItem *) currentItem(); | 611 | FileItem * i = (FileItem *) currentItem(); |
608 | DocLnk f; | 612 | DocLnk f; |
609 | QString n = i->text(0); | 613 | QString n = i->text(0); |
610 | n.replace(QRegExp("\\..*"),""); | 614 | n.replace(QRegExp("\\..*"),""); |
611 | f.setName( n ); | 615 | f.setName( n ); |
612 | f.setFile( i->getFilePath() ); | 616 | f.setFile( i->getFilePath() ); |
613 | f.writeLink(); | 617 | f.writeLink(); |
614 | } | 618 | } |
615 | 619 | ||
616 | void FileView::run() | 620 | void FileView::run() |
617 | { | 621 | { |
618 | FileItem * i = (FileItem *) currentItem(); | 622 | FileItem * i = (FileItem *) currentItem(); |
619 | i->launch(); | 623 | i->launch(); |
620 | } | 624 | } |
621 | 625 | ||
622 | void FileView::showFileMenu() | 626 | void FileView::showFileMenu() |
623 | { | 627 | { |
624 | FileItem * i = (FileItem *) currentItem(); | 628 | FileItem * i = (FileItem *) currentItem(); |
625 | if ( !i ) | 629 | if ( !i ) |
626 | return; | 630 | return; |
627 | 631 | ||
628 | QPopupMenu * m = new QPopupMenu( this ); | 632 | QPopupMenu * m = new QPopupMenu( this ); |
629 | 633 | ||
630 | if ( !i->isDir() ) { | 634 | if ( !i->isDir() ) { |
631 | m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); | 635 | m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); |
632 | m->insertSeparator(); | 636 | m->insertSeparator(); |
633 | } | 637 | } |
634 | 638 | ||
635 | MimeType mt(i->getFilePath()); | 639 | MimeType mt(i->getFilePath()); |
636 | const AppLnk* app = mt.application(); | 640 | const AppLnk* app = mt.application(); |
637 | 641 | ||
638 | if ( !i->isDir() ) { | 642 | if ( !i->isDir() ) { |
639 | if ( app ) | 643 | if ( app ) |
640 | m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); | 644 | m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); |
641 | else if( i->isExecutable() ) | 645 | else if( i->isExecutable() ) |
642 | m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); | 646 | m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); |
643 | 647 | ||
644 | m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), | 648 | m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), |
645 | this, SLOT( viewAsText() ) ); | 649 | this, SLOT( viewAsText() ) ); |
646 | 650 | ||
647 | m->insertSeparator(); | 651 | m->insertSeparator(); |
648 | } | 652 | } |
649 | 653 | ||
650 | m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); | 654 | m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); |
651 | m->insertItem( Resource::loadPixmap("cut"), | 655 | m->insertItem( Resource::loadPixmap("cut"), |
652 | tr( "Cut" ), this, SLOT( cut() ) ); | 656 | tr( "Cut" ), this, SLOT( cut() ) ); |
653 | m->insertItem( Resource::loadPixmap("copy"), | 657 | m->insertItem( Resource::loadPixmap("copy"), |
654 | tr( "Copy" ), this, SLOT( copy() ) ); | 658 | tr( "Copy" ), this, SLOT( copy() ) ); |
655 | m->insertItem( Resource::loadPixmap("paste"), | 659 | m->insertItem( Resource::loadPixmap("paste"), |
656 | tr( "Paste" ), this, SLOT( paste() ) ); | 660 | tr( "Paste" ), this, SLOT( paste() ) ); |
657 | m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) ); | 661 | m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) ); |
658 | m->insertItem( tr( "Delete" ), this, SLOT( del() ) ); | 662 | m->insertItem( tr( "Delete" ), this, SLOT( del() ) ); |
659 | m->insertSeparator(); | 663 | m->insertSeparator(); |
660 | m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); | 664 | m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); |
661 | m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); | 665 | m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); |
662 | m->popup( QCursor::pos() ); | 666 | m->popup( QCursor::pos() ); |
663 | } | 667 | } |
664 | 668 | ||
665 | // | 669 | // |
666 | // FileBrowser | 670 | // FileBrowser |
667 | // | 671 | // |
668 | 672 | ||
669 | FileBrowser::FileBrowser( QWidget * parent, | 673 | FileBrowser::FileBrowser( QWidget * parent, |
670 | const char * name, WFlags f ) : | 674 | const char * name, WFlags f ) : |
671 | QMainWindow( parent, name, f ) | 675 | QMainWindow( parent, name, f ) |
672 | { | 676 | { |
673 | init( QDir::current().canonicalPath() ); | 677 | init( QDir::current().canonicalPath() ); |
674 | } | 678 | } |
675 | 679 | ||
676 | FileBrowser::FileBrowser( const QString & dir, QWidget * parent, | 680 | FileBrowser::FileBrowser( const QString & dir, QWidget * parent, |
677 | const char * name, WFlags f ) : | 681 | const char * name, WFlags f ) : |