summaryrefslogtreecommitdiffhomepage
path: root/gui/new_file_dialog.h
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-10-30 08:34:40 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-10-30 08:39:33 +0100
commit2160e39a4f3d5198eafbb483671583a5a0b51eaa (patch)
tree2370dd4e9a7b43c204d175af3ab2a0ff5b33c41d /gui/new_file_dialog.h
parentaa066bdd4622d4f6824fee864f6be6806813f04d (diff)
rename gui directory
Diffstat (limited to 'gui/new_file_dialog.h')
-rw-r--r--gui/new_file_dialog.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/gui/new_file_dialog.h b/gui/new_file_dialog.h
new file mode 100644
index 00000000..3a35cf71
--- /dev/null
+++ b/gui/new_file_dialog.h
@@ -0,0 +1,50 @@
+#pragma once
+
+#include "ui_new_config.h"
+#include "opentrack/options.hpp"
+#include <QFile>
+#include <QRegExp>
+#include <QString>
+#include <QMessageBox>
+
+class new_file_dialog : public QDialog
+{
+ Q_OBJECT
+public:
+ new_file_dialog(QWidget* parent = 0) : QDialog(parent), ok(false)
+ {
+ ui.setupUi(this);
+ connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(ok_clicked()));
+ connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(cancel_clicked()));
+ setFixedSize(size());
+ }
+ bool is_ok(QString& name_)
+ {
+ name_ = name;
+ return ok;
+ }
+private:
+ Ui::UI_new_config ui;
+ bool ok;
+ QString name;
+private slots:
+ void cancel_clicked() { close(); }
+ void ok_clicked()
+ {
+ QString text = ui.lineEdit->text();
+ text = text.replace('/', "");
+ text = text.replace('\\', "");
+ if (text != "" && !text.endsWith(".ini"))
+ text += ".ini";
+ if (text == "" || text == ".ini" || QFile(options::group::ini_directory() + "/" + text).exists())
+ {
+ QMessageBox::warning(this,
+ "File exists", "This file already exists. Pick another name.",
+ QMessageBox::Ok, QMessageBox::NoButton);
+ return;
+ }
+ ok = true;
+ close();
+ name = text;
+ }
+};