Browse Source

added firstrun dialog

fiffty-50 4 years ago
parent
commit
e487a1fc3c

+ 25 - 7
main.cpp

@@ -16,31 +16,49 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "mainwindow.h"
+#include "src/gui/dialogues/firstrundialog.h"
 #include <QApplication>
 #include <QProcess>
 #include <QSettings>
+#include <QFileInfo>
 
-int main(int argc, char *argv[])
+const auto DATA_DIR = QLatin1String("data");
+/*!
+ * \brief setup checks if data folder and settings files exists.
+ * \return
+ */
+bool setup()
 {
+    if (!QDir(DATA_DIR).exists())
+        QDir().mkdir(DATA_DIR);
+
+    QDir      settingspath(DATA_DIR + QLatin1Char('/') + QCoreApplication::organizationName());
+    QString   settingsfile = QCoreApplication::applicationName() + QLatin1String(".ini");
+    QFileInfo check_file(settingspath,settingsfile);
 
+    return check_file.exists() && check_file.isFile();
+};
+
+int main(int argc, char *argv[])
+{
     QCoreApplication::setOrganizationName("openPilotLog");
     QCoreApplication::setOrganizationDomain("https://github.com/fiffty-50/openpilotlog");
     QCoreApplication::setApplicationName("openPilotLog");
 
-
-    if (!QDir("data").exists()) {
-        QDir().mkdir("data");
-    }
-    QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, "data");
+    QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, DATA_DIR);
     QSettings::setDefaultFormat(QSettings::IniFormat);
     QSettings settings;
 
     QApplication openPilotLog(argc, argv);
+    if(!setup()){
+        FirstRunDialog dialog;
+        dialog.exec();
+    }
+
 
     //Theming
     int selectedtheme = settings.value("main/theme").toInt();
     QDir::setCurrent("/themes");
-
     switch (selectedtheme) {
     case 1: {
         qDebug() << "main :: Loading light theme";

+ 3 - 0
openPilotLog.pro

@@ -28,6 +28,7 @@ SOURCES += \
     src/database/db.cpp \
     src/database/dbinfo.cpp \
     src/database/entry.cpp \
+    src/gui/dialogues/firstrundialog.cpp \
     src/gui/dialogues/newpilot.cpp \
     src/gui/dialogues/newtail.cpp \
     src/gui/widgets/aircraftwidget.cpp \
@@ -49,6 +50,7 @@ HEADERS += \
     src/database/db.h \
     src/database/dbinfo.h \
     src/database/entry.h \
+    src/gui/dialogues/firstrundialog.h \
     src/gui/dialogues/newpilot.h \
     src/gui/dialogues/newtail.h \
     src/gui/widgets/aircraftwidget.h \
@@ -60,6 +62,7 @@ HEADERS += \
 
 FORMS += \
     mainwindow.ui \
+    src/gui/dialogues/firstrundialog.ui \
     src/gui/dialogues/newpilot.ui \
     src/gui/dialogues/newtail.ui \
     src/gui/widgets/aircraftwidget.ui \

+ 27 - 0
src/gui/dialogues/firstrundialog.cpp

@@ -0,0 +1,27 @@
+#include "firstrundialog.h"
+#include "ui_firstrundialog.h"
+
+FirstRunDialog::FirstRunDialog(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::FirstRunDialog)
+{
+    ui->setupUi(this);
+
+    disregard();
+}
+
+FirstRunDialog::~FirstRunDialog()
+{
+    delete ui;
+}
+
+void FirstRunDialog::on_pushButton_clicked()
+{
+    accept();
+}
+
+void FirstRunDialog::disregard()
+{
+    //emit ui->pushButton->clicked();
+
+}

+ 26 - 0
src/gui/dialogues/firstrundialog.h

@@ -0,0 +1,26 @@
+#ifndef FIRSTRUNDIALOG_H
+#define FIRSTRUNDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+class FirstRunDialog;
+}
+
+class FirstRunDialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit FirstRunDialog(QWidget *parent = nullptr);
+    ~FirstRunDialog();
+
+private slots:
+    void on_pushButton_clicked();
+
+private:
+    Ui::FirstRunDialog *ui;
+    void disregard();
+};
+
+#endif // FIRSTRUNDIALOG_H

+ 45 - 0
src/gui/dialogues/firstrundialog.ui

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FirstRunDialog</class>
+ <widget class="QDialog" name="FirstRunDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>640</width>
+    <height>480</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QPushButton" name="pushButton">
+   <property name="geometry">
+    <rect>
+     <x>280</x>
+     <y>250</y>
+     <width>80</width>
+     <height>27</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>OK</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>170</x>
+     <y>200</y>
+     <width>304</width>
+     <height>19</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>First Run / Setup Dialog to be shown here.</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>