summaryrefslogtreecommitdiff
path: root/core/apps/textedit/fileBrowser.cpp
Side-by-side diff
Diffstat (limited to 'core/apps/textedit/fileBrowser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/fileBrowser.cpp106
1 files changed, 104 insertions, 2 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
@@ -9,12 +9,14 @@
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include "fileBrowser.h"
+#include "inputDialog.h"
+
#include <qpe/config.h>
#include <qpe/resource.h>
#include <qpe/fileselector.h>
#include <qpe/qpeapplication.h>
#include <qwidgetstack.h>
@@ -22,12 +24,17 @@
#include <qcombo.h>
#include <qpushbutton.h>
#include <qfile.h>
#include <qmessagebox.h>
#include <qlayout.h>
#include <unistd.h>
+#include <qpopupmenu.h>
+#include <qlineedit.h>
+
+#include <unistd.h>
+#include <stdlib.h>
static int u_id = 1;
static int get_unique_id()
{
return u_id++;
}
@@ -64,13 +71,13 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) );
homeButton->setFlat(TRUE);
layout->addWidget( homeButton, 0, 2 );
FileStack = new QWidgetStack( this );
- ListView = new QListView( this, "ListView" );
+ ListView = new QListView( this, "ListView" );
ListView->setMinimumSize( QSize( 100, 25 ) );
ListView->addColumn( tr( "Name" ) );
ListView->setColumnWidth(0,120);
ListView->setSorting( 2, FALSE);
ListView->addColumn( tr( "Size" ) );
ListView->setColumnWidth(1,-1);
@@ -78,13 +85,18 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
// ListView->addColumn( tr( "" ) );
ListView->setColumnWidthMode(0,QListView::Manual);
ListView->setColumnAlignment(1,QListView::AlignRight);
ListView->setColumnAlignment(2,QListView::AlignRight);
ListView->setAllColumnsShowFocus( TRUE );
- connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
+ QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold);
+ connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
+ this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) );
+
+ connect( ListView, SIGNAL( clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
+
FileStack->addWidget( ListView, get_unique_id() );
fileSelector = new FileSelector( "text/*", FileStack, "fileselector" , FALSE, FALSE); //buggy
// connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
// connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) );
@@ -269,6 +281,96 @@ void fileBrowser::selectionChanged( const QString &select )
void fileBrowser::docOpen( const DocLnk &doc )
{
fileList.append( doc.file().latin1() );
accept();
}
+
+void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i)
+{
+ switch (mouse) {
+ case 1:
+ break;
+ case 2:
+ showListMenu(item);
+ break;
+ };
+}
+
+void fileBrowser::showListMenu(QListViewItem *item) {
+
+ QPopupMenu m;// = new QPopupMenu( Local_View );
+ if( item->text(0).find("/",0,TRUE))
+ m.insertItem( tr( "Change Directory" ), this, SLOT( doCd() ));
+ else
+ m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() ));
+ m.insertItem( tr( "Rename" ), this, SLOT( localRename() ));
+ m.insertSeparator();
+ m.insertItem( tr( "Delete" ), this, SLOT( localDelete() ));
+ m.exec( QCursor::pos() );
+
+}
+
+void fileBrowser::doCd() {
+ listClicked( ListView->currentItem());
+}
+
+void fileBrowser::makDir() {
+ InputDialog *fileDlg;
+ fileDlg = new InputDialog(this,"Make Directory",TRUE, 0);
+ fileDlg->exec();
+ if( fileDlg->result() == 1 ) {
+ QString filename = fileDlg->LineEdit1->text();
+ currentDir.mkdir( currentDir.canonicalPath()+"/"+filename);
+ }
+ populateList();
+}
+
+void fileBrowser::localRename() {
+ QString curFile = ListView->currentItem()->text(0);
+ InputDialog *fileDlg;
+ fileDlg = new InputDialog(this,"Rename",TRUE, 0);
+ fileDlg->inputText = curFile;
+ fileDlg->exec();
+ if( fileDlg->result() == 1 ) {
+ QString oldname = currentDir.canonicalPath() + "/" + curFile;
+ QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist";
+ if( rename(oldname.latin1(), newName.latin1())== -1)
+ QMessageBox::message("Note","Could not rename");
+ }
+ populateList();
+}
+
+void fileBrowser::localDelete() {
+ QString f = ListView->currentItem()->text(0);
+ if(QDir(f).exists() ) {
+ switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+
+ " ?\nIt must be empty","Yes","No",0,0,1) ) {
+ case 0: {
+ f=currentDir.canonicalPath()+"/"+f;
+ QString cmd="rmdir "+f;
+ system( cmd.latin1());
+ populateList();
+ }
+ break;
+ case 1:
+ // exit
+ break;
+ };
+
+ } else {
+ switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f
+ +" ?","Yes","No",0,0,1) ) {
+ case 0: {
+ f=currentDir.canonicalPath()+"/"+f;
+ QString cmd="rm "+f;
+ system( cmd.latin1());
+ populateList();
+ }
+ break;
+ case 1:
+ // exit
+ break;
+ };
+ }
+
+}