summaryrefslogtreecommitdiff
path: root/noncore/apps/advancedfm/advancedfm.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/advancedfm/advancedfm.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfm.cpp345
1 files changed, 158 insertions, 187 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp
index 91318f1..2fc4b49 100644
--- a/noncore/apps/advancedfm/advancedfm.cpp
+++ b/noncore/apps/advancedfm/advancedfm.cpp
@@ -37,12 +37,14 @@
#include <qwidget.h>
#include <qlayout.h>
#include <qimage.h>
#include <qmessagebox.h>
#include <qlineedit.h>
+#include <qpe/qpemessagebox.h>
+
#include <sys/stat.h>
#include <time.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/vfs.h>
#include <mntent.h>
@@ -64,62 +66,58 @@ AdvancedFm::AdvancedFm( )
}
AdvancedFm::~AdvancedFm() {
}
-void AdvancedFm::cleanUp()
-{
+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)
-{
- if( w == tab)
- whichTab = 1;
- else
- whichTab = 2;
-
-// qDebug("tab changed %d", whichTab );
-
+void AdvancedFm::tabChanged(QWidget *) {
+// qWarning("tab changed");
QString path = CurrentDir()->canonicalPath();
currentPathCombo->lineEdit()->setText( path );
- viewMenu->setItemChecked(viewMenu->idAt(0),TRUE);
- viewMenu->setItemChecked(viewMenu->idAt(1),FALSE);
+ if(whichTab == 1) {
+ viewMenu->setItemChecked(viewMenu->idAt(0), true);
+ viewMenu->setItemChecked(viewMenu->idAt(1), false);
+ } else {
+ viewMenu->setItemChecked(viewMenu->idAt(0), false);
+ viewMenu->setItemChecked(viewMenu->idAt(1), true);
+ }
QString fs= getFileSystemType( (const QString &) path);
- setCaption("AdvancedFm :: "+fs+" :: "
- +checkDiskSpace( (const QString &) path )+ " kB free" );
+ setCaption(tr("AdvancedFm :: ")+fs+" :: "
+ +checkDiskSpace( (const QString &) path )+ tr(" kB free") );
chdir( path.latin1());
}
-void AdvancedFm::populateView()
-{
+void AdvancedFm::populateView() {
QPixmap pm;
QListView *thisView = CurrentView();
QDir *thisDir = CurrentDir();
QString path = thisDir->canonicalPath();
-
+// qWarning("path is "+path);
thisView->clear();
thisDir->setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
thisDir->setMatchAllDirs(TRUE);
thisDir->setNameFilter(filterStr);
QString fileL, fileS, fileDate;
QString fs= getFileSystemType((const QString &) path);
- setCaption("AdvancedFm :: "+fs+" :: "
- +checkDiskSpace((const QString &) path)+" kB free" );
+ setCaption(tr("AdvancedFm :: ")+fs+" :: "
+ +checkDiskSpace((const QString &) path)+ tr(" kB free") );
bool isDir=FALSE;
const QFileInfoList *list = thisDir->entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/);
QFileInfoListIterator it(*list);
QFileInfo *fi;
while ( (fi=it.current()) ) {
if (fi->isSymLink() ) {
@@ -130,12 +128,13 @@ void AdvancedFm::populateView()
fileDate = sym.lastModified().toString();
} else {
fileS.sprintf( "%10i", fi->size() );
fileL = fi->fileName();
fileDate= fi->lastModified().toString();
if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) {
+// if(fileL == "..")
fileL+="/";
isDir=TRUE;
}
}
QFileInfo fileInfo( path + "/" + fileL);
@@ -208,215 +207,206 @@ void AdvancedFm::populateView()
}
thisView->setSorting( 3,FALSE);
fillCombo( (const QString &) path );
}
-void AdvancedFm::rePopulate()
-{
- int tmpTab = whichTab;
- qDebug("%d", tmpTab);
-
- for(int i =1; i < 3; i++)
- {
- TabWidget->setCurrentWidget(i - 1);
+void AdvancedFm::rePopulate() {
populateView();
- }
- TabWidget->setCurrentWidget( tmpTab - 1);
+ setOtherTabCurrent();
+ populateView();
+
+// int tmpTab = whichTab;
+// // qDebug("%d", tmpTab);
+
+// for(int i =1; i < 3; i++) {
+// TabWidget->setCurrentWidget(i - 1);
+// populateView();
+// }
+// TabWidget->setCurrentWidget( tmpTab - 1);
}
-void AdvancedFm::ListClicked(QListViewItem *selectedItem)
-{
- if(selectedItem)
- {
+void AdvancedFm::ListClicked(QListViewItem *selectedItem) {
+//qWarning("listclicked");
+ if(selectedItem) {
QString strItem=selectedItem->text(0);
+// qWarning(strItem);
QString strSize=selectedItem->text(1);
strSize=strSize.stripWhiteSpace();
bool isDirectory = false;
QString strItem2;
- if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 )//if symlink
- {
+ if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) {//if symlink
strItem2 = dealWithSymName((const QString&)strItem);
if(QDir(strItem2).exists() )
strItem = strItem2;
}
- if( strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 )
- {
+ if( strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
if(QDir(strItem).exists())
isDirectory = true;
}
- if( isDirectory )
- {
+ if( isDirectory ) {
CurrentDir()->cd( strItem, TRUE);
populateView();
CurrentView()->ensureItemVisible( CurrentView()->firstChild());
}
chdir( strItem.latin1());
}
}
-void AdvancedFm::ListPressed( int mouse, QListViewItem *, const QPoint& , int ) {
+void AdvancedFm::ListPressed( int mouse, QListViewItem *item, const QPoint& , int ) {
+ dealWithSchmooSchmaa( item->listView());
switch (mouse) {
case 1:
{
- if(renameBox != 0 )
- {
+ if(renameBox != 0 ) {
cancelRename();
}
}
break;
case 2:
menuTimer.start( 500, TRUE );
break;
};
}
-void AdvancedFm::switchToLocalTab()
-{
+
+void AdvancedFm::switchToLocalTab() {
+//qWarning("switch to local view");
TabWidget->setCurrentWidget(0);
Local_View->setFocus();
}
-void AdvancedFm::switchToRemoteTab()
-{
+void AdvancedFm::switchToRemoteTab() {
+//qWarning("switch to local view");
TabWidget->setCurrentWidget(1);
Remote_View->setFocus();
}
-void AdvancedFm::readConfig()
-{
+void AdvancedFm::readConfig() {
Config cfg("AdvancedFm");
}
-void AdvancedFm::writeConfig()
-{
+void AdvancedFm::writeConfig() {
Config cfg("AdvancedFm");
}
-void AdvancedFm::currentPathComboChanged()
-{
- if(QDir( currentPathCombo->lineEdit()->text()).exists())
- {
+void AdvancedFm::currentPathComboChanged() {
+ if(QDir( currentPathCombo->lineEdit()->text()).exists()) {
CurrentDir()->setPath( currentPathCombo->lineEdit()->text() );
populateView();
- }
- else
- {
+ } else {
QMessageBox::message(tr("Note"),tr("That directory does not exist"));
}
}
-void AdvancedFm::fillCombo(const QString &currentPath)
-{
-// qDebug("%d",TabWidget->currentTab());
- if ( whichTab == 1)
- {
+void AdvancedFm::fillCombo(const QString &currentPath) {
+
+ if ( whichTab == 1) {
currentPathCombo->lineEdit()->setText( currentPath);
- if( localDirPathStringList.grep( currentPath,TRUE).isEmpty() )
- {
+ if( localDirPathStringList.grep( currentPath,TRUE).isEmpty() ) {
currentPathCombo->clear();
localDirPathStringList.prepend( currentPath );
currentPathCombo->insertStringList( localDirPathStringList,-1);
}
- }
- else
- {
+ } else {
currentPathCombo->lineEdit()->setText( currentPath);
- if( remoteDirPathStringList.grep( currentPath,TRUE).isEmpty() )
- {
+ if( remoteDirPathStringList.grep( currentPath,TRUE).isEmpty() ) {
currentPathCombo->clear();
remoteDirPathStringList.prepend( currentPath );
currentPathCombo->insertStringList( remoteDirPathStringList,-1);
}
}
}
-void AdvancedFm::currentPathComboActivated(const QString & currentPath)
-{
+void AdvancedFm::currentPathComboActivated(const QString & currentPath) {
chdir( currentPath.latin1() );
CurrentDir()->cd( currentPath, TRUE);
populateView();
update();
}
-QStringList AdvancedFm::getPath()
-{
+QStringList AdvancedFm::getPath() {
QStringList strList;
QListView *thisView=CurrentView();
QList<QListViewItem> * getSelectedItems( QListView * thisView );
QListViewItemIterator it( thisView );
- for ( ; it.current(); ++it )
- {
- if ( it.current()->isSelected() )
- {
+ for ( ; it.current(); ++it ) {
+ if ( it.current()->isSelected() ) {
strList << it.current()->text(0);
// qDebug(it.current()->text(0));
}
}
return strList;
}
-void AdvancedFm::homeButtonPushed()
-{
+void AdvancedFm::homeButtonPushed() {
QString current = QDir::homeDirPath();
chdir( current.latin1() );
CurrentDir()->cd( current, TRUE);
populateView();
update();
}
-void AdvancedFm::docButtonPushed()
-{
+void AdvancedFm::docButtonPushed() {
QString current = QPEApplication::documentDir();
chdir( current.latin1() );
CurrentDir()->cd( current, TRUE);
populateView();
update();
}
-void AdvancedFm::SDButtonPushed()
-{
+void AdvancedFm::SDButtonPushed() {
QString current = "/mnt/card";// this can change so fix
chdir( current.latin1() );
CurrentDir()->cd( current, TRUE);
populateView();
update();
}
-void AdvancedFm::CFButtonPushed()
-{
+void AdvancedFm::CFButtonPushed() {
QString current;
if(zaurusDevice)
current= "/mnt/cf"; //zaurus
else
current = "/mnt/hda"; //ipaq
chdir( current.latin1() );
CurrentDir()->cd( current, TRUE);
populateView();
update();
}
-void AdvancedFm::doAbout()
-{
+void AdvancedFm::doAbout() {
QMessageBox::message("AdvancedFm",tr("Advanced FileManager\n"
"is copyright 2002-2003 by\n"
"L.J.Potter<llornkcor@handhelds.org>\n"
"and is licensed by the GPL"));
}
-void AdvancedFm::keyPressEvent( QKeyEvent *e)
-{
-// e->accept();
- if( CurrentView()->hasFocus() )
+void AdvancedFm::keyPressEvent( QKeyEvent *e) {
+// qWarning("key %d", e->key());
+// if( CurrentView()->hasFocus() )
{
switch ( e->key() ) {
+ case Key_Left:
+ upDir();
+ break;
+ case Key_Next:
+ break;
+ case Key_Return:
+ case Key_Enter:
+ navigateToSelected();
+ break;
+ case Key_Tab: {
+ setOtherTabCurrent();
+ }
+ break;
case Key_Delete:
del();
break;
case Key_A:
copyAs();
break;
@@ -481,58 +471,51 @@ void AdvancedFm::keyPressEvent( QKeyEvent *e)
break;
};
e->accept();
}
}
-void AdvancedFm::keyReleaseEvent( QKeyEvent *e)
-{
+void AdvancedFm::keyReleaseEvent( QKeyEvent *e) {
if( CurrentView()->hasFocus() )
e->ignore();
}
-void AdvancedFm::QPEButtonPushed()
-{
+void AdvancedFm::QPEButtonPushed() {
QString current = QPEApplication::qpeDir();
chdir( current.latin1() );
CurrentDir()->cd( current, TRUE);
populateView();
update();
}
-void AdvancedFm::parsetab(const QString &fileName)
-{
+void AdvancedFm::parsetab(const QString &fileName) {
fileSystemTypeList.clear();
fsList.clear();
struct mntent *me;
FILE *mntfp = setmntent( fileName.latin1(), "r" );
- if ( mntfp )
- {
- while ( (me = getmntent( mntfp )) != 0 )
- {
+ if ( mntfp ) {
+ while ( (me = getmntent( mntfp )) != 0 ) {
QString deviceName = me->mnt_fsname;
QString filesystemType = me->mnt_type;
QString mountDir = me->mnt_dir;
- if(deviceName != "none")
- {
+ if(deviceName != "none") {
if( fsList.contains(filesystemType) == 0
& filesystemType.find("proc",0,TRUE) == -1
& filesystemType.find("cramfs",0,TRUE) == -1
& filesystemType.find("auto",0,TRUE) == -1)
fsList << filesystemType;
fileSystemTypeList << mountDir+"::"+filesystemType;
}
}
}
endmntent( mntfp );
}
-QString AdvancedFm::getFileSystemType(const QString &currentText)
-{
+QString AdvancedFm::getFileSystemType(const QString &currentText) {
parsetab("/etc/mtab"); //why did TT forget filesystem type?
QString current = currentText;//.right( currentText.length()-1);
QString baseFs;
for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) {
QString temp = (*it);
QString path = temp.left(temp.find("::",0,TRUE) );
@@ -542,14 +525,13 @@ QString AdvancedFm::getFileSystemType(const QString &currentText)
return temp.right( temp.length() - temp.find("::",0,TRUE) - 2);
}
}
return baseFs;
}
-QString AdvancedFm::getDiskSpace( const QString &path)
-{
+QString AdvancedFm::getDiskSpace( const QString &path) {
struct statfs fss;
if ( !statfs( path.latin1(), &fss ) ) {
int blkSize = fss.f_bsize;
// int totalBlks = fs.f_blocks;
int availBlks = fss.f_bavail;
@@ -561,32 +543,28 @@ QString AdvancedFm::getDiskSpace( const QString &path)
return QString::number(availBlks * mult / div);
}
return "";
}
-void AdvancedFm::showFileMenu()
-{
+void AdvancedFm::showFileMenu() {
QString curApp;
curApp = CurrentView()->currentItem()->text(0);
MimeType mt( curApp );
const AppLnk* app = mt.application();
QFile fi(curApp);
QPopupMenu *m = new QPopupMenu(0);
QPopupMenu *n = new QPopupMenu(0);
// QPopupMenu *o = new QPopupMenu(0);
m->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() ));
- if ( QFileInfo(fi).isDir() )
- {
+ if ( QFileInfo(fi).isDir() ) {
m->insertSeparator();
m->insertItem( tr( "Change Directory" ), this, SLOT( doDirChange() ));
- }
- else
- {
+ } else {
if ( app )
m->insertItem( app->pixmap(), tr( "Open in "
+ app->name() ), this, SLOT( runThis() ) );
else if( QFileInfo(fi).isExecutable() ) //damn opie doesnt like this
m->insertItem( tr( "Execute" ), this, SLOT( runThis() ) );
@@ -631,24 +609,21 @@ void AdvancedFm::showFileMenu()
m->exec( QPoint( 4,QCursor::pos().y()) );
if(m) delete m;
}
-void AdvancedFm::cancelMenuTimer()
-{
-// qDebug("selectionChanged: cancel menu timer");
+void AdvancedFm::cancelMenuTimer() {
+
if( menuTimer.isActive() )
menuTimer.stop();
}
-QString AdvancedFm::checkDiskSpace(const QString &path)
-{
+QString AdvancedFm::checkDiskSpace(const QString &path) {
struct statfs fss;
- if ( !statfs( path.latin1(), &fss ) )
- {
+ if ( !statfs( path.latin1(), &fss ) ) {
int blkSize = fss.f_bsize;
// int totalBlks = fs.f_blocks;
int availBlks = fss.f_bavail;
long mult = blkSize / 1024;
long div = 1024 / blkSize;
@@ -658,14 +633,13 @@ QString AdvancedFm::checkDiskSpace(const QString &path)
return QString::number(availBlks * mult / div);
}
return "";
}
-void AdvancedFm::addToDocs()
-{
+void AdvancedFm::addToDocs() {
QStringList strListPaths = getPath();
QDir *thisDir = CurrentDir();
if( strListPaths.count() > 0) {
QString curFile;
for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) {
@@ -679,14 +653,13 @@ void AdvancedFm::addToDocs()
f.writeLink();
}
}
}
-void AdvancedFm::customDirsToMenu()
-{
+void AdvancedFm::customDirsToMenu() {
Config cfg("AdvancedFm");
cfg.setGroup("Menu");
QStringList list = cfg.readListEntry( "CustomDir", ',');
menuButton->insertItems(list );
@@ -694,15 +667,13 @@ void AdvancedFm::customDirsToMenu()
// for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
// {
// customDirMenu->insertItem(*it );
// }
}
-void AdvancedFm::dirMenuSelected(int item)
-{
- qDebug("menu item %d", item);
+void AdvancedFm::dirMenuSelected(int item) {
switch(item)
{
case -21:
case 0:
addCustomDir();
@@ -718,67 +689,56 @@ void AdvancedFm::dirMenuSelected(int item)
}
break;
};
}
-void AdvancedFm::addCustomDir()
-{
+void AdvancedFm::addCustomDir() {
Config cfg("AdvancedFm");
cfg.setGroup("Menu");
QString dir;
QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)',');
dir = CurrentDir()->canonicalPath();
bool addIt=true;
- for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
- {
- if( dir == (*it))
- {
+ for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
+ if( dir == (*it)) {
addIt=false;
}
}
- if(addIt)
- {
+ if(addIt) {
menuButton->insertItem(dir);
// customDirMenu->insertItem(dir);
list << dir;
}
cfg.writeEntry("CustomDir", list, ',');
cfg.write();
}
-void AdvancedFm::removeCustomDir()
-{
+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;
dir = CurrentDir()->canonicalPath();
int ramble=2;
// int ramble=-24;
//first remove list
- if(list.grep(dir,true).isEmpty())
- {
+ if(list.grep(dir,true).isEmpty()) {
QMessageBox::message(tr( "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
- {
+ } 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
- {
+ } else {
// customDirMenu->removeItem( ramble);
menuButton->remove( ramble);
}
ramble++;
// ramble--;
@@ -788,106 +748,98 @@ void AdvancedFm::removeCustomDir()
cfg.write();
}
// customDirsToMenu();
}
-void AdvancedFm::gotoCustomDir(const QString &dir)
-{
+void AdvancedFm::gotoCustomDir(const QString &dir) {
// qDebug("gotoCustomDir(const QString &dir) " +dir );
// QString curDir = dir;
// QDir *thisDir = CurrentDir();
// if( curDir.isEmpty()) {
// }
- if( dir == s_addBookmark)
- {
+ if( dir == s_addBookmark) {
addCustomDir();
}
- if( dir == s_removeBookmark)
- {
+ if( dir == s_removeBookmark) {
removeCustomDir( );
- }
- else
- {
+ } else {
gotoDirectory( dir);
// if(QDir( curDir).exists() )
// {
// thisDir->setPath( curDir );
// chdir( curDir.latin1() );
// thisDir->cd( curDir, TRUE);
// populateView();
// }
}
}
-QDir *AdvancedFm::CurrentDir()
-{
- if ( whichTab == 1)
- {
+QDir *AdvancedFm::CurrentDir() {
+
+ if ( whichTab == 1) {
return &currentDir;
- }
- else
- {
+ } else {
return &currentRemoteDir;
}
}
-QDir *AdvancedFm::OtherDir()
-{
- if ( whichTab == 1)
- {
+QDir *AdvancedFm::OtherDir() {
+ if ( whichTab == 1) {
return &currentRemoteDir;
- }
- else
- {
+ } else {
return &currentDir;
}
}
-QListView * AdvancedFm::CurrentView()
-{
- if ( whichTab == 1)
+QListView * AdvancedFm::CurrentView() {
+ if ( whichTab == 1) {
+// qWarning("CurrentView Tab 1");
return Local_View;
- else
+ } else {
+// qWarning("CurrentView Tab 2");
return Remote_View;
}
+}
-QListView * AdvancedFm::OtherView()
-{
+QListView * AdvancedFm::OtherView() {
if ( whichTab == 1)
return Remote_View;
else
return Local_View;
}
-void AdvancedFm::setOtherTabCurrent()
-{
- if ( whichTab == 1)
+void AdvancedFm::setOtherTabCurrent() {
+// qWarning("setOtherTabCurrent()");
+ if ( whichTab == 1) {
TabWidget->setCurrentWidget(1);
- else
+ } else {
TabWidget->setCurrentWidget(0);
}
+ OtherView()->setFocus();
+ OtherView()->setSelected( CurrentView()->firstChild(), true);
+}
void AdvancedFm::qcopReceive(const QCString &msg, const QByteArray &data) {
- qDebug("qcop message "+msg );
+// qDebug("qcop message "+msg );
QDataStream stream ( data, IO_ReadOnly );
if ( msg == "openDirectory(QString)" ) {
- qDebug("received");
+// qDebug("received");
QString file;
stream >> file;
gotoDirectory( (const QString &) file);
}
}
void AdvancedFm::setDocument(const QString &file) {
gotoDirectory( file);
}
void AdvancedFm::gotoDirectory(const QString &file) {
-
+// qWarning("goto dir "+file);
QString curDir = file;
QDir *thisDir = CurrentDir();
if(QDir( curDir).exists() ) {
thisDir->setPath( curDir );
chdir( curDir.latin1() );
thisDir->cd( curDir, TRUE);
@@ -915,6 +867,25 @@ void AdvancedFm::findFile(const QString &fileName) {
if(it.current()->text(0) == fi.fileName()) {
it.current()->setSelected(true);
thisView->ensureItemVisible(it.current());
}
}
}
+
+void AdvancedFm::slotSwitchMenu(int ) {
+// qDebug("Switch %d", item);
+ // viewMenu->setItemChecked(item, true);
+}
+
+void AdvancedFm::dealWithSchmooSchmaa(QWidget *w) {
+ tabChanged( w);
+ if( w == Local_View) {
+ Remote_View->clearFocus();
+ } else {
+ Local_View->clearFocus();
+ }
+}
+
+void AdvancedFm::navigateToSelected() {
+ if( !CurrentView()->currentItem()) return;
+ doDirChange();
+}