Wireshark  4.3.0
The Wireshark network protocol analyzer
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 #include "glib.h"
15 
16 #include <ui/profile.h>
17 
18 #include <QAbstractTableModel>
19 #include <QSortFilterProxyModel>
20 #include <QLoggingCategory>
21 #include <QFileInfoList>
22 
23 Q_DECLARE_LOGGING_CATEGORY(profileLogger)
24 
25 class ProfileSortModel : public QSortFilterProxyModel
26 {
27  Q_OBJECT
28 
29 public:
30  ProfileSortModel(QObject *parent = Q_NULLPTR);
31 
32  enum FilterType {
33  AllProfiles = 0,
34  PersonalProfiles,
35  GlobalProfiles
36  };
37 
38  void setFilterType(FilterType ft);
39  void setFilterString(QString txt = QString());
40 
41  static QStringList filterTypes();
42 
43 protected:
44  virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
45  virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
46 
47 private:
48  FilterType ft_;
49  QString ftext_;
50 };
51 
52 class ProfileModel : public QAbstractTableModel
53 {
54  Q_OBJECT
55 
56 public:
57  explicit ProfileModel(QObject * parent = Q_NULLPTR);
58 
59  enum {
60  COL_NAME,
61  COL_TYPE,
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_INDEX_VALUE_IS_URL
73  } data_values_;
74 
75  // QAbstractItemModel interface
76  virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
77  virtual int columnCount(const QModelIndex & parent = QModelIndex()) const;
78  virtual QVariant data(const QModelIndex & idx, int role = Qt::DisplayRole) const;
79  virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
80  virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
81  virtual Qt::ItemFlags flags(const QModelIndex &index) const;
82 
83  void deleteEntry(QModelIndex idx);
84  void deleteEntries(QModelIndexList idcs);
85 
86  int findByName(QString name);
87  QModelIndex addNewProfile(QString name);
88  QModelIndex duplicateEntry(QModelIndex idx, int new_status = PROF_STAT_COPY);
89 
90  void doResetModel(bool reset_import = false);
91  bool resetDefault() const;
92 
93  QModelIndex activeProfile() const;
94  static QString activeProfileName();
95  static QString activeProfilePath();
96 
97  GList * at(int row) const;
98 
99  bool changesPending() const;
100  bool importPending() const;
101 
102  bool userProfilesExist() const;
103 
104 #ifdef HAVE_MINIZIP
105  bool exportProfiles(QString filename, QModelIndexList items, QString * err = Q_NULLPTR);
106  int importProfilesFromZip(QString filename, int *skippedCnt = Q_NULLPTR, QStringList *result = Q_NULLPTR);
107 #endif
108  int importProfilesFromDir(QString filename, int *skippedCnt = Q_NULLPTR, bool fromZip = false, QStringList *result = Q_NULLPTR);
109 
110  static bool checkNameValidity(QString name, QString *msg = Q_NULLPTR);
111  QList<int> findAllByNameAndVisibility(QString name, bool isGlobal = false, bool searchReference = false) const;
112  void markAsImported(QStringList importedItems);
113  bool clearImported(QString *msg = Q_NULLPTR);
114 
115  int lastSetRow() const;
116 
117  bool checkInvalid(const QModelIndex &index) const;
118  bool checkIfDeleted(const QModelIndex &index) const;
119  bool checkIfDeleted(int row) const;
120  bool checkDuplicate(const QModelIndex &index, bool isOriginalToDuplicate = false) const;
121 
122 signals:
123  void itemChanged(const QModelIndex &idx);
124 
125 protected:
126  static QString illegalCharacters();
127 
128 private:
129  QList<profile_def *> profiles_;
130  QStringList profile_files_;
131  QString set_profile_;
132  bool reset_default_;
133  bool profiles_imported_;
134 
135  int last_set_row_;
136 
137  void loadProfiles();
138  profile_def * guard(const QModelIndex &index) const;
139  profile_def * guard(int row) const;
140  GList * entry(profile_def *) const;
141 
142  int findByNameAndVisibility(QString name, bool isGlobal = false, bool searchReference = false) const;
143  int findAsReference(QString reference) const;
144 
145 #ifdef HAVE_MINIZIP
146  static bool acceptFile(QString fileName, int fileSize);
147  static QString cleanName(QString fileName);
148 #endif
149 
150  QVariant dataDisplay(const QModelIndex & idx) const;
151  QVariant dataFontRole(const QModelIndex & idx) const;
152  QVariant dataBackgroundRole(const QModelIndex & idx) const;
153  QVariant dataToolTipRole(const QModelIndex & idx) const;
154  QVariant dataPath(const QModelIndex & idx) const;
155 
156 #ifdef HAVE_MINIZIP
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:53
Definition: profile_model.h:26
Definition: profile.h:32