annotate src/mainwindow.cpp @ 67:9cb71d6eabc9

Added tag 1.2 for changeset fe55e1e5bbf2
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 26 Aug 2016 15:27:05 +0200
parents 94cac17fe5be
children
rev   line source
50
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2016 by ETH Zürich
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
3 *
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
6 * See LICENSE.txt for details.
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
7 */
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 /** @file See mainwindow.h */
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10 #include "mainwindow.h"
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 #include "constants.h"
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13 #include "converter.h"
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 #include "filenamerequester.h"
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 #include <QApplication>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17 #include <QCheckBox>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 #include <QDebug>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19 #include <QDialogButtonBox>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
20 #include <QDesktopServices>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21 #include <QDir>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22 #include <QGroupBox>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23 #include <QHBoxLayout>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 #include <QLabel>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 #include <QLineEdit>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 #include <QMessageBox>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 #include <QMimeData>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 #include <QPushButton>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 #include <QUrl>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30 #include <QStandardPaths>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31 #include <QStyle>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32 #include <QVBoxLayout>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 #include <QWidget>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 #include <QGridLayout>
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 MainWindow::MainWindow() {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37 setupGUI();
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38 readSettings();
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 #ifndef Q_OS_WIN
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 QIcon windowIcon = QIcon(ICON_NAME);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 setWindowIcon(windowIcon);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42 setWindowTitle(QStringLiteral(APPNAME));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 #endif
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
44 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
45
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 void MainWindow::setupGUI() {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 auto vLay = new QVBoxLayout;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 auto inoutLay = new QGridLayout;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 auto inputLabel = new QLabel(tr("Input File:"));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
50 inoutLay->addWidget(inputLabel, 0, 0);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
51 mInputRequester = new FileNameRequester(QDir::Files);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52 mInputRequester->setExistingOnly(true);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 inputLabel->setBuddy(mInputRequester);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54
53
a43d8cf2fa95 Various fixes and improvements. Fix windows packaging.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 50
diff changeset
55 setWindowTitle(QStringLiteral(PRETTY_NAME));
a43d8cf2fa95 Various fixes and improvements. Fix windows packaging.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 50
diff changeset
56
50
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57 inoutLay->addWidget(mInputRequester, 0, 1);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 auto outLabel = new QLabel(tr("Export Folder:"));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 inoutLay->addWidget(outLabel, 1, 0);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61 mOutRequester = new FileNameRequester(QDir::Dirs);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 mOutRequester->setExistingOnly(false);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63 inoutLay->addWidget(mOutRequester, 1, 1);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 outLabel->setBuddy(mOutRequester);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66 vLay->addLayout(inoutLay);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 auto optionsGrp = new QGroupBox("Export Options:");
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
69 auto optionsLay = new QVBoxLayout;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70 mPdfChk = new QCheckBox(tr("PDF"));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71 mPdfChk->setToolTip(tr("Convert into PDF Format."));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 mHtmlChk = new QCheckBox(tr("HTML"));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73 mHtmlChk->setToolTip(tr("Convert into HTML Format."));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74 mXlsxChk = new QCheckBox(tr("XLSX"));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 mXlsxChk->setToolTip(tr("Convert into XLSX Format."));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
76
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77 optionsLay->addWidget(mPdfChk);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 optionsLay->addWidget(mHtmlChk);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79 optionsLay->addWidget(mXlsxChk);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
80 optionsGrp->setLayout(optionsLay);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
81 vLay->addWidget(optionsGrp);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
82
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
83 mTitleEdit = new QLineEdit;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
84 auto titleLay = new QHBoxLayout;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
85 auto titleLabel = new QLabel(QStringLiteral("<small>") + tr("mandatory") +
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
86 QStringLiteral("</small>"));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
87 mTitleEdit->setPlaceholderText(tr("Title (e.g. Feedback Questions SS2016)"));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88 titleLay->addWidget(mTitleEdit);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 titleLay->addWidget(titleLabel);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
90 vLay->addLayout(titleLay);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
91 vLay->addStretch(1);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92 auto btns = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
93 mConvertBtn = btns->button(QDialogButtonBox::Ok);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
94 mConvertBtn->setText(tr("Convert"));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
95 vLay->addWidget(btns);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
96
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
97 auto widget = new QWidget;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
98 widget->setLayout(vLay);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
99 setCentralWidget(widget);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
100 checkCompleted();
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
101
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
102 connect(mConvertBtn, &QPushButton::clicked, this, &MainWindow::doConvert);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
103 connect(mPdfChk, &QCheckBox::stateChanged, this, &MainWindow::checkCompleted);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
104 connect(mHtmlChk, &QCheckBox::stateChanged, this, &MainWindow::checkCompleted);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
105 connect(mXlsxChk, &QCheckBox::stateChanged, this, &MainWindow::checkCompleted);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
106 connect(mTitleEdit, &QLineEdit::textChanged, this, &MainWindow::checkCompleted);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
107 connect(mInputRequester, &FileNameRequester::fileNameChanged, this, &MainWindow::checkCompleted);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108 connect(mOutRequester, &FileNameRequester::fileNameChanged, this, &MainWindow::checkCompleted);
53
a43d8cf2fa95 Various fixes and improvements. Fix windows packaging.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 50
diff changeset
109 connect(btns, &QDialogButtonBox::rejected, this, &QMainWindow::close);
50
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
110 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
111
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
112 void MainWindow::showErrorMessage(const QString& errMsg) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
113 QMessageBox::warning(this, tr("Error!"), errMsg);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
114 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
115
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
116 void MainWindow::closeEvent(QCloseEvent *event) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
117 mSettings.setValue("geometry", saveGeometry());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
118 mSettings.setValue("windowState", saveState());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
119 QMainWindow::closeEvent(event);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
120 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
121
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
122 void MainWindow::readSettings() {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
123 if (mSettings.contains("geometry")) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
124 restoreGeometry(mSettings.value("geometry").toByteArray());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
125 restoreState(mSettings.value("windowState").toByteArray());
53
a43d8cf2fa95 Various fixes and improvements. Fix windows packaging.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 50
diff changeset
126 } else {
64
94cac17fe5be GUI: Increase initial size of the mainwindow
Andre Heinecke <andre.heinecke@intevation.de>
parents: 60
diff changeset
127 resize(800, 300);
50
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
128 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
129
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
130 setInputFile(mSettings.value("lastInput",
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
131 QStandardPaths::writableLocation(DEFAULT_DIR)).toString());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
132 mOutRequester->setFileName(mSettings.value("lastOutput",
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
133 QStandardPaths::writableLocation(DEFAULT_DIR)).toString());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
134
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
135 mPdfChk->setChecked(mSettings.value("pdfChk", true).toBool());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
136 mHtmlChk->setChecked(mSettings.value("htmlChk", false).toBool());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
137 mXlsxChk->setChecked(mSettings.value("xlsxChk", false).toBool());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
138 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
139
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
140 void MainWindow::setInputFile(const QString& file)
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
141 {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
142 mInputRequester->setFileName(file);
53
a43d8cf2fa95 Various fixes and improvements. Fix windows packaging.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 50
diff changeset
143 QFileInfo fi(file);
a43d8cf2fa95 Various fixes and improvements. Fix windows packaging.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 50
diff changeset
144 mOutRequester->setFileName(fi.dir().path());
50
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
145 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
146
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
147 void MainWindow::setTitle(const QString& title) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
148 mTitleEdit->setText(title);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
149 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
150
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
151 void MainWindow::checkCompleted() {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
152 if (!mTitleEdit->text().isEmpty() &&
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
153 (mPdfChk->isChecked() || mXlsxChk->isChecked() || mHtmlChk->isChecked())) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
154 mConvertBtn->setEnabled(true);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
155 } else {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
156 mConvertBtn->setEnabled(false);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
157 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
158 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
159
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
160 void MainWindow::doConvert() {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
161 /* Construct output names */
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
162 QStringList outNames;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
163
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
164 QDir outDir(mOutRequester->fileName());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
165 if (!outDir.exists() && !outDir.mkpath(mOutRequester->fileName())) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
166 showErrorMessage(tr("Failed to create output directory."));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
167 return;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
168 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
169
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
170 const QFileInfo fi(mInputRequester->fileName());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
171 if (!fi.exists() || !fi.isReadable()) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
172 showErrorMessage(tr("Failed to open \"%1\" for reading.").arg(mInputRequester->fileName()));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
173 return;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
174 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
175 if (mPdfChk->isChecked()) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
176 outNames << outDir.absoluteFilePath(fi.baseName() + QStringLiteral(".pdf"));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
177 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
178 if (mHtmlChk->isChecked()) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
179 outNames << outDir.absoluteFilePath(fi.baseName() + QStringLiteral(".html"));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
180 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
181 if (mXlsxChk->isChecked()) {
60
82d38421fdf3 Fix file name defaults and xlsx extension
Andre Heinecke <andre.heinecke@intevation.de>
parents: 53
diff changeset
182 outNames << outDir.absoluteFilePath(fi.baseName() + QStringLiteral(".xlsx"));
50
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
183 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
184
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
185 QStringList cleanedNames;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
186 foreach (const QString &name, outNames) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
187 const QFileInfo fi2(name);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
188 if (!fi2.exists()) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
189 cleanedNames << name;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
190 continue;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
191 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
192 /* File exists. Lets try a number. */
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
193 bool replacementFound = false;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
194 for (int i = 1; i < MAX_FILENAME_COUNT; i++) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
195 const QString newName = outDir.absoluteFilePath(QStringLiteral("%1_%2.%3").arg(
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
196 fi2.baseName()).arg(i).arg(fi2.suffix()));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
197 const QFileInfo fi3(newName);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
198 if (!fi3.exists()) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
199 qDebug() << "Using " << newName << " as replacement because other files exist.";
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
200 cleanedNames << newName;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
201 replacementFound = true;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
202 break;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
203 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
204 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
205 if (!replacementFound) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
206 showErrorMessage(tr("Failed to find an available free name for \"%1\" please choose another folder.").arg(name));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
207 return;
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
208 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
209 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
210
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
211 mSettings.setValue("lastInput", mInputRequester->fileName());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
212 mSettings.setValue("lastOutput", mOutRequester->fileName());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
213 mSettings.setValue("pdfChk", mPdfChk->isChecked());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
214 mSettings.setValue("xlsxChk", mXlsxChk->isChecked());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
215 mSettings.setValue("htmlChk", mHtmlChk->isChecked());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
216
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
217 /* Convert away */
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
218 Converter conv(mInputRequester->fileName(), cleanedNames, mTitleEdit->text());
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
219
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
220 conv.start();
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
221 hide();
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
222 qDebug() << "Waiting for conversion.";
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
223 conv.wait();
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
224 qDebug() << "Conversion done.";
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
225 const QStringList errors = conv.errors();
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
226 if (!errors.isEmpty()) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
227 Q_FOREACH (const QString err, errors) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
228 showErrorMessage(err);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
229 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
230 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
231
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
232 if (cleanedNames.size() == 1) {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
233 qDebug() << "Opening: " << QUrl(QStringLiteral("file:///%1").arg(cleanedNames[0]), QUrl::TolerantMode);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
234 QDesktopServices::openUrl(QUrl(QStringLiteral("file:///%1").arg(cleanedNames[0]), QUrl::TolerantMode));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
235 } else {
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
236 qDebug() << "Opening: " << QUrl(QStringLiteral("file:///%1").arg(outDir.path()), QUrl::TolerantMode);
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
237 QDesktopServices::openUrl(QUrl(QStringLiteral("file:///%1").arg(outDir.path()), QUrl::TolerantMode));
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
238 }
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
239
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
240 close();
36ee5dd46fd3 Add GUI
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
241 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)