OSDN Git Service

アイコン変更、キーイベント修正、コピー処理実装。
[gefu/Gefu.git] / mainwindow.cpp
1 #include "copyworker.h"\r
2 #include "deleteworker.h"\r
3 #include "mainwindow.h"\r
4 #include "operationdialog.h"\r
5 #include "overwritedialog.h"\r
6 #include "renamemultidialog.h"\r
7 #include "renamesingledialog.h"\r
8 #include "renameworker.h"\r
9 #include "ui_mainwindow.h"\r
10 #include <QFileSystemModel>\r
11 #include <QDebug>\r
12 #include <QKeyEvent>\r
13 #include <QDesktopServices>\r
14 #include <QSettings>\r
15 #include <QFileDialog>\r
16 #include <QMessageBox>\r
17 #include <QProcess>\r
18 #include <QThread>\r
19 #include <QInputDialog>\r
20 \r
21 MainWindow::MainWindow(QWidget *parent) :\r
22     QMainWindow(parent),\r
23     ui(new Ui::MainWindow)\r
24 {\r
25     ui->setupUi(this);\r
26 \r
27     QSettings settings;\r
28     bool checked = settings.value("Common/ShowHidden", false).toBool();\r
29     ui->view_Hidden->setChecked(checked);\r
30 \r
31     // メニューのシグナル/スロットを設定する\r
32     connect(ui->action_Command, SIGNAL(triggered()), this, SLOT(onActionCommand()));\r
33     connect(ui->action_Exec, SIGNAL(triggered()), this, SLOT(onActionExec()));\r
34     connect(ui->action_Open, SIGNAL(triggered()), this, SLOT(onActionOpen()));\r
35     connect(ui->action_Quit, SIGNAL(triggered()), this, SLOT(onActionQuit()));\r
36     connect(ui->action_Setting, SIGNAL(triggered()), this, SLOT(onActionSetting()));\r
37 \r
38     connect(ui->mark_All, SIGNAL(triggered()), this, SLOT(onMarkAll()));\r
39     connect(ui->mark_AllFiles, SIGNAL(triggered()), this, SLOT(onMarkAllFiles()));\r
40     connect(ui->mark_AllOff, SIGNAL(triggered()), this, SLOT(onMarkAllOff()));\r
41     connect(ui->mark_Invert, SIGNAL(triggered()), this, SLOT(onMarkInvert()));\r
42     connect(ui->mark_Toggle, SIGNAL(triggered()), this, SLOT(onMarkToggle()));\r
43 \r
44     connect(ui->move_Down, SIGNAL(triggered()), this, SLOT(onMoveCursorDown()));\r
45     connect(ui->move_Up, SIGNAL(triggered()), this, SLOT(onMoveCursorUp()));\r
46     connect(ui->move_Begin, SIGNAL(triggered()), this, SLOT(onMoveCursorBegin()));\r
47     connect(ui->move_End, SIGNAL(triggered()), this, SLOT(onMoveCursorEnd()));\r
48     connect(ui->move_Back, SIGNAL(triggered()), this, SLOT(onMoveBack()));\r
49     connect(ui->move_Forward, SIGNAL(triggered()), this, SLOT(onMoveForward()));\r
50     connect(ui->move_Home, SIGNAL(triggered()), this, SLOT(onMoveHome()));\r
51     connect(ui->move_Jump, SIGNAL(triggered()), this, SLOT(onMoveJump()));\r
52     connect(ui->move_Parent, SIGNAL(triggered()), this, SLOT(onMoveParent()));\r
53     connect(ui->move_Root, SIGNAL(triggered()), this, SLOT(onMoveRoot()));\r
54 \r
55     connect(ui->view_FromOther, SIGNAL(triggered()), this, SLOT(onViewFromOther()));\r
56     connect(ui->view_ToOther, SIGNAL(triggered()), this, SLOT(onViewToOther()));\r
57     connect(ui->view_Hidden, SIGNAL(triggered()), this, SLOT(onViewHidden()));\r
58     connect(ui->view_Swap, SIGNAL(triggered()), this, SLOT(onViewSwap()));\r
59 \r
60     connect(ui->cmd_Copy, SIGNAL(triggered()), this, SLOT(onCmdCopy()));\r
61     connect(ui->cmd_Delete, SIGNAL(triggered()), this, SLOT(onCmdDelete()));\r
62     connect(ui->cmd_NewFile, SIGNAL(triggered()), this, SLOT(onCmdNewFile()));\r
63     connect(ui->cmd_NewFolder, SIGNAL(triggered()), this, SLOT(onCmdNewFolder()));\r
64     connect(ui->cmd_Rename, SIGNAL(triggered()), this, SLOT(onCmdRename()));\r
65 \r
66     connect(ui->help_About, SIGNAL(triggered()), this, SLOT(onHelpAbout()));\r
67 \r
68     // ウィンドウタイトルを設定する\r
69     setWindowTitle(tr("げふぅ v0.00"));\r
70     // ウィンドウアイコンを設定する\r
71     setWindowIcon(QIcon(":/images/Gefu.png"));\r
72 \r
73     // ウィンドウ初期サイズを設定する\r
74     resize(800, 600);\r
75 \r
76     QString path;\r
77 \r
78     path = settings.value("Left/dir", QDir::homePath()).toString();\r
79     ui->folderPanel_L->setCurrentFolder(path);\r
80 \r
81     path = settings.value("Right/dir", QDir::homePath()).toString();\r
82     ui->folderPanel_R->setCurrentFolder(path);\r
83 }\r
84 \r
85 MainWindow::~MainWindow()\r
86 {\r
87     QSettings settings;\r
88 \r
89     settings.setValue("Left/dir", ui->folderPanel_L->dir()->absolutePath());\r
90     settings.setValue("Right/dir", ui->folderPanel_R->dir()->absolutePath());\r
91 \r
92     delete ui;\r
93 }\r
94 \r
95 void MainWindow::setStatusText(const QString &str)\r
96 {\r
97     ui->statusBar->showMessage(str);\r
98 }\r
99 \r
100 FolderPanel* MainWindow::activePanel()\r
101 {\r
102     if (ui->folderPanel_L->fileTable()->hasFocus()) {\r
103         return ui->folderPanel_L;\r
104     }\r
105     if (ui->folderPanel_R->fileTable()->hasFocus()) {\r
106         return ui->folderPanel_R;\r
107     }\r
108 \r
109     return NULL;\r
110 }\r
111 \r
112 FolderPanel* MainWindow::inactivePanel()\r
113 {\r
114     FolderPanel *fp = activePanel();\r
115     if (fp == ui->folderPanel_L) {\r
116         return ui->folderPanel_R;\r
117     }\r
118     if (fp == ui->folderPanel_R) {\r
119         return ui->folderPanel_L;\r
120     }\r
121 \r
122     return NULL;\r
123 }\r
124 \r
125 ///\r
126 /// \brief MainWindow::onActionCommand\r
127 ///\r
128 /// コマンドを実行します(X)\r
129 ///\r
130 void MainWindow::onActionCommand()\r
131 {\r
132     FolderPanel *fp = activePanel();\r
133     if (!fp) {\r
134         return;\r
135     }\r
136 \r
137     QString command = "";\r
138     for (int n = 0; n < fp->fileTable()->rowCount(); n++) {\r
139         if (fp->fileTable()->item(n, 0)->checkState() == Qt::Checked) {\r
140             QString path = fp->fileTable()->item(n, 1)->text();\r
141             path = fp->dir()->absoluteFilePath(path);\r
142             path = QDir::cleanPath(path);\r
143             path = QDir::toNativeSeparators(path);\r
144 \r
145             QFileInfo info(path);\r
146             if (info.isExecutable()) {\r
147                 command = "\"" + path + "\" " + command;\r
148             }\r
149             else {\r
150                 command += " \"" + path + "\"";\r
151             }\r
152         }\r
153     }\r
154 \r
155     if (command.isEmpty()) {\r
156 //        int row = fp->fileTable()->currentIndex().row();\r
157         int row = fp->fileTable()->currentRow();\r
158         QString path = fp->fileTable()->item(row, 1)->text();\r
159         path = fp->dir()->absoluteFilePath(path);\r
160         path = QDir::cleanPath(path);\r
161         path = QDir::toNativeSeparators(path);\r
162 \r
163         command = "\"" + path + "\"";\r
164     }\r
165 \r
166     QInputDialog dlg(this);\r
167     dlg.setInputMode(QInputDialog::TextInput);\r
168     dlg.setLabelText(tr("コマンドを入力:"));\r
169     dlg.setWindowTitle(tr("コマンドを実行"));\r
170     dlg.setTextValue(command);\r
171     dlg.resize(500, 100);\r
172     int ret = dlg.exec();\r
173     command = dlg.textValue();\r
174     if (ret == QDialog::Accepted && !command.isEmpty()) {\r
175         QProcess process(this);\r
176         process.setWorkingDirectory(fp->dir()->absolutePath());\r
177         if (!process.startDetached(command)) {\r
178             QMessageBox::critical(\r
179                         this,\r
180                         tr("エラー"),\r
181                         tr("コマンドの実行に失敗しました。<br/>") + command);\r
182         }\r
183     }\r
184 }\r
185 \r
186 ///\r
187 /// \brief MainWindow::onActionExec\r
188 ///\r
189 /// アプリケーションで開きます(Shift + Enter)\r
190 ///\r
191 void MainWindow::onActionExec()\r
192 {\r
193     FolderPanel *fp = activePanel();\r
194     if (!fp) {\r
195         return;\r
196     }\r
197 \r
198     int count = 0;\r
199     for (int n = 0; n < fp->fileTable()->rowCount(); n++) {\r
200         if (fp->fileTable()->item(n, 0)->checkState() == Qt::Checked) {\r
201             QString path = fp->fileTable()->item(n, 1)->text();\r
202             path = fp->dir()->absoluteFilePath(path);\r
203             path = QDir::toNativeSeparators(path);\r
204             QDesktopServices::openUrl(QUrl("file:///" + path));\r
205             count++;\r
206         }\r
207     }\r
208 \r
209     if (count == 0) {\r
210 //        int row = fp->fileTable()->currentIndex().row();\r
211         int row = fp->fileTable()->currentRow();\r
212         QString path = fp->fileTable()->item(row, 1)->text();\r
213         path = fp->dir()->absoluteFilePath(path);\r
214         path = QDir::toNativeSeparators(path);\r
215         QDesktopServices::openUrl(QUrl("file:///" + path));\r
216     }\r
217 }\r
218 \r
219 ///\r
220 /// \brief MainWindow::onActionOpen\r
221 ///\r
222 /// フォルダを開きます(Enter)\r
223 ///\r
224 void MainWindow::onActionOpen()\r
225 {\r
226     FolderPanel *fp = activePanel();\r
227     if (!fp) {\r
228         return;\r
229     }\r
230 \r
231 //    int row = fp->fileTable()->currentIndex().row();\r
232     int row = fp->fileTable()->currentRow();\r
233     QString path = fp->fileTable()->item(row, 1)->text();\r
234     path = fp->dir()->absoluteFilePath(path);\r
235     QFileInfo info(path);\r
236 \r
237     if (info.isDir()) {\r
238         fp->setCurrentFolder(path);\r
239     }\r
240 }\r
241 \r
242 ///\r
243 /// \brief MainWindow::onActionQuit\r
244 ///\r
245 /// アプリケーションを終了します(Q)\r
246 ///\r
247 void MainWindow::onActionQuit()\r
248 {\r
249     qApp->quit();\r
250 }\r
251 \r
252 ///\r
253 /// \brief MainWindow::onActionSetting\r
254 ///\r
255 /// 環境設定ダイアログを表示します(Z)\r
256 ///\r
257 void MainWindow::onActionSetting()\r
258 {\r
259     QMessageBox::information(this, tr("情報"), tr("環境設定機能は未実装です。"));\r
260 }\r
261 \r
262 ///\r
263 /// \brief MainWindow::on_mark_All_triggered\r
264 ///\r
265 /// すべてマークします(Shift + A)\r
266 ///\r
267 void MainWindow::onMarkAll()\r
268 {\r
269     FolderPanel *fp = activePanel();\r
270     if (fp == NULL) {\r
271         return;\r
272     }\r
273 \r
274     int row = 0;\r
275     if (fp->fileTable()->item(row, 1)->text() == "..") {\r
276         row++;\r
277     }\r
278 \r
279     for (; row < fp->fileTable()->rowCount(); row++) {\r
280         fp->fileTable()->item(row, 0)->setCheckState(Qt::Checked);\r
281     }\r
282 }\r
283 \r
284 ///\r
285 /// \brief MainWindow::onMarkAllFiles\r
286 ///\r
287 /// すべての「ファイル」をマークします(A)\r
288 ///\r
289 void MainWindow::onMarkAllFiles()\r
290 {\r
291     FolderPanel *fp = activePanel();\r
292     if (fp == NULL) {\r
293         return;\r
294     }\r
295 \r
296     int row = 0;\r
297     if (fp->fileTable()->item(row, 1)->text() == "..") {\r
298         row++;\r
299     }\r
300 \r
301     for (; row < fp->fileTable()->rowCount(); row++) {\r
302         QString path = fp->fileTable()->item(row, 1)->text();\r
303         path = fp->dir()->absoluteFilePath(path);\r
304 \r
305         QFileInfo info(path);\r
306         if (info.isDir()) {\r
307             fp->fileTable()->item(row, 0)->setCheckState(Qt::Unchecked);\r
308         }\r
309         else {\r
310            fp->fileTable()->item(row, 0)->setCheckState(Qt::Checked);\r
311         }\r
312     }\r
313 }\r
314 \r
315 ///\r
316 /// \brief MainWindow::onMarkAllOff\r
317 ///\r
318 /// すべてのマークを解除します(U)\r
319 ///\r
320 void MainWindow::onMarkAllOff()\r
321 {\r
322     FolderPanel *fp = activePanel();\r
323     if (fp == NULL) {\r
324         return;\r
325     }\r
326 \r
327     int row = 0;\r
328     if (fp->fileTable()->item(row, 1)->text() == "..") {\r
329         row++;\r
330     }\r
331 \r
332     for (; row < fp->fileTable()->rowCount(); row++) {\r
333         fp->fileTable()->item(row, 0)->setCheckState(Qt::Unchecked);\r
334     }\r
335 }\r
336 \r
337 ///\r
338 /// \brief MainWindow::onMarkInvert\r
339 ///\r
340 /// マークを反転します(I)\r
341 ///\r
342 void MainWindow::onMarkInvert()\r
343 {\r
344     FolderPanel *fp = activePanel();\r
345     if (fp == NULL) {\r
346         return;\r
347     }\r
348 \r
349     int row = 0;\r
350     if (fp->fileTable()->item(row, 1)->text() == "..") {\r
351         row++;\r
352     }\r
353 \r
354     for (; row < fp->fileTable()->rowCount(); row++) {\r
355         QTableWidgetItem *item = fp->fileTable()->item(row, 0);\r
356         if (item->checkState() == Qt::Checked) {\r
357             item->setCheckState(Qt::Unchecked);\r
358         }\r
359         else {\r
360             item->setCheckState(Qt::Checked);\r
361         }\r
362     }\r
363 }\r
364 \r
365 ///\r
366 /// \brief MainWindow::onMarkToggle\r
367 ///\r
368 /// マークを設定または解除します(Space)\r
369 ///\r
370 void MainWindow::onMarkToggle()\r
371 {\r
372     FolderPanel *fp = activePanel();\r
373     if (fp == NULL) {\r
374         return;\r
375     }\r
376 \r
377 //    int row = fp->fileTable()->currentIndex().row();\r
378     int row = fp->fileTable()->currentRow();\r
379     QTableWidgetItem *item = fp->fileTable()->item(row, 0);\r
380     if (fp->fileTable()->item(row, 1)->text() != "..") {\r
381        if (item->checkState() == Qt::Checked) {\r
382             item->setCheckState(Qt::Unchecked);\r
383        }\r
384         else {\r
385             item->setCheckState(Qt::Checked);\r
386        }\r
387     }\r
388     // 最終行でなければ、次のアイテムに移動する\r
389     if (row < fp->fileTable()->rowCount() - 1) {\r
390         QModelIndex nextIndex = fp->fileTable()->model()->index(row + 1, 1);\r
391         fp->fileTable()->setCurrentIndex(nextIndex);\r
392     }\r
393 }\r
394 \r
395 ///\r
396 /// \brief MainWindow::onMoveCursorDown\r
397 ///\r
398 /// カーソルを下に移動します(J)\r
399 ///\r
400 void MainWindow::onMoveCursorDown()\r
401 {\r
402     FolderPanel *fp = activePanel();\r
403     if (fp == NULL) {\r
404         return;\r
405     }\r
406 \r
407 //    int row = fp->fileTable()->currentIndex().row();\r
408     int row = fp->fileTable()->currentRow();\r
409     if (row < fp->fileTable()->rowCount() - 1) {\r
410         QModelIndex nextIndex = fp->fileTable()->model()->index(row + 1, 1);\r
411         fp->fileTable()->setCurrentIndex(nextIndex);\r
412     }\r
413 }\r
414 \r
415 ///\r
416 /// \brief MainWindow::onMoveCursorUp\r
417 ///\r
418 /// カーソルを上に移動します(K)\r
419 ///\r
420 void MainWindow::onMoveCursorUp()\r
421 {\r
422     FolderPanel *fp = activePanel();\r
423     if (fp == NULL) {\r
424         return;\r
425     }\r
426 \r
427 //    int row = fp->fileTable()->currentIndex().row();\r
428     int row = fp->fileTable()->currentRow();\r
429     if (row > 0) {\r
430         QModelIndex nextIndex = fp->fileTable()->model()->index(row - 1, 1);\r
431         fp->fileTable()->setCurrentIndex(nextIndex);\r
432     }\r
433 }\r
434 \r
435 ///\r
436 /// \brief MainWindow::onMoveCursorBegin\r
437 ///\r
438 /// カーソルを先頭に移動します(G)\r
439 ///\r
440 void MainWindow::onMoveCursorBegin()\r
441 {\r
442     FolderPanel *fp = activePanel();\r
443     if (fp == NULL) {\r
444         return;\r
445     }\r
446 \r
447     QModelIndex nextIndex = fp->fileTable()->model()->index(0, 1);\r
448     fp->fileTable()->setCurrentIndex(nextIndex);\r
449 }\r
450 \r
451 ///\r
452 /// \brief MainWindow::onMoveCursorEnd\r
453 ///\r
454 /// カーソルを末尾に移動します(Shift + G)\r
455 void MainWindow::onMoveCursorEnd()\r
456 {\r
457     FolderPanel *fp = activePanel();\r
458     if (fp == NULL) {\r
459         return;\r
460     }\r
461 \r
462     int row = fp->fileTable()->rowCount() - 1;\r
463     QModelIndex nextIndex = fp->fileTable()->model()->index(row, 1);\r
464     fp->fileTable()->setCurrentIndex(nextIndex);\r
465 }\r
466 \r
467 ///\r
468 /// \brief MainWindow::onMoveBack\r
469 ///\r
470 /// 前の履歴に戻ります(Alt + ←)\r
471 ///\r
472 void MainWindow::onMoveBack()\r
473 {\r
474     QMessageBox::information(this, tr("情報"), tr("履歴機能は未実装です。"));\r
475 }\r
476 \r
477 ///\r
478 /// \brief MainWindow::onMoveForward\r
479 ///\r
480 /// 次の履歴に進みます(Alt + →)\r
481 ///\r
482 void MainWindow::onMoveForward()\r
483 {\r
484     QMessageBox::information(this, tr("情報"), tr("履歴機能は未実装です。"));\r
485 \r
486 }\r
487 \r
488 ///\r
489 /// \brief MainWindow::onMoveHome\r
490 ///\r
491 /// ホームフォルダに移動します(H)\r
492 ///\r
493 void MainWindow::onMoveHome()\r
494 {\r
495     FolderPanel *fp = activePanel();\r
496     if (fp == NULL) {\r
497         return;\r
498     }\r
499 \r
500     fp->setCurrentFolder(QDir::homePath());\r
501 }\r
502 \r
503 ///\r
504 /// \brief MainWindow::onMoveJump\r
505 ///\r
506 /// フォルダを選択して移動します(Shift + J)\r
507 void MainWindow::onMoveJump()\r
508 {\r
509     FolderPanel *fp = activePanel();\r
510     if (fp == NULL) {\r
511         return;\r
512     }\r
513 \r
514     QString path = QFileDialog::getExistingDirectory(\r
515                 this,\r
516                 tr("フォルダを選択"),\r
517                 fp->dir()->absolutePath());\r
518     if (!path.isEmpty()) {\r
519         fp->setCurrentFolder(path);\r
520     }\r
521 }\r
522 \r
523 ///\r
524 /// \brief MainWindow::onMoveOther\r
525 ///\r
526 /// キーボードフォーカスを他方のパネルに移動します(TAB)\r
527 ///\r
528 void MainWindow::onMoveOther()\r
529 {\r
530     FolderPanel *fp = this->inactivePanel();\r
531     if (fp) {\r
532         fp->fileTable()->setFocus();\r
533     }\r
534 }\r
535 \r
536 ///\r
537 /// \brief MainWindow::onMoveParent\r
538 ///\r
539 /// 親フォルダに移動します(Backspace)\r
540 ///\r
541 void MainWindow::onMoveParent()\r
542 {\r
543     FolderPanel *fp = activePanel();\r
544     if (fp == NULL) {\r
545         return;\r
546     }\r
547 \r
548     if (!fp->dir()->isRoot()) {\r
549         QString path = fp->dir()->absoluteFilePath("..");\r
550         fp->setCurrentFolder(path);\r
551     }\r
552 }\r
553 \r
554 ///\r
555 /// \brief MainWindow::onMoveRoot\r
556 ///\r
557 /// ルートフォルダに移動します()\r
558 void MainWindow::onMoveRoot()\r
559 {\r
560     FolderPanel *fp = activePanel();\r
561     if (fp == NULL) {\r
562         return;\r
563     }\r
564 \r
565     if (!fp->dir()->isRoot()) {\r
566         fp->setCurrentFolder(QDir::rootPath());\r
567     }\r
568 }\r
569 \r
570 ///\r
571 /// \brief MainWindow::onViewFromOther\r
572 ///\r
573 /// 隣のパネルと同じフォルダを表示します(O)\r
574 ///\r
575 void MainWindow::onViewFromOther()\r
576 {\r
577     FolderPanel *fp1 = activePanel();\r
578     FolderPanel *fp2 = inactivePanel();\r
579     if (fp1 == NULL || fp2 == NULL) {\r
580         return;\r
581     }\r
582 \r
583     fp1->setCurrentFolder(fp2->dir()->absolutePath());\r
584 }\r
585 \r
586 ///\r
587 /// \brief MainWindow::onViewToOther\r
588 ///\r
589 /// 隣のパネルに同じフォルダを表示します(Shift + O)\r
590 ///\r
591 void MainWindow::onViewToOther()\r
592 {\r
593     FolderPanel *fp1 = activePanel();\r
594     FolderPanel *fp2 = inactivePanel();\r
595     if (fp1 == NULL || fp2 == NULL) {\r
596         return;\r
597     }\r
598 \r
599     fp2->setCurrentFolder(fp1->dir()->absolutePath());\r
600 }\r
601 \r
602 ///\r
603 /// \brief MainWindow::onViewHidden\r
604 ///\r
605 /// 隠しファイルの表示/非表示を切り替えます(Shift + H)\r
606 void MainWindow::onViewHidden()\r
607 {\r
608     QSettings settings;\r
609     bool checked = !settings.value("Common/ShowHidden", false).toBool();\r
610     settings.setValue("Common/ShowHidden", checked);\r
611 \r
612     if (checked) {\r
613         ui->folderPanel_L->dir()->setFilter(ui->folderPanel_L->dir()->filter() | QDir::Hidden);\r
614         ui->folderPanel_R->dir()->setFilter(ui->folderPanel_R->dir()->filter() | QDir::Hidden);\r
615     }\r
616     else {\r
617         ui->folderPanel_L->dir()->setFilter(ui->folderPanel_L->dir()->filter() ^ QDir::Hidden);\r
618         ui->folderPanel_R->dir()->setFilter(ui->folderPanel_R->dir()->filter() ^ QDir::Hidden);\r
619     }\r
620 \r
621     ui->folderPanel_L->setCurrentFolder(ui->folderPanel_L->dir()->absolutePath());\r
622     ui->folderPanel_R->setCurrentFolder(ui->folderPanel_R->dir()->absolutePath());\r
623 }\r
624 \r
625 ///\r
626 /// \brief MainWindow::onViewSwap\r
627 ///\r
628 /// パネルの表示内容を交換します(W)\r
629 ///\r
630 void MainWindow::onViewSwap()\r
631 {\r
632     FolderPanel *fp1 = activePanel();\r
633     FolderPanel *fp2 = inactivePanel();\r
634     if (fp1 == NULL || fp2 == NULL) {\r
635         return;\r
636     }\r
637 \r
638     QString path1 = fp1->dir()->absolutePath();\r
639     QString path2 = fp2->dir()->absolutePath();\r
640 \r
641     fp1->setCurrentFolder(path2);\r
642     fp2->setCurrentFolder(path1);\r
643 }\r
644 \r
645 void MainWindow::onCmdCopy()\r
646 {\r
647     FolderPanel *fp = activePanel();\r
648     if (!fp) {\r
649         return;\r
650     }\r
651 \r
652     QStringList list = selectedItems(fp);\r
653     if (list.isEmpty()) {\r
654         return;\r
655     }\r
656 \r
657     CopyWorker *worker = new CopyWorker();\r
658     connect(worker, SIGNAL(askOverWrite(bool*,int*,int*,QString*,QString,QString)),\r
659             this, SLOT(onAskOverWrite(bool*,int*,int*,QString*,QString,QString)));\r
660     worker->setCopyList(&list);\r
661     worker->setTargetDir(inactivePanel()->dir()->absolutePath());\r
662 \r
663     OperationDialog opDlg(this);\r
664     opDlg.setWindowTitle(tr("コピー"));\r
665     opDlg.setWorker(worker);\r
666 \r
667     ui->folderPanel_L->UninstallWatcher();\r
668     ui->folderPanel_R->UninstallWatcher();\r
669     opDlg.exec();\r
670     ui->folderPanel_L->setCurrentFolder(ui->folderPanel_L->dir()->absolutePath());\r
671     ui->folderPanel_R->setCurrentFolder(ui->folderPanel_R->dir()->absolutePath());\r
672 \r
673 }\r
674 \r
675 void MainWindow::onAskOverWrite(bool *bOk, int *prevCopyMethod, int *copyMethod,\r
676                                 QString *alias, const QString srcPath,\r
677                                 const QString tgtPath)\r
678 {\r
679     OverWriteDialog dlg;\r
680     dlg.setCopyMethod(*prevCopyMethod);\r
681     dlg.setSameMethodChecked(*copyMethod != OverWriteDialog::Undefined);\r
682     dlg.setFileInfo(srcPath, tgtPath);\r
683     if (dlg.exec() == QDialog::Rejected) {\r
684         *bOk = false;\r
685     }\r
686     else {\r
687         *prevCopyMethod = dlg.copyMethod();\r
688         if (dlg.isSameMethodChecked()) {\r
689             *copyMethod = *prevCopyMethod;\r
690         }\r
691         *alias = dlg.alias();\r
692         *bOk = true;\r
693     }\r
694     CopyWorker *worker = static_cast<CopyWorker*>(sender());\r
695     worker->endAsking();\r
696 }\r
697 \r
698 ///\r
699 /// \brief MainWindow::onCmdDelete\r
700 ///\r
701 /// ファイルを削除します\r
702 ///\r
703 void MainWindow::onCmdDelete()\r
704 {\r
705     FolderPanel *fp = activePanel();\r
706     if (!fp) {\r
707         return;\r
708     }\r
709 \r
710     QStringList list = selectedItems(fp);\r
711     if (list.isEmpty()) {\r
712         return;\r
713     }\r
714 \r
715     QString msg;\r
716     if (list.size() == 1) {\r
717         msg = QFileInfo(list.at(0)).fileName();\r
718     }\r
719     else {\r
720         msg = tr("%1個のアイテム").arg(list.size());\r
721     }\r
722     int ret = QMessageBox::question(\r
723                 this,\r
724                 tr("確認"),\r
725                 msg + tr("を削除します<br/>よろしいですか?"));\r
726     if (ret == QMessageBox::Yes) {\r
727         DeleteWorker *worker = new DeleteWorker();\r
728         worker->setDeleteList(&list);\r
729 \r
730         OperationDialog opDlg(this);\r
731         opDlg.setWindowTitle(tr("削除"));\r
732         opDlg.setWorker(worker);\r
733 \r
734         ui->folderPanel_L->UninstallWatcher();\r
735         ui->folderPanel_R->UninstallWatcher();\r
736         opDlg.exec();\r
737         ui->folderPanel_L->setCurrentFolder(ui->folderPanel_L->dir()->absolutePath());\r
738         ui->folderPanel_R->setCurrentFolder(ui->folderPanel_R->dir()->absolutePath());\r
739     }\r
740 }\r
741 \r
742 ///\r
743 /// \brief MainWindow::onCmdNewFile\r
744 ///\r
745 /// ファイルを作成します\r
746 ///\r
747 void MainWindow::onCmdNewFile()\r
748 {\r
749     FolderPanel *fp = activePanel();\r
750     if (!fp) {\r
751         return;\r
752     }\r
753 \r
754     bool bOk;\r
755     QString name = QInputDialog::getText(\r
756                 this,\r
757                 tr("ファイルを作成"),\r
758                 tr("ファイル名"),\r
759                 QLineEdit::Normal,\r
760                 "",\r
761                 &bOk);\r
762     if (bOk && !name.isEmpty()) {\r
763         QFile file(fp->dir()->absoluteFilePath(name));\r
764         if (!file.open(QIODevice::WriteOnly)) {\r
765             QMessageBox::critical(this,\r
766                                   tr("エラー"),\r
767                                   tr("ファイルの作成に失敗しました。"));\r
768         }\r
769         else {\r
770             file.close();\r
771         }\r
772     }\r
773 }\r
774 \r
775 ///\r
776 /// \brief MainWindow::onCmdNewFolder\r
777 ///\r
778 /// フォルダを作成します\r
779 ///\r
780 void MainWindow::onCmdNewFolder()\r
781 {\r
782     FolderPanel *fp = activePanel();\r
783     if (!fp) {\r
784         return;\r
785     }\r
786 \r
787     bool bOk;\r
788     QString name = QInputDialog::getText(\r
789                 this,\r
790                 tr("フォルダを作成"),\r
791                 tr("フォルダ名"),\r
792                 QLineEdit::Normal,\r
793                 "",\r
794                 &bOk);\r
795     if (bOk && !name.isEmpty()) {\r
796         if (!fp->dir()->mkpath(name)) {\r
797             QMessageBox::critical(this,\r
798                                   tr("エラー"),\r
799                                   tr("フォルダの作成に失敗しました。"));\r
800         }\r
801     }\r
802 }\r
803 \r
804 ///\r
805 /// \brief MainWindow::onCmdRename\r
806 ///\r
807 /// 名前を変更します\r
808 ///\r
809 void MainWindow::onCmdRename()\r
810 {\r
811     FolderPanel *fp = activePanel();\r
812     if (!fp) {\r
813         return;\r
814     }\r
815 \r
816     QStringList list = selectedItems(fp);\r
817     if (list.isEmpty()) {\r
818         return;\r
819     }\r
820 \r
821     IRenameDialog *dlg;\r
822     if (list.size() == 1) {\r
823         dlg = new RenameSingleDialog(this);\r
824     }\r
825     else {\r
826         dlg = new RenameMultiDialog(this);\r
827     }\r
828     dlg->setWorkingDirectory(fp->dir()->absolutePath());\r
829     dlg->setNames(list);\r
830     int dlgResult = dlg->exec();\r
831     if (dlgResult == QDialog::Accepted && !dlg->renameMap().isEmpty()) {\r
832         RenameWorker *worker = new RenameWorker();\r
833         worker->setRenameMap(&dlg->renameMap());\r
834 \r
835         OperationDialog opDlg(this);\r
836         opDlg.setWindowTitle(tr("名前を変更"));\r
837         opDlg.setWorker(worker);\r
838 \r
839         ui->folderPanel_L->UninstallWatcher();\r
840         ui->folderPanel_R->UninstallWatcher();\r
841         opDlg.exec();\r
842         ui->folderPanel_L->setCurrentFolder(ui->folderPanel_L->dir()->absolutePath());\r
843         ui->folderPanel_R->setCurrentFolder(ui->folderPanel_R->dir()->absolutePath());\r
844     }\r
845 }\r
846 \r
847 ///\r
848 /// \brief MainWindow::onHelpAbout\r
849 ///\r
850 /// アプリケーションの概要を表示します(?)\r
851 ///\r
852 void MainWindow::onHelpAbout()\r
853 {\r
854     QMessageBox::about(\r
855                 this,\r
856                 tr("げふぅ について"),\r
857                 tr("<h3>Gefu Ver0.00</h3>"\r
858                    "<center>Gefu is Experimental File Utility.<br/>"\r
859                    "(げふぅは実験的なファイルユーティリティです)</center>"\r
860                    "<p>Copyright 2014 @miyabi_satoh All rights reserved.</p>"));\r
861 }\r
862 \r
863 QStringList MainWindow::selectedItems(FolderPanel *fp)\r
864 {\r
865     QStringList list;\r
866     for (int n = 0; n < fp->fileTable()->rowCount(); n++) {\r
867         if (fp->fileTable()->item(n, 0)->checkState() == Qt::Checked) {\r
868             list << fp->dir()->absoluteFilePath(fp->fileTable()->item(n, 1)->text());\r
869         }\r
870     }\r
871 \r
872     if (list.isEmpty()) {\r
873         int row = fp->fileTable()->currentRow();\r
874         QString name = fp->fileTable()->item(row, 1)->text();\r
875         if (name != "..") {\r
876             list << fp->dir()->absoluteFilePath(name);\r
877         }\r
878     }\r
879 \r
880     return list;\r
881 }\r