From 63ed4745a2c3abef00ec69fa1b6832674fa17605 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Thu, 10 Apr 2014 15:30:00 -0700 Subject: [PATCH] Replace QTableWidgets with QLabels + HTML tables. This lets the user select and copy the folder and plugin data as text. Add clickable local filesystem URLs while we're at it. (I suspect that you shouldn't use QTableWidgets unless you're creating a spreadsheet.) Change-Id: I45650bd4f4b6215824a4ed70ec80698d0805baba Reviewed-on: https://code.wireshark.org/review/1064 Reviewed-by: Gerald Combs --- ui/qt/about_dialog.cpp | 143 +++++++++++++++++------------- ui/qt/about_dialog.h | 4 +- ui/qt/about_dialog.ui | 191 +++++++++++++++++++++-------------------- wsutil/filesystem.h | 1 + 4 files changed, 186 insertions(+), 153 deletions(-) diff --git a/ui/qt/about_dialog.cpp b/ui/qt/about_dialog.cpp index 1998233fbe..94aa026103 100644 --- a/ui/qt/about_dialog.cpp +++ b/ui/qt/about_dialog.cpp @@ -51,48 +51,68 @@ #include "wsutil/tempfile.h" #include "wsutil/plugins.h" -#include +#include "qt_ui_utils.h" + +#include #include +#include #include "wireshark_application.h" // To do: -// - Tweat and enhance ui... +// - Tweak and enhance ui... -void AboutDialog::about_folders_row(const char *name, const char *dir, const char *typ_file) +const QString AboutDialog::about_folders_row(const char *name, const QString dir, const char *typ_file) { - ui->tbFolders->setRowCount(ui->tbFolders->rowCount() + 1); + int one_em = fontMetrics().height(); - ui->tbFolders->setItem(ui->tbFolders->rowCount()-1, 0, new QTableWidgetItem(name)); - ui->tbFolders->setItem(ui->tbFolders->rowCount()-1, 1, new QTableWidgetItem(dir)); - ui->tbFolders->setItem(ui->tbFolders->rowCount()-1, 2, new QTableWidgetItem(typ_file)); + QString short_dir = fontMetrics().elidedText(dir, Qt::ElideMiddle, one_em * 18); // Arbitrary + // It would be really nice to be able to add a tooltip with the + // full path here but Qt's rich text doesn't appear to support + // "a title=". + return QString("%1%3%4\n") + .arg(name) + .arg(QUrl::fromLocalFile(dir).toString()) + .arg(short_dir) + .arg(typ_file); } static void plugins_add_description(const char *name, const char *version, const char *types, const char *filename, void *user_data ) { - - QTableWidget *tbPlugins = (QTableWidget *)user_data; - tbPlugins->setRowCount(tbPlugins->rowCount() + 1); - - tbPlugins->setItem(tbPlugins->rowCount()-1, 0, new QTableWidgetItem(name)); - tbPlugins->setItem(tbPlugins->rowCount()-1, 1, new QTableWidgetItem(version)); - tbPlugins->setItem(tbPlugins->rowCount()-1, 2, new QTableWidgetItem(types)); - tbPlugins->setItem(tbPlugins->rowCount()-1, 3, new QTableWidgetItem(filename)); + QList *plugin_data = (QList *)user_data; + QStringList plugin_row = QStringList() << name << version << types << filename; + *plugin_data << plugin_row; } -void AboutDialog::plugins_scan() +const QString AboutDialog::plugins_scan() { + QList plugin_data; + QString plugin_table; + #ifdef HAVE_PLUGINS - plugins_get_descriptions(plugins_add_description, ui->tbPlugins); + plugins_get_descriptions(plugins_add_description, &plugin_data); #endif #ifdef HAVE_LUA - wslua_plugins_get_descriptions(plugins_add_description, ui->tbPlugins); + wslua_plugins_get_descriptions(plugins_add_description, &plugin_data); #endif + + int one_em = fontMetrics().height(); + QString short_file; + + foreach (QStringList plugin_row, plugin_data) { + short_file = fontMetrics().elidedText(plugin_row[3], Qt::ElideMiddle, one_em * 25); // Arbitrary + plugin_table += QString("%1%2%3%4\n") + .arg(plugin_row[0]) // Name + .arg(plugin_row[1]) // Version + .arg(plugin_row[2]) // Type + .arg(short_file); + } + return plugin_table; } AboutDialog::AboutDialog(QWidget *parent) : @@ -104,7 +124,7 @@ AboutDialog::AboutDialog(QWidget *parent) : QFile f_license; char *path = NULL; const char *constpath; - gchar *message; + QString message; #if defined (HAVE_LIBSMI) || defined (HAVE_GEOIP) gint i; gchar **resultArray; @@ -114,20 +134,20 @@ AboutDialog::AboutDialog(QWidget *parent) : /* Wireshark tab */ /* Construct the message string */ - message = g_strdup_printf( - "Version " VERSION "%s\n" + message = QString( + "Version " VERSION "%1\n" "\n" - "%s" + "%2" "\n" - "%s" + "%3" "\n" - "%s" + "%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.", - wireshark_gitversion, get_copyright_info(), comp_info_str->str, - runtime_info_str->str); + "Check the man page and http://www.wireshark.org for more information.") + .arg(wireshark_gitversion).arg(get_copyright_info()).arg(comp_info_str->str) + .arg(runtime_info_str->str); ui->label_wireshark->setTextInteractionFlags(Qt::TextSelectableByMouse); ui->label_wireshark->setText(message); @@ -151,54 +171,48 @@ AboutDialog::AboutDialog(QWidget *parent) : /* Folders */ - /* set column widths */ + int one_em = fontMetrics().height(); -#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) - ui->tbFolders->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); -#else - ui->tbFolders->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); -#endif - - ui->tbFolders->setRowCount(0); + // Couldn't get CSS to work. + message = QString("\n").arg(one_em / 4); + message += "\n"; /* "file open" */ - about_folders_row("\"File\" dialogs", get_last_open_dir(), "capture files"); + message += about_folders_row("\"File\" dialogs", get_last_open_dir(), "capture files"); /* temp */ - about_folders_row("Temp", g_get_tmp_dir(), "untitled capture files"); + message += about_folders_row("Temp", g_get_tmp_dir(), "untitled capture files"); /* pers conf */ - path = get_persconffile_path("", FALSE); - about_folders_row("Personal configuration", path, "\"dfilters\", \"preferences\", \"ethers\", ..."); - g_free(path); + message += about_folders_row("Personal configuration", + gchar_free_to_qstring(get_persconffile_path("", FALSE)), + "dfilters, preferences, ethers, ..."); /* global conf */ constpath = get_datafile_dir(); if (constpath != NULL) { - about_folders_row("Global configuration", constpath, "\"dfilters\", \"preferences\", \"manuf\", ..."); + message += about_folders_row("Global configuration", constpath, + "dfilters, preferences, manuf, ..."); } /* system */ - constpath = get_systemfile_dir(); - about_folders_row("System", constpath, "\"ethers\", \"ipxnets\""); + message += about_folders_row("System", get_systemfile_dir(), "ethers, ipxnets"); /* program */ - constpath = get_progfile_dir(); - about_folders_row("Program", constpath, "program files"); + message += about_folders_row("Program", get_progfile_dir(), "program files"); #if defined(HAVE_PLUGINS) || defined(HAVE_LUA) /* pers plugins */ - path = get_plugins_pers_dir(); - about_folders_row("Personal Plugins", path, "dissector plugins"); - g_free(path); + message += about_folders_row("Personal Plugins", gchar_free_to_qstring(get_plugins_pers_dir()), + "dissector plugins"); /* global plugins */ - about_folders_row("Global Plugins", get_plugin_dir(), "dissector plugins"); + message += about_folders_row("Global Plugins", get_plugin_dir(), "dissector plugins"); #endif #ifdef HAVE_PYTHON /* global python bindings */ - about_folders_row("Python Bindings", get_wspython_dir(), "python bindings"); + message += about_folders_row("Python Bindings", get_wspython_dir(), "python bindings"); #endif #ifdef HAVE_GEOIP @@ -207,8 +221,10 @@ AboutDialog::AboutDialog(QWidget *parent) : resultArray = g_strsplit(path, G_SEARCHPATH_SEPARATOR_S, 10); - for(i = 0; resultArray[i]; i++) - about_folders_row("GeoIP path", g_strstrip(resultArray[i]), "GeoIP database search path"); + for(i = 0; resultArray[i]; i++) { + message += about_folders_row("GeoIP path", g_strstrip(resultArray[i]), + "GeoIP database search path"); + } g_strfreev(resultArray); g_free(path); #endif @@ -219,20 +235,27 @@ AboutDialog::AboutDialog(QWidget *parent) : resultArray = g_strsplit(path, G_SEARCHPATH_SEPARATOR_S, 10); - for(i = 0; resultArray[i]; i++) - about_folders_row("MIB/PIB path", g_strstrip(resultArray[i]), "SMI MIB/PIB search path"); + for(i = 0; resultArray[i]; i++) { + message += about_folders_row("MIB/PIB path", g_strstrip(resultArray[i]), + "SMI MIB/PIB search path"); + } g_strfreev(resultArray); g_free(path); #endif + message += "
NameLocationTypical Files
"; + ui->label_folders->setText(message); + /* Plugins */ -#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) - ui->tbPlugins->horizontalHeader()->setResizeMode(3, QHeaderView::Stretch); -#else - ui->tbPlugins->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch); -#endif - plugins_scan(); + + message = QString("\n").arg(one_em / 4); + message += "\n"; + + message += plugins_scan(); + + message += "
NameVersionTypePath
"; + ui->label_plugins->setText(message); /* License */ diff --git a/ui/qt/about_dialog.h b/ui/qt/about_dialog.h index 38a5e4d2c0..359f047d22 100644 --- a/ui/qt/about_dialog.h +++ b/ui/qt/about_dialog.h @@ -36,8 +36,8 @@ public: explicit AboutDialog(QWidget *parent = 0); ~AboutDialog(); - void about_folders_row(const char *, const char *dir, const char *typ_file); - void plugins_scan(); + const QString about_folders_row(const char *, const QString dir, const char *typ_file); + const QString plugins_scan(); private: Ui::AboutDialog *ui; }; diff --git a/ui/qt/about_dialog.ui b/ui/qt/about_dialog.ui index 6811e9bdb2..b64ea88ac9 100644 --- a/ui/qt/about_dialog.ui +++ b/ui/qt/about_dialog.ui @@ -27,7 +27,7 @@ - 1 + 0 false @@ -39,10 +39,10 @@ Wireshark - + - - + + Qt::Horizontal @@ -55,20 +55,34 @@ - - - - - - - :/about/wssplash.png - - - false - - + + + + + + + + + :/about/wssplash.png + + + false + + + + + + + <span size=\"x-large\" weight=\"bold\">Network Protocol Analyzer</span> + + + Qt::AlignCenter + + + + - + Qt::Horizontal @@ -81,24 +95,60 @@ - - + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + - <span size=\"x-large\" weight=\"bold\">Network Protocol Analyzer</span> + + + + true + + + + Qt::Horizontal + + + + 40 + 20 + + + + - - - + + + Qt::Vertical - - true + + + 20 + 357 + - + @@ -122,40 +172,22 @@ - - - QAbstractItemView::NoEditTriggers + + + - + + Qt::RichText + + + Qt::AlignHCenter|Qt::AlignTop + + true - - true + + Qt::TextBrowserInteraction - - 0 - - - 3 - - - false - - - - Name - - - - - Folder - - - - - Typical Files - - @@ -166,45 +198,22 @@ - - - QAbstractItemView::NoEditTriggers + + + - + + Qt::RichText + + + Qt::AlignHCenter|Qt::AlignTop + + true - - true + + Qt::TextBrowserInteraction - - 0 - - - 4 - - - false - - - - Name - - - - - Version - - - - - Type - - - - - Path - - diff --git a/wsutil/filesystem.h b/wsutil/filesystem.h index 26a25de8cd..2a80ed5bbb 100644 --- a/wsutil/filesystem.h +++ b/wsutil/filesystem.h @@ -84,6 +84,7 @@ WS_DLL_PUBLIC char *get_datafile_path(const char *filename); /* * Get the personal plugin dir. + * Return value is malloced so the caller should g_free() it. */ WS_DLL_PUBLIC char *get_plugins_pers_dir(void);