diff --git a/colorizer/colorizer_object.go b/colorizer/colorizer_object.go index 27225ef..a785ed9 100644 --- a/colorizer/colorizer_object.go +++ b/colorizer/colorizer_object.go @@ -21,8 +21,28 @@ type Colorizer struct { colors map[string]string } +func (c *Colorizer) Clear(data string) string { + var result string = "" + + data = html.EscapeString(data) + + data_splitted := strings.Split(data, "^") + + if len(data_splitted) > 1 { + for item := range data_splitted { + if len(data_splitted[item]) > 0 { + result += data_splitted[item] + } + } + } else { + result = data_splitted[0] + } + + return result +} + func (c *Colorizer) Fix(data string) string { - result := "" + var result string = "" data = html.EscapeString(data) diff --git a/ui/mainwindow_init.go b/ui/mainwindow_init.go index dddb622..561bc53 100644 --- a/ui/mainwindow_init.go +++ b/ui/mainwindow_init.go @@ -443,6 +443,7 @@ func (m *MainWindow) InitializeTabs() { m.all_servers_store_sortable.SetSortColumnId(m.column_pos["Servers"]["Name"], gtk.SORT_ASCENDING) // Sorting functions. + m.all_servers_store_sortable.SetSortFunc(m.column_pos["Servers"]["Name"], m.sortServersByName) m.all_servers_store_sortable.SetSortFunc(m.column_pos["Servers"]["Players"], m.sortServersByPlayers) m.all_servers_store_sortable.SetSortFunc(m.column_pos["Servers"]["Ping"], m.sortServersByPing) @@ -576,7 +577,7 @@ func (m *MainWindow) InitializeToolbar() { fav_button_icon_pixbuf.SetSize(24, 24) fav_button_icon_pixbuf.Write(fav_button_icon_bytes) fav_button_icon := gtk.NewImageFromPixbuf(fav_button_icon_pixbuf.GetPixbuf()) - fav_button := gtk.NewToolButton(fav_button_icon, "Update all servers") + fav_button := gtk.NewToolButton(fav_button_icon, "Add to favorites") fav_button.SetTooltipText("Add selected server to favorites") fav_button.OnClicked(m.addToFavorites) m.toolbar.Insert(fav_button, 3) diff --git a/ui/mainwindow_servers_sorting.go b/ui/mainwindow_servers_sorting.go index cfb569d..a41d402 100644 --- a/ui/mainwindow_servers_sorting.go +++ b/ui/mainwindow_servers_sorting.go @@ -10,15 +10,47 @@ import ( "github.com/mattn/go-gtk/gtk" ) -func (m *MainWindow) sortServersByName() { +func (m *MainWindow) sortServersByName(model *gtk.TreeModel, a *gtk.TreeIter, b *gtk.TreeIter) int { + var name1_raw glib.GValue + var name2_raw glib.GValue + current_tab := m.tab_widget.GetTabLabelText(m.tab_widget.GetNthPage(m.tab_widget.GetCurrentPage())) + if current_tab == "Servers" { + model.GetValue(a, m.column_pos["Servers"]["Name"], &name1_raw) + model.GetValue(b, m.column_pos["Servers"]["Name"], &name2_raw) + } else if current_tab == "Favorites" { + model.GetValue(a, m.column_pos["Favorites"]["Name"], &name1_raw) + model.GetValue(b, m.column_pos["Favorites"]["Name"], &name2_raw) + } else { + return 0 + } + + name1 := ctx.Colorizer.Clear(name1_raw.GetString()) + name2 := ctx.Colorizer.Clear(name2_raw.GetString()) + + if name1 < name2 { + return -1 + } else { + return 1 + } + + return 0 } func (m *MainWindow) sortServersByPlayers(model *gtk.TreeModel, a *gtk.TreeIter, b *gtk.TreeIter) int { var players1_raw glib.GValue var players2_raw glib.GValue - model.GetValue(a, m.column_pos["Servers"]["Players"], &players1_raw) - model.GetValue(b, m.column_pos["Servers"]["Players"], &players2_raw) + + current_tab := m.tab_widget.GetTabLabelText(m.tab_widget.GetNthPage(m.tab_widget.GetCurrentPage())) + if current_tab == "Servers" { + model.GetValue(a, m.column_pos["Servers"]["Players"], &players1_raw) + model.GetValue(b, m.column_pos["Servers"]["Players"], &players2_raw) + } else if current_tab == "Favorites" { + model.GetValue(a, m.column_pos["Favorites"]["Players"], &players1_raw) + model.GetValue(b, m.column_pos["Favorites"]["Players"], &players2_raw) + } else { + return 0 + } players1_online := strings.Split(players1_raw.GetString(), "/")[0] players2_online := strings.Split(players2_raw.GetString(), "/")[0] @@ -39,8 +71,17 @@ func (m *MainWindow) sortServersByPlayers(model *gtk.TreeModel, a *gtk.TreeIter, func (m *MainWindow) sortServersByPing(model *gtk.TreeModel, a *gtk.TreeIter, b *gtk.TreeIter) int { var ping1_raw glib.GValue var ping2_raw glib.GValue - model.GetValue(a, m.column_pos["Servers"]["Ping"], &ping1_raw) - model.GetValue(b, m.column_pos["Servers"]["Ping"], &ping2_raw) + + current_tab := m.tab_widget.GetTabLabelText(m.tab_widget.GetNthPage(m.tab_widget.GetCurrentPage())) + if current_tab == "Servers" { + model.GetValue(a, m.column_pos["Servers"]["Ping"], &ping1_raw) + model.GetValue(b, m.column_pos["Servers"]["Ping"], &ping2_raw) + } else if current_tab == "Favorites" { + model.GetValue(a, m.column_pos["Favorites"]["Ping"], &ping1_raw) + model.GetValue(b, m.column_pos["Favorites"]["Ping"], &ping2_raw) + } else { + return 0 + } ping1, _ := strconv.Atoi(ping1_raw.GetString()) ping2, _ := strconv.Atoi(ping2_raw.GetString())