QWidget *ColoringRulesTreeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(option); QWidget *w = NULL; QTreeWidgetItem *ti = tree_->topLevelItem(index.row()); if (!ti) return NULL; switch (index.column()) { case name_col_: { SyntaxLineEdit *sle = new SyntaxLineEdit(parent); connect(sle, SIGNAL(textChanged(QString)), this, SLOT(ruleNameChanged(QString))); sle->setText(ti->text(name_col_)); w = (QWidget*) sle; } break; case filter_col_: { SyntaxLineEdit *dfe = new SyntaxLineEdit(parent); connect(dfe, SIGNAL(textChanged(QString)), dfe, SLOT(checkDisplayFilter(QString))); connect(dfe, SIGNAL(textChanged(QString)), this, SLOT(ruleFilterChanged(QString))); dfe->setText(ti->text(filter_col_)); w = (QWidget*) dfe; } break; default: break; } return w; }
QWidget *ColoringRulesTreeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const { QWidget *w = NULL; QTreeWidgetItem *ti = tree_->topLevelItem(index.row()); if (!ti) return NULL; switch (index.column()) { case name_col_: { SyntaxLineEdit *sle = new SyntaxLineEdit(parent); connect(sle, SIGNAL(textChanged(QString)), this, SLOT(ruleNameChanged(QString))); sle->setText(ti->text(name_col_)); w = (QWidget*) sle; } break; case filter_col_: { DisplayFilterEdit *dfe = new DisplayFilterEdit(parent); // It's possible to have an invalid filter and an enabled OK button at this point. // We might want to add a local slot for checking the filter status. connect(dfe, SIGNAL(textChanged(QString)), dfe, SLOT(checkDisplayFilter(QString))); dfe->setText(ti->text(filter_col_)); w = (QWidget*) dfe; } break; default: break; } return w; }
void FilterExpressionsPreferencesFrame::on_expressionTreeWidget_itemActivated(QTreeWidgetItem *item, int column) { if (!item || cur_line_edit_) return; QWidget *editor = NULL; cur_column_ = column; switch (column) { case label_col_: { cur_line_edit_ = new QLineEdit(); saved_col_string_ = item->text(label_col_); connect(cur_line_edit_, SIGNAL(editingFinished()), this, SLOT(labelEditingFinished())); editor = cur_line_edit_; break; } case expression_col_: { SyntaxLineEdit *syntax_edit = new SyntaxLineEdit(); saved_col_string_ = item->text(expression_col_); connect(syntax_edit, SIGNAL(textChanged(QString)), syntax_edit, SLOT(checkDisplayFilter(QString))); connect(syntax_edit, SIGNAL(editingFinished()), this, SLOT(expressionEditingFinished())); editor = cur_line_edit_ = syntax_edit; break; } default: return; } if (cur_line_edit_) { cur_line_edit_->setText(saved_col_string_); cur_line_edit_->selectAll(); connect(cur_line_edit_, SIGNAL(destroyed()), this, SLOT(lineEditDestroyed())); } if (editor) { QFrame *edit_frame = new QFrame(); QHBoxLayout *hb = new QHBoxLayout(); QSpacerItem *spacer = new QSpacerItem(5, 10); hb->addWidget(editor, 0); hb->addSpacerItem(spacer); hb->setStretch(1, 1); hb->setContentsMargins(0, 0, 0, 0); edit_frame->setLineWidth(0); edit_frame->setFrameStyle(QFrame::NoFrame); // The documentation suggests setting autoFillbackground. That looks silly // so we clear the item text instead. item->setText(cur_column_, ""); edit_frame->setLayout(hb); ui->expressionTreeWidget->setItemWidget(item, cur_column_, edit_frame); editor->setFocus(); } }
void SyntaxLineEdit::checkFieldName(QString field) { if (field.isEmpty()) { setSyntaxState(SyntaxLineEdit::Empty); return; } char invalid_char = proto_check_field_name(field.toUtf8().constData()); if (invalid_char) { setSyntaxState(SyntaxLineEdit::Invalid); } else { checkDisplayFilter(field); } }
void FieldFilterEdit::checkFilter(const QString& filter_text) { popFilterSyntaxStatus(); checkDisplayFilter(filter_text); switch (syntaxState()) { case Deprecated: { emit pushFilterSyntaxWarning(syntaxErrorMessage()); break; } case Invalid: { QString invalidMsg(tr("Invalid filter: ")); invalidMsg.append(syntaxErrorMessage()); emit pushFilterSyntaxStatus(invalidMsg); break; } default: break; } }
void SyntaxLineEdit::checkCustomColumn(QString fields) { if (fields.isEmpty()) { setSyntaxState(SyntaxLineEdit::Empty); return; } gchar **splitted_fields = g_regex_split_simple(COL_CUSTOM_PRIME_REGEX, fields.toUtf8().constData(), G_REGEX_ANCHORED, G_REGEX_MATCH_ANCHORED); for (guint i = 0; i < g_strv_length(splitted_fields); i++) { if (splitted_fields[i] && *splitted_fields[i]) { if (proto_check_field_name(splitted_fields[i]) != 0) { setSyntaxState(SyntaxLineEdit::Invalid); g_strfreev(splitted_fields); return; } } } g_strfreev(splitted_fields); checkDisplayFilter(fields); }
void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) { char *gdp_path, *dp_path; char *rf_path; int rf_open_errno; gchar *err_msg = NULL; /* First check if profile exists */ if (!profile_exists(profile_name, FALSE)) { if (profile_exists(profile_name, TRUE)) { char *pf_dir_path, *pf_dir_path2, *pf_filename; /* Copy from global profile */ if (create_persconffile_profile(profile_name, &pf_dir_path) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't create directory\n\"%s\":\n%s.", pf_dir_path, g_strerror(errno)); g_free(pf_dir_path); } if (copy_persconffile_profile(profile_name, profile_name, TRUE, &pf_filename, &pf_dir_path, &pf_dir_path2) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.", pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno)); g_free(pf_filename); g_free(pf_dir_path); g_free(pf_dir_path2); } } else { /* No personal and no global profile exists */ return; } } /* Then check if changing to another profile */ if (profile_name && strcmp (profile_name, get_profile_name()) == 0) { return; } /* Get the current geometry, before writing it to disk */ emit profileChanging(); if (profile_exists(get_profile_name(), FALSE)) { /* Write recent file for profile we are leaving, if it still exists */ write_profile_recent(); } /* Set profile name and update the status bar */ set_profile_name (profile_name); emit profileNameChanged(profile_name); /* Apply new preferences */ readConfigurationFiles (&gdp_path, &dp_path, true); if (!recent_read_profile_static(&rf_path, &rf_open_errno)) { simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Could not open common recent file\n\"%s\": %s.", rf_path, g_strerror(rf_open_errno)); g_free(rf_path); } if (recent.gui_fileopen_remembered_dir && test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) { set_last_open_dir(recent.gui_fileopen_remembered_dir); } timestamp_set_type (recent.gui_time_format); timestamp_set_precision(recent.gui_time_precision); timestamp_set_seconds_type (recent.gui_seconds_format); packet_list_enable_color(recent.packet_list_colorize); tap_update_timer_.setInterval(prefs.tap_update_interval); prefs_to_capture_opts(); prefs_apply_all(); #ifdef HAVE_LIBPCAP update_local_interfaces(); #endif setMonospaceFont(prefs.gui_qt_font_name); emit columnsChanged(); emit preferencesChanged(); emit recentFilesRead(); emit filterExpressionsChanged(); emit checkDisplayFilter(); /* Enable all protocols and disable from the disabled list */ proto_enable_all(); if (gdp_path == NULL && dp_path == NULL) { set_disabled_protos_list(); set_disabled_heur_dissector_list(); } /* Reload color filters */ if (!color_filters_reload(&err_msg, color_filter_add_cb)) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); g_free(err_msg); } emit localInterfaceListChanged(); emit packetDissectionChanged(); }
void DisplayFilterEdit::checkFilter(const QString& filter_text) { if (clear_button_) { clear_button_->setVisible(!filter_text.isEmpty()); } popFilterSyntaxStatus(); checkDisplayFilter(filter_text); switch (syntaxState()) { case Deprecated: { /* * We're being lazy and only printing the first "problem" token. * Would it be better to print all of them? */ QString deprecatedMsg(tr("\"%1\" may have unexpected results (see the User's Guide)") .arg(deprecatedToken())); emit pushFilterSyntaxWarning(deprecatedMsg); break; } case Invalid: { QString invalidMsg(tr("Invalid filter: ")); invalidMsg.append(syntaxErrorMessage()); emit pushFilterSyntaxStatus(invalidMsg); break; } default: break; } 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())); } else { bookmark_button_->setStockIcon("x-filter-bookmark"); } if (!match && (syntaxState() == Valid || syntaxState() == Deprecated) && !filter_text.isEmpty()) { enable_save_action = true; } save_action->setEnabled(enable_save_action); }