# HG changeset patch # User Dan Stowell # Date 1287406748 -3600 # Node ID fad5611ef9db2f98e91c1989c950338a37c2186a # Parent 7298621f11923ffc2303343d47ebf285f39ca84d Encapsulate itunes-remote functionality into class ITunesSVRemote. Provides context for playback sync etc diff -r 7298621f1192 -r fad5611ef9db main/MainWindow.cpp --- 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; diff -r 7298621f1192 -r fad5611ef9db main/MainWindow.h --- 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 +#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 }; diff -r 7298621f1192 -r fad5611ef9db osx/svitunes.h --- 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 #include -//LATER: bool iTunesRunning(); +//#import -// 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 diff -r 7298621f1192 -r fad5611ef9db osx/svitunes.mm --- 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\ diff -r 7298621f1192 -r fad5611ef9db sonic-visualiser.pro --- 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