Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
WorkspaceState Class Reference

Manages workspace state that persists between sessions. More...

#include <workspace_state.h>

Inheritance diagram for WorkspaceState:

Signals

void recentCaptureFilesChanged ()
 Emitted when the recent capture files list changes.
void recentFileStatusChanged (const QString &filename)
 Emitted when a file's status (size/accessibility) is updated.
void stateLoaded ()
 Emitted when state is loaded from disk.
void stateSaved ()
 Emitted when state is saved to disk.

Public Member Functions

virtual ~WorkspaceState ()
 Destroys the singleton and releases all owned resources.
 WorkspaceState (const WorkspaceState &)=delete
 Deleted copy constructor to enforce the singleton pattern.
WorkspaceState & operator= (const WorkspaceState &)=delete
 Deleted assignment operator to enforce the singleton pattern.
bool loadCommonState (QString *errorPath=nullptr, int *errorCode=nullptr)
 Load state from the recent_common file.
QString recentCommonFilePath () const
 Get the path to the recent_common file.
QString recentProfileFilePath () const
 Get the path to the profile-specific recent file.
QString personalThemesPath () const
 Get the path to the personal themes directory.
const QList< RecentFileInfo > & recentCaptureFiles () const
 Get the list of recently opened capture files.
QStringList recentCaptureFilenames () const
 Get just the filenames of recent capture files.
void addRecentCaptureFile (const QString &filePath)
 Add a capture file to the recent files list.
void removeRecentCaptureFile (const QString &filePath)
 Remove a capture file from the recent files list.
void clearRecentCaptureFiles ()
 Clear all recent capture files.

Static Public Member Functions

static WorkspaceState * instance ()
 Returns the singleton instance.
static bool isDevelopmentBuild ()
 Check if this is a development build.
static bool isPortableApplication ()
 Check if the application is running in portable mode. (Windows only).

Protected Member Functions

 WorkspaceState (QObject *parent=nullptr)
 Constructs the WorkspaceState; use instance() to obtain the singleton.

Detailed Description

Manages workspace state that persists between sessions.

This class provides Qt-native access to the "recent" settings. It currently runs parallel to ui/recent.c for gradual migration.

Usage: WorkspaceState::instance()->loadCommonState(); QStringList files = WorkspaceState::instance()->recentCaptureFiles();

The singleton pattern avoids adding more dependencies to MainApplication.

Constructor & Destructor Documentation

◆ WorkspaceState()

WorkspaceState::WorkspaceState ( QObject * parent = nullptr)
explicitprotected

Constructs the WorkspaceState; use instance() to obtain the singleton.

Parameters
parentOptional parent QObject.

Member Function Documentation

◆ addRecentCaptureFile()

void WorkspaceState::addRecentCaptureFile ( const QString & filePath)

Add a capture file to the recent files list.

Parameters
filePathThe path to the capture file.

◆ instance()

WorkspaceState * WorkspaceState::instance ( )
static

Returns the singleton instance.

Thread-safe in C++11 and later (Meyer's Singleton).

◆ isDevelopmentBuild()

bool WorkspaceState::isDevelopmentBuild ( )
static

Check if this is a development build.

Returns true when VERSION_FLAVOR is non-empty (the default "Development Build" set by CMake). Release builds either leave VERSION_FLAVOR empty or undefine it entirely.

Returns
true for development builds, false for releases.

◆ isPortableApplication()

bool WorkspaceState::isPortableApplication ( )
static

Check if the application is running in portable mode. (Windows only).

In portable mode, state files are stored in the application directory instead of a user-specific location. For any other OS than Windows, this will return false.

Returns
true if running in portable mode, false otherwise.

◆ loadCommonState()

bool WorkspaceState::loadCommonState ( QString * errorPath = nullptr,
int * errorCode = nullptr )

Load state from the recent_common file.

Call this during application startup after recent_read_static() has been called.

Parameters
[out]errorPathIf loading fails, contains the path that failed.
[out]errorCodeIf loading fails, contains the errno.
Returns
true on success, false on failure.

◆ personalThemesPath()

QString WorkspaceState::personalThemesPath ( ) const

Get the path to the personal themes directory.

Mirrors get_extcap_pers_dir() but stays UI-only. Layout: Windows: APPDATA%\Wireshark\themes Unix: ~/.local/lib/wireshark/themes

Unlike built-in themes (which live under :/themes/<name>/theme.jsonc), personal themes are plain *.jsonc files dropped directly into this directory. The filename stem (without .jsonc) becomes the theme's internal name; for example, mytheme.jsonc yields internalName "mytheme".

The directory is not created here. Callers should treat a missing directory as "no personal themes" rather than an error.

Returns
Full path to the personal themes directory (may not exist).

◆ recentCaptureFilenames()

QStringList WorkspaceState::recentCaptureFilenames ( ) const

Get just the filenames of recent capture files.

Convenience method for code that only needs the paths.

Returns
List of file paths, most recent last.

◆ recentCaptureFiles()

const QList< RecentFileInfo > & WorkspaceState::recentCaptureFiles ( ) const

Get the list of recently opened capture files.

Returns
List of file info structs, most recent last.

◆ recentCommonFilePath()

QString WorkspaceState::recentCommonFilePath ( ) const

Get the path to the recent_common file.

Returns
Full path to the recent_common file.

◆ recentFileStatusChanged

void WorkspaceState::recentFileStatusChanged ( const QString & filename)
signal

Emitted when a file's status (size/accessibility) is updated.

Parameters
filenameThe file whose status was updated.

◆ recentProfileFilePath()

QString WorkspaceState::recentProfileFilePath ( ) const

Get the path to the profile-specific recent file.

Returns
Full path to the recent file for the current profile.

◆ removeRecentCaptureFile()

void WorkspaceState::removeRecentCaptureFile ( const QString & filePath)

Remove a capture file from the recent files list.

Parameters
filePathThe path to remove.

The documentation for this class was generated from the following files: