changeset 370:ca9f27734349 macness

svitunes: retrieve the genre metadata, as well as the path
author Dan Stowell <dan.stowell@eecs.qmul.ac.uk>
date Fri, 15 Oct 2010 11:07:11 +0100
parents 8b3038e55d50
children 012fdb1d19bf 909cf273bed1
files main/MainWindow.cpp main/main.cpp osx/svitunes.h osx/svitunes.mm
diffstat 4 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Tue Oct 12 16:02:02 2010 +0100
+++ b/main/MainWindow.cpp	Fri Oct 15 11:07:11 2010 +0100
@@ -2165,14 +2165,17 @@
 void
 MainWindow::importITunesAudio()
 {
-    QString path = iTunesNowPlayingPath();
+    QStringList nowPlaying = iTunesNowPlaying();
+    QString path = nowPlaying.at(0);
+    QString genre = (nowPlaying.size() > 1) ? nowPlaying.at(1) : "";
+    std::cerr << "MainWindow::importITunesAudio(): genre is " << genre.toStdString() << std::endl;
 
     if (path != "") {
-	if (openAudio(path, ReplaceMainModel) == FileOpenFailed) {
+    if (openAudio(path, ReplaceMainModel) == FileOpenFailed) {
             emit hideSplash();
-	    QMessageBox::critical(this, tr("Failed to open file"),
-				  tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
-	}
+        QMessageBox::critical(this, tr("Failed to open file"),
+                  tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
+    }
     }
 }
 #endif
--- a/main/main.cpp	Tue Oct 12 16:02:02 2010 +0100
+++ b/main/main.cpp	Fri Oct 15 11:07:11 2010 +0100
@@ -220,7 +220,8 @@
     void setupDockMenu() {
         std::cerr << "SV adding mac dock menu" << std::endl;
         QMenu *dockMenu = new QMenu();
-        QString theText = iTunesNowPlayingPath();
+        QStringList nowPlaying = iTunesNowPlaying();
+        QString theText = nowPlaying.at(0);
         if (theText == ""){
             theText = "[[No current track in iTunes]]";
         }
--- a/osx/svitunes.h	Tue Oct 12 16:02:02 2010 +0100
+++ b/osx/svitunes.h	Fri Oct 15 11:07:11 2010 +0100
@@ -17,7 +17,8 @@
 
 //LATER: bool iTunesRunning();
 
-QString iTunesNowPlayingPath();
+// Returns a list containing [posixpath, genre]
+QStringList iTunesNowPlaying();
 
 //LATER: QStringList iTunesSelectedPaths();
 
--- a/osx/svitunes.mm	Tue Oct 12 16:02:02 2010 +0100
+++ b/osx/svitunes.mm	Fri Oct 15 11:07:11 2010 +0100
@@ -32,7 +32,7 @@
     return result;
 }
 
-QString iTunesNowPlayingPath(){
+QStringList iTunesNowPlaying(){
     NSDictionary *errorDict;
     NSAppleScript *scriptObject = [[NSAppleScript alloc]    initWithSource:@" \
 tell application \"System Events\" to set iTunesIsRunning to (name of processes) contains \"iTunes\" \n\
@@ -50,7 +50,7 @@
         end if \n\
     end if \n\
     \
-    return the POSIX path of (location of aTrack as text) \n\
+    return the POSIX path of (location of aTrack as text) & \"\n\" & (genre of aTrack) \n\
 end tell \n\
 "
     ];
@@ -73,5 +73,5 @@
     QString resultString = qt_mac_NSStringToQString(nsResultString);
     
     [scriptObject release];
-    return resultString;
+    return resultString.split(QChar('\n'));
 }