mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:15:39 +00:00
UI: BlockedPage, StatisticsPage: Improve "Clear" button.
This commit is contained in:
parent
5c2474b1d7
commit
1647429d3b
@ -180,7 +180,7 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint8 *procBits,
|
||||
<< getTrafficStmt(DatabaseSql::sqlDeleteTrafDay, oldTrafDay)
|
||||
<< getTrafficStmt(DatabaseSql::sqlDeleteTrafMonth, oldTrafMonth);
|
||||
|
||||
deleteTrafficList(deleteTrafStmts);
|
||||
stepStmtList(deleteTrafStmts);
|
||||
}
|
||||
|
||||
m_sqliteDb->commitTransaction();
|
||||
@ -229,6 +229,33 @@ qint64 DatabaseManager::getAppId(const QString &appPath)
|
||||
return appId;
|
||||
}
|
||||
|
||||
void DatabaseManager::deleteApp(qint64 appId)
|
||||
{
|
||||
// Delete Statemets
|
||||
const QStmtList deleteAppStmts = QStmtList()
|
||||
<< getAppStmt(DatabaseSql::sqlDeleteAppTrafHour, appId)
|
||||
<< getAppStmt(DatabaseSql::sqlDeleteAppTrafDay, appId)
|
||||
<< getAppStmt(DatabaseSql::sqlDeleteAppTrafMonth, appId)
|
||||
<< getAppStmt(DatabaseSql::sqlDeleteAppId, appId);
|
||||
|
||||
stepStmtList(deleteAppStmts);
|
||||
}
|
||||
|
||||
void DatabaseManager::resetAppTotals()
|
||||
{
|
||||
m_sqliteDb->beginTransaction();
|
||||
|
||||
SqliteStmt *stmt = getSqliteStmt(DatabaseSql::sqlResetAppTrafTotals);
|
||||
const qint64 unixTime = DateUtil::getUnixTime();
|
||||
|
||||
stmt->bindInt(1, DateUtil::getUnixHour(unixTime));
|
||||
|
||||
stmt->step();
|
||||
stmt->reset();
|
||||
|
||||
m_sqliteDb->commitTransaction();
|
||||
}
|
||||
|
||||
qint64 DatabaseManager::createAppId(const QString &appPath)
|
||||
{
|
||||
qint64 appId = 0;
|
||||
@ -296,9 +323,9 @@ bool DatabaseManager::updateTraffic(SqliteStmt *stmt, quint32 inBytes,
|
||||
&& m_sqliteDb->changes() != 0;
|
||||
}
|
||||
|
||||
void DatabaseManager::deleteTrafficList(const QStmtList &deleteStmtList)
|
||||
void DatabaseManager::stepStmtList(const QStmtList &stmtList)
|
||||
{
|
||||
foreach (SqliteStmt *stmtDelete, deleteStmtList) {
|
||||
foreach (SqliteStmt *stmtDelete, stmtList) {
|
||||
stmtDelete->step();
|
||||
stmtDelete->reset();
|
||||
}
|
||||
@ -353,6 +380,15 @@ SqliteStmt *DatabaseManager::getTrafficStmt(const char *sql, qint32 trafTime)
|
||||
return stmt;
|
||||
}
|
||||
|
||||
SqliteStmt *DatabaseManager::getAppStmt(const char *sql, qint64 appId)
|
||||
{
|
||||
SqliteStmt *stmt = getSqliteStmt(sql);
|
||||
|
||||
stmt->bindInt64(1, appId);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
SqliteStmt *DatabaseManager::getSqliteStmt(const char *sql)
|
||||
{
|
||||
SqliteStmt *stmt = m_sqliteStmts.value(sql);
|
||||
|
@ -35,6 +35,10 @@ public:
|
||||
|
||||
qint64 getAppId(const QString &appPath);
|
||||
|
||||
void deleteApp(qint64 appId);
|
||||
|
||||
void resetAppTotals();
|
||||
|
||||
qint32 getTrafficTime(const char *sql, qint64 appId = 0);
|
||||
|
||||
void getTraffic(const char *sql, qint32 trafTime,
|
||||
@ -63,9 +67,10 @@ private:
|
||||
bool updateTraffic(SqliteStmt *stmt, quint32 inBytes,
|
||||
quint32 outBytes, qint64 appId = 0);
|
||||
|
||||
void deleteTrafficList(const QStmtList &deleteStmtList);
|
||||
void stepStmtList(const QStmtList &stmtList);
|
||||
|
||||
SqliteStmt *getTrafficStmt(const char *sql, qint32 trafTime);
|
||||
SqliteStmt *getAppStmt(const char *sql, qint64 appId);
|
||||
|
||||
SqliteStmt *getSqliteStmt(const char *sql);
|
||||
|
||||
|
@ -68,6 +68,10 @@ const char * const DatabaseSql::sqlInsertAppId =
|
||||
" VALUES(?1, ?2, ?3, 0, 0);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteAppId =
|
||||
"DELETE FROM app WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectAppPaths =
|
||||
"SELECT app_id, path FROM app ORDER BY creat_time;"
|
||||
;
|
||||
@ -259,3 +263,22 @@ const char * const DatabaseSql::sqlDeleteTrafDay =
|
||||
const char * const DatabaseSql::sqlDeleteTrafMonth =
|
||||
"DELETE FROM traffic_month WHERE traf_time < ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteAppTrafHour =
|
||||
"DELETE FROM traffic_app_hour"
|
||||
" WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteAppTrafDay =
|
||||
"DELETE FROM traffic_app_day"
|
||||
" WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteAppTrafMonth =
|
||||
"DELETE FROM traffic_app_month"
|
||||
" WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlResetAppTrafTotals =
|
||||
"UPDATE app SET traf_time = ?1, in_bytes = 0, out_bytes = 0;"
|
||||
;
|
||||
|
@ -9,6 +9,7 @@ public:
|
||||
|
||||
static const char * const sqlSelectAppId;
|
||||
static const char * const sqlInsertAppId;
|
||||
static const char * const sqlDeleteAppId;
|
||||
|
||||
static const char * const sqlSelectAppPaths;
|
||||
|
||||
@ -57,6 +58,12 @@ public:
|
||||
static const char * const sqlDeleteTrafHour;
|
||||
static const char * const sqlDeleteTrafDay;
|
||||
static const char * const sqlDeleteTrafMonth;
|
||||
|
||||
static const char * const sqlDeleteAppTrafHour;
|
||||
static const char * const sqlDeleteAppTrafDay;
|
||||
static const char * const sqlDeleteAppTrafMonth;
|
||||
|
||||
static const char * const sqlResetAppTrafTotals;
|
||||
};
|
||||
|
||||
#endif // DATABASESQL_H
|
||||
|
@ -7,6 +7,8 @@
|
||||
<file>images/application_double.png</file>
|
||||
<file>images/application_edit.png</file>
|
||||
<file>images/application_error.png</file>
|
||||
<file>images/arrow_refresh.png</file>
|
||||
<file>images/bin_empty.png</file>
|
||||
<file>images/cancel.png</file>
|
||||
<file>images/chart_line.png</file>
|
||||
<file>images/clock.png</file>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>qml/controls/ButtonMenu.qml</file>
|
||||
<file>qml/controls/TextAreaFrame.qml</file>
|
||||
<file>qml/controls/TextContextMenu.qml</file>
|
||||
<file>qml/controls/TextFieldFrame.qml</file>
|
||||
|
BIN
src/ui/images/arrow_refresh.png
Normal file
BIN
src/ui/images/arrow_refresh.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 685 B |
BIN
src/ui/images/bin_empty.png
Normal file
BIN
src/ui/images/bin_empty.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 475 B |
@ -32,6 +32,22 @@ void AppBlockedModel::clear()
|
||||
StringListModel::clear();
|
||||
}
|
||||
|
||||
void AppBlockedModel::remove(int row)
|
||||
{
|
||||
row = adjustRow(row);
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
|
||||
const QString appPath = list().at(row);
|
||||
|
||||
m_appIpList.remove(appPath);
|
||||
m_appIpSet.remove(appPath);
|
||||
|
||||
removeRow(row);
|
||||
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void AppBlockedModel::addLogEntry(const LogEntryBlocked &logEntry)
|
||||
{
|
||||
const QString appPath = logEntry.path();
|
||||
|
@ -25,6 +25,8 @@ signals:
|
||||
public slots:
|
||||
void clear() override;
|
||||
|
||||
void remove(int row = -1) override;
|
||||
|
||||
private:
|
||||
QHash<QString, QStringList> m_appIpList;
|
||||
QHash<QString, QSet<QString>> m_appIpSet;
|
||||
|
@ -16,8 +16,11 @@ void AppStatModel::initialize()
|
||||
updateList();
|
||||
}
|
||||
|
||||
TrafListModel *AppStatModel::trafListModel(int trafType, int row) const
|
||||
TrafListModel *AppStatModel::trafListModel(int trafType, int row,
|
||||
const QString &appPath) const
|
||||
{
|
||||
Q_UNUSED(appPath) // used to properly refresh trafListModel
|
||||
|
||||
Q_ASSERT(row < m_appIds.size());
|
||||
|
||||
m_trafListModel->setType(static_cast<TrafListModel::TrafType>(trafType));
|
||||
@ -34,6 +37,23 @@ void AppStatModel::clear()
|
||||
updateList();
|
||||
}
|
||||
|
||||
void AppStatModel::remove(int row)
|
||||
{
|
||||
row = adjustRow(row);
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
|
||||
const qint64 appId = m_appIds.at(row);
|
||||
|
||||
m_databaseManager->deleteApp(appId);
|
||||
|
||||
m_appIds.remove(row);
|
||||
|
||||
removeRow(row);
|
||||
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void AppStatModel::updateList()
|
||||
{
|
||||
QStringList list;
|
||||
|
@ -16,7 +16,8 @@ public:
|
||||
|
||||
void initialize();
|
||||
|
||||
Q_INVOKABLE TrafListModel *trafListModel(int trafType, int row) const;
|
||||
Q_INVOKABLE TrafListModel *trafListModel(int trafType, int row,
|
||||
const QString &appPath) const;
|
||||
|
||||
void handleProcNew(const QString &appPath);
|
||||
void handleStatTraf(quint16 procCount, const quint8 *procBits,
|
||||
@ -27,6 +28,8 @@ signals:
|
||||
public slots:
|
||||
void clear() override;
|
||||
|
||||
void remove(int row = -1) override;
|
||||
|
||||
private:
|
||||
void updateList();
|
||||
|
||||
|
@ -27,6 +27,11 @@ void StringListModel::setList(const QStringList &list)
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void StringListModel::clear()
|
||||
{
|
||||
setList(QStringList());
|
||||
}
|
||||
|
||||
void StringListModel::insert(const QString &text, int row)
|
||||
{
|
||||
row = adjustRow(row);
|
||||
@ -41,7 +46,7 @@ void StringListModel::remove(int row)
|
||||
row = adjustRow(row);
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
m_list.removeAt(row);
|
||||
removeRow(row);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
@ -56,9 +61,9 @@ void StringListModel::replace(const QString &text, int row)
|
||||
emit dataChanged(modelIndex, modelIndex);
|
||||
}
|
||||
|
||||
void StringListModel::clear()
|
||||
void StringListModel::removeRow(int row)
|
||||
{
|
||||
setList(QStringList());
|
||||
m_list.removeAt(row);
|
||||
}
|
||||
|
||||
int StringListModel::adjustRow(int row) const
|
||||
|
@ -17,17 +17,18 @@ public:
|
||||
const QStringList &list() const { return m_list; }
|
||||
void setList(const QStringList &list);
|
||||
|
||||
protected:
|
||||
void insert(const QString &text, int row = -1);
|
||||
void remove(int row = -1);
|
||||
void replace(const QString &text, int row = -1);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
virtual void clear();
|
||||
|
||||
private:
|
||||
virtual void insert(const QString &text, int row = -1);
|
||||
virtual void remove(int row = -1);
|
||||
virtual void replace(const QString &text, int row = -1);
|
||||
|
||||
protected:
|
||||
void removeRow(int row);
|
||||
|
||||
int adjustRow(int row) const;
|
||||
|
||||
private:
|
||||
|
@ -45,7 +45,7 @@ void TrafListModel::reset()
|
||||
|
||||
m_trafCount = getTrafCount(m_type, m_minTrafTime, m_maxTrafTime);
|
||||
|
||||
m_rowCache.invalidate();
|
||||
invalidateRowCache();
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
@ -96,13 +96,25 @@ void TrafListModel::clear()
|
||||
reset();
|
||||
}
|
||||
|
||||
void TrafListModel::resetAppTotals()
|
||||
{
|
||||
m_databaseManager->resetAppTotals();
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
void TrafListModel::refresh()
|
||||
{
|
||||
beginResetModel();
|
||||
m_rowCache.invalidate();
|
||||
invalidateRowCache();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void TrafListModel::invalidateRowCache()
|
||||
{
|
||||
m_rowCache.invalidate();
|
||||
}
|
||||
|
||||
void TrafListModel::updateRowCache(int row) const
|
||||
{
|
||||
m_rowCache.row = row;
|
||||
|
@ -56,9 +56,12 @@ signals:
|
||||
public slots:
|
||||
void clear();
|
||||
|
||||
void resetAppTotals();
|
||||
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
void invalidateRowCache();
|
||||
void updateRowCache(int row) const;
|
||||
|
||||
QString formatTrafUnit(qint64 bytes) const;
|
||||
|
20
src/ui/qml/controls/ButtonMenu.qml
Normal file
20
src/ui/qml/controls/ButtonMenu.qml
Normal file
@ -0,0 +1,20 @@
|
||||
import QtQuick 2.9
|
||||
import QtQuick.Controls 2.2
|
||||
|
||||
Button {
|
||||
id: bt
|
||||
|
||||
checkable: true
|
||||
|
||||
default property alias content: menu.contentData
|
||||
|
||||
Menu {
|
||||
id: menu
|
||||
y: bt.height
|
||||
visible: bt.checked
|
||||
|
||||
onClosed: {
|
||||
bt.checked = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -16,12 +16,6 @@ BasePage {
|
||||
(appListView.currentIndex >= 0 && appListView.currentItem)
|
||||
? appListView.currentItem.appPath : ""
|
||||
|
||||
function clearAppPaths() {
|
||||
appListView.currentIndex = -1;
|
||||
|
||||
appBlockedModel.clear();
|
||||
}
|
||||
|
||||
HostInfoCache {
|
||||
id: hostInfoCache
|
||||
}
|
||||
@ -31,13 +25,25 @@ BasePage {
|
||||
spacing: 10
|
||||
|
||||
RowLayout {
|
||||
spacing: 15
|
||||
|
||||
Button {
|
||||
ButtonMenu {
|
||||
enabled: appListView.count
|
||||
icon.source: "qrc:/images/bin_empty.png"
|
||||
text: translationManager.dummyBool
|
||||
&& qsTranslate("qml", "Clear")
|
||||
onClicked: clearAppPaths()
|
||||
|
||||
MenuItem {
|
||||
enabled: appListView.currentIndex >= 0
|
||||
text: "Remove Application"
|
||||
onTriggered: appBlockedModel.remove(
|
||||
appListView.currentIndex)
|
||||
}
|
||||
MenuItem {
|
||||
text: "Clear All"
|
||||
onTriggered: {
|
||||
appListView.currentIndex = -1;
|
||||
appBlockedModel.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
|
@ -11,7 +11,9 @@ BasePage {
|
||||
readonly property LogManager logManager: fortManager.logManager
|
||||
readonly property AppStatModel appStatModel: logManager.appStatModel
|
||||
readonly property TrafListModel trafListModel:
|
||||
appStatModel.trafListModel(tabBar.currentIndex, appListView.currentIndex)
|
||||
appStatModel.trafListModel(tabBar.currentIndex,
|
||||
appListView.currentIndex,
|
||||
currentAppPath)
|
||||
|
||||
readonly property string currentAppPath:
|
||||
(appListView.currentIndex >= 0 && appListView.currentItem)
|
||||
@ -40,10 +42,9 @@ BasePage {
|
||||
spacing: 10
|
||||
|
||||
RowLayout {
|
||||
spacing: 15
|
||||
|
||||
Button {
|
||||
enabled: appListView.count
|
||||
icon.source: "qrc:/images/arrow_refresh.png"
|
||||
text: translationManager.dummyBool
|
||||
&& qsTranslate("qml", "Refresh")
|
||||
onClicked: trafListModel.refresh()
|
||||
@ -52,6 +53,11 @@ BasePage {
|
||||
Row {
|
||||
spacing: 5
|
||||
|
||||
Item {
|
||||
width: 1
|
||||
height: 1
|
||||
}
|
||||
|
||||
Label {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: translationManager.dummyBool
|
||||
@ -74,14 +80,28 @@ BasePage {
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
ButtonMenu {
|
||||
enabled: appListView.count
|
||||
icon.source: "qrc:/images/bin_empty.png"
|
||||
text: translationManager.dummyBool
|
||||
&& qsTranslate("qml", "Clear")
|
||||
onClicked: {
|
||||
appStatModel.clear();
|
||||
|
||||
MenuItem {
|
||||
enabled: appListView.currentIndex > 0
|
||||
text: "Remove Application"
|
||||
onTriggered: appStatModel.remove(
|
||||
appListView.currentIndex)
|
||||
}
|
||||
MenuItem {
|
||||
text: "Reset Totals"
|
||||
onTriggered: trafListModel.resetAppTotals()
|
||||
}
|
||||
MenuItem {
|
||||
text: "Clear All"
|
||||
onTriggered: {
|
||||
appListView.currentIndex = 0;
|
||||
appStatModel.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user