OSDN Git Service

GUI終了時のエラー落ちを修正(?)
[peercast-im/PeerCastIM.git] / c: / Git / PeerCast.root / PeerCast / ui / win32 / simple / Simple.cpp
1 // ------------------------------------------------
2 // File : simple.cpp
3 // Date: 4-apr-2002
4 // Author: giles
5 // Desc: 
6 //              Simple tray icon interface to PeerCast, mostly win32 related stuff.
7 //              
8 // (c) 2002 peercast.org
9 // ------------------------------------------------
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
14
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 // ------------------------------------------------
20
21 #include <windows.h>
22 #include <direct.h> 
23 #include "stdafx.h"
24 #include "resource.h"
25 #include "gui.h"
26 #include "channel.h"
27 #include "servent.h"
28 #include "servmgr.h"
29 #include "win32/wsys.h"
30 #include "peercast.h"
31 #include "simple.h"
32 #include "version2.h"
33 #include "gdiplus.h"
34 #include "time.h"
35 #ifdef _DEBUG
36 #include "chkMemoryLeak.h"
37 #define DEBUG_NEW new(__FILE__, __LINE__)
38 #define new DEBUG_NEW
39 #endif
40
41 #define MAX_LOADSTRING 100
42
43 #define PLAY_CMD 7000
44 #define RELAY_CMD 8000
45 #define INFO_CMD 9000
46 #define URL_CMD 10000
47
48 #define MAX_CHANNELS 999
49
50
51 extern "C"
52 {
53         void loadIcons(HINSTANCE hInstance, HWND hWnd);
54 };
55
56 UINT g_iTaskbarCreated = ~0;    // for PCRaw (tray icon)
57
58 // PeerCast globals
59
60 static int currNotify=0;
61 String iniFileName;
62 HWND guiWnd;
63 HWND mainWnd;
64 static HMENU trayMenu = NULL,ltrayMenu = NULL;  // for PCRaw (tray icon)
65 bool showGUI=true;
66 bool allowMulti=false;
67 bool killMe=false;
68 bool allowTrayMenu=true;
69 static bool winDistinctionNT=false;
70 int             seenNewVersionTime=0;
71 HICON icon1,icon2;
72 ChanInfo chanInfo;
73 bool chanInfoIsRelayed;
74 //GnuID lastPlayID;
75 String exePath;
76 ULONG_PTR gdiplusToken;
77
78 // ---------------------------------
79 Sys * APICALL MyPeercastInst::createSys()
80 {
81         return new WSys(mainWnd);
82 }
83 // ---------------------------------
84 const char * APICALL MyPeercastApp ::getIniFilename()
85 {
86         return iniFileName.cstr();
87 }
88
89 // ---------------------------------
90 const char *APICALL MyPeercastApp ::getClientTypeOS() 
91 {
92         return PCX_OS_WIN32;
93 }
94
95 // ---------------------------------
96 const char * APICALL MyPeercastApp::getPath()
97 {
98         return exePath.cstr();
99 }
100
101 // --------------------------------- JP-EX
102 void    APICALL MyPeercastApp ::openLogFile()
103 {
104         logFile.openWriteReplace("log.txt");
105 }
106 // --------------------------------- JP-EX
107 void    APICALL MyPeercastApp ::getDirectory()
108 {
109         char path_buffer[256],drive[32],dir[128];
110         GetModuleFileName(NULL,path_buffer,255);
111         _splitpath(path_buffer,drive,dir,NULL,NULL);
112         sprintf(servMgr->modulePath,"%s%s",drive,dir);
113 }
114 // --------------------------------- JP-EX
115 bool    APICALL MyPeercastApp ::clearTemp()
116 {
117         if (servMgr->clearPLS)
118                 return true;
119
120         return false;
121 }
122
123
124 class NOTIFYICONDATA2
125 {
126 public:
127         DWORD cbSize; // DWORD
128         HWND hWnd; // HWND
129         UINT uID; // UINT
130         UINT uFlags; // UINT
131         UINT uCallbackMessage; // UINT
132         HICON hIcon; // HICON
133         char szTip[128]; // char[128]
134         DWORD dwState; // DWORD
135         DWORD dwStateMask; // DWORD
136         char szInfo[256]; // char[256]
137         UINT uTimeoutOrVersion; // UINT
138         char szInfoTitle[64]; // char[64]
139         DWORD dwInfoFlags; // DWORD
140         //GUID guidItem; > IE 6
141 };
142
143 NOTIFYICONDATA2 trayIcon;
144
145
146 // Global Variables:
147 HINSTANCE hInst;                                                                // current instance
148 TCHAR szTitle[MAX_LOADSTRING];                                                          // The title bar text
149 TCHAR szWindowClass[MAX_LOADSTRING];                                                            // The title bar text
150 TCHAR szWindowClass2[MAX_LOADSTRING];                                                           // The title bar text
151 TCHAR szWindowClass3[MAX_LOADSTRING];                                                           // The title bar text
152
153 // Foward declarations of functions included in this code module:
154 ATOM                            MyRegisterClass(HINSTANCE hInstance);
155 ATOM                            MyRegisterClass2(HINSTANCE hInstance);
156 ATOM                            MyRegisterClass3(HINSTANCE hInstance);
157 BOOL                            InitInstance(HINSTANCE, int);
158 LRESULT CALLBACK        WndProc(HWND, UINT, WPARAM, LPARAM);
159 LRESULT CALLBACK        About(HWND, UINT, WPARAM, LPARAM);
160 LRESULT CALLBACK        ChanInfoProc(HWND, UINT, WPARAM, LPARAM);
161
162 void setTrayIcon(int type, const char *,const char *,bool);
163 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt);
164
165
166 HWND chWnd=NULL;
167
168 bool gbGetFile = FALSE;
169 bool gbStart = FALSE;
170 time_t gtGetFile;
171 time_t gtStartTime;
172 // --------------------------------------------------
173 void LOG2(const char *fmt,...)
174 {
175         va_list ap;
176         va_start(ap, fmt);
177         char str[4096];
178         vsprintf(str,fmt,ap);
179         OutputDebugString(str);
180         va_end(ap);     
181 }
182
183
184
185 // ---------------------------------------
186 int APIENTRY WinMain(HINSTANCE hInstance,
187                      HINSTANCE hPrevInstance,
188                      LPSTR     lpCmdLine,
189                      int       nCmdShow)
190 {
191 #ifdef _DEBUG
192         // memory leak check
193         ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
194 #endif
195
196         char tmpURL[8192];
197         tmpURL[0]=0;
198         char *chanURL=NULL;
199
200         hInst = hInstance;
201
202         iniFileName.set(".\\peercast.ini");
203
204         WIN32_FIND_DATA fd; //JP-EX
205         HANDLE hFind; //JP-EX
206
207         OSVERSIONINFO osInfo; //JP-EX
208         osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
209         GetVersionEx(&osInfo);
210         if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
211                 winDistinctionNT = true;
212         else
213                 winDistinctionNT = false;
214
215         // off by default now
216         showGUI = false;
217
218         if (strlen(lpCmdLine) > 0)
219         {
220                 char *p;
221                 if ((p = strstr(lpCmdLine,"-inifile"))!=NULL) 
222                         iniFileName.setFromString(p+8);
223
224                 if (strstr(lpCmdLine,"-zen")) 
225                         showGUI = false;
226
227                 if (strstr(lpCmdLine,"-multi")) 
228                         allowMulti = true;
229
230                 if (strstr(lpCmdLine,"-kill")) 
231                         killMe = true;
232
233                 if ((p = strstr(lpCmdLine,"-url"))!=NULL)
234                 {
235                         p+=4;
236                         while (*p)
237                         {
238                                 if (*p=='"')
239                                 {
240                                         p++;
241                                         break;
242                                 }                               
243                                 if (*p != ' ')
244                                         break;
245                                 p++;
246                         }
247                         if (*p)
248                                 strncpy(tmpURL,p,sizeof(tmpURL)-1);
249                 }
250         }
251
252         // get current path
253         {
254                 exePath = iniFileName;
255                 char *s = exePath.cstr();
256                 char *end = NULL;
257                 while (*s)
258                 {
259                         if (*s++ == '\\')
260                                 end = s;
261                 }
262                 if (end)
263                         *end = 0;
264         }
265
266         
267         if (strnicmp(tmpURL,"peercast://",11)==0)
268         {
269                 if (strnicmp(tmpURL+11,"pls/",4)==0)
270                         chanURL = tmpURL+11+4;
271                 else
272                         chanURL = tmpURL+11;
273                 showGUI = false;
274         }
275
276
277         MSG msg;
278         HACCEL hAccelTable;
279
280         // Initialize global strings
281         //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
282         //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);
283
284         strcpy(szTitle,"PeerCast");
285         strcpy(szWindowClass,"PeerCast");
286         strcpy(szWindowClass2,"Main");
287         strcpy(szWindowClass3,"Start");
288
289         
290
291         if (!allowMulti)
292         {
293                 HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);
294                 
295                 if (GetLastError() == ERROR_ALREADY_EXISTS)
296                 {
297                         HWND oldWin = FindWindow(szWindowClass,NULL);
298                         if (oldWin)
299                         {
300                                                 SendMessage(oldWin,WM_SHOWGUI,0,0);
301                                 if (killMe)
302                                 {
303                                         SendMessage(oldWin,WM_DESTROY,0,0);
304                                         return 0;
305                                 }
306
307                                 if (chanURL)
308                                 {
309                                         COPYDATASTRUCT copy;
310                                         copy.dwData = WM_PLAYCHANNEL;
311                                         copy.cbData = strlen(chanURL)+1;                        // plus null term
312                                         copy.lpData = chanURL;
313                                         SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)&copy);
314                                 }else{
315                                         if (showGUI)
316                                                 SendMessage(oldWin,WM_SHOWGUI,0,0);
317                                 }
318                         }
319                         return 0;
320                 }
321         }
322
323         if (killMe)
324                 return 0;
325         
326         MyRegisterClass(hInstance);
327         MyRegisterClass2(hInstance);
328         MyRegisterClass3(hInstance);
329
330         // Perform application initialization:
331         if (!InitInstance (hInstance, nCmdShow)) 
332                 return FALSE;
333
334         peercastInst = new MyPeercastInst();
335         peercastApp = new MyPeercastApp();
336
337         peercastInst->init();
338
339         LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
340
341         if (peercastApp->clearTemp()) //JP-EX
342         {
343                 DeleteFile("play.pls");
344                 hFind = FindFirstFile("*.asx",&fd);
345                 if (hFind != INVALID_HANDLE_VALUE)
346                 {
347                         do
348                         {
349                                 DeleteFile((char *)&fd.cFileName);
350                         }
351                         while (FindNextFile(hFind,&fd));
352
353                         FindClose(hFind);
354                 }
355         }
356
357         if (chanURL)
358         {
359                 ChanInfo info;
360                 servMgr->procConnectArgs(chanURL,info);
361                 chanMgr->findAndPlayChannel(info,false);
362         }
363
364         struct tm t;
365         memset(&t,0,sizeof(t));
366         t.tm_year = 2007 - 1900;
367         t.tm_mon = 4 - 1;
368         t.tm_mday = 7;
369         t.tm_hour = 21;
370         t.tm_min = 0;
371         t.tm_sec = 0;
372         gtStartTime = ::mktime(&t);
373         t.tm_hour = 20;
374         t.tm_min = 50;
375         gtGetFile = ::mktime(&t);
376
377         if (gtStartTime > sys->getTime()){
378                 gbGetFile = TRUE;
379                 gbStart = TRUE;
380         }
381
382         hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);
383
384         // setup menu notifes
385         int mask = peercastInst->getNotifyMask();
386         if (mask & ServMgr::NT_PEERCAST)
387                 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
388         if (mask & ServMgr::NT_BROADCASTERS)
389                 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
390         if (mask & ServMgr::NT_TRACKINFO)
391                 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);
392
393         // Main message loop:
394         while (GetMessage(&msg, NULL, 0, 0)) 
395         {
396                 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
397                 {
398                         TranslateMessage(&msg);
399                         DispatchMessage(&msg);
400                 }
401         }
402
403     Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);
404
405         peercastInst->saveSettings();
406         peercastInst->quit();
407
408         Gdiplus::GdiplusShutdown(gdiplusToken);
409
410         return msg.wParam;
411 }
412
413
414
415 //
416 //  FUNCTION: MyRegisterClass()
417 //
418 //  PURPOSE: Registers the window class.
419 //
420 //  COMMENTS:
421 //
422 //    This function and its usage is only necessary if you want this code
423 //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
424 //    function that was added to Windows 95. It is important to call this function
425 //    so that the application will get 'well formed' small icons associated
426 //    with it.
427 //
428 ATOM MyRegisterClass(HINSTANCE hInstance)
429 {
430         WNDCLASSEX wcex;
431
432         wcex.cbSize = sizeof(WNDCLASSEX); 
433
434         wcex.style                      = CS_HREDRAW | CS_VREDRAW;
435         wcex.lpfnWndProc        = (WNDPROC)WndProc;
436         wcex.cbClsExtra         = 0;
437         wcex.cbWndExtra         = 0;
438         wcex.hInstance          = hInstance;
439         wcex.hIcon                      = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
440         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
441         wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
442 //      wcex.lpszMenuName       = (LPCSTR)IDC_SIMPLE;
443         wcex.lpszMenuName       = NULL;
444         wcex.lpszClassName      = szWindowClass;
445         wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
446
447         return RegisterClassEx(&wcex);
448 }
449
450 ATOM MyRegisterClass2(HINSTANCE hInstance)
451 {
452         WNDCLASSEX wcex;
453         
454         wcex.cbSize = sizeof(WNDCLASSEX); 
455
456         wcex.style                      = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
457         wcex.lpfnWndProc        = (WNDPROC)GUIProc;
458         wcex.cbClsExtra         = 0;
459         wcex.cbWndExtra         = 0;
460         wcex.hInstance          = hInstance;
461         wcex.hIcon                      = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
462         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
463         wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
464 //      wcex.lpszMenuName       = (LPCSTR)IDC_SIMPLE;
465         wcex.lpszMenuName       = NULL;
466         wcex.lpszClassName      = szWindowClass2;
467         wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
468
469         return RegisterClassEx(&wcex);
470 }
471
472 ATOM MyRegisterClass3(HINSTANCE hInstance)
473 {
474         WNDCLASSEX wcex;
475         
476         wcex.cbSize = sizeof(WNDCLASSEX); 
477
478         wcex.style                      = CS_HREDRAW | CS_VREDRAW;
479         wcex.lpfnWndProc        = (WNDPROC)StartProc;
480         wcex.cbClsExtra         = 0;
481         wcex.cbWndExtra         = 0;
482         wcex.hInstance          = hInstance;
483         wcex.hIcon                      = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
484         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
485         wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
486 //      wcex.lpszMenuName       = (LPCSTR)IDC_SIMPLE;
487         wcex.lpszMenuName       = NULL;
488         wcex.lpszClassName      = szWindowClass3;
489         wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
490
491         return RegisterClassEx(&wcex);
492 }
493
494 //-----------------------------
495 void loadIcons(HINSTANCE hInstance, HWND hWnd)
496 {
497         icon1 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL);
498         icon2 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL2);
499
500     trayIcon.cbSize = sizeof(trayIcon);
501     trayIcon.hWnd = hWnd;
502     trayIcon.uID = 100;
503     trayIcon.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
504     trayIcon.uCallbackMessage = WM_TRAYICON;
505     trayIcon.hIcon = icon1;
506     strcpy(trayIcon.szTip, "PeerCast");
507
508     Shell_NotifyIcon(NIM_ADD, (NOTIFYICONDATA*)&trayIcon);
509
510     //ShowWindow(hWnd, nCmdShow);
511     UpdateWindow(hWnd);
512
513         if(!trayMenu)   // for PCRaw (tray icon)
514                 trayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_TRAYMENU));
515         if(!ltrayMenu)  // for PCRaw (tray icon)
516                 ltrayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_LTRAYMENU));
517
518
519 }
520
521 //-----------------------------
522 //
523 //   FUNCTION: InitInstance(HANDLE, int)
524 //
525 //   PURPOSE: Saves instance handle and creates main window
526 //
527 //   COMMENTS:
528 //
529 //        In this function, we save the instance handle in a global variable and
530 //        create and display the main program window.
531 //
532 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
533 {
534         HWND hWnd;
535
536         hInst = hInstance; // Store instance handle in our global variable
537
538         hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
539           CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
540
541         if (!hWnd)
542         {
543           return FALSE;
544         }
545
546         mainWnd = hWnd;
547
548         g_iTaskbarCreated = RegisterWindowMessage("TaskbarCreated");    // for PCRaw (tray icon)
549
550         loadIcons(hInstance,hWnd);
551
552         using namespace Gdiplus;
553         GdiplusStartupInput gdiplusStartupInput;
554         GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
555
556         return TRUE;
557 }
558 //-----------------------------
559 //static String trackTitle;
560 //static String channelComment;
561
562 //-----------------------------
563 void channelPopup(const char *title, const char *msg, bool isPopup = true)
564 {
565         String both;
566
567         if (*title == '\0') return;
568         both.append(msg);
569         both.append(" (");
570         both.append(title);
571         both.append(")");
572
573         trayIcon.uFlags = NIF_ICON|NIF_TIP;
574         strncpy(trayIcon.szTip, both.cstr(),sizeof(trayIcon.szTip)-1);
575         trayIcon.szTip[sizeof(trayIcon.szTip)-1]=0;
576
577         if (isPopup) trayIcon.uFlags |= 16;
578         trayIcon.uTimeoutOrVersion = 10000;
579         strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
580         strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
581                 
582         Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
583 }
584 //-----------------------------
585 void clearChannelPopup()
586 {
587         trayIcon.uFlags = NIF_ICON|16;
588         trayIcon.uTimeoutOrVersion = 10000;
589     strncpy(trayIcon.szInfo,"",sizeof(trayIcon.szInfo)-1);
590         strncpy(trayIcon.szInfoTitle,"",sizeof(trayIcon.szInfoTitle)-1);
591         Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
592 }
593
594 //-----------------------------
595 // PopupEntry
596 struct PopupEntry {
597         GnuID id;
598         String name;
599         String track;
600         String comment;
601         PopupEntry *next;
602 };
603 static PopupEntry *PEList = NULL;
604 static WLock PELock;
605
606 static void putPopupEntry(PopupEntry *pe)
607 {
608         PELock.on();
609         pe->next = PEList;
610         PEList = pe;
611         PELock.off();
612 }
613
614 static PopupEntry *getPopupEntry(GnuID id)
615 {
616         PELock.on();
617         PopupEntry *pe = PEList;
618         PopupEntry *prev = NULL;
619         while (pe) {
620                 if (id.isSame(pe->id)) {
621                         if (prev) prev->next = pe->next;
622                         else PEList = pe->next;
623                         PELock.off();
624                         pe->next = NULL;
625                         return pe;
626                 }
627                 prev = pe;
628                 pe = pe->next;
629         }
630         PELock.off();
631         return NULL;
632 }
633
634 static PopupEntry *getTopPopupEntry()
635 {
636         PopupEntry *p = NULL;
637         PELock.on();
638         if (PEList) {
639                 p = PEList;
640                 PEList = PEList->next;
641         }
642         PELock.off();
643         return p;
644 }
645
646 //-----------------------------
647 void    APICALL MyPeercastApp::channelStart(ChanInfo *info)
648 {
649
650 //      lastPlayID = info->id;
651 //
652 //      if(!isIndexTxt(info))   // for PCRaw (popup)
653 //              clearChannelPopup();
654
655         PopupEntry *pe = getPopupEntry(info->id);
656         if (!pe) {
657                 pe = new PopupEntry;
658                 pe->id = info->id;
659         }
660         if (!isIndexTxt(info))
661                 putPopupEntry(pe);
662         else
663                 delete pe;
664 }
665 //-----------------------------
666 void    APICALL MyPeercastApp::channelStop(ChanInfo *info)
667 {
668 //      if (info->id.isSame(lastPlayID))
669 //      {
670 //              lastPlayID.clear();
671 //
672 //              if(!isIndexTxt(info))   // for PCRaw (popup)
673 //                      clearChannelPopup();
674 //      }
675
676         PopupEntry *pe = getPopupEntry(info->id);
677         if (pe) delete pe;
678
679         pe = getTopPopupEntry();
680         if (!pe) {
681                 clearChannelPopup();
682         } else {
683                 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
684                 {
685                         String name,track; //JP-Patch
686                         name = pe->name; //JP-Patch
687                         track = pe->track; //JP-Patch
688                         name.convertTo(String::T_SJIS); //JP-Patch
689                         track.convertTo(String::T_SJIS); //JP-Patch
690                         clearChannelPopup();
691                 //      channelPopup(info->name.cstr(),trackTitle.cstr());
692                         channelPopup(name.cstr(),track.cstr(), false); //JP-Patch
693                 }
694                 putPopupEntry(pe);
695         }
696 }
697 //-----------------------------
698 void    APICALL MyPeercastApp::channelUpdate(ChanInfo *info)
699 {
700         if (info)
701         {
702                 PopupEntry *pe = getPopupEntry(info->id);
703                 if (!pe) return;
704
705                 String tmp;
706                 tmp.append(info->track.artist);
707                 tmp.append(" ");
708                 tmp.append(info->track.title);
709
710
711                 if (!tmp.isSame(pe->track))
712                 {
713                         pe->name = info->name;
714                         pe->track = tmp;
715                         if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
716                         {
717                                 //trackTitle=tmp;
718                                 String name,track; //JP-Patch
719                                 name = info->name; //JP-Patch
720                                 track = tmp; //JP-Patch
721                                 name.convertTo(String::T_SJIS); //JP-Patch
722                                 track.convertTo(String::T_SJIS); //JP-Patch
723                                 if(!isIndexTxt(info))   // for PCRaw (popup)
724                                 {
725                                         clearChannelPopup();
726                                 //      channelPopup(info->name.cstr(),trackTitle.cstr());
727                                         channelPopup(name.cstr(),track.cstr()); //JP-Patch
728                                 }
729                         }
730                 } else if (!info->comment.isSame(pe->comment))
731                 {
732                         pe->name = info->name;
733                         pe->comment = info->comment;
734                         if (ServMgr::NT_BROADCASTERS & peercastInst->getNotifyMask())
735                         {
736                                 //channelComment = info->comment;
737                                 String name,comment; //JP-Patch
738                                 name = info->name; //JP-Patch
739                                 comment = info->comment; //JP-Patch
740                                 name.convertTo(String::T_SJIS); //JP-Patch
741                                 comment.convertTo(String::T_SJIS); //JP-Patch
742                                 if(!isIndexTxt(info))   // for PCRaw (popup)
743                                 {
744                                         clearChannelPopup();
745                                 //      channelPopup(info->name.cstr(),channelComment.cstr());
746                                         channelPopup(name.cstr(),comment.cstr());
747                                 }
748                         }
749                 }
750
751                 if (!isIndexTxt(info))
752                         putPopupEntry(pe);
753                 else
754                         delete pe;
755         }
756 }
757 //-----------------------------
758 void    APICALL MyPeercastApp::notifyMessage(ServMgr::NOTIFY_TYPE type, const char *msg)
759 {
760         currNotify = type;
761
762         if (type == ServMgr::NT_UPGRADE)
763         {
764             trayIcon.uFlags = NIF_ICON;
765             trayIcon.hIcon = icon2;
766         }else{
767             trayIcon.uFlags = NIF_ICON;
768             trayIcon.hIcon = icon1;
769         }
770
771         const char *title="";
772
773         switch(type)
774         {
775                 case ServMgr::NT_UPGRADE:
776                         title = "Upgrade alert";
777                         break;
778                 case ServMgr::NT_PEERCAST:
779                         title = "Message from PeerCast:";
780                         break;
781
782         }
783
784         if (type & peercastInst->getNotifyMask())
785         {
786                 trayIcon.uFlags |= 16;
787         trayIcon.uTimeoutOrVersion = 10000;
788         strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
789                 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
790             Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
791         }
792 }
793 //-----------------------------
794
795 // createGUI()
796 //
797 void createGUI(HWND hWnd)
798 {
799         if (!guiWnd){
800                 guiWnd = ::CreateWindow(szWindowClass2,
801                         "Peercast-IM@S",
802                         WS_OVERLAPPEDWINDOW & ~(WS_MAXIMIZEBOX) /*| WS_VSCROLL | WS_HSCROLL*/,
803                         0,
804                         0,
805                         800,
806                         600,
807                         NULL,
808                         NULL,
809                         hInst,
810                         NULL);
811         }
812         ShowWindow(guiWnd,SW_SHOWNORMAL);
813 }
814
815
816 // 
817 // addRelayedChannelsMenu(HMENU m)
818 // 
819 //
820 void addRelayedChannelsMenu(HMENU cm)
821 {
822         int cnt = GetMenuItemCount(cm);
823         for(int i=0; i<cnt-3; i++)
824                 DeleteMenu(cm,0,MF_BYPOSITION);
825
826         Channel *c = chanMgr->channel;
827         while(c)
828         {
829                 if (c->isActive())
830                 {
831                         char str[128],name[64];
832                         strncpy(name,c->info.name,32);
833                         name[32]=0;
834                         if (strlen(c->info.name) > 32)
835                                 strcat(name,"...");
836
837
838                         sprintf(str,"%s  (%d kb/s %s)",name,c->info.bitrate,ChanInfo::getTypeStr(c->info.contentType));
839                         //InsertMenu(cm,0,MF_BYPOSITION,RELAY_CMD+i,str);
840                 }
841                 c=c->next;
842         }
843 }
844
845 typedef int (*COMPARE_FUNC)(const void *,const void *);
846
847 static int compareHitLists(ChanHitList **c2, ChanHitList **c1)
848 {
849         return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
850 }
851
852 static int compareChannels(Channel **c2, Channel **c1)
853 {
854         return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
855 }
856
857 // 
858 // addAllChannelsMenu(HMENU m)
859 // 
860 //
861 void addAllChannelsMenu(HMENU cm)
862 {
863         int cnt = GetMenuItemCount(cm);
864 /*      for(int i=0; i<cnt-2; i++)
865                 DeleteMenu(cm,0,MF_BYPOSITION);*/
866
867         for(int i=0; i<cnt; i++)
868                 DeleteMenu(cm,0,MF_BYPOSITION);
869
870         HMENU yMenu = CreatePopupMenu();
871         if (!servMgr->rootHost2.isEmpty()){
872                 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES2,servMgr->rootHost2);
873         }
874         if (!servMgr->rootHost.isEmpty()){
875                 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES1,servMgr->rootHost);
876         }
877
878         InsertMenu(cm,0,MF_BYPOSITION|MF_POPUP,(UINT)yMenu,"\83C\83G\83\8d\81[\83y\81[\83W");
879         InsertMenu(cm,0,MF_BYPOSITION|MF_SEPARATOR,NULL,NULL);
880         // add channels to menu
881         int numActive=0;
882         Channel *ch = chanMgr->channel;
883         while(ch)
884         {
885                 char str[128],name[64];
886                 String sjis; //JP-Patch
887                 sjis = ch->info.name; //JP-Patch
888                 sjis.convertTo(String::T_SJIS); //JP-Patch
889                 strncpy(name,sjis.cstr(),32);
890                 //strncpy(name,ch->info.name,32);
891                 name[32]=0;
892                 //if (strlen(ch->info.name) > 32)
893                 if (strlen(sjis.cstr()) > 32) //JP-Patch
894                         strcat(name,"...");
895
896                 sprintf(str,"%s  (%d kb/s %s)",name,ch->info.bitrate,ChanInfo::getTypeStr(ch->info.contentType));
897
898                 HMENU opMenu = CreatePopupMenu();
899                 InsertMenu(opMenu,0,MF_BYPOSITION,INFO_CMD+numActive,"Info");
900                 if (ch->info.url.isValidURL())
901                         InsertMenu(opMenu,0,MF_BYPOSITION,URL_CMD+numActive,"URL");
902                 InsertMenu(opMenu,0,MF_BYPOSITION,PLAY_CMD+numActive,"Play");
903
904                 UINT fl = MF_BYPOSITION|MF_POPUP;
905                 if (ch)
906                         fl |= (ch->isPlaying()?MF_CHECKED:0);
907
908                 InsertMenu(cm,0,fl,(UINT)opMenu,str);
909                 
910                 numActive++;
911
912                 ch=ch->next;
913         }
914
915
916         //if (!numActive)
917         //              InsertMenu(cm,0,MF_BYPOSITION,0,"<No channels>");
918
919
920
921
922 }
923
924
925 // 
926 // flipNotifyPopup(id, flag)
927 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt)
928 {
929         int mask = peercastInst->getNotifyMask();
930
931         mask ^= nt;
932         if (mask & nt)
933                 CheckMenuItem(trayMenu,id,MF_CHECKED|MF_BYCOMMAND);
934         else
935                 CheckMenuItem(trayMenu,id,MF_UNCHECKED|MF_BYCOMMAND);
936
937         peercastInst->setNotifyMask(mask);
938         peercastInst->saveSettings();
939 }
940  
941
942 static void showHTML(const char *file)
943 {
944         char url[256];
945         sprintf(url,"%s/%s",servMgr->htmlPath,file);                                    
946
947 //      sys->callLocalURL(url,servMgr->serverHost.port);
948         sys->callLocalURL(url,  // for PCRaw (url)
949                 (servMgr->allowServer1&Servent::ALLOW_HTML)?(servMgr->serverHost.port):(servMgr->serverHost.port+1));
950 }
951
952 static ChanInfo getChannelInfo(int index)
953 {
954         Channel *c = chanMgr->findChannelByIndex(index);
955         if (c)
956                 return c->info;
957
958         ChanInfo info;
959         return info;
960 }
961
962 //
963 //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
964 //
965 //  PURPOSE:  Processes messages for the main window.
966 //
967 //  WM_COMMAND  - process the application menu
968 //  WM_PAINT    - Paint the main window
969 //  WM_DESTROY  - post a quit message and return
970 //
971 //
972 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
973 {
974         int wmId, wmEvent;
975         POINT point;
976         char buf[1024];
977
978         if(message == g_iTaskbarCreated)        // for PCRaw (tray icon)
979                 loadIcons(hInst, hWnd);
980  
981         switch (message) 
982         {
983                 case WM_SHOWGUI:
984                         createGUI(hWnd);
985                         break;
986
987
988                 case WM_TRAYICON:
989                         switch((UINT)lParam) 
990                         {
991                                 case WM_LBUTTONDOWN:
992                                         if (allowTrayMenu)
993                                                 SendMessage(hWnd,WM_SHOWMENU,2,0);
994                                         SetForegroundWindow(hWnd);    
995                                         break;
996                                 case WM_RBUTTONDOWN:
997                                         if (allowTrayMenu)
998                                                 SendMessage(hWnd,WM_SHOWMENU,1,0);
999                                         SetForegroundWindow(hWnd);    
1000                                         break;
1001                                 case WM_LBUTTONDBLCLK:
1002                                         createGUI(hWnd);
1003                                         break;
1004                         }
1005                         break;
1006
1007                 case WM_COPYDATA:
1008                         {
1009                                 COPYDATASTRUCT *pc = (COPYDATASTRUCT *)lParam;
1010                                 LOG_DEBUG("URL request: %s",pc->lpData);
1011                                 if (pc->dwData == WM_PLAYCHANNEL)
1012                                 {
1013                                         ChanInfo info;
1014                                         servMgr->procConnectArgs((char *)pc->lpData,info);
1015                                         chanMgr->findAndPlayChannel(info,false);
1016                                 }
1017                                 //sys->callLocalURL((const char *)pc->lpData,servMgr->serverHost.port);
1018                         }
1019                         break;
1020                 case WM_GETPORTNUMBER:
1021                         {
1022                                 int port;
1023                                 port=servMgr->serverHost.port;
1024                                 ReplyMessage(port);
1025                         }
1026                         break;
1027
1028                 case WM_SHOWMENU:
1029                         {
1030                                 if (servMgr->saveGuiPos){
1031                                         CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1032                                 } else {
1033                                         CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1034                                 }
1035
1036                                 SetForegroundWindow(hWnd);    
1037                                 bool skipMenu=false;
1038
1039                                 allowTrayMenu = false;
1040
1041                                 // check for notifications
1042                                 if (currNotify & ServMgr::NT_UPGRADE)
1043                                 {
1044                                         if (servMgr->downloadURL[0])
1045                                         {
1046                                                 if ((sys->getTime()-seenNewVersionTime) > (60*60))      // notify every hour
1047                                                 {
1048                                                         if (MessageBox(hWnd,"A newer version of PeerCast is available, press OK to upgrade.","PeerCast",MB_OKCANCEL|MB_APPLMODAL|MB_ICONEXCLAMATION) == IDOK)
1049                                                                 sys->getURL(servMgr->downloadURL);
1050
1051                                                         seenNewVersionTime=sys->getTime();
1052                                                         skipMenu=true;
1053                                                 }
1054                                         }
1055                                 }
1056
1057
1058                                 if (!skipMenu)
1059                                 {
1060                                         RECT rcWnd;
1061                                         HMENU menu;
1062                                         UINT flg = 0;
1063
1064                                         SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWnd, 0);
1065                                         GetCursorPos(&point);
1066
1067                                         if (point.x < rcWnd.left){
1068                                                 point.x = rcWnd.left;
1069                                                 flg |= TPM_LEFTALIGN;
1070                                         }
1071                                         if (point.x > rcWnd.right){
1072                                                 point.x = rcWnd.right;
1073                                                 flg |= TPM_RIGHTALIGN;
1074                                         }
1075                                         if (point.y < rcWnd.top){
1076                                                 point.y = rcWnd.top;
1077                                                 flg |= TPM_TOPALIGN;
1078                                         }
1079                                         if (point.y > rcWnd.bottom){
1080                                                 point.y = rcWnd.bottom;
1081                                                 flg |= TPM_BOTTOMALIGN;
1082                                         }
1083                                         if (flg == 0){
1084                                                 flg = TPM_RIGHTALIGN;
1085                                         }
1086
1087                                         switch (wParam)
1088                                         {
1089                                                 case 1:
1090                                                         menu = GetSubMenu(trayMenu,0);
1091                                                         addAllChannelsMenu(GetSubMenu(menu,0));
1092                                                         addRelayedChannelsMenu(GetSubMenu(menu,1));
1093                                                         break;
1094                                                 case 2:
1095                                                         menu = GetSubMenu(ltrayMenu,0);
1096                                                         addAllChannelsMenu(menu);
1097                                                         break;
1098                                         }
1099                                         if (!TrackPopupMenu(menu,flg,point.x,point.y,0,hWnd,NULL))
1100                                         {
1101                                                 LOG_ERROR("Can`t track popup menu: %d",GetLastError());
1102                                         }
1103                                         PostMessage(hWnd,WM_NULL,0,0); 
1104
1105                                 }
1106                                 allowTrayMenu = true;
1107                         }
1108                         break;
1109
1110                 case WM_CREATE:
1111                         if (showGUI)
1112                                 createGUI(hWnd);
1113                         break;
1114
1115                 case WM_COMMAND:
1116                         wmId    = LOWORD(wParam); 
1117                         wmEvent = HIWORD(wParam); 
1118
1119                         if ((wmId >= INFO_CMD) && (wmId < INFO_CMD+MAX_CHANNELS))
1120                         {
1121                                 int c = wmId - INFO_CMD;
1122                                 chanInfo = getChannelInfo(c);
1123                                 chanInfoIsRelayed = false;
1124                                 if (winDistinctionNT)
1125                                         DialogBox(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc);
1126                                 else
1127                                 {
1128                                         HWND WKDLG; //JP-Patch
1129                                         WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc); //JP-Patch
1130                                         ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1131                                 }
1132                                 return 0;
1133                         }
1134                         if ((wmId >= URL_CMD) && (wmId < URL_CMD+MAX_CHANNELS))
1135                         {
1136                                 int c = wmId - URL_CMD;
1137                                 chanInfo = getChannelInfo(c);
1138                                 if (chanInfo.url.isValidURL())
1139                                         sys->getURL(chanInfo.url);
1140                                 return 0;
1141                         }
1142                         if ((wmId >= PLAY_CMD) && (wmId < PLAY_CMD+MAX_CHANNELS))
1143                         {
1144                                 int c = wmId - PLAY_CMD;
1145                                 chanInfo = getChannelInfo(c);
1146                                 chanMgr->findAndPlayChannel(chanInfo,false);
1147                                 return 0;
1148                         }
1149                         if ((wmId >= RELAY_CMD) && (wmId < RELAY_CMD+MAX_CHANNELS))
1150                         {
1151                                 int c = wmId - RELAY_CMD;
1152                                 chanInfo = getChannelInfo(c);
1153                                 chanMgr->findAndPlayChannel(chanInfo,true);
1154                                 return 0;
1155                         }
1156
1157                         // Parse the menu selections:
1158                         switch (wmId)
1159                         {
1160                                 case ID_POPUP_SHOWMESSAGES_PEERCAST:
1161                                         flipNotifyPopup(ID_POPUP_SHOWMESSAGES_PEERCAST,ServMgr::NT_PEERCAST);
1162                                         break;
1163                                 case ID_POPUP_SHOWMESSAGES_BROADCASTERS:
1164                                         flipNotifyPopup(ID_POPUP_SHOWMESSAGES_BROADCASTERS,ServMgr::NT_BROADCASTERS);
1165                                         break;
1166                                 case ID_POPUP_SHOWMESSAGES_TRACKINFO:
1167                                         flipNotifyPopup(ID_POPUP_SHOWMESSAGES_TRACKINFO,ServMgr::NT_TRACKINFO);
1168                                         break;
1169
1170                                 case ID_POPUP_ABOUT:
1171                                 case IDM_ABOUT:
1172                                         DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
1173                                         break;
1174                                 case ID_POPUP_SHOWGUI:
1175                                 case IDM_SETTINGS_GUI:
1176                                 case ID_POPUP_ADVANCED_SHOWGUI:
1177                                 {
1178                                         createGUI(hWnd);
1179                                         break;
1180                                 }
1181                                 case ID_POPUP_YELLOWPAGES:
1182                                         sys->getURL("http://yp.peercast.org/");
1183                                         break;
1184                                 case ID_POPUP_YELLOWPAGES1:
1185                                         sprintf(buf, "http://%s",servMgr->rootHost.cstr());
1186                                         sys->getURL(buf);
1187                                         break;
1188                                 case ID_POPUP_YELLOWPAGES2:
1189                                         sprintf(buf, "http://%s",servMgr->rootHost2.cstr());
1190                                         sys->getURL(buf);
1191                                         break;
1192
1193                                 case ID_POPUP_ADVANCED_VIEWLOG:
1194                                         showHTML("viewlog.html");
1195                                         break;
1196                                 case ID_POPUP_ADVANCED_SAVESETTINGS:
1197                                         servMgr->saveSettings(iniFileName.cstr());
1198                                         break;
1199                                 case ID_POPUP_ADVANCED_INFORMATION:
1200                                         showHTML("index.html");
1201                                         break;
1202                                 case ID_FIND_CHANNELS:
1203                                 case ID_POPUP_ADVANCED_ALLCHANNELS:
1204                                 case ID_POPUP_UPGRADE:
1205                                         sys->callLocalURL("admin?cmd=upgrade",servMgr->serverHost.port);
1206                                         break;
1207                                 case ID_POPUP_ADVANCED_RELAYEDCHANNELS:
1208                                 case ID_POPUP_FAVORITES_EDIT:
1209                                         showHTML("relays.html");
1210                                         break;
1211                                 case ID_POPUP_ADVANCED_BROADCAST:
1212                                         showHTML("broadcast.html");
1213                                         break;
1214                                 case ID_POPUP_SETTINGS:
1215                                         showHTML("settings.html");
1216                                         break;
1217                                 case ID_POPUP_CONNECTIONS:
1218                                         showHTML("connections.html");
1219                                         break;
1220                                 case ID_POPUP_HELP:
1221                                         sys->getURL("http://www.peercast.org/help.php");
1222                                         break;
1223
1224                                 case ID_POPUP_SAVE_GUI_POS:
1225                                         if (servMgr->saveGuiPos){
1226                                                 servMgr->saveGuiPos = false;
1227                                                 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1228                                         } else {
1229                                                 servMgr->saveGuiPos = true;
1230                                                 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1231                                         }
1232                                         peercastInst->saveSettings();
1233                                         break;
1234
1235                                 case ID_POPUP_KEEP_DOWNSTREAMS:
1236                                         if (servMgr->keepDownstreams){
1237                                                 servMgr->keepDownstreams = false;
1238                                                 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_UNCHECKED|MF_BYCOMMAND);
1239                                         } else {
1240                                                 servMgr->keepDownstreams = true;
1241                                                 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_CHECKED|MF_BYCOMMAND);
1242                                         }
1243                                         //peercastInst->saveSettings();
1244                                         break;
1245
1246                                 case ID_POPUP_EXIT_CONFIRM:
1247                                 case IDM_EXIT:
1248                                    DestroyWindow(hWnd);
1249                                    break;
1250                                 default:
1251                                    return DefWindowProc(hWnd, message, wParam, lParam);
1252                         }
1253                         break;
1254                 case WM_DESTROY:
1255                         PostQuitMessage(0);
1256                         break;
1257                 default:
1258                         return DefWindowProc(hWnd, message, wParam, lParam);
1259    }
1260    return 0;
1261 }
1262 // Mesage handler for about box.
1263 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1264 {
1265         switch (message)
1266         {
1267                 case WM_INITDIALOG:
1268                         //SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENT);
1269 //                      SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTJP);
1270 #ifdef VERSION_EX
1271                         SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTEX);
1272 #else
1273                         SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTVP);
1274 #endif
1275                         return TRUE;
1276
1277                 case WM_COMMAND:
1278                         switch (LOWORD(wParam))
1279                         {
1280                                 case IDOK:
1281                                 case IDCANCEL:
1282                                         EndDialog(hDlg, LOWORD(wParam));
1283                                         return TRUE;
1284                                 case IDC_BUTTON1:
1285                                         sys->getURL("http://www.peercast.org");
1286                                         EndDialog(hDlg, LOWORD(wParam));
1287                                         return TRUE;
1288
1289                         }
1290                         break;
1291                 case WM_DESTROY:
1292                         break;
1293         }
1294     return FALSE;
1295 }
1296
1297 // Mesage handler for chaninfo box
1298 LRESULT CALLBACK ChanInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1299 {
1300         switch (message)
1301         {
1302                 case WM_INITDIALOG:
1303                         {
1304                                 char str[1024];
1305                                 //strcpy(str,chanInfo.track.artist.cstr());
1306                                 strcpy(str,chanInfo.track.artist); //JP-Patch
1307                                 strcat(str," - ");
1308                                 //strcat(str,chanInfo.track.title.cstr());
1309                                 strcat(str,chanInfo.track.title);
1310                                 String name,track,comment,desc,genre; //JP-Patch
1311                                 name = chanInfo.name; //JP-Patch
1312                                 track = str; //JP-Patch
1313                                 comment = chanInfo.comment; //JP-Patch
1314                                 desc = chanInfo.desc; //JP-Patc
1315                                 genre = chanInfo.genre; //JP-Patch
1316                                 name.convertTo(String::T_SJIS); //JP-Patc
1317                                 track.convertTo(String::T_SJIS); //JP-Patch
1318                                 comment.convertTo(String::T_SJIS); //JP-Patch
1319                                 desc.convertTo(String::T_SJIS); //JP-Patch
1320                                 genre.convertTo(String::T_SJIS); //JP-Patch
1321                                 
1322                                 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)chanInfo.name.cstr());
1323                                 SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)name.cstr()); //JP-Patch
1324                                 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)str);
1325                                 SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)track.cstr()); //JP-Patch
1326                                 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)chanInfo.comment.cstr());
1327                                 SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)comment.cstr()); //JP-Patch
1328                                 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)chanInfo.desc.cstr());
1329                                 SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)desc.cstr()); //JP-Patch
1330                                 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)chanInfo.genre.cstr());
1331                                 SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)genre.cstr()); //JP-Patch
1332
1333                                 sprintf(str,"%d kb/s %s",chanInfo.bitrate,ChanInfo::getTypeStr(chanInfo.contentType));
1334                                 SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LONG)str);
1335
1336
1337                                 if (!chanInfo.url.isValidURL())
1338                                         EnableWindow(GetDlgItem(hDlg,IDC_CONTACT),false);
1339
1340                                 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1341                                 if (ch)
1342                                 {
1343                                         SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)ch->getStatusStr());
1344                                         SendDlgItemMessage(hDlg, IDC_KEEP,BM_SETCHECK, ch->stayConnected, 0);
1345                                 }else
1346                                 {
1347                                         SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)"OK");
1348                                         EnableWindow(GetDlgItem(hDlg,IDC_KEEP),false);
1349                                 }
1350
1351
1352
1353                                 POINT point;
1354                                 RECT rect,drect;
1355                                 HWND hDsk = GetDesktopWindow();
1356                                 GetWindowRect(hDsk,&drect);
1357                                 GetWindowRect(hDlg,&rect);
1358                                 GetCursorPos(&point);
1359
1360                                 POINT pos,size;
1361                                 size.x = rect.right-rect.left;
1362                                 size.y = rect.bottom-rect.top;
1363
1364                                 if (point.x-drect.left < size.x)
1365                                         pos.x = point.x;
1366                                 else
1367                                         pos.x = point.x-size.x;
1368
1369                                 if (point.y-drect.top < size.y)
1370                                         pos.y = point.y;
1371                                 else
1372                                         pos.y = point.y-size.y;
1373
1374                                 SetWindowPos(hDlg,HWND_TOPMOST,pos.x,pos.y,size.x,size.y,0);
1375                                 chWnd = hDlg;
1376                         }
1377                         return TRUE;
1378
1379                 case WM_COMMAND:
1380                         {
1381                                 char str[1024],idstr[64];
1382                                 chanInfo.id.toStr(idstr);
1383
1384                                 switch (LOWORD(wParam))
1385                                 {
1386                                         case IDC_CONTACT:
1387                                         {
1388                                                 sys->getURL(chanInfo.url);
1389                                                 return TRUE;
1390                                         }
1391                                         case IDC_DETAILS:
1392                                         {
1393                                                 sprintf(str,"admin?page=chaninfo&id=%s&relay=%d",idstr,chanInfoIsRelayed);
1394                                                 sys->callLocalURL(str,servMgr->serverHost.port);
1395                                                 return TRUE;
1396                                         }
1397                                         case IDC_KEEP:
1398                                         {
1399                                                 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1400                                                 if (ch)
1401                                                         ch->stayConnected = SendDlgItemMessage(hDlg, IDC_KEEP,BM_GETCHECK, 0, 0) == BST_CHECKED;;
1402                                                 return TRUE;
1403                                         }
1404
1405
1406                                         case IDC_PLAY:
1407                                         {
1408                                                 chanMgr->findAndPlayChannel(chanInfo,false);
1409                                                 return TRUE;
1410                                         }
1411
1412                                 }
1413                         }
1414                         break;
1415
1416                 case WM_CLOSE:
1417                         if (winDistinctionNT)
1418                                 EndDialog(hDlg, 0);
1419                         else
1420                                 DestroyWindow(hDlg); //JP-Patch
1421                         break;
1422
1423                 case WM_ACTIVATE:
1424                         if (LOWORD(wParam) == WA_INACTIVE)
1425                                 if (winDistinctionNT)
1426                                         EndDialog(hDlg, 0);
1427                                 else
1428                                         DestroyWindow(hDlg); //JP-Patch
1429                         break;
1430                 case WM_DESTROY:
1431                         chWnd = NULL;
1432                         break;
1433
1434
1435         }
1436     return FALSE;
1437 }