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 <QIcon>
24#include <QTimer>
25#include <QWidget>
26#include <QTableView>
27#include <QVBoxLayout>
28#include <QSplitter>
29#include <QAbstractTableModel>
30#include <QFutureWatcher>
31#include <QItemSelection>
32#include <QtCharts/QChartView>
33#include <memory>
34#include <boost/uuid/uuid.hpp>
35#include "ores.qt/ClientManager.hpp"
36#include "ores.logging/make_logger.hpp"
37#include "ores.iam.api/domain/session.hpp"
38#include "ores.iam.api/messaging/session_samples_protocol.hpp"
39
40namespace ores::qt {
41
45class SessionHistoryModel : public QAbstractTableModel {
46 Q_OBJECT
47
48public:
49 explicit SessionHistoryModel(QObject* parent = nullptr);
50
51 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
52 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
53 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
54 QVariant headerData(int section, Qt::Orientation orientation,
55 int role = Qt::DisplayRole) const override;
56
57 void setSessions(const std::vector<iam::domain::session>& sessions);
58 void clear();
59
67 void updateActiveBytesFromClient(std::uint64_t bytes_sent,
68 std::uint64_t bytes_received);
69
70 const std::vector<iam::domain::session>& sessions() const { return sessions_; }
71
72private:
73 enum Column {
74 StartTime,
75 EndTime,
76 Duration,
77 ClientIP,
78 Country,
79 BytesSent,
80 BytesReceived,
81 ClientVersion,
82 ColumnCount
83 };
84
85 std::vector<iam::domain::session> sessions_;
86 QIcon activeIcon_;
87 QIcon historyIcon_;
88};
89
96class SessionHistoryDialog : public QWidget {
97 Q_OBJECT
98
99private:
100 inline static std::string_view logger_name =
101 "ores.qt.session_history_dialog";
102
103 [[nodiscard]] static auto& lg() {
104 using namespace ores::logging;
105 static auto instance = make_logger(logger_name);
106 return instance;
107 }
108
109public:
110 explicit SessionHistoryDialog(ClientManager* clientManager,
111 QWidget* parent = nullptr);
112 ~SessionHistoryDialog() override;
113
120 void setAccount(const boost::uuids::uuid& accountId,
121 const QString& username);
122
126 void refresh();
127
128signals:
129 void statusMessage(const QString& message);
130 void errorMessage(const QString& message);
131
132private slots:
133 void onSessionsLoaded();
134 void onSamplesLoaded();
135 void onSessionSelectionChanged(const QItemSelection& selected,
136 const QItemSelection& deselected);
137 void onSampleRefreshTimeout();
138
139private:
140 void setupUi();
141
142 QTableView* tableView_;
143 SessionHistoryModel* model_;
144 QSplitter* splitter_;
145 QChartView* chartView_;
146 ClientManager* clientManager_;
147 boost::uuids::uuid accountId_;
148 QString username_;
149
150 struct FetchResult {
151 bool success;
152 std::vector<iam::domain::session> sessions;
153 std::uint32_t total_count;
154 };
155
156 struct FetchSamplesResult {
157 bool success;
158 bool is_active = false; // true if the session is still running
159 boost::uuids::uuid session_id;
160 QString session_label;
161 std::vector<iam::messaging::session_sample_dto> samples;
162 };
163
164 QFutureWatcher<FetchResult>* watcher_;
165 QFutureWatcher<FetchSamplesResult>* samplesWatcher_;
166 QTimer* sampleRefreshTimer_;
167
168 // Currently selected session state (for auto-refresh)
169 bool hasSelectedSession_ = false;
170 boost::uuids::uuid selectedSessionId_ = {};
171 QString selectedSessionLabel_;
172 bool selectedSessionActive_ = false;
173};
174
175}
176
177#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Table model for displaying session history.
Definition SessionHistoryDialog.hpp:45
void updateActiveBytesFromClient(std::uint64_t bytes_sent, std::uint64_t bytes_received)
Inject live byte counters into active (no end_time) session rows.
Definition SessionHistoryDialog.cpp:179
Dialog for displaying session history for an account.
Definition SessionHistoryDialog.hpp:96
void setAccount(const boost::uuids::uuid &accountId, const QString &username)
Set the account to display sessions for.
Definition SessionHistoryDialog.cpp:265
void refresh()
Refresh the session list from the server.
Definition SessionHistoryDialog.cpp:273