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
25{
26public:
27 enum StatusType {
28 New = 0,
29 Existing,
30 Changed,
31 Copy
32 };
33
35 ProfileItem(QString name, QString reference, StatusType status, bool isGlobal, bool fromGlobal, bool isImport);
36
37 const QString& getName() const { return name_; }
38 const QString getType() const;
39 const QString& getAutoSwitchFilter() const { return autoSwitchFilter_; }
40 StatusType getStatus() const { return status_; }
41 bool isGlobal() const { return isGlobal_; }
42 bool isFromGlobal() const { return fromGlobal_; }
43 bool isChanged() const { return isChanged_; }
44 bool isDefault() const;
45 bool isImport() const { return isImport_; }
46 bool isDeleted() const { return setForDeletion_; }
47
48 const QString& getReference() const { return reference_; }
49
50 //Provide the profile's path
51 //
52 //profileName Name to append to profile path. If profileName is empty, current profile name is used
53 QString getProfilePath(QString profileName = "") const;
54
55 void setName(QString value);
56 void setStatus(StatusType status) {status_ = status; }
57 void setAutoSwitchFilter(QString value);
58 void setForDeletion() { setForDeletion_ = true; }
59
60private:
61 QString name_;
62 StatusType status_;
63
64 QString autoSwitchFilter_ = "";
65 bool isGlobal_;
66 bool fromGlobal_ = false;
67 bool isImport_ = false;
68 bool setForDeletion_ = false;
69
70 //Original name when created
71 QString reference_;
72
73 bool isChanged_ = false;
74};
75
76
77class ProfileSortModel : public QSortFilterProxyModel
78{
79 Q_OBJECT
80
81public:
82 ProfileSortModel(QObject *parent = Q_NULLPTR);
83
84 enum FilterType {
85 AllProfiles = 0,
86 PersonalProfiles,
87 GlobalProfiles
88 };
89
90 void setFilterType(FilterType ft);
91 void setFilterString(QString txt = QString());
92
93 static QStringList filterTypes();
94
95protected:
96 virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
97 virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
98
99private:
100 FilterType ft_;
101 QString ftext_;
102};
103
104class ProfileModel : public QAbstractTableModel
105{
106 Q_OBJECT
107
108public:
109 explicit ProfileModel(QObject * parent = Q_NULLPTR);
110 virtual ~ProfileModel();
111
112 enum {
113 COL_NAME,
114 COL_TYPE,
115 COL_AUTO_SWITCH_FILTER,
116 _LAST_ENTRY
117 } columns_;
118
119 enum {
120 DATA_IS_DEFAULT = Qt::UserRole,
121 DATA_IS_GLOBAL,
122 } data_values_;
123
124 void fillTable();
125
126 // QAbstractItemModel interface
127 virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
128 virtual int columnCount(const QModelIndex & parent = QModelIndex()) const;
129 virtual QVariant data(const QModelIndex & idx, int role = Qt::DisplayRole) const;
130 virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
131 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
132 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
133
134 void deleteEntries(QModelIndexList idcs);
135 bool restoreEntries(QModelIndexList idcs);
136
137 int findByName(const QString& name);
138 QModelIndex addNewProfile(QString name);
139 QModelIndex duplicateEntry(QModelIndex idx, ProfileItem::StatusType status = ProfileItem::StatusType::Copy);
140
141 QModelIndex activeProfile() const;
142
143 bool userProfilesExist() const;
144
145 bool isDataValid(QString& err);
146
147#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
148 bool exportProfiles(QString filename, QModelIndexList items, QString& err);
149 void importProfilesFromZip(QString filename, int& skippedCnt, QStringList& importList);
150#endif
151 void importProfilesFromDir(QString filename, int& skippedCnt, QStringList& importList, bool fromZip = false);
152
153 static bool checkNameValidity(QString name, QString& msg);
154 QList<int> findAllByNameAndVisibility(const QString& name, bool isGlobal = false, bool searchReference = false) const;
155
156 bool checkDuplicate(const QModelIndex &index, bool isOriginalToDuplicate = false) const;
157
158 void applyChanges();
159
160 const ProfileItem* getCurrentProfile() const { return current_profile_; }
161 const ProfileItem* getProfile(int index) const { return profile_items_[index]; }
162 const ProfileItem* getPersonalProfile(const QString& name);
163
164 QVariant dataPath(const QModelIndex& idx, QString& profilePath) const;
165
166protected:
167 static QString illegalCharacters();
168
169 QModelIndex addNewProfile(QString name, QString reference, bool isGlobal = false, bool fromGlobal = false, bool isImport = false);
170
171private:
172 QList<ProfileItem*> profile_items_;
173 QStringList profile_files_;
174 ProfileItem* current_profile_ = Q_NULLPTR;
175
176 int findByNameAndVisibility(const QString& name, bool isGlobal = false, bool searchReference = false) const;
177
178#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
179 static bool acceptFile(QString fileName, int fileSize);
180 static QString cleanName(QString fileName);
181#endif
182
183 QVariant dataDisplay(const QModelIndex & idx) const;
184 QVariant dataFontRole(const QModelIndex & idx) const;
185 QVariant dataBackgroundRole(const QModelIndex & idx) const;
186 QVariant dataForegroundRole(const QModelIndex & idx) const;
187 QVariant dataToolTipRole(const QModelIndex & idx) const;
188
189#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
190 QStringList exportFileList(QModelIndexList items);
191#endif
192 bool copyTempToProfile(QString tempPath, QString profilePath, bool& wasEmpty);
193 QFileInfoList filterProfilePath(QString, QFileInfoList ent, bool fromZip);
194 QFileInfoList uniquePaths(QFileInfoList lst);
195
196};
197
198#endif
Definition profile_model.h:25
Definition profile_model.h:105
Definition profile_model.h:78
Definition profile.h:22
Definition packet-epl.h:22