UI: Add OptionsController.

This commit is contained in:
Nodir Temirkhodjaev 2019-12-18 15:15:07 +05:00
parent 3a07701b84
commit 60a3d88773
16 changed files with 378 additions and 14 deletions

View File

@ -21,6 +21,7 @@ SOURCES += \
form/graph/axistickerspeed.cpp \ form/graph/axistickerspeed.cpp \
form/graph/graphplot.cpp \ form/graph/graphplot.cpp \
form/graph/graphwindow.cpp \ form/graph/graphwindow.cpp \
form/opt/optionscontroller.cpp \
form/opt/optionswindow.cpp \ form/opt/optionswindow.cpp \
fortcommon.cpp \ fortcommon.cpp \
fortmanager.cpp \ fortmanager.cpp \
@ -97,6 +98,7 @@ HEADERS += \
form/graph/axistickerspeed.h \ form/graph/axistickerspeed.h \
form/graph/graphplot.h \ form/graph/graphplot.h \
form/graph/graphwindow.h \ form/graph/graphwindow.h \
form/opt/optionscontroller.h \
form/opt/optionswindow.h \ form/opt/optionswindow.h \
fortcommon.h \ fortcommon.h \
fortmanager.h \ fortmanager.h \

View File

@ -0,0 +1,99 @@
#include "optionscontroller.h"
#include "../../fortmanager.h"
#include "../../fortsettings.h"
OptionsController::OptionsController(FortManager *fortManager,
QObject *parent) :
QObject(parent),
m_confFlagsEdited(false),
m_confEdited(false),
m_othersEdited(false),
m_fortManager(fortManager)
{
}
void OptionsController::setConfFlagsEdited(bool v)
{
if (m_confFlagsEdited != v) {
m_confFlagsEdited = v;
emit editedChanged();
}
}
void OptionsController::setConfEdited(bool v)
{
if (m_confEdited != v) {
m_confEdited = v;
emit editedChanged();
}
}
void OptionsController::setOthersEdited(bool v)
{
if (m_othersEdited != v) {
m_othersEdited = v;
emit editedChanged();
}
}
void OptionsController::resetEdited()
{
setConfFlagsEdited(false);
setConfEdited(false);
setOthersEdited(false);
emit editResetted();
}
void OptionsController::initialize()
{
// Settings/configuration was migrated?
if (fortSettings()->confMigrated()) {
setConfEdited(true);
}
}
FortSettings *OptionsController::fortSettings()
{
return m_fortManager->fortSettings();
}
TaskManager *OptionsController::taskManager()
{
return m_fortManager->taskManager();
}
void OptionsController::closeWindow()
{
m_fortManager->closeOptionsWindow();
}
void OptionsController::save(bool closeOnSuccess)
{
fortSettings()->bulkUpdateBegin();
emit aboutToSave();
bool confSaved = true;
if (confFlagsEdited() || confEdited()) {
const bool confFlagsOnly = confFlagsEdited() && !confEdited();
confSaved = closeOnSuccess
? m_fortManager->saveConf(confFlagsOnly)
: m_fortManager->applyConf(confFlagsOnly);
}
if (confSaved && othersEdited()) {
emit saved();
}
fortSettings()->bulkUpdateEnd();
if (confSaved) {
if (closeOnSuccess) {
closeWindow();
} else {
resetEdited();
}
}
}

View File

@ -0,0 +1,58 @@
#ifndef OPTIONSCONTROLLER_H
#define OPTIONSCONTROLLER_H
#include <QObject>
QT_FORWARD_DECLARE_CLASS(FortManager)
QT_FORWARD_DECLARE_CLASS(FortSettings)
QT_FORWARD_DECLARE_CLASS(TaskManager)
class OptionsController : public QObject
{
Q_OBJECT
public:
explicit OptionsController(FortManager *fortManager,
QObject *parent = nullptr);
bool confFlagsEdited() const { return m_confFlagsEdited; }
void setConfFlagsEdited(bool v);
bool confEdited() const { return m_confEdited; }
void setConfEdited(bool v);
bool othersEdited() const { return m_othersEdited; }
void setOthersEdited(bool v);
void resetEdited();
void initialize();
FortSettings *fortSettings();
TaskManager *taskManager();
signals:
void editedChanged();
void editResetted();
void aboutToSave();
void saved();
public slots:
void closeWindow();
void saveChanges() { save(true); }
void applyChanges() { save(false); }
private:
void save(bool closeOnSuccess);
private:
uint m_confFlagsEdited : 1;
uint m_confEdited : 1;
uint m_othersEdited : 1;
FortManager *m_fortManager = nullptr;
};
#endif // OPTIONSCONTROLLER_H

View File

@ -1,15 +1,38 @@
#include "optionswindow.h" #include "optionswindow.h"
#include <QCloseEvent>
#include <QDesktopServices>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QIcon> #include <QIcon>
#include <QKeyEvent>
#include <QPushButton>
#include <QStackedLayout>
#include <QTabBar> #include <QTabBar>
#include <QToolButton>
#include <QVBoxLayout> #include <QVBoxLayout>
OptionsWindow::OptionsWindow(QWidget *parent) : #include "../../fortsettings.h"
WidgetWindow(parent) #include "../../task/taskmanager.h"
#include "../../task/taskinfoupdatechecker.h"
namespace {
bool openUrlExternally(const QUrl &url)
{
return QDesktopServices::openUrl(url);
}
}
OptionsWindow::OptionsWindow(FortManager *fortManager,
QWidget *parent) :
WidgetWindow(parent),
m_ctrl(fortManager)
{ {
setupUi(); setupUi();
retranslateUi(); retranslateUi();
ctrl()->initialize();
} }
void OptionsWindow::setupUi() void OptionsWindow::setupUi()
@ -18,6 +41,7 @@ void OptionsWindow::setupUi()
layout->setContentsMargins(2, 2, 2, 2); layout->setContentsMargins(2, 2, 2, 2);
//layout->setMargin(0); //layout->setMargin(0);
// Main Tab Bar
m_tabBar = new QTabBar(); m_tabBar = new QTabBar();
m_tabBar->addTab(QIcon(":/images/cog.png"), QString()); m_tabBar->addTab(QIcon(":/images/cog.png"), QString());
m_tabBar->addTab(QIcon(":/images/link.png"), QString()); m_tabBar->addTab(QIcon(":/images/link.png"), QString());
@ -27,9 +51,73 @@ void OptionsWindow::setupUi()
m_tabBar->addTab(QIcon(":/images/clock.png"), QString()); m_tabBar->addTab(QIcon(":/images/clock.png"), QString());
layout->addWidget(m_tabBar); layout->addWidget(m_tabBar);
m_stackLayout = new QStackedLayout();
layout->addLayout(m_stackLayout);
// Dialog butons
auto buttonsLayout = setupDialogButtons();
layout->addLayout(buttonsLayout);
this->setLayout(layout); this->setLayout(layout);
} }
QLayout *OptionsWindow::setupDialogButtons()
{
auto buttonsLayout = new QHBoxLayout();
buttonsLayout->setContentsMargins(2, 2, 2, 2);
m_logsButton = createLinkButton(":/images/folder_error.png", fortSettings()->logsPath());
m_profileButton = createLinkButton(":/images/folder_user.png", fortSettings()->profilePath());
m_statButton = createLinkButton(":/images/folder_database.png", fortSettings()->statPath());
m_releasesButton = createLinkButton(":/images/server_go.png", fortSettings()->appUpdatesUrl());
m_newVersionButton = createLinkButton(":/images/server_compressed.png");
connect(m_logsButton, &QAbstractButton::clicked, this, &OptionsWindow::onLinkClicked);
connect(m_profileButton, &QAbstractButton::clicked, this, &OptionsWindow::onLinkClicked);
connect(m_statButton, &QAbstractButton::clicked, this, &OptionsWindow::onLinkClicked);
connect(m_releasesButton, &QAbstractButton::clicked, this, &OptionsWindow::onLinkClicked);
connect(m_newVersionButton, &QAbstractButton::clicked, this, &OptionsWindow::onLinkClicked);
setupNewVersionButton();
buttonsLayout->addWidget(m_logsButton);
buttonsLayout->addWidget(m_profileButton);
buttonsLayout->addWidget(m_statButton);
buttonsLayout->addWidget(m_releasesButton);
buttonsLayout->addWidget(m_newVersionButton);
buttonsLayout->addStretch(1);
m_okButton = new QPushButton(QIcon(":/images/tick.png"), QString());
m_applyButton = new QPushButton(QIcon(":/images/accept.png"), QString());
m_cancelButton = new QPushButton(QIcon(":/images/cancel.png"), QString());
connect(m_okButton, &QAbstractButton::clicked, ctrl(), &OptionsController::saveChanges);
connect(m_applyButton, &QAbstractButton::clicked, ctrl(), &OptionsController::applyChanges);
connect(m_cancelButton, &QAbstractButton::clicked, ctrl(), &OptionsController::closeWindow);
buttonsLayout->addWidget(m_okButton);
buttonsLayout->addWidget(m_applyButton);
buttonsLayout->addWidget(m_cancelButton);
return buttonsLayout;
}
void OptionsWindow::setupNewVersionButton()
{
auto updateChecker = taskManager()->taskInfoUpdateChecker();
const auto refreshNewVersionButton = [&] {
m_newVersionButton->setVisible(!updateChecker->version().isEmpty());
m_newVersionButton->setWindowFilePath(updateChecker->downloadUrl());
m_newVersionButton->setToolTip(updateChecker->releaseText());
};
refreshNewVersionButton();
connect(updateChecker, &TaskInfoUpdateChecker::versionChanged, this, refreshNewVersionButton);
}
void OptionsWindow::retranslateUi() void OptionsWindow::retranslateUi()
{ {
m_tabBar->setTabText(0, tr("Options")); m_tabBar->setTabText(0, tr("Options"));
@ -38,4 +126,58 @@ void OptionsWindow::retranslateUi()
m_tabBar->setTabText(3, tr("Programs")); m_tabBar->setTabText(3, tr("Programs"));
m_tabBar->setTabText(4, tr("Statistics")); m_tabBar->setTabText(4, tr("Statistics"));
m_tabBar->setTabText(5, tr("Schedule")); m_tabBar->setTabText(5, tr("Schedule"));
m_logsButton->setText(tr("Logs"));
m_profileButton->setText(tr("Profile"));
m_statButton->setText(tr("Statistics"));
m_releasesButton->setText(tr("Releases"));
m_newVersionButton->setText(tr("New Version!"));
m_okButton->setText(tr("OK"));
m_applyButton->setText(tr("Apply"));
m_cancelButton->setText(tr("Cancel"));
}
void OptionsWindow::closeEvent(QCloseEvent *event)
{
if (isVisible()) {
event->ignore();
ctrl()->closeWindow();
}
}
void OptionsWindow::keyReleaseEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape
&& event->modifiers() == Qt::NoModifier) {
ctrl()->closeWindow();
}
}
FortSettings *OptionsWindow::fortSettings()
{
return ctrl()->fortSettings();
}
TaskManager *OptionsWindow::taskManager()
{
return ctrl()->taskManager();
}
void OptionsWindow::onLinkClicked()
{
auto button = qobject_cast<QAbstractButton *>(sender());
if (button) {
openUrlExternally(QUrl::fromLocalFile(button->windowFilePath()));
}
}
QAbstractButton *OptionsWindow::createLinkButton(const QString &iconPath,
const QString &linkPath,
const QString &toolTip)
{
auto button = new QPushButton(QIcon(iconPath), QString());
button->setWindowFilePath(linkPath);
button->setToolTip(!toolTip.isEmpty() ? toolTip : linkPath);
return button;
} }

View File

@ -2,7 +2,11 @@
#define OPTIONSWINDOW_H #define OPTIONSWINDOW_H
#include "../../util/window/widgetwindow.h" #include "../../util/window/widgetwindow.h"
#include "optionscontroller.h"
QT_FORWARD_DECLARE_CLASS(QAbstractButton)
QT_FORWARD_DECLARE_CLASS(QPushButton)
QT_FORWARD_DECLARE_CLASS(QStackedLayout)
QT_FORWARD_DECLARE_CLASS(QTabBar) QT_FORWARD_DECLARE_CLASS(QTabBar)
class OptionsWindow : public WidgetWindow class OptionsWindow : public WidgetWindow
@ -10,18 +14,50 @@ class OptionsWindow : public WidgetWindow
Q_OBJECT Q_OBJECT
public: public:
explicit OptionsWindow(QWidget *parent = nullptr); explicit OptionsWindow(FortManager *fortManager,
QWidget *parent = nullptr);
signals: signals:
public slots: public slots:
void retranslateUi(); void retranslateUi();
private: private slots:
void setupUi(); void onLinkClicked();
protected:
void closeEvent(QCloseEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
private: private:
OptionsController *ctrl() { return &m_ctrl; }
void setupUi();
QLayout *setupDialogButtons();
void setupNewVersionButton();
FortSettings *fortSettings();
TaskManager *taskManager();
static QAbstractButton *createLinkButton(const QString &iconPath,
const QString &linkPath = QString(),
const QString &toolTip = QString());
private:
OptionsController m_ctrl;
QTabBar *m_tabBar = nullptr; QTabBar *m_tabBar = nullptr;
QStackedLayout *m_stackLayout = nullptr;
QAbstractButton *m_logsButton = nullptr;
QAbstractButton *m_profileButton = nullptr;
QAbstractButton *m_statButton = nullptr;
QAbstractButton *m_releasesButton = nullptr;
QAbstractButton *m_newVersionButton = nullptr;
QPushButton *m_okButton = nullptr;
QPushButton *m_applyButton = nullptr;
QPushButton *m_cancelButton = nullptr;
}; };
#endif // OPTIONSWINDOW_H #endif // OPTIONSWINDOW_H

View File

@ -0,0 +1,6 @@
#include "optionspage.h"
OptionsPage::OptionsPage(QObject *parent) : QObject(parent)
{
}

View File

@ -0,0 +1,16 @@
#ifndef OPTIONSPAGE_H
#define OPTIONSPAGE_H
#include <QObject>
class OptionsPage : public QObject
{
Q_OBJECT
public:
explicit OptionsPage(QObject *parent = nullptr);
signals:
};
#endif // OPTIONSPAGE_H

View File

@ -22,7 +22,10 @@
<file>images/cross.png</file> <file>images/cross.png</file>
<file>images/cut.png</file> <file>images/cut.png</file>
<file>images/database_save.png</file> <file>images/database_save.png</file>
<file>images/folder_database.png</file>
<file>images/folder_error.png</file>
<file>images/folder_explore.png</file> <file>images/folder_explore.png</file>
<file>images/folder_user.png</file>
<file>images/link.png</file> <file>images/link.png</file>
<file>images/page_copy.png</file> <file>images/page_copy.png</file>
<file>images/page_paste.png</file> <file>images/page_paste.png</file>
@ -32,6 +35,8 @@
<file>images/resultset_next.png</file> <file>images/resultset_next.png</file>
<file>images/resultset_previous.png</file> <file>images/resultset_previous.png</file>
<file>images/run.png</file> <file>images/run.png</file>
<file>images/server_compressed.png</file>
<file>images/server_go.png</file>
<file>images/shield.png</file> <file>images/shield.png</file>
<file>images/sheild-96.png</file> <file>images/sheild-96.png</file>
<file>images/stripes-light.png</file> <file>images/stripes-light.png</file>

View File

@ -74,6 +74,10 @@ FortManager::FortManager(FortSettings *fortSettings,
m_taskManager(new TaskManager(this, this)), m_taskManager(new TaskManager(this, this)),
m_appInfoCache(new AppInfoCache(this)) m_appInfoCache(new AppInfoCache(this))
{ {
if (m_fortSettings->isPortable()) {
qputenv("QT_DISABLE_SHADER_DISK_CACHE", "1");
}
setupThreadPool(); setupThreadPool();
setupLogger(); setupLogger();
@ -235,11 +239,7 @@ void FortManager::setupAppInfoCache()
bool FortManager::setupOptionsWindow() bool FortManager::setupOptionsWindow()
{ {
if (m_fortSettings->isPortable()) { m_optWindow = new OptionsWindow(this);
qputenv("QT_DISABLE_SHADER_DISK_CACHE", "1");
}
m_optWindow = new OptionsWindow();
connect(TranslationManager::instance(), &TranslationManager::languageChanged, connect(TranslationManager::instance(), &TranslationManager::languageChanged,
m_optWindow, &OptionsWindow::retranslateUi); m_optWindow, &OptionsWindow::retranslateUi);

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

BIN
src/ui/images/server_go.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

View File

@ -50,13 +50,13 @@ int main(int argc, char *argv[])
return FORT_ERROR_INSTANCE; return FORT_ERROR_INSTANCE;
} }
FortManager fortManager(&fortSettings);
fortManager.launch();
// Process control requests from clients // Process control requests from clients
if (!controlManager.listen(&fortManager)) { if (!controlManager.listen(&fortManager)) {
return FORT_ERROR_CONTROL; return FORT_ERROR_CONTROL;
} }
FortManager fortManager(&fortSettings);
fortManager.launch();
return QApplication::exec(); return QApplication::exec();
} }

View File

@ -61,7 +61,7 @@ bool TaskUpdateChecker::parseBuffer(const QByteArray &buffer)
m_releaseNotes = map["body"].toString(); // ChangeLog m_releaseNotes = map["body"].toString(); // ChangeLog
// Cut release text from dashes // Cut release text from dashes
const int releaseDashesPos = m_releaseNotes.indexOf("---"); const int releaseDashesPos = m_releaseNotes.indexOf("\n---");
if (releaseDashesPos > 0) { if (releaseDashesPos > 0) {
m_releaseNotes.truncate(releaseDashesPos); m_releaseNotes.truncate(releaseDashesPos);
} }