summary refs log tree commit diff stats
path: root/src/fe-text
AgeCommit message (Collapse)Author
2016-07-24Kill fe_set_hilight()Patrick Griffis
It just duplicates functionality and this fixes: - alert_taskbar chanopt not being respected - tab color being incorrect when highlight print events are eaten
2016-06-29Introduce and use fe_timeout_add_secondsBen Gamari
This should allow the operating system to be a bit more lax about timeouts, allowing more efficient power management.
2015-10-16build: Let 'make dist' do a better jobRico Tzschichholz
2015-10-12common: Moved some functions over from plugins/sysinfo that are useful for ↵Arnavion
the rest of HC. OS name, CPU, GPU, HDD info and build arch are now all available within core HC. OS name and build arch are used in the About dialog.
2015-10-10Use VS 2015Arnavion
2015-02-19Remove compiled date from aboutTingPing
Distros like Debian depend on repeated builds having the same results which this breaks. Since this provides no real value just remove it.
2015-02-11Better project files.Arnavion
- Output directly to rel\ instead of to bin\ and then copying files over. - Deduped Win32 vs x64 configs - Moved some common properties to hexchat.props - All build intermediates (except htm's intermediates) are no longer emitted in the source directory
2015-02-04Implement windows 8.1+ notificationsTingPing
This splits notifications up into multiple backends currently only libnotify on unix and win8 toasts. The win8 backend was originally written by @leeter though heavily modified.
2014-12-31Move userlist sorting to frontendTingPing
This Fixes possible crashes when the two usertrees get out of sync and a double free occurs. Also now requires restart to change sort orders. Fixes #1252 Fixes #818 (probably)
2014-12-28Remove option to disable ipv6TingPing
It has been default for a while, is the only tested option, and will only get more common.
2014-12-28Fix overflowTingPing
2014-12-28Fix warningTingPing
2014-12-28Fix building as c89TingPing
2014-12-28Use glib for all allocationsTingPing
- Removes need to check for malloc failure - Removes need for NULL checks on free - Adds checks for integer overflows - Removes some extra memset calls - Removes chance of mixing libc and glib malloc/free
2014-12-08Removed some unnecessary null-checks for calls to g_free and g_strfreevArnavion
2014-09-17win32: Fixed build break due to 7a4a024Arnavion
2014-02-04Add /getbool commandTingPing
2014-02-04osx: Set Menlo as default fontTingPing
This moves the find_font function to the front ends since it depends on pango and cairo
2014-01-30Now make_ping_time() in common/util.c returns the time in milliseconds insteadDiogo Sousa
of microseconds. In fe_set_lag(serv, lag) the lag argument is now in milliseconds as well. Fixes #758.
2014-01-20configure: Clean up EXTRA_DISTTingPing
2013-11-02Fix invalid timestamps crashing on WindowsTingPing
2013-10-22Open channel list window on /listFarow
2013-10-09Fix messages with server-time not showing as new activityDiogo Sousa
Added a parameter to fe_print_text() to say that the message does not represent new activity. This is used when a log from an old session is loaded. This used to be implicit whenever the timestamp was non-zero, but with server-time this no longer makes sense. Fixes issue #746.
2013-09-15Convert project files to vs2013Eustachy Kapusta
2013-07-24Move optimization settings from all subsequent projects to hexchat.propsEustachy Kapusta
2013-07-01Update fe-text's help messageTingPing
2013-04-28Don't hardcode "plugins" as the subdirectory for plugins in manyChristoph J. Thompson
places. modified: config-win32.h modified: configure.ac modified: plugins/checksum/Makefile.am modified: plugins/doat/Makefile.am modified: plugins/fishlim/Makefile.am modified: plugins/perl/Makefile.am modified: plugins/python/Makefile.am modified: plugins/sysinfo/Makefile.am modified: plugins/xdcc/Makefile.am modified: src/common/plugin.c modified: src/fe-text/fe-text.c
2013-04-27Reverts commit d964af81428a6d768aeb96906eb0538a30d919caTingPing
2013-04-25win32: Moved PlatformToolset configuration to individual project files. It ↵Arnavion
should be set before setting other properties or importing other props. This fixes the broken GUI Platform Toolset indicator, as well as VS compilation itself if another version such as 2010 was also installed.
2013-04-22fix warning in new glibTingPing
2013-04-05Fix root user warning running before g_type_initTingPing
closes #504
2013-04-02Apply to fe-text tooBerke Viktor
2013-04-01Remove another bunch of obsolete junkBerke Viktor
2013-03-31Supposed fix for license issuesBerke Viktor
I have no clue what to put here so I'll just use what the About dialog provides (unless specified otherwise in the file)
2013-03-27fix warningTingPing
2013-03-20Redesign the Ban List window. Closes Issues #303, #342, #427RichardHitt
This is a combination of 18 commits. The first commit's message is: Here is the initial banlist branch of RichardHitt/hexchat. Changed files are only src/fe-gtk/{banlist.c,fe-gtk.h}. This version works and contains my first efforts at selective sensitization of radio buttons and control buttons. From this point I intend to undertake a stepwise redesign. Step 1 will be to make the existing banlist code work for multiple simultaneous banlist windows (for different channels, obviously). It will be a hackathon with the only goal of getting it working. Step 2 will be the objectization and alpha-stage tidying-up of all the terrible looking stuff I will have done in Step 1. This is the 2nd commit message: Here's the post-Step-1 commit. It works for multiple banlist windows. Note particularly what I've done to banlist.h. Note that for many functions in banlist.c the argument is now a banlist_info *, rather than a session *. Note in banlist.c the initialization of array modes[] which contains driving information for the checkboxes. Of course those checkboxes aren't yet implemented. Maybe in Step 2 I will change to checkboxes from radio buttons; but definitely I will change to letting modes[] drive processing. This is the 3rd commit message: Converted to checkboxes. Much additional work. Note that the infrastructure for Auto-invite is not yet present in the hexchat tree. I'm nearly done with banlist, I think! This is the 4th commit message: Fleshed out 'invite'. Tagged masks uniformly, e.g. (b) (e) (I). General cleanup, nearly at the point of beta quality. This is the 5th commit message: Added fourth mode type: quiet. Did lots and lots of cleanup. Beta-ready? This is the 6th commit message: Get the banlist timestamps properly sortable. This is the 7th commit message: Redesign the supports_foo() routines. Now they're responsible for setting the flags in ->capable, ->readable, ->writeable. This is the 8th commit message: Deleted a couple of RBH comments. This is the 9th commit message: Now the ESC key will close the banlist window. This is the 10th commit message: Fix the fe-text occurrence of fe_add_ban_list(). This is the 11th commit message: Fixed also fe_ban_list_end() and removed fe_is_banwindow(). This is the 12th commit message: Use old-style initialization for array of structures modes[] This is the 13th commit message: Oops, incomplete regression of modes[] initialization. This fixes. This is the 14th commit message: Fixed strptime buy implementing a special version here. Fixed column width concerns by setting resizable and autosize. This is the 15th commit message: Get rid of testing line. This is the 16th commit message: Changed to gtkutil_destroy_on_esc () This is the 17th commit message: Remove no-longer-used functnion This is the 18th commit message: Minor cleanups to banlist.c, banlist.h Please enter the commit message for your changes. Lines starting with '#' will be ignored, and an empty message aborts the commit. Author: RichardHitt <rbh00@netcom.com> Committer: Richard Hitt <rbh00@f17.rbh00.pacbell.net> Not currently on any branch. Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: src/common/fe.h modified: src/common/hexchat.h modified: src/common/inbound.c modified: src/common/modes.c modified: src/common/proto-irc.c modified: src/common/server.c modified: src/fe-gtk/banlist.c modified: src/fe-gtk/banlist.h modified: src/fe-gtk/fe-gtk.c modified: src/fe-gtk/fe-gtk.h modified: src/fe-gtk/maingui.c modified: src/fe-text/fe-text.c
2013-03-16Handle EOF in text-feTingPing
2013-03-16fix fe-text on win32TingPing
It still throws out some errors
2013-03-16fix fe-textTingPing
2013-01-17fix fe-beep issue in fe-textTingPing
2013-01-09Make source cleah with cppcheck, except for mpc and saslRichardHitt
2012-12-23fix incorrect FSF addressDan Mashal
2012-11-04Some more platform unificationBerke Viktor
2012-11-04Eliminate warnings due to missing includesBerke Viktor
2012-11-03Initial commit for utf8 everywhere.Arnavion
2012-10-28Further doc relocations and conversionsBerke Viktor
2012-10-28More polishing for the About dialogBerke Viktor
2012-10-24A lot more rebrandingBerke Viktor
2012-10-24Rename libxchatcommon to libhexchatcommonBerke Viktor
2012-10-24Fix fe-text compilation - it still segfaults thoughBerke Viktor
/* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/******************************************************************
* $Id$
*
* $Log$
*
* Copyright � 2005 David Cullen, All rights reserved
*
******************************************************************/
#include "stdafx.h"
#include "xchat-plugin.h"
#include <windows.h>
#include <tchar.h>
#include "wmpa.h"
#include "WMPADialog.h"

#define XMMS_SESSION 0

/******************************************************************
* Globalss
******************************************************************/
xchat_plugin *ph = NULL;
CWMPPlayer4 *wmp;
static const char subKey[] = "Software\\FlowerSoft\\WMPA";

/******************************************************************
* xchat_plugin_init
******************************************************************/
int xchat_plugin_init(xchat_plugin *plugin_handle,
                      char **plugin_name,
                      char **plugin_desc,
                      char **plugin_version,
                      char *arg)
{
   BOOL success;

   ph = plugin_handle;

   *plugin_name = "WMPA";
   *plugin_desc = "Announce the current song from Windows Media Player.";
   *plugin_version = VER_STRING;

   // Show the song browser
   success = StartWindowsMediaPlayer();
   if (!success) {
      xchat_printf(ph, "WMPA: Failed to show the song browser.");
      xchat_printf(ph, "WMPA: Could not load plug-in version %s.", VER_STRING);
      return(E_FAIL);
   }

   // Get a pointer to the Windows Media Player control
   wmp = GetWindowsMediaPlayer();
   if (wmp == NULL) {
      xchat_printf(ph, "WMPA: Failed to get a pointer to the Windows Media Player interface.");
      xchat_printf(ph, "WMPA: Could not load plug-in version %s.", VER_STRING);
      return(E_POINTER);
   }

   // Restore the settings (need wmp first)
   success = wmpaRestoreSettings();
   if (!success) {
      xchat_printf(ph, "WMPA: Failed to restore the settings.");
   }

   xchat_hook_command(ph, "auto", XCHAT_PRI_NORM, wmpaAuto, 0, 0);
   xchat_hook_command(ph, "curr", XCHAT_PRI_NORM, wmpaCurr, 0, 0);
   xchat_hook_command(ph, "find", XCHAT_PRI_NORM, wmpaFind, 0, 0);
   xchat_hook_command(ph, "slist", XCHAT_PRI_NORM, wmpaList, 0, 0);
   xchat_hook_command(ph, "next", XCHAT_PRI_NORM, wmpaNext, 0, 0);
   xchat_hook_command(ph, "play", XCHAT_PRI_NORM, wmpaPlay, 0, 0);
   xchat_hook_command(ph, "pause", XCHAT_PRI_NORM, wmpaPause, 0, 0);
   xchat_hook_command(ph, "prev", XCHAT_PRI_NORM, wmpaPrev, 0, 0);
   xchat_hook_command(ph, "song", XCHAT_PRI_NORM, wmpaSong, 0, 0);
   xchat_hook_command(ph, "stop", XCHAT_PRI_NORM, wmpaStop, 0, 0);
   xchat_hook_command(ph, "volume", XCHAT_PRI_NORM, wmpaVolume, 0, 0);
   xchat_hook_command(ph, "wmpahelp", XCHAT_PRI_NORM, wmpaHelp, 0, 0);

   xchat_printf(ph, "WMPA %s successfully loaded.", VER_STRING);
   wmpaCommands();
   xchat_printf(ph, "WMPA: e-mail me if you find any bugs: dcullen@intergate.com");

   return 1;
}

/******************************************************************
* xchat_plugin_deinit
******************************************************************/
int xchat_plugin_deinit(void)
{
   BOOL success;

   xchat_printf(ph, "WMPA %s is unloading.", VER_STRING);

   // Save the settings
   success = wmpaSaveSettings();
   if (!success) {
      xchat_printf(ph, "WMPA: Failed to save the settings.");
   }

   wmp = NULL;

   BOOL result = StopWindowsMediaPlayer();
   if (!result) {
      xchat_printf(ph, "WMPA could not shut down Windows Media Player.");
   }

   xchat_printf(ph, "WMPA %s has unloaded.", VER_STRING);
   return 1;
}

/******************************************************************
* xchat_plugin_get_info
******************************************************************/
void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
{
   *name = "WMPA";
   *desc = "Announce the current song from Windows Media Player.";
   *version = VER_STRING;
   if (reserved) *reserved = NULL;
}

/******************************************************************
* wmpaCommands
******************************************************************/
void wmpaCommands(void)
{
   xchat_printf(ph, "WMPA: /auto [on/off]   : Turn on/off auto announce of the current song or display the current setting");
   xchat_printf(ph, "WMPA: /curr            : Tell what song is currently playing");
   xchat_printf(ph, "WMPA: /find [word]     : Find songs with \"word\" in their title, create a new playlist, and play it");
   xchat_printf(ph, "WMPA: /slist [word]    : List songs with \"word\" in their title");
   xchat_printf(ph, "WMPA: /next            : Play the next song");
   xchat_printf(ph, "WMPA: /play            : Play the current song");
   xchat_printf(ph, "WMPA: /pause           : Pause the current song");
   xchat_printf(ph, "WMPA: /prev            : Play the previous song");
   xchat_printf(ph, "WMPA: /song            : Announce the current song from Windows Media Player in xchat");
   xchat_printf(ph, "WMPA: /stop            : Stop the current song");
   xchat_printf(ph, "WMPA: /volume [volume] : Set the volume (0 to 100) or display the current volume");
   xchat_printf(ph, "WMPA: /wmpahelp        : Display this help.");
}

/******************************************************************
* wmpaAuto
******************************************************************/
int wmpaAuto(char *word[], char *word_eol[], void *user_data)
{
   CWMPADialog *pDialog;
   char *state;

   pDialog = GetWMPADialog();
   if (pDialog == NULL) return(XCHAT_EAT_ALL);

   if (CString(word[2]).IsEmpty()) {
      if (pDialog->autoAnnounce) {
         state = "on";
      }
      else {
         state = "off";
      }
   }
   else {
      state = word[2];
      if (CString(state) == "on") {
         pDialog->autoAnnounce = TRUE;
      }
      if (CString(state) == "off") {
         pDialog->autoAnnounce = FALSE;
      }
      wmpaSaveSettings();
   }

   xchat_printf(ph, "WMPA: auto is %s", state);

   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaCurr
******************************************************************/
int wmpaCurr(char *word[], char *word_eol[], void *user_data)
{
   xchat_printf(ph, "WMPA: Playing %s", (LPCTSTR) wmpaGetSongTitle());

   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaFind
******************************************************************/
int wmpaFind(char *word[], char *word_eol[], void *user_data)
{
   long index;
   long count;
   long found;

   if (wmp != NULL) {
      CWMPMediaCollection mc = wmp->GetMediaCollection();
      CWMPPlaylist all = mc.getAll();
      CWMPPlaylistCollection pc = wmp->GetPlaylistCollection();
      CWMPPlaylistArray pa = pc.getAll();
      CWMPPlaylist playlist;
      CWMPMedia media;

      for (index = 0; index < pc.getAll().GetCount(); index++) {
         if (pc.getAll().Item(index).GetName() == CString(word_eol[2])) {
            playlist = pc.getAll().Item(index);
            pc.remove(playlist);
         }
      }

      playlist = pc.newPlaylist(word_eol[2]);

      count = all.GetCount();
      found = 0;
      for (index = 0; index < count; index++) {
         media = all.GetItem(index);
         CString artist = media.getItemInfo("Artist");
         CString title  = media.getItemInfo("Title");
         CString album  = media.getItemInfo("Album");
         if ( (artist.Find(word_eol[2]) != -1) ||
              (title.Find(word_eol[2])  != -1) ||
              (album.Find(word_eol[2])  != -1) ) {
            playlist.appendItem(media);
            found++;
         }
      }

      if (found > 0) {
         xchat_printf(ph, "WMPA: Found %d songs with \"%s\" in them", found, word_eol[2]);
         wmp->SetCurrentPlaylist(playlist);
         wmp->GetControls().play();
         xchat_printf(ph, "WMPA: Playing %s", (LPCTSTR) wmpaGetSongTitle());

         CWMPADialog *dialog = GetWMPADialog();
         if (dialog != NULL) {
            dialog->UpdateSongList();
            dialog->SelectCurrentSong();
            dialog->UpdatePlayLists();
         }

      }
      else {
         xchat_printf(ph, "WMPA: Could not find %s", word_eol[2]);
      }

   }

   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaList
******************************************************************/
int wmpaList(char *word[], char *word_eol[], void *user_data)
{
   long index;
   long count;
   long found;

   if (wmp != NULL) {
      xchat_printf(ph, "WMPA: Listing songs with \"%s\" in them", word_eol[2]);

      CWMPMediaCollection mc = wmp->GetMediaCollection();
      CWMPPlaylist all = mc.getAll();
      CWMPMedia media;

      count = all.GetCount();
      found = 0;
      for (index = 0; index < count; index++) {
         media = all.GetItem(index);
         CString artist = media.getItemInfo("Artist");
         CString title  = media.getItemInfo("Title");
         CString album  = media.getItemInfo("Album");
         if ( (artist.Find(word_eol[2]) != -1) ||
              (title.Find(word_eol[2])  != -1) ||
              (album.Find(word_eol[2])  != -1) ) {
            xchat_printf(ph, "WMPA: Found \"%s - %s (%s)\"", artist, title, album);
            found++;
         }
      }

      if (found > 0) {
         if (found == 1)
            xchat_printf(ph, "WMPA: Found %d song with \"%s\" in it", found, word_eol[2]);
         else
            xchat_printf(ph, "WMPA: Found %d songs with \"%s\" in them", found, word_eol[2]);
      }
      else {
         xchat_printf(ph, "WMPA: Could not find any songs with \"%s\" in them", word_eol[2]);
      }

   }

   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaNext
******************************************************************/
int wmpaNext(char *word[], char *word_eol[], void *user_data)
{
   if (wmp != NULL) {
      wmp->GetControls().next();
      xchat_printf(ph, "WMPA: Playing %s", (LPCTSTR) wmpaGetSongTitle());
   }
   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaPlay
******************************************************************/
int wmpaPlay(char *word[], char *word_eol[], void *user_data)
{
   if (wmp != NULL) {
      wmp->GetControls().play();
      xchat_printf(ph, "WMPA: Playing %s", (LPCTSTR) wmpaGetSongTitle());
   }
   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaPause
******************************************************************/
int wmpaPause(char *word[], char *word_eol[], void *user_data)
{
   if (wmp != NULL) {
      wmp->GetControls().pause();
      xchat_printf(ph, "WMPA: Pausing %s", (LPCTSTR) wmpaGetSongTitle());
   }
   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaPrev
******************************************************************/
int wmpaPrev(char *word[], char *word_eol[], void *user_data)
{
   if (wmp != NULL) {
      wmp->GetControls().previous();
      xchat_printf(ph, "WMPA: Playing %s", (LPCTSTR) wmpaGetSongTitle());
   }
   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaSong
******************************************************************/
int wmpaSong(char *word[], char *word_eol[], void *user_data)
{
   CString songTitle = wmpaGetSongTitle();

   xchat_commandf(ph, "me is playing %s", (LPCTSTR) songTitle);

   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaStop
******************************************************************/
int wmpaStop(char *word[], char *word_eol[], void *user_data)
{
   if (wmp != NULL) {
      wmp->GetControls().stop();
      xchat_printf(ph, "WMPA: Stopping %s", (LPCTSTR) wmpaGetSongTitle());
   }
   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaHelp
******************************************************************/
int wmpaHelp(char *word[], char *word_eol[], void *user_data)
{
   xchat_printf(ph, "\n");
   xchat_printf(ph, "WMPA %s Help", VER_STRING);
   wmpaCommands();
   xchat_printf(ph, "\n");

   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaVolume
******************************************************************/
int wmpaVolume(char *word[], char *word_eol[], void *user_data)
{
   char *endPtr;
   long volume;

   if (CString(word[2]).IsEmpty()) {
      volume = wmp->GetSettings().GetVolume();
   }
   else {
      volume = strtol(word[2], &endPtr, 10);

      if ((wmp != NULL) && (volume >= 0) && (volume <= 100)) {
         wmp->GetSettings().SetVolume(volume);
         wmpaSaveSettings();
      }
   }

   xchat_printf(ph, "WMPA: volume is %d", volume);

   return(XCHAT_EAT_ALL);
}

/******************************************************************
* wmpaRestoreSettings
******************************************************************/
BOOL wmpaRestoreSettings(void)
{
   CWMPADialog *pDialog;
   DWORD type;
   int volume;
   BOOL autoAnnounce;
   DWORD size;
   BOOL result;

   if (wmp == NULL) return(FALSE);

   volume = 50;
   result = GetSetting("Volume", &type, (LPBYTE) &volume, &size);
   wmp->GetSettings().SetVolume(volume);

   autoAnnounce = FALSE;
   pDialog = GetWMPADialog();
   if (pDialog != NULL) {
      result = result && GetSetting("Auto", &type, (LPBYTE) &autoAnnounce, &size);
      pDialog->autoAnnounce = autoAnnounce;
   }
   else {
      result = FALSE;
   }

   return(result);
}

/******************************************************************
* wmpaSaveSettings
******************************************************************/
BOOL wmpaSaveSettings(void)
{
   CWMPADialog *pDialog;
   int volume;
   BOOL autoAnnounce;
   BOOL result;

   if (wmp == NULL) return(FALSE);

   volume = wmp->GetSettings().GetVolume();
   result = SaveSetting("Volume", REG_DWORD, (CONST BYTE *) &volume, sizeof(volume));

   pDialog = GetWMPADialog();
   if (pDialog != NULL) {
      autoAnnounce = pDialog->autoAnnounce;
      result = result && SaveSetting("Auto", REG_DWORD, (CONST BYTE *) &autoAnnounce, sizeof(autoAnnounce));
   }
   else {
      result = FALSE;
   }

   return(result);
}

/******************************************************************
* wmpaGetSongTitle
******************************************************************/
CString wmpaGetSongTitle(void)
{
   char buffer[32];

   if (wmp == NULL) return(CString());

   CWMPMedia media      = wmp->GetCurrentMedia();
   if (media == NULL) {
      xchat_printf(ph, "WMPA: Could not get current media");
      return(XCHAT_EAT_ALL);
   }

   CString artist       = media.getItemInfo("Artist");
   CString title        = media.getItemInfo("Title");
   CString album        = media.getItemInfo("Album");
   CString bitrate      = media.getItemInfo("Bitrate");
   CString duration     = media.GetDurationString();

   long krate = strtoul((LPCTSTR) bitrate, NULL, 10) / 1000;
   _ultoa(krate, buffer, 10);
   bitrate = CString(buffer);

   // Creatte the song title
   CString songTitle("");
   songTitle += artist;
   if (songTitle.IsEmpty()) songTitle += "Various";
   songTitle += " - ";
   songTitle += title;
   songTitle += " (";
   songTitle += album;
   songTitle += ") [";
   songTitle += duration;
   songTitle += "/";
   songTitle += bitrate;
   songTitle += "Kbps]";

   return(songTitle);
}

/******************************************************************
* SaveSetting
******************************************************************/
BOOL SaveSetting(LPCTSTR name, DWORD type, CONST BYTE *value, DWORD size)
{
   HKEY hKey;
   DWORD disposition;
   LONG result;

   if (wmp == NULL) return(FALSE);
   if (name == NULL) return(FALSE);

   result = RegOpenKeyEx(HKEY_CURRENT_USER,
                         subKey,
                         0,
                         KEY_WRITE,
                         &hKey);

   if (result != ERROR_SUCCESS) {
      result = RegCreateKeyEx(HKEY_CURRENT_USER,
                              subKey,
                              0,
                              NULL,
                              REG_OPTION_NON_VOLATILE,
                              KEY_WRITE,
                              NULL,
                              &hKey,
                              &disposition);

      if (result != ERROR_SUCCESS) return(FALSE);
   }

   result = RegSetValueEx(hKey,
                          name,
                          0,
                          type,
                          value,
                          size);

   if (result == ERROR_SUCCESS) {
      RegCloseKey(hKey);
      return(TRUE);
   }

   RegCloseKey(hKey);
   return(FALSE);
}

/******************************************************************
* GetSetting
******************************************************************/
BOOL GetSetting(LPCTSTR name, DWORD *type, LPBYTE value, DWORD *size)
{
   HKEY hKey;
   LONG result;

   if (wmp == NULL) return(FALSE);
   if (type == NULL) return(FALSE);
   if (value == NULL) return(FALSE);
   if (size == NULL) return(FALSE);

   result = RegOpenKeyEx(HKEY_CURRENT_USER,
                         subKey,
                         0,
                         KEY_READ,
                         &hKey);

   if (result != ERROR_SUCCESS) return(FALSE);

   result = RegQueryValueEx(hKey,
                            name,
                            0,
                            type,
                            value,
                            size);

   RegCloseKey(hKey);

   if (result == ERROR_SUCCESS) {
      return(TRUE);
   }

   RegCloseKey(hKey);
   return(FALSE);
}