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.
219 lines
6.2 KiB
Plaintext
219 lines
6.2 KiB
Plaintext
{
|
|
This file is part of R&Q.
|
|
Under same license
|
|
}
|
|
{$I RnQConfig.inc}
|
|
unit selectcontactsDlg;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, System.SysUtils, System.UITypes, System.Variants,
|
|
SciterJS, SciterJSAPI, SciterLib, RnQDialogs, ICQCommon, ICQContacts;
|
|
|
|
{$I PubRTTI.inc}
|
|
|
|
type
|
|
TUINListItem = record
|
|
kind, groupId: Integer;
|
|
key, name, status, UID: String;
|
|
expanded: Boolean;
|
|
items: TArray |
|
end;
|
|
|
|
{$I NoRTTI.inc}
|
|
|
|
TUINListMethods = class(TNativeMethods)
|
|
class procedure RegisterMethods(var ReturnValue: TSciterValue); override;
|
|
class procedure GetContacts(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
|
|
class procedure GetUINLists(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
|
|
class procedure GetUINList(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
|
|
class procedure SaveUINList(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
|
|
class procedure DeleteUINList(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
|
|
end;
|
|
|
|
TUINListItems = TArray |
|
PUINListItems = ^TUINListItems;
|
|
|
|
implementation
|
|
|
|
uses
|
|
RnQLangs, RQUtil, RDGlobal, uinlistLib, globalLib, utilLib, ICQConsts;
|
|
|
|
class procedure TUINListMethods.RegisterMethods(var ReturnValue: TSciterValue);
|
|
begin
|
|
AddMethod('GetContacts', GetContacts);
|
|
AddMethod('GetUINLists', GetUINLists);
|
|
AddMethod('GetUINList', GetUINList);
|
|
AddMethod('SaveUINList', SaveUINList);
|
|
AddMethod('DeleteUINList', DeleteUINList);
|
|
inherited;
|
|
end;
|
|
|
|
class procedure TUINListMethods.GetContacts(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
|
|
|
|
function FindGroup(var UINList: TUINListItems; Id: Integer): PUINListItems;
|
|
var
|
|
I, C: Integer;
|
|
begin
|
|
if Id = 0 then
|
|
Exit(@UINList);
|
|
|
|
for I := 0 to Length(UINList) - 1 do
|
|
if (UINList[I].kind = 0) and (UINList[I].groupId = Id) then
|
|
Exit(@UINList[I].Items);
|
|
|
|
SetLength(UINList, Length(UINList) + 1);
|
|
C := Length(UINList) - 1;
|
|
UINList[C].kind := 0;
|
|
UINList[C].key := 'Group:' + IntToStr(Id);
|
|
UINList[C].groupId := Id;
|
|
UINList[C].name := groups.ID2Name(Id);
|
|
UINList[C].UID := '';
|
|
UINList[C].expanded := True;
|
|
Result := @UINList[C].Items;
|
|
end;
|
|
|
|
var
|
|
List: TRnQCList;
|
|
ListRecord: TUINListItems;
|
|
ListVar: TParams;
|
|
ParentListRecord: PUINListItems;
|
|
OptionsInt, I, C: Integer;
|
|
OptionsVar: Variant;
|
|
Options: TSCOptions;
|
|
Contact: TICQContact;
|
|
begin
|
|
OptionsInt := 0;
|
|
S2V(argv, OptionsVar);
|
|
for I := VarArrayLowBound(OptionsVar, 1) to VarArrayHighBound(OptionsVar, 1) do
|
|
if OptionsVar[I] = 'sco_multi' then OptionsInt := OptionsInt + 1
|
|
else if OptionsVar[I] = 'sco_groups' then OptionsInt := OptionsInt + 2
|
|
else if OptionsVar[I] = 'sco_predefined' then OptionsInt := OptionsInt + 4;
|
|
Options := TSCOptions(Byte(OptionsInt));
|
|
|
|
List := Account.AccProto.ReadList(LT_ROSTER).Clone.Add(NotInList);
|
|
|
|
if sco_groups in Options then
|
|
SortCLbyGroups(List)
|
|
else
|
|
SortCL(List);
|
|
List.ResetEnumeration;
|
|
|
|
while List.HasMore do
|
|
begin
|
|
Contact := List.GetNext;
|
|
if Contact.UID = '' then
|
|
Continue;
|
|
|
|
if sco_groups in Options then
|
|
ParentListRecord := FindGroup(ListRecord, Contact.Group)
|
|
else
|
|
ParentListRecord := @ListRecord;
|
|
|
|
SetLength(ParentListRecord^, Length(ParentListRecord^) + 1);
|
|
C := Length(ParentListRecord^) - 1;
|
|
|
|
ParentListRecord^[C].kind := 1;
|
|
ParentListRecord^[C].key := 'UIN:' + Contact.UID;
|
|
ParentListRecord^[C].groupId := Contact.Group;
|
|
ParentListRecord^[C].name := Contact.Displayed;
|
|
ParentListRecord^[C].UID := Contact.UID;
|
|
ParentListRecord^[C].status := RosterImgNameFor(Contact);
|
|
end;
|
|
|
|
SetLength(ListVar, Length(ListRecord));
|
|
for I := 0 to Length(ListRecord) - 1 do
|
|
ListVar[I] := UI.RecordToVar(ListRecord[I]);
|
|
|
|
V2S(ListVar, retval);
|
|
|
|
List.Free;
|
|
end;
|
|
|
|
class procedure TUINListMethods.GetUINLists(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
|
|
var
|
|
Names: TParams;
|
|
I: Integer;
|
|
begin
|
|
SetLength(Names, uinlists.Count);
|
|
for I := 0 to uinlists.Count - 1 do
|
|
Names[I] := uinlists.getAt(i)^.name;
|
|
V2S(Names, retval);
|
|
end;
|
|
|
|
class procedure TUINListMethods.GetUINList(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
|
|
var
|
|
ListName: String;
|
|
RnQUINs: TRnQCList;
|
|
UINs: TParams;
|
|
I: Integer;
|
|
begin
|
|
ListName := SciterVarToString(argv);
|
|
|
|
if not uinlists.exists(ListName) then
|
|
Exit;
|
|
|
|
RnQUINs := uinlists.get(ListName).cl;
|
|
SetLength(UINs, RnQUINs.Count);
|
|
for I := 0 to RnQUINs.Count - 1 do
|
|
UINs[I] := RnQUINs.getAt(I).UID;
|
|
|
|
V2S(UINs, retval);
|
|
end;
|
|
|
|
class procedure TUINListMethods.SaveUINList(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
|
|
var
|
|
ListName: String;
|
|
UINs: Variant;
|
|
RnQUINs: TRnQCList;
|
|
I: Integer;
|
|
begin
|
|
ListName := SciterVarToString(argv);
|
|
if ListName = '' then
|
|
Exit;
|
|
|
|
if not uinlists.exists(ListName) or
|
|
(MessageDlg(getTranslation('This uin-list already exists.\nDo you want to overwrite it?'), mtConfirmation, [mbYes, mbNo]) = mrYes) then
|
|
begin
|
|
Inc(argv);
|
|
S2V(argv, UINs);
|
|
|
|
RnQUINs := uinlists.put(ListName).cl;
|
|
for I := Low(TParams(UINs)) to High(TParams(UINs)) do
|
|
RnQUINs.Add(Account.AccProto.GetContact(TUID(TParams(UINs)[I])));
|
|
RnQUINs.ResetEnumeration;
|
|
|
|
MsgDlg('Done', True, mtInformation);
|
|
ActionManager.Execute(AK_SAVEUINLISTS, SaveDelay);
|
|
V2S(True, retval);
|
|
end;
|
|
end;
|
|
|
|
class procedure TUINListMethods.DeleteUINList(argc: UINT; argv: PSciterValue; retval: PSciterValue); cdecl;
|
|
var
|
|
ListName: String;
|
|
List: PUINList;
|
|
begin
|
|
ListName := SciterVarToString(argv);
|
|
List := uinlists.get(ListName);
|
|
if not Assigned(List) then
|
|
Exit;
|
|
if MessageDlg(GetTranslation('Are you sure you want to delete %s ?', [ListName]), mtConfirmation, [mbYes, mbNo]) <> mrYes then
|
|
Exit;
|
|
|
|
if uinlists.remove(List) then
|
|
begin
|
|
//MsgDlg('Done', True, mtInformation);
|
|
V2S(True, retval);
|
|
ActionManager.Execute(AK_SAVEUINLISTS, SaveDelay);
|
|
end
|
|
else
|
|
begin
|
|
MsgDlg('Failed', True, mtError);
|
|
V2S(False, retval);
|
|
end;
|
|
end;
|
|
|
|
end.
|