2 * This file is part of the PulseView project.
4 * Copyright (C) 2014 Martin Ling <martin-sigrok@earth.li>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 #include <QLibraryInfo>
26 #include <QMessageBox>
29 #include <boost/version.hpp>
31 #ifdef ENABLE_STACKTRACE
32 #include <boost/stacktrace.hpp>
36 #include <libsigrokdecode/libsigrokdecode.h>
39 #include "application.hpp"
41 #include "globalsettings.hpp"
46 using std::shared_ptr;
49 static gint sort_pds(gconstpointer a, gconstpointer b)
51 const struct srd_decoder *sda, *sdb;
53 sda = (const struct srd_decoder *)a;
54 sdb = (const struct srd_decoder *)b;
55 return strcmp(sda->id, sdb->id);
59 Application::Application(int &argc, char* argv[]) :
60 QApplication(argc, argv)
62 setApplicationVersion(PV_VERSION_STRING);
63 setApplicationName("PulseView");
64 setOrganizationName("sigrok");
65 setOrganizationDomain("sigrok.org");
68 const QStringList Application::get_languages() const
70 QStringList files = QDir(":/l10n/").entryList(QStringList("*.qm"), QDir::Files);
73 result << "en"; // Add default language to the set
75 // Remove file extensions
76 for (const QString& file : files)
77 result << file.split(".").front();
79 result.sort(Qt::CaseInsensitive);
84 const QString Application::get_language_editors(const QString& language) const
86 if (language == "de") return "Sören Apel, Uwe Hermann";
87 if (language == "es_mx") return "Carlos Diaz";
92 void Application::switch_language(const QString& language)
94 removeTranslator(&app_translator_);
95 removeTranslator(&qt_translator_);
96 removeTranslator(&qtbase_translator_);
98 if ((language != "C") && (language != "en")) {
99 // Application translations
100 QString resource = ":/l10n/" + language +".qm";
101 if (app_translator_.load(resource))
102 installTranslator(&app_translator_);
104 qWarning() << "Translation resource" << resource << "not found";
107 QString tr_path(QLibraryInfo::location(QLibraryInfo::TranslationsPath));
109 if (qt_translator_.load("qt_" + language, tr_path))
110 installTranslator(&qt_translator_);
112 qWarning() << "QT translations for" << language << "not found at" <<
113 tr_path << ", Qt translations package is probably missing";
115 // Qt base translations
116 if (qtbase_translator_.load("qtbase_" + language, tr_path))
117 installTranslator(&qtbase_translator_);
119 qWarning() << "QT base translations for" << language << "not found at" <<
120 tr_path << ", Qt translations package is probably missing";
123 if (!topLevelWidgets().empty()) {
124 // Force all windows to update
125 for (QWidget *widget : topLevelWidgets())
128 QMessageBox msg(topLevelWidgets().front());
129 msg.setText(tr("Some parts of the application may still " \
130 "use the previous language. Re-opening the affected windows or " \
131 "restarting the application will remedy this."));
132 msg.setStandardButtons(QMessageBox::Ok);
133 msg.setIcon(QMessageBox::Information);
138 void Application::on_setting_changed(const QString &key, const QVariant &value)
140 if (key == pv::GlobalSettings::Key_General_Language)
141 switch_language(value.toString());
144 void Application::collect_version_info(shared_ptr<sigrok::Context> context)
146 // Library versions and features
147 version_info_.emplace_back(applicationName(), applicationVersion());
148 version_info_.emplace_back("Qt", qVersion());
149 version_info_.emplace_back("glibmm", PV_GLIBMM_VERSION);
150 version_info_.emplace_back("Boost", BOOST_LIB_VERSION);
152 version_info_.emplace_back("libsigrok", QString("%1/%2 (rt: %3/%4)")
153 .arg(SR_PACKAGE_VERSION_STRING, SR_LIB_VERSION_STRING,
154 sr_package_version_string_get(), sr_lib_version_string_get()));
156 GSList *l_orig = sr_buildinfo_libs_get();
157 for (GSList *l = l_orig; l; l = l->next) {
158 GSList *m = (GSList *)l->data;
159 const char *lib = (const char *)m->data;
160 const char *version = (const char *)m->next->data;
161 version_info_.emplace_back(QString(" - %1").arg(QString(lib)), QString(version));
162 g_slist_free_full(m, g_free);
164 g_slist_free(l_orig);
166 char *host = sr_buildinfo_host_get();
167 version_info_.emplace_back(" - Host", QString(host));
170 char *scpi_backends = sr_buildinfo_scpi_backends_get();
171 version_info_.emplace_back(" - SCPI backends", QString(scpi_backends));
172 g_free(scpi_backends);
175 struct srd_decoder *dec;
177 version_info_.emplace_back("libsigrokdecode", QString("%1/%2 (rt: %3/%4)")
178 .arg(SRD_PACKAGE_VERSION_STRING, SRD_LIB_VERSION_STRING,
179 srd_package_version_string_get(), srd_lib_version_string_get()));
181 l_orig = srd_buildinfo_libs_get();
182 for (GSList *l = l_orig; l; l = l->next) {
183 GSList *m = (GSList *)l->data;
184 const char *lib = (const char *)m->data;
185 const char *version = (const char *)m->next->data;
186 version_info_.emplace_back(QString(" - %1").arg(QString(lib)), QString(version));
187 g_slist_free_full(m, g_free);
189 g_slist_free(l_orig);
191 host = srd_buildinfo_host_get();
192 version_info_.emplace_back(" - Host", QString(host));
197 l_orig = sr_resourcepaths_get(SR_RESOURCE_FIRMWARE);
198 for (GSList *l = l_orig; l; l = l->next)
199 fw_path_list_.emplace_back((char*)l->data);
200 g_slist_free_full(l_orig, g_free);
204 l_orig = srd_searchpaths_get();
205 for (GSList *l = l_orig; l; l = l->next)
206 pd_path_list_.emplace_back((char*)l->data);
207 g_slist_free_full(l_orig, g_free);
211 for (auto& entry : context->drivers())
212 driver_list_.emplace_back(QString::fromUtf8(entry.first.c_str()),
213 QString::fromUtf8(entry.second->long_name().c_str()));
216 for (auto& entry : context->input_formats())
217 input_format_list_.emplace_back(QString::fromUtf8(entry.first.c_str()),
218 QString::fromUtf8(entry.second->description().c_str()));
221 for (auto& entry : context->output_formats())
222 output_format_list_.emplace_back(QString::fromUtf8(entry.first.c_str()),
223 QString::fromUtf8(entry.second->description().c_str()));
227 GSList *sl = g_slist_copy((GSList *)srd_decoder_list());
228 sl = g_slist_sort(sl, sort_pds);
229 for (const GSList *l = sl; l; l = l->next) {
230 dec = (struct srd_decoder *)l->data;
231 pd_list_.emplace_back(QString::fromUtf8(dec->id),
232 QString::fromUtf8(dec->longname));
238 void Application::print_version_info()
240 cout << PV_TITLE << " " << PV_VERSION_STRING << endl;
242 cout << endl << "Libraries and features:" << endl;
243 for (pair<QString, QString>& entry : version_info_)
244 cout << " " << entry.first.toStdString() << " " << entry.second.toStdString() << endl;
246 cout << endl << "Firmware search paths:" << endl;
247 for (QString& entry : fw_path_list_)
248 cout << " " << entry.toStdString() << endl;
250 cout << endl << "Protocol decoder search paths:" << endl;
251 for (QString& entry : pd_path_list_)
252 cout << " " << entry.toStdString() << endl;
254 cout << endl << "Supported hardware drivers:" << endl;
255 for (pair<QString, QString>& entry : driver_list_)
256 cout << " " << entry.first.leftJustified(21, ' ').toStdString() <<
257 entry.second.toStdString() << endl;
259 cout << endl << "Supported input formats:" << endl;
260 for (pair<QString, QString>& entry : input_format_list_)
261 cout << " " << entry.first.leftJustified(21, ' ').toStdString() <<
262 entry.second.toStdString() << endl;
264 cout << endl << "Supported output formats:" << endl;
265 for (pair<QString, QString>& entry : output_format_list_)
266 cout << " " << entry.first.leftJustified(21, ' ').toStdString() <<
267 entry.second.toStdString() << endl;
270 cout << endl << "Supported protocol decoders:" << endl;
271 for (pair<QString, QString>& entry : pd_list_)
272 cout << " " << entry.first.leftJustified(21, ' ').toStdString() <<
273 entry.second.toStdString() << endl;
277 vector< pair<QString, QString> > Application::get_version_info() const
279 return version_info_;
282 vector<QString> Application::get_fw_path_list() const
284 return fw_path_list_;
287 vector<QString> Application::get_pd_path_list() const
289 return pd_path_list_;
292 vector< pair<QString, QString> > Application::get_driver_list() const
297 vector< pair<QString, QString> > Application::get_input_format_list() const
299 return input_format_list_;
302 vector< pair<QString, QString> > Application::get_output_format_list() const
304 return output_format_list_;
307 vector< pair<QString, QString> > Application::get_pd_list() const
312 bool Application::notify(QObject *receiver, QEvent *event)
315 return QApplication::notify(receiver, event);
316 } catch (exception& e) {
317 qDebug().nospace() << "Caught exception of type " << \
318 typeid(e).name() << " (" << e.what() << ")";
319 #ifdef ENABLE_STACKTRACE