20#ifndef ORES_QT_CLIENT_ACCOUNT_MODEL_HPP
21#define ORES_QT_CLIENT_ACCOUNT_MODEL_HPP
25#include <unordered_set>
26#include <QFutureWatcher>
27#include <QAbstractTableModel>
29#include "ores.qt/ClientManager.hpp"
30#include "ores.utility/log/make_logger.hpp"
31#include "ores.accounts/domain/account.hpp"
32#include "ores.accounts/domain/login_info.hpp"
59 std::optional<accounts::domain::login_info> loginInfo;
72 inline static std::string_view logger_name =
73 "ores.qt.client_account_model";
75 [[nodiscard]]
static auto& lg() {
77 static auto instance = make_logger(logger_name);
83 QObject* parent =
nullptr);
87 int rowCount(
const QModelIndex& parent = QModelIndex())
const override;
88 int columnCount(
const QModelIndex& parent = QModelIndex())
const override;
89 QVariant data(
const QModelIndex& index,
int role = Qt::DisplayRole)
const override;
90 QVariant headerData(
int section, Qt::Orientation orientation,
91 int role = Qt::DisplayRole)
const override;
103 void refresh(
bool replace =
true);
110 bool canFetchMore(
const QModelIndex& parent = QModelIndex())
const override;
118 void fetchMore(
const QModelIndex& parent = QModelIndex())
override;
176 void onAccountsLoaded();
177 void onPulseTimerTimeout();
189 QVariant recency_foreground_color(
const std::string& username)
const;
194 void update_recent_accounts();
220 const std::optional<accounts::domain::login_info>& loginInfo);
224 std::vector<accounts::domain::account> accounts;
225 std::vector<accounts::domain::login_info> loginInfos;
226 std::uint32_t total_available_count;
229 using FutureWatcherResult = FetchResult;
231 ClientManager* clientManager_;
232 std::vector<AccountWithLoginInfo> accounts_;
233 QFutureWatcher<FutureWatcherResult>* watcher_;
234 std::uint32_t page_size_{100};
235 std::uint32_t total_available_count_{0};
236 bool is_fetching_{
false};
239 std::unordered_set<std::string> recent_usernames_;
240 QDateTime last_reload_time_;
241 QTimer* pulse_timer_;
242 mutable bool pulse_state_{
false};
243 mutable int pulse_count_{0};
244 static constexpr int max_pulse_cycles_{6};
245 static constexpr int pulse_interval_ms_{500};
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
LoginStatus
Enum representing account login status buckets.
Definition ClientAccountModel.hpp:42
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:30
Represents a user account in the system.
Definition account.hpp:31
Composite structure combining account with its login status.
Definition ClientAccountModel.hpp:57
Model for displaying accounts fetched from the server via client.
Definition ClientAccountModel.hpp:68
bool canFetchMore(const QModelIndex &parent=QModelIndex()) const override
Check if more data can be fetched from the server.
Definition ClientAccountModel.cpp:359
void fetchMore(const QModelIndex &parent=QModelIndex()) override
Fetch the next page of data from the server.
Definition ClientAccountModel.cpp:371
std::vector< AccountWithLoginInfo > getAccountsWithLoginInfo() const
Get all accounts with their login info.
Definition ClientAccountModel.cpp:355
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientAccountModel.cpp:379
const accounts::domain::account * getAccount(int row) const
Get account at the specified row (for backward compatibility).
Definition ClientAccountModel.cpp:348
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientAccountModel.hpp:162
const AccountWithLoginInfo * getAccountWithLoginInfo(int row) const
Get account with login info at the specified row.
Definition ClientAccountModel.cpp:341
void dataLoaded()
Emitted when data has been successfully loaded.
void refresh(bool replace=true)
Refresh account data from server asynchronously.
Definition ClientAccountModel.cpp:143
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientAccountModel.hpp:148
void loadError(const QString &error_message)
Emitted when an error occurs during data loading.
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:56