summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2005-02-06 04:03:25 (UTC)
committer llornkcor <llornkcor>2005-02-06 04:03:25 (UTC)
commite23dd592fc71aa22c449363231eac2f8ebd2a45b (patch) (unidiff)
tree6944284c2632754357578581b564413f0fa09109
parentb09f9ce74d40f47bc336b4647c6c091a4f3bd5b6 (diff)
downloadopie-e23dd592fc71aa22c449363231eac2f8ebd2a45b.zip
opie-e23dd592fc71aa22c449363231eac2f8ebd2a45b.tar.gz
opie-e23dd592fc71aa22c449363231eac2f8ebd2a45b.tar.bz2
fix #1499 - rename working
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfm.cpp38
-rw-r--r--noncore/apps/advancedfm/advancedfmMenu.cpp3
2 files changed, 5 insertions, 36 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp
index 8cc5d7b..56e3282 100644
--- a/noncore/apps/advancedfm/advancedfm.cpp
+++ b/noncore/apps/advancedfm/advancedfm.cpp
@@ -1,771 +1,739 @@
1/*************************************************************************** 1/***************************************************************************
2 AdvancedFm.cpp 2 AdvancedFm.cpp
3 ------------------- 3 -------------------
4 ** Created: Sat Mar 9 23:33:09 2002 4 ** Created: Sat Mar 9 23:33:09 2002
5 copyright : (C) 2002 by ljp 5 copyright : (C) 2002 by ljp
6 email : ljp@llornkcor.com 6 email : ljp@llornkcor.com
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 ***************************************************************************/ 11 ***************************************************************************/
12#define DEVELOPERS_VERSION 12#define DEVELOPERS_VERSION
13#include "advancedfm.h" 13#include "advancedfm.h"
14 14
15#include <opie2/odebug.h> 15#include <opie2/odebug.h>
16 16
17#include <opie2/ostorageinfo.h> 17#include <opie2/ostorageinfo.h>
18 18
19#include <qpe/qpeapplication.h> 19#include <qpe/qpeapplication.h>
20#include <qpe/config.h> 20#include <qpe/config.h>
21#include <qpe/mimetype.h> 21#include <qpe/mimetype.h>
22#include <qpe/applnk.h> 22#include <qpe/applnk.h>
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24#include <qpe/menubutton.h> 24#include <qpe/menubutton.h>
25 25
26#include <qcombobox.h> 26#include <qcombobox.h>
27#include <qpopupmenu.h> 27#include <qpopupmenu.h>
28#include <qlistview.h> 28#include <qlistview.h>
29#include <qmessagebox.h> 29#include <qmessagebox.h>
30#include <qlineedit.h> 30#include <qlineedit.h>
31 31
32 32
33#include <sys/stat.h> 33#include <sys/stat.h>
34#include <time.h> 34#include <time.h>
35#include <dirent.h> 35#include <dirent.h>
36#include <fcntl.h> 36#include <fcntl.h>
37#include <sys/vfs.h> 37#include <sys/vfs.h>
38#include <mntent.h> 38#include <mntent.h>
39 39
40using namespace Opie::Ui; 40using namespace Opie::Ui;
41 41
42AdvancedFm::AdvancedFm(QWidget *,const char*, WFlags ) 42AdvancedFm::AdvancedFm(QWidget *,const char*, WFlags )
43 : QMainWindow( ) { 43 : QMainWindow( ) {
44 init(); 44 init();
45 renameBox = 0; 45 renameBox = 0;
46 whichTab = 1; 46 whichTab = 1;
47 unknownXpm = Resource::loadImage("UnknownDocument").smoothScale(AppLnk::smallIconSize(),AppLnk::smallIconSize() ); 47 unknownXpm = Resource::loadImage("UnknownDocument").smoothScale(AppLnk::smallIconSize(),AppLnk::smallIconSize() );
48 48
49 initConnections(); 49 initConnections();
50 rePopulate(); 50 rePopulate();
51 channel = new QCopChannel( "QPE/Application/advancedfm", this ); 51 channel = new QCopChannel( "QPE/Application/advancedfm", this );
52 connect(channel,SIGNAL(received(const QCString&,const QByteArray&)),this,SLOT(qcopReceive(const QCString&,const QByteArray&))); 52 connect(channel,SIGNAL(received(const QCString&,const QByteArray&)),this,SLOT(qcopReceive(const QCString&,const QByteArray&)));
53 switchToLocalTab(); 53 switchToLocalTab();
54} 54}
55 55
56AdvancedFm::~AdvancedFm() { 56AdvancedFm::~AdvancedFm() {
57} 57}
58 58
59 59
60void AdvancedFm::cleanUp() { 60void AdvancedFm::cleanUp() {
61 QString sfile=QDir::homeDirPath(); 61 QString sfile=QDir::homeDirPath();
62 if(sfile.right(1) != "/") 62 if(sfile.right(1) != "/")
63 sfile+="/._temp"; 63 sfile+="/._temp";
64 else 64 else
65 sfile+="._temp"; 65 sfile+="._temp";
66 QFile file( sfile); 66 QFile file( sfile);
67 if(file.exists()) 67 if(file.exists())
68 file.remove(); 68 file.remove();
69} 69}
70 70
71void AdvancedFm::tabChanged(QWidget *wd) { 71void AdvancedFm::tabChanged(QWidget *wd) {
72 if(wd == tab) { 72 if(wd == tab) {
73 whichTab = 1; 73 whichTab = 1;
74 viewMenu->setItemChecked(viewMenu->idAt(0), true); 74 viewMenu->setItemChecked(viewMenu->idAt(0), true);
75 viewMenu->setItemChecked(viewMenu->idAt(1), false); 75 viewMenu->setItemChecked(viewMenu->idAt(1), false);
76 // qDebug("tabchanged: LOCAL VIEW SHOWN"); 76 // qDebug("tabchanged: LOCAL VIEW SHOWN");
77 } 77 }
78 78
79 else if(wd == tab_2) { 79 else if(wd == tab_2) {
80 whichTab = 2; 80 whichTab = 2;
81 viewMenu->setItemChecked(viewMenu->idAt(0), false); 81 viewMenu->setItemChecked(viewMenu->idAt(0), false);
82 viewMenu->setItemChecked(viewMenu->idAt(1), true); 82 viewMenu->setItemChecked(viewMenu->idAt(1), true);
83 // qDebug("tabchanged: REMOTE VIEW SHOWN"); 83 // qDebug("tabchanged: REMOTE VIEW SHOWN");
84 } 84 }
85 qApp->processEvents(); 85 qApp->processEvents();
86 QString path = CurrentDir()->canonicalPath(); 86 QString path = CurrentDir()->canonicalPath();
87 87
88 chdir( path.latin1()); 88 chdir( path.latin1());
89 currentPathCombo->lineEdit()->setText(path); 89 currentPathCombo->lineEdit()->setText(path);
90} 90}
91 91
92 92
93void AdvancedFm::populateView() { 93void AdvancedFm::populateView() {
94 94
95 QPixmap pm; 95 QPixmap pm;
96 QListView *thisView = CurrentView(); 96 QListView *thisView = CurrentView();
97 QDir *thisDir = CurrentDir(); 97 QDir *thisDir = CurrentDir();
98 QString path = thisDir->canonicalPath(); 98 QString path = thisDir->canonicalPath();
99 99
100 thisView->clear(); 100 thisView->clear();
101 thisDir->setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 101 thisDir->setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
102 thisDir->setMatchAllDirs(TRUE); 102 thisDir->setMatchAllDirs(TRUE);
103 thisDir->setNameFilter(filterStr); 103 thisDir->setNameFilter(filterStr);
104 QString fileL, fileS, fileDate; 104 QString fileL, fileS, fileDate;
105 105
106 QString fs = getFileSystemType((const QString &) path); 106 QString fs = getFileSystemType((const QString &) path);
107 setCaption(tr("AdvancedFm :: ")+fs+" :: " 107 setCaption(tr("AdvancedFm :: ")+fs+" :: "
108 +checkDiskSpace((const QString &) path)+ tr(" kB free") ); 108 +checkDiskSpace((const QString &) path)+ tr(" kB free") );
109 bool isDir = FALSE; 109 bool isDir = FALSE;
110 110
111 const QFileInfoList *list = thisDir->entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); 111 const QFileInfoList *list = thisDir->entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/);
112 QFileInfoListIterator it(*list); 112 QFileInfoListIterator it(*list);
113 QFileInfo *fi; 113 QFileInfo *fi;
114 while ( (fi=it.current()) ) { 114 while ( (fi=it.current()) ) {
115 if (fi->isSymLink() ) { 115 if (fi->isSymLink() ) {
116 QString symLink = fi->readLink(); 116 QString symLink = fi->readLink();
117 QFileInfo sym( symLink); 117 QFileInfo sym( symLink);
118 fileS.sprintf( "%10i", sym.size() ); 118 fileS.sprintf( "%10i", sym.size() );
119 fileL = fi->fileName() +" -> " + sym.filePath().data(); 119 fileL = fi->fileName() +" -> " + sym.filePath().data();
120 fileDate = sym.lastModified().toString(); 120 fileDate = sym.lastModified().toString();
121 } else { 121 } else {
122 fileS.sprintf( "%10i", fi->size() ); 122 fileS.sprintf( "%10i", fi->size() );
123 fileL = fi->fileName(); 123 fileL = fi->fileName();
124 fileDate= fi->lastModified().toString(); 124 fileDate= fi->lastModified().toString();
125 if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) { 125 if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) {
126// if(fileL == "..") 126// if(fileL == "..")
127 fileL += "/"; 127 fileL += "/";
128 isDir=TRUE; 128 isDir=TRUE;
129 } 129 }
130 } 130 }
131 QFileInfo fileInfo( path + "/" + fileL); 131 QFileInfo fileInfo( path + "/" + fileL);
132 132
133 if(fileL !="./" && fi->exists()) { 133 if(fileL !="./" && fi->exists()) {
134 item = new QListViewItem( thisView, fileL, fileS , fileDate); 134 item = new QListViewItem( thisView, fileL, fileS , fileDate);
135 135
136 if(isDir || fileL.find("/",0,TRUE) != -1) { 136 if(isDir || fileL.find("/",0,TRUE) != -1) {
137 137
138 if( !QDir( fi->filePath() ).isReadable()) //is directory 138 if( !QDir( fi->filePath() ).isReadable()) //is directory
139 pm = Resource::loadPixmap( "lockedfolder" ); 139 pm = Resource::loadPixmap( "lockedfolder" );
140 else 140 else
141 pm= Resource::loadPixmap( "folder" ); 141 pm= Resource::loadPixmap( "folder" );
142 } 142 }
143 else if ( fs == "vfat" && fileInfo.filePath().contains("/bin") ) { 143 else if ( fs == "vfat" && fileInfo.filePath().contains("/bin") ) {
144 pm = Resource::loadPixmap( "exec"); 144 pm = Resource::loadPixmap( "exec");
145 } 145 }
146 else if( (fileInfo.permission( QFileInfo::ExeUser) 146 else if( (fileInfo.permission( QFileInfo::ExeUser)
147 | fileInfo.permission( QFileInfo::ExeGroup) 147 | fileInfo.permission( QFileInfo::ExeGroup)
148 | fileInfo.permission( QFileInfo::ExeOther)) && fs != "vfat" ) { 148 | fileInfo.permission( QFileInfo::ExeOther)) && fs != "vfat" ) {
149 pm = Resource::loadPixmap( "exec"); 149 pm = Resource::loadPixmap( "exec");
150 } 150 }
151 else if( !fi->isReadable() ) { 151 else if( !fi->isReadable() ) {
152 pm = Resource::loadPixmap( "locked" ); 152 pm = Resource::loadPixmap( "locked" );
153 } 153 }
154 else { //everything else goes by mimetype 154 else { //everything else goes by mimetype
155 MimeType mt(fi->filePath()); 155 MimeType mt(fi->filePath());
156 pm=mt.pixmap(); //sets the correct pixmap for mimetype 156 pm=mt.pixmap(); //sets the correct pixmap for mimetype
157 if(pm.isNull()) { 157 if(pm.isNull()) {
158 pm = unknownXpm; 158 pm = unknownXpm;
159 } 159 }
160 } 160 }
161 if( fi->isSymLink() || fileL.find("->",0,TRUE) != -1) { 161 if( fi->isSymLink() || fileL.find("->",0,TRUE) != -1) {
162 // odebug << " overlay link image" << oendl; 162 // odebug << " overlay link image" << oendl;
163 pm= Resource::loadPixmap( "advancedfm/symlink" ); 163 pm= Resource::loadPixmap( "advancedfm/symlink" );
164 // pm= Resource::loadPixmap( "folder" ); 164 // pm= Resource::loadPixmap( "folder" );
165// QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); 165// QPixmap lnk = Resource::loadPixmap( "opie/symlink" );
166// QPainter painter( &pm ); 166// QPainter painter( &pm );
167// painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); 167// painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk );
168// pm.setMask( pm.createHeuristicMask( FALSE ) ); 168// pm.setMask( pm.createHeuristicMask( FALSE ) );
169 } 169 }
170 item->setPixmap( 0,pm); 170 item->setPixmap( 0,pm);
171 171
172 } 172 }
173 isDir=FALSE; 173 isDir=FALSE;
174 ++it; 174 ++it;
175 } 175 }
176 176
177 if( path.find("dev",0,TRUE) != -1) { 177 if( path.find("dev",0,TRUE) != -1) {
178 struct stat buf; 178 struct stat buf;
179 dev_t devT; 179 dev_t devT;
180 DIR *dir; 180 DIR *dir;
181 struct dirent *mydirent; 181 struct dirent *mydirent;
182 182
183 if((dir = opendir( path.latin1())) != NULL) 183 if((dir = opendir( path.latin1())) != NULL)
184 while ((mydirent = readdir(dir)) != NULL) { 184 while ((mydirent = readdir(dir)) != NULL) {
185 lstat( mydirent->d_name, &buf); 185 lstat( mydirent->d_name, &buf);
186// odebug << mydirent->d_name << oendl; 186// odebug << mydirent->d_name << oendl;
187 fileL.sprintf("%s", mydirent->d_name); 187 fileL.sprintf("%s", mydirent->d_name);
188 devT = buf.st_dev; 188 devT = buf.st_dev;
189 fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF); 189 fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF);
190 fileDate.sprintf("%s", ctime( &buf.st_mtime)); 190 fileDate.sprintf("%s", ctime( &buf.st_mtime));
191 if( fileL.find(".") == -1 ) { 191 if( fileL.find(".") == -1 ) {
192 item= new QListViewItem( thisView, fileL, fileS, fileDate); 192 item= new QListViewItem( thisView, fileL, fileS, fileDate);
193 pm = unknownXpm; 193 pm = unknownXpm;
194 item->setPixmap( 0,pm); 194 item->setPixmap( 0,pm);
195 } 195 }
196 } 196 }
197 197
198 closedir(dir); 198 closedir(dir);
199 } 199 }
200 200
201 thisView->setSorting( 3,FALSE); 201 thisView->setSorting( 3,FALSE);
202 fillCombo( (const QString &) path ); 202 fillCombo( (const QString &) path );
203} 203}
204 204
205void AdvancedFm::rePopulate() { 205void AdvancedFm::rePopulate() {
206 // qDebug("repopulate views"); 206 // qDebug("repopulate views");
207 populateView(); 207 populateView();
208 setOtherTabCurrent(); 208 setOtherTabCurrent();
209 populateView(); 209 populateView();
210} 210}
211 211
212void AdvancedFm::ListClicked(QListViewItem *selectedItem) { 212void AdvancedFm::ListClicked(QListViewItem *selectedItem) {
213 if(selectedItem) { 213 if(selectedItem) {
214 QString strItem=selectedItem->text(0); 214 QString strItem=selectedItem->text(0);
215// owarn << strItem << oendl; 215// owarn << strItem << oendl;
216 QString strSize=selectedItem->text(1); 216 QString strSize=selectedItem->text(1);
217 strSize=strSize.stripWhiteSpace(); 217 strSize=strSize.stripWhiteSpace();
218 bool isDirectory = false; 218 bool isDirectory = false;
219 QString strItem2; 219 QString strItem2;
220 220
221 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) {//if symlink 221 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) {//if symlink
222 strItem2 = dealWithSymName((const QString&)strItem); 222 strItem2 = dealWithSymName((const QString&)strItem);
223 if(QDir(strItem2).exists() ) 223 if(QDir(strItem2).exists() )
224 strItem = strItem2; 224 strItem = strItem2;
225 } 225 }
226 226
227 if( strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { 227 if( strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
228 228
229 if(QDir(strItem).exists()) 229 if(QDir(strItem).exists())
230 isDirectory = true; 230 isDirectory = true;
231 } 231 }
232 232
233 if( isDirectory ) { 233 if( isDirectory ) {
234 CurrentDir()->cd( strItem, TRUE); 234 CurrentDir()->cd( strItem, TRUE);
235 populateView(); 235 populateView();
236 CurrentView()->ensureItemVisible( CurrentView()->firstChild()); 236 CurrentView()->ensureItemVisible( CurrentView()->firstChild());
237 } 237 }
238 chdir( strItem.latin1()); 238 chdir( strItem.latin1());
239 } 239 }
240} 240}
241 241
242void AdvancedFm::ListPressed( int mouse, QListViewItem *item, const QPoint& , int ) { 242void AdvancedFm::ListPressed( int mouse, QListViewItem *item, const QPoint& , int ) {
243 Q_UNUSED(item); 243 Q_UNUSED(item);
244 switch (mouse) { 244 switch (mouse) {
245 case 1: 245 case 1:
246 { 246 {
247 if(renameBox != 0 ) { 247 if(renameBox != 0 ) {
248 cancelRename(); 248 cancelRename();
249 } 249 }
250 } 250 }
251 break; 251 break;
252// case 2: 252// case 2:
253// menuTimer.start( 50, TRUE ); 253// menuTimer.start( 50, TRUE );
254// break; 254// break;
255 }; 255 };
256} 256}
257 257
258 258
259void AdvancedFm::refreshCurrentTab() { 259void AdvancedFm::refreshCurrentTab() {
260 populateView(); 260 populateView();
261 // if ( TabWidget->currentWidget() == tab) { 261 // if ( TabWidget->currentWidget() == tab) {
262} 262}
263 263
264void AdvancedFm::switchToLocalTab() { 264void AdvancedFm::switchToLocalTab() {
265 TabWidget->setCurrentWidget(tab); 265 TabWidget->setCurrentWidget(tab);
266 Local_View->setFocus(); 266 Local_View->setFocus();
267 // whichTab = 1; 267 // whichTab = 1;
268} 268}
269 269
270void AdvancedFm::switchToRemoteTab() { 270void AdvancedFm::switchToRemoteTab() {
271 TabWidget->setCurrentWidget(tab_2); 271 TabWidget->setCurrentWidget(tab_2);
272 Remote_View->setFocus(); 272 Remote_View->setFocus();
273 // whichTab = 2; 273 // whichTab = 2;
274} 274}
275 275
276void AdvancedFm::currentPathComboChanged() { 276void AdvancedFm::currentPathComboChanged() {
277 QString pDir = currentPathCombo->lineEdit()->text(); 277 QString pDir = currentPathCombo->lineEdit()->text();
278 if(QDir(pDir).exists()) { 278 if(QDir(pDir).exists()) {
279 CurrentDir()->setPath(pDir ); 279 CurrentDir()->setPath(pDir );
280 populateView(); 280 populateView();
281 } else { 281 } else {
282 QMessageBox::message(tr("Note"),tr("<p>%1 does not exist</p>").arg(pDir)); 282 QMessageBox::message(tr("Note"),tr("<p>%1 does not exist</p>").arg(pDir));
283 } 283 }
284} 284}
285 285
286void AdvancedFm::fillCombo(const QString &currentPath) { 286void AdvancedFm::fillCombo(const QString &currentPath) {
287 287
288 if ( TabWidget->currentWidget() == tab) { 288 if ( TabWidget->currentWidget() == tab) {
289// if ( whichTab == 1) { 289// if ( whichTab == 1) {
290 currentPathCombo->lineEdit()->setText( currentPath); 290 currentPathCombo->lineEdit()->setText( currentPath);
291 if( localDirPathStringList.grep( currentPath,TRUE).isEmpty() ) { 291 if( localDirPathStringList.grep( currentPath,TRUE).isEmpty() ) {
292 currentPathCombo->clear(); 292 currentPathCombo->clear();
293 localDirPathStringList.prepend( currentPath ); 293 localDirPathStringList.prepend( currentPath );
294 currentPathCombo->insertStringList( localDirPathStringList,-1); 294 currentPathCombo->insertStringList( localDirPathStringList,-1);
295 } 295 }
296 } else { 296 } else {
297 currentPathCombo->lineEdit()->setText( currentPath); 297 currentPathCombo->lineEdit()->setText( currentPath);
298 if( remoteDirPathStringList.grep( currentPath,TRUE).isEmpty() ) { 298 if( remoteDirPathStringList.grep( currentPath,TRUE).isEmpty() ) {
299 currentPathCombo->clear(); 299 currentPathCombo->clear();
300 remoteDirPathStringList.prepend( currentPath ); 300 remoteDirPathStringList.prepend( currentPath );
301 currentPathCombo->insertStringList( remoteDirPathStringList,-1); 301 currentPathCombo->insertStringList( remoteDirPathStringList,-1);
302 } 302 }
303 } 303 }
304} 304}
305 305
306QStringList AdvancedFm::getPath() { 306QStringList AdvancedFm::getPath() {
307 QStringList strList; 307 QStringList strList;
308 QListView *thisView=CurrentView(); 308 QListView *thisView=CurrentView();
309 QList<QListViewItem> * getSelectedItems( QListView * thisView ); 309 QList<QListViewItem> * getSelectedItems( QListView * thisView );
310 QListViewItemIterator it( thisView ); 310 QListViewItemIterator it( thisView );
311 for ( ; it.current(); ++it ) { 311 for ( ; it.current(); ++it ) {
312 if ( it.current()->isSelected() ) { 312 if ( it.current()->isSelected() ) {
313 strList << it.current()->text(0); 313 strList << it.current()->text(0);
314// odebug << it.current()->text(0) << oendl; 314// odebug << it.current()->text(0) << oendl;
315 } 315 }
316 } 316 }
317 return strList; 317 return strList;
318} 318}
319 319
320void AdvancedFm::changeTo(const QString &dir) { 320void AdvancedFm::changeTo(const QString &dir) {
321 chdir( dir.latin1()); 321 chdir( dir.latin1());
322 CurrentDir()->cd(dir, TRUE); 322 CurrentDir()->cd(dir, TRUE);
323 populateView(); 323 populateView();
324 update(); 324 update();
325} 325}
326 326
327void AdvancedFm::homeButtonPushed() { 327void AdvancedFm::homeButtonPushed() {
328 changeTo(QDir::homeDirPath()); 328 changeTo(QDir::homeDirPath());
329} 329}
330 330
331void AdvancedFm::docButtonPushed() { 331void AdvancedFm::docButtonPushed() {
332 changeTo(QPEApplication::documentDir()); 332 changeTo(QPEApplication::documentDir());
333} 333}
334 334
335void AdvancedFm::SDButtonPushed() { 335void AdvancedFm::SDButtonPushed() {
336 Opie::Core::OStorageInfo info; 336 Opie::Core::OStorageInfo info;
337 changeTo(info.sdPath()); 337 changeTo(info.sdPath());
338} 338}
339 339
340void AdvancedFm::CFButtonPushed() { 340void AdvancedFm::CFButtonPushed() {
341 Opie::Core::OStorageInfo info; 341 Opie::Core::OStorageInfo info;
342 changeTo(info.cfPath()); 342 changeTo(info.cfPath());
343} 343}
344 344
345void AdvancedFm::QPEButtonPushed() { 345void AdvancedFm::QPEButtonPushed() {
346 changeTo(QPEApplication::qpeDir()); 346 changeTo(QPEApplication::qpeDir());
347} 347}
348 348
349void AdvancedFm::doAbout() { 349void AdvancedFm::doAbout() {
350 QMessageBox::message("AdvancedFm",tr("<P>Advanced FileManager is copyright 2002-2003 by L.J.Potter<llornkcor@handhelds.org> and is licensed by the GPL</P>")); 350 QMessageBox::message("AdvancedFm",tr("<P>Advanced FileManager is copyright 2002-2003 by L.J.Potter<llornkcor@handhelds.org> and is licensed by the GPL</P>"));
351} 351}
352 352
353void AdvancedFm::keyPressEvent( QKeyEvent *e) { 353void AdvancedFm::keyPressEvent( QKeyEvent *e) {
354 Q_UNUSED(e); 354 Q_UNUSED(e);
355} 355}
356 356
357void AdvancedFm::keyReleaseEvent( QKeyEvent *e) { 357void AdvancedFm::keyReleaseEvent( QKeyEvent *e) {
358// if( CurrentView()->hasFocus() ) 358// if( CurrentView()->hasFocus() )
359// e->ignore(); 359// e->ignore();
360 if( currentPathCombo->lineEdit()->hasFocus()) { 360
361 if( currentPathCombo->lineEdit()->hasFocus()) {
361 // qDebug("shout!"); 362 // qDebug("shout!");
362 } 363 }
363 364
364 else if( e->key() == Key_Left ) 365 else if( e->key() == Key_Left )
365 upDir(); 366 upDir();
366 else if( e->key() == Key_Return || e->key() == Key_Enter) 367 else if( e->key() == Key_Return || e->key() == Key_Enter)
367 navigateToSelected(); 368 navigateToSelected();
368 else if( e->key() == Key_Tab) 369 else if( e->key() == Key_Tab)
369 setOtherTabCurrent(); 370 setOtherTabCurrent();
370 else if( e->key() == Key_Delete ) 371 else if( e->key() == Key_Delete )
371 del(); 372 del();
372 else if( e->key() == Key_A)
373 copyAs();
374 else if( e->key() == Key_C)
375 copy();
376 else if( e->key() == Key_E)
377 runThis();
378 else if( e->key() == Key_G)
379 currentPathCombo->lineEdit()->setFocus();
380 else if( e->key() == Key_H )
381 showHidden();
382 else if( e->key() == Key_I)
383 fileStatus();
384 else if( e->key() == Key_M)
385 move();
386 else if( e->key() == Key_N )
387 mkDir();
388 else if( e->key() == Key_P)
389 filePerms();
390 else if( e->key() == Key_R )
391 rn();
392 else if( e->key() == Key_U )
393 upDir();
394 else if( e->key() == Key_1)
395 switchToLocalTab();
396 else if( e->key() == Key_2)
397 switchToRemoteTab();
398 else if( e->key() == Key_3)
399 CFButtonPushed();
400 else if( e->key() == Key_4)
401 SDButtonPushed();
402 else if( e->key() == Key_5 )
403 homeButtonPushed();
404 else if( e->key() == Key_6 )
405 docButtonPushed();
406 else 373 else
407 e->accept(); 374 e->accept();
375
408} 376}
409 377
410 378
411void AdvancedFm::parsetab(const QString &fileName) { 379void AdvancedFm::parsetab(const QString &fileName) {
412 380
413 fileSystemTypeList.clear(); 381 fileSystemTypeList.clear();
414 fsList.clear(); 382 fsList.clear();
415 struct mntent *me; 383 struct mntent *me;
416 FILE *mntfp = setmntent( fileName.latin1(), "r" ); 384 FILE *mntfp = setmntent( fileName.latin1(), "r" );
417 if ( mntfp ) { 385 if ( mntfp ) {
418 while ( (me = getmntent( mntfp )) != 0 ) { 386 while ( (me = getmntent( mntfp )) != 0 ) {
419 QString deviceName = me->mnt_fsname; 387 QString deviceName = me->mnt_fsname;
420 QString filesystemType = me->mnt_type; 388 QString filesystemType = me->mnt_type;
421 QString mountDir = me->mnt_dir; 389 QString mountDir = me->mnt_dir;
422 if(deviceName != "none") { 390 if(deviceName != "none") {
423 if( fsList.contains(filesystemType) == 0 391 if( fsList.contains(filesystemType) == 0
424 & filesystemType.find("proc",0,TRUE) == -1 392 & filesystemType.find("proc",0,TRUE) == -1
425 & filesystemType.find("cramfs",0,TRUE) == -1 393 & filesystemType.find("cramfs",0,TRUE) == -1
426 & filesystemType.find("auto",0,TRUE) == -1) 394 & filesystemType.find("auto",0,TRUE) == -1)
427 fsList << filesystemType; 395 fsList << filesystemType;
428 fileSystemTypeList << mountDir+"::"+filesystemType; 396 fileSystemTypeList << mountDir+"::"+filesystemType;
429 } 397 }
430 } 398 }
431 } 399 }
432 endmntent( mntfp ); 400 endmntent( mntfp );
433} 401}
434 402
435QString AdvancedFm::getFileSystemType(const QString &currentText) { 403QString AdvancedFm::getFileSystemType(const QString &currentText) {
436 parsetab("/etc/mtab"); //why did TT forget filesystem type? 404 parsetab("/etc/mtab"); //why did TT forget filesystem type?
437 QString current = currentText;//.right( currentText.length()-1); 405 QString current = currentText;//.right( currentText.length()-1);
438 QString baseFs; 406 QString baseFs;
439 for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) { 407 for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) {
440 QString temp = (*it); 408 QString temp = (*it);
441 QString path = temp.left(temp.find("::",0,TRUE) ); 409 QString path = temp.left(temp.find("::",0,TRUE) );
442 path = path.right( path.length()-1); 410 path = path.right( path.length()-1);
443 if(path.isEmpty()) baseFs = temp.right( temp.length() - temp.find("::",0,TRUE) - 2); 411 if(path.isEmpty()) baseFs = temp.right( temp.length() - temp.find("::",0,TRUE) - 2);
444 if( current.find( path,0,TRUE) != -1 && !path.isEmpty()) { 412 if( current.find( path,0,TRUE) != -1 && !path.isEmpty()) {
445 return temp.right( temp.length() - temp.find("::",0,TRUE) - 2); 413 return temp.right( temp.length() - temp.find("::",0,TRUE) - 2);
446 } 414 }
447 } 415 }
448 return baseFs; 416 return baseFs;
449} 417}
450 418
451QString AdvancedFm::getDiskSpace( const QString &path) { 419QString AdvancedFm::getDiskSpace( const QString &path) {
452 struct statfs fss; 420 struct statfs fss;
453 if ( !statfs( path.latin1(), &fss ) ) { 421 if ( !statfs( path.latin1(), &fss ) ) {
454 int blkSize = fss.f_bsize; 422 int blkSize = fss.f_bsize;
455 // int totalBlks = fs.f_blocks; 423 // int totalBlks = fs.f_blocks;
456 int availBlks = fss.f_bavail; 424 int availBlks = fss.f_bavail;
457 425
458 long mult = blkSize / 1024; 426 long mult = blkSize / 1024;
459 long div = 1024 / blkSize; 427 long div = 1024 / blkSize;
460 if ( !mult ) mult = 1; 428 if ( !mult ) mult = 1;
461 if ( !div ) div = 1; 429 if ( !div ) div = 1;
462 430
463 return QString::number(availBlks * mult / div); 431 return QString::number(availBlks * mult / div);
464 } 432 }
465 return ""; 433 return "";
466} 434}
467 435
468 436
469void AdvancedFm::showFileMenu() { 437void AdvancedFm::showFileMenu() {
470 QString curApp; 438 QString curApp;
471 curApp = CurrentView()->currentItem()->text(0); 439 curApp = CurrentView()->currentItem()->text(0);
472 440
473 MimeType mt(curApp); 441 MimeType mt(curApp);
474 const AppLnk* app = mt.application(); 442 const AppLnk* app = mt.application();
475 QFile fi(curApp); 443 QFile fi(curApp);
476 QPopupMenu *m = new QPopupMenu(0); 444 QPopupMenu *m = new QPopupMenu(0);
477 QPopupMenu *n = new QPopupMenu(0); 445 QPopupMenu *n = new QPopupMenu(0);
478 // QPopupMenu *o = new QPopupMenu(0); 446 // QPopupMenu *o = new QPopupMenu(0);
479 m->insertItem(tr("Show Hidden Files"),this,SLOT(showHidden())); 447 m->insertItem(tr("Show Hidden Files"),this,SLOT(showHidden()));
480 448
481 if ( QFileInfo(fi).isDir()) { 449 if ( QFileInfo(fi).isDir()) {
482 m->insertSeparator(); 450 m->insertSeparator();
483 m->insertItem(tr("Change Directory"),this,SLOT(doDirChange())); 451 m->insertItem(tr("Change Directory"),this,SLOT(doDirChange()));
484 } else { 452 } else {
485 453
486 if (app) 454 if (app)
487 m->insertItem(app->pixmap(),tr("Open in " + app->name()),this,SLOT(runThis())); 455 m->insertItem(app->pixmap(),tr("Open in " + app->name()),this,SLOT(runThis()));
488 else if(QFileInfo(fi).isExecutable() ) //damn opie doesnt like this 456 else if(QFileInfo(fi).isExecutable() ) //damn opie doesnt like this
489 m->insertItem(tr("Execute"),this,SLOT(runThis())); 457 m->insertItem(tr("Execute"),this,SLOT(runThis()));
490 m->insertItem(Resource::loadPixmap("txt"),tr("Open as text"),this,SLOT(runText())); 458 m->insertItem(Resource::loadPixmap("txt"),tr("Open as text"),this,SLOT(runText()));
491 } 459 }
492 460
493 m->insertItem(tr("Actions"),n); 461 m->insertItem(tr("Actions"),n);
494 n->insertItem(tr("Make Directory"),this,SLOT(makeDir())); 462 n->insertItem(tr("Make Directory"),this,SLOT(makeDir()));
495 463
496 n->insertItem(tr("Make Symlink"),this,SLOT(mkSym())); 464 n->insertItem(tr("Make Symlink"),this,SLOT(mkSym()));
497 465
498 n->insertSeparator(); 466 n->insertSeparator();
499 n->insertItem(tr("Rename"),this,SLOT(renameIt())); 467 n->insertItem(tr("Rename"),this,SLOT(renameIt()));
500 468
501 n->insertItem(tr("Copy"),this,SLOT(copyTimer())); 469 n->insertItem(tr("Copy"),this,SLOT(copyTimer()));
502 n->insertItem(tr("Copy As"),this,SLOT(copyAsTimer())); 470 n->insertItem(tr("Copy As"),this,SLOT(copyAsTimer()));
503 n->insertItem(tr("Copy Same Dir"),this,SLOT(copySameDirTimer())); 471 n->insertItem(tr("Copy Same Dir"),this,SLOT(copySameDirTimer()));
504 n->insertItem(tr("Move"),this,SLOT(moveTimer())); 472 n->insertItem(tr("Move"),this,SLOT(moveTimer()));
505 473
506 n->insertSeparator(); 474 n->insertSeparator();
507 n->insertItem(tr("Delete"),this,SLOT(doDelete())); 475 n->insertItem(tr("Delete"),this,SLOT(doDelete()));
508 m->insertItem(tr("Add To Documents"),this,SLOT(addToDocs())); 476 m->insertItem(tr("Add To Documents"),this,SLOT(addToDocs()));
509 477
510 m->insertItem(tr("Run Command"),this,SLOT(runCommand())); 478 m->insertItem(tr("Run Command"),this,SLOT(runCommand()));
511 m->insertItem(tr("File Info"),this,SLOT(fileStatus())); 479 m->insertItem(tr("File Info"),this,SLOT(fileStatus()));
512 480
513 m->insertSeparator(); 481 m->insertSeparator();
514 m->insertItem(tr("Set Permissions"),this,SLOT(filePerms())); 482 m->insertItem(tr("Set Permissions"),this,SLOT(filePerms()));
515 483
516#if defined(QT_QWS_OPIE) 484#if defined(QT_QWS_OPIE)
517 m->insertItem(tr("Properties"),this,SLOT(doProperties())); 485 m->insertItem(tr("Properties"),this,SLOT(doProperties()));
518#endif 486#endif
519 m->setCheckable(TRUE); 487 m->setCheckable(TRUE);
520 if (!b) 488 if (!b)
521 m->setItemChecked(m->idAt(0),TRUE); 489 m->setItemChecked(m->idAt(0),TRUE);
522 else 490 else
523 m->setItemChecked(m->idAt(0),FALSE); 491 m->setItemChecked(m->idAt(0),FALSE);
524 492
525 if(Ir::supported()) 493 if(Ir::supported())
526 m->insertItem(tr("Beam File"),this,SLOT(doBeam())); 494 m->insertItem(tr("Beam File"),this,SLOT(doBeam()));
527 m->setFocus(); 495 m->setFocus();
528 496
529 m->exec(QPoint(QCursor::pos().x(),QCursor::pos().y())); 497 m->exec(QPoint(QCursor::pos().x(),QCursor::pos().y()));
530 498
531 if(m) delete m; 499 if(m) delete m;
532} 500}
533 501
534 502
535QString AdvancedFm::checkDiskSpace(const QString &path) { 503QString AdvancedFm::checkDiskSpace(const QString &path) {
536 struct statfs fss; 504 struct statfs fss;
537 if ( !statfs( path.latin1(), &fss ) ) { 505 if ( !statfs( path.latin1(), &fss ) ) {
538 int blkSize = fss.f_bsize; 506 int blkSize = fss.f_bsize;
539// int totalBlks = fs.f_blocks; 507// int totalBlks = fs.f_blocks;
540 int availBlks = fss.f_bavail; 508 int availBlks = fss.f_bavail;
541 509
542 long mult = blkSize / 1024; 510 long mult = blkSize / 1024;
543 long div = 1024 / blkSize; 511 long div = 1024 / blkSize;
544 if ( !mult ) mult = 1; 512 if ( !mult ) mult = 1;
545 if ( !div ) div = 1; 513 if ( !div ) div = 1;
546 514
547 515
548 return QString::number(availBlks * mult / div); 516 return QString::number(availBlks * mult / div);
549 } 517 }
550 return ""; 518 return "";
551} 519}
552 520
553void AdvancedFm::addToDocs() { 521void AdvancedFm::addToDocs() {
554 QStringList strListPaths = getPath(); 522 QStringList strListPaths = getPath();
555 QDir *thisDir = CurrentDir(); 523 QDir *thisDir = CurrentDir();
556 524
557 if( strListPaths.count() > 0) { 525 if( strListPaths.count() > 0) {
558 QString curFile; 526 QString curFile;
559 for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { 527 for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) {
560 curFile = thisDir->canonicalPath()+"/"+(*it); 528 curFile = thisDir->canonicalPath()+"/"+(*it);
561// odebug << curFile << oendl; 529// odebug << curFile << oendl;
562 QFileInfo fi(curFile); 530 QFileInfo fi(curFile);
563 DocLnk f; 531 DocLnk f;
564// curFile.replace(QRegExp("\\..*"),""); 532// curFile.replace(QRegExp("\\..*"),"");
565 f.setName(fi.baseName() ); 533 f.setName(fi.baseName() );
566 f.setFile( curFile); 534 f.setFile( curFile);
567 f.writeLink(); 535 f.writeLink();
568 } 536 }
569 } 537 }
570} 538}
571 539
572 540
573void AdvancedFm::customDirsToMenu() { 541void AdvancedFm::customDirsToMenu() {
574 542
575 Config cfg("AdvancedFm"); 543 Config cfg("AdvancedFm");
576 cfg.setGroup("Menu"); 544 cfg.setGroup("Menu");
577 545
578 QStringList list = cfg.readListEntry( "CustomDir", ','); 546 QStringList list = cfg.readListEntry( "CustomDir", ',');
579 menuButton->insertItems(list ); 547 menuButton->insertItems(list );
580 548
581// for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 549// for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
582// { 550// {
583// customDirMenu->insertItem(*it ); 551// customDirMenu->insertItem(*it );
584// } 552// }
585} 553}
586 554
587void AdvancedFm::dirMenuSelected(int item) { 555void AdvancedFm::dirMenuSelected(int item) {
588 switch(item) 556 switch(item)
589 { 557 {
590 558
591 case -21: 559 case -21:
592 case 0: 560 case 0:
593 addCustomDir(); 561 addCustomDir();
594 break; 562 break;
595 case -22: 563 case -22:
596 case 1: 564 case 1:
597 removeCustomDir(); 565 removeCustomDir();
598 break; 566 break;
599 default: 567 default:
600 { 568 {
601// gotoCustomDir( menuButton->text(item)); 569// gotoCustomDir( menuButton->text(item));
602// gotoCustomDir( customDirMenu->text(item)); 570// gotoCustomDir( customDirMenu->text(item));
603 } 571 }
604 break; 572 break;
605 573
606 }; 574 };
607} 575}
608 576
609void AdvancedFm::addCustomDir() { 577void AdvancedFm::addCustomDir() {
610 Config cfg("AdvancedFm"); 578 Config cfg("AdvancedFm");
611 cfg.setGroup("Menu"); 579 cfg.setGroup("Menu");
612 QString dir; 580 QString dir;
613 QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); 581 QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)',');
614 582
615 dir = CurrentDir()->canonicalPath(); 583 dir = CurrentDir()->canonicalPath();
616 584
617 bool addIt=true; 585 bool addIt=true;
618 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 586 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
619 if( dir == (*it)) { 587 if( dir == (*it)) {
620 addIt=false; 588 addIt=false;
621 } 589 }
622 } 590 }
623 if(addIt) { 591 if(addIt) {
624 menuButton->insertItem(dir); 592 menuButton->insertItem(dir);
625// customDirMenu->insertItem(dir); 593// customDirMenu->insertItem(dir);
626 list << dir; 594 list << dir;
627 } 595 }
628 596
629 cfg.writeEntry("CustomDir", list, ','); 597 cfg.writeEntry("CustomDir", list, ',');
630 cfg.write(); 598 cfg.write();
631} 599}
632 600
633void AdvancedFm::removeCustomDir() { 601void AdvancedFm::removeCustomDir() {
634// odebug << "remove custom dir" << oendl; 602// odebug << "remove custom dir" << oendl;
635 Config cfg("AdvancedFm"); 603 Config cfg("AdvancedFm");
636 cfg.setGroup("Menu"); 604 cfg.setGroup("Menu");
637 QString dir; 605 QString dir;
638 QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); 606 QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)',');
639 QStringList list2; 607 QStringList list2;
640 dir = CurrentDir()->canonicalPath(); 608 dir = CurrentDir()->canonicalPath();
641 int ramble=2; 609 int ramble=2;
642// int ramble=-24; 610// int ramble=-24;
643//first remove list 611//first remove list
644 if(list.grep(dir,true).isEmpty()) { 612 if(list.grep(dir,true).isEmpty()) {
645 QMessageBox::message(tr( "AdvancedFm" ), 613 QMessageBox::message(tr( "AdvancedFm" ),
646 tr("<p>Cannot remove current directory from bookmarks. It is not bookmarked!</p>")); 614 tr("<p>Cannot remove current directory from bookmarks. It is not bookmarked!</p>"));
647 } else { 615 } else {
648 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 616 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
649 if((*it) != dir) { 617 if((*it) != dir) {
650//current item is not our current dir, so add it to temp list 618//current item is not our current dir, so add it to temp list
651 list2 <<(*it); 619 list2 <<(*it);
652 } else { 620 } else {
653// customDirMenu->removeItem( ramble); 621// customDirMenu->removeItem( ramble);
654 menuButton->remove( ramble); 622 menuButton->remove( ramble);
655 623
656 } 624 }
657 ramble++; 625 ramble++;
658// ramble--; 626// ramble--;
659 } 627 }
660 628
661 cfg.writeEntry("CustomDir", list2, ','); 629 cfg.writeEntry("CustomDir", list2, ',');
662 cfg.write(); 630 cfg.write();
663 } 631 }
664// customDirsToMenu(); 632// customDirsToMenu();
665 633
666} 634}
667 635
668void AdvancedFm::gotoCustomDir(const QString &dir) { 636void AdvancedFm::gotoCustomDir(const QString &dir) {
669// odebug << "gotoCustomDir(const QString &dir) " +dir << oendl; 637// odebug << "gotoCustomDir(const QString &dir) " +dir << oendl;
670// QString curDir = dir; 638// QString curDir = dir;
671// QDir *thisDir = CurrentDir(); 639// QDir *thisDir = CurrentDir();
672// if( curDir.isEmpty()) { 640// if( curDir.isEmpty()) {
673// } 641// }
674 if( dir == s_addBookmark) { 642 if( dir == s_addBookmark) {
675 addCustomDir(); 643 addCustomDir();
676 } 644 }
677 if( dir == s_removeBookmark) { 645 if( dir == s_removeBookmark) {
678 removeCustomDir( ); 646 removeCustomDir( );
679 } else { 647 } else {
680 changeTo( dir); 648 changeTo( dir);
681// if(QDir( curDir).exists() ) 649// if(QDir( curDir).exists() )
682// { 650// {
683// thisDir->setPath( curDir ); 651// thisDir->setPath( curDir );
684// chdir( curDir.latin1() ); 652// chdir( curDir.latin1() );
685// thisDir->cd( curDir, TRUE); 653// thisDir->cd( curDir, TRUE);
686// populateView(); 654// populateView();
687// } 655// }
688 } 656 }
689} 657}
690 658
691QDir *AdvancedFm::CurrentDir() { 659QDir *AdvancedFm::CurrentDir() {
692 if ( whichTab == 1) { 660 if ( whichTab == 1) {
693 // qDebug("CurrentTab is Local"); 661 // qDebug("CurrentTab is Local");
694 return &currentDir; 662 return &currentDir;
695 } else { 663 } else {
696 // qDebug("CurrentTab is Remote"); 664 // qDebug("CurrentTab is Remote");
697 return &currentRemoteDir; 665 return &currentRemoteDir;
698 } 666 }
699} 667}
700 668
701QDir *AdvancedFm::OtherDir() { 669QDir *AdvancedFm::OtherDir() {
702 // if ( TabWidget->currentWidget() == tab) { 670 // if ( TabWidget->currentWidget() == tab) {
703 if ( whichTab == 1) { 671 if ( whichTab == 1) {
704 return &currentRemoteDir; 672 return &currentRemoteDir;
705 } else { 673 } else {
706 return &currentDir; 674 return &currentDir;
707 } 675 }
708} 676}
709 677
710QListView * AdvancedFm::CurrentView() { 678QListView * AdvancedFm::CurrentView() {
711 // if ( TabWidget->currentWidget() == tab) { 679 // if ( TabWidget->currentWidget() == tab) {
712 if ( whichTab == 1) { 680 if ( whichTab == 1) {
713 // qDebug("CurrentView: local"); 681 // qDebug("CurrentView: local");
714 return Local_View; 682 return Local_View;
715 } else { 683 } else {
716// owarn << "CurrentView Tab 2" << oendl; 684// owarn << "CurrentView Tab 2" << oendl;
717 // qDebug("CurrentView: remote"); 685 // qDebug("CurrentView: remote");
718 return Remote_View; 686 return Remote_View;
719 } 687 }
720} 688}
721 689
722QListView * AdvancedFm::OtherView() { 690QListView * AdvancedFm::OtherView() {
723 if ( whichTab == 1) 691 if ( whichTab == 1)
724 return Remote_View; 692 return Remote_View;
725 else 693 else
726 return Local_View; 694 return Local_View;
727} 695}
728 696
729void AdvancedFm::setOtherTabCurrent() { 697void AdvancedFm::setOtherTabCurrent() {
730 // qDebug("setOtherTabCurrent() %d",whichTab); 698 // qDebug("setOtherTabCurrent() %d",whichTab);
731 if ( whichTab == 1) { 699 if ( whichTab == 1) {
732 TabWidget->setCurrentWidget(1); 700 TabWidget->setCurrentWidget(1);
733 } else { 701 } else {
734 TabWidget->setCurrentWidget(0); 702 TabWidget->setCurrentWidget(0);
735 } 703 }
736// OtherView()->setFocus(); 704// OtherView()->setFocus();
737 OtherView()->setSelected( CurrentView()->firstChild(), true); 705 OtherView()->setSelected( CurrentView()->firstChild(), true);
738} 706}
739 707
740void AdvancedFm::qcopReceive(const QCString &msg, const QByteArray &data) { 708void AdvancedFm::qcopReceive(const QCString &msg, const QByteArray &data) {
741// odebug << "qcop message "+msg << oendl; 709// odebug << "qcop message "+msg << oendl;
742 QDataStream stream ( data, IO_ReadOnly ); 710 QDataStream stream ( data, IO_ReadOnly );
743 if ( msg == "openDirectory(QString)" ) { 711 if ( msg == "openDirectory(QString)" ) {
744// odebug << "received" << oendl; 712// odebug << "received" << oendl;
745 QString file; 713 QString file;
746 stream >> file; 714 stream >> file;
747 changeTo( (const QString &) file); 715 changeTo( (const QString &) file);
748 } 716 }
749} 717}
750 718
751void AdvancedFm::setDocument(const QString &file) { 719void AdvancedFm::setDocument(const QString &file) {
752 changeTo( file); 720 changeTo( file);
753} 721}
754 722
755 723
756void AdvancedFm::slotSwitchMenu(int item) { 724void AdvancedFm::slotSwitchMenu(int item) {
757 if(item == -23) { 725 if(item == -23) {
758 switchToLocalTab(); 726 switchToLocalTab();
759 tabChanged( tab); 727 tabChanged( tab);
760 } 728 }
761 729
762 if(item == -24) { 730 if(item == -24) {
763 switchToRemoteTab(); 731 switchToRemoteTab();
764 tabChanged( tab_2); 732 tabChanged( tab_2);
765 } 733 }
766} 734}
767 735
768void AdvancedFm::navigateToSelected() { 736void AdvancedFm::navigateToSelected() {
769 if( !CurrentView()->currentItem()) return; 737 if( !CurrentView()->currentItem()) return;
770 doDirChange(); 738 doDirChange();
771} 739}
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp
index 6abdc85..80324eb 100644
--- a/noncore/apps/advancedfm/advancedfmMenu.cpp
+++ b/noncore/apps/advancedfm/advancedfmMenu.cpp
@@ -1,873 +1,874 @@
1/*************************************************************************** 1/***************************************************************************
2 AdvancedFm.cpp 2 AdvancedFm.cpp
3 ------------------- 3 -------------------
4 ** Created: Sat Mar 9 23:33:09 2002 4 ** Created: Sat Mar 9 23:33:09 2002
5 copyright : (C) 2002 by ljp 5 copyright : (C) 2002 by ljp
6 email : ljp@llornkcor.com 6 email : ljp@llornkcor.com
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 ***************************************************************************/ 11 ***************************************************************************/
12 12
13#include "advancedfm.h" 13#include "advancedfm.h"
14#include "output.h" 14#include "output.h"
15#include "filePermissions.h" 15#include "filePermissions.h"
16 16
17/* OPIE */ 17/* OPIE */
18#include <opie2/odebug.h> 18#include <opie2/odebug.h>
19#include <qpe/lnkproperties.h> 19#include <qpe/lnkproperties.h>
20#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21#include <qpe/applnk.h> 21#include <qpe/applnk.h>
22using namespace Opie::Core; 22using namespace Opie::Core;
23 23
24/* QT*/ 24/* QT*/
25 25
26#include <qmessagebox.h> 26#include <qmessagebox.h>
27#include <qpopupmenu.h> 27#include <qpopupmenu.h>
28#include <qlistview.h> 28#include <qlistview.h>
29 29
30/* STD */ 30/* STD */
31 31
32#include <errno.h> 32#include <errno.h>
33#include <stdlib.h> 33#include <stdlib.h>
34#include <unistd.h> 34#include <unistd.h>
35#include <sys/stat.h> 35#include <sys/stat.h>
36#include <dirent.h> 36#include <dirent.h>
37#include <sys/sendfile.h> 37#include <sys/sendfile.h>
38#include <fcntl.h> 38#include <fcntl.h>
39 39
40void AdvancedFm::doDirChange() { 40void AdvancedFm::doDirChange() {
41 QString pathItem = CurrentView()->currentItem()->text(0); 41 QString pathItem = CurrentView()->currentItem()->text(0);
42 if( pathItem == "../") { 42 if( pathItem == "../") {
43 ListClicked( CurrentView()->currentItem()); 43 ListClicked( CurrentView()->currentItem());
44 } else { 44 } else {
45 if( pathItem.find(" -> ",0,TRUE) != -1) 45 if( pathItem.find(" -> ",0,TRUE) != -1)
46 pathItem = dealWithSymName((const QString&)pathItem)+"/"; 46 pathItem = dealWithSymName((const QString&)pathItem)+"/";
47// owarn << pathItem << oendl; 47// owarn << pathItem << oendl;
48 changeTo( CurrentDir()->path()+"/"+pathItem.left( pathItem.length() - 1) ); 48 changeTo( CurrentDir()->path()+"/"+pathItem.left( pathItem.length() - 1) );
49 } 49 }
50} 50}
51 51
52void AdvancedFm::showMenuHidden() { 52void AdvancedFm::showMenuHidden() {
53 if (b) { 53 if (b) {
54 CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 54 CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
55 OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 55 OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
56 fileMenu->setItemChecked( fileMenu->idAt(0),TRUE); 56 fileMenu->setItemChecked( fileMenu->idAt(0),TRUE);
57 } else { 57 } else {
58 CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 58 CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
59 OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 59 OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
60 fileMenu->setItemChecked( fileMenu->idAt(0),FALSE); 60 fileMenu->setItemChecked( fileMenu->idAt(0),FALSE);
61 } 61 }
62 b = !b; 62 b = !b;
63 populateView(); 63 populateView();
64} 64}
65 65
66void AdvancedFm::showHidden() { 66void AdvancedFm::showHidden() {
67 if (b) { 67 if (b) {
68 CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 68 CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
69 OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 69 OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
70 } else { 70 } else {
71 CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 71 CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
72 OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 72 OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
73 } 73 }
74 populateView(); 74 populateView();
75} 75}
76 76
77QString AdvancedFm::dealWithSymName(const QString &fileName) { 77QString AdvancedFm::dealWithSymName(const QString &fileName) {
78 QString strItem = fileName; 78 QString strItem = fileName;
79 return strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); 79 return strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4);
80} 80}
81 81
82void AdvancedFm::runThis() { 82void AdvancedFm::runThis() {
83 if( !CurrentView()->currentItem()) return; 83 if( !CurrentView()->currentItem()) return;
84 QString fs; 84 QString fs;
85 QDir *thisDir = CurrentDir(); 85 QDir *thisDir = CurrentDir();
86 86
87 QString curFile = CurrentView()->currentItem()->text(0); 87 QString curFile = CurrentView()->currentItem()->text(0);
88 QString path = thisDir->canonicalPath(); 88 QString path = thisDir->canonicalPath();
89 89
90 if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 ) //if symlink 90 if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 ) //if symlink
91 91
92 curFile = dealWithSymName((const QString&)curFile); 92 curFile = dealWithSymName((const QString&)curFile);
93 93
94 if(curFile != "../") { 94 if(curFile != "../") {
95 95
96 fs = getFileSystemType((const QString &) path); 96 fs = getFileSystemType((const QString &) path);
97 QFileInfo fileInfo( path + "/" + curFile); 97 QFileInfo fileInfo( path + "/" + curFile);
98// odebug << fileInfo.owner() << oendl; 98// odebug << fileInfo.owner() << oendl;
99 99
100 if( (fileInfo.permission( QFileInfo::ExeUser) 100 if( (fileInfo.permission( QFileInfo::ExeUser)
101 | fileInfo.permission( QFileInfo::ExeGroup) 101 | fileInfo.permission( QFileInfo::ExeGroup)
102 | fileInfo.permission( QFileInfo::ExeOther)) // & fs.find("vfat",0,TRUE) == -1) { 102 | fileInfo.permission( QFileInfo::ExeOther)) // & fs.find("vfat",0,TRUE) == -1) {
103 | fs == "vfat" && fileInfo.filePath().contains("/bin") ) { 103 | fs == "vfat" && fileInfo.filePath().contains("/bin") ) {
104 QCopEnvelope e("QPE/System", "execute(QString)" ); 104 QCopEnvelope e("QPE/System", "execute(QString)" );
105 e << curFile; 105 e << curFile;
106 } else { 106 } else {
107 curFile = path + "/" + curFile; 107 curFile = path + "/" + curFile;
108 DocLnk nf(curFile); 108 DocLnk nf(curFile);
109 QString execStr = nf.exec(); 109 QString execStr = nf.exec();
110// odebug << execStr << oendl; 110// odebug << execStr << oendl;
111 if( execStr.isEmpty() ) { 111 if( execStr.isEmpty() ) {
112 } else { 112 } else {
113 nf.execute(); 113 nf.execute();
114 } 114 }
115 } 115 }
116 } 116 }
117} 117}
118 118
119void AdvancedFm::runText() { 119void AdvancedFm::runText() {
120 if( !CurrentView()->currentItem()) return; 120 if( !CurrentView()->currentItem()) return;
121 QString curFile = CurrentView()->currentItem()->text(0); 121 QString curFile = CurrentView()->currentItem()->text(0);
122 if(curFile != "../") { 122 if(curFile != "../") {
123 if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 ) //if symlink 123 if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 ) //if symlink
124 curFile = dealWithSymName((const QString&)curFile); 124 curFile = dealWithSymName((const QString&)curFile);
125 curFile = CurrentDir()->canonicalPath()+"/"+curFile; 125 curFile = CurrentDir()->canonicalPath()+"/"+curFile;
126 QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" ); 126 QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" );
127 e << curFile; 127 e << curFile;
128 } 128 }
129} 129}
130 130
131void AdvancedFm::makeDir() { 131void AdvancedFm::makeDir() {
132 InputDialog *fileDlg; 132 InputDialog *fileDlg;
133 fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); 133 fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0);
134 fileDlg->exec(); 134 fileDlg->exec();
135 if( fileDlg->result() == 1 ) { 135 if( fileDlg->result() == 1 ) {
136 QDir *thisDir = CurrentDir(); 136 QDir *thisDir = CurrentDir();
137 QString filename = fileDlg->LineEdit1->text(); 137 QString filename = fileDlg->LineEdit1->text();
138 thisDir->mkdir( thisDir->canonicalPath()+"/"+filename); 138 thisDir->mkdir( thisDir->canonicalPath()+"/"+filename);
139 } 139 }
140 populateView(); 140 populateView();
141} 141}
142 142
143void AdvancedFm::doDelete() { 143void AdvancedFm::doDelete() {
144 QStringList curFileList = getPath(); 144 QStringList curFileList = getPath();
145 bool doMsg=true; 145 bool doMsg=true;
146 int count = curFileList.count(); 146 int count = curFileList.count();
147 if( count > 0) { 147 if( count > 0) {
148 if(count > 1 ) { 148 if(count > 1 ) {
149 QString msg; 149 QString msg;
150 msg=tr("<p>Really delete %1 files?</p>").arg(count); 150 msg=tr("<p>Really delete %1 files?</p>").arg(count);
151 switch ( QMessageBox::warning(this,tr("Delete"),msg 151 switch ( QMessageBox::warning(this,tr("Delete"),msg
152 ,tr("Yes"),tr("No"),0,0,1) ) 152 ,tr("Yes"),tr("No"),0,0,1) )
153 { 153 {
154 case 0: 154 case 0:
155 doMsg=false; 155 doMsg=false;
156 break; 156 break;
157 case 1: 157 case 1:
158 return; 158 return;
159 break; 159 break;
160 default: 160 default:
161 return; 161 return;
162 break; 162 break;
163 }; 163 };
164 } 164 }
165 165
166 QString myFile; 166 QString myFile;
167 167
168 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 168 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
169 myFile = (*it); 169 myFile = (*it);
170 if( myFile.find(" -> ",0,TRUE) != -1) 170 if( myFile.find(" -> ",0,TRUE) != -1)
171 myFile = myFile.left( myFile.find(" -> ",0,TRUE)); 171 myFile = myFile.left( myFile.find(" -> ",0,TRUE));
172 172
173 QString f = CurrentDir()->canonicalPath(); 173 QString f = CurrentDir()->canonicalPath();
174 if(f.right(1).find("/",0,TRUE) == -1) 174 if(f.right(1).find("/",0,TRUE) == -1)
175 f += "/"; 175 f += "/";
176 f += myFile; 176 f += myFile;
177 if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) { 177 if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) {
178 //if file is a directory 178 //if file is a directory
179 179
180 switch ( QMessageBox::warning( this, tr("Delete Directory?"), 180 switch ( QMessageBox::warning( this, tr("Delete Directory?"),
181 tr("<p>Really delete %1 and all it's contents?</p>" ).arg( f ) , 181 tr("<p>Really delete %1 and all it's contents?</p>" ).arg( f ) ,
182 tr("Yes"), tr("No"), 0, 0, 1) ) { 182 tr("Yes"), tr("No"), 0, 0, 1) ) {
183 case 0: 183 case 0:
184 { 184 {
185 f=f.left(f.length()-1); 185 f=f.left(f.length()-1);
186 QString cmd="rm -rf "+f; 186 QString cmd="rm -rf "+f;
187 startProcess( (const QString)cmd.latin1() ); 187 startProcess( (const QString)cmd.latin1() );
188 populateView(); 188 populateView();
189 } 189 }
190 break; 190 break;
191 case 1: 191 case 1:
192 // exit 192 // exit
193 break; 193 break;
194 default: 194 default:
195 break; 195 break;
196 }; 196 };
197 197
198 } else { 198 } else {
199 if(doMsg) { 199 if(doMsg) {
200 switch ( QMessageBox::warning(this,tr("Delete"), 200 switch ( QMessageBox::warning(this,tr("Delete"),
201 tr("<p>Really delete %1?</p>").arg( myFile ), 201 tr("<p>Really delete %1?</p>").arg( myFile ),
202 tr("Yes"), tr("No"), 0, 0, 1) ) { 202 tr("Yes"), tr("No"), 0, 0, 1) ) {
203 case 0: 203 case 0:
204 break; 204 break;
205 case 1: 205 case 1:
206 return; 206 return;
207 break; 207 break;
208 default: 208 default:
209 return; 209 return;
210 break; 210 break;
211 }; 211 };
212 } 212 }
213 213
214 QString cmd="rm "+f; 214 QString cmd="rm "+f;
215 QFile file(f); 215 QFile file(f);
216 QFileInfo fi(myFile); 216 QFileInfo fi(myFile);
217 if( fi.fileName().find("../",0,TRUE)==-1) { 217 if( fi.fileName().find("../",0,TRUE)==-1) {
218// odebug << "remove link files "+myFile << oendl; 218// odebug << "remove link files "+myFile << oendl;
219 219
220// DocLnk lnk(f); 220// DocLnk lnk(f);
221 DocLnk *lnk; 221 DocLnk *lnk;
222 lnk = new DocLnk(f); 222 lnk = new DocLnk(f);
223// odebug << "Deleting doclnk " + lnk->linkFile() << oendl; 223// odebug << "Deleting doclnk " + lnk->linkFile() << oendl;
224 if(lnk->isValid()) 224 if(lnk->isValid())
225 lnk->removeLinkFile(); 225 lnk->removeLinkFile();
226 // delete lnk; 226 // delete lnk;
227 file.remove(); 227 file.remove();
228 } 228 }
229 } 229 }
230 } 230 }
231 } 231 }
232 populateView(); 232 populateView();
233} 233}
234 234
235void AdvancedFm::filePerms() { 235void AdvancedFm::filePerms() {
236 QStringList curFileList = getPath(); 236 QStringList curFileList = getPath();
237 QString filePath; 237 QString filePath;
238 238
239 filePath = CurrentDir()->canonicalPath()+"/"; 239 filePath = CurrentDir()->canonicalPath()+"/";
240 240
241 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 241 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
242 filePermissions *filePerm; 242 filePermissions *filePerm;
243 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(filePath+*it)); 243 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(filePath+*it));
244 QPEApplication::execDialog( filePerm ); 244 QPEApplication::execDialog( filePerm );
245 if( filePerm ) 245 if( filePerm )
246 delete filePerm; 246 delete filePerm;
247 } 247 }
248 populateView(); 248 populateView();
249} 249}
250 250
251void AdvancedFm::doProperties() { 251void AdvancedFm::doProperties() {
252#if defined(QT_QWS_OPIE) 252#if defined(QT_QWS_OPIE)
253 253
254 QStringList curFileList = getPath(); 254 QStringList curFileList = getPath();
255 255
256 QString filePath; 256 QString filePath;
257 filePath = CurrentDir()->canonicalPath()+"/"; 257 filePath = CurrentDir()->canonicalPath()+"/";
258 258
259// odebug << "" << curFileList.count() << "" << oendl; 259// odebug << "" << curFileList.count() << "" << oendl;
260 260
261 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 261 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
262// odebug << (filePath+*it) << oendl; 262// odebug << (filePath+*it) << oendl;
263 DocLnk lnk( (filePath+*it)); 263 DocLnk lnk( (filePath+*it));
264 LnkProperties prop( &lnk ); 264 LnkProperties prop( &lnk );
265 QPEApplication::execDialog( &prop ); 265 QPEApplication::execDialog( &prop );
266 } 266 }
267#endif 267#endif
268 268
269} 269}
270 270
271void AdvancedFm::upDir() { 271void AdvancedFm::upDir() {
272 272
273 QDir dir( CurrentDir()->canonicalPath()); 273 QDir dir( CurrentDir()->canonicalPath());
274 dir.cdUp(); 274 dir.cdUp();
275 changeTo(dir.canonicalPath()); 275 changeTo(dir.canonicalPath());
276} 276}
277 277
278void AdvancedFm::copyTimer() { 278void AdvancedFm::copyTimer() {
279 QTimer::singleShot(125,this,SLOT(copy())); 279 QTimer::singleShot(125,this,SLOT(copy()));
280} 280}
281 281
282void AdvancedFm::copy() { 282void AdvancedFm::copy() {
283 QStringList curFileList = getPath(); 283 QStringList curFileList = getPath();
284 284
285 QDir *thisDir = CurrentDir(); 285 QDir *thisDir = CurrentDir();
286 QDir *thatDir = OtherDir(); 286 QDir *thatDir = OtherDir();
287 287
288 bool doMsg = true; 288 bool doMsg = true;
289 int count = curFileList.count(); 289 int count = curFileList.count();
290 if( count > 0) { 290 if( count > 0) {
291 if(count > 1 ){ 291 if(count > 1 ){
292 QString msg; 292 QString msg;
293 msg=tr("<p>Really copy %1 files?</p>").arg(count); 293 msg=tr("<p>Really copy %1 files?</p>").arg(count);
294 switch ( QMessageBox::warning(this,tr("Copy"),msg 294 switch ( QMessageBox::warning(this,tr("Copy"),msg
295 ,tr("Yes"),tr("No"),0,0,1) ) 295 ,tr("Yes"),tr("No"),0,0,1) )
296 { 296 {
297 case 0: 297 case 0:
298 doMsg=false; 298 doMsg=false;
299 break; 299 break;
300 case 1: 300 case 1:
301 return; 301 return;
302 break; 302 break;
303 default: 303 default:
304 return; 304 return;
305 break; 305 break;
306 }; 306 };
307 } 307 }
308 308
309 QString curFile, item, destFile; 309 QString curFile, item, destFile;
310 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 310 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
311 item=(*it); 311 item=(*it);
312 if(item.find("->",0,TRUE)) //symlink 312 if(item.find("->",0,TRUE)) //symlink
313 item = item.left(item.find("->",0,TRUE)); 313 item = item.left(item.find("->",0,TRUE));
314 314
315 curFile = thisDir->canonicalPath()+"/"+ item; 315 curFile = thisDir->canonicalPath()+"/"+ item;
316 destFile = thatDir->canonicalPath()+"/"+ item; 316 destFile = thatDir->canonicalPath()+"/"+ item;
317 317
318// odebug << "Destination file is "+destFile << oendl; 318// odebug << "Destination file is "+destFile << oendl;
319// odebug << "CurrentFile file is " + curFile << oendl; 319// odebug << "CurrentFile file is " + curFile << oendl;
320 320
321 QFile f(destFile); 321 QFile f(destFile);
322 if( f.exists()) { 322 if( f.exists()) {
323 if(doMsg) { 323 if(doMsg) {
324 switch ( QMessageBox::warning(this,tr("File Exists!"), 324 switch ( QMessageBox::warning(this,tr("File Exists!"),
325 tr("<p>%1 already exists. Ok to overwrite?</P>").arg(item), 325 tr("<p>%1 already exists. Ok to overwrite?</P>").arg(item),
326 tr("Yes"),tr("No"),0,0,1)) { 326 tr("Yes"),tr("No"),0,0,1)) {
327 case 0: 327 case 0:
328 break; 328 break;
329 case 1: 329 case 1:
330 return; 330 return;
331 break; 331 break;
332 default: 332 default:
333 return; 333 return;
334 break; 334 break;
335 }; 335 };
336 } 336 }
337 f.remove(); 337 f.remove();
338 } 338 }
339 339
340 if( !copyFile( curFile, destFile) ) { 340 if( !copyFile( curFile, destFile) ) {
341 QMessageBox::message("AdvancedFm", 341 QMessageBox::message("AdvancedFm",
342 tr( "<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile)); 342 tr( "<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile));
343 return; 343 return;
344 } 344 }
345 } 345 }
346 rePopulate(); 346 rePopulate();
347 } 347 }
348} 348}
349 349
350void AdvancedFm::copyAsTimer() { 350void AdvancedFm::copyAsTimer() {
351 QTimer::singleShot(125,this,SLOT(copyAs())); 351 QTimer::singleShot(125,this,SLOT(copyAs()));
352} 352}
353 353
354void AdvancedFm::copyAs() { 354void AdvancedFm::copyAs() {
355 355
356 QStringList curFileList = getPath(); 356 QStringList curFileList = getPath();
357 QString curFile, item; 357 QString curFile, item;
358 InputDialog *fileDlg; 358 InputDialog *fileDlg;
359 359
360 QDir *thisDir = CurrentDir(); 360 QDir *thisDir = CurrentDir();
361 QDir *thatDir = OtherDir(); 361 QDir *thatDir = OtherDir();
362 362
363 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 363 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
364 QString destFile; 364 QString destFile;
365 item=(*it); 365 item=(*it);
366 curFile = thisDir->canonicalPath()+"/"+(*it); 366 curFile = thisDir->canonicalPath()+"/"+(*it);
367 fileDlg = new InputDialog( this, tr("Copy %1 As").arg(curFile), TRUE, 0); 367 fileDlg = new InputDialog( this, tr("Copy %1 As").arg(curFile), TRUE, 0);
368 368
369 fileDlg->setInputText((const QString &) destFile ); 369 fileDlg->setInputText((const QString &) destFile );
370 fileDlg->exec(); 370 fileDlg->exec();
371 371
372 if( fileDlg->result() == 1 ) { 372 if( fileDlg->result() == 1 ) {
373 QString filename = fileDlg->LineEdit1->text(); 373 QString filename = fileDlg->LineEdit1->text();
374 destFile = thatDir->canonicalPath()+"/"+filename; 374 destFile = thatDir->canonicalPath()+"/"+filename;
375 375
376 QFile f( destFile); 376 QFile f( destFile);
377 if( f.exists()) { 377 if( f.exists()) {
378 switch (QMessageBox::warning(this,tr("File Exists!"), 378 switch (QMessageBox::warning(this,tr("File Exists!"),
379 tr("<P> %1 already exists. Ok to overwrite?</p>").arg(item), 379 tr("<P> %1 already exists. Ok to overwrite?</p>").arg(item),
380 tr("Yes"),tr("No"),0,0,1) ) { 380 tr("Yes"),tr("No"),0,0,1) ) {
381 case 0: 381 case 0:
382 f.remove(); 382 f.remove();
383 break; 383 break;
384 case 1: 384 case 1:
385 return; 385 return;
386 break; 386 break;
387 default: 387 default:
388 return; 388 return;
389 break; 389 break;
390 }; 390 };
391 } 391 }
392 if( !copyFile( curFile, destFile) ) { 392 if( !copyFile( curFile, destFile) ) {
393 QMessageBox::message("AdvancedFm",tr("<p>Could not copy %1 to %2</P>").arg(curFile).arg(destFile)); 393 QMessageBox::message("AdvancedFm",tr("<p>Could not copy %1 to %2</P>").arg(curFile).arg(destFile));
394 return; 394 return;
395 } 395 }
396 } 396 }
397 delete fileDlg; 397 delete fileDlg;
398 398
399 } 399 }
400 rePopulate(); 400 rePopulate();
401 // setOtherTabCurrent(); 401 // setOtherTabCurrent();
402 qApp->processEvents(); 402 qApp->processEvents();
403 403
404} 404}
405 405
406void AdvancedFm::copySameDirTimer() { 406void AdvancedFm::copySameDirTimer() {
407 QTimer::singleShot(125,this,SLOT(copySameDir())); 407 QTimer::singleShot(125,this,SLOT(copySameDir()));
408} 408}
409 409
410void AdvancedFm::copySameDir() { 410void AdvancedFm::copySameDir() {
411 qApp->processEvents(); 411 qApp->processEvents();
412 QStringList curFileList = getPath(); 412 QStringList curFileList = getPath();
413 QString curFile, item, destFile; 413 QString curFile, item, destFile;
414 InputDialog *fileDlg; 414 InputDialog *fileDlg;
415 415
416 QDir *thisDir = CurrentDir(); 416 QDir *thisDir = CurrentDir();
417 417
418 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 418 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
419 item=(*it); 419 item=(*it);
420 curFile = thisDir->canonicalPath()+"/"+ item; 420 curFile = thisDir->canonicalPath()+"/"+ item;
421 421
422 fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); 422 fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0);
423 fileDlg->setInputText((const QString &) destFile ); 423 fileDlg->setInputText((const QString &) destFile );
424 fileDlg->exec(); 424 fileDlg->exec();
425 425
426 if( fileDlg->result() == 1 ) { 426 if( fileDlg->result() == 1 ) {
427 427
428 QString filename = fileDlg->LineEdit1->text(); 428 QString filename = fileDlg->LineEdit1->text();
429 destFile = thisDir->canonicalPath()+"/"+filename; 429 destFile = thisDir->canonicalPath()+"/"+filename;
430 430
431 QFile f(destFile); 431 QFile f(destFile);
432 if( f.exists()) { 432 if( f.exists()) {
433 switch (QMessageBox::warning(this,tr("Delete"), 433 switch (QMessageBox::warning(this,tr("Delete"),
434 tr("<p> %1 already exists. Do you really want to delete it?</P>").arg(destFile), 434 tr("<p> %1 already exists. Do you really want to delete it?</P>").arg(destFile),
435 tr("Yes"),tr("No"),0,0,1) ) { 435 tr("Yes"),tr("No"),0,0,1) ) {
436 case 0: 436 case 0:
437 f.remove(); 437 f.remove();
438 break; 438 break;
439 case 1: 439 case 1:
440 return; 440 return;
441 break; 441 break;
442 default: 442 default:
443 return; 443 return;
444 break; 444 break;
445 }; 445 };
446 } 446 }
447 if(!copyFile( curFile,destFile) ) { 447 if(!copyFile( curFile,destFile) ) {
448 QMessageBox::message("AdvancedFm",tr("<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile)); 448 QMessageBox::message("AdvancedFm",tr("<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile));
449 return; 449 return;
450 } 450 }
451 451
452// odebug << "copy "+curFile+" as "+destFile << oendl; 452// odebug << "copy "+curFile+" as "+destFile << oendl;
453 } 453 }
454 delete fileDlg; 454 delete fileDlg;
455 } 455 }
456 rePopulate(); 456 rePopulate();
457} 457}
458 458
459void AdvancedFm::moveTimer() { 459void AdvancedFm::moveTimer() {
460 QTimer::singleShot(125,this,SLOT(move())); 460 QTimer::singleShot(125,this,SLOT(move()));
461} 461}
462 462
463void AdvancedFm::move() { 463void AdvancedFm::move() {
464 464
465 QStringList curFileList = getPath(); 465 QStringList curFileList = getPath();
466 if( curFileList.count() > 0) { 466 if( curFileList.count() > 0) {
467 QString curFile, destFile, item; 467 QString curFile, destFile, item;
468 468
469 QDir *thisDir = CurrentDir(); 469 QDir *thisDir = CurrentDir();
470 QDir *thatDir = OtherDir(); 470 QDir *thatDir = OtherDir();
471 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 471 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
472 item=(*it); 472 item=(*it);
473 QString destFile = thatDir->canonicalPath(); 473 QString destFile = thatDir->canonicalPath();
474 474
475 if(destFile.right(1).find("/",0,TRUE) == -1) 475 if(destFile.right(1).find("/",0,TRUE) == -1)
476 destFile+="/"; 476 destFile+="/";
477 destFile += item; 477 destFile += item;
478// odebug << "Destination file is "+destFile << oendl; 478// odebug << "Destination file is "+destFile << oendl;
479 479
480 curFile = thisDir->canonicalPath(); 480 curFile = thisDir->canonicalPath();
481 if(curFile.right(1).find("/",0,TRUE) == -1) 481 if(curFile.right(1).find("/",0,TRUE) == -1)
482 curFile +="/"; 482 curFile +="/";
483 curFile+= item; 483 curFile+= item;
484// odebug << "CurrentFile file is " + curFile << oendl; 484// odebug << "CurrentFile file is " + curFile << oendl;
485 485
486 if(QFileInfo(curFile).isDir()) { 486 if(QFileInfo(curFile).isDir()) {
487 moveDirectory( curFile, destFile ); 487 moveDirectory( curFile, destFile );
488 rePopulate(); 488 rePopulate();
489 return; 489 return;
490 } 490 }
491 QFile f( destFile); 491 QFile f( destFile);
492 if( f.exists()) { 492 if( f.exists()) {
493 switch ( QMessageBox::warning(this,tr("File Exists!"), 493 switch ( QMessageBox::warning(this,tr("File Exists!"),
494 tr("<p>%1 already exists. Ok to overwrite?</P>").arg(destFile), 494 tr("<p>%1 already exists. Ok to overwrite?</P>").arg(destFile),
495 tr("Yes"),tr("No"),0,0,1)) { 495 tr("Yes"),tr("No"),0,0,1)) {
496 case 0: 496 case 0:
497 break; 497 break;
498 case 1: 498 case 1:
499 return; 499 return;
500 break; 500 break;
501 default: 501 default:
502 return; 502 return;
503 break; 503 break;
504 }; 504 };
505 } 505 }
506 if( !copyFile( curFile, destFile) ) { 506 if( !copyFile( curFile, destFile) ) {
507 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg(curFile)); 507 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg(curFile));
508 return; 508 return;
509 } else 509 } else
510 QFile::remove(curFile); 510 QFile::remove(curFile);
511 } 511 }
512 } 512 }
513 rePopulate(); 513 rePopulate();
514 //setOtherTabCurrent(); 514 //setOtherTabCurrent();
515} 515}
516 516
517bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { 517bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) {
518 int err = 0; 518 int err = 0;
519 if( copyDirectory( src, dest ) ) { 519 if( copyDirectory( src, dest ) ) {
520 QString cmd = "rm -rf " + src; 520 QString cmd = "rm -rf " + src;
521 err = system((const char*)cmd); 521 err = system((const char*)cmd);
522 } else 522 } else
523 err = -1; 523 err = -1;
524 524
525 if(err!=0) { 525 if(err!=0) {
526 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg( src)); 526 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg( src));
527 return false; 527 return false;
528 } 528 }
529 return true; 529 return true;
530} 530}
531 531
532bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { 532bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) {
533 533
534 QString cmd = "/bin/cp -fpR " + src + " " + dest; 534 QString cmd = "/bin/cp -fpR " + src + " " + dest;
535 owarn << cmd << oendl; 535 owarn << cmd << oendl;
536 int err = system( (const char *) cmd ); 536 int err = system( (const char *) cmd );
537 if ( err != 0 ) { 537 if ( err != 0 ) {
538 QMessageBox::message("AdvancedFm", tr( "<p>Could not copy %1 to %2</p>").arg( src ).arg( dest ) ); 538 QMessageBox::message("AdvancedFm", tr( "<p>Could not copy %1 to %2</p>").arg( src ).arg( dest ) );
539 return false; 539 return false;
540 } 540 }
541 541
542 return true; 542 return true;
543} 543}
544 544
545 545
546bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { 546bool AdvancedFm::copyFile( const QString & src, const QString & dest ) {
547 if(QFileInfo(src).isDir()) { 547 if(QFileInfo(src).isDir()) {
548 if( copyDirectory( src, dest )) { 548 if( copyDirectory( src, dest )) {
549 // setOtherTabCurrent(); 549 // setOtherTabCurrent();
550 rePopulate(); 550 rePopulate();
551 return true; 551 return true;
552 } 552 }
553 else 553 else
554 return false; 554 return false;
555 } 555 }
556 556
557 557
558 bool success = true; 558 bool success = true;
559 struct stat status; 559 struct stat status;
560 QFile srcFile(src); 560 QFile srcFile(src);
561 QFile destFile(dest); 561 QFile destFile(dest);
562 int err=0; 562 int err=0;
563 int read_fd=0; 563 int read_fd=0;
564 int write_fd=0; 564 int write_fd=0;
565 struct stat stat_buf; 565 struct stat stat_buf;
566 off_t offset = 0; 566 off_t offset = 0;
567 if(!srcFile.open( IO_ReadOnly|IO_Raw)) { 567 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
568// owarn << "open failed" << oendl; 568// owarn << "open failed" << oendl;
569 return success = false; 569 return success = false;
570 } 570 }
571 read_fd = srcFile.handle(); 571 read_fd = srcFile.handle();
572 if(read_fd != -1) { 572 if(read_fd != -1) {
573 fstat (read_fd, &stat_buf); 573 fstat (read_fd, &stat_buf);
574 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { 574 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) {
575// owarn << "destfile open failed" << oendl; 575// owarn << "destfile open failed" << oendl;
576 return success = false; 576 return success = false;
577 } 577 }
578 write_fd = destFile.handle(); 578 write_fd = destFile.handle();
579 if(write_fd != -1) { 579 if(write_fd != -1) {
580 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); 580 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
581 if( err == -1) { 581 if( err == -1) {
582 QString msg; 582 QString msg;
583 switch(err) { 583 switch(err) {
584 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; 584 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
585 case EINVAL: msg = "Descriptor is not valid or locked. "; 585 case EINVAL: msg = "Descriptor is not valid or locked. ";
586 case ENOMEM: msg = "Insufficient memory to read from in_fd."; 586 case ENOMEM: msg = "Insufficient memory to read from in_fd.";
587 case EIO: msg = "Unspecified error while reading from in_fd."; 587 case EIO: msg = "Unspecified error while reading from in_fd.";
588 }; 588 };
589 success = false; 589 success = false;
590// owarn << msg << oendl; 590// owarn << msg << oendl;
591 } 591 }
592 } else { 592 } else {
593 success = false; 593 success = false;
594 } 594 }
595 } else { 595 } else {
596 success = false; 596 success = false;
597 } 597 }
598 srcFile.close(); 598 srcFile.close();
599 destFile.close(); 599 destFile.close();
600 // Set file permissions 600 // Set file permissions
601 if( stat( QFile::encodeName(src), &status ) == 0 ) { 601 if( stat( QFile::encodeName(src), &status ) == 0 ) {
602 chmod( QFile::encodeName(dest), status.st_mode ); 602 chmod( QFile::encodeName(dest), status.st_mode );
603 } 603 }
604 604
605 return success; 605 return success;
606} 606}
607 607
608void AdvancedFm::runCommand() { 608void AdvancedFm::runCommand() {
609 if( !CurrentView()->currentItem()) return; 609 if( !CurrentView()->currentItem()) return;
610 QDir *thisDir = CurrentDir(); 610 QDir *thisDir = CurrentDir();
611 611
612 QString curFile; 612 QString curFile;
613 curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); 613 curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0);
614 614
615 InputDialog *fileDlg; 615 InputDialog *fileDlg;
616 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); 616 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0);
617 fileDlg->setInputText(curFile); 617 fileDlg->setInputText(curFile);
618 fileDlg->exec(); 618 fileDlg->exec();
619 //QString command; 619 //QString command;
620 620
621 if( fileDlg->result() == 1 ) { 621 if( fileDlg->result() == 1 ) {
622// odebug << fileDlg->LineEdit1->text() << oendl; 622// odebug << fileDlg->LineEdit1->text() << oendl;
623 QStringList command; 623 QStringList command;
624 624
625 command << "/bin/sh"; 625 command << "/bin/sh";
626 command << "-c"; 626 command << "-c";
627 command << fileDlg->LineEdit1->text(); 627 command << fileDlg->LineEdit1->text();
628 Output *outDlg; 628 Output *outDlg;
629 outDlg = new Output( command, this, tr("AdvancedFm Output"), true); 629 outDlg = new Output( command, this, tr("AdvancedFm Output"), true);
630 QPEApplication::execDialog( outDlg ); 630 QPEApplication::execDialog( outDlg );
631 qApp->processEvents(); 631 qApp->processEvents();
632 632
633 } 633 }
634} 634}
635 635
636void AdvancedFm::runCommandStd() { 636void AdvancedFm::runCommandStd() {
637 if( !CurrentView()->currentItem()) return; 637 if( !CurrentView()->currentItem()) return;
638 QString curFile; 638 QString curFile;
639 QDir *thisDir = CurrentDir(); 639 QDir *thisDir = CurrentDir();
640 QListView *thisView = CurrentView(); 640 QListView *thisView = CurrentView();
641 if( thisView->currentItem()) 641 if( thisView->currentItem())
642 curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); 642 curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0);
643 643
644 InputDialog *fileDlg; 644 InputDialog *fileDlg;
645 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); 645 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0);
646 fileDlg->setInputText(curFile); 646 fileDlg->setInputText(curFile);
647 fileDlg->exec(); 647 fileDlg->exec();
648 648
649 if( fileDlg->result() == 1 ) { 649 if( fileDlg->result() == 1 ) {
650 qApp->processEvents(); 650 qApp->processEvents();
651 startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); 651 startProcess( (const QString)fileDlg->LineEdit1->text().latin1());
652 } 652 }
653} 653}
654 654
655void AdvancedFm::fileStatus() { 655void AdvancedFm::fileStatus() {
656 if( !CurrentView()->currentItem()) return; 656 if( !CurrentView()->currentItem()) return;
657 QString curFile; 657 QString curFile;
658 curFile = CurrentView()->currentItem()->text(0); 658 curFile = CurrentView()->currentItem()->text(0);
659 659
660 QStringList command; 660 QStringList command;
661 command << "/bin/sh"; 661 command << "/bin/sh";
662 command << "-c"; 662 command << "-c";
663 command << "stat -l "+ curFile; 663 command << "stat -l "+ curFile;
664 664
665 Output *outDlg; 665 Output *outDlg;
666 outDlg = new Output( command, this, tr("AdvancedFm Output"), true); 666 outDlg = new Output( command, this, tr("AdvancedFm Output"), true);
667 QPEApplication::execDialog( outDlg ); 667 QPEApplication::execDialog( outDlg );
668 qApp->processEvents(); 668 qApp->processEvents();
669} 669}
670 670
671 671
672void AdvancedFm::mkDir() { 672void AdvancedFm::mkDir() {
673 makeDir(); 673 makeDir();
674} 674}
675 675
676void AdvancedFm::rn() { 676void AdvancedFm::rn() {
677 renameIt(); 677 renameIt();
678} 678}
679 679
680void AdvancedFm::del() { 680void AdvancedFm::del() {
681 doDelete(); 681 doDelete();
682} 682}
683 683
684void AdvancedFm::mkSym() { 684void AdvancedFm::mkSym() {
685 QString cmd; 685 QString cmd;
686 QStringList curFileList = getPath(); 686 QStringList curFileList = getPath();
687 if( curFileList.count() > 0) { 687 if( curFileList.count() > 0) {
688 QDir *thisDir = CurrentDir(); 688 QDir *thisDir = CurrentDir();
689 QDir * thatDir = OtherDir(); 689 QDir * thatDir = OtherDir();
690 690
691 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 691 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
692 692
693 QString destName = thatDir->canonicalPath()+"/"+(*it); 693 QString destName = thatDir->canonicalPath()+"/"+(*it);
694 if(destName.right(1) == "/") { 694 if(destName.right(1) == "/") {
695 destName = destName.left( destName.length() -1); 695 destName = destName.left( destName.length() -1);
696 } 696 }
697 697
698 QString curFile = thisDir->canonicalPath()+"/"+(*it); 698 QString curFile = thisDir->canonicalPath()+"/"+(*it);
699 699
700 if( curFile.right(1) == "/") { 700 if( curFile.right(1) == "/") {
701 curFile = curFile.left( curFile.length() -1); 701 curFile = curFile.left( curFile.length() -1);
702 } 702 }
703 703
704 cmd = "ln -s "+curFile+" "+destName; 704 cmd = "ln -s "+curFile+" "+destName;
705// odebug << cmd << oendl; 705// odebug << cmd << oendl;
706 startProcess( (const QString)cmd ); 706 startProcess( (const QString)cmd );
707 } 707 }
708 rePopulate(); 708 rePopulate();
709 setOtherTabCurrent(); 709 setOtherTabCurrent();
710 } 710 }
711} 711}
712 712
713void AdvancedFm::doBeam() { 713void AdvancedFm::doBeam() {
714 Ir ir; 714 Ir ir;
715 if(!ir.supported()) { 715 if(!ir.supported()) {
716 } else { 716 } else {
717 QStringList curFileList = getPath(); 717 QStringList curFileList = getPath();
718 if( curFileList.count() > 0) { 718 if( curFileList.count() > 0) {
719 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 719 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
720 QString curFile = (*it); 720 QString curFile = (*it);
721 QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; 721 QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile;
722 if( curFilePath.right(1) == "/") { 722 if( curFilePath.right(1) == "/") {
723 curFilePath = curFilePath.left( curFilePath.length() -1); 723 curFilePath = curFilePath.left( curFilePath.length() -1);
724 } 724 }
725 Ir *file = new Ir(this, "IR"); 725 Ir *file = new Ir(this, "IR");
726 connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished(Ir*))); 726 connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished(Ir*)));
727 file->send( curFilePath, curFile ); 727 file->send( curFilePath, curFile );
728 } 728 }
729 } 729 }
730 } 730 }
731} 731}
732 732
733void AdvancedFm::fileBeamFinished( Ir *) { 733void AdvancedFm::fileBeamFinished( Ir *) {
734 QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); 734 QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") );
735} 735}
736 736
737void AdvancedFm::selectAll() { 737void AdvancedFm::selectAll() {
738 QListView *thisView = CurrentView(); 738 QListView *thisView = CurrentView();
739 thisView->selectAll(true); 739 thisView->selectAll(true);
740 thisView->setSelected( thisView->firstChild(),false); 740 thisView->setSelected( thisView->firstChild(),false);
741} 741}
742 742
743void AdvancedFm::startProcess(const QString & cmd) { 743void AdvancedFm::startProcess(const QString & cmd) {
744 QStringList command; 744 QStringList command;
745 OProcess *process; 745 OProcess *process;
746 process = new OProcess(); 746 process = new OProcess();
747 connect(process,SIGNAL(processExited(Opie::Core::OProcess*)),this,SLOT(processEnded(Opie::Core::OProcess*))); 747 connect(process,SIGNAL(processExited(Opie::Core::OProcess*)),this,SLOT(processEnded(Opie::Core::OProcess*)));
748 connect(process,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(oprocessStderr(Opie::Core::OProcess*,char*,int))); 748 connect(process,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(oprocessStderr(Opie::Core::OProcess*,char*,int)));
749 749
750 command << "/bin/sh"; 750 command << "/bin/sh";
751 command << "-c"; 751 command << "-c";
752 command << cmd.latin1(); 752 command << cmd.latin1();
753 *process << command; 753 *process << command;
754 if(!process->start(OProcess::NotifyOnExit, OProcess::All) ) 754 if(!process->start(OProcess::NotifyOnExit, OProcess::All) )
755 odebug << "could not start process" << oendl; 755 odebug << "could not start process" << oendl;
756} 756}
757 757
758void AdvancedFm::processEnded(OProcess *) { 758void AdvancedFm::processEnded(OProcess *) {
759 rePopulate(); 759 rePopulate();
760} 760}
761 761
762void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) { 762void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) {
763// owarn << "received stderrt " << buflen << " bytes" << oendl; 763// owarn << "received stderrt " << buflen << " bytes" << oendl;
764 764
765 QString lineStr = buffer; 765 QString lineStr = buffer;
766 QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") ); 766 QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") );
767} 767}
768 768
769bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { 769bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) {
770 if ( o->inherits( "QLineEdit" ) ) { 770 if ( o->inherits( "QLineEdit" ) ) {
771 if ( e->type() == QEvent::KeyPress ) { 771 if ( e->type() == QEvent::KeyPress ) {
772 QKeyEvent *ke = (QKeyEvent*)e; 772 QKeyEvent *ke = (QKeyEvent*)e;
773 if ( ke->key() == Key_Return || 773 if ( ke->key() == Key_Return ||
774 ke->key() == Key_Enter ) { 774 ke->key() == Key_Enter ) {
775 okRename(); 775 okRename();
776 return true; 776 return true;
777 } 777 }
778 else if ( ke->key() == Key_Escape ) { 778 else if ( ke->key() == Key_Escape ) {
779 cancelRename(); 779 cancelRename();
780 return true; 780 return true;
781 } 781 }
782 } 782 }
783 else if ( e->type() == QEvent::FocusOut ) { 783 else if ( e->type() == QEvent::FocusOut ) {
784 cancelRename(); 784 cancelRename();
785 return true; 785 return true;
786 } 786 }
787 } 787 }
788 if ( o->inherits( "QListView" ) ) { 788 if ( o->inherits( "QListView" ) ) {
789 if ( e->type() == QEvent::FocusIn ) { 789 if ( e->type() == QEvent::FocusIn ) {
790 if( o == Local_View) { //keep track of which view 790 if( o == Local_View) { //keep track of which view
791 whichTab = 1; 791 whichTab = 1;
792 viewMenu->setItemChecked(viewMenu->idAt(0), true); 792 viewMenu->setItemChecked(viewMenu->idAt(0), true);
793 viewMenu->setItemChecked(viewMenu->idAt(1), false); 793 viewMenu->setItemChecked(viewMenu->idAt(1), false);
794 } else { 794 } else {
795 whichTab = 2; 795 whichTab = 2;
796 viewMenu->setItemChecked(viewMenu->idAt(0), false); 796 viewMenu->setItemChecked(viewMenu->idAt(0), false);
797 viewMenu->setItemChecked(viewMenu->idAt(1), true); 797 viewMenu->setItemChecked(viewMenu->idAt(1), true);
798 } 798 }
799 } 799 }
800 OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection 800 OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection
801 } 801 }
802 802
803 return QWidget::eventFilter( o, e ); 803 return QWidget::eventFilter( o, e );
804} 804}
805 805
806 806
807void AdvancedFm::cancelRename() { 807void AdvancedFm::cancelRename() {
808// odebug << "cancel rename" << oendl; 808// odebug << "cancel rename" << oendl;
809 QListView * view; 809 QListView * view;
810 view = CurrentView(); 810 view = CurrentView();
811 811
812 bool resetFocus = view->viewport()->focusProxy() == renameBox; 812 bool resetFocus = view->viewport()->focusProxy() == renameBox;
813 delete renameBox; 813 delete renameBox;
814 renameBox = 0; 814 renameBox = 0;
815 if ( resetFocus ) { 815 if ( resetFocus ) {
816 view->viewport()->setFocusProxy( view); 816 view->viewport()->setFocusProxy( view);
817 view->setFocus(); 817 view->setFocus();
818 } 818 }
819} 819}
820 820
821void AdvancedFm::doRename(QListView * view) { 821void AdvancedFm::doRename(QListView * view) {
822 if( !CurrentView()->currentItem()) return; 822 if( !CurrentView()->currentItem()) return;
823 823
824 QRect r = view->itemRect( view->currentItem( )); 824 QRect r = view->itemRect( view->currentItem( ));
825 r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); 825 r = QRect( view->viewportToContents( r.topLeft() ), r.size() );
826 r.setX( view->contentsX() ); 826 r.setX( view->contentsX() );
827 if ( r.width() > view->visibleWidth() ) 827 if ( r.width() > view->visibleWidth() )
828 r.setWidth( view->visibleWidth() ); 828 r.setWidth( view->visibleWidth() );
829 829
830 renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); 830 renameBox = new QLineEdit( view->viewport(), "qt_renamebox" );
831 renameBox->setFrame(true); 831 renameBox->setFrame(true);
832 renameBox->setText( view->currentItem()->text(0) ); 832 renameBox->setText( view->currentItem()->text(0) );
833 renameBox->selectAll(); 833 renameBox->selectAll();
834 renameBox->installEventFilter( this ); 834 renameBox->installEventFilter( this );
835 view->addChild( renameBox, r.x(), r.y() ); 835 view->addChild( renameBox, r.x(), r.y() );
836 renameBox->resize( r.size() ); 836 renameBox->resize( r.size() );
837 view->viewport()->setFocusProxy( renameBox ); 837 view->viewport()->setFocusProxy( renameBox );
838 renameBox->setFocus(); 838 renameBox->setFocus();
839 renameBox->show(); 839 renameBox->show();
840} 840}
841 841
842 842
843void AdvancedFm::renameIt() { 843void AdvancedFm::renameIt() {
844 if( !CurrentView()->currentItem()) return; 844 if( !CurrentView()->currentItem()) return;
845 845
846 QListView *thisView = CurrentView(); 846 QListView *thisView = CurrentView();
847 oldName = thisView->currentItem()->text(0); 847 oldName = thisView->currentItem()->text(0);
848 doRename( thisView ); 848 doRename( thisView );
849} 849}
850 850
851void AdvancedFm::okRename() { 851void AdvancedFm::okRename() {
852 qDebug("okrename"); 852 qDebug("okrename");
853 if( !renameBox) return; 853 if( !renameBox) return;
854 854
855 QString newName = renameBox->text(); 855 QString newName = renameBox->text();
856 cancelRename(); 856 cancelRename();
857 QListView * view = CurrentView(); 857 QListView * view = CurrentView();
858 QString path = CurrentDir()->canonicalPath() + "/"; 858 QString path = CurrentDir()->canonicalPath() + "/";
859 oldName = path + oldName; 859 oldName = path + oldName;
860 newName = path + newName; 860 newName = path + newName;
861 if( rename( oldName.latin1(), newName.latin1())== -1) 861 if( rename( oldName.latin1(), newName.latin1())== -1)
862 QMessageBox::message(tr("Note"),tr("Could not rename")); 862 QMessageBox::message(tr("Note"),tr("Could not rename"));
863 else 863 else
864 oldName = ""; 864 oldName = "";
865 QListViewItem *item = view->currentItem(); 865 QListViewItem *item = view->currentItem();
866 view->takeItem( item ); 866 view->takeItem( item );
867 delete item; 867 delete item;
868 rePopulate(); 868 populateView();
869
869} 870}
870 871
871void AdvancedFm::openSearch() { 872void AdvancedFm::openSearch() {
872 QMessageBox::message(tr("Note"),tr("Not Yet Implemented")); 873 QMessageBox::message(tr("Note"),tr("Not Yet Implemented"));
873} 874}