From 8b44d194b5e56e3835a3da4320cfb89806d37ef0 Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Wed, 23 Nov 2016 09:49:39 +0500 Subject: [PATCH] Hide private servers checkboxes. --- ui/mainwindow.go | 44 +++++++++++++++++++++++++++++++++++++++++++ ui/mainwindow_init.go | 30 +++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 80649fd..4de2327 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -60,8 +60,12 @@ type MainWindow struct { profiles *gtk.ComboBoxText // Checkbox for hiding/showing offline servers in 'Servers' tab list. all_servers_hide_offline *gtk.CheckButton + // Checkbox for hiding/showing passworded servers in 'Servers' tab list. + all_servers_hide_private *gtk.CheckButton // Checkbox for hiding/showing offline servers in 'Favorites' tab list. fav_servers_hide_offline *gtk.CheckButton + // Checkbox for hiding/showing passworded servers in 'Favorites' tab list. + fav_servers_hide_private *gtk.CheckButton // Game launch button. launch_button *gtk.Button // Server's information. @@ -311,6 +315,18 @@ func (m *MainWindow) hideOfflineAllServers() { ctx.Eventer.LaunchEvent("loadAllServers", map[string]string{}) } +// Executes when "Hide passworded servers" checkbox changed it's state on +// "Servers" tab. +func (m *MainWindow) hidePrivateAllServers() { + fmt.Println("(Un)Hiding private servers in 'Servers' tab...") + if m.all_servers_hide_private.GetActive() { + ctx.Cfg.Cfg["/serverslist/all_servers/hide_private"] = "1" + } else { + ctx.Cfg.Cfg["/serverslist/all_servers/hide_private"] = "0" + } + ctx.Eventer.LaunchEvent("loadAllServers", map[string]string{}) +} + // Executes when "Hide offline servers" checkbox changed it's state on // "Favorites" tab. func (m *MainWindow) hideOfflineFavoriteServers() { @@ -323,6 +339,18 @@ func (m *MainWindow) hideOfflineFavoriteServers() { ctx.Eventer.LaunchEvent("loadFavoriteServers", map[string]string{}) } +// Executes when "Hide passworded servers" checkbox changed it's state on +// "Favorites" tab. +func (m *MainWindow) hidePrivateFavoriteServers() { + fmt.Println("(Un)Hiding private servers in 'Favorite' tab...") + if m.all_servers_hide_private.GetActive() { + ctx.Cfg.Cfg["/serverslist/favorite/hide_private"] = "1" + } else { + ctx.Cfg.Cfg["/serverslist/favorite/hide_private"] = "0" + } + ctx.Eventer.LaunchEvent("loadFavoriteServers", map[string]string{}) +} + func (m *MainWindow) loadAllServers(data map[string]string) { fmt.Println("Loading all servers...") for _, server := range ctx.Cache.Servers { @@ -344,6 +372,14 @@ func (m *MainWindow) loadAllServers(data map[string]string) { continue } + if m.all_servers_hide_private.GetActive() && server.Server.IsPrivate == "1" { + if server.AllServersIterInList && server.AllServersIterSet { + m.all_servers_store.Remove(iter) + server.AllServersIterInList = false + } + continue + } + if !server.AllServersIterInList && server.AllServersIterSet { m.all_servers_store.Append(iter) server.AllServersIterInList = true @@ -396,6 +432,14 @@ func (m *MainWindow) loadFavoriteServers(data map[string]string) { continue } + if m.fav_servers_hide_private.GetActive() && server.Server.IsPrivate == "1" { + if server.FavServersIterInList && server.FavServersIterSet { + m.fav_servers_store.Remove(iter) + server.FavServersIterInList = false + } + continue + } + // If server on favorites widget, but not favorited (e.g. just // removed from favorites) - remove it from list. if server.Server.Favorite != "1" && server.FavServersIterSet && server.FavServersIterInList { diff --git a/ui/mainwindow_init.go b/ui/mainwindow_init.go index c5acecd..e941197 100644 --- a/ui/mainwindow_init.go +++ b/ui/mainwindow_init.go @@ -466,6 +466,21 @@ func (m *MainWindow) InitializeTabs() { } } + // Checkbox for hiding passworded servers. + m.all_servers_hide_private = gtk.NewCheckButtonWithLabel("Hide private servers") + m.all_servers_hide_private.SetTooltipText("Hide servers which requires password to enter") + tab_all_srv_ctl_vbox.PackStart(m.all_servers_hide_private, false, true, 5) + m.all_servers_hide_private.Clicked(m.hidePrivateAllServers) + // Restore checkbox value. + all_servers_hide_private_cb_val, ok := ctx.Cfg.Cfg["/serverslist/all_servers/hide_private"] + if !ok { + m.all_servers_hide_private.SetActive(true) + } else { + if all_servers_hide_private_cb_val == "1" { + m.all_servers_hide_private.SetActive(true) + } + } + // Final separator. ctl_sep := gtk.NewVSeparator() tab_all_srv_ctl_vbox.PackStart(ctl_sep, true, true, 5) @@ -547,6 +562,21 @@ func (m *MainWindow) InitializeTabs() { } } + // Checkbox for hiding passworded servers. + m.fav_servers_hide_private = gtk.NewCheckButtonWithLabel("Hide private servers") + m.fav_servers_hide_private.SetTooltipText("Hide servers which requires password to enter") + tab_fav_srv_ctl_vbox.PackStart(m.fav_servers_hide_private, false, true, 5) + m.fav_servers_hide_private.Clicked(m.hidePrivateFavoriteServers) + // Restore checkbox value. + fav_servers_hide_private_cb_val, ok := ctx.Cfg.Cfg["/serverslist/favorite/hide_private"] + if !ok { + m.fav_servers_hide_private.SetActive(true) + } else { + if fav_servers_hide_private_cb_val == "1" { + m.fav_servers_hide_private.SetActive(true) + } + } + // Final separator. ctl_fav_sep := gtk.NewVSeparator() tab_fav_srv_ctl_vbox.PackStart(ctl_fav_sep, true, true, 5)