10#ifndef PROFILE_MODEL_H
11#define PROFILE_MODEL_H
17#include <QAbstractTableModel>
18#include <QSortFilterProxyModel>
19#include <QLoggingCategory>
20#include <QFileInfoList>
22Q_DECLARE_LOGGING_CATEGORY(profileLogger)
56 ProfileItem(QString name, QString reference, StatusType status,
bool isGlobal,
bool fromGlobal,
bool isImport);
62 const QString &
getName()
const {
return name_; }
68 const QString getType()
const;
104 bool isDefault()
const;
133 QString getProfilePath(QString profileName)
const;
139 QString getProfilePath()
const;
145 void setName(QString value);
157 void setAutoSwitchFilter(QString value);
166 QString autoSwitchFilter_;
168 bool fromGlobal_ =
false;
169 bool isImport_ =
false;
170 bool setForDeletion_ =
false;
174 bool isChanged_ =
false;
228 virtual bool lessThan(
const QModelIndex &source_left,
const QModelIndex &source_right)
const override;
236 virtual bool filterAcceptsRow(
int source_row,
const QModelIndex &source_parent)
const override;
297 virtual int rowCount(
const QModelIndex &parent = QModelIndex())
const override;
304 virtual int columnCount(
const QModelIndex &parent = QModelIndex())
const override;
312 virtual QVariant
data(
const QModelIndex &idx,
int role = Qt::DisplayRole)
const override;
321 virtual bool setData(
const QModelIndex &index,
const QVariant &value,
int role)
override;
330 virtual QVariant
headerData(
int section, Qt::Orientation orientation,
int role = Qt::DisplayRole)
const override;
341 virtual Qt::ItemFlags
flags(
const QModelIndex &index)
const override;
401#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
409 bool exportProfiles(QString filename, QModelIndexList items, QString &err);
417 void importProfilesFromZip(QString filename,
int &skippedCnt, QStringList &importList);
427 void importProfilesFromDir(QString filename,
int &skippedCnt, QStringList &importList,
bool fromZip =
false);
453 bool checkDuplicate(
const QModelIndex &index,
bool isOriginalToDuplicate =
false)
const;
488 QVariant
dataPath(
const QModelIndex &idx, QString &profilePath)
const;
506 QModelIndex
addNewProfile(QString name, QString reference,
bool isGlobal =
false,
bool fromGlobal =
false,
bool isImport =
false);
509 QList<ProfileItem *> profile_items_;
510 QStringList profile_files_;
520 int findByNameAndVisibility(
const QString &name,
bool isGlobal =
false,
bool searchReference =
false)
const;
522#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
529 static bool acceptFile(QString fileName,
int fileSize);
536 static QString cleanName(QString fileName);
544 QVariant dataDisplay(
const QModelIndex &idx)
const;
551 QVariant dataFontRole(
const QModelIndex &idx)
const;
558 QVariant dataBackgroundRole(
const QModelIndex &idx)
const;
565 QVariant dataForegroundRole(
const QModelIndex &idx)
const;
572 QVariant dataToolTipRole(
const QModelIndex &idx)
const;
574#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
580 QStringList exportFileList(QModelIndexList items);
590 bool copyTempToProfile(QString tempPath, QString profilePath,
bool &wasEmpty);
599 QFileInfoList filterProfilePath(QString path, QFileInfoList ent,
bool fromZip);
606 QFileInfoList uniquePaths(QFileInfoList lst);
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