+++ /dev/null
-#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
+++ /dev/null
-#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
+++ /dev/null
-<?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
--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+#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
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
\r
FolderPanel::~FolderPanel()\r
{\r
- delete m_fsWatcher;\r
+ UninstallWatcher();\r
delete ui;\r
}\r
\r
\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
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
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
}\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
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
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
<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
--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+#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
-#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
#include <QFileDialog>\r
#include <QMessageBox>\r
#include <QProcess>\r
+#include <QThread>\r
#include <QInputDialog>\r
\r
MainWindow::MainWindow(QWidget *parent) :\r
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
}\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
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
}\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
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
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
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
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
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
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
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
}\r
else {\r
file.close();\r
- fp->setCurrentFolder(fp->dir()->absolutePath());\r
}\r
}\r
}\r
tr("エラー"),\r
tr("フォルダの作成に失敗しました。"));\r
}\r
- else {\r
- fp->setCurrentFolder(fp->dir()->absoluteFilePath(name));\r
- }\r
}\r
}\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
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
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
<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
--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+<?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
#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
QStringList labels;\r
labels << tr("変更前") << tr("変更後");\r
ui->tableWidget->setHorizontalHeaderLabels(labels);\r
+\r
+ ui->tableWidget->horizontalHeader()->setStretchLastSection(true);\r
}\r
\r
RenameMultiDialog::~RenameMultiDialog()\r
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
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
#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
~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
\r
private:\r
Ui::RenameMultiDialog *ui;\r
- QDir m_dir;\r
};\r
\r
#endif // RENAMEMULTIDIALOG_H\r
<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
#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
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
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
#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
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
\r
private:\r
Ui::RenameSingleDialog *ui;\r
- QDir m_dir;\r
};\r
\r
#endif // RENAMESINGLEDIALOG_H\r
<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
--- /dev/null
+#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
--- /dev/null
+#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