FinchValuesImpl.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Last Edited by: Swinehart, July 24, 1987 3:31:51 pm PDT
DIRECTORY
Atom USING [ GetPName ],
BasicTime USING [ GMT, FromNSTime, Period, Now, nullGMT, ToNSTime ],
Commander USING [CommandProc, Register],
Convert USING [ CardFromRope ],
IO,
NameDB USING [ AttributeSeq, GetAttributes, SetAttribute ],
Rope USING [Cat, Equal, ROPE],
UserCredentials USING [Get],
ViewRec USING [ RecordViewer, SampleRV, ViewRef ],
VoiceUtils USING [ MakeAtom ]
;
FinchValuesImpl: CEDAR PROGRAM
IMPORTS Atom, BasicTime, Commander, Convert, IO, NameDB, Rope, UserCredentials, ViewRec, VoiceUtils = {
ROPE: TYPE = Rope.ROPE;
Values: TYPE = REF ValuesRec;
ValuesRec: TYPE = RECORD [
name: ROPE ← "Telephone Parameters",
Accept: PROC←NIL,
Cancel: PROC←NIL,
ringTune: ROPE←NIL,
ringMode: ATOM←NIL,
doTune: ATOM←NIL,
audioSource: ATOM←NIL,
multiring: ROPE←NIL,
autoAnswer: BOOL�LSE,
dialToneTune: BOOL�LSE,
transmitOnly: BOOL�LSE
];
values: Values ← NEW[ValuesRec←[]];
attributes: NameDB.AttributeSeq;
rv: ViewRec.RecordViewer←NIL;
rName: ROPE;
Accept: PROC = {
attributes ← PutRope[attributes, $ringtune, values.ringTune, NIL];
attributes ← PutAtom[attributes, $ringmode, values.ringMode, $R];
attributes ← PutAtom[attributes, $dotune, values.doTune, $false];
attributes ← PutAtom[attributes, $audioSource, values.audioSource, $telset];
attributes ← PutRope[attributes, $multiring, values.multiring, "false"];
attributes ← PutBool[attributes, $autoanswer, values.autoAnswer];
attributes ← PutBool[attributes, $dialtonetune, values.dialToneTune];
attributes ← PutBool[attributes, $transmitonly, values.transmitOnly];
};
Cancel: PROC = {
attributes ← NameDB.GetAttributes[rName: rName, dbType: $blue];
values.ringTune ← GetRope[attributes, $ringtune, NIL];
values.ringMode ← GetAtom[attributes, $ringmode, $R];
values.doTune ← GetAtom[attributes, $dotune, $false];
values.audioSource ← GetAtom[attributes, $audioSource, $telset];
values.multiring ← GetRope[attributes, $multiring, "false"];
values.autoAnswer ← GetBool[attributes, $autoanswer];
values.dialToneTune ← GetBool[attributes, $dialtonetune];
values.transmitOnly ← GetBool[attributes, $transmitonly];
IF rv#NIL THEN ViewRec.SampleRV[rv];
};
GetRope: PROC[attributes: NameDB.AttributeSeq, attribute: ATOM, default: ROPE]
RETURNS[rope: ROPE] = {
rope ← GetAttribute[attributes, attribute];
IF rope=NIL THEN rope�ult;
};
GetAtom: PROC[attributes: NameDB.AttributeSeq, attribute: ATOM, default: ATOM]
RETURNS[atom: ATOM] = {
value: ROPE ← GetAttribute[attributes, attribute];
RETURN[IF value=NIL THEN default ELSE VoiceUtils.MakeAtom[value, FALSE]];
};
GetBool: PROC[attributes: NameDB.AttributeSeq, attribute: ATOM]
RETURNS[bool: BOOL] = {
value: ROPE ← GetAttribute[attributes, attribute];
RETURN[value.Equal["true", FALSE]];
};
PutRope: PROC[attributes: NameDB.AttributeSeq, attribute: ATOM, value: ROPE, default: ROPE]
RETURNS[newAttributes: NameDB.AttributeSeq] = {
currentValue: ROPE ← GetRope[attributes, attribute, default];
newAttributes ← attributes;
IF currentValue.Equal[value, FALSE] THEN RETURN;
NameDB.SetAttribute[rName, attribute, value];
newAttributes ← NameDB.GetAttributes[rName: rName, dbType: $blue];
};
PutAtom: PROC[attributes: NameDB.AttributeSeq, attribute: ATOM, atom: ATOM, default: ATOM]
RETURNS[newAttributes: NameDB.AttributeSeq] = {
currentAtom: ATOM ← GetAtom[attributes, attribute, default];
newAttributes ← attributes;
IF currentAtom=atom THEN RETURN;
NameDB.SetAttribute[rName, attribute, IF atom=NIL THEN NIL ELSE Atom.GetPName[atom]];
newAttributes ← NameDB.GetAttributes[rName: rName, dbType: $blue];
};
PutBool: PROC[attributes: NameDB.AttributeSeq, attribute:ATOM, bool: BOOL]
RETURNS[newAttributes: NameDB.AttributeSeq] = {
currentBool: BOOL ← GetBool[attributes, attribute];
newAttributes ← attributes;
IF bool=currentBool THEN RETURN;
NameDB.SetAttribute[rName, attribute, IF bool THEN "true" ELSE "false"];
newAttributes ← NameDB.GetAttributes[rName: rName, dbType: $blue];
};
GetAttribute: PROC[attributes: NameDB.AttributeSeq, attribute:ATOM, timed: BOOLFALSE]
RETURNS[value: ROPENIL] = {
IF timed THEN {
expired: BOOL;
value ← GetAttribute[attributes, QualifiedAttribute["time", attribute]];
IF value = NIL THEN RETURN[NIL];
expired ← RelTime[value]<0;
value ← GetAttribute[
attributes,
QualifiedAttribute[IF expired THEN "untimed" ELSE "timed", attribute]];
};
FOR a: NameDB.AttributeSeq ← attributes, a.rest WHILE a#NIL DO
IF a.first.type # attribute THEN LOOP;
value ← a.first.value;
IF Rope.Equal["#", value] THEN RETURN[GetAttribute[attributes, attribute, TRUE]];
ENDLOOP;
};
QualifiedAttribute: PROC[qualifier: ROPE, attribute: ATOM] RETURNS[qualified: ATOM] = {
RETURN[VoiceUtils.MakeAtom[Rope.Cat[qualifier, ".", Atom.GetPName[attribute]], FALSE]];
};
TimeFromRope: PROC[ropeTime: ROPE] RETURNS [time: BasicTime.GMT] = {
RETURN[BasicTime.FromNSTime[Convert.CardFromRope[ropeTime]]];
};
RelTime: PROC[ropeTime: ROPE] RETURNS [relativeToNow: INT] = {
RETURN[BasicTime.Period[from: BasicTime.Now[],
to: BasicTime.FromNSTime[Convert.CardFromRope[ropeTime]]]];
};
TimeRope: PROC [time: BasicTime.GMT ← BasicTime.nullGMT] RETURNS[nowRope: ROPE] = {
IF time = BasicTime.nullGMT THEN time ← BasicTime.Now[];
RETURN[IO.PutFR["%bB", [cardinal[BasicTime.ToNSTime[time]]]]];
};
Initialize: Commander.CommandProc = {
rName ← UserCredentials.Get[].name;
values.Accept ← Accept;
values.Cancel ← Cancel;
Cancel[];
rv ← ViewRec.ViewRef[
agg: values,
createOptions: [highlightSelectedProc: FALSE],
viewerInit: [iconic: FALSE]
];
};
Commander.Register["FinchValues", Initialize, "Produce user interface to change telephone parameters."];
}.