Debian Codegraph @

src/main.cpp

raw symbols SCIP
1 /*
2 * midisnoop - MIDI monitor and prober
3 * Copyright (C) 2012 Devin Anderson
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 675 Mass
17 * Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <cstdio>
21 #include <cstdlib>
22 #include <exception>
23
24 #include <QtCore/QDebug>
25 #include <QtCore/QLibraryInfo>
26 #include <QtCore/QLocale>
27 #include <QtCore/QTranslator>
28 #include <QtCore/QTextStream>
29
30 #include "controller.h"
31 #include "error.h"
32
33 int
34 main(int argc, char **argv)
35 {
36 Application application(argc, argv);
37 QString errorMessage;
38
39 application.setApplicationName("midisnoop");
40 application.setOrganizationDomain("midisnoop.googlecode.com");
41 application.setOrganizationName("midisnoop.googlecode.com");
42
43 // Translations
44 QString directory = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
45 QString language = QLocale::system().name();
46 QTranslator qtTranslator;
47 qtTranslator.load("qt_" + language, directory);
48 application.installTranslator(&qtTranslator);
49 QTranslator translator;
50 translator.load("midisnoop_" + language);
51 application.installTranslator(&translator);
52 qDebug() << application.tr("Translations loaded.");
53
54 try {
55
56 // Controller
57 qDebug() << application.tr("Creating core application objects ...");
58 Controller controller(application);
59 qDebug() << application.tr("Core application objects created.");
60
61 // Run the program
62 qDebug() << application.tr("Running ...");
63 controller.run();
64
65 } catch (Error &e) {
66 errorMessage = e.getMessage();
67 } catch (std::exception &e) {
68 errorMessage = e.what();
69 }
70
71 // Deal with errors.
72 int result;
73 if (errorMessage.isEmpty()) {
74 qDebug() << application.tr("Exiting without errors ...");
75 result = EXIT_SUCCESS;
76 } else {
77 QTextStream(stderr) << application.tr("Error: %1\n").arg(errorMessage);
78 result = EXIT_FAILURE;
79 }
80
81 // Cleanup
82 qDebug() << application.tr("Unloading translations ...");
83 application.removeTranslator(&translator);
84 application.removeTranslator(&qtTranslator);
85
86 return result;
87 }