Hide private servers checkboxes.

This commit is contained in:
Stanislav Nikitin 2016-11-23 09:49:39 +05:00
parent 3b0a93e63a
commit 8b44d194b5
2 changed files with 74 additions and 0 deletions

View File

@ -60,8 +60,12 @@ type MainWindow struct {
profiles *gtk.ComboBoxText profiles *gtk.ComboBoxText
// Checkbox for hiding/showing offline servers in 'Servers' tab list. // Checkbox for hiding/showing offline servers in 'Servers' tab list.
all_servers_hide_offline *gtk.CheckButton 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. // Checkbox for hiding/showing offline servers in 'Favorites' tab list.
fav_servers_hide_offline *gtk.CheckButton 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. // Game launch button.
launch_button *gtk.Button launch_button *gtk.Button
// Server's information. // Server's information.
@ -311,6 +315,18 @@ func (m *MainWindow) hideOfflineAllServers() {
ctx.Eventer.LaunchEvent("loadAllServers", map[string]string{}) 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 // Executes when "Hide offline servers" checkbox changed it's state on
// "Favorites" tab. // "Favorites" tab.
func (m *MainWindow) hideOfflineFavoriteServers() { func (m *MainWindow) hideOfflineFavoriteServers() {
@ -323,6 +339,18 @@ func (m *MainWindow) hideOfflineFavoriteServers() {
ctx.Eventer.LaunchEvent("loadFavoriteServers", map[string]string{}) 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) { func (m *MainWindow) loadAllServers(data map[string]string) {
fmt.Println("Loading all servers...") fmt.Println("Loading all servers...")
for _, server := range ctx.Cache.Servers { for _, server := range ctx.Cache.Servers {
@ -344,6 +372,14 @@ func (m *MainWindow) loadAllServers(data map[string]string) {
continue 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 { if !server.AllServersIterInList && server.AllServersIterSet {
m.all_servers_store.Append(iter) m.all_servers_store.Append(iter)
server.AllServersIterInList = true server.AllServersIterInList = true
@ -396,6 +432,14 @@ func (m *MainWindow) loadFavoriteServers(data map[string]string) {
continue 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 // If server on favorites widget, but not favorited (e.g. just
// removed from favorites) - remove it from list. // removed from favorites) - remove it from list.
if server.Server.Favorite != "1" && server.FavServersIterSet && server.FavServersIterInList { if server.Server.Favorite != "1" && server.FavServersIterSet && server.FavServersIterInList {

View File

@ -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. // Final separator.
ctl_sep := gtk.NewVSeparator() ctl_sep := gtk.NewVSeparator()
tab_all_srv_ctl_vbox.PackStart(ctl_sep, true, true, 5) 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. // Final separator.
ctl_fav_sep := gtk.NewVSeparator() ctl_fav_sep := gtk.NewVSeparator()
tab_fav_srv_ctl_vbox.PackStart(ctl_fav_sep, true, true, 5) tab_fav_srv_ctl_vbox.PackStart(ctl_fav_sep, true, true, 5)