OSDN Git Service

リネーム処理のスレッド化、削除処理の実装。
authorMasayuki Satoh <miyabi.satoh@gmail.com>
Sun, 17 Aug 2014 06:37:03 +0000 (15:37 +0900)
committerMasayuki Satoh <miyabi.satoh@gmail.com>
Sun, 17 Aug 2014 06:37:03 +0000 (15:37 +0900)
27 files changed:
commanddialog.cpp [deleted file]
commanddialog.h [deleted file]
commanddialog.ui [deleted file]
common.h [new file with mode: 0644]
deleteworker.cpp [new file with mode: 0644]
deleteworker.h [new file with mode: 0644]
folderpanel.cpp
folderpanel.h
folderpanel.ui
irenamedialog.cpp [new file with mode: 0644]
irenamedialog.h [new file with mode: 0644]
iworker.cpp [new file with mode: 0644]
iworker.h [new file with mode: 0644]
mainwindow.cpp
mainwindow.h
mainwindow.ui
operationdialog.cpp [new file with mode: 0644]
operationdialog.h [new file with mode: 0644]
operationdialog.ui [new file with mode: 0644]
renamemultidialog.cpp
renamemultidialog.h
renamemultidialog.ui
renamesingledialog.cpp
renamesingledialog.h
renamesingledialog.ui
renameworker.cpp [new file with mode: 0644]
renameworker.h [new file with mode: 0644]

diff --git a/commanddialog.cpp b/commanddialog.cpp
deleted file mode 100644 (file)
index 801aac4..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#include "commanddialog.h"\r
-#include "ui_commanddialog.h"\r
-#include <QPushButton>\r
-#include <QDebug>\r
-\r
-CommandDialog::CommandDialog(QWidget *parent) :\r
-    QDialog(parent),\r
-    ui(new Ui::CommandDialog),\r
-    m_Process(this)\r
-{\r
-    ui->setupUi(this);\r
-    ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("実行"));\r
-}\r
-\r
-CommandDialog::~CommandDialog()\r
-{\r
-    delete ui;\r
-}\r
-\r
-void CommandDialog::setCommandLine(const QString &cmdLine)\r
-{\r
-    ui->lineEdit->setText(cmdLine);\r
-}\r
-\r
-void CommandDialog::setWorkingDirectory(const QString &dir)\r
-{\r
-    m_Process.setWorkingDirectory(dir);\r
-}\r
-\r
-void CommandDialog::accept()\r
-{\r
-    if (!ui->lineEdit->text().isEmpty()) {\r
-        m_Process.startDetached(ui->lineEdit->text());\r
-    }\r
-    QDialog::accept();\r
-}\r
diff --git a/commanddialog.h b/commanddialog.h
deleted file mode 100644 (file)
index 9fa8b61..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef COMMANDDIALOG_H\r
-#define COMMANDDIALOG_H\r
-\r
-#include <QDialog>\r
-#include <QProcess>\r
-\r
-namespace Ui {\r
-class CommandDialog;\r
-}\r
-\r
-class CommandDialog : public QDialog\r
-{\r
-    Q_OBJECT\r
-\r
-public:\r
-    explicit CommandDialog(QWidget *parent = 0);\r
-    ~CommandDialog();\r
-\r
-    void setCommandLine(const QString &cmdLine);\r
-    void setWorkingDirectory(const QString &dir);\r
-\r
-private:\r
-    Ui::CommandDialog *ui;\r
-    QProcess m_Process;\r
-\r
-private slots:\r
-    void accept();\r
-};\r
-\r
-#endif // COMMANDDIALOG_H\r
diff --git a/commanddialog.ui b/commanddialog.ui
deleted file mode 100644 (file)
index c24184f..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<ui version="4.0">\r
- <class>CommandDialog</class>\r
- <widget class="QDialog" name="CommandDialog">\r
-  <property name="windowModality">\r
-   <enum>Qt::WindowModal</enum>\r
-  </property>\r
-  <property name="geometry">\r
-   <rect>\r
-    <x>0</x>\r
-    <y>0</y>\r
-    <width>400</width>\r
-    <height>85</height>\r
-   </rect>\r
-  </property>\r
-  <property name="windowTitle">\r
-   <string>コマンドを実行</string>\r
-  </property>\r
-  <layout class="QVBoxLayout" name="verticalLayout">\r
-   <item>\r
-    <widget class="QLabel" name="label">\r
-     <property name="text">\r
-      <string>実行するコマンド:</string>\r
-     </property>\r
-    </widget>\r
-   </item>\r
-   <item>\r
-    <widget class="QLineEdit" name="lineEdit">\r
-     <property name="font">\r
-      <font>\r
-       <family>MS ゴシック</family>\r
-      </font>\r
-     </property>\r
-    </widget>\r
-   </item>\r
-   <item>\r
-    <widget class="QDialogButtonBox" name="buttonBox">\r
-     <property name="orientation">\r
-      <enum>Qt::Horizontal</enum>\r
-     </property>\r
-     <property name="standardButtons">\r
-      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>\r
-     </property>\r
-    </widget>\r
-   </item>\r
-  </layout>\r
- </widget>\r
- <resources/>\r
- <connections>\r
-  <connection>\r
-   <sender>buttonBox</sender>\r
-   <signal>accepted()</signal>\r
-   <receiver>CommandDialog</receiver>\r
-   <slot>accept()</slot>\r
-   <hints>\r
-    <hint type="sourcelabel">\r
-     <x>248</x>\r
-     <y>254</y>\r
-    </hint>\r
-    <hint type="destinationlabel">\r
-     <x>157</x>\r
-     <y>274</y>\r
-    </hint>\r
-   </hints>\r
-  </connection>\r
-  <connection>\r
-   <sender>buttonBox</sender>\r
-   <signal>rejected()</signal>\r
-   <receiver>CommandDialog</receiver>\r
-   <slot>reject()</slot>\r
-   <hints>\r
-    <hint type="sourcelabel">\r
-     <x>316</x>\r
-     <y>260</y>\r
-    </hint>\r
-    <hint type="destinationlabel">\r
-     <x>286</x>\r
-     <y>274</y>\r
-    </hint>\r
-   </hints>\r
-  </connection>\r
- </connections>\r
-</ui>\r
diff --git a/common.h b/common.h
new file mode 100644 (file)
index 0000000..891bb5f
--- /dev/null
+++ b/common.h
@@ -0,0 +1,9 @@
+#ifndef COMMON_H\r
+#define COMMON_H\r
+\r
+#include <QString>\r
+#include <QMap>\r
+\r
+typedef QMap<QString, QString> StringMap;\r
+\r
+#endif // COMMON_H\r
diff --git a/deleteworker.cpp b/deleteworker.cpp
new file mode 100644 (file)
index 0000000..f1ad34a
--- /dev/null
@@ -0,0 +1,84 @@
+#include "deleteworker.h"\r
+#include <QFileInfo>\r
+#include <QDir>\r
+#include <QDebug>\r
+\r
+DeleteWorker::DeleteWorker(QObject *parent) :\r
+    IWorker(parent),\r
+    m_DeleteList(NULL),\r
+    m_Targets()\r
+{\r
+}\r
+\r
+void DeleteWorker::operate()\r
+{\r
+    m_progressText->setText(tr("削除準備中..."));\r
+\r
+    foreach (const QString &path, *m_DeleteList) {\r
+        if (isStopRequested()) {\r
+            break;\r
+        }\r
+        Listup(path);\r
+    }\r
+\r
+    if (!isStopRequested()) {\r
+        int successCount = 0;\r
+        int errorCount = 0;\r
+        foreach (const QString &path, m_Targets) {\r
+            if (isStopRequested()) {\r
+                break;\r
+            }\r
+\r
+            emit operation(tr("削除:") + path);\r
+\r
+            QFileInfo info(path);\r
+            bool ret;\r
+            if (info.isDir()) {\r
+                QDir dir(path);\r
+                ret = dir.rmdir(path);\r
+            }\r
+            else {\r
+                ret = QFile::remove(path);\r
+            }\r
+\r
+            if (ret) {\r
+                successCount++;\r
+                emit success(tr("成功"));\r
+            }\r
+            else {\r
+                errorCount++;\r
+                emit error(tr("失敗"));\r
+            }\r
+\r
+            QString msg;\r
+            msg = tr("%1個のアイテムを削除しました。").arg(successCount);\r
+            if (errorCount > 0) {\r
+                msg += tr("%1個のアイテムを削除できませんでした。").arg(errorCount);\r
+            }\r
+            m_progressText->setText(msg);\r
+        }\r
+    }\r
+\r
+    emit finished();\r
+}\r
+\r
+void DeleteWorker::Listup(const QString &path)\r
+{\r
+    qDebug() << tr("Listup: ") << path;\r
+\r
+    if (isStopRequested()) {\r
+        return;\r
+    }\r
+\r
+    QFileInfo info(path);\r
+\r
+    if (info.isDir()) {\r
+        QDir dir(path);\r
+        foreach (QFileInfo info2, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {\r
+            qDebug() << info2.fileName();\r
+            Listup(info2.absoluteFilePath());\r
+        }\r
+    }\r
+    qDebug() << "Targeting: " << path;\r
+    m_Targets << path;\r
+}\r
diff --git a/deleteworker.h b/deleteworker.h
new file mode 100644 (file)
index 0000000..a927abc
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef DELETEWORKER_H\r
+#define DELETEWORKER_H\r
+\r
+#include "iworker.h"\r
+\r
+class DeleteWorker : public IWorker\r
+{\r
+    Q_OBJECT\r
+public:\r
+    explicit DeleteWorker(QObject *parent = 0);\r
+\r
+    void setDeleteList(const QStringList *list) {\r
+        m_DeleteList = list;\r
+    }\r
+\r
+public slots:\r
+    void operate();\r
+\r
+private:\r
+    const QStringList *m_DeleteList;\r
+    QStringList m_Targets;\r
+\r
+    void Listup(const QString &path);\r
+};\r
+\r
+#endif // DELETEWORKER_H\r
index f2075b3..281d95e 100644 (file)
@@ -13,7 +13,8 @@ FolderPanel::FolderPanel(QWidget *parent) :
     ui(new Ui::FolderPanel),\r
     m_dir(),\r
     m_IconFactory(),\r
-    m_fsWatcher(new QFileSystemWatcher(this))\r
+    m_fsWatcher(new QFileSystemWatcher(this)),\r
+    m_bUpdating(false)\r
 {\r
     ui->setupUi(this);\r
 \r
@@ -44,7 +45,7 @@ FolderPanel::FolderPanel(QWidget *parent) :
 \r
 FolderPanel::~FolderPanel()\r
 {\r
-    delete m_fsWatcher;\r
+    UninstallWatcher();\r
     delete ui;\r
 }\r
 \r
@@ -297,6 +298,7 @@ bool FolderPanel::eventFilter(QObject *obj, QEvent *event)
 \r
 void FolderPanel::setCurrentFolder(const QString &path)\r
 {\r
+    mainWindow()->setStatusText(tr("ファイルリストを更新中..."));\r
     QString curDir = m_dir.absolutePath();\r
     m_dir.setPath(QDir::cleanPath(path));\r
     m_dir.canonicalPath();\r
@@ -309,17 +311,14 @@ void FolderPanel::setCurrentFolder(const QString &path)
                     tr("フォルダが存在しないか利用できません。"));\r
         m_dir.setPath(curDir);\r
         ui->locationField->setText(curDir);\r
+        mainWindow()->setStatusText(tr("レディ"));\r
         return;\r
     }\r
 \r
     // フォルダの変更監視\r
-    delete m_fsWatcher;\r
-    m_fsWatcher = new QFileSystemWatcher(this);\r
-    m_fsWatcher->addPath(m_dir.absolutePath());\r
-    connect(m_fsWatcher, SIGNAL(directoryChanged(QString)),\r
-            this, SLOT(on_directoryChanged(QString)));\r
-\r
+    InstallWatcher();\r
 \r
+    m_bUpdating = true;\r
     ui->fileTable->model()->removeRows(0, ui->fileTable->rowCount());\r
     for (int i = 0; i < list.size(); i++) {\r
         QFileInfo info = list.at(i);\r
@@ -384,6 +383,26 @@ void FolderPanel::setCurrentFolder(const QString &path)
     ui->fileTable->resizeRowsToContents();\r
 \r
     ui->locationField->setText(m_dir.absolutePath());\r
+    mainWindow()->setStatusText(tr("レディ"));\r
+    m_bUpdating = false;\r
+}\r
+\r
+void FolderPanel::InstallWatcher()\r
+{\r
+    UninstallWatcher();\r
+\r
+    m_fsWatcher = new QFileSystemWatcher(this);\r
+    m_fsWatcher->addPath(m_dir.absolutePath());\r
+    connect(m_fsWatcher, SIGNAL(directoryChanged(QString)),\r
+            this, SLOT(on_directoryChanged(QString)));\r
+}\r
+\r
+void FolderPanel::UninstallWatcher()\r
+{\r
+    if (m_fsWatcher != NULL) {\r
+        delete m_fsWatcher;\r
+    }\r
+    m_fsWatcher = NULL;\r
 }\r
 \r
 void FolderPanel::on_fileTable_cellChanged(int row, int column)\r
@@ -424,3 +443,15 @@ void FolderPanel::on_directoryChanged(QString)
     }\r
     ui->fileTable->selectRow(row);\r
 }\r
+\r
+void FolderPanel::on_fileTable_itemSelectionChanged()\r
+{\r
+    if (m_bUpdating) {\r
+        return;\r
+    }\r
+\r
+    int row = ui->fileTable->currentRow();\r
+    if (0 <= row && row < ui->fileTable->rowCount()) {\r
+        mainWindow()->setStatusText(ui->fileTable->item(row, 1)->text());\r
+    }\r
+}\r
index 33f6086..2e0236c 100644 (file)
@@ -27,12 +27,15 @@ public:
     const QDir* dir() const { return &m_dir; }\r
 \r
     void setCurrentFolder(const QString &path);\r
+    void InstallWatcher();\r
+    void UninstallWatcher();\r
 \r
 private:\r
     Ui::FolderPanel *ui;\r
     QDir m_dir;\r
     QFileIconProvider m_IconFactory;\r
     QFileSystemWatcher *m_fsWatcher;\r
+    bool m_bUpdating;\r
 \r
     MainWindow* mainWindow();\r
     bool eventFilter(QObject *, QEvent *);\r
@@ -41,6 +44,7 @@ private slots:
     void on_fileTable_cellChanged(int row, int column);\r
     void on_locationField_editingFinished();\r
     void on_directoryChanged(QString);\r
+    void on_fileTable_itemSelectionChanged();\r
 };\r
 \r
 #endif // FOLDERPANEL_H\r
index 49fccc2..ff0ebfc 100644 (file)
@@ -6,8 +6,8 @@
    <rect>\r
     <x>0</x>\r
     <y>0</y>\r
-    <width>400</width>\r
-    <height>300</height>\r
+    <width>256</width>\r
+    <height>214</height>\r
    </rect>\r
   </property>\r
   <property name="sizePolicy">\r
diff --git a/irenamedialog.cpp b/irenamedialog.cpp
new file mode 100644 (file)
index 0000000..25248e1
--- /dev/null
@@ -0,0 +1,11 @@
+#include "irenamedialog.h"\r
+\r
+IRenameDialog::IRenameDialog(QWidget *parent) :\r
+    QDialog(parent)\r
+{\r
+}\r
+\r
+void IRenameDialog::setWorkingDirectory(const QString &path)\r
+{\r
+    m_dir.setPath(path);\r
+}\r
diff --git a/irenamedialog.h b/irenamedialog.h
new file mode 100644 (file)
index 0000000..985970d
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef IRENAMEDIALOG_H\r
+#define IRENAMEDIALOG_H\r
+\r
+#include <QDialog>\r
+#include <QDir>\r
+#include "common.h"\r
+\r
+class IRenameDialog : public QDialog\r
+{\r
+    Q_OBJECT\r
+public:\r
+    explicit IRenameDialog(QWidget *parent = 0);\r
+\r
+    const StringMap& renameMap() const { return m_RenameMap; }\r
+\r
+    void setWorkingDirectory(const QString &path);\r
+    virtual void setNames(const QStringList &names) = 0;\r
+\r
+signals:\r
+\r
+public slots:\r
+\r
+protected:\r
+    QDir m_dir;\r
+    StringMap m_RenameMap;\r
+};\r
+\r
+#endif // IRENAMEDIALOG_H\r
diff --git a/iworker.cpp b/iworker.cpp
new file mode 100644 (file)
index 0000000..0483a97
--- /dev/null
@@ -0,0 +1,9 @@
+#include "iworker.h"\r
+\r
+IWorker::IWorker(QObject *parent) :\r
+    QObject(parent),\r
+    m_progressText(NULL),\r
+    m_Mutex(),\r
+    m_stopRequested(false)\r
+{\r
+}\r
diff --git a/iworker.h b/iworker.h
new file mode 100644 (file)
index 0000000..4e96a53
--- /dev/null
+++ b/iworker.h
@@ -0,0 +1,45 @@
+#ifndef IWORKER_H\r
+#define IWORKER_H\r
+\r
+#include <QLabel>\r
+#include <QMutex>\r
+#include <QObject>\r
+\r
+class IWorker : public QObject\r
+{\r
+    Q_OBJECT\r
+public:\r
+    explicit IWorker(QObject *parent = 0);\r
+\r
+    void setProgressText(QLabel *label) {\r
+        m_progressText = label;\r
+    }\r
+\r
+    void requestStop() {\r
+        QMutexLocker lock(&m_Mutex);\r
+        m_stopRequested = true;\r
+    }\r
+\r
+protected:\r
+    QLabel *m_progressText;\r
+\r
+    bool isStopRequested() {\r
+        QMutexLocker lock(&m_Mutex);\r
+        return m_stopRequested;\r
+    }\r
+\r
+signals:\r
+    void finished();\r
+    void operation(const QString &msg);\r
+    void success(const QString &msg);\r
+    void error(const QString &msg);\r
+\r
+public slots:\r
+    virtual void operate() = 0;\r
+\r
+private:\r
+    QMutex m_Mutex;\r
+    bool m_stopRequested;\r
+};\r
+\r
+#endif // IWORKER_H\r
index 023f512..fea78ce 100644 (file)
@@ -1,7 +1,9 @@
-#include "commanddialog.h"\r
+#include "deleteworker.h"\r
 #include "mainwindow.h"\r
+#include "operationdialog.h"\r
 #include "renamemultidialog.h"\r
 #include "renamesingledialog.h"\r
+#include "renameworker.h"\r
 #include "ui_mainwindow.h"\r
 #include <QFileSystemModel>\r
 #include <QDebug>\r
@@ -11,6 +13,7 @@
 #include <QFileDialog>\r
 #include <QMessageBox>\r
 #include <QProcess>\r
+#include <QThread>\r
 #include <QInputDialog>\r
 \r
 MainWindow::MainWindow(QWidget *parent) :\r
@@ -84,6 +87,11 @@ MainWindow::~MainWindow()
     delete ui;\r
 }\r
 \r
+void MainWindow::setStatusText(const QString &str)\r
+{\r
+    ui->statusBar->showMessage(str);\r
+}\r
+\r
 FolderPanel* MainWindow::activePanel()\r
 {\r
     if (ui->folderPanel_L->fileTable()->hasFocus()) {\r
@@ -140,7 +148,8 @@ void MainWindow::onActionCommand()
     }\r
 \r
     if (command.isEmpty()) {\r
-        int row = fp->fileTable()->currentIndex().row();\r
+//        int row = fp->fileTable()->currentIndex().row();\r
+        int row = fp->fileTable()->currentRow();\r
         QString path = fp->fileTable()->item(row, 1)->text();\r
         path = fp->dir()->absoluteFilePath(path);\r
         path = QDir::cleanPath(path);\r
@@ -149,10 +158,24 @@ void MainWindow::onActionCommand()
         command = "\"" + path + "\"";\r
     }\r
 \r
-    CommandDialog dlg(this);\r
-    dlg.setWorkingDirectory(fp->dir()->absolutePath());\r
-    dlg.setCommandLine(command);\r
-    dlg.exec();\r
+    QInputDialog dlg(this);\r
+    dlg.setInputMode(QInputDialog::TextInput);\r
+    dlg.setLabelText(tr("コマンドを入力:"));\r
+    dlg.setWindowTitle(tr("コマンドを実行"));\r
+    dlg.setTextValue(command);\r
+    dlg.resize(500, 100);\r
+    int ret = dlg.exec();\r
+    command = dlg.textValue();\r
+    if (ret == QDialog::Accepted && !command.isEmpty()) {\r
+        QProcess process(this);\r
+        process.setWorkingDirectory(fp->dir()->absolutePath());\r
+        if (!process.startDetached(command)) {\r
+            QMessageBox::critical(\r
+                        this,\r
+                        tr("エラー"),\r
+                        tr("コマンドの実行に失敗しました。<br/>") + command);\r
+        }\r
+    }\r
 }\r
 \r
 ///\r
@@ -179,7 +202,8 @@ void MainWindow::onActionExec()
     }\r
 \r
     if (count == 0) {\r
-        int row = fp->fileTable()->currentIndex().row();\r
+//        int row = fp->fileTable()->currentIndex().row();\r
+        int row = fp->fileTable()->currentRow();\r
         QString path = fp->fileTable()->item(row, 1)->text();\r
         path = fp->dir()->absoluteFilePath(path);\r
         path = QDir::toNativeSeparators(path);\r
@@ -199,7 +223,8 @@ void MainWindow::onActionOpen()
         return;\r
     }\r
 \r
-    int row = fp->fileTable()->currentIndex().row();\r
+//    int row = fp->fileTable()->currentIndex().row();\r
+    int row = fp->fileTable()->currentRow();\r
     QString path = fp->fileTable()->item(row, 1)->text();\r
     path = fp->dir()->absoluteFilePath(path);\r
     QFileInfo info(path);\r
@@ -344,7 +369,8 @@ void MainWindow::onMarkToggle()
         return;\r
     }\r
 \r
-    int row = fp->fileTable()->currentIndex().row();\r
+//    int row = fp->fileTable()->currentIndex().row();\r
+    int row = fp->fileTable()->currentRow();\r
     QTableWidgetItem *item = fp->fileTable()->item(row, 0);\r
     if (fp->fileTable()->item(row, 1)->text() != "..") {\r
        if (item->checkState() == Qt::Checked) {\r
@@ -373,7 +399,8 @@ void MainWindow::onMoveCursorDown()
         return;\r
     }\r
 \r
-    int row = fp->fileTable()->currentIndex().row();\r
+//    int row = fp->fileTable()->currentIndex().row();\r
+    int row = fp->fileTable()->currentRow();\r
     if (row < fp->fileTable()->rowCount() - 1) {\r
         QModelIndex nextIndex = fp->fileTable()->model()->index(row + 1, 1);\r
         fp->fileTable()->setCurrentIndex(nextIndex);\r
@@ -392,7 +419,8 @@ void MainWindow::onMoveCursorUp()
         return;\r
     }\r
 \r
-    int row = fp->fileTable()->currentIndex().row();\r
+//    int row = fp->fileTable()->currentIndex().row();\r
+    int row = fp->fileTable()->currentRow();\r
     if (row > 0) {\r
         QModelIndex nextIndex = fp->fileTable()->model()->index(row - 1, 1);\r
         fp->fileTable()->setCurrentIndex(nextIndex);\r
@@ -579,15 +607,12 @@ void MainWindow::onViewHidden()
     if (checked) {\r
         ui->folderPanel_L->dir()->setFilter(ui->folderPanel_L->dir()->filter() | QDir::Hidden);\r
         ui->folderPanel_R->dir()->setFilter(ui->folderPanel_R->dir()->filter() | QDir::Hidden);\r
-//        ui->view_Hidden->setIcon(QIcon(":/images/Show.png"));\r
     }\r
     else {\r
         ui->folderPanel_L->dir()->setFilter(ui->folderPanel_L->dir()->filter() ^ QDir::Hidden);\r
         ui->folderPanel_R->dir()->setFilter(ui->folderPanel_R->dir()->filter() ^ QDir::Hidden);\r
-//        ui->view_Hidden->setIcon(QIcon(":/images/Hide.png"));\r
     }\r
 \r
-//    ui->view_Hidden->setIconVisibleInMenu(true);\r
     ui->folderPanel_L->setCurrentFolder(ui->folderPanel_L->dir()->absolutePath());\r
     ui->folderPanel_R->setCurrentFolder(ui->folderPanel_R->dir()->absolutePath());\r
 }\r
@@ -622,22 +647,23 @@ void MainWindow::onCmdDelete()
     QStringList list;\r
     for (int n = 0; n < fp->fileTable()->rowCount(); n++) {\r
         if (fp->fileTable()->item(n, 0)->checkState() == Qt::Checked) {\r
-            list << fp->fileTable()->item(n, 1)->text();\r
+            list << fp->dir()->absoluteFilePath(fp->fileTable()->item(n, 1)->text());\r
         }\r
     }\r
 \r
     if (list.isEmpty()) {\r
-        int row = fp->fileTable()->currentIndex().row();\r
+//        int row = fp->fileTable()->currentIndex().row();\r
+        int row = fp->fileTable()->currentRow();\r
         QString name = fp->fileTable()->item(row, 1)->text();\r
         if (name == "..") {\r
             return;\r
         }\r
-        list << name;\r
+        list << fp->dir()->absoluteFilePath(name);\r
     }\r
 \r
     QString msg;\r
     if (list.size() == 1) {\r
-        msg = list.at(0);\r
+        msg = QFileInfo(list.at(0)).fileName();\r
     }\r
     else {\r
         msg = tr("%1個のアイテム").arg(list.size());\r
@@ -647,7 +673,18 @@ void MainWindow::onCmdDelete()
                 tr("確認"),\r
                 msg + tr("を削除します<br/>よろしいですか?"));\r
     if (ret == QMessageBox::Yes) {\r
-        qDebug() << "OK";\r
+        DeleteWorker *worker = new DeleteWorker();\r
+        worker->setDeleteList(&list);\r
+\r
+        OperationDialog opDlg(this);\r
+        opDlg.setWindowTitle(tr("削除"));\r
+        opDlg.setWorker(worker);\r
+\r
+        ui->folderPanel_L->UninstallWatcher();\r
+        ui->folderPanel_R->UninstallWatcher();\r
+        opDlg.exec();\r
+        ui->folderPanel_L->setCurrentFolder(ui->folderPanel_L->dir()->absolutePath());\r
+        ui->folderPanel_R->setCurrentFolder(ui->folderPanel_R->dir()->absolutePath());\r
     }\r
 }\r
 \r
@@ -680,7 +717,6 @@ void MainWindow::onCmdNewFile()
         }\r
         else {\r
             file.close();\r
-            fp->setCurrentFolder(fp->dir()->absolutePath());\r
         }\r
     }\r
 }\r
@@ -711,9 +747,6 @@ void MainWindow::onCmdNewFolder()
                                   tr("エラー"),\r
                                   tr("フォルダの作成に失敗しました。"));\r
         }\r
-        else {\r
-            fp->setCurrentFolder(fp->dir()->absoluteFilePath(name));\r
-        }\r
     }\r
 }\r
 \r
@@ -737,7 +770,8 @@ void MainWindow::onCmdRename()
     }\r
 \r
     if (list.isEmpty()) {\r
-        int row = fp->fileTable()->currentIndex().row();\r
+//        int row = fp->fileTable()->currentIndex().row();\r
+        int row = fp->fileTable()->currentRow();\r
         QString name = fp->fileTable()->item(row, 1)->text();\r
         if (name == "..") {\r
             return;\r
@@ -745,22 +779,29 @@ void MainWindow::onCmdRename()
         list << name;\r
     }\r
 \r
-    int dlgResult;\r
+    IRenameDialog *dlg;\r
     if (list.size() == 1) {\r
-        RenameSingleDialog dlg(this);\r
-        dlg.setWorkingDirectory(fp->dir()->absolutePath());\r
-        dlg.setName(list.at(0));\r
-        dlgResult = dlg.exec();\r
+        dlg = new RenameSingleDialog(this);\r
     }\r
     else {\r
-        RenameMultiDialog dlg(this);\r
-        dlg.setWorkingDirectory(fp->dir()->absolutePath());\r
-        dlg.setNames(list);\r
-        dlgResult = dlg.exec();\r
-    }\r
-\r
-    if (dlgResult == QDialog::Accepted) {\r
-        fp->setCurrentFolder(fp->dir()->absolutePath());\r
+        dlg = new RenameMultiDialog(this);\r
+    }\r
+    dlg->setWorkingDirectory(fp->dir()->absolutePath());\r
+    dlg->setNames(list);\r
+    int dlgResult = dlg->exec();\r
+    if (dlgResult == QDialog::Accepted && !dlg->renameMap().isEmpty()) {\r
+        RenameWorker *worker = new RenameWorker();\r
+        worker->setRenameMap(&dlg->renameMap());\r
+\r
+        OperationDialog opDlg(this);\r
+        opDlg.setWindowTitle(tr("名前を変更"));\r
+        opDlg.setWorker(worker);\r
+\r
+        ui->folderPanel_L->UninstallWatcher();\r
+        ui->folderPanel_R->UninstallWatcher();\r
+        opDlg.exec();\r
+        ui->folderPanel_L->setCurrentFolder(ui->folderPanel_L->dir()->absolutePath());\r
+        ui->folderPanel_R->setCurrentFolder(ui->folderPanel_R->dir()->absolutePath());\r
     }\r
 }\r
 \r
index c1d59d4..12931ef 100644 (file)
@@ -16,6 +16,8 @@ public:
     explicit MainWindow(QWidget *parent = 0);\r
     ~MainWindow();\r
 \r
+    void setStatusText(const QString &str);\r
+\r
 public slots:\r
     void onActionCommand();\r
     void onActionExec();\r
index 00f8b71..a0fb47f 100644 (file)
@@ -6,8 +6,8 @@
    <rect>\r
     <x>0</x>\r
     <y>0</y>\r
-    <width>647</width>\r
-    <height>377</height>\r
+    <width>442</width>\r
+    <height>217</height>\r
    </rect>\r
   </property>\r
   <property name="windowTitle">\r
     <rect>\r
      <x>0</x>\r
      <y>0</y>\r
-     <width>647</width>\r
+     <width>442</width>\r
      <height>24</height>\r
     </rect>\r
    </property>\r
diff --git a/operationdialog.cpp b/operationdialog.cpp
new file mode 100644 (file)
index 0000000..5cc4287
--- /dev/null
@@ -0,0 +1,96 @@
+#include "operationdialog.h"\r
+#include "ui_operationdialog.h"\r
+#include <QThread>\r
+\r
+OperationDialog::OperationDialog(QWidget *parent) :\r
+    QDialog(parent),\r
+    ui(new Ui::OperationDialog),\r
+    m_worker(NULL),\r
+    m_Error(false),\r
+    m_Cancel(false)\r
+{\r
+    ui->setupUi(this);\r
+}\r
+\r
+OperationDialog::~OperationDialog()\r
+{\r
+    delete ui;\r
+}\r
+\r
+void OperationDialog::showEvent(QShowEvent *event)\r
+{\r
+    ui->textEdit->setVisible(false);\r
+\r
+    QThread *thread = new QThread();\r
+    m_worker->moveToThread(thread);\r
+    m_worker->setProgressText(ui->label);\r
+    connect(thread, SIGNAL(started()), m_worker, SLOT(operate()));\r
+    connect(m_worker, SIGNAL(finished()), thread, SLOT(quit()));\r
+\r
+    connect(thread, SIGNAL(finished()), this, SLOT(onFinished()));\r
+    connect(thread, SIGNAL(finished()), m_worker, SLOT(deleteLater()));\r
+    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));\r
+\r
+    connect(m_worker, SIGNAL(operation(QString)), this, SLOT(onOperation(QString)));\r
+    connect(m_worker, SIGNAL(success(QString)), this, SLOT(onSuccess(QString)));\r
+    connect(m_worker, SIGNAL(error(QString)), this, SLOT(onError(QString)));\r
+\r
+    thread->start();\r
+}\r
+\r
+void OperationDialog::onOperation(const QString &msg)\r
+{\r
+    ui->textEdit->append(msg + " ... ");\r
+}\r
+\r
+void OperationDialog::onSuccess(const QString &msg)\r
+{\r
+    ui->textEdit->append("<font color='green'>" + msg + "</font>");\r
+}\r
+\r
+void OperationDialog::onError(const QString &msg)\r
+{\r
+    m_Error = true;\r
+    ui->textEdit->append("<font color='red'><strong>" + msg + "</strong></font>");\r
+}\r
+\r
+void OperationDialog::onFinished()\r
+{\r
+    ui->progressBar->setMaximum(1);\r
+    ui->progressBar->setValue(1);\r
+    ui->btnCloseCancel->setText(tr("閉じる"));\r
+\r
+    ui->textEdit->append("");\r
+    if (m_Cancel) {\r
+        ui->textEdit->append(tr("操作は途中でキャンセルされました。"));\r
+    }\r
+    else {\r
+        ui->textEdit->append(tr("完了"));\r
+        if (!m_Error && ui->chkAutoClose->checkState() == Qt::Checked) {\r
+            QDialog::accept();\r
+        }\r
+    }\r
+}\r
+\r
+void OperationDialog::on_btnCloseCancel_clicked()\r
+{\r
+    if (ui->btnCloseCancel->text() == tr("閉じる")) {\r
+        QDialog::accept();\r
+    }\r
+    else {\r
+        m_Cancel = true;\r
+        m_worker->requestStop();\r
+    }\r
+}\r
+\r
+void OperationDialog::on_btnShowDetail_clicked()\r
+{\r
+    if (ui->textEdit->isVisible()) {\r
+        ui->textEdit->setVisible(false);\r
+        ui->btnShowDetail->setText(tr("詳細を表示"));\r
+    }\r
+    else {\r
+        ui->textEdit->setVisible(true);\r
+        ui->btnShowDetail->setText(tr("詳細を隠す"));\r
+    }\r
+}\r
diff --git a/operationdialog.h b/operationdialog.h
new file mode 100644 (file)
index 0000000..6227e4a
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef OPERATIONDIALOG_H\r
+#define OPERATIONDIALOG_H\r
+\r
+#include "iworker.h"\r
+#include <QDialog>\r
+\r
+namespace Ui {\r
+class OperationDialog;\r
+}\r
+\r
+class OperationDialog : public QDialog\r
+{\r
+    Q_OBJECT\r
+\r
+public:\r
+    explicit OperationDialog(QWidget *parent = 0);\r
+    ~OperationDialog();\r
+\r
+    void setWorker(IWorker *worker) {\r
+        m_worker = worker;\r
+    }\r
+\r
+protected:\r
+    void showEvent(QShowEvent *event);\r
+\r
+private:\r
+    Ui::OperationDialog *ui;\r
+    IWorker *m_worker;\r
+    bool m_Error;\r
+    bool m_Cancel;\r
+\r
+private slots:\r
+    void onOperation(const QString &msg);\r
+    void onSuccess(const QString &msg);\r
+    void onError(const QString &msg);\r
+    void onFinished();\r
+    void on_btnCloseCancel_clicked();\r
+    void on_btnShowDetail_clicked();\r
+};\r
+\r
+#endif // OPERATIONDIALOG_H\r
diff --git a/operationdialog.ui b/operationdialog.ui
new file mode 100644 (file)
index 0000000..f22c380
--- /dev/null
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ui version="4.0">\r
+ <class>OperationDialog</class>\r
+ <widget class="QDialog" name="OperationDialog">\r
+  <property name="geometry">\r
+   <rect>\r
+    <x>0</x>\r
+    <y>0</y>\r
+    <width>400</width>\r
+    <height>300</height>\r
+   </rect>\r
+  </property>\r
+  <property name="windowTitle">\r
+   <string>Dialog</string>\r
+  </property>\r
+  <layout class="QGridLayout" name="gridLayout">\r
+   <property name="sizeConstraint">\r
+    <enum>QLayout::SetMinAndMaxSize</enum>\r
+   </property>\r
+   <item row="1" column="0">\r
+    <widget class="QTextEdit" name="textEdit">\r
+     <property name="enabled">\r
+      <bool>true</bool>\r
+     </property>\r
+     <property name="sizePolicy">\r
+      <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">\r
+       <horstretch>0</horstretch>\r
+       <verstretch>0</verstretch>\r
+      </sizepolicy>\r
+     </property>\r
+     <property name="minimumSize">\r
+      <size>\r
+       <width>170</width>\r
+       <height>0</height>\r
+      </size>\r
+     </property>\r
+     <property name="undoRedoEnabled">\r
+      <bool>false</bool>\r
+     </property>\r
+     <property name="lineWrapMode">\r
+      <enum>QTextEdit::NoWrap</enum>\r
+     </property>\r
+     <property name="readOnly">\r
+      <bool>true</bool>\r
+     </property>\r
+    </widget>\r
+   </item>\r
+   <item row="2" column="0">\r
+    <layout class="QHBoxLayout" name="horizontalLayout">\r
+     <item>\r
+      <widget class="QCheckBox" name="chkAutoClose">\r
+       <property name="text">\r
+        <string>成功時、自動的に閉じる</string>\r
+       </property>\r
+      </widget>\r
+     </item>\r
+     <item>\r
+      <spacer name="horizontalSpacer">\r
+       <property name="orientation">\r
+        <enum>Qt::Horizontal</enum>\r
+       </property>\r
+       <property name="sizeHint" stdset="0">\r
+        <size>\r
+         <width>40</width>\r
+         <height>20</height>\r
+        </size>\r
+       </property>\r
+      </spacer>\r
+     </item>\r
+     <item>\r
+      <widget class="QPushButton" name="btnCloseCancel">\r
+       <property name="text">\r
+        <string>キャンセル</string>\r
+       </property>\r
+      </widget>\r
+     </item>\r
+    </layout>\r
+   </item>\r
+   <item row="0" column="0">\r
+    <layout class="QVBoxLayout" name="verticalLayout">\r
+     <property name="sizeConstraint">\r
+      <enum>QLayout::SetNoConstraint</enum>\r
+     </property>\r
+     <item>\r
+      <widget class="QLabel" name="label">\r
+       <property name="sizePolicy">\r
+        <sizepolicy hsizetype="Preferred" vsizetype="Fixed">\r
+         <horstretch>0</horstretch>\r
+         <verstretch>0</verstretch>\r
+        </sizepolicy>\r
+       </property>\r
+       <property name="text">\r
+        <string>TextLabel</string>\r
+       </property>\r
+       <property name="scaledContents">\r
+        <bool>true</bool>\r
+       </property>\r
+      </widget>\r
+     </item>\r
+     <item>\r
+      <widget class="QProgressBar" name="progressBar">\r
+       <property name="sizePolicy">\r
+        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">\r
+         <horstretch>0</horstretch>\r
+         <verstretch>0</verstretch>\r
+        </sizepolicy>\r
+       </property>\r
+       <property name="maximum">\r
+        <number>0</number>\r
+       </property>\r
+       <property name="value">\r
+        <number>0</number>\r
+       </property>\r
+       <property name="textVisible">\r
+        <bool>false</bool>\r
+       </property>\r
+      </widget>\r
+     </item>\r
+     <item>\r
+      <widget class="QPushButton" name="btnShowDetail">\r
+       <property name="sizePolicy">\r
+        <sizepolicy hsizetype="Maximum" vsizetype="Fixed">\r
+         <horstretch>0</horstretch>\r
+         <verstretch>0</verstretch>\r
+        </sizepolicy>\r
+       </property>\r
+       <property name="text">\r
+        <string>詳細を表示</string>\r
+       </property>\r
+      </widget>\r
+     </item>\r
+    </layout>\r
+   </item>\r
+  </layout>\r
+ </widget>\r
+ <resources/>\r
+ <connections/>\r
+</ui>\r
index 3c9f212..14b0550 100644 (file)
@@ -1,13 +1,11 @@
 #include "renamemultidialog.h"\r
 #include "ui_renamemultidialog.h"\r
-\r
 #include <QFileIconProvider>\r
 #include <QMessageBox>\r
 \r
 RenameMultiDialog::RenameMultiDialog(QWidget *parent) :\r
-    QDialog(parent),\r
-    ui(new Ui::RenameMultiDialog),\r
-    m_dir()\r
+    IRenameDialog(parent),\r
+    ui(new Ui::RenameMultiDialog)\r
 {\r
     ui->setupUi(this);\r
 \r
@@ -15,6 +13,8 @@ RenameMultiDialog::RenameMultiDialog(QWidget *parent) :
     QStringList labels;\r
     labels << tr("変更前") << tr("変更後");\r
     ui->tableWidget->setHorizontalHeaderLabels(labels);\r
+\r
+    ui->tableWidget->horizontalHeader()->setStretchLastSection(true);\r
 }\r
 \r
 RenameMultiDialog::~RenameMultiDialog()\r
@@ -41,11 +41,6 @@ void RenameMultiDialog::setNames(const QStringList &names)
     ui->tableWidget->resizeRowsToContents();\r
 }\r
 \r
-void RenameMultiDialog::setWorkingDirectory(const QString &dir)\r
-{\r
-    m_dir.setPath(dir);\r
-}\r
-\r
 void RenameMultiDialog::on_btn_UpperAll_clicked()\r
 {\r
     for (int n = 0; n < ui->tableWidget->rowCount(); n++) {\r
@@ -164,18 +159,11 @@ void RenameMultiDialog::accept()
         QTableWidgetItem *iBefore = ui->tableWidget->item(n, 0);\r
         QTableWidgetItem *iAfter = ui->tableWidget->item(n, 1);\r
         if (iBefore->text() != iAfter->text()) {\r
-            bool ret = QFile::rename(\r
-                        m_dir.absoluteFilePath(iBefore->text()),\r
-                        m_dir.absoluteFilePath(iAfter->text()));\r
-            if (!ret) {\r
-                QMessageBox::critical(\r
-                            this,\r
-                            tr("エラー"),\r
-                            iBefore->text() + tr("のファイル名変更に失敗しました。"));\r
-            }\r
+            m_RenameMap.insert(m_dir.absoluteFilePath(iBefore->text()),\r
+                               m_dir.absoluteFilePath(iAfter->text()));\r
         }\r
     }\r
 \r
-    QDialog::accept();\r
+    IRenameDialog::accept();\r
 }\r
 \r
index b7bacc5..a3e06ee 100644 (file)
@@ -2,14 +2,13 @@
 #define RENAMEMULTIDIALOG_H\r
 \r
 #include <QAbstractButton>\r
-#include <QDialog>\r
-#include <QDir>\r
+#include "irenamedialog.h"\r
 \r
 namespace Ui {\r
 class RenameMultiDialog;\r
 }\r
 \r
-class RenameMultiDialog : public QDialog\r
+class RenameMultiDialog : public IRenameDialog\r
 {\r
     Q_OBJECT\r
 \r
@@ -18,7 +17,6 @@ public:
     ~RenameMultiDialog();\r
 \r
     void setNames(const QStringList &names);\r
-    void setWorkingDirectory(const QString &dir);\r
 \r
 private slots:\r
     void on_btn_UpperAll_clicked();\r
@@ -32,7 +30,6 @@ private slots:
 \r
 private:\r
     Ui::RenameMultiDialog *ui;\r
-    QDir m_dir;\r
 };\r
 \r
 #endif // RENAMEMULTIDIALOG_H\r
index e148dc3..cbf086a 100644 (file)
@@ -6,8 +6,8 @@
    <rect>\r
     <x>0</x>\r
     <y>0</y>\r
-    <width>417</width>\r
-    <height>475</height>\r
+    <width>412</width>\r
+    <height>539</height>\r
    </rect>\r
   </property>\r
   <property name="windowTitle">\r
        <family>MS ゴシック</family>\r
       </font>\r
      </property>\r
+     <property name="focusPolicy">\r
+      <enum>Qt::WheelFocus</enum>\r
+     </property>\r
+     <property name="tabKeyNavigation">\r
+      <bool>false</bool>\r
+     </property>\r
      <property name="showGrid">\r
       <bool>false</bool>\r
      </property>\r
index 0a57d3a..1cf85a6 100644 (file)
@@ -1,12 +1,10 @@
 #include "renamesingledialog.h"\r
 #include "ui_renamesingledialog.h"\r
-\r
 #include <QMessageBox>\r
 \r
 RenameSingleDialog::RenameSingleDialog(QWidget *parent) :\r
-    QDialog(parent),\r
-    ui(new Ui::RenameSingleDialog),\r
-    m_dir()\r
+    IRenameDialog(parent),\r
+    ui(new Ui::RenameSingleDialog)\r
 {\r
     ui->setupUi(this);\r
 \r
@@ -18,15 +16,10 @@ RenameSingleDialog::~RenameSingleDialog()
     delete ui;\r
 }\r
 \r
-void RenameSingleDialog::setName(const QString &name)\r
-{\r
-    ui->nameBefore->setText(name);\r
-    ui->nameAfter->setText(name);\r
-}\r
-\r
-void RenameSingleDialog::setWorkingDirectory(const QString &dir)\r
+void RenameSingleDialog::setNames(const QStringList &names)\r
 {\r
-    m_dir.setPath(dir);\r
+    ui->nameBefore->setText(names.at(0));\r
+    ui->nameAfter->setText(names.at(0));\r
 }\r
 \r
 void RenameSingleDialog::on_btn_UpperAll_clicked()\r
@@ -54,17 +47,9 @@ void RenameSingleDialog::on_btn_LowerExt_clicked()
 void RenameSingleDialog::accept()\r
 {\r
     if (ui->nameAfter->text() != ui->nameBefore->text()) {\r
-        bool ret = QFile::rename(\r
-                    m_dir.absoluteFilePath(ui->nameBefore->text()),\r
-                    m_dir.absoluteFilePath(ui->nameAfter->text()));\r
-        if (!ret) {\r
-            QMessageBox::critical(\r
-                        this,\r
-                        tr("エラー"),\r
-                        tr("ファイル名の変更に失敗しました。"));\r
-            return;\r
-        }\r
+        m_RenameMap.insert(m_dir.absoluteFilePath(ui->nameBefore->text()),\r
+                           m_dir.absoluteFilePath(ui->nameAfter->text()));\r
     }\r
 \r
-    QDialog::accept();\r
+    IRenameDialog::accept();\r
 }\r
index a5bc234..98addef 100644 (file)
@@ -1,14 +1,13 @@
 #ifndef RENAMESINGLEDIALOG_H\r
 #define RENAMESINGLEDIALOG_H\r
 \r
-#include <QDialog>\r
-#include <QDir>\r
+#include "irenamedialog.h"\r
 \r
 namespace Ui {\r
 class RenameSingleDialog;\r
 }\r
 \r
-class RenameSingleDialog : public QDialog\r
+class RenameSingleDialog : public IRenameDialog\r
 {\r
     Q_OBJECT\r
 \r
@@ -16,8 +15,7 @@ public:
     explicit RenameSingleDialog(QWidget *parent = 0);\r
     ~RenameSingleDialog();\r
 \r
-    void setName(const QString &name);\r
-    void setWorkingDirectory(const QString &dir);\r
+    void setNames(const QStringList &names);\r
 \r
 private slots:\r
     void on_btn_UpperAll_clicked();\r
@@ -28,7 +26,6 @@ private slots:
 \r
 private:\r
     Ui::RenameSingleDialog *ui;\r
-    QDir m_dir;\r
 };\r
 \r
 #endif // RENAMESINGLEDIALOG_H\r
index ff4604b..7ebb056 100644 (file)
@@ -9,8 +9,8 @@
    <rect>\r
     <x>0</x>\r
     <y>0</y>\r
-    <width>400</width>\r
-    <height>195</height>\r
+    <width>261</width>\r
+    <height>193</height>\r
    </rect>\r
   </property>\r
   <property name="sizePolicy">\r
diff --git a/renameworker.cpp b/renameworker.cpp
new file mode 100644 (file)
index 0000000..4f76bcc
--- /dev/null
@@ -0,0 +1,46 @@
+#include "renameworker.h"\r
+#include <QFile>\r
+#include <QFileInfo>\r
+\r
+RenameWorker::RenameWorker(QObject *parent) :\r
+    IWorker(parent),\r
+    m_RenameMap(NULL)\r
+{\r
+}\r
+\r
+void RenameWorker::operate()\r
+{\r
+    m_progressText->setText(tr("名前を変更しています..."));\r
+    StringMap::const_iterator it;\r
+    bool ret;\r
+    int successCount = 0;\r
+    int errorCount = 0;\r
+    for (it = m_RenameMap->begin(); it != m_RenameMap->end(); it++) {\r
+        if (isStopRequested()) {\r
+            break;\r
+        }\r
+\r
+        emit operation(tr("名前変更:")\r
+                     + QFileInfo(it.key()).fileName()\r
+                     + tr(" -> ")\r
+                     + QFileInfo(it.value()).fileName());\r
+        ret = QFile::rename(it.key(), it.value());\r
+        if (ret) {\r
+            successCount++;\r
+            emit success(tr("成功"));\r
+        }\r
+        else {\r
+            errorCount++;\r
+            emit error(tr("失敗"));\r
+        }\r
+    }\r
+\r
+    QString msg;\r
+    msg = tr("%1個の名前を変更しました。").arg(successCount);\r
+    if (errorCount > 0) {\r
+        msg += tr("%1個の名前を変更できませんでした。").arg(errorCount);\r
+    }\r
+    m_progressText->setText(msg);\r
+\r
+    emit finished();\r
+}\r
diff --git a/renameworker.h b/renameworker.h
new file mode 100644 (file)
index 0000000..d7f72f4
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef RENAMEWORKER_H\r
+#define RENAMEWORKER_H\r
+\r
+#include "common.h"\r
+#include "iworker.h"\r
+\r
+class RenameWorker : public IWorker\r
+{\r
+    Q_OBJECT\r
+public:\r
+    explicit RenameWorker(QObject *parent = 0);\r
+\r
+    void setRenameMap(const StringMap *map) {\r
+        m_RenameMap = map;\r
+    }\r
+\r
+public slots:\r
+    void operate();\r
+\r
+private:\r
+    const StringMap *m_RenameMap;\r
+};\r
+\r
+#endif // RENAMEWORKER_H\r