-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 32 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.h | 2 |
2 files changed, 29 insertions, 5 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp index 96a2d0a..16dc7da 100644 --- a/noncore/apps/advancedfm/advancedfm.cpp +++ b/noncore/apps/advancedfm/advancedfm.cpp | |||
@@ -57,32 +57,34 @@ | |||
57 | #include <qimage.h> | 57 | #include <qimage.h> |
58 | #include <qpixmap.h> | 58 | #include <qpixmap.h> |
59 | #include <qmessagebox.h> | 59 | #include <qmessagebox.h> |
60 | #include <qlineedit.h> | 60 | #include <qlineedit.h> |
61 | #include <qregexp.h> | 61 | #include <qregexp.h> |
62 | 62 | ||
63 | #include <unistd.h> | 63 | #include <unistd.h> |
64 | #include <stdlib.h> | 64 | #include <stdlib.h> |
65 | #include <sys/stat.h> | 65 | #include <sys/stat.h> |
66 | #include <dirent.h> | 66 | #include <dirent.h> |
67 | #include <stdio.h> | 67 | #include <stdio.h> |
68 | #include <time.h> | 68 | #include <time.h> |
69 | #include <fcntl.h> | 69 | #include <fcntl.h> |
70 | #include <mntent.h> | 70 | #include <mntent.h> |
71 | #include <string.h> | 71 | #include <string.h> |
72 | #include <errno.h> | 72 | #include <errno.h> |
73 | #include <sys/vfs.h> | ||
74 | #include <mntent.h> | ||
73 | 75 | ||
74 | AdvancedFm::AdvancedFm( ) | 76 | AdvancedFm::AdvancedFm( ) |
75 | : QMainWindow( ) | 77 | : QMainWindow( ) |
76 | { | 78 | { |
77 | setCaption( tr( "AdvancedFm" ) ); | 79 | setCaption( tr( "AdvancedFm" ) ); |
78 | 80 | ||
79 | QGridLayout *layout = new QGridLayout( this ); | 81 | QGridLayout *layout = new QGridLayout( this ); |
80 | layout->setSpacing( 2); | 82 | layout->setSpacing( 2); |
81 | layout->setMargin( 2); | 83 | layout->setMargin( 2); |
82 | 84 | ||
83 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 85 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
84 | 86 | ||
85 | QPEMenuBar *menuBar = new QPEMenuBar(this); | 87 | QPEMenuBar *menuBar = new QPEMenuBar(this); |
86 | fileMenu = new QPopupMenu( this ); | 88 | fileMenu = new QPopupMenu( this ); |
87 | viewMenu = new QPopupMenu( this ); | 89 | viewMenu = new QPopupMenu( this ); |
88 | 90 | ||
@@ -291,33 +293,33 @@ void AdvancedFm::tabChanged(QWidget *w) | |||
291 | currentPathCombo->lineEdit()->setText( currentRemoteDir.canonicalPath()); | 293 | currentPathCombo->lineEdit()->setText( currentRemoteDir.canonicalPath()); |
292 | viewMenu->setItemChecked(viewMenu->idAt(1),TRUE); | 294 | viewMenu->setItemChecked(viewMenu->idAt(1),TRUE); |
293 | viewMenu->setItemChecked(viewMenu->idAt(0),FALSE); | 295 | viewMenu->setItemChecked(viewMenu->idAt(0),FALSE); |
294 | } | 296 | } |
295 | } | 297 | } |
296 | 298 | ||
297 | 299 | ||
298 | void AdvancedFm::populateLocalView() | 300 | void AdvancedFm::populateLocalView() |
299 | { | 301 | { |
300 | QPixmap pm; | 302 | QPixmap pm; |
301 | Local_View->clear(); | 303 | Local_View->clear(); |
302 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 304 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
303 | currentDir.setMatchAllDirs(TRUE); | 305 | currentDir.setMatchAllDirs(TRUE); |
304 | currentDir.setNameFilter(filterStr); | 306 | currentDir.setNameFilter(filterStr); |
305 | QString fileL, fileS, fileDate; | 307 | QString fileL, fileS, fileDate; |
306 | QString fs= getFileSystemType((const QString &) currentDir.canonicalPath()); | 308 | QString fs= getFileSystemType((const QString &) currentDir.canonicalPath()); |
307 | setCaption("AdvancedFm :: "+fs); | 309 | setCaption("AdvancedFm :: "+fs+" :: "+checkDiskSpace((const QString &) currentDir.canonicalPath())+" kB free" ); |
308 | bool isDir=FALSE; | 310 | bool isDir=FALSE; |
309 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | 311 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); |
310 | QFileInfoListIterator it(*list); | 312 | QFileInfoListIterator it(*list); |
311 | QFileInfo *fi; | 313 | QFileInfo *fi; |
312 | while ( (fi=it.current()) ) { | 314 | while ( (fi=it.current()) ) { |
313 | if (fi->isSymLink() ) { | 315 | if (fi->isSymLink() ) { |
314 | QString symLink=fi->readLink(); | 316 | QString symLink=fi->readLink(); |
315 | QFileInfo sym( symLink); | 317 | QFileInfo sym( symLink); |
316 | fileS.sprintf( "%10li", sym.size() ); | 318 | fileS.sprintf( "%10li", sym.size() ); |
317 | fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.absFilePath().data() ); | 319 | fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.absFilePath().data() ); |
318 | fileDate = sym.lastModified().toString(); | 320 | fileDate = sym.lastModified().toString(); |
319 | } else { | 321 | } else { |
320 | fileS.sprintf( "%10li", fi->size() ); | 322 | fileS.sprintf( "%10li", fi->size() ); |
321 | fileL.sprintf( "%s",fi->fileName().data() ); | 323 | fileL.sprintf( "%s",fi->fileName().data() ); |
322 | fileDate= fi->lastModified().toString(); | 324 | fileDate= fi->lastModified().toString(); |
323 | if( QDir(QDir::cleanDirPath( currentDir.canonicalPath()+"/"+fileL)).exists() ) { | 325 | if( QDir(QDir::cleanDirPath( currentDir.canonicalPath()+"/"+fileL)).exists() ) { |
@@ -389,33 +391,33 @@ void AdvancedFm::populateLocalView() | |||
389 | 391 | ||
390 | Local_View->setSorting( 3,FALSE); | 392 | Local_View->setSorting( 3,FALSE); |
391 | fillCombo( (const QString &) currentDir.canonicalPath()); | 393 | fillCombo( (const QString &) currentDir.canonicalPath()); |
392 | } | 394 | } |
393 | 395 | ||
394 | 396 | ||
395 | void AdvancedFm::populateRemoteView() | 397 | void AdvancedFm::populateRemoteView() |
396 | { | 398 | { |
397 | QPixmap pm; | 399 | QPixmap pm; |
398 | Remote_View->clear(); | 400 | Remote_View->clear(); |
399 | currentRemoteDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 401 | currentRemoteDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
400 | currentRemoteDir.setMatchAllDirs(TRUE); | 402 | currentRemoteDir.setMatchAllDirs(TRUE); |
401 | currentRemoteDir.setNameFilter(filterStr); | 403 | currentRemoteDir.setNameFilter(filterStr); |
402 | QString fileL, fileS, fileDate; | 404 | QString fileL, fileS, fileDate; |
403 | 405 | ||
404 | QString fs= getFileSystemType((const QString &) currentRemoteDir.canonicalPath()); | 406 | QString fs= getFileSystemType((const QString &) currentRemoteDir.canonicalPath()); |
405 | setCaption("AdvancedFm :: "+fs); | 407 | setCaption("AdvancedFm :: "+fs+" :: "+checkDiskSpace((const QString &) currentRemoteDir.canonicalPath())+" kB free" ); |
406 | bool isDir=FALSE; | 408 | bool isDir=FALSE; |
407 | const QFileInfoList *list = currentRemoteDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | 409 | const QFileInfoList *list = currentRemoteDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); |
408 | QFileInfoListIterator it(*list); | 410 | QFileInfoListIterator it(*list); |
409 | QFileInfo *fi; | 411 | QFileInfo *fi; |
410 | while ( (fi=it.current()) ) { | 412 | while ( (fi=it.current()) ) { |
411 | if (fi->isSymLink() ){ | 413 | if (fi->isSymLink() ){ |
412 | QString symLink=fi->readLink(); | 414 | QString symLink=fi->readLink(); |
413 | // qDebug("Symlink detected "+symLink); | 415 | // qDebug("Symlink detected "+symLink); |
414 | QFileInfo sym( symLink); | 416 | QFileInfo sym( symLink); |
415 | fileS.sprintf( "%10li", sym.size() ); | 417 | fileS.sprintf( "%10li", sym.size() ); |
416 | fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.absFilePath().data() ); | 418 | fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.absFilePath().data() ); |
417 | fileDate = sym.lastModified().toString(); | 419 | fileDate = sym.lastModified().toString(); |
418 | } else { | 420 | } else { |
419 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 421 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
420 | fileS.sprintf( "%10li", fi->size() ); | 422 | fileS.sprintf( "%10li", fi->size() ); |
421 | fileL.sprintf( "%s",fi->fileName().data() ); | 423 | fileL.sprintf( "%s",fi->fileName().data() ); |
@@ -1453,32 +1455,34 @@ void AdvancedFm::runCommand() { | |||
1453 | sleep(1); | 1455 | sleep(1); |
1454 | command +=" 2>&1"; | 1456 | command +=" 2>&1"; |
1455 | fp = popen( (const char *) command, "r"); | 1457 | fp = popen( (const char *) command, "r"); |
1456 | if ( !fp ) { | 1458 | if ( !fp ) { |
1457 | qDebug("Could not execute '" + command + "'! err=%d", fp); | 1459 | qDebug("Could not execute '" + command + "'! err=%d", fp); |
1458 | QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") ); | 1460 | QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") ); |
1459 | pclose(fp); | 1461 | pclose(fp); |
1460 | return; | 1462 | return; |
1461 | } else { | 1463 | } else { |
1462 | while ( fgets( line, sizeof line, fp)) { | 1464 | while ( fgets( line, sizeof line, fp)) { |
1463 | QString lineStr = line; | 1465 | QString lineStr = line; |
1464 | lineStr=lineStr.left(lineStr.length()-1); | 1466 | lineStr=lineStr.left(lineStr.length()-1); |
1465 | outDlg->OutputEdit->append(lineStr); | 1467 | outDlg->OutputEdit->append(lineStr); |
1466 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 1468 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
1467 | } | 1469 | } |
1468 | } | 1470 | } |
1471 | pclose(fp); | ||
1472 | |||
1469 | } | 1473 | } |
1470 | } | 1474 | } |
1471 | 1475 | ||
1472 | void AdvancedFm::runCommandStd() { | 1476 | void AdvancedFm::runCommandStd() { |
1473 | QString curFile; | 1477 | QString curFile; |
1474 | if (TabWidget->currentPageIndex() == 0) { | 1478 | if (TabWidget->currentPageIndex() == 0) { |
1475 | if( Local_View->currentItem()) | 1479 | if( Local_View->currentItem()) |
1476 | curFile = currentDir.canonicalPath() +"/"+ Local_View->currentItem()->text(0); | 1480 | curFile = currentDir.canonicalPath() +"/"+ Local_View->currentItem()->text(0); |
1477 | } else { | 1481 | } else { |
1478 | if(Remote_View->currentItem()) | 1482 | if(Remote_View->currentItem()) |
1479 | curFile = currentRemoteDir.canonicalPath() +"/"+ Remote_View->currentItem()->text(0); | 1483 | curFile = currentRemoteDir.canonicalPath() +"/"+ Remote_View->currentItem()->text(0); |
1480 | } | 1484 | } |
1481 | 1485 | ||
1482 | InputDialog *fileDlg; | 1486 | InputDialog *fileDlg; |
1483 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 1487 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
1484 | fileDlg->setInputText(curFile); | 1488 | fileDlg->setInputText(curFile); |
@@ -1508,32 +1512,33 @@ void AdvancedFm::fileStatus() { | |||
1508 | char line[130]; | 1512 | char line[130]; |
1509 | sleep(1); | 1513 | sleep(1); |
1510 | fp = popen( (const char *) command, "r"); | 1514 | fp = popen( (const char *) command, "r"); |
1511 | if ( !fp ) { | 1515 | if ( !fp ) { |
1512 | qDebug("Could not execute '" + command + "'! err=%d", fp); | 1516 | qDebug("Could not execute '" + command + "'! err=%d", fp); |
1513 | QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") ); | 1517 | QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") ); |
1514 | pclose(fp); | 1518 | pclose(fp); |
1515 | return; | 1519 | return; |
1516 | } else { | 1520 | } else { |
1517 | while ( fgets( line, sizeof line, fp)) { | 1521 | while ( fgets( line, sizeof line, fp)) { |
1518 | outDlg->OutputEdit->append(line); | 1522 | outDlg->OutputEdit->append(line); |
1519 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 1523 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
1520 | 1524 | ||
1521 | } | 1525 | } |
1522 | 1526 | ||
1523 | } | 1527 | } |
1528 | pclose(fp); | ||
1524 | } | 1529 | } |
1525 | 1530 | ||
1526 | void AdvancedFm::mkDir() { | 1531 | void AdvancedFm::mkDir() { |
1527 | if (TabWidget->currentPageIndex() == 0) | 1532 | if (TabWidget->currentPageIndex() == 0) |
1528 | localMakDir(); | 1533 | localMakDir(); |
1529 | else | 1534 | else |
1530 | remoteMakDir(); | 1535 | remoteMakDir(); |
1531 | 1536 | ||
1532 | } | 1537 | } |
1533 | 1538 | ||
1534 | void AdvancedFm::rn() { | 1539 | void AdvancedFm::rn() { |
1535 | if (TabWidget->currentPageIndex() == 0) | 1540 | if (TabWidget->currentPageIndex() == 0) |
1536 | localRename(); | 1541 | localRename(); |
1537 | else | 1542 | else |
1538 | remoteRename(); | 1543 | remoteRename(); |
1539 | 1544 | ||
@@ -1823,23 +1828,42 @@ void AdvancedFm::showFileMenu() { | |||
1823 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) //bad hack for Sharp zaurus failings | 1828 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) //bad hack for Sharp zaurus failings |
1824 | m->insertItem( tr( "Properties" ), this, SLOT( doProperties() )); | 1829 | m->insertItem( tr( "Properties" ), this, SLOT( doProperties() )); |
1825 | m->setCheckable(TRUE); | 1830 | m->setCheckable(TRUE); |
1826 | if (!b) | 1831 | if (!b) |
1827 | m->setItemChecked(m->idAt(0),TRUE); | 1832 | m->setItemChecked(m->idAt(0),TRUE); |
1828 | else | 1833 | else |
1829 | m->setItemChecked(m->idAt(0),FALSE); | 1834 | m->setItemChecked(m->idAt(0),FALSE); |
1830 | if(Ir::supported()) | 1835 | if(Ir::supported()) |
1831 | m->insertItem( tr( "Beam File" ), this, SLOT( doBeam() )); | 1836 | m->insertItem( tr( "Beam File" ), this, SLOT( doBeam() )); |
1832 | m->setFocus(); | 1837 | m->setFocus(); |
1833 | m->exec( QCursor::pos() ); | 1838 | m->exec( QCursor::pos() ); |
1834 | sleep(1); | 1839 | sleep(1); |
1835 | if(m) delete m; | 1840 | if(m) delete m; |
1836 | } | 1841 | } |
1837 | 1842 | ||
1838 | 1843 | ||
1839 | void AdvancedFm::cancelMenuTimer() | 1844 | void AdvancedFm::cancelMenuTimer() { |
1840 | { | ||
1841 | 1845 | ||
1842 | qDebug("selectionChanged: cancel menu timer"); | 1846 | qDebug("selectionChanged: cancel menu timer"); |
1843 | if( menuTimer.isActive() ) | 1847 | if( menuTimer.isActive() ) |
1844 | menuTimer.stop(); | 1848 | menuTimer.stop(); |
1845 | } | 1849 | } |
1850 | |||
1851 | QString AdvancedFm::checkDiskSpace(const QString &path) { | ||
1852 | |||
1853 | struct statfs fss; | ||
1854 | if ( !statfs( path.latin1(), &fss ) ) { | ||
1855 | int blkSize = fss.f_bsize; | ||
1856 | // int totalBlks = fs.f_blocks; | ||
1857 | int availBlks = fss.f_bavail; | ||
1858 | |||
1859 | long mult = blkSize / 1024; | ||
1860 | long div = 1024 / blkSize; | ||
1861 | if ( !mult ) mult = 1; | ||
1862 | if ( !div ) div = 1; | ||
1863 | |||
1864 | |||
1865 | return QString::number(availBlks * mult / div); | ||
1866 | } | ||
1867 | return ""; | ||
1868 | } | ||
1869 | |||
diff --git a/noncore/apps/advancedfm/advancedfm.h b/noncore/apps/advancedfm/advancedfm.h index 45f00ad..78f0bad 100644 --- a/noncore/apps/advancedfm/advancedfm.h +++ b/noncore/apps/advancedfm/advancedfm.h | |||
@@ -100,33 +100,33 @@ protected slots: | |||
100 | void runCommand(); | 100 | void runCommand(); |
101 | void runCommandStd(); | 101 | void runCommandStd(); |
102 | QStringList getPath(); | 102 | QStringList getPath(); |
103 | void mkSym(); | 103 | void mkSym(); |
104 | void switchToLocalTab(); | 104 | void switchToLocalTab(); |
105 | void switchToRemoteTab(); | 105 | void switchToRemoteTab(); |
106 | 106 | ||
107 | protected: | 107 | protected: |
108 | QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; | 108 | QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; |
109 | QStringList remoteDirPathStringList, localDirPathStringList; | 109 | QStringList remoteDirPathStringList, localDirPathStringList; |
110 | 110 | ||
111 | void keyReleaseEvent( QKeyEvent *); | 111 | void keyReleaseEvent( QKeyEvent *); |
112 | QString getFileSystemType(const QString &); | 112 | QString getFileSystemType(const QString &); |
113 | QString getDiskSpace(const QString &); | 113 | QString getDiskSpace(const QString &); |
114 | 114 | ||
115 | void parsetab(const QString &fileName); | 115 | void parsetab(const QString &fileName); |
116 | 116 | QString checkDiskSpace(const QString &); | |
117 | protected slots: | 117 | protected slots: |
118 | void showFileMenu(); | 118 | void showFileMenu(); |
119 | void cancelMenuTimer(); | 119 | void cancelMenuTimer(); |
120 | void homeButtonPushed(); | 120 | void homeButtonPushed(); |
121 | void docButtonPushed(); | 121 | void docButtonPushed(); |
122 | void SDButtonPushed(); | 122 | void SDButtonPushed(); |
123 | void CFButtonPushed(); | 123 | void CFButtonPushed(); |
124 | void QPEButtonPushed(); | 124 | void QPEButtonPushed(); |
125 | void upDir(); | 125 | void upDir(); |
126 | void currentPathComboChanged(); | 126 | void currentPathComboChanged(); |
127 | void copy(); | 127 | void copy(); |
128 | void copyAs(); | 128 | void copyAs(); |
129 | void copySameDir(); | 129 | void copySameDir(); |
130 | void currentPathComboActivated(const QString &); | 130 | void currentPathComboActivated(const QString &); |
131 | void fillCombo(const QString &); | 131 | void fillCombo(const QString &); |
132 | bool copyFile( const QString & , const QString & ); | 132 | bool copyFile( const QString & , const QString & ); |