fd19a08b281a774c281b627b2c17c35cdcdeb55f
[cuteexplorer] / src / mainwindow.cpp
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3
4 MainWindow::MainWindow(QWidget *parent) :
5     QMainWindow(parent),
6     ui(new Ui::MainWindow)
7 {
8     ui->setupUi(this);
9     connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close()));
10     connect(ui->upButton, SIGNAL(clicked()), ui->fileListWidget, SLOT(changePathUp()));
11     connect(ui->locationLine, SIGNAL(returnPressed()), this, SLOT(locationLineEnterKeyHandler()));
12     connect(ui->fileListWidget, SIGNAL(pathChanged(QString)), ui->locationLine, SLOT(setText(QString)));
13     connect(ui->actionDelete, SIGNAL(triggered()), ui->fileListWidget, SLOT(actionDelete()));
14     connect(ui->actionMode, SIGNAL(toggled(bool)), ui->fileListWidget, SLOT(actionSwitchMode(bool)));
15     connect(ui->actionCopy, SIGNAL(triggered()), ui->fileListWidget, SLOT(actionCopy()));
16     connect(ui->actionCut, SIGNAL(triggered()), ui->fileListWidget, SLOT(actionCut()));
17     connect(ui->actionPaste, SIGNAL(triggered()), ui->fileListWidget, SLOT(actionPaste()));
18     connect(ui->actionShow_hidden, SIGNAL(toggled(bool)), ui->fileListWidget, SLOT(actionShowHidden(bool)));
19     connect(ui->actionRename, SIGNAL(triggered()), ui->fileListWidget, SLOT(actionRename()));
20     connect(ui->actionSend, SIGNAL(triggered()), ui->fileListWidget, SLOT(actionSendFiles()));
21
22     connect(ui->actionHelp, SIGNAL(triggered()), this, SLOT(showHelp()));
23     connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout()));
24
25     ui->locationLine->setText(ui->fileListWidget->getPath());
26
27
28     ui->fileListWidget->addAction(ui->actionCopy);
29     ui->fileListWidget->addAction(ui->actionCut);
30     ui->fileListWidget->addAction(ui->actionPaste);
31     ui->fileListWidget->addAction(ui->actionDelete);
32     ui->fileListWidget->addAction(ui->actionRename);
33     ui->fileListWidget->addAction(ui->actionSend);
34 }
35
36 MainWindow::~MainWindow()
37 {
38     delete ui;
39 }
40
41 void MainWindow::locationLineEnterKeyHandler()
42 {
43     ui->fileListWidget->changePath(ui->locationLine->text());
44 }
45 void MainWindow::keyPressEvent(QKeyEvent *e)
46 {
47     if(e->key() == Qt::Key_Control || e->key() == Qt::Key_Shift)
48         ui->fileListWidget->setSelectMode(true);
49     else
50         QMainWindow::keyPressEvent(e);
51 }
52 void MainWindow::keyReleaseEvent(QKeyEvent *e)
53 {
54     if(e->key() == Qt::Key_Control || e->key() == Qt::Key_Shift)
55         ui->fileListWidget->setSelectMode(false);
56     else
57         QMainWindow::keyPressEvent(e);
58 }
59
60 void MainWindow::changeEvent(QEvent *e)
61 {
62     QMainWindow::changeEvent(e);
63     switch (e->type()) {
64     case QEvent::LanguageChange:
65         ui->retranslateUi(this);
66         break;
67     default:
68         break;
69     }
70 }
71
72 void MainWindow::showHelp()
73 {
74     QString helpText;
75
76     helpText.append("<h2>CuteExplorer "+tr("Help") +"</h2>");
77     helpText.append("<p>"+ tr("Cut, copy, delete, rename, paste and send files")+"<br/>");
78     helpText.append(tr("commands can be found from context menu (click and hold on maemo).")+"<br/>");
79     helpText.append(tr("To select files, use ctrl and shift")+"<br/>");
80     QMessageBox::about(this, tr("Help"),
81                        helpText);
82 }
83 void MainWindow::showAbout()
84 {
85     QString about;
86     about.append("<h2>CuteExplorer</h2>");
87     about.append(tr("<p>Version %1<br/>").arg(QString(CUTE_VERSION)));
88     about.append(tr("Using Qt %1<br/>").arg(QString(QT_VERSION_STR)));
89     about.append(tr("Copyright") + " 2010 Tommi \"tomma\" Asp &lt;tomma.asp@gmail.com&gt;<br/>");
90
91     about.append(tr("<p>CuteExplorer is file manager mainly for maemo5.<br/>"));
92     about.append(tr("This is still under development so please visit<br/>"));
93     about.append(tr("<a href=http://cuteexplorer.garage.maemo.org>http://cuteexplorer.garage.maemo.org</a><br/>"));
94     about.append(tr("to report bugs or leave feature requests. Thanks!</p>"));
95
96     QMessageBox::about(this, tr("About CuteExplorer"),
97                        about);
98 }
99