1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ITunesInterface.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfour-char-constants"
#import <Sluift/iTunes.h>
#pragma clang diagnostic pop
#include <ScriptingBridge/ScriptingBridge.h>
#include <memory>
#include <boost/optional.hpp>
#include <SwifTools/Cocoa/CocoaUtil.h>
using namespace Swift;
struct ITunesInterface::Private {
Private() : iTunes(nil) {
}
iTunesApplication* iTunes;
};
ITunesInterface::ITunesInterface() : p(new Private()) {
}
ITunesInterface::~ITunesInterface() {
}
boost::optional<ITunesInterface::Track> ITunesInterface::getCurrentTrack() const {
if (!haveApplication()) {
return boost::optional<ITunesInterface::Track>();
}
iTunesTrack* currentTrack = p->iTunes.currentTrack;
if (!currentTrack) {
return boost::optional<ITunesInterface::Track>();
}
ITunesInterface::Track result;
result.name = ns2StdString(currentTrack.name);
result.artist = ns2StdString(currentTrack.artist);
result.album = ns2StdString(currentTrack.album);
result.trackNumber = currentTrack.trackNumber;
result.duration = currentTrack.duration;
result.rating = currentTrack.rating;
return result;
}
bool ITunesInterface::haveApplication() const {
if (!p->iTunes) {
p->iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
}
return p->iTunes != nil && [p->iTunes isRunning];
}
|