]> git.sven.stormbind.net Git - sven/vym.git/blob - src/zip-settings-dialog.cpp
New upstream version 2.9.22
[sven/vym.git] / src / zip-settings-dialog.cpp
1 #include "zip-settings-dialog.h"
2
3 #include <QDebug>
4 #include <QFileDialog>
5 #include <QString>
6
7 #include "file.h"
8
9 extern QString vymName;
10 extern QString zipToolPath;
11 extern QString unzipToolPath;
12 extern bool zipToolAvailable;
13 extern bool unzipToolAvailable;
14
15 ZipSettingsDialog::ZipSettingsDialog(QWidget *parent) : QDialog(parent)
16 {
17
18     ui.setupUi(this);
19     init();
20
21     QDialog::setWindowTitle("VYM - " +
22                             tr("zip settings", "dialog window title"));
23
24     connect(ui.zipToolPathLE, SIGNAL(textChanged(const QString &)), this,
25             SLOT(zipToolPathChanged()));
26     connect(ui.zipToolButton, SIGNAL(clicked()), this,
27             SLOT(zipToolButtonPressed()));
28     connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(accept()));
29
30 #if defined(Q_OS_WIN32)
31     ui.zipToolLabel->setText(tr("Path to 7z.exe", "zip tool settings dialog"));
32
33     ui.unzipToolPathLE->hide();
34     ui.unzipToolButton->hide();
35     ui.unzipToolStatusLabel->hide();
36     ui.unzipToolLabel->hide();
37 #else
38     connect(ui.unzipToolPathLE, SIGNAL(textChanged(const QString &)), this,
39             SLOT(unzipToolPathChanged()));
40     connect(ui.unzipToolButton, SIGNAL(clicked()), this,
41             SLOT(unzipToolButtonPressed()));
42 #endif
43 }
44
45 void ZipSettingsDialog::zipToolPathChanged()
46 {
47     zipToolPath = ui.zipToolPathLE->text();
48     updateCheckResults();
49 }
50
51 void ZipSettingsDialog::unzipToolPathChanged()
52 {
53     unzipToolPath = ui.unzipToolPathLE->text();
54     updateCheckResults();
55 }
56
57 void ZipSettingsDialog::zipToolButtonPressed()
58 {
59     QString filter;
60     QString text;
61
62 #if defined(Q_OS_WIN32)
63     filter = "Windows executable (*.exe);;";
64     text = QString(tr("Set path to 7z to zip/unzip files"));
65 #else
66     filter = "All (*);;";
67     text = QString(tr("Set path to zip files"));
68 #endif
69
70     QString fn = QFileDialog::getOpenFileName(
71         this, vymName + " - " + text + ":", zipToolPath, filter);
72
73     if (!fn.isEmpty()) {
74         zipToolPath = fn;
75         ui.zipToolPathLE->setText(fn);
76         updateCheckResults();
77     }
78 }
79
80 void ZipSettingsDialog::unzipToolButtonPressed()
81 {
82     QString filter;
83     QString text;
84
85 #if defined(Q_OS_WIN32)
86     // On windows we just use 7z for both zip/unzip
87     return;
88 #else
89     filter = "All (*);;";
90     text = QString(tr("Set path to unzip files"));
91 #endif
92
93     QString fn = QFileDialog::getOpenFileName(
94         this, vymName + " - " + text + ":", zipToolPath, filter);
95
96     if (!fn.isEmpty()) {
97         unzipToolPath = fn;
98         ui.unzipToolPathLE->setText(fn);
99         updateCheckResults();
100     }
101 }
102
103 void ZipSettingsDialog::init()
104 {
105     ui.zipToolPathLE->setText(zipToolPath);
106     ui.unzipToolPathLE->setText(unzipToolPath);
107     updateCheckResults();
108 }
109
110 void ZipSettingsDialog::updateCheckResults()
111 {
112     checkZipTool();
113     checkUnzipTool();
114     QString zipStatus;
115     if (zipToolAvailable)
116         zipStatus = QString(tr("Status: %1").arg("ok"));
117     else
118         zipStatus = QString(tr("Status: %1").arg("not ok"));
119     ui.zipToolStatusLabel->setText(zipStatus);
120
121     QString unzipStatus;
122     if (unzipToolAvailable)
123         unzipStatus = QString(tr("Status: %1").arg("ok"));
124     else
125         unzipStatus = QString(tr("Status: %1").arg("not ok"));
126     ui.unzipToolStatusLabel->setText(unzipStatus);
127 }