From 4f66a9a7bcd34452fef6ff8810a8946f5f4fd915 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Jun 2010 00:03:26 +0200 Subject: [PATCH] added actions for creating directories and removing directories or files --- qhimdtransfer/qhimdmainwindow.cpp | 64 +++++++++++++++++++++++++++++++++++++ qhimdtransfer/qhimdmainwindow.h | 4 ++ qhimdtransfer/qhimdmainwindow.ui | 50 ++++++++++++++++++++++++++++- 3 files changed, 117 insertions(+), 1 deletions(-) diff --git a/qhimdtransfer/qhimdmainwindow.cpp b/qhimdtransfer/qhimdmainwindow.cpp index 34ff44d..13800ae 100644 --- a/qhimdtransfer/qhimdmainwindow.cpp +++ b/qhimdtransfer/qhimdmainwindow.cpp @@ -4,6 +4,7 @@ #include "qhimduploaddialog.h" #include #include +#include #include @@ -480,11 +481,19 @@ void QHiMDMainWindow::on_action_Connect_triggered() void QHiMDMainWindow::on_localScan_clicked(QModelIndex index) { + bool removable = false; + if(localmodel.fileInfo(index).isDir()) { ui->updir->setText(localmodel.filePath(index)); settings.setValue("lastUploadDirectory", localmodel.filePath(index)); } + + if(index.parent().isValid() && !localmodel.fileInfo(index).isSymLink() + && localmodel.fileInfo(index).isWritable()) + removable = true; + ui->action_Remove->setEnabled(removable); + ui->remove->setEnabled(removable); } void QHiMDMainWindow::on_upload_button_clicked() @@ -555,3 +564,58 @@ void QHiMDMainWindow::on_himd_devices_activated(QString device) { open_himd_at(device); } + +void QHiMDMainWindow::on_action_New_Folder_triggered() +{ + bool ok; + QString newdir; + QModelIndex index = ui->localScan->currentIndex(); + + if(!localmodel.fileInfo(index).isDir()) + index = localmodel.parent(index); + + newdir = QInputDialog::getText(this, + tr("Create directory"), + tr("Creating a new directory in %1\n" + "Select name for the new directory").arg(localmodel.filePath(index)), + QLineEdit::Normal, + tr("new folder"), + &ok); + + if(!ok || newdir.isEmpty()) + return; + + index = localmodel.mkdir(index, newdir); + ui->localScan->setCurrentIndex(index); + on_localScan_clicked(ui->localScan->currentIndex()); +} + +void QHiMDMainWindow::on_action_Remove_triggered() +{ + int ret; + QModelIndex index = ui->localScan->currentIndex(); + + ret = QMessageBox::question(this, tr("Removing file or directory"), + tr("Are you sure you want to remove %1 ?\n\n" + "Note: The file or directory will be removed permanently " + "and cannot be recovered").arg(localmodel.filePath(index)), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel); + + if(ret != QMessageBox::Ok) + return; + + ui->localScan->setCurrentIndex(localmodel.parent(index)); + on_localScan_clicked(ui->localScan->currentIndex()); + localmodel.remove(index); +} + +void QHiMDMainWindow::on_newdir_clicked() +{ + on_action_New_Folder_triggered(); +} + +void QHiMDMainWindow::on_remove_clicked() +{ + on_action_Remove_triggered(); +} diff --git a/qhimdtransfer/qhimdmainwindow.h b/qhimdtransfer/qhimdmainwindow.h index 0ca406f..4961a46 100644 --- a/qhimdtransfer/qhimdmainwindow.h +++ b/qhimdtransfer/qhimdmainwindow.h @@ -68,6 +68,10 @@ private slots: void himd_found(QString path); void himd_removed(QString path); void on_himd_devices_activated(QString device); + void on_action_New_Folder_triggered(); + void on_action_Remove_triggered(); + void on_newdir_clicked(); + void on_remove_clicked(); signals: void himd_busy(QString path); diff --git a/qhimdtransfer/qhimdmainwindow.ui b/qhimdtransfer/qhimdmainwindow.ui index 149bd77..0f55506 100644 --- a/qhimdtransfer/qhimdmainwindow.ui +++ b/qhimdtransfer/qhimdmainwindow.ui @@ -62,6 +62,9 @@ true + + true + @@ -125,7 +128,7 @@ - + @@ -146,6 +149,29 @@ + + + + New folder + + + + + + + + + + + false + + + Remove file + + + - + + + @@ -156,6 +182,12 @@ true + + true + + + false + @@ -185,6 +217,9 @@ + + + @@ -307,6 +342,19 @@ &Connect + + + New folder + + + + + false + + + Remove file + + -- 1.6.4.msysgit.0