From 62b8074a3692107274ea9a56e1cea8ed8f476ccb Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 2 May 2009 01:14:31 -0400 Subject: Initial commit - version 0.2 --- CreateArchive.sh | 4 +++ main.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ script.spec | 15 +++++++++++ 3 files changed, 100 insertions(+) create mode 100755 CreateArchive.sh create mode 100644 main.js create mode 100644 script.spec 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 diff --git a/main.js b/main.js new file mode 100644 index 0000000..3e27b6e --- /dev/null +++ b/main.js @@ -0,0 +1,81 @@ +/* + Copyright (C) 2009 Jason A. Donenfeld . 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 = "

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 -- cgit v1.2.3-59-g8ed1b