diff options
author | Roland Knall <rknall@gmail.com> | 2019-07-24 23:39:25 +0200 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2019-07-25 18:00:24 +0000 |
commit | 970524e3291eecab8ce2d7291fe4468685ca59e3 (patch) | |
tree | 0a7c9f03715e6f4e9378e414aa5a09e45e09933d /ui/qt/models | |
parent | edd5eaa57e4eb9157d7593dff6a58e030bf8987e (diff) |
Qt: Export profiles
Allow for the export of profiles. The currently selected profile may be
selected, as well as all user-defined profiles
Fixes: Bug, where invalid data has been written into the profiles not
present inside the original file
Change-Id: I7c6310920a1f3a064cfcedc7774b742ff01c9b9e
Reviewed-on: https://code.wireshark.org/review/34077
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/models')
-rw-r--r-- | ui/qt/models/profile_model.cpp | 48 | ||||
-rw-r--r-- | ui/qt/models/profile_model.h | 2 |
2 files changed, 50 insertions, 0 deletions
diff --git a/ui/qt/models/profile_model.cpp b/ui/qt/models/profile_model.cpp index 98bb90f953..750efb00e5 100644 --- a/ui/qt/models/profile_model.cpp +++ b/ui/qt/models/profile_model.cpp @@ -700,6 +700,54 @@ QFileInfoList ProfileModel::filterProfilePath(QString path, QFileInfoList ent, b } #ifdef HAVE_MINIZIP +QStringList ProfileModel::exportFileList(QModelIndexList items) +{ + QStringList result; + + foreach(QModelIndex idx, items) + { + profile_def * prof = guard(idx.row()); + if ( prof->is_global || QString(prof->name).compare(DEFAULT_PROFILE) == 0 ) + continue; + + if ( ! idx.data(ProfileModel::DATA_PATH_IS_NOT_DESCRIPTION).toBool() ) + continue; + + QString path = idx.data(ProfileModel::DATA_PATH).toString(); + QDir temp(path); + temp.setSorting(QDir::Name); + temp.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot); + QFileInfoList entries = temp.entryInfoList(); + foreach ( QFileInfo fi, entries ) + result << fi.absoluteFilePath(); + } + + return result; +} + +bool ProfileModel::exportProfiles(QString filename, QModelIndexList items, QString *err) +{ + if ( changesPending() ) + { + if ( err ) + err->append(tr("Exporting profiles while changes are pending is not allowed")); + return false; + } + + QStringList files = exportFileList(items); + if ( files.count() == 0 ) + { + if ( err ) + err->append((tr("No profiles found to export"))); + return false; + } + + if ( WireSharkZipHelper::zip(filename, files, QString(get_profiles_dir()) + QDir::separator() ) ) + return true; + + return false; +} + /* This check runs BEFORE the file has been unzipped! */ bool ProfileModel::acceptFile(QString fileName, int fileSize) { diff --git a/ui/qt/models/profile_model.h b/ui/qt/models/profile_model.h index 1e7246a02b..a095211292 100644 --- a/ui/qt/models/profile_model.h +++ b/ui/qt/models/profile_model.h @@ -93,6 +93,8 @@ public: bool changesPending() const; #ifdef HAVE_MINIZIP + QStringList exportFileList(QModelIndexList items); + bool exportProfiles(QString filename, QModelIndexList items, QString * err = Q_NULLPTR); int importProfilesFromZip(QString filename, int *skippedCnt = Q_NULLPTR); #endif int importProfilesFromDir(QString filename, int *skippedCnt = Q_NULLPTR, bool fromZip = false); |