Compare commits

..

3 Commits

3 changed files with 121 additions and 4 deletions

View File

@ -1,14 +1,21 @@
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "../../libs/GenericCore/genericcore.h"
#include <QCloseEvent>
#include <QMessageBox>
#include "data/settingshandler.h"
#include "genericcore.h"
static QString updateTextClean = "Do you want to update the application now?";
static QString updateTextDirty = "Do you want to save the tasks & update the application now?";
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow) {
ui->setupUi(this);
m_core = std::make_shared<GenericCore>();
m_core = new GenericCore();
/// application icon
const QString iconString = "://feature.png";
@ -21,11 +28,81 @@ MainWindow::MainWindow(QWidget* parent)
#else
setWindowIcon(QIcon(iconString));
#endif
/// TODO restore window geometry and state (& save it in closeEvent)
const QVariantMap settings = SettingsHandler::getSettings("GUI");
restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("windowState").toByteArray());
connect(m_core, &GenericCore::displayStatusMessage, this, &MainWindow::displayStatusMessage);
connect(this, &MainWindow::displayStatusMessage, this, &MainWindow::showStatusMessage);
connect(this, &MainWindow::checkForUpdates, this,
&MainWindow::on_actionCheck_for_update_triggered, Qt::QueuedConnection);
}
MainWindow::~MainWindow() { delete ui; }
MainWindow::~MainWindow() {
delete ui;
delete m_core;
}
void MainWindow::on_pushButton_clicked() {
const QString prefix("Backend provided by: ");
ui->label->setText(prefix + m_core->toString());
}
void MainWindow::showStatusMessage(const QString text) {
qInfo() << text;
ui->statusbar->showMessage(text);
}
void MainWindow::on_actionCheck_for_update_triggered() {
showStatusMessage("Checking for update...");
const bool updateAvailable = m_core->isApplicationUpdateAvailable();
if (updateAvailable) {
const QString text = isWindowModified() ? updateTextDirty : updateTextClean;
const QMessageBox::StandardButton clickedButton = QMessageBox::question(
this, tr("Update available."), text, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (clickedButton == QMessageBox::Yes) {
m_core->triggerApplicationUpdate();
close();
}
}
}
void MainWindow::closeEvent(QCloseEvent* event) {
if (isWindowModified()) {
QMessageBox msgBox;
msgBox.setWindowTitle(windowTitle() + " - Save dialog");
msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Save:
// TODO m_core->saveItems();
event->accept();
break;
case QMessageBox::Discard:
event->accept();
break;
case QMessageBox::Cancel:
event->ignore();
break;
default:
/// should never be reached
qCritical() << "unexpected switch case in closeEvent:" << ret;
event->ignore();
break;
}
} else {
event->accept();
}
if (event->isAccepted()) {
qInfo() << "Saving GUI settings...";
SettingsHandler::saveSettings({{"geometry", saveGeometry()}, {"windowState", saveState()}},
"GUI");
}
}

View File

@ -19,12 +19,22 @@ class MainWindow : public QMainWindow {
MainWindow(QWidget* parent = nullptr);
~MainWindow();
signals:
void displayStatusMessage(QString message);
void checkForUpdates();
protected:
void closeEvent(QCloseEvent* event) override;
private slots:
void showStatusMessage(const QString text);
void on_pushButton_clicked();
void on_actionCheck_for_update_triggered();
private:
Ui::MainWindow* ui;
std::shared_ptr<GenericCore> m_core;
GenericCore* m_core;
};
#endif // MAINWINDOW_H

View File

@ -40,8 +40,38 @@
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
<property name="title">
<string>&amp;File</string>
</property>
</widget>
<widget class="QMenu" name="menu_Edit">
<property name="title">
<string>&amp;Edit</string>
</property>
</widget>
<widget class="QMenu" name="menu_View">
<property name="title">
<string>&amp;View</string>
</property>
</widget>
<widget class="QMenu" name="menu_Help">
<property name="title">
<string>&amp;Help</string>
</property>
<addaction name="actionCheck_for_update"/>
</widget>
<addaction name="menu_File"/>
<addaction name="menu_Edit"/>
<addaction name="menu_View"/>
<addaction name="menu_Help"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionCheck_for_update">
<property name="text">
<string>Check for &amp;update</string>
</property>
</action>
</widget>
<resources/>
<connections/>