Fixed favorite servers updating crash when nothing was selected on Servers tab.
This commit is contained in:
parent
3fc873ff2b
commit
ac57e6376c
@ -429,15 +429,17 @@ func (m *MainWindow) loadAllServers() {
|
||||
iter = server.AllServersIter
|
||||
}
|
||||
|
||||
if !server.AllServersIterInList {
|
||||
m.all_servers_store.Append(iter)
|
||||
server.AllServersIterInList = true
|
||||
if m.all_servers_hide_offline.GetActive() && server.Server.Players == "" && server.Server.Maxplayers == "" {
|
||||
if server.AllServersIterInList {
|
||||
m.all_servers_store.Remove(iter)
|
||||
server.AllServersIterInList = false
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if m.all_servers_hide_offline.GetActive() && server.Server.Players == "" && server.Server.Maxplayers == "" && server.AllServersIterInList {
|
||||
m.all_servers_store.Remove(iter)
|
||||
server.AllServersIterInList = false
|
||||
continue
|
||||
if !server.AllServersIterInList && server.AllServersIterSet {
|
||||
m.all_servers_store.Append(iter)
|
||||
server.AllServersIterInList = true
|
||||
}
|
||||
|
||||
if server.Server.Name == "" && server.Server.Players == "" && server.Server.Maxplayers == "" {
|
||||
@ -465,15 +467,6 @@ func (m *MainWindow) loadAllServers() {
|
||||
func (m *MainWindow) loadFavoriteServers() {
|
||||
fmt.Println("Loading favorite servers...")
|
||||
for _, server := range ctx.Cache.Servers {
|
||||
if server.Server.Favorite != "1" && server.FavServersIterSet && server.FavServersIterInList {
|
||||
m.fav_servers_store.Remove(server.FavServersIter)
|
||||
server.FavServersIterInList = false
|
||||
}
|
||||
|
||||
if server.Server.Favorite != "1" {
|
||||
continue
|
||||
}
|
||||
|
||||
iter := new(gtk.TreeIter)
|
||||
|
||||
if !server.FavServersIterSet {
|
||||
@ -483,17 +476,32 @@ func (m *MainWindow) loadFavoriteServers() {
|
||||
iter = server.FavServersIter
|
||||
}
|
||||
|
||||
if !server.FavServersIterInList {
|
||||
m.fav_servers_store.Append(iter)
|
||||
server.FavServersIterInList = true
|
||||
if m.fav_servers_hide_offline.GetActive() && server.Server.Players == "" && server.Server.Maxplayers == "" {
|
||||
if server.FavServersIterInList {
|
||||
m.fav_servers_store.Remove(iter)
|
||||
server.FavServersIterInList = false
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if m.fav_servers_hide_offline.GetActive() && server.Server.Players == "" && server.Server.Maxplayers == "" && server.FavServersIterInList {
|
||||
m.fav_servers_store.Remove(iter)
|
||||
// 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 {
|
||||
m.fav_servers_store.Remove(server.FavServersIter)
|
||||
server.FavServersIterInList = false
|
||||
server.FavServersIterSet = false
|
||||
}
|
||||
|
||||
// Server isn't in favorites and wasn't previously added to widget.
|
||||
if server.Server.Favorite != "1" {
|
||||
continue
|
||||
}
|
||||
|
||||
if !server.FavServersIterInList && server.FavServersIterSet {
|
||||
m.fav_servers_store.Append(iter)
|
||||
server.FavServersIterInList = true
|
||||
}
|
||||
|
||||
if server.Server.Name == "" && server.Server.Players == "" {
|
||||
m.fav_servers_store.SetValue(iter, 0, m.server_offline_pic.GPixbuf)
|
||||
m.fav_servers_store.SetValue(iter, m.column_pos["Favorites"]["IP"], server.Server.Ip + ":" + server.Server.Port)
|
||||
|
@ -21,22 +21,24 @@ func (m *MainWindow) getGameModeName(name string) string {
|
||||
|
||||
func (m *MainWindow) getIpFromServersList(current_tab string) string {
|
||||
// Getting server's address from list.
|
||||
// Assuming that we're on "Servers" tab by default.
|
||||
sel := m.all_servers.GetSelection()
|
||||
model := m.all_servers.GetModel()
|
||||
if strings.Contains(current_tab, "Favorites") {
|
||||
sel = m.fav_servers.GetSelection()
|
||||
model = m.fav_servers.GetModel()
|
||||
}
|
||||
|
||||
iter := new(gtk.TreeIter)
|
||||
_ = sel.GetSelected(iter)
|
||||
|
||||
// Getting server address.
|
||||
var srv_addr string
|
||||
srv_addr_gval := glib.ValueFromNative(srv_addr)
|
||||
model.GetValue(iter, m.column_pos["Servers"]["IP"], srv_addr_gval)
|
||||
|
||||
if strings.Contains(current_tab, "Favorites") {
|
||||
// Getting server's address from list.
|
||||
sel = m.fav_servers.GetSelection()
|
||||
model = m.fav_servers.GetModel()
|
||||
iter := new(gtk.TreeIter)
|
||||
_ = sel.GetSelected(iter)
|
||||
if strings.Contains(current_tab, "Servers") {
|
||||
model.GetValue(iter, m.column_pos["Servers"]["IP"], srv_addr_gval)
|
||||
} else if strings.Contains(current_tab, "Favorites") {
|
||||
model.GetValue(iter, m.column_pos["Favorites"]["IP"], srv_addr_gval)
|
||||
}
|
||||
server_address := srv_addr_gval.GetString()
|
||||
|
Reference in New Issue
Block a user