1 #include "copymoveworker.h"
\r
2 #include "overwritedialog.h"
\r
9 const int SLEEP_TIME = 1;
\r
11 CopyMoveWorker::CopyMoveWorker() :
\r
22 void CopyMoveWorker::Listup(const QString &srcPath, const QString &tgtPath)
\r
27 this->thread()->msleep(SLEEP_TIME);
\r
29 QFileInfo info(srcPath);
\r
30 QDir tgtDir(tgtPath);
\r
32 m_CopyMap.insert(srcPath, tgtDir.absoluteFilePath(info.fileName()));
\r
33 if (!info.isDir()) {
\r
37 QDir srcDir(srcPath);
\r
38 QFileInfoList list = srcDir.entryInfoList(QDir::NoDotAndDotDot |
\r
44 foreach (QFileInfo info2, list) {
\r
45 Listup(info2.absoluteFilePath(),
\r
46 tgtDir.absoluteFilePath(info.fileName()));
\r
50 ///////////////////////////////////////////////////////////////////////////////
\r
51 /// \brief CopyMoveWorker::run
\r
53 void CopyMoveWorker::run()
\r
55 foreach (const QString &path, m_CopyList) {
\r
57 emit finished(true);
\r
60 Listup(path, m_tgtDir);
\r
64 int successCount = 0;
\r
67 int errDelCount = 0;
\r
68 const QString operation = (m_Move) ? tr("移動:%1 -> %2") :
\r
73 StringMap::iterator it;
\r
74 for (it = m_CopyMap.begin(); it != m_CopyMap.end(); it++) {
\r
75 this->thread()->msleep(SLEEP_TIME);
\r
77 emit finished(true);
\r
80 QFileInfo srcInfo(it.key());
\r
81 QFileInfo tgtInfo(it.value());
\r
83 emit progress(operation
\r
84 .arg(srcInfo.absoluteFilePath())
\r
85 .arg(tgtInfo.absoluteFilePath()));
\r
87 if (srcInfo.isDir()) {
\r
88 if (tgtInfo.exists()) {
\r
89 emit success(tr("すでに存在"));
\r
91 else if (QDir().mkdir(it.value())) {
\r
92 emit success("フォルダ作成");
\r
95 emit error("フォルダの作成に失敗");
\r
100 do { // コピーをスキップするのにbreakを使うがためのdo-while
\r
101 if (tgtInfo.exists()) {
\r
104 emit askOverWrite(©Method,
\r
106 srcInfo.absoluteFilePath(),
\r
107 tgtInfo.absoluteFilePath());
\r
109 while (isAsking()) {
\r
110 thread()->msleep(100);
\r
115 msg = tr("%1個のファイルをコピーしました。").arg(successCount);
\r
116 if (skipCount > 0) {
\r
117 msg += tr("%1個のファイルをスキップしました。").arg(skipCount);
\r
119 if (errorCount > 0) {
\r
120 msg += tr("%1個のファイルをコピーできませんでした。").arg(errorCount);
\r
122 emit progress(msg);
\r
123 emit finished(true);
\r
127 if (copyMethod == "rbOverWrite") {
\r
128 if (srcInfo.absoluteFilePath() == tgtInfo.absoluteFilePath()) {
\r
129 emit success(tr("同一ファイルへの操作のためスキップ"));
\r
133 QFile(tgtInfo.absoluteFilePath()).remove();
\r
135 else if (copyMethod == "rbOverWriteIfNew") {
\r
136 if (srcInfo.lastModified() <= tgtInfo.lastModified()) {
\r
137 emit success(tr("古いファイルのためスキップ"));
\r
141 if (srcInfo.absoluteFilePath() == tgtInfo.absoluteFilePath()) {
\r
142 emit success(tr("同一ファイルへの操作のためスキップ"));
\r
146 QFile(tgtInfo.absoluteFilePath()).remove();
\r
148 else if (copyMethod == "rbAppendNumber") {
\r
149 QString baseName = tgtInfo.baseName();
\r
150 QString suffix = tgtInfo.completeSuffix();
\r
151 for (int n = 1; ; n++) {
\r
152 QString newName = baseName + tr("%1.").arg(n) + suffix;
\r
153 tgtInfo.setFile(tgtInfo.absolutePath(), newName);
\r
154 if (!tgtInfo.exists()) {
\r
158 emit progress(tr("=> %1 にリネーム").arg(tgtInfo.fileName()));
\r
160 else if (copyMethod == "rbSkip") {
\r
161 emit success(tr("スキップ"));
\r
165 else if (copyMethod == "rbRename") {
\r
166 tgtInfo.setFile(tgtInfo.absolutePath(), alias);
\r
167 emit progress(tr("=> %1 にリネーム").arg(tgtInfo.fileName()));
\r
170 qDebug() << "Unknown method : " << copyMethod;
\r
175 ret = QFile::copy(srcInfo.absoluteFilePath(), tgtInfo.absoluteFilePath());
\r
178 emit success(tr("成功"));
\r
179 if (m_Move && srcInfo.absoluteFilePath() != tgtInfo.absoluteFilePath()) {
\r
180 ret = QFile(srcInfo.absoluteFilePath()).remove();
\r
183 emit error("元ファイルの削除に失敗");
\r
189 emit error(tr("失敗"));
\r
193 msg = tr("%1ファイル成功。").arg(successCount);
\r
194 if (skipCount > 0) {
\r
195 msg += tr("%1ファイルスキップ。").arg(skipCount);
\r
197 if (errorCount > 0) {
\r
198 msg += tr("%1ファイル失敗。").arg(errorCount);
\r
200 if (errDelCount > 0) {
\r
201 msg += tr("%1ファイル削除失敗。").arg(errDelCount);
\r
203 emit information(msg);
\r
208 for (it = m_CopyMap.begin(); it != m_CopyMap.end(); it++) {
\r
209 if (QFileInfo(it.key()).isDir()) {
\r
210 QDir().rmpath(it.key());
\r
218 QString CopyMoveWorker::initialText() const
\r
221 return tr("移動準備中...");
\r
224 return tr("コピー準備中...");
\r