You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RnQ/RnQ/mainDlg.pas

334 lines
9.6 KiB
Plaintext

{
This file is part of R&Q.
Under same license
}
unit mainDlg;
{$I RnQConfig.inc}
interface
uses
Winapi.Windows, System.SysUtils,
SciterJS, SciterJSAPI, UtilLib;
{$I NoRTTI.inc}
type
TMainMethods = class(TNativeMethods)
class procedure RegisterMethods(var ReturnValue: TSciterValue); override;
class procedure CheckUIN(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
class procedure CheckAddUIN(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
class procedure GetGroups(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
class procedure GetSessionsList(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
class procedure CloseSession(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
class procedure CloseAllSessions(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
end;
implementation
uses
GlobalLib, RoasterLib, GroupsLib, SciterLib, RDGlobal, RQUtil, RnQLangs, ICQCommon, ICQContacts;
class procedure TMainMethods.RegisterMethods(var ReturnValue: TSciterValue);
begin
AddMethod('CheckUIN', CheckUIN);
AddMethod('CheckAddUIN', CheckAddUIN);
AddMethod('GetGroups', GetGroups);
AddMethod('GetSessionsList', GetSessionsList);
AddMethod('CloseSession', CloseSession);
AddMethod('CloseAllSessions', CloseAllSessions);
inherited;
end;
class procedure TMainMethods.CheckUIN(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
var
Res: Boolean;
begin
Res := Account.AccProto.ValidICQ(Trim(SciterVarToString(argv)));
if not Res then
MsgDlg('Invalid UIN', True, mtError);
V2S(Res, retval);
end;
class procedure TMainMethods.CheckAddUIN(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
var
UID: TUID;
Contact: TICQContact;
Res: Boolean;
begin
Res := False;
if argc < 1 then
Exit;
UID := Trim(SciterVarToString(argv));
if not Account.AccProto.ValidICQ(UID) then
MsgDlg('Invalid UIN', True, mtError)
else
begin
Contact := Account.AccProto.GetContact(UID);
if not Assigned(Contact) then
MsgDlg('Couldn''t create contact!', True, mtError)
else if Contact.IsInRoster then
begin
roasterLib.focus(Contact);
MsgDlg(GetTranslation('%s already exists', [uid]), False, mtWarning)
end else
Res := True;
end;
V2S(Res, retval);
end;
class procedure TMainMethods.GetGroups(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
var
I, Tmp: Integer;
AddOut: Boolean;
GroupItems: TArray;
MenuItems: TParams;
begin
Tmp := 0;
API.ValueIntData(argv, Tmp);
AddOut := Tmp = 1;
GroupItems := groups.GetGroups(AddOut);
SetLength(MenuItems, Length(GroupItems));
for I := 0 to Length(MenuItems) - 1 do
MenuItems[I] := UI.RecordToVar(GroupItems[I]);
V2S(MenuItems, retval);
end;
class procedure TMainMethods.GetSessionsList(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
var
Sessions: TArray;
SessionsVar: TParams;
I: Integer;
begin
Sessions := Account.AccProto.GetSessionsList;
for I := 0 to Length(Sessions) - 1 do
SessionsVar := SessionsVar + [UI.RecordToVar(Sessions[I])];
V2S(SessionsVar, retval);
end;
class procedure TMainMethods.CloseSession(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
var
Hash: String;
Current: Integer;
begin
Hash := SciterVarToString(argv);
Inc(argv);
Current := 0;
API.ValueIntData(argv, Current);
if not (Hash = '') then
Account.AccProto.CloseSession(Hash, Current = 1);
end;
class procedure TMainMethods.CloseAllSessions(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
begin
Account.AccProto.CloseAllSessions;
end;
//// Mute
//// Exec
// if Assigned(Account.AccProto) and Assigned(clickedContact) then
// Account.AccProto.SetMuted(clickedContact, not clickedContact.IsMuted);
//
//// Update
// TAction(Sender).Visible := False; Exit; // Unused
//
// if not Assigned(clickedContact) then
// Exit;
//
// TAction(Sender).Visible := not (clickedContact.UID2Cmp = spamsFilename);
// TAction(Sender).Enabled := Account.AccProto.IsOnline;
//
// if clickedContact.IsMuted then
// begin
// TAction(Sender).HelpKeyword := 'unmuted';
// TAction(Sender).Caption := GetTranslation('Unmute');
// end
// else
// begin
// TAction(Sender).HelpKeyword := 'muted';
// TAction(Sender).Caption := GetTranslation('Mute');
// end;
// if OnlFeature(Account.AccProto) then
// Account.AccProto.RemoveMeFromHisCL(clickedContact.uid)
// TODO: Plugin menu items
// function TRnQmain.AddMainMenuItem(wPar: WPARAM; lPar: LPARAM): Integer; cdecl;
//function TRnQmain.AddContactMenuItem(pMI: PCLISTMENUITEM): Integer; // cdecl;
//{ function TRnQmain.AddContactMenuItem(pPluginProc : Pointer; menuIcon: hIcon; menuCaption:String;
// menuHint:string; //procIdx : Integer;
// position : Integer;
// PopupName : String; popupPosition : Integer;
// hotKey : DWORD; PicName : String = ''):integer; }
//var
// // clMI : TCLISTMENUITEM;
// str, Str1: String;
// i: Integer;
// MI: TRQMenuItem;
// PM: TRQMenuItem;
// MM: TMenuItem;
// // Ic : TIcon;
// // bmp : TBitmap;
//begin
// // Str :=String(wPar);
// // clMI := PCLISTMENUITEM(lPar)^;
// if pMI.cbSize <> sizeof(TCLISTMENUITEM) then
// begin
// Result := 0;
// Exit;
// end;
// // Str := pMI.pszName;
// MI := TRQMenuItem.Create(Self);
// MI.caption := UnUTF(pMI.pszName);
// MI.Hint := UnUTF(pMI.pszHint);
// if (pMI.hIcon <> 0) then
// begin
// ico2bmp2(pMI.hIcon, MI.Bitmap);
// end;
// // MI.ServiceName := clMI.pszService;
// MI.PluginProc := pMI.Proc;
// // MI.Plugin := pPlugin;
// // MI.ProcIdx := procIdx;
// if pMI.Proc = NIL then
// MI.OnClick := NIL
// else
// MI.OnClick := OnPluginMenuClick;
// MI.ImageName := pMI.pszPic;
// MI.Enabled := (pMI.flags and RQFM_DISABLED) = 0;
// MI.visible := (pMI.flags and RQFM_HIDDEN) = 0;
// MM := contactMenu.Items;
// str := UnUTF(pMI.pszPopupName);
// if str <> '' then
// begin
// Str1 := str;
// while str > '' do
// begin
// i := pos('\', str);
// if i = 0 then
// i := length(str) + 1;
// Str1 := copy(str, 1, i - 1);
// delete(str, 1, i + length('\') - 1);
// if Assigned(MM.Find(Str1)) then
// MM := TMenuItem(MM.Find(Str1))
// else
// begin
// PM := TRQMenuItem.Create(contactMenu);
// PM.caption := Str1;
// MM.add(PM);
// MM := PM;
// // PM.Add(MI);
// end;
// end;
// end;
// // else
// // contactMenu.Items.Insert(12, MI);
// MM.add(MI);
// Result := MI.Handle;
//end;
//
//// function TRnQmain.UpdateContactMenuItem(menuHandle: hmenu; pMI : PCLISTMENUITEM ): Integer;// cdecl;
//Procedure TRnQmain.UpdateContactMenuItem(menuHandle: hmenu; pMI: PCLISTMENUITEM); // cdecl;
// function findItem(item: TMenuItem): TMenuItem;
// var
// i: Integer;
// begin
// Result := NIL;
// if item.Handle = menuHandle then
// Result := item
// else if item.Count > 0 then
// for i := 0 to item.Count - 1 do
// begin
// // if item.Items[i].Count > 0 then
// Result := findItem(item.Items[i]);
// if Result <> NIL then
// break;
// end;
// end;
//
//var
// MI: TMenuItem;
//begin
// MI := findItem(contactMenu.Items);
// if MI <> NIL then
// begin
// if (pMI.flags and RQFM_UPD_CAPTION) > 0 then
// MI.caption := UnUTF(pMI.pszName);
// if (pMI.flags and RQFM_UPD_HINT) > 0 then
// MI.Hint := UnUTF(pMI.pszHint);
// if (pMI.flags and RQFM_UPD_ENABLE) > 0 then
// MI.Enabled := (pMI.flags and RQFM_DISABLED) = 0;
// if (pMI.flags and RQFM_UPD_VISIBLE) > 0 then
// MI.visible := (pMI.flags and RQFM_HIDDEN) = 0;
// if (pMI.flags and RQFM_UPD_ICON) > 0 then
// if (pMI.hIcon <> 0) then
// ico2bmp2(pMI.hIcon, MI.Bitmap)
// else
// begin
// MI.Bitmap := NIL; // .Empty := True;
// end;
// end;
// // Result := mi
//end;
//
//procedure TRnQmain.DelContactMenuItem(menuHandle: hmenu);
// function findItem(item: TMenuItem): TMenuItem;
// var
// i: Integer;
// begin
// Result := NIL;
// if item.Handle = menuHandle then
// Result := item
// else if item.Count > 0 then
// for i := 0 to item.Count - 1 do
// begin
// // if item.Items[i].Count > 0 then
// Result := findItem(item.Items[i]);
// if Result <> NIL then
// break;
// end;
// end;
//
//var
// item, parItem: TMenuItem;
//begin
// item := findItem(contactMenu.Items);
// if item <> NIL then
// begin
// parItem := item.parent;
// parItem.remove(item);
// item.free;
// while (parItem <> contactMenu.Items) and (parItem.Count = 0) do
// begin
// item := parItem;
// parItem := item.parent;
// parItem.remove(item);
// item.free;
// end;
// end;
//end;
//
//procedure TRnQmain.OnPluginMenuClick(Sender: TObject);
//var
// // pr : procedure(uid:String);
// pr: procedure(uid: RawByteString);
//begin
// if Sender is TRQMenuItem then
// begin
// if TRQMenuItem(Sender).PluginProc <> NIL then
// // if (TRQMenuItem(Sender).Plugin^) is Tplugin then
// begin
// pr := TRQMenuItem(Sender).PluginProc;
// pr(clickedContact.UID2cmp);
// // Tplugin(TRQMenuItem(Sender).Plugin).cast(
// // char(PM_EVENT)+char(PE_CONTACTMENUCLICK)+_int(TRQMenuItem(Sender).ProcIdx)+_int(StrToIntDef(clickedContact.UID, 0))
// // )
// end;
// end;
//end;
end.