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.
363 lines
8.6 KiB
Plaintext
363 lines
8.6 KiB
Plaintext
unit RnQMacros;
|
|
{$I RnQConfig.inc}
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, System.Classes, Vcl.Menus, RDGlobal;
|
|
|
|
{$I NoRTTI.inc}
|
|
|
|
type
|
|
PMacro = ^TMacro;
|
|
TMacro = record
|
|
hk: Tshortcut;
|
|
sw: boolean;
|
|
opcode: integer;
|
|
data: RawByteString;
|
|
end;
|
|
|
|
TMacros = TArray |
|
|
|
TRnQbtn = record
|
|
Name, Cptn, Hint: String;
|
|
ImageName: TPicName;
|
|
// DefShortCut : String;
|
|
ev: procedure;
|
|
end;
|
|
|
|
function InitMacroses: boolean;
|
|
|
|
function removeMacro(i: integer): boolean;
|
|
function findHK(hk: Tshortcut): integer;
|
|
function addMacro(hk: Tshortcut; sw: boolean; op: integer): boolean;
|
|
procedure ExecuteMacro(m: Integer);
|
|
// convert
|
|
procedure str2macros(s: RawByteString; var m: Tmacros);
|
|
function str2macro(s: RawByteString): Tmacro;
|
|
|
|
procedure popupMenu(m: Tpopupmenu);
|
|
|
|
procedure PopupHintByMacro;
|
|
procedure ToggleAutosize;
|
|
procedure ToggleShowGroups;
|
|
procedure ToggleShowEmptyGroups;
|
|
procedure ToggleStatusSeparation;
|
|
procedure MacroBossMode;
|
|
|
|
implementation
|
|
|
|
uses
|
|
Vcl.Forms,
|
|
RnQSysUtils, RnQBinUtils, RnQLangs, RnQGlobal, RnQTips, ICQContacts,
|
|
SciterLib, roasterLib, utilLib, globalLib, iniLib, themesLib;
|
|
|
|
procedure ExecuteMacro(m: Integer);
|
|
begin
|
|
if BossMode.isBossKeyOn and askPassOnBossKeyOn and Assigned(Account.AccProto) and (Length(Account.AccProto.pwd) > 0) and
|
|
(m <> OP_BOSSKEY) then
|
|
Exit;
|
|
|
|
case m of
|
|
OP_CHAT:
|
|
if UI.Chat.IsVisible then
|
|
begin
|
|
UI.Chat.Hide;
|
|
RestoreForegroundWindow;
|
|
end else if UI.Chat.Chats.Count > 0 then
|
|
begin
|
|
oldForeWindow := GetForegroundWindow;
|
|
ForceForegroundWindow(UI.Chat.Window);
|
|
UI.Chat.Open;
|
|
end;
|
|
OP_ROSTER:
|
|
UI.CL.ToggleVisible;
|
|
OP_TRAY:
|
|
TrayAction;
|
|
OP_CLEAREVENT:
|
|
begin
|
|
if not(UI.Chat.IsVisible and UI.Chat.SawAllHere) and not eventQ.Empty then
|
|
eventQ.pop.Free;
|
|
UI.Tips.RemoveAll;
|
|
end;
|
|
OP_CLEAREVENTS:
|
|
begin
|
|
eventQ.Clear;
|
|
UI.Tips.RemoveAll;
|
|
end;
|
|
OP_POPEVENT:
|
|
ChopAndRealizeEvent;
|
|
OP_QUIT:
|
|
UI.CL.Close;
|
|
OP_SHUTDOWN:
|
|
ExitWindows(0, 0);
|
|
OP_GROUPS:
|
|
ToggleShowGroups;
|
|
OP_MAINMENU:
|
|
UI.CL.OpenMainMenuDelayed;
|
|
OP_STATUSMENU:
|
|
UI.CL.OpenStatusMenuDelayed;
|
|
// OP_VISIBILITYMENU:
|
|
OP_BROWSER:
|
|
OpenURL(' ');
|
|
OP_OFFLINECONTACTS:
|
|
ToggleOnlyOnline;
|
|
OP_AUTOSIZE:
|
|
ToggleAutosize;
|
|
OP_CONNECT:
|
|
DoConnect;
|
|
OP_VIEWINFO:
|
|
if Assigned(clickedContact) then
|
|
clickedContact.ViewInfo;
|
|
OP_ADDBYUIN:
|
|
UI.CL.OpenAddContact;
|
|
OP_WP:
|
|
;
|
|
OP_TOGGLEBORDER:
|
|
ToggleMainFormBorder;
|
|
OP_PREFERENCES:
|
|
ShowForm(WF_SHEET);
|
|
OP_LOCK:
|
|
DoLock;
|
|
OP_HINT:
|
|
PopupHintByMacro;
|
|
{ OP_TIP:
|
|
begin
|
|
tipFrm.actionCount:=1;
|
|
tipFrm.action:=TA_2lclick;
|
|
end; }
|
|
OP_RELOADTHEME:
|
|
ReloadCurrentTheme;
|
|
OP_RELOADLANG:
|
|
ReloadCurrentLang;
|
|
// OP_VISIBLE_TO:
|
|
// begin
|
|
// c := clickedContact;
|
|
// if (c = nil) or c.ImVisibleTo then
|
|
// Exit;
|
|
// roasterLib.UpdateInPlace(c);
|
|
// end;
|
|
OP_TOGGLE_SOUND:
|
|
begin
|
|
playSounds := not playSounds;
|
|
// saveCFG;
|
|
ActionManager.Execute(AK_SAVECONFIG, SaveDelay);
|
|
end;
|
|
OP_BOSSKEY:
|
|
MacroBossMode;
|
|
OP_RESTARTRNQ:
|
|
ReStart;
|
|
OP_SEARCHALLHISTORY:
|
|
UI.OpenHistorySearch;
|
|
end;
|
|
end; // ExecuteMacro
|
|
|
|
function InitMacroses: boolean;
|
|
begin
|
|
setlength(macros, 0);
|
|
addMacro(TextToShortCut('ctrl+shift+i'), True, OP_TRAY);
|
|
addMacro(TextToShortCut('ctrl+shift+o'), True, OP_CHAT);
|
|
addMacro(TextToShortCut('ctrl+o'), FALSE, OP_OFFLINECONTACTS);
|
|
addMacro(TextToShortCut('ctrl+g'), FALSE, OP_GROUPS);
|
|
addMacro(TextToShortCut('ctrl+a'), FALSE, OP_AUTOSIZE);
|
|
addMacro(TextToShortCut('ctrl+p'), FALSE, OP_PREFERENCES);
|
|
addMacro(TextToShortCut('alt+i'), FALSE, OP_VIEWINFO);
|
|
addMacro(TextToShortCut('F11'), FALSE, OP_TOGGLEBORDER);
|
|
addMacro(TextToShortCut('F3'), FALSE, OP_HINT);
|
|
addMacro(TextToShortCut('ctrl+shift+m'), FALSE, OP_MAINMENU);
|
|
result := True;
|
|
end;
|
|
|
|
function removeMacro(i: integer): boolean;
|
|
begin
|
|
result := (i >= 0) and (i < Length(macros));
|
|
if result then
|
|
begin
|
|
while i < Length(macros) - 1 do
|
|
begin
|
|
macros[i] := macros[i + 1];
|
|
inc(i);
|
|
end;
|
|
setlength(macros, i);
|
|
end;
|
|
end; // removeMacro
|
|
|
|
function findHK(hk: Tshortcut): integer;
|
|
begin
|
|
for result := 0 to Length(macros) - 1 do
|
|
if macros[result].hk = hk then
|
|
Exit;
|
|
result := -1;
|
|
end; // findHK
|
|
|
|
function addMacro(hk: Tshortcut; sw: boolean; op: integer): boolean;
|
|
var
|
|
i: integer;
|
|
begin
|
|
if hk = 0 then
|
|
begin
|
|
result := FALSE;
|
|
Exit;
|
|
end;
|
|
i := findHK(hk);
|
|
result := i < 0;
|
|
if result then
|
|
begin
|
|
i := Length(macros);
|
|
setlength(macros, i + 1);
|
|
end;
|
|
|
|
macros[i].hk := hk;
|
|
macros[i].sw := sw;
|
|
macros[i].opcode := op;
|
|
end; // addMacro
|
|
|
|
const
|
|
MFK_HK = 1;
|
|
MFK_SW = 2;
|
|
MFK_OP = 3;
|
|
|
|
function str2macro(s: RawByteString): Tmacro;
|
|
var
|
|
t, l: integer;
|
|
d: AnsiString;
|
|
begin
|
|
while s > '' do
|
|
begin
|
|
t := dword_LEat(@s[1]); // 1234
|
|
l := dword_LEat(@s[5]); // 5678
|
|
d := copy(s, 9, l);
|
|
case t of
|
|
MFK_HK:
|
|
result.hk := str2int(d);
|
|
MFK_SW:
|
|
result.sw := boolean(d[1]);
|
|
MFK_OP:
|
|
result.opcode := str2int(d);
|
|
end;
|
|
delete(s, 1, 8 + l);
|
|
end;
|
|
end; // str2macro
|
|
|
|
procedure str2macros(s: RawByteString; var m: Tmacros);
|
|
var
|
|
l, n: integer;
|
|
begin
|
|
n := 0;
|
|
while Length(s) > 0 do
|
|
begin
|
|
l := str2int(s);
|
|
inc(n);
|
|
setlength(m, n);
|
|
m[n - 1] := str2macro(copy(s, 5, l));
|
|
delete(s, 1, 4 + l);
|
|
end;
|
|
end; // str2macros
|
|
|
|
procedure PopupHintByMacro;
|
|
begin
|
|
if Assigned(UI.CL) then
|
|
UI.CL.ShowHint;
|
|
end; // PopupHintByMacro
|
|
|
|
procedure popupMenu(m: Tpopupmenu);
|
|
begin
|
|
ForceForegroundWindow(UI.CL.Window);
|
|
m.Popup(Screen.width div 2, Screen.height div 2);
|
|
end; // popupMenu
|
|
|
|
procedure ToggleAutosize;
|
|
begin
|
|
AutosizeRoster := not AutosizeRoster;
|
|
UI.CL.InitSettings;
|
|
end; // ToggleAutosize
|
|
|
|
procedure ToggleShowGroups;
|
|
begin
|
|
ShowGroups := not ShowGroups;
|
|
UI.CL.InitSettings;
|
|
ActionManager.Execute(AK_SAVECONFIG, SaveDelay);
|
|
roasterLib.RebuildCL;
|
|
end;
|
|
|
|
procedure ToggleShowEmptyGroups;
|
|
begin
|
|
ShowEmptyGroups := not ShowEmptyGroups;
|
|
UI.CL.InitSettings;
|
|
ActionManager.Execute(AK_SAVECONFIG, SaveDelay);
|
|
roasterLib.RebuildCL;
|
|
end;
|
|
|
|
procedure ToggleStatusSeparation;
|
|
begin
|
|
OnlOfflInOne := not OnlOfflInOne;
|
|
UI.CL.InitSettings;
|
|
ActionManager.Execute(AK_SAVECONFIG, SaveDelay);
|
|
roasterLib.RebuildCL;
|
|
end;
|
|
|
|
procedure MacroBossMode;
|
|
var
|
|
pass: String;
|
|
s: String;
|
|
begin
|
|
if BossMode.isBossKeyOn and askPassOnBossKeyOn then
|
|
begin
|
|
if not (AccPass = '') or (Assigned(Account.AccProto) and (Length(Account.AccProto.pwd) > 0)) then
|
|
begin
|
|
if enteringProtoPWD then
|
|
Exit;
|
|
if AccPass > '' then
|
|
s := 'Account password'
|
|
else
|
|
s := 'Login password';
|
|
enteringProtoPWD := True;
|
|
pass := UI.EnterPassword(GetTranslation(s));
|
|
enteringProtoPWD := False;
|
|
end;
|
|
if not (AccPass = '') and (AccPass <> pass) then
|
|
Exit
|
|
else if (Assigned(Account.AccProto) and (Length(Account.AccProto.pwd) > 0)) then
|
|
if not Account.AccProto.pwdEqual(pass) then
|
|
Exit;
|
|
end;
|
|
BossMode.isBossKeyOn := not BossMode.isBossKeyOn;
|
|
if BossMode.isBossKeyOn then
|
|
begin
|
|
BossMode.toShowChat := UI.Chat.Visible;
|
|
BossMode.toShowCL := UI.CL.Visible;
|
|
if BossMode.toShowChat then
|
|
begin
|
|
UI.Chat.Hide;
|
|
RestoreForegroundWindow;
|
|
end;
|
|
if BossMode.toShowCL then
|
|
UI.CL.ToggleVisible;
|
|
BossMode.activeChat := True;
|
|
UI.Tips.RemoveAll;
|
|
end
|
|
else
|
|
begin
|
|
if not BossMode.activeChat then
|
|
if BossMode.toShowChat then
|
|
if UI.Chat.Chats.count > 0 then
|
|
UI.Chat.Open;
|
|
if BossMode.toShowCL and not UI.CL.Visible then
|
|
UI.CL.ToggleVisible;
|
|
if BossMode.activeChat then
|
|
if BossMode.toShowChat then
|
|
if UI.Chat.Chats.count > 0 then
|
|
UI.Chat.Open;
|
|
end;
|
|
if Assigned(StatusIcon) and Assigned(statusIcon.TrayIcon) then
|
|
begin
|
|
if StatusIcon.TrayIcon.Hidden and not BossMode.isBossKeyOn then
|
|
StatusIcon.TrayIcon.Show
|
|
else if not StatusIcon.TrayIcon.Hidden and BossMode.isBossKeyOn then
|
|
StatusIcon.TrayIcon.Hide;
|
|
StatusIcon.TrayIcon.Update;
|
|
end;
|
|
end;
|
|
|
|
end.
|