FinchToolImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by: Swinehart, June 1, 1986 6:45:02 pm PDT
Last Edited by: Pier, April 17, 1984 3:51:54 pm PST
Polle Zellweger (PTZ) October 27, 1985 10:10:45 pm PST
DIRECTORY
BasicTime USING [ GMT, Now, Period ],
Booting USING [ CheckpointProc, RollbackProc, RegisterProcs ],
Buttons USING [ButtonProc, Create, ReLabel, SetDisplayStyle ],
Commander USING [CommandProc, Handle, Register],
CommandTool USING [ArgN],
Containers USING [ ChildXBound, ChildYBound, Container, Create ],
FinchSmarts USING [
AnswerCall, ConvDesc, DisconnectCall, Feep, InitFinchSmarts, UninitFinchSmarts ],
FinchTool,
Icons USING [ IconFlavor, NewIconFromFile ],
IO,
Labels USING [Create],
List USING [Reverse],
MBQueue USING [ Create, CreateButton, CreateMenuEntry, Queue ],
Menus USING [AppendMenuEntry, CreateMenu, Menu, MenuProc ],
Nice USING [ View ],
Process USING [ Detach, Pause, MsecToTicks, SetTimeout],
Rope USING [ ActionType, Cat, Concat, Equal, Fetch, Find, Flatten, Length, Map, MakeRope, Replace, ROPE, Substr ],
Rules USING [ Create ],
Thrush USING [ NB, notReallyInConv, Reason, StateInConv ],
TypeScript USING [ Create ],
UserProfile USING [ Token ],
VFonts USING [ Font, defaultFont ],
ViewerClasses USING [ Viewer, ViewerClassRec, ViewerRec ],
ViewerEvents USING [ EventProc, RegisterEventProc ],
ViewerIO USING [ CreateViewerStreams ],
ViewerLocks USING [ CallUnderWriteLock ],
ViewerOps USING [AddProp, ComputeColumn, CreateViewer, DestroyViewer, FetchProp, PaintViewer, SetOpenHeight],
ViewerSpecs USING [ openTopY, openLeftWidth, openRightWidth ],
ViewerTools USING [GetSelectionContents, GetContents, MakeNewTextViewer, SetContents, SetSelection ],
VoiceUtils USING [ CurrentRName, Report, RegisterWhereToReport, WhereProc ]
;
FinchToolImpl: CEDAR MONITOR     
IMPORTS BasicTime, Booting, Buttons, Commander, CommandTool, Containers, FinchSmarts, FinchTool, Icons, IO, Labels, MBQueue, Menus, Nice, Rope, Rules, Process, TypeScript, UserProfile, VFonts, ViewerEvents, ViewerIO, ViewerLocks, ViewerOps, ViewerSpecs, ViewerTools, VoiceUtils
EXPORTS FinchTool = {
OPEN IO;
Current assumption, subject to change as we develop the notion of multiple calls: Only one call is allowed, by Lark, to reach interesting states (>=failed, +notified). We can select any call that does go beyond an interesting state, to indicate the "current" call; all actions that deal with ongoing call will refer to that one. We will not, for the moment, allow any manual selection of conversation-log entries. When there isn't an entry, it's OK to place calls without hanging up first. So Lark and FinchTool/Directory know about the one-call philosophy; FinchSmarts does not, at present.
Current assumption: all descriptions, including called/calling party fields and conversation logs, describe only the first other party; in a conference, they'll ignore late arrivals.
Types and Typeoids
ConvDesc: TYPE = FinchSmarts.ConvDesc;
NB: TYPE = Thrush.NB;
Reason: TYPE = Thrush.Reason;
ROPE: TYPE = Rope.ROPE;
Viewer: TYPE = ViewerClasses.Viewer;
finchToolHandle: PUBLIC FinchTool.Handle;
cmdHandle: Commander.Handle←NIL;
serverInstance: Rope.ROPENIL;
printLabel: ARRAY Thrush.StateInConv OF Rope.ROPEALL["does not make sense"];
finchQueue: PUBLIC MBQueue.Queue ← MBQueue.Create[];
finchIcon: Icons.IconFlavor ← tool;
leftFinchIcon: Icons.IconFlavor ← tool;
rightFinchIcon: Icons.IconFlavor ← tool;
conversationIcon: Icons.IconFlavor ← tool;
labelledFinchIcon: Icons.IconFlavor ← tool;
labelledLeftFinchIcon: Icons.IconFlavor ← tool;
labelledRightFinchIcon: Icons.IconFlavor ← tool;
labelledConversationIcon: Icons.IconFlavor ← tool;
finchMenu: Menus.Menu;
finchConvMenu: Menus.Menu;
xFudge: INTEGER = 2;
entryHeight: INTEGER = 14;
defaultToolHeight: NAT ← ViewerSpecs.openTopY/5;
Placing and Controlling Calls
PhoneProc: Buttons.ButtonProc = { -- Place call to party identified by primary selection
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
calledPartyText: Rope.ROPE ← ViewerTools.GetSelectionContents[];
DoPhone[ViewerTools.GetSelectionContents[],
SELECT mouseButton FROM
red, yellow => FALSE, blue=> TRUE, ENDCASE=>ERROR];
};
CalledPartyProc: Buttons.ButtonProc = { -- Place call to Called Party field
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
calledPartyText: Rope.ROPE←ViewerTools.GetContents[finchToolHandle.calledPartyText];
SELECT mouseButton FROM
red => ViewerTools.SetSelection[finchToolHandle.calledPartyText, NIL];
yellow => DoPhone[calledPartyText, FALSE];
blue => DoPhone[calledPartyText, TRUE];
ENDCASE => ERROR;
};
CallingPartyProc: Buttons.ButtonProc = { -- Place call to Calling Party field
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
callingPartyText: Rope.ROPE←ViewerTools.GetContents[finchToolHandle.callingPartyText];
SELECT mouseButton FROM
red => ViewerTools.SetSelection[finchToolHandle.callingPartyText, NIL];
yellow => DoPhone[callingPartyText, FALSE];
blue => DoPhone[callingPartyText, TRUE];
ENDCASE => ERROR;
};
PhoneCmd: Commander.CommandProc = { -- Commander Phone command
ENABLE UNWIND => cmdHandle ← NIL;
calledPartyText: Rope.ROPE ← cmd.commandLine.Substr[start: 1, len: cmd.commandLine.Length[]-2];
cmdHandle ← cmd;
DoPhone[calledPartyText];
cmdHandle ← NIL;
};
PhoneHomeCmd: Commander.CommandProc = { -- Phone home (ET) command
cmd.commandLine ← " home\n";
[result, msg] ← PhoneCmd[cmd];
};
RedialCmd: Commander.CommandProc = { -- Redial command
IF ~CheckActive[finchToolHandle] THEN RETURN;
DoPhone[ViewerTools.GetContents[finchToolHandle.calledPartyText], FALSE];
};
DoPhone: PROC[calledPartyText: Rope.ROPE, wantResidence: BOOLFALSE] = {
callee, newCalledPartyText: Rope.ROPE;
pauseNeededInMs: CARDINAL;
IF ~CheckActive[finchToolHandle] OR calledPartyText = NIL OR calledPartyText.Length[]=0
THEN RETURN;
[callee, newCalledPartyText, wantResidence] ← ParseCallee[calledPartyText, wantResidence];
Status["Placing call to ", newCalledPartyText];
IF newCalledPartyText#ViewerTools.GetContents[finchToolHandle.calledPartyText] THEN
ViewerTools.SetContents[finchToolHandle.calledPartyText, newCalledPartyText];
pauseNeededInMs ← HangItUp[FALSE, TRUE];
IF pauseNeededInMs#0 THEN Process.Pause[Process.MsecToTicks[pauseNeededInMs]];
-- Maybe a status check wait loop here ??
FinchTool.CallByDescription[description: callee, residence: wantResidence];
No Conversation ID needed here because assumed not active in any now.
};
Answer: Menus.MenuProc = TRUSTED {
Called whenever the user clicks the answer button
Refers to entries in the viewer finchToolHandle.conversations, not necessarily current one.
cDesc: ConvDesc = GetSelectedDesc[];
IF cDesc = NIL OR (SELECT cDesc.situation.self.state FROM
$notified, $ringing =>FALSE, ENDCASE=>TRUE) THEN {
Report[" No conversation to join"]; RETURN; };
FinchSmarts.AnswerCall[convID: cDesc.situation.self.convID];
};
ConversationMgmtProc: Buttons.ButtonProc = {
Button-invoked operations when applied directly to conversation-viewer log entries.
viewer: Viewer = NARROW[parent];
cDesc: ConvDesc = GetSelectedDesc[viewer];
SelectEntryInConversations[viewer]; -- no manual control over selection!
IF ~CheckActive[finchToolHandle] OR cDesc=NIL THEN RETURN;
IF control THEN Hangup[parent: viewer.parent, mouseButton: mouseButton]
ELSE IF mouseButton#red THEN Answer[parent: viewer.parent, mouseButton: mouseButton];
};
Hangup: PUBLIC Menus.MenuProc = { []←HangItUp[TRUE]; };
Called whenever the user clicks the hangup button
Refers to entries in the viewer finchToolHandle.conversations, not necessarily current one.
HangUpCmd: Commander.CommandProc = {
IF ~CheckActive[finchToolHandle] THEN RETURN;
[] ← HangItUp[TRUE];
};
HangupQuietly: PUBLIC Menus.MenuProc = { []←HangItUp[FALSE]; };
Called to disconnect a call in progress without logging a message.
HangItUp: PROC[complain: BOOL, moreToCome: BOOLFALSE] RETURNS [pauseNeededInMs: CARDINAL𡤀] = TRUSTED {
cDesc: ConvDesc = GetSelectedDesc[];
state: Thrush.StateInConv ← IF cDesc=NIL THEN idle ELSE cDesc.situation.self.state;
isTrunk: BOOLFALSE;
IF cDesc#NIL THEN FOR i: NAT IN [1..cDesc.numParties) DO
IF cDesc.partyInfo[i].type=$trunk THEN isTrunk←TRUE; ENDLOOP;
SELECT state FROM
idle => {
IF complain THEN Report[" No conversation to leave"]; RETURN };
reserved, parsing => IF moreToCome THEN RETURN;
ENDCASE;
IF isTrunk THEN pauseNeededInMs ← IF cDesc.situation.self.state=active THEN 2000 ELSE 500;
FinchSmarts.DisconnectCall[convID: cDesc.situation.self.convID];
};
ParseCallee: PROC[fullCallee: ROPE, wantResidence: BOOL] RETURNS [callee: ROPE, fCallee: ROPE, residence: BOOL] = {
Parses single party-specification: phone number (leading character is not a letter), or named recipient. Names can be RNames or other text sequences that can be looked up in one's private (TDir-style) telephone directory. "XXX at home" is a request to call a residence rather than office number. "home" is equivalent to "<logged-in user> at home". "left XXX" and "middle XXX" are equivalent to "XXX". "right XXX" is the same as "XXX at home". This is to accommodate the strange Command Tool. "XXX at <number>" says you want to call the specified number, and the recipient is XXX (not implemented yet.)
endCallee: INT;
[callee, residence] ←
CheckForMouseButtonSpec[fullCallee, "left ", wantResidence, wantResidence];
[callee, residence] ← CheckForMouseButtonSpec[callee, "middle ", residence, residence];
[callee, residence] ← CheckForMouseButtonSpec[callee, "right ", residence, TRUE];
IF callee.Equal["home", FALSE] THEN {
callee ← VoiceUtils.CurrentRName[];
residence ← TRUE;
};
IF (endCallee�llee.Find[" at home", 0, FALSE]) >= 0 THEN {
callee ← callee.Substr[len: endCallee];
residence ← TRUE;
};
fCallee ← callee;
IF wantResidence THEN fCallee ← fCallee.Concat[" at home"];
};
CheckForMouseButtonSpec: PROC[
fullCallee, pattern: ROPE, wantedRes: BOOL, ifMatch: BOOL]
RETURNS [fCallee: ROPE, wantResidence: BOOL] = {
pLen: INT ← pattern.Length[];
fCallee ← fullCallee;
wantResidence ← wantedRes;
IF fullCallee.Length[] >= pLen AND pattern.Equal[fullCallee.Substr[len: pLen]] THEN {
fCallee ← fullCallee.Substr[start: pLen];
wantResidence ← ifMatch;
};
};
GetSelectedDesc: PUBLIC PROC[chosenButton: Viewer←NIL] RETURNS [cDesc: ConvDesc←NIL] = {
viewer: Viewer = finchToolHandle.conversations;
selected: Viewer ← IF viewer=NIL THEN NIL
ELSE NARROW[ViewerOps.FetchProp[viewer, $selectedEntry]];
IF chosenButton#NIL AND selected#chosenButton THEN RETURN;
IF ~CheckActive[finchToolHandle] OR selected = NIL THEN RETURN;
cDesc ← NARROW[ViewerOps.FetchProp[selected, $convDesc]];
};
Other User Commands
FeepCmd: Commander.CommandProc = {
ENABLE UNWIND => cmdHandle ← NIL;
textToFeep: Rope.ROPE ← FeepValue[cmd.commandLine.Substr[start: 1, len: cmd.commandLine.Length[]-2]];
cmdHandle ← cmd;
IF CheckActive[finchToolHandle] THEN {
cDesc: ConvDesc = GetSelectedDesc[];
IF cDesc#NIL THEN FinchSmarts.Feep[cDesc.situation.self.convID, textToFeep]
ELSE Report["Sorry, was not able to `feep'."];
};
cmdHandle ← NIL;
};
FeepValue: PUBLIC PROC[text: ROPE] RETURNS [feepText: ROPE] = {
Convert an arbitrary rope into characters found on a DTMF touchpad. '*, '#, and digits and all punctuation (often used to format phone numbers) map to themselves. Letters (either case) map to their standard telephone-dial locations. Also, 'Q->'7 and 'Z->'9. One can put a leading '. or something in front of an address to force higher levels to interpret it as a "number" instead of a name.
Now people can dial .FAX or .HELP or 9(800)TheCard, or 9Fastell.
FeepFetch: PROC[data: REF, index: INT] RETURNS [c: CHAR] = {
c←NARROW[data, ROPE].Fetch[index];
c ← SELECT c FROM
IN ['A..'Z] => FeepMap[c+('a-'A)],
IN ['a..'z] => FeepMap[c],
ENDCASE => c;
};
IF text=NIL OR text.Length[]=0 THEN RETURN[text];
RETURN[Rope.Flatten[Rope.MakeRope[base: text, size: text.Length[], fetch: FeepFetch]]];
};
FeepMap: PACKED ARRAY CHAR['a..'z] OF CHAR = [
'2, '2, '2, '3, '3, '3, '4, '4, '4, '5, '5, '5, '6, '6, '6, '7, '7, '7, '7, '8, '8, '8, '9, '9, '9, '9 ];
Starting and Stopping
StartFinch: PUBLIC PROC[] = TRUSTED {
handle: FinchTool.Handle ← finchToolHandle;
IF handle=NIL THEN {
MakeFinchTool[];
handle ← finchToolHandle;
IF handle=NIL THEN RETURN; -- complain?--
};
Report["Connecting . . ."];
FinchSmarts.InitFinchSmarts[
serverInstance, ReportSystemState, ReportConversationState];
Report[IF handle.finchActive THEN "Finch is connected" ELSE "Could not connect",
" to telephone server"];
finchToolHandle.finchActiveAtCheckpoint ← FALSE;
};
FinchCmd: Commander.CommandProc = {
serverInstance ← CommandTool.ArgN[cmd,1];
StartFinch[];
};
ReFinchOnRollback: Booting.RollbackProc = {
IF finchToolHandle=NIL OR ~finchToolHandle.finchActiveAtCheckpoint THEN RETURN;
finchToolHandle.finchActiveAtCheckpoint ← FALSE;
Try[StartFinch];
};
StopFinch: PUBLIC PROC[] = TRUSTED {
handle: FinchTool.Handle = finchToolHandle;
IF handle=NIL THEN RETURN;
Report["Disconnecting . . ."];
FinchSmarts.UninitFinchSmarts[];
Report[IF handle.finchActive THEN "Could not disconnect" ELSE "Finch is disconnected",
" from telephone server"];
};
ButtonStopFinch: Buttons.ButtonProc = { StopFinch[]; };
UnfinchOnDestroy: ViewerEvents.EventProc = {
IF finchToolHandle=NIL THEN RETURN;
StopFinch[];
IF finchToolHandle.conversations#NIL THEN {
finchToolHandle.conversations.inhibitDestroy ← FALSE;
ViewerOps.DestroyViewer[finchToolHandle.conversations];
};
FinchTool.DestroyDirectories[];
IF finchToolHandle.tsIn#NIL THEN finchToolHandle.tsIn.Close[];
IF finchToolHandle.tsOut#NIL THEN finchToolHandle.tsOut.Close[];
finchToolHandle ← NIL;
};
UnFinchOnCheckpointOrBoot: Booting.CheckpointProc = {
IF finchToolHandle=NIL THEN RETURN;
finchToolHandle.finchActiveAtCheckpoint ←
finchToolHandle.finchActiveAtCheckpoint OR finchToolHandle.finchActive;
IF finchToolHandle.finchActive THEN Try[StopFinch];
};
CheckActive: PUBLIC PROC[handle: FinchTool.Handle] RETURNS[active: BOOLFALSE] = TRUSTED {
If not active, try to make it active.
IF handle#NIL AND handle.finchActive THEN RETURN[TRUE];
StartFinch[];
RETURN[handle.finchActive];
};
UnfinchCmd: Commander.CommandProc = { StopFinch[]; };
ReportSystemState: PROC[on: BOOL] = TRUSTED {
IF finchToolHandle=NIL THEN RETURN;
finchToolHandle.finchActive ← on;
IF finchToolHandle.finchWasActive=finchToolHandle.finchActive THEN RETURN;
finchToolHandle.finchWasActive𡤏inchToolHandle.finchActive;
ViewerOps.PaintViewer[finchToolHandle.outer, menu];
};
didOurBest: BOOLFALSE;
maxTime: CARDINAL ← 2500;
Try: PROC[p: PROC] = TRUSTED {
didOurBest ← FALSE;
Process.Detach[FORK Try1[p]];
FOR i: NAT IN [0..100) DO
Process.Pause[Process.MsecToTicks[maxTime/100]];
IF didOurBest THEN EXIT;
ENDLOOP;
};
Try1: PROC[p: PROC] = {
p[];
didOurBest ← TRUE;
};
Conversation Management
ReportConversationState: PROC[ nb: NB, cDesc: ConvDesc, remark: Rope.ROPE ] = {
s: IO.STREAM;
p: PROCESS;
difficulty: BOOLFALSE;
button: Viewer;
state: Thrush.StateInConv;
SELECT nb FROM $success => NULL; ENDCASE => { Status[remark]; RETURN; };
Don't use conversation buttons for failure reports
IF cDesc = NIL THEN {Status["No State to report"]; RETURN;}; --Not much more can be done.
button ← NARROW[cDesc.clientData];
IF button = NIL THEN button ← AddConvDesc[finchToolHandle.conversations, cDesc];
s ← IO.ROS[];
state�sc.situation.self.state;
IF ~cDesc.originatorRecorded AND cDesc.numParties>1 THEN
SELECT cDesc.whoOriginated FROM
If we originated, called-party is already set better than we can get this way (home or office, nicknames, and so on.) Else pick up calling party (incoming), or called-party (outgoing). originatorRecorded is set TRUE whenever one of these fields is set.
us => SetContents[finchToolHandle.calledPartyText, cDesc]; -- Set called-party field
them => SetContents[finchToolHandle.callingPartyText, cDesc]; --Set calling-party field
-- unknown => -- ENDCASE;
IF state=ringing THEN { -- start twiddling if haven't already
IF ~finchToolHandle.keepTwiddling THEN {
finchToolHandle.keepTwiddling ← TRUE;
TRUSTED {Process.Detach[p ← FORK TwiddleFinchIcon[finchToolHandle]]}
};
}
ELSE -- stop twiddling if haven't already
IF finchToolHandle.keepTwiddling THEN
PaintFinchIcon[finchToolHandle, cDesc, state=idle];
IF (state#reserved AND state#parsing) THEN {
s.PutRope["Call "];
IF cDesc.numParties>1 THEN
s.PutF[" %s %s",
rope[SELECT cDesc.whoOriginated FROM
$us => "to", $them=>"from", ENDCASE=>"to/from"],
rope[RepairIntelnet[OtherParty[cDesc, TRUE]]]
];
s.PutF[" at %t", time[cDesc.startTime] ];
IF ~finchToolHandle.keepTwiddling THEN
Don't want to step on twiddling if state=ringing. This call covers hanging up from non-ringing state or placing outgoing call.
PaintFinchIcon[finchToolHandle, cDesc, state=idle];
};
If idle, elaborate.
IF state <= Thrush.notReallyInConv THEN {
s.PutF["%s%s, duration = %r",
rope[IF state#$idle THEN " was not successful"
ELSE IF cDesc.ultimateState>ringing THEN printLabel[$idle] ELSE " was abandoned"],
rope[IF state#$failed THEN ""
ELSE SELECT cDesc.situation.reason FROM
$busy => " -- busy",
$notFound => " -- no valid party found",
$error => " -- connection failed",
$noCircuits => " -- no circuits",
ENDCASE => " for some reason"
],
int[BasicTime.Period[cDesc.startTime, BasicTime.Now[]]]
];
}
ELSE s.PutRope[printLabel[state]];
IF cDesc.situation.comment#NIL THEN s.PutF[" (%s)", rope[cDesc.situation.comment]];
IF remark#NIL THEN s.PutF[" [%s]", rope[remark]];
IF ~cDesc.reportComplete THEN Buttons.ReLabel[ button: button, paint: TRUE,
newName: s.RopeFromROS[] ];
IF state <= Thrush.notReallyInConv THEN cDesc.reportComplete←TRUE;
SelectEntryInConversations[button, state >= $failed AND state#$notified];
};
Describe the other party.
OtherParty: PROC[cDesc: ConvDesc, indicateUnauthenticated: BOOLFALSE] RETURNS [otherParty: ROPENIL] = {
IF cDesc.numParties<2 THEN RETURN;
otherParty ← cDesc.partyInfo[1].name;
IF indicateUnauthenticated AND cDesc.partyInfo[1].type=$telephone THEN otherParty ← otherParty.Concat["?"];
};
Other party descriptions can be of the form "xxx.pa (nnnn)", which confuses Phone commands. Number in parens and lack-of-authentication question mark should be eliminated from number field being set here.
SetContents: PROC[v: ViewerClasses.Viewer, cDesc: ConvDesc] = {
contents: ROPE ← RepairIntelnet[OtherParty[cDesc, FALSE]];
i: INT𡤌ontents.Find["(", 0, FALSE];
IF contents=NIL OR contents.Length[]=0 THEN RETURN;
IF i>0 THEN contents ← contents.Substr[len: i-1];
ViewerTools.SetContents[v, contents, TRUE];
cDesc.originatorRecorded ← TRUE;
};
Other party description can contain Intelnet pause characters and authentication code.
Intelnet pause characters are all characters < '\040, followed by "P". For the present, we assume that there's a P following the pause in one of these; other values are possible, but we don't expect them in phone numbers.
Should be repaired (pause => "*" and auth-code removed) wherever the user sees it.
RepairIntelnet: PROC[num: ROPE] RETURNS[number: ROPE] = {
i: INT←-1;
M: Rope.ActionType={i←i+1; RETURN[c<'\040]};
number ← num;
IF number.Map[0, number.Length[], M] THEN {
number ← Rope.Replace[number, i, 2, "*"]; -- replace first pause with "*"
i←-1;
IF number.Map[0, number.Length[], M] THEN
number ← Rope.Replace[number, i, 5, ""]; -- replace second pause and authentication with "*"
};
};
PaintFinchIcon: ENTRY PROC [handle: FinchTool.Handle, cDesc: ConvDesc, useFinchIcon: BOOL] = {
oldIcon: Icons.IconFlavor ← handle.outer.icon;
handle.keepTwiddling ← FALSE;
NOTIFY handle.twiddleWait;
IF useFinchIcon THEN {
handle.outer.icon ← finchIcon;
handle.outer.label ← NIL;
}
ELSE {
handle.outer.icon ← labelledConversationIcon;
handle.outer.label ← SELECT cDesc.whoOriginated FROM
$us => Rope.Concat["to ", -- this doesn't work right for "listen to this!`' mode
IF cDesc.bluejayConnection THEN "Recording service"
ELSE IF cDesc.proseConnection THEN "Text-to-Speech service"
ELSE
ViewerTools.GetContents[handle.calledPartyText]
],
$them => Rope.Concat["from ", ViewerTools.GetContents[handle.callingPartyText]],
ENDCASE => Rope.Concat["to/from ", RepairIntelnet[OtherParty[cDesc, FALSE]]];
};
IF finchToolHandle.outer.iconic AND oldIcon#handle.outer.icon THEN
ViewerOps.PaintViewer[viewer: handle.outer, hint: all];
};
TwiddleFinchIcon: ENTRY PROC [handle: FinchTool.Handle] = {
ENABLE UNWIND => NULL;
MsPause: INTERNAL PROC [ms: INT] = TRUSTED {
Process.SetTimeout[@handle.twiddleWait, Process.MsecToTicks[ms]];
WAIT handle.twiddleWait;
};
NewIcon: INTERNAL PROC [icon: Icons.IconFlavor, ms: INT] RETURNS [keepGoing: BOOL] = {
IF ms # 0 THEN {
handle.outer.icon ← icon;
IF handle.outer.iconic THEN
ViewerOps.PaintViewer[viewer: handle.outer, hint: all];
MsPause[ms];
};
RETURN [handle.keepTwiddling];
};
pauseReps: INT ← handle.pauseTimeOn/
((handle.pauseTimeTilted + handle.pauseTimeMiddle+handle.pauseTimeDrawFactor)*2);
handle.outer.label ← ViewerTools.GetContents[handle.callingPartyText];
Assumes that the ordinary Finch icon is unlabelled.
WHILE handle.keepTwiddling DO
IF ~handle.outer.iconic THEN
MsPause[250]
ELSE {
FOR i: INT IN [0..pauseReps) DO
IF ~NewIcon[labelledRightFinchIcon, handle.pauseTimeTilted] THEN RETURN;
IF ~NewIcon[labelledFinchIcon, handle.pauseTimeMiddle] THEN RETURN;
IF ~NewIcon[labelledLeftFinchIcon, handle.pauseTimeTilted] THEN RETURN;
IF ~NewIcon[labelledFinchIcon, handle.pauseTimeMiddle] THEN RETURN;
ENDLOOP;
IF ~NewIcon[labelledFinchIcon, handle.pauseTimeOff] THEN RETURN;
};
ENDLOOP;
};
Viewer Construction and Management
Finch Viewer
lineHeight: INT ← 12;
tsHeight: INT ← 3*lineHeight;
convHeight: INT ← 5*lineHeight;
MakeFinchTool: PROC = BEGIN
finchWidth: INTEGER;
dif, wH: INTEGER;
bt: Viewer;
h: FinchTool.Handle;
v: Viewer;
IF finchToolHandle#NIL THEN {
ViewerOps.PaintViewer[finchToolHandle.outer, all]; RETURN; };
finchToolHandle ← NEW[FinchTool.FinchToolRec];
h ← finchToolHandle;
h.finchToolHeight ← defaultToolHeight;
MakeMenus[];
finchToolHandle.outer ← Containers.Create[[-- outer container
name: "Finch", -- name displayed in the caption
icon: finchIcon,
iconic: FALSE,   -- so tool will not be iconic (small) when first created
column: left,    -- initially in the left column
menu: finchMenu,-- displaying our menu command
openHeight: h.finchToolHeight, -- See Walnut
scrollable: FALSE ]];  -- inhibit user from scrolling contents
v ← h.outer;
finchWidth ← IF v.column=right THEN ViewerSpecs.openRightWidth ELSE ViewerSpecs.openLeftWidth;
[]←ViewerEvents.RegisterEventProc[
proc: UnfinchOnDestroy, event: destroy, filter: v, before: TRUE];
bt ← FirstButton[q: finchQueue, name: "Called Party:", proc: CalledPartyProc, parent: v];
h.calledPartyText ← NextRightTextViewer[sib: bt, w: finchWidth/2-bt.ww];
bt ← AnotherButton[q: finchQueue, name: "Calling Party:", proc: CallingPartyProc, sib: h.calledPartyText, newLine: FALSE];
h.callingPartyText ← NextRightTextViewer[sib: bt, w: finchWidth];
Containers.ChildXBound[h.outer, h.callingPartyText];
bt ← MakeRuler[sib: bt, h: 2];
Check how much space is left (if any) in the control window for a typescript.
wH ← v.ch;
IF (dif ← (wH-bt.cy)) < tsHeight+convHeight THEN {
SetOpenHeight[v, wH + (tsHeight+convHeight-dif)];
IF ~v.iconic THEN ViewerOps.ComputeColumn[v.column];
};
h.typescript ← MakeTypescript[sib: bt];
[h.tsIn, h.tsOut] ← ViewerIO.CreateViewerStreams[NIL, h.typescript];
bt ← MakeRuler[sib: h.typescript, h: 2];
h.conversations ← ViewerOps.CreateViewer[
flavor: $Container, paint: TRUE,
info: [wy: bt.wy + 2, ww: v.ww,
wh: convHeight, parent: v, border: FALSE] ];
Containers.ChildXBound[h.outer, h.conversations];
Containers.ChildYBound[h.outer, h.conversations];
ViewerOps.PaintViewer[v, all];    -- reflect above change
IF Rope.Equal[s1: "TRUE", case: FALSE,
s2: UserProfile.Token[key: "Finch.InitialDirectoriesLeft", default: "FALSE"]]
OR Rope.Equal[s1: "TRUE", case: FALSE,
s2: UserProfile.Token[key: "Finch.InitialDirectoriesRight", default: "FALSE"]] THEN
FinchTool.BuildDirectories[];
END;
MakeMenus: PROC = {
Finch Tool Viewer
MakeOneMenu: PROC[menu: Menus.Menu, name: ROPE, proc: Menus.MenuProc] = {
Menus.AppendMenuEntry[ 
menu: menu,
entry: MBQueue.CreateMenuEntry[finchQueue, name, proc, finchToolHandle]
];
};
finchMenu ← Menus.CreateMenu[];
MakeOneMenu[finchMenu, "Phone", PhoneProc];
MakeOneMenu[finchMenu, "Answer", Answer];
MakeOneMenu[finchMenu, "Disconnect", Hangup];
MakeOneMenu[finchMenu, "SpeakText", SpeakSelectedProc];
MakeOneMenu[finchMenu, "StopSpeech", StopSpeechProc];
MakeOneMenu[finchMenu, "Directory", MakeDirectory];
MakeOneMenu[finchMenu, "Drop Out", ButtonStopFinch];
Conversation Viewer
finchConvMenu ← Menus.CreateMenu[];
MakeOneMenu[finchConvMenu, "Answer", Answer];
MakeOneMenu[finchConvMenu, "Disconnect", Hangup];
};
MakeFinchToolCmd: Commander.CommandProc = { MakeFinchTool[]; };
Conversations Viewer
AddConvDesc: PROC[cViewer: Viewer, cDesc: ConvDesc] RETURNS [newV: Viewer←NIL] = {
lastButton: Viewer =
NARROW[ViewerOps.FetchProp[finchToolHandle.conversations, $lastButton]];
BuildLine: PROC = {
IF lastButton = NIL THEN
newV ← FirstButton[
q: finchQueue, name: NIL, proc: ConversationMgmtProc, width: 1024, parent: cViewer]
ELSE newV ← AnotherButton[
q: finchQueue, name: NIL, proc: ConversationMgmtProc, width: 1024, sib: lastButton, newLine: TRUE];
};
IF lastButton#NIL THEN {
lastDesc: ConvDesc = NARROW[ViewerOps.FetchProp[lastButton, $convDesc]];
ViewersOps.AddProp[newV, $convDesc, NIL];
Above could be used to forget about any conversation but the latest one. Once we're dealing with multiple converations, that won't be good enough. Perhaps a better place to do that is where we detect them going idle.
IF lastDesc#NIL AND lastDesc.reportComplete AND
(lastDesc.ultimateState=$reserved OR lastDesc.ultimateState=$parsing)
THEN newV ← lastButton;
At present, this occurs only when one had dial-tone or was dialing and hung up. Otherwise, busy calls would be lost and we some day hope to be able to use the information about busy calls in redialing. STCWN (Subject to change without notice.)
};
IF newV=NIL THEN
IF cViewer.parent.iconic THEN BuildLine[]
ELSE ViewerLocks.CallUnderWriteLock[BuildLine, cViewer];
cDesc.clientData ← newV;
ViewerOps.AddProp[newV, $convDesc, cDesc];
ViewerOps.AddProp[cViewer, $lastButton, newV];
};
SelectEntryInConversations: PROC[entryButton: Viewer, doSelect: BOOLTRUE] = {
prevSelected: Viewer =
NARROW[ViewerOps.FetchProp[entryButton.parent, $selectedEntry]];
IF prevSelected # NIL AND ~prevSelected.destroyed AND
((prevSelected=entryButton) # doSelect) THEN {
Buttons.SetDisplayStyle[prevSelected, $BlackOnWhite];
ViewerOps.PaintViewer[prevSelected, all];
ViewerOps.AddProp[entryButton.parent, $selectedEntry, NIL];
};
IF entryButton.destroyed THEN { Report["Conversation is no longer available."];RETURN; }
ELSE IF ~doSelect OR prevSelected = entryButton THEN RETURN;
Buttons.SetDisplayStyle[entryButton, $BlackOnGrey]; -- show it is selected
ViewerOps.PaintViewer[entryButton, all];
ViewerOps.AddProp[entryButton.parent, $selectedEntry, entryButton];
};
Directory
MakeDirectory: Menus.MenuProc = {
FinchTool.BuildDirectories[];
};
Viewer and Button Utilities
SetOpenHeight: PROC[viewer: ViewerClasses.Viewer, clientHeight: INTEGER] = {
LockedSetHeight: PROC = {ViewerOps.SetOpenHeight[viewer, clientHeight]};
ViewerLocks.CallUnderWriteLock[LockedSetHeight, viewer];
};
FirstLabel: PROC[name: ROPE, parent: Viewer] RETURNS [nV: Viewer] = {
IF ~FinchTool.CheckAborted[parent] THEN RETURN;
nV← Labels.Create[
info: [name: name, parent: parent, wh: entryHeight, wy: 1,
wx: IF parent.scrollable THEN 0 ELSE xFudge, border: FALSE]];
};
ImmediateButton: PUBLIC PROC[name: ROPE, proc: Buttons.ButtonProc, border: BOOL,
sib: Viewer←NIL, parent: Viewer←NIL, fork: BOOLTRUE, guarded: BOOLFALSE, newLine: BOOLFALSE]
RETURNS[Viewer] = {
info: ViewerClasses.ViewerRec;
wy: INTEGER ← 1;
sibWh: INTEGER ← 0;
IF parent=NIL THEN IF sib#NIL THEN parent ← sib.parent ELSE ERROR;
IF sib#NIL THEN { wy ← sib.wy; sibWh ← sib.wh; };
info ← [name: name, wy: wy, wh: entryHeight, parent: parent, border: border];
IF (~newLine) AND sib=NIL THEN ERROR;
IF newLine THEN { -- first button on new line
info.wy← info.wy + sibWh + (IF border THEN 1 ELSE 0); -- extra bit
info.wx← IF parent.scrollable THEN 0 ELSE xFudge;
}
ELSE -- next button right on same line as previous
info.wx← sib.wx+sib.ww+xFudge;
RETURN[Buttons.Create[info: info, proc: proc, fork: fork, guarded: guarded]];
};
QueuedButton: PUBLIC PROC[name: ROPE, proc: Buttons.ButtonProc, border: BOOL,
sib: Viewer, guarded: BOOLFALSE, newLine: BOOLFALSE]
RETURNS[Viewer] = {
info: ViewerClasses.ViewerRec← [name: name, wy: sib.wy, wh: entryHeight,
parent: sib.parent, border: border];
IF newLine THEN -- first button on new line
{ info.wy← sib.wy + sib.wh + (IF border THEN 1 ELSE 0); -- extra bit
info.wx← IF sib.parent.scrollable THEN 0 ELSE xFudge;
}
ELSE -- next button right on same line as previous
info.wx← sib.wx+sib.ww+xFudge;
RETURN[MBQueue.CreateButton[q: finchQueue, info: info, proc: proc, guarded: guarded]];
};
-- sib is a viewer to the left or above the button to be made
AnotherButton: PUBLIC PROC[
q: MBQueue.Queue, name: ROPE, proc: Buttons.ButtonProc, sib: Viewer,
data: REF ANYNIL, border: BOOLFALSE, width: INTEGER← 0,
guarded: BOOLFALSE, font: VFonts.Font ← VFonts.defaultFont, newLine: BOOLFALSE]
RETURNS [nV: Viewer] = {
info: ViewerClasses.ViewerRec← [name: name, wy: sib.wy, ww: width, wh: entryHeight,
parent: sib.parent, border: border];
IF ~CheckAborted[sib] THEN RETURN;
IF newLine THEN { -- first button on new line
info.wy← sib.wy + sib.wh + (IF border THEN 1 ELSE 0); -- extra bit
info.wx← IF sib.parent.scrollable THEN 0 ELSE xFudge;
}
ELSE -- next button right on same line as previous
info.wx← sib.wx+sib.ww+xFudge;
RETURN[MBQueue.CreateButton[
q: q, info: info, proc: proc, clientData: data, font: font, guarded: guarded]]
};
FirstButton: PUBLIC PROC[
q: MBQueue.Queue, name: ROPE, proc: Buttons.ButtonProc,
parent: Viewer, data: REF ANYNIL, border: BOOLFALSE, width: INTEGER← 0,
guarded: BOOLFALSE, font: VFonts.Font ← VFonts.defaultFont]
RETURNS [nV: Viewer] = {
info: ViewerClasses.ViewerRec←
[name: name, parent: parent, wh: entryHeight, wy: 1, ww: width,
wx: IF parent.scrollable THEN 0 ELSE xFudge, border: border];
IF ~CheckAborted[parent] THEN RETURN;
nV← MBQueue.CreateButton[
q: q, info: info, proc: proc, clientData: data, font: font, guarded: guarded];
};
CheckAborted: PUBLIC PROC[sib: Viewer] RETURNS[ok: BOOL] = {
IF sib = NIL THEN RETURN[TRUE];
IF sib.destroyed THEN RETURN[FALSE];
RETURN[TRUE];
};
Creates a text viewer, next right on the same line as sib
sib must be a Viewer, not NIL
NextRightTextViewer: PUBLIC PROC[sib: Viewer, w: INTEGER] RETURNS [nV: Viewer] = {
IF ~FinchTool.CheckAborted[sib] THEN RETURN;
nV← ViewerTools.MakeNewTextViewer[
info: [parent: sib.parent, wx: sib.wx+sib.ww+xFudge, wy: sib.wy,
ww: w, wh: entryHeight, border: FALSE]];
};
MakeRuler: PROC[sib: Viewer, h: INTEGER← 1] RETURNS [r: Viewer] = {
Make an h-bit wide line after sib
IF ~FinchTool.CheckAborted[sib] THEN RETURN;
r← Rules.Create[
info: [parent: sib.parent, wy: sib.wy+sib.wh+1, ww: sib.parent.ww, wh: h]];
Containers.ChildXBound[sib.parent, r];
};
Sib is sibling to create TS after
MakeTypescript: PROC[sib: Viewer] RETURNS [ts: Viewer] = {
y: INTEGER← sib.wy+sib.wh+xFudge;
IF ~CheckAborted[sib] THEN RETURN;
ts← TypeScript.Create[
info: [parent: sib.parent, ww: sib.cw, wy: y, wh: tsHeight, border: FALSE] ];
Containers.ChildYBound[sib.parent, ts];
Containers.ChildXBound[sib.parent, ts];
};
Reporting and Logging
Report: PUBLIC PROC[msg1, msg2, msg3, msg4: ROPENIL] = {
VoiceUtils.Report[where: $Finch, remark:
IO.PutFR["%s%s%s%s",
rope[msg1], rope[msg2], rope[msg3], rope[msg4]]];
};
ReportRope: PUBLIC PROC[msg1: ROPE] = {
IF msg1#NIL THEN VoiceUtils.Report[where: $Finch, remark: msg1];
};
Status: PUBLIC PROC[msg1, msg2, msg3, msg4: ROPENIL] = {
what: ROPE = Rope.Cat[msg1, msg2, msg3, msg4];
ReportRope[what];
};
FinchWhereProc: VoiceUtils.WhereProc = {
RETURN[IF cmdHandle#NIL THEN cmdHandle.out ELSE IF finchToolHandle=NIL THEN NIL
ELSE finchToolHandle.tsOut];
};
FinchWhereCmdProc: VoiceUtils.WhereProc = {
RETURN[NIL];
};
ViewCmd: Commander.CommandProc = TRUSTED {
Nice.View[finchToolHandle, "FinchTool PD"];
};
Registration, Initialization
finchIcon ← Icons.NewIconFromFile["Finch.Icons", 0!ANY=>CONTINUE];
leftFinchIcon ← Icons.NewIconFromFile["Finch.Icons", 4!ANY=>CONTINUE];
rightFinchIcon ← Icons.NewIconFromFile["Finch.Icons", 3!ANY=>CONTINUE];
labelledFinchIcon ← Icons.NewIconFromFile["Finch.Icons", 11!ANY=>CONTINUE];
labelledLeftFinchIcon ← Icons.NewIconFromFile["Finch.Icons", 12!ANY=>CONTINUE];
labelledRightFinchIcon ← Icons.NewIconFromFile["Finch.Icons", 10!ANY=>CONTINUE];
conversationIcon ← Icons.NewIconFromFile["Finch.Icons", 5!ANY=>CONTINUE];
labelledConversationIcon ← Icons.NewIconFromFile["Finch.Icons", 14!ANY=>CONTINUE];
Register a command with the UserExec that will create an instance of this tool
Commander.Register[key: "FinchTool", proc: MakeFinchToolCmd,
doc: "Create a Finch viewers tool" ];
Commander.Register["Finch", FinchCmd, "Start Finch (connect to server)"];
Commander.Register["Unfinch", UnfinchCmd, "Stop Finch (disconnect server)"];
-- initialize text for print form of connect state
Commander.Register["Phone", PhoneCmd, "Place telephone call to specified party"];
Commander.Register["ET", PhoneHomeCmd, "Phonnne hommmmmmme"];
Commander.Register["Redial", RedialCmd, "Hang up and try current call again"];
Commander.Register["HangUp", HangUpCmd, "Hang up current conversation"];
Commander.Register["SpeakText", SpeakTextCmd, "Utter the remainder of the command"];
Commander.Register["STOP!", StopSpeakingCmd, "Stop speaking"];
Commander.Register["Feep", FeepCmd, "Issue touch-tones"];
VoiceUtils.RegisterWhereToReport[proc: FinchWhereProc, where: $Finch];
VoiceUtils.RegisterWhereToReport[proc: FinchWhereCmdProc, where: $FinchCmd];
printLabel[$active] ← " is in progress";
printLabel[$idle] ← " is completed";
printLabel[$ringing] ← " is ringing";
printLabel[$notified] ← NIL;
printLabel[$initiating] ← NIL;
printLabel[$ringback] ← " is ringing";
printLabel[$reserved] ← " Telephone set is off hook";
printLabel[$parsing] ← " Call is being dialed";
TRUSTED { Booting.RegisterProcs[c: UnFinchOnCheckpointOrBoot, r: ReFinchOnRollback, b: UnFinchOnCheckpointOrBoot]; };
Debugging nonsense
Commander.Register["VuFinchTool", ViewCmd,
"Program Management variables for FinchTool"];
}.
Swinehart, August 7, 1985 8:56:34 am PDT
Merge PTZ TextSpeech stuff
changes to: DIRECTORY, MakeMenus, SpeakSelectedProc
Polle Zellweger (PTZ) August 19, 1985 5:00:46 pm PDT
Handle Prose flushing.
changes to: MakeMenus, ReportConversationState, StopSpeechProc
Polle Zellweger (PTZ) August 19, 1985 5:54:32 pm PDT
changes to: DIRECTORY, FinchToolImpl, ReportConversationState, StopSpeechProc
Polle Zellweger (PTZ) September 3, 1985 5:57:21 pm PDT
Curtail intermediate Prose reports if ~finchToolHandle.debug; allow user to specify SpeakText queueIt via red|blue button; some cosmetic feedback changes.
changes to: ReportConversationState, SpeakSelectedProc, speakTextFeedbackLen, SpeakTextWithFeedback, StopSpeechProc
Swinehart, September 6, 1985 10:03:45 am PDT
Don't OPEN FinchTool.bcd, eliminate (status line, extra Phone button).
Eliminate dual-menu, demote Drop-Out. Merge Phone, Redial.
PhoneSelection becomes CommandTool feature, with user profile help.
Add names->feepNum features (can dial 9(800)TheCard)
Add feep command (for talking to your bank or whatever).
Add HangUp, SpeakText, StopSpeaking commands.
Pick up incoming call idents, outgoing calls originated at telset, in called-party fields.
Automatically connect to Server when command is issued; don't delete conversation viewer when disconnecting any more. Reorganize order of procedures.
Polle Zellweger (PTZ) October 4, 1985 6:58:47 pm PDT
Add labelled icons, used to display caller when Finch tool etc is closed.
changes to: labelledFinchIcon, labelledLeftFinchIcon, labelledRightFinchIcon, labelledConversationIcon, TwiddleFinchIcon, (module initialization)
Polle Zellweger (PTZ) October 16, 1985 4:38:58 pm PDT
Change Finch telephone icon to labelled conversation icon while conversation in progress. Added monitor to protect icon twiddling and restoring.
changes to: FinchToolImpl, ConversationHandle, ReportConversationState, PaintFinchIcon, TwiddleFinchIcon, NewIcon, MsPause
Polle Zellweger (PTZ) October 18, 1985 4:08:31 pm PDT
Add ability to recognize node boundaries in selection for text-to-speech.
changes to: SpeakTextWithFeedback, RopeWithNodesFromSelection (new)