OSDN Git Service

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