handle settings for window size

This commit is contained in:
Chris Cromer 2018-12-23 19:24:09 -03:00
parent ff33532ed3
commit 0a7d34595c
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
9 changed files with 131 additions and 70 deletions

View File

@ -1,5 +1,5 @@
<schemalist> <schemalist>
<schema id="cl.cromer.ubb.sernatur" path="/cl/cromer/ubb/sernatur/" gettext-domain="sernatur"> <schema id="cl.cromer.ubb.sernatur.db" path="/cl/cromer/ubb/sernatur/" gettext-domain="sernatur">
<key name="host" type="s"> <key name="host" type="s">
<default>"localhost"</default> <default>"localhost"</default>
<summary>Host to connect to</summary> <summary>Host to connect to</summary>
@ -49,12 +49,5 @@
Password to use Password to use
</description> </description>
</key> </key>
<key name="maximized" type="b">
<default>false</default>
<summary>Should the program open maximized or not</summary>
<description>
Should the program open maximized or not
</description>
</key>
</schema> </schema>
</schemalist> </schemalist>

View File

@ -0,0 +1,25 @@
<schemalist>
<schema id="cl.cromer.ubb.sernatur.window" path="/cl/cromer/ubb/sernatur/" gettext-domain="sernatur">
<key name="maximized" type="b">
<default>false</default>
<summary>Should the program open maximized or not</summary>
<description>
Should the program open maximized or not
</description>
</key>
<key name="width" type="i">
<default>640</default>
<summary>Window width</summary>
<description>
Window width
</description>
</key>
<key name="height" type="i">
<default>480</default>
<summary>Window height</summary>
<description>
Window height
</description>
</key>
</schema>
</schemalist>

View File

@ -1 +1,2 @@
install_data('cl.cromer.ubb.sernatur.gschema.xml', install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'glib-2.0', 'schemas')) install_data('cl.cromer.ubb.sernatur.db.gschema.xml', install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'glib-2.0', 'schemas'))
install_data('cl.cromer.ubb.sernatur.window.gschema.xml', install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'glib-2.0', 'schemas'))

View File

@ -21,7 +21,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<property name="title">SERNATUR</property> <property name="title">SERNATUR</property>
<property name="icon_name">sernatur</property> <property name="icon_name">sernatur</property>
<property name="show_menubar">False</property> <property name="show_menubar">False</property>
<signal name="window-state-event" handler="state_handler" swapped="no"/> <signal name="configure-event" handler="resize_window" swapped="no"/>
<signal name="window-state-event" handler="maximize_window" swapped="no"/>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>

View File

@ -1,4 +1,5 @@
src/sernatur.vala src/sernatur.vala
src/sernatur-window.vala src/sernatur-window.vala
data/ui/sernatur.window.ui data/ui/sernatur.window.ui
data/gschema/cl.cromer.ubb.sernatur.gschema.xml data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml
data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml

View File

@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: sernatur\n" "Project-Id-Version: sernatur\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-12-23 16:09-0300\n" "POT-Creation-Date: 2018-12-23 19:19-0300\n"
"PO-Revision-Date: 2018-12-23 16:10-0300\n" "PO-Revision-Date: 2018-12-23 19:21-0300\n"
"Last-Translator: Chris Cromer <chris@cromer.cl>\n" "Last-Translator: Chris Cromer <chris@cromer.cl>\n"
"Language-Team: none\n" "Language-Team: none\n"
"Language: es\n" "Language: es\n"
@ -18,73 +18,81 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.0.6\n" "X-Generator: Poedit 2.0.6\n"
#: src/sernatur-window.vala:63 #: src/sernatur.vala:54
#, c-format
msgid "Could not load application icon: %s\n"
msgstr "No se puede cargar el icono de la aplicación: %s\n"
#: src/sernatur-window.vala:97
msgid "Error" msgid "Error"
msgstr "Error" msgstr "Error"
#: src/sernatur-window.vala:91 #: src/sernatur-window.vala:125
msgid "Server version:" msgid "Server version:"
msgstr "Versión del servidor:" msgstr "Versión del servidor:"
#: data/ui/sernatur.window.ui:40 #: data/ui/sernatur.window.ui:42
msgid "_File" msgid "_File"
msgstr "" msgstr ""
#: data/ui/sernatur.window.ui:105 #: data/ui/sernatur.window.ui:107
msgid "_Edit" msgid "_Edit"
msgstr "" msgstr ""
#: data/ui/sernatur.window.ui:155 #: data/ui/sernatur.window.ui:157
msgid "_View" msgid "_View"
msgstr "" msgstr ""
#: data/ui/sernatur.window.ui:163 #: data/ui/sernatur.window.ui:165
msgid "_Help" msgid "_Help"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:5 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:6 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:6
msgid "Host to connect to" msgid "Host to connect to"
msgstr "Servidor a conectar" msgstr "Servidor a conectar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:12 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:12
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:13 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:13
msgid "Port number to use" msgid "Port number to use"
msgstr "Número de puerto a usar" msgstr "Número de puerto a usar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:19 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:19
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:20 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:20
msgid "Options to use" msgid "Options to use"
msgstr "Opciones a usar" msgstr "Opciones a usar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:26 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:26
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:27 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:27
msgid "tty to send debug info (ignored)" msgid "tty to send debug info (ignored)"
msgstr "tty para enviar datos de depuración (ignorado)" msgstr "tty para enviar datos de depuración (ignorado)"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:33 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:33
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:34 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:34
msgid "Database to use" msgid "Database to use"
msgstr "Base de dato a usar" msgstr "Base de dato a usar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:40 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:40
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:41 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:41
msgid "Username to use" msgid "Username to use"
msgstr "Nombre de usuario a usar" msgstr "Nombre de usuario a usar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:47 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:47
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:48 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:48
msgid "Password to use" msgid "Password to use"
msgstr "Contraseña a usar" msgstr "Contraseña a usar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:54 #: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:5
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:55 #: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:6
msgid "Should the program open maximized or not" msgid "Should the program open maximized or not"
msgstr "Si el programa debe abrir maximizado ó no" msgstr "Si el programa debe abrir maximizado ó no"
#, fuzzy #: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:12
#~ msgid "The file '%s' doesn't exist.\n" #: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:13
#~ msgstr "El archivo '%s' no existe.\n" msgid "Window width"
msgstr "El ancho de la ventana"
#~ msgid "Connection failed" #: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:19
#~ msgstr "Conexión falló" #: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:20
msgid "Window height"
msgstr "La altura de la venta"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: sernatur\n" "Project-Id-Version: sernatur\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-12-23 16:09-0300\n" "POT-Creation-Date: 2018-12-23 19:19-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,66 +17,81 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: src/sernatur-window.vala:63 #: src/sernatur.vala:54
#, c-format
msgid "Could not load application icon: %s\n"
msgstr ""
#: src/sernatur-window.vala:97
msgid "Error" msgid "Error"
msgstr "" msgstr ""
#: src/sernatur-window.vala:91 #: src/sernatur-window.vala:125
msgid "Server version:" msgid "Server version:"
msgstr "" msgstr ""
#: data/ui/sernatur.window.ui:40 #: data/ui/sernatur.window.ui:42
msgid "_File" msgid "_File"
msgstr "" msgstr ""
#: data/ui/sernatur.window.ui:105 #: data/ui/sernatur.window.ui:107
msgid "_Edit" msgid "_Edit"
msgstr "" msgstr ""
#: data/ui/sernatur.window.ui:155 #: data/ui/sernatur.window.ui:157
msgid "_View" msgid "_View"
msgstr "" msgstr ""
#: data/ui/sernatur.window.ui:163 #: data/ui/sernatur.window.ui:165
msgid "_Help" msgid "_Help"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:5 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:6 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:6
msgid "Host to connect to" msgid "Host to connect to"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:12 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:12
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:13 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:13
msgid "Port number to use" msgid "Port number to use"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:19 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:19
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:20 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:20
msgid "Options to use" msgid "Options to use"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:26 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:26
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:27 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:27
msgid "tty to send debug info (ignored)" msgid "tty to send debug info (ignored)"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:33 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:33
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:34 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:34
msgid "Database to use" msgid "Database to use"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:40 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:40
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:41 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:41
msgid "Username to use" msgid "Username to use"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:47 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:47
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:48 #: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:48
msgid "Password to use" msgid "Password to use"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:54 #: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:5
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:55 #: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:6
msgid "Should the program open maximized or not" msgid "Should the program open maximized or not"
msgstr "" msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:12
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:13
msgid "Window width"
msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:19
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:20
msgid "Window height"
msgstr ""

View File

@ -28,11 +28,11 @@ namespace Sernatur {
* This is a callback for when the window's state changes * This is a callback for when the window's state changes
* @param widget The widget that called this GtkCallback * @param widget The widget that called this GtkCallback
* @param state The event window state_handler * @param state The event window state_handler
* @return Returns true or false * @return Returns true if the event is handled or false if it isn't
*/ */
[GtkCallback] [GtkCallback]
private bool state_handler(Gtk.Widget widget, Gdk.EventWindowState state) { private bool maximize_window(Gtk.Widget widget, Gdk.EventWindowState state) {
Settings settings = new Settings ("cl.cromer.ubb.sernatur"); Settings settings = new Settings ("cl.cromer.ubb.sernatur.window");
if (state.changed_mask == Gdk.WindowState.MAXIMIZED && (state.new_window_state & Gdk.WindowState.MAXIMIZED) != 0) { if (state.changed_mask == Gdk.WindowState.MAXIMIZED && (state.new_window_state & Gdk.WindowState.MAXIMIZED) != 0) {
// Maximized // Maximized
settings.set_boolean ("maximized", true); settings.set_boolean ("maximized", true);
@ -44,6 +44,20 @@ namespace Sernatur {
return true; return true;
} }
[GtkCallback]
private bool resize_window(Gtk.Widget widget, Gdk.Event event) {
Settings settings = new Settings ("cl.cromer.ubb.sernatur.window");
if (event.get_event_type () == Gdk.EventType.CONFIGURE && !settings.get_boolean ("maximized")) {
if (settings.get_int ("width") != event.get_window ().get_width ()) {
settings.set_int ("width", event.get_window ().get_width ());
}
if (settings.get_int ("height") != event.get_window ().get_height ()) {
settings.set_int ("height", event.get_window ().get_height ());
}
}
return false;
}
/** /**
* Initialize the main window class * Initialize the main window class
* @param application The application used to make the GLib object * @param application The application used to make the GLib object
@ -52,7 +66,7 @@ namespace Sernatur {
GLib.Object (application: application); GLib.Object (application: application);
Database conn; Database conn;
Settings settings = new Settings ("cl.cromer.ubb.sernatur"); Settings settings = new Settings ("cl.cromer.ubb.sernatur.db");
string host = settings.get_string ("host"); string host = settings.get_string ("host");
string port = settings.get_string ("port"); string port = settings.get_string ("port");
string options = settings.get_string ("options"); string options = settings.get_string ("options");

View File

@ -39,16 +39,19 @@ namespace Sernatur {
*/ */
public override void activate () { public override void activate () {
window = new MainWindow (this); window = new MainWindow (this);
GLib.Settings settings = new GLib.Settings ("cl.cromer.ubb.sernatur"); GLib.Settings settings = new GLib.Settings ("cl.cromer.ubb.sernatur.window");
window.set_default_size (settings.get_int("width"), settings.get_int("height"));
if (settings.get_boolean ("maximized")) { if (settings.get_boolean ("maximized")) {
window.maximize (); window.maximize ();
} }
try { try {
window.icon = IconTheme.get_default ().load_icon ("sernatur", 48, 0); window.icon = IconTheme.get_default ().load_icon ("sernatur", 48, 0);
} }
catch (Error e) { catch (Error e) {
stderr.printf ("Could not load application icon: %s\n", e.message); stderr.printf (dgettext (null, "Could not load application icon: %s\n"), e.message);
} }
window.present (); window.present ();
} }