author | llornkcor <llornkcor> | 2002-04-18 03:02:37 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-04-18 03:02:37 (UTC) |
commit | 65748a36a621a19078789cc277a89c8a1f341351 (patch) (unidiff) | |
tree | b512d4b7ce7521c1d5d475ad3b3f5827f5bdffe7 /noncore/apps/advancedfm/advancedfm.cpp | |
parent | 276f934cd66542d8cc403bb74e9cb661264ddd2f (diff) | |
download | opie-65748a36a621a19078789cc277a89c8a1f341351.zip opie-65748a36a621a19078789cc277a89c8a1f341351.tar.gz opie-65748a36a621a19078789cc277a89c8a1f341351.tar.bz2 |
initial offering
Diffstat (limited to 'noncore/apps/advancedfm/advancedfm.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 1263 |
1 files changed, 1263 insertions, 0 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp new file mode 100644 index 0000000..a4ec714 --- a/dev/null +++ b/noncore/apps/advancedfm/advancedfm.cpp | |||
@@ -0,0 +1,1263 @@ | |||
1 | /*************************************************************************** | ||
2 | AdvancedFm.cpp | ||
3 | ------------------- | ||
4 | ** Created: Sat Mar 9 23:33:09 2002 | ||
5 | copyright : (C) 2002 by ljp | ||
6 | email : ljp@llornkcor.com | ||
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 * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | ||
11 | ***************************************************************************/ | ||
12 | #define DEVELOPERS_VERSION | ||
13 | #define QTOPIA_INTERNAL_FSLP // to get access to fileproperties | ||
14 | |||
15 | #include "advancedfm.h" | ||
16 | #include "inputDialog.h" | ||
17 | #include "filePermissions.h" | ||
18 | #include "output.h" | ||
19 | |||
20 | #include <qpe/lnkproperties.h> | ||
21 | #include <qpe/filemanager.h> | ||
22 | #include <qpe/qcopenvelope_qws.h> | ||
23 | #include <qpe/qpemenubar.h> | ||
24 | #include <qpe/qpetoolbar.h> | ||
25 | #include <qpe/qpeapplication.h> | ||
26 | #include <qpe/resource.h> | ||
27 | #include <qpe/qcopenvelope_qws.h> | ||
28 | #include <qpe/config.h> | ||
29 | #include <qpe/mimetype.h> | ||
30 | #include <qpe/applnk.h> | ||
31 | |||
32 | //#include <opie/ofileselector.h> | ||
33 | #include <qmultilineedit.h> | ||
34 | |||
35 | #include <qtextstream.h> | ||
36 | #include <qpushbutton.h> | ||
37 | #include <qtoolbutton.h> | ||
38 | #include <qdatetime.h> | ||
39 | #include <qdir.h> | ||
40 | #include <qfile.h> | ||
41 | #include <qstring.h> | ||
42 | #include <qcombobox.h> | ||
43 | #include <qpopupmenu.h> | ||
44 | #include <qlistview.h> | ||
45 | #include <qmainwindow.h> | ||
46 | #include <qlabel.h> | ||
47 | #include <qprogressbar.h> | ||
48 | #include <qspinbox.h> | ||
49 | #include <qtabwidget.h> | ||
50 | #include <qwidget.h> | ||
51 | #include <qlayout.h> | ||
52 | #include <qimage.h> | ||
53 | #include <qpixmap.h> | ||
54 | #include <qmessagebox.h> | ||
55 | #include <qlineedit.h> | ||
56 | #include <qregexp.h> | ||
57 | |||
58 | #include <unistd.h> | ||
59 | #include <stdlib.h> | ||
60 | #include <sys/stat.h> | ||
61 | #include <dirent.h> | ||
62 | #include <stdio.h> | ||
63 | #include <time.h> | ||
64 | #include <fcntl.h> | ||
65 | |||
66 | AdvancedFm::AdvancedFm( ) | ||
67 | : QMainWindow( ) | ||
68 | { | ||
69 | setCaption( tr( "AdvancedFm" ) ); | ||
70 | |||
71 | QGridLayout *layout = new QGridLayout( this ); | ||
72 | layout->setSpacing( 2); | ||
73 | layout->setMargin( 2); | ||
74 | |||
75 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | ||
76 | |||
77 | QPEMenuBar *menuBar = new QPEMenuBar(this); | ||
78 | // fileMenu = new QPopupMenu( this ); | ||
79 | fileMenu = new QPopupMenu( this ); | ||
80 | viewMenu = new QPopupMenu( this ); | ||
81 | |||
82 | layout->addMultiCellWidget( menuBar, 0, 0, 0, 1 ); | ||
83 | |||
84 | menuBar->insertItem( tr( "File" ), fileMenu); | ||
85 | menuBar->insertItem( tr( "View" ), viewMenu); | ||
86 | |||
87 | cfButton = new QPushButton(Resource::loadIconSet("cardmon/pcmcia"),"",this,"CFButton"); | ||
88 | cfButton ->setFixedSize( QSize( 20, 20 ) ); | ||
89 | connect( cfButton ,SIGNAL(released()),this,SLOT( CFButtonPushed()) ); | ||
90 | cfButton->setFlat(TRUE); | ||
91 | layout->addMultiCellWidget( cfButton , 0, 0, 2, 2); | ||
92 | |||
93 | sdButton = new QPushButton(Resource::loadIconSet("sdmon/sdcard"),"",this,"SDButton"); | ||
94 | sdButton->setFixedSize( QSize( 20, 20 ) ); | ||
95 | connect( sdButton ,SIGNAL(released()),this,SLOT( SDButtonPushed()) ); | ||
96 | sdButton->setFlat(TRUE); | ||
97 | layout->addMultiCellWidget( sdButton , 0, 0, 3, 3); | ||
98 | |||
99 | cdUpButton = new QPushButton(Resource::loadIconSet("up"),"",this,"cdUpButton"); | ||
100 | cdUpButton ->setFixedSize( QSize( 20, 20 ) ); | ||
101 | connect( cdUpButton ,SIGNAL(released()),this,SLOT( upDir()) ); | ||
102 | cdUpButton ->setFlat(TRUE); | ||
103 | layout->addMultiCellWidget( cdUpButton , 0, 0, 4, 4); | ||
104 | |||
105 | docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); | ||
106 | docButton->setFixedSize( QSize( 20, 20 ) ); | ||
107 | connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); | ||
108 | docButton->setFlat(TRUE); | ||
109 | layout->addMultiCellWidget( docButton, 0, 0, 5, 5); | ||
110 | |||
111 | homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); | ||
112 | homeButton->setFixedSize( QSize( 20, 20 ) ); | ||
113 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); | ||
114 | homeButton->setFlat(TRUE); | ||
115 | layout->addMultiCellWidget( homeButton, 0, 0, 6, 6); | ||
116 | // fileMenu->insertItem( tr( "New" ), this, SLOT( newConnection() )); | ||
117 | // fileMenu->insertItem( tr( "Connect" ), this, SLOT( connector() )); | ||
118 | // fileMenu->insertItem( tr( "Disconnect" ), this, SLOT( disConnector() )); | ||
119 | |||
120 | fileMenu->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); | ||
121 | fileMenu->insertSeparator(); | ||
122 | fileMenu->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); | ||
123 | fileMenu->insertItem( tr( "Rename" ), this, SLOT( localRename() )); | ||
124 | fileMenu->insertItem( tr( "Run Command" ), this, SLOT( runCommandStd() )); | ||
125 | fileMenu->insertItem( tr( "Run Command with Output" ), this, SLOT( runCommand() )); | ||
126 | fileMenu->insertSeparator(); | ||
127 | fileMenu->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | ||
128 | fileMenu->setCheckable(TRUE); | ||
129 | |||
130 | viewMenu->insertItem( tr( "Switch to Local" ), this, SLOT( switchToLocalTab() )); | ||
131 | viewMenu->insertItem( tr( "Switch to Remote" ), this, SLOT( switchToRemoteTab() )); | ||
132 | viewMenu->setCheckable(TRUE); | ||
133 | |||
134 | TabWidget = new QTabWidget( this, "TabWidget" ); | ||
135 | layout->addMultiCellWidget( TabWidget, 1, 1, 0, 6); | ||
136 | |||
137 | tab = new QWidget( TabWidget, "tab" ); | ||
138 | tabLayout = new QGridLayout( tab ); | ||
139 | tabLayout->setSpacing( 2); | ||
140 | tabLayout->setMargin( 2); | ||
141 | |||
142 | Local_View = new QListView( tab, "Local_View" ); | ||
143 | // Local_View->setResizePolicy( QListView::AutoOneFit ); | ||
144 | Local_View->addColumn( tr("File"),140); | ||
145 | Local_View->addColumn( tr("Size"),-1); | ||
146 | Local_View->setColumnAlignment(1,QListView::AlignRight); | ||
147 | Local_View->addColumn( tr("Date"),-1); | ||
148 | Local_View->setColumnAlignment(2,QListView::AlignRight); | ||
149 | Local_View->setAllColumnsShowFocus(TRUE); | ||
150 | // Local_View->setMultiSelection( TRUE ); | ||
151 | // Local_View->setSelectionMode(QListView::Extended); | ||
152 | QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold); | ||
153 | |||
154 | tabLayout->addWidget( Local_View, 0, 0 ); | ||
155 | |||
156 | connect( Local_View, SIGNAL( clicked( QListViewItem*)), | ||
157 | this,SLOT( localListClicked(QListViewItem *)) ); | ||
158 | connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
159 | this,SLOT( localListPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
160 | |||
161 | TabWidget->insertTab( tab, tr("1")); | ||
162 | |||
163 | tab_2 = new QWidget( TabWidget, "tab_2" ); | ||
164 | tabLayout_2 = new QGridLayout( tab_2 ); | ||
165 | tabLayout_2->setSpacing( 2); | ||
166 | tabLayout_2->setMargin( 2); | ||
167 | |||
168 | Remote_View = new QListView( tab_2, "Remote_View" ); | ||
169 | Remote_View->addColumn( tr("File"),140); | ||
170 | Remote_View->addColumn( tr("Size"),-1); | ||
171 | Remote_View->setColumnAlignment(1,QListView::AlignRight); | ||
172 | Remote_View->addColumn( tr("Date"),-1); | ||
173 | Remote_View->setColumnAlignment(2,QListView::AlignRight); | ||
174 | Remote_View->setAllColumnsShowFocus(TRUE); | ||
175 | // Remote_View->setMultiSelection( TRUE ); | ||
176 | // Remote_View->setSelectionMode(QListView::Extended); | ||
177 | QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); | ||
178 | |||
179 | connect( Remote_View, SIGNAL( clicked( QListViewItem*)), | ||
180 | this,SLOT( remoteListClicked(QListViewItem *)) ); | ||
181 | connect( Remote_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
182 | this,SLOT( remoteListPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
183 | |||
184 | tabLayout_2->addWidget( Remote_View, 0, 0 ); | ||
185 | |||
186 | TabWidget->insertTab( tab_2, tr( "2")); | ||
187 | |||
188 | connect(TabWidget,SIGNAL(currentChanged(QWidget *)), | ||
189 | this,SLOT(tabChanged(QWidget*))); | ||
190 | |||
191 | // tab_3 = new QWidget( TabWidget, "tab_3" ); | ||
192 | // tabLayout_3 = new QGridLayout( tab_3 ); | ||
193 | // tabLayout_3->setSpacing( 2); | ||
194 | // tabLayout_3->setMargin( 2); | ||
195 | |||
196 | // OFileSelector *fileSelector; | ||
197 | // fileSelector = new OFileSelector(tab_3,0,0,"/","","*"); | ||
198 | // tabLayout_3->addMultiCellWidget( fileSelector, 0, 0, 0, 3 ); | ||
199 | |||
200 | // TabWidget->insertTab( tab_3, tr( "Files" ) ); | ||
201 | |||
202 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | ||
203 | currentDir.setPath( QDir::currentDirPath()); | ||
204 | |||
205 | currentRemoteDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | ||
206 | currentRemoteDir.setPath( QDir::currentDirPath()); | ||
207 | |||
208 | currentPathCombo = new QComboBox( FALSE, this, "currentPathCombo" ); | ||
209 | currentPathCombo->setEditable(TRUE); | ||
210 | layout->addMultiCellWidget( currentPathCombo, 3, 3, 0, 6); | ||
211 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); | ||
212 | |||
213 | connect( currentPathCombo, SIGNAL( activated( const QString & ) ), | ||
214 | this, SLOT( currentPathComboActivated( const QString & ) ) ); | ||
215 | |||
216 | connect( currentPathCombo->lineEdit(),SIGNAL(returnPressed()), | ||
217 | this,SLOT(currentPathComboChanged())); | ||
218 | |||
219 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); | ||
220 | |||
221 | layout->addMultiCellWidget( currentPathCombo, 3, 3, 0, 6); | ||
222 | |||
223 | filterStr="*"; | ||
224 | b=FALSE; | ||
225 | populateLocalView(); | ||
226 | populateRemoteView(); | ||
227 | } | ||
228 | |||
229 | AdvancedFm::~AdvancedFm() | ||
230 | { | ||
231 | } | ||
232 | |||
233 | void AdvancedFm::cleanUp() | ||
234 | { | ||
235 | QString sfile=QDir::homeDirPath(); | ||
236 | if(sfile.right(1) != "/") | ||
237 | sfile+="/._temp"; | ||
238 | else | ||
239 | sfile+="._temp"; | ||
240 | QFile file( sfile); | ||
241 | if(file.exists()) | ||
242 | file.remove(); | ||
243 | } | ||
244 | |||
245 | void AdvancedFm::tabChanged(QWidget *w) | ||
246 | { | ||
247 | if (TabWidget->currentPageIndex() == 0) { | ||
248 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); | ||
249 | viewMenu->setItemChecked(viewMenu->idAt(0),TRUE); | ||
250 | viewMenu->setItemChecked(viewMenu->idAt(1),FALSE); | ||
251 | } | ||
252 | if (TabWidget->currentPageIndex() == 1) { | ||
253 | currentPathCombo->lineEdit()->setText( currentRemoteDir.canonicalPath()); | ||
254 | viewMenu->setItemChecked(viewMenu->idAt(1),TRUE); | ||
255 | viewMenu->setItemChecked(viewMenu->idAt(0),FALSE); | ||
256 | } | ||
257 | } | ||
258 | |||
259 | |||
260 | void AdvancedFm::populateLocalView() | ||
261 | { | ||
262 | // QList<QListViewItem> * getSelectedItems( QListView * Local_View ); | ||
263 | // QListViewItemIterator it( Local_View ); | ||
264 | // for ( ; it.current(); ++it ) { | ||
265 | // if ( it.current()->isSelected() ) { | ||
266 | // QString strItem = it.current()->text(0); | ||
267 | // QString localFile = currentDir.canonicalPath()+"/"+strItem; | ||
268 | // QFileInfo fi(localFile); | ||
269 | // } | ||
270 | // } | ||
271 | QPixmap pm; | ||
272 | Local_View->clear(); | ||
273 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
274 | currentDir.setMatchAllDirs(TRUE); | ||
275 | currentDir.setNameFilter(filterStr); | ||
276 | QString fileL, fileS, fileDate; | ||
277 | // qDebug(currentDir.canonicalPath()); | ||
278 | |||
279 | bool isDir=FALSE; | ||
280 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | ||
281 | QFileInfoListIterator it(*list); | ||
282 | QFileInfo *fi; | ||
283 | while ( (fi=it.current()) ) { | ||
284 | if (fi->isSymLink() ) { | ||
285 | QString symLink=fi->readLink(); | ||
286 | // qDebug("Symlink detected "+symLink); | ||
287 | QFileInfo sym( symLink); | ||
288 | fileS.sprintf( "%10li", sym.size() ); | ||
289 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | ||
290 | fileDate = sym.lastModified().toString(); | ||
291 | } else { | ||
292 | fileS.sprintf( "%10li", fi->size() ); | ||
293 | fileL.sprintf( "%s",fi->fileName().data() ); | ||
294 | fileDate= fi->lastModified().toString(); | ||
295 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | ||
296 | fileL+="/"; | ||
297 | isDir=TRUE; | ||
298 | // qDebug( fileL); | ||
299 | } | ||
300 | } | ||
301 | if(fileL !="./" && fi->exists()) { | ||
302 | item= new QListViewItem( Local_View, fileL, fileS , fileDate); | ||
303 | |||
304 | if(isDir || fileL.find("/",0,TRUE) != -1) { | ||
305 | if( !QDir( fi->filePath() ).isReadable()) | ||
306 | pm = Resource::loadPixmap( "lockedfolder" ); | ||
307 | else | ||
308 | pm= Resource::loadPixmap( "folder" ); | ||
309 | item->setPixmap( 0,pm ); | ||
310 | } else { | ||
311 | if( !fi->isReadable() ) | ||
312 | pm = Resource::loadPixmap( "locked" ); | ||
313 | else { | ||
314 | MimeType mt(fi->filePath()); | ||
315 | pm=mt.pixmap(); //sets the correct pixmap for mimetype | ||
316 | if(pm.isNull()) | ||
317 | pm = Resource::loadPixmap( "UnknownDocument-14" ); | ||
318 | item->setPixmap( 0,pm); | ||
319 | } | ||
320 | } | ||
321 | if( fileL.find("->",0,TRUE) != -1) { | ||
322 | // overlay link image | ||
323 | pm= Resource::loadPixmap( "folder" ); | ||
324 | QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); | ||
325 | QPainter painter( &pm ); | ||
326 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | ||
327 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | ||
328 | item->setPixmap( 0, pm); | ||
329 | } | ||
330 | } isDir=FALSE; | ||
331 | ++it; | ||
332 | } | ||
333 | |||
334 | if(currentDir.canonicalPath().find("dev",0,TRUE) != -1) { | ||
335 | struct stat buf; | ||
336 | struct stat st; | ||
337 | dev_t devT; | ||
338 | mode_t mode; | ||
339 | DIR *dir; | ||
340 | int fd = 0; | ||
341 | struct dirent *mydirent; | ||
342 | int i = 1; | ||
343 | if((dir = opendir( currentDir.canonicalPath().latin1())) != NULL) | ||
344 | while ((mydirent = readdir(dir)) != NULL) { | ||
345 | lstat( mydirent->d_name, &buf); | ||
346 | qDebug(mydirent->d_name); | ||
347 | // mode = buf.st_mode; | ||
348 | fileL.sprintf("%s", mydirent->d_name); | ||
349 | // fileS.sprintf("%d, %d", ); //this isn't correct | ||
350 | devT = buf.st_dev; | ||
351 | fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF); | ||
352 | // fileS.sprintf("%d,%d", devT, devT); | ||
353 | fileDate.sprintf("%s", ctime( &buf.st_mtime)); | ||
354 | if( fileL.find(".") == -1 ){ | ||
355 | item= new QListViewItem( Local_View, fileL, fileS, fileDate); | ||
356 | pm = Resource::loadPixmap( "UnknownDocument-14" ); | ||
357 | item->setPixmap( 0,pm); | ||
358 | } | ||
359 | } | ||
360 | |||
361 | closedir(dir); | ||
362 | } | ||
363 | |||
364 | Local_View->setSorting( 3,FALSE); | ||
365 | fillCombo( (const QString &) currentDir.canonicalPath()); | ||
366 | } | ||
367 | |||
368 | void AdvancedFm::populateRemoteView() | ||
369 | { | ||
370 | // QList<QListViewItem> * getSelectedItems( QListView * Local_View ); | ||
371 | // QListViewItemIterator it( Remote_View ); | ||
372 | // for ( ; it.current(); ++it ) { | ||
373 | // if ( it.current()->isSelected() ) { | ||
374 | // QString strItem = it.current()->text(0); | ||
375 | // QString localFile = currentRemoteDir.canonicalPath()+"/"+strItem; | ||
376 | // QFileInfo fi(localFile); | ||
377 | // } | ||
378 | // } | ||
379 | QPixmap pm; | ||
380 | Remote_View->clear(); | ||
381 | currentRemoteDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
382 | currentRemoteDir.setMatchAllDirs(TRUE); | ||
383 | currentRemoteDir.setNameFilter(filterStr); | ||
384 | QString fileL, fileS, fileDate; | ||
385 | bool isDir=FALSE; | ||
386 | const QFileInfoList *list = currentRemoteDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | ||
387 | QFileInfoListIterator it(*list); | ||
388 | QFileInfo *fi; | ||
389 | while ( (fi=it.current()) ) { | ||
390 | if (fi->isSymLink() ){ | ||
391 | QString symLink=fi->readLink(); | ||
392 | // qDebug("Symlink detected "+symLink); | ||
393 | QFileInfo sym( symLink); | ||
394 | fileS.sprintf( "%10li", sym.size() ); | ||
395 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | ||
396 | fileDate = sym.lastModified().toString(); | ||
397 | } else { | ||
398 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | ||
399 | fileS.sprintf( "%10li", fi->size() ); | ||
400 | fileL.sprintf( "%s",fi->fileName().data() ); | ||
401 | fileDate= fi->lastModified().toString(); | ||
402 | if( QDir(QDir::cleanDirPath( currentRemoteDir.canonicalPath()+"/"+fileL)).exists() ) { | ||
403 | fileL+="/"; | ||
404 | isDir=TRUE; | ||
405 | // qDebug( fileL); | ||
406 | } | ||
407 | } | ||
408 | if(fileL !="./" && fi->exists()) { | ||
409 | item= new QListViewItem( Remote_View,fileL,fileS , fileDate); | ||
410 | QPixmap pm; | ||
411 | |||
412 | if(isDir || fileL.find("/",0,TRUE) != -1) { | ||
413 | if( !QDir( fi->filePath() ).isReadable()) | ||
414 | pm = Resource::loadPixmap( "lockedfolder" ); | ||
415 | else | ||
416 | pm= Resource::loadPixmap( "folder" ); | ||
417 | item->setPixmap( 0,pm ); | ||
418 | } else { | ||
419 | if( !fi->isReadable() ) | ||
420 | pm = Resource::loadPixmap( "locked" ); | ||
421 | else { | ||
422 | MimeType mt(fi->filePath()); | ||
423 | pm=mt.pixmap(); //sets the correct pixmap for mimetype | ||
424 | if(pm.isNull()) | ||
425 | pm = Resource::loadPixmap( "UnknownDocument-14" ); | ||
426 | item->setPixmap( 0,pm); | ||
427 | } | ||
428 | } | ||
429 | if( fileL.find("->",0,TRUE) != -1) { | ||
430 | // overlay link image | ||
431 | pm= Resource::loadPixmap( "folder" ); | ||
432 | QPixmap lnk = Resource::loadPixmap( "symlink" ); | ||
433 | QPainter painter( &pm ); | ||
434 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | ||
435 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | ||
436 | item->setPixmap( 0, pm); | ||
437 | } | ||
438 | } isDir=FALSE; | ||
439 | ++it; | ||
440 | } | ||
441 | |||
442 | if(currentRemoteDir.canonicalPath().find("dev",0,TRUE) != -1) { | ||
443 | struct stat buf; | ||
444 | struct stat st; | ||
445 | mode_t mode; | ||
446 | DIR *dir; | ||
447 | int fd = 0; | ||
448 | struct dirent *mydirent; | ||
449 | int i = 1; | ||
450 | if((dir = opendir( currentRemoteDir.canonicalPath().latin1())) != NULL) | ||
451 | while ((mydirent = readdir(dir)) != NULL) { | ||
452 | lstat( mydirent->d_name, &buf); | ||
453 | qDebug(mydirent->d_name); | ||
454 | // mode = buf.st_mode; | ||
455 | fileL.sprintf("%s", mydirent->d_name); | ||
456 | // fileS.sprintf("%d, %d", ); //this isn't correct | ||
457 | fileS.sprintf("%d,%d", (int) (buf.st_dev>>8)&0xFF, (int) buf.st_dev &0xFF); | ||
458 | fileDate.sprintf("%s", ctime( &buf.st_mtime)); | ||
459 | if( fileL.find(".") == -1 ){ | ||
460 | item= new QListViewItem( Remote_View, fileL, fileS, fileDate); | ||
461 | pm = Resource::loadPixmap( "UnknownDocument-14" ); | ||
462 | item->setPixmap( 0,pm); | ||
463 | } | ||
464 | } | ||
465 | |||
466 | closedir(dir); | ||
467 | } | ||
468 | |||
469 | Remote_View->setSorting( 3,FALSE); | ||
470 | fillCombo( (const QString &) currentRemoteDir.canonicalPath() ); | ||
471 | } | ||
472 | |||
473 | void AdvancedFm::localListClicked(QListViewItem *selectedItem) | ||
474 | { | ||
475 | if(selectedItem) { | ||
476 | QString strItem=selectedItem->text(0); | ||
477 | QString strSize=selectedItem->text(1); | ||
478 | strSize=strSize.stripWhiteSpace(); | ||
479 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | ||
480 | // is symlink | ||
481 | QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); | ||
482 | if(QDir(strItem2).exists() ) { | ||
483 | currentDir.cd(strItem2, TRUE); | ||
484 | populateLocalView(); | ||
485 | } | ||
486 | } else { // not a symlink | ||
487 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | ||
488 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { | ||
489 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | ||
490 | currentDir.cd(strItem,FALSE); | ||
491 | populateLocalView(); | ||
492 | } else { | ||
493 | currentDir.cdUp(); | ||
494 | populateLocalView(); | ||
495 | } | ||
496 | if(QDir(strItem).exists()){ | ||
497 | currentDir.cd(strItem, TRUE); | ||
498 | populateLocalView(); | ||
499 | } | ||
500 | } else { | ||
501 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | ||
502 | if( QFile::exists(strItem ) ) { | ||
503 | // qDebug("upload "+strItem); | ||
504 | } | ||
505 | } //end not symlink | ||
506 | chdir(strItem.latin1()); | ||
507 | } | ||
508 | } | ||
509 | } | ||
510 | |||
511 | void AdvancedFm::remoteListClicked(QListViewItem *selectedItem) | ||
512 | { | ||
513 | if(selectedItem) { | ||
514 | QString strItem=selectedItem->text(0); | ||
515 | QString strSize=selectedItem->text(1); | ||
516 | strSize=strSize.stripWhiteSpace(); | ||
517 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | ||
518 | // is symlink | ||
519 | QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); | ||
520 | if(QDir(strItem2).exists() ) { | ||
521 | currentRemoteDir.cd(strItem2, TRUE); | ||
522 | populateRemoteView(); | ||
523 | } | ||
524 | } else { // not a symlink | ||
525 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | ||
526 | if(QDir(QDir::cleanDirPath( currentRemoteDir.canonicalPath()+"/"+strItem)).exists() ) { | ||
527 | strItem=QDir::cleanDirPath( currentRemoteDir.canonicalPath()+"/"+strItem); | ||
528 | currentRemoteDir.cd(strItem,FALSE); | ||
529 | populateRemoteView(); | ||
530 | } else { | ||
531 | currentRemoteDir.cdUp(); | ||
532 | populateRemoteView(); | ||
533 | } | ||
534 | if(QDir(strItem).exists()){ | ||
535 | currentRemoteDir.cd(strItem, TRUE); | ||
536 | populateRemoteView(); | ||
537 | } | ||
538 | } else { | ||
539 | strItem=QDir::cleanDirPath( currentRemoteDir.canonicalPath()+"/"+strItem); | ||
540 | if( QFile::exists(strItem ) ) { | ||
541 | // qDebug("upload "+strItem); | ||
542 | } | ||
543 | } //end not symlink | ||
544 | chdir(strItem.latin1()); | ||
545 | } | ||
546 | } | ||
547 | } | ||
548 | |||
549 | void AdvancedFm::doLocalCd() | ||
550 | { | ||
551 | localListClicked( Local_View->currentItem()); | ||
552 | } | ||
553 | |||
554 | void AdvancedFm::doRemoteCd() | ||
555 | { | ||
556 | localListClicked( Remote_View->currentItem()); | ||
557 | } | ||
558 | |||
559 | void AdvancedFm::showHidden() | ||
560 | { | ||
561 | if (!b) { | ||
562 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | ||
563 | // localMenu->setItemChecked(localMenu->idAt(0),TRUE); | ||
564 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
565 | b=TRUE; | ||
566 | |||
567 | } else { | ||
568 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | ||
569 | // localMenu->setItemChecked(localMenu->idAt(0),FALSE); | ||
570 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
571 | b=FALSE; | ||
572 | } | ||
573 | populateLocalView(); | ||
574 | } | ||
575 | |||
576 | void AdvancedFm::showRemoteHidden() | ||
577 | { | ||
578 | if (!b) { | ||
579 | currentRemoteDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | ||
580 | // viewMenu->setItemChecked(localMenu->idAt(0),TRUE); | ||
581 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
582 | b=TRUE; | ||
583 | |||
584 | } else { | ||
585 | currentRemoteDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | ||
586 | // localMenu->setItemChecked(localMenu->idAt(0),FALSE); | ||
587 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | ||
588 | b=FALSE; | ||
589 | } | ||
590 | populateRemoteView(); | ||
591 | } | ||
592 | |||
593 | void AdvancedFm::localListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) | ||
594 | { | ||
595 | switch (mouse) { | ||
596 | case 1: | ||
597 | break; | ||
598 | case 2: | ||
599 | showLocalMenu(item); | ||
600 | Local_View->clearSelection(); | ||
601 | break; | ||
602 | }; | ||
603 | } | ||
604 | |||
605 | void AdvancedFm::remoteListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) | ||
606 | { | ||
607 | switch (mouse) { | ||
608 | case 1: | ||
609 | break; | ||
610 | case 2: | ||
611 | showRemoteMenu(item); | ||
612 | Remote_View->clearSelection(); | ||
613 | break; | ||
614 | }; | ||
615 | } | ||
616 | |||
617 | void AdvancedFm::showLocalMenu(QListViewItem * item) | ||
618 | { | ||
619 | if(item) { | ||
620 | QPopupMenu m; | ||
621 | m.insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); | ||
622 | m.insertSeparator(); | ||
623 | if( /*item->text(0).right(1) == "/" ||*/ item->text(0).find("/",0,TRUE) !=-1) | ||
624 | m.insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); | ||
625 | else | ||
626 | m.insertItem( tr( "Open" ), this, SLOT( runThis() )); | ||
627 | m.insertItem( tr( "Open as Text" ), this, SLOT( runText() )); | ||
628 | m.insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); | ||
629 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); | ||
630 | m.insertItem( tr( "Copy" ), this, SLOT( copy() )); | ||
631 | m.insertItem( tr( "Copy As" ), this, SLOT( copyAs() )); | ||
632 | m.insertItem( tr( "Move" ), this, SLOT( move() )); | ||
633 | m.insertSeparator(); | ||
634 | m.insertItem( tr( "Run Command" ), this, SLOT( runCommand() )); | ||
635 | m.insertItem( tr( "File Info" ), this, SLOT( fileStatus() )); | ||
636 | m.insertSeparator(); | ||
637 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | ||
638 | m.insertSeparator(); | ||
639 | m.insertItem( tr( "Set Permissions" ), this, SLOT( filePerms() )); | ||
640 | m.insertItem( tr( "Properties" ), this, SLOT( doProperties() )); | ||
641 | m.setCheckable(TRUE); | ||
642 | if (b) | ||
643 | m.setItemChecked(m.idAt(0),TRUE); | ||
644 | else | ||
645 | m.setItemChecked(m.idAt(0),FALSE); | ||
646 | m.exec( QCursor::pos() ); | ||
647 | } | ||
648 | } | ||
649 | |||
650 | void AdvancedFm::showRemoteMenu(QListViewItem * item) | ||
651 | { | ||
652 | if(item) { | ||
653 | QPopupMenu m; | ||
654 | m.insertItem( tr( "Show Hidden Files" ), this, SLOT( showRemoteHidden() )); | ||
655 | m.insertSeparator(); | ||
656 | if( /*item->text(0).right(1) == "/" ||*/ item->text(0).find("/",0,TRUE) !=-1) | ||
657 | m.insertItem( tr( "Change Directory" ), this, SLOT( doRemoteCd() )); | ||
658 | else | ||
659 | m.insertItem( tr( "Open" ), this, SLOT( runThis() )); | ||
660 | m.insertItem( tr( "Open as Text" ), this, SLOT( runText() )); | ||
661 | m.insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); | ||
662 | m.insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); | ||
663 | m.insertItem( tr( "Copy" ), this, SLOT( copy() )); | ||
664 | m.insertItem( tr( "Copy As" ), this, SLOT( copyAs() )); | ||
665 | m.insertItem( tr( "Move" ), this, SLOT( move() )); | ||
666 | m.insertSeparator(); | ||
667 | m.insertItem( tr( "Run Command" ), this, SLOT( runCommand() )); | ||
668 | m.insertItem( tr( "File Info" ), this, SLOT( fileStatus() )); | ||
669 | m.insertSeparator(); | ||
670 | m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); | ||
671 | m.insertSeparator(); | ||
672 | m.insertItem( tr( "Set Permissions" ), this, SLOT( filePerms() )); | ||
673 | m.insertItem( tr( "Properties" ), this, SLOT( doProperties() )); | ||
674 | m.setCheckable(TRUE); | ||
675 | if (b) | ||
676 | m.setItemChecked(m.idAt(0),TRUE); | ||
677 | else | ||
678 | m.setItemChecked(m.idAt(0),FALSE); | ||
679 | m.exec( QCursor::pos() ); | ||
680 | } | ||
681 | } | ||
682 | |||
683 | void AdvancedFm::runThis() { | ||
684 | // QFileInfo *fi; | ||
685 | if (TabWidget->currentPageIndex() == 0) { | ||
686 | QString curFile = Local_View->currentItem()->text(0); | ||
687 | curFile = currentDir.canonicalPath()+"/"+curFile; | ||
688 | DocLnk nf(curFile); | ||
689 | QString execStr = nf.exec(); | ||
690 | qDebug( execStr); | ||
691 | if( execStr.isEmpty() ) { | ||
692 | } else { | ||
693 | nf.execute(); | ||
694 | } | ||
695 | // MimeType mt( curFile); | ||
696 | } else { | ||
697 | QString curFile = Remote_View->currentItem()->text(0); | ||
698 | curFile = currentRemoteDir.canonicalPath()+"/"+curFile; | ||
699 | DocLnk nf(curFile); | ||
700 | QString execStr = nf.exec(); | ||
701 | qDebug(execStr); | ||
702 | if( execStr.isEmpty() ) { | ||
703 | } else { | ||
704 | nf.execute(); | ||
705 | } | ||
706 | // MimeType mt( curFile); | ||
707 | } | ||
708 | } | ||
709 | |||
710 | void AdvancedFm::runText() { | ||
711 | if (TabWidget->currentPageIndex() == 0) { | ||
712 | QString curFile = Local_View->currentItem()->text(0); | ||
713 | curFile = currentDir.canonicalPath()+"/"+curFile; | ||
714 | QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" ); | ||
715 | e << curFile; | ||
716 | } else { | ||
717 | QString curFile = Remote_View->currentItem()->text(0); | ||
718 | curFile = currentRemoteDir.canonicalPath()+"/"+curFile; | ||
719 | DocLnk nf(curFile); | ||
720 | QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" ); | ||
721 | e << curFile; | ||
722 | } | ||
723 | } | ||
724 | |||
725 | void AdvancedFm::localMakDir() | ||
726 | { | ||
727 | InputDialog *fileDlg; | ||
728 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); | ||
729 | fileDlg->exec(); | ||
730 | if( fileDlg->result() == 1 ) { | ||
731 | QString filename = fileDlg->LineEdit1->text(); | ||
732 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); | ||
733 | } | ||
734 | populateLocalView(); | ||
735 | } | ||
736 | |||
737 | void AdvancedFm::remoteMakDir() | ||
738 | { | ||
739 | InputDialog *fileDlg; | ||
740 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); | ||
741 | fileDlg->exec(); | ||
742 | if( fileDlg->result() == 1 ) { | ||
743 | QString filename = fileDlg->LineEdit1->text(); | ||
744 | currentRemoteDir.mkdir( currentRemoteDir.canonicalPath()+"/"+filename); | ||
745 | } | ||
746 | populateRemoteView(); | ||
747 | } | ||
748 | |||
749 | void AdvancedFm::localDelete() | ||
750 | { | ||
751 | QString f = Local_View->currentItem()->text(0); | ||
752 | if(QDir(f).exists() ) { | ||
753 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+ | ||
754 | tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) { | ||
755 | case 0: { | ||
756 | f=currentDir.canonicalPath()+"/"+f; | ||
757 | QString cmd="rmdir "+f; | ||
758 | system( cmd.latin1()); | ||
759 | populateLocalView(); | ||
760 | } | ||
761 | break; | ||
762 | case 1: | ||
763 | // exit | ||
764 | break; | ||
765 | }; | ||
766 | |||
767 | } else { | ||
768 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f | ||
769 | +" ?",tr("Yes"),tr("No"),0,0,1) ) { | ||
770 | case 0: { | ||
771 | f=currentDir.canonicalPath()+"/"+f; | ||
772 | QString cmd="rm "+f; | ||
773 | system( cmd.latin1()); | ||
774 | populateLocalView(); | ||
775 | } | ||
776 | break; | ||
777 | case 1: | ||
778 | // exit | ||
779 | break; | ||
780 | }; | ||
781 | } | ||
782 | } | ||
783 | |||
784 | void AdvancedFm::remoteDelete() | ||
785 | { | ||
786 | QString f = Remote_View->currentItem()->text(0); | ||
787 | if(QDir(f).exists() ) { | ||
788 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+ | ||
789 | tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) { | ||
790 | case 0: { | ||
791 | f = currentRemoteDir.canonicalPath()+"/"+f; | ||
792 | QString cmd="rmdir "+f; | ||
793 | system( cmd.latin1()); | ||
794 | populateRemoteView(); | ||
795 | } | ||
796 | break; | ||
797 | case 1: | ||
798 | // exit | ||
799 | break; | ||
800 | }; | ||
801 | |||
802 | } else { | ||
803 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f | ||
804 | +" ?",tr("Yes"),tr("No"),0,0,1) ) { | ||
805 | case 0: { | ||
806 | f = currentRemoteDir.canonicalPath()+"/"+f; | ||
807 | QString cmd="rm "+f; | ||
808 | system( cmd.latin1()); | ||
809 | populateRemoteView(); | ||
810 | } | ||
811 | break; | ||
812 | case 1: | ||
813 | // exit | ||
814 | break; | ||
815 | }; | ||
816 | } | ||
817 | } | ||
818 | |||
819 | void AdvancedFm::localRename() | ||
820 | { | ||
821 | QString curFile = Local_View->currentItem()->text(0); | ||
822 | InputDialog *fileDlg; | ||
823 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | ||
824 | fileDlg->setInputText((const QString &)curFile); | ||
825 | fileDlg->exec(); | ||
826 | if( fileDlg->result() == 1 ) { | ||
827 | QString oldname = currentDir.canonicalPath() + "/" + curFile; | ||
828 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; | ||
829 | if( rename(oldname.latin1(), newName.latin1())== -1) | ||
830 | QMessageBox::message(tr("Note"),tr("Could not rename")); | ||
831 | } | ||
832 | populateLocalView(); | ||
833 | } | ||
834 | |||
835 | void AdvancedFm::remoteRename() | ||
836 | { | ||
837 | QString curFile = Local_View->currentItem()->text(0); | ||
838 | InputDialog *fileDlg; | ||
839 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | ||
840 | fileDlg->setInputText((const QString &)curFile); | ||
841 | fileDlg->exec(); | ||
842 | if( fileDlg->result() == 1 ) { | ||
843 | QString oldname = currentRemoteDir.canonicalPath() + "/" + curFile; | ||
844 | QString newName = currentRemoteDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; | ||
845 | if( rename(oldname.latin1(), newName.latin1())== -1) | ||
846 | QMessageBox::message(tr("Note"),tr("Could not rename")); | ||
847 | } | ||
848 | populateRemoteView(); | ||
849 | } | ||
850 | |||
851 | void AdvancedFm::switchToLocalTab() | ||
852 | { | ||
853 | TabWidget->setCurrentPage(0); | ||
854 | } | ||
855 | |||
856 | void AdvancedFm::switchToRemoteTab() | ||
857 | { | ||
858 | TabWidget->setCurrentPage(1); | ||
859 | } | ||
860 | |||
861 | void AdvancedFm::readConfig() | ||
862 | { | ||
863 | Config cfg("AdvancedFm"); | ||
864 | } | ||
865 | |||
866 | void AdvancedFm::writeConfig() | ||
867 | { | ||
868 | Config cfg("AdvancedFm"); | ||
869 | } | ||
870 | |||
871 | void AdvancedFm::currentPathComboChanged() | ||
872 | { | ||
873 | if (TabWidget->currentPageIndex() == 0) { | ||
874 | if(QDir( currentPathCombo->lineEdit()->text()).exists()) { | ||
875 | currentDir.setPath( currentPathCombo->lineEdit()->text() ); | ||
876 | populateLocalView(); | ||
877 | } else { | ||
878 | QMessageBox::message(tr("Note"),tr("That directory does not exist")); | ||
879 | } | ||
880 | } | ||
881 | if (TabWidget->currentPageIndex() == 0) { | ||
882 | if(QDir( currentPathCombo->lineEdit()->text()).exists()) { | ||
883 | currentRemoteDir.setPath( currentPathCombo->lineEdit()->text() ); | ||
884 | populateRemoteView(); | ||
885 | } else { | ||
886 | QMessageBox::message(tr("Note"),tr("That directory does not exist")); | ||
887 | } | ||
888 | } | ||
889 | } | ||
890 | |||
891 | void AdvancedFm::fillCombo(const QString ¤tPath) { | ||
892 | |||
893 | if (TabWidget->currentPageIndex() == 0) { | ||
894 | currentPathCombo->lineEdit()->setText( currentPath); | ||
895 | if( localDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | ||
896 | currentPathCombo->clear(); | ||
897 | localDirPathStringList.prepend( currentPath ); | ||
898 | currentPathCombo->insertStringList( localDirPathStringList,-1); | ||
899 | } | ||
900 | } else { | ||
901 | currentPathCombo->lineEdit()->setText( currentPath); | ||
902 | if( remoteDirPathStringList.grep( currentPath,TRUE).isEmpty() ) { | ||
903 | currentPathCombo->clear(); | ||
904 | remoteDirPathStringList.prepend( currentPath ); | ||
905 | currentPathCombo->insertStringList( remoteDirPathStringList,-1); | ||
906 | } | ||
907 | } | ||
908 | } | ||
909 | |||
910 | void AdvancedFm::currentPathComboActivated(const QString & currentPath) { | ||
911 | if (TabWidget->currentPageIndex() == 0) { | ||
912 | chdir( currentPath.latin1() ); | ||
913 | currentDir.cd( currentPath, TRUE); | ||
914 | populateLocalView(); | ||
915 | update(); | ||
916 | } else { | ||
917 | chdir( currentPath.latin1() ); | ||
918 | currentRemoteDir.cd( currentPath, TRUE); | ||
919 | populateRemoteView(); | ||
920 | update(); | ||
921 | } | ||
922 | } | ||
923 | |||
924 | void AdvancedFm::filePerms() { | ||
925 | QString curFile = getPath(); | ||
926 | filePermissions *filePerm; | ||
927 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(curFile)); | ||
928 | filePerm->showMaximized(); | ||
929 | filePerm->exec(); | ||
930 | if( filePerm) | ||
931 | delete filePerm; | ||
932 | } | ||
933 | |||
934 | void AdvancedFm::doProperties() { | ||
935 | |||
936 | DocLnk lnk( getPath()); | ||
937 | LnkProperties prop( &lnk ); | ||
938 | // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | ||
939 | prop.showMaximized(); | ||
940 | prop.exec(); | ||
941 | } | ||
942 | |||
943 | QString AdvancedFm::getPath() { | ||
944 | if (TabWidget->currentPageIndex() == 0) { | ||
945 | return currentDir.canonicalPath()+"/"+ Local_View->currentItem()->text(0); | ||
946 | } else { | ||
947 | return currentRemoteDir.canonicalPath() + "/"+Remote_View->currentItem()->text(0); | ||
948 | } | ||
949 | } | ||
950 | |||
951 | void AdvancedFm::homeButtonPushed() { | ||
952 | QString current = QDir::homeDirPath(); | ||
953 | chdir( current.latin1() ); | ||
954 | if (TabWidget->currentPageIndex() == 0) { | ||
955 | currentDir.cd( current, TRUE); | ||
956 | populateLocalView(); | ||
957 | } else { | ||
958 | currentRemoteDir.cd( current, TRUE); | ||
959 | populateRemoteView(); | ||
960 | } | ||
961 | update(); | ||
962 | } | ||
963 | |||
964 | void AdvancedFm::docButtonPushed() { | ||
965 | QString current = QPEApplication::documentDir(); | ||
966 | chdir( current.latin1() ); | ||
967 | if (TabWidget->currentPageIndex() == 0) { | ||
968 | currentDir.cd( current, TRUE); | ||
969 | populateLocalView(); | ||
970 | } else { | ||
971 | currentRemoteDir.cd( current, TRUE); | ||
972 | populateRemoteView(); | ||
973 | } | ||
974 | update(); | ||
975 | } | ||
976 | |||
977 | void AdvancedFm::SDButtonPushed() { | ||
978 | QString current = "/mnt/card"; | ||
979 | chdir( current.latin1() ); | ||
980 | if (TabWidget->currentPageIndex() == 0) { | ||
981 | currentDir.cd( current, TRUE); | ||
982 | populateLocalView(); | ||
983 | } else { | ||
984 | currentRemoteDir.cd( current, TRUE); | ||
985 | populateRemoteView(); | ||
986 | } | ||
987 | update(); | ||
988 | |||
989 | } | ||
990 | |||
991 | void AdvancedFm::CFButtonPushed() { | ||
992 | QString current = "/mnt/cf"; | ||
993 | chdir( current.latin1() ); | ||
994 | if (TabWidget->currentPageIndex() == 0) { | ||
995 | currentDir.cd( current, TRUE); | ||
996 | populateLocalView(); | ||
997 | } else { | ||
998 | currentRemoteDir.cd( current, TRUE); | ||
999 | populateRemoteView(); | ||
1000 | } | ||
1001 | update(); | ||
1002 | |||
1003 | } | ||
1004 | |||
1005 | |||
1006 | void AdvancedFm::upDir() | ||
1007 | { | ||
1008 | if (TabWidget->currentPageIndex() == 0) { | ||
1009 | QString current = currentDir.canonicalPath(); | ||
1010 | QDir dir(current); | ||
1011 | dir.cdUp(); | ||
1012 | current = dir.canonicalPath(); | ||
1013 | chdir( current.latin1() ); | ||
1014 | currentDir.cd( current, TRUE); | ||
1015 | populateLocalView(); | ||
1016 | update(); | ||
1017 | } else { | ||
1018 | QString current = currentRemoteDir.canonicalPath(); | ||
1019 | QDir dir(current); | ||
1020 | dir.cdUp(); | ||
1021 | current = dir.canonicalPath(); | ||
1022 | chdir( current.latin1() ); | ||
1023 | currentRemoteDir.cd( current, TRUE); | ||
1024 | populateRemoteView(); | ||
1025 | update(); | ||
1026 | } | ||
1027 | } | ||
1028 | |||
1029 | void AdvancedFm::copy() | ||
1030 | { | ||
1031 | QString curFile = getPath(); | ||
1032 | if (TabWidget->currentPageIndex() == 0) { | ||
1033 | QString destFile = currentRemoteDir.canonicalPath()+"/"+Local_View->currentItem()->text(0); | ||
1034 | QFile f(destFile); | ||
1035 | if( f.exists()) | ||
1036 | f.remove(); | ||
1037 | if(!copyFile(destFile, curFile) ) | ||
1038 | qWarning("nothin doing"); | ||
1039 | populateRemoteView(); | ||
1040 | TabWidget->setCurrentPage(1); | ||
1041 | } else { | ||
1042 | QString destFile = currentDir.canonicalPath()+"/"+Remote_View->currentItem()->text(0); | ||
1043 | QFile f(destFile); | ||
1044 | if( f.exists()) | ||
1045 | f.remove(); | ||
1046 | if(!copyFile(destFile, curFile) ) | ||
1047 | qWarning("nothin doing"); | ||
1048 | populateLocalView(); | ||
1049 | TabWidget->setCurrentPage(0); | ||
1050 | } | ||
1051 | } | ||
1052 | |||
1053 | void AdvancedFm::copyAs() | ||
1054 | { | ||
1055 | QString curFile = getPath(); | ||
1056 | if (TabWidget->currentPageIndex() == 0) { | ||
1057 | QString destFile = Local_View->currentItem()->text(0); | ||
1058 | InputDialog *fileDlg; | ||
1059 | fileDlg = new InputDialog(this,tr("Copy As"),TRUE, 0); | ||
1060 | fileDlg->setInputText((const QString &) destFile ); | ||
1061 | fileDlg->exec(); | ||
1062 | if( fileDlg->result() == 1 ) { | ||
1063 | QString filename = fileDlg->LineEdit1->text(); | ||
1064 | destFile = currentRemoteDir.canonicalPath()+"/"+destFile; | ||
1065 | |||
1066 | QFile f(destFile); | ||
1067 | if( f.exists()) | ||
1068 | f.remove(); | ||
1069 | if(!copyFile(destFile, curFile) ) | ||
1070 | qWarning("nothin doing"); | ||
1071 | } | ||
1072 | populateRemoteView(); | ||
1073 | TabWidget->setCurrentPage(1); | ||
1074 | } else { | ||
1075 | QString destFile = Remote_View->currentItem()->text(0); | ||
1076 | InputDialog *fileDlg; | ||
1077 | fileDlg = new InputDialog(this,tr("Copy As"),TRUE, 0); | ||
1078 | fileDlg->setInputText((const QString &) destFile); | ||
1079 | fileDlg->exec(); | ||
1080 | if( fileDlg->result() == 1 ) { | ||
1081 | QString filename = fileDlg->LineEdit1->text(); | ||
1082 | destFile = currentDir.canonicalPath()+"/"+destFile; | ||
1083 | |||
1084 | QFile f(destFile); | ||
1085 | if( f.exists()) | ||
1086 | f.remove(); | ||
1087 | if(!copyFile(destFile, curFile) ) | ||
1088 | qWarning("nothin doing"); | ||
1089 | } | ||
1090 | populateLocalView(); | ||
1091 | TabWidget->setCurrentPage(0); | ||
1092 | } | ||
1093 | } | ||
1094 | |||
1095 | void AdvancedFm::move() { | ||
1096 | QString curFile = getPath(); | ||
1097 | // qDebug(curFile); | ||
1098 | QString destFile; | ||
1099 | if (TabWidget->currentPageIndex() == 0) { | ||
1100 | QString destFile = currentRemoteDir.canonicalPath()+Local_View->currentItem()->text(0); | ||
1101 | // qDebug(destFile); | ||
1102 | |||
1103 | QFile f(destFile); | ||
1104 | if( f.exists()) | ||
1105 | f.remove(); | ||
1106 | if(!copyFile( destFile, curFile) ) { | ||
1107 | QMessageBox::message(tr("Note"),tr("Could not move\n"+curFile)); | ||
1108 | return; | ||
1109 | } | ||
1110 | QFile::remove(curFile); | ||
1111 | TabWidget->setCurrentPage(1); | ||
1112 | } else { | ||
1113 | QString destFile = currentDir.canonicalPath()+destFile + Remote_View->currentItem()->text(0); | ||
1114 | // qDebug(destFile); | ||
1115 | |||
1116 | QFile f(destFile); | ||
1117 | if( f.exists()) | ||
1118 | f.remove(); | ||
1119 | if(!copyFile(destFile, curFile) ) { | ||
1120 | QMessageBox::message(tr("Note"),tr("Could not move\n"+curFile)); | ||
1121 | return; | ||
1122 | } | ||
1123 | QFile::remove(curFile); | ||
1124 | TabWidget->setCurrentPage(0); | ||
1125 | } | ||
1126 | populateRemoteView(); | ||
1127 | populateLocalView(); | ||
1128 | } | ||
1129 | |||
1130 | bool AdvancedFm::copyFile( const QString & dest, const QString & src ) | ||
1131 | { | ||
1132 | char bf[ 50000 ]; | ||
1133 | int bytesRead; | ||
1134 | bool success = TRUE; | ||
1135 | struct stat status; | ||
1136 | |||
1137 | QFile s( src ); | ||
1138 | QFile d( dest ); | ||
1139 | |||
1140 | if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) ) { | ||
1141 | while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) ) { | ||
1142 | if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ | ||
1143 | success = FALSE; | ||
1144 | break; | ||
1145 | } | ||
1146 | } | ||
1147 | if( success && (bytesRead > 0) ){ | ||
1148 | d.writeBlock( bf, bytesRead ); | ||
1149 | } | ||
1150 | } else { | ||
1151 | success = FALSE; | ||
1152 | } | ||
1153 | |||
1154 | // Set file permissions | ||
1155 | if( stat( (const char *) src, &status ) == 0 ){ | ||
1156 | chmod( (const char *) dest, status.st_mode ); | ||
1157 | } | ||
1158 | |||
1159 | return success; | ||
1160 | } | ||
1161 | |||
1162 | void AdvancedFm::runCommand() { | ||
1163 | QString curFile; | ||
1164 | if (TabWidget->currentPageIndex() == 0) { | ||
1165 | if( Local_View->currentItem()) | ||
1166 | curFile = currentDir.canonicalPath() + Local_View->currentItem()->text(0); | ||
1167 | } else { | ||
1168 | if(Remote_View->currentItem()) | ||
1169 | curFile = currentRemoteDir.canonicalPath() + Remote_View->currentItem()->text(0); | ||
1170 | } | ||
1171 | |||
1172 | InputDialog *fileDlg; | ||
1173 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | ||
1174 | fileDlg->setInputText(curFile); | ||
1175 | fileDlg->exec(); | ||
1176 | QString command; | ||
1177 | if( fileDlg->result() == 1 ) { | ||
1178 | command = fileDlg->LineEdit1->text(); | ||
1179 | |||
1180 | int err=0; | ||
1181 | Output *outDlg; | ||
1182 | outDlg = new Output(this, tr("Formatter Output"),FALSE); | ||
1183 | outDlg->showMaximized(); | ||
1184 | outDlg->show(); | ||
1185 | qApp->processEvents(); | ||
1186 | FILE *fp; | ||
1187 | char line[130]; | ||
1188 | sleep(1); | ||
1189 | // if(command.find("2>",0,TRUE) != -1) | ||
1190 | command +=" 2>&1"; | ||
1191 | fp = popen( (const char *) command, "r"); | ||
1192 | if ( !fp ) { | ||
1193 | qDebug("Could not execute '" + command + "'! err=%d", fp); | ||
1194 | QMessageBox::warning( this, tr("AdvancedFm"), tr("command failed!"), tr("&OK") ); | ||
1195 | pclose(fp); | ||
1196 | return; | ||
1197 | } else { | ||
1198 | while ( fgets( line, sizeof line, fp)) { | ||
1199 | outDlg->OutputEdit->append(line); | ||
1200 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
1201 | |||
1202 | } | ||
1203 | |||
1204 | } | ||
1205 | |||
1206 | } | ||
1207 | |||
1208 | } | ||
1209 | |||
1210 | void AdvancedFm::runCommandStd() { | ||
1211 | QString curFile; | ||
1212 | if (TabWidget->currentPageIndex() == 0) { | ||
1213 | if( Local_View->currentItem()) | ||
1214 | curFile = currentDir.canonicalPath() + Local_View->currentItem()->text(0); | ||
1215 | } else { | ||
1216 | if(Remote_View->currentItem()) | ||
1217 | curFile = currentRemoteDir.canonicalPath() + Remote_View->currentItem()->text(0); | ||
1218 | } | ||
1219 | |||
1220 | InputDialog *fileDlg; | ||
1221 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | ||
1222 | fileDlg->setInputText(curFile); | ||
1223 | fileDlg->exec(); | ||
1224 | QString command; | ||
1225 | if( fileDlg->result() == 1 ) { | ||
1226 | qApp->processEvents(); | ||
1227 | command = fileDlg->LineEdit1->text() + " &"; | ||
1228 | system(command.latin1()); | ||
1229 | } | ||
1230 | } | ||
1231 | |||
1232 | void AdvancedFm::fileStatus() { | ||
1233 | QString curFile; | ||
1234 | if (TabWidget->currentPageIndex() == 0) { | ||
1235 | curFile = Local_View->currentItem()->text(0); | ||
1236 | } else { | ||
1237 | curFile = Remote_View->currentItem()->text(0); | ||
1238 | } | ||
1239 | QString command = " stat -l "+ curFile +" 2>&1"; | ||
1240 | int err=0; | ||
1241 | Output *outDlg; | ||
1242 | outDlg = new Output(this, tr("Formatter Output"),FALSE); | ||
1243 | outDlg->showMaximized(); | ||
1244 | outDlg->show(); | ||
1245 | qApp->processEvents(); | ||
1246 | FILE *fp; | ||
1247 | char line[130]; | ||
1248 | sleep(1); | ||
1249 | fp = popen( (const char *) command, "r"); | ||
1250 | if ( !fp ) { | ||
1251 | qDebug("Could not execute '" + command + "'! err=%d", fp); | ||
1252 | QMessageBox::warning( this, tr("AdvancedFm"), tr("command failed!"), tr("&OK") ); | ||
1253 | pclose(fp); | ||
1254 | return; | ||
1255 | } else { | ||
1256 | while ( fgets( line, sizeof line, fp)) { | ||
1257 | outDlg->OutputEdit->append(line); | ||
1258 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
1259 | |||
1260 | } | ||
1261 | |||
1262 | } | ||
1263 | } | ||