comparison main/main.cpp @ 283:d27c322b5d6e

* Avoid crash when "hiding" non-visible splash (I don't quite understand this one, but hey)
author Chris Cannam
date Thu, 13 Nov 2008 18:17:33 +0000
parents 64a8ee011004
children 5c5a1ce79ad5
comparison
equal deleted inserted replaced
282:64a8ee011004 283:d27c322b5d6e
19 #include "system/Init.h" 19 #include "system/Init.h"
20 #include "base/TempDirectory.h" 20 #include "base/TempDirectory.h"
21 #include "base/PropertyContainer.h" 21 #include "base/PropertyContainer.h"
22 #include "base/Preferences.h" 22 #include "base/Preferences.h"
23 #include "widgets/TipDialog.h" 23 #include "widgets/TipDialog.h"
24 #include "rdf/SimpleSPARQLQuery.h"
25 24
26 #include <QMetaType> 25 #include <QMetaType>
27 #include <QApplication> 26 #include <QApplication>
28 #include <QDesktopWidget> 27 #include <QDesktopWidget>
29 #include <QMessageBox> 28 #include <QMessageBox>
235 QApplication::setOrganizationName("sonic-visualiser"); 234 QApplication::setOrganizationName("sonic-visualiser");
236 QApplication::setOrganizationDomain("sonicvisualiser.org"); 235 QApplication::setOrganizationDomain("sonicvisualiser.org");
237 QApplication::setApplicationName(QApplication::tr("Sonic Visualiser")); 236 QApplication::setApplicationName(QApplication::tr("Sonic Visualiser"));
238 237
239 QPixmap pixmap(":/icons/sv-splash.png"); 238 QPixmap pixmap(":/icons/sv-splash.png");
240 QSplashScreen splash(pixmap); 239 QSplashScreen *splash = 0;
241 240
242 QSettings settings; 241 QSettings settings;
243 242
244 settings.beginGroup("Preferences"); 243 settings.beginGroup("Preferences");
245 if (settings.value("show-splash", true).toBool()) { 244 if (settings.value("show-splash", true).toBool()) {
246 splash.show(); 245 splash = new QSplashScreen(pixmap);
247 QTimer::singleShot(5000, &splash, SLOT(hide())); 246 splash->show();
247 QTimer::singleShot(5000, splash, SLOT(hide()));
248 application.processEvents(); 248 application.processEvents();
249 } 249 }
250 settings.endGroup(); 250 settings.endGroup();
251 251
252 settings.beginGroup("RDF"); 252 settings.beginGroup("RDF");
254 QStringList list; 254 QStringList list;
255 list << "http://www.vamp-plugins.org/rdf/plugins/index.txt"; 255 list << "http://www.vamp-plugins.org/rdf/plugins/index.txt";
256 settings.setValue("rdf-indices", list); 256 settings.setValue("rdf-indices", list);
257 } 257 }
258 settings.endGroup(); 258 settings.endGroup();
259
260 SimpleSPARQLQuery::setImplementationPreference
261 (SimpleSPARQLQuery::UseDatastore);
262 // (SimpleSPARQLQuery::UseDirectParser);
263 259
264 QIcon icon; 260 QIcon icon;
265 int sizes[] = { 16, 22, 24, 32, 48, 64, 128 }; 261 int sizes[] = { 16, 22, 24, 32, 48, 64, 128 };
266 for (int i = 0; i < sizeof(sizes)/sizeof(sizes[0]); ++i) { 262 for (int i = 0; i < sizeof(sizes)/sizeof(sizes[0]); ++i) {
267 icon.addFile(QString(":icons/sv-%1x%2.png").arg(sizes[i]).arg(sizes[i])); 263 icon.addFile(QString(":icons/sv-%1x%2.png").arg(sizes[i]).arg(sizes[i]));
301 qRegisterMetaType<size_t>("size_t"); 297 qRegisterMetaType<size_t>("size_t");
302 qRegisterMetaType<PropertyContainer::PropertyName>("PropertyContainer::PropertyName"); 298 qRegisterMetaType<PropertyContainer::PropertyName>("PropertyContainer::PropertyName");
303 299
304 MainWindow *gui = new MainWindow(audioOutput, oscSupport); 300 MainWindow *gui = new MainWindow(audioOutput, oscSupport);
305 application.setMainWindow(gui); 301 application.setMainWindow(gui);
306 QObject::connect(gui, SIGNAL(hideSplash()), &splash, SLOT(hide())); 302 if (splash) {
303 QObject::connect(gui, SIGNAL(hideSplash()), splash, SLOT(hide()));
304 }
307 305
308 QDesktopWidget *desktop = QApplication::desktop(); 306 QDesktopWidget *desktop = QApplication::desktop();
309 QRect available = desktop->availableGeometry(); 307 QRect available = desktop->availableGeometry();
310 308
311 int width = available.width() * 2 / 3; 309 int width = available.width() * 2 / 3;
369 status = gui->open(path, MainWindow::CreateAdditionalModel); 367 status = gui->open(path, MainWindow::CreateAdditionalModel);
370 } 368 }
371 } 369 }
372 } 370 }
373 if (status == MainWindow::FileOpenFailed) { 371 if (status == MainWindow::FileOpenFailed) {
374 splash.hide(); 372 if (splash) splash->hide();
375 QMessageBox::critical 373 QMessageBox::critical
376 (gui, QMessageBox::tr("Failed to open file"), 374 (gui, QMessageBox::tr("Failed to open file"),
377 QMessageBox::tr("File or URL \"%1\" could not be opened").arg(path)); 375 QMessageBox::tr("File or URL \"%1\" could not be opened").arg(path));
378 } else if (status == MainWindow::FileOpenWrongMode) { 376 } else if (status == MainWindow::FileOpenWrongMode) {
379 splash.hide(); 377 if (splash) splash->hide();
380 QMessageBox::critical 378 QMessageBox::critical
381 (gui, QMessageBox::tr("Failed to open file"), 379 (gui, QMessageBox::tr("Failed to open file"),
382 QMessageBox::tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data")); 380 QMessageBox::tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
383 } 381 }
384 } 382 }
396 } 394 }
397 #endif 395 #endif
398 settings.endGroup(); 396 settings.endGroup();
399 #endif 397 #endif
400 398
401 splash.finish(gui); 399 if (splash) splash->finish(gui);
400 delete splash;
402 401
403 /* 402 /*
404 TipDialog tipDialog; 403 TipDialog tipDialog;
405 if (tipDialog.isOK()) { 404 if (tipDialog.isOK()) {
406 tipDialog.exec(); 405 tipDialog.exec();