First "sort by server name" implementation and button name fix.
First implementation of "Sort by server name" algo. Shitty, kinda unreliable, but better than GTK's default. Added Colorizer.Clear() func, which clears passed data from colorcodes. Fixed name on "Add to favorites" button. Still cannot be successfully launched until some race conditions will be fixed in go-gtk.
This commit is contained in:
parent
4d466a9d2b
commit
0c0fcd5b24
@ -21,8 +21,28 @@ type Colorizer struct {
|
|||||||
colors map[string]string
|
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 {
|
func (c *Colorizer) Fix(data string) string {
|
||||||
result := ""
|
var result string = ""
|
||||||
|
|
||||||
data = html.EscapeString(data)
|
data = html.EscapeString(data)
|
||||||
|
|
||||||
|
@ -443,6 +443,7 @@ func (m *MainWindow) InitializeTabs() {
|
|||||||
m.all_servers_store_sortable.SetSortColumnId(m.column_pos["Servers"]["Name"], gtk.SORT_ASCENDING)
|
m.all_servers_store_sortable.SetSortColumnId(m.column_pos["Servers"]["Name"], gtk.SORT_ASCENDING)
|
||||||
|
|
||||||
// Sorting functions.
|
// 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"]["Players"], m.sortServersByPlayers)
|
||||||
m.all_servers_store_sortable.SetSortFunc(m.column_pos["Servers"]["Ping"], m.sortServersByPing)
|
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.SetSize(24, 24)
|
||||||
fav_button_icon_pixbuf.Write(fav_button_icon_bytes)
|
fav_button_icon_pixbuf.Write(fav_button_icon_bytes)
|
||||||
fav_button_icon := gtk.NewImageFromPixbuf(fav_button_icon_pixbuf.GetPixbuf())
|
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.SetTooltipText("Add selected server to favorites")
|
||||||
fav_button.OnClicked(m.addToFavorites)
|
fav_button.OnClicked(m.addToFavorites)
|
||||||
m.toolbar.Insert(fav_button, 3)
|
m.toolbar.Insert(fav_button, 3)
|
||||||
|
@ -10,15 +10,47 @@ import (
|
|||||||
"github.com/mattn/go-gtk/gtk"
|
"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 {
|
func (m *MainWindow) sortServersByPlayers(model *gtk.TreeModel, a *gtk.TreeIter, b *gtk.TreeIter) int {
|
||||||
var players1_raw glib.GValue
|
var players1_raw glib.GValue
|
||||||
var players2_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]
|
players1_online := strings.Split(players1_raw.GetString(), "/")[0]
|
||||||
players2_online := strings.Split(players2_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 {
|
func (m *MainWindow) sortServersByPing(model *gtk.TreeModel, a *gtk.TreeIter, b *gtk.TreeIter) int {
|
||||||
var ping1_raw glib.GValue
|
var ping1_raw glib.GValue
|
||||||
var ping2_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())
|
ping1, _ := strconv.Atoi(ping1_raw.GetString())
|
||||||
ping2, _ := strconv.Atoi(ping2_raw.GetString())
|
ping2, _ := strconv.Atoi(ping2_raw.GetString())
|
||||||
|
Reference in New Issue
Block a user