Qt: About dialog updates.
authorGerald Combs <gerald@wireshark.org>
Mon, 29 Jan 2018 22:40:45 +0000 (14:40 -0800)
committerAnders Broman <a.broman58@gmail.com>
Wed, 31 Jan 2018 04:55:37 +0000 (04:55 +0000)
Open lua scripts when double-clicked. Behavior depends on your system
configuration. Add tooltips accordingly.

Let Qt wrap the "Wireshark" tab information.

Set column widths by eyeballing their contents.

Elide the Folders and Plugins strings in the middle.

Fixup placeholder text capitalization.

Draw links using the palette link color.

Change-Id: Ic141eae05541480ec1e254c55fd81728d04713d9
Reviewed-on: https://code.wireshark.org/review/25510
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
epan/wslua/init_wslua.c
epan/wslua/init_wslua.h
ui/qt/about_dialog.cpp
ui/qt/about_dialog.h
ui/qt/about_dialog.ui
ui/qt/models/astringlist_list_model.cpp
ui/qt/models/astringlist_list_model.h
ui/qt/models/url_link_delegate.cpp
ui/qt/models/url_link_delegate.h

index 59a374b9355964a956b89a0d8123996706697c9d..9369972486cc6ed3d05c877bb2fb5a4a2a4d537d 100644 (file)
@@ -9,19 +9,7 @@
  * 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
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0+
  */
 
 #include "config.h"
@@ -726,7 +714,7 @@ void wslua_plugins_get_descriptions(wslua_plugin_description_callback callback,
 
     for (lua_plug = wslua_plugin_list; lua_plug != NULL; lua_plug = lua_plug->next)
     {
-        callback(lua_plug->name, lua_plug->version, "lua script",
+        callback(lua_plug->name, lua_plug->version, wslua_plugin_type_name(),
                  lua_plug->filename, user_data);
     }
 }
@@ -745,6 +733,10 @@ wslua_plugins_dump_all(void)
     wslua_plugins_get_descriptions(print_wslua_plugin_description, NULL);
 }
 
+const char *wslua_plugin_type_name(void) {
+    return "lua script";
+}
+
 static ei_register_info* ws_lua_ei = NULL;
 static int ws_lua_ei_len = 0;
 
index 1c6d9624ea3a87db5dabdcddd3aee29c1ef94630..9504379eaab739183b0ff11f4259091808f2ed01 100644 (file)
@@ -5,19 +5,7 @@
  * 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
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0+
  */
 
 #ifndef __INIT_WSLUA_H__
@@ -38,6 +26,7 @@ typedef void (*wslua_plugin_description_callback)(const char *, const char *,
                                                   void *);
 WS_DLL_PUBLIC void wslua_plugins_get_descriptions(wslua_plugin_description_callback callback, void *user_data);
 WS_DLL_PUBLIC void wslua_plugins_dump_all(void);
+WS_DLL_PUBLIC const char *wslua_plugin_type_name(void);
 
 #ifdef __cplusplus
 }
index d022afcc09644abb34e92c009ddb99af1c0b9000..5d5dc5c49bf7570df77156e99a761a423224192f 100644 (file)
@@ -15,6 +15,9 @@
 #include "wireshark_application.h"
 #include <wsutil/filesystem.h>
 
+#include <QDesktopServices>
+#include <QUrl>
+
 #ifdef HAVE_LIBSMI
 #include <epan/oids.h>
 #endif
@@ -144,8 +147,14 @@ PluginListModel::PluginListModel(QObject * parent) : AStringListListModel(parent
     typeNames_ << QString("");
     foreach(QStringList row, plugin_data)
     {
-        typeNames_ << row.at(2);
-        appendRow(row);
+        QString type_name = row.at(2);
+        QString tooltip;
+        typeNames_ << type_name;
+
+        if (type_name == wslua_plugin_type_name()) {
+            tooltip = tr("Double-click to edit");
+        }
+        appendRow(row, tooltip);
     }
 
     typeNames_.sort();
@@ -274,9 +283,11 @@ AboutDialog::AboutDialog(QWidget *parent) :
     QFile f_license;
     QString message;
 
-    GString *comp_info_str = get_compiled_version_info(get_wireshark_qt_compiled_info,
-                                              get_gui_compiled_info);
-    GString *runtime_info_str = get_runtime_version_info(get_wireshark_runtime_info);
+    QString vcs_version_info_str = get_ws_vcs_version_info();
+    QString copyright_info_str = get_copyright_info();
+    QString comp_info_str = gstring_free_to_qbytearray(get_compiled_version_info(get_wireshark_qt_compiled_info,
+                                              get_gui_compiled_info));
+    QString runtime_info_str = gstring_free_to_qbytearray(get_runtime_version_info(get_wireshark_runtime_info));
 
 
     AuthorListModel * authorModel = new AuthorListModel(this);
@@ -298,20 +309,16 @@ AboutDialog::AboutDialog(QWidget *parent) :
     /* Wireshark tab */
 
     /* Construct the message string */
-    message = QString(
-        "Version %1\n"
-        "\n"
-        "%2"
-        "\n"
-        "%3"
-        "\n"
-        "%4"
-        "\n"
-        "Wireshark is Open Source Software released under the GNU General Public License.\n"
-        "\n"
-        "Check the man page and http://www.wireshark.org for more information.")
-        .arg(get_ws_vcs_version_info(), get_copyright_info(), comp_info_str->str, runtime_info_str->str);
-
+    message = "<p>Version " + vcs_version_info_str.toHtmlEscaped() + "</p>\n\n";
+    message += "<p>" + copyright_info_str.toHtmlEscaped() + "</p>\n\n";
+    message += "<p>" + comp_info_str.toHtmlEscaped() + "</p>\n\n";
+    message += "<p>" + runtime_info_str.toHtmlEscaped() + "</p>\n\n";
+    message += "<p>Wireshark is Open Source Software released under the GNU General Public License.</p>\n\n";
+    message += "<p>Check the man page and http://www.wireshark.org for more information.</p>\n\n";
+
+    ui->label_wireshark->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
+    ui->label_wireshark->setTextFormat(Qt::RichText);
+    ui->label_wireshark->setWordWrap(true);
     ui->label_wireshark->setTextInteractionFlags(Qt::TextSelectableByMouse);
     ui->label_wireshark->setText(message);
 
@@ -333,6 +340,7 @@ AboutDialog::AboutDialog(QWidget *parent) :
     ui->tblFolders->setRootIsDecorated(false);
     ui->tblFolders->setItemDelegateForColumn(1, new UrlLinkDelegate(this));
     ui->tblFolders->setContextMenuPolicy(Qt::CustomContextMenu);
+    ui->tblFolders->setTextElideMode(Qt::ElideMiddle);
     connect(ui->tblFolders, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(handleCopyMenu(QPoint)));
     connect(ui->searchFolders, SIGNAL(textChanged(QString)), folderProxyModel, SLOT(setFilter(QString)));
     connect(ui->tblFolders, SIGNAL(clicked(QModelIndex)), this, SLOT(urlClicked(QModelIndex)));
@@ -352,6 +360,7 @@ AboutDialog::AboutDialog(QWidget *parent) :
     ui->tblPlugins->setRootIsDecorated(false);
     ui->cmbType->addItems(pluginModel->typeNames());
     ui->tblPlugins->setContextMenuPolicy(Qt::CustomContextMenu);
+    ui->tblPlugins->setTextElideMode(Qt::ElideMiddle);
     connect(ui->tblPlugins, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(handleCopyMenu(QPoint)));
     connect(ui->searchPlugins, SIGNAL(textChanged(QString)), pluginFilterModel, SLOT(setFilter(QString)));
     connect(ui->cmbType, SIGNAL(currentIndexChanged(QString)), pluginTypeModel, SLOT(setFilter(QString)));
@@ -396,31 +405,33 @@ AboutDialog::~AboutDialog()
 
 void AboutDialog::showEvent(QShowEvent * event)
 {
-    QList<QWidget *> pages;
-
-    // Authors, Folders & Shortcuts: Equal-sized columns.
-    pages << ui->tab_authors << ui->tab_folders << ui->tab_shortcuts;
-
-    foreach ( QWidget * tabPage, pages )
-    {
-        QList<QTreeView *> childs = tabPage->findChildren<QTreeView*>();
-        if ( childs.count() == 0 )
-            continue;
+    int one_em = fontMetrics().height();
 
-        QTreeView * tree = childs.at(0);
+    // Authors: Names slightly narrower than emails.
+    QAbstractItemModel *model = ui->tblAuthors->model();
+    int column_count = model->columnCount();
+    ui->tblAuthors->setColumnWidth(0, (ui->tblAuthors->parentWidget()->width() / column_count) - one_em);
 
-        int columnCount = tree->model()->columnCount();
-        for ( int cnt = 0; cnt < columnCount; cnt++ )
-            tree->setColumnWidth(cnt, tabPage->width() / columnCount);
-        tree->header()->setStretchLastSection(true);
-    }
+    // Folders: First and last to contents.
+    ui->tblFolders->resizeColumnToContents(0);
+    ui->tblFolders->resizeColumnToContents(2);
+    ui->tblFolders->setColumnWidth(1, ui->tblFolders->parentWidget()->width() -
+                                   (ui->tblFolders->columnWidth(0) + ui->tblFolders->columnWidth(2)));
 
-    // Plugins: Content-sized columns
-    QAbstractItemModel *model = ui->tblPlugins->model();
+    // Plugins: All but the last to contents.
+    model = ui->tblPlugins->model();
     for (int col = 0; model && col < model->columnCount() - 1; col++) {
         ui->tblPlugins->resizeColumnToContents(col);
     }
 
+    // Shortcuts: Set widths manually.
+    model = ui->tblShortcuts->model();
+    // Contents + 2 em-widths
+    ui->tblShortcuts->resizeColumnToContents(0);
+    ui->tblShortcuts->setColumnWidth(0, ui->tblShortcuts->columnWidth(0) + (one_em * 2));
+    ui->tblShortcuts->setColumnWidth(1, one_em * 12);
+    ui->tblShortcuts->resizeColumnToContents(2);
+
     QDialog::showEvent(event);
 }
 
@@ -532,6 +543,17 @@ void AboutDialog::copyActionTriggered(bool copyRow)
     clipBoard->setText(clipdata);
 }
 
+void AboutDialog::on_tblPlugins_doubleClicked(const QModelIndex &index)
+{
+    const int row = index.row();
+    const int type_col = 2;
+    const int path_col = 3;
+    const QAbstractItemModel *model = index.model();
+    if (model->index(row, type_col).data().toString() == wslua_plugin_type_name()) {
+        QDesktopServices::openUrl(QUrl::fromLocalFile(model->index(row, path_col).data().toString()));
+    }
+}
+
 /*
  * Editor modelines
  *
index 7bb458f30ed4e46f79d573997c78377934555075..1c4fe0c6625b6e86481d65ddb55500da3a93ca70 100644 (file)
@@ -97,7 +97,7 @@ private slots:
     void handleCopyMenu(QPoint);
     void copyActionTriggered(bool row = false);
     void copyRowActionTriggered();
-
+    void on_tblPlugins_doubleClicked(const QModelIndex &index);
 };
 
 #endif // ABOUT_DIALOG_H
index fade8f3e94e83dfbb8ce373a27c64c2a61d29252..527012415ff738d1758fe99f3c45061cbe5ec9af 100644 (file)
            <property name="text">
             <string/>
            </property>
-           <property name="scaledContents">
-            <bool>true</bool>
-           </property>
-           <property name="alignment">
-            <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
-           </property>
           </widget>
          </item>
          <item>
          <item>
           <widget class="QLineEdit" name="searchPlugins">
            <property name="placeholderText">
-            <string>Search plugins</string>
+            <string>Search Plugins</string>
            </property>
           </widget>
          </item>
           <enum>QAbstractItemView::SelectRows</enum>
          </property>
          <property name="textElideMode">
-          <enum>Qt::ElideNone</enum>
+          <enum>Qt::ElideRight</enum>
          </property>
          <property name="wordWrap">
           <bool>true</bool>
index 23955ffb183b86bf8df7606cbb24caf15d419941..6156b4496654d5d0226b239cd440e5f8218e4e8d 100644 (file)
@@ -19,16 +19,17 @@ AStringListListModel::AStringListListModel(QObject * parent):
 QAbstractTableModel(parent)
 {}
 
-AStringListListModel::~AStringListListModel() { modelData.clear(); }
+AStringListListModel::~AStringListListModel() { display_data_.clear(); }
 
-void AStringListListModel::appendRow(const QStringList & data, const QModelIndex &parent)
+void AStringListListModel::appendRow(const QStringList & display_strings, const QString & row_tooltip, const QModelIndex &parent)
 {
     QStringList columns = headerColumns();
-    if ( data.count() != columns.count() )
+    if ( display_strings.count() != columns.count() )
         return;
 
     emit beginInsertRows(parent, rowCount(), rowCount());
-    modelData << data;
+    display_data_ << display_strings;
+    tooltip_data_ << row_tooltip;
     emit endInsertRows();
 }
 
@@ -36,7 +37,7 @@ int AStringListListModel::rowCount(const QModelIndex &parent) const
 {
     Q_UNUSED(parent);
 
-    return modelData.count();
+    return display_data_.count();
 }
 
 int AStringListListModel::columnCount(const QModelIndex &parent) const
@@ -66,11 +67,18 @@ QVariant AStringListListModel::data(const QModelIndex &index, int role) const
 
     if ( role == Qt::DisplayRole )
     {
-        QStringList data = modelData.at(index.row());
+        QStringList data = display_data_.at(index.row());
 
         if ( index.column() < columnCount() )
             return QVariant::fromValue(data.at(index.column()));
     }
+    else if ( role == Qt::ToolTipRole )
+    {
+        QString tooltip = tooltip_data_.at(index.row());
+        if (!tooltip.isEmpty()) {
+            return tooltip;
+        }
+    }
 
     return QVariant();
 }
index a7459cdfe50756da1618e41dda14c395b3e24c95..ddefe4d8dd41c9de512659c6cf287f4aaa86e4b6 100644 (file)
@@ -33,12 +33,13 @@ public:
     virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
 
 protected:
-    virtual void appendRow(const QStringList &, const QModelIndex &parent = QModelIndex());
+    virtual void appendRow(const QStringList &, const QString & row_tooltip = QString(), const QModelIndex &parent = QModelIndex());
 
     virtual QStringList headerColumns() const = 0;
 
 private:
-    QList<QStringList> modelData;
+    QList<QStringList> display_data_;
+    QStringList tooltip_data_;
 };
 
 class AStringListListSortFilterProxyModel : public QSortFilterProxyModel
index 503a606100427dabf215088066b62ad4631b9834..14d05daac11fa2b360d7621144be123980814937 100644 (file)
 
 #include <ui/qt/models/url_link_delegate.h>
 
-#include <QComboBox>
-#include <QEvent>
-#include <QLineEdit>
 #include <QPainter>
-#include <QTextDocument>
-#include <QRect>
-#include <QStyledItemDelegate>
-#include <QStyleOptionViewItem>
-#include <QTextEdit>
 
 UrlLinkDelegate::UrlLinkDelegate(QObject *parent)
  : QStyledItemDelegate(parent)
 {}
 
 void UrlLinkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
-    QStyleOptionViewItem options = option;
-    initStyleOption(&options, index);
-
     QStyleOptionViewItem opt = option;
     initStyleOption(&opt, index);
 
     opt.font.setUnderline(true);
+    opt.palette.setColor(QPalette::Text, opt.palette.link().color());
 
     QStyledItemDelegate::paint(painter, opt, index);
 }
index 9bd0542133547768be2d514e33502ebca0e6a1c2..fa1a20bd6c144e8acb10c692d6064e1c27e568c3 100644 (file)
@@ -13,7 +13,6 @@
 
 #include <config.h>
 
-#include <QWidget>
 #include <QStyledItemDelegate>
 #include <QStyleOptionViewItem>
 #include <QModelIndex>