# HG changeset patch # User Dan Stowell # Date 1294758693 0 # Node ID 61111a6a229f01e18c31056a3d670be514b117b4 # Parent 5c4943eae1663212e3b08378980ffc46412043ae# Parent 174ca518546fb55d4a8c8ec1d4a710303c3c5c56 Merge Dan's initial macness improvements (rev 174ca518546f) into default branch diff -r 5c4943eae166 -r 61111a6a229f main/main.cpp --- a/main/main.cpp Mon Oct 25 11:15:47 2010 +0200 +++ b/main/main.cpp Tue Jan 11 15:11:33 2011 +0000 @@ -36,6 +36,7 @@ #include #include #include +#include #include "../version.h" @@ -188,7 +189,10 @@ public: SVApplication(int &argc, char **argv) : QApplication(argc, argv), - m_mainWindow(0) { } + m_readyForFiles(false), + m_filepathQueue(QStringList()), + m_mainWindow(0) + { } virtual ~SVApplication() { } void setMainWindow(MainWindow *mw) { m_mainWindow = mw; } @@ -202,8 +206,15 @@ if (!success) manager.cancel(); } + void handleFilepathArgument(QString path, QSplashScreen *splash); + + bool m_readyForFiles; + QStringList m_filepathQueue; + protected: MainWindow *m_mainWindow; + bool event(QEvent *); + }; int @@ -347,59 +358,21 @@ // complete. As a lazy hack, apply it explicitly from here gui->preferenceChanged("Property Box Layout"); - bool haveSession = false; - bool haveMainModel = false; - bool havePriorCommandLineModel = false; + application.m_readyForFiles = true; // Ready to receive files from e.g. Apple Events for (QStringList::iterator i = args.begin(); i != args.end(); ++i) { - MainWindow::FileOpenStatus status = MainWindow::FileOpenFailed; - if (i == args.begin()) continue; if (i->startsWith('-')) continue; QString path = *i; - if (path.endsWith("sv")) { - if (!haveSession) { - status = gui->openSessionFile(path); - if (status == MainWindow::FileOpenSucceeded) { - haveSession = true; - haveMainModel = true; - } - } else { - std::cerr << "WARNING: Ignoring additional session file argument \"" << path.toStdString() << "\"" << std::endl; - status = MainWindow::FileOpenSucceeded; - } - } - if (status != MainWindow::FileOpenSucceeded) { - if (!haveMainModel) { - status = gui->open(path, MainWindow::ReplaceMainModel); - if (status == MainWindow::FileOpenSucceeded) { - haveMainModel = true; - } - } else { - if (haveSession && !havePriorCommandLineModel) { - status = gui->open(path, MainWindow::AskUser); - if (status == MainWindow::FileOpenSucceeded) { - havePriorCommandLineModel = true; - } - } else { - status = gui->open(path, MainWindow::CreateAdditionalModel); - } - } - } - if (status == MainWindow::FileOpenFailed) { - if (splash) splash->hide(); - QMessageBox::critical - (gui, QMessageBox::tr("Failed to open file"), - QMessageBox::tr("File or URL \"%1\" could not be opened").arg(path)); - } else if (status == MainWindow::FileOpenWrongMode) { - if (splash) splash->hide(); - QMessageBox::critical - (gui, QMessageBox::tr("Failed to open file"), - QMessageBox::tr("Audio required

Please load at least one audio file before importing annotation data")); - } + application.handleFilepathArgument(path, splash); + } + + for (QStringList::iterator i = application.m_filepathQueue.begin(); i != application.m_filepathQueue.end(); ++i) { + QString path = *i; + application.handleFilepathArgument(path, splash); } #ifdef HAVE_FFTW3F @@ -457,3 +430,68 @@ return rv; } + +bool SVApplication::event(QEvent *event){ + QString thePath; + switch (event->type()) { + case QEvent::FileOpen: + thePath = static_cast(event)->file(); + if(m_readyForFiles) + handleFilepathArgument(thePath, NULL); + else + m_filepathQueue.append(thePath); + return true; + default: + return QApplication::event(event); + } +} + +/** Application-global handler for filepaths passed in, e.g. as command-line arguments or apple events */ +void SVApplication::handleFilepathArgument(QString path, QSplashScreen *splash){ + static bool haveSession = false; + static bool haveMainModel = false; + static bool havePriorCommandLineModel = false; + + MainWindow::FileOpenStatus status = MainWindow::FileOpenFailed; + + if (path.endsWith("sv")) { + if (!haveSession) { + status = m_mainWindow->openSessionFile(path); + if (status == MainWindow::FileOpenSucceeded) { + haveSession = true; + haveMainModel = true; + } + } else { + std::cerr << "WARNING: Ignoring additional session file argument \"" << path.toStdString() << "\"" << std::endl; + status = MainWindow::FileOpenSucceeded; + } + } + if (status != MainWindow::FileOpenSucceeded) { + if (!haveMainModel) { + status = m_mainWindow->open(path, MainWindow::ReplaceMainModel); + if (status == MainWindow::FileOpenSucceeded) { + haveMainModel = true; + } + } else { + if (haveSession && !havePriorCommandLineModel) { + status = m_mainWindow->open(path, MainWindow::AskUser); + if (status == MainWindow::FileOpenSucceeded) { + havePriorCommandLineModel = true; + } + } else { + status = m_mainWindow->open(path, MainWindow::CreateAdditionalModel); + } + } + } + if (status == MainWindow::FileOpenFailed) { + if (splash) splash->hide(); + QMessageBox::critical + (m_mainWindow, QMessageBox::tr("Failed to open file"), + QMessageBox::tr("File or URL \"%1\" could not be opened").arg(path)); + } else if (status == MainWindow::FileOpenWrongMode) { + if (splash) splash->hide(); + QMessageBox::critical + (m_mainWindow, QMessageBox::tr("Failed to open file"), + QMessageBox::tr("Audio required

Please load at least one audio file before importing annotation data")); + } +} diff -r 5c4943eae166 -r 61111a6a229f osx/Info.plist --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/osx/Info.plist Tue Jan 11 15:11:33 2011 +0000 @@ -0,0 +1,67 @@ + + + + + CFBundleIconFile + sv-macicon.icns + CFBundlePackageType + APPL + CFBundleGetInfoString + Created by Qt/QMake + CFBundleSignature + SNCV + CFBundleExecutable + Sonic Visualiser + CFBundleIdentifier + org.isophonics.SonicVisualiser + CFBundleDocumentTypes + + + + CFBundleTypeExtensions + + sv + + + CFBundleTypeMIMETypes + + application/x-sonic-visualiser-project + + CFBundleTypeName + Sonic Visualiser Project + CFBundleTypeOSTypes + + **** + + CFBundleTypeRole + Editor + LSHandlerRank + Owner + LSIsAppleDefaultForType + + + + + + CFBundleTypeExtensions + + mp3 + + CFBundleTypeMIMETypes + + audio/mpeg + + CFBundleTypeName + MP3 Audio + CFBundleTypeRole + Viewer + LSIsAppleDefaultForType + + LSHandlerRank + Alternate + + + + diff -r 5c4943eae166 -r 61111a6a229f sonic-visualiser.pro --- a/sonic-visualiser.pro Mon Oct 25 11:15:47 2010 +0200 +++ b/sonic-visualiser.pro Tue Jan 11 15:11:33 2011 +0000 @@ -42,4 +42,6 @@ main/PreferencesDialog.cpp \ main/Surveyer.cpp +# for mac integration +QMAKE_INFO_PLIST = osx/Info.plist