Diffstat (limited to 'noncore/apps/advancedfm/advancedfm.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 209 |
1 files changed, 197 insertions, 12 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp index 9edf7c1..d8bdff7 100644 --- a/noncore/apps/advancedfm/advancedfm.cpp +++ b/noncore/apps/advancedfm/advancedfm.cpp | |||
@@ -13,24 +13,28 @@ | |||
13 | #include "advancedfm.h" | 13 | #include "advancedfm.h" |
14 | 14 | ||
15 | #include <opie/otabwidget.h> | 15 | #include <opie/otabwidget.h> |
16 | // #include <opie/ofileselector.h> | 16 | // #include <opie/ofileselector.h> |
17 | // #include <opie/ofiledialog.h> | 17 | // #include <opie/ofiledialog.h> |
18 | 18 | ||
19 | #include <qpe/config.h> | ||
19 | #include <qpe/filemanager.h> | 20 | #include <qpe/filemanager.h> |
20 | #include <qpe/qcopenvelope_qws.h> | 21 | #include <qpe/qcopenvelope_qws.h> |
21 | #include <qpe/qpemenubar.h> | 22 | #include <qpe/qpemenubar.h> |
22 | #include <qpe/qpetoolbar.h> | 23 | #include <qpe/qpetoolbar.h> |
23 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
24 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
25 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
26 | #include <qpe/mimetype.h> | 27 | #include <qpe/mimetype.h> |
27 | #include <qpe/applnk.h> | 28 | #include <qpe/applnk.h> |
28 | #include <qpe/ir.h> | 29 | #include <qpe/ir.h> |
29 | #include <qpe/resource.h> | 30 | #include <qpe/resource.h> |
31 | #include <qpe/menubutton.h> | ||
32 | |||
30 | 33 | ||
34 | #include <qregexp.h> | ||
31 | #include <qtabwidget.h> | 35 | #include <qtabwidget.h> |
32 | #include <qtextstream.h> | 36 | #include <qtextstream.h> |
33 | #include <qpushbutton.h> | 37 | #include <qpushbutton.h> |
34 | #include <qdatetime.h> | 38 | #include <qdatetime.h> |
35 | #include <qdir.h> | 39 | #include <qdir.h> |
36 | #include <qfile.h> | 40 | #include <qfile.h> |
@@ -87,13 +91,13 @@ void AdvancedFm::cleanUp() { | |||
87 | QFile file( sfile); | 91 | QFile file( sfile); |
88 | if(file.exists()) | 92 | if(file.exists()) |
89 | file.remove(); | 93 | file.remove(); |
90 | } | 94 | } |
91 | 95 | ||
92 | void AdvancedFm::tabChanged(QWidget *w) { | 96 | void AdvancedFm::tabChanged(QWidget *w) { |
93 | qDebug("tab changed %d",TabWidget->getCurrentTab()); | 97 | // qDebug("tab changed %d",TabWidget->getCurrentTab()); |
94 | 98 | ||
95 | if ( w == tab) { | 99 | if ( w == tab) { |
96 | // if (TabWidget->getCurrentTab() == 0) { | 100 | // if (TabWidget->getCurrentTab() == 0) { |
97 | // if (TabWidget->currentPageIndex() == 0) { | 101 | // if (TabWidget->currentPageIndex() == 0) { |
98 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); | 102 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); |
99 | viewMenu->setItemChecked(viewMenu->idAt(0),TRUE); | 103 | viewMenu->setItemChecked(viewMenu->idAt(0),TRUE); |
@@ -191,13 +195,13 @@ void AdvancedFm::populateLocalView() { | |||
191 | dev_t devT; | 195 | dev_t devT; |
192 | DIR *dir; | 196 | DIR *dir; |
193 | struct dirent *mydirent; | 197 | struct dirent *mydirent; |
194 | if((dir = opendir( currentDir.canonicalPath().latin1())) != NULL) | 198 | if((dir = opendir( currentDir.canonicalPath().latin1())) != NULL) |
195 | while ((mydirent = readdir(dir)) != NULL) { | 199 | while ((mydirent = readdir(dir)) != NULL) { |
196 | lstat( mydirent->d_name, &buf); | 200 | lstat( mydirent->d_name, &buf); |
197 | qDebug(mydirent->d_name); | 201 | // qDebug(mydirent->d_name); |
198 | fileL.sprintf("%s", mydirent->d_name); | 202 | fileL.sprintf("%s", mydirent->d_name); |
199 | devT = buf.st_dev; | 203 | devT = buf.st_dev; |
200 | fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF); | 204 | fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF); |
201 | fileDate.sprintf("%s", ctime( &buf.st_mtime)); | 205 | fileDate.sprintf("%s", ctime( &buf.st_mtime)); |
202 | if( fileL.find(".") == -1 ){ | 206 | if( fileL.find(".") == -1 ){ |
203 | item= new QListViewItem( Local_View, fileL, fileS, fileDate); | 207 | item= new QListViewItem( Local_View, fileL, fileS, fileDate); |
@@ -290,13 +294,13 @@ void AdvancedFm::populateRemoteView() { | |||
290 | struct stat buf; | 294 | struct stat buf; |
291 | DIR *dir; | 295 | DIR *dir; |
292 | struct dirent *mydirent; | 296 | struct dirent *mydirent; |
293 | if((dir = opendir( currentRemoteDir.canonicalPath().latin1())) != NULL) | 297 | if((dir = opendir( currentRemoteDir.canonicalPath().latin1())) != NULL) |
294 | while ((mydirent = readdir(dir)) != NULL) { | 298 | while ((mydirent = readdir(dir)) != NULL) { |
295 | lstat( mydirent->d_name, &buf); | 299 | lstat( mydirent->d_name, &buf); |
296 | qDebug(mydirent->d_name); | 300 | // qDebug(mydirent->d_name); |
297 | fileL.sprintf("%s", mydirent->d_name); | 301 | fileL.sprintf("%s", mydirent->d_name); |
298 | fileS.sprintf("%d,%d", (int) (buf.st_dev>>8)&0xFF, (int) buf.st_dev &0xFF); | 302 | fileS.sprintf("%d,%d", (int) (buf.st_dev>>8)&0xFF, (int) buf.st_dev &0xFF); |
299 | fileDate.sprintf("%s", ctime( &buf.st_mtime)); | 303 | fileDate.sprintf("%s", ctime( &buf.st_mtime)); |
300 | if( fileL.find(".") == -1 ){ | 304 | if( fileL.find(".") == -1 ){ |
301 | item= new QListViewItem( Remote_View, fileL, fileS, fileDate); | 305 | item= new QListViewItem( Remote_View, fileL, fileS, fileDate); |
302 | pm = Resource::loadPixmap( "UnknownDocument-14" ); | 306 | pm = Resource::loadPixmap( "UnknownDocument-14" ); |
@@ -404,40 +408,40 @@ void AdvancedFm::localListPressed( int mouse, QListViewItem *, const QPoint& , i | |||
404 | // qDebug("list pressed"); | 408 | // qDebug("list pressed"); |
405 | switch (mouse) { | 409 | switch (mouse) { |
406 | case 1: | 410 | case 1: |
407 | { | 411 | { |
408 | if(renameBox != 0 ) | 412 | if(renameBox != 0 ) |
409 | { | 413 | { |
410 | qDebug("cancel rename"); | 414 | // qDebug("cancel rename"); |
411 | cancelRename(); | 415 | cancelRename(); |
412 | } | 416 | } |
413 | 417 | ||
414 | } | 418 | } |
415 | break; | 419 | break; |
416 | case 2: | 420 | case 2: |
417 | menuTimer.start( 500, TRUE ); | 421 | menuTimer.start( 500, TRUE ); |
418 | qDebug("Start menu timer\n"); | 422 | // qDebug("Start menu timer\n"); |
419 | break; | 423 | break; |
420 | }; | 424 | }; |
421 | } | 425 | } |
422 | 426 | ||
423 | void AdvancedFm::remoteListPressed( int mouse, QListViewItem*, const QPoint&, int ) { | 427 | void AdvancedFm::remoteListPressed( int mouse, QListViewItem*, const QPoint&, int ) { |
424 | 428 | ||
425 | switch (mouse) { | 429 | switch (mouse) { |
426 | case 1: | 430 | case 1: |
427 | { | 431 | { |
428 | if(renameBox != 0 ) | 432 | if(renameBox != 0 ) |
429 | { | 433 | { |
430 | qDebug("cancel rename"); | 434 | // qDebug("cancel rename"); |
431 | cancelRename(); | 435 | cancelRename(); |
432 | } | 436 | } |
433 | } | 437 | } |
434 | break; | 438 | break; |
435 | case 2: | 439 | case 2: |
436 | menuTimer.start( 500, TRUE ); | 440 | menuTimer.start( 500, TRUE ); |
437 | qDebug("Start menu timer"); | 441 | // qDebug("Start menu timer"); |
438 | break; | 442 | break; |
439 | }; | 443 | }; |
440 | } | 444 | } |
441 | 445 | ||
442 | 446 | ||
443 | void AdvancedFm::switchToLocalTab() { | 447 | void AdvancedFm::switchToLocalTab() { |
@@ -477,13 +481,13 @@ void AdvancedFm::currentPathComboChanged() { | |||
477 | QMessageBox::message(tr("Note"),tr("That directory does not exist")); | 481 | QMessageBox::message(tr("Note"),tr("That directory does not exist")); |
478 | } | 482 | } |
479 | } | 483 | } |
480 | } | 484 | } |
481 | 485 | ||
482 | void AdvancedFm::fillCombo(const QString ¤tPath) { | 486 | void AdvancedFm::fillCombo(const QString ¤tPath) { |
483 | qDebug("%d",TabWidget->getCurrentTab()); | 487 | // qDebug("%d",TabWidget->getCurrentTab()); |
484 | if (TabWidget->getCurrentTab() == 0) { | 488 | if (TabWidget->getCurrentTab() == 0) { |
485 | // if (TabWidget->currentPageIndex() == 0) { | 489 | // if (TabWidget->currentPageIndex() == 0) { |
486 | currentPathCombo->lineEdit()->setText( currentPath); | 490 | currentPathCombo->lineEdit()->setText( currentPath); |
487 | if( localDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | 491 | if( localDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { |
488 | currentPathCombo->clear(); | 492 | currentPathCombo->clear(); |
489 | localDirPathStringList.prepend( currentPath ); | 493 | localDirPathStringList.prepend( currentPath ); |
@@ -520,23 +524,23 @@ QStringList AdvancedFm::getPath() { | |||
520 | // if (TabWidget->currentPageIndex() == 0) { | 524 | // if (TabWidget->currentPageIndex() == 0) { |
521 | QList<QListViewItem> * getSelectedItems( QListView * Local_View ); | 525 | QList<QListViewItem> * getSelectedItems( QListView * Local_View ); |
522 | QListViewItemIterator it( Local_View ); | 526 | QListViewItemIterator it( Local_View ); |
523 | for ( ; it.current(); ++it ) { | 527 | for ( ; it.current(); ++it ) { |
524 | if ( it.current()->isSelected() ) { | 528 | if ( it.current()->isSelected() ) { |
525 | strList << it.current()->text(0); | 529 | strList << it.current()->text(0); |
526 | qDebug(it.current()->text(0)); | 530 | // qDebug(it.current()->text(0)); |
527 | } | 531 | } |
528 | } | 532 | } |
529 | return strList; | 533 | return strList; |
530 | } else { | 534 | } else { |
531 | QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); | 535 | QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); |
532 | QListViewItemIterator it( Remote_View ); | 536 | QListViewItemIterator it( Remote_View ); |
533 | for ( ; it.current(); ++it ) { | 537 | for ( ; it.current(); ++it ) { |
534 | if ( it.current()->isSelected() ) { | 538 | if ( it.current()->isSelected() ) { |
535 | strList << it.current()->text(0); | 539 | strList << it.current()->text(0); |
536 | qDebug(it.current()->text(0)); | 540 | // qDebug(it.current()->text(0)); |
537 | } | 541 | } |
538 | } | 542 | } |
539 | return strList; | 543 | return strList; |
540 | } | 544 | } |
541 | return ""; | 545 | return ""; |
542 | } | 546 | } |
@@ -872,28 +876,209 @@ void AdvancedFm::addToDocs() { | |||
872 | if( strListPaths.count() > 0) { | 876 | if( strListPaths.count() > 0) { |
873 | QString curFile; | 877 | QString curFile; |
874 | if (TabWidget->getCurrentTab() == 0) { | 878 | if (TabWidget->getCurrentTab() == 0) { |
875 | // if (TabWidget->currentPageIndex() == 0) { | 879 | // if (TabWidget->currentPageIndex() == 0) { |
876 | for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { | 880 | for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { |
877 | curFile = currentDir.canonicalPath()+"/"+(*it); | 881 | curFile = currentDir.canonicalPath()+"/"+(*it); |
878 | qDebug(curFile); | 882 | // qDebug(curFile); |
879 | DocLnk f; | 883 | DocLnk f; |
880 | // curFile.replace(QRegExp("\\..*"),""); | 884 | // curFile.replace(QRegExp("\\..*"),""); |
881 | f.setName((*it)); | 885 | f.setName((*it)); |
882 | f.setFile( curFile); | 886 | f.setFile( curFile); |
883 | f.writeLink(); | 887 | f.writeLink(); |
884 | } | 888 | } |
885 | } else { | 889 | } else { |
886 | for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { | 890 | for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { |
887 | curFile = currentRemoteDir.canonicalPath()+"/"+(*it); | 891 | curFile = currentRemoteDir.canonicalPath()+"/"+(*it); |
888 | qDebug(curFile); | 892 | // qDebug(curFile); |
889 | 893 | ||
890 | DocLnk f; | 894 | DocLnk f; |
891 | // curFile.replace(QRegExp("\\..*"),""); | 895 | // curFile.replace(QRegExp("\\..*"),""); |
892 | f.setName((*it)); | 896 | f.setName((*it)); |
893 | f.setFile( curFile); | 897 | f.setFile( curFile); |
894 | f.writeLink(); | 898 | f.writeLink(); |
895 | } | 899 | } |
896 | } | 900 | } |
897 | } | 901 | } |
898 | } | 902 | } |
899 | 903 | ||
904 | |||
905 | void AdvancedFm::customDirsToMenu() | ||
906 | { | ||
907 | |||
908 | Config cfg("AdvancedFm"); | ||
909 | cfg.setGroup("Menu"); | ||
910 | |||
911 | QStringList list = cfg.readListEntry( "CustomDir", ','); | ||
912 | menuButton->insertItems(list ); | ||
913 | |||
914 | // for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | ||
915 | // { | ||
916 | // customDirMenu->insertItem(*it ); | ||
917 | // } | ||
918 | } | ||
919 | |||
920 | void AdvancedFm::dirMenuSelected(int item) | ||
921 | { | ||
922 | qDebug("menu item %d", item); | ||
923 | switch(item) | ||
924 | { | ||
925 | |||
926 | case -21: | ||
927 | case 0: | ||
928 | addCustomDir(); | ||
929 | break; | ||
930 | case -22: | ||
931 | case 1: | ||
932 | removeCustomDir(); | ||
933 | break; | ||
934 | default: | ||
935 | { | ||
936 | // gotoCustomDir( menuButton->text(item)); | ||
937 | // gotoCustomDir( customDirMenu->text(item)); | ||
938 | } | ||
939 | break; | ||
940 | |||
941 | }; | ||
942 | } | ||
943 | |||
944 | void AdvancedFm::addCustomDir() | ||
945 | { | ||
946 | Config cfg("AdvancedFm"); | ||
947 | cfg.setGroup("Menu"); | ||
948 | QString dir; | ||
949 | QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); | ||
950 | |||
951 | if (TabWidget->getCurrentTab() == 0) | ||
952 | { | ||
953 | dir = currentDir.canonicalPath(); | ||
954 | } | ||
955 | else | ||
956 | { | ||
957 | dir = currentRemoteDir.canonicalPath(); | ||
958 | } | ||
959 | |||
960 | bool addIt=true; | ||
961 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | ||
962 | { | ||
963 | if( dir == (*it)) | ||
964 | { | ||
965 | addIt=false; | ||
966 | } | ||
967 | } | ||
968 | if(addIt) | ||
969 | { | ||
970 | menuButton->insertItem(dir); | ||
971 | // customDirMenu->insertItem(dir); | ||
972 | list << dir; | ||
973 | } | ||
974 | |||
975 | cfg.writeEntry("CustomDir", list, ','); | ||
976 | cfg.write(); | ||
977 | } | ||
978 | |||
979 | void AdvancedFm::removeCustomDir() | ||
980 | { | ||
981 | // qDebug("remove custom dir"); | ||
982 | Config cfg("AdvancedFm"); | ||
983 | cfg.setGroup("Menu"); | ||
984 | QString dir; | ||
985 | QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); | ||
986 | QStringList list2; | ||
987 | |||
988 | if (TabWidget->getCurrentTab() == 0) | ||
989 | { | ||
990 | dir = currentDir.canonicalPath(); | ||
991 | } | ||
992 | else | ||
993 | { | ||
994 | dir = currentRemoteDir.canonicalPath(); | ||
995 | } | ||
996 | int ramble=2; | ||
997 | // int ramble=-24; | ||
998 | //first remove list | ||
999 | if(list.grep(dir,true).isEmpty()) | ||
1000 | { | ||
1001 | QMessageBox::message("AdvancedFm",tr("Cannot remove current directory\nfrom bookmarks.\nIt is not bookmarked!!")); | ||
1002 | } | ||
1003 | else | ||
1004 | { | ||
1005 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | ||
1006 | { | ||
1007 | if((*it) != dir)//current item is not our current dir, so add it to temp list | ||
1008 | { | ||
1009 | list2 <<(*it); | ||
1010 | } | ||
1011 | else | ||
1012 | { | ||
1013 | // customDirMenu->removeItem( ramble); | ||
1014 | menuButton->remove( ramble); | ||
1015 | |||
1016 | } | ||
1017 | ramble++; | ||
1018 | // ramble--; | ||
1019 | } | ||
1020 | |||
1021 | cfg.writeEntry("CustomDir", list2, ','); | ||
1022 | cfg.write(); | ||
1023 | } | ||
1024 | // customDirsToMenu(); | ||
1025 | |||
1026 | } | ||
1027 | |||
1028 | void AdvancedFm::gotoCustomDir(const QString &dir) | ||
1029 | { | ||
1030 | // qDebug("gotoCustomDir(const QString &dir) " +dir ); | ||
1031 | QString curDir = dir; | ||
1032 | // if( curDir.isEmpty()) { | ||
1033 | // } | ||
1034 | if( curDir == s_addBookmark) | ||
1035 | { | ||
1036 | addCustomDir(); | ||
1037 | } | ||
1038 | if( curDir == s_removeBookmark) | ||
1039 | { | ||
1040 | removeCustomDir( ); | ||
1041 | } | ||
1042 | else | ||
1043 | { | ||
1044 | if(QDir( curDir).exists() ) | ||
1045 | { | ||
1046 | if (TabWidget->getCurrentTab() == 0) | ||
1047 | { | ||
1048 | currentDir.setPath( curDir ); | ||
1049 | chdir( curDir.latin1() ); | ||
1050 | currentDir.cd( curDir, TRUE); | ||
1051 | populateLocalView(); | ||
1052 | } | ||
1053 | else | ||
1054 | { | ||
1055 | currentRemoteDir.setPath( curDir ); | ||
1056 | chdir( curDir.latin1() ); | ||
1057 | currentRemoteDir.cd( curDir, TRUE); | ||
1058 | populateRemoteView(); | ||
1059 | } | ||
1060 | } | ||
1061 | } | ||
1062 | // menuButton | ||
1063 | // qDebug("gotoCustomDir(const QString &dir) " +dir ); | ||
1064 | // QString curDir = dir; | ||
1065 | // if(QDir( curDir).exists() ) | ||
1066 | // { | ||
1067 | // if (TabWidget->getCurrentTab() == 0) | ||
1068 | // { | ||
1069 | // currentDir.setPath( curDir ); | ||
1070 | // chdir( curDir.latin1() ); | ||
1071 | // currentDir.cd( curDir, TRUE); | ||
1072 | // populateLocalView(); | ||
1073 | // } | ||
1074 | // else | ||
1075 | // { | ||
1076 | // currentRemoteDir.setPath( curDir ); | ||
1077 | // chdir( curDir.latin1() ); | ||
1078 | // currentRemoteDir.cd( curDir, TRUE); | ||
1079 | // populateRemoteView(); | ||
1080 | // } | ||
1081 | // } | ||
1082 | // menuButton->setLabel(" "); | ||
1083 | // menuButton | ||
1084 | } | ||