2012-01-04 22:13:01 +00:00
|
|
|
/* main_welcome.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2012-01-04 22:13:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2015-04-26 18:25:47 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
#include <epan/prefs.h>
|
|
|
|
|
2016-01-19 00:02:48 +00:00
|
|
|
#include "ui/capture_globals.h"
|
|
|
|
|
2016-04-19 07:03:08 +00:00
|
|
|
#include "ws_version_info.h"
|
2012-01-04 22:13:01 +00:00
|
|
|
|
|
|
|
#include "main_welcome.h"
|
2015-06-25 16:17:03 +00:00
|
|
|
#include <ui_main_welcome.h>
|
2012-08-19 21:44:22 +00:00
|
|
|
#include "tango_colors.h"
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2015-10-09 20:56:27 +00:00
|
|
|
#include "qt_ui_utils.h"
|
2012-01-04 22:13:01 +00:00
|
|
|
#include "wireshark_application.h"
|
|
|
|
#include "interface_tree.h"
|
|
|
|
|
2015-10-09 20:56:27 +00:00
|
|
|
#include <QClipboard>
|
|
|
|
#include <QDir>
|
2015-02-08 20:24:19 +00:00
|
|
|
#include <QListWidget>
|
2015-10-09 20:56:27 +00:00
|
|
|
#include <QMenu>
|
2012-11-05 03:54:21 +00:00
|
|
|
#include <QResizeEvent>
|
2015-02-08 20:24:19 +00:00
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
#include <QWidget>
|
|
|
|
|
2013-04-25 21:08:56 +00:00
|
|
|
#if !defined(Q_OS_MAC) || QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
2012-11-05 19:58:06 +00:00
|
|
|
#include <QGraphicsBlurEffect>
|
|
|
|
#endif
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2015-10-12 21:34:08 +00:00
|
|
|
#ifndef VERSION_FLAVOR
|
|
|
|
#define VERSION_FLAVOR ""
|
|
|
|
#endif
|
|
|
|
|
2016-03-18 17:31:09 +00:00
|
|
|
#ifdef HAVE_EXTCAP
|
2015-12-29 14:35:43 +00:00
|
|
|
#include <extcap.h>
|
|
|
|
#endif
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
MainWelcome::MainWelcome(QWidget *parent) :
|
2012-08-17 00:58:50 +00:00
|
|
|
QFrame(parent),
|
2012-11-05 03:54:21 +00:00
|
|
|
welcome_ui_(new Ui::MainWelcome),
|
|
|
|
splash_overlay_(NULL)
|
2012-08-17 00:58:50 +00:00
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
{
|
2012-08-17 00:58:50 +00:00
|
|
|
welcome_ui_->setupUi(this);
|
2012-12-03 19:58:55 +00:00
|
|
|
|
2016-06-12 22:10:02 +00:00
|
|
|
recent_files_ = welcome_ui_->recentList;
|
|
|
|
|
2015-04-28 08:26:46 +00:00
|
|
|
welcome_ui_->interfaceTree->resetColumnCount();
|
|
|
|
|
2016-06-12 22:10:02 +00:00
|
|
|
welcome_ui_->captureFilterComboBox->setEnabled(false);
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2012-08-19 21:44:22 +00:00
|
|
|
setStyleSheet(QString(
|
|
|
|
"MainWelcome {"
|
|
|
|
" padding: 2em;"
|
|
|
|
" }"
|
2012-12-04 00:24:25 +00:00
|
|
|
"MainWelcome, QAbstractItemView {"
|
2015-10-12 16:20:14 +00:00
|
|
|
" background-color: palette(base);"
|
|
|
|
" color: palette(text);"
|
2012-08-19 21:44:22 +00:00
|
|
|
" }"
|
|
|
|
"QListWidget {"
|
|
|
|
" border: 0;"
|
|
|
|
"}"
|
|
|
|
"QTreeWidget {"
|
|
|
|
" border: 0;"
|
|
|
|
"}"
|
|
|
|
)
|
2012-08-17 00:58:50 +00:00
|
|
|
);
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2015-10-12 21:34:08 +00:00
|
|
|
QString welcome_ss = QString(
|
|
|
|
"QLabel {"
|
|
|
|
" border-radius: 0.33em;"
|
|
|
|
" color: #%1;"
|
|
|
|
" background-color: #%2;"
|
|
|
|
" padding: 0.33em;"
|
|
|
|
"}"
|
|
|
|
)
|
|
|
|
.arg(tango_aluminium_6, 6, 16, QChar('0')) // Text color
|
|
|
|
.arg(tango_sky_blue_2, 6, 16, QChar('0')); // Background color
|
|
|
|
welcome_ui_->mainWelcomeBanner->setStyleSheet(welcome_ss);
|
|
|
|
|
2014-12-20 00:27:57 +00:00
|
|
|
QString title_ss = QString(
|
|
|
|
"QLabel {"
|
|
|
|
" color: #%1;"
|
|
|
|
"}"
|
|
|
|
)
|
|
|
|
.arg(tango_aluminium_4, 6, 16, QChar('0')); // Text color
|
2015-02-10 21:48:48 +00:00
|
|
|
|
|
|
|
// XXX Is there a better term than "flavor"? Provider? Admonition (a la DocBook)?
|
|
|
|
// Release_source?
|
|
|
|
// Typical use cases are automated builds from wireshark.org and private,
|
|
|
|
// not-for-redistribution packages.
|
|
|
|
QString flavor = VERSION_FLAVOR;
|
|
|
|
if (flavor.isEmpty()) {
|
|
|
|
welcome_ui_->flavorBanner->hide();
|
|
|
|
} else {
|
|
|
|
// If needed there are a couple of ways we can make this customizable.
|
|
|
|
// - Add one or more classes, e.g. "note" or "warning" similar to
|
|
|
|
// SyntaxLineEdit, which we can then expose vi #defines.
|
|
|
|
// - Just expose direct color values via #defines.
|
|
|
|
QString flavor_ss = QString(
|
|
|
|
"QLabel {"
|
|
|
|
" border-radius: 0.25em;"
|
|
|
|
" color: %1;"
|
|
|
|
" background-color: %2;"
|
|
|
|
" padding: 0.25em;"
|
|
|
|
"}"
|
|
|
|
)
|
|
|
|
.arg("white") // Text color
|
|
|
|
.arg("#2c4bc4"); // Background color. Matches capture start button.
|
|
|
|
// .arg(tango_butter_5, 6, 16, QChar('0')); // "Warning" background
|
|
|
|
|
|
|
|
welcome_ui_->flavorBanner->setText(flavor);
|
|
|
|
welcome_ui_->flavorBanner->setStyleSheet(flavor_ss);
|
|
|
|
}
|
2014-12-20 00:27:57 +00:00
|
|
|
welcome_ui_->captureLabel->setStyleSheet(title_ss);
|
|
|
|
welcome_ui_->recentLabel->setStyleSheet(title_ss);
|
|
|
|
welcome_ui_->helpLabel->setStyleSheet(title_ss);
|
|
|
|
|
2013-04-24 11:07:25 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2012-08-17 00:58:50 +00:00
|
|
|
recent_files_->setAttribute(Qt::WA_MacShowFocusRect, false);
|
2012-12-03 19:58:55 +00:00
|
|
|
welcome_ui_->interfaceTree->setAttribute(Qt::WA_MacShowFocusRect, false);
|
2012-08-17 00:58:50 +00:00
|
|
|
#endif
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2014-12-21 04:06:43 +00:00
|
|
|
welcome_ui_->openFrame->hide();
|
2012-08-17 00:58:50 +00:00
|
|
|
recent_files_->setStyleSheet(
|
2012-07-30 21:36:23 +00:00
|
|
|
"QListWidget::item {"
|
2012-08-19 21:44:22 +00:00
|
|
|
" padding-top: 0.2em;"
|
|
|
|
" padding-bottom: 0.2em;"
|
2012-07-30 21:36:23 +00:00
|
|
|
"}"
|
|
|
|
"QListWidget::item::first {"
|
|
|
|
" padding-top: 0;"
|
|
|
|
"}"
|
|
|
|
"QListWidget::item::last {"
|
|
|
|
" padding-bottom: 0;"
|
|
|
|
"}"
|
2012-01-04 22:13:01 +00:00
|
|
|
);
|
2012-08-17 00:58:50 +00:00
|
|
|
recent_files_->setTextElideMode(Qt::ElideLeft);
|
|
|
|
|
2015-10-09 20:56:27 +00:00
|
|
|
recent_ctx_menu_ = new QMenu(this);
|
|
|
|
welcome_ui_->recentList->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(recent_files_, SIGNAL(customContextMenuRequested(QPoint)),
|
|
|
|
this, SLOT(showRecentContextMenu(QPoint)));
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
connect(wsApp, SIGNAL(updateRecentItemStatus(const QString &, qint64, bool)), this, SLOT(updateRecentFiles()));
|
2015-02-19 23:18:44 +00:00
|
|
|
connect(wsApp, SIGNAL(appInitialized()), this, SLOT(appInitialized()));
|
2012-12-03 19:58:55 +00:00
|
|
|
connect(welcome_ui_->interfaceTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
|
|
|
|
this, SLOT(interfaceDoubleClicked(QTreeWidgetItem*,int)));
|
2016-03-18 17:31:09 +00:00
|
|
|
#ifdef HAVE_EXTCAP
|
2015-04-28 08:26:46 +00:00
|
|
|
connect(welcome_ui_->interfaceTree, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
|
|
|
|
this, SLOT(interfaceClicked(QTreeWidgetItem*,int)));
|
|
|
|
#endif
|
2016-02-23 18:04:16 +00:00
|
|
|
connect(welcome_ui_->interfaceTree, SIGNAL(itemSelectionChanged()),
|
2013-08-08 00:26:57 +00:00
|
|
|
welcome_ui_->captureFilterComboBox, SIGNAL(interfacesChanged()));
|
2016-02-23 18:04:16 +00:00
|
|
|
connect(welcome_ui_->interfaceTree, SIGNAL(itemSelectionChanged()), this, SLOT(interfaceSelected()));
|
2016-01-19 00:02:48 +00:00
|
|
|
connect(welcome_ui_->captureFilterComboBox->lineEdit(), SIGNAL(textEdited(QString)),
|
|
|
|
this, SLOT(captureFilterTextEdited(QString)));
|
2015-03-04 23:43:33 +00:00
|
|
|
connect(welcome_ui_->captureFilterComboBox, SIGNAL(pushFilterSyntaxStatus(const QString&)),
|
|
|
|
this, SIGNAL(pushFilterSyntaxStatus(const QString&)));
|
2013-08-08 00:26:57 +00:00
|
|
|
connect(welcome_ui_->captureFilterComboBox, SIGNAL(popFilterSyntaxStatus()),
|
|
|
|
this, SIGNAL(popFilterSyntaxStatus()));
|
|
|
|
connect(welcome_ui_->captureFilterComboBox, SIGNAL(captureFilterSyntaxChanged(bool)),
|
|
|
|
this, SIGNAL(captureFilterSyntaxChanged(bool)));
|
|
|
|
connect(welcome_ui_->captureFilterComboBox, SIGNAL(startCapture()),
|
|
|
|
this, SIGNAL(startCapture()));
|
2012-08-17 00:58:50 +00:00
|
|
|
connect(recent_files_, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(openRecentItem(QListWidgetItem *)));
|
2012-01-04 22:13:01 +00:00
|
|
|
updateRecentFiles();
|
|
|
|
|
2013-04-25 21:08:56 +00:00
|
|
|
#if !defined(Q_OS_MAC) || QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
2012-11-05 19:58:06 +00:00
|
|
|
// This crashes with Qt 4.8.3 on OS X.
|
|
|
|
QGraphicsBlurEffect *blur = new QGraphicsBlurEffect(welcome_ui_->childContainer);
|
2016-03-31 20:25:44 +00:00
|
|
|
blur->setBlurRadius(2);
|
2012-11-05 19:58:06 +00:00
|
|
|
welcome_ui_->childContainer->setGraphicsEffect(blur);
|
|
|
|
#endif
|
|
|
|
|
2012-11-05 03:54:21 +00:00
|
|
|
splash_overlay_ = new SplashOverlay(this);
|
|
|
|
}
|
|
|
|
|
2015-10-04 09:31:19 +00:00
|
|
|
MainWelcome::~MainWelcome()
|
|
|
|
{
|
|
|
|
delete welcome_ui_;
|
|
|
|
}
|
|
|
|
|
2013-11-25 14:15:49 +00:00
|
|
|
InterfaceTree *MainWelcome::getInterfaceTree()
|
|
|
|
{
|
|
|
|
return welcome_ui_->interfaceTree;
|
|
|
|
}
|
|
|
|
|
2016-01-07 17:27:13 +00:00
|
|
|
const QString MainWelcome::captureFilter()
|
|
|
|
{
|
|
|
|
return welcome_ui_->captureFilterComboBox->currentText();
|
|
|
|
}
|
|
|
|
|
2016-01-19 00:02:48 +00:00
|
|
|
void MainWelcome::setCaptureFilter(const QString capture_filter)
|
|
|
|
{
|
|
|
|
// capture_filter comes from the current filter in
|
|
|
|
// CaptureInterfacesDialog. We need to find a good way to handle
|
|
|
|
// multiple filters.
|
|
|
|
welcome_ui_->captureFilterComboBox->lineEdit()->setText(capture_filter);
|
|
|
|
}
|
|
|
|
|
2015-02-19 23:18:44 +00:00
|
|
|
void MainWelcome::appInitialized()
|
2012-11-05 03:54:21 +00:00
|
|
|
{
|
2015-02-19 23:18:44 +00:00
|
|
|
// XXX Add a "check for updates" link?
|
|
|
|
QString full_release = tr("You are running Wireshark ");
|
|
|
|
full_release += get_ws_vcs_version_info();
|
2015-10-05 15:03:30 +00:00
|
|
|
full_release += tr(".");
|
2015-02-19 23:18:44 +00:00
|
|
|
#ifdef HAVE_SOFTWARE_UPDATE
|
|
|
|
if (prefs.gui_update_enabled) {
|
|
|
|
full_release += tr(" You receive automatic updates.");
|
|
|
|
} else {
|
|
|
|
full_release += tr(" You have disabled automatic updates.");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
// XXX Is there a way to tell if the user installed Wireshark via an
|
|
|
|
// external package manager? If so we could say so here. We could
|
|
|
|
// also add a link to the download page.
|
|
|
|
#endif
|
|
|
|
welcome_ui_->fullReleaseLabel->setText(full_release);
|
|
|
|
|
2013-04-25 21:08:56 +00:00
|
|
|
#if !defined(Q_OS_MAC) || QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
2012-11-05 19:58:06 +00:00
|
|
|
welcome_ui_->childContainer->setGraphicsEffect(NULL);
|
|
|
|
#endif
|
2015-02-19 23:18:44 +00:00
|
|
|
|
2016-02-23 18:04:16 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
welcome_ui_->captureFilterComboBox->lineEdit()->setText(global_capture_opts.default_options.cfilter);
|
|
|
|
#endif // HAVE_LIBPCAP
|
|
|
|
|
|
|
|
// Trigger interfacesUpdated.
|
|
|
|
welcome_ui_->interfaceTree->selectedInterfaceChanged();
|
|
|
|
|
2016-06-12 22:10:02 +00:00
|
|
|
welcome_ui_->captureFilterComboBox->setEnabled(true);
|
|
|
|
|
2012-11-05 03:54:21 +00:00
|
|
|
delete splash_overlay_;
|
|
|
|
splash_overlay_ = NULL;
|
2012-01-04 22:13:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 00:21:24 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2016-01-19 00:02:48 +00:00
|
|
|
// Update each selected device cfilter when the user changes the contents
|
|
|
|
// of the capture filter lineedit. We do so here so that we don't clobber
|
|
|
|
// filters set in the Capture Options / Interfaces dialog or ones set via
|
|
|
|
// the command line.
|
|
|
|
void MainWelcome::captureFilterTextEdited(const QString capture_filter)
|
|
|
|
{
|
|
|
|
if (global_capture_opts.num_selected > 0) {
|
|
|
|
interface_t device;
|
|
|
|
|
|
|
|
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
|
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
|
|
|
|
if (!device.selected) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// if (device.active_dlt == -1) {
|
|
|
|
// simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The link type of interface %s was not specified.", device.name);
|
|
|
|
// continue; /* Programming error: somehow managed to select an "unsupported" entry */
|
|
|
|
// }
|
|
|
|
g_array_remove_index(global_capture_opts.all_ifaces, i);
|
|
|
|
g_free(device.cfilter);
|
|
|
|
if (capture_filter.isEmpty()) {
|
|
|
|
device.cfilter = NULL;
|
|
|
|
} else {
|
|
|
|
device.cfilter = qstring_strdup(capture_filter);
|
|
|
|
}
|
|
|
|
g_array_insert_val(global_capture_opts.all_ifaces, i, device);
|
|
|
|
// update_filter_string(device.name, filter_text);
|
|
|
|
}
|
|
|
|
}
|
2016-02-23 18:04:16 +00:00
|
|
|
welcome_ui_->interfaceTree->updateToolTips();
|
|
|
|
}
|
2016-06-28 00:21:24 +00:00
|
|
|
#else
|
|
|
|
// No-op if we don't have capturing.
|
|
|
|
void MainWelcome::captureFilterTextEdited(const QString)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2016-02-23 18:04:16 +00:00
|
|
|
|
|
|
|
// The interface list selection has changed. At this point the user might
|
|
|
|
// have entered a filter or we might have pre-filled one from a number of
|
|
|
|
// sources such as our remote connection, the command line, or a previous
|
|
|
|
// selection.
|
|
|
|
// Must not change any interface data.
|
|
|
|
void MainWelcome::interfaceSelected()
|
|
|
|
{
|
|
|
|
QPair <const QString, bool> sf_pair = CaptureFilterEdit::getSelectedFilter();
|
|
|
|
const QString user_filter = sf_pair.first;
|
|
|
|
bool conflict = sf_pair.second;
|
|
|
|
|
|
|
|
if (conflict) {
|
|
|
|
welcome_ui_->captureFilterComboBox->lineEdit()->clear();
|
|
|
|
welcome_ui_->captureFilterComboBox->setConflict(true);
|
|
|
|
} else {
|
|
|
|
welcome_ui_->captureFilterComboBox->lineEdit()->setText(user_filter);
|
|
|
|
}
|
2016-01-19 00:02:48 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 21:47:20 +00:00
|
|
|
void MainWelcome::interfaceDoubleClicked(QTreeWidgetItem *item, int)
|
2012-12-03 19:58:55 +00:00
|
|
|
{
|
|
|
|
if (item) {
|
2016-03-18 17:31:09 +00:00
|
|
|
#ifdef HAVE_EXTCAP
|
2015-12-29 14:35:43 +00:00
|
|
|
QString extcap_string = QVariant(item->data(IFTREE_COL_EXTCAP, Qt::UserRole)).toString();
|
|
|
|
/* We trust the string here. If this interface is really extcap, the string is
|
|
|
|
* being checked immediatly before the dialog is being generated */
|
2016-01-23 12:18:30 +00:00
|
|
|
if (extcap_string.length() > 0) {
|
2015-12-29 14:35:43 +00:00
|
|
|
QString device_name = QVariant(item->data(IFTREE_COL_NAME, Qt::UserRole)).toString();
|
|
|
|
/* this checks if configuration is required and not yet provided or saved via prefs */
|
2016-01-23 12:18:30 +00:00
|
|
|
if (extcap_has_configuration((const char *)(device_name.toStdString().c_str()), TRUE)) {
|
2015-12-29 14:35:43 +00:00
|
|
|
emit showExtcapOptions(device_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2012-12-03 19:58:55 +00:00
|
|
|
emit startCapture();
|
|
|
|
}
|
|
|
|
}
|
2015-05-11 20:53:15 +00:00
|
|
|
|
2016-03-18 17:31:09 +00:00
|
|
|
#ifdef HAVE_EXTCAP
|
2015-04-28 08:26:46 +00:00
|
|
|
void MainWelcome::interfaceClicked(QTreeWidgetItem *item, int column)
|
|
|
|
{
|
2016-01-23 12:18:30 +00:00
|
|
|
if (column == IFTREE_COL_EXTCAP) {
|
2015-04-28 08:26:46 +00:00
|
|
|
QString extcap_string = QVariant(item->data(IFTREE_COL_EXTCAP, Qt::UserRole)).toString();
|
|
|
|
/* We trust the string here. If this interface is really extcap, the string is
|
|
|
|
* being checked immediatly before the dialog is being generated */
|
2016-01-23 12:18:30 +00:00
|
|
|
if (extcap_string.length() > 0) {
|
2015-04-28 08:26:46 +00:00
|
|
|
QString device_name = QVariant(item->data(IFTREE_COL_NAME, Qt::UserRole)).toString();
|
|
|
|
emit showExtcapOptions(device_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-18 17:31:09 +00:00
|
|
|
#endif
|
2012-12-03 19:58:55 +00:00
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
void MainWelcome::updateRecentFiles() {
|
|
|
|
QString itemLabel;
|
|
|
|
QListWidgetItem *rfItem;
|
|
|
|
QFont rfFont;
|
2015-11-21 20:15:53 +00:00
|
|
|
QString selectedFilename;
|
|
|
|
|
|
|
|
if (!recent_files_->selectedItems().isEmpty()) {
|
|
|
|
rfItem = recent_files_->selectedItems().first();
|
|
|
|
selectedFilename = rfItem->data(Qt::UserRole).toString();
|
|
|
|
}
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2016-09-02 13:45:53 +00:00
|
|
|
if (wsApp->recentItems().count() == 0) {
|
|
|
|
// Recent menu has been cleared, remove all recent files.
|
|
|
|
while (recent_files_->count()) {
|
|
|
|
delete recent_files_->item(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
int rfRow = 0;
|
2012-11-03 22:48:29 +00:00
|
|
|
foreach (recent_item_status *ri, wsApp->recentItems()) {
|
2012-01-04 22:13:01 +00:00
|
|
|
itemLabel = ri->filename;
|
|
|
|
|
2012-08-17 00:58:50 +00:00
|
|
|
if (rfRow >= recent_files_->count()) {
|
|
|
|
recent_files_->addItem(itemLabel);
|
2012-01-04 22:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
itemLabel.append(" (");
|
|
|
|
if (ri->accessible) {
|
|
|
|
if (ri->size/1024/1024/1024 > 10) {
|
2012-07-30 21:36:23 +00:00
|
|
|
itemLabel.append(QString("%1 GB").arg(ri->size/1024/1024/1024));
|
2012-01-04 22:13:01 +00:00
|
|
|
} else if (ri->size/1024/1024 > 10) {
|
2012-07-30 21:36:23 +00:00
|
|
|
itemLabel.append(QString("%1 MB").arg(ri->size/1024/1024));
|
2012-01-04 22:13:01 +00:00
|
|
|
} else if (ri->size/1024 > 10) {
|
2012-07-30 21:36:23 +00:00
|
|
|
itemLabel.append(QString("%1 KB").arg(ri->size/1024));
|
2012-01-04 22:13:01 +00:00
|
|
|
} else {
|
|
|
|
itemLabel.append(QString("%1 Bytes").arg(ri->size));
|
|
|
|
}
|
|
|
|
} else {
|
2012-07-30 21:36:23 +00:00
|
|
|
itemLabel.append(tr("not found"));
|
2012-01-04 22:13:01 +00:00
|
|
|
}
|
2012-07-30 21:36:23 +00:00
|
|
|
itemLabel.append(")");
|
2012-01-04 22:13:01 +00:00
|
|
|
rfFont.setItalic(!ri->accessible);
|
2012-08-17 00:58:50 +00:00
|
|
|
rfItem = recent_files_->item(rfRow);
|
2012-01-04 22:13:01 +00:00
|
|
|
rfItem->setText(itemLabel);
|
2016-05-12 00:55:46 +00:00
|
|
|
rfItem->setData(Qt::AccessibleTextRole, itemLabel);
|
2012-01-04 22:13:01 +00:00
|
|
|
rfItem->setData(Qt::UserRole, ri->filename);
|
|
|
|
rfItem->setFlags(ri->accessible ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags);
|
|
|
|
rfItem->setFont(rfFont);
|
2015-11-21 20:15:53 +00:00
|
|
|
if (ri->filename == selectedFilename) {
|
|
|
|
recent_files_->setItemSelected(rfItem, true);
|
|
|
|
}
|
2012-01-04 22:13:01 +00:00
|
|
|
rfRow++;
|
|
|
|
}
|
|
|
|
|
2016-05-13 18:13:07 +00:00
|
|
|
int row = recent_files_->count();
|
|
|
|
while (row > 0 && row > (int) prefs.gui_recent_files_count_max) {
|
|
|
|
row--;
|
2016-05-17 04:12:57 +00:00
|
|
|
delete recent_files_->item(row);
|
2012-01-04 22:13:01 +00:00
|
|
|
}
|
2014-12-21 04:06:43 +00:00
|
|
|
if (recent_files_->count() > 0) {
|
|
|
|
welcome_ui_->openFrame->animatedShow();
|
|
|
|
} else {
|
|
|
|
welcome_ui_->openFrame->animatedHide();
|
|
|
|
}
|
2012-01-04 22:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWelcome::openRecentItem(QListWidgetItem *item) {
|
|
|
|
QString cfPath = item->data(Qt::UserRole).toString();
|
|
|
|
emit recentFileActivated(cfPath);
|
|
|
|
}
|
|
|
|
|
2012-11-05 03:54:21 +00:00
|
|
|
void MainWelcome::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
if (splash_overlay_)
|
|
|
|
splash_overlay_->resize(event->size());
|
|
|
|
// event->accept();
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2012-11-05 03:54:21 +00:00
|
|
|
QFrame::resizeEvent(event);
|
|
|
|
}
|
2012-09-04 08:18:31 +00:00
|
|
|
|
2016-02-23 18:04:16 +00:00
|
|
|
void MainWelcome::setCaptureFilterText(const QString capture_filter)
|
|
|
|
{
|
|
|
|
welcome_ui_->captureFilterComboBox->lineEdit()->setText(capture_filter);
|
|
|
|
captureFilterTextEdited(capture_filter);
|
|
|
|
}
|
|
|
|
|
2013-12-21 16:55:43 +00:00
|
|
|
void MainWelcome::changeEvent(QEvent* event)
|
|
|
|
{
|
|
|
|
if (0 != event)
|
|
|
|
{
|
|
|
|
switch (event->type())
|
|
|
|
{
|
|
|
|
case QEvent::LanguageChange:
|
|
|
|
welcome_ui_->retranslateUi(this);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QFrame::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-10-09 20:56:27 +00:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
static const QString show_in_str_ = QObject::tr("Show in Finder");
|
|
|
|
#else
|
|
|
|
static const QString show_in_str_ = QObject::tr("Show in Folder");
|
|
|
|
#endif
|
|
|
|
void MainWelcome::showRecentContextMenu(QPoint pos)
|
|
|
|
{
|
|
|
|
QListWidgetItem *li = recent_files_->itemAt(pos);
|
|
|
|
if (!li) return;
|
|
|
|
|
|
|
|
recent_ctx_menu_->clear();
|
|
|
|
|
|
|
|
QString cf_path = li->data(Qt::UserRole).toString();
|
|
|
|
QAction *show_action = recent_ctx_menu_->addAction(show_in_str_);
|
|
|
|
|
|
|
|
show_action->setData(cf_path);
|
|
|
|
connect(show_action, SIGNAL(triggered(bool)), this, SLOT(showRecentFolder()));
|
|
|
|
|
|
|
|
QAction *copy_action = recent_ctx_menu_->addAction(tr("Copy file path"));
|
|
|
|
copy_action->setData(cf_path);
|
|
|
|
connect(copy_action, SIGNAL(triggered(bool)), this, SLOT(copyRecentPath()));
|
|
|
|
|
|
|
|
recent_ctx_menu_->exec(recent_files_->mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWelcome::showRecentFolder()
|
|
|
|
{
|
|
|
|
QAction *ria = qobject_cast<QAction*>(sender());
|
|
|
|
if (!ria) return;
|
|
|
|
|
|
|
|
QString cf_path = ria->data().toString();
|
|
|
|
desktop_show_in_folder(cf_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWelcome::copyRecentPath()
|
|
|
|
{
|
|
|
|
QAction *ria = qobject_cast<QAction*>(sender());
|
|
|
|
if (!ria) return;
|
|
|
|
|
|
|
|
QString cf_path = ria->data().toString();
|
|
|
|
if (cf_path.isEmpty()) return;
|
|
|
|
|
|
|
|
wsApp->clipboard()->setText(cf_path);
|
|
|
|
}
|
|
|
|
|
2012-09-04 08:18:31 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|