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