changeset 381:fad5611ef9db macness

Encapsulate itunes-remote functionality into class ITunesSVRemote. Provides context for playback sync etc
author Dan Stowell <dan.stowell@eecs.qmul.ac.uk>
date Mon, 18 Oct 2010 13:59:08 +0100
parents 7298621f1192
children abb9c3dedec2
files main/MainWindow.cpp main/MainWindow.h osx/svitunes.h osx/svitunes.mm sonic-visualiser.pro
diffstat 5 files changed, 34 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Mon Oct 18 13:29:48 2010 +0100
+++ b/main/MainWindow.cpp	Mon Oct 18 13:59:08 2010 +0100
@@ -79,9 +79,6 @@
 #include "widgets/ModelDataTableDialog.h"
 #include "rdf/PluginRDFIndexer.h"
 #include "rdf/RDFExporter.h"
-#ifdef Q_WS_MAC
-	#include "osx/svitunes.h"
-#endif
 
 #include "Surveyer.h"
 #include "framework/VersionTester.h"
@@ -160,7 +157,8 @@
     m_preferencesDialog(0),
     m_layerTreeDialog(0),
     m_activityLog(new ActivityLog()),
-    m_keyReference(new KeyReference())
+    m_keyReference(new KeyReference()),
+    m_iTunes(new ITunesSVRemote())
 {
     Profiler profiler("MainWindow::MainWindow");
 
@@ -2165,7 +2163,7 @@
 void
 MainWindow::importITunesAudio()
 {
-    QStringList nowPlaying = iTunesNowPlaying();
+    QStringList nowPlaying = m_iTunes->getNowPlaying();
     QString path = nowPlaying.at(0);
     QString genre = (nowPlaying.size() > 1) ? nowPlaying.at(1) : "";
     std::cerr << "MainWindow::importITunesAudio(): genre is " << genre.toStdString() << std::endl;
--- a/main/MainWindow.h	Mon Oct 18 13:29:48 2010 +0100
+++ b/main/MainWindow.h	Mon Oct 18 13:59:08 2010 +0100
@@ -33,6 +33,9 @@
 #include "data/fileio/FileSource.h"
 #include "widgets/LayerTreeDialog.h"
 #include <map>
+#ifdef Q_WS_MAC
+	#include "osx/svitunes.h"
+#endif
 
 class Document;
 class PaneStack;
@@ -282,6 +285,10 @@
     virtual bool shouldCreateNewSessionForRDFAudio(bool *cancel);
     
     virtual void connectLayerEditDialog(ModelDataTableDialog *);
+
+#ifdef Q_WS_MAC
+    ITunesSVRemote *m_iTunes;
+#endif
 };
 
 
--- a/osx/svitunes.h	Mon Oct 18 13:29:48 2010 +0100
+++ b/osx/svitunes.h	Mon Oct 18 13:59:08 2010 +0100
@@ -18,11 +18,28 @@
 #include <QString>
 #include <QStringList>
 
-//LATER: bool iTunesRunning();
+//#import <Foundation/Foundation.h>
 
-// Returns a list containing [posixpath, genre]
-QStringList iTunesNowPlaying();
-
-//LATER: QStringList iTunesSelectedPaths();
+/**
+* Class to handle communication with a running iTunes program on the system.
+* Only implemented for Mac at present, since using applescript communication.
+* Pseudo-singleton - one instance expected to be owned by SVApplication.
+*/
+class ITunesSVRemote : QObject
+{
+    Q_OBJECT
+    
+    public:
+        
+        //LATER: bool iTunesRunning();
+    
+        // Returns a list containing [posixpath, genre]
+        QStringList getNowPlaying();
+    
+        //LATER: QStringList iTunesSelectedPaths();
+    
+//    private:
+//        QString qt_mac_NSStringToQString(const NSString *nsstr);
+};
 
 #endif
--- a/osx/svitunes.mm	Mon Oct 18 13:29:48 2010 +0100
+++ b/osx/svitunes.mm	Mon Oct 18 13:59:08 2010 +0100
@@ -32,7 +32,7 @@
     return result;
 }
 
-QStringList iTunesNowPlaying(){
+QStringList ITunesSVRemote::getNowPlaying(){
     NSDictionary *errorDict;
     NSAppleScript *scriptObject = [[NSAppleScript alloc]    initWithSource:@" \
 tell application \"System Events\" to set iTunesIsRunning to (name of processes) contains \"iTunes\" \n\
--- a/sonic-visualiser.pro	Mon Oct 18 13:29:48 2010 +0100
+++ b/sonic-visualiser.pro	Mon Oct 18 13:59:08 2010 +0100
@@ -43,6 +43,7 @@
 mac {
     QMAKE_INFO_PLIST = osx/Info.plist
     
+    HEADERS += osx/svitunes.h
     OBJECTIVE_SOURCES += osx/svitunes.mm
 
     LIBS += -framework Foundation