Wireshark 4.5.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
24class ProfileSortModel : public QSortFilterProxyModel
25{
26 Q_OBJECT
27
28public:
29 ProfileSortModel(QObject *parent = Q_NULLPTR);
30
31 enum FilterType {
32 AllProfiles = 0,
33 PersonalProfiles,
34 GlobalProfiles
35 };
36
37 void setFilterType(FilterType ft);
38 void setFilterString(QString txt = QString());
39
40 static QStringList filterTypes();
41
42protected:
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;
45
46private:
47 FilterType ft_;
48 QString ftext_;
49};
50
51class ProfileModel : public QAbstractTableModel
52{
53 Q_OBJECT
54
55public:
56 explicit ProfileModel(QObject * parent = Q_NULLPTR);
57
58 enum {
59 COL_NAME,
60 COL_TYPE,
61 COL_AUTO_SWITCH_FILTER,
62 _LAST_ENTRY
63 } columns_;
64
65 enum {
66 DATA_STATUS = Qt::UserRole,
67 DATA_IS_DEFAULT,
68 DATA_IS_GLOBAL,
69 DATA_IS_SELECTED,
70 DATA_PATH,
71 DATA_PATH_IS_NOT_DESCRIPTION,
72 } data_values_;
73
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;
81
82 void deleteEntry(QModelIndex idx);
83 void deleteEntries(QModelIndexList idcs);
84
85 int findByName(QString name);
86 QModelIndex addNewProfile(QString name);
87 QModelIndex duplicateEntry(QModelIndex idx, int new_status = PROF_STAT_COPY);
88
89 void doResetModel(bool reset_import = false);
90 bool resetDefault() const;
91
92 QModelIndex activeProfile() const;
93 static QString activeProfileName();
94 static QString activeProfilePath();
95
96 GList * at(int row) const;
97
98 bool changesPending() const;
99 bool importPending() const;
100
101 bool userProfilesExist() const;
102
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);
106#endif
107 int importProfilesFromDir(QString filename, int *skippedCnt = Q_NULLPTR, bool fromZip = false, QStringList *result = Q_NULLPTR);
108
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);
113
114 int lastSetRow() const;
115
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;
120
121signals:
122 void itemChanged(const QModelIndex &idx);
123
124protected:
125 static QString illegalCharacters();
126
127private:
128 QList<profile_def *> profiles_;
129 QStringList profile_files_;
130 QString set_profile_;
131 bool reset_default_;
132 bool profiles_imported_;
133
134 int last_set_row_;
135
136 void loadProfiles();
137 profile_def * guard(const QModelIndex &index) const;
138 profile_def * guard(int row) const;
139 GList * entry(profile_def *) const;
140
141 int findByNameAndVisibility(QString name, bool isGlobal = false, bool searchReference = false) const;
142 int findAsReference(QString reference) const;
143
144#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
145 static bool acceptFile(QString fileName, int fileSize);
146 static QString cleanName(QString fileName);
147#endif
148
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;
155
156#if defined(HAVE_MINIZIP) || defined(HAVE_MINIZIPNG)
157 QStringList exportFileList(QModelIndexList items);
158#endif
159 bool copyTempToProfile(QString tempPath, QString profilePath, bool *wasEmpty = Q_NULLPTR);
160 QFileInfoList filterProfilePath(QString, QFileInfoList ent, bool fromZip);
161 QFileInfoList uniquePaths(QFileInfoList lst);
162
163};
164
165#endif
Definition profile_model.h:52
Definition profile_model.h:25
Definition profile.h:34