2012-01-04 22:13:01 +00:00
|
|
|
/* main_welcome.cpp
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* 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 <glib.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
|
|
|
|
#include "version_info.h"
|
|
|
|
|
|
|
|
#include "main_welcome.h"
|
2012-08-17 00:58:50 +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
|
|
|
|
|
|
|
#include "wireshark_application.h"
|
|
|
|
#include "interface_tree.h"
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
//MWOverlay::MWOverlay(QWidget *parent) : QWidget(parent)
|
|
|
|
//{
|
|
|
|
// setPalette(Qt::transparent);
|
|
|
|
// setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
|
|
|
// QGraphicsBlurEffect *blur = new QGraphicsBlurEffect(this);
|
|
|
|
// setGraphicsEffect(blur);
|
|
|
|
//}
|
|
|
|
|
|
|
|
//void MWOverlay::paintEvent(QPaintEvent *event)
|
|
|
|
//{
|
|
|
|
// QPainter painter(this);
|
|
|
|
// painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
|
|
|
// QRect border = rect();
|
|
|
|
//// g_log(NULL, G_LOG_LEVEL_DEBUG, "rect pre: %d %d %d %d", border.top(), border.left(), border.bottom(), border.right());
|
|
|
|
// border.setWidth(border.width() - 8);
|
|
|
|
// border.moveLeft(4);
|
|
|
|
// border.setHeight(border.height() - 8);
|
|
|
|
// border.moveTop(4);
|
|
|
|
//// g_log(NULL, G_LOG_LEVEL_DEBUG, "rect post: %d %d %d %d", border.top(), border.left(), border.bottom(), border.right());
|
|
|
|
// QPen pen;
|
|
|
|
// pen.setWidth(8);
|
|
|
|
// pen.setColor(QColor(60, 60, 60, 80));
|
|
|
|
// painter.setPen(pen);
|
|
|
|
//// painter.setBrush(Qt::blue);
|
|
|
|
// painter.drawRect(border);
|
|
|
|
//}
|
|
|
|
|
|
|
|
MainWelcome::MainWelcome(QWidget *parent) :
|
2012-08-17 00:58:50 +00:00
|
|
|
QFrame(parent),
|
|
|
|
welcome_ui_(new Ui::MainWelcome)
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
{
|
2012-08-17 00:58:50 +00:00
|
|
|
// QGridLayout *grid = new QGridLayout(this);
|
|
|
|
// QVBoxLayout *column;
|
|
|
|
// QLabel *heading;
|
2012-08-23 10:30:37 +00:00
|
|
|
#ifdef Q_WS_MAC
|
2012-01-04 22:13:01 +00:00
|
|
|
InterfaceTree *iface_tree;
|
2012-08-23 10:30:37 +00:00
|
|
|
#endif
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2012-08-17 00:58:50 +00:00
|
|
|
welcome_ui_->setupUi(this);
|
|
|
|
task_list_ = welcome_ui_->taskList;
|
2012-08-23 10:30:37 +00:00
|
|
|
#ifdef Q_WS_MAC
|
2012-08-17 00:58:50 +00:00
|
|
|
iface_tree = welcome_ui_->interfaceTree;
|
2012-08-23 10:30:37 +00:00
|
|
|
#endif
|
2012-08-17 00:58:50 +00:00
|
|
|
recent_files_ = welcome_ui_->recentList;
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2012-08-19 21:44:22 +00:00
|
|
|
setStyleSheet(QString(
|
|
|
|
"MainWelcome {"
|
|
|
|
" padding: 2em;"
|
|
|
|
" }"
|
|
|
|
"QWidget {"
|
|
|
|
" background-color: white;"
|
|
|
|
" color: #%1;"
|
|
|
|
" }"
|
|
|
|
"QListWidget {"
|
|
|
|
" border: 0;"
|
|
|
|
// " border: 1px dotted blue;"
|
|
|
|
"}"
|
|
|
|
// "QListWidget::focus {"
|
|
|
|
// " border: 1px dotted palette(mid);"
|
|
|
|
// "}"
|
|
|
|
"QListWidget::item::hover {"
|
|
|
|
" background-color: #%3;"
|
|
|
|
" color: #%4;"
|
|
|
|
"}"
|
|
|
|
"QListWidget::item:selected {"
|
|
|
|
" background-color: #%2;"
|
|
|
|
" color: white;"
|
|
|
|
"}"
|
|
|
|
"QTreeWidget {"
|
|
|
|
" border: 0;"
|
|
|
|
// " border: 1px dotted green;"
|
|
|
|
"}"
|
|
|
|
// "QTreeWidget::focus {"
|
|
|
|
// " border: 1px dotted palette(mid);"
|
|
|
|
// " background-color: palette(midlight);"
|
|
|
|
// "}"
|
|
|
|
)
|
|
|
|
.arg(tango_aluminium_6, 6, 16, QChar('0')) // Text color
|
2012-10-08 20:01:59 +00:00
|
|
|
.arg(tango_sky_blue_4, 6, 16, QChar('0')) // Selected background
|
2012-08-19 21:44:22 +00:00
|
|
|
.arg(tango_aluminium_2, 6, 16, QChar('0')) // Hover background
|
|
|
|
.arg(tango_aluminium_6, 6, 16, QChar('0')) // Hover foreground
|
2012-08-17 00:58:50 +00:00
|
|
|
);
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2012-08-17 00:58:50 +00:00
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
recent_files_->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
welcome_ui_->taskList->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
iface_tree->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
#endif
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2012-08-17 19:37:18 +00:00
|
|
|
task_list_->setStyleSheet(
|
|
|
|
"QListWidget {"
|
|
|
|
" margin-right: 2em;"
|
|
|
|
"}"
|
|
|
|
"QListWidget::item {"
|
|
|
|
" padding: 1.5em;"
|
|
|
|
" margin-bottom: 1em;"
|
|
|
|
" border-radius: 0.5em;"
|
|
|
|
"}"
|
|
|
|
// "QListWidget::item:hover {"
|
|
|
|
// " background-color: palette(midlight);"
|
|
|
|
// " background-color: palette(midlight);"
|
|
|
|
// "}"
|
|
|
|
);
|
|
|
|
|
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);
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
connect(wsApp, SIGNAL(updateRecentItemStatus(const QString &, qint64, bool)), this, SLOT(updateRecentFiles()));
|
2012-08-17 00:58:50 +00:00
|
|
|
connect(task_list_, SIGNAL(itemSelectionChanged()), this, SLOT(showTask()));
|
|
|
|
connect(recent_files_, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(openRecentItem(QListWidgetItem *)));
|
2012-01-04 22:13:01 +00:00
|
|
|
updateRecentFiles();
|
|
|
|
|
2012-08-17 00:58:50 +00:00
|
|
|
task_list_->setCurrentRow(0);
|
2012-01-04 22:13:01 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 00:58:50 +00:00
|
|
|
void MainWelcome::showTask() {
|
|
|
|
welcome_ui_->taskStack->setCurrentIndex(task_list_->currentRow());
|
|
|
|
}
|
2012-01-04 22:13:01 +00:00
|
|
|
|
|
|
|
void MainWelcome::updateRecentFiles() {
|
|
|
|
QString itemLabel;
|
|
|
|
QListWidgetItem *rfItem;
|
|
|
|
QFont rfFont;
|
|
|
|
|
|
|
|
int rfRow = 0;
|
|
|
|
foreach (recent_item_status *ri, wsApp->recent_item_list()) {
|
|
|
|
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);
|
|
|
|
rfItem->setData(Qt::UserRole, ri->filename);
|
|
|
|
rfItem->setFlags(ri->accessible ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags);
|
|
|
|
rfItem->setFont(rfFont);
|
|
|
|
rfRow++;
|
|
|
|
}
|
|
|
|
|
2012-08-17 00:58:50 +00:00
|
|
|
while (recent_files_->count() > (int) prefs.gui_recent_files_count_max) {
|
|
|
|
recent_files_->takeItem(recent_files_->count());
|
2012-01-04 22:13:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWelcome::openRecentItem(QListWidgetItem *item) {
|
|
|
|
QString cfPath = item->data(Qt::UserRole).toString();
|
|
|
|
emit recentFileActivated(cfPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
//void MainWelcome::resizeEvent(QResizeEvent *event)
|
|
|
|
//{
|
|
|
|
// overlay->resize(event->size());
|
|
|
|
//// event->accept();
|
|
|
|
|
|
|
|
// QFrame::resizeEvent(event);
|
|
|
|
//}
|
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:
|
|
|
|
*/
|