From 2b3c9ef9eaeb08d487ae26e3709a74d7d0f4fd18 Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Sat, 10 Nov 2018 20:58:15 +0500 Subject: [PATCH] gofmt. --- clipboardwatcher/clipboardwatcher_object.go | 152 +++--- colorizer/colorizer_object.go | 102 ++-- colorizer/exported.go | 4 +- configuration/config_object.go | 110 ++-- configuration/exported.go | 4 +- context/exported.go | 4 +- database/migrations.go | 131 +++-- datamodels/configuration.go | 4 +- datamodels/database.go | 2 +- datamodels/profile.go | 24 +- datamodels/server.go | 64 +-- eventer/eventer_object.go | 80 +-- eventer/exported.go | 4 +- ioq3dataparser/exported.go | 50 +- launcher/exported.go | 4 +- timer/timer.go | 162 +++--- timer/timertask.go | 34 +- translator/translator.go | 156 +++--- translator/translator_unix.go | 100 ++-- translator/translator_windows.go | 22 +- ui/gtk2/mainwindow_helpers.go | 60 +-- ui/qt5/exported.go | 12 +- ui/qt5/mainwindow.go | 159 +++--- ui/qt5/mainwindow_init.go | 548 ++++++++++---------- ui/qt5/mainwindow_init_menu_mac.go | 84 +-- 25 files changed, 1054 insertions(+), 1022 deletions(-) diff --git a/clipboardwatcher/clipboardwatcher_object.go b/clipboardwatcher/clipboardwatcher_object.go index 6439c8d..b0df6c6 100644 --- a/clipboardwatcher/clipboardwatcher_object.go +++ b/clipboardwatcher/clipboardwatcher_object.go @@ -10,105 +10,105 @@ package clipboardwatcher import ( - // stdlib - "errors" - "fmt" - "strings" + // stdlib + "errors" + "fmt" + "strings" - // other - "github.com/mattn/go-gtk/gdk" - "github.com/mattn/go-gtk/gtk" + // other + "github.com/mattn/go-gtk/gdk" + "github.com/mattn/go-gtk/gtk" ) type ClipboardWatcher struct { - // Clipboard. - clipboard *gtk.Clipboard - // PRIMARY clipboard. - prim_clipboard *gtk.Clipboard + // Clipboard. + clipboard *gtk.Clipboard + // PRIMARY clipboard. + prim_clipboard *gtk.Clipboard - // Flags. - // We have just copy connect string to clipboard. - // Used to ignore clipboard data in check*Input() - just_set bool + // Flags. + // We have just copy connect string to clipboard. + // Used to ignore clipboard data in check*Input() + just_set bool } func (cw *ClipboardWatcher) checkInput() { - if !cw.just_set { - text := cw.clipboard.WaitForText() - cw.parseData(text) - } else { - cw.just_set = false - } + if !cw.just_set { + text := cw.clipboard.WaitForText() + cw.parseData(text) + } else { + cw.just_set = false + } } func (cw *ClipboardWatcher) checkPrimaryInput() { - if !cw.just_set { - text := cw.prim_clipboard.WaitForText() - cw.parseData(text) - } else { - cw.just_set = false - } + if !cw.just_set { + text := cw.prim_clipboard.WaitForText() + cw.parseData(text) + } else { + cw.just_set = false + } } func (cw *ClipboardWatcher) CopyServerData(server_address string) error { - server, ok := Cache.Servers[server_address] - if !ok { - // ToDo: show message box? - return errors.New("Server wasn't selected") - } + server, ok := Cache.Servers[server_address] + if !ok { + // ToDo: show message box? + return errors.New("Server wasn't selected") + } - // Composing connection string. - var connect_string string = "" - connect_string += "/connect " + server.Server.Ip + ":" + server.Server.Port - if len(server.Server.Password) >= 1 { - connect_string += ";password " + server.Server.Password - } - fmt.Println("Connect string: ", connect_string) - cw.just_set = true - cw.clipboard.SetText(connect_string) + // Composing connection string. + var connect_string string = "" + connect_string += "/connect " + server.Server.Ip + ":" + server.Server.Port + if len(server.Server.Password) >= 1 { + connect_string += ";password " + server.Server.Password + } + fmt.Println("Connect string: ", connect_string) + cw.just_set = true + cw.clipboard.SetText(connect_string) - return nil + return nil } func (cw *ClipboardWatcher) Initialize() { - fmt.Println("Initializing clipboard watcher...") + fmt.Println("Initializing clipboard watcher...") - cw.just_set = false + cw.just_set = false - cw.clipboard = gtk.NewClipboardGetForDisplay(gdk.DisplayGetDefault(), gdk.SELECTION_CLIPBOARD) - cw.clipboard.Connect("owner-change", cw.checkInput) + cw.clipboard = gtk.NewClipboardGetForDisplay(gdk.DisplayGetDefault(), gdk.SELECTION_CLIPBOARD) + cw.clipboard.Connect("owner-change", cw.checkInput) - cw.prim_clipboard = gtk.NewClipboardGetForDisplay(gdk.DisplayGetDefault(), gdk.SELECTION_PRIMARY) - cw.prim_clipboard.Connect("owner-change", cw.checkPrimaryInput) + cw.prim_clipboard = gtk.NewClipboardGetForDisplay(gdk.DisplayGetDefault(), gdk.SELECTION_PRIMARY) + cw.prim_clipboard.Connect("owner-change", cw.checkPrimaryInput) } func (cw *ClipboardWatcher) parseData(data string) { - // We should check only first string. - data = strings.Split(data, "\n")[0] - // Checking if we have connection string here. - if strings.Contains(data, "ct ") { - fmt.Println("Connection string detected!") - var server string = "" - var password string = "" - conn_string := strings.Split(data, ";") - if len(conn_string) > 0 { - srv_string := strings.Split(data, ";")[0] - srv_splitted := strings.Split(srv_string, "ct ") - if len(srv_splitted) > 1 { - server_raw := strings.Split(srv_splitted[1], " ")[0] - // Get rid of spaces. - server = strings.TrimSpace(server_raw) - } - } - if len(conn_string) > 1 && strings.Contains(data, "password") { - pw_string := strings.Split(data, ";")[1] - pw_splitted := strings.Split(pw_string, "password ") - if len(pw_splitted) > 1 { - password_raw := strings.Split(pw_splitted[1], " ")[0] - // Get rid of spaces. - password = strings.TrimSpace(password_raw) - } - } - Eventer.LaunchEvent("setQuickConnectDetails", map[string]string{"server": server, "password": password}) - } + // We should check only first string. + data = strings.Split(data, "\n")[0] + // Checking if we have connection string here. + if strings.Contains(data, "ct ") { + fmt.Println("Connection string detected!") + var server string = "" + var password string = "" + conn_string := strings.Split(data, ";") + if len(conn_string) > 0 { + srv_string := strings.Split(data, ";")[0] + srv_splitted := strings.Split(srv_string, "ct ") + if len(srv_splitted) > 1 { + server_raw := strings.Split(srv_splitted[1], " ")[0] + // Get rid of spaces. + server = strings.TrimSpace(server_raw) + } + } + if len(conn_string) > 1 && strings.Contains(data, "password") { + pw_string := strings.Split(data, ";")[1] + pw_splitted := strings.Split(pw_string, "password ") + if len(pw_splitted) > 1 { + password_raw := strings.Split(pw_splitted[1], " ")[0] + // Get rid of spaces. + password = strings.TrimSpace(password_raw) + } + } + Eventer.LaunchEvent("setQuickConnectDetails", map[string]string{"server": server, "password": password}) + } } diff --git a/colorizer/colorizer_object.go b/colorizer/colorizer_object.go index 4223dcc..e0a1eaa 100644 --- a/colorizer/colorizer_object.go +++ b/colorizer/colorizer_object.go @@ -10,76 +10,76 @@ package colorizer import ( - // stdlib - "fmt" - "html" - "strings" + // stdlib + "fmt" + "html" + "strings" ) type Colorizer struct { - // RAW colors to Pango relation. - colors map[string]string + // RAW colors to Pango relation. + colors map[string]string } func (c *Colorizer) ClearFromMarkup(data string) string { - var result string = "" + var result string = "" - data = html.EscapeString(data) + data = html.EscapeString(data) - data_splitted := strings.Split(data, ">") + data_splitted := strings.Split(data, ">") - if len(data_splitted) > 1 { - for item := range data_splitted { - if len(data_splitted[item]) > 0 { - result += strings.Split(data_splitted[item], "<")[0] - } - } - } else { - result = data_splitted[0] - } + if len(data_splitted) > 1 { + for item := range data_splitted { + if len(data_splitted[item]) > 0 { + result += strings.Split(data_splitted[item], "<")[0] + } + } + } else { + result = data_splitted[0] + } - return result + return result } func (c *Colorizer) Fix(data string) string { - var result string = "" + var result string = "" - data = html.EscapeString(data) + 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 { - colorcode_raw := string([]rune(data_splitted[item])[0]) - colorcode, ok := c.colors[colorcode_raw] - if !ok { - colorcode = "#000000" - } - result += "" + string([]rune(data_splitted[item])[1:]) + "" - } else { - result += data_splitted[item] - } - } - } else { - result = data_splitted[0] - } - return "" + result + "" + data_splitted := strings.Split(data, "^") + if len(data_splitted) > 1 { + for item := range data_splitted { + if len(data_splitted[item]) > 0 { + colorcode_raw := string([]rune(data_splitted[item])[0]) + colorcode, ok := c.colors[colorcode_raw] + if !ok { + colorcode = "#000000" + } + result += "" + string([]rune(data_splitted[item])[1:]) + "" + } else { + result += data_splitted[item] + } + } + } else { + result = data_splitted[0] + } + return "" + result + "" } func (c *Colorizer) Initialize() { - fmt.Println("Initializing colorizer...") - c.initializeStorages() + fmt.Println("Initializing colorizer...") + c.initializeStorages() } func (c *Colorizer) initializeStorages() { - c.colors = map[string]string{ - "1": "#cc0000", - "2": "#00cc00", - "3": "#eeee00", - "4": "#1c86ee", - "5": "#00eeee", - "6": "#ee00ee", - "7": "#000000", - "8": "#000000", - } + c.colors = map[string]string{ + "1": "#cc0000", + "2": "#00cc00", + "3": "#eeee00", + "4": "#1c86ee", + "5": "#00eeee", + "6": "#ee00ee", + "7": "#000000", + "8": "#000000", + } } diff --git a/colorizer/exported.go b/colorizer/exported.go index 3b0404c..a39947d 100644 --- a/colorizer/exported.go +++ b/colorizer/exported.go @@ -10,6 +10,6 @@ package colorizer func New() *Colorizer { - c := Colorizer {} - return &c + c := Colorizer{} + return &c } diff --git a/configuration/config_object.go b/configuration/config_object.go index 22afdcc..5dbc216 100644 --- a/configuration/config_object.go +++ b/configuration/config_object.go @@ -10,85 +10,85 @@ package configuration import ( - // stdlib - "fmt" - "os" - "path" - "runtime" + // stdlib + "fmt" + "os" + "path" + "runtime" ) type Config struct { - // Configuration from database. - Cfg map[string]string - // Temporary (or runtime) configuration things. - TEMP map[string]string + // Configuration from database. + Cfg map[string]string + // Temporary (or runtime) configuration things. + TEMP map[string]string } func (c *Config) initializePathsMac() { - fmt.Println("Initializing configuration paths...") - home_path := os.Getenv("HOME") - data_path := path.Join(home_path, "Library", "Application Support", "URTrator") - fmt.Println("Will use data path: " + data_path) - c.TEMP["DATA"] = data_path + fmt.Println("Initializing configuration paths...") + home_path := os.Getenv("HOME") + data_path := path.Join(home_path, "Library", "Application Support", "URTrator") + fmt.Println("Will use data path: " + data_path) + c.TEMP["DATA"] = data_path - profile_path := path.Join(home_path, "Library", "Application Support", "Quake3", "q3ut4") - c.TEMP["DEFAULT_PROFILE_PATH"] = profile_path + profile_path := path.Join(home_path, "Library", "Application Support", "Quake3", "q3ut4") + c.TEMP["DEFAULT_PROFILE_PATH"] = profile_path - if _, err := os.Stat(data_path); os.IsNotExist(err) { - os.MkdirAll(data_path, 0755) - } + if _, err := os.Stat(data_path); os.IsNotExist(err) { + os.MkdirAll(data_path, 0755) + } } func (c *Config) initializePathsNix() { - fmt.Println("Initializing configuration paths...") + fmt.Println("Initializing configuration paths...") - // Get storage path. By default we will use ~/.config/urtrator - // directory. - home_path := os.Getenv("HOME") - data_path := path.Join(home_path, ".config", "urtrator") - fmt.Println("Will use data path: " + data_path) - c.TEMP["DATA"] = data_path + // Get storage path. By default we will use ~/.config/urtrator + // directory. + home_path := os.Getenv("HOME") + data_path := path.Join(home_path, ".config", "urtrator") + fmt.Println("Will use data path: " + data_path) + c.TEMP["DATA"] = data_path - profile_path := path.Join(home_path, ".q3a", "q3ut4") - c.TEMP["DEFAULT_PROFILE_PATH"] = profile_path + profile_path := path.Join(home_path, ".q3a", "q3ut4") + c.TEMP["DEFAULT_PROFILE_PATH"] = profile_path - if _, err := os.Stat(data_path); os.IsNotExist(err) { - os.MkdirAll(data_path, 0755) - } + if _, err := os.Stat(data_path); os.IsNotExist(err) { + os.MkdirAll(data_path, 0755) + } } func (c *Config) initializePathsWin() { - fmt.Println("Initializing configuration paths...") - homepath_without_drive := os.Getenv("HOMEPATH") - homedrive := os.Getenv("HOMEDRIVE") - data_path := path.Join(homedrive, homepath_without_drive, "AppData", "Roaming", "URTrator") - c.TEMP["DATA"] = data_path + fmt.Println("Initializing configuration paths...") + homepath_without_drive := os.Getenv("HOMEPATH") + homedrive := os.Getenv("HOMEDRIVE") + data_path := path.Join(homedrive, homepath_without_drive, "AppData", "Roaming", "URTrator") + c.TEMP["DATA"] = data_path - // Verify it! - profile_path := path.Join(homedrive, homepath_without_drive, "AppData", "UrbanTerror43", "q3ut4") - c.TEMP["DEFAULT_PROFILE_PATH"] = profile_path + // Verify it! + profile_path := path.Join(homedrive, homepath_without_drive, "AppData", "UrbanTerror43", "q3ut4") + c.TEMP["DEFAULT_PROFILE_PATH"] = profile_path - if _, err := os.Stat(data_path); os.IsNotExist(err) { - os.MkdirAll(data_path, 0755) - } + if _, err := os.Stat(data_path); os.IsNotExist(err) { + os.MkdirAll(data_path, 0755) + } } func (c *Config) initializeStorages() { - c.TEMP = make(map[string]string) - c.Cfg = make(map[string]string) + c.TEMP = make(map[string]string) + c.Cfg = make(map[string]string) } func (c *Config) Initialize() { - fmt.Println("Initializing configuration storage...") - c.initializeStorages() + fmt.Println("Initializing configuration storage...") + c.initializeStorages() - if runtime.GOOS == "linux" { - c.initializePathsNix() - } else if runtime.GOOS == "darwin" { - c.initializePathsMac() - } else if runtime.GOOS == "windows" { - c.initializePathsWin() - } else { - panic("We're not ready for other OSes yet!") - } + if runtime.GOOS == "linux" { + c.initializePathsNix() + } else if runtime.GOOS == "darwin" { + c.initializePathsMac() + } else if runtime.GOOS == "windows" { + c.initializePathsWin() + } else { + panic("We're not ready for other OSes yet!") + } } diff --git a/configuration/exported.go b/configuration/exported.go index cf94706..5c781ef 100644 --- a/configuration/exported.go +++ b/configuration/exported.go @@ -10,6 +10,6 @@ package configuration func New() *Config { - c := Config{} - return &c + c := Config{} + return &c } diff --git a/context/exported.go b/context/exported.go index 692f7e2..56cfe73 100644 --- a/context/exported.go +++ b/context/exported.go @@ -10,6 +10,6 @@ package context func New() *Context { - c := Context{} - return &c + c := Context{} + return &c } diff --git a/database/migrations.go b/database/migrations.go index 19c2646..3cba768 100644 --- a/database/migrations.go +++ b/database/migrations.go @@ -10,8 +10,8 @@ package database import ( - // stdlib - "fmt" + // stdlib + "fmt" ) var start_schema = ` @@ -39,95 +39,128 @@ INSERT INTO database (version) VALUES (1); // Migrate database to latest version. // ToDo: make it more good :). func migrate_full(db *Database, version int) { - if version < 1 {start_to_one(db); version = 1} - if version == 1 {one_to_two(db); version = 2} - if version == 2 {two_to_three(db); version = 3} - if version == 3 {three_to_four(db); version = 4} - if version == 4 {four_to_five(db); version = 5} - if version == 5 {five_to_six(db); version = 6 } - if version == 6 {six_to_seven(db); version = 7} - if version == 7 {seven_to_eight(db); version = 8} - if version == 8 {eight_to_nine(db); version = 9} - if version == 9 {nine_to_ten(db); version = 10} - if version == 10 {ten_to_eleven(db); version = 11} + if version < 1 { + start_to_one(db) + version = 1 + } + if version == 1 { + one_to_two(db) + version = 2 + } + if version == 2 { + two_to_three(db) + version = 3 + } + if version == 3 { + three_to_four(db) + version = 4 + } + if version == 4 { + four_to_five(db) + version = 5 + } + if version == 5 { + five_to_six(db) + version = 6 + } + if version == 6 { + six_to_seven(db) + version = 7 + } + if version == 7 { + seven_to_eight(db) + version = 8 + } + if version == 8 { + eight_to_nine(db) + version = 9 + } + if version == 9 { + nine_to_ten(db) + version = 10 + } + if version == 10 { + ten_to_eleven(db) + version = 11 + } } // Initial database structure. func start_to_one(db *Database) { - fmt.Println("Upgrading database from 0 to 1...") - db.Db.MustExec(start_schema) + fmt.Println("Upgrading database from 0 to 1...") + db.Db.MustExec(start_schema) } // Favorite server mark. func one_to_two(db *Database) { - fmt.Println("Upgrading database from 1 to 2...") - db.Db.MustExec("ALTER TABLE servers ADD favorite VARCHAR(1) DEFAULT '0'") - db.Db.MustExec("UPDATE database SET version=2") + fmt.Println("Upgrading database from 1 to 2...") + db.Db.MustExec("ALTER TABLE servers ADD favorite VARCHAR(1) DEFAULT '0'") + db.Db.MustExec("UPDATE database SET version=2") } // URTRator settings and Urban Terror profiles. func two_to_three(db *Database) { - fmt.Println("Upgrading database from 2 to 3...") - db.Db.MustExec("DROP TABLE IF EXISTS settings") - db.Db.MustExec("CREATE TABLE settings (show_tray_icon VARCHAR(1) NOT NULL DEFAULT '0', enable_autoupdate VARCHAR(1) NOT NULL DEFAULT '0')") - db.Db.MustExec("DROP TABLE IF EXISTS urt_profiles") - db.Db.MustExec("CREATE TABLE urt_profiles (name VARCHAR(128) NOT NULL, version VARCHAR(5) NOT NULL DEFAULT '4.3', binary VARCHAR(1024) NOT NULL, second_x_session VARCHAR(1) NOT NULL DEFAULT '0', additional_parameters VARCHAR(1024) NOT NULL DEFAULT '')") - db.Db.MustExec("UPDATE database SET version=3") + fmt.Println("Upgrading database from 2 to 3...") + db.Db.MustExec("DROP TABLE IF EXISTS settings") + db.Db.MustExec("CREATE TABLE settings (show_tray_icon VARCHAR(1) NOT NULL DEFAULT '0', enable_autoupdate VARCHAR(1) NOT NULL DEFAULT '0')") + db.Db.MustExec("DROP TABLE IF EXISTS urt_profiles") + db.Db.MustExec("CREATE TABLE urt_profiles (name VARCHAR(128) NOT NULL, version VARCHAR(5) NOT NULL DEFAULT '4.3', binary VARCHAR(1024) NOT NULL, second_x_session VARCHAR(1) NOT NULL DEFAULT '0', additional_parameters VARCHAR(1024) NOT NULL DEFAULT '')") + db.Db.MustExec("UPDATE database SET version=3") } // UrT version inconsistency. func three_to_four(db *Database) { - fmt.Println("Upgrading database from 3 to 4...") - db.Db.MustExec("UPDATE urt_profiles SET version='4.3.0' WHERE version='4.3.000'") - db.Db.MustExec("UPDATE database SET version=4") + fmt.Println("Upgrading database from 3 to 4...") + db.Db.MustExec("UPDATE urt_profiles SET version='4.3.0' WHERE version='4.3.000'") + db.Db.MustExec("UPDATE database SET version=4") } // Server's passwords. func four_to_five(db *Database) { - fmt.Println("Upgrading database from 4 to 5...") - db.Db.MustExec("ALTER TABLE servers ADD password VARCHAR(64) DEFAULT ''") - db.Db.MustExec("UPDATE database SET version=5") + fmt.Println("Upgrading database from 4 to 5...") + db.Db.MustExec("ALTER TABLE servers ADD password VARCHAR(64) DEFAULT ''") + db.Db.MustExec("UPDATE database SET version=5") } // Profile for server. func five_to_six(db *Database) { - fmt.Println("Upgrading database from 5 to 6...") - db.Db.MustExec("ALTER TABLE servers ADD profile_to_use VARCHAR(128) DEFAULT ''") - db.Db.MustExec("UPDATE database SET version=6") + fmt.Println("Upgrading database from 5 to 6...") + db.Db.MustExec("ALTER TABLE servers ADD profile_to_use VARCHAR(128) DEFAULT ''") + db.Db.MustExec("UPDATE database SET version=6") } // Configuration storage. func six_to_seven(db *Database) { - fmt.Println("Upgrading database from 6 to 7...") - db.Db.MustExec("CREATE TABLE configuration (key VARCHAR(128) NOT NULL, value VARCHAR(1024) NOT NULL)") - db.Db.MustExec("UPDATE database SET version=7") + fmt.Println("Upgrading database from 6 to 7...") + db.Db.MustExec("CREATE TABLE configuration (key VARCHAR(128) NOT NULL, value VARCHAR(1024) NOT NULL)") + db.Db.MustExec("UPDATE database SET version=7") } // Server's extended information. func seven_to_eight(db *Database) { - fmt.Println("Upgrading database from 7 to 8...") - db.Db.MustExec("ALTER TABLE servers ADD extended_config VARCHAR(4096) NOT NULL DEFAULT ''") - db.Db.MustExec("ALTER TABLE servers ADD players_info VARCHAR(8192) NOT NULL DEFAULT ''") - db.Db.MustExec("UPDATE database SET version=8") + fmt.Println("Upgrading database from 7 to 8...") + db.Db.MustExec("ALTER TABLE servers ADD extended_config VARCHAR(4096) NOT NULL DEFAULT ''") + db.Db.MustExec("ALTER TABLE servers ADD players_info VARCHAR(8192) NOT NULL DEFAULT ''") + db.Db.MustExec("UPDATE database SET version=8") } // Is server private flag. func eight_to_nine(db *Database) { - fmt.Println("Upgrading database from 8 to 9...") - db.Db.MustExec("ALTER TABLE servers ADD is_private VARCHAR(1) NOT NULL DEFAULT '0'") - db.Db.MustExec("UPDATE database SET version=9") + fmt.Println("Upgrading database from 8 to 9...") + db.Db.MustExec("ALTER TABLE servers ADD is_private VARCHAR(1) NOT NULL DEFAULT '0'") + db.Db.MustExec("UPDATE database SET version=9") } // Bots count. func nine_to_ten(db *Database) { - fmt.Println("Upgrading database from 9 to 10...") - db.Db.MustExec("ALTER TABLE servers ADD bots VARCHAR(2) NOT NULL DEFAULT '0'") - db.Db.MustExec("UPDATE database SET version=10") + fmt.Println("Upgrading database from 9 to 10...") + db.Db.MustExec("ALTER TABLE servers ADD bots VARCHAR(2) NOT NULL DEFAULT '0'") + db.Db.MustExec("UPDATE database SET version=10") } // Urban terror's profile path. func ten_to_eleven(db *Database) { - fmt.Println("Upgrading database from 10 to 11...") - db.Db.MustExec("ALTER TABLE urt_profiles ADD profile_path VARCHAR(4096) NOT NULL DEFAULT '~/.q3ut4'") - db.Db.MustExec("UPDATE database SET version=11") + fmt.Println("Upgrading database from 10 to 11...") + db.Db.MustExec("ALTER TABLE urt_profiles ADD profile_path VARCHAR(4096) NOT NULL DEFAULT '~/.q3ut4'") + db.Db.MustExec("UPDATE database SET version=11") } diff --git a/datamodels/configuration.go b/datamodels/configuration.go index a33f447..9c56294 100644 --- a/datamodels/configuration.go +++ b/datamodels/configuration.go @@ -10,6 +10,6 @@ package datamodels type Configuration struct { - Key string `db:"key"` - Value string `db:"value"` + Key string `db:"key"` + Value string `db:"value"` } diff --git a/datamodels/database.go b/datamodels/database.go index f8ee1a2..1d9dc43 100644 --- a/datamodels/database.go +++ b/datamodels/database.go @@ -10,5 +10,5 @@ package datamodels type Database struct { - Version string `db:"version"` + Version string `db:"version"` } diff --git a/datamodels/profile.go b/datamodels/profile.go index a8eb9ee..0120c82 100644 --- a/datamodels/profile.go +++ b/datamodels/profile.go @@ -10,16 +10,16 @@ package datamodels type Profile struct { - // Profile name. - Name string `db:"name"` - // Game version. - Version string `db:"version"` - // Binary path. - Binary string `db:"binary"` - // Will we use second X session? - Second_x_session string `db:"second_x_session"` - // Additional game parameters we will pass. - Additional_params string `db:"additional_parameters"` - // Profile path. - Profile_path string `db:"profile_path"` + // Profile name. + Name string `db:"name"` + // Game version. + Version string `db:"version"` + // Binary path. + Binary string `db:"binary"` + // Will we use second X session? + Second_x_session string `db:"second_x_session"` + // Additional game parameters we will pass. + Additional_params string `db:"additional_parameters"` + // Profile path. + Profile_path string `db:"profile_path"` } diff --git a/datamodels/server.go b/datamodels/server.go index 32e22d3..15bbc17 100644 --- a/datamodels/server.go +++ b/datamodels/server.go @@ -10,36 +10,36 @@ package datamodels type Server struct { - // Server's address - Ip string `db:"ip"` - // Server's port - Port string `db:"port"` - // Server's name - Name string `db:"name"` - // Current players count - Players string `db:"players"` - // Bots count - Bots string `db:"bots"` - // Maximum players - Maxplayers string `db:"maxplayers"` - // Ping - Ping string `db:"ping"` - // Gametype. See Urban Terror documentation on relationship. - Gamemode string `db:"gamemode"` - // Current map - Map string `db:"map"` - // Server's software version - Version string `db:"version"` - // Is server was favorited? - Favorite string `db:"favorite"` - // Server's password. - Password string `db:"password"` - // Profile to use with server. - ProfileToUse string `db:"profile_to_use"` - // Extended server's configuration. - ExtendedConfig string `db:"extended_config"` - // Players information. - PlayersInfo string `db:"players_info"` - // Is server private? - IsPrivate string `db:"is_private"` + // Server's address + Ip string `db:"ip"` + // Server's port + Port string `db:"port"` + // Server's name + Name string `db:"name"` + // Current players count + Players string `db:"players"` + // Bots count + Bots string `db:"bots"` + // Maximum players + Maxplayers string `db:"maxplayers"` + // Ping + Ping string `db:"ping"` + // Gametype. See Urban Terror documentation on relationship. + Gamemode string `db:"gamemode"` + // Current map + Map string `db:"map"` + // Server's software version + Version string `db:"version"` + // Is server was favorited? + Favorite string `db:"favorite"` + // Server's password. + Password string `db:"password"` + // Profile to use with server. + ProfileToUse string `db:"profile_to_use"` + // Extended server's configuration. + ExtendedConfig string `db:"extended_config"` + // Players information. + PlayersInfo string `db:"players_info"` + // Is server private? + IsPrivate string `db:"is_private"` } diff --git a/eventer/eventer_object.go b/eventer/eventer_object.go index 684a53f..6677c2b 100644 --- a/eventer/eventer_object.go +++ b/eventer/eventer_object.go @@ -10,66 +10,66 @@ package eventer import ( - crand "crypto/rand" - "errors" - "fmt" - //"reflect" + crand "crypto/rand" + "errors" + "fmt" + //"reflect" - // github - "github.com/mattn/go-gtk/glib" - "github.com/mattn/go-gtk/gtk" + // github + "github.com/mattn/go-gtk/glib" + "github.com/mattn/go-gtk/gtk" ) type Eventer struct { - // Events - events map[string]map[string]func(data map[string]string) + // Events + events map[string]map[string]func(data map[string]string) } func (e *Eventer) AddEventHandler(event string, handler func(data map[string]string)) { - _, ok := e.events[event] - if !ok { - e.events[event] = make(map[string]func(data map[string]string)) - } - event_id_raw := make([]byte, 16) - crand.Read(event_id_raw) - event_id := fmt.Sprintf("%x", event_id_raw) - e.events[event][event_id] = handler + _, ok := e.events[event] + if !ok { + e.events[event] = make(map[string]func(data map[string]string)) + } + event_id_raw := make([]byte, 16) + crand.Read(event_id_raw) + event_id := fmt.Sprintf("%x", event_id_raw) + e.events[event][event_id] = handler } func (e *Eventer) Initialize() { - e.initializeStorage() + e.initializeStorage() } func (e *Eventer) initializeStorage() { - e.events = make(map[string]map[string]func(data map[string]string)) + e.events = make(map[string]map[string]func(data map[string]string)) } func (e *Eventer) LaunchEvent(event string, data map[string]string) error { - _, ok := e.events[event] - if !ok { - return errors.New("Event " + event + " not found!") - } + _, ok := e.events[event] + if !ok { + return errors.New("Event " + event + " not found!") + } - fmt.Println("Launching event " + event) - glib.IdleAdd(func() bool { - e.reallyLaunchEvent(event, data) - return false - }) + fmt.Println("Launching event " + event) + glib.IdleAdd(func() bool { + e.reallyLaunchEvent(event, data) + return false + }) - for { - if gtk.EventsPending() { - gtk.MainIteration() - } else { - break - } - } + for { + if gtk.EventsPending() { + gtk.MainIteration() + } else { + break + } + } - return nil + return nil } func (e *Eventer) reallyLaunchEvent(event string, data map[string]string) { - fmt.Println("Really launching event " + event + "...") - for _, val := range e.events[event] { - val(data) - } + fmt.Println("Really launching event " + event + "...") + for _, val := range e.events[event] { + val(data) + } } diff --git a/eventer/exported.go b/eventer/exported.go index 27cd73a..ee19547 100644 --- a/eventer/exported.go +++ b/eventer/exported.go @@ -10,6 +10,6 @@ package eventer func New() *Eventer { - e := Eventer{} - return &e + e := Eventer{} + return &e } diff --git a/ioq3dataparser/exported.go b/ioq3dataparser/exported.go index 913b340..6700168 100644 --- a/ioq3dataparser/exported.go +++ b/ioq3dataparser/exported.go @@ -10,39 +10,39 @@ package ioq3dataparser import ( - // stdlib - "strings" + // stdlib + "strings" ) func ParseInfoToMap(data string) map[string]string { - parsed_data := make(map[string]string) + parsed_data := make(map[string]string) - srv_config := strings.Split(data, "\\") - srv_config = srv_config[1:] - // Parse server configuration into passed server's datamodel. - for i := 0; i < len(srv_config[1:]); i = i + 2 { - parsed_data[srv_config[i]] = srv_config[i + 1] - } + srv_config := strings.Split(data, "\\") + srv_config = srv_config[1:] + // Parse server configuration into passed server's datamodel. + for i := 0; i < len(srv_config[1:]); i = i + 2 { + parsed_data[srv_config[i]] = srv_config[i+1] + } - return parsed_data + return parsed_data } func ParsePlayersInfoToMap(data string) map[string]map[string]string { - parsed_data := make(map[string]map[string]string) + parsed_data := make(map[string]map[string]string) - // Structure: frags|ping|nick - raw_data := strings.Split(data, "\\") - for i := range raw_data { - raw_player_data := strings.Split(raw_data[i], " ") - player_data := make(map[string]string) - if len(raw_player_data) > 1 { - nickname := strings.Join(raw_player_data[2:], " ") - player_data["nick"] = string([]byte(nickname)[1:len(nickname)-1]) - player_data["ping"] = raw_player_data[1] - player_data["frags"] = raw_player_data[0] - parsed_data[player_data["nick"]] = player_data - } - } + // Structure: frags|ping|nick + raw_data := strings.Split(data, "\\") + for i := range raw_data { + raw_player_data := strings.Split(raw_data[i], " ") + player_data := make(map[string]string) + if len(raw_player_data) > 1 { + nickname := strings.Join(raw_player_data[2:], " ") + player_data["nick"] = string([]byte(nickname)[1 : len(nickname)-1]) + player_data["ping"] = raw_player_data[1] + player_data["frags"] = raw_player_data[0] + parsed_data[player_data["nick"]] = player_data + } + } - return parsed_data + return parsed_data } diff --git a/launcher/exported.go b/launcher/exported.go index 50dd26a..7303cfd 100644 --- a/launcher/exported.go +++ b/launcher/exported.go @@ -10,6 +10,6 @@ package launcher func New() *Launcher { - l := Launcher{} - return &l + l := Launcher{} + return &l } diff --git a/timer/timer.go b/timer/timer.go index ca3b6a7..403ea69 100644 --- a/timer/timer.go +++ b/timer/timer.go @@ -10,121 +10,121 @@ package timer import ( - // stdlib - "errors" - "fmt" - "strconv" - "sync" - "time" + // stdlib + "errors" + "fmt" + "strconv" + "sync" + "time" ) type Timer struct { - // Tasks. - tasks map[string]*TimerTask - // Tasks map mutex. - tasksMutex sync.Mutex + // Tasks. + tasks map[string]*TimerTask + // Tasks map mutex. + tasksMutex sync.Mutex } func (t *Timer) AddTask(task *TimerTask) error { - fmt.Println("Adding task '" + task.Name + "'...") + fmt.Println("Adding task '" + task.Name + "'...") - _, ok := t.tasks[task.Name] - if ok { - error_text := "Task '" + task.Name + "' already exist! Ignoring..." - fmt.Println(error_text) - return errors.New(error_text) - } + _, ok := t.tasks[task.Name] + if ok { + error_text := "Task '" + task.Name + "' already exist! Ignoring..." + fmt.Println(error_text) + return errors.New(error_text) + } - task.InProgress = false + task.InProgress = false - curtime := time.Now() - nextlaunch := curtime.Add(time.Duration(task.Timeout) * time.Second) - task.NextLaunch = nextlaunch + curtime := time.Now() + nextlaunch := curtime.Add(time.Duration(task.Timeout) * time.Second) + task.NextLaunch = nextlaunch - t.tasksMutex.Lock() - t.tasks[task.Name] = task - t.tasksMutex.Unlock() + t.tasksMutex.Lock() + t.tasks[task.Name] = task + t.tasksMutex.Unlock() - fmt.Println("Added task '" + task.Name + "' with " + strconv.Itoa(task.Timeout) + " seconds timeout") - return nil + fmt.Println("Added task '" + task.Name + "' with " + strconv.Itoa(task.Timeout) + " seconds timeout") + return nil } func (t *Timer) executeTasks() { - t.tasksMutex.Lock() - for task_name, task := range t.tasks { - // Check if task should be run. - curtime := time.Now() - diff := curtime.Sub(task.NextLaunch) - //fmt.Println(diff) - if diff > 0 { - fmt.Println("Checking task '" + task_name + "'...") - // Check if task is already running. - if task.InProgress { - fmt.Println("Already executing, skipping...") - continue - } + t.tasksMutex.Lock() + for task_name, task := range t.tasks { + // Check if task should be run. + curtime := time.Now() + diff := curtime.Sub(task.NextLaunch) + //fmt.Println(diff) + if diff > 0 { + fmt.Println("Checking task '" + task_name + "'...") + // Check if task is already running. + if task.InProgress { + fmt.Println("Already executing, skipping...") + continue + } - fmt.Println("Launching task '" + task_name + "'...") - task.InProgress = true - Eventer.LaunchEvent(task.Callee, map[string]string{}) + fmt.Println("Launching task '" + task_name + "'...") + task.InProgress = true + Eventer.LaunchEvent(task.Callee, map[string]string{}) - curtime = time.Now() - nextlaunch := curtime.Add(time.Duration(task.Timeout) * time.Second) - task.NextLaunch = nextlaunch - } - } - t.tasksMutex.Unlock() + curtime = time.Now() + nextlaunch := curtime.Add(time.Duration(task.Timeout) * time.Second) + task.NextLaunch = nextlaunch + } + } + t.tasksMutex.Unlock() } func (t *Timer) GetTaskStatus(task_name string) bool { - t.tasksMutex.Lock() - task, ok := t.tasks[task_name] - t.tasksMutex.Unlock() - if !ok { - return false - } + t.tasksMutex.Lock() + task, ok := t.tasks[task_name] + t.tasksMutex.Unlock() + if !ok { + return false + } - return task.InProgress + return task.InProgress } func (t *Timer) Initialize() { - fmt.Println("Initializing timer...") + fmt.Println("Initializing timer...") - t.initializeStorage() - Eventer.AddEventHandler("taskDone", t.SetTaskNotInProgress) + t.initializeStorage() + Eventer.AddEventHandler("taskDone", t.SetTaskNotInProgress) - ticker := time.NewTicker(time.Second * 1) - go func() { - for _ = range ticker.C { - go t.executeTasks() - } - }() + ticker := time.NewTicker(time.Second * 1) + go func() { + for _ = range ticker.C { + go t.executeTasks() + } + }() } func (t *Timer) initializeStorage() { - t.tasks = make(map[string]*TimerTask) + t.tasks = make(map[string]*TimerTask) } func (t *Timer) RemoveTask(task_name string) { - t.tasksMutex.Lock() - _, ok := t.tasks[task_name] - t.tasksMutex.Unlock() - if !ok { - return - } + t.tasksMutex.Lock() + _, ok := t.tasks[task_name] + t.tasksMutex.Unlock() + if !ok { + return + } - t.tasksMutex.Lock() - delete(t.tasks, task_name) - t.tasksMutex.Unlock() + t.tasksMutex.Lock() + delete(t.tasks, task_name) + t.tasksMutex.Unlock() } func (t *Timer) SetTaskNotInProgress(data map[string]string) { - t.tasksMutex.Lock() - _, ok := t.tasks[data["task_name"]] - if !ok { - return - } + t.tasksMutex.Lock() + _, ok := t.tasks[data["task_name"]] + if !ok { + return + } - t.tasks[data["task_name"]].InProgress = false - t.tasksMutex.Unlock() + t.tasks[data["task_name"]].InProgress = false + t.tasksMutex.Unlock() } diff --git a/timer/timertask.go b/timer/timertask.go index f4a652f..feae986 100644 --- a/timer/timertask.go +++ b/timer/timertask.go @@ -10,25 +10,25 @@ package timer import ( - // stdlib - "time" + // stdlib + "time" ) type TimerTask struct { - // Task name. - Name string - // Task timeout, in seconds. - Timeout int - // What we should call? - // This should be an event name. - Callee string + // Task name. + Name string + // Task timeout, in seconds. + Timeout int + // What we should call? + // This should be an event name. + Callee string - // Internal variables, used by Timer. - // These variables can be defined, but they will be most likely - // overrided after first task launch. - // Next task launch time. - NextLaunch time.Time - // Is task currently executed? - // Kinda alternative to mutex. - InProgress bool + // Internal variables, used by Timer. + // These variables can be defined, but they will be most likely + // overrided after first task launch. + // Next task launch time. + NextLaunch time.Time + // Is task currently executed? + // Kinda alternative to mutex. + InProgress bool } diff --git a/translator/translator.go b/translator/translator.go index 36c279d..1786e12 100644 --- a/translator/translator.go +++ b/translator/translator.go @@ -14,23 +14,23 @@ package translator import ( - // stdlib - "encoding/json" - "fmt" - "io/ioutil" - "path/filepath" - "strings" + // stdlib + "encoding/json" + "fmt" + "io/ioutil" + "path/filepath" + "strings" ) type Translator struct { - // Accepted languages. - AcceptedLanguages map[string]string - // Currently active language. - Language string - // Translations. - translations map[string]map[string]string - // Path to translations files. - translationsPath string + // Accepted languages. + AcceptedLanguages map[string]string + // Currently active language. + Language string + // Translations. + translations map[string]map[string]string + // Path to translations files. + translationsPath string } // Formats string from passed map. @@ -50,73 +50,73 @@ type Translator struct { // Also note that we will replace ALL occurences of "{{ VAR }}" within string! // All untranslated variables will not be touched at all. func (t *Translator) formatFromMap(data string, params map[string]string) string { - new_data := data - for k, v := range params { - new_data = strings.Replace(new_data, "{{ " + k + " }}", v, -1) - } - return new_data + new_data := data + for k, v := range params { + new_data = strings.Replace(new_data, "{{ "+k+" }}", v, -1) + } + return new_data } // Translator initialization. func (t *Translator) Initialize() { - fmt.Println("Initializing translations...") + fmt.Println("Initializing translations...") - t.AcceptedLanguages = map[string]string{ - "System's default language": "default", - "English": "en_US", - "French": "fr_FR", - "Russian": "ru_RU", - } + t.AcceptedLanguages = map[string]string{ + "System's default language": "default", + "English": "en_US", + "French": "fr_FR", + "Russian": "ru_RU", + } - // Initialize storages. - t.translations = make(map[string]map[string]string) - t.translationsPath = "" + // Initialize storages. + t.translations = make(map[string]map[string]string) + t.translationsPath = "" - // Getting locale name from environment. - // ToDo: Windows compatability. Possible reference: - // https://github.com/cloudfoundry-attic/jibber_jabber/blob/master/jibber_jabber_windows.go - t.detectLanguage() + // Getting locale name from environment. + // ToDo: Windows compatability. Possible reference: + // https://github.com/cloudfoundry-attic/jibber_jabber/blob/master/jibber_jabber_windows.go + t.detectLanguage() - fmt.Println("Using translations for '" + t.Language + "'") + fmt.Println("Using translations for '" + t.Language + "'") - err := t.detectTranslationsDirectory() - if err == nil { - t.loadTranslations() - } else { - fmt.Println("Skipping translations loading due to missing translations directory.") - } + err := t.detectTranslationsDirectory() + if err == nil { + t.loadTranslations() + } else { + fmt.Println("Skipping translations loading due to missing translations directory.") + } } // Load translations into memory. func (t *Translator) loadTranslations() { - fmt.Println("Loading translations for language " + t.Language) - fmt.Println("Translations directory: " + t.translationsPath) + fmt.Println("Loading translations for language " + t.Language) + fmt.Println("Translations directory: " + t.translationsPath) - t.translations[t.Language] = make(map[string]string) + t.translations[t.Language] = make(map[string]string) - if t.translationsPath != "" { - // Check if language was selected in options dialog. In that - // case it will overwrite autodetected language. - var translationsDir string = "" - if cfg.Cfg["/general/language"] != "" { - translationsDir = filepath.Join(t.translationsPath, cfg.Cfg["/general/language"]) - t.Language = cfg.Cfg["/general/language"] - } else { - translationsDir = filepath.Join(t.translationsPath, t.Language) - } - files_list, _ := ioutil.ReadDir(translationsDir) - if len(files_list) > 0 { - for i := range files_list { - // Read file. - file_path := filepath.Join(translationsDir, files_list[i].Name()) - file_data, _ := ioutil.ReadFile(file_path) - var trans map[string]string - json.Unmarshal(file_data, &trans) - // Assign parsed translations to language code. - t.translations[t.Language] = trans - } - } - } + if t.translationsPath != "" { + // Check if language was selected in options dialog. In that + // case it will overwrite autodetected language. + var translationsDir string = "" + if cfg.Cfg["/general/language"] != "" { + translationsDir = filepath.Join(t.translationsPath, cfg.Cfg["/general/language"]) + t.Language = cfg.Cfg["/general/language"] + } else { + translationsDir = filepath.Join(t.translationsPath, t.Language) + } + files_list, _ := ioutil.ReadDir(translationsDir) + if len(files_list) > 0 { + for i := range files_list { + // Read file. + file_path := filepath.Join(translationsDir, files_list[i].Name()) + file_data, _ := ioutil.ReadFile(file_path) + var trans map[string]string + json.Unmarshal(file_data, &trans) + // Assign parsed translations to language code. + t.translations[t.Language] = trans + } + } + } } // Actual translation function. @@ -129,18 +129,18 @@ func (t *Translator) loadTranslations() { // Translates passed data from loaded translations file. // Returns passed data without changes if translation wasn't found. func (t *Translator) Translate(data string, params map[string]string) string { - val, ok := t.translations[t.Language][data] - if !ok { - if params != nil && len(params) > 0 { - return t.formatFromMap(data, params) - } else { - return data - } - } + val, ok := t.translations[t.Language][data] + if !ok { + if params != nil && len(params) > 0 { + return t.formatFromMap(data, params) + } else { + return data + } + } - if params != nil && len(params) > 0 { - return t.formatFromMap(val, params) - } + if params != nil && len(params) > 0 { + return t.formatFromMap(val, params) + } - return val + return val } diff --git a/translator/translator_unix.go b/translator/translator_unix.go index 58b7317..294a445 100644 --- a/translator/translator_unix.go +++ b/translator/translator_unix.go @@ -22,64 +22,64 @@ package translator import ( - // stdlib - "errors" - "fmt" - "os" - "path/filepath" - "strings" + // stdlib + "errors" + "fmt" + "os" + "path/filepath" + "strings" ) // Detect language on Unices. func (t *Translator) detectLanguage() { - // Use LC_ALL first. - t.Language = os.Getenv("LC_ALL") - // If LC_ALL is empty - use LANG. - if t.Language == "" { - t.Language = os.Getenv("LANG") - } + // Use LC_ALL first. + t.Language = os.Getenv("LC_ALL") + // If LC_ALL is empty - use LANG. + if t.Language == "" { + t.Language = os.Getenv("LANG") + } - // If still nothing - force "en_US" as default locale. Otherwise - // split language string by "." and take first part. - // Note: en_US is a default thing, so you will not found anything - // in "translations" directory! - if t.Language == "" { - fmt.Println("No locale data for current user found, using default (en_US)...") - t.Language = "en_US" - } else { - t.Language = strings.Split(t.Language, ".")[0] - } + // If still nothing - force "en_US" as default locale. Otherwise + // split language string by "." and take first part. + // Note: en_US is a default thing, so you will not found anything + // in "translations" directory! + if t.Language == "" { + fmt.Println("No locale data for current user found, using default (en_US)...") + t.Language = "en_US" + } else { + t.Language = strings.Split(t.Language, ".")[0] + } } func (t *Translator) detectTranslationsDirectory() error { - // Try to use directory near binary. - dir, _ := filepath.Abs(filepath.Dir(os.Args[0])) - // ..which can be overriden by URTRATOR_BINDIR environment variable. - // Useful for developers. - envdir := os.Getenv("URTRATOR_BINDIR") - if envdir != "" { - dir = envdir - } + // Try to use directory near binary. + dir, _ := filepath.Abs(filepath.Dir(os.Args[0])) + // ..which can be overriden by URTRATOR_BINDIR environment variable. + // Useful for developers. + envdir := os.Getenv("URTRATOR_BINDIR") + if envdir != "" { + dir = envdir + } - translations_dir := filepath.Join(dir, "translations") - _, err := os.Stat(translations_dir) - if err != nil { - fmt.Println("Translations wasn't found near binary!") - // As we're using JSON translation storage, it should be - // put in /usr/share/urtrator/translations by package - // maintainers in distros. - fmt.Println("Trying /usr/share/urtrator/translations...") - _, err := os.Stat("/usr/share/urtrator/translations") - if err != nil { - t.Language = "en_US" - fmt.Println("Translations unavailable, forcing en_US language code") - return errors.New("No translations directory was detected!") - } else { - t.translationsPath = "/usr/share/urtrator/translations" - } - } else { - t.translationsPath = translations_dir - } + translations_dir := filepath.Join(dir, "translations") + _, err := os.Stat(translations_dir) + if err != nil { + fmt.Println("Translations wasn't found near binary!") + // As we're using JSON translation storage, it should be + // put in /usr/share/urtrator/translations by package + // maintainers in distros. + fmt.Println("Trying /usr/share/urtrator/translations...") + _, err := os.Stat("/usr/share/urtrator/translations") + if err != nil { + t.Language = "en_US" + fmt.Println("Translations unavailable, forcing en_US language code") + return errors.New("No translations directory was detected!") + } else { + t.translationsPath = "/usr/share/urtrator/translations" + } + } else { + t.translationsPath = translations_dir + } - return nil + return nil } diff --git a/translator/translator_windows.go b/translator/translator_windows.go index e390af2..ee1a2f7 100644 --- a/translator/translator_windows.go +++ b/translator/translator_windows.go @@ -22,23 +22,23 @@ package translator import ( - // stdlib - "fmt" - "path/filepath" - "os" + // stdlib + "fmt" + "os" + "path/filepath" ) // Detect language on Windows. func (t *Translator) detectLanguage() { - fmt.Println("ToDo! Forcing en_US for now!") - t.Language = "en_US" + fmt.Println("ToDo! Forcing en_US for now!") + t.Language = "en_US" } func (t *Translator) detectTranslationsDirectory() error { - // Translations MUST reside in directory neear binary! - // ToDo: more checks. - dir, _ := filepath.Abs(filepath.Dir(os.Args[0])) - t.translationsPath = filepath.Join(dir, "translations") + // Translations MUST reside in directory neear binary! + // ToDo: more checks. + dir, _ := filepath.Abs(filepath.Dir(os.Args[0])) + t.translationsPath = filepath.Join(dir, "translations") - return nil + return nil } diff --git a/ui/gtk2/mainwindow_helpers.go b/ui/gtk2/mainwindow_helpers.go index 941d6b3..4aae9d5 100644 --- a/ui/gtk2/mainwindow_helpers.go +++ b/ui/gtk2/mainwindow_helpers.go @@ -1,47 +1,47 @@ package ui import ( - // stdlib - "strings" + // stdlib + "strings" - // other - "github.com/mattn/go-gtk/glib" - "github.com/mattn/go-gtk/gtk" + // other + "github.com/mattn/go-gtk/glib" + "github.com/mattn/go-gtk/gtk" ) func (m *MainWindow) getGameModeName(name string) string { - val, ok := m.gamemodes[name] + val, ok := m.gamemodes[name] - if !ok { - return "Unknown or custom" - } + if !ok { + return "Unknown or custom" + } - return val + return val } 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, ctx.Translator.Translate("Favorites", nil)) { - sel = m.fav_servers.GetSelection() - model = m.fav_servers.GetModel() - } + // 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, ctx.Translator.Translate("Favorites", nil)) { + sel = m.fav_servers.GetSelection() + model = m.fav_servers.GetModel() + } - iter := new(gtk.TreeIter) - _ = sel.GetSelected(iter) + iter := new(gtk.TreeIter) + _ = sel.GetSelected(iter) - // Getting server address. - var srv_addr string - srv_addr_gval := glib.ValueFromNative(srv_addr) + // Getting server address. + var srv_addr string + srv_addr_gval := glib.ValueFromNative(srv_addr) - if strings.Contains(current_tab, ctx.Translator.Translate("Servers", nil)) { - model.GetValue(iter, m.column_pos["Servers"]["IP"], srv_addr_gval) - } else if strings.Contains(current_tab, ctx.Translator.Translate("Favorites", nil)) { - model.GetValue(iter, m.column_pos["Favorites"]["IP"], srv_addr_gval) - } - server_address := srv_addr_gval.GetString() + if strings.Contains(current_tab, ctx.Translator.Translate("Servers", nil)) { + model.GetValue(iter, m.column_pos["Servers"]["IP"], srv_addr_gval) + } else if strings.Contains(current_tab, ctx.Translator.Translate("Favorites", nil)) { + model.GetValue(iter, m.column_pos["Favorites"]["IP"], srv_addr_gval) + } + server_address := srv_addr_gval.GetString() - return server_address + return server_address } diff --git a/ui/qt5/exported.go b/ui/qt5/exported.go index eb12052..8fd9433 100644 --- a/ui/qt5/exported.go +++ b/ui/qt5/exported.go @@ -10,16 +10,16 @@ package ui import ( - // local - "github.com/pztrn/urtrator/context" + // local + "github.com/pztrn/urtrator/context" ) var ( - ctx *context.Context + ctx *context.Context ) func NewMainWindow(c *context.Context) *MainWindow { - ctx = c - m := MainWindow{} - return &m + ctx = c + m := MainWindow{} + return &m } diff --git a/ui/qt5/mainwindow.go b/ui/qt5/mainwindow.go index d3811de..053d076 100644 --- a/ui/qt5/mainwindow.go +++ b/ui/qt5/mainwindow.go @@ -10,109 +10,108 @@ package ui import ( - // stdlib - "fmt" - //"runtime" - //"sort" - //"strconv" - //"strings" + // stdlib + "fmt" + //"runtime" + //"sort" + //"strconv" + //"strings" - // Local - //"github.com/pztrn/urtrator/datamodels" - //"github.com/pztrn/urtrator/ioq3dataparser" + // Local + //"github.com/pztrn/urtrator/datamodels" + //"github.com/pztrn/urtrator/ioq3dataparser" - // github - "github.com/therecipe/qt/widgets" + // github + "github.com/therecipe/qt/widgets" ) type MainWindow struct { - ////////////////////////////////////////////////// - // Main widgets and pointers. - ////////////////////////////////////////////////// - // Application. - app *widgets.QApplication - // Main window. - window *widgets.QMainWindow - // Main menu. - mainmenu *widgets.QMenuBar - // Main vertical box. - vbox *widgets.QVBoxLayout - // Toolbar. - toolbar *widgets.QToolBar - // Splitter. - splitter *widgets.QSplitter - // Tabs widget. - tabs *widgets.QTabWidget + ////////////////////////////////////////////////// + // Main widgets and pointers. + ////////////////////////////////////////////////// + // Application. + app *widgets.QApplication + // Main window. + window *widgets.QMainWindow + // Main menu. + mainmenu *widgets.QMenuBar + // Main vertical box. + vbox *widgets.QVBoxLayout + // Toolbar. + toolbar *widgets.QToolBar + // Splitter. + splitter *widgets.QSplitter + // Tabs widget. + tabs *widgets.QTabWidget - ////////////////////////////////////////////////// - // Servers lists and related. - ////////////////////////////////////////////////// - // "Servers" tab list. - all_servers *widgets.QTreeView - // Hide offline servers checkbox. - all_servers_hide_offline *widgets.QCheckBox - // Hide private servers? - all_servers_hide_private *widgets.QCheckBox - // Server's version. - all_servers_version *widgets.QComboBox - // Game mode. - all_servers_gamemode *widgets.QComboBox - // Favorites tab list. - fav_servers *widgets.QTreeView - // Hide offline servers checkbox. - fav_servers_hide_offline *widgets.QCheckBox - // Hide private servers? - fav_servers_hide_private *widgets.QCheckBox - // Server's version. - fav_servers_version *widgets.QComboBox - // Game mode. - fav_servers_gamemode *widgets.QComboBox - // Sidebar's server's information widget. - sidebar_server_info *widgets.QTreeView - // Sidebar's server's players widget. - sidebar_server_players *widgets.QTreeView + ////////////////////////////////////////////////// + // Servers lists and related. + ////////////////////////////////////////////////// + // "Servers" tab list. + all_servers *widgets.QTreeView + // Hide offline servers checkbox. + all_servers_hide_offline *widgets.QCheckBox + // Hide private servers? + all_servers_hide_private *widgets.QCheckBox + // Server's version. + all_servers_version *widgets.QComboBox + // Game mode. + all_servers_gamemode *widgets.QComboBox + // Favorites tab list. + fav_servers *widgets.QTreeView + // Hide offline servers checkbox. + fav_servers_hide_offline *widgets.QCheckBox + // Hide private servers? + fav_servers_hide_private *widgets.QCheckBox + // Server's version. + fav_servers_version *widgets.QComboBox + // Game mode. + fav_servers_gamemode *widgets.QComboBox + // Sidebar's server's information widget. + sidebar_server_info *widgets.QTreeView + // Sidebar's server's players widget. + sidebar_server_players *widgets.QTreeView - ////////////////////////////////////////////////// - // Datas. - ////////////////////////////////////////////////// - // Window size. - window_width int - window_height int - // Window position. - window_pos_x int - window_pos_y int - // Supported game modes. - gamemodes map[string]string - // Columns names for servers tabs. - column_names map[string]string - // Real columns positions on servers tabs. - column_pos map[string]map[string]int + ////////////////////////////////////////////////// + // Datas. + ////////////////////////////////////////////////// + // Window size. + window_width int + window_height int + // Window position. + window_pos_x int + window_pos_y int + // Supported game modes. + gamemodes map[string]string + // Columns names for servers tabs. + column_names map[string]string + // Real columns positions on servers tabs. + column_pos map[string]map[string]int } func (m *MainWindow) close(a bool) { - fmt.Println("Closing URTrator...") - m.app.Quit() + fmt.Println("Closing URTrator...") + m.app.Quit() } func (m *MainWindow) dropDatabasesData(bool) { - fmt.Println("About to drop databases data...") + fmt.Println("About to drop databases data...") } func (m *MainWindow) showAboutDialog(a bool) { - fmt.Println("Showing about dialog...") + fmt.Println("Showing about dialog...") } func (m *MainWindow) showAboutQtDialog(a bool) { - fmt.Println("Showing about Qt dialog...") - widgets.QMessageBox_AboutQt(m.window, "About Qt") + fmt.Println("Showing about Qt dialog...") + widgets.QMessageBox_AboutQt(m.window, "About Qt") } - func (m *MainWindow) showOptionsDialog(a bool) { - fmt.Println("Showing options dialog...") + fmt.Println("Showing options dialog...") } func (m *MainWindow) splitterMoved(pos int, index int) { - fmt.Println("Splitter moved!") - fmt.Println(index, pos) + fmt.Println("Splitter moved!") + fmt.Println(index, pos) } diff --git a/ui/qt5/mainwindow_init.go b/ui/qt5/mainwindow_init.go index 0da224a..a0fad2e 100644 --- a/ui/qt5/mainwindow_init.go +++ b/ui/qt5/mainwindow_init.go @@ -10,336 +10,336 @@ package ui import ( - // stdlib - "fmt" - "os" - //"runtime" - "sort" - "strconv" + // stdlib + "fmt" + "os" + //"runtime" + "sort" + "strconv" - // local - "github.com/pztrn/urtrator/common" + // local + "github.com/pztrn/urtrator/common" - // Qt5 - "github.com/therecipe/qt/core" - "github.com/therecipe/qt/widgets" + // Qt5 + "github.com/therecipe/qt/core" + "github.com/therecipe/qt/widgets" ) func (m *MainWindow) Initialize() { - fmt.Println("Initializing main window...") + fmt.Println("Initializing main window...") - m.app = widgets.NewQApplication(len(os.Args), os.Args) + m.app = widgets.NewQApplication(len(os.Args), os.Args) - m.initializeStorages() + m.initializeStorages() - m.window = widgets.NewQMainWindow(nil, 0) - m.window.SetWindowTitle("URTrator") + m.window = widgets.NewQMainWindow(nil, 0) + m.window.SetWindowTitle("URTrator") - // Restoring window position. - var win_pos_x_str string = "0" - var win_pos_y_str string = "0" - saved_win_pos_x_str, ok := ctx.Cfg.Cfg["/mainwindow/position_x"] - if ok { - win_pos_x_str = saved_win_pos_x_str - } - saved_win_pos_y_str, ok := ctx.Cfg.Cfg["/mainwindow/position_y"] - if ok { - win_pos_y_str = saved_win_pos_y_str - } - win_pos_x, _ := strconv.Atoi(win_pos_x_str) - win_pos_y, _ := strconv.Atoi(win_pos_y_str) + // Restoring window position. + var win_pos_x_str string = "0" + var win_pos_y_str string = "0" + saved_win_pos_x_str, ok := ctx.Cfg.Cfg["/mainwindow/position_x"] + if ok { + win_pos_x_str = saved_win_pos_x_str + } + saved_win_pos_y_str, ok := ctx.Cfg.Cfg["/mainwindow/position_y"] + if ok { + win_pos_y_str = saved_win_pos_y_str + } + win_pos_x, _ := strconv.Atoi(win_pos_x_str) + win_pos_y, _ := strconv.Atoi(win_pos_y_str) - // Restoring window size. - var win_size_width_str string = "1000" - var win_size_height_str string = "600" - saved_win_size_width_str, ok := ctx.Cfg.Cfg["/mainwindow/width"] - if ok { - win_size_width_str = saved_win_size_width_str - } - saved_win_size_height_str, ok := ctx.Cfg.Cfg["/mainwindow/height"] - if ok { - win_size_height_str = saved_win_size_height_str - } + // Restoring window size. + var win_size_width_str string = "1000" + var win_size_height_str string = "600" + saved_win_size_width_str, ok := ctx.Cfg.Cfg["/mainwindow/width"] + if ok { + win_size_width_str = saved_win_size_width_str + } + saved_win_size_height_str, ok := ctx.Cfg.Cfg["/mainwindow/height"] + if ok { + win_size_height_str = saved_win_size_height_str + } - m.window_width, _ = strconv.Atoi(win_size_width_str) - m.window_height, _ = strconv.Atoi(win_size_height_str) - m.window.SetGeometry2(win_pos_x, win_pos_y, m.window_width, m.window_height) + m.window_width, _ = strconv.Atoi(win_size_width_str) + m.window_height, _ = strconv.Atoi(win_size_height_str) + m.window.SetGeometry2(win_pos_x, win_pos_y, m.window_width, m.window_height) - m.initializeMenu() + m.initializeMenu() - // Central widget. - cv := widgets.NewQWidget(nil, core.Qt__Widget) - //cv_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Expanding, widgets.QSizePolicy__Expanding, widgets.QSizePolicy__DefaultType) - //cv.SetSizePolicy(cv_policy) - m.window.SetCentralWidget(cv) + // Central widget. + cv := widgets.NewQWidget(nil, core.Qt__Widget) + //cv_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Expanding, widgets.QSizePolicy__Expanding, widgets.QSizePolicy__DefaultType) + //cv.SetSizePolicy(cv_policy) + m.window.SetCentralWidget(cv) - // Main vertical box. - m.vbox = widgets.NewQVBoxLayout() - m.vbox.SetContentsMargins(4, 4, 4, 4) - cv.SetLayout(m.vbox) + // Main vertical box. + m.vbox = widgets.NewQVBoxLayout() + m.vbox.SetContentsMargins(4, 4, 4, 4) + cv.SetLayout(m.vbox) - m.initializeToolbar() - m.initializeTabs() - m.initializeSidebar() + m.initializeToolbar() + m.initializeTabs() + m.initializeSidebar() - m.window.Show() + m.window.Show() - // Restore splitter position. - // We will restore saved thing, or will use "window_width - 150". - saved_pane_pos, ok := ctx.Cfg.Cfg["/mainwindow/pane_negative_position"] - if ok { - pane_negative_pos, _ := strconv.Atoi(saved_pane_pos) - new_splitter_pos := m.window_width - pane_negative_pos - fmt.Println(new_splitter_pos) - m.splitter.MoveSplitter(new_splitter_pos, 1) - fmt.Println(m.splitter.ClosestLegalPosition(1, new_splitter_pos)) - } else { - g := m.window.Geometry() - w := g.Width() - m.splitter.MoveSplitter(w - 150, 1) - } + // Restore splitter position. + // We will restore saved thing, or will use "window_width - 150". + saved_pane_pos, ok := ctx.Cfg.Cfg["/mainwindow/pane_negative_position"] + if ok { + pane_negative_pos, _ := strconv.Atoi(saved_pane_pos) + new_splitter_pos := m.window_width - pane_negative_pos + fmt.Println(new_splitter_pos) + m.splitter.MoveSplitter(new_splitter_pos, 1) + fmt.Println(m.splitter.ClosestLegalPosition(1, new_splitter_pos)) + } else { + g := m.window.Geometry() + w := g.Width() + m.splitter.MoveSplitter(w-150, 1) + } - m.splitter.ConnectSplitterMoved(m.splitterMoved) + m.splitter.ConnectSplitterMoved(m.splitterMoved) - widgets.QApplication_Exec() + widgets.QApplication_Exec() } func (m *MainWindow) initializeSidebar() { - sidebar_widget := widgets.NewQWidget(nil, core.Qt__Widget) - m.splitter.AddWidget(sidebar_widget) + sidebar_widget := widgets.NewQWidget(nil, core.Qt__Widget) + m.splitter.AddWidget(sidebar_widget) - sidebar_layout := widgets.NewQVBoxLayout() - sidebar_layout.SetContentsMargins(4, 4, 4, 4) - sidebar_widget.SetLayout(sidebar_layout) + sidebar_layout := widgets.NewQVBoxLayout() + sidebar_layout.SetContentsMargins(4, 4, 4, 4) + sidebar_widget.SetLayout(sidebar_layout) - // Server's information list. - m.sidebar_server_info = widgets.NewQTreeView(nil) - sidebar_layout.AddWidget(m.sidebar_server_info, 0, core.Qt__AlignHCenter & core.Qt__AlignTop) + // Server's information list. + m.sidebar_server_info = widgets.NewQTreeView(nil) + sidebar_layout.AddWidget(m.sidebar_server_info, 0, core.Qt__AlignHCenter&core.Qt__AlignTop) - // Server's players widget. - m.sidebar_server_players = widgets.NewQTreeView(nil) - sidebar_layout.AddWidget(m.sidebar_server_players, 0, core.Qt__AlignHCenter & core.Qt__AlignTop) + // Server's players widget. + m.sidebar_server_players = widgets.NewQTreeView(nil) + sidebar_layout.AddWidget(m.sidebar_server_players, 0, core.Qt__AlignHCenter&core.Qt__AlignTop) - // Add spacer. - spacer := widgets.NewQSpacerItem(6, 6, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Expanding) - sidebar_layout.AddSpacerItem(spacer) + // Add spacer. + spacer := widgets.NewQSpacerItem(6, 6, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Expanding) + sidebar_layout.AddSpacerItem(spacer) } func (m *MainWindow) initializeStorages() { - m.gamemodes = make(map[string]string) - m.gamemodes = map[string]string{ - "1": "Last Man Standing", - "2": "Free For All", - "3": "Team DM", - "4": "Team Survivor", - "5": "Follow The Leader", - "6": "Cap'n'Hold", - "7": "Capture The Flag", - "8": "Bomb", - "9": "Jump", - "10": "Freeze Tag", - "11": "Gun Game", - "12": "Instagib", - } + m.gamemodes = make(map[string]string) + m.gamemodes = map[string]string{ + "1": "Last Man Standing", + "2": "Free For All", + "3": "Team DM", + "4": "Team Survivor", + "5": "Follow The Leader", + "6": "Cap'n'Hold", + "7": "Capture The Flag", + "8": "Bomb", + "9": "Jump", + "10": "Freeze Tag", + "11": "Gun Game", + "12": "Instagib", + } - // Columns names. - // Key - default position in lists. - m.column_names = map[string]string{ - "2": "Name", - "3": "Mode", - "4": "Map", - "5": "Players", - "6": "Ping", - "7": "Version", - "8": "IP", - } - // Real columns positions. - m.column_pos = make(map[string]map[string]int) - m.column_pos["Servers"] = make(map[string]int) - m.column_pos["Favorites"] = make(map[string]int) + // Columns names. + // Key - default position in lists. + m.column_names = map[string]string{ + "2": "Name", + "3": "Mode", + "4": "Map", + "5": "Players", + "6": "Ping", + "7": "Version", + "8": "IP", + } + // Real columns positions. + m.column_pos = make(map[string]map[string]int) + m.column_pos["Servers"] = make(map[string]int) + m.column_pos["Favorites"] = make(map[string]int) } func (m *MainWindow) initializeTabs() { - m.splitter = widgets.NewQSplitter(nil) - m.splitter.SetOrientation(core.Qt__Horizontal) - m.vbox.AddWidget(m.splitter, 0, core.Qt__AlignHCenter & core.Qt__AlignTop) + m.splitter = widgets.NewQSplitter(nil) + m.splitter.SetOrientation(core.Qt__Horizontal) + m.vbox.AddWidget(m.splitter, 0, core.Qt__AlignHCenter&core.Qt__AlignTop) - m.tabs = widgets.NewQTabWidget(nil) - m.splitter.AddWidget(m.tabs) + m.tabs = widgets.NewQTabWidget(nil) + m.splitter.AddWidget(m.tabs) - // Default size policy for filters widget. - filters_size_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__DefaultType) + // Default size policy for filters widget. + filters_size_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__DefaultType) - ////////////////////////////////////////////////// - // Servers page. - ////////////////////////////////////////////////// - serverspagewidget := widgets.NewQWidget(nil, core.Qt__Widget) - serverspagewidget_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Expanding, widgets.QSizePolicy__Expanding, widgets.QSizePolicy__DefaultType) - serverspagewidget.SetSizePolicy(serverspagewidget_policy) - m.tabs.AddTab(serverspagewidget, ctx.Translator.Translate("Servers", nil)) - serverspagewidget_layout := widgets.NewQHBoxLayout() - serverspagewidget_layout.SetContentsMargins(4, 4, 4, 4) - serverspagewidget.SetLayout(serverspagewidget_layout) + ////////////////////////////////////////////////// + // Servers page. + ////////////////////////////////////////////////// + serverspagewidget := widgets.NewQWidget(nil, core.Qt__Widget) + serverspagewidget_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Expanding, widgets.QSizePolicy__Expanding, widgets.QSizePolicy__DefaultType) + serverspagewidget.SetSizePolicy(serverspagewidget_policy) + m.tabs.AddTab(serverspagewidget, ctx.Translator.Translate("Servers", nil)) + serverspagewidget_layout := widgets.NewQHBoxLayout() + serverspagewidget_layout.SetContentsMargins(4, 4, 4, 4) + serverspagewidget.SetLayout(serverspagewidget_layout) - // Servers list. - m.all_servers = widgets.NewQTreeView(nil) - serverspagewidget_layout.AddWidget(m.all_servers, 0, core.Qt__AlignLeft & core.Qt__AlignTop) + // Servers list. + m.all_servers = widgets.NewQTreeView(nil) + serverspagewidget_layout.AddWidget(m.all_servers, 0, core.Qt__AlignLeft&core.Qt__AlignTop) - // Servers list filters widget. - serverspagewidget_filters_widget := widgets.NewQWidget(nil, core.Qt__Widget) - serverspagewidget_filters_widget_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__DefaultType) - serverspagewidget_filters_widget.SetSizePolicy(serverspagewidget_filters_widget_policy) - serverspagewidget_layout.AddWidget(serverspagewidget_filters_widget, 0, core.Qt__AlignRight & core.Qt__AlignTop) + // Servers list filters widget. + serverspagewidget_filters_widget := widgets.NewQWidget(nil, core.Qt__Widget) + serverspagewidget_filters_widget_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__DefaultType) + serverspagewidget_filters_widget.SetSizePolicy(serverspagewidget_filters_widget_policy) + serverspagewidget_layout.AddWidget(serverspagewidget_filters_widget, 0, core.Qt__AlignRight&core.Qt__AlignTop) - // Servers list filters layout. - serverspagewidget_filters_layout := widgets.NewQVBoxLayout() - serverspagewidget_filters_widget.SetLayout(serverspagewidget_filters_layout) - serverspagewidget_filters_layout.SetContentsMargins(4, 4, 4, 4) + // Servers list filters layout. + serverspagewidget_filters_layout := widgets.NewQVBoxLayout() + serverspagewidget_filters_widget.SetLayout(serverspagewidget_filters_layout) + serverspagewidget_filters_layout.SetContentsMargins(4, 4, 4, 4) - // Filters itself. + // Filters itself. - // Hide offline servers checkbox. - m.all_servers_hide_offline = widgets.NewQCheckBox(nil) - m.all_servers_hide_offline.SetText(ctx.Translator.Translate("Hide offline servers", nil)) - m.all_servers_hide_offline.SetSizePolicy(filters_size_policy) - serverspagewidget_filters_layout.AddWidget(m.all_servers_hide_offline, 0, core.Qt__AlignTop) - // Restore value of hide offline servers checkbox. - // Set to checked for new installations. - all_servers_hide_offline_cb_val, ok := ctx.Cfg.Cfg["/serverslist/all_servers/hide_offline"] - if !ok { - m.all_servers_hide_offline.SetCheckState(2) - } else { - if all_servers_hide_offline_cb_val == "1" { - m.all_servers_hide_offline.SetCheckState(2) - } - } + // Hide offline servers checkbox. + m.all_servers_hide_offline = widgets.NewQCheckBox(nil) + m.all_servers_hide_offline.SetText(ctx.Translator.Translate("Hide offline servers", nil)) + m.all_servers_hide_offline.SetSizePolicy(filters_size_policy) + serverspagewidget_filters_layout.AddWidget(m.all_servers_hide_offline, 0, core.Qt__AlignTop) + // Restore value of hide offline servers checkbox. + // Set to checked for new installations. + all_servers_hide_offline_cb_val, ok := ctx.Cfg.Cfg["/serverslist/all_servers/hide_offline"] + if !ok { + m.all_servers_hide_offline.SetCheckState(2) + } else { + if all_servers_hide_offline_cb_val == "1" { + m.all_servers_hide_offline.SetCheckState(2) + } + } - // Hide private servers. - m.all_servers_hide_private = widgets.NewQCheckBox(nil) - m.all_servers_hide_private.SetText(ctx.Translator.Translate("Hide private servers", nil)) - m.all_servers_hide_private.SetSizePolicy(filters_size_policy) - serverspagewidget_filters_layout.AddWidget(m.all_servers_hide_private, 0, core.Qt__AlignTop) - // 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.SetCheckState(2) - } else { - if all_servers_hide_private_cb_val == "1" { - m.all_servers_hide_private.SetCheckState(2) - } - } + // Hide private servers. + m.all_servers_hide_private = widgets.NewQCheckBox(nil) + m.all_servers_hide_private.SetText(ctx.Translator.Translate("Hide private servers", nil)) + m.all_servers_hide_private.SetSizePolicy(filters_size_policy) + serverspagewidget_filters_layout.AddWidget(m.all_servers_hide_private, 0, core.Qt__AlignTop) + // 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.SetCheckState(2) + } else { + if all_servers_hide_private_cb_val == "1" { + m.all_servers_hide_private.SetCheckState(2) + } + } - // Game version. - m.all_servers_version = widgets.NewQComboBox(nil) - m.all_servers_version.SetSizePolicy(filters_size_policy) - serverspagewidget_filters_layout.AddWidget(m.all_servers_version, 0, core.Qt__AlignTop) - // Fill game version combobox with supported versions. - m.all_servers_version.AddItems(common.SUPPORTED_URT_VERSIONS) + // Game version. + m.all_servers_version = widgets.NewQComboBox(nil) + m.all_servers_version.SetSizePolicy(filters_size_policy) + serverspagewidget_filters_layout.AddWidget(m.all_servers_version, 0, core.Qt__AlignTop) + // Fill game version combobox with supported versions. + m.all_servers_version.AddItems(common.SUPPORTED_URT_VERSIONS) - // Game mode. - m.all_servers_gamemode = widgets.NewQComboBox(nil) - m.all_servers_gamemode.SetSizePolicy(filters_size_policy) - serverspagewidget_filters_layout.AddWidget(m.all_servers_gamemode, 0, core.Qt__AlignTop) - // Fill game mode with supported gamemodes. - // First - create sorted gamemodes keys slice. - gm_keys := make([]int, 0, len(m.gamemodes)) - for k, _ := range m.gamemodes { - ki, _ := strconv.Atoi(k) - gm_keys = append(gm_keys, ki) - } - sort.Ints(gm_keys) - // Create a strings slice with gamemodes, using sorted keys. - gmodes := make([]string, 0, len(m.gamemodes)) - // Add "All gamemodes" as first gamemode :) - gmodes = append(gmodes, ctx.Translator.Translate("All gamemodes", nil)) - for i := range gm_keys { - ks := strconv.Itoa(gm_keys[i]) - gmodes = append(gmodes, m.gamemodes[ks]) - } - m.all_servers_gamemode.AddItems(gmodes) + // Game mode. + m.all_servers_gamemode = widgets.NewQComboBox(nil) + m.all_servers_gamemode.SetSizePolicy(filters_size_policy) + serverspagewidget_filters_layout.AddWidget(m.all_servers_gamemode, 0, core.Qt__AlignTop) + // Fill game mode with supported gamemodes. + // First - create sorted gamemodes keys slice. + gm_keys := make([]int, 0, len(m.gamemodes)) + for k, _ := range m.gamemodes { + ki, _ := strconv.Atoi(k) + gm_keys = append(gm_keys, ki) + } + sort.Ints(gm_keys) + // Create a strings slice with gamemodes, using sorted keys. + gmodes := make([]string, 0, len(m.gamemodes)) + // Add "All gamemodes" as first gamemode :) + gmodes = append(gmodes, ctx.Translator.Translate("All gamemodes", nil)) + for i := range gm_keys { + ks := strconv.Itoa(gm_keys[i]) + gmodes = append(gmodes, m.gamemodes[ks]) + } + m.all_servers_gamemode.AddItems(gmodes) - // After creating filters - add spacer to move them on top of widget. - all_servers_filters_spacer := widgets.NewQSpacerItem(6, 6, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Expanding) - serverspagewidget_filters_layout.AddSpacerItem(all_servers_filters_spacer) + // After creating filters - add spacer to move them on top of widget. + all_servers_filters_spacer := widgets.NewQSpacerItem(6, 6, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Expanding) + serverspagewidget_filters_layout.AddSpacerItem(all_servers_filters_spacer) - ////////////////////////////////////////////////// - // Favorites page. - ////////////////////////////////////////////////// - favoritespagewidget := widgets.NewQWidget(nil, core.Qt__Widget) - favoritespagewidget_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Expanding, widgets.QSizePolicy__Expanding, widgets.QSizePolicy__DefaultType) - favoritespagewidget.SetSizePolicy(favoritespagewidget_policy) - m.tabs.AddTab(favoritespagewidget, ctx.Translator.Translate("Favorites", nil)) - favoritespagewidget_layout := widgets.NewQHBoxLayout() - favoritespagewidget_layout.SetContentsMargins(4, 4, 4, 4) - favoritespagewidget.SetLayout(favoritespagewidget_layout) + ////////////////////////////////////////////////// + // Favorites page. + ////////////////////////////////////////////////// + favoritespagewidget := widgets.NewQWidget(nil, core.Qt__Widget) + favoritespagewidget_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Expanding, widgets.QSizePolicy__Expanding, widgets.QSizePolicy__DefaultType) + favoritespagewidget.SetSizePolicy(favoritespagewidget_policy) + m.tabs.AddTab(favoritespagewidget, ctx.Translator.Translate("Favorites", nil)) + favoritespagewidget_layout := widgets.NewQHBoxLayout() + favoritespagewidget_layout.SetContentsMargins(4, 4, 4, 4) + favoritespagewidget.SetLayout(favoritespagewidget_layout) - // Favorites list. - m.fav_servers = widgets.NewQTreeView(nil) - favoritespagewidget_layout.AddWidget(m.fav_servers, 0, core.Qt__AlignHCenter & core.Qt__AlignTop) + // Favorites list. + m.fav_servers = widgets.NewQTreeView(nil) + favoritespagewidget_layout.AddWidget(m.fav_servers, 0, core.Qt__AlignHCenter&core.Qt__AlignTop) - // Favorites list filters widget. - favoritespagewidget_filters_widget := widgets.NewQWidget(nil, core.Qt__Widget) - favoritespagewidget_filters_widget_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__DefaultType) - favoritespagewidget_filters_widget.SetSizePolicy(favoritespagewidget_filters_widget_policy) - favoritespagewidget_layout.AddWidget(favoritespagewidget_filters_widget, 0, core.Qt__AlignRight & core.Qt__AlignTop) + // Favorites list filters widget. + favoritespagewidget_filters_widget := widgets.NewQWidget(nil, core.Qt__Widget) + favoritespagewidget_filters_widget_policy := widgets.NewQSizePolicy2(widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__DefaultType) + favoritespagewidget_filters_widget.SetSizePolicy(favoritespagewidget_filters_widget_policy) + favoritespagewidget_layout.AddWidget(favoritespagewidget_filters_widget, 0, core.Qt__AlignRight&core.Qt__AlignTop) - // Favorites list filters layout. - favoritespagewidget_filters_layout := widgets.NewQVBoxLayout() - favoritespagewidget_filters_widget.SetLayout(favoritespagewidget_filters_layout) - favoritespagewidget_filters_layout.SetContentsMargins(4, 4, 4, 4) + // Favorites list filters layout. + favoritespagewidget_filters_layout := widgets.NewQVBoxLayout() + favoritespagewidget_filters_widget.SetLayout(favoritespagewidget_filters_layout) + favoritespagewidget_filters_layout.SetContentsMargins(4, 4, 4, 4) - // Filters itself. + // Filters itself. - // Hide offline servers checkbox. - m.fav_servers_hide_offline = widgets.NewQCheckBox(nil) - m.fav_servers_hide_offline.SetText(ctx.Translator.Translate("Hide offline servers", nil)) - m.fav_servers_hide_offline.SetSizePolicy(filters_size_policy) - favoritespagewidget_filters_layout.AddWidget(m.fav_servers_hide_offline, 0, core.Qt__AlignTop) - // Restore it's value. - favorite_servers_hide_offline_cb_val, ok := ctx.Cfg.Cfg["/serverslist/favorite/hide_offline"] - if !ok { - m.fav_servers_hide_offline.SetCheckState(2) - } else { - if favorite_servers_hide_offline_cb_val == "1" { - m.fav_servers_hide_offline.SetCheckState(2) - } - } + // Hide offline servers checkbox. + m.fav_servers_hide_offline = widgets.NewQCheckBox(nil) + m.fav_servers_hide_offline.SetText(ctx.Translator.Translate("Hide offline servers", nil)) + m.fav_servers_hide_offline.SetSizePolicy(filters_size_policy) + favoritespagewidget_filters_layout.AddWidget(m.fav_servers_hide_offline, 0, core.Qt__AlignTop) + // Restore it's value. + favorite_servers_hide_offline_cb_val, ok := ctx.Cfg.Cfg["/serverslist/favorite/hide_offline"] + if !ok { + m.fav_servers_hide_offline.SetCheckState(2) + } else { + if favorite_servers_hide_offline_cb_val == "1" { + m.fav_servers_hide_offline.SetCheckState(2) + } + } - // Hide private servers. - m.fav_servers_hide_private = widgets.NewQCheckBox(nil) - m.fav_servers_hide_private.SetText(ctx.Translator.Translate("Hide private servers", nil)) - m.fav_servers_hide_private.SetSizePolicy(filters_size_policy) - favoritespagewidget_filters_layout.AddWidget(m.fav_servers_hide_private, 0, core.Qt__AlignTop) - fav_servers_hide_private_cb_val, ok := ctx.Cfg.Cfg["/serverslist/favorite/hide_private"] - if !ok { - m.fav_servers_hide_private.SetCheckState(2) - } else { - if fav_servers_hide_private_cb_val == "1" { - m.fav_servers_hide_private.SetCheckState(2) - } - } + // Hide private servers. + m.fav_servers_hide_private = widgets.NewQCheckBox(nil) + m.fav_servers_hide_private.SetText(ctx.Translator.Translate("Hide private servers", nil)) + m.fav_servers_hide_private.SetSizePolicy(filters_size_policy) + favoritespagewidget_filters_layout.AddWidget(m.fav_servers_hide_private, 0, core.Qt__AlignTop) + fav_servers_hide_private_cb_val, ok := ctx.Cfg.Cfg["/serverslist/favorite/hide_private"] + if !ok { + m.fav_servers_hide_private.SetCheckState(2) + } else { + if fav_servers_hide_private_cb_val == "1" { + m.fav_servers_hide_private.SetCheckState(2) + } + } - // Game version. - m.fav_servers_version = widgets.NewQComboBox(nil) - m.fav_servers_version.SetSizePolicy(filters_size_policy) - favoritespagewidget_filters_layout.AddWidget(m.fav_servers_version, 0, core.Qt__AlignTop) - // Fill game version combobox with supported versions. - m.fav_servers_version.AddItems(common.SUPPORTED_URT_VERSIONS) + // Game version. + m.fav_servers_version = widgets.NewQComboBox(nil) + m.fav_servers_version.SetSizePolicy(filters_size_policy) + favoritespagewidget_filters_layout.AddWidget(m.fav_servers_version, 0, core.Qt__AlignTop) + // Fill game version combobox with supported versions. + m.fav_servers_version.AddItems(common.SUPPORTED_URT_VERSIONS) - // Game mode. - m.fav_servers_gamemode = widgets.NewQComboBox(nil) - m.fav_servers_gamemode.SetSizePolicy(filters_size_policy) - favoritespagewidget_filters_layout.AddWidget(m.fav_servers_gamemode, 0, core.Qt__AlignTop) - // Fill game mode with supported gamemodes. - // As we have previously created this list - reuse it. - m.fav_servers_gamemode.AddItems(gmodes) + // Game mode. + m.fav_servers_gamemode = widgets.NewQComboBox(nil) + m.fav_servers_gamemode.SetSizePolicy(filters_size_policy) + favoritespagewidget_filters_layout.AddWidget(m.fav_servers_gamemode, 0, core.Qt__AlignTop) + // Fill game mode with supported gamemodes. + // As we have previously created this list - reuse it. + m.fav_servers_gamemode.AddItems(gmodes) - // After creating filters - add spacer to move them on top of widget. - fav_servers_filters_spacer := widgets.NewQSpacerItem(6, 6, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Expanding) - favoritespagewidget_filters_layout.AddSpacerItem(fav_servers_filters_spacer) + // After creating filters - add spacer to move them on top of widget. + fav_servers_filters_spacer := widgets.NewQSpacerItem(6, 6, widgets.QSizePolicy__Minimum, widgets.QSizePolicy__Expanding) + favoritespagewidget_filters_layout.AddSpacerItem(fav_servers_filters_spacer) } func (m *MainWindow) initializeToolbar() { - m.toolbar = widgets.NewQToolBar("Main Toolbar", m.window) - m.window.AddToolBar(core.Qt__TopToolBarArea, m.toolbar) + m.toolbar = widgets.NewQToolBar("Main Toolbar", m.window) + m.window.AddToolBar(core.Qt__TopToolBarArea, m.toolbar) } diff --git a/ui/qt5/mainwindow_init_menu_mac.go b/ui/qt5/mainwindow_init_menu_mac.go index 7091c9b..949aa01 100644 --- a/ui/qt5/mainwindow_init_menu_mac.go +++ b/ui/qt5/mainwindow_init_menu_mac.go @@ -12,61 +12,61 @@ package ui import ( - // stdlib - //"fmt" - //"os" - //"runtime" + // stdlib + //"fmt" + //"os" + //"runtime" - // Qt5 - "github.com/therecipe/qt/widgets" + // Qt5 + "github.com/therecipe/qt/widgets" ) func (m *MainWindow) initializeMenu() { - m.mainmenu = widgets.NewQMenuBar(nil) + m.mainmenu = widgets.NewQMenuBar(nil) - ////////////////////////////////////////////////// - // File menu. - ////////////////////////////////////////////////// - filemenu := widgets.NewQMenu2("&File", nil) + ////////////////////////////////////////////////// + // File menu. + ////////////////////////////////////////////////// + filemenu := widgets.NewQMenu2("&File", nil) - // Options action. - file_options := filemenu.AddAction("&Options") - file_options.SetMenuRole(widgets.QAction__PreferencesRole) - file_options.ConnectTriggered(m.showOptionsDialog) + // Options action. + file_options := filemenu.AddAction("&Options") + file_options.SetMenuRole(widgets.QAction__PreferencesRole) + file_options.ConnectTriggered(m.showOptionsDialog) - // Separator :) - filemenu.AddSeparator() + // Separator :) + filemenu.AddSeparator() - // Exit URTrator. - file_exit := filemenu.AddAction("&Exit") - file_exit.SetMenuRole(widgets.QAction__QuitRole) - file_exit.ConnectTriggered(m.close) + // Exit URTrator. + file_exit := filemenu.AddAction("&Exit") + file_exit.SetMenuRole(widgets.QAction__QuitRole) + file_exit.ConnectTriggered(m.close) - m.mainmenu.AddMenu(filemenu) - ////////////////////////////////////////////////// - // About menu - ////////////////////////////////////////////////// - aboutmenu := widgets.NewQMenu2("&Help", nil) + m.mainmenu.AddMenu(filemenu) + ////////////////////////////////////////////////// + // About menu + ////////////////////////////////////////////////// + aboutmenu := widgets.NewQMenu2("&Help", nil) - // About URTrator. - about_about := aboutmenu.AddAction("&About URTrator...") - about_about.SetMenuRole(widgets.QAction__AboutRole) - about_about.ConnectTriggered(m.showAboutDialog) + // About URTrator. + about_about := aboutmenu.AddAction("&About URTrator...") + about_about.SetMenuRole(widgets.QAction__AboutRole) + about_about.ConnectTriggered(m.showAboutDialog) - // About Qt. - about_about_qt := aboutmenu.AddAction("About &Qt...") - about_about_qt.SetMenuRole(widgets.QAction__AboutQtRole) - about_about_qt.ConnectTriggered(m.showAboutQtDialog) + // About Qt. + about_about_qt := aboutmenu.AddAction("About &Qt...") + about_about_qt.SetMenuRole(widgets.QAction__AboutQtRole) + about_about_qt.ConnectTriggered(m.showAboutQtDialog) - // Separator :) - aboutmenu.AddSeparator() + // Separator :) + aboutmenu.AddSeparator() - // Drop database data. - about_drop_database := aboutmenu.AddAction("&Drop database...") - //about_drop_database.SetMenuRole(widgets.QAction__ApplicationSpecificRole) - about_drop_database.ConnectTriggered(m.dropDatabasesData) + // Drop database data. + about_drop_database := aboutmenu.AddAction("&Drop database...") + //about_drop_database.SetMenuRole(widgets.QAction__ApplicationSpecificRole) + about_drop_database.ConnectTriggered(m.dropDatabasesData) - m.mainmenu.AddMenu(aboutmenu) + m.mainmenu.AddMenu(aboutmenu) - m.window.SetMenuBar(m.mainmenu) + m.window.SetMenuBar(m.mainmenu) }