Kerberos: add kerberos_inject_longterm_key() helper function
[wireshark-sm.git] / ui / qt / models / profile_model.h
blobff05475271fdaa0f5f143f8fe1582ae6f6eefa11
1 /** @file
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
8 */
10 #ifndef PROFILE_MODEL_H
11 #define PROFILE_MODEL_H
13 #include "config.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
26 Q_OBJECT
28 public:
29 ProfileSortModel(QObject *parent = Q_NULLPTR);
31 enum FilterType {
32 AllProfiles = 0,
33 PersonalProfiles,
34 GlobalProfiles
37 void setFilterType(FilterType ft);
38 void setFilterString(QString txt = QString());
40 static QStringList filterTypes();
42 protected:
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;
46 private:
47 FilterType ft_;
48 QString ftext_;
51 class ProfileModel : public QAbstractTableModel
53 Q_OBJECT
55 public:
56 explicit ProfileModel(QObject * parent = Q_NULLPTR);
58 enum {
59 COL_NAME,
60 COL_TYPE,
61 COL_AUTO_SWITCH_FILTER,
62 _LAST_ENTRY
63 } columns_;
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_;
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);
106 #endif
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;
121 signals:
122 void itemChanged(const QModelIndex &idx);
124 protected:
125 static QString illegalCharacters();
127 private:
128 QList<profile_def *> profiles_;
129 QStringList profile_files_;
130 QString set_profile_;
131 bool reset_default_;
132 bool profiles_imported_;
134 int last_set_row_;
136 void loadProfiles();
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);
147 #endif
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);
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);
165 #endif