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.
429 lines
12 KiB
Plaintext
429 lines
12 KiB
Plaintext
unit RnQMacros;
|
|
{$I RnQConfig.inc}
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Graphics, Types, Classes, Menus, RDGlobal, GR32;
|
|
|
|
{$I NoRTTI.inc}
|
|
|
|
type
|
|
PMacro = ^TMacro;
|
|
TMacro = record
|
|
hk: Tshortcut;
|
|
sw: boolean;
|
|
opcode: integer;
|
|
data: RawByteString;
|
|
end;
|
|
|
|
TMacros = TArray |
|
|
|
// TRnQMactros = record
|
|
// Name: String;
|
|
// Cptn: String;
|
|
// DefShortCut: String;
|
|
// ev: procedure;
|
|
// end;
|
|
|
|
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
|
|
Forms, SciterLib,
|
|
RQUtil, RDUtils, RnQSysUtils, RnQBinUtils, RnQLangs, RnQGlobal,
|
|
RnQGraphics32,
|
|
roasterLib, utilLib, globalLib, iniLib, themesLib, Nodes,
|
|
mainDlg, RnQTips, Protocols_all, ICQContacts, ICQConsts;
|
|
{ const
|
|
macroses : array[0..34] of TRnQMACROS = (
|
|
( Name:'chat'; Cptn:'show/hide chat window'; DefShortCut:'ctrl+shift+o'; ev:),
|
|
( Name:'roaster'; Cptn:'show/hide contact list'; DefShortCut:''),
|
|
( Name:'tray'; Cptn:'simulate double-click on tray'; DefShortCut:'ctrl+shift+i'),
|
|
( Name:'clear event'; Cptn:'clear event'; DefShortCut:''),
|
|
( Name:'clear events'; Cptn:'clear all events'; DefShortCut:''),
|
|
( Name:'pop event'; Cptn:'pop event'; DefShortCut:''; ev: chopAndRealizeEvent),
|
|
( Name:'quit'; Cptn:'quit'; DefShortCut:''),
|
|
( Name:'shutdown'; Cptn:'shutdown the computer'; DefShortCut:''),
|
|
( Name:'groups'; Cptn:'show/hide groups'; DefShortCut:''),
|
|
( Name:'main menu'; Cptn:'pop up main menu'; DefShortCut:''),
|
|
( Name:'status menu'; Cptn:'pop up status menu'; DefShortCut:''),
|
|
( Name:'visibility menu'; Cptn:'pop up visibility menu'; DefShortCut:''),
|
|
( Name:'browser'; Cptn:'open browser'; DefShortCut:''),
|
|
( Name:'offline contacts'; Cptn:'show/hide offline contacts'; DefShortCut:''),
|
|
( Name:'autosize'; Cptn:'toggle autosize'; DefShortCut:''),
|
|
( Name:'connect'; Cptn:'connect'; DefShortCut:''),
|
|
( Name:'cd play'; Cptn:'play audio cd'; DefShortCut:''),
|
|
( Name:'cd stop'; Cptn:'stop/eject audio cd'; DefShortCut:''),
|
|
( Name:'view info'; Cptn:'show contact info'; DefShortCut:''),
|
|
( Name:'by uin'; Cptn:'show ''add by uin'' dialog'; DefShortCut:''),
|
|
( Name:'wp'; Cptn:'show white-pages'; DefShortCut:''),
|
|
( Name:'toggle border'; Cptn:'toggle contact list border'; DefShortCut:''),
|
|
( Name:'preferences'; Cptn:'show preferences'; DefShortCut:''),
|
|
( Name:'lock'; Cptn:'lock'; DefShortCut:''),
|
|
( Name:'show hint'; Cptn:'contact tip pop up'; DefShortCut:''; ev: popupHintByMacro),
|
|
( Name:'tip'; Cptn:'simulate double-click on tip message'; DefShortCut:''),
|
|
( Name:'reload theme'; Cptn:'reload theme'; DefShortCut:''; ev=reloadCurrentTheme),
|
|
( Name:'reload language'; Cptn:'reload language'; DefShortCut:''),
|
|
( Name:'visible to'; Cptn:'visible to selected contact'; DefShortCut:''),
|
|
( Name:'toggle sound'; Cptn:'sound on/off'; DefShortCut:''),
|
|
//( Name:''; Cptn:''; DefShortCut:''),
|
|
|
|
( Name:'RnQPlay'; Cptn:'Play'; DefShortCut:'ctrl+shift+ins'),
|
|
( Name:'RnQPause'; Cptn:'Pause'; DefShortCut:'ctrl+shift+home'),
|
|
( Name:'RnQStop'; Cptn:'Stop'; DefShortCut:'ctrl+shift+end'),
|
|
( Name:'RnQNext'; Cptn:'Next'; DefShortCut:'ctrl+shift+pgdn'),
|
|
( Name:'RnQPrev'; Cptn:'Prev'; DefShortCut:'ctrl+shift+pgup')
|
|
);
|
|
}
|
|
|
|
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_CD_PLAY:
|
|
begin
|
|
if sendMCIcommand('status cdaudio mode')='open' then
|
|
sendMCIcommand('set cdaudio door closed');
|
|
sendMCIcommand('play cdaudio');
|
|
end;
|
|
OP_CD_STOP:
|
|
begin
|
|
if s='playing' then
|
|
sendMCIcommand('stop cdaudio')
|
|
else
|
|
if s='open' then
|
|
sendMCIcommand('set cdaudio door closed')
|
|
else
|
|
sendMCIcommand('set cdaudio door open');
|
|
end; }
|
|
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.rebuild;
|
|
end;
|
|
|
|
procedure ToggleShowEmptyGroups;
|
|
begin
|
|
ShowEmptyGroups := not ShowEmptyGroups;
|
|
UI.CL.InitSettings;
|
|
ActionManager.Execute(AK_SAVECONFIG, SaveDelay);
|
|
roasterLib.rebuild;
|
|
end;
|
|
|
|
procedure ToggleStatusSeparation;
|
|
begin
|
|
OnlOfflInOne := not OnlOfflInOne;
|
|
UI.CL.InitSettings;
|
|
ActionManager.Execute(AK_SAVECONFIG, SaveDelay);
|
|
roasterLib.rebuild;
|
|
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.
|