iTunesPlugin now accepts commands as a !RainmeterPluginBang (i.e. you can use !RainmeterPluginBang "iTunesMeasure NextTrack" instead of creating an own measure for each command).

This commit is contained in:
Birunthan Mohanathas 2010-12-17 11:15:04 +00:00
parent b9ae3a31d8
commit 6809d5bb4d
2 changed files with 785 additions and 696 deletions

View File

@ -12,7 +12,7 @@
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,1,0,0 FILEVERSION 0,2,0,0
PRODUCTVERSION PRODUCTVER PRODUCTVERSION PRODUCTVER
FILEFLAGSMASK 0x17L FILEFLAGSMASK 0x17L
#ifdef _DEBUG #ifdef _DEBUG
@ -29,7 +29,7 @@ BEGIN
BLOCK "040904E4" BLOCK "040904E4"
BEGIN BEGIN
VALUE "FileDescription", "iTunes Plugin for Rainmeter" VALUE "FileDescription", "iTunes Plugin for Rainmeter"
VALUE "FileVersion", "1.1.0.0" VALUE "FileVersion", "0.2.0.0"
VALUE "InternalName", "PluginiTunes" VALUE "InternalName", "PluginiTunes"
VALUE "LegalCopyright", "Copyright (C) 2010 - Elestel" VALUE "LegalCopyright", "Copyright (C) 2010 - Elestel"
VALUE "OriginalFilename", "PluginiTunes.dll" VALUE "OriginalFilename", "PluginiTunes.dll"

View File

@ -31,13 +31,13 @@ const int VOLUME_STEP = 5;
/* The exported functions */ /* The exported functions */
extern "C" extern "C"
{ {
__declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id); __declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id);
__declspec( dllexport ) void Finalize(HMODULE instance, UINT id); __declspec( dllexport ) void Finalize(HMODULE instance, UINT id);
__declspec( dllexport ) LPCTSTR GetString(UINT id, UINT flags); __declspec( dllexport ) LPCTSTR GetString(UINT id, UINT flags);
__declspec( dllexport ) UINT Update(UINT id); __declspec( dllexport ) UINT Update(UINT id);
__declspec( dllexport ) UINT GetPluginVersion(); __declspec( dllexport ) UINT GetPluginVersion();
__declspec( dllexport ) LPCTSTR GetPluginAuthor(); __declspec( dllexport ) LPCTSTR GetPluginAuthor();
__declspec( dllexport ) void ExecuteBang(LPCTSTR args, UINT id); __declspec( dllexport ) void ExecuteBang(LPCTSTR args, UINT id);
} }
enum COMMAND_TYPE enum COMMAND_TYPE
@ -200,7 +200,7 @@ const static wchar_t* CommandName[COMMAND_COUNT] =
L"UpdatePodcastFeeds", // COMMAND_UPDATEPODCASTFEEDS L"UpdatePodcastFeeds", // COMMAND_UPDATEPODCASTFEEDS
L"CreateFolder", // COMMAND_CREATEFOLDER L"CreateFolder", // COMMAND_CREATEFOLDER
L"CreateFolderInSource", // COMMAND_CREATEFOLDERINSOURCE L"CreateFolderInSource", // COMMAND_CREATEFOLDERINSOURCE
L"GetITObjectPersistentIDs", // COMMAND_GETITOBJECTPERSISTENTIDS L"GetITObjectPersistentIDs",// COMMAND_GETITOBJECTPERSISTENTIDS
// Collection Properties // Collection Properties
//TODO: Sources //TODO: Sources
//TODO: Encoders //TODO: Encoders
@ -214,7 +214,7 @@ const static wchar_t* CommandName[COMMAND_COUNT] =
L"SetMute", // COMMAND_SETMUTE L"SetMute", // COMMAND_SETMUTE
// Player Properties // Player Properties
L"GetPlayerState", // COMMAND_GETPLAYERSTATE L"GetPlayerState", // COMMAND_GETPLAYERSTATE
L"GetPlayerPositionPercent", // COMMAND_GETPLAYERPOSITIONPERCENT L"GetPlayerPositionPercent",// COMMAND_GETPLAYERPOSITIONPERCENT
L"GetPlayerPosition", // COMMAND_GETPLAYERPOSITION L"GetPlayerPosition", // COMMAND_GETPLAYERPOSITION
L"SetPlayerPosition", // COMMAND_SETPLAYERPOSITION L"SetPlayerPosition", // COMMAND_SETPLAYERPOSITION
// Encoder Properties // Encoder Properties
@ -456,17 +456,17 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
if (SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER))) if (SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER)))
{ {
InstanceCreated = true; InstanceCreated = true;
LSLog(LOG_DEBUG, L"Rainmeter", L"iTunesApp initialized successfully."); LSLog(LOG_DEBUG, L"Rainmeter", L"iTunesPlugin: iTunesApp initialized successfully.");
initEventHandler(); initEventHandler();
} }
else else
{ {
LSLog(LOG_DEBUG, L"Rainmeter", L"Unable to create the iTunesApp instance."); LSLog(LOG_DEBUG, L"Rainmeter", L"iTunesPlugin: Unable to create the iTunesApp instance.");
} }
} }
else else
{ {
LSLog(LOG_DEBUG, L"Rainmeter", L"Unable to find the iTunes window."); LSLog(LOG_DEBUG, L"Rainmeter", L"iTunesPlugin: Unable to find the iTunes window.");
} }
const wchar_t* type = ReadConfigString(section, L"Command", L""); const wchar_t* type = ReadConfigString(section, L"Command", L"");
@ -501,12 +501,12 @@ UINT Update(UINT id)
if (!iTunesAboutToPromptUserToQuit && SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER))) if (!iTunesAboutToPromptUserToQuit && SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER)))
{ {
InstanceCreated = true; InstanceCreated = true;
LSLog(LOG_DEBUG, L"Rainmeter", L"iTunesApp initialized successfully."); LSLog(LOG_DEBUG, L"Rainmeter", L"iTunesPlugin: iTunesApp initialized successfully.");
initEventHandler(); initEventHandler();
} }
else else
{ {
LSLog(LOG_DEBUG, L"Rainmeter", L"Unable to create the iTunesApp instance."); LSLog(LOG_DEBUG, L"Rainmeter", L"iTunesPlugin: Unable to create the iTunesApp instance.");
return 0; return 0;
} }
} }
@ -693,9 +693,98 @@ void ExecuteBang(LPCTSTR args, UINT id)
return; return;
} }
CCommandIdMap::const_iterator it = CommandIdMap.find(id); COMMAND_TYPE command;
COMMAND_TYPE command = (it != CommandIdMap.end()) ? it->second : COMMAND_COUNT;
if (wcslen(args) == 0)
{
CCommandIdMap::const_iterator it = CommandIdMap.find(id);
command = (it != CommandIdMap.end()) ? it->second : COMMAND_COUNT;
}
else
{
if (_wcsicmp(args, L"Backtrack") == 0)
{
command = COMMAND_BACKTRACK;
}
else if (_wcsicmp(args, L"FastForward") == 0)
{
command = COMMAND_FASTFORWARD;
}
else if (_wcsicmp(args, L"NextTrack") == 0)
{
command = COMMAND_NEXTTRACK;
}
else if (_wcsicmp(args, L"Pause") == 0)
{
command = COMMAND_PAUSE;
}
else if (_wcsicmp(args, L"PlayPause") == 0)
{
command = COMMAND_PLAYPAUSE;
}
else if (_wcsicmp(args, L"Power") == 0)
{
command = COMMAND_POWER;
}
else if (_wcsicmp(args, L"PreviousTrack") == 0)
{
command = COMMAND_PREVIOUSTRACK;
}
else if (_wcsicmp(args, L"Resume") == 0)
{
command = COMMAND_RESUME;
}
else if (_wcsicmp(args, L"Rewind") == 0)
{
command = COMMAND_REWIND;
}
else if (_wcsicmp(args, L"Stop") == 0)
{
command = COMMAND_STOP;
}
else if (_wcsicmp(args, L"SoundVolumeUp") == 0)
{
command = COMMAND_SOUNDVOLUMEUP;
}
else if (_wcsicmp(args, L"SoundVolumeDown") == 0)
{
command = COMMAND_SOUNDVOLUMEDOWN;
}
else if (_wcsicmp(args, L"ToggleiTunes") == 0)
{
command = COMMAND_TOGGLEITUNES;
}
else if (_wcsicmp(args, L"ToggleVisuals") == 0)
{
command = COMMAND_TOGGLEVISUALS;
}
else if (_wcsicmp(args, L"UpdateiPod") == 0)
{
command = COMMAND_UPDATEIPOD;
}
else if (_wcsicmp(args, L"UpdatePodcastFeeds") == 0)
{
command = COMMAND_UPDATEPODCASTFEEDS;
}
else if (_wcsicmp(args, L"GotoMusicStoreHomePage") == 0)
{
command = COMMAND_GOTOMUSICSTOREHOMEPAGE;
}
else if (_wcsicmp(args, L"Quit") == 0)
{
command = COMMAND_QUIT;
}
else
{
LSLog(LOG_DEBUG, L"Rainmeter", L"iTunesPlugin: Invalid command.");
return;
}
}
switch (command)
{
case COMMAND_POWER:
{
if (!InstanceCreated) if (!InstanceCreated)
{ {
if (COMMAND_POWER == command && CoInitialized && SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER))) if (COMMAND_POWER == command && CoInitialized && SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER)))
@ -707,16 +796,16 @@ void ExecuteBang(LPCTSTR args, UINT id)
} }
InstanceCreated = true; InstanceCreated = true;
} }
return; break;
} }
else
switch (command)
{ {
case COMMAND_POWER:
iTunes->Quit(); iTunes->Quit();
iTunes.Release(); iTunes.Release();
InstanceCreated = false; InstanceCreated = false;
break; break;
}
}
case COMMAND_TOGGLEITUNES: case COMMAND_TOGGLEITUNES:
{ {
IITBrowserWindowPtr browserWindow; IITBrowserWindowPtr browserWindow;
@ -889,7 +978,7 @@ void Finalize(HMODULE instance, UINT id)
UINT GetPluginVersion() UINT GetPluginVersion()
{ {
return 0001; return 0002;
} }
LPCTSTR GetPluginAuthor() LPCTSTR GetPluginAuthor()