mirror of
https://github.com/tnodir/fort
synced 2024-11-15 15:26:07 +00:00
UI: ProgramsWindow: Improve AppEditForm.
This commit is contained in:
parent
930a0b7aae
commit
4ba73e2c52
@ -22,6 +22,7 @@
|
|||||||
#include "../../fortsettings.h"
|
#include "../../fortsettings.h"
|
||||||
#include "../../model/applistmodel.h"
|
#include "../../model/applistmodel.h"
|
||||||
#include "../../util/app/appinfocache.h"
|
#include "../../util/app/appinfocache.h"
|
||||||
|
#include "../../util/fileutil.h"
|
||||||
#include "../../util/guiutil.h"
|
#include "../../util/guiutil.h"
|
||||||
#include "../../util/iconcache.h"
|
#include "../../util/iconcache.h"
|
||||||
#include "../../util/window/widgetwindowstatewatcher.h"
|
#include "../../util/window/widgetwindowstatewatcher.h"
|
||||||
@ -133,6 +134,7 @@ void ProgramsWindow::onRetranslateUi()
|
|||||||
m_labelEditPath->setText(tr("Program Path:"));
|
m_labelEditPath->setText(tr("Program Path:"));
|
||||||
m_btSelectFile->setToolTip(tr("Select File"));
|
m_btSelectFile->setToolTip(tr("Select File"));
|
||||||
m_labelEditName->setText(tr("Program Name:"));
|
m_labelEditName->setText(tr("Program Name:"));
|
||||||
|
m_btGetName->setToolTip(tr("Get Program Name"));
|
||||||
m_labelAppGroup->setText(tr("Application Group:"));
|
m_labelAppGroup->setText(tr("Application Group:"));
|
||||||
m_cbUseGroupPerm->setText(tr("Use Application Group's Enabled State"));
|
m_cbUseGroupPerm->setText(tr("Use Application Group's Enabled State"));
|
||||||
m_rbAllowApp->setText(tr("Allow"));
|
m_rbAllowApp->setText(tr("Allow"));
|
||||||
@ -203,6 +205,13 @@ void ProgramsWindow::setupUi()
|
|||||||
|
|
||||||
void ProgramsWindow::setupAppEditForm()
|
void ProgramsWindow::setupAppEditForm()
|
||||||
{
|
{
|
||||||
|
// Dialog
|
||||||
|
m_formAppEdit = new QDialog(this);
|
||||||
|
m_formAppEdit->setWindowModality(Qt::WindowModal);
|
||||||
|
m_formAppEdit->setSizeGripEnabled(true);
|
||||||
|
m_formAppEdit->setMinimumWidth(500);
|
||||||
|
|
||||||
|
// Form Layout
|
||||||
auto formLayout = setupAppEditFormAppLayout();
|
auto formLayout = setupAppEditFormAppLayout();
|
||||||
|
|
||||||
// Allow/Block
|
// Allow/Block
|
||||||
@ -217,10 +226,15 @@ void ProgramsWindow::setupAppEditForm()
|
|||||||
// OK/Cancel
|
// OK/Cancel
|
||||||
auto buttonsLayout = new QHBoxLayout();
|
auto buttonsLayout = new QHBoxLayout();
|
||||||
|
|
||||||
m_btEditOk = new QPushButton();
|
m_btEditOk = ControlUtil::createButton(QString(), [&] {
|
||||||
|
if (saveAppEditForm()) {
|
||||||
|
m_formAppEdit->close();
|
||||||
|
}
|
||||||
|
});
|
||||||
m_btEditOk->setDefault(true);
|
m_btEditOk->setDefault(true);
|
||||||
|
|
||||||
m_btEditCancel = new QPushButton();
|
m_btEditCancel = new QPushButton();
|
||||||
|
connect(m_btEditCancel, &QAbstractButton::clicked, m_formAppEdit, &QWidget::close);
|
||||||
|
|
||||||
buttonsLayout->addWidget(m_btEditOk, 1, Qt::AlignRight);
|
buttonsLayout->addWidget(m_btEditOk, 1, Qt::AlignRight);
|
||||||
buttonsLayout->addWidget(m_btEditCancel);
|
buttonsLayout->addWidget(m_btEditCancel);
|
||||||
@ -237,13 +251,46 @@ void ProgramsWindow::setupAppEditForm()
|
|||||||
layout->addWidget(ControlUtil::createSeparator());
|
layout->addWidget(ControlUtil::createSeparator());
|
||||||
layout->addLayout(buttonsLayout);
|
layout->addLayout(buttonsLayout);
|
||||||
|
|
||||||
m_formAppEdit = new QDialog(this);
|
|
||||||
m_formAppEdit->setWindowModality(Qt::WindowModal);
|
|
||||||
m_formAppEdit->setSizeGripEnabled(true);
|
|
||||||
m_formAppEdit->setLayout(layout);
|
m_formAppEdit->setLayout(layout);
|
||||||
m_formAppEdit->setMinimumWidth(500);
|
}
|
||||||
|
|
||||||
connect(m_btSelectFile, &QAbstractButton::clicked, this, [&] {
|
QLayout *ProgramsWindow::setupAppEditFormAppLayout()
|
||||||
|
{
|
||||||
|
auto layout = new QFormLayout();
|
||||||
|
|
||||||
|
// App Path
|
||||||
|
auto pathLayout = setupAppEditFormAppPathLayout();
|
||||||
|
|
||||||
|
layout->addRow("Program Path:", pathLayout);
|
||||||
|
m_labelEditPath = qobject_cast<QLabel *>(layout->labelForField(pathLayout));
|
||||||
|
|
||||||
|
// App Name
|
||||||
|
auto nameLayout = setupAppEditFormAppNameLayout();
|
||||||
|
|
||||||
|
layout->addRow("Program Name:", nameLayout);
|
||||||
|
m_labelEditName = qobject_cast<QLabel *>(layout->labelForField(nameLayout));
|
||||||
|
|
||||||
|
// App Group
|
||||||
|
setupComboAppGroups();
|
||||||
|
|
||||||
|
layout->addRow("Application Group:", m_comboAppGroup);
|
||||||
|
m_labelAppGroup = qobject_cast<QLabel *>(layout->labelForField(m_comboAppGroup));
|
||||||
|
|
||||||
|
// Use Group Perm.
|
||||||
|
m_cbUseGroupPerm = new QCheckBox();
|
||||||
|
|
||||||
|
layout->addRow(QString(), m_cbUseGroupPerm);
|
||||||
|
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLayout *ProgramsWindow::setupAppEditFormAppPathLayout()
|
||||||
|
{
|
||||||
|
auto layout = new QHBoxLayout();
|
||||||
|
|
||||||
|
m_editPath = new QLineEdit();
|
||||||
|
|
||||||
|
m_btSelectFile = ControlUtil::createFlatButton(":/icons/folder-open.png", [&] {
|
||||||
const auto filePath = ControlUtil::getOpenFileName(
|
const auto filePath = ControlUtil::getOpenFileName(
|
||||||
m_labelEditPath->text(), tr("Programs (*.exe);;All files (*.*)"));
|
m_labelEditPath->text(), tr("Programs (*.exe);;All files (*.*)"));
|
||||||
|
|
||||||
@ -252,56 +299,38 @@ void ProgramsWindow::setupAppEditForm()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_rbAllowApp, &QRadioButton::toggled, this, [&](bool checked) {
|
layout->addWidget(m_editPath);
|
||||||
m_cbBlockAppNone->setEnabled(checked);
|
layout->addWidget(m_btSelectFile);
|
||||||
m_cscBlockAppIn->setEnabled(checked);
|
|
||||||
m_cbBlockAppAt->setEnabled(checked);
|
|
||||||
m_dteBlockAppAt->setEnabled(checked);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(m_btEditOk, &QAbstractButton::clicked, this, [&] {
|
return layout;
|
||||||
if (saveAppEditForm()) {
|
|
||||||
m_formAppEdit->close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(m_btEditCancel, &QAbstractButton::clicked, m_formAppEdit, &QWidget::close);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QLayout *ProgramsWindow::setupAppEditFormAppLayout()
|
QLayout *ProgramsWindow::setupAppEditFormAppNameLayout()
|
||||||
{
|
{
|
||||||
auto formLayout = new QFormLayout();
|
auto layout = new QHBoxLayout();
|
||||||
|
|
||||||
// App Path
|
|
||||||
auto pathLayout = new QHBoxLayout();
|
|
||||||
|
|
||||||
m_editPath = new QLineEdit();
|
|
||||||
|
|
||||||
m_btSelectFile = ControlUtil::createLinkButton(":/icons/folder-open.png");
|
|
||||||
|
|
||||||
pathLayout->addWidget(m_editPath);
|
|
||||||
pathLayout->addWidget(m_btSelectFile);
|
|
||||||
|
|
||||||
formLayout->addRow("Program Path:", pathLayout);
|
|
||||||
m_labelEditPath = qobject_cast<QLabel *>(formLayout->labelForField(pathLayout));
|
|
||||||
|
|
||||||
// App Name
|
|
||||||
m_editName = new QLineEdit();
|
m_editName = new QLineEdit();
|
||||||
|
|
||||||
formLayout->addRow("Program Name:", m_editName);
|
const auto updateAppName = [&] {
|
||||||
m_labelEditName = qobject_cast<QLabel *>(formLayout->labelForField(m_editName));
|
const auto appPath = m_editPath->text();
|
||||||
|
if (appPath.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
// App Group
|
const auto appInfo = appInfoCache()->appInfo(appPath);
|
||||||
setupComboAppGroups();
|
const auto appName =
|
||||||
|
appInfo.isValid() ? appInfo.fileDescription : FileUtil::fileName(appPath);
|
||||||
|
|
||||||
formLayout->addRow("Application Group:", m_comboAppGroup);
|
m_editName->setText(appName);
|
||||||
m_labelAppGroup = qobject_cast<QLabel *>(formLayout->labelForField(m_comboAppGroup));
|
};
|
||||||
|
|
||||||
// Use Group Perm.
|
m_btGetName = ControlUtil::createFlatButton(":/icons/sign-sync.png", updateAppName);
|
||||||
m_cbUseGroupPerm = new QCheckBox();
|
|
||||||
|
|
||||||
formLayout->addRow(QString(), m_cbUseGroupPerm);
|
connect(appInfoCache(), &AppInfoCache::cacheChanged, this, updateAppName);
|
||||||
|
|
||||||
return formLayout;
|
layout->addWidget(m_editName);
|
||||||
|
layout->addWidget(m_btGetName);
|
||||||
|
|
||||||
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramsWindow::setupComboAppGroups()
|
void ProgramsWindow::setupComboAppGroups()
|
||||||
@ -346,6 +375,13 @@ QLayout *ProgramsWindow::setupAppEditFormAllowLayout()
|
|||||||
// Allow Forever
|
// Allow Forever
|
||||||
m_cbBlockAppNone = new QCheckBox();
|
m_cbBlockAppNone = new QCheckBox();
|
||||||
|
|
||||||
|
connect(m_rbAllowApp, &QRadioButton::toggled, this, [&](bool checked) {
|
||||||
|
m_cbBlockAppNone->setEnabled(checked);
|
||||||
|
m_cscBlockAppIn->setEnabled(checked);
|
||||||
|
m_cbBlockAppAt->setEnabled(checked);
|
||||||
|
m_dteBlockAppAt->setEnabled(checked);
|
||||||
|
});
|
||||||
|
|
||||||
return allowLayout;
|
return allowLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,7 +602,7 @@ void ProgramsWindow::updateAppEditForm(bool editCurrentApp)
|
|||||||
void ProgramsWindow::openAppEditFormByRow(
|
void ProgramsWindow::openAppEditFormByRow(
|
||||||
const AppRow &appRow, bool editCurrentApp, bool isSingleSelection)
|
const AppRow &appRow, bool editCurrentApp, bool isSingleSelection)
|
||||||
{
|
{
|
||||||
const bool isPathEditable = !(isSingleSelection && appRow.appId > 0);
|
const bool isPathEditable = isSingleSelection && appRow.appId == 0;
|
||||||
|
|
||||||
m_formAppForSelected = editCurrentApp;
|
m_formAppForSelected = editCurrentApp;
|
||||||
|
|
||||||
@ -577,6 +613,8 @@ void ProgramsWindow::openAppEditFormByRow(
|
|||||||
m_btSelectFile->setEnabled(isPathEditable);
|
m_btSelectFile->setEnabled(isPathEditable);
|
||||||
m_editName->setText(isSingleSelection ? appRow.appName : QString());
|
m_editName->setText(isSingleSelection ? appRow.appName : QString());
|
||||||
m_editName->setEnabled(isSingleSelection);
|
m_editName->setEnabled(isSingleSelection);
|
||||||
|
m_editName->setClearButtonEnabled(isSingleSelection);
|
||||||
|
m_btGetName->setEnabled(isSingleSelection);
|
||||||
m_comboAppGroup->setCurrentIndex(appRow.groupIndex);
|
m_comboAppGroup->setCurrentIndex(appRow.groupIndex);
|
||||||
m_cbUseGroupPerm->setChecked(appRow.useGroupPerm);
|
m_cbUseGroupPerm->setChecked(appRow.useGroupPerm);
|
||||||
m_rbAllowApp->setChecked(!appRow.blocked);
|
m_rbAllowApp->setChecked(!appRow.blocked);
|
||||||
@ -588,6 +626,10 @@ void ProgramsWindow::openAppEditFormByRow(
|
|||||||
m_dteBlockAppAt->setMinimumDateTime(QDateTime::currentDateTime());
|
m_dteBlockAppAt->setMinimumDateTime(QDateTime::currentDateTime());
|
||||||
m_cbBlockAppNone->setChecked(appRow.endTime.isNull());
|
m_cbBlockAppNone->setChecked(appRow.endTime.isNull());
|
||||||
|
|
||||||
|
if (isSingleSelection && appRow.appName.isEmpty()) {
|
||||||
|
m_btGetName->click(); // Auto-fill name
|
||||||
|
}
|
||||||
|
|
||||||
m_formAppEdit->show();
|
m_formAppEdit->show();
|
||||||
|
|
||||||
activateAppEditForm();
|
activateAppEditForm();
|
||||||
@ -602,11 +644,18 @@ void ProgramsWindow::activateAppEditForm()
|
|||||||
|
|
||||||
bool ProgramsWindow::saveAppEditForm()
|
bool ProgramsWindow::saveAppEditForm()
|
||||||
{
|
{
|
||||||
QString appPath = m_editPath->text();
|
const QString appPath = m_editPath->text();
|
||||||
if (appPath.isEmpty())
|
if (appPath.isEmpty()) {
|
||||||
|
m_editPath->setFocus();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString appName = m_editName->text();
|
||||||
|
if (appName.isEmpty()) {
|
||||||
|
m_editName->setFocus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QString appName = m_editName->text();
|
|
||||||
const int groupIndex = m_comboAppGroup->currentIndex();
|
const int groupIndex = m_comboAppGroup->currentIndex();
|
||||||
const bool useGroupPerm = m_cbUseGroupPerm->isChecked();
|
const bool useGroupPerm = m_cbUseGroupPerm->isChecked();
|
||||||
const bool blocked = m_rbBlockApp->isChecked();
|
const bool blocked = m_rbBlockApp->isChecked();
|
||||||
|
@ -58,6 +58,8 @@ private:
|
|||||||
void setupUi();
|
void setupUi();
|
||||||
void setupAppEditForm();
|
void setupAppEditForm();
|
||||||
QLayout *setupAppEditFormAppLayout();
|
QLayout *setupAppEditFormAppLayout();
|
||||||
|
QLayout *setupAppEditFormAppPathLayout();
|
||||||
|
QLayout *setupAppEditFormAppNameLayout();
|
||||||
void setupComboAppGroups();
|
void setupComboAppGroups();
|
||||||
QLayout *setupAppEditFormAllowLayout();
|
QLayout *setupAppEditFormAllowLayout();
|
||||||
QLayout *setupCheckDateTimeEdit();
|
QLayout *setupCheckDateTimeEdit();
|
||||||
@ -106,9 +108,10 @@ private:
|
|||||||
QPushButton *m_btBlockApp = nullptr;
|
QPushButton *m_btBlockApp = nullptr;
|
||||||
QLabel *m_labelEditPath = nullptr;
|
QLabel *m_labelEditPath = nullptr;
|
||||||
QLineEdit *m_editPath = nullptr;
|
QLineEdit *m_editPath = nullptr;
|
||||||
|
QPushButton *m_btSelectFile = nullptr;
|
||||||
QLabel *m_labelEditName = nullptr;
|
QLabel *m_labelEditName = nullptr;
|
||||||
QLineEdit *m_editName = nullptr;
|
QLineEdit *m_editName = nullptr;
|
||||||
QPushButton *m_btSelectFile = nullptr;
|
QPushButton *m_btGetName = nullptr;
|
||||||
QLabel *m_labelAppGroup = nullptr;
|
QLabel *m_labelAppGroup = nullptr;
|
||||||
QComboBox *m_comboAppGroup = nullptr;
|
QComboBox *m_comboAppGroup = nullptr;
|
||||||
QCheckBox *m_cbUseGroupPerm = nullptr;
|
QCheckBox *m_cbUseGroupPerm = nullptr;
|
||||||
|
@ -144,7 +144,7 @@ QVariant AppListModel::dataDisplay(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case 0:
|
case 0:
|
||||||
return getAppName(appRow);
|
return appNameText(appRow);
|
||||||
case 1:
|
case 1:
|
||||||
return appGroupAt(appRow.groupIndex)->name();
|
return appGroupAt(appRow.groupIndex)->name();
|
||||||
case 2:
|
case 2:
|
||||||
@ -230,19 +230,13 @@ QVariant AppListModel::dataTextAlignment(const QModelIndex &index) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AppListModel::getAppName(const AppRow &appRow) const
|
QString AppListModel::appNameText(const AppRow &appRow) const
|
||||||
{
|
{
|
||||||
auto appName = appRow.appName;
|
const auto appName = appRow.appName;
|
||||||
if (appName.isEmpty()) {
|
if (!appName.isEmpty())
|
||||||
const auto appInfo = appInfoCache()->appInfo(appRow.appPath);
|
return appName;
|
||||||
appName = !appInfo.fileDescription.isEmpty() ? appInfo.fileDescription
|
|
||||||
: FileUtil::fileName(appRow.appPath);
|
|
||||||
|
|
||||||
if (appInfo.isValid()) {
|
return FileUtil::fileName(appRow.appPath);
|
||||||
confManager()->updateAppName(appRow.appId, appName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return appName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AppListModel::appStateText(const AppRow &appRow)
|
QString AppListModel::appStateText(const AppRow &appRow)
|
||||||
|
@ -85,7 +85,7 @@ private:
|
|||||||
QVariant dataForeground(const QModelIndex &index) const;
|
QVariant dataForeground(const QModelIndex &index) const;
|
||||||
QVariant dataTextAlignment(const QModelIndex &index) const;
|
QVariant dataTextAlignment(const QModelIndex &index) const;
|
||||||
|
|
||||||
QString getAppName(const AppRow &appRow) const;
|
QString appNameText(const AppRow &appRow) const;
|
||||||
static QString appStateText(const AppRow &appRow);
|
static QString appStateText(const AppRow &appRow);
|
||||||
|
|
||||||
QColor appGroupColor(const AppRow &appRow) const;
|
QColor appGroupColor(const AppRow &appRow) const;
|
||||||
|
@ -30,5 +30,5 @@ QPixmap IconCache::file(const QString &filePath)
|
|||||||
|
|
||||||
QIcon IconCache::icon(const QString &filePath)
|
QIcon IconCache::icon(const QString &filePath)
|
||||||
{
|
{
|
||||||
return QIcon(file(filePath));
|
return filePath.isEmpty() ? QIcon() : QIcon(file(filePath));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user