1 // ------------------------------------------------
6 // Simple tray icon interface to PeerCast, mostly win32 related stuff.
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.
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 // ------------------------------------------------
29 #include "win32/wsys.h"
34 #include "chkMemoryLeak.h"
35 #define DEBUG_NEW new(__FILE__, __LINE__)
39 #define MAX_LOADSTRING 100
42 #define RELAY_CMD 8000
46 #define MAX_CHANNELS 999
50 void loadIcons(HINSTANCE hInstance, HWND hWnd);
53 UINT g_iTaskbarCreated = ~0; // for PCRaw (tray icon)
57 static int currNotify=0;
61 static HMENU trayMenu = NULL,ltrayMenu = NULL; // for PCRaw (tray icon)
63 bool allowMulti=false;
65 bool allowTrayMenu=true;
66 static bool winDistinctionNT=false;
67 int seenNewVersionTime=0;
70 bool chanInfoIsRelayed;
75 // ---------------------------------
76 Sys * APICALL MyPeercastInst::createSys()
78 return new WSys(mainWnd);
80 // ---------------------------------
81 const char * APICALL MyPeercastApp ::getIniFilename()
83 return iniFileName.cstr();
86 // ---------------------------------
87 const char *APICALL MyPeercastApp ::getClientTypeOS()
92 // ---------------------------------
93 const char * APICALL MyPeercastApp::getPath()
95 return exePath.cstr();
98 // --------------------------------- JP-EX
99 void APICALL MyPeercastApp ::openLogFile()
101 logFile.openWriteReplace("log.txt");
103 // --------------------------------- JP-EX
104 void APICALL MyPeercastApp ::getDirectory()
106 char path_buffer[256],drive[32],dir[128];
107 GetModuleFileName(NULL,path_buffer,255);
108 _splitpath(path_buffer,drive,dir,NULL,NULL);
109 sprintf(servMgr->modulePath,"%s%s",drive,dir);
111 // --------------------------------- JP-EX
112 bool APICALL MyPeercastApp ::clearTemp()
114 if (servMgr->clearPLS)
121 class NOTIFYICONDATA2
124 DWORD cbSize; // DWORD
128 UINT uCallbackMessage; // UINT
129 HICON hIcon; // HICON
130 char szTip[128]; // char[128]
131 DWORD dwState; // DWORD
132 DWORD dwStateMask; // DWORD
133 char szInfo[256]; // char[256]
134 UINT uTimeoutOrVersion; // UINT
135 char szInfoTitle[64]; // char[64]
136 DWORD dwInfoFlags; // DWORD
137 //GUID guidItem; > IE 6
140 NOTIFYICONDATA2 trayIcon;
144 HINSTANCE hInst; // current instance
145 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
146 TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
148 // Foward declarations of functions included in this code module:
149 ATOM MyRegisterClass(HINSTANCE hInstance);
150 BOOL InitInstance(HINSTANCE, int);
151 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
152 LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
153 LRESULT CALLBACK ChanInfoProc(HWND, UINT, WPARAM, LPARAM);
155 void setTrayIcon(int type, const char *,const char *,bool);
156 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt);
161 // --------------------------------------------------
162 void LOG2(const char *fmt,...)
167 vsprintf(str,fmt,ap);
168 OutputDebugString(str);
174 // ---------------------------------------
176 int APIENTRY WinMain(HINSTANCE hInstance,
177 HINSTANCE hPrevInstance,
183 ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
192 iniFileName.set(".\\peercast.ini");
194 WIN32_FIND_DATA fd; //JP-EX
195 HANDLE hFind; //JP-EX
197 OSVERSIONINFO osInfo; //JP-EX
198 osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
199 GetVersionEx(&osInfo);
200 if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
201 winDistinctionNT = true;
203 winDistinctionNT = false;
205 // off by default now
208 if (strlen(lpCmdLine) > 0)
211 if ((p = strstr(lpCmdLine,"-inifile"))!=NULL)
212 iniFileName.setFromString(p+8);
214 if (strstr(lpCmdLine,"-zen"))
217 if (strstr(lpCmdLine,"-multi"))
220 if (strstr(lpCmdLine,"-kill"))
223 if ((p = strstr(lpCmdLine,"-url"))!=NULL)
238 strncpy(tmpURL,p,sizeof(tmpURL)-1);
244 exePath = iniFileName;
245 char *s = exePath.cstr();
257 if (strnicmp(tmpURL,"peercast://",11)==0)
259 if (strnicmp(tmpURL+11,"pls/",4)==0)
260 chanURL = tmpURL+11+4;
270 // Initialize global strings
271 //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
272 //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);
274 strcpy(szTitle,"PeerCast");
275 strcpy(szWindowClass,"PeerCast");
279 HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);
281 if (GetLastError() == ERROR_ALREADY_EXISTS)
283 HWND oldWin = FindWindow(szWindowClass,NULL);
288 SendMessage(oldWin,WM_DESTROY,0,0);
295 copy.dwData = WM_PLAYCHANNEL;
296 copy.cbData = strlen(chanURL)+1; // plus null term
297 copy.lpData = chanURL;
298 SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)©);
301 SendMessage(oldWin,WM_SHOWGUI,0,0);
311 MyRegisterClass(hInstance);
313 // Perform application initialization:
314 if (!InitInstance (hInstance, nCmdShow))
317 peercastInst = new MyPeercastInst();
318 peercastApp = new MyPeercastApp();
320 peercastInst->init();
322 LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
324 if (peercastApp->clearTemp()) //JP-EX
326 DeleteFile("play.pls");
327 hFind = FindFirstFile("*.asx",&fd);
328 if (hFind != INVALID_HANDLE_VALUE)
332 DeleteFile((char *)&fd.cFileName);
334 while (FindNextFile(hFind,&fd));
343 servMgr->procConnectArgs(chanURL,info);
344 chanMgr->findAndPlayChannel(info,false);
348 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);
350 // setup menu notifes
351 int mask = peercastInst->getNotifyMask();
352 if (mask & ServMgr::NT_PEERCAST)
353 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
354 if (mask & ServMgr::NT_BROADCASTERS)
355 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
356 if (mask & ServMgr::NT_TRACKINFO)
357 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);
359 // Main message loop:
360 while (GetMessage(&msg, NULL, 0, 0))
362 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
364 TranslateMessage(&msg);
365 DispatchMessage(&msg);
369 Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);
371 peercastInst->saveSettings();
372 peercastInst->quit();
380 // FUNCTION: MyRegisterClass()
382 // PURPOSE: Registers the window class.
386 // This function and its usage is only necessary if you want this code
387 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
388 // function that was added to Windows 95. It is important to call this function
389 // so that the application will get 'well formed' small icons associated
392 ATOM MyRegisterClass(HINSTANCE hInstance)
396 wcex.cbSize = sizeof(WNDCLASSEX);
398 wcex.style = CS_HREDRAW | CS_VREDRAW;
399 wcex.lpfnWndProc = (WNDPROC)WndProc;
402 wcex.hInstance = hInstance;
403 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
404 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
405 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
406 wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
407 wcex.lpszClassName = szWindowClass;
408 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
410 return RegisterClassEx(&wcex);
414 //-----------------------------
415 void loadIcons(HINSTANCE hInstance, HWND hWnd)
417 icon1 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL);
418 icon2 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL2);
420 trayIcon.cbSize = sizeof(trayIcon);
421 trayIcon.hWnd = hWnd;
423 trayIcon.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
424 trayIcon.uCallbackMessage = WM_TRAYICON;
425 trayIcon.hIcon = icon1;
426 strcpy(trayIcon.szTip, "PeerCast");
428 Shell_NotifyIcon(NIM_ADD, (NOTIFYICONDATA*)&trayIcon);
430 //ShowWindow(hWnd, nCmdShow);
433 if(!trayMenu) // for PCRaw (tray icon)
434 trayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_TRAYMENU));
435 if(!ltrayMenu) // for PCRaw (tray icon)
436 ltrayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_LTRAYMENU));
441 //-----------------------------
443 // FUNCTION: InitInstance(HANDLE, int)
445 // PURPOSE: Saves instance handle and creates main window
449 // In this function, we save the instance handle in a global variable and
450 // create and display the main program window.
452 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
456 hInst = hInstance; // Store instance handle in our global variable
458 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
459 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
468 g_iTaskbarCreated = RegisterWindowMessage("TaskbarCreated"); // for PCRaw (tray icon)
470 loadIcons(hInstance,hWnd);
474 //-----------------------------
475 //static String trackTitle;
476 //static String channelComment;
478 //-----------------------------
479 void channelPopup(const char *title, const char *msg, bool isPopup = true)
483 if (*title == '\0') return;
489 trayIcon.uFlags = NIF_ICON|NIF_TIP;
490 strncpy(trayIcon.szTip, both.cstr(),sizeof(trayIcon.szTip)-1);
491 trayIcon.szTip[sizeof(trayIcon.szTip)-1]=0;
493 if (isPopup) trayIcon.uFlags |= 16;
494 trayIcon.uTimeoutOrVersion = 10000;
495 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
496 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
498 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
500 //-----------------------------
501 void clearChannelPopup()
503 trayIcon.uFlags = NIF_ICON|16;
504 trayIcon.uTimeoutOrVersion = 10000;
505 strncpy(trayIcon.szInfo,"",sizeof(trayIcon.szInfo)-1);
506 strncpy(trayIcon.szInfoTitle,"",sizeof(trayIcon.szInfoTitle)-1);
507 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
510 //-----------------------------
519 static PopupEntry *PEList = NULL;
522 static void putPopupEntry(PopupEntry *pe)
530 static PopupEntry *getPopupEntry(GnuID id)
533 PopupEntry *pe = PEList;
534 PopupEntry *prev = NULL;
536 if (id.isSame(pe->id)) {
537 if (prev) prev->next = pe->next;
538 else PEList = pe->next;
550 static PopupEntry *getTopPopupEntry()
552 PopupEntry *p = NULL;
556 PEList = PEList->next;
562 //-----------------------------
563 void APICALL MyPeercastApp::channelStart(ChanInfo *info)
566 // lastPlayID = info->id;
568 // if(!isIndexTxt(info)) // for PCRaw (popup)
569 // clearChannelPopup();
571 PopupEntry *pe = getPopupEntry(info->id);
576 if (!isIndexTxt(info))
581 //-----------------------------
582 void APICALL MyPeercastApp::channelStop(ChanInfo *info)
584 // if (info->id.isSame(lastPlayID))
586 // lastPlayID.clear();
588 // if(!isIndexTxt(info)) // for PCRaw (popup)
589 // clearChannelPopup();
592 PopupEntry *pe = getPopupEntry(info->id);
595 pe = getTopPopupEntry();
599 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
601 String name,track; //JP-Patch
602 name = pe->name; //JP-Patch
603 track = pe->track; //JP-Patch
604 name.convertTo(String::T_SJIS); //JP-Patch
605 track.convertTo(String::T_SJIS); //JP-Patch
607 // channelPopup(info->name.cstr(),trackTitle.cstr());
608 channelPopup(name.cstr(),track.cstr(), false); //JP-Patch
613 //-----------------------------
614 void APICALL MyPeercastApp::channelUpdate(ChanInfo *info)
618 PopupEntry *pe = getPopupEntry(info->id);
622 tmp.append(info->track.artist);
624 tmp.append(info->track.title);
627 if (!tmp.isSame(pe->track))
629 pe->name = info->name;
631 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
634 String name,track; //JP-Patch
635 name = info->name; //JP-Patch
636 track = tmp; //JP-Patch
637 name.convertTo(String::T_SJIS); //JP-Patch
638 track.convertTo(String::T_SJIS); //JP-Patch
639 if(!isIndexTxt(info)) // for PCRaw (popup)
642 // channelPopup(info->name.cstr(),trackTitle.cstr());
643 channelPopup(name.cstr(),track.cstr()); //JP-Patch
646 } else if (!info->comment.isSame(pe->comment))
648 pe->name = info->name;
649 pe->comment = info->comment;
650 if (ServMgr::NT_BROADCASTERS & peercastInst->getNotifyMask())
652 //channelComment = info->comment;
653 String name,comment; //JP-Patch
654 name = info->name; //JP-Patch
655 comment = info->comment; //JP-Patch
656 name.convertTo(String::T_SJIS); //JP-Patch
657 comment.convertTo(String::T_SJIS); //JP-Patch
658 if(!isIndexTxt(info)) // for PCRaw (popup)
661 // channelPopup(info->name.cstr(),channelComment.cstr());
662 channelPopup(name.cstr(),comment.cstr());
667 if (!isIndexTxt(info))
673 //-----------------------------
674 void APICALL MyPeercastApp::notifyMessage(ServMgr::NOTIFY_TYPE type, const char *msg)
676 static bool shownUpgradeAlert=false;
682 if (!shownUpgradeAlert)
684 trayIcon.uFlags = NIF_ICON;
686 if (type == ServMgr::NT_UPGRADE)
688 shownUpgradeAlert = true;
689 trayIcon.hIcon = icon2;
692 trayIcon.hIcon = icon1;
696 if (type == ServMgr::NT_UPGRADE)
700 const char *title="";
704 case ServMgr::NT_UPGRADE:
705 title = "Upgrade alert";
707 case ServMgr::NT_PEERCAST:
708 title = "Message from PeerCast:";
713 if (type & peercastInst->getNotifyMask())
715 trayIcon.uFlags |= 16;
716 trayIcon.uTimeoutOrVersion = 10000;
717 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
718 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
719 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
722 //-----------------------------
726 void createGUI(HWND hWnd)
729 guiWnd = CreateDialog(hInst, (LPCTSTR)IDD_MAINWINDOW, hWnd, (DLGPROC)GUIProc);
730 ShowWindow(guiWnd,SW_SHOWNORMAL);
735 // addRelayedChannelsMenu(HMENU m)
738 void addRelayedChannelsMenu(HMENU cm)
740 int cnt = GetMenuItemCount(cm);
741 for(int i=0; i<cnt-3; i++)
742 DeleteMenu(cm,0,MF_BYPOSITION);
744 Channel *c = chanMgr->channel;
749 char str[128],name[64];
750 strncpy(name,c->info.name,32);
752 if (strlen(c->info.name) > 32)
756 sprintf(str,"%s (%d kb/s %s)",name,c->info.bitrate,ChanInfo::getTypeStr(c->info.contentType));
757 //InsertMenu(cm,0,MF_BYPOSITION,RELAY_CMD+i,str);
763 typedef int (*COMPARE_FUNC)(const void *,const void *);
765 static int compareHitLists(ChanHitList **c2, ChanHitList **c1)
767 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
770 static int compareChannels(Channel **c2, Channel **c1)
772 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
776 // addAllChannelsMenu(HMENU m)
779 void addAllChannelsMenu(HMENU cm)
781 int cnt = GetMenuItemCount(cm);
782 /* for(int i=0; i<cnt-2; i++)
783 DeleteMenu(cm,0,MF_BYPOSITION);*/
785 for(int i=0; i<cnt; i++)
786 DeleteMenu(cm,0,MF_BYPOSITION);
788 HMENU yMenu = CreatePopupMenu();
789 if (!servMgr->rootHost2.isEmpty()){
790 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES2,servMgr->rootHost2);
792 if (!servMgr->rootHost.isEmpty()){
793 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES1,servMgr->rootHost);
796 InsertMenu(cm,0,MF_BYPOSITION|MF_POPUP,(UINT)yMenu,"
\83C
\83G
\83\8d\81[
\83y
\81[
\83W");
797 InsertMenu(cm,0,MF_BYPOSITION|MF_SEPARATOR,NULL,NULL);
798 // add channels to menu
800 Channel *ch = chanMgr->channel;
803 char str[128],name[64];
804 String sjis; //JP-Patch
805 sjis = ch->info.name; //JP-Patch
806 sjis.convertTo(String::T_SJIS); //JP-Patch
807 strncpy(name,sjis.cstr(),32);
808 //strncpy(name,ch->info.name,32);
810 //if (strlen(ch->info.name) > 32)
811 if (strlen(sjis.cstr()) > 32) //JP-Patch
814 sprintf(str,"%s (%d kb/s %s)",name,ch->info.bitrate,ChanInfo::getTypeStr(ch->info.contentType));
816 HMENU opMenu = CreatePopupMenu();
817 InsertMenu(opMenu,0,MF_BYPOSITION,INFO_CMD+numActive,"Info");
818 if (ch->info.url.isValidURL())
819 InsertMenu(opMenu,0,MF_BYPOSITION,URL_CMD+numActive,"URL");
820 InsertMenu(opMenu,0,MF_BYPOSITION,PLAY_CMD+numActive,"Play");
822 UINT fl = MF_BYPOSITION|MF_POPUP;
824 fl |= (ch->isPlaying()?MF_CHECKED:0);
826 InsertMenu(cm,0,fl,(UINT)opMenu,str);
835 // InsertMenu(cm,0,MF_BYPOSITION,0,"<No channels>");
844 // flipNotifyPopup(id, flag)
845 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt)
847 int mask = peercastInst->getNotifyMask();
851 CheckMenuItem(trayMenu,id,MF_CHECKED|MF_BYCOMMAND);
853 CheckMenuItem(trayMenu,id,MF_UNCHECKED|MF_BYCOMMAND);
855 peercastInst->setNotifyMask(mask);
856 peercastInst->saveSettings();
860 static void showHTML(const char *file)
863 sprintf(url,"%s/%s",servMgr->htmlPath,file);
865 // sys->callLocalURL(url,servMgr->serverHost.port);
866 sys->callLocalURL(url, // for PCRaw (url)
867 (servMgr->allowServer1&Servent::ALLOW_HTML)?(servMgr->serverHost.port):(servMgr->serverHost.port+1));
870 static ChanInfo getChannelInfo(int index)
872 Channel *c = chanMgr->findChannelByIndex(index);
881 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
883 // PURPOSE: Processes messages for the main window.
885 // WM_COMMAND - process the application menu
886 // WM_PAINT - Paint the main window
887 // WM_DESTROY - post a quit message and return
890 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
896 if(message == g_iTaskbarCreated) // for PCRaw (tray icon)
897 loadIcons(hInst, hWnd);
911 SendMessage(hWnd,WM_SHOWMENU,2,0);
912 SetForegroundWindow(hWnd);
916 SendMessage(hWnd,WM_SHOWMENU,1,0);
917 SetForegroundWindow(hWnd);
919 case WM_LBUTTONDBLCLK:
927 COPYDATASTRUCT *pc = (COPYDATASTRUCT *)lParam;
928 LOG_DEBUG("URL request: %s",pc->lpData);
929 if (pc->dwData == WM_PLAYCHANNEL)
932 servMgr->procConnectArgs((char *)pc->lpData,info);
933 chanMgr->findAndPlayChannel(info,false);
935 //sys->callLocalURL((const char *)pc->lpData,servMgr->serverHost.port);
938 case WM_GETPORTNUMBER:
941 port=servMgr->serverHost.port;
948 if (servMgr->saveGuiPos){
949 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
951 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
954 SetForegroundWindow(hWnd);
957 allowTrayMenu = false;
959 // check for notifications
960 if (currNotify & ServMgr::NT_UPGRADE)
962 if (servMgr->downloadURL[0])
964 if ((sys->getTime()-seenNewVersionTime) > (60*60)) // notify every hour
966 if (MessageBox(hWnd,"A newer version of PeerCast is available, press OK to upgrade.","PeerCast",MB_OKCANCEL|MB_APPLMODAL|MB_ICONEXCLAMATION) == IDOK)
967 sys->getURL(servMgr->downloadURL);
969 seenNewVersionTime=sys->getTime();
982 SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWnd, 0);
983 GetCursorPos(&point);
985 if (point.x < rcWnd.left){
986 point.x = rcWnd.left;
987 flg |= TPM_LEFTALIGN;
989 if (point.x > rcWnd.right){
990 point.x = rcWnd.right;
991 flg |= TPM_RIGHTALIGN;
993 if (point.y < rcWnd.top){
997 if (point.y > rcWnd.bottom){
998 point.y = rcWnd.bottom;
999 flg |= TPM_BOTTOMALIGN;
1002 flg = TPM_RIGHTALIGN;
1008 menu = GetSubMenu(trayMenu,0);
1009 addAllChannelsMenu(GetSubMenu(menu,0));
1010 addRelayedChannelsMenu(GetSubMenu(menu,1));
1013 menu = GetSubMenu(ltrayMenu,0);
1014 addAllChannelsMenu(menu);
1017 if (!TrackPopupMenu(menu,flg,point.x,point.y,0,hWnd,NULL))
1019 LOG_ERROR("Can`t track popup menu: %d",GetLastError());
1021 PostMessage(hWnd,WM_NULL,0,0);
1024 allowTrayMenu = true;
1034 wmId = LOWORD(wParam);
1035 wmEvent = HIWORD(wParam);
1037 if ((wmId >= INFO_CMD) && (wmId < INFO_CMD+MAX_CHANNELS))
1039 int c = wmId - INFO_CMD;
1040 chanInfo = getChannelInfo(c);
1041 chanInfoIsRelayed = false;
1042 if (winDistinctionNT)
1043 DialogBox(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc);
1046 HWND WKDLG; //JP-Patch
1047 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc); //JP-Patch
1048 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1052 if ((wmId >= URL_CMD) && (wmId < URL_CMD+MAX_CHANNELS))
1054 int c = wmId - URL_CMD;
1055 chanInfo = getChannelInfo(c);
1056 if (chanInfo.url.isValidURL())
1057 sys->getURL(chanInfo.url);
1060 if ((wmId >= PLAY_CMD) && (wmId < PLAY_CMD+MAX_CHANNELS))
1062 int c = wmId - PLAY_CMD;
1063 chanInfo = getChannelInfo(c);
1064 chanMgr->findAndPlayChannel(chanInfo,false);
1067 if ((wmId >= RELAY_CMD) && (wmId < RELAY_CMD+MAX_CHANNELS))
1069 int c = wmId - RELAY_CMD;
1070 chanInfo = getChannelInfo(c);
1071 chanMgr->findAndPlayChannel(chanInfo,true);
1075 // Parse the menu selections:
1078 case ID_POPUP_SHOWMESSAGES_PEERCAST:
1079 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_PEERCAST,ServMgr::NT_PEERCAST);
1081 case ID_POPUP_SHOWMESSAGES_BROADCASTERS:
1082 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_BROADCASTERS,ServMgr::NT_BROADCASTERS);
1084 case ID_POPUP_SHOWMESSAGES_TRACKINFO:
1085 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_TRACKINFO,ServMgr::NT_TRACKINFO);
1088 case ID_POPUP_ABOUT:
1090 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
1092 case ID_POPUP_SHOWGUI:
1093 case IDM_SETTINGS_GUI:
1094 case ID_POPUP_ADVANCED_SHOWGUI:
1099 case ID_POPUP_YELLOWPAGES:
1100 sys->getURL("http://yp.peercast.org/");
1102 case ID_POPUP_YELLOWPAGES1:
1103 sprintf(buf, "http://%s",servMgr->rootHost.cstr());
1106 case ID_POPUP_YELLOWPAGES2:
1107 sprintf(buf, "http://%s",servMgr->rootHost2.cstr());
1111 case ID_POPUP_ADVANCED_VIEWLOG:
1112 showHTML("viewlog.html");
1114 case ID_POPUP_ADVANCED_SAVESETTINGS:
1115 servMgr->saveSettings(iniFileName.cstr());
1117 case ID_POPUP_ADVANCED_INFORMATION:
1118 showHTML("index.html");
1120 case ID_FIND_CHANNELS:
1121 case ID_POPUP_ADVANCED_ALLCHANNELS:
1122 case ID_POPUP_UPGRADE:
1123 sys->callLocalURL("admin?cmd=upgrade",servMgr->serverHost.port);
1125 case ID_POPUP_ADVANCED_RELAYEDCHANNELS:
1126 case ID_POPUP_FAVORITES_EDIT:
1127 showHTML("relays.html");
1129 case ID_POPUP_ADVANCED_BROADCAST:
1130 showHTML("broadcast.html");
1132 case ID_POPUP_SETTINGS:
1133 showHTML("settings.html");
1135 case ID_POPUP_CONNECTIONS:
1136 showHTML("connections.html");
1139 sys->getURL("http://www.peercast.org/help.php");
1142 case ID_POPUP_SAVE_GUI_POS:
1143 if (servMgr->saveGuiPos){
1144 servMgr->saveGuiPos = false;
1145 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1147 servMgr->saveGuiPos = true;
1148 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1150 peercastInst->saveSettings();
1153 case ID_POPUP_KEEP_DOWNSTREAMS:
1154 if (servMgr->keepDownstreams){
1155 servMgr->keepDownstreams = false;
1156 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_UNCHECKED|MF_BYCOMMAND);
1158 servMgr->keepDownstreams = true;
1159 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_CHECKED|MF_BYCOMMAND);
1161 //peercastInst->saveSettings();
1164 case ID_POPUP_EXIT_CONFIRM:
1166 DestroyWindow(hWnd);
1169 return DefWindowProc(hWnd, message, wParam, lParam);
1176 return DefWindowProc(hWnd, message, wParam, lParam);
1180 // Mesage handler for about box.
1181 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1186 //SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENT);
1187 // SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTJP);
1188 //SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTVP);
1192 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LPARAM)PCX_AGENTEX); // x64
\91ÃŽ
\89\9e
1195 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTVP);
1201 switch (LOWORD(wParam))
1205 EndDialog(hDlg, LOWORD(wParam));
1208 sys->getURL("http://www.peercast.org");
1209 EndDialog(hDlg, LOWORD(wParam));
1220 // Mesage handler for chaninfo box
1221 LRESULT CALLBACK ChanInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1228 //strcpy(str,chanInfo.track.artist.cstr());
1229 strcpy(str,chanInfo.track.artist); //JP-Patch
1231 //strcat(str,chanInfo.track.title.cstr());
1232 strcat(str,chanInfo.track.title);
1233 String name,track,comment,desc,genre; //JP-Patch
1234 name = chanInfo.name; //JP-Patch
1235 track = str; //JP-Patch
1236 comment = chanInfo.comment; //JP-Patch
1237 desc = chanInfo.desc; //JP-Patc
1238 genre = chanInfo.genre; //JP-Patch
1239 name.convertTo(String::T_SJIS); //JP-Patc
1240 track.convertTo(String::T_SJIS); //JP-Patch
1241 comment.convertTo(String::T_SJIS); //JP-Patch
1242 desc.convertTo(String::T_SJIS); //JP-Patch
1243 genre.convertTo(String::T_SJIS); //JP-Patch
1245 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)chanInfo.name.cstr());
1246 SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)name.cstr()); //JP-Patch
1247 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)str);
1248 SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)track.cstr()); //JP-Patch
1249 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)chanInfo.comment.cstr());
1250 SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)comment.cstr()); //JP-Patch
1251 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)chanInfo.desc.cstr());
1252 SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)desc.cstr()); //JP-Patch
1253 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)chanInfo.genre.cstr());
1254 SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)genre.cstr()); //JP-Patch
1256 sprintf(str,"%d kb/s %s",chanInfo.bitrate,ChanInfo::getTypeStr(chanInfo.contentType));
1257 SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LONG)str);
1260 if (!chanInfo.url.isValidURL())
1261 EnableWindow(GetDlgItem(hDlg,IDC_CONTACT),false);
1263 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1266 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)ch->getStatusStr());
1267 SendDlgItemMessage(hDlg, IDC_KEEP,BM_SETCHECK, ch->stayConnected, 0);
1270 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)"OK");
1271 EnableWindow(GetDlgItem(hDlg,IDC_KEEP),false);
1278 HWND hDsk = GetDesktopWindow();
1279 GetWindowRect(hDsk,&drect);
1280 GetWindowRect(hDlg,&rect);
1281 GetCursorPos(&point);
1284 size.x = rect.right-rect.left;
1285 size.y = rect.bottom-rect.top;
1287 if (point.x-drect.left < size.x)
1290 pos.x = point.x-size.x;
1292 if (point.y-drect.top < size.y)
1295 pos.y = point.y-size.y;
1297 SetWindowPos(hDlg,HWND_TOPMOST,pos.x,pos.y,size.x,size.y,0);
1304 char str[1024],idstr[64];
1305 chanInfo.id.toStr(idstr);
1307 switch (LOWORD(wParam))
1311 sys->getURL(chanInfo.url);
1316 sprintf(str,"admin?page=chaninfo&id=%s&relay=%d",idstr,chanInfoIsRelayed);
1317 sys->callLocalURL(str,servMgr->serverHost.port);
1322 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1324 ch->stayConnected = SendDlgItemMessage(hDlg, IDC_KEEP,BM_GETCHECK, 0, 0) == BST_CHECKED;;
1331 chanMgr->findAndPlayChannel(chanInfo,false);
1340 if (winDistinctionNT)
1343 DestroyWindow(hDlg); //JP-Patch
1347 if (LOWORD(wParam) == WA_INACTIVE)
1348 if (winDistinctionNT)
1351 DestroyWindow(hDlg); //JP-Patch