ORE Studio 0.0.4
Loading...
Searching...
No Matches
SessionHistoryDialog.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_SESSION_HISTORY_DIALOG_HPP
21#define ORES_QT_SESSION_HISTORY_DIALOG_HPP
22
23#include <QDialog>
24#include <QTableView>
25#include <QVBoxLayout>
26#include <QAbstractTableModel>
27#include <QFutureWatcher>
28#include <memory>
29#include <boost/uuid/uuid.hpp>
30#include "ores.qt/ClientManager.hpp"
31#include "ores.logging/make_logger.hpp"
32#include "ores.iam/domain/session.hpp"
33
34namespace ores::qt {
35
39class SessionHistoryModel : public QAbstractTableModel {
40 Q_OBJECT
41
42public:
43 explicit SessionHistoryModel(QObject* parent = nullptr);
44
45 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
46 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
47 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
48 QVariant headerData(int section, Qt::Orientation orientation,
49 int role = Qt::DisplayRole) const override;
50
51 void setSessions(const std::vector<iam::domain::session>& sessions);
52 void clear();
53
54private:
55 enum Column {
56 StartTime,
57 EndTime,
58 Duration,
59 ClientIP,
60 Country,
61 BytesSent,
62 BytesReceived,
63 ClientVersion,
64 ColumnCount
65 };
66
67 std::vector<iam::domain::session> sessions_;
68};
69
76class SessionHistoryDialog : public QDialog {
77 Q_OBJECT
78
79private:
80 inline static std::string_view logger_name =
81 "ores.qt.session_history_dialog";
82
83 [[nodiscard]] static auto& lg() {
84 using namespace ores::logging;
85 static auto instance = make_logger(logger_name);
86 return instance;
87 }
88
89public:
90 explicit SessionHistoryDialog(ClientManager* clientManager,
91 QWidget* parent = nullptr);
92 ~SessionHistoryDialog() override;
93
100 void setAccount(const boost::uuids::uuid& accountId,
101 const QString& username);
102
106 void refresh();
107
108signals:
109 void statusMessage(const QString& message);
110 void errorMessage(const QString& message);
111
112private slots:
113 void onSessionsLoaded();
114
115private:
116 void setupUi();
117
118 QTableView* tableView_;
119 SessionHistoryModel* model_;
120 ClientManager* clientManager_;
121 boost::uuids::uuid accountId_;
122 QString username_;
123
124 struct FetchResult {
125 bool success;
126 std::vector<iam::domain::session> sessions;
127 std::uint32_t total_count;
128 };
129
130 QFutureWatcher<FetchResult>* watcher_;
131};
132
133}
134
135#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:90
Table model for displaying session history.
Definition SessionHistoryDialog.hpp:39
Dialog for displaying session history for an account.
Definition SessionHistoryDialog.hpp:76
void setAccount(const boost::uuids::uuid &accountId, const QString &username)
Set the account to display sessions for.
Definition SessionHistoryDialog.cpp:206
void refresh()
Refresh the session list from the server.
Definition SessionHistoryDialog.cpp:214