diff options
Diffstat (limited to 'plugins/winamp')
-rw-r--r-- | plugins/winamp/winamp.c | 215 | ||||
-rw-r--r-- | plugins/winamp/winamp.vcxproj | 70 |
2 files changed, 102 insertions, 183 deletions
diff --git a/plugins/winamp/winamp.c b/plugins/winamp/winamp.c index 389adcbc..d8788164 100644 --- a/plugins/winamp/winamp.c +++ b/plugins/winamp/winamp.c @@ -13,6 +13,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <glib.h> #include "hexchat-plugin.h" @@ -21,163 +22,127 @@ static hexchat_plugin *ph; /* plugin handle */ -BOOL winamp_found = FALSE; - -int status = 0; - -/* Slightly modified from X-Chat's log_escape_strcpy */ -static char * -song_strcpy (char *dest, char *src) +static int +winamp(char *word[], char *word_eol[], void *userdata) { - while (*src) - { - *dest = *src; - dest++; - src++; + HWND hwndWinamp = FindWindowW(L"Winamp v1.x",NULL); - if (*src == '%') + if (hwndWinamp) + { + if (!stricmp("PAUSE", word[2])) { - dest[0] = '%'; - dest++; + if (SendMessage(hwndWinamp,WM_USER, 0, 104)) + { + SendMessage(hwndWinamp, WM_COMMAND, 40046, 0); + + if (SendMessage(hwndWinamp, WM_USER, 0, 104) == PLAYING) + hexchat_printf(ph, "Winamp: playing"); + else + hexchat_printf(ph, "Winamp: paused"); + } } - } - - dest[0] = 0; - return dest - 1; -} - -static int -winamp(char *word[], char *word_eol[], void *userdata) -{ + else if (!stricmp("STOP", word[2])) + { + SendMessage(hwndWinamp, WM_COMMAND, 40047, 0); + hexchat_printf(ph, "Winamp: stopped"); + } + else if (!stricmp("PLAY", word[2])) + { + SendMessage(hwndWinamp, WM_COMMAND, 40045, 0); + hexchat_printf(ph, "Winamp: playing"); + } + else if (!stricmp("NEXT", word[2])) + { + SendMessage(hwndWinamp, WM_COMMAND, 40048, 0); + hexchat_printf(ph, "Winamp: next playlist entry"); + } + else if (!stricmp("PREV", word[2])) + { + SendMessage(hwndWinamp, WM_COMMAND, 40044, 0); + hexchat_printf(ph, "Winamp: previous playlist entry"); + } + else if (!stricmp("START", word[2])) + { + SendMessage(hwndWinamp, WM_COMMAND, 40154, 0); + hexchat_printf(ph, "Winamp: playlist start"); + } + else if (!word_eol[2][0]) + { + wchar_t wcurrent_play[2048]; + char *current_play, *p; + int len = GetWindowTextW(hwndWinamp, wcurrent_play, G_N_ELEMENTS(wcurrent_play)); -char current_play[2048], *p; -char p_esc[2048]; -char cur_esc[2048]; -char truc[2048]; -HWND hwndWinamp = FindWindow("Winamp v1.x",NULL); + current_play = g_utf16_to_utf8 (wcurrent_play, len, NULL, NULL, NULL); + if (!current_play) + { + hexchat_print (ph, "Winamp: Error getting song information."); + return HEXCHAT_EAT_ALL; + } - if (hwndWinamp) - { - { - if (!stricmp("PAUSE", word[2])) + if (strchr(current_play, '-')) { - if (SendMessage(hwndWinamp,WM_USER, 0, 104)) + /* Remove any trailing text and whitespace */ + p = current_play + strlen(current_play) - 8; + while (p >= current_play) { - SendMessage(hwndWinamp, WM_COMMAND, 40046, 0); - - if (SendMessage(hwndWinamp, WM_USER, 0, 104) == PLAYING) - hexchat_printf(ph, "Winamp: playing"); - else - hexchat_printf(ph, "Winamp: paused"); + if (!strnicmp(p, "- Winamp", 8)) + break; + p--; } - } - else - if (!stricmp("STOP", word[2])) - { - SendMessage(hwndWinamp, WM_COMMAND, 40047, 0); - hexchat_printf(ph, "Winamp: stopped"); - } - else - if (!stricmp("PLAY", word[2])) - { - SendMessage(hwndWinamp, WM_COMMAND, 40045, 0); - hexchat_printf(ph, "Winamp: playing"); - } - else - - if (!stricmp("NEXT", word[2])) - { - SendMessage(hwndWinamp, WM_COMMAND, 40048, 0); - hexchat_printf(ph, "Winamp: next playlist entry"); - } - else - if (!stricmp("PREV", word[2])) - { - SendMessage(hwndWinamp, WM_COMMAND, 40044, 0); - hexchat_printf(ph, "Winamp: previous playlist entry"); - } - else - - if (!stricmp("START", word[2])) - { - SendMessage(hwndWinamp, WM_COMMAND, 40154, 0); - hexchat_printf(ph, "Winamp: playlist start"); - } - - else - - if (!word_eol[2][0]) - { - GetWindowText(hwndWinamp, current_play, sizeof(current_play)); - - if (strchr(current_play, '-')) - { - - p = current_play + strlen(current_play) - 8; - while (p >= current_play) - { - if (!strnicmp(p, "- Winamp", 8)) break; - p--; - } - - if (p >= current_play) p--; - - while (p >= current_play && *p == ' ') p--; - *++p=0; - - - p = strchr(current_play, '.') + 1; - - song_strcpy(p_esc, p); - song_strcpy(cur_esc, current_play); - - if (p) - { - sprintf(truc, "me is now playing:%s", p_esc); - } - else - { - sprintf(truc, "me is now playing:%s", cur_esc); - } - - hexchat_commandf(ph, truc); - - } - else hexchat_print(ph, "Winamp: Nothing being played."); + if (p >= current_play) + p--; + + while (p >= current_play && *p == ' ') + p--; + *++p = '\0'; + + /* Ignore any leading track number */ + p = strstr (current_play, ". "); + if (p) + p += 2; + else + p = current_play; + + if (*p != '\0') + hexchat_commandf (ph, "me is now playing: %s", p); + else + hexchat_print (ph, "Winamp: No song information found."); + g_free (current_play); } - else - hexchat_printf(ph, "Usage: /WINAMP [PAUSE|PLAY|STOP|NEXT|PREV|START]\n"); - } - + else + hexchat_print(ph, "Winamp: Nothing being played."); + } + else + hexchat_printf(ph, "Usage: /WINAMP [PAUSE|PLAY|STOP|NEXT|PREV|START]\n"); } else { - hexchat_print(ph, "Winamp not found.\n"); + hexchat_print(ph, "Winamp not found.\n"); } return HEXCHAT_EAT_ALL; } int hexchat_plugin_init(hexchat_plugin *plugin_handle, - char **plugin_name, - char **plugin_desc, - char **plugin_version, - char *arg) + char **plugin_name, + char **plugin_desc, + char **plugin_version, + char *arg) { /* we need to save this for use with any hexchat_* functions */ ph = plugin_handle; *plugin_name = "Winamp"; *plugin_desc = "Winamp plugin for HexChat"; - *plugin_version = "0.5"; + *plugin_version = "0.6"; hexchat_hook_command (ph, "WINAMP", HEXCHAT_PRI_NORM, winamp, "Usage: /WINAMP [PAUSE|PLAY|STOP|NEXT|PREV|START] - control Winamp or show what's currently playing", 0); hexchat_command (ph, "MENU -ishare\\music.png ADD \"Window/Display Current Song (Winamp)\" \"WINAMP\""); hexchat_print (ph, "Winamp plugin loaded\n"); - return 1; /* return 1 for success */ + return 1; /* return 1 for success */ } int diff --git a/plugins/winamp/winamp.vcxproj b/plugins/winamp/winamp.vcxproj index 3c0cfb34..cf839cfa 100644 --- a/plugins/winamp/winamp.vcxproj +++ b/plugins/winamp/winamp.vcxproj @@ -2,6 +2,7 @@ <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup Label="Configuration"> <PlatformToolset>v120</PlatformToolset> + <ConfigurationType>DynamicLibrary</ConfigurationType> </PropertyGroup> <ItemGroup Label="ProjectConfigurations"> <ProjectConfiguration Include="Release|Win32"> @@ -19,76 +20,31 @@ <RootNamespace>winamp</RootNamespace> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> - <ConfigurationType>DynamicLibrary</ConfigurationType> - <UseDebugLibraries>false</UseDebugLibraries> - <WholeProgramOptimization>true</WholeProgramOptimization> - <CharacterSet>MultiByte</CharacterSet> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> - <ConfigurationType>DynamicLibrary</ConfigurationType> - <UseDebugLibraries>false</UseDebugLibraries> - <WholeProgramOptimization>true</WholeProgramOptimization> - <CharacterSet>MultiByte</CharacterSet> - </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <ImportGroup Label="ExtensionSettings"> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - <Import Project="..\..\win32\hexchat.props" /> - </ImportGroup> - <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - <Import Project="..\..\win32\hexchat.props" /> - </ImportGroup> - <PropertyGroup Label="UserMacros" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <LinkIncremental>false</LinkIncremental> - <TargetName>hcwinamp</TargetName> - <OutDir>$(HexChatBin)</OutDir> - <IntDir>$(HexChatObj)$(ProjectName)\</IntDir> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <LinkIncremental>false</LinkIncremental> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="..\..\win32\hexchat.props" /> + <PropertyGroup> <TargetName>hcwinamp</TargetName> - <OutDir>$(HexChatBin)</OutDir> - <IntDir>$(HexChatObj)$(ProjectName)\</IntDir> + <OutDir>$(HexChatRel)plugins\</OutDir> </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> - <PrecompiledHeader> - </PrecompiledHeader> - <FunctionLevelLinking>true</FunctionLevelLinking> - <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;WINAMP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - <AdditionalIncludeDirectories>..\..\src\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> - <Link> - <SubSystem>Windows</SubSystem> - <GenerateDebugInformation>true</GenerateDebugInformation> - <EnableCOMDATFolding>true</EnableCOMDATFolding> - <OptimizeReferences>true</OptimizeReferences> - <ModuleDefinitionFile>winamp.def</ModuleDefinitionFile> - </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ClCompile> - <PrecompiledHeader> - </PrecompiledHeader> - <FunctionLevelLinking>true</FunctionLevelLinking> - <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;_WIN64;_AMD64_;NDEBUG;_WINDOWS;_USRDLL;WINAMP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - <AdditionalIncludeDirectories>..\..\src\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup> + <ClCompile> + <AdditionalIncludeDirectories>$(DepsRoot)\include;$(Glib);..\..\src\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> <Link> - <SubSystem>Windows</SubSystem> - <GenerateDebugInformation>true</GenerateDebugInformation> - <EnableCOMDATFolding>true</EnableCOMDATFolding> - <OptimizeReferences>true</OptimizeReferences> <ModuleDefinitionFile>winamp.def</ModuleDefinitionFile> + <AdditionalDependencies>$(DepLibs);%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> </Link> </ItemDefinitionGroup> <ItemGroup> @@ -98,6 +54,4 @@ <ClCompile Include="winamp.c" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> - <ImportGroup Label="ExtensionTargets"> - </ImportGroup> </Project> \ No newline at end of file |