diff options
author | Roland Knall <rknall@gmail.com> | 2019-11-04 17:27:55 +0000 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2019-11-05 09:29:47 +0000 |
commit | e1dc9f82a63c3389f80e2e98a4cc983b43b9367b (patch) | |
tree | 5756d4eadd211040393422515802e521d216c482 | |
parent | c39bb02fbc1ccc5533df3b1d932e50c5d0fda739 (diff) |
Qt: Load filenames properly
Use a more stable approach for checking the file and avoid having
QFile reset with the filename. It is ok due to the fact, that it
is not opened, but is frowned upon in the documentation.
This only sets the filename once.
Change-Id: Ibe13eaf5938e060d7c39655591af34ac44340f49
Reviewed-on: https://code.wireshark.org/review/34965
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
-rw-r--r-- | ui/qt/models/filter_list_model.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/ui/qt/models/filter_list_model.cpp b/ui/qt/models/filter_list_model.cpp index b530d09ad5..6907ac5328 100644 --- a/ui/qt/models/filter_list_model.cpp +++ b/ui/qt/models/filter_list_model.cpp @@ -54,21 +54,22 @@ FilterListModel::FilterListModel(FilterListModel::FilterListType type, QObject * void FilterListModel::reload() { - QFile file; - storage.clear(); + const char * cfile = (type_ == FilterListModel::Capture) ? CFILTER_FILE_NAME : DFILTER_FILE_NAME; + /* Try personal config file first */ - file.setFileName(gchar_free_to_qstring(get_persconffile_path((type_ == FilterListModel::Capture) ? CFILTER_FILE_NAME : DFILTER_FILE_NAME, TRUE))); - /* Try personal old-style config file next */ - if ( ! file.exists() ) - file.setFileName(gchar_free_to_qstring(get_persconffile_path(FILTER_FILE_NAME, TRUE))); - /* Last but not least, try the global file */ - if ( ! file.exists() ) - file.setFileName(gchar_free_to_qstring(get_datafile_path((type_ == FilterListModel::Capture) ? CFILTER_FILE_NAME : DFILTER_FILE_NAME))); + QString fileName = gchar_free_to_qstring(get_persconffile_path(cfile, TRUE)); + if ( fileName.length() <= 0 || ! QFileInfo::exists(fileName) ) + fileName = gchar_free_to_qstring(get_persconffile_path(FILTER_FILE_NAME, TRUE)); + if ( fileName.length() <= 0 || ! QFileInfo::exists(fileName) ) + fileName = gchar_free_to_qstring(get_datafile_path(cfile)); + if ( fileName.length() <= 0 || ! QFileInfo::exists(fileName) ) + return; + QFile file(fileName); /* Still can use the model, just have to start from an empty set */ - if ( ! file.exists() || ! file.open(QIODevice::ReadOnly | QIODevice::Text) ) + if ( ! file.open(QIODevice::ReadOnly | QIODevice::Text) ) return; QTextStream in(&file); |