5673d64efaf1053dac8c8001638e16dd521c954b
[cuteexplorer] / 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     ui->actionExit->setShortcut(QKeySequence::Quit);
28
29     ui->actionCopy->setShortcut(QKeySequence::Copy);
30     ui->actionCut->setShortcut(QKeySequence::Cut);
31     ui->actionPaste->setShortcut(QKeySequence::Paste);
32     ui->actionDelete->setShortcut(QKeySequence("Ctrl+D"));
33     ui->actionRename->setShortcut(QKeySequence("Ctrl+R"));
34     ui->actionSend->setShortcut(QKeySequence::Save);
35     ui->fileListWidget->addAction(ui->actionCopy);
36     ui->fileListWidget->addAction(ui->actionCut);
37     ui->fileListWidget->addAction(ui->actionPaste);
38     ui->fileListWidget->addAction(ui->actionDelete);
39     ui->fileListWidget->addAction(ui->actionRename);
40     ui->fileListWidget->addAction(ui->actionSend);
41 }
42
43 MainWindow::~MainWindow()
44 {
45     delete ui;
46 }
47
48 void MainWindow::locationLineEnterKeyHandler()
49 {
50     ui->fileListWidget->changePath(ui->locationLine->text());
51 }
52 void MainWindow::keyPressEvent(QKeyEvent *e)
53 {
54     if(e->key() == Qt::Key_Control || e->key() == Qt::Key_Shift)
55         ui->fileListWidget->setSelectMode(true);
56     else
57         QMainWindow::keyPressEvent(e);
58 }
59 void MainWindow::keyReleaseEvent(QKeyEvent *e)
60 {
61     if(e->key() == Qt::Key_Control || e->key() == Qt::Key_Shift)
62         ui->fileListWidget->setSelectMode(false);
63     else
64         QMainWindow::keyPressEvent(e);
65 }
66
67 void MainWindow::changeEvent(QEvent *e)
68 {
69     QMainWindow::changeEvent(e);
70     switch (e->type()) {
71     case QEvent::LanguageChange:
72         ui->retranslateUi(this);
73         break;
74     default:
75         break;
76     }
77 }
78
79 void MainWindow::showHelp()
80 {
81     QString helpText;
82
83     helpText.append("<h2>CuteExplorer "+tr("Help") +"</h2>");
84     helpText.append("<p>"+ tr("Cut, copy, delete, rename, paste and send files")+"<br/>");
85     helpText.append(tr("commands can be found from context menu (click and hold on maemo).")+"<br/>");
86     helpText.append(tr("To select files, use ctrl and shift")+"<br/>");
87     QMessageBox::about(this, tr("Help"),
88                        helpText);
89 }
90 void MainWindow::showAbout()
91 {
92     QString about;
93     about.append("<h2>CuteExplorer</h2>");
94     about.append(tr("<p>Version %1<br/>").arg(QString(CUTE_VERSION)));
95     about.append(tr("Using Qt %1<br/>").arg(QString(QT_VERSION_STR)));
96     about.append(tr("Copyright") + " 2010 Tommi \"tomma\" Asp &lt;tomma.asp@gmail.com&gt;<br/>");
97
98     about.append(tr("<p>CuteExplorer is file manager mainly for maemo5.<br/>"));
99     about.append(tr("This is still under development so please visit<br/>"));
100     about.append(tr("<a href=http://cuteexplorer.garage.maemo.org>http://cuteexplorer.garage.maemo.org</a><br/>"));
101     about.append(tr("to report bugs or leave feature requests. Thanks!</p>"));
102
103     QMessageBox::about(this, tr("About CuteExplorer"),
104                        about);
105 }
106