summaryrefslogtreecommitdiff
path: root/plugins/Utils.pas/mirutils.pas
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Utils.pas/mirutils.pas')
-rw-r--r--plugins/Utils.pas/mirutils.pas373
1 files changed, 1 insertions, 372 deletions
diff --git a/plugins/Utils.pas/mirutils.pas b/plugins/Utils.pas/mirutils.pas
index 918f615390..976ee5bca1 100644
--- a/plugins/Utils.pas/mirutils.pas
+++ b/plugins/Utils.pas/mirutils.pas
@@ -35,26 +35,6 @@ function ParseVarString(astr:pAnsiChar;aContact:TMCONTACT=0;extra:pAnsiChar=nil)
function ParseVarString(astr:pWideChar;aContact:TMCONTACT=0;extra:pWideChar=nil):pWideChar; overload;
function ShowVarHelp(dlg:HWND;id:integer=0):integer;
-function IsChat(hContact:TMCONTACT):bool;
-procedure SendToChat(hContact:TMCONTACT;pszText:PWideChar);
-
-function LoadContact(group,setting:PAnsiChar):TMCONTACT;
-function SaveContact(hContact:TMCONTACT;group,setting:PAnsiChar):integer;
-
-function SetCListSelContact(hContact:TMCONTACT):TMCONTACT;
-function GetCListSelContact:TMCONTACT; {$IFDEF DELPHI_10_UP}inline;{$ENDIF}
-function GetContactProtoAcc(hContact:TMCONTACT):PAnsiChar;
-function IsMirandaUser(hContact:TMCONTACT):integer; // >0=Miranda; 0=Not miranda; -1=unknown
-procedure ShowContactDialog(hContact:TMCONTACT;DblClk:boolean=true;anystatus:boolean=true);
-function FindContactHandle(proto:pAnsiChar;const dbv:TDBVARIANT;is_chat:boolean=false):TMCONTACT;
-function WndToContact(wnd:HWND):TMCONTACT; overload;
-function WndToContact:TMCONTACT; overload;
-function GetContactStatus(hContact:TMCONTACT):integer;
-// -2 - deleted account, -1 - disabled account, 0 - hidden
-// 1 - metacontact, 2 - submetacontact, positive - active
-// proto - ASSIGNED buffer
-function IsContactActive(hContact:TMCONTACT;proto:pAnsiChar=nil):integer;
-
function CreateGroupW(name:pWideChar;hContact:TMCONTACT):integer;
function MakeGroupMenu(idxfrom:integer=100):HMENU;
@@ -79,7 +59,7 @@ implementation
uses
Messages,
dbsettings,freeimage,
- common,io,syswin;
+ common,io;
const
clGroup = 'Group';
@@ -165,13 +145,6 @@ begin
result:=MirCP;
end;
-function IsChat(hContact:TMCONTACT):bool;
-begin
- result:=DBReadByte(hContact,
- PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,hContact,0)),
- 'ChatRoom',0)=1;
-end;
-
function isVarsInstalled:bool;
{$IFDEF AllowInline}inline;{$ENDIF}
begin
@@ -306,168 +279,6 @@ begin
end;
end;
-function GetContactProtoAcc(hContact:TMCONTACT):PAnsiChar;
-begin
- if ServiceExists(MS_PROTO_GETCONTACTBASEACCOUNT)<>0 then
- result:=PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEACCOUNT,hContact,0))
- else
- result:=PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,hContact,0));
-end;
-
-function IsMirandaUser(hContact:TMCONTACT):integer; // >0=Miranda; 0=Not miranda; -1=unknown
-var
- sz:PAnsiChar;
-begin
- sz:=PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,hContact,0));
- sz:=DBReadString(hContact,sz,'MirVer');
- if sz<>nil then
- begin
- result:=int_ptr(StrPos(sz,'Miranda'));
- mFreeMem(sz);
- end
- else
- result:=-1;
-end;
-
-function SetCListSelContact(hContact:TMCONTACT):TMCONTACT;
-var
- wnd:HWND;
-begin
- wnd:=CallService(MS_CLUI_GETHWNDTREE,0,0);
- result:=hContact;
-// hContact:=SendMessage(wnd,CLM_FINDCONTACT ,hContact,0);
- SendMessage(wnd,CLM_SELECTITEM ,hContact,0);
-// SendMessage(wnd,CLM_ENSUREVISIBLE,hContact,0);
-end;
-
-function GetCListSelContact:TMCONTACT;
-begin
- result:=SendMessageW(CallService(MS_CLUI_GETHWNDTREE,0,0),CLM_GETSELECTION,0,0);
-end;
-
-function LoadContact(group,setting:PAnsiChar):TMCONTACT;
-var
- p,proto:pAnsiChar;
- section:array [0..63] of AnsiChar;
- dbv:TDBVARIANT;
- is_chat:boolean;
-begin
- p:=StrCopyE(section,setting);
- StrCopy(p,opt_cproto); proto :=DBReadString(0,group,section);
- StrCopy(p,opt_ischat); is_chat:=DBReadByte (0,group,section,0)<>0;
- StrCopy(p,opt_cuid );
- if is_chat then
- dbv.szVal.W:=DBReadUnicode(0,group,section,@dbv)
- else
- DBReadSetting(0,group,section,@dbv);
-
- result:=FindContactHandle(proto,dbv,is_chat);
-
- mFreeMem(proto);
- if not is_chat then
- DBFreeVariant(@dbv)
- else
- mFreeMem(dbv.szVal.W);
-end;
-
-function SaveContact(hContact:TMCONTACT;group,setting:PAnsiChar):integer;
-var
- p,proto,uid:pAnsiChar;
- cws:TDBVARIANT;
- section:array [0..63] of AnsiChar;
- pw:pWideChar;
- is_chat:boolean;
-begin
- result:=0;
- proto:=GetContactProtoAcc(hContact);
- if proto<>nil then
- begin
- p:=StrCopyE(section,setting);
- is_chat:=IsChat(hContact);
- if is_chat then
- begin
- pw:=DBReadUnicode(hContact,proto,'ChatRoomID');
- StrCopy(p,opt_cuid); DBWriteUnicode(0,group,section,pw);
- mFreeMem(pw);
- result:=1;
- end
- else
- begin
- uid:=pAnsiChar(CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0));
- if uid<>pAnsiChar(CALLSERVICE_NOTFOUND) then
- begin
- if DBReadSetting(hContact,proto,uid,@cws)=0 then
- begin
- StrCopy(p,opt_cuid); DBWriteSetting(0,group,section,@cws);
- DBFreeVariant(@cws);
- result:=1;
- end;
- end;
- end;
- if result<>0 then
- begin
- StrCopy(p,opt_cproto); DBWriteString(0,group,section,proto);
- StrCopy(p,opt_ischat); DBWriteByte (0,group,section,ord(is_chat));
- end;
- end;
-end;
-
-function WndToContact(wnd:HWND):TMCONTACT; overload;
-var
- hContact:TMCONTACT;
- mwid:TMessageWindowInputData;
- mwod:TMessageWindowOutputData;
-begin
- wnd:=GetParent(wnd); //!!
- hContact:=db_find_first();
- with mwid do
- begin
- cbSize:=SizeOf(mwid);
- uFlags:=MSG_WINDOW_UFLAG_MSG_BOTH;
- end;
- mwod.cbSize:=SizeOf(mwod);
- while hContact<>0 do
- begin
- mwid.hContact:=hContact;
- if CallService(MS_MSG_GETWINDOWDATA,wparam(@mwid),lparam(@mwod))=0 then
- begin
- if {((mwod.uState and MSG_WINDOW_STATE_FOCUS)<>0) and} (mwod.hwndWindow=wnd) then
- begin
- result:=mwid.hContact;
- exit;
- end
- end;
- hContact:=db_find_next(hContact);
- end;
- result:=0;
-end;
-
-function WndToContact:TMCONTACT; overload;
-var
- wnd:HWND;
-begin
- wnd:=GetFocus;
- if wnd=0 then
- wnd:=WaitFocusedWndChild(GetForegroundWindow);
- if wnd<>0 then
- result:=WndToContact(wnd)
- else
- result:=0;
- if result=0 then
- result:=GetCListSelContact;
-end;
-
-function GetContactStatus(hContact:TMCONTACT):integer;
-var
- szProto:PAnsiChar;
-begin
- szProto:=PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,hContact,0));
- if szProto=NIL then
- result:=ID_STATUS_OFFLINE
- else
- result:=DBReadWord(hContact,szProto,'Status',ID_STATUS_OFFLINE);
-end;
-
function CheckPath(filename,profilepath,path:PAnsiChar):PAnsiChar;
var
buf:array [0..511] of AnsiChar;
@@ -547,188 +358,6 @@ begin
end;
end;
-procedure ShowContactDialog(hContact:TMCONTACT;DblClk:boolean=true;anystatus:boolean=true);
-var
- pc:array [0..127] of AnsiChar;
-begin
-{
-CallService(MS_CLIST_CONTACTDOUBLECLICKED,hContact,0);
-}
- if (hContact<>0) and (CallService(MS_DB_CONTACT_IS,hContact,0)<>0) then
- begin
- if StrCopy(pc,PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,hContact,0)))<>nil then
- if DblClk or (DBReadByte(hContact,pc,'ChatRoom',0)=1) then // chat room
- begin
- if not anystatus then
- begin
- StrCat(pc,PS_GETSTATUS);
- anystatus:=(CallService(pc,0,0)<>ID_STATUS_OFFLINE);
- end;
- if anystatus then
- begin
- CallService(MS_CLIST_CONTACTDOUBLECLICKED,hContact,0); //??
- // if chat exist, open chat
- // else create new session
- end;
- end
- else
- begin
- if ServiceExists(MS_MSG_CONVERS)<>0 then // Convers compat.
- CallService(MS_MSG_CONVERS,hContact,0)
- else
- CallService(MS_MSG_SENDMESSAGE,hContact,0)
- end;
- end;
-end;
-
-procedure SendChatText(pszID:pointer;pszModule:PAnsiChar;pszText:pointer);
-var
- gcd:TGCDEST;
- gce:TGCEVENT;
-begin
- gcd.pszModule:=pszModule;
- gcd.iType :=GC_EVENT_SENDMESSAGE;
- gcd.szID.w :=pszID;
-
- FillChar(gce,SizeOf(TGCEVENT),0);
- gce.cbSize :=SizeOf(TGCEVENT);
- gce.pDest :=@gcd;
- gce.bIsMe :=true;
- gce.szText.w:=pszText;
- gce.dwFlags :=GCEF_ADDTOLOG;
- gce.time :=GetCurrentTime;
-
- CallServiceSync(MS_GC_EVENT,0,lparam(@gce));
-end;
-
-procedure SendToChat(hContact:TMCONTACT;pszText:PWideChar);
-var
- gci:TGC_INFO;
- pszModule:PAnsiChar;
- i,cnt:integer;
-begin
- pszModule:=PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,hContact,0));
- cnt:=CallService(MS_GC_GETSESSIONCOUNT,0,lparam(pszModule));
- i:=0;
- gci.pszModule:=pszModule;
- while i<cnt do
- begin
- gci.iItem:=i;
- gci.Flags:=GCF_BYINDEX+GCF_HCONTACT+GCF_ID;
- CallService(MS_GC_GETINFO,0,lparam(@gci));
- if gci.hContact=hContact then
- begin
- SendChatText(gci.pszID.w,pszModule,pszText);
- break;
- end;
- inc(i);
- end;
-end;
-
-function FindContactHandle(proto:pAnsiChar;const dbv:TDBVARIANT;is_chat:boolean=false):TMCONTACT;
-var
- uid:pAnsiChar;
- ldbv:TDBVARIANT;
- hContact:TMCONTACT;
- pw:pWideChar;
-begin
- result:=0;
- uid:=nil;
- if not is_chat then
- begin
- uid:=pAnsiChar(CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0));
- if uid=pAnsiChar(CALLSERVICE_NOTFOUND) then exit;
- end;
-
- hContact:=db_find_first();
- while hContact<>0 do
- begin
- if is_chat then
- begin
- if IsChat(hContact) then
- begin
- pw:=DBReadUnicode(hContact,proto,'ChatRoomID');
- if StrCmpW(pw,dbv.szVal.W)=0 then result:=hContact;
- mFreeMem(pw);
- end
- end
- else
- begin
- if DBReadSetting(hContact,proto,uid,@ldbv)=0 then
- begin
- if dbv._type=ldbv._type then
- begin
- case dbv._type of
-// DBVT_DELETED: ;
- DBVT_BYTE : if dbv.bVal=ldbv.bVal then result:=hContact;
- DBVT_WORD : if dbv.wVal=ldbv.wVal then result:=hContact;
- DBVT_DWORD : if dbv.dVal=ldbv.dVal then result:=hContact;
- DBVT_UTF8,
- DBVT_ASCIIZ : if StrCmp (dbv.szVal.A,ldbv.szVal.A)=0 then result:=hContact;
- DBVT_WCHAR : if StrCmpW(dbv.szVal.W,ldbv.szVal.W)=0 then result:=hContact;
- DBVT_BLOB : begin
- if dbv.cpbVal = ldbv.cpbVal then
- begin
- if CompareMem(dbv.pbVal,ldbv.pbVal,dbv.cpbVal) then
- result:=hContact;
- end;
- end;
- end;
- end;
- DBFreeVariant(@ldbv);
- end;
- end;
- // added 2011.04.20
- if result<>0 then break;
- hContact:=db_find_next(hContact);
- end;
-end;
-
-function IsContactActive(hContact:TMCONTACT;proto:pAnsiChar=nil):integer;
-var
- p:PPROTOACCOUNT;
- name: array [0..31] of AnsiChar;
-begin
-
- if db_get_static(hContact,'Protocol','p',@name,SizeOf(name))=0 then
- begin
- result:=0;
-
- if ServiceExists(MS_PROTO_GETACCOUNT)<>0 then
- begin
- p:=PPROTOACCOUNT(CallService(MS_PROTO_GETACCOUNT,0,lparam(@name)));
- if p=nil then
- result:=-2 // deleted
- else if (not p^.bIsEnabled) or p^.bDynDisabled then
- result:=-1; // disabled
- end
- else
- begin
- if CallService(MS_PROTO_ISPROTOCOLLOADED,0,lparam(@name))=0 then
- result:=-1;
- end;
-
- if (result=0) and (DBReadByte(hContact,strCList,'Hidden',0)=0) then
- begin
- result:=255;
- if db_mc_getMeta(hContact)<>0 then
- result:=2;
- if StrCmp(
- PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,hContact,0)),
- META_PROTO)=0 then
- result:=1;
- end;
- if proto<>nil then
- StrCopy(proto,@name);
- end
- else
- begin
- result:=-2;
- if proto<>nil then
- proto^:=#0;
- end;
-end;
-
// Import plugin function adaptation
function CreateGroupW(name:pWideChar;hContact:TMCONTACT):integer;
var