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;
134 QString getProfilePath(QString profileName =
"")
const;
140 void setName(QString value);
152 void setAutoSwitchFilter(QString value);
161 QString autoSwitchFilter_;
163 bool fromGlobal_ =
false;
164 bool isImport_ =
false;
165 bool setForDeletion_ =
false;
169 bool isChanged_ =
false;
223 virtual bool lessThan(
const QModelIndex &source_left,
const QModelIndex &source_right)
const;
231 virtual bool filterAcceptsRow(
int source_row,
const QModelIndex &source_parent)
const;
292 virtual int rowCount(
const QModelIndex &parent = QModelIndex())
const;
299 virtual int columnCount(
const QModelIndex &parent = QModelIndex())
const;
307 virtual QVariant data(
const QModelIndex &idx,
int role = Qt::DisplayRole)
const;
316 virtual bool setData(
const QModelIndex &index,
const QVariant &value,
int role);
325 virtual QVariant
headerData(
int section, Qt::Orientation orientation,
int role = Qt::DisplayRole)
const;
336 virtual Qt::ItemFlags flags(
const QModelIndex &index)
const;
396#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
404 bool exportProfiles(QString filename, QModelIndexList items, QString &err);
412 void importProfilesFromZip(QString filename,
int &skippedCnt, QStringList &importList);
422 void importProfilesFromDir(QString filename,
int &skippedCnt, QStringList &importList,
bool fromZip =
false);
448 bool checkDuplicate(
const QModelIndex &index,
bool isOriginalToDuplicate =
false)
const;
483 QVariant
dataPath(
const QModelIndex &idx, QString &profilePath)
const;
501 QModelIndex
addNewProfile(QString name, QString reference,
bool isGlobal =
false,
bool fromGlobal =
false,
bool isImport =
false);
504 QList<ProfileItem *> profile_items_;
505 QStringList profile_files_;
515 int findByNameAndVisibility(
const QString &name,
bool isGlobal =
false,
bool searchReference =
false)
const;
517#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
524 static bool acceptFile(QString fileName,
int fileSize);
531 static QString cleanName(QString fileName);
539 QVariant dataDisplay(
const QModelIndex &idx)
const;
546 QVariant dataFontRole(
const QModelIndex &idx)
const;
553 QVariant dataBackgroundRole(
const QModelIndex &idx)
const;
560 QVariant dataForegroundRole(
const QModelIndex &idx)
const;
567 QVariant dataToolTipRole(
const QModelIndex &idx)
const;
569#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
575 QStringList exportFileList(QModelIndexList items);
585 bool copyTempToProfile(QString tempPath, QString profilePath,
bool &wasEmpty);
594 QFileInfoList filterProfilePath(QString path, QFileInfoList ent,
bool fromZip);
601 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: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 packet-epl.h:22