aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/display_filter_edit.cpp92
-rw-r--r--ui/qt/display_filter_edit.h3
-rw-r--r--ui/qt/filter_dialog.cpp4
-rw-r--r--ui/qt/wireshark_application.cpp4
-rw-r--r--ui/qt/wireshark_application.h2
5 files changed, 79 insertions, 26 deletions
diff --git a/ui/qt/display_filter_edit.cpp b/ui/qt/display_filter_edit.cpp
index 3d7df3eeb1..749f856403 100644
--- a/ui/qt/display_filter_edit.cpp
+++ b/ui/qt/display_filter_edit.cpp
@@ -40,6 +40,7 @@
#include <QCompleter>
#include <QEvent>
#include <QMenu>
+#include <QMessageBox>
#include <QPainter>
#include <QStringListModel>
@@ -98,6 +99,8 @@ static const QString fld_abbrev_chars_ = "-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
DisplayFilterEdit::DisplayFilterEdit(QWidget *parent, DisplayFilterEditType type) :
SyntaxLineEdit(parent),
type_(type),
+ save_action_(NULL),
+ remove_action_(NULL),
bookmark_button_(NULL),
clear_button_(NULL),
apply_button_(NULL)
@@ -193,7 +196,9 @@ DisplayFilterEdit::DisplayFilterEdit(QWidget *parent, DisplayFilterEditType type
.arg(bksz.width())
.arg(cbsz.width() + apsz.width() + frameWidth + 1)
);
- checkFilter();
+
+ connect(wsApp, SIGNAL(appInitialized()), this, SLOT(updateBookmarkMenu()));
+ connect(wsApp, SIGNAL(displayFilterListChanged()), this, SLOT(updateBookmarkMenu()));
}
void DisplayFilterEdit::setDefaultPlaceholderText()
@@ -335,57 +340,77 @@ void DisplayFilterEdit::checkFilter(const QString& filter_text)
if (bookmark_button_) {
bool enable_save_action = false;
bool match = false;
- QMenu *bb_menu = bookmark_button_->menu();
- bb_menu->clear();
- QAction *save_action = bb_menu->addAction(tr("Save this filter"));
- connect(save_action, SIGNAL(triggered(bool)), this, SLOT(saveFilter()));
- QAction *manage_action = bb_menu->addAction(tr("Manage Display Filters"));
- connect(manage_action, SIGNAL(triggered(bool)), this, SLOT(showFilters()));
- QAction *expr_action = bb_menu->addAction(tr("Manage Filter Expressions"));
- connect(expr_action, SIGNAL(triggered(bool)), this, SLOT(showExpressionPrefs()));
-
- QAction *first_filter = NULL;
for (GList *df_item = get_filter_list_first(DFILTER_LIST); df_item; df_item = g_list_next(df_item)) {
if (!df_item->data) continue;
filter_def *df_def = (filter_def *) df_item->data;
if (!df_def->name || !df_def->strval) continue;
- int one_em = bb_menu->fontMetrics().height();
- QString prep_text = QString("%1: %2").arg(df_def->name).arg(df_def->strval);
- prep_text = bb_menu->fontMetrics().elidedText(prep_text, Qt::ElideRight, one_em * 40);
-
- QAction *prep_action = bb_menu->addAction(prep_text);
- prep_action->setData(df_def->strval);
- connect(prep_action, SIGNAL(triggered(bool)), this, SLOT(prepareFilter()));
- if (!first_filter) first_filter = prep_action;
-
if (filter_text.compare(df_def->strval) == 0) {
match = true;
}
}
- if (first_filter) bb_menu->insertSeparator(first_filter);
if (match) {
bookmark_button_->setStockIcon("x-filter-matching-bookmark");
- QAction *remove_action = new QAction(tr("Remove this filter"), bb_menu);
- bb_menu->insertAction(manage_action, remove_action);
- remove_action->setData(filter_text);
- connect(remove_action, SIGNAL(triggered(bool)), this, SLOT(removeFilter()));
+ if (remove_action_) {
+ remove_action_->setData(text());
+ remove_action_->setVisible(true);
+ }
} else {
bookmark_button_->setStockIcon("x-filter-bookmark");
+ if (remove_action_) {
+ remove_action_->setVisible(false);
+ }
}
if (!match && (syntaxState() == Valid || syntaxState() == Deprecated) && !filter_text.isEmpty()) {
enable_save_action = true;
}
- save_action->setEnabled(enable_save_action);
+ if (save_action_) {
+ save_action_->setEnabled(enable_save_action);
+ }
}
if (apply_button_) {
apply_button_->setEnabled(syntaxState() != Invalid);
}
}
+void DisplayFilterEdit::updateBookmarkMenu()
+{
+ if (!bookmark_button_)
+ return;
+
+ QMenu *bb_menu = bookmark_button_->menu();
+ bb_menu->clear();
+
+ save_action_ = bb_menu->addAction(tr("Save this filter"));
+ connect(save_action_, SIGNAL(triggered(bool)), this, SLOT(saveFilter()));
+ remove_action_ = bb_menu->addAction(tr("Remove this filter"));
+ connect(remove_action_, SIGNAL(triggered(bool)), this, SLOT(removeFilter()));
+ QAction *manage_action = bb_menu->addAction(tr("Manage Display Filters"));
+ connect(manage_action, SIGNAL(triggered(bool)), this, SLOT(showFilters()));
+ QAction *expr_action = bb_menu->addAction(tr("Manage Filter Expressions"));
+ connect(expr_action, SIGNAL(triggered(bool)), this, SLOT(showExpressionPrefs()));
+ bb_menu->addSeparator();
+
+ for (GList *df_item = get_filter_list_first(DFILTER_LIST); df_item; df_item = g_list_next(df_item)) {
+ if (!df_item->data) continue;
+ filter_def *df_def = (filter_def *) df_item->data;
+ if (!df_def->name || !df_def->strval) continue;
+
+ int one_em = bb_menu->fontMetrics().height();
+ QString prep_text = QString("%1: %2").arg(df_def->name).arg(df_def->strval);
+ prep_text = bb_menu->fontMetrics().elidedText(prep_text, Qt::ElideRight, one_em * 40);
+
+ QAction *prep_action = bb_menu->addAction(prep_text);
+ prep_action->setData(df_def->strval);
+ connect(prep_action, SIGNAL(triggered(bool)), this, SLOT(prepareFilter()));
+ }
+
+ checkFilter();
+}
+
// GTK+ behavior:
// - Operates on words (proto.c:fld_abbrev_chars).
// - Popup appears when you enter or remove text.
@@ -537,6 +562,21 @@ void DisplayFilterEdit::removeFilter()
remove_from_filter_list(DFILTER_LIST, df_item);
}
}
+
+ char *f_path;
+ int f_save_errno;
+
+ save_filter_list(DFILTER_LIST, &f_path, &f_save_errno);
+ if (f_path != NULL) {
+ // We had an error saving the filter.
+ QString warning_title = tr("Unable to save display filter settings.");
+ QString warning_msg = tr("Could not save to your display filter file\n\"%1\": %2.").arg(f_path).arg(g_strerror(f_save_errno));
+
+ QMessageBox::warning(this, warning_title, warning_msg, QMessageBox::Ok);
+ g_free(f_path);
+ }
+
+ updateBookmarkMenu();
}
void DisplayFilterEdit::showFilters()
diff --git a/ui/qt/display_filter_edit.h b/ui/qt/display_filter_edit.h
index 4b30fbd1fc..c9ecb765f0 100644
--- a/ui/qt/display_filter_edit.h
+++ b/ui/qt/display_filter_edit.h
@@ -49,6 +49,7 @@ protected:
public slots:
bool checkFilter();
+ void updateBookmarkMenu();
void applyDisplayFilter();
void displayFilterSuccess(bool success);
@@ -66,6 +67,8 @@ private slots:
private:
DisplayFilterEditType type_;
QString placeholder_text_;
+ QAction *save_action_;
+ QAction *remove_action_;
StockIconToolButton *bookmark_button_;
StockIconToolButton *clear_button_;
StockIconToolButton *apply_button_;
diff --git a/ui/qt/filter_dialog.cpp b/ui/qt/filter_dialog.cpp
index 30da83d569..519ab0fbc7 100644
--- a/ui/qt/filter_dialog.cpp
+++ b/ui/qt/filter_dialog.cpp
@@ -238,6 +238,10 @@ void FilterDialog::on_buttonBox_accepted()
QMessageBox::warning(this, warning_title, warning_msg, QMessageBox::Ok);
g_free(f_path);
}
+
+ if (filter_type_ == DisplayFilter) {
+ wsApp->emitAppSignal(WiresharkApplication::DisplayFilterListChanged);
+ }
}
void FilterDialog::on_buttonBox_helpRequested()
diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp
index d02edd225d..e7f6b11c63 100644
--- a/ui/qt/wireshark_application.cpp
+++ b/ui/qt/wireshark_application.cpp
@@ -385,6 +385,7 @@ void WiresharkApplication::setConfigurationProfile(const gchar *profile_name)
emit recentFilesRead();
emit filterExpressionsChanged();
emit checkDisplayFilter();
+ emit displayFilterListChanged();
/* Enable all protocols and disable from the disabled list */
proto_enable_all();
@@ -703,6 +704,9 @@ void WiresharkApplication::emitAppSignal(AppSignal signal)
case ColumnsChanged:
emit columnsChanged();
break;
+ case DisplayFilterListChanged:
+ emit displayFilterListChanged();
+ break;
case FilterExpressionsChanged:
emit filterExpressionsChanged();
break;
diff --git a/ui/qt/wireshark_application.h b/ui/qt/wireshark_application.h
index 56447ba387..c447f5f058 100644
--- a/ui/qt/wireshark_application.h
+++ b/ui/qt/wireshark_application.h
@@ -63,6 +63,7 @@ public:
enum AppSignal {
ColumnsChanged,
+ DisplayFilterListChanged,
FilterExpressionsChanged,
PacketDissectionChanged,
PreferencesChanged,
@@ -148,6 +149,7 @@ signals:
void profileNameChanged(const gchar *profile_name);
void columnsChanged(); // XXX This recreates the packet list. We might want to rename it accordingly.
+ void displayFilterListChanged();
void filterExpressionsChanged();
void packetDissectionChanged();
void preferencesChanged();