mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:06:08 +00:00
UI: Connections: Add "Add Program" button.
To add/edit selected connection's program.
This commit is contained in:
parent
0b6afac217
commit
d2bf94ebb9
6
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
6
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
@ -135,6 +135,12 @@ bool SqliteDb::prepare(SqliteStmt &stmt, const char *sql, const QVariantList &va
|
||||
return stmt.prepare(db(), sql) && (vars.isEmpty() || stmt.bindVars(vars));
|
||||
}
|
||||
|
||||
bool SqliteDb::prepare(SqliteStmt &stmt, const QString &sql, const QVariantList &vars)
|
||||
{
|
||||
const auto sqlData = sql.toUtf8();
|
||||
return prepare(stmt, sqlData.constData(), vars);
|
||||
}
|
||||
|
||||
bool SqliteDb::done(SqliteStmt *stmt)
|
||||
{
|
||||
const SqliteStmt::StepResult res = stmt->step();
|
||||
|
1
src/ui/3rdparty/sqlite/sqlitedb.h
vendored
1
src/ui/3rdparty/sqlite/sqlitedb.h
vendored
@ -37,6 +37,7 @@ public:
|
||||
int resultCount = 1, bool *ok = nullptr);
|
||||
|
||||
bool prepare(SqliteStmt &stmt, const char *sql, const QVariantList &vars = QVariantList());
|
||||
bool prepare(SqliteStmt &stmt, const QString &sql, const QVariantList &vars = QVariantList());
|
||||
bool done(SqliteStmt *stmt);
|
||||
|
||||
qint64 lastInsertRowid() const;
|
||||
|
@ -72,6 +72,7 @@ void ConnectionsWindow::onRetranslateUi()
|
||||
|
||||
m_btEdit->setText(tr("Edit"));
|
||||
m_actCopy->setText(tr("Copy"));
|
||||
m_actAddProgram->setText(tr("Add Program"));
|
||||
m_actRemoveConn->setText(tr("Remove"));
|
||||
m_actClearConns->setText(tr("Clear All"));
|
||||
|
||||
@ -131,6 +132,9 @@ QLayout *ConnectionsWindow::setupHeader()
|
||||
m_actCopy = editMenu->addAction(IconCache::icon(":/icons/copy.png"), QString());
|
||||
m_actCopy->setShortcut(Qt::Key_Copy);
|
||||
|
||||
m_actAddProgram = editMenu->addAction(IconCache::icon(":/icons/window.png"), QString());
|
||||
m_actAddProgram->setShortcut(Qt::Key_Insert);
|
||||
|
||||
m_actRemoveConn = editMenu->addAction(IconCache::icon(":/icons/sign-delete.png"), QString());
|
||||
m_actRemoveConn->setShortcut(Qt::Key_Delete);
|
||||
|
||||
@ -138,6 +142,15 @@ QLayout *ConnectionsWindow::setupHeader()
|
||||
|
||||
connect(m_actCopy, &QAction::triggered, this,
|
||||
[&] { GuiUtil::setClipboardData(m_connListView->selectedText()); });
|
||||
connect(m_actAddProgram, &QAction::triggered, this, [&] {
|
||||
const auto connIndex = connListCurrentIndex();
|
||||
const auto connRow = connListModel()->connRowAt(connIndex);
|
||||
|
||||
if (!fortManager()->showProgramEditForm(connRow.appPath)) {
|
||||
fortManager()->showErrorBox(
|
||||
tr("Please close already opened Edit Program window and try again."));
|
||||
}
|
||||
});
|
||||
connect(m_actRemoveConn, &QAction::triggered, this, [&] {
|
||||
if (fortManager()->showQuestionBox(
|
||||
tr("Are you sure to remove connections till this row?"))) {
|
||||
@ -291,6 +304,7 @@ void ConnectionsWindow::setupTableConnsChanged()
|
||||
const int connIndex = connListCurrentIndex();
|
||||
const bool connSelected = (connIndex >= 0);
|
||||
m_actCopy->setEnabled(connSelected);
|
||||
m_actAddProgram->setEnabled(connSelected);
|
||||
m_actRemoveConn->setEnabled(connSelected);
|
||||
m_appInfoRow->setVisible(connSelected);
|
||||
};
|
||||
|
@ -63,6 +63,7 @@ private:
|
||||
|
||||
QPushButton *m_btEdit = nullptr;
|
||||
QAction *m_actCopy = nullptr;
|
||||
QAction *m_actAddProgram = nullptr;
|
||||
QAction *m_actRemoveConn = nullptr;
|
||||
QAction *m_actClearConns = nullptr;
|
||||
QPushButton *m_btLogOptions = nullptr;
|
||||
|
@ -498,6 +498,17 @@ void ProgramsWindow::setupTableAppsChanged()
|
||||
connect(m_appListView, &TableView::currentIndexChanged, this, refreshTableAppsChanged);
|
||||
}
|
||||
|
||||
bool ProgramsWindow::openAppEditFormByPath(const QString &appPath)
|
||||
{
|
||||
if (m_formAppEdit->isVisible())
|
||||
return false;
|
||||
|
||||
const auto appRow = appListModel()->appRowByPath(appPath);
|
||||
|
||||
openAppEditFormByRow(appRow, false, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProgramsWindow::updateAppEditForm(bool editCurrentApp)
|
||||
{
|
||||
bool isSingleSelection = true;
|
||||
@ -514,6 +525,12 @@ void ProgramsWindow::updateAppEditForm(bool editCurrentApp)
|
||||
appRow = appListModel()->appRowAt(appIndex);
|
||||
}
|
||||
|
||||
openAppEditFormByRow(appRow, editCurrentApp, isSingleSelection);
|
||||
}
|
||||
|
||||
void ProgramsWindow::openAppEditFormByRow(
|
||||
const AppRow &appRow, bool editCurrentApp, bool isSingleSelection)
|
||||
{
|
||||
m_formAppIsNew = !editCurrentApp;
|
||||
|
||||
m_editPath->setText(isSingleSelection ? appRow.appPath : "*");
|
||||
|
@ -23,6 +23,8 @@ class FortSettings;
|
||||
class ProgramsController;
|
||||
class TableView;
|
||||
|
||||
struct AppRow;
|
||||
|
||||
class ProgramsWindow : public WidgetWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -30,6 +32,8 @@ class ProgramsWindow : public WidgetWindow
|
||||
public:
|
||||
explicit ProgramsWindow(FortManager *fortManager, QWidget *parent = nullptr);
|
||||
|
||||
bool openAppEditFormByPath(const QString &appPath);
|
||||
|
||||
protected slots:
|
||||
void onSaveWindowState();
|
||||
void onRestoreWindowState();
|
||||
@ -57,6 +61,8 @@ private:
|
||||
void setupTableAppsChanged();
|
||||
|
||||
void updateAppEditForm(bool editCurrentApp);
|
||||
void openAppEditFormByRow(const AppRow &appRow, bool editCurrentApp, bool isSingleSelection);
|
||||
|
||||
bool saveAppEditForm();
|
||||
bool saveAppEditFormMulti(const QString &appPath, const QString &appName,
|
||||
const QDateTime &endTime, int groupIndex, bool useGroupPerm, bool blocked);
|
||||
|
@ -368,6 +368,12 @@ void FortManager::closeProgramsWindow()
|
||||
m_progWindow = nullptr;
|
||||
}
|
||||
|
||||
bool FortManager::showProgramEditForm(const QString &appPath)
|
||||
{
|
||||
showProgramsWindow();
|
||||
return m_progWindow->openAppEditFormByPath(appPath);
|
||||
}
|
||||
|
||||
void FortManager::showOptionsWindow()
|
||||
{
|
||||
if (!(m_optWindow && m_optWindow->isVisible()) && !checkPassword())
|
||||
|
@ -87,6 +87,8 @@ public slots:
|
||||
void showProgramsWindow();
|
||||
void closeProgramsWindow();
|
||||
|
||||
bool showProgramEditForm(const QString &appPath);
|
||||
|
||||
void showOptionsWindow();
|
||||
void closeOptionsWindow();
|
||||
|
||||
|
@ -244,6 +244,25 @@ QString AppListModel::getAppName(const AppRow &appRow) const
|
||||
return appName;
|
||||
}
|
||||
|
||||
bool AppListModel::updateAppRow(const QString &sql, const QVariantList &vars, AppRow &appRow) const
|
||||
{
|
||||
SqliteStmt stmt;
|
||||
if (!(sqliteDb()->prepare(stmt, sql, vars) && stmt.step() == SqliteStmt::StepRow))
|
||||
return false;
|
||||
|
||||
appRow.appId = stmt.columnInt64(0);
|
||||
appRow.groupIndex = stmt.columnInt(1);
|
||||
appRow.appPath = stmt.columnText(2);
|
||||
appRow.appName = stmt.columnText(3);
|
||||
appRow.useGroupPerm = stmt.columnBool(4);
|
||||
appRow.blocked = stmt.columnBool(5);
|
||||
appRow.alerted = stmt.columnBool(6);
|
||||
appRow.endTime = stmt.columnDateTime(7);
|
||||
appRow.creatTime = stmt.columnDateTime(8);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const AppRow &AppListModel::appRowAt(int row) const
|
||||
{
|
||||
updateRowCache(row);
|
||||
@ -251,6 +270,16 @@ const AppRow &AppListModel::appRowAt(int row) const
|
||||
return m_appRow;
|
||||
}
|
||||
|
||||
AppRow AppListModel::appRowByPath(const QString &appPath) const
|
||||
{
|
||||
AppRow appRow;
|
||||
appRow.appPath = appPath;
|
||||
|
||||
updateAppRow(sqlBase() + " WHERE path = ?1;", { appPath }, appRow);
|
||||
|
||||
return appRow;
|
||||
}
|
||||
|
||||
bool AppListModel::addApp(const QString &appPath, const QString &appName, const QDateTime &endTime,
|
||||
int groupIndex, bool useGroupPerm, bool blocked)
|
||||
{
|
||||
@ -323,22 +352,7 @@ void AppListModel::purgeApps()
|
||||
|
||||
bool AppListModel::updateTableRow(int row) const
|
||||
{
|
||||
SqliteStmt stmt;
|
||||
if (!(sqliteDb()->prepare(stmt, sql().toLatin1(), { row })
|
||||
&& stmt.step() == SqliteStmt::StepRow))
|
||||
return false;
|
||||
|
||||
m_appRow.appId = stmt.columnInt64(0);
|
||||
m_appRow.groupIndex = stmt.columnInt(1);
|
||||
m_appRow.appPath = stmt.columnText(2);
|
||||
m_appRow.appName = stmt.columnText(3);
|
||||
m_appRow.useGroupPerm = stmt.columnBool(4);
|
||||
m_appRow.blocked = stmt.columnBool(5);
|
||||
m_appRow.alerted = stmt.columnBool(6);
|
||||
m_appRow.endTime = stmt.columnDateTime(7);
|
||||
m_appRow.creatTime = stmt.columnDateTime(8);
|
||||
|
||||
return true;
|
||||
return updateAppRow(sql(), { row }, m_appRow);
|
||||
}
|
||||
|
||||
QString AppListModel::sqlBase() const
|
||||
|
@ -54,6 +54,7 @@ public:
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
const AppRow &appRowAt(int row) const;
|
||||
AppRow appRowByPath(const QString &appPath) const;
|
||||
|
||||
bool addApp(const QString &appPath, const QString &appName, const QDateTime &endTime,
|
||||
int groupIndex, bool useGroupPerm, bool blocked);
|
||||
@ -83,6 +84,8 @@ private:
|
||||
|
||||
QString getAppName(const AppRow &appRow) const;
|
||||
|
||||
bool updateAppRow(const QString &sql, const QVariantList &vars, AppRow &appRow) const;
|
||||
|
||||
private:
|
||||
ConfManager *m_confManager = nullptr;
|
||||
AppInfoCache *m_appInfoCache = nullptr;
|
||||
|
@ -221,8 +221,7 @@ bool ConnListModel::updateTableRow(int row) const
|
||||
const qint64 rowId = rowIdMin() + row;
|
||||
|
||||
SqliteStmt stmt;
|
||||
if (!(sqliteDb()->prepare(stmt, sql().toLatin1(), { rowId })
|
||||
&& stmt.step() == SqliteStmt::StepRow))
|
||||
if (!(sqliteDb()->prepare(stmt, sql(), { rowId }) && stmt.step() == SqliteStmt::StepRow))
|
||||
return false;
|
||||
|
||||
m_connRow.rowId = rowId;
|
||||
|
@ -238,8 +238,7 @@ QVariant ZoneListModel::zoneSourceByCode(const QString &sourceCode) const
|
||||
bool ZoneListModel::updateTableRow(int row) const
|
||||
{
|
||||
SqliteStmt stmt;
|
||||
if (!(sqliteDb()->prepare(stmt, sql().toLatin1(), { row })
|
||||
&& stmt.step() == SqliteStmt::StepRow))
|
||||
if (!(sqliteDb()->prepare(stmt, sql(), { row }) && stmt.step() == SqliteStmt::StepRow))
|
||||
return false;
|
||||
|
||||
m_zoneRow.zoneId = stmt.columnInt(0);
|
||||
|
Loading…
Reference in New Issue
Block a user