pull/41/head
xSmurf 8 years ago
parent 2e6f98e410
commit 55ee3ad83d

@ -52,19 +52,19 @@ func activate(app *gtk.Application) {
failDialog(win, "Failed to connect to dbus system bus: %v", err) failDialog(win, "Failed to connect to dbus system bus: %v", err)
} }
rlPermanent := NewRuleList(dbus, win, boxPermanent) rlPermanent := newRuleList(dbus, win, boxPermanent)
if _, err := dbus.isEnabled(); err != nil { if _, err := dbus.isEnabled(); err != nil {
failDialog(win, "Unable is connect to firewall daemon. Is it running?") failDialog(win, "Unable is connect to firewall daemon. Is it running?")
} }
rlPermanent.loadRules(sgfw.RULE_MODE_PERMANENT) rlPermanent.loadRules(sgfw.RULE_MODE_PERMANENT)
rlSession := NewRuleList(dbus, win, boxSession) rlSession := newRuleList(dbus, win, boxSession)
if _, err := dbus.isEnabled(); err != nil { if _, err := dbus.isEnabled(); err != nil {
failDialog(win, "Unable is connect to firewall daemon. Is it running?") failDialog(win, "Unable is connect to firewall daemon. Is it running?")
} }
rlSession.loadRules(sgfw.RULE_MODE_SESSION) rlSession.loadRules(sgfw.RULE_MODE_SESSION)
rlSystem := NewRuleList(dbus, win, boxSystem) rlSystem := newRuleList(dbus, win, boxSystem)
if _, err := dbus.isEnabled(); err != nil { if _, err := dbus.isEnabled(); err != nil {
failDialog(win, "Unable is connect to firewall daemon. Is it running?") failDialog(win, "Unable is connect to firewall daemon. Is it running?")
} }

@ -23,15 +23,15 @@ type ruleRow struct {
rl *ruleList rl *ruleList
rule *sgfw.DbusRule rule *sgfw.DbusRule
widget *gtk.ListBoxRow widget *gtk.ListBoxRow
app_label *gtk.Label gtkLabelApp *gtk.Label
verb_label *gtk.Label gtkLabelVerb *gtk.Label
target_label *gtk.Label gtkLabelTarget *gtk.Label
edit_button *gtk.Button gtkButtonEdit *gtk.Button
save_button *gtk.Button gtkButtonSave *gtk.Button
delete_button *gtk.Button gtkButtonDelete *gtk.Button
} }
func NewRuleList(dbus *dbusObject, win *gtk.Window, list *gtk.ListBox) *ruleList { func newRuleList(dbus *dbusObject, win *gtk.Window, list *gtk.ListBox) *ruleList {
rl := &ruleList{dbus: dbus, win: win, list: list} rl := &ruleList{dbus: dbus, win: win, list: list}
rl.list.SetSelectionMode(gtk.SELECTION_NONE) rl.list.SetSelectionMode(gtk.SELECTION_NONE)
rl.col1, _ = gtk.SizeGroupNew(gtk.SIZE_GROUP_HORIZONTAL) rl.col1, _ = gtk.SizeGroupNew(gtk.SIZE_GROUP_HORIZONTAL)
@ -57,9 +57,9 @@ func (rl *ruleList) addRules(rules []sgfw.DbusRule, mode sgfw.RuleMode) {
} }
row := createWidget(&rules[i]) row := createWidget(&rules[i])
row.rl = rl row.rl = rl
rl.col1.AddWidget(row.app_label) rl.col1.AddWidget(row.gtkLabelApp)
rl.col2.AddWidget(row.verb_label) rl.col2.AddWidget(row.gtkLabelVerb)
rl.col3.AddWidget(row.target_label) rl.col3.AddWidget(row.gtkLabelTarget)
rl.list.Add(row.widget) rl.list.Add(row.widget)
} }
} }
@ -71,23 +71,23 @@ func createWidget(rule *sgfw.DbusRule) *ruleRow {
var grid *gtk.Grid var grid *gtk.Grid
builder.getItems( builder.getItems(
"grid", &grid, "grid", &grid,
"app_label", &row.app_label, "app_label", &row.gtkLabelApp,
"verb_label", &row.verb_label, "verb_label", &row.gtkLabelVerb,
"target_label", &row.target_label, "target_label", &row.gtkLabelTarget,
"edit_button", &row.edit_button, "edit_button", &row.gtkButtonEdit,
"save_button", &row.save_button, "save_button", &row.gtkButtonSave,
"delete_button", &row.delete_button, "delete_button", &row.gtkButtonDelete,
) )
switch sgfw.RuleMode(rule.Mode) { switch sgfw.RuleMode(rule.Mode) {
case sgfw.RULE_MODE_SYSTEM: case sgfw.RULE_MODE_SYSTEM:
row.edit_button.SetVisible(false) row.gtkButtonEdit.SetVisible(false)
row.edit_button.SetNoShowAll(true) row.gtkButtonEdit.SetNoShowAll(true)
row.delete_button.SetSensitive(false) row.gtkButtonDelete.SetSensitive(false)
row.delete_button.SetTooltipText("Cannot delete system rules") row.gtkButtonDelete.SetTooltipText("Cannot delete system rules")
break break
case sgfw.RULE_MODE_SESSION: case sgfw.RULE_MODE_SESSION:
row.save_button.SetSensitive(true) row.gtkButtonSave.SetSensitive(true)
row.save_button.SetNoShowAll(false) row.gtkButtonSave.SetNoShowAll(false)
break break
} }
@ -103,10 +103,10 @@ func createWidget(rule *sgfw.DbusRule) *ruleRow {
} }
func (rr *ruleRow) update() { func (rr *ruleRow) update() {
rr.app_label.SetText(rr.rule.App) rr.gtkLabelApp.SetText(rr.rule.App)
rr.app_label.SetTooltipText(rr.rule.Path) rr.gtkLabelApp.SetTooltipText(rr.rule.Path)
rr.verb_label.SetText(getVerbText(rr.rule)) rr.gtkLabelVerb.SetText(getVerbText(rr.rule))
rr.target_label.SetText(getTargetText(rr.rule)) rr.gtkLabelTarget.SetText(getTargetText(rr.rule))
} }
func getVerbText(rule *sgfw.DbusRule) string { func getVerbText(rule *sgfw.DbusRule) string {
@ -165,9 +165,9 @@ func (rr *ruleRow) onDelete() {
} }
func (rl *ruleList) remove(rr *ruleRow) { func (rl *ruleList) remove(rr *ruleRow) {
rl.col1.RemoveWidget(rr.app_label) rl.col1.RemoveWidget(rr.gtkLabelApp)
rl.col2.RemoveWidget(rr.verb_label) rl.col2.RemoveWidget(rr.gtkLabelVerb)
rl.col3.RemoveWidget(rr.target_label) rl.col3.RemoveWidget(rr.gtkLabelTarget)
rl.list.Remove(rr.widget) rl.list.Remove(rr.widget)
} }

Loading…
Cancel
Save