comparison main/main.cpp @ 0:cd5d7ff8ef38

* Reorganising code base. This revision will not compile.
author Chris Cannam
date Mon, 31 Jul 2006 12:03:45 +0000
parents
children 40116f709d3b
comparison
equal deleted inserted replaced
-1:000000000000 0:cd5d7ff8ef38
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include "MainWindow.h"
17
18 #include "base/System.h"
19 #include "base/TempDirectory.h"
20 #include "base/PropertyContainer.h"
21 #include "base/Preferences.h"
22 #include "fileio/ConfigFile.h"
23
24 #include <QMetaType>
25 #include <QApplication>
26 #include <QDesktopWidget>
27 #include <QMessageBox>
28 #include <QTranslator>
29 #include <QLocale>
30
31 #include <iostream>
32 #include <signal.h>
33
34 //!!! catch trappable signals, cleanup temporary directory etc
35 //!!! check for crap left over from previous run
36
37 static QMutex cleanupMutex;
38
39 static void
40 signalHandler(int /* signal */)
41 {
42 // Avoid this happening more than once across threads
43
44 cleanupMutex.lock();
45 std::cerr << "signalHandler: cleaning up and exiting" << std::endl;
46 TempDirectory::getInstance()->cleanup();
47 exit(0); // without releasing mutex
48 }
49
50 extern void svSystemSpecificInitialisation();
51
52 int
53 main(int argc, char **argv)
54 {
55 QApplication application(argc, argv);
56
57 signal(SIGINT, signalHandler);
58 signal(SIGTERM, signalHandler);
59
60 #ifndef Q_WS_WIN32
61 signal(SIGHUP, signalHandler);
62 signal(SIGQUIT, signalHandler);
63 #endif
64
65 svSystemSpecificInitialisation();
66
67 QString language = QLocale::system().name();
68
69 QTranslator qtTranslator;
70 QString qtTrName = QString("qt_%1").arg(language);
71 std::cerr << "Loading " << qtTrName.toStdString() << "..." << std::endl;
72 qtTranslator.load(qtTrName);
73 application.installTranslator(&qtTranslator);
74
75 QTranslator svTranslator;
76 QString svTrName = QString("sonic-visualiser_%1").arg(language);
77 std::cerr << "Loading " << svTrName.toStdString() << "..." << std::endl;
78 svTranslator.load(svTrName, ":i18n");
79 application.installTranslator(&svTranslator);
80
81 // Permit size_t and PropertyName to be used as args in queued signal calls
82 qRegisterMetaType<size_t>("size_t");
83 qRegisterMetaType<PropertyContainer::PropertyName>("PropertyContainer::PropertyName");
84
85 MainWindow gui;
86
87 QDesktopWidget *desktop = QApplication::desktop();
88 QRect available = desktop->availableGeometry();
89
90 int width = available.width() * 2 / 3;
91 int height = available.height() / 2;
92 if (height < 450) height = available.height() * 2 / 3;
93 if (width > height * 2) width = height * 2;
94
95 gui.resize(width, height);
96 gui.show();
97
98 if (argc > 1) {
99 QString path = argv[1];
100 bool success = false;
101 if (path.endsWith(".sv")) {
102 success = gui.openSessionFile(path);
103 }
104 if (!success) {
105 success = gui.openSomeFile(path);
106 }
107 if (!success) {
108 QMessageBox::critical(&gui, QMessageBox::tr("Failed to open file"),
109 QMessageBox::tr("File \"%1\" could not be opened").arg(path));
110 }
111 }
112
113 int rv = application.exec();
114 std::cerr << "application.exec() returned " << rv << std::endl;
115
116 cleanupMutex.lock();
117 TempDirectory::getInstance()->cleanup();
118 Preferences::getInstance()->getConfigFile()->commit();
119 return rv;
120 }