3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #ifndef PROFILE_MODEL_H
11 #define PROFILE_MODEL_H
15 #include <ui/profile.h>
17 #include <QAbstractTableModel>
18 #include <QSortFilterProxyModel>
19 #include <QLoggingCategory>
20 #include <QFileInfoList>
22 Q_DECLARE_LOGGING_CATEGORY(profileLogger
)
24 class ProfileSortModel
: public QSortFilterProxyModel
29 ProfileSortModel(QObject
*parent
= Q_NULLPTR
);
37 void setFilterType(FilterType ft
);
38 void setFilterString(QString txt
= QString());
40 static QStringList
filterTypes();
43 virtual bool lessThan(const QModelIndex
&source_left
, const QModelIndex
&source_right
) const;
44 virtual bool filterAcceptsRow(int source_row
, const QModelIndex
&source_parent
) const;
51 class ProfileModel
: public QAbstractTableModel
56 explicit ProfileModel(QObject
* parent
= Q_NULLPTR
);
61 COL_AUTO_SWITCH_FILTER
,
66 DATA_STATUS
= Qt::UserRole
,
71 DATA_PATH_IS_NOT_DESCRIPTION
,
74 // QAbstractItemModel interface
75 virtual int rowCount(const QModelIndex
& parent
= QModelIndex()) const;
76 virtual int columnCount(const QModelIndex
& parent
= QModelIndex()) const;
77 virtual QVariant
data(const QModelIndex
& idx
, int role
= Qt::DisplayRole
) const;
78 virtual bool setData(const QModelIndex
&index
, const QVariant
&value
, int role
);
79 virtual QVariant
headerData(int section
, Qt::Orientation orientation
, int role
= Qt::DisplayRole
) const;
80 virtual Qt::ItemFlags
flags(const QModelIndex
&index
) const;
82 void deleteEntry(QModelIndex idx
);
83 void deleteEntries(QModelIndexList idcs
);
85 int findByName(QString name
);
86 QModelIndex
addNewProfile(QString name
);
87 QModelIndex
duplicateEntry(QModelIndex idx
, int new_status
= PROF_STAT_COPY
);
89 void doResetModel(bool reset_import
= false);
90 bool resetDefault() const;
92 QModelIndex
activeProfile() const;
93 static QString
activeProfileName();
94 static QString
activeProfilePath();
96 GList
* at(int row
) const;
98 bool changesPending() const;
99 bool importPending() const;
101 bool userProfilesExist() const;
103 #if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
104 bool exportProfiles(QString filename
, QModelIndexList items
, QString
* err
= Q_NULLPTR
);
105 int importProfilesFromZip(QString filename
, int *skippedCnt
= Q_NULLPTR
, QStringList
*result
= Q_NULLPTR
);
107 int importProfilesFromDir(QString filename
, int *skippedCnt
= Q_NULLPTR
, bool fromZip
= false, QStringList
*result
= Q_NULLPTR
);
109 static bool checkNameValidity(QString name
, QString
*msg
= Q_NULLPTR
);
110 QList
<int> findAllByNameAndVisibility(QString name
, bool isGlobal
= false, bool searchReference
= false) const;
111 void markAsImported(QStringList importedItems
);
112 bool clearImported(QString
*msg
= Q_NULLPTR
);
114 int lastSetRow() const;
116 bool checkInvalid(const QModelIndex
&index
) const;
117 bool checkIfDeleted(const QModelIndex
&index
) const;
118 bool checkIfDeleted(int row
) const;
119 bool checkDuplicate(const QModelIndex
&index
, bool isOriginalToDuplicate
= false) const;
122 void itemChanged(const QModelIndex
&idx
);
125 static QString
illegalCharacters();
128 QList
<profile_def
*> profiles_
;
129 QStringList profile_files_
;
130 QString set_profile_
;
132 bool profiles_imported_
;
137 profile_def
* guard(const QModelIndex
&index
) const;
138 profile_def
* guard(int row
) const;
139 GList
* entry(profile_def
*) const;
141 int findByNameAndVisibility(QString name
, bool isGlobal
= false, bool searchReference
= false) const;
142 int findAsReference(QString reference
) const;
144 #if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
145 static bool acceptFile(QString fileName
, int fileSize
);
146 static QString
cleanName(QString fileName
);
149 QVariant
dataDisplay(const QModelIndex
& idx
) const;
150 QVariant
dataFontRole(const QModelIndex
& idx
) const;
151 QVariant
dataBackgroundRole(const QModelIndex
& idx
) const;
152 QVariant
dataForegroundRole(const QModelIndex
& idx
) const;
153 QVariant
dataToolTipRole(const QModelIndex
& idx
) const;
154 QVariant
dataPath(const QModelIndex
& idx
) const;
156 #if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
157 QStringList
exportFileList(QModelIndexList items
);
159 bool copyTempToProfile(QString tempPath
, QString profilePath
, bool *wasEmpty
= Q_NULLPTR
);
160 QFileInfoList
filterProfilePath(QString
, QFileInfoList ent
, bool fromZip
);
161 QFileInfoList
uniquePaths(QFileInfoList lst
);