10#ifndef PROFILE_MODEL_H
11#define PROFILE_MODEL_H
17#include <QAbstractItemModel>
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 QString getName()
const;
85 const QString getType()
const;
97 StatusType getStatus()
const;
121 bool isDefault()
const;
156 QString getProfilePath(QString profileName)
const;
162 QString getProfilePath()
const;
168 void setName(QString value);
180 void setAutoSwitchFilter(QString value);
190 QString autoSwitchFilter_;
192 bool fromGlobal_ =
false;
193 bool isImport_ =
false;
194 bool setForDeletion_ =
false;
198 bool isChanged_ =
false;
252 virtual bool lessThan(
const QModelIndex &source_left,
const QModelIndex &source_right)
const override;
260 virtual bool filterAcceptsRow(
int source_row,
const QModelIndex &source_parent)
const override;
321 virtual int rowCount(
const QModelIndex &parent = QModelIndex())
const override;
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;
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;
338 virtual int columnCount(
const QModelIndex &parent = QModelIndex())
const override;
346 virtual QVariant
data(
const QModelIndex &idx,
int role = Qt::DisplayRole)
const override;
355 virtual bool setData(
const QModelIndex &index,
const QVariant &value,
int role)
override;
364 virtual QVariant
headerData(
int section, Qt::Orientation orientation,
int role = Qt::DisplayRole)
const override;
375 virtual Qt::ItemFlags
flags(
const QModelIndex &index)
const override;
441 QModelIndexList
withChildren(
const QModelIndexList &items)
const;
443#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
451 bool exportProfiles(QString filename, QModelIndexList items, QString &err);
460 bool isExportable(
const QModelIndex &idx)
const;
468 void importProfilesFromZip(QString filename,
int &skippedCnt, QStringList &importList,
const QString &targetParent = QString());
478 void importProfilesFromDir(QString filename,
int &skippedCnt, QStringList &importList,
bool fromZip =
false,
const QString &targetParent = QString());
495 QList<int>
findAllByNameAndVisibility(
const QString &name,
bool isGlobal =
false,
bool searchReference =
false, Qt::CaseSensitivity cs = Qt::CaseSensitive)
const;
504 bool checkDuplicate(
const QModelIndex &index,
bool isOriginalToDuplicate =
false)
const;
539 QVariant
dataPath(
const QModelIndex &idx, QString &profilePath)
const;
557 QModelIndex
addNewProfile(QString name, QString reference,
bool isGlobal =
false,
bool fromGlobal =
false,
bool isImport =
false);
560 QList<ProfileItem *> profile_items_;
561 QStringList profile_files_;
571 int findByNameAndVisibility(
const QString &name,
bool isGlobal =
false,
bool searchReference =
false, Qt::CaseSensitivity cs = Qt::CaseSensitive)
const;
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;
578 QList<ProfileItem *> draggedItems(
const QMimeData *data)
const;
581#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
588 static bool acceptFile(QString fileName, uint64_t fileSize);
595 static QString cleanName(QString fileName);
603 QVariant dataDisplay(
const QModelIndex &idx)
const;
610 QVariant dataFontRole(
const QModelIndex &idx)
const;
617 QVariant dataBackgroundRole(
const QModelIndex &idx)
const;
624 QVariant dataForegroundRole(
const QModelIndex &idx)
const;
631 QVariant dataToolTipRole(
const QModelIndex &idx)
const;
633#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
641 QList<QPair<QString, QString>> exportFileList(QModelIndexList items, QString &err);
651 bool copyTempToProfile(QString tempPath, QString profilePath,
bool &wasEmpty);
660 QFileInfoList filterProfilePath(QString path, QFileInfoList ent,
bool fromZip,
bool inProfile =
false);
667 QFileInfoList uniquePaths(QFileInfoList lst);
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