summary refs log blame commit diff stats
path: root/plugins/wmpa/wmpadialog.cpp
blob: 28d33c931a92fc4cf5906746c9cb009008a5fbe7 (plain) (tree)
4338ddf9 pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* 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 */
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.17626
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace thememan.Properties {
    using System;
    
    
    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class Resources {
        
        private static global::System.Resources.ResourceManager resourceMan;
        
        private static global::System.Globalization.CultureInfo resourceCulture;
        
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal Resources() {
        }
        
        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("thememan.Properties.Resources", typeof(Resources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
        
        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
    }
}
id='n231' href='#n231'>231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375











                                                                    
                            
































































































                                                                                   
                                                                              

          
                                                                            


















































































                                                                            
                                                                              

          
                                                                            
















                                                                                                           
                                                                                 

             
                                                                               
























































































































































                                                                            
/******************************************************************
* $Id$
*
* $Log$
*
* Copyright � 2005 David Cullen, All rights reserved
*
******************************************************************/
#include "stdafx.h"
#include "wmpa.h"
#include "WMPADialog.h"
#include "shellapi.h"
#include "hexchat-plugin.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define ID_TRAY_ICON    1000
#define WM_TRAY_ICON    (WM_APP + 1)

/////////////////////////////////////////////////////////////////////////////
// CWMPADialog dialog

CWMPADialog::CWMPADialog(CWnd* pParent /*=NULL*/)
	: CDialog(CWMPADialog::IDD, pParent)
{
	EnableAutomation();

	//{{AFX_DATA_INIT(CWMPADialog)
	//}}AFX_DATA_INIT
}


void CWMPADialog::OnFinalRelease()
{
	// When the last reference for an automation object is released
	// OnFinalRelease is called.  The base class will automatically
	// deletes the object.  Add additional cleanup required for your
	// object before calling the base class.

	CDialog::OnFinalRelease();
}

void CWMPADialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWMPADialog)
	DDX_Control(pDX, IDC_SONGLIST, m_SongListBox);
	DDX_Control(pDX, IDC_PLAYLIST, m_PlaylistBox);
	DDX_Control(pDX, IDC_WMP, m_WMP);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWMPADialog, CDialog)
	//{{AFX_MSG_MAP(CWMPADialog)
	ON_LBN_DBLCLK(IDC_PLAYLIST, OnDblclkPlaylist)
	ON_WM_SHOWWINDOW()
	ON_WM_CLOSE()
	ON_LBN_DBLCLK(IDC_SONGLIST, OnDblclkSonglist)
	ON_WM_DESTROY()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CWMPADialog, CDialog)
	//{{AFX_DISPATCH_MAP(CWMPADialog)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

// Note: we add support for IID_IWMPADialog to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the
//  dispinterface in the .ODL file.

// {01C1B3AA-C7FC-4023-89A5-C814E1B62B9B}
static const IID IID_IWMPADialog =
{ 0x1c1b3aa, 0xc7fc, 0x4023, { 0x89, 0xa5, 0xc8, 0x14, 0xe1, 0xb6, 0x2b, 0x9b } };

BEGIN_INTERFACE_MAP(CWMPADialog, CDialog)
	INTERFACE_PART(CWMPADialog, IID_IWMPADialog, Dispatch)
END_INTERFACE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWMPADialog message handlers

void CWMPADialog::OnDblclkPlaylist()
{
	// TODO: Add your control notification handler code here
   long index;

   // Get the playlist name
   index = m_PlaylistBox.GetCurSel();
   CString playlistName;
   m_PlaylistBox.GetText(index, playlistName);

   // Get the playlist
   CWMPPlaylistCollection pc = m_WMP.GetPlaylistCollection();
   CWMPPlaylistArray pa = pc.getByName((LPCTSTR) playlistName);
   CWMPPlaylist playlist = pa.Item(0);
   m_WMP.SetCurrentPlaylist(playlist);

   // Set the song list
   UpdateSongList();

   m_WMP.GetControls().play();
   if (autoAnnounce) {
      hexchat_commandf(ph, "me is playing %s", (LPCTSTR) wmpaGetSongTitle());
   }
   else {
      hexchat_printf(ph, "WMPA: Playing %s", (LPCTSTR) wmpaGetSongTitle());
   }
}

void CWMPADialog::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDialog::OnShowWindow(bShow, nStatus);
	
	// TODO: Add your message handler code here
   if (bShow) {
      if (!trayInit) {
         ZeroMemory(&nid, sizeof(nid));
         nid.cbSize = sizeof(nid);
         nid.hWnd = m_hWnd;
         nid.uID = ID_TRAY_ICON;
         nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
         nid.uCallbackMessage = WM_TRAY_ICON;
         nid.hIcon = m_hIcon;
         strcpy(nid.szTip, "WMPA");
         strcat(nid.szTip,  VER_STRING);
         strcat(nid.szTip, "\nWindows Media\nPlayer Announcer");
         nid.dwState = 0;
         nid.dwStateMask = 0;
         strcpy(nid.szInfo, "WMPA ");
         strcat(nid.szInfo, VER_STRING);
         nid.uTimeout = 10000; // 10 second time out
         strcat(nid.szInfoTitle, "WMPA");
         nid.dwInfoFlags = 0;
         trayInit = TRUE;
      }
   }

}


void CWMPADialog::PostNcDestroy()
{
	// TODO: Add your specialized code here and/or call the base class
   delete this;

	CDialog::PostNcDestroy();
}


BOOL CWMPADialog::OnInitDialog()
{
	CDialog::OnInitDialog();

   CString title = "WMPA";
   title += " ";
   title += VER_STRING;
   SetWindowText((LPCTSTR) title);

   UpdatePlayLists();

   autoAnnounce = FALSE;
   trayInit = FALSE;
   trayClicked = FALSE;

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CWMPADialog::OnClose()
{
	// TODO: Add your message handler code here and/or call default
   Shell_NotifyIcon(NIM_ADD, &nid);
   ShowWindow(SW_HIDE);

   // Don't let the user close the dialog
//   CDialog::OnClose();
}

void CWMPADialog::OnCancel()
{
//   this->DestroyWindow();
}

void CWMPADialog::OnDblclkSonglist()
{
	// TODO: Add your control notification handler code here
   int index = m_SongListBox.GetCurSel();
   m_WMP.GetControls().playItem(m_WMP.GetCurrentPlaylist().GetItem(index));
   if (autoAnnounce) {
      hexchat_commandf(ph, "me is playing %s", (LPCTSTR) wmpaGetSongTitle());
   }
   else {
      hexchat_printf(ph, "WMPA: Playing %s", (LPCTSTR) wmpaGetSongTitle());
   }
}

BEGIN_EVENTSINK_MAP(CWMPADialog, CDialog)
    //{{AFX_EVENTSINK_MAP(CWMPADialog)
	ON_EVENT(CWMPADialog, IDC_WMP, 5806 /* CurrentItemChange */, OnCurrentItemChangeWmp, VTS_DISPATCH)
	ON_EVENT(CWMPADialog, IDC_WMP, 5101 /* PlayStateChange */, OnPlayStateChangeWmp, VTS_I4)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CWMPADialog::OnCurrentItemChangeWmp(LPDISPATCH pdispMedia)
{
	// TODO: Add your control notification handler code here

   int state = m_WMP.GetPlayState();
   if (state == 3) { // Playing
      if (autoAnnounce) {
         hexchat_commandf(ph, "me is playing %s", (LPCTSTR) wmpaGetSongTitle());
      }
      else {
         hexchat_printf(ph, "WMPA: Playing %s", (LPCTSTR) wmpaGetSongTitle());
      }
   }

   SelectCurrentSong();
}

void CWMPADialog::OnDestroy()
{
	CDialog::OnDestroy();
	
   // TODO: Add your message handler code here
}

void CWMPADialog::UpdateSongList()
{
   char buffer[32];
   CString name;
   CString artist;
   CString title;
   CString album;
   CString bitrate;
   CString duration;
   CString song;
   long index;
   long count;

   m_SongListBox.ResetContent();
   CWMPPlaylist playlist = m_WMP.GetCurrentPlaylist();
   count = playlist.GetCount();
   m_SongListBox.ResetContent();
   for (index = 0; index < count; index++) {
      name         = playlist.GetItem(index).GetName();
      artist       = playlist.GetItem(index).getItemInfo("Artist");
      title        = playlist.GetItem(index).getItemInfo("Title");
      album        = playlist.GetItem(index).getItemInfo("Album");
      bitrate      = playlist.GetItem(index).getItemInfo("Bitrate");
      duration     = playlist.GetItem(index).GetDurationString();

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

      if (album.IsEmpty()) {
         playlist.removeItem(playlist.GetItem(index));
         count = playlist.GetCount();
      }
      else {
         song = "";
         song += artist;
         if (song.IsEmpty()) song = "Various";
         song += " - ";
         song += title;
         song += " (";
         song += album;
         song += ") [";
         song += duration;
         song += "/";
         song += bitrate;
         song += "Kbps]";
         m_SongListBox.AddString((LPCTSTR) song);
      }

   }
   m_SongListBox.SetCurSel(0);
}

void CWMPADialog::SelectCurrentSong()
{
   CWMPMedia media;
   long index;
   long count;

   count = m_WMP.GetCurrentPlaylist().GetCount();
   for (index = 0; index < count; index++) {
      media = m_WMP.GetCurrentPlaylist().GetItem(index);
      if (m_WMP.GetCurrentMedia().GetIsIdentical(media)) {
         m_SongListBox.SetCurSel(index);
      }
   }
}

void CWMPADialog::UpdatePlayLists()
{
	// TODO: Add extra initialization here
   CWMPPlaylistCollection pc = m_WMP.GetPlaylistCollection();
   CWMPPlaylistArray pa = pc.getAll();
   CWMPPlaylist playlist;

   int index;
   int count = pa.GetCount();
   m_PlaylistBox.ResetContent();
   for (index = 0; index < count; index++) {
      playlist = pa.Item(index);
      m_PlaylistBox.AddString((LPCTSTR) playlist.GetName());
   }
}


void CWMPADialog::OnPlayStateChangeWmp(long NewState)
{
	// TODO: Add your control notification handler code here
}

void CWMPADialog::OnSize(UINT nType, int cx, int cy)
{
	CDialog::OnSize(nType, cx, cy);
	// TODO: Add your message handler code here
   switch (nType) {
      case SIZE_MINIMIZED:
         break;

      case SIZE_RESTORED:
         Shell_NotifyIcon(NIM_DELETE, &nid);
         break;

      default:
         break;
   }
}

LRESULT CWMPADialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
   // TODO: Add your specialized code here and/or call the base class
   switch (message) {
      case WM_TRAY_ICON:
         switch (lParam) {
            case WM_LBUTTONDBLCLK:
               trayClicked = TRUE;
               break;

            case WM_LBUTTONUP:
               if (trayClicked == TRUE) {
                  ShowWindow(SW_RESTORE);
               }
               break;

            default:
               trayClicked = FALSE;
               break;
         }
         return(TRUE);
         break;

      default:
         return CDialog::WindowProc(message, wParam, lParam);
         break;
   }
}

void CWMPADialog::DeleteTrayIcon()
{
   Shell_NotifyIcon(NIM_DELETE, &nid);
}