Wireshark 5.1.0
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 <QAbstractItemModel>
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 QString getName() const;
63
68 const QString &getLeafName() const { return name_; }
69
73 ProfileItem *parent() const { return parent_; }
74
79 void setParent(ProfileItem *parent) { parent_ = parent; }
80
85 const QString getType() const;
86
91 const QString &getAutoSwitchFilter() const { return autoSwitchFilter_; }
92
97 StatusType getStatus() const;
98
103 bool isGlobal() const { return isGlobal_; }
104
109 bool isFromGlobal() const { return fromGlobal_; }
110
115 bool isChanged() const { return isChanged_; }
116
121 bool isDefault() const;
122
127 bool isImport() const { return isImport_; }
128
133 bool isDeleted() const { return setForDeletion_; }
134
143 const QString &getReference() const { return reference_; }
144
149 void setReference(QString value) { reference_ = value; }
150
156 QString getProfilePath(QString profileName) const;
157
162 QString getProfilePath() const;
163
168 void setName(QString value);
169
174 void setStatus(StatusType status) { status_ = status; }
175
180 void setAutoSwitchFilter(QString value);
181
183 void setForDeletion() { setForDeletion_ = true; }
184
185private:
186 QString name_;
187 ProfileItem *parent_ = nullptr;
188 StatusType status_;
189
190 QString autoSwitchFilter_;
191 bool isGlobal_;
192 bool fromGlobal_ = false;
193 bool isImport_ = false;
194 bool setForDeletion_ = false;
195
196 QString reference_;
197
198 bool isChanged_ = false;
199};
200
201
206class ProfileSortModel : public QSortFilterProxyModel
207{
208 Q_OBJECT
209
210public:
215 ProfileSortModel(QObject *parent = Q_NULLPTR);
216
225
230 void setFilterType(FilterType ft);
231
236 void setFilterString(QString txt = QString());
237
242 static QStringList filterTypes();
243
244protected:
252 virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
253
260 virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
261
262private:
263 FilterType ft_;
264 QString ftext_;
265};
266
267
272class ProfileModel : public QAbstractItemModel
273{
274 Q_OBJECT
275
276public:
281 explicit ProfileModel(QObject *parent = Q_NULLPTR);
282
286 virtual ~ProfileModel();
287
291 enum {
297
301 enum {
302 DATA_IS_DEFAULT = Qt::UserRole,
305
312 void fillTable();
313
314 // ── QAbstractItemModel interface ──────────────────────────────────────
315
321 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
322
323 virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
324 virtual QModelIndex parent(const QModelIndex &index) const override;
325 using QObject::parent;
326
327 virtual Qt::DropActions supportedDropActions() const override;
328 virtual QStringList mimeTypes() const override;
329 virtual QMimeData *mimeData(const QModelIndexList &indexes) const override;
330 virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
331 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
332
338 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
339
346 virtual QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override;
347
355 virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override;
356
364 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
365
375 virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
376
377 // ── Mutation helpers ──────────────────────────────────────────────────
378
383 void deleteEntries(QModelIndexList idcs);
384
390 bool restoreEntries(QModelIndexList idcs);
391
392 // ── Lookup ────────────────────────────────────────────────────────────
393
399 QModelIndex findByName(const QString &name);
400
406 QModelIndex addNewProfile(QString name);
407
415 QModelIndex duplicateEntry(QModelIndex idx, ProfileItem::StatusType status = ProfileItem::StatusType::Copy, const QString &name = QString());
416
421 QModelIndex activeProfile() const;
422
427 bool userProfilesExist() const;
428
434 bool isDataValid(QString &err);
435
441 QModelIndexList withChildren(const QModelIndexList &items) const;
442
443#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
451 bool exportProfiles(QString filename, QModelIndexList items, QString &err);
452
460 bool isExportable(const QModelIndex &idx) const;
461
468 void importProfilesFromZip(QString filename, int &skippedCnt, QStringList &importList, const QString &targetParent = QString());
469#endif
470
478 void importProfilesFromDir(QString filename, int &skippedCnt, QStringList &importList, bool fromZip = false, const QString &targetParent = QString());
479
486 static bool checkNameValidity(QString name, QString &msg);
487
495 QList<int> findAllByNameAndVisibility(const QString &name, bool isGlobal = false, bool searchReference = false, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
496
504 bool checkDuplicate(const QModelIndex &index, bool isOriginalToDuplicate = false) const;
505
510 void applyChanges();
511
517 const ProfileItem *getCurrentProfile() const { return current_profile_; }
518
524 const ProfileItem *getProfile(const QModelIndex &index) const { return itemAt(index); }
525
531 const ProfileItem *getPersonalProfile(const QString &name);
532
539 QVariant dataPath(const QModelIndex &idx, QString &profilePath) const;
540
541protected:
546 static QString illegalCharacters();
547
557 QModelIndex addNewProfile(QString name, QString reference, bool isGlobal = false, bool fromGlobal = false, bool isImport = false);
558
559private:
560 QList<ProfileItem *> profile_items_;
561 QStringList profile_files_;
562 ProfileItem *current_profile_ = Q_NULLPTR;
563
571 int findByNameAndVisibility(const QString &name, bool isGlobal = false, bool searchReference = false, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
572
573 ProfileItem *itemAt(const QModelIndex &index) const;
574 QList<ProfileItem *> children(const ProfileItem *parent) const;
575 QModelIndex indexOf(const ProfileItem *item, int column = COL_NAME) const;
576 void linkParent(ProfileItem *item, const QString &name) const;
577 void removeItem(ProfileItem *item);
578 QList<ProfileItem *> draggedItems(const QMimeData *data) const;
579 bool canMove(const ProfileItem *item, const ProfileItem *target) const;
580
581#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
588 static bool acceptFile(QString fileName, uint64_t fileSize);
589
595 static QString cleanName(QString fileName);
596#endif
597
603 QVariant dataDisplay(const QModelIndex &idx) const;
604
610 QVariant dataFontRole(const QModelIndex &idx) const;
611
617 QVariant dataBackgroundRole(const QModelIndex &idx) const;
618
624 QVariant dataForegroundRole(const QModelIndex &idx) const;
625
631 QVariant dataToolTipRole(const QModelIndex &idx) const;
632
633#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
641 QList<QPair<QString, QString>> exportFileList(QModelIndexList items, QString &err);
642#endif
643
651 bool copyTempToProfile(QString tempPath, QString profilePath, bool &wasEmpty);
652
660 QFileInfoList filterProfilePath(QString path, QFileInfoList ent, bool fromZip, bool inProfile = false);
661
667 QFileInfoList uniquePaths(QFileInfoList lst);
668};
669
670#endif
Represents a single configuration profile entry in the profile manager, tracking its name,...
Definition profile_model.h:29
bool isChanged() const
Returns whether the profile has unsaved changes relative to its on-disk state.
Definition profile_model.h:115
ProfileItem * parent() const
Returns the parent profile, or nullptr for a top-level profile.
Definition profile_model.h:73
const QString & getReference() const
Returns the original name of the profile at creation time.
Definition profile_model.h:143
const QString & getLeafName() const
Returns the name of the profile without parent profiles.
Definition profile_model.h:68
void setParent(ProfileItem *parent)
Sets the parent profile.
Definition profile_model.h:79
const QString & getAutoSwitchFilter() const
Returns the display-filter expression used for automatic profile switching.
Definition profile_model.h:91
bool isDeleted() const
Returns whether this profile is marked for deletion on the next apply.
Definition profile_model.h:133
bool isImport() const
Returns whether this profile was imported from an external source.
Definition profile_model.h:127
void setForDeletion()
Marks this profile for deletion on the next call to ProfileModel::applyChanges().
Definition profile_model.h:183
void setStatus(StatusType status)
Updates the lifecycle status of the profile.
Definition profile_model.h:174
void setReference(QString value)
Sets the reference name, e.g. after the on-disk directory has been moved.
Definition profile_model.h:149
ProfileItem(profile_def *profile)
Constructs a ProfileItem from a raw libwireshark profile definition.
Definition profile_model.cpp:42
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:109
bool isGlobal() const
Returns whether this is a read-only global (system-wide) profile.
Definition profile_model.h:103
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:535
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:979
QList< int > findAllByNameAndVisibility(const QString &name, bool isGlobal=false, bool searchReference=false, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Finds all profiles matching the given name and global-scope flag.
Definition profile_model.cpp:775
const ProfileItem * getCurrentProfile() const
Returns the ProfileItem representing the profile that was active when the model was constructed.
Definition profile_model.h:517
@ DATA_IS_DEFAULT
Definition profile_model.h:302
@ DATA_IS_GLOBAL
Definition profile_model.h:303
enum ProfileModel::@335073123265076173203353240160121376071234354003 data_values_
Custom Qt::UserRole data keys returned by data().
enum ProfileModel::@167051107222365245320312345074023160155247170055 columns_
Column index constants for the profile table.
bool restoreEntries(QModelIndexList idcs)
Clears the deletion flag on the profiles at the given indices.
Definition profile_model.cpp:938
static bool checkNameValidity(QString name, QString &msg)
Validates a candidate profile name for illegal characters and reserved names.
Definition profile_model.cpp:1523
virtual QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const override
Returns data for the given index and role.
Definition profile_model.cpp:668
const ProfileItem * getPersonalProfile(const QString &name)
Finds a personal (non-global) profile by name.
Definition profile_model.cpp:753
QModelIndex duplicateEntry(QModelIndex idx, ProfileItem::StatusType status=ProfileItem::StatusType::Copy, const QString &name=QString())
Creates a duplicate of the profile at idx.
Definition profile_model.cpp:823
bool userProfilesExist() const
Returns whether any editable (non-global, non-default) profiles exist.
Definition profile_model.cpp:275
QModelIndex findByName(const QString &name)
Returns the index of the first profile whose name matches exactly.
Definition profile_model.cpp:744
void deleteEntries(QModelIndexList idcs)
Marks the profiles at the given indices for deletion.
Definition profile_model.cpp:906
bool isDataValid(QString &err)
Validates all pending profile changes for conflicts and illegal names.
Definition profile_model.cpp:416
@ COL_NAME
Definition profile_model.h:292
@ COL_TYPE
Definition profile_model.h:293
@ COL_AUTO_SWITCH_FILTER
Definition profile_model.h:294
@ _LAST_ENTRY
Definition profile_model.h:295
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of profile rows.
Definition profile_model.cpp:335
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns (always _LAST_ENTRY).
Definition profile_model.cpp:361
QModelIndex addNewProfile(QString name)
Adds a new empty personal profile with the given name.
Definition profile_model.cpp:793
static QString illegalCharacters()
Returns the set of characters that are not permitted in profile names.
Definition profile_model.cpp:1513
ProfileModel(QObject *parent=Q_NULLPTR)
Constructs a ProfileModel and populates it from the current profile directories.
Definition profile_model.cpp:222
QModelIndexList withChildren(const QModelIndexList &items) const
Returns the given profiles with all their sub-profiles.
Definition profile_model.cpp:1261
QModelIndex activeProfile() const
Returns the model index of the currently active (in-use) profile row.
Definition profile_model.cpp:959
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the item flags for the given index.
Definition profile_model.cpp:719
void applyChanges()
Applies all pending changes (additions, renames, copies, deletions) to the on-disk profile directorie...
Definition profile_model.cpp:1553
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:455
const ProfileItem * getProfile(const QModelIndex &index) const
Returns the ProfileItem at the given model index.
Definition profile_model.h:524
void fillTable()
(Re-)populates the model from the on-disk profile directories.
Definition profile_model.cpp:245
virtual ~ProfileModel()
Destroys the model and frees all ProfileItem instances.
Definition profile_model.cpp:238
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:698
void importProfilesFromDir(QString filename, int &skippedCnt, QStringList &importList, bool fromZip=false, const QString &targetParent=QString())
Imports profiles from a directory (or an extracted ZIP staging area).
Definition profile_model.cpp:1408
static QStringList filterTypes()
Returns a localised list of filter type display names, ordered by FilterType value.
Definition profile_model.cpp:184
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:194
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:128
void setFilterString(QString txt=QString())
Sets a case-insensitive substring filter applied to profile names.
Definition profile_model.cpp:171
ProfileSortModel(QObject *parent=Q_NULLPTR)
Constructs a ProfileSortModel with no active text filter and AllProfiles visibility.
Definition profile_model.cpp:120
FilterType
Controls which profiles are visible based on their scope.
Definition profile_model.h:220
@ AllProfiles
Definition profile_model.h:221
@ PersonalProfiles
Definition profile_model.h:222
@ GlobalProfiles
Definition profile_model.h:223
void setFilterType(FilterType ft)
Sets the profile-scope filter.
Definition profile_model.cpp:158
Describes a single Wireshark configuration profile and its associated settings.
Definition profile.h:25
Definition packet-epl.h:22