From: Masayuki Satoh Date: Sun, 17 Aug 2014 20:01:42 +0000 (+0900) Subject: アイコン変更、キーイベント修正、コピー処理実装。 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b98d8dc4b63f580eaf69e4c5f4a8f09dc1aaabe2;p=gefu%2FGefu.git アイコン変更、キーイベント修正、コピー処理実装。 --- diff --git a/Gefu.pro b/Gefu.pro index 60b4b2a..36fca69 100644 --- a/Gefu.pro +++ b/Gefu.pro @@ -21,7 +21,9 @@ SOURCES += main.cpp\ irenamedialog.cpp \ iworker.cpp \ renameworker.cpp \ - deleteworker.cpp + deleteworker.cpp \ + copyworker.cpp \ + overwritedialog.cpp HEADERS += mainwindow.h \ folderpanel.h \ @@ -33,13 +35,16 @@ HEADERS += mainwindow.h \ irenamedialog.h \ iworker.h \ renameworker.h \ - deleteworker.h + deleteworker.h \ + copyworker.h \ + overwritedialog.h FORMS += mainwindow.ui \ folderpanel.ui \ renamesingledialog.ui \ renamemultidialog.ui \ - operationdialog.ui + operationdialog.ui \ + overwritedialog.ui RESOURCES += \ resource.qrc diff --git a/copyworker.cpp b/copyworker.cpp new file mode 100644 index 0000000..618bf18 --- /dev/null +++ b/copyworker.cpp @@ -0,0 +1,172 @@ +#include "copyworker.h" +#include "overwritedialog.h" +#include +#include +#include +#include +#include + +CopyWorker::CopyWorker(QObject *parent) : + IWorker(parent), + m_CopyList(NULL), + m_tgtDir(), + m_CopyMap(), + m_AskingMutex(), + m_Asking(false) +{ +} + +void CopyWorker::operate() +{ + m_progressText->setText(tr("コピー準備中...")); + + foreach (const QString &srcPath, *m_CopyList) { + if (isStopRequested()) { + emit canceled(); + return; + } + Listup(srcPath, m_tgtDir); + } + + bool ret; + int copyMethod = OverWriteDialog::Undefined; + int prevCopyMethod = OverWriteDialog::Undefined; + int successCount = 0; + int skipCount = 0; + int errorCount = 0; + QString msg; + QString alias; + StringMap::iterator it; + for (it = m_CopyMap.begin(); it != m_CopyMap.end(); it++) { + if (isStopRequested()) { + emit canceled(); + return; + } + QFileInfo srcInfo(it.key()); + QFileInfo tgtInfo(it.value()); + + emit operation(tr("コピー:") + + srcInfo.absoluteFilePath() + + tr(" -> ") + + tgtInfo.absoluteFilePath()); + + if (srcInfo.isDir()) { + if (tgtInfo.exists()) { + emit success(tr("すでに存在")); + } + else if (QDir().mkdir(it.value())) { + emit success("フォルダ作成"); + } + else { + emit error("フォルダの作成に失敗"); + } + continue; + } + + do { // コピーをスキップするのにbreakを使うがためのdo-while + if (tgtInfo.exists()) { + // 解決方法を選択 + if (copyMethod == OverWriteDialog::Undefined || + copyMethod == OverWriteDialog::Rename) + { + bool bOk; + m_Asking = true; + emit askOverWrite(&bOk, &prevCopyMethod, ©Method, &alias, + srcInfo.absoluteFilePath(), + tgtInfo.absoluteFilePath()); + while (isAsking()) { + this->thread()->msleep(100); + } + + if (!bOk) { + requestStop(); + msg = tr("%1個のファイルをコピーしました。").arg(successCount); + if (skipCount > 0) { + msg += tr("%1個のファイルをスキップしました。").arg(skipCount); + } + if (errorCount > 0) { + msg += tr("%1個のファイルをコピーできませんでした。").arg(errorCount); + } + m_progressText->setText(msg); + emit canceled(); + return; + } + } + + if (prevCopyMethod == OverWriteDialog::OverWrite) { + QFile(tgtInfo.absoluteFilePath()).remove(); + } + else if (prevCopyMethod == OverWriteDialog::OverWriteIfNew) { + if (srcInfo.lastModified() <= tgtInfo.lastModified()) { + emit success(tr("スキップ")); + skipCount++; + break; + } + QFile(tgtInfo.absoluteFilePath()).remove(); + } + else if (prevCopyMethod == OverWriteDialog::AppendNumber) { + QString baseName = tgtInfo.baseName(); + QString suffix = tgtInfo.completeSuffix(); + for (int n = 1; ; n++) { + QString newName = baseName + tr("%1.").arg(n) + suffix; + tgtInfo.setFile(tgtInfo.absolutePath(), newName); + if (!tgtInfo.exists()) { + break; + } + } + emit operation(tr("=>") + tgtInfo.fileName() + tr("にリネーム")); + } + else if (prevCopyMethod == OverWriteDialog::Skip) { + emit success(tr("スキップ")); + skipCount++; + break; + } + else if (prevCopyMethod == OverWriteDialog::Rename) { + tgtInfo.setFile(tgtInfo.absolutePath(), alias); + emit operation(tr("=>") + tgtInfo.fileName() + tr("にリネーム")); + } + } + + ret = QFile::copy(srcInfo.absoluteFilePath(), tgtInfo.absoluteFilePath()); + if (ret) { + successCount++; + emit success(tr("成功")); + } + else { + errorCount++; + emit error(tr("失敗")); + } + } while (0); + + msg = tr("%1個のファイルをコピーしました。").arg(successCount); + if (skipCount > 0) { + msg += tr("%1個のファイルをスキップしました。").arg(skipCount); + } + if (errorCount > 0) { + msg += tr("%1個のファイルをコピーできませんでした。").arg(errorCount); + } + m_progressText->setText(msg); + } + + emit finished(); +} + +void CopyWorker::Listup(const QString &srcPath, const QString &tgtPath) +{ + if (isStopRequested()) { + return; + } + + QFileInfo info(srcPath); + QDir tgtDir(tgtPath); + + m_CopyMap.insert(srcPath, tgtDir.absoluteFilePath(info.fileName())); +// qDebug() << srcPath << " -> " << tgtDir.absoluteFilePath(info.fileName()); + if (info.isDir()) { + QDir srcDir(srcPath); + foreach (QFileInfo info2, srcDir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) { + Listup(info2.absoluteFilePath(), + tgtDir.absoluteFilePath(info.fileName())); + } + } +} diff --git a/copyworker.h b/copyworker.h new file mode 100644 index 0000000..d9b848d --- /dev/null +++ b/copyworker.h @@ -0,0 +1,49 @@ +#ifndef COPYWORKER_H +#define COPYWORKER_H + +#include "common.h" +#include "iworker.h" + +#include + +class CopyWorker : public IWorker +{ + Q_OBJECT +public: + explicit CopyWorker(QObject *parent = 0); + + void setCopyList(const QStringList *list) { + m_CopyList = list; + } + void setTargetDir(const QString &path) { + m_tgtDir = path; + } + + void endAsking() { + QMutexLocker lock(&m_AskingMutex); + m_Asking = false; + } + +public slots: + void operate(); + +signals: + void askOverWrite(bool *bOk, int *prevCopyMethod, int *copyMethod, QString *alias, + const QString srcPath, const QString tgtPath); + +private: + const QStringList *m_CopyList; + QString m_tgtDir; + StringMap m_CopyMap; + QMutex m_AskingMutex; + bool m_Asking; + + bool isAsking() { + QMutexLocker lock(&m_AskingMutex); + return m_Asking; + } + + void Listup(const QString &srcPath, const QString &tgtPath); +}; + +#endif // COPYWORKER_H diff --git a/deleteworker.cpp b/deleteworker.cpp index f1ad34a..25282ba 100644 --- a/deleteworker.cpp +++ b/deleteworker.cpp @@ -16,47 +16,47 @@ void DeleteWorker::operate() foreach (const QString &path, *m_DeleteList) { if (isStopRequested()) { - break; + emit canceled(); + return; } Listup(path); } - if (!isStopRequested()) { - int successCount = 0; - int errorCount = 0; - foreach (const QString &path, m_Targets) { - if (isStopRequested()) { - break; - } + bool ret; + int successCount = 0; + int errorCount = 0; + QString msg; + foreach (const QString &path, m_Targets) { + if (isStopRequested()) { + emit canceled(); + return; + } - emit operation(tr("削除:") + path); + emit operation(tr("削除:") + path); - QFileInfo info(path); - bool ret; - if (info.isDir()) { - QDir dir(path); - ret = dir.rmdir(path); - } - else { - ret = QFile::remove(path); - } + QFileInfo info(path); + if (info.isDir()) { + QDir dir(path); + ret = dir.rmdir(path); + } + else { + ret = QFile::remove(path); + } - if (ret) { - successCount++; - emit success(tr("成功")); - } - else { - errorCount++; - emit error(tr("失敗")); - } + if (ret) { + successCount++; + emit success(tr("成功")); + } + else { + errorCount++; + emit error(tr("失敗")); + } - QString msg; - msg = tr("%1個のアイテムを削除しました。").arg(successCount); - if (errorCount > 0) { - msg += tr("%1個のアイテムを削除できませんでした。").arg(errorCount); - } - m_progressText->setText(msg); + msg = tr("%1個のアイテムを削除しました。").arg(successCount); + if (errorCount > 0) { + msg += tr("%1個のアイテムを削除できませんでした。").arg(errorCount); } + m_progressText->setText(msg); } emit finished(); @@ -64,7 +64,7 @@ void DeleteWorker::operate() void DeleteWorker::Listup(const QString &path) { - qDebug() << tr("Listup: ") << path; +// qDebug() << tr("Listup: ") << path; if (isStopRequested()) { return; @@ -75,10 +75,10 @@ void DeleteWorker::Listup(const QString &path) if (info.isDir()) { QDir dir(path); foreach (QFileInfo info2, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) { - qDebug() << info2.fileName(); +// qDebug() << info2.fileName(); Listup(info2.absoluteFilePath()); } } - qDebug() << "Targeting: " << path; +// qDebug() << "Targeting: " << path; m_Targets << path; } diff --git a/folderpanel.cpp b/folderpanel.cpp index 29087f2..60c0825 100644 --- a/folderpanel.cpp +++ b/folderpanel.cpp @@ -71,240 +71,359 @@ MainWindow* FolderPanel::mainWindow() bool FolderPanel::eventFilter(QObject *obj, QEvent *event) { - if (event->type() == QEvent::KeyPress) { + if (this->mainWindow() && event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(event); switch (keyEvent->key()) { - case Qt::Key_A: { + case Qt::Key_A: // A すべてのファイルをマーク // Shift + A すべてマーク - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ShiftModifier) { - mainWnd->onMarkAll(); - } - else { - mainWnd->onMarkAllFiles(); - } - } - keyEvent->accept(); - return true; } - - case Qt::Key_D: { + if (keyEvent->modifiers() & Qt::ShiftModifier) { + this->mainWindow()->onMarkAll(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onMarkAllFiles(); + keyEvent->accept(); + return true; + } + break; + + case Qt::Key_C: + // Ctrl + C ファイルをコピー + if (keyEvent->modifiers() & Qt::ShiftModifier) { + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + this->mainWindow()->onCmdCopy(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + } + break; + + case Qt::Key_D: // Ctrl + D ファイルを削除 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ControlModifier) { - mainWnd->onCmdDelete(); - } + if (keyEvent->modifiers() & Qt::ShiftModifier) { + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + this->mainWindow()->onCmdDelete(); + keyEvent->accept(); + return true; } - keyEvent->accept(); - return true; } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + } + break; - case Qt::Key_E: { + case Qt::Key_E: // E エディタで開く // Ctrl + E ファイルを作成 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ControlModifier) { - mainWnd->onCmdNewFile(); - } - else { - } - } - keyEvent->accept(); - return true; } - - case Qt::Key_G: { + if (keyEvent->modifiers() & Qt::ShiftModifier) { + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + this->mainWindow()->onCmdNewFile(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + } + break; + + case Qt::Key_G: // G カーソルを先頭に移動 // Shift + G カーソルを末尾に移動 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ShiftModifier) { - mainWnd->onMoveCursorEnd(); - } - else { - mainWnd->onMoveCursorBegin(); - } - } - keyEvent->accept(); - return true; } - - case Qt::Key_H: { + if (keyEvent->modifiers() & Qt::ShiftModifier) { + this->mainWindow()->onMoveCursorEnd(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onMoveCursorBegin(); + keyEvent->accept(); + return true; + } + break; + + case Qt::Key_H: // H ホームフォルダに移動 // Shift + H 隠しファイルを表示/非表示 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ShiftModifier) { - mainWnd->onViewHidden(); - } - else { - mainWnd->onMoveHome(); - } - } - keyEvent->accept(); - return true; } - - case Qt::Key_I: { + if (keyEvent->modifiers() & Qt::ShiftModifier) { + this->mainWindow()->onViewHidden(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onMoveHome(); + keyEvent->accept(); + return true; + } + break; + + case Qt::Key_I: // I マークを反転 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - mainWnd->onMarkInvert(); + if (keyEvent->modifiers() & Qt::ShiftModifier) { + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { } - keyEvent->accept(); - return true; } + else { + this->mainWindow()->onMarkInvert(); + keyEvent->accept(); + return true; + } + break; - case Qt::Key_J: { + case Qt::Key_J: // J カーソルを下に移動 // Shift + J フォルダを選択して移動 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ShiftModifier) { - mainWnd->onMoveJump(); - } - else { - mainWnd->onMoveCursorDown(); - } - } - keyEvent->accept(); - return true; } - - case Qt::Key_K: { + if (keyEvent->modifiers() & Qt::ShiftModifier) { + this->mainWindow()->onMoveJump(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onMoveCursorDown(); + keyEvent->accept(); + return true; + } + break; + + case Qt::Key_K: // K カーソルを上に移動 // Ctrl + K フォルダを作成 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ControlModifier) { - mainWnd->onCmdNewFolder(); - } - else { - mainWnd->onMoveCursorUp(); - } - } - keyEvent->accept(); - return true; } - - case Qt::Key_O: { + if (keyEvent->modifiers() & Qt::ShiftModifier) { + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + this->mainWindow()->onCmdNewFolder(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onMoveCursorUp(); + keyEvent->accept(); + return true; + } + break; + + case Qt::Key_M: + // M 開く + // Shift + M アプリケーションで開く + if (keyEvent->modifiers() & Qt::ShiftModifier) { + this->mainWindow()->onActionExec(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onActionOpen(); + keyEvent->accept(); + return true; + } + break; + + case Qt::Key_O: // O 隣のパネルと同じフォルダを表示 // Shift + O 隣のパネルに同じフォルダを表示 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ShiftModifier) { - mainWnd->onViewToOther(); - } - else { - mainWnd->onViewFromOther(); - } - } - keyEvent->accept(); - return true; } - - case Qt::Key_Q: { + if (keyEvent->modifiers() & Qt::ShiftModifier) { + this->mainWindow()->onViewToOther(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onViewFromOther(); + keyEvent->accept(); + return true; + } + break; + + case Qt::Key_Q: // Q アプリケーションを終了 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - mainWnd->onActionQuit(); + if (keyEvent->modifiers() & Qt::ShiftModifier) { + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onActionQuit(); + keyEvent->accept(); + return true; } - keyEvent->accept(); - return true; } + break; - case Qt::Key_R: { + case Qt::Key_R: // R 履歴を表示 // Ctrl + R 名前を変更 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ControlModifier) { - mainWnd->onCmdRename(); - } - else { - - } + if (keyEvent->modifiers() & Qt::ShiftModifier) { + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + this->mainWindow()->onCmdRename(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::AltModifier) { } - keyEvent->accept(); - return true; } + else { + } + break; - case Qt::Key_U: { + case Qt::Key_U: // U すべてのマークを解除 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - mainWnd->onMarkAllOff(); + if (keyEvent->modifiers() & Qt::ShiftModifier) { + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { } - keyEvent->accept(); - return true; } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onMarkAllOff(); + keyEvent->accept(); + return true; + } + break; - case Qt::Key_W: { + case Qt::Key_W: // W 表示フォルダを交換 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - mainWnd->onViewSwap(); + if (keyEvent->modifiers() & Qt::ShiftModifier) { + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onViewSwap(); + keyEvent->accept(); + return true; } - keyEvent->accept(); - return true; } + break; - case Qt::Key_X: { + case Qt::Key_X: // X コマンドを実行 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - mainWnd->onActionCommand(); + if (keyEvent->modifiers() & Qt::ShiftModifier) { } - keyEvent->accept(); - return true; } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onActionCommand(); + keyEvent->accept(); + return true; + } + break; - case Qt::Key_Question: { + case Qt::Key_Question: // ? アプリケーション情報を表示 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - mainWnd->onHelpAbout(); + if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onHelpAbout(); + keyEvent->accept(); + return true; } - keyEvent->accept(); - return true; } + break; - case Qt::Key_Space: { + case Qt::Key_Space: // マーク/解除 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - mainWnd->onMarkToggle(); + if (keyEvent->modifiers() & Qt::ShiftModifier) { } - keyEvent->accept(); - return true; } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onMarkToggle(); + keyEvent->accept(); + return true; + } + break; - case Qt::Key_Tab: { + case Qt::Key_Tab: // 隣のパネルに移動 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - mainWnd->onMoveOther(); + if (keyEvent->modifiers() & Qt::ShiftModifier) { + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { } - keyEvent->accept(); - return true; } + else { + this->mainWindow()->onMoveOther(); + keyEvent->accept(); + return true; + } + break; - case Qt::Key_Backspace: { + case Qt::Key_Backspace: // BS 親フォルダに移動 // Shift + BS ルートフォルダに移動 - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ShiftModifier) { - mainWnd->onMoveRoot(); - } - else { - mainWnd->onMoveParent(); - } - } - keyEvent->accept(); - return true; } - - case Qt::Key_Return: { + if (keyEvent->modifiers() & Qt::ShiftModifier) { + this->mainWindow()->onMoveRoot(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onMoveParent(); + keyEvent->accept(); + return true; + } + break; + + case Qt::Key_Return: // RET 開く // Shift + RET アプリケーションで開く - MainWindow *mainWnd = this->mainWindow(); - if (mainWnd) { - if (keyEvent->modifiers() & Qt::ShiftModifier) { - mainWnd->onActionExec(); - } - else { - mainWnd->onActionOpen(); - } - } - keyEvent->accept(); - return true; } + if (keyEvent->modifiers() & Qt::ShiftModifier) { + this->mainWindow()->onActionExec(); + keyEvent->accept(); + return true; + } + else if (keyEvent->modifiers() & Qt::ControlModifier) { + } + else if (keyEvent->modifiers() & Qt::AltModifier) { + } + else { + this->mainWindow()->onActionOpen(); + keyEvent->accept(); + return true; + } + break; } } diff --git a/images/Gefu.icns b/images/Gefu.icns index 333a1c2..32c7119 100644 Binary files a/images/Gefu.icns and b/images/Gefu.icns differ diff --git a/images/Gefu.ico b/images/Gefu.ico index 2a20f38..6b17145 100644 Binary files a/images/Gefu.ico and b/images/Gefu.ico differ diff --git a/images/Gefu.png b/images/Gefu.png index a6cce71..7c5fb65 100644 Binary files a/images/Gefu.png and b/images/Gefu.png differ diff --git a/images/Gefu_128x128.png b/images/Gefu_128x128.png index 5894db2..ed834a9 100644 Binary files a/images/Gefu_128x128.png and b/images/Gefu_128x128.png differ diff --git a/images/Gefu_16x16.png b/images/Gefu_16x16.png index 70220d2..d50a4d2 100644 Binary files a/images/Gefu_16x16.png and b/images/Gefu_16x16.png differ diff --git a/images/Gefu_24x24.png b/images/Gefu_24x24.png new file mode 100644 index 0000000..b422aa1 Binary files /dev/null and b/images/Gefu_24x24.png differ diff --git a/images/Gefu_256x256.png b/images/Gefu_256x256.png index 3b6259d..9fb9f3f 100644 Binary files a/images/Gefu_256x256.png and b/images/Gefu_256x256.png differ diff --git a/images/Gefu_32x32.png b/images/Gefu_32x32.png index 5def30c..7c5fb65 100644 Binary files a/images/Gefu_32x32.png and b/images/Gefu_32x32.png differ diff --git a/images/Gefu_48x48.png b/images/Gefu_48x48.png new file mode 100644 index 0000000..ad5841e Binary files /dev/null and b/images/Gefu_48x48.png differ diff --git a/images/Gefu_512x512.png b/images/Gefu_512x512.png index 621b544..30a2d3a 100644 Binary files a/images/Gefu_512x512.png and b/images/Gefu_512x512.png differ diff --git a/iworker.h b/iworker.h index 4e96a53..a19c4fb 100644 --- a/iworker.h +++ b/iworker.h @@ -29,6 +29,7 @@ protected: } signals: + void canceled(); void finished(); void operation(const QString &msg); void success(const QString &msg); diff --git a/main.cpp b/main.cpp index 872b46d..e5f13b7 100644 --- a/main.cpp +++ b/main.cpp @@ -10,6 +10,7 @@ int main(int argc, char *argv[]) a.setApplicationName("Gefu"); a.setWindowIcon(QIcon(":/images/Gefu.png")); + qRegisterMetaType(); QSettings::setDefaultFormat(QSettings::IniFormat); MainWindow w; diff --git a/mainwindow.cpp b/mainwindow.cpp index 897b063..3349a90 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,6 +1,8 @@ +#include "copyworker.h" #include "deleteworker.h" #include "mainwindow.h" #include "operationdialog.h" +#include "overwritedialog.h" #include "renamemultidialog.h" #include "renamesingledialog.h" #include "renameworker.h" @@ -55,6 +57,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->view_Hidden, SIGNAL(triggered()), this, SLOT(onViewHidden())); connect(ui->view_Swap, SIGNAL(triggered()), this, SLOT(onViewSwap())); + connect(ui->cmd_Copy, SIGNAL(triggered()), this, SLOT(onCmdCopy())); connect(ui->cmd_Delete, SIGNAL(triggered()), this, SLOT(onCmdDelete())); connect(ui->cmd_NewFile, SIGNAL(triggered()), this, SLOT(onCmdNewFile())); connect(ui->cmd_NewFolder, SIGNAL(triggered()), this, SLOT(onCmdNewFolder())); @@ -639,28 +642,74 @@ void MainWindow::onViewSwap() fp2->setCurrentFolder(path1); } -void MainWindow::onCmdDelete() +void MainWindow::onCmdCopy() { FolderPanel *fp = activePanel(); if (!fp) { return; } - QStringList list; - for (int n = 0; n < fp->fileTable()->rowCount(); n++) { - if (fp->fileTable()->item(n, 0)->checkState() == Qt::Checked) { - list << fp->dir()->absoluteFilePath(fp->fileTable()->item(n, 1)->text()); + QStringList list = selectedItems(fp); + if (list.isEmpty()) { + return; + } + + CopyWorker *worker = new CopyWorker(); + connect(worker, SIGNAL(askOverWrite(bool*,int*,int*,QString*,QString,QString)), + this, SLOT(onAskOverWrite(bool*,int*,int*,QString*,QString,QString))); + worker->setCopyList(&list); + worker->setTargetDir(inactivePanel()->dir()->absolutePath()); + + OperationDialog opDlg(this); + opDlg.setWindowTitle(tr("コピー")); + opDlg.setWorker(worker); + + ui->folderPanel_L->UninstallWatcher(); + ui->folderPanel_R->UninstallWatcher(); + opDlg.exec(); + ui->folderPanel_L->setCurrentFolder(ui->folderPanel_L->dir()->absolutePath()); + ui->folderPanel_R->setCurrentFolder(ui->folderPanel_R->dir()->absolutePath()); + +} + +void MainWindow::onAskOverWrite(bool *bOk, int *prevCopyMethod, int *copyMethod, + QString *alias, const QString srcPath, + const QString tgtPath) +{ + OverWriteDialog dlg; + dlg.setCopyMethod(*prevCopyMethod); + dlg.setSameMethodChecked(*copyMethod != OverWriteDialog::Undefined); + dlg.setFileInfo(srcPath, tgtPath); + if (dlg.exec() == QDialog::Rejected) { + *bOk = false; + } + else { + *prevCopyMethod = dlg.copyMethod(); + if (dlg.isSameMethodChecked()) { + *copyMethod = *prevCopyMethod; } + *alias = dlg.alias(); + *bOk = true; } + CopyWorker *worker = static_cast(sender()); + worker->endAsking(); +} +/// +/// \brief MainWindow::onCmdDelete +/// +/// ファイルを削除します +/// +void MainWindow::onCmdDelete() +{ + FolderPanel *fp = activePanel(); + if (!fp) { + return; + } + + QStringList list = selectedItems(fp); if (list.isEmpty()) { -// int row = fp->fileTable()->currentIndex().row(); - int row = fp->fileTable()->currentRow(); - QString name = fp->fileTable()->item(row, 1)->text(); - if (name == "..") { - return; - } - list << fp->dir()->absoluteFilePath(name); + return; } QString msg; @@ -764,21 +813,9 @@ void MainWindow::onCmdRename() return; } - QStringList list; - for (int n = 0; n < fp->fileTable()->rowCount(); n++) { - if (fp->fileTable()->item(n, 0)->checkState() == Qt::Checked) { - list << fp->fileTable()->item(n, 1)->text(); - } - } - + QStringList list = selectedItems(fp); if (list.isEmpty()) { -// int row = fp->fileTable()->currentIndex().row(); - int row = fp->fileTable()->currentRow(); - QString name = fp->fileTable()->item(row, 1)->text(); - if (name == "..") { - return; - } - list << name; + return; } IRenameDialog *dlg; @@ -822,3 +859,23 @@ void MainWindow::onHelpAbout() "(げふぅは実験的なファイルユーティリティです)" "

Copyright 2014 @miyabi_satoh All rights reserved.

")); } + +QStringList MainWindow::selectedItems(FolderPanel *fp) +{ + QStringList list; + for (int n = 0; n < fp->fileTable()->rowCount(); n++) { + if (fp->fileTable()->item(n, 0)->checkState() == Qt::Checked) { + list << fp->dir()->absoluteFilePath(fp->fileTable()->item(n, 1)->text()); + } + } + + if (list.isEmpty()) { + int row = fp->fileTable()->currentRow(); + QString name = fp->fileTable()->item(row, 1)->text(); + if (name != "..") { + list << fp->dir()->absoluteFilePath(name); + } + } + + return list; +} diff --git a/mainwindow.h b/mainwindow.h index 12931ef..fe9c43c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,6 +1,7 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include #include class FolderPanel; @@ -48,6 +49,7 @@ public slots: void onViewHidden(); void onViewSwap(); + void onCmdCopy(); void onCmdDelete(); void onCmdNewFile(); void onCmdNewFolder(); @@ -56,12 +58,15 @@ public slots: void onHelpAbout(); private slots: + void onAskOverWrite(bool *bOk, int *prevCopyMethod, int *copyMethod, + QString *alias, const QString srcPath, const QString tgtPath); private: Ui::MainWindow *ui; FolderPanel* activePanel(); FolderPanel* inactivePanel(); + QStringList selectedItems(FolderPanel *fp); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index a0fb47f..2ee3f2d 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 442 - 217 + 662 + 324 @@ -19,21 +19,6 @@ - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - @@ -59,14 +44,14 @@ - - 0 - - - QLayout::SetMinimumSize - + + + 1 + 0 + + Qt::NoFocus @@ -76,7 +61,39 @@ + + + + 1 + 0 + + + + PushButton + + + + + + + + 1 + 0 + + + + PushButton + + + + + + + 1 + 0 + + Qt::NoFocus @@ -86,6 +103,32 @@ + + + + 1 + 0 + + + + PushButton + + + + + + + + 1 + 0 + + + + PushButton + + + + @@ -166,7 +209,7 @@ 0 0 - 442 + 662 24 diff --git a/operationdialog.cpp b/operationdialog.cpp index 0bc6420..fede99b 100644 --- a/operationdialog.cpp +++ b/operationdialog.cpp @@ -6,8 +6,7 @@ OperationDialog::OperationDialog(QWidget *parent) : QDialog(parent), ui(new Ui::OperationDialog), m_worker(NULL), - m_Error(false), - m_Cancel(false) + m_Error(false) { ui->setupUi(this); } @@ -27,13 +26,14 @@ void OperationDialog::showEvent(QShowEvent *) connect(thread, SIGNAL(started()), m_worker, SLOT(operate())); connect(m_worker, SIGNAL(finished()), thread, SLOT(quit())); - connect(thread, SIGNAL(finished()), this, SLOT(onFinished())); connect(thread, SIGNAL(finished()), m_worker, SLOT(deleteLater())); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); connect(m_worker, SIGNAL(operation(QString)), this, SLOT(onOperation(QString))); connect(m_worker, SIGNAL(success(QString)), this, SLOT(onSuccess(QString))); connect(m_worker, SIGNAL(error(QString)), this, SLOT(onError(QString))); + connect(m_worker, SIGNAL(finished()), this, SLOT(onFinished())); + connect(m_worker, SIGNAL(canceled()), this, SLOT(onCanceled())); thread->start(); } @@ -61,24 +61,28 @@ void OperationDialog::onFinished() ui->btnCloseCancel->setText(tr("閉じる")); ui->textEdit->append(""); - if (m_Cancel) { - ui->textEdit->append(tr("操作は途中でキャンセルされました。")); - } - else { - ui->textEdit->append(tr("完了")); - if (!m_Error && ui->chkAutoClose->checkState() == Qt::Checked) { - QDialog::accept(); - } + ui->textEdit->append(tr("完了")); + if (!m_Error && ui->chkAutoClose->checkState() == Qt::Checked) { + QDialog::accept(); } } +void OperationDialog::onCanceled() +{ + ui->progressBar->setMaximum(1); + ui->progressBar->setValue(1); + ui->btnCloseCancel->setText(tr("閉じる")); + + ui->textEdit->append(""); + ui->textEdit->append(tr("操作は途中でキャンセルされました。")); +} + void OperationDialog::on_btnCloseCancel_clicked() { if (ui->btnCloseCancel->text() == tr("閉じる")) { QDialog::accept(); } else { - m_Cancel = true; m_worker->requestStop(); } } diff --git a/operationdialog.h b/operationdialog.h index c1cb276..7d4d0bf 100644 --- a/operationdialog.h +++ b/operationdialog.h @@ -27,13 +27,13 @@ private: Ui::OperationDialog *ui; IWorker *m_worker; bool m_Error; - bool m_Cancel; private slots: void onOperation(const QString &msg); void onSuccess(const QString &msg); void onError(const QString &msg); void onFinished(); + void onCanceled(); void on_btnCloseCancel_clicked(); void on_btnShowDetail_clicked(); }; diff --git a/overwritedialog.cpp b/overwritedialog.cpp new file mode 100644 index 0000000..55899f5 --- /dev/null +++ b/overwritedialog.cpp @@ -0,0 +1,138 @@ +#include "overwritedialog.h" +#include "ui_overwritedialog.h" +#include +#include +#include + +OverWriteDialog::OverWriteDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::OverWriteDialog), + m_tgtPath() +{ + ui->setupUi(this); + + ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); + + connect(ui->rbAppendNumber, SIGNAL(clicked()), this, SLOT(onRenameOrElse())); + connect(ui->rbOverWrite, SIGNAL(clicked()), this, SLOT(onRenameOrElse())); + connect(ui->rbOverWriteIfNew, SIGNAL(clicked()), this, SLOT(onRenameOrElse())); + connect(ui->rbRename, SIGNAL(clicked()), this, SLOT(onRenameOrElse())); + connect(ui->rbSkip, SIGNAL(clicked()), this, SLOT(onRenameOrElse())); + +} + +OverWriteDialog::~OverWriteDialog() +{ + delete ui; +} + +void OverWriteDialog::setCopyMethod(int method) +{ + switch (method) { + case OverWriteDialog::OverWrite: + ui->rbOverWrite->setChecked(true); + break; + case OverWriteDialog::AppendNumber: + ui->rbAppendNumber->setChecked(true); + break; + case OverWriteDialog::Skip: + ui->rbSkip->setChecked(true); + break; + case OverWriteDialog::Rename: + ui->rbRename->setChecked(true); + ui->lineEdit->setFocus(); + break; + default: + ui->rbOverWriteIfNew->setChecked(true); + break; + } + onRenameOrElse(); +} + +void OverWriteDialog::setSameMethodChecked(bool checked) +{ + ui->checkBox->setChecked(checked); +} + +void OverWriteDialog::setFileInfo(const QString srcPath, const QString tgtPath) +{ + QFileInfo srcInfo(srcPath); + QFileInfo tgtInfo(tgtPath); + m_tgtPath = tgtPath; + ui->lineEdit->setText(tgtInfo.fileName()); + + QTableWidgetItem *iSrcSize = new QTableWidgetItem(tr("%1 Bytes").arg(srcInfo.size())); + iSrcSize->setFlags(iSrcSize->flags() ^ Qt::ItemIsEditable); + iSrcSize->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + ui->tableWidget->setItem(0, 0, iSrcSize); + + QTableWidgetItem *iTgtSize = new QTableWidgetItem(tr("%1 Bytes").arg(tgtInfo.size())); + iTgtSize->setFlags(iTgtSize->flags() ^ Qt::ItemIsEditable); + iTgtSize->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + ui->tableWidget->setItem(1, 0, iTgtSize); + + QTableWidgetItem *iSrcDate = new QTableWidgetItem(srcInfo.lastModified().toString("yy/MM/dd hh:mm")); + iSrcDate->setFlags(iSrcDate->flags() ^ Qt::ItemIsEditable); + iSrcDate->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + ui->tableWidget->setItem(0, 1, iSrcDate); + + QTableWidgetItem *iTgtDate = new QTableWidgetItem(tgtInfo.lastModified().toString("yy/MM/dd hh:mm")); + iTgtDate->setFlags(iTgtDate->flags() ^ Qt::ItemIsEditable); + iTgtDate->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + ui->tableWidget->setItem(1, 1, iTgtDate); +} + +int OverWriteDialog::copyMethod() +{ + if (ui->rbAppendNumber->isChecked()) { + return OverWriteDialog::AppendNumber; + } + if (ui->rbOverWrite->isChecked()) { + return OverWriteDialog::OverWrite; + } + if (ui->rbOverWriteIfNew->isChecked()) { + return OverWriteDialog::OverWriteIfNew; + } + if (ui->rbRename->isChecked()) { + return OverWriteDialog::Rename; + } + return OverWriteDialog::Skip; +} + +bool OverWriteDialog::isSameMethodChecked() +{ + return ui->checkBox->isChecked(); +} + +const QString OverWriteDialog::alias() +{ + return ui->lineEdit->text(); +} + +void OverWriteDialog::onRenameOrElse() +{ + if (ui->rbRename->isChecked()) { + ui->lineEdit->setEnabled(true); + } + else { + ui->lineEdit->setEnabled(false); + } +} + +void OverWriteDialog::accept() +{ + if (ui->rbRename->isChecked()) { + QString newPath = QFileInfo(m_tgtPath).absoluteDir().absoluteFilePath(ui->lineEdit->text()); + if (QFileInfo(newPath).exists()) { + QMessageBox::critical( + this, + tr("エラー"), + tr("すでに同名のファイルが存在しています。")); + ui->lineEdit->setFocus(); + return; + } + } + + QDialog::accept(); +} diff --git a/overwritedialog.h b/overwritedialog.h new file mode 100644 index 0000000..e481d8c --- /dev/null +++ b/overwritedialog.h @@ -0,0 +1,45 @@ +#ifndef OVERWRITEDIALOG_H +#define OVERWRITEDIALOG_H + +#include +#include + +namespace Ui { +class OverWriteDialog; +} + +class OverWriteDialog : public QDialog +{ + Q_OBJECT + +public: + enum { + Undefined = 0x00, + OverWrite = 0x01, + OverWriteIfNew = 0x02, + AppendNumber = 0x04, + Skip = 0x08, + Rename = 0x10, + }; + + explicit OverWriteDialog(QWidget *parent = 0); + ~OverWriteDialog(); + + void setCopyMethod(int method); + void setSameMethodChecked(bool checked); + void setFileInfo(const QString srcPath, const QString tgtPath); + + int copyMethod(); + bool isSameMethodChecked(); + const QString alias(); + +private slots: + void onRenameOrElse(); + void accept(); + +private: + Ui::OverWriteDialog *ui; + QString m_tgtPath; +}; + +#endif // OVERWRITEDIALOG_H diff --git a/overwritedialog.ui b/overwritedialog.ui new file mode 100644 index 0000000..dfa23c3 --- /dev/null +++ b/overwritedialog.ui @@ -0,0 +1,212 @@ + + + OverWriteDialog + + + + 0 + 0 + 384 + 286 + + + + 同名のファイルが存在しています + + + + + + + 0 + 0 + + + + + 0 + 87 + + + + + 16777215 + 87 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + false + + + false + + + false + + + 2 + + + 2 + + + false + + + false + + + + 元 + + + + + 先 + + + + + サイズ + + + + + 更新日時 + + + + + + + + 処理方法 + + + + + + + + 上書き + + + + + + + 新しければ上書き + + + + + + + ファイル名末尾に数字を付与 + + + + + + + スキップ + + + + + + + + + 名前を変更 + + + + + + + + + + + + + + + + + + + 同じ処理を以降の競合にも適用する + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + OverWriteDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + OverWriteDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/renameworker.cpp b/renameworker.cpp index 4f76bcc..021949d 100644 --- a/renameworker.cpp +++ b/renameworker.cpp @@ -15,9 +15,11 @@ void RenameWorker::operate() bool ret; int successCount = 0; int errorCount = 0; + QString msg; for (it = m_RenameMap->begin(); it != m_RenameMap->end(); it++) { if (isStopRequested()) { - break; + emit canceled(); + return; } emit operation(tr("名前変更:") @@ -33,14 +35,12 @@ void RenameWorker::operate() errorCount++; emit error(tr("失敗")); } + msg = tr("%1個の名前を変更しました。").arg(successCount); + if (errorCount > 0) { + msg += tr("%1個の名前を変更できませんでした。").arg(errorCount); + } + m_progressText->setText(msg); } - QString msg; - msg = tr("%1個の名前を変更しました。").arg(successCount); - if (errorCount > 0) { - msg += tr("%1個の名前を変更できませんでした。").arg(errorCount); - } - m_progressText->setText(msg); - emit finished(); }