Configuration and tray icon.
Configuration is now properly saved for parameters in Options window. Also they are restored fine. Added tray icon with two default actions: show/hide and exit. More to come.
This commit is contained in:
@@ -66,6 +66,10 @@ type MainWindow struct {
|
||||
qc_server_address *gtk.Entry
|
||||
// Quick connect: password
|
||||
qc_password *gtk.Entry
|
||||
// Tray icon.
|
||||
tray_icon *gtk.StatusIcon
|
||||
// Tray menu.
|
||||
tray_menu *gtk.Menu
|
||||
|
||||
// Storages.
|
||||
// All servers store.
|
||||
@@ -83,6 +87,10 @@ type MainWindow struct {
|
||||
// Other
|
||||
// Old profiles count.
|
||||
old_profiles_count int
|
||||
|
||||
// Flags.
|
||||
// Window is hidden?
|
||||
hidden bool
|
||||
}
|
||||
|
||||
func (m *MainWindow) addToFavorites() {
|
||||
@@ -280,6 +288,11 @@ func (m *MainWindow) Initialize() {
|
||||
// Sidebar initialization.
|
||||
m.initializeSidebar()
|
||||
|
||||
// Tray icon.
|
||||
if ctx.Cfg.Cfg["/general/show_tray_icon"] == "1" {
|
||||
m.initializeTrayIcon()
|
||||
}
|
||||
|
||||
m.vbox.PackStart(m.hpane, true, true, 5)
|
||||
|
||||
// Temporary hack.
|
||||
@@ -445,6 +458,9 @@ func (m *MainWindow) initializeStorages() {
|
||||
|
||||
// Profiles count after filling combobox. Defaulting to 0.
|
||||
m.old_profiles_count = 0
|
||||
|
||||
// Window hidden flag.
|
||||
m.hidden = false
|
||||
}
|
||||
|
||||
func (m *MainWindow) InitializeTabs() {
|
||||
@@ -605,6 +621,41 @@ func (m *MainWindow) InitializeToolbar() {
|
||||
m.toolbar.Insert(fav_delete_button, 4)
|
||||
}
|
||||
|
||||
func (m *MainWindow) initializeTrayIcon() {
|
||||
fmt.Println("Initializing tray icon...")
|
||||
|
||||
icon_bytes, _ := base64.StdEncoding.DecodeString(common.Logo)
|
||||
icon_pixbuf := gdkpixbuf.NewLoader()
|
||||
icon_pixbuf.Write(icon_bytes)
|
||||
logo = icon_pixbuf.GetPixbuf()
|
||||
|
||||
m.tray_icon = gtk.NewStatusIconFromPixbuf(logo)
|
||||
m.tray_icon.SetName("URTrator")
|
||||
m.tray_icon.SetTitle("URTrator")
|
||||
m.tray_icon.SetTooltipText("URTrator is ready")
|
||||
|
||||
m.tray_menu = gtk.NewMenu()
|
||||
|
||||
// Open/Close URTrator menu item.
|
||||
open_close_item := gtk.NewMenuItemWithLabel("Show / Hide URTrator")
|
||||
open_close_item.Connect("activate", m.showHide)
|
||||
m.tray_menu.Append(open_close_item)
|
||||
|
||||
// Separator
|
||||
sep1 := gtk.NewSeparatorMenuItem()
|
||||
m.tray_menu.Append(sep1)
|
||||
|
||||
// Exit menu item.
|
||||
exit_item := gtk.NewMenuItemWithLabel("Exit")
|
||||
exit_item.Connect("activate", m.window.Destroy)
|
||||
m.tray_menu.Append(exit_item)
|
||||
|
||||
// Connect things.
|
||||
m.tray_icon.Connect("activate", m.showHide)
|
||||
m.tray_icon.Connect("popup-menu", m.showTrayMenu)
|
||||
m.tray_menu.ShowAll()
|
||||
}
|
||||
|
||||
func (m *MainWindow) launchGame() error {
|
||||
fmt.Println("Launching Urban Terror...")
|
||||
|
||||
@@ -800,6 +851,22 @@ func (m *MainWindow) loadProfiles() {
|
||||
fmt.Println("Added " + strconv.Itoa(m.old_profiles_count) + " profiles")
|
||||
}
|
||||
|
||||
func (m *MainWindow) showHide() {
|
||||
// ToDo: set window position on restore. Window loosing it on
|
||||
// multimonitor configurations.
|
||||
if m.hidden {
|
||||
m.window.Show()
|
||||
m.hidden = false
|
||||
} else {
|
||||
m.window.Hide()
|
||||
m.hidden = true
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MainWindow) showTrayMenu(cbx *glib.CallbackContext) {
|
||||
m.tray_menu.Popup(nil, nil, gtk.StatusIconPositionMenu, m.tray_icon, uint(cbx.Args(0)), uint32(cbx.Args(1)))
|
||||
}
|
||||
|
||||
func (m *MainWindow) unlockInterface() {
|
||||
m.launch_button.SetSensitive(true)
|
||||
m.statusbar.Push(m.statusbar_context_id, "URTrator is ready.")
|
||||
|
@@ -62,6 +62,15 @@ func (o *OptionsDialog) closeOptionsDialogWithDiscard() {
|
||||
func (o *OptionsDialog) closeOptionsDialogWithSaving() {
|
||||
fmt.Println("Saving changes to options...")
|
||||
|
||||
o.saveGeneral()
|
||||
|
||||
mbox_string := "Some options require application restart to be applied."
|
||||
m := gtk.NewMessageDialog(o.window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, mbox_string)
|
||||
m.Response(func() {
|
||||
m.Destroy()
|
||||
})
|
||||
m.Run()
|
||||
|
||||
ctx.Eventer.LaunchEvent("loadProfiles")
|
||||
|
||||
o.window.Destroy()
|
||||
@@ -106,6 +115,15 @@ func (o *OptionsDialog) editProfile() {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *OptionsDialog) fill() {
|
||||
if ctx.Cfg.Cfg["/general/show_tray_icon"] == "1" {
|
||||
o.show_tray_icon.SetActive(true)
|
||||
}
|
||||
if ctx.Cfg.Cfg["/general/urtrator_autoupdate"] == "1" {
|
||||
o.autoupdate.SetActive(true)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *OptionsDialog) initializeGeneralTab() {
|
||||
general_vbox := gtk.NewVBox(false, 0)
|
||||
|
||||
@@ -214,6 +232,22 @@ func (o *OptionsDialog) loadProfiles() {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *OptionsDialog) saveGeneral() {
|
||||
if o.show_tray_icon.GetActive() {
|
||||
ctx.Cfg.Cfg["/general/show_tray_icon"] = "1"
|
||||
} else {
|
||||
ctx.Cfg.Cfg["/general/show_tray_icon"] = "0"
|
||||
}
|
||||
|
||||
if o.autoupdate.GetActive() {
|
||||
ctx.Cfg.Cfg["/general/urtrator_autoupdate"] = "1"
|
||||
} else {
|
||||
ctx.Cfg.Cfg["/general/urtrator_autoupdate"] = "0"
|
||||
}
|
||||
|
||||
fmt.Println(ctx.Cfg.Cfg)
|
||||
}
|
||||
|
||||
func (o *OptionsDialog) ShowOptionsDialog() {
|
||||
o.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
o.window.SetTitle("URTrator - Options")
|
||||
@@ -226,6 +260,7 @@ func (o *OptionsDialog) ShowOptionsDialog() {
|
||||
o.vbox = gtk.NewVBox(false, 0)
|
||||
|
||||
o.initializeTabs()
|
||||
o.fill()
|
||||
|
||||
o.window.Add(o.vbox)
|
||||
o.window.ShowAll()
|
||||
|
Reference in New Issue
Block a user