| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
workspace_state.h
Go to the documentation of this file.
1
15#ifndef WORKSPACE_STATE_H
16#define WORKSPACE_STATE_H
17
18#include "config.h"
19
20#include <QObject>
21#include <QStringList>
22#include <QFileInfo>
23#include <QList>
24#include <functional>
25
32 struct RecentFileInfo {
33 QString filename;
34 qint64 size = 0;
35 bool accessible = false;
36};
37
50 class WorkspaceState : public QObject
51{
52 Q_OBJECT
53
54 public:
60 static WorkspaceState* instance();
61
62 virtual ~WorkspaceState();
63
64 // Prevent copying
65 WorkspaceState(const WorkspaceState&) = delete;
66 WorkspaceState& operator=(const WorkspaceState&) = delete;
67
77 bool loadCommonState(QString *errorPath = nullptr, int *errorCode = nullptr);
78
84 QString recentCommonFilePath() const;
85
91 QString recentProfileFilePath() const;
92
98 const QList<RecentFileInfo>& recentCaptureFiles() const;
99
107 QStringList recentCaptureFilenames() const;
108
114 void addRecentCaptureFile(const QString &filePath);
115
121 void removeRecentCaptureFile(const QString &filePath);
122
126 void clearRecentCaptureFiles();
127
128signals:
132 void recentCaptureFilesChanged();
133
139 void recentFileStatusChanged(const QString &filename);
140
144 void stateLoaded();
145
149 void stateSaved();
150
151 protected:
152 explicit WorkspaceState(QObject *parent = nullptr);
153
154 private slots:
158 void onFileStatusChecked(const QString &filename, qint64 size, bool accessible);
159
160 private:
168 bool parseRecentFile(const QString &filePath,
169 std::function<void(const QString &key, const QString &value)> handler);
170
174 void queueFileStatusCheck(const QString &filename);
175
176 QList<RecentFileInfo> recent_capture_files_;
177
178 static constexpr const char* RECENT_COMMON_FILE_NAME = "recent_common";
179 static constexpr const char* RECENT_PROFILE_FILE_NAME = "recent";
180 static constexpr const char* KEY_CAPTURE_FILE = "recent.capture_file";
181};
182
183#endif // WORKSPACE_STATE_H
WorkspaceState
Manages workspace state that persists between sessions.
Definition workspace_state.h:51
WorkspaceState::loadCommonState
bool loadCommonState(QString *errorPath=nullptr, int *errorCode=nullptr)
Load state from the recent_common file.
Definition workspace_state.cpp:107
WorkspaceState::recentCaptureFilenames
QStringList recentCaptureFilenames() const
Get just the filenames of recent capture files.
Definition workspace_state.cpp:163
WorkspaceState::recentCaptureFilesChanged
void recentCaptureFilesChanged()
Emitted when the recent capture files list changes.
WorkspaceState::recentProfileFilePath
QString recentProfileFilePath() const
Get the path to the profile-specific recent file.
Definition workspace_state.cpp:60
WorkspaceState::addRecentCaptureFile
void addRecentCaptureFile(const QString &filePath)
Add a capture file to the recent files list.
Definition workspace_state.cpp:173
WorkspaceState::recentCommonFilePath
QString recentCommonFilePath() const
Get the path to the recent_common file.
Definition workspace_state.cpp:45
WorkspaceState::stateLoaded
void stateLoaded()
Emitted when state is loaded from disk.
WorkspaceState::instance
static WorkspaceState * instance()
Returns the singleton instance.
Definition workspace_state.cpp:38
WorkspaceState::recentFileStatusChanged
void recentFileStatusChanged(const QString &filename)
Emitted when a file's status (size/accessibility) is updated.
WorkspaceState::recentCaptureFiles
const QList< RecentFileInfo > & recentCaptureFiles() const
Get the list of recently opened capture files.
Definition workspace_state.cpp:158
WorkspaceState::clearRecentCaptureFiles
void clearRecentCaptureFiles()
Clear all recent capture files.
Definition workspace_state.cpp:223
WorkspaceState::stateSaved
void stateSaved()
Emitted when state is saved to disk.
WorkspaceState::removeRecentCaptureFile
void removeRecentCaptureFile(const QString &filePath)
Remove a capture file from the recent files list.
Definition workspace_state.cpp:207
RecentFileInfo
Information about a recent capture file.
Definition workspace_state.h:32