mirror of
https://github.com/tnodir/fort
synced 2024-11-15 09:59:38 +00:00
UI: ProgramsWindow: Add/edit end time of apps.
This commit is contained in:
parent
af8d9fbc87
commit
4e4ca1a6d5
@ -164,7 +164,7 @@ const char * const sqlDeleteAppAlert =
|
||||
|
||||
const char * const sqlUpdateApp =
|
||||
"UPDATE app"
|
||||
" SET app_group_id = ?2, blocked = ?3"
|
||||
" SET app_group_id = ?2, blocked = ?3, end_time = ?4"
|
||||
" WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
@ -420,7 +420,8 @@ end:
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfManager::updateApp(qint64 appId, int groupIndex, bool blocked)
|
||||
bool ConfManager::updateApp(qint64 appId, const QDateTime &endTime,
|
||||
int groupIndex, bool blocked)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
@ -429,7 +430,9 @@ bool ConfManager::updateApp(qint64 appId, int groupIndex, bool blocked)
|
||||
const QVariantList vars = QVariantList()
|
||||
<< appId
|
||||
<< appGroupIdByIndex(groupIndex)
|
||||
<< blocked;
|
||||
<< blocked
|
||||
<< endTime
|
||||
;
|
||||
|
||||
m_sqliteDb->executeEx(sqlUpdateApp, vars, 0, &ok);
|
||||
if (!ok) goto end;
|
||||
|
@ -52,7 +52,8 @@ public:
|
||||
bool addApp(const QString &appPath, const QDateTime &endTime,
|
||||
int groupIndex, bool blocked, bool alerted);
|
||||
bool deleteApp(qint64 appId);
|
||||
bool updateApp(qint64 appId, int groupIndex, bool blocked);
|
||||
bool updateApp(qint64 appId, const QDateTime &endTime,
|
||||
int groupIndex, bool blocked);
|
||||
bool walkApps(std::function<walkAppsCallback> func);
|
||||
|
||||
bool updateDriverConf(const FirewallConf &conf, bool onlyFlags = false);
|
||||
|
@ -77,8 +77,8 @@ void SchedulePage::retranslateTaskDetails()
|
||||
tr("Each 12 hours"), tr("Daily"), tr("Weekly"), tr("Monthly")
|
||||
};
|
||||
|
||||
m_lscTaskInterval->setNames(list);
|
||||
m_lscTaskInterval->spinBox()->setSuffix(tr(" hours"));
|
||||
m_cscTaskInterval->setNames(list);
|
||||
m_cscTaskInterval->spinBox()->setSuffix(tr(" hours"));
|
||||
}
|
||||
|
||||
void SchedulePage::setupTaskListModel()
|
||||
@ -152,25 +152,25 @@ void SchedulePage::setupTaskDetails()
|
||||
currentTaskInfo()->abort();
|
||||
});
|
||||
|
||||
layout->addWidget(m_lscTaskInterval, 1);
|
||||
layout->addWidget(m_cscTaskInterval, 1);
|
||||
layout->addWidget(m_btTaskRun);
|
||||
layout->addWidget(m_btTaskAbort);
|
||||
}
|
||||
|
||||
void SchedulePage::setupTaskInterval()
|
||||
{
|
||||
m_lscTaskInterval = new CheckSpinCombo();
|
||||
m_lscTaskInterval->checkBox()->setFont(ControlUtil::fontDemiBold());
|
||||
m_lscTaskInterval->spinBox()->setRange(1, 24 * 30 * 12); // ~Year
|
||||
m_lscTaskInterval->setValues(taskIntervalHourValues);
|
||||
m_cscTaskInterval = new CheckSpinCombo();
|
||||
m_cscTaskInterval->checkBox()->setFont(ControlUtil::fontDemiBold());
|
||||
m_cscTaskInterval->spinBox()->setRange(1, 24 * 30 * 12); // ~Year
|
||||
m_cscTaskInterval->setValues(taskIntervalHourValues);
|
||||
|
||||
connect(m_lscTaskInterval->checkBox(), &QCheckBox::toggled, [&](bool checked) {
|
||||
connect(m_cscTaskInterval->checkBox(), &QCheckBox::toggled, [&](bool checked) {
|
||||
const int taskIndex = currentTaskIndex();
|
||||
const auto index = taskListModel()->index(taskIndex, 0);
|
||||
|
||||
taskListModel()->setData(index, checked, TaskListModel::RoleEnabled);
|
||||
});
|
||||
connect(m_lscTaskInterval->spinBox(), QOverload<int>::of(&QSpinBox::valueChanged), [&](int value) {
|
||||
connect(m_cscTaskInterval->spinBox(), QOverload<int>::of(&QSpinBox::valueChanged), [&](int value) {
|
||||
const int taskIndex = currentTaskIndex();
|
||||
const auto index = taskListModel()->index(taskIndex, 1);
|
||||
|
||||
@ -192,11 +192,11 @@ void SchedulePage::setupTableTasksChanged()
|
||||
if (taskSelected) {
|
||||
const auto index = taskListModel()->index(taskIndex, 0);
|
||||
|
||||
m_lscTaskInterval->checkBox()->setChecked(
|
||||
m_cscTaskInterval->checkBox()->setChecked(
|
||||
taskListModel()->data(index, TaskListModel::RoleEnabled).toBool());
|
||||
m_lscTaskInterval->checkBox()->setText(
|
||||
m_cscTaskInterval->checkBox()->setText(
|
||||
taskListModel()->data(index).toString());
|
||||
m_lscTaskInterval->spinBox()->setValue(
|
||||
m_cscTaskInterval->spinBox()->setValue(
|
||||
taskListModel()->data(index, TaskListModel::RoleIntervalHours).toInt());
|
||||
|
||||
const bool running = currentTaskInfo()->running();
|
||||
|
@ -54,7 +54,7 @@ private:
|
||||
|
||||
TableView *m_tableTasks = nullptr;
|
||||
QWidget *m_taskDetailsRow = nullptr;
|
||||
CheckSpinCombo *m_lscTaskInterval = nullptr;
|
||||
CheckSpinCombo *m_cscTaskInterval = nullptr;
|
||||
QPushButton *m_btTaskRun = nullptr;
|
||||
QPushButton *m_btTaskAbort = nullptr;
|
||||
};
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QSpinBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "../../conf/appgroup.h"
|
||||
@ -22,10 +23,19 @@
|
||||
#include "../../util/app/appinfocache.h"
|
||||
#include "../../util/guiutil.h"
|
||||
#include "../../util/osutil.h"
|
||||
#include "../controls/checkspincombo.h"
|
||||
#include "../controls/controlutil.h"
|
||||
#include "../controls/tableview.h"
|
||||
#include "programscontroller.h"
|
||||
|
||||
namespace {
|
||||
|
||||
const ValuesList appBlockInHourValues = {
|
||||
3, 1, 6, 12, 24, 24 * 7, 24 * 30
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
ProgramsWindow::ProgramsWindow(FortManager *fortManager,
|
||||
QWidget *parent) :
|
||||
WidgetWindow(parent),
|
||||
@ -33,7 +43,6 @@ ProgramsWindow::ProgramsWindow(FortManager *fortManager,
|
||||
m_appListModel(ctrl()->appListModel())
|
||||
{
|
||||
setupController();
|
||||
setupAppListModel();
|
||||
|
||||
setupUi();
|
||||
|
||||
@ -50,10 +59,6 @@ void ProgramsWindow::setupController()
|
||||
this, &ProgramsWindow::onRestoreWindowState);
|
||||
}
|
||||
|
||||
void ProgramsWindow::setupAppListModel()
|
||||
{
|
||||
}
|
||||
|
||||
void ProgramsWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (isVisible()) {
|
||||
@ -96,6 +101,8 @@ void ProgramsWindow::onRetranslateUi()
|
||||
m_labelAppGroup->setText(tr("Application Group:"));
|
||||
m_rbAllowApp->setText(tr("Allow"));
|
||||
m_rbBlockApp->setText(tr("Block"));
|
||||
m_cscBlockApp->checkBox()->setText(tr("Block In"));
|
||||
retranslateAppBlockInHours();
|
||||
m_btEditOk->setText(tr("OK"));
|
||||
m_btEditCancel->setText(tr("Cancel"));
|
||||
|
||||
@ -107,6 +114,17 @@ void ProgramsWindow::onRetranslateUi()
|
||||
m_btAppOpenFolder->setToolTip(tr("Open Folder"));
|
||||
}
|
||||
|
||||
void ProgramsWindow::retranslateAppBlockInHours()
|
||||
{
|
||||
const QStringList list = {
|
||||
tr("Custom"), tr("1 hour"), tr("6 hours"),
|
||||
tr("12 hours"), tr("Day"), tr("Week"), tr("Month")
|
||||
};
|
||||
|
||||
m_cscBlockApp->setNames(list);
|
||||
m_cscBlockApp->spinBox()->setSuffix(tr(" hours"));
|
||||
}
|
||||
|
||||
void ProgramsWindow::setupUi()
|
||||
{
|
||||
auto layout = new QVBoxLayout();
|
||||
@ -157,24 +175,15 @@ QLayout *ProgramsWindow::setupHeader()
|
||||
m_btBlockApp = ControlUtil::createLinkButton(":/images/stop.png");
|
||||
|
||||
connect(m_btAddApp, &QAbstractButton::clicked, [&] {
|
||||
m_editPath->setText(QString());
|
||||
m_editPath->setReadOnly(false);
|
||||
m_btSelectFile->setEnabled(true);
|
||||
m_formAppEdit->show();
|
||||
const AppRow appRow;
|
||||
updateAppEditForm(appRow);
|
||||
});
|
||||
connect(m_btEditApp, &QAbstractButton::clicked, [&] {
|
||||
const auto appIndex = appListCurrentIndex();
|
||||
if (appIndex < 0)
|
||||
return;
|
||||
|
||||
if (appIndex >= 0) {
|
||||
const auto appRow = appListModel()->appRow(appIndex);
|
||||
|
||||
m_editPath->setText(appRow.appPath);
|
||||
m_editPath->setReadOnly(true);
|
||||
m_btSelectFile->setEnabled(false);
|
||||
m_comboAppGroup->setCurrentIndex(appRow.groupIndex);
|
||||
m_rbBlockApp->setChecked(appRow.blocked());
|
||||
m_formAppEdit->show();
|
||||
updateAppEditForm(appRow);
|
||||
}
|
||||
});
|
||||
connect(m_btDeleteApp, &QAbstractButton::clicked, [&] {
|
||||
if (!fortManager()->showQuestionBox(tr("Are you sure to remove the selected program?")))
|
||||
@ -244,6 +253,12 @@ void ProgramsWindow::setupAppEditForm()
|
||||
allowLayout->addWidget(m_rbAllowApp, 1, Qt::AlignRight);
|
||||
allowLayout->addWidget(m_rbBlockApp, 1, Qt::AlignLeft);
|
||||
|
||||
// Block after N hours
|
||||
m_cscBlockApp = new CheckSpinCombo();
|
||||
m_cscBlockApp->spinBox()->setRange(1, 24 * 30 * 12); // ~Year
|
||||
m_cscBlockApp->setValues(appBlockInHourValues);
|
||||
m_cscBlockApp->setNamesByValues();
|
||||
|
||||
// OK/Cancel
|
||||
auto buttonsLayout = new QHBoxLayout();
|
||||
|
||||
@ -257,10 +272,12 @@ void ProgramsWindow::setupAppEditForm()
|
||||
auto layout = new QVBoxLayout();
|
||||
layout->addLayout(formLayout);
|
||||
layout->addLayout(allowLayout);
|
||||
layout->addWidget(m_cscBlockApp);
|
||||
layout->addWidget(ControlUtil::createSeparator());
|
||||
layout->addLayout(buttonsLayout);
|
||||
|
||||
m_formAppEdit = new QDialog(this);
|
||||
m_formAppEdit->setWindowModality(Qt::WindowModal);
|
||||
m_formAppEdit->setSizeGripEnabled(true);
|
||||
m_formAppEdit->setLayout(layout);
|
||||
m_formAppEdit->setMinimumWidth(500);
|
||||
@ -275,6 +292,8 @@ void ProgramsWindow::setupAppEditForm()
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_rbAllowApp, &QRadioButton::toggled, m_cscBlockApp, &CheckSpinCombo::setEnabled);
|
||||
|
||||
connect(m_btEditOk, &QAbstractButton::clicked, [&] {
|
||||
const QString appPath = m_editPath->text();
|
||||
if (appPath.isEmpty())
|
||||
@ -283,7 +302,18 @@ void ProgramsWindow::setupAppEditForm()
|
||||
const int groupIndex = m_comboAppGroup->currentIndex();
|
||||
const bool blocked = m_rbBlockApp->isChecked();
|
||||
|
||||
if (appListModel()->updateApp(appListCurrentIndex(), groupIndex, blocked)) {
|
||||
QDateTime endTime;
|
||||
if (!blocked && m_cscBlockApp->checkBox()->isChecked()) {
|
||||
const int hours = m_cscBlockApp->spinBox()->value();
|
||||
|
||||
endTime = QDateTime::currentDateTime()
|
||||
.addSecs(hours * 60 * 60);
|
||||
}
|
||||
|
||||
if (m_formAppIsEditing
|
||||
? appListModel()->updateApp(appListCurrentIndex(),
|
||||
groupIndex, blocked, endTime)
|
||||
: appListModel()->addApp(appPath, groupIndex, blocked, endTime)) {
|
||||
m_formAppEdit->close();
|
||||
}
|
||||
});
|
||||
@ -419,6 +449,21 @@ void ProgramsWindow::setupTableAppsChanged()
|
||||
connect(m_appListView, &TableView::currentIndexChanged, this, refreshTableAppsChanged);
|
||||
}
|
||||
|
||||
void ProgramsWindow::updateAppEditForm(const AppRow &appRow)
|
||||
{
|
||||
m_formAppIsEditing = !appRow.appPath.isEmpty();
|
||||
|
||||
m_editPath->setText(appRow.appPath);
|
||||
m_editPath->setReadOnly(m_formAppIsEditing);
|
||||
m_btSelectFile->setEnabled(!m_formAppIsEditing);
|
||||
m_comboAppGroup->setCurrentIndex(appRow.groupIndex);
|
||||
m_rbAllowApp->setChecked(!appRow.blocked());
|
||||
m_rbBlockApp->setChecked(appRow.blocked());
|
||||
m_cscBlockApp->setEnabled(!appRow.blocked());
|
||||
m_cscBlockApp->checkBox()->setChecked(false);
|
||||
m_formAppEdit->show();
|
||||
}
|
||||
|
||||
int ProgramsWindow::appListCurrentIndex() const
|
||||
{
|
||||
return m_appListView->currentIndex().row();
|
||||
|
@ -13,12 +13,15 @@ QT_FORWARD_DECLARE_CLASS(QRadioButton)
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(AppInfoCache)
|
||||
QT_FORWARD_DECLARE_CLASS(AppListModel)
|
||||
QT_FORWARD_DECLARE_CLASS(CheckSpinCombo)
|
||||
QT_FORWARD_DECLARE_CLASS(FirewallConf)
|
||||
QT_FORWARD_DECLARE_CLASS(FortManager)
|
||||
QT_FORWARD_DECLARE_CLASS(FortSettings)
|
||||
QT_FORWARD_DECLARE_CLASS(ProgramsController)
|
||||
QT_FORWARD_DECLARE_CLASS(TableView)
|
||||
|
||||
QT_FORWARD_DECLARE_STRUCT(AppRow)
|
||||
|
||||
class ProgramsWindow : public WidgetWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -39,7 +42,8 @@ protected:
|
||||
|
||||
private:
|
||||
void setupController();
|
||||
void setupAppListModel();
|
||||
|
||||
void retranslateAppBlockInHours();
|
||||
|
||||
void setupUi();
|
||||
void setupAppEditForm();
|
||||
@ -51,6 +55,7 @@ private:
|
||||
void setupAppInfoRow();
|
||||
void setupAppInfoVersion();
|
||||
void setupTableAppsChanged();
|
||||
void updateAppEditForm(const AppRow &appRow);
|
||||
|
||||
int appListCurrentIndex() const;
|
||||
QString appListCurrentPath() const;
|
||||
@ -63,6 +68,8 @@ private:
|
||||
AppInfoCache *appInfoCache() const;
|
||||
|
||||
private:
|
||||
bool m_formAppIsEditing = false;
|
||||
|
||||
ProgramsController *m_ctrl = nullptr;
|
||||
|
||||
AppListModel *m_appListModel = nullptr;
|
||||
@ -79,6 +86,7 @@ private:
|
||||
QComboBox *m_comboAppGroup = nullptr;
|
||||
QRadioButton *m_rbAllowApp = nullptr;
|
||||
QRadioButton *m_rbBlockApp = nullptr;
|
||||
CheckSpinCombo *m_cscBlockApp = nullptr;
|
||||
QPushButton *m_btEditOk = nullptr;
|
||||
QPushButton *m_btEditCancel = nullptr;
|
||||
QDialog *m_formAppEdit = nullptr;
|
||||
|
@ -159,17 +159,19 @@ AppRow AppListModel::appRow(int row) const
|
||||
return m_rowCache;
|
||||
}
|
||||
|
||||
bool AppListModel::addApp(const QString &appPath, int groupIndex, bool blocked)
|
||||
bool AppListModel::addApp(const QString &appPath, int groupIndex, bool blocked,
|
||||
const QDateTime &endTime)
|
||||
{
|
||||
if (confManager()->updateDriverUpdateApp(appPath, groupIndex, false, blocked, false)
|
||||
&& confManager()->addApp(appPath, QDateTime(), groupIndex, blocked, false)) {
|
||||
&& confManager()->addApp(appPath, endTime, groupIndex, blocked, false)) {
|
||||
reset();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AppListModel::updateApp(int row, int groupIndex, bool blocked)
|
||||
bool AppListModel::updateApp(int row, int groupIndex, bool blocked,
|
||||
const QDateTime &endTime)
|
||||
{
|
||||
updateRowCache(row);
|
||||
|
||||
@ -177,7 +179,7 @@ bool AppListModel::updateApp(int row, int groupIndex, bool blocked)
|
||||
const QString appPath = m_rowCache.appPath;
|
||||
|
||||
if (confManager()->updateDriverUpdateApp(appPath, groupIndex, false, blocked, false)
|
||||
&& confManager()->updateApp(appId, groupIndex, blocked)) {
|
||||
&& confManager()->updateApp(appId, endTime, groupIndex, blocked)) {
|
||||
const auto itemIndex = index(row, 3);
|
||||
invalidateRowCache();
|
||||
emit dataChanged(itemIndex, itemIndex);
|
||||
|
@ -61,8 +61,10 @@ public:
|
||||
QString appPathByRow(int row) const;
|
||||
AppRow appRow(int row) const;
|
||||
|
||||
bool addApp(const QString &appPath, int groupIndex, bool blocked);
|
||||
bool updateApp(int row, int groupIndex, bool blocked);
|
||||
bool addApp(const QString &appPath, int groupIndex, bool blocked,
|
||||
const QDateTime &endTime = QDateTime());
|
||||
bool updateApp(int row, int groupIndex, bool blocked,
|
||||
const QDateTime &endTime = QDateTime());
|
||||
void deleteApp(int row);
|
||||
|
||||
public slots:
|
||||
|
Loading…
Reference in New Issue
Block a user