Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
profile_model.h
Go to the documentation of this file.
1
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:
35 New = 0,
38 Copy
39 };
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
134 QString getProfilePath(QString profileName = "") const;
135
140 void setName(QString value);
141
146 void setStatus(StatusType status) { status_ = status; }
147
152 void setAutoSwitchFilter(QString value);
153
155 void setForDeletion() { setForDeletion_ = true; }
156
157private:
158 QString name_;
159 StatusType status_;
161 QString autoSwitchFilter_;
162 bool isGlobal_;
163 bool fromGlobal_ = false;
164 bool isImport_ = false;
165 bool setForDeletion_ = false;
167 QString reference_;
169 bool isChanged_ = false;
170};
171
172
177class ProfileSortModel : public QSortFilterProxyModel
178{
179 Q_OBJECT
180
181public:
186 ProfileSortModel(QObject *parent = Q_NULLPTR);
187
196
201 void setFilterType(FilterType ft);
202
207 void setFilterString(QString txt = QString());
208
213 static QStringList filterTypes();
214
215protected:
223 virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
224
231 virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
232
233private:
234 FilterType ft_;
235 QString ftext_;
236};
237
238
243class ProfileModel : public QAbstractTableModel
244{
245 Q_OBJECT
246
247public:
252 explicit ProfileModel(QObject *parent = Q_NULLPTR);
253
257 virtual ~ProfileModel();
258
262 enum {
268
272 enum {
273 DATA_IS_DEFAULT = Qt::UserRole,
276
283 void fillTable();
284
285 // ── QAbstractItemModel interface ──────────────────────────────────────
286
292 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
293
299 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
300
307 virtual QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const;
308
316 virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
317
325 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
326
336 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
337
338 // ── Mutation helpers ──────────────────────────────────────────────────
339
344 void deleteEntries(QModelIndexList idcs);
345
351 bool restoreEntries(QModelIndexList idcs);
352
353 // ── Lookup ────────────────────────────────────────────────────────────
354
360 int findByName(const QString &name);
361
367 QModelIndex addNewProfile(QString name);
368
375 QModelIndex duplicateEntry(QModelIndex idx, ProfileItem::StatusType status = ProfileItem::StatusType::Copy);
376
381 QModelIndex activeProfile() const;
382
387 bool userProfilesExist() const;
388
394 bool isDataValid(QString &err);
395
396#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
404 bool exportProfiles(QString filename, QModelIndexList items, QString &err);
405
412 void importProfilesFromZip(QString filename, int &skippedCnt, QStringList &importList);
413#endif
414
422 void importProfilesFromDir(QString filename, int &skippedCnt, QStringList &importList, bool fromZip = false);
423
430 static bool checkNameValidity(QString name, QString &msg);
431
439 QList<int> findAllByNameAndVisibility(const QString &name, bool isGlobal = false, bool searchReference = false) const;
440
448 bool checkDuplicate(const QModelIndex &index, bool isOriginalToDuplicate = false) const;
449
454 void applyChanges();
455
461 const ProfileItem *getCurrentProfile() const { return current_profile_; }
462
468 const ProfileItem *getProfile(int index) const { return profile_items_[index]; }
469
475 const ProfileItem *getPersonalProfile(const QString &name);
476
483 QVariant dataPath(const QModelIndex &idx, QString &profilePath) const;
484
485protected:
490 static QString illegalCharacters();
491
501 QModelIndex addNewProfile(QString name, QString reference, bool isGlobal = false, bool fromGlobal = false, bool isImport = false);
502
503private:
504 QList<ProfileItem *> profile_items_;
505 QStringList profile_files_;
506 ProfileItem *current_profile_ = Q_NULLPTR;
515 int findByNameAndVisibility(const QString &name, bool isGlobal = false, bool searchReference = false) const;
516
517#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
524 static bool acceptFile(QString fileName, int fileSize);
525
531 static QString cleanName(QString fileName);
532#endif
533
539 QVariant dataDisplay(const QModelIndex &idx) const;
540
546 QVariant dataFontRole(const QModelIndex &idx) const;
547
553 QVariant dataBackgroundRole(const QModelIndex &idx) const;
554
560 QVariant dataForegroundRole(const QModelIndex &idx) const;
561
567 QVariant dataToolTipRole(const QModelIndex &idx) const;
568
569#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
575 QStringList exportFileList(QModelIndexList items);
576#endif
577
585 bool copyTempToProfile(QString tempPath, QString profilePath, bool &wasEmpty);
586
594 QFileInfoList filterProfilePath(QString path, QFileInfoList ent, bool fromZip);
595
601 QFileInfoList uniquePaths(QFileInfoList lst);
602};
603
604#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:155
void setStatus(StatusType status)
Updates the lifecycle status of the profile.
Definition profile_model.h:146
StatusType
Lifecycle status of a profile item within the model.
Definition profile_model.h:34
@ Copy
Definition profile_model.h:38
@ 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
Table model that manages the full set of configuration profiles, supporting creation,...
Definition profile_model.h:244
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:433
const ProfileItem * getCurrentProfile() const
Returns the ProfileItem representing the profile that was active when the model was constructed.
Definition profile_model.h:461
const ProfileItem * getProfile(int index) const
Returns the ProfileItem at the given flat list index.
Definition profile_model.h:468
int findByName(const QString &name)
Returns the row index of the first profile whose name matches exactly.
Definition profile_model.cpp:638
bool restoreEntries(QModelIndexList idcs)
Clears the deletion flag on the profiles at the given indices.
Definition profile_model.cpp:862
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of profile rows.
Definition profile_model.cpp:264
static bool checkNameValidity(QString name, QString &msg)
Validates a candidate profile name for illegal characters and reserved names.
Definition profile_model.cpp:1169
const ProfileItem * getPersonalProfile(const QString &name)
Finds a personal (non-global) profile by name.
Definition profile_model.cpp:647
bool userProfilesExist() const
Returns whether any editable (non-global, non-default) profiles exist.
Definition profile_model.cpp:253
QModelIndex duplicateEntry(QModelIndex idx, ProfileItem::StatusType status=ProfileItem::StatusType::Copy)
Creates a duplicate of the profile at idx.
Definition profile_model.cpp:710
enum ProfileModel::@599 columns_
Column index constants for the profile table.
void deleteEntries(QModelIndexList idcs)
Marks the profiles at the given indices for deletion.
Definition profile_model.cpp:785
bool isDataValid(QString &err)
Validates all pending profile changes for conflicts and illegal names.
Definition profile_model.cpp:310
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of columns (always _LAST_ENTRY).
Definition profile_model.cpp:269
@ COL_NAME
Definition profile_model.h:263
@ COL_TYPE
Definition profile_model.h:264
@ COL_AUTO_SWITCH_FILTER
Definition profile_model.h:265
@ _LAST_ENTRY
Definition profile_model.h:266
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:1109
QModelIndex addNewProfile(QString name)
Adds a new empty personal profile with the given name.
Definition profile_model.cpp:681
static QString illegalCharacters()
Returns the set of characters that are not permitted in profile names.
Definition profile_model.cpp:1158
QModelIndex activeProfile() const
Returns the model index of the currently active (in-use) profile row.
Definition profile_model.cpp:880
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
Sets data for an editable cell (profile name or auto-switch filter).
Definition profile_model.cpp:900
enum ProfileModel::@600 data_values_
Custom Qt::UserRole data keys returned by data().
void applyChanges()
Applies all pending changes (additions, renames, copies, deletions) to the on-disk profile directorie...
Definition profile_model.cpp:1199
@ DATA_IS_DEFAULT
Definition profile_model.h:273
@ DATA_IS_GLOBAL
Definition profile_model.h:274
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the header label for the given section.
Definition profile_model.cpp:594
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:663
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:347
void fillTable()
(Re-)populates the model from the on-disk profile directories.
Definition profile_model.cpp:231
virtual ~ProfileModel()
Destroys the model and frees all ProfileItem instances.
Definition profile_model.cpp:224
Sort/filter proxy model for ProfileModel, supporting filtering by profile visibility (all,...
Definition profile_model.h:178
static QStringList filterTypes()
Returns a localised list of filter type display names, ordered by FilterType value.
Definition profile_model.cpp:174
void setFilterString(QString txt=QString())
Sets a case-insensitive substring filter applied to profile names.
Definition profile_model.cpp:161
virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
Compares two rows for sort ordering, placing personal profiles before global ones and sorting alphabe...
Definition profile_model.cpp:118
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
Determines whether a source row passes the active scope and text filters.
Definition profile_model.cpp:184
FilterType
Controls which profiles are visible based on their scope.
Definition profile_model.h:191
@ AllProfiles
Definition profile_model.h:192
@ PersonalProfiles
Definition profile_model.h:193
@ GlobalProfiles
Definition profile_model.h:194
void setFilterType(FilterType ft)
Sets the profile-scope filter.
Definition profile_model.cpp:148
Definition profile.h:22
Definition packet-epl.h:22