void CaptureFilterEdit::removeFilter() { QAction *ra = qobject_cast<QAction*>(sender()); if (!ra || ra->data().toString().isEmpty()) return; QString remove_filter = ra->data().toString(); for (GList *cf_item = get_filter_list_first(CFILTER_LIST); cf_item; cf_item = g_list_next(cf_item)) { if (!cf_item->data) continue; filter_def *cf_def = (filter_def *) cf_item->data; if (!cf_def->name || !cf_def->strval) continue; if (remove_filter.compare(cf_def->strval) == 0) { remove_from_filter_list(CFILTER_LIST, cf_item); } } char *f_path; int f_save_errno; save_filter_list(CFILTER_LIST, &f_path, &f_save_errno); if (f_path != NULL) { // We had an error saving the filter. QString warning_title = tr("Unable to save capture filter settings."); QString warning_msg = tr("Could not save to your capture 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 CaptureFilterEdit::initCaptureFilter() { #ifdef HAVE_LIBPCAP setText(global_capture_opts.default_options.cfilter); #endif // HAVE_LIBPCAP updateBookmarkMenu(); }
void FileSelector::toggleBookmark() { QString path = m_model->filePath(m_view->rootIndex()); if (m_bookmarks.contains(path)) { m_bookmarks.removeAll(path); m_bookmarkButton->setIcon(QIcon(":nobookmark.png")); } else { m_bookmarks.append(path); m_bookmarkButton->setIcon(QIcon(":bookmark.png")); } updateBookmarkMenu(); }
void CaptureFilterEdit::removeFilter() { QAction *ra = qobject_cast<QAction*>(sender()); if (!ra || ra->data().toString().isEmpty()) return; QString remove_filter = ra->data().toString(); for (GList *cf_item = get_filter_list_first(CFILTER_LIST); cf_item; cf_item = g_list_next(cf_item)) { if (!cf_item->data) continue; filter_def *cf_def = (filter_def *) cf_item->data; if (!cf_def->name || !cf_def->strval) continue; if (remove_filter.compare(cf_def->strval) == 0) { remove_from_filter_list(CFILTER_LIST, cf_item); } } save_filter_list(CFILTER_LIST); updateBookmarkMenu(); }
CaptureFilterEdit::CaptureFilterEdit(QWidget *parent, bool plain) : SyntaxLineEdit(parent), plain_(plain), field_name_only_(false), enable_save_action_(false), save_action_(NULL), remove_action_(NULL), bookmark_button_(NULL), clear_button_(NULL), apply_button_(NULL) { setAccessibleName(tr("Capture filter entry")); completion_model_ = new QStringListModel(this); setCompleter(new QCompleter(completion_model_, this)); setCompletionTokenChars(libpcap_primitive_chars_); setConflict(false); if (!plain_) { bookmark_button_ = new StockIconToolButton(this, "x-capture-filter-bookmark"); bookmark_button_->setCursor(Qt::ArrowCursor); bookmark_button_->setMenu(new QMenu()); bookmark_button_->setPopupMode(QToolButton::InstantPopup); bookmark_button_->setToolTip(tr("Manage saved bookmarks.")); bookmark_button_->setIconSize(QSize(14, 14)); bookmark_button_->setStyleSheet( "QToolButton {" " border: none;" " background: transparent;" // Disables platform style on Windows. " padding: 0 0 0 0;" "}" "QToolButton::menu-indicator { image: none; }" ); connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(bookmarkClicked())); } if (!plain_) { clear_button_ = new StockIconToolButton(this, "x-filter-clear"); clear_button_->setCursor(Qt::ArrowCursor); clear_button_->setToolTip(QString()); clear_button_->setIconSize(QSize(14, 14)); clear_button_->setStyleSheet( "QToolButton {" " border: none;" " background: transparent;" // Disables platform style on Windows. " padding: 0 0 0 0;" " margin-left: 1px;" "}" ); connect(clear_button_, SIGNAL(clicked()), this, SLOT(clearFilter())); } connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&))); #if 0 // Disable the apply button for now if (!plain_) { apply_button_ = new StockIconToolButton(this, "x-filter-apply"); apply_button_->setCursor(Qt::ArrowCursor); apply_button_->setEnabled(false); apply_button_->setToolTip(tr("Apply this filter string to the display.")); apply_button_->setIconSize(QSize(24, 14)); apply_button_->setStyleSheet( "QToolButton {" " border: none;" " background: transparent;" // Disables platform style on Windows. " padding: 0 0 0 0;" "}" ); connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyCaptureFilter())); } #endif connect(this, SIGNAL(returnPressed()), this, SLOT(applyCaptureFilter())); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); QSize bksz; if (bookmark_button_) bksz = bookmark_button_->sizeHint(); QSize cbsz; if (clear_button_) cbsz = clear_button_->sizeHint(); QSize apsz; if (apply_button_) apsz = apply_button_->sizeHint(); setStyleSheet(QString( "CaptureFilterEdit {" " padding-left: %1px;" " margin-left: %2px;" " margin-right: %3px;" "}" ) .arg(frameWidth + 1) .arg(bksz.width()) .arg(cbsz.width() + apsz.width() + frameWidth + 1) ); QComboBox *cf_combo = qobject_cast<QComboBox *>(parent); if (cf_combo) { connect(cf_combo, SIGNAL(activated(QString)), this, SIGNAL(textEdited(QString))); } QThread *syntax_thread = new QThread; syntax_worker_ = new CaptureFilterSyntaxWorker; syntax_worker_->moveToThread(syntax_thread); connect(wsApp, SIGNAL(appInitialized()), this, SLOT(updateBookmarkMenu())); connect(wsApp, SIGNAL(captureFilterListChanged()), this, SLOT(updateBookmarkMenu())); connect(syntax_thread, SIGNAL(started()), syntax_worker_, SLOT(start())); connect(syntax_thread, SIGNAL(started()), this, SLOT(checkFilter())); connect(syntax_worker_, SIGNAL(syntaxResult(QString,int,QString)), this, SLOT(setFilterSyntaxState(QString,int,QString))); connect(syntax_thread, SIGNAL(finished()), syntax_worker_, SLOT(deleteLater())); syntax_thread->start(); }
FileSelector::FileSelector(QWidget *parent) : QWidget(parent), m_view(new QListView(this)), m_model(new QFileSystemModel(this)), m_title(new QLabel(this)), m_path(new QLabel(this)), m_bookmarkButton(new QPushButton(this)), m_bookmarkMenu(new QMenu(this)), m_bookmarks(), m_signalMapper(new QSignalMapper(this)) { QGridLayout *layout = new QGridLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setRowStretch(5, 1); layout->setSpacing(0); m_title->setAlignment(Qt::AlignCenter); layout->addWidget(m_title, 0, 0, 1, 2); layout->addWidget(m_path, 1, 0, 1, 2); m_view->setModel(m_model); connect(m_view, SIGNAL(activated(QModelIndex)), this, SLOT(enter(QModelIndex))); layout->addWidget(m_view, 2, 0, 6, 1); m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_view->setSelectionMode(QListView::ExtendedSelection); QFont font = m_view->font(); font.setPointSize(8); m_view->setFont(font); m_model->setNameFilterDisables(false); m_model->setRootPath("/"); connect(m_signalMapper, SIGNAL(mapped(QString)), this, SLOT(setCurrentDirectory(QString))); m_bookmarkButton->setIcon(QIcon(":nobookmark.png")); m_bookmarkButton->setShortcut(QKeySequence(Qt::ALT+Qt::Key_B)); connect(m_bookmarkButton, SIGNAL(clicked()), this, SLOT(toggleBookmark())); layout->addWidget(m_bookmarkButton, 2, 1); QPushButton *button = new QPushButton(); button->setIcon(QIcon(":up.png")); button->setShortcut(QKeySequence(Qt::ALT+Qt::Key_Up)); connect(button, SIGNAL(clicked()), this, SLOT(goUp())); layout->addWidget(button, 3, 1); button = new QPushButton(); button->setIcon(QIcon(":ok.png")); connect(button, SIGNAL(clicked()), this, SLOT(accept())); layout->addWidget(button, 6, 1); button = new QPushButton(); button->setIcon(QIcon(":cancel.png")); button->setShortcut(QKeySequence(Qt::Key_Escape)); connect(button, SIGNAL(clicked()), this, SIGNAL(cancel())); layout->addWidget(button, 7, 1); QSettings conf(QDir::homePath()+"Maps/nanomap.conf", QSettings::NativeFormat); conf.beginGroup("fileselector"); m_bookmarks = conf.value("bookmarks").toStringList(); conf.endGroup(); setCurrentDirectory(m_model->index(QDir::homePath())); updateBookmarkMenu(); m_view->setFocus(Qt::OtherFocusReason); resize(320, 240); }