Author: jsuchome
Date: Thu Jun 14 09:28:43 2007
New Revision: 38446
URL: http://svn.opensuse.org/viewcvs/yast?rev=38446&view=rev
Log:
code cleanup (simplified workflow)
initial version of summary dialog with 2 tabs
install squidGuard on start
Modified:
trunk/squidguard/src/Squidguard.ycp
trunk/squidguard/src/complex.ycp
trunk/squidguard/src/dialogs.ycp
trunk/squidguard/src/wizards.ycp
Modified: trunk/squidguard/src/Squidguard.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squidguard/src/Squidguard.ycp?rev=38446&r1=38445&r2=38446&view=diff
==============================================================================
--- trunk/squidguard/src/Squidguard.ycp (original)
+++ trunk/squidguard/src/Squidguard.ycp Thu Jun 14 09:28:43 2007
@@ -35,6 +35,7 @@
module "Squidguard";
textdomain "squidguard";
+import "PackageSystem";
import "Progress";
import "Report";
import "Summary";
@@ -60,6 +61,12 @@
*/
global boolean write_only = false;
+// list of blacklisted urls
+global list<string> blacklist = [];
+
+// list of whitelisted urls
+global list<string> whitelist = [];
+
/**
* Abort function
* return boolean return true if abort
@@ -87,34 +94,22 @@
return modified;
}
-// Settings: Define all variables needed for configuration of squidguard
-// TODO FIXME: Define all the variables necessary to hold
-// TODO FIXME: the configuration here (with the appropriate
-// TODO FIXME: description)
-// TODO FIXME: For example:
-// /**
-// * List of the configured cards.
-// */
-// list cards = [];
-//
-// /**
-// * Some additional parameter needed for the configuration.
-// */
-// boolean additional_parameter = true;
-
/**
* Read all squidguard settings
* @return true on success
*/
global boolean Read() {
+ if (!PackageSystem::CheckAndInstallPackagesInteractive (["squidGuard"]))
+ return false;
+
/* Squidguard read dialog caption */
string caption = _("Initializing squidguard Configuration");
// TODO FIXME Set the right number of stages
integer steps = 4;
- integer sl = 500;
+ integer sl = 100;
sleep(sl);
// TODO FIXME Names of real stages
@@ -142,6 +137,9 @@
// read database
if(Abort()) return false;
Progress::NextStage();
+
+ // TODO read black and white list here
+
/* Error message */
if(false) Report::Error(_("Cannot read database1."));
sleep(sl);
@@ -189,7 +187,7 @@
// TODO FIXME And set the right number of stages
integer steps = 2;
- integer sl = 500;
+ integer sl = 100;
sleep(sl);
// TODO FIXME Names of real stages
Modified: trunk/squidguard/src/complex.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squidguard/src/complex.ycp?rev=38446&r1=38445&r2=38446&view=diff
==============================================================================
--- trunk/squidguard/src/complex.ycp (original)
+++ trunk/squidguard/src/complex.ycp Thu Jun 14 09:28:43 2007
@@ -31,15 +31,106 @@
textdomain "squidguard";
+import "CWM";
+import "CWMTab";
import "Label";
import "Popup";
import "Wizard";
-import "Wizard_hw";
import "Confirm";
import "Squidguard";
include "squidguard/helps.ycp";
+include "squidguard/dialogs.ycp";
+
+/**
+ * map with description of the tabs
+ */
+map tabs_description = $[
+
+ "blacklist" : $[
+ // tab header
+ "header" : _("&Blacklist "),
+ // tab contents description: uses widget names from widget_descr map
+ "contents" : `VBox (
+ "blacklist_table",
+ `HBox (
+ "add_button",
+ "edit_button",
+ "delete_button",
+ `Right ("reset_button")
+ )
+ ),
+ // widgets that are checked for events
+ "widget_names" : [
+ "blacklist_table",
+ "add_button",
+ "edit_button",
+ "delete_button",
+ "reset_button"
+ ],
+ ],
+ "whitelist" : $[
+ // tab header
+ "header" : _("&Whitelist"),
+ "contents" : `VBox (
+ `HVCenter (`Label ("...... and whitelist"))
+ )
+ ],
+];
+
+
+/**
+ * map with description of all widgets
+ */
+map widget_descr = $[
+
+ "blacklist_table" : $[
+ "widget" : `custom,
+ "custom_widget" : `VBox (
+ // label (above table)
+ `Left (`Label (_("Blacklisted Addresses"))),
+ // table header
+ `Table (`id ("table"), `opt (`notify), `header(_("URL")))
+ ),
+ "init" : InitBlacklistTable,
+ "handle" : HandleInitBlacklistTable,
+ "handle_events" : [ "table" ],
+ "help" : _("<p>Here, configure the blacklist. Use <b>Add</b>, <b>Edit</b>, and <b>Delete</b> to modify list of URLs.</p>
+<p>Data are saved after pushing <b>Finish</b> button.</p>"),
+ ],
+ "add_button" : $[
+ "widget" : `push_button,
+ "label" : Label::AddButton (),
+ "no_help" : true,
+ "handle" : HandleAddButton,
+ // only pushing the button is interesting event
+ "handle_events" : [ "add_button" ],
+ ],
+ "edit_button" : $[
+ "widget" : `push_button,
+ "label" : Label::EditButton (),
+ "no_help" : true,
+ "handle_events" : [ "edit_button" ],
+ "handle" : HandleEditButton,
+ ],
+ "delete_button" : $[
+ "widget" : `push_button,
+ "label" : Label::DeleteButton (),
+ "no_help" : true,
+ "handle_events" : [ "delete_button" ],
+ "handle" : HandleDeleteButton,
+ ],
+ "reset_button" : $[
+ "widget" : `push_button,
+ // push button label
+ "label" : _("Rese&t"),
+ "no_help" : true,
+ "handle_events" : [ "reset_button" ],
+// "handle" : HandleResetButton,
+ ],
+];
+
/**
* Return a modification status
@@ -49,10 +140,6 @@
return Squidguard::Modified();
}
-boolean ReallyAbort() {
- return !Squidguard::Modified() || Popup::ReallyAbort(true);
-}
-
boolean PollAbort() {
return UI::PollInput() == `abort;
}
@@ -86,120 +173,37 @@
*/
any SummaryDialog() {
- /* Squidguard summary dialog caption */
+ // caption for the whole dialog
string caption = _("Squidguard Configuration");
- /* FIXME */
- list summary = Squidguard::Summary();
- list unconfigured = summary[1]:[];
- string configured = summary[0]:"";
-
- /* Frame label */
- term contents = Wizard_hw::DetectedContent(_("Squidguard to Configure"),
- unconfigured, false, configured);
-
- Wizard::SetContentsButtons(caption, contents, HELPS["summary"]:"",
- Label::BackButton(), Label::FinishButton());
-
- any ret = nil;
- while(true) {
-
- ret = UI::UserInput();
-
- /* abort? */
- if(ret == `abort || ret == `cancel || ret == `back) {
- if(ReallyAbort()) break;
- else continue;
- }
- /* overview dialog */
- else if(ret == `edit_button) {
- ret = `overview;
- break;
- }
- /* configure the selected device */
- else if(ret == `configure_button) {
- // TODO FIXME: check for change of the configuration
- any selected = UI::QueryWidget(`id(`detected_selbox), `CurrentItem);
- if(selected == `other) {
- ret = `other;
- }
- else {
- ret = `configure;
- }
- break;
- }
- else if(ret == `next) {
- break;
- }
- else {
- y2error("unexpected retcode: %1", ret);
- continue;
- }
- }
+ widget_descr["tab"] = CWMTab::CreateWidget($[
+ "tab_order" : ["blacklist", "whitelist"],
+ "tabs" : tabs_description,
+ "widget_descr" : widget_descr,
+ "initial_tab" : "blacklist",
+ ]);
+ Wizard::SetContentsButtons ("", `VBox (), "", Label::BackButton(), Label::NextButton());
+
+ // layout description of the main dialog
+ term contents = `VBox (
+ `VSpacing (0.2),
+ "tab",
+ `VSpacing (0.2)
+ );
+
+ symbol ret = CWM::ShowAndRun ($[
+ "widget_names" : [ "tab" ],
+ "widget_descr" : widget_descr,
+ "contents" : contents,
+ "caption" : caption,
+ "back_button" : Label::BackButton (),
+ "next_button" : Label::FinishButton (),
+ ]);
+ y2milestone("Returning %1", ret);
return ret;
}
-/**
- * Overview dialog
- * @return dialog result
- */
-any OverviewDialog() {
-
- /* Squidguard overview dialog caption */
- string caption = _("Squidguard Overview");
-
- list overview = Squidguard::Overview();
-
- /* FIXME table header */
- term contents = Wizard_hw::ConfiguredContent(
- /* Table header */
- `header(_("Number"), _("Squidguard")),
- overview, nil, nil, nil, nil );
-
- contents = Wizard_hw::SpacingAround(contents, 1.5, 1.5, 1.0, 1.0);
-
- Wizard::SetContentsButtons(caption, contents, HELPS["overview"]:"",
- Label::BackButton(), Label::FinishButton());
-
- any ret = nil;
- while(true) {
-
- ret = UI::UserInput();
-
- /* abort? */
- if(ret == `abort || ret == `cancel) {
- if(ReallyAbort()) break;
- else continue;
- }
- /* add */
- else if(ret == `add_button) {
- /* FIXME */
- ret = `add;
- break;
- }
- /* edit */
- else if(ret == `edit_button) {
- /* FIXME */
- ret = `edit;
- break;
- }
- /* delete */
- else if(ret == `delete_button) {
- /* FIXME */
- continue;
- }
- else if(ret == `next || ret == `back) {
- break;
- }
- else {
- y2error("unexpected retcode: %1", ret);
- continue;
- }
- }
-
- return ret;
-}
/* EOF */
}
Modified: trunk/squidguard/src/dialogs.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squidguard/src/dialogs.ycp?rev=38446&r1=38445&r2=38446&view=diff
==============================================================================
--- trunk/squidguard/src/dialogs.ycp (original)
+++ trunk/squidguard/src/dialogs.ycp Thu Jun 14 09:28:43 2007
@@ -31,62 +31,149 @@
textdomain "squidguard";
+import "CWMTab";
import "Label";
-import "Wizard";
+import "Popup";
import "Squidguard";
+import "URL";
+import "Wizard";
include "squidguard/helps.ycp";
+
+boolean ReallyAbort() {
+ return !Squidguard::Modified() || Popup::ReallyAbort(true);
+}
+
/**
- * Configure1 dialog
- * @return dialog result
+ * initialize the table with blacklist
*/
-any Configure1Dialog () {
+define void InitBlacklistTable (string id) {
- /* Squidguard configure1 dialog caption */
- string caption = _("Squidguard Configuration");
+ list items = maplist (string url, (list<string>) Squidguard::blacklist, {
+ return `item (`id (url), url);
+ });
+ UI::ChangeWidget (`id ("table"), `Items, items);
+ UI::ChangeWidget (`id ("edit_button"), `Enabled, size (items) > 0);
+ UI::ChangeWidget (`id ("delete_button"), `Enabled, size (items) > 0);
+ if (size (items) > 0)
+ UI::SetFocus (`id ("table"));
+}
- /* Squidguard configure1 dialog contents */
- term contents = `Label (_("First part of configuration of squidguard"));
+/**
+ * Handle universal (=both for black and whitelist table) Delete button events
+ */
+define symbol HandleDeleteButton (string key, map event) {
- Wizard::SetContentsButtons(caption, contents, HELPS["c1"]:"",
- Label::BackButton(), Label::NextButton());
+ string current_item = (string) UI::QueryWidget (`id ("table"), `CurrentItem);
+ if (CWMTab::CurrentTab () == "whitelist")
+ {
+ Squidguard::whitelist = (list<string>) filter (string url, Squidguard::whitelist, {
+ return url != current_item;
+ });
+// InitWhitelistTable ("table");
+ }
+ else
+ {
+ Squidguard::blacklist = (list<string>) filter (string url, Squidguard::blacklist, {
+ return url != current_item;
+ });
+ InitBlacklistTable ("table");
+ }
- any ret = nil;
- while(true) {
+ return nil;
+}
- ret = UI::UserInput();
+/**
+ * Handle universal (=both for black and whitelist table) Edit button events
+ */
+define symbol HandleEditButton (string key, map event) {
- /* abort? */
- if(ret == `abort || ret == `cancel) {
- if(ReallyAbort()) break;
- else continue;
+ string current = (string) UI::QueryWidget (`id ("table"), `CurrentItem);
+ return nil;
+}
+
+// handle table events (double click = edit button)
+define symbol HandleInitBlacklistTable (string key, map event) {
+
+ return HandleEditButton ("edit_button", $[]);
+}
+
+/**
+ * Handle universal (=both for black and whitelist table) Add button events
+ */
+define symbol HandleAddButton (string key, map event) {
+
+ // popup label
+ string label = _("Add new blacklist URL");
+ if (CWMTab::CurrentTab () == "whitelist")
+ label = _("Add new whitelist URL");
+
+ UI::OpenDialog (`opt(`decorated), `HBox (`HSpacing (0.5), `VBox (
+ `VSpacing (0.5),
+ `TextEntry (`id (`url), label),
+ `HBox (
+ `PushButton (`id(`ok),`opt(`key_F10, `default), Label::OKButton()),
+ `PushButton (`id(`cancel),`opt(`key_F9), Label::CancelButton())
+ ),
+ `VSpacing (0.5)), `HSpacing (0.5))
+ );
+ UI::SetFocus (`id (`url));
+ any ret = nil;
+ string url = "";
+ repeat
+ {
+ ret = UI::UserInput ();
+ if (ret == `ok)
+ {
+ url = (string) UI::QueryWidget (`id(`url), `Value);
+ if (url == "")
+ {
+ ret = `cancel;
+ break;
+ }
+ // check if url is valid
+ if (!URL::Check (url))
+ {
+ // popup message
+ Popup::Error (_("The entered URL is not valid."));
+ ret = `notnext;
+ continue;
+ }
+ }
+ } until (ret == `ok || ret == `cancel);
+ UI::CloseDialog ();
+ if (ret == `ok)
+ {
+ if (CWMTab::CurrentTab () == "blacklist")
+ {
+ // use union to filter out duplicates
+ Squidguard::blacklist = (list<string>) union (Squidguard::blacklist, [ url ]);
+ InitBlacklistTable ("table");
+ }
+ else
+ {
+ Squidguard::whitelist = (list<string>) union (Squidguard::whitelist, [ url ]);
+// InitWhitelistTable ("table");
}
- else if(ret == `next || ret == `back) {
- break;
- }
- else {
- y2error("unexpected retcode: %1", ret);
- continue;
- }
}
-
- return ret;
+ return nil;
}
+
/**
- * Configure2 dialog
+ * Configure1 dialog
* @return dialog result
*/
-any Configure2Dialog () {
+any Configure1Dialog () {
- /* Squidguard configure2 dialog caption */
+ /* Squidguard configure1 dialog caption */
string caption = _("Squidguard Configuration");
- /* Squidguard configure2 dialog contents */
- term contents = `Label (_("Second part of configuration of squidguard"));
+ /* Squidguard configure1 dialog contents */
+ term contents = `Label (_("First part of configuration of squidguard"));
- Wizard::SetContentsButtons(caption, contents, HELPS["c2"]:"",
+ Wizard::SetContentsButtons(caption, contents, HELPS["c1"]:"",
Label::BackButton(), Label::NextButton());
any ret = nil;
@@ -111,5 +198,6 @@
return ret;
}
+
/* EOF */
}
Modified: trunk/squidguard/src/wizards.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squidguard/src/wizards.ycp?rev=38446&r1=38445&r2=38446&view=diff
==============================================================================
--- trunk/squidguard/src/wizards.ycp (original)
+++ trunk/squidguard/src/wizards.ycp Thu Jun 14 09:28:43 2007
@@ -35,85 +35,7 @@
import "Wizard";
include "squidguard/complex.ycp";
-include "squidguard/dialogs.ycp";
-/**
- * Add a configuration of squidguard
- * @return sequence result
- */
-any AddSequence() {
-
- /* FIXME: adapt to your needs */
- map aliases = $[
- "config1" : ``(Configure1Dialog()),
- "config2" : ``(Configure2Dialog()),
- ];
-
- /* FIXME: adapt to your needs */
- map sequence = $[
- "ws_start" : "config1",
- "config1" : $[
- `abort : `abort,
- `next : "config2"
- ],
- "config2" : $[
- `abort : `abort,
- `next : `next
- ]
- ];
-
- return Sequencer::Run(aliases, sequence);
-}
-
-/**
- * Main workflow of the squidguard configuration
- * @return sequence result
- */
-any MainSequence() {
-
- /* FIXME: adapt to your needs */
- map aliases = $[
- "summary" : ``( SummaryDialog() ),
- "overview" : ``( OverviewDialog() ),
- "configure" : [ ``( AddSequence() ), true ],
- "add" : [ ``( AddSequence() ), true ],
- "edit" : [ ``( AddSequence() ), true ]
- ];
-
- /* FIXME: adapt to your needs */
- map sequence = $[
- "ws_start" : "summary",
- "summary" : $[
- `abort : `abort,
- `next : `next,
- `overview : "overview",
- `configure : "configure",
- `other : "configure",
- ],
- "overview" : $[
- `abort : `abort,
- `next : `next,
- `add : "add",
- `edit : "edit",
- ],
- "configure" : $[
- `abort : `abort,
- `next : "summary",
- ],
- "add" : $[
- `abort : `abort,
- `next : "overview",
- ],
- "edit" : $[
- `abort : `abort,
- `next : "overview",
- ]
- ];
-
- any ret = Sequencer::Run(aliases, sequence);
-
- return ret;
-}
/**
* Whole configuration of squidguard
@@ -122,9 +44,9 @@
any SquidguardSequence() {
map aliases = $[
- "read" : [ ``( ReadDialog() ), true ],
- "main" : ``( MainSequence() ),
- "write" : [ ``( WriteDialog() ), true ]
+ "read" : [ ``( ReadDialog () ), true ],
+ "main" : ``( SummaryDialog () ),
+ "write" : [ ``( WriteDialog () ), true ]
];
map sequence = $[
@@ -167,7 +89,7 @@
Wizard::SetContentsButtons(caption, contents, "",
Label::BackButton(), Label::NextButton());
- any ret = MainSequence();
+ any ret = SummaryDialog ();
UI::CloseDialog();
return ret;
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org