From: Soeren Apel Date: Fri, 28 Sep 2018 21:59:18 +0000 (+0200) Subject: Fix #1213 by improving the version information handling X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4971985821bf983a56a8e6399a8609f0e4dacbe7;p=pulseview.git Fix #1213 by improving the version information handling --- diff --git a/main.cpp b/main.cpp index dc3f739f..8054e49b 100644 --- a/main.cpp +++ b/main.cpp @@ -36,6 +36,8 @@ #include #include +#include "config.h" + #ifdef ENABLE_SIGNALS #include "signalhandler.hpp" #endif @@ -59,8 +61,6 @@ #include "android/loghandler.hpp" #endif -#include "config.h" - #ifdef _WIN32 #include Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) @@ -166,6 +166,7 @@ int main(int argc, char *argv[]) vector open_files; bool restore_sessions = true; bool do_scan = true; + bool show_version = false; Application a(argc, argv); @@ -202,9 +203,8 @@ int main(int argc, char *argv[]) return 0; case 'V': - // Print version info - fprintf(stdout, "%s %s\n", PV_TITLE, PV_VERSION_STRING); - return 0; + show_version = true; + break; case 'l': { @@ -300,32 +300,37 @@ int main(int argc, char *argv[]) // Create the device manager, initialise the drivers pv::DeviceManager device_manager(context, driver, do_scan); - // Initialise the main window - pv::MainWindow w(device_manager); - w.show(); + a.collect_version_info(context); + if (show_version) { + a.print_version_info(); + } else { + // Initialise the main window + pv::MainWindow w(device_manager); + w.show(); - if (restore_sessions) - w.restore_sessions(); + if (restore_sessions) + w.restore_sessions(); - if (open_files.empty()) - w.add_default_session(); - else - for (string open_file : open_files) - w.add_session_with_file(open_file, open_file_format); + if (open_files.empty()) + w.add_default_session(); + else + for (string open_file : open_files) + w.add_session_with_file(open_file, open_file_format); #ifdef ENABLE_SIGNALS - if (SignalHandler::prepare_signals()) { - SignalHandler *const handler = new SignalHandler(&w); - QObject::connect(handler, SIGNAL(int_received()), - &w, SLOT(close())); - QObject::connect(handler, SIGNAL(term_received()), - &w, SLOT(close())); - } else - qWarning() << "Could not prepare signal handler."; + if (SignalHandler::prepare_signals()) { + SignalHandler *const handler = new SignalHandler(&w); + QObject::connect(handler, SIGNAL(int_received()), + &w, SLOT(close())); + QObject::connect(handler, SIGNAL(term_received()), + &w, SLOT(close())); + } else + qWarning() << "Could not prepare signal handler."; #endif - // Run the application - ret = a.exec(); + // Run the application + ret = a.exec(); + } #ifndef ENABLE_STACKTRACE } catch (exception& e) { diff --git a/pv/application.cpp b/pv/application.cpp index c16c9c4b..4d0dde78 100644 --- a/pv/application.cpp +++ b/pv/application.cpp @@ -20,15 +20,36 @@ #include "application.hpp" #include "config.h" +#include #include #include +#include + #ifdef ENABLE_STACKTRACE #include #endif +#ifdef ENABLE_DECODE +#include +#endif + +using std::cout; +using std::endl; using std::exception; +using std::shared_ptr; + +#ifdef ENABLE_DECODE +static gint sort_pds(gconstpointer a, gconstpointer b) +{ + const struct srd_decoder *sda, *sdb; + + sda = (const struct srd_decoder *)a; + sdb = (const struct srd_decoder *)b; + return strcmp(sda->id, sdb->id); +} +#endif Application::Application(int &argc, char* argv[]) : QApplication(argc, argv) @@ -39,6 +60,176 @@ Application::Application(int &argc, char* argv[]) : setOrganizationDomain("sigrok.org"); } +void Application::collect_version_info(shared_ptr context) +{ + // Library versions and features + version_info_.emplace_back(applicationName(), applicationVersion()); + version_info_.emplace_back("Qt", qVersion()); + version_info_.emplace_back("glibmm", PV_GLIBMM_VERSION); + version_info_.emplace_back("Boost", BOOST_LIB_VERSION); + + version_info_.emplace_back("libsigrok", QString("%1/%2 (rt: %3/%4)") + .arg(SR_PACKAGE_VERSION_STRING, SR_LIB_VERSION_STRING, + sr_package_version_string_get(), sr_lib_version_string_get())); + + GSList *l_orig = sr_buildinfo_libs_get(); + for (GSList *l = l_orig; l; l = l->next) { + GSList *m = (GSList *)l->data; + const char *lib = (const char *)m->data; + const char *version = (const char *)m->next->data; + version_info_.emplace_back(QString(" - %1").arg(QString(lib)), QString(version)); + g_slist_free_full(m, g_free); + } + g_slist_free(l_orig); + + char *host = sr_buildinfo_host_get(); + version_info_.emplace_back(" - Host", QString(host)); + g_free(host); + + char *scpi_backends = sr_buildinfo_scpi_backends_get(); + version_info_.emplace_back(" - SCPI backends", QString(scpi_backends)); + g_free(scpi_backends); + +#ifdef ENABLE_DECODE + struct srd_decoder *dec; + + version_info_.emplace_back("libsigrokdecode", QString("%1/%2 (rt: %3/%4)") + .arg(SRD_PACKAGE_VERSION_STRING, SRD_LIB_VERSION_STRING, + srd_package_version_string_get(), srd_lib_version_string_get())); + + l_orig = srd_buildinfo_libs_get(); + for (GSList *l = l_orig; l; l = l->next) { + GSList *m = (GSList *)l->data; + const char *lib = (const char *)m->data; + const char *version = (const char *)m->next->data; + version_info_.emplace_back(QString(" - %1").arg(QString(lib)), QString(version)); + g_slist_free_full(m, g_free); + } + g_slist_free(l_orig); + + host = srd_buildinfo_host_get(); + version_info_.emplace_back(" - Host", QString(host)); + g_free(host); +#endif + + // Firmware paths + l_orig = sr_resourcepaths_get(SR_RESOURCE_FIRMWARE); + for (GSList *l = l_orig; l; l = l->next) + fw_path_list_.push_back(QString((char*)l->data)); + g_slist_free_full(l_orig, g_free); + + // PD paths +#ifdef ENABLE_DECODE + l_orig = srd_searchpaths_get(); + for (GSList *l = l_orig; l; l = l->next) + pd_path_list_.push_back(QString((char*)l->data)); + g_slist_free_full(l_orig, g_free); +#endif + + // Device drivers + for (auto entry : context->drivers()) + driver_list_.emplace_back(QString::fromUtf8(entry.first.c_str()), + QString::fromUtf8(entry.second->long_name().c_str())); + + // Input formats + for (auto entry : context->input_formats()) + input_format_list_.emplace_back(QString::fromUtf8(entry.first.c_str()), + QString::fromUtf8(entry.second->description().c_str())); + + // Output formats + for (auto entry : context->output_formats()) + output_format_list_.emplace_back(QString::fromUtf8(entry.first.c_str()), + QString::fromUtf8(entry.second->description().c_str())); + + // Protocol decoders +#ifdef ENABLE_DECODE + GSList *sl = g_slist_copy((GSList *)srd_decoder_list()); + sl = g_slist_sort(sl, sort_pds); + for (const GSList *l = sl; l; l = l->next) { + dec = (struct srd_decoder *)l->data; + pd_list_.emplace_back(QString::fromUtf8(dec->id), + QString::fromUtf8(dec->longname)); + } + g_slist_free(sl); +#endif +} + +void Application::print_version_info() +{ + cout << PV_TITLE << PV_VERSION_STRING << endl; + + cout << endl << "Libraries and features:" << endl; + for (pair &entry : version_info_) + cout << " " << entry.first.toStdString() << " " << entry.second.toStdString() << endl; + + cout << endl << "Firmware search paths:" << endl; + for (QString &entry : fw_path_list_) + cout << " " << entry.toStdString() << endl; + + cout << endl << "Protocol decoder search paths:" << endl; + for (QString &entry : pd_path_list_) + cout << " " << entry.toStdString() << endl; + + cout << endl << "Supported hardware drivers:" << endl; + for (pair &entry : driver_list_) + cout << " " << entry.first.leftJustified(21, ' ').toStdString() << + entry.second.toStdString() << endl; + + cout << endl << "Supported input formats:" << endl; + for (pair &entry : input_format_list_) + cout << " " << entry.first.leftJustified(21, ' ').toStdString() << + entry.second.toStdString() << endl; + + cout << endl << "Supported output formats:" << endl; + for (pair &entry : output_format_list_) + cout << " " << entry.first.leftJustified(21, ' ').toStdString() << + entry.second.toStdString() << endl; + +#ifdef ENABLE_DECODE + cout << endl << "Supported protocol decoders:" << endl; + for (pair &entry : pd_list_) + cout << " " << entry.first.leftJustified(21, ' ').toStdString() << + entry.second.toStdString() << endl; +#endif + + cout << endl; +} + +vector< pair > Application::get_version_info() const +{ + return version_info_; +} + +vector Application::get_fw_path_list() const +{ + return fw_path_list_; +} + +vector Application::get_pd_path_list() const +{ + return pd_path_list_; +} + +vector< pair > Application::get_driver_list() const +{ + return driver_list_; +} + +vector< pair > Application::get_input_format_list() const +{ + return input_format_list_; +} + +vector< pair > Application::get_output_format_list() const +{ + return output_format_list_; +} + +vector< pair > Application::get_pd_list() const +{ + return pd_list_; +} + bool Application::notify(QObject *receiver, QEvent *event) { try { diff --git a/pv/application.hpp b/pv/application.hpp index 7059c02a..c618f80d 100644 --- a/pv/application.hpp +++ b/pv/application.hpp @@ -20,14 +20,44 @@ #ifndef PULSEVIEW_PV_APPLICATION_HPP #define PULSEVIEW_PV_APPLICATION_HPP +#include + #include +#include + +using std::shared_ptr; +using std::pair; +using std::vector; + class Application : public QApplication { + Q_OBJECT + public: Application(int &argc, char* argv[]); + + void collect_version_info(shared_ptr context); + void print_version_info(); + + vector< pair > get_version_info() const; + vector get_fw_path_list() const; + vector get_pd_path_list() const; + vector< pair > get_driver_list() const; + vector< pair > get_input_format_list() const; + vector< pair > get_output_format_list() const; + vector< pair > get_pd_list() const; + private: bool notify(QObject *receiver, QEvent *event); + + vector< pair > version_info_; + vector fw_path_list_; + vector pd_path_list_; + vector< pair > driver_list_; + vector< pair > input_format_list_; + vector< pair > output_format_list_; + vector< pair > pd_list_; }; #endif // PULSEVIEW_PV_APPLICATION_HPP diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index f0752c07..bc6688c2 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -20,7 +20,6 @@ #include "config.h" #include -#include #include #include @@ -43,6 +42,7 @@ #include "settings.hpp" +#include "pv/application.hpp" #include "pv/devicemanager.hpp" #include "pv/globalsettings.hpp" #include "pv/logging.hpp" @@ -318,167 +318,74 @@ QWidget *Settings::get_decoder_settings_form(QWidget *parent) #endif } -#ifdef ENABLE_DECODE -static gint sort_pds(gconstpointer a, gconstpointer b) -{ - const struct srd_decoder *sda, *sdb; - - sda = (const struct srd_decoder *)a; - sdb = (const struct srd_decoder *)b; - return strcmp(sda->id, sdb->id); -} -#endif - QWidget *Settings::get_about_page(QWidget *parent) const { -#ifdef ENABLE_DECODE - struct srd_decoder *dec; -#endif + Application* a = qobject_cast(QApplication::instance()); QLabel *icon = new QLabel(); icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg"))); - /* Setup the license field, with the project homepage link. */ + // Setup the license field with the project homepage link QLabel *gpl_home_info = new QLabel(); gpl_home_info->setText(tr("%1
%2").arg( tr("GNU GPL, version 3 or later"), QApplication::organizationDomain())); gpl_home_info->setOpenExternalLinks(true); - shared_ptr context = device_manager_.context(); - QString s; s.append(""); s.append(""); - /* Version, library, and feature info */ s.append(""); - - s.append(QString("") - .arg(QApplication::applicationName(), - QApplication::applicationVersion())); - s.append(QString("") - .arg(QString("Qt"), qVersion())); - s.append(QString("") - .arg(QString("glibmm"), PV_GLIBMM_VERSION)); - s.append(QString("") - .arg(QString("Boost"), BOOST_LIB_VERSION)); - - s.append(QString("") - .arg(QString("libsigrok"), SR_PACKAGE_VERSION_STRING, - SR_LIB_VERSION_STRING, sr_package_version_string_get(), - sr_lib_version_string_get())); - - GSList *l_orig = sr_buildinfo_libs_get(); - for (GSList *l = l_orig; l; l = l->next) { - GSList *m = (GSList *)l->data; - const char *lib = (const char *)m->data; - const char *version = (const char *)m->next->data; - s.append(QString("") - .arg(QString(lib), QString(version))); - g_slist_free_full(m, g_free); - } - g_slist_free(l_orig); - - char *host = sr_buildinfo_host_get(); - s.append(QString("") - .arg(QString(host))); - g_free(host); - - char *scpi_backends = sr_buildinfo_scpi_backends_get(); - s.append(QString("") - .arg(QString(scpi_backends))); - g_free(scpi_backends); - -#ifdef ENABLE_DECODE - s.append(QString("") - .arg(QString("libsigrokdecode"), SRD_PACKAGE_VERSION_STRING, - SRD_LIB_VERSION_STRING, srd_package_version_string_get(), - srd_lib_version_string_get())); - - l_orig = srd_buildinfo_libs_get(); - for (GSList *l = l_orig; l; l = l->next) { - GSList *m = (GSList *)l->data; - const char *lib = (const char *)m->data; - const char *version = (const char *)m->next->data; - s.append(QString("") - .arg(QString(lib), QString(version))); - g_slist_free_full(m, g_free); - } - g_slist_free(l_orig); - - host = srd_buildinfo_host_get(); - s.append(QString("") - .arg(QString(host))); - g_free(host); -#endif + for (pair &entry : a->get_version_info()) + s.append(QString("") + .arg(entry.first, entry.second)); s.append(""); s.append(""); - - l_orig = sr_resourcepaths_get(SR_RESOURCE_FIRMWARE); - for (GSList *l = l_orig; l; l = l->next) - s.append(QString("").arg( - QString((char*)l->data))); - g_slist_free_full(l_orig, g_free); + for (QString &entry : a->get_fw_path_list()) + s.append(QString("").arg(entry)); #ifdef ENABLE_DECODE s.append(""); s.append(""); - - l_orig = srd_searchpaths_get(); - for (GSList *l = l_orig; l; l = l->next) - s.append(QString("").arg( - QString((char*)l->data))); - g_slist_free_full(l_orig, g_free); + for (QString &entry : a->get_pd_path_list()) + s.append(QString("").arg(entry)); #endif - /* Set up the supported field */ s.append(""); s.append(""); - for (auto entry : context->drivers()) { + for (pair &entry : a->get_driver_list()) s.append(QString("") - .arg(QString::fromUtf8(entry.first.c_str()), - QString::fromUtf8(entry.second->long_name().c_str()))); - } + .arg(entry.first, entry.second)); s.append(""); s.append(""); - for (auto entry : context->input_formats()) { + for (pair &entry : a->get_input_format_list()) s.append(QString("") - .arg(QString::fromUtf8(entry.first.c_str()), - QString::fromUtf8(entry.second->description().c_str()))); - } + .arg(entry.first, entry.second)); s.append(""); s.append(""); - for (auto entry : context->output_formats()) { + for (pair &entry : a->get_output_format_list()) s.append(QString("") - .arg(QString::fromUtf8(entry.first.c_str()), - QString::fromUtf8(entry.second->description().c_str()))); - } + .arg(entry.first, entry.second)); #ifdef ENABLE_DECODE s.append(""); s.append(""); - GSList *sl = g_slist_copy((GSList *)srd_decoder_list()); - sl = g_slist_sort(sl, sort_pds); - for (const GSList *l = sl; l; l = l->next) { - dec = (struct srd_decoder *)l->data; + for (pair &entry : a->get_pd_list()) s.append(QString("") - .arg(QString::fromUtf8(dec->id), - QString::fromUtf8(dec->longname))); - } - g_slist_free(sl); + .arg(entry.first, entry.second)); #endif s.append("
" + tr("Versions, libraries and features:") + "
%1%2
%1%2
%1%2
%1%2
%1%2/%3 (rt: %4/%5)
- %1%2
- Host%1
- SCPI backends%1
%1%2/%3 (rt: %4/%5)
- %1%2
- Host%1
%1%2
" + tr("Firmware search paths:") + "
%1
%1
" + tr("Protocol decoder search paths:") + "
%1
%1
" + tr("Supported hardware drivers:") + "
%1%2
" + tr("Supported input formats:") + "
%1%2
" + tr("Supported output formats:") + "
%1%2
" + tr("Supported protocol decoders:") + "
%1%2
");