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 @@ -7,36 +7,40 @@ * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #define DEVELOPERS_VERSION #include "advancedfm.h" #include <opie/otabwidget.h> // #include <opie/ofileselector.h> // #include <opie/ofiledialog.h> +#include <qpe/config.h> #include <qpe/filemanager.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/qpeapplication.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/config.h> #include <qpe/mimetype.h> #include <qpe/applnk.h> #include <qpe/ir.h> #include <qpe/resource.h> +#include <qpe/menubutton.h> + +#include <qregexp.h> #include <qtabwidget.h> #include <qtextstream.h> #include <qpushbutton.h> #include <qdatetime.h> #include <qdir.h> #include <qfile.h> #include <qstring.h> #include <qcombobox.h> #include <qpopupmenu.h> #include <qlistview.h> #include <qmainwindow.h> #include <qlabel.h> @@ -81,25 +85,25 @@ AdvancedFm::~AdvancedFm() { void AdvancedFm::cleanUp() { QString sfile=QDir::homeDirPath(); if(sfile.right(1) != "/") sfile+="/._temp"; else sfile+="._temp"; QFile file( sfile); if(file.exists()) file.remove(); } void AdvancedFm::tabChanged(QWidget *w) { - qDebug("tab changed %d",TabWidget->getCurrentTab()); +// qDebug("tab changed %d",TabWidget->getCurrentTab()); if ( w == tab) { // if (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); viewMenu->setItemChecked(viewMenu->idAt(0),TRUE); viewMenu->setItemChecked(viewMenu->idAt(1),FALSE); QString fs= getFileSystemType((const QString &) currentDir.canonicalPath()); setCaption("AdvancedFm :: "+fs+" :: " +checkDiskSpace((const QString &) currentDir.canonicalPath())+" kB free" ); } @@ -185,25 +189,25 @@ void AdvancedFm::populateLocalView() { isDir=FALSE; ++it; } if(currentDir.canonicalPath().find("dev",0,TRUE) != -1) { struct stat buf; dev_t devT; DIR *dir; struct dirent *mydirent; if((dir = opendir( currentDir.canonicalPath().latin1())) != NULL) while ((mydirent = readdir(dir)) != NULL) { lstat( mydirent->d_name, &buf); - qDebug(mydirent->d_name); +// qDebug(mydirent->d_name); fileL.sprintf("%s", mydirent->d_name); devT = buf.st_dev; fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF); fileDate.sprintf("%s", ctime( &buf.st_mtime)); if( fileL.find(".") == -1 ){ item= new QListViewItem( Local_View, fileL, fileS, fileDate); pm = Resource::loadPixmap( "UnknownDocument-14" ); item->setPixmap( 0,pm); } } closedir(dir); @@ -284,25 +288,25 @@ void AdvancedFm::populateRemoteView() { } isDir=FALSE; ++it; } if(currentRemoteDir.canonicalPath().find("dev",0,TRUE) != -1) { struct stat buf; DIR *dir; struct dirent *mydirent; if((dir = opendir( currentRemoteDir.canonicalPath().latin1())) != NULL) while ((mydirent = readdir(dir)) != NULL) { lstat( mydirent->d_name, &buf); - qDebug(mydirent->d_name); +// qDebug(mydirent->d_name); fileL.sprintf("%s", mydirent->d_name); fileS.sprintf("%d,%d", (int) (buf.st_dev>>8)&0xFF, (int) buf.st_dev &0xFF); fileDate.sprintf("%s", ctime( &buf.st_mtime)); if( fileL.find(".") == -1 ){ item= new QListViewItem( Remote_View, fileL, fileS, fileDate); pm = Resource::loadPixmap( "UnknownDocument-14" ); item->setPixmap( 0,pm); } } closedir(dir); } @@ -398,52 +402,52 @@ void AdvancedFm::remoteListClicked(QListViewItem *selectedItem) { } } } void AdvancedFm::localListPressed( int mouse, QListViewItem *, const QPoint& , int ) { // qDebug("list pressed"); switch (mouse) { case 1: { if(renameBox != 0 ) { - qDebug("cancel rename"); +// qDebug("cancel rename"); cancelRename(); } } break; case 2: menuTimer.start( 500, TRUE ); - qDebug("Start menu timer\n"); +// qDebug("Start menu timer\n"); break; }; } void AdvancedFm::remoteListPressed( int mouse, QListViewItem*, const QPoint&, int ) { switch (mouse) { case 1: { if(renameBox != 0 ) { - qDebug("cancel rename"); +// qDebug("cancel rename"); cancelRename(); } } break; case 2: menuTimer.start( 500, TRUE ); - qDebug("Start menu timer"); +// qDebug("Start menu timer"); break; }; } void AdvancedFm::switchToLocalTab() { TabWidget->setCurrentTab(0); Local_View->setFocus(); } void AdvancedFm::switchToRemoteTab() { TabWidget->setCurrentTab(1); @@ -471,25 +475,25 @@ void AdvancedFm::currentPathComboChanged() { if (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { if(QDir( currentPathCombo->lineEdit()->text()).exists()) { currentRemoteDir.setPath( currentPathCombo->lineEdit()->text() ); populateRemoteView(); } else { QMessageBox::message(tr("Note"),tr("That directory does not exist")); } } } void AdvancedFm::fillCombo(const QString ¤tPath) { - qDebug("%d",TabWidget->getCurrentTab()); +// qDebug("%d",TabWidget->getCurrentTab()); if (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { currentPathCombo->lineEdit()->setText( currentPath); if( localDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { currentPathCombo->clear(); localDirPathStringList.prepend( currentPath ); currentPathCombo->insertStringList( localDirPathStringList,-1); } } else { currentPathCombo->lineEdit()->setText( currentPath); if( remoteDirPathStringList.grep( currentPath,TRUE).isEmpty() ) { currentPathCombo->clear(); @@ -514,35 +518,35 @@ void AdvancedFm::currentPathComboActivated(const QString & currentPath) { } } QStringList AdvancedFm::getPath() { QStringList strList; if (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { QList<QListViewItem> * getSelectedItems( QListView * Local_View ); QListViewItemIterator it( Local_View ); for ( ; it.current(); ++it ) { if ( it.current()->isSelected() ) { strList << it.current()->text(0); - qDebug(it.current()->text(0)); +// qDebug(it.current()->text(0)); } } return strList; } else { QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); QListViewItemIterator it( Remote_View ); for ( ; it.current(); ++it ) { if ( it.current()->isSelected() ) { strList << it.current()->text(0); - qDebug(it.current()->text(0)); +// qDebug(it.current()->text(0)); } } return strList; } return ""; } void AdvancedFm::homeButtonPushed() { QString current = QDir::homeDirPath(); chdir( current.latin1() ); if (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { @@ -866,34 +870,215 @@ QString AdvancedFm::checkDiskSpace(const QString &path) { } return ""; } void AdvancedFm::addToDocs() { QStringList strListPaths = getPath(); if( strListPaths.count() > 0) { QString curFile; if (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { curFile = currentDir.canonicalPath()+"/"+(*it); - qDebug(curFile); +// qDebug(curFile); DocLnk f; // curFile.replace(QRegExp("\\..*"),""); f.setName((*it)); f.setFile( curFile); f.writeLink(); } } else { for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { curFile = currentRemoteDir.canonicalPath()+"/"+(*it); - qDebug(curFile); +// qDebug(curFile); DocLnk f; // curFile.replace(QRegExp("\\..*"),""); f.setName((*it)); f.setFile( curFile); f.writeLink(); } } } } + +void AdvancedFm::customDirsToMenu() +{ + + Config cfg("AdvancedFm"); + cfg.setGroup("Menu"); + + QStringList list = cfg.readListEntry( "CustomDir", ','); + menuButton->insertItems(list ); + +// for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) +// { +// customDirMenu->insertItem(*it ); +// } +} + +void AdvancedFm::dirMenuSelected(int item) +{ + qDebug("menu item %d", item); + switch(item) + { + + case -21: + case 0: + addCustomDir(); + break; + case -22: + case 1: + removeCustomDir(); + break; + default: + { +// gotoCustomDir( menuButton->text(item)); +// gotoCustomDir( customDirMenu->text(item)); + } + break; + + }; +} + +void AdvancedFm::addCustomDir() +{ + Config cfg("AdvancedFm"); + cfg.setGroup("Menu"); + QString dir; + QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); + + if (TabWidget->getCurrentTab() == 0) + { + dir = currentDir.canonicalPath(); + } + else + { + dir = currentRemoteDir.canonicalPath(); + } + + bool addIt=true; + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) + { + if( dir == (*it)) + { + addIt=false; + } + } + if(addIt) + { + menuButton->insertItem(dir); +// customDirMenu->insertItem(dir); + list << dir; + } + + cfg.writeEntry("CustomDir", list, ','); + cfg.write(); +} + +void AdvancedFm::removeCustomDir() +{ +// qDebug("remove custom dir"); + Config cfg("AdvancedFm"); + cfg.setGroup("Menu"); + QString dir; + QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); + QStringList list2; + + if (TabWidget->getCurrentTab() == 0) + { + dir = currentDir.canonicalPath(); + } + else + { + dir = currentRemoteDir.canonicalPath(); + } + int ramble=2; +// int ramble=-24; +//first remove list + if(list.grep(dir,true).isEmpty()) + { + QMessageBox::message("AdvancedFm",tr("Cannot remove current directory\nfrom bookmarks.\nIt is not bookmarked!!")); + } + else + { + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) + { + if((*it) != dir)//current item is not our current dir, so add it to temp list + { + list2 <<(*it); + } + else + { +// customDirMenu->removeItem( ramble); + menuButton->remove( ramble); + + } + ramble++; +// ramble--; + } + + cfg.writeEntry("CustomDir", list2, ','); + cfg.write(); + } +// customDirsToMenu(); + +} + +void AdvancedFm::gotoCustomDir(const QString &dir) +{ +// qDebug("gotoCustomDir(const QString &dir) " +dir ); + QString curDir = dir; +// if( curDir.isEmpty()) { +// } + if( curDir == s_addBookmark) + { + addCustomDir(); + } + if( curDir == s_removeBookmark) + { + removeCustomDir( ); + } + else + { + if(QDir( curDir).exists() ) + { + if (TabWidget->getCurrentTab() == 0) + { + currentDir.setPath( curDir ); + chdir( curDir.latin1() ); + currentDir.cd( curDir, TRUE); + populateLocalView(); + } + else + { + currentRemoteDir.setPath( curDir ); + chdir( curDir.latin1() ); + currentRemoteDir.cd( curDir, TRUE); + populateRemoteView(); + } + } + } +// menuButton +// qDebug("gotoCustomDir(const QString &dir) " +dir ); +// QString curDir = dir; +// if(QDir( curDir).exists() ) +// { +// if (TabWidget->getCurrentTab() == 0) +// { +// currentDir.setPath( curDir ); +// chdir( curDir.latin1() ); +// currentDir.cd( curDir, TRUE); +// populateLocalView(); +// } +// else +// { +// currentRemoteDir.setPath( curDir ); +// chdir( curDir.latin1() ); +// currentRemoteDir.cd( curDir, TRUE); +// populateRemoteView(); +// } +// } +// menuButton->setLabel(" "); +// menuButton +} |