// Text of project svHdrsP written on 12/6/97 at 8:19 AM
// Beginning of text file svHdrsLocalize


DefineGlobalConstant ( 'kEnglish,
	{
	extrasSlip:
		{
		copyString:		"© 1997 Netstrategy Software",
		created:		"Created:",
		author:			"Author:",
		},

	saveHdrs:
		{
		extrasLabel:		"inet Headers",
		infoLabel:			"inet Headers",
		extrasDescrip:		"Message Header prefs for the EnRoute internet transport.",
		filterTitle:		"Message Size Filter",
		prefsPopTitle:		"Message Headers",
		prefsViewTitle:		"Message Header Settings",
		prefHeading:		"When checking for incoming mail",
		useSaving:			"Save headers locally (faster scanning)",
		notSaving:			"Don't save headers (less storage)",
		maxUIDIxHdg:		"When managing large POP accounts",
		},


	} );



DefineGlobalConstant ( 'kGerman, { } );


SetLocalizationFrame ( {
	English:	kEnglish,
	German:		kGerman,
} );
// End of text file svHdrsLocalize
// Beginning of text file svHdrs.partInfo

DefConst ( 'k_PrefVRootSym, Intern ( kAppSymbol & ":PrefV" ) );

print (k_PrefVRootSym);

DefConst ( 'k_AuthorName, "Les R. Titze" );

DefConst ( 'k_CopyrightStr,
	LocObj ( "© 1997 Netstrategy Software", 'extrasSlip.copyString ) );

partData := {
	author:			k_AuthorName,
	copyright:		k_CopyrightStr,
	};

constant kFilterVersion  := "1.4.2b01" & if language = 'German then " D   ";
constant kPartName       := LocObj ( "inet Headers", 'saveHdrs.extrasLabel );
constant kPartFrameTitle := kPartName;

constant kPartInfoLabel  := LocObj ( "inet Headers", 'saveHdrs.infoLabel );

print ( DateNTime(Time()) && "<---" && $' & kPartName & $' && "as '|" & kAppSymbol & "| Version" && kFilterVersion );

DefConst ( 'k_BuildTime, Time() );

DefConst ( 'k_yearMonthDayStrSpec, 180969 ); // (ROM_datetimestrspecs).yearMonthDayStrSpec

DefConst ( 'k_InfoHdrStr, kPartInfoLabel && kFilterVersion );

DefConst ( 'k_AboutText, LocObj ( "Created:", 'extrasSlip.created )
		&& LongDateStr ( k_BuildTime, 180969 ) & unicodeCR
		& LocObj ( "Author:", 'extrasSlip.author ) && k_AuthorName & unicodeCR
		& k_CopyrightStr & unicodeCR
		& unicodeCR & LocObj (
		"Message Header prefs for the EnRoute internet transport.",
		'saveHdrs.extrasDescrip ) );

SetPartFrameSlot ( 'text, kPartName );
SetPartFrameSlot ( 'labels, '_extensions );

// End of text file svHdrs.partInfo
// Beginning of file svHdrsPrefV
hdrsPrefV :=
    {viewBounds: {left: 0, top: 86, right: 215, bottom: 258},
     viewSetupFormScript:
       func()
       	begin
       	// LRT - 96/12/21 4:25 PM
       	// try to provide for close to avoid Grip of death
       	GetRoot().(EnsureInternal(k_PrefVRootSym)) := self;
       
       	if not GetVariable ( self, 'transport ) then
       		self.transport := GetRoot().|EnRouteN1:Netstrategy|;
       	end,
     viewSetupDoneScript:
       func()
       	begin
       	if not transport then
       		begin
       		:Close();
       		end;
       	end,
     appSymbol: kAppSymbol,
     prefs: {},
     ReorientToScreen: ROM_DefRotateFunc,
     viewQuitScript:
       func()
       	begin
       	try
       		if prefsView and prefsView.openViewsA then
       			begin
       			try
       			local ourV := LFetch ( prefsView.openViewsA, kAppSymbol, 0,
       				'|=|, 'appSymbol );
       
       			if ourV then
       				begin
       				if kDebugOn then print ( "Removing Ourself from openViewsA" );
       				SetRemove ( prefsView.openViewsA, ourV );
       				end;
       			onexception |evt.ex| do nil;
       		end;
       
       		inherited:?viewQuitScript();
       
       		// LRT - 96/12/21 4:59 PM
       		RemoveSlot ( GetRoot(), k_PrefVRootSym );
       
       	onexception |evt.ex| do nil;
       	end,
     title: LocObj ( "Message Header Settings", 'saveHdrs.prefsViewTitle ),
     SetPickerVis:
       func ( view, showIt )
       	begin
       	if showIt then
       		begin
       		if not view._hidden then return;
       		view._hidden := nil;
       		view:Show();
       		end;
       	else	// Hide
       		begin
       		if view._hidden then return;
       		view._hidden := true;
       		view:Hide();
       		end;
       	end,
     _proto: @179
    };

_view000 :=
    {viewBounds: {left: 6, top: 0, right: 118, bottom: 16}, _proto: @229};
AddStepForm(hdrsPrefV, _view000);



heading :=
    {text: LocObj ( "When checking for incoming mail", 'saveHdrs.prefHeading ),
     viewBounds: {left: 5, top: 25, right: 0, bottom: 39},
     viewJustify: 8388656,
     _proto: @218
    };
AddStepForm(hdrsPrefV, heading);



_view001 :=
    {viewBounds: {left: 0, top: 42, right: 0, bottom: 76},
     viewSetupFormScript:
       func()
       	begin
       	// calculate and set the default clusterValue
       	if transport then
       		clusterValue := transport:GetConfig ( prefSlot );
       
       	clusterValue := if clusterValue then 1 else 0;
       	end,
     clusterChanged:
       func()
       	begin
       	if transport then
       		begin
       		transport:SetConfig ( 'saveHdrsInPOPList, clusterValue = 1 );
       		end;
       	end,
     viewJustify: 48,
     prefSlot: 'saveHdrsInPOPList,
     _proto: @203
    };
AddStepForm(hdrsPrefV, _view001);

usePlainTxt :=
    {buttonValue: 1,
     viewBounds: {left: 15, top: 0, right: 0, bottom: 16},
     text:
       LocObj ( "Save headers locally (faster scanning)", 'saveHdrs.useSaving ),
     viewJustify: 52,
     _proto: @202
    };
AddStepForm(_view001, usePlainTxt);



quoteText :=
    {buttonValue: 0,
     viewBounds: {left: 15, top: 16, right: 0, bottom: 32},
     text: LocObj ( "Don't save headers (less storage)", 'saveHdrs.notSaving ),
     viewJustify: 52,
     _proto: @202
    };
AddStepForm(_view001, quoteText);





forBigListsHdg :=
    {text: LocObj ( "When managing large POP accounts", 'saveHdrs.maxUIDIxHdg ),
     viewBounds: {left: 5, top: 93, right: 0, bottom: 107},
     viewJustify: 8388656
     ,
     _proto: @218
    };
AddStepForm(hdrsPrefV, forBigListsHdg);



how2Limit :=
    {
     labelCommands:
       [
       {
       	value:	nil,			// value for pref 'limitPOPListSize
       	item:	"all messages on server",
       },
       
       {
       	value:	'newest,		// value for pref 'limitPOPListSize
       	item:	"only the most recent",
       },
       
       {
       	value:	'oldest,		// value for pref 'limitPOPListSize
       	item:	"only the oldest",
       },
       ],
     text: "Check",
     viewBounds: {left: 14, top: 111, right: 0, bottom: 125}
     ,
     prefSlot: 'limitPOPListSize,
     GetPrefValue:
       func()
       	begin
       	local foundVal := LSearch ( labelCommands,
       		transport:GetConfig ( prefSlot ), 0, '|=|, 'value );
       
       	if not foundVal then 0 else foundVal;
       	end,
     checkCurrentItem: true,
     viewJustify: 8388656,
     labelActionScript:
       func(ix)
       	begin
       	local val := labelCommands[ix].value;
       
       	if val then
       		:SetPickerVis ( numToLimit, true );
       	else
       		:SetPickerVis ( numToLimit, nil );
       
       	transport:SetConfig ( prefSlot, labelCommands[ix].value );
       	end,
     textSetup:
       func()
       	begin
       	labelCommands [ :GetPrefValue() ].item;
       	end,
     viewSetupDoneScript:
       func()
       	begin
       	/*
       	local val := labelCommands [ :GetPrefValue() ].value;
       
       	if val then
       		begin
       		if not numToLimit.viewCObject then
       			numToLimit:Open();
       		end;
       	else
       		begin
       		if numToLimit.viewCObject then
       			numToLimit:Close();
       		end;
       	*/
       	end,
     _proto: @190
    };
AddStepForm(hdrsPrefV, how2Limit);
StepDeclare(hdrsPrefV, how2Limit, 'how2Limit);



numToLimit :=
    {
     labelCommands:
       [
       {
       	value:	5,		// value for pref 'limitPOPListSize
       	item:	"5 messages",
       },
       
       {
       	value:	10,		// value for pref 'limitPOPListSize
       	item:	"10 messages",
       },
       
       {
       	value:	20,
       	item:	"20 messages",
       },
       
       {
       	value:	30,
       	item:	"30 messages",
       },
       
       {
       	value:	50,
       	item:	"50 messages",
       },
       
       {
       	value:	75,
       	item:	"75 messages",
       },
       
       {
       	value:	100,
       	item:	"100 messages",
       },
       
       {
       	value:	150,
       	item:	"150 messages",
       },
       ],
     text: "",
     viewBounds: {left: 44, top: 131, right: 0, bottom: 145},
     prefSlot: 'maxPOPListSize,
     GetPrefValue:
       func()
       	begin
       	local foundVal := LSearch ( labelCommands,
       		transport:GetConfig ( prefSlot ), 0, '|=|, 'value );
       
       	if not foundVal then 1 else foundVal;
       	end,
     checkCurrentItem: true,
     viewJustify: 8388656,
     textSetup:
       func()
       	begin
       	labelCommands [ :GetPrefValue() ].item;
       	end,
     viewSetupDoneScript:
       func()
       	begin
       	if not transport:GetConfig ( 'limitPOPListSize ) then
       		:SetPickerVis ( self, nil );
       	end,
     labelActionScript:
       func(cmd)
       	begin
       	transport:SetConfig ( prefSlot, labelCommands[cmd].value );
       	end,
     _hidden: nil,
     _proto: @190
    };
AddStepForm(hdrsPrefV, numToLimit);
StepDeclare(hdrsPrefV, numToLimit, 'numToLimit);



_view002 :=
    {viewBounds: {left: -18, top: -18, right: -5, bottom: -5}, _proto: @163};
AddStepForm(hdrsPrefV, _view002);



// After Script for "hdrsPrefV"
thisView := hdrsPrefV;
// sets 'saveHdrsInPOPList  



constant |layout_svHdrsPrefV| := hdrsPrefV;
// End of file svHdrsPrefV
// Beginning of file svHdrsExtn
quoPrnExtn :=
    {viewBounds: {left: 8, top: 8, right: 232, bottom: 280},
     AttachExtension:
       DefConst ( 'k_DoPrefExtnFunc, func(prefsView)
       	begin
       	local ourProto := GetLayout ( "svHdrsPrefV" );
       
       	local ourBox := ourProto.viewBounds;
       
       	local pGlobBox := prefsView:GlobalBox();
       	local pLocBox  := prefsView:LocalBox();
       
       	local height := ourBox.bottom - ourBox.top;
       
       	local ourBox :=
       		{
       		left:	pGlobBox.left,
       		top:	pGlobBox.top + 25,
       		right:	pGlobBox.left + pLocBox.right,
       		bottom:	pGlobBox.top + 25 + height,
       		};
       
       	local v := BuildContext (
       		{
       		_proto:			ourProto,
       		viewBounds:		ourBox,
       		viewJustify:	0,
       		prefsView:		prefsView,
       		} );
       
       	if not prefsView.openViewsA then
       		prefsView.(EnsureInternal('openViewsA)) := [ v ];
       	else
       		AddArraySlot ( prefsView.openViewsA, v );
       
       	v:Open();
       	end );
       
       func()
       	begin
       	if kDebugOn then print ( "AttachExtension()" && kAppSymbol );
       
       	local gEnRoute := GetGlobalVar ( 'EnRouteCore );
       
       	if not gEnRoute then return;
       
       	local instA := gEnRoute.installed;
       
       	if not instA or Length(instA) = 0 then return;
       
       	try
       	local transport := LFetch ( instA, transportSym, 0, '|=|, 'id );
       	onexception |evt.ex| do nil;
       
       	if not transport then return;
       
       	transport := GetRoot().(transportSym);
       
       	if not transport then return;
       
       	if not transport.prefExtns
       	or not IsArray(transport.prefExtns) then
       		begin
       		// LRT - 96/12/21 2:42 PM
       		// Grip of death
       		//transport.prefExtns := [];
       		transport.(EnsureInternal('prefExtns)) := Array(0,nil);
       		end;
       
       	if IsReadOnly ( transport.prefExtns ) then
       		transport.prefExtns := Clone ( transport.prefExtns );
       
       	local extnsA := transport.prefExtns;
       
       	try
       	local inIx;
       	while ( inIx := LSearch ( extnsA, kAppSymbol, 0, '|=|, 'id ) ) do
       		begin
       		ArrayRemoveCount ( extnsA, inIx, 1 );
       		if kDebugOn then print ( "Removed old one from prefExtns" );
       		end;
       	onexception |evt.ex| do nil;
       
       	local thisExtn := EnsureInternal (
       		{
       		id:			kAppSymbol,
       		item:		LocObj ( "Message Headers", 'saveHdrs.prefsPopTitle ),
       		pickable:	true,
       		_proto:
       			{
       			callFunc:	nil,
       			},
       		} );
       
       	thisExtn._proto.callFunc := k_DoPrefExtnFunc;	// prevent bad refs in "RemoveScript"
       
       	AddArraySlot ( transport.prefExtns, thisExtn );
       	nil;
       	end,
     DetachExtension:
       func()
       	begin
       	if kDebugOn then print ( "DetachExtension()" && kAppSymbol );
       	end,
     InstallExtension:
       func()
       	begin
       	local gEnRoute := GetGlobalVar ( 'EnRouteCore );
       
       	if not gEnRoute then
       		begin
       		gEnRoute := EnsureInternal(
       			{
       			//	MacBinaryRegistry:	[],
       				installed:			[],
       				extended:			[],
       			} );
       		DefGlobalVar ( EnsureInternal ( 'EnRouteCore ), gEnRoute );
       		end;
       
       	local extendA := gEnRoute.extended;
       	if not extendA then
       		begin
       		extendA := gEnRoute.(EnsureInternal('extended)) := Array(0,nil);
       		end;
       
       	if Length ( extendA ) > 0 then
       		begin
       		local inIx;
       		try
       		while ( inIx := LSearch ( extendA, kAppSymbol, 0, '|=|, 'id ) ) do
       			begin
       			ArrayRemoveCount ( extendA, inIx, 1 );
       			if kDebugOn then print ( "Removed old one from EnRoute Core" );
       			end;
       		onexception |evt.ex| do nil;
       		end;
       
       	local thisExtn := EnsureInternal (
       		{
       			transportSym:	transportSym,
       			id:				kAppSymbol, 
       			title:			LocObj ( "Message Headers", 'saveHdrs.prefsPopTitle ),
       			extension:
       				{
       				_proto:		nil,
       				},
       		} );
       
       	// prevent bad package refs during "RemoveScript"
       	thisExtn.extension._proto := self;
       
       	AddArraySlot ( gEnRoute.extended, thisExtn );
       
       	local transport := GetRoot().(transportSym);
       
       	if transport then
       		:?AttachExtension();
       	else
       		begin
       		//if kDebugOn then begin gc(); stats(); end;
       		end;
       	end,
     transportSym: '|EnRouteN1:Netstrategy|,
     viewClass: 74
    };

// After Script for "quoPrnExtn"
thisView := quoPrnExtn;
RemoveSlot ( thisView, ' viewBounds );
RemoveSlot ( thisView, ' viewClass );


constant |layout_svHdrsExtn| := quoPrnExtn;
// End of file svHdrsExtn
// Beginning of file svHdrsRoot
svHdrsRoot :=
    {viewBounds: {left: 0, top: 0, right: 200, bottom: 125},
     viewJustify: 80,
     _proto: @180
    };

_view003 :=
    {title: k_InfoHdrStr,
     viewBounds: {left: 0, top: 0, right: 68, bottom: 16},
     _proto: @229
    };
AddStepForm(svHdrsRoot, _view003);

// After Script for "_view003"
thisView := _view003;
RemoveSlot ( thisView, 'viewBounds );



_view004 :=
    {text: k_AboutText,
     viewBounds: {left: 5, top: 22, right: -5, bottom: -5},
     viewJustify: 240,
     _proto: @218
    };
AddStepForm(svHdrsRoot, _view004);




constant |layout_svHdrsRoot| := svHdrsRoot;
// End of file svHdrsRoot
// Beginning of text file svHdrsInstall

InstallScript := func ( partFrame )
	begin
	local extnFrame := GetLayout ( "svHdrsExtn" );

	extnFrame:?InstallExtension();
	end;

RemoveScript := func ( removeFrame )
	begin
	try
		local prefV := GetRoot().(k_PrefVRootSym);
		if prefV and prefV.viewCObject then
			begin
			prefV:Close();
			end;
	onexception |evt.ex| do nil;
	RemoveSlot ( GetRoot(), k_PrefVRootSym );

	local tpSymbols := [];
	local gEnRoute := GetGlobalVar ( 'EnRouteCore );
	if gEnRoute then
		begin
		local extendA := gEnRoute.extended;
		if extendA and Length ( extendA ) > 0 then
			begin
			local inIx;
			while ( inIx := LSearch ( extendA, kAppSymbol, 0, '|=|, 'id ) ) do
				begin
				AddArraySlot ( tpSymbols, extendA[inIx].transportSym );
				ArrayRemoveCount ( extendA, inIx, 1 );
				if kDebugOn then print ( "Removed from EnRoute Core" );
				end;
			end;
		end;

	local tpSym;
	foreach tpSym in tpSymbols do
		begin
		if tpSym then
			begin
			local transport := GetRoot().(tpSym);
			if transport and transport.prefExtns then
				begin
				local extnsA := transport.prefExtns;
				local inIx;
				while ( inIx := LSearch ( extnsA, kAppSymbol, 0, '|=|, 'id ) ) do
					begin
					ArrayRemoveCount ( extnsA, inIx, 1 );
					if kDebugOn then print ( "Removed from prefExtns" );
					end;
				if Length ( transport.prefExtns ) = 0 then
					RemoveSlot ( transport, 'prefExtns );
				end;
			end;
		end;
	end;
// End of text file svHdrsInstall



