Diffstat (limited to 'core/apps/textedit/fileBrowser.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/apps/textedit/fileBrowser.cpp | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp index 8cb7c38..1fdf9d9 100644 --- a/core/apps/textedit/fileBrowser.cpp +++ b/core/apps/textedit/fileBrowser.cpp | |||
@@ -3,37 +3,44 @@ | |||
3 | ** Created: Fri Dec 14 08:16:46 2001 | 3 | ** Created: Fri Dec 14 08:16:46 2001 |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | ****************************************************************************/ | 13 | ****************************************************************************/ |
14 | #include "fileBrowser.h" | 14 | #include "fileBrowser.h" |
15 | #include "inputDialog.h" | ||
16 | |||
15 | #include <qpe/config.h> | 17 | #include <qpe/config.h> |
16 | #include <qpe/resource.h> | 18 | #include <qpe/resource.h> |
17 | #include <qpe/fileselector.h> | 19 | #include <qpe/fileselector.h> |
18 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
19 | 21 | ||
20 | #include <qwidgetstack.h> | 22 | #include <qwidgetstack.h> |
21 | #include <qlistview.h> | 23 | #include <qlistview.h> |
22 | #include <qcombo.h> | 24 | #include <qcombo.h> |
23 | #include <qpushbutton.h> | 25 | #include <qpushbutton.h> |
24 | #include <qfile.h> | 26 | #include <qfile.h> |
25 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
26 | #include <qlayout.h> | 28 | #include <qlayout.h> |
27 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | #include <qpopupmenu.h> | ||
31 | #include <qlineedit.h> | ||
32 | |||
33 | #include <unistd.h> | ||
34 | #include <stdlib.h> | ||
28 | 35 | ||
29 | static int u_id = 1; | 36 | static int u_id = 1; |
30 | static int get_unique_id() | 37 | static int get_unique_id() |
31 | { | 38 | { |
32 | return u_id++; | 39 | return u_id++; |
33 | } | 40 | } |
34 | 41 | ||
35 | fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) | 42 | fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) |
36 | : QDialog( parent, name, modal, fl ) | 43 | : QDialog( parent, name, modal, fl ) |
37 | { | 44 | { |
38 | if ( !name ) | 45 | if ( !name ) |
39 | setName( "fileBrowser" ); | 46 | setName( "fileBrowser" ); |
@@ -72,25 +79,30 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags | |||
72 | ListView->addColumn( tr( "Name" ) ); | 79 | ListView->addColumn( tr( "Name" ) ); |
73 | ListView->setColumnWidth(0,120); | 80 | ListView->setColumnWidth(0,120); |
74 | ListView->setSorting( 2, FALSE); | 81 | ListView->setSorting( 2, FALSE); |
75 | ListView->addColumn( tr( "Size" ) ); | 82 | ListView->addColumn( tr( "Size" ) ); |
76 | ListView->setColumnWidth(1,-1); | 83 | ListView->setColumnWidth(1,-1); |
77 | ListView->addColumn( "Date",-1); | 84 | ListView->addColumn( "Date",-1); |
78 | // ListView->addColumn( tr( "" ) ); | 85 | // ListView->addColumn( tr( "" ) ); |
79 | ListView->setColumnWidthMode(0,QListView::Manual); | 86 | ListView->setColumnWidthMode(0,QListView::Manual); |
80 | ListView->setColumnAlignment(1,QListView::AlignRight); | 87 | ListView->setColumnAlignment(1,QListView::AlignRight); |
81 | ListView->setColumnAlignment(2,QListView::AlignRight); | 88 | ListView->setColumnAlignment(2,QListView::AlignRight); |
82 | ListView->setAllColumnsShowFocus( TRUE ); | 89 | ListView->setAllColumnsShowFocus( TRUE ); |
83 | 90 | ||
84 | connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 91 | QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold); |
92 | connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
93 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
94 | |||
95 | connect( ListView, SIGNAL( clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | ||
96 | |||
85 | FileStack->addWidget( ListView, get_unique_id() ); | 97 | FileStack->addWidget( ListView, get_unique_id() ); |
86 | 98 | ||
87 | fileSelector = new FileSelector( "text/*", FileStack, "fileselector" , FALSE, FALSE); //buggy | 99 | fileSelector = new FileSelector( "text/*", FileStack, "fileselector" , FALSE, FALSE); //buggy |
88 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 100 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
89 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 101 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
90 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); | 102 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); |
91 | layout->addMultiCellWidget( FileStack, 1, 1, 0, 2 ); | 103 | layout->addMultiCellWidget( FileStack, 1, 1, 0, 2 ); |
92 | 104 | ||
93 | SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); | 105 | SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); |
94 | SelectionCombo->setMinimumSize( QSize( 200, 25 ) ); | 106 | SelectionCombo->setMinimumSize( QSize( 200, 25 ) ); |
95 | SelectionCombo->insertItem( tr( "Documents" ) ); | 107 | SelectionCombo->insertItem( tr( "Documents" ) ); |
96 | SelectionCombo->insertItem( tr( "All files" ) ); | 108 | SelectionCombo->insertItem( tr( "All files" ) ); |
@@ -263,12 +275,102 @@ void fileBrowser::selectionChanged( const QString &select ) | |||
263 | dirLabel->show(); | 275 | dirLabel->show(); |
264 | docButton->show(); | 276 | docButton->show(); |
265 | homeButton->show(); | 277 | homeButton->show(); |
266 | FileStack->raiseWidget( ListView ); | 278 | FileStack->raiseWidget( ListView ); |
267 | } | 279 | } |
268 | } | 280 | } |
269 | 281 | ||
270 | void fileBrowser::docOpen( const DocLnk &doc ) | 282 | void fileBrowser::docOpen( const DocLnk &doc ) |
271 | { | 283 | { |
272 | fileList.append( doc.file().latin1() ); | 284 | fileList.append( doc.file().latin1() ); |
273 | accept(); | 285 | accept(); |
274 | } | 286 | } |
287 | |||
288 | void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) | ||
289 | { | ||
290 | switch (mouse) { | ||
291 | case 1: | ||
292 | break; | ||
293 | case 2: | ||
294 | showListMenu(item); | ||
295 | break; | ||
296 | }; | ||
297 | } | ||
298 | |||
299 | void fileBrowser::showListMenu(QListViewItem *item) { | ||
300 | |||
301 | QPopupMenu m;// = new QPopupMenu( Local_View ); | ||
302 | if( item->text(0).find("/",0,TRUE)) | ||
303 | m.insertItem( tr( "Change Directory" ), this, SLOT( doCd() )); | ||
304 | else | ||
305 | m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() )); | ||
306 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); | ||
307 | m.insertSeparator(); | ||
308 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | ||
309 | m.exec( QCursor::pos() ); | ||
310 | |||
311 | } | ||
312 | |||
313 | void fileBrowser::doCd() { | ||
314 | listClicked( ListView->currentItem()); | ||
315 | } | ||
316 | |||
317 | void fileBrowser::makDir() { | ||
318 | InputDialog *fileDlg; | ||
319 | fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); | ||
320 | fileDlg->exec(); | ||
321 | if( fileDlg->result() == 1 ) { | ||
322 | QString filename = fileDlg->LineEdit1->text(); | ||
323 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); | ||
324 | } | ||
325 | populateList(); | ||
326 | } | ||
327 | |||
328 | void fileBrowser::localRename() { | ||
329 | QString curFile = ListView->currentItem()->text(0); | ||
330 | InputDialog *fileDlg; | ||
331 | fileDlg = new InputDialog(this,"Rename",TRUE, 0); | ||
332 | fileDlg->inputText = curFile; | ||
333 | fileDlg->exec(); | ||
334 | if( fileDlg->result() == 1 ) { | ||
335 | QString oldname = currentDir.canonicalPath() + "/" + curFile; | ||
336 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; | ||
337 | if( rename(oldname.latin1(), newName.latin1())== -1) | ||
338 | QMessageBox::message("Note","Could not rename"); | ||
339 | } | ||
340 | populateList(); | ||
341 | } | ||
342 | |||
343 | void fileBrowser::localDelete() { | ||
344 | QString f = ListView->currentItem()->text(0); | ||
345 | if(QDir(f).exists() ) { | ||
346 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+ | ||
347 | " ?\nIt must be empty","Yes","No",0,0,1) ) { | ||
348 | case 0: { | ||
349 | f=currentDir.canonicalPath()+"/"+f; | ||
350 | QString cmd="rmdir "+f; | ||
351 | system( cmd.latin1()); | ||
352 | populateList(); | ||
353 | } | ||
354 | break; | ||
355 | case 1: | ||
356 | // exit | ||
357 | break; | ||
358 | }; | ||
359 | |||
360 | } else { | ||
361 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f | ||
362 | +" ?","Yes","No",0,0,1) ) { | ||
363 | case 0: { | ||
364 | f=currentDir.canonicalPath()+"/"+f; | ||
365 | QString cmd="rm "+f; | ||
366 | system( cmd.latin1()); | ||
367 | populateList(); | ||
368 | } | ||
369 | break; | ||
370 | case 1: | ||
371 | // exit | ||
372 | break; | ||
373 | }; | ||
374 | } | ||
375 | |||
376 | } | ||