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 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
55 inoutLay->addWidget(mInputRequester, 0, 1); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
56 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
57 auto outLabel = new QLabel(tr("Export Folder:")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
58 inoutLay->addWidget(outLabel, 1, 0); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 mOutRequester = new FileNameRequester(QDir::Dirs); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
60 mOutRequester->setExistingOnly(false); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
61 inoutLay->addWidget(mOutRequester, 1, 1); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
62 outLabel->setBuddy(mOutRequester); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 vLay->addLayout(inoutLay); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
65 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
66 auto optionsGrp = new QGroupBox("Export Options:"); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
67 auto optionsLay = new QVBoxLayout; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
68 mPdfChk = new QCheckBox(tr("PDF")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
69 mPdfChk->setToolTip(tr("Convert into PDF Format.")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
70 mHtmlChk = new QCheckBox(tr("HTML")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
71 mHtmlChk->setToolTip(tr("Convert into HTML Format.")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
72 mXlsxChk = new QCheckBox(tr("XLSX")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
73 mXlsxChk->setToolTip(tr("Convert into XLSX Format.")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
74 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
75 optionsLay->addWidget(mPdfChk); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
76 optionsLay->addWidget(mHtmlChk); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
77 optionsLay->addWidget(mXlsxChk); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 optionsGrp->setLayout(optionsLay); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 vLay->addWidget(optionsGrp); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
80 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
81 mTitleEdit = new QLineEdit; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 auto titleLay = new QHBoxLayout; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
83 auto titleLabel = new QLabel(QStringLiteral("<small>") + tr("mandatory") + |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
84 QStringLiteral("</small>")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
85 mTitleEdit->setPlaceholderText(tr("Title (e.g. Feedback Questions SS2016)")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 titleLay->addWidget(mTitleEdit); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
87 titleLay->addWidget(titleLabel); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
88 vLay->addLayout(titleLay); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
89 vLay->addStretch(1); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
90 auto btns = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
91 mConvertBtn = btns->button(QDialogButtonBox::Ok); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
92 mConvertBtn->setText(tr("Convert")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
93 vLay->addWidget(btns); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
94 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
95 auto widget = new QWidget; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
96 widget->setLayout(vLay); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
97 setCentralWidget(widget); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
98 checkCompleted(); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
99 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
100 connect(mConvertBtn, &QPushButton::clicked, this, &MainWindow::doConvert); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
101 connect(mPdfChk, &QCheckBox::stateChanged, this, &MainWindow::checkCompleted); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
102 connect(mHtmlChk, &QCheckBox::stateChanged, this, &MainWindow::checkCompleted); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
103 connect(mXlsxChk, &QCheckBox::stateChanged, this, &MainWindow::checkCompleted); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
104 connect(mTitleEdit, &QLineEdit::textChanged, this, &MainWindow::checkCompleted); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
105 connect(mInputRequester, &FileNameRequester::fileNameChanged, this, &MainWindow::checkCompleted); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
106 connect(mOutRequester, &FileNameRequester::fileNameChanged, this, &MainWindow::checkCompleted); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
107 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
108 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
109 void MainWindow::showErrorMessage(const QString& errMsg) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
110 QMessageBox::warning(this, tr("Error!"), errMsg); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
111 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
112 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
113 void MainWindow::closeEvent(QCloseEvent *event) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
114 mSettings.setValue("geometry", saveGeometry()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
115 mSettings.setValue("windowState", saveState()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
116 QMainWindow::closeEvent(event); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
117 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
118 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
119 void MainWindow::readSettings() { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
120 if (mSettings.contains("geometry")) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
121 restoreGeometry(mSettings.value("geometry").toByteArray()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
122 restoreState(mSettings.value("windowState").toByteArray()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
123 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
124 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
125 setInputFile(mSettings.value("lastInput", |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
126 QStandardPaths::writableLocation(DEFAULT_DIR)).toString()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
127 mOutRequester->setFileName(mSettings.value("lastOutput", |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
128 QStandardPaths::writableLocation(DEFAULT_DIR)).toString()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
129 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
130 mPdfChk->setChecked(mSettings.value("pdfChk", true).toBool()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
131 mHtmlChk->setChecked(mSettings.value("htmlChk", false).toBool()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
132 mXlsxChk->setChecked(mSettings.value("xlsxChk", false).toBool()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
133 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
134 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
135 void MainWindow::setInputFile(const QString& file) |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
136 { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
137 mInputRequester->setFileName(file); |
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::setTitle(const QString& title) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
141 mTitleEdit->setText(title); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
142 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
143 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
144 void MainWindow::checkCompleted() { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
145 if (!mTitleEdit->text().isEmpty() && |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
146 (mPdfChk->isChecked() || mXlsxChk->isChecked() || mHtmlChk->isChecked())) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
147 mConvertBtn->setEnabled(true); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
148 } else { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
149 mConvertBtn->setEnabled(false); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
150 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
151 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
152 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
153 void MainWindow::doConvert() { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
154 /* Construct output names */ |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
155 QStringList outNames; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
156 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
157 QDir outDir(mOutRequester->fileName()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
158 if (!outDir.exists() && !outDir.mkpath(mOutRequester->fileName())) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
159 showErrorMessage(tr("Failed to create output directory.")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
160 return; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
161 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
162 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
163 const QFileInfo fi(mInputRequester->fileName()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
164 if (!fi.exists() || !fi.isReadable()) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
165 showErrorMessage(tr("Failed to open \"%1\" for reading.").arg(mInputRequester->fileName())); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
166 return; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
167 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
168 if (mPdfChk->isChecked()) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
169 outNames << outDir.absoluteFilePath(fi.baseName() + QStringLiteral(".pdf")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
170 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
171 if (mHtmlChk->isChecked()) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
172 outNames << outDir.absoluteFilePath(fi.baseName() + QStringLiteral(".html")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
173 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
174 if (mXlsxChk->isChecked()) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
175 outNames << outDir.absoluteFilePath(fi.baseName() + QStringLiteral(".xslx")); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
176 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
177 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
178 QStringList cleanedNames; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
179 foreach (const QString &name, outNames) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
180 const QFileInfo fi2(name); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
181 if (!fi2.exists()) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
182 cleanedNames << name; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
183 continue; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
184 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
185 /* File exists. Lets try a number. */ |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
186 bool replacementFound = false; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
187 for (int i = 1; i < MAX_FILENAME_COUNT; i++) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
188 const QString newName = outDir.absoluteFilePath(QStringLiteral("%1_%2.%3").arg( |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
189 fi2.baseName()).arg(i).arg(fi2.suffix())); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
190 const QFileInfo fi3(newName); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
191 if (!fi3.exists()) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
192 qDebug() << "Using " << newName << " as replacement because other files exist."; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
193 cleanedNames << newName; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
194 replacementFound = true; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
195 break; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
196 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
197 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
198 if (!replacementFound) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
199 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
|
200 return; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
201 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
202 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
203 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
204 mSettings.setValue("lastInput", mInputRequester->fileName()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
205 mSettings.setValue("lastOutput", mOutRequester->fileName()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
206 mSettings.setValue("pdfChk", mPdfChk->isChecked()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
207 mSettings.setValue("xlsxChk", mXlsxChk->isChecked()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
208 mSettings.setValue("htmlChk", mHtmlChk->isChecked()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
209 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
210 /* Convert away */ |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
211 Converter conv(mInputRequester->fileName(), cleanedNames, mTitleEdit->text()); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
212 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
213 conv.start(); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
214 hide(); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
215 qDebug() << "Waiting for conversion."; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
216 conv.wait(); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
217 qDebug() << "Conversion done."; |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
218 const QStringList errors = conv.errors(); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
219 if (!errors.isEmpty()) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
220 Q_FOREACH (const QString err, errors) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
221 showErrorMessage(err); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
222 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
223 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
224 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
225 if (cleanedNames.size() == 1) { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
226 qDebug() << "Opening: " << QUrl(QStringLiteral("file:///%1").arg(cleanedNames[0]), QUrl::TolerantMode); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
227 QDesktopServices::openUrl(QUrl(QStringLiteral("file:///%1").arg(cleanedNames[0]), QUrl::TolerantMode)); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
228 } else { |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
229 qDebug() << "Opening: " << QUrl(QStringLiteral("file:///%1").arg(outDir.path()), QUrl::TolerantMode); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
230 QDesktopServices::openUrl(QUrl(QStringLiteral("file:///%1").arg(outDir.path()), QUrl::TolerantMode)); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
231 } |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
232 |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
233 close(); |
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
234 } |