annotate main/main.cpp @ 5:0a687ed1b50f

* Add Thumbwheel widget for all our zooming needs * Use QSettings to save/restore window size and position -- precursor to switching our preferences to QSettings as well -- wish I'd noticed it sooner * Only suspend writes (not reads from the underlying cache objects) from the fft caches when repainting the spectrogram -- performance should now be significantly better
author Chris Cannam
date Thu, 03 Aug 2006 15:40:11 +0000
parents 40116f709d3b
children d4487202d0e8
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Visualiser
Chris@0 5 An audio file viewer and annotation editor.
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "MainWindow.h"
Chris@0 17
Chris@1 18 #include "system/System.h"
Chris@1 19 #include "system/Init.h"
Chris@0 20 #include "base/TempDirectory.h"
Chris@0 21 #include "base/PropertyContainer.h"
Chris@0 22 #include "base/Preferences.h"
Chris@1 23 #include "base/ConfigFile.h"
Chris@0 24
Chris@0 25 #include <QMetaType>
Chris@0 26 #include <QApplication>
Chris@0 27 #include <QDesktopWidget>
Chris@0 28 #include <QMessageBox>
Chris@0 29 #include <QTranslator>
Chris@0 30 #include <QLocale>
Chris@5 31 #include <QSettings>
Chris@0 32
Chris@0 33 #include <iostream>
Chris@0 34 #include <signal.h>
Chris@0 35
Chris@0 36 //!!! catch trappable signals, cleanup temporary directory etc
Chris@0 37 //!!! check for crap left over from previous run
Chris@0 38
Chris@0 39 static QMutex cleanupMutex;
Chris@0 40
Chris@0 41 static void
Chris@0 42 signalHandler(int /* signal */)
Chris@0 43 {
Chris@0 44 // Avoid this happening more than once across threads
Chris@0 45
Chris@0 46 cleanupMutex.lock();
Chris@0 47 std::cerr << "signalHandler: cleaning up and exiting" << std::endl;
Chris@0 48 TempDirectory::getInstance()->cleanup();
Chris@0 49 exit(0); // without releasing mutex
Chris@0 50 }
Chris@0 51
Chris@0 52 int
Chris@0 53 main(int argc, char **argv)
Chris@0 54 {
Chris@0 55 QApplication application(argc, argv);
Chris@0 56
Chris@0 57 signal(SIGINT, signalHandler);
Chris@0 58 signal(SIGTERM, signalHandler);
Chris@0 59
Chris@0 60 #ifndef Q_WS_WIN32
Chris@0 61 signal(SIGHUP, signalHandler);
Chris@0 62 signal(SIGQUIT, signalHandler);
Chris@0 63 #endif
Chris@0 64
Chris@0 65 svSystemSpecificInitialisation();
Chris@0 66
Chris@5 67 QApplication::setOrganizationName("Sonic Visualiser");
Chris@5 68 QApplication::setOrganizationDomain("sonicvisualiser.org");
Chris@5 69 QApplication::setApplicationName("Sonic Visualiser");
Chris@5 70
Chris@0 71 QString language = QLocale::system().name();
Chris@0 72
Chris@0 73 QTranslator qtTranslator;
Chris@0 74 QString qtTrName = QString("qt_%1").arg(language);
Chris@0 75 std::cerr << "Loading " << qtTrName.toStdString() << "..." << std::endl;
Chris@0 76 qtTranslator.load(qtTrName);
Chris@0 77 application.installTranslator(&qtTranslator);
Chris@0 78
Chris@0 79 QTranslator svTranslator;
Chris@0 80 QString svTrName = QString("sonic-visualiser_%1").arg(language);
Chris@0 81 std::cerr << "Loading " << svTrName.toStdString() << "..." << std::endl;
Chris@0 82 svTranslator.load(svTrName, ":i18n");
Chris@0 83 application.installTranslator(&svTranslator);
Chris@0 84
Chris@0 85 // Permit size_t and PropertyName to be used as args in queued signal calls
Chris@0 86 qRegisterMetaType<size_t>("size_t");
Chris@0 87 qRegisterMetaType<PropertyContainer::PropertyName>("PropertyContainer::PropertyName");
Chris@0 88
Chris@0 89 MainWindow gui;
Chris@0 90
Chris@0 91 QDesktopWidget *desktop = QApplication::desktop();
Chris@0 92 QRect available = desktop->availableGeometry();
Chris@0 93
Chris@0 94 int width = available.width() * 2 / 3;
Chris@0 95 int height = available.height() / 2;
Chris@0 96 if (height < 450) height = available.height() * 2 / 3;
Chris@0 97 if (width > height * 2) width = height * 2;
Chris@0 98
Chris@5 99 QSettings settings;
Chris@5 100 settings.beginGroup("MainWindow");
Chris@5 101 QSize size = settings.value("size", QSize(width, height)).toSize();
Chris@5 102 gui.resize(size);
Chris@5 103 if (settings.contains("position")) {
Chris@5 104 gui.move(settings.value("position").toPoint());
Chris@5 105 }
Chris@5 106 settings.endGroup();
Chris@5 107
Chris@0 108 gui.show();
Chris@0 109
Chris@0 110 if (argc > 1) {
Chris@0 111 QString path = argv[1];
Chris@0 112 bool success = false;
Chris@0 113 if (path.endsWith(".sv")) {
Chris@0 114 success = gui.openSessionFile(path);
Chris@0 115 }
Chris@0 116 if (!success) {
Chris@0 117 success = gui.openSomeFile(path);
Chris@0 118 }
Chris@0 119 if (!success) {
Chris@0 120 QMessageBox::critical(&gui, QMessageBox::tr("Failed to open file"),
Chris@0 121 QMessageBox::tr("File \"%1\" could not be opened").arg(path));
Chris@0 122 }
Chris@0 123 }
Chris@0 124
Chris@0 125 int rv = application.exec();
Chris@0 126 std::cerr << "application.exec() returned " << rv << std::endl;
Chris@0 127
Chris@0 128 cleanupMutex.lock();
Chris@0 129 TempDirectory::getInstance()->cleanup();
Chris@0 130 Preferences::getInstance()->getConfigFile()->commit();
Chris@5 131
Chris@0 132 return rv;
Chris@0 133 }