summaryrefslogtreecommitdiff
path: root/plugins/Watrack/status
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Watrack/status')
-rw-r--r--plugins/Watrack/status/i_hotkey.inc62
-rw-r--r--plugins/Watrack/status/i_opt_11.inc459
-rw-r--r--plugins/Watrack/status/i_opt_12.inc108
-rw-r--r--plugins/Watrack/status/i_opt_3.inc106
-rw-r--r--plugins/Watrack/status/i_opt_status.inc49
-rw-r--r--plugins/Watrack/status/i_opt_tmpl.inc244
-rw-r--r--plugins/Watrack/status/i_st_rc.inc45
-rw-r--r--plugins/Watrack/status/i_st_vars.inc26
-rw-r--r--plugins/Watrack/status/i_status.inc223
-rw-r--r--plugins/Watrack/status/status.pas142
-rw-r--r--plugins/Watrack/status/status.rc88
-rw-r--r--plugins/Watrack/status/status.resbin0 -> 3092 bytes
-rw-r--r--plugins/Watrack/status/tmpl.pas304
13 files changed, 1856 insertions, 0 deletions
diff --git a/plugins/Watrack/status/i_hotkey.inc b/plugins/Watrack/status/i_hotkey.inc
new file mode 100644
index 0000000000..3ad23ae656
--- /dev/null
+++ b/plugins/Watrack/status/i_hotkey.inc
@@ -0,0 +1,62 @@
+{main hotkey code}
+function InsertProc(wParam:WPARAM;lParam:LPARAM):int_ptr; cdecl;
+var
+ CurWin:HWND;
+ s:pWideChar;
+ p:PAnsiChar;
+ isUnicode:boolean;
+ i:integer;
+ j:integer;
+ tt:tTemplateType;
+begin
+ result:=0;
+ if DisablePlugin=dsPermanent then
+ exit;
+ if Loword(LastStatus)<>WAT_PLS_NORMAL then
+ exit;
+// i:=CallService(MS_WAT_GETMUSICINFO,0,0);
+ if UseMessages=BST_CHECKED then
+ begin
+ CurWin:=GetFocus;
+ if CurWin<>0 then
+ begin
+// j:=WndToContact(WaitFocusedWndChild(GetForegroundwindow){GetFocus});
+ j:=WndToContact(CurWin);
+ p:=GetContactProtoAcc(j);
+// p:=PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,j,0));
+ if DBReadByte(j,p,'ChatRoom',0)=1 then
+ begin
+ isUnicode:=false;
+ tt:=tmpl_chat;
+ end
+ else
+ begin
+ isUnicode:=true;
+ tt:=tmpl_pm;
+ end;
+ if SimpleMode<>BST_UNCHECKED then
+ i:=0
+ else
+ i:=FindProto(p);
+ s:=GetMacros(tt,i);
+ // not empty and not disabled
+ if (s<>nil) and (uint_ptr(s)<>uint_ptr(-1)) then
+ begin
+ if StrScanW(s,'{')<>nil then
+ SendRTF(CurWin,s,isUnicode,UserCP)
+ else
+ begin
+ if isUnicode then
+ SendMessageW(CurWin,EM_REPLACESEL,0,tlparam(s))
+ else
+ begin
+ SendMessageA(CurWin,EM_REPLACESEL,0,tlparam(WideToAnsi(s,p,UserCP)));
+ mFreeMem(p);
+ end;
+ end;
+ mFreeMem(s);
+ end;
+ result:=1;
+ end;
+ end;
+end;
diff --git a/plugins/Watrack/status/i_opt_11.inc b/plugins/Watrack/status/i_opt_11.inc
new file mode 100644
index 0000000000..55279d3156
--- /dev/null
+++ b/plugins/Watrack/status/i_opt_11.inc
@@ -0,0 +1,459 @@
+{Templates}
+const
+ DLGED_INIT = $1000; // dialog init, not activate Apply button
+ DLGED_PROT = $0800; // proto changed
+ DLGED_STAT = $0400; // status changed
+ DLGED_PACK = $0200; // needed string packing
+ DLGED_CHGD = $0100; // something changed
+ DLGED_MSG = $0001; // message template changed
+ DLGED_STTT = $0004; // status template changed
+ DLGED_CHNL = $0008; // channel template changed
+ DLGED_XTTL = $0010; // xstatus title changed
+ DLGED_XTTT = $0020; // xstatus template changed
+ DLGED_TUNE = $0040; // tunes template changed
+ DLGED_BASE = DLGED_MSG +DLGED_STTT+DLGED_CHNL+
+ DLGED_TUNE+DLGED_XTTL+DLGED_XTTT;
+
+const
+ maxShowControls = 7;
+ aListFields:array [0..maxShowControls-1] of integer= (
+ IDC_STATUS_TEXT,
+ IDC_XSTATUS_TITLE, IDC_XSTATUS_TEXT,
+ IDC_LISTENING_TEXT,
+ IDC_STAT_ENABLE,IDC_XSTAT_ENABLE,IDC_TUNES_ENABLE);
+
+ aShowFields: array [0..2,0..maxShowControls-1] of integer = (
+{status} (SW_SHOW, SW_HIDE, SW_HIDE, SW_HIDE, SW_SHOW, SW_HIDE, SW_HIDE),
+{xstatus} (SW_HIDE, SW_SHOW, SW_SHOW, SW_HIDE, SW_HIDE, SW_SHOW, SW_HIDE),
+{tunes} (SW_HIDE, SW_HIDE, SW_HIDE, SW_SHOW, SW_HIDE, SW_HIDE, SW_SHOW));
+
+var
+ CurProto,
+ CurStatus:integer;
+
+procedure RedrawFields(Dialog:hwnd;proto:integer=-1);
+var
+ wnd1,wnd:HWND;
+ p:pWideChar;
+ i:integer;
+begin
+ Changed:=Changed or DLGED_INIT;
+ if proto<0 then
+ proto:=CurProto;
+
+ SetDlgItemTextW(Dialog,IDC_EDIT_MSG,
+ GetTemplateStr(tmpl_pm,proto,CurStatus));
+
+ p:=GetTemplateStr(tmpl_stext,proto,CurStatus);
+
+ wnd:=GetDlgItem(Dialog,IDC_STATUS_TEXT);
+
+ SendMessageW(wnd,WM_SETTEXT,0,lparam(p));
+ if IsTemplateActive(tmpl_stext,proto,CurStatus) then
+ begin
+ EnableWindow(wnd,true);
+ i:=BST_CHECKED;
+ end
+ else
+ begin
+ EnableWindow(wnd,false);
+ i:=BST_UNCHECKED;
+ end;
+ CheckDlgButton(Dialog,IDC_STAT_ENABLE,i);
+
+ if IsXStatusSupported(CurProto) then
+ begin
+ wnd :=GetDlgItem(Dialog,IDC_XSTATUS_TITLE);
+ wnd1:=GetDlgItem(Dialog,IDC_XSTATUS_TEXT);
+ p:=GetTemplateStr(tmpl_xtitle,proto,CurStatus);
+ SendMessageW(wnd ,WM_SETTEXT,0,lparam(p));
+ SendMessageW(wnd1,WM_SETTEXT,0,
+ lparam(GetTemplateStr(tmpl_xtext,proto,CurStatus)));
+
+ if IsTemplateActive(tmpl_xtitle,proto,CurStatus) then
+ begin
+ EnableWindow(wnd ,true);
+ EnableWindow(wnd1,true);
+ i:=BST_CHECKED;
+ end
+ else
+ begin
+ EnableWindow(wnd ,false);
+ EnableWindow(wnd1,false);
+ i:=BST_UNCHECKED;
+ end;
+ CheckDlgButton(Dialog,IDC_XSTAT_ENABLE,i);
+ end;
+
+ if IsTunesSupported(CurProto) then
+ begin
+ p:=GetTemplateStr(tmpl_tunes,proto,CurStatus);
+ wnd:=GetDlgItem(Dialog,IDC_LISTENING_TEXT);
+ SendMessageW(wnd,WM_SETTEXT,0,lparam(p));
+ if IsTemplateActive(tmpl_tunes,proto,CurStatus) then
+ begin
+ EnableWindow(wnd,true);
+ i:=BST_CHECKED;
+ end
+ else
+ begin
+ EnableWindow(wnd,false);
+ i:=BST_UNCHECKED;
+ end;
+ CheckDlgButton(Dialog,IDC_TUNES_ENABLE,i);
+ end;
+
+ if IsChatSupported(CurProto) then
+ SetDlgItemTextW(Dialog,IDC_EDIT_CHANNEL,
+ GetTemplateStr(tmpl_chat,proto,CurStatus));
+
+ Changed:=Changed and not DLGED_INIT;
+end;
+
+procedure SetScreenFull(Dialog:hwnd);
+var
+ show:integer;
+ buf:array [0..127] of AnsiChar;
+ endis:boolean;
+ wnd:HWND;
+begin
+ Changed:=Changed or DLGED_INIT;
+ CurStatus:=0;
+
+ CheckDlgButton(Dialog,IDC_IRC_USER ,BST_CHECKED);
+ CheckDlgButton(Dialog,IDC_IRC_CHANNEL,BST_UNCHECKED);
+ ShowWindow(GetDlgItem(Dialog,IDC_EDIT_MSG ),SW_SHOW);
+ ShowWindow(GetDlgItem(Dialog,IDC_EDIT_CHANNEL),SW_HIDE);
+
+ if IsChatSupported(CurProto) then
+ show:=SW_SHOW
+ else
+ show:=SW_HIDE;
+
+ ShowWindow(GetDlgItem(Dialog,IDC_IRC_USER ),show);
+ ShowWindow(GetDlgItem(Dialog,IDC_IRC_CHANNEL),show);
+
+// wnd:=GetDlgItem(Dialog,IDC_PROTOLIST);
+
+//!!!! SendMessage(wnd,CB_SETCURSEL,0,0); //???
+
+// SendMessageA(wnd,LVM_GETITEMTEXTA,);
+// ListView_GetItemTextA(wnd,CurProto,0,@buf,SizeOf(buf));
+
+ StrCopy(buf,GetProtoName(CurProto));
+ StrCat(buf,PS_ICQ_GETCUSTOMSTATUSICON);
+ endis:=ServiceExists(buf)<>0;
+
+ EnableWindow(GetDlgItem(Dialog,IDC_CBEX ),endis);
+ EnableWindow(GetDlgItem(Dialog,IDC_XSTAT_AUDIO),endis);
+ EnableWindow(GetDlgItem(Dialog,IDC_XSTAT_VIDEO),endis);
+ if endis then
+ begin
+ CheckDlgButton(Dialog,IDC_XSTAT_AUDIO,BST_CHECKED);
+ CheckDlgButton(Dialog,IDC_XSTAT_VIDEO,BST_UNCHECKED);
+ end;
+
+ wnd:=GetDlgItem(Dialog,IDC_STATUSLIST);
+ FillStatusList(CurProto,wnd,true);
+ SendMessage(wnd,CB_SETCURSEL,0,0);
+ RedrawFields(Dialog);
+end;
+
+procedure SetTemplate(Dialog:hwnd;idc:integer;Tmpl:tTemplateType);
+begin
+ SetTemplateStr (GetDlgText(Dialog,ABS(idc)),Tmpl,CurProto,CurStatus);
+ SetTemplateActive(idc>0 ,Tmpl,CurProto,CurStatus);
+end;
+
+procedure SaveChanges(Dialog:hwnd);
+var
+ i,j:integer;
+begin
+ if (Changed and DLGED_BASE)<>0 then
+ begin
+ if (Changed and DLGED_MSG )<>0 then SetTemplate(Dialog,IDC_EDIT_MSG ,tmpl_pm);
+ if (Changed and DLGED_CHNL)<>0 then SetTemplate(Dialog,IDC_EDIT_CHANNEL,tmpl_chat);
+
+
+ if (Changed and DLGED_STTT)<>0 then
+ begin
+ if IsDlgButtonChecked(Dialog,IDC_STAT_ENABLE)<>BST_UNCHECKED then
+ i:=IDC_STATUS_TEXT
+ else
+ i:=-IDC_STATUS_TEXT;
+ SetTemplate(Dialog,i,tmpl_stext);
+ end;
+
+ if (Changed and DLGED_TUNE)<>0 then
+ begin
+ if IsDlgButtonChecked(Dialog,IDC_TUNES_ENABLE)<>BST_UNCHECKED then
+ i:=IDC_LISTENING_TEXT
+ else
+ i:=-IDC_LISTENING_TEXT;
+ SetTemplate(Dialog,i,tmpl_tunes);
+ end;
+
+ if (Changed and (DLGED_XTTL or DLGED_XTTT))<>0 then
+ begin
+ if IsDlgButtonChecked(Dialog,IDC_XSTAT_ENABLE)<>BST_UNCHECKED then
+ begin
+ i:=IDC_XSTATUS_TITLE;
+ j:=IDC_XSTATUS_TEXT;
+ end
+ else
+ begin
+ i:=-IDC_XSTATUS_TITLE;
+ j:=-IDC_XSTATUS_TEXT;
+ end;
+ if (Changed and DLGED_XTTL)<>0 then SetTemplate(Dialog,i,tmpl_xtitle);
+ if (Changed and DLGED_XTTT)<>0 then SetTemplate(Dialog,j,tmpl_xtext);
+ end;
+
+ Changed:=Changed and (not DLGED_BASE);
+ end;
+end;
+
+function SaveCBExValue(Dialog:HWnd;direct:boolean):cardinal;
+var
+ wnd:HWND;
+ i,j,shift:cardinal;
+begin
+ wnd:=GetDlgItem(Dialog,IDC_CBEX);
+ i:=GetProtoSetting(CurProto,true);
+
+ if (IsDlgButtonChecked(Dialog,IDC_XSTAT_VIDEO)<>BST_UNCHECKED) xor direct then
+ shift:=0
+ else
+ shift:=8;
+
+ j:=SendMessage(wnd,CB_GETCURSEL,0,0);
+ i:=(i and ($FFFF0000 or ($FF shl (8-shift)))) or (j shl shift);
+
+ SetProtoSetting(CurProto,i,true);
+
+ result:=(i shr (8-shift)) and $FF;
+end;
+
+procedure FillCBType(Dialog:hwnd;proto:pAnsiChar=nil);
+var
+ wnd:HWND;
+ j:integer;
+begin
+ wnd:=GetDlgItem(Dialog,IDC_CBSTATYPE);
+ SendMessage(wnd,CB_RESETCONTENT,0,0);
+
+ CB_AddStrDataW(wnd,TranslateW('Status'),0);
+ if IsXStatusSupported(uint_ptr(proto)) then CB_AddStrDataW(wnd,TranslateW('XStatus'),1);
+ if IsTunesSupported (uint_ptr(proto)) then CB_AddStrDataW(wnd,TranslateW('Tunes' ),2);
+
+ SendMessage(wnd,CB_SETCURSEL,0,0);
+
+ for j:=0 to maxShowControls-1 do
+ ShowWindow(GetDlgItem(Dialog,aListFields[j]),aShowFields[0][j]);
+end;
+
+function DlgProcOptions11(Dialog:HWnd;hMessage:UINT;wParam:WPARAM;lParam:LPARAM):lresult; stdcall;
+var
+ Item:LV_ITEMA;
+ buf:array [0..127] of AnsiChar;
+ i,j:integer;
+ wnd:HWND;
+ b:boolean;
+begin
+ result:=0;
+ case hMessage of
+ WM_DESTROY: begin
+ ListView_SetImageList(GetDlgItem(Dialog,IDC_STATUSLIST),0,LVSIL_SMALL);
+ ListView_SetImageList(GetDlgItem(Dialog,IDC_PROTOLIST ),0,LVSIL_SMALL);
+ end;
+
+ WM_INITDIALOG: begin
+ TranslateDialogDefault(Dialog);
+ Changed:=DLGED_INIT;
+ FillProtoList(GetDlgItem(Dialog,IDC_PROTOLIST),true);
+ CurProto :=0;
+ SetScreenFull(Dialog);
+ FillCBType(Dialog,nil);
+ SendMessage(Dialog,WM_COMMAND,(CBN_SELCHANGE shl 16)+IDC_CBSTATYPE,
+ GetDlgItem(Dialog,IDC_CBSTATYPE));
+ result:=0;
+ Changed:=0;
+ end;
+
+ WM_COMMAND: begin
+ case wParam shr 16 of
+ EN_CHANGE: begin
+ if (Changed and DLGED_INIT)=0 then
+ begin
+ Changed:=Changed or DLGED_CHGD or DLGED_PACK;
+ case loword(wParam) of
+ IDC_EDIT_MSG : Changed:=Changed or DLGED_MSG;
+ IDC_EDIT_CHANNEL : Changed:=Changed or DLGED_CHNL;
+ IDC_STATUS_TEXT : Changed:=Changed or DLGED_STTT;
+ IDC_XSTATUS_TITLE : Changed:=Changed or DLGED_XTTL;
+ IDC_XSTATUS_TEXT : Changed:=Changed or DLGED_XTTT;
+ IDC_LISTENING_TEXT: Changed:=Changed or DLGED_TUNE;
+ end;
+ SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
+ end;
+ end;
+
+ CBN_SELCHANGE: begin
+ case loword(wParam) of
+ IDC_CBSTATYPE: begin
+ i:=CB_GetData(lParam);
+ for j:=0 to maxShowControls-1 do
+ ShowWindow(GetDlgItem(Dialog,aListFields[j]),aShowFields[i][j]);
+ end;
+
+ IDC_CBEX: begin
+ SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
+ end;
+ end;
+ end;
+
+ BN_CLICKED: begin
+ case LoWord(wParam) of
+ IDC_CMD_DEFAULT: begin
+ RedrawFields(Dialog,0);
+ Changed:=Changed or DLGED_CHGD or DLGED_BASE;
+ SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
+ end;
+ IDC_CMD_RESET: begin
+ RedrawFields(Dialog);
+ end;
+
+ IDC_STAT_ENABLE, IDC_XSTAT_ENABLE, IDC_TUNES_ENABLE: begin
+ case LoWord(wParam) of
+ IDC_STAT_ENABLE: begin
+ Changed:=Changed or DLGED_STTT;
+ EnableWindow(GetDlgItem(Dialog,IDC_STATUS_TEXT),
+ IsDlgButtonChecked(Dialog,IDC_STAT_ENABLE)<>BST_UNCHECKED);
+ end;
+ IDC_XSTAT_ENABLE: begin
+ b:=IsDlgButtonChecked(Dialog,IDC_XSTAT_ENABLE)<>BST_UNCHECKED;
+ EnableWindow(GetDlgItem(Dialog,IDC_XSTATUS_TITLE),b);
+ EnableWindow(GetDlgItem(Dialog,IDC_XSTATUS_TEXT ),b);
+ Changed:=Changed or DLGED_XTTL;
+ Changed:=Changed or DLGED_XTTT;
+ end;
+ IDC_TUNES_ENABLE: begin
+ Changed:=Changed or DLGED_TUNE;
+ EnableWindow(GetDlgItem(Dialog,IDC_LISTENING_TEXT),
+ IsDlgButtonChecked(Dialog,IDC_TUNES_ENABLE)<>BST_UNCHECKED);
+ end;
+ end;
+ SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
+ end;
+
+ IDC_XSTAT_VIDEO, IDC_XSTAT_AUDIO: begin
+ SendDlgItemMessage(Dialog,IDC_CBEX,CB_SETCURSEL,SaveCBExValue(Dialog,false),0);
+ end;
+ IDC_HELP_COLOR: begin
+ ShowColorHelpDlg(Dialog);
+ exit;
+ end;
+ IDC_HELP_FORMAT: begin
+ MessageBoxW(0,TranslateW(sFormatHelp),TranslateW('Format text Info'),0);
+ exit;
+ end;
+ IDC_HELP_VARIABLES: begin
+ CallService(MS_WAT_MACROHELP,Dialog,0);
+ exit;
+ end;
+ IDC_IRC_USER: begin
+// CheckDlgButton(Dialog,IDC_IRC_USER ,BST_CHECKED);
+// CheckDlgButton(Dialog,IDC_IRC_CHANNEL,BST_UNCHECKED);
+ ShowWindow(GetDlgItem(Dialog,IDC_EDIT_MSG ),SW_SHOW);
+ ShowWindow(GetDlgItem(Dialog,IDC_EDIT_CHANNEL),SW_HIDE);
+ end;
+ IDC_IRC_CHANNEL: begin
+// CheckDlgButton(Dialog,IDC_IRC_USER ,BST_UNCHECKED);
+// CheckDlgButton(Dialog,IDC_IRC_CHANNEL,BST_CHECKED);
+ ShowWindow(GetDlgItem(Dialog,IDC_EDIT_CHANNEL),SW_SHOW);
+ ShowWindow(GetDlgItem(Dialog,IDC_EDIT_MSG ),SW_HIDE);
+ end;
+ else
+ SaveChanges(Dialog); //??
+ end;
+ end;
+ end;
+
+ end;
+
+ WM_HELP: begin
+ case PHELPINFO(lParam).iCtrlId of
+ IDC_EDIT_MSG,IDC_EDIT_CHANNEL,IDC_XSTATUS_TITLE,
+ IDC_STATUS_TEXT,IDC_XSTATUS_TEXT,IDC_LISTENING_TEXT:
+ CallService(MS_WAT_MACROHELP,Dialog,0);
+ end;
+ end;
+
+ WM_NOTIFY: begin
+ if (Changed and DLGED_INIT)<>0 then
+ exit;
+ if integer(PNMLISTVIEW(lParam)^.hdr.code)=LVN_ITEMCHANGED then
+ begin
+ SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
+ if ((PNMLISTVIEW(lParam)^.uNewState and LVIS_FOCUSED)<>0) then
+ begin
+ SaveChanges(Dialog);
+
+ if PNMLISTVIEW(lParam)^.hdr.idFrom=IDC_PROTOLIST then
+ begin
+ CheckStatusList(GetDlgItem(Dialog,IDC_STATUSLIST),CurProto);
+ SaveCBExValue(Dialog,true);
+ CurProto:=PNMLISTVIEW(lParam)^.iItem;
+ SetScreenFull(Dialog);
+// ListView_GetItemTextA(PNMLISTVIEW(lParam)^.hdr.hwndFrom,CurProto,0,@buf,SizeOf(buf));
+ StrCopy(buf,GetProtoName(CurProto));
+ wnd:=GetDlgItem(Dialog,IDC_CBEX);
+ FillCBType(Dialog,buf);
+ if AddCBEx(wnd,buf)<>0 then
+ begin
+ i:=GetProtoSetting(CurProto,true);
+ SendMessage(wnd,CB_SETCURSEL,i and $FF,0);
+ end;
+ end
+
+ else //IDC_STATUSLIST
+ begin
+ Item.iItem:=PNMLISTVIEW(lParam)^.iItem;
+ Item.mask:=LVIF_PARAM;
+ SendMessageA(PNMLISTVIEW(lParam)^.hdr.hwndFrom,LVM_GETITEMA,0,tlparam(@Item));
+// ListView_GetItemA(PNMLISTVIEW(lParam)^.hdr.hwndFrom,Item);
+ CurStatus:=GetStatusNum(Item.lParam);
+ RedrawFields(Dialog);
+ end;
+ end
+
+ else if PNMLISTVIEW(lParam)^.uNewState<>0 then
+ begin
+ if PNMLISTVIEW(lParam)^.hdr.idFrom=IDC_PROTOLIST then
+ Changed:=Changed or DLGED_PROT or DLGED_CHGD
+ else
+ Changed:=Changed or DLGED_STAT or DLGED_CHGD;
+ end;
+ end
+
+ else if integer(PNMHdr(lParam)^.code)=PSN_APPLY then
+ begin
+ if (Changed and DLGED_PROT)<>0 then
+ begin
+ CheckProtoList(GetDlgItem(Dialog,IDC_PROTOLIST));
+ Changed:=Changed and not DLGED_PROT;
+ end;
+ if (Changed and DLGED_STAT)<>0 then
+ begin
+ CheckStatusList(GetDlgItem(Dialog,IDC_STATUSLIST),CurProto);
+ Changed:=Changed and not DLGED_STAT;
+ end;
+ SaveCBExValue(Dialog,true);
+ SaveChanges(Dialog);
+ SaveTemplates;
+ end;
+ end;
+ else
+ {result:=}DefWindowProc(Dialog,hMessage,wParam,lParam);
+ end;
+end;
diff --git a/plugins/Watrack/status/i_opt_12.inc b/plugins/Watrack/status/i_opt_12.inc
new file mode 100644
index 0000000000..7414ecf9d7
--- /dev/null
+++ b/plugins/Watrack/status/i_opt_12.inc
@@ -0,0 +1,108 @@
+{Templates}
+
+procedure SetScreenLite(Dialog:HWnd);
+var
+ p:pWideChar;
+begin
+ Changed:=Changed or DLGED_INIT;
+
+ p:=GetTemplateStr(tmpl_pm ,0,0);
+ SetDlgItemTextW(Dialog,IDC_EDIT_MSG ,p);
+ p:=GetTemplateStr(tmpl_xtitle,0,0);
+ SetDlgItemTextW(Dialog,IDC_XSTATUS_TITLE,p);
+ p:=GetTemplateStr(tmpl_stext ,0,0);
+ SetDlgItemTextW(Dialog,IDC_STATUS_TEXT ,p);
+ p:=GetTemplateStr(tmpl_chat ,0,0);
+ SetDlgItemTextW(Dialog,IDC_EDIT_CHANNEL ,p);
+
+ Changed:=Changed and not DLGED_INIT;
+end;
+
+procedure SetTemplateLite(Dialog:HWnd;idc:integer;Tmpl:tTemplateType);
+begin
+ SetTemplateStr(GetDlgText(Dialog,idc),Tmpl,0,0);
+end;
+
+procedure SaveChangesLite(Dialog:HWnd);
+begin
+ if (Changed and DLGED_BASE)<>0 then
+ begin
+ if (Changed and DLGED_MSG )<>0 then SetTemplateLite(Dialog,IDC_EDIT_MSG ,tmpl_pm);
+ if (Changed and DLGED_CHNL)<>0 then SetTemplateLite(Dialog,IDC_EDIT_CHANNEL,tmpl_chat);
+ if (Changed and DLGED_XTTL)<>0 then
+ begin
+ SetTemplateLite(Dialog,IDC_XSTATUS_TITLE,tmpl_xtitle);
+ end;
+ if (Changed and DLGED_STTT)<>0 then
+ begin
+ SetTemplateLite(Dialog,IDC_STATUS_TEXT,tmpl_stext);
+ SetTemplateLite(Dialog,IDC_STATUS_TEXT,tmpl_xtext);
+ SetTemplateLite(Dialog,IDC_STATUS_TEXT,tmpl_tunes);
+ end;
+
+ Changed:=Changed and (not DLGED_BASE);
+ SaveTemplates;
+ end;
+end;
+
+function DlgProcOptions12(Dialog:HWnd;hMessage:UINT;wParam:WPARAM;lParam:LPARAM):lparam; stdcall;
+begin
+ result:=0;
+ case hMessage of
+ WM_INITDIALOG: begin
+ TranslateDialogDefault(Dialog);
+ SetScreenLite(Dialog);
+ result:=0;
+ Changed:=0;
+ end;
+
+ WM_COMMAND: begin
+ if (Changed and DLGED_INIT)=0 then
+ begin
+ case wParam shr 16 of
+ EN_CHANGE: begin
+ Changed:=Changed or DLGED_CHGD or DLGED_PACK;
+ case loword(wParam) of
+ IDC_EDIT_MSG : Changed:=Changed or DLGED_MSG;
+ IDC_XSTATUS_TITLE : Changed:=Changed or DLGED_XTTL;
+ IDC_STATUS_TEXT : Changed:=Changed or DLGED_STTT;
+ IDC_EDIT_CHANNEL : Changed:=Changed or DLGED_CHNL;
+ end;
+ end;
+ BN_CLICKED: begin
+ case LoWord(wParam) of
+ IDC_CMD_RESET: begin
+ SetScreenLite(Dialog);
+ end;
+ IDC_HELP_COLOR: begin
+ ShowColorHelpDlg(Dialog);
+ exit;
+ end;
+ IDC_HELP_FORMAT: begin
+ MessageBoxW(0,TranslateW(sFormatHelp),TranslateW('Format text Info'),0);
+ exit;
+ end;
+ IDC_HELP_VARIABLES: begin
+ CallService(MS_WAT_MACROHELP,Dialog,0);
+ exit;
+ end;
+ end;
+ end;
+ else
+ exit;
+ end;
+ SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
+ end;
+ end;
+
+ WM_HELP: CallService(MS_WAT_MACROHELP,Dialog,0);
+
+ WM_NOTIFY: begin
+ if integer(PNMHdr(lParam)^.code)=PSN_APPLY then
+ SaveChangesLite(Dialog);
+ end;
+
+ else
+ {result:=}DefWindowProc(Dialog,hMessage,wParam,lParam);
+ end;
+end;
diff --git a/plugins/Watrack/status/i_opt_3.inc b/plugins/Watrack/status/i_opt_3.inc
new file mode 100644
index 0000000000..3defc68b54
--- /dev/null
+++ b/plugins/Watrack/status/i_opt_3.inc
@@ -0,0 +1,106 @@
+{format specific}
+
+function DlgProcOptions3(Dialog:HWnd;hMessage:UINT;wParam:WPARAM;lParam:LPARAM):lresult; stdcall;
+const
+ dlginit:boolean=false;
+var
+ wnd:HWND;
+ b:boolean;
+begin
+ result:=0;
+ case hMessage of
+ WM_INITDIALOG: begin
+ dlginit:=false;
+ TranslateDialogDefault(Dialog);
+
+ MakeHint(Dialog,IDC_SIMPLEMODE,
+ 'If this option is "ON", one templates will be used with all '+
+ 'protocols, protocol and player (media) statuses. Template option page will be '+
+ 'changed next time.');
+ CheckDlgButton(Dialog,IDC_SIMPLEMODE,SimpleMode);
+ MakeHint(Dialog,IDC_INDEPENDED,
+ 'If this option is "ON", XStatus doesn''t depend of protocol status.');
+ CheckDlgButton(Dialog,IDC_INDEPENDED,XIndepended);
+ MakeHint(Dialog,IDC_USESTATUS,
+ 'If this option is "ON", status text will be replaced by music info.');
+ CheckDlgButton(Dialog,IDC_USESTATUS,UseStatus);
+ MakeHint(Dialog,IDC_USEMSGS,
+ 'If this option is "ON", you can paste music info to your '+
+ 'message window pressing hotkey.');
+ CheckDlgButton(Dialog,IDC_USEMSGS,UseMessages);
+ MakeHint(Dialog,IDC_KEEPSTATUS,
+ 'If this option is "ON", XStatus not changed when player shutdowned.');
+ CheckDlgButton(Dialog,IDC_KEEPSTATUS,KeepStatus);
+ MakeHint(Dialog,IDC_CLEARXSTAT,
+ 'xStatus will cleared before text changing and restored with new text later.');
+ CheckDlgButton(Dialog,IDC_CLEARXSTAT,ClearXStat);
+ MakeHint(Dialog,IDC_EXTSTATUS,
+ 'If this option is "ON", XStatus will be changed to "Music" and '+
+ 'status text will be replaced by music info.');
+ CheckDlgButton(Dialog,IDC_EXTSTATUS ,UseExtStatus);
+ MakeHint(Dialog,IDC_LISTENINGTO,
+ 'If this option is "ON", "Listening To" protocol property will be filled '+
+ 'by music info.');
+ CheckDlgButton(Dialog,IDC_LISTENINGTO,UseListeningTo);
+
+ wnd:=GetDlgItem(Dialog,IDC_SETXSTATUS);
+// SendMessage(wnd,CB_RESETCONTENT,0,0);
+ CB_AddStrDataW(wnd,TranslateW('any XStatus is set' ),0,0);
+ CB_AddStrDataW(wnd,TranslateW('''Music'' status is set' ),1,1);
+ CB_AddStrDataW(wnd,TranslateW('XStatus is empty or ''Music'''),2,2);
+ CB_SelectData(wnd,XStatusSet);
+
+ SendMessage(Dialog,WM_COMMAND,(BN_CLICKED shl 16)+IDC_EXTSTATUS,
+ GetDlgItem(Dialog,IDC_EXTSTATUS));
+
+ dlginit:=true;
+ result:=0;
+ end;
+
+ WM_COMMAND: begin
+ if ((wParam shr 16)=BN_CLICKED) and (LoWord(wParam)=IDC_EXTSTATUS) then
+ begin
+ b:=IsDlgButtonchecked(Dialog,IDC_EXTSTATUS)<>BST_UNCHECKED;
+ EnableWindow(GetDlgItem(Dialog,IDC_INDEPENDED),b);
+ EnableWindow(GetDlgItem(Dialog,IDC_CLEARXSTAT),b);
+// EnableWindow(GetDlgItem(Dialog,IDC_OLDXSTATUS),b);
+// EnableWindow(GetDlgItem(Dialog,IDC_ONLYMUSIC ),b);
+ EnableWindow(GetDlgItem(Dialog,IDC_SETXSTATUS),b);
+ EnableWindow(GetDlgItem(Dialog,IDC_KEEPSTATUS),b);
+ end;
+
+ case wParam shr 16 of
+ CBN_SELCHANGE,
+ EN_CHANGE,
+ BN_CLICKED: SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
+ end;
+ result:=1;
+ end;
+
+ WM_NOTIFY: begin
+ if dlginit then
+ begin
+ case integer(PNMHdr(lParam)^.code) of
+ LVN_ITEMCHANGED: begin
+ SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
+ end;
+
+ PSN_APPLY: begin
+ SimpleMode :=IsDlgButtonChecked(Dialog,IDC_SIMPLEMODE);
+ XIndepended :=IsDlgButtonChecked(Dialog,IDC_INDEPENDED);
+ UseMessages :=IsDlgButtonChecked(Dialog,IDC_USEMSGS);
+ UseStatus :=IsDlgButtonChecked(Dialog,IDC_USESTATUS);
+ UseExtStatus :=IsDlgButtonChecked(Dialog,IDC_EXTSTATUS);
+ KeepStatus :=IsDlgButtonChecked(Dialog,IDC_KEEPSTATUS);
+ ClearXStat :=IsDlgButtonChecked(Dialog,IDC_CLEARXSTAT);
+ UseListeningTo:=IsDlgButtonChecked(Dialog,IDC_LISTENINGTO);
+ XStatusSet :=CB_GetData(GetDlgItem(Dialog,IDC_SETXSTATUS));
+ SaveOpt;
+ end;
+ end;
+ end;
+ end;
+ else
+ {result:=}DefWindowProc(Dialog,hMessage,wParam,lParam);
+ end;
+end;
diff --git a/plugins/Watrack/status/i_opt_status.inc b/plugins/Watrack/status/i_opt_status.inc
new file mode 100644
index 0000000000..09e0c208ce
--- /dev/null
+++ b/plugins/Watrack/status/i_opt_status.inc
@@ -0,0 +1,49 @@
+{}
+const
+ opt_ModStatus :PAnsiChar = 'module/statuses';
+
+ opt_UseStatus :PAnsiChar = 'usestatus';
+ opt_UseExtStat :PAnsiChar = 'useextstat';
+ opt_UseMsgs :PAnsiChar = 'usemsgs';
+ opt_XStatusSet :PAnsiChar = 'xstatusset';
+ opt_KeepStatus :PAnsiChar = 'keepstatus';
+ opt_Independed :PAnsiChar = 'independed';
+ opt_ClearXStat :PAnsiChar = 'clearxstat';
+ opt_SimplMode :PAnsiChar = 'simplemode';
+ opt_ListeningTo:PAnsiChar = 'listeningto';
+
+function GetModStatus:integer;
+begin
+ result:=DBReadByte(0,PluginShort,opt_ModStatus,1);
+end;
+
+procedure SetModStatus(stat:integer);
+begin
+ DBWriteByte(0,PluginShort,opt_ModStatus,stat);
+end;
+
+procedure LoadOpt;
+begin
+ SimpleMode :=DBReadByte(0,PluginShort,opt_SimplMode ,BST_CHECKED);
+ UseStatus :=DBReadByte(0,PluginShort,opt_UseStatus ,BST_CHECKED);
+ UseExtStatus :=DBReadByte(0,PluginShort,opt_UseExtStat ,BST_CHECKED);
+ UseMessages :=DBReadByte(0,PluginShort,opt_UseMsgs ,BST_CHECKED);
+ KeepStatus :=DBReadByte(0,PluginShort,opt_KeepStatus ,BST_UNCHECKED);
+ XIndepended :=DBReadByte(0,PluginShort,opt_Independed ,BST_CHECKED);
+ ClearXStat :=DBReadByte(0,PluginShort,opt_ClearXStat ,BST_UNCHECKED);
+ UseListeningTo:=DBReadByte(0,PluginShort,opt_ListeningTo,BST_UNCHECKED);
+ XStatusSet :=DBReadByte(0,PluginShort,opt_XStatusSet ,1);
+end;
+
+procedure SaveOpt;
+begin
+ DBWriteByte(0,PluginShort,opt_SimplMode ,SimpleMode);
+ DBWriteByte(0,PluginShort,opt_UseStatus ,UseStatus);
+ DBWriteByte(0,PluginShort,opt_UseExtStat ,UseExtStatus);
+ DBWriteByte(0,PluginShort,opt_UseMsgs ,UseMessages);
+ DBWriteByte(0,PluginShort,opt_KeepStatus ,KeepStatus);
+ DBWriteByte(0,PluginShort,opt_Independed ,XIndepended);
+ DBWriteByte(0,PluginShort,opt_ClearXStat ,ClearXStat);
+ DBWriteByte(0,PluginShort,opt_ListeningTo,UseListeningTo);
+ DBWriteByte(0,PluginShort,opt_XStatusSet ,XStatusSet);
+end;
diff --git a/plugins/Watrack/status/i_opt_tmpl.inc b/plugins/Watrack/status/i_opt_tmpl.inc
new file mode 100644
index 0000000000..9f5ea87907
--- /dev/null
+++ b/plugins/Watrack/status/i_opt_tmpl.inc
@@ -0,0 +1,244 @@
+{Save/load options}
+
+const
+ opt_numstr:PAnsiChar = 'template/numstr';
+const
+ ppref = 'proto/';
+ spref = 'strings/';
+
+procedure SaveTemplates;
+var
+ i,lProtoStatus:cardinal;
+ lTmplType:tTemplateType;
+ p:PAnsiChar;
+ buf:PAnsiChar;
+ NumProto:cardinal;
+ tmpl:pStrTemplate;
+ tmp:SmallInt;
+ setting:array [0..63] of AnsiChar;
+ pset:PAnsiChar;
+begin
+ DBWriteWord(0,PluginShort,opt_numstr,NumString);
+ StrCopy(setting,spref);
+ pset:=StrEnd(setting);
+ for i:=1 to NumString do
+ begin
+ IntToStr(pset,i);
+ DBWriteUnicode(0,PluginShort,setting,strings^[i].text);
+ end;
+
+ NumProto:=GetNumProto;
+ mGetMem(buf,16384);
+ for i:=0 to NumProto do
+ begin
+ pset:=StrCopyE(setting,ppref);
+ pset:=StrCopyE(pset,GetProtoName(i));
+
+ StrCopy(pset,'/XStatus');
+ DBWriteWord(0,PluginShort,setting,GetProtoSetting(i,true));
+ inc(pset);
+ if i<>0 then
+ begin
+ StrCopy(pset,'enabled');
+ DBWriteWord(0,PluginShort,setting,GetProtoSetting(i));
+ end;
+
+ p:=buf;
+ tmpl:=@StrTemplates^[i];
+ pset[3]:=#0;
+ for lProtoStatus:=0 to NumStatus-1 do
+ for lTmplType:=tmpl_first to tmpl_last do
+ begin
+ tmp:=tmpl^[lProtoStatus,lTmplType];
+ if tmp=0 then
+ begin
+ if p<>buf then
+ begin
+ p^:=',';
+ inc(p);
+ end;
+ p^:='0'; inc(p); // for compatibility
+ p^:=AnsiChar(lProtoStatus +ORD('0')); inc(p);
+ p^:=AnsiChar(ORD(lTmplType)+ORD('0')); inc(p);
+ end
+ else if (tmp<>0) and (tmp<>smallint(dubtmpl)) then
+ begin
+ pset[0]:='0'; // for compatibility
+ pset[1]:=AnsiChar(lProtoStatus +ORD('0'));
+ pset[2]:=AnsiChar(ORD(lTmplType)+ORD('0'));
+ DBWriteWord(0,PluginShort,setting,word(tmp));
+ end;
+ end;
+ if p<>buf then
+ begin
+ p^:=#0;
+ StrCopy(pset,'empty');
+ DBWriteString(0,PluginShort,setting,buf);
+ end;
+ end;
+ mFreeMem(buf);
+end;
+
+procedure InitDefault;
+var
+ tmpl:pStrTemplate;
+begin
+ NumString:=8;
+ mGetMem (strings ,SizeOf(tMyString)*NumString);
+ FillChar(strings^,SizeOf(tMyString)*NumString,0);
+
+ if isVarsInstalled then
+ begin
+ StrDupW(strings^[1].text,defAltTemplate);
+ StrDupW(strings^[4].text,defAltChannelText);
+ end
+ else
+ begin
+ StrDupW(strings^[1].text,defTemplate);
+ StrDupW(strings^[4].text,defChannelText);
+ end;
+ StrDupW(strings^[2].text,defStatusTitle);
+ StrDupW(strings^[3].text,defStatusText);
+
+ tmpl:=@StrTemplates^[DefaultTemplate];
+ if tmpl^[0,tmpl_first]=smallint(dubtmpl) then
+ begin
+ // music played
+ tmpl^[0,tmpl_pm ]:=1;
+ tmpl^[0,tmpl_chat ]:=4;
+ tmpl^[0,tmpl_xtitle]:=2;
+ tmpl^[0,tmpl_stext ]:=3;
+ tmpl^[0,tmpl_xtext ]:=3;
+ end;
+end;
+
+function EnumSettingsProc(const szSetting:PAnsiChar;lParam:LPARAM):int; cdecl;
+var
+ p:^PAnsiChar;
+ i:cardinal;
+ pp:AnsiChar;
+begin
+ if StrCmp(ppref,szSetting,Length(ppref))=0 then
+ begin
+ i:=StrLen(szSetting)+1;
+ pp:=szSetting[i-2];
+ if (pp>='0') and (pp<='9') then
+ begin
+ p:=pointer(lParam);
+ move(szSetting^,p^^,i);
+ inc(p^,i);
+ end;
+ end;
+ result:=0;
+end;
+
+function EnumTemplates:PAnsiChar;
+var
+ ces:TDBCONTACTENUMSETTINGS;
+ p:PAnsiChar;
+begin
+ mGetMem(result,16384);
+ result^:=#0;
+ p:=result;
+ ces.pfnEnumProc:=@EnumSettingsProc;
+ ces.lParam :=lparam(@p);
+ ces.szModule :=PluginShort;
+ ces.ofsSettings:=0;
+ CallService(MS_DB_CONTACT_ENUMSETTINGS,0,lparam(@ces));
+end;
+
+procedure LoadTemplates;
+var
+ buf:PAnsiChar;
+ lProtoStatus,i,j:cardinal;
+ lTmplType:tTemplateType;
+ p:PAnsiChar;
+ pc:PAnsiChar;
+ NumProto:cardinal;
+ tmpl:pStrTemplate;
+ setting:array [0..63] of AnsiChar;
+ pset:PAnsiChar;
+begin
+ NumString:=DBReadWord(0,PluginShort,opt_numstr,0);
+ if NumString>0 then
+ begin
+ mGetMem (strings ,SizeOf(tMyString)*NumString);
+ FillChar(strings^,SizeOf(tMyString)*NumString,0);
+ StrCopy(setting,spref);
+ pset:=StrEnd(setting);
+ for i:=1 to NumString do
+ begin
+ IntToStr(pset,i);
+ strings^[i].text:=DBReadUnicode(0,PluginShort,setting,nil);
+ end;
+
+ NumProto:=GetNumProto;
+ buf:=EnumTemplates;
+ for i:=0 to NumProto do
+ begin
+ pset:=StrCopyE(setting,ppref);
+ pset:=StrCopyE(pset,GetProtoName(i));
+
+ StrCopy(pset,'/XStatus');
+ j:=DBReadWord(0,PluginShort,setting,$080B);
+{!!
+ if j=0 then
+ j:=DefaultXStatus;
+}
+ SetProtoSetting(i,j,true);
+
+ inc(pset);
+ if i<>0 then
+ begin
+ StrCopy(pset,'enabled');
+ SetProtoSetting(i,DBReadWord(0,PluginShort,setting,psf_all));
+ end;
+
+ tmpl:=@StrTemplates^[i];
+ StrCopy(pset,'empty');
+ pc:=DBReadString(0,PluginShort,setting,nil);
+ if pc<>nil then
+ begin
+ p:=pc;
+ if (p^>='0') and (p^<='9') then
+ while p^<>#0 do
+ begin
+ lProtoStatus := ORD(p[1])-ORD('0');
+ lTmplType :=tTemplateType(ORD(p[2])-ORD('0'));
+ tmpl^[lProtoStatus,lTmplType]:=0;
+ inc(p,3);
+ if p^=',' then
+ inc(p);
+ end;
+ mFreeMem(pc);
+ end;
+
+ pc:=buf;
+ pset^:=#0;
+ j:=StrLen(setting);
+ pset[3]:=#0;
+ while pc^<>#0 do
+ begin
+ if StrCmp(pc,setting,j)=0 then // only proper proto
+ begin
+ pc:=StrEnd(pc);
+ lProtoStatus := ORD((pc-2)^)-ORD('0');
+ lTmplType :=tTemplateType(ORD((pc-1)^)-ORD('0'));
+
+ pset[0]:='0';
+ pset[1]:=AnsiChar(lProtoStatus +ORD('0'));
+ pset[2]:=AnsiChar(ORD(lTmplType)+ORD('0'));
+
+ tmpl^[lProtoStatus,lTmplType]:=
+ DBReadWord(0,PluginShort,setting,dubtmpl);
+ end
+ else
+ pc:=StrEnd(pc);
+ inc(pc);
+ end;
+ end;
+ mFreeMem(buf);
+ end
+ else
+ InitDefault;
+end;
diff --git a/plugins/Watrack/status/i_st_rc.inc b/plugins/Watrack/status/i_st_rc.inc
new file mode 100644
index 0000000000..c17768c2e7
--- /dev/null
+++ b/plugins/Watrack/status/i_st_rc.inc
@@ -0,0 +1,45 @@
+{DLG 1 - common}
+const
+ IDC_USEMSGS = 2025;
+ IDC_HOTKEYGLOB = 2026;
+ IDC_STAT_HOTKEY = 2027;
+ IDC_USESTATUS = 2028;
+ IDC_EXTSTATUS = 2029;
+// IDC_ONLYMUSIC = 2030;
+ IDC_KEEPSTATUS = 2031;
+ IDC_SIMPLEMODE = 2032;
+// IDC_NOTES = 2033;
+ IDC_INDEPENDED = 2034;
+// IDC_OLDXSTATUS = 2035;
+ IDC_CLEARXSTAT = 2036;
+ IDC_LISTENINGTO = 2037;
+
+ IDC_SETXSTATUS = 2030;
+
+{DLG 2 - templates}
+const
+ IDC_HELP_FORMAT = 1025;
+ IDC_HELP_COLOR = 1027;
+ IDC_HELP_VARIABLES = 1028;
+ {special}
+ IDC_EDIT_MSG = 2032;
+ IDC_STATUS_TEXT = 2034;
+ IDC_EDIT_CHANNEL = 2035;
+ IDC_XSTATUS_TITLE = 2036;
+ IDC_XSTATUS_TEXT = 2037;
+ IDC_LISTENING_TEXT = 2038;
+ IDC_STAT_ENABLE = 2039;
+ IDC_CBSTATYPE = 2040;
+ IDC_XSTAT_ENABLE = 2041;
+ IDC_TUNES_ENABLE = 2042;
+
+ IDC_PROTOLIST = 1037;
+ IDC_STATUSLIST = 1038;
+ IDC_IRC_CHANNEL = 1041;
+ IDC_IRC_USER = 1042;
+ IDC_CMD_RESET = 1044;
+ IDC_CMD_DEFAULT = 1045;
+
+ IDC_CBEX = 1046;
+ IDC_XSTAT_VIDEO = 1047;
+ IDC_XSTAT_AUDIO = 1048;
diff --git a/plugins/Watrack/status/i_st_vars.inc b/plugins/Watrack/status/i_st_vars.inc
new file mode 100644
index 0000000000..e1696c3621
--- /dev/null
+++ b/plugins/Watrack/status/i_st_vars.inc
@@ -0,0 +1,26 @@
+{}
+const
+{
+ OldStatusText:array [0..15] of pWideChar =
+ (nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil);
+}
+ OldXStatus:array [0..31] of byte =
+ (255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255);
+var
+ UseListeningTo:cardinal;
+ SimpleMode :cardinal;
+ UseStatus :cardinal;
+ UseExtStatus :cardinal;
+ UseMessages :cardinal;
+ KeepStatus :cardinal;
+ XIndepended :cardinal;
+ XStatusSet :cardinal;
+ ClearXStat :cardinal;
+ hINS :THANDLE;
+// hLTo :THANDLE;
+ plStatusHook :THANDLE;
+
+const
+ Changed:cardinal=0;
+ LastStatus:integer=WAT_PLS_NOTFOUND;
diff --git a/plugins/Watrack/status/i_status.inc b/plugins/Watrack/status/i_status.inc
new file mode 100644
index 0000000000..a7e3d2e5ef
--- /dev/null
+++ b/plugins/Watrack/status/i_status.inc
@@ -0,0 +1,223 @@
+{Status and XStatus processing}
+
+// XStatus
+const
+ xsnum = 31;
+
+function ListenProc(wParam:WPARAM;lParam:LPARAM):int_ptr; cdecl;
+begin
+ // ignoring incoming ListeningTo info, uses internal
+ if PLISTENINGTOINFO(lParam).cbSize=SizeOf(TLISTENINGTOINFO) then
+ begin
+ result:=int_ptr(GetMacros(tmpl_tunes,0)); // need real proto number here
+ if result=-1 then result:=0;
+ end
+ else
+ begin
+ result:=CallService(MS_WAT_REPLACETEXT,0,wParam);
+ end;
+end;
+
+function IsOurStatus(protomask,status:dword):boolean;
+var
+ mask:dword;
+begin
+{ if status=ID_STATUS_OFFLINE then mask:=M_STAT_OFFLINE
+ else }
+ if status=ID_STATUS_ONLINE then mask:=psf_online
+ else if status=ID_STATUS_INVISIBLE then mask:=psf_invisible
+ else if status=ID_STATUS_AWAY then mask:=psf_shortaway
+ else if status=ID_STATUS_NA then mask:=psf_longaway
+ else if status=ID_STATUS_DND then mask:=psf_heavydnd
+ else if status=ID_STATUS_OCCUPIED then mask:=psf_lightdnd
+ else if status=ID_STATUS_FREECHAT then mask:=psf_freechat
+ else if status=ID_STATUS_ONTHEPHONE then mask:=psf_onthephone
+ else if status=ID_STATUS_OUTTOLUNCH then mask:=psf_outtolunch
+ else mask:=0;
+ result:=(protomask and mask)<>0;
+end;
+
+function NewPlStatus(wParam:WPARAM;lParam:LPARAM):int;cdecl;
+var
+ si:pSongInfo;
+ i,j:integer;
+ xstat:integer;
+ txt,title:pWideChar;
+ proto,ls:PAnsiChar;
+ mask,status:dword;
+ todo,isvideo:bool;
+ oldstatus:integer;
+ staudio,stvideo:integer;
+ lti:TLISTENINGTOINFO;
+ buf,buf1:array [0..31] of WideChar;
+ doClear:boolean;
+begin
+ result:=0;
+ si:=pSongInfo(lParam);
+
+ case wParam of
+ WAT_EVENT_NEWTRACK: begin
+ isvideo:=pSongInfo(lParam)^.width<>0;
+ doClear:=false;
+ end;
+
+ WAT_EVENT_PLAYERSTATUS: begin
+ LastStatus:=lParam;
+ if (loword(lParam)=WAT_PLS_NORMAL) then
+ exit;
+ doClear:=true;
+ end;
+ else
+ exit; // not accept template changes
+ end;
+
+ i:=GetNumProto;
+ for j:=1 to i do
+ begin
+ proto:=GetProtoName(j);
+ mask:=GetProtoSetting(j);
+
+ if (SimpleMode<>BST_UNCHECKED) or ((mask and psf_enabled)<>0) then
+ begin
+
+ if (UseStatus<>BST_UNCHECKED) or (UseExtStatus<>BST_UNCHECKED) then
+ begin
+ status:=CallProtoService(proto,PS_GETSTATUS,0,0);
+ todo :=(SimpleMode<>BST_UNCHECKED) or IsOurStatus(mask,status);
+ end
+ else
+ begin
+ status:=ID_STATUS_ONLINE;
+ todo :=true;
+ end;
+
+ if (UseListeningTo<>BST_UNCHECKED) and
+ IsTunesSupported(j) then
+// (ProtoServiceExists(proto,PS_SET_LISTENINGTO)<>0) then
+ begin
+ if doClear then
+ CallProtoService(proto,PS_SET_LISTENINGTO,0,0)
+ else if (wParam=WAT_EVENT_NEWTRACK) then
+ begin
+ lti.cbSize :=SizeOf(lti);
+ if si.width<>0 then
+ lti.szType.W:='Video'
+ else
+ lti.szType.W:='Music';
+ lti.szArtist.W:=si.artist;
+ lti.szAlbum .W:=si.album;
+ lti.szTitle .W:=si.title;
+ lti.szTrack .W:=IntToStr(buf1,si.track);
+ lti.szYear .W:=si.year;
+ lti.szGenre .W:=si.genre;
+ lti.szLength.W:=IntToStr(buf,si.total);
+ lti.szPlayer.W:=si.player;
+ lti.dwFlags :=LTI_UNICODE;
+
+ CallProtoService(proto,PS_SET_LISTENINGTO,0,tlparam(@lti));
+ end;
+ end;
+
+ if UseStatus<>BST_UNCHECKED then
+ if todo then
+ begin
+ if SimpleMode<>BST_UNCHECKED then
+ txt:=GetMacros(tmpl_stext,0)
+ else
+ txt:=GetMacros(tmpl_stext,j);
+ if uint_ptr(txt)<>uint_ptr(-1) then
+ begin
+ if (txt=nil) or (txt^=#0) then
+ ls:=nil
+ else
+ WideToAnsi(txt,ls,UserCP);
+ SetStatus(proto,-status,ls);
+ mFreeMem(ls);
+ mFreeMem(txt);
+ end;
+ end;
+
+ if UseExtStatus<>BST_UNCHECKED then
+ begin
+ if todo or (XIndepended<>BST_UNCHECKED) then
+ begin
+ if IsXStatusSupported(j) then
+ begin
+ if doClear then // player status changed to no music/no player
+ begin
+
+ if KeepStatus=BST_UNCHECKED then
+ begin
+ // just restoring savedstatus if was. no text changing
+ if OldXStatus[j]<>255 then
+ begin
+ oldstatus:=OldXStatus[j];
+ OldXStatus[j]:=255;
+ SetXStatus(proto,oldstatus,pWideChar(-1),pWideChar(-1));
+ end;
+ end;
+
+ end
+ else
+ begin
+ if SimpleMode<>BST_UNCHECKED then
+ txt:=GetMacros(tmpl_xtext,0)
+ else
+ txt:=GetMacros(tmpl_xtext,j);
+ if uint_ptr(txt)<>uint_ptr(-1) then // status template presents
+ begin
+ // XStatus for audio/video
+ if SimpleMode<>BST_UNCHECKED then
+ begin
+ stvideo := 8;
+ staudio := 11;
+ end
+ else
+ begin
+ mask:=GetProtoSetting(j,true);
+ staudio:=mask and $FF;
+ stvideo:=(mask shr 8) and $FF;
+ end;
+ // Check, what we able to do something
+ oldstatus:=GetXStatus(proto,nil,nil);
+ if XStatusSet<>0 then // no matter which xstatus
+ begin
+ if not ((oldstatus=staudio) or (oldstatus=stvideo) or // music
+ ((oldstatus=0) and (XStatusSet=2))) then // empty
+ begin
+ mFreeMem(txt);
+ continue; //!! do nothing!
+ end;
+ end;
+ if isvideo then
+ xstat:=stvideo
+ else
+ xstat:=staudio;
+
+ if xstat=0 then // not choosed, keep old (current)
+ xstat:=oldstatus
+ else
+ begin
+ if OldXStatus[j]=255 then
+ OldXStatus[j]:=oldstatus;
+ end;
+
+ if ClearXStat<>BST_UNCHECKED then
+ SetXStatus(proto,0);
+
+ if SimpleMode<>BST_UNCHECKED then
+ title:=GetMacros(tmpl_xtitle,0)
+ else
+ title:=GetMacros(tmpl_xtitle,j);
+ SetXStatus(proto,xstat,txt,title);
+ mFreeMem(title);
+ mFreeMem(txt);
+ end;
+ end;
+ end;
+ end;
+ end;
+
+ end;
+ end;
+end;
diff --git a/plugins/Watrack/status/status.pas b/plugins/Watrack/status/status.pas
new file mode 100644
index 0000000000..b5db16bb1c
--- /dev/null
+++ b/plugins/Watrack/status/status.pas
@@ -0,0 +1,142 @@
+{Statistic}
+unit Status;
+{$include compilers.inc}
+interface
+{$Resource status.res}
+implementation
+
+uses
+ windows,messages,commctrl,
+ common,m_api,mirutils,protocols,dbsettings,wrapper,
+ global,wat_api,hlpdlg,CBEx,myRTF,Tmpl;
+
+const
+ HKN_INSERT:PansiChar = 'WAT_Insert';
+
+procedure reghotkey;
+var
+ hkrec:HOTKEYDESC;
+begin
+// if DisablePlugin=dsPermanent then
+// exit;
+ FillChar(hkrec,SizeOf(hkrec),0);
+ with hkrec do
+ begin
+ cbSize :=HOTKEYDESC_SIZE_V1;
+ pszName :=HKN_INSERT;
+ pszDescription.a:='Global WATrack hotkey';
+ pszSection.a :=PluginName;
+ pszService :=MS_WAT_INSERT;
+ DefHotKey :=((HOTKEYF_ALT or HOTKEYF_CONTROL) shl 8) or VK_F5;
+// lParam :=0;
+ end;
+ CallService(MS_HOTKEY_REGISTER,0,lparam(@hkrec));
+end;
+
+{$include i_st_vars.inc}
+{$include i_st_rc.inc}
+{$include i_opt_status.inc}
+{$include i_hotkey.inc}
+{$include i_status.inc}
+{$include i_opt_3.inc}
+{$include i_opt_11.inc}
+{$include i_opt_12.inc}
+
+// ------------ base interface functions -------------
+
+var
+ mStatus:twModule;
+
+function InitProc(aGetStatus:boolean=false):integer;
+begin
+ if aGetStatus then
+ begin
+ if GetModStatus=0 then
+ begin
+ result:=0;
+ exit;
+ end;
+ end
+ else
+ SetModStatus(1);
+ result:=1;
+
+ LoadOpt;
+ CreateProtoList;
+ CreateTemplates;
+ hINS:=CreateServiceFunction(MS_WAT_INSERT,@InsertProc);
+ reghotkey;
+ plStatusHook:=HookEvent(ME_WAT_NEWSTATUS,@NewPlStatus);
+
+// mStatus.ModuleStat:=1;
+
+// if ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT)<>0 then
+// hLTo:=CreateServiceFunction(MS_LISTENINGTO_GETPARSEDTEXT,@ListenProc);
+end;
+
+procedure DeInitProc(aSetDisable:boolean);
+var
+ j:integer;
+begin
+ if aSetDisable then
+ SetModStatus(0);
+
+ for j:=1 to GetNumProto do
+ begin
+ if (SimpleMode<>BST_UNCHECKED) or ((GetProtoSetting(j) and psf_enabled)<>0) then
+ CallProtoService(GetProtoName(j),PS_SET_LISTENINGTO,0,0);
+ end;
+// DestroyServiceFunction(hLTo);
+ DestroyServiceFunction(hINS);
+ UnhookEvent(plStatusHook);
+ FreeProtoList;
+ FreeTemplates;
+
+// mStatus.ModuleStat:=0;
+end;
+
+function AddOptionsPage(var tmpl:pAnsiChar;var proc:pointer;var name:PAnsiChar):integer;
+const
+ count:integer=2;
+begin
+ if count=0 then
+ count:=2;
+ case count of
+ 2: begin
+ tmpl:='COMMON';
+ proc:=@DlgProcOptions3;
+ name:='Status (common)';
+ end;
+ 1: begin
+ if SimpleMode=BST_UNCHECKED then
+ begin
+ tmpl:='TEMPLATE11';
+ proc:=@DlgProcOptions11;
+ end
+ else
+ begin
+ tmpl:='TEMPLATE12';
+ proc:=@DlgProcOptions12;
+ end;
+ name:='Status (templates)';
+ end
+ end;
+
+ dec(count);
+ result:=count;
+end;
+
+procedure Init;
+begin
+ mStatus.Next :=ModuleLink;
+ mStatus.Init :=@InitProc;
+ mStatus.DeInit :=@DeInitProc;
+ mStatus.AddOption :=@AddOptionsPage;
+ mStatus.ModuleName:='Statuses';
+// mStatus.ModuleStat:=0;
+ ModuleLink :=@mStatus;
+end;
+
+begin
+ Init;
+end.
diff --git a/plugins/Watrack/status/status.rc b/plugins/Watrack/status/status.rc
new file mode 100644
index 0000000000..9a1c78c476
--- /dev/null
+++ b/plugins/Watrack/status/status.rc
@@ -0,0 +1,88 @@
+#include "i_st_rc.inc"
+
+LANGUAGE 0,0
+
+COMMON DIALOGEX 0, 0, 304, 226, 0
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE
+EXSTYLE WS_EX_CONTROLPARENT
+FONT 8, "MS Shell Dlg", 0, 0
+{
+ GROUPBOX "Options", -1, 2, 2, 188, 218, WS_TABSTOP
+ AUTOCHECKBOX "Simple Template mode", IDC_SIMPLEMODE , 6, 12, 182, 14, BS_VCENTER | BS_MULTILINE// | BS_NOTIFY
+
+ AUTOCHECKBOX "Insert in messages" , IDC_USEMSGS , 6, 34, 182, 14, BS_VCENTER | BS_MULTILINE// | BS_NOTIFY
+ AUTOCHECKBOX "Use status messages" , IDC_USESTATUS , 6, 50, 182, 14, BS_VCENTER | BS_MULTILINE// | BS_NOTIFY
+ AUTOCHECKBOX "Use listening info" , IDC_LISTENINGTO, 6, 66, 182, 14, BS_VCENTER | BS_MULTILINE// | BS_NOTIFY
+
+ AUTOCHECKBOX "Use XStatus" , IDC_EXTSTATUS , 6, 86, 182, 14, BS_VCENTER | BS_MULTILINE// | BS_NOTIFY
+ AUTOCHECKBOX "Independed XStatus" , IDC_INDEPENDED, 14, 102, 174, 14, BS_VCENTER | BS_MULTILINE// | BS_NOTIFY
+ AUTOCHECKBOX "Clear xStatus before set new one" , IDC_CLEARXSTAT, 14, 118, 174, 14, BS_VCENTER | BS_MULTILINE// | BS_NOTIFY
+ AUTOCHECKBOX "Keep 'Music' XStatus" , IDC_KEEPSTATUS, 14, 134, 174, 14, BS_VCENTER | BS_MULTILINE// | BS_NOTIFY
+// AUTOCHECKBOX "Use existing XStatus" , IDC_OLDXSTATUS, 14, 134, 174, 14, BS_VCENTER | BS_MULTILINE// | BS_NOTIFY
+// AUTOCHECKBOX "Only if 'Music' status was set", IDC_ONLYMUSIC , 14, 150, 174, 14, BS_VCENTER | BS_MULTILINE// | BS_NOTIFY
+ LTEXT "Set XStatus when...", -1, 14, 150, 174, 14
+ COMBOBOX IDC_SETXSTATUS, 14, 166, 174, 96, CBS_DROPDOWNLIST | WS_VSCROLL
+}
+
+TEMPLATE11 DIALOGEX 0, 0, 304, 226, 0
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE
+EXSTYLE WS_EX_CONTROLPARENT
+FONT 8, "MS Shell Dlg", 0, 0
+{
+ PUSHBUTTON "Color", IDC_HELP_COLOR , 184, 1, 26, 12
+ PUSHBUTTON "Format", IDC_HELP_FORMAT , 213, 1, 32, 12
+ PUSHBUTTON "Variables", IDC_HELP_VARIABLES, 248, 1, 52, 12
+
+ CTEXT "Protocols", -1, 6, 2, 80, 10
+ CONTROL "", IDC_PROTOLIST, "SysListView32", WS_BORDER | WS_TABSTOP | LVS_NOCOLUMNHEADER | LVS_SHOWSELALWAYS | LVS_SINGLESEL | LVS_REPORT, 6, 12, 80, 92, WS_EX_CONTROLPARENT
+ CTEXT "Statuses", -1, 90, 2, 92, 10
+ CONTROL "", IDC_STATUSLIST, "SysListView32", WS_BORDER | WS_TABSTOP | LVS_NOCOLUMNHEADER | LVS_SHOWSELALWAYS | LVS_SINGLESEL | LVS_REPORT, 90, 12, 92, 92, WS_EX_CONTROLPARENT
+
+ AUTORADIOBUTTON "User message", IDC_IRC_USER , 196, 51, 102, 12, NOT WS_TABSTOP | WS_GROUP
+ AUTORADIOBUTTON "Channel message", IDC_IRC_CHANNEL, 196, 63, 102, 12, NOT WS_TABSTOP
+
+ PUSHBUTTON "Reset", IDC_CMD_RESET , 184, 103, 56, 12
+ PUSHBUTTON "Default", IDC_CMD_DEFAULT, 242, 103, 56, 12
+
+ LTEXT "Template", -1, 16, 106, 166, 10, SS_CENTERIMAGE
+ EDITTEXT IDC_EDIT_MSG , 6, 116, 290, 44, ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL
+ EDITTEXT IDC_EDIT_CHANNEL, 6, 116, 290, 44, ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL
+
+ AUTOCHECKBOX "Enable Status message" , IDC_STAT_ENABLE , 6, 161, 174, 12, BS_VCENTER | BS_MULTILINE
+ AUTOCHECKBOX "Enable XStatus message", IDC_XSTAT_ENABLE, 6, 161, 174, 12, BS_VCENTER | BS_MULTILINE
+ AUTOCHECKBOX "Enable Tunes message" , IDC_TUNES_ENABLE, 6, 161, 174, 12, BS_VCENTER | BS_MULTILINE
+ COMBOBOX IDC_CBSTATYPE,196,161,100,56,CBS_DROPDOWNLIST | WS_VSCROLL | NOT WS_TABSTOP
+ EDITTEXT IDC_STATUS_TEXT , 6, 175, 290, 45, ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
+ EDITTEXT IDC_XSTATUS_TITLE , 6, 175, 290, 14, ES_AUTOHSCROLL
+ EDITTEXT IDC_XSTATUS_TEXT , 6, 192, 290, 28, ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
+ EDITTEXT IDC_LISTENING_TEXT , 6, 175, 290, 45, ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL
+
+ AUTORADIOBUTTON "Audio", IDC_XSTAT_AUDIO, 186, 75, 54, 12, NOT WS_TABSTOP | BS_RIGHT | BS_LEFTTEXT | WS_GROUP
+ AUTORADIOBUTTON "Video", IDC_XSTAT_VIDEO, 244, 75, 54, 12, NOT WS_TABSTOP
+
+ CONTROL "", IDC_CBEX, "ComboBoxEx32",
+ WS_GROUP | WS_TABSTOP | WS_VSCROLL | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST, 186, 88, 112, 100
+}
+
+TEMPLATE12 DIALOGEX 0, 0, 304, 226, 0
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE
+EXSTYLE WS_EX_CONTROLPARENT
+FONT 8, "MS Shell Dlg", 0, 0
+{
+ PUSHBUTTON "Color", IDC_HELP_COLOR , 184, 4, 26, 12
+ PUSHBUTTON "Format", IDC_HELP_FORMAT , 213, 4, 32, 12
+ PUSHBUTTON "Variables", IDC_HELP_VARIABLES, 248, 4, 52, 12
+
+ PUSHBUTTON "Reset", IDC_CMD_RESET, 6, 4, 56, 12
+ LTEXT "This is simplified version of template editor. This templates will be used with all protocols, protocol and player (media) statuses",
+ -1, 6,20,290,22
+
+ CTEXT "Template", -1, 6, 42, 290, 10
+ EDITTEXT IDC_EDIT_MSG, 6, 52, 290, 48, ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL
+ CTEXT "Chat Template", -1, 6, 102, 290, 10
+ EDITTEXT IDC_EDIT_CHANNEL, 6, 112, 290, 48, ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL
+
+ CTEXT "[X]Status Title / Text", -1, 6, 165, 290, 10
+ EDITTEXT IDC_XSTATUS_TITLE, 6, 175, 290, 14, ES_AUTOHSCROLL
+ EDITTEXT IDC_STATUS_TEXT , 6, 192, 290, 28, ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
+}
diff --git a/plugins/Watrack/status/status.res b/plugins/Watrack/status/status.res
new file mode 100644
index 0000000000..fba2526583
--- /dev/null
+++ b/plugins/Watrack/status/status.res
Binary files differ
diff --git a/plugins/Watrack/status/tmpl.pas b/plugins/Watrack/status/tmpl.pas
new file mode 100644
index 0000000000..4adcd20bdf
--- /dev/null
+++ b/plugins/Watrack/status/tmpl.pas
@@ -0,0 +1,304 @@
+unit Tmpl;
+
+interface
+// ----- main data -----
+type
+ tTemplateType = (
+ tmpl_pm ,tmpl_chat,
+ tmpl_xtitle,tmpl_xtext,
+ tmpl_stext ,
+ tmpl_tunes);
+const
+ tmpl_first = tmpl_pm;
+ tmpl_last = tmpl_tunes;
+{
+const
+ TMPL_EMPTY = 0;
+ TMPL_PARENT = $4000;
+ TMPL_INACTIVE = ;
+}
+procedure CreateTemplates;
+procedure FreeTemplates;
+procedure SaveTemplates;
+
+function SetTemplateActive(active:boolean;aType:tTemplateType;proto:cardinal=0;
+ ProtoStatus:integer=0):boolean;
+function IsTemplateActive(aType:tTemplateType;proto:cardinal=0;
+ ProtoStatus:integer=0):boolean;
+function GetTemplateStr(aType:tTemplateType;proto:cardinal=0;
+ ProtoStatus:integer=0):PWideChar;
+function SetTemplateStr(aStr:PWideChar;aType:tTemplateType;proto:cardinal=0;
+ ProtoStatus:integer=0):integer;
+
+function GetMacros(TmplType:tTemplateType;proto:integer):pWideChar;
+
+implementation
+
+uses common, m_api, windows, dbsettings, mirutils, protocols,wat_api,global;
+
+const
+ dubtmpl = $4000;
+const
+ DefaultTemplate = 0;
+ NumStatus = 10;
+
+type
+ pStrTemplate = ^tStrTemplate;
+ tStrTemplate = array [0..NumStatus-1,tTemplateType] of SmallInt;
+
+type
+ pMyString = ^tMyString;
+ tMyString = record
+ count:cardinal; // link count
+ text :pWideChar;
+ end;
+ pMyStrArray = ^tMyStrArray;
+ tMyStrArray = array [1..1000] of tMyString;
+
+type
+ tTmpl = integer;
+ pStrTemplates = ^tStrTemplates;
+ tStrTemplates = array [0..100] of tStrTemplate;
+
+const
+ NumTemplates:cardinal=0;
+ StrTemplates:pStrTemplates=nil;
+
+var
+ strings:pMyStrArray;
+ NumString:cardinal;
+
+const
+ defTemplate = 'I am listening to %artist% - "%title%"';
+ defChannelText = '/me listening to %artist% - "%title%"';
+ defStatusTitle = 'Now listening to';
+ defStatusText = '%artist% - %title%';
+
+ defAltTemplate = 'I am listening to %artist% - %title%?iflonger(%album%,0, (from "%album%"),)';
+ defAltChannelText = '/me listening to %artist% - %title%?iflonger(%album%,0, (from "%album%"),)';
+
+// ----- procedures -----
+{$include i_opt_tmpl.inc}
+
+function AddString(var newstr:PWideChar):cardinal;
+var
+ i:cardinal;
+ tmp:pMyStrArray;
+begin
+ for i:=1 to NumString do // search in table
+ begin
+ if StrCmpW(newstr,strings^[i].text)=0 then
+ begin
+ result:=i;
+ mFreeMem(newstr);
+ exit;
+ end;
+ end;
+ Inc(NumString);
+ mGetMem(tmp,SizeOf(tMyString)*NumString);
+ move(strings^,tmp^,SizeOf(tMyString)*(NumString-1));
+ mFreeMem(strings);
+ strings:=tmp;
+ tmp^[NumString].count:=0;
+ tmp^[NumString].text:=newstr;
+ result:=NumString;
+end;
+
+procedure PackStrings;
+var
+ i,j:integer;
+ OldNumString:cardinal;
+ lTmplType:tTemplateType;
+ lProtoStatus:cardinal;
+ tmp:pMyStrArray;
+ NumProto:integer;
+ tmpl:pStrTemplate;
+begin
+ // clear counters
+ for i:=1 to NumString do
+ strings^[i].count:=0;
+ // counts strings
+ NumProto:=GetNumProto;
+ for i:=0 to NumProto do
+ begin
+ tmpl:=@StrTemplates^[i];
+ for lProtoStatus:=0 to NumStatus-1 do
+ for lTmplType:=tmpl_first to tmpl_last do
+ begin
+ j:=tmpl^[lProtoStatus,lTmplType];
+ if j>0 then
+ inc(strings^[j].count);
+ end;
+ end;
+ // delete strings
+ i:=1;
+ OldNumString:=NumString;
+
+ if DisablePlugin=dsEnabled then
+ DisablePlugin:=dsTemporary;
+
+ while Cardinal(i)<=NumString do
+ begin
+ if strings^[i].count=0 then
+ begin
+ mFreeMem(strings^[i].text);
+ if cardinal(i)<NumString then
+ begin
+ // shift strings
+ move(strings^[i+1],strings^[i],SizeOf(tMyString)*(NumString-cardinal(i)));
+ // shift protos
+ for j:=0 to NumProto do
+ begin
+ tmpl:=@StrTemplates^[j];
+ for lProtoStatus:=0 to NumStatus-1 do
+ for lTmplType:=tmpl_first to tmpl_last do
+ begin
+ if tmpl^[lProtoStatus,lTmplType]>i then
+ dec(tmpl^[lProtoStatus,lTmplType]);
+ end;
+ end;
+ end;
+ dec(NumString);
+ continue;
+ end;
+ inc(i);
+ end;
+ if OldNumString<>NumString then
+ begin
+ mGetMem(tmp,SizeOf(tMyString)*NumString);
+ move(strings^,tmp^,SizeOf(tMyString)*NumString);
+ mFreeMem(strings);
+ strings:=tmp;
+ end;
+
+// if DisablePlugin<0 then
+// SetTitle;
+ if DisablePlugin<>dsPermanent then
+ DisablePlugin:=dsEnabled;
+
+end;
+
+function SetTemplateActive(active:boolean;aType:tTemplateType;proto:cardinal=0;
+ ProtoStatus:integer=0):boolean;
+var
+ res:smallint;
+begin
+ if proto>NumTemplates then
+ proto:=0;
+
+ res:=ABS(StrTemplates^[proto][ProtoStatus,aType]);
+ if not active then res:=-res;
+ StrTemplates^[proto][ProtoStatus,aType]:=res;
+ result:=res>0;
+end;
+
+function IsTemplateActive(aType:tTemplateType;proto:cardinal=0;
+ ProtoStatus:integer=0):boolean;
+begin
+ if proto>NumTemplates then
+ proto:=0;
+
+ result:=StrTemplates^[proto][ProtoStatus,aType]>0;
+end;
+
+function GetTmplString(num:integer):pWideChar;
+begin
+ if (num>0) and (Cardinal(num)<=NumString) then
+ result:=strings^[num].text
+ else
+ result:=nil;
+end;
+
+function GetTemplateStr(aType:tTemplateType;proto:cardinal=0;
+ ProtoStatus:integer=0):PWideChar;
+var
+ i:smallint;
+begin
+ if proto>NumTemplates then
+ proto:=0;
+
+ i:=abs(StrTemplates^[proto ][ProtoStatus,aType]);
+ if i=smallint(dubtmpl) then begin i:=abs(StrTemplates^[proto ][0 ,aType]);
+ if i=smallint(dubtmpl) then begin i:=abs(StrTemplates^[DefaultTemplate][ProtoStatus,aType]);
+ if i=smallint(dubtmpl) then i:=abs(StrTemplates^[DefaultTemplate][0 ,aType]); end; end;
+ if i=smallint(dubtmpl) then
+ i:=0;
+
+ result:=GetTmplString(ABS(i)); //normalize
+end;
+
+function SetTemplateStr(aStr:PWideChar;aType:tTemplateType;proto:cardinal=0;
+ ProtoStatus:integer=0):integer;
+var
+ tmpl:pStrTemplate;
+ tmp,tmp1:smallint;
+begin
+ tmpl:=@StrTemplates^[proto];
+
+ if (aStr=nil) or (aStr^=#0) then
+ result:=0
+ else
+ result:=AddString(aStr);
+
+ tmp1:=result;
+ tmp:=tmpl^[0,aType];
+ if tmp1=tmp then
+ tmp1:=smallint(dubtmpl)
+ else if tmp=smallint(dubtmpl) then
+ begin
+ if tmp1=tmpl^[0,aType] then
+ tmp1:=smallint(dubtmpl);
+ end;
+ tmpl^[ProtoStatus,aType]:=tmp1;
+end;
+
+procedure CreateTemplates;
+var
+ i:integer;
+begin
+ NumTemplates:=GetNumProto;
+ // Size in bytes
+ i:=SizeOf(tStrTemplate)*(NumTemplates+1);
+ mGetMem(StrTemplates,i);
+ // size in words
+ FillWord(StrTemplates^,i div 2,dubtmpl);
+ LoadTemplates;
+end;
+
+procedure FreeTemplates;
+begin
+ mFreeMem(StrTemplates);
+ while NumString>0 do
+ begin
+ mFreeMem(strings^[NumString].text);
+ dec(NumString);
+ end;
+ mFreeMem(strings);
+end;
+
+function GetMacros(TmplType:tTemplateType;proto:integer):pWideChar;
+var
+ r:PWideChar;
+ status:integer;
+begin
+ if proto=0 then
+ r:=GetTemplateStr(TmplType,0,0)
+ else
+ begin
+ status:=GetProtoStatusNum(proto);
+ if IsTemplateActive(TmplType,proto,status) then
+ r:=GetTemplateStr(TmplType,proto,status)
+ else
+ begin
+ result:=pWideChar(-1);
+ exit;
+ end;
+ end;
+
+ if r=nil then
+ result:=nil
+ else
+ result:=pWideChar(CallService(MS_WAT_REPLACETEXT,0,lparam(r)));
+end;
+
+end.