]> sigrok.org Git - sigrok-qt.git/blob - main.cpp
Update to recent API change.
[sigrok-qt.git] / main.cpp
1 /*
2  * This file is part of the sigrok project.
3  *
4  * Copyright (C) 2010-2012 Uwe Hermann <uwe@hermann-uwe.de>
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 extern "C" {
22 #include <sigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
23 #include <stdint.h>
24 #include <libsigrok/libsigrok.h>
25 }
26
27 #include <iostream>
28 #include <QtGui/QApplication>
29 #include <QTranslator>
30 #include <QLocale>
31 #include <QDebug>
32 #include "mainwindow.h"
33
34 uint8_t *sample_buffer;
35 MainWindow *w;
36
37 int main(int argc, char *argv[])
38 {
39         QString locale = QLocale::system().name();
40         QApplication a(argc, argv);
41         QTranslator translator;
42         struct sr_context *sr_ctx;
43         sr_dev_driver **drivers;
44         int ret;
45
46         translator.load(QString("locale/sigrok-qt_") + locale);
47         a.installTranslator(&translator);
48
49         /* Set some application metadata. */
50         QApplication::setApplicationVersion(APP_VERSION);
51         QApplication::setApplicationName("sigrok-qt");
52         QApplication::setOrganizationDomain("http://www.sigrok.org");
53
54         /* Disable this to actually allow running the (pre-alpha!) Qt GUI. */
55         qDebug() << "The Qt GUI is not yet usable, aborting.";
56         // return 1;
57
58         if ((ret = sr_init(&sr_ctx)) != SR_OK) {
59                 qDebug() << "ERROR: libsigrok init failed (%s): %s."
60                          << sr_strerror_name(ret), sr_strerror(ret);
61                 return 1;
62         }
63         qDebug() << "libsigrok initialized successfully.";
64
65         /* Initialize all libsigrok drivers. */
66         drivers = sr_driver_list();
67         for (int i = 0; drivers[i]; ++i) {
68                 if (sr_driver_init(sr_ctx, drivers[i]) != SR_OK) {
69                         qDebug("Failed to initialize driver '%s'.",
70                                drivers[i]->name);
71                         return 1;
72                 }
73         }
74
75         if (srd_init(NULL) != SRD_OK) {
76                 qDebug() << "ERROR: libsigrokdecode init failed.";
77                 return 1;
78         }
79         qDebug() << "libsigrokdecode initialized successfully.";
80
81         w = new MainWindow;
82         w->show();
83
84         /* The GUI wants to show a list of all PDs before use, so we
85          * might as well load them now.
86          */
87         srd_decoder_load_all();
88
89         /* Run the application. */
90         ret = a.exec();
91
92         /* Shutdown libsigrok. */
93         if ((ret = sr_exit(sr_ctx)) != SR_OK) {
94                 qDebug() << "ERROR: libsigrok shutdown failed (%s): %s."
95                          << sr_strerror_name(ret), sr_strerror(ret);
96         }
97         qDebug() << "libsigrok shutdown was successful.";
98
99         /* Shutdown libsigrokdecode. */
100         if ((ret = srd_exit()) != SRD_OK) {
101                 qDebug() << "ERROR: libsigrokdecode shutdown failed: %d.";
102         }
103         qDebug() << "libsigrokdecode shutdown was successful.";
104
105         return ret;
106 }