changeset 389:61111a6a229f

Merge Dan's initial macness improvements (rev 174ca518546f) into default branch
author Dan Stowell <dan.stowell@eecs.qmul.ac.uk>
date Tue, 11 Jan 2011 15:11:33 +0000
parents 5c4943eae166 (current diff) 174ca518546f (diff)
children 00a5d0029e95
files main/main.cpp sonic-visualiser.pro
diffstat 3 files changed, 153 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- 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 <QSplashScreen>
 #include <QTimer>
 #include <QPainter>
+#include <QFileOpenEvent>
 
 #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("<b>Audio required</b><p>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<QFileOpenEvent *>(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("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
+    }
+}
--- /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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+	<key>CFBundleIconFile</key>
+	<string>sv-macicon.icns</string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+    <key>CFBundleGetInfoString</key>
+	<string>Created by Qt/QMake</string>
+	<key>CFBundleSignature</key>
+	<string>SNCV</string>
+	<key>CFBundleExecutable</key>
+	<string>Sonic Visualiser</string>
+	<key>CFBundleIdentifier</key>
+	<string>org.isophonics.SonicVisualiser</string>
+	<key>CFBundleDocumentTypes</key>
+	<array>
+		<!-- we are an 'editor' of SV files -->
+		<dict>
+			<key>CFBundleTypeExtensions</key>
+			<array>
+				<string>sv</string>
+			</array>
+			<!-- TODO
+			<key>CFBundleTypeIconFile</key>
+			<string>SVProject.icns</string> -->
+			<key>CFBundleTypeMIMETypes</key>
+			<array>
+				<string>application/x-sonic-visualiser-project</string>
+			</array>
+			<key>CFBundleTypeName</key>
+			<string>Sonic Visualiser Project</string>
+			<key>CFBundleTypeOSTypes</key>
+			<array>
+				<string>****</string>
+			</array>
+			<key>CFBundleTypeRole</key>
+			<string>Editor</string>
+			<key>LSHandlerRank</key>
+			<string>Owner</string>
+			<key>LSIsAppleDefaultForType</key>
+			<true/>
+		</dict>
+		
+		<!-- we are a 'viewer' of general audio files -->
+		<dict>
+			<key>CFBundleTypeExtensions</key>
+			<array>
+				<string>mp3</string>
+			</array>
+			<key>CFBundleTypeMIMETypes</key>
+			<array>
+				<string>audio/mpeg</string>
+			</array>
+			<key>CFBundleTypeName</key>
+			<string>MP3 Audio</string>
+			<key>CFBundleTypeRole</key>
+			<string>Viewer</string>
+			<key>LSIsAppleDefaultForType</key>
+			<false/>
+			<key>LSHandlerRank</key>
+			<string>Alternate</string>
+		</dict>
+	</array>
+  </dict>
+</plist>
--- 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