diff options
author | 2009-05-02 01:14:31 -0400 | |
---|---|---|
committer | 2009-05-02 01:14:31 -0400 | |
commit | 62b8074a3692107274ea9a56e1cea8ed8f476ccb (patch) | |
tree | b1deba8140082b1bebbcba31fc547c058fff6e44 | |
download | PidginSong-master.tar.xz PidginSong-master.zip |
-rwxr-xr-x | CreateArchive.sh | 4 | ||||
-rw-r--r-- | main.js | 81 | ||||
-rw-r--r-- | script.spec | 15 |
3 files changed, 100 insertions, 0 deletions
diff --git a/CreateArchive.sh b/CreateArchive.sh new file mode 100755 index 0000000..4cd5670 --- /dev/null +++ b/CreateArchive.sh @@ -0,0 +1,4 @@ +mkdir PidginSong +cp main.js script.spec PidginSong +tar -czf PidginSong.amarokscript.tar.gz PidginSong/* +rm -r PidginSong
\ No newline at end of file @@ -0,0 +1,81 @@ +/* + Copyright (C) 2009 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. +*/ + +Importer.loadQtBinding("qt.core"); + +function modifyAllInfos(addition) +{ + var accounts = getAccounts(); + for(var i = 0; i < accounts.length; i++) + { + setInfo(accounts[i], modifyInfo(getInfo(accounts[i]), addition)); + } +} +function modifyInfo(info, addition) +{ + var line = "<br><br>Currently Playing: "; + var index = info.indexOf(line); + if(index != -1) + { + info = info.substring(0, index); + } + return info.replace("\n", "") + line + addition; +} +function getInfo(account) +{ + return executeCommand("purple-remote", ["PurpleAccountGetUserInfo(" + account + ")"]); +} +function setInfo(account, info) +{ + info = "string:" + info; + executeCommand("purple-send", ["PurpleAccountSetUserInfo", "int32:" + account, info]); + executeCommand("purple-send", ["ServSetInfo", "int32:" + executeCommand("purple-remote", ["PurpleAccountGetConnection(" + account + ")"]), info]); +} +function getAccounts() +{ + var commandOutput = executeCommand("purple-remote", ["PurpleAccountsGetAllActive()"]); + var pattern = /Int32\((\d+)\)/g; + var match; + var accounts = new Array(); + while((match = pattern.exec(commandOutput)) != null) + { + accounts.push(match[1]); + } + return accounts; +} +function executeCommand(command, args) +{ + var process = new QProcess(); + process.start(command, args); + if(process.waitForFinished()) + { + return new QTextStream(process).readAll(); + } + return false; +} + +function onTrackPlayPause(paused) +{ + if(paused) + { + onTrackFinished(); + } + else + { + onTrackChange(); + } +} +function onTrackChange() +{ + var currentTrack = Amarok.Engine.currentTrack(); + modifyAllInfos(currentTrack.artist + " - " + currentTrack.title); +} +function onTrackFinished() +{ + modifyAllInfos("(none)"); +} + +Amarok.Engine.trackPlayPause.connect(onTrackPlayPause); +Amarok.Engine.trackChanged.connect(onTrackChange); +Amarok.Engine.trackFinished.connect(onTrackFinished); diff --git a/script.spec b/script.spec new file mode 100644 index 0000000..265d5c3 --- /dev/null +++ b/script.spec @@ -0,0 +1,15 @@ +[Desktop Entry] +Icon=view-pim-journal +Type=script +ServiceTypes=KPluginInfo + +Name=PidginSong +Comment=Publishes the currently playing song at the bottom of Pidgin profiles + +X-KDE-PluginInfo-Author=Jason A. Donenfeld +X-KDE-PluginInfo-Email=Jason@zx2c4.com +X-KDE-PluginInfo-Name=PidginSong +X-KDE-PluginInfo-Version=0.2 +X-KDE-PluginInfo-Category=Generic +X-KDE-PluginInfo-Depends=Amarok2.0 +X-KDE-PluginInfo-EnabledByDefault=false |