Wireshark 4.7.3
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
profile_model.h
Go to the documentation of this file.
1
9
10#ifndef PROFILE_MODEL_H
11#define PROFILE_MODEL_H
12
13#include "config.h"
14
15#include <ui/profile.h>
16
17#include <QAbstractTableModel>
18#include <QSortFilterProxyModel>
19#include <QLoggingCategory>
20#include <QFileInfoList>
21
22Q_DECLARE_LOGGING_CATEGORY(profileLogger)
23
24
29{
30public:
40
46
56 ProfileItem(QString name, QString reference, StatusType status, bool isGlobal, bool fromGlobal, bool isImport);
57
62 const QString &getName() const { return name_; }
63
68 const QString getType() const;
69
74 const QString &getAutoSwitchFilter() const { return autoSwitchFilter_; }
75
80 StatusType getStatus() const { return status_; }
81
86 bool isGlobal() const { return isGlobal_; }
87
92 bool isFromGlobal() const { return fromGlobal_; }
93
98 bool isChanged() const { return isChanged_; }
99
104 bool isDefault() const;
105
110 bool isImport() const { return isImport_; }
111
116 bool isDeleted() const { return setForDeletion_; }
117
126 const QString &getReference() const { return reference_; }
127
133 QString getProfilePath(QString profileName) const;
134
139 QString getProfilePath() const;
140
145 void setName(QString value);
146
151 void setStatus(StatusType status) { status_ = status; }
152
157 void setAutoSwitchFilter(QString value);
158
160 void setForDeletion() { setForDeletion_ = true; }
161
162private:
163 QString name_;
164 StatusType status_;
165
166 QString autoSwitchFilter_;
167 bool isGlobal_;
168 bool fromGlobal_ = false;
169 bool isImport_ = false;
170 bool setForDeletion_ = false;
171
172 QString reference_;
173
174 bool isChanged_ = false;
175};
176
177
182class ProfileSortModel : public QSortFilterProxyModel
183{
184 Q_OBJECT
185
186public:
191 ProfileSortModel(QObject *parent = Q_NULLPTR);
192
201
206 void setFilterType(FilterType ft);
207
212 void setFilterString(QString txt = QString());
213
218 static QStringList filterTypes();
219
220protected:
228 virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
229
236 virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
237
238private:
239 FilterType ft_;
240 QString ftext_;
241};
242
243
248class ProfileModel : public QAbstractTableModel
249{
250 Q_OBJECT
251
252public:
257 explicit ProfileModel(QObject *parent = Q_NULLPTR);
258
262 virtual ~ProfileModel();
263
267 enum {
273
277 enum {
278 DATA_IS_DEFAULT = Qt::UserRole,
281
288 void fillTable();
289
290 // ── QAbstractItemModel interface ──────────────────────────────────────
291
297 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
298
304 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
305
312 virtual QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override;
313
321 virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override;
322
330 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
331
341 virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
342
343 // ── Mutation helpers ──────────────────────────────────────────────────
344
349 void deleteEntries(QModelIndexList idcs);
350
356 bool restoreEntries(QModelIndexList idcs);
357
358 // ── Lookup ────────────────────────────────────────────────────────────
359
365 int findByName(const QString &name);
366
372 QModelIndex addNewProfile(QString name);
373
380 QModelIndex duplicateEntry(QModelIndex idx, ProfileItem::StatusType status = ProfileItem::StatusType::Copy);
381
386 QModelIndex activeProfile() const;
387
392 bool userProfilesExist() const;
393
399 bool isDataValid(QString &err);
400
401#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
409 bool exportProfiles(QString filename, QModelIndexList items, QString &err);
410
417 void importProfilesFromZip(QString filename, int &skippedCnt, QStringList &importList);
418#endif
419
427 void importProfilesFromDir(QString filename, int &skippedCnt, QStringList &importList, bool fromZip = false);
428
435 static bool checkNameValidity(QString name, QString &msg);
436
444 QList<int> findAllByNameAndVisibility(const QString &name, bool isGlobal = false, bool searchReference = false) const;
445
453 bool checkDuplicate(const QModelIndex &index, bool isOriginalToDuplicate = false) const;
454
459 void applyChanges();
460
466 const ProfileItem *getCurrentProfile() const { return current_profile_; }
467
473 const ProfileItem *getProfile(int index) const { return profile_items_[index]; }
474
480 const ProfileItem *getPersonalProfile(const QString &name);
481
488 QVariant dataPath(const QModelIndex &idx, QString &profilePath) const;
489
490protected:
495 static QString illegalCharacters();
496
506 QModelIndex addNewProfile(QString name, QString reference, bool isGlobal = false, bool fromGlobal = false, bool isImport = false);
507
508private:
509 QList<ProfileItem *> profile_items_;
510 QStringList profile_files_;
511 ProfileItem *current_profile_ = Q_NULLPTR;
512
520 int findByNameAndVisibility(const QString &name, bool isGlobal = false, bool searchReference = false) const;
521
522#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
529 static bool acceptFile(QString fileName, int fileSize);
530
536 static QString cleanName(QString fileName);
537#endif
538
544 QVariant dataDisplay(const QModelIndex &idx) const;
545
551 QVariant dataFontRole(const QModelIndex &idx) const;
552
558 QVariant dataBackgroundRole(const QModelIndex &idx) const;
559
565 QVariant dataForegroundRole(const QModelIndex &idx) const;
566
572 QVariant dataToolTipRole(const QModelIndex &idx) const;
573
574#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
580 QStringList exportFileList(QModelIndexList items);
581#endif
582
590 bool copyTempToProfile(QString tempPath, QString profilePath, bool &wasEmpty);
591
599 QFileInfoList filterProfilePath(QString path, QFileInfoList ent, bool fromZip);
600
606 QFileInfoList uniquePaths(QFileInfoList lst);
607};
608
609#endif
Represents a single configuration profile entry in the profile manager, tracking its name,...
Definition profile_model.h:29
const QString & getName() const
Returns the current display name of the profile.
Definition profile_model.h:62
bool isChanged() const
Returns whether the profile has unsaved changes relative to its on-disk state.
Definition profile_model.h:98
StatusType getStatus() const
Returns the current lifecycle status of this profile item.
Definition profile_model.h:80
const QString & getReference() const
Returns the original name of the profile at creation time.
Definition profile_model.h:126
const QString & getAutoSwitchFilter() const
Returns the display-filter expression used for automatic profile switching.
Definition profile_model.h:74
bool isDeleted() const
Returns whether this profile is marked for deletion on the next apply.
Definition profile_model.h:116
bool isImport() const
Returns whether this profile was imported from an external source.
Definition profile_model.h:110
void setForDeletion()
Marks this profile for deletion on the next call to ProfileModel::applyChanges().
Definition profile_model.h:160
void setStatus(StatusType status)
Updates the lifecycle status of the profile.
Definition profile_model.h:151
ProfileItem(profile_def *profile)
Constructs a ProfileItem from a raw libwireshark profile definition.
Definition profile_model.cpp:37
StatusType
Lifecycle status of a profile item within the model.
Definition profile_model.h:34
@ Copy
Definition profile_model.h:38
@ New
Definition profile_model.h:35
@ Changed
Definition profile_model.h:37
@ Existing
Definition profile_model.h:36
bool isFromGlobal() const
Returns whether this profile was originally copied from a global profile.
Definition profile_model.h:92
bool isGlobal() const
Returns whether this is a read-only global (system-wide) profile.
Definition profile_model.h:86
QVariant dataPath(const QModelIndex &idx, QString &profilePath) const
Returns display data for a cell together with the profile's filesystem path.
Definition profile_model.cpp:429
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override
Sets data for an editable cell (profile name or auto-switch filter).
Definition profile_model.cpp:896
const ProfileItem * getCurrentProfile() const
Returns the ProfileItem representing the profile that was active when the model was constructed.
Definition profile_model.h:466
@ DATA_IS_DEFAULT
Definition profile_model.h:278
@ DATA_IS_GLOBAL
Definition profile_model.h:279
const ProfileItem * getProfile(int index) const
Returns the ProfileItem at the given flat list index.
Definition profile_model.h:473
enum ProfileModel::@335073123265076173203353240160121376071234354003 data_values_
Custom Qt::UserRole data keys returned by data().
enum ProfileModel::@167051107222365245320312345074023160155247170055 columns_
Column index constants for the profile table.
int findByName(const QString &name)
Returns the row index of the first profile whose name matches exactly.
Definition profile_model.cpp:634
bool restoreEntries(QModelIndexList idcs)
Clears the deletion flag on the profiles at the given indices.
Definition profile_model.cpp:858
static bool checkNameValidity(QString name, QString &msg)
Validates a candidate profile name for illegal characters and reserved names.
Definition profile_model.cpp:1165
virtual QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const override
Returns data for the given index and role.
Definition profile_model.cpp:560
const ProfileItem * getPersonalProfile(const QString &name)
Finds a personal (non-global) profile by name.
Definition profile_model.cpp:643
bool userProfilesExist() const
Returns whether any editable (non-global, non-default) profiles exist.
Definition profile_model.cpp:249
QModelIndex duplicateEntry(QModelIndex idx, ProfileItem::StatusType status=ProfileItem::StatusType::Copy)
Creates a duplicate of the profile at idx.
Definition profile_model.cpp:706
void deleteEntries(QModelIndexList idcs)
Marks the profiles at the given indices for deletion.
Definition profile_model.cpp:781
bool isDataValid(QString &err)
Validates all pending profile changes for conflicts and illegal names.
Definition profile_model.cpp:306
@ COL_NAME
Definition profile_model.h:268
@ COL_TYPE
Definition profile_model.h:269
@ COL_AUTO_SWITCH_FILTER
Definition profile_model.h:270
@ _LAST_ENTRY
Definition profile_model.h:271
void importProfilesFromDir(QString filename, int &skippedCnt, QStringList &importList, bool fromZip=false)
Imports profiles from a directory (or an extracted ZIP staging area).
Definition profile_model.cpp:1105
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of profile rows.
Definition profile_model.cpp:260
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns (always _LAST_ENTRY).
Definition profile_model.cpp:265
QModelIndex addNewProfile(QString name)
Adds a new empty personal profile with the given name.
Definition profile_model.cpp:677
static QString illegalCharacters()
Returns the set of characters that are not permitted in profile names.
Definition profile_model.cpp:1154
ProfileModel(QObject *parent=Q_NULLPTR)
Constructs a ProfileModel and populates it from the current profile directories.
Definition profile_model.cpp:204
QModelIndex activeProfile() const
Returns the model index of the currently active (in-use) profile row.
Definition profile_model.cpp:876
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the item flags for the given index.
Definition profile_model.cpp:611
void applyChanges()
Applies all pending changes (additions, renames, copies, deletions) to the on-disk profile directorie...
Definition profile_model.cpp:1195
QList< int > findAllByNameAndVisibility(const QString &name, bool isGlobal=false, bool searchReference=false) const
Finds all profiles matching the given name and global-scope flag.
Definition profile_model.cpp:659
bool checkDuplicate(const QModelIndex &index, bool isOriginalToDuplicate=false) const
Checks whether the profile at index has a name collision with another entry.
Definition profile_model.cpp:343
void fillTable()
(Re-)populates the model from the on-disk profile directories.
Definition profile_model.cpp:227
virtual ~ProfileModel()
Destroys the model and frees all ProfileItem instances.
Definition profile_model.cpp:220
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns the header label for the given section.
Definition profile_model.cpp:590
static QStringList filterTypes()
Returns a localised list of filter type display names, ordered by FilterType value.
Definition profile_model.cpp:170
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Determines whether a source row passes the active scope and text filters.
Definition profile_model.cpp:180
virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override
Compares two rows for sort ordering, placing personal profiles before global ones and sorting alphabe...
Definition profile_model.cpp:114
void setFilterString(QString txt=QString())
Sets a case-insensitive substring filter applied to profile names.
Definition profile_model.cpp:157
ProfileSortModel(QObject *parent=Q_NULLPTR)
Constructs a ProfileSortModel with no active text filter and AllProfiles visibility.
Definition profile_model.cpp:108
FilterType
Controls which profiles are visible based on their scope.
Definition profile_model.h:196
@ AllProfiles
Definition profile_model.h:197
@ PersonalProfiles
Definition profile_model.h:198
@ GlobalProfiles
Definition profile_model.h:199
void setFilterType(FilterType ft)
Sets the profile-scope filter.
Definition profile_model.cpp:144
Describes a single Wireshark configuration profile and its associated settings.
Definition profile.h:25
Definition packet-epl.h:22