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>
<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">
<default>"localhost"</default>
<summary>Host to connect to</summary>
@ -49,12 +49,5 @@
Password to use
</description>
</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>
</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="icon_name">sernatur</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>
<placeholder/>
</child>

View File

@ -1,4 +1,5 @@
src/sernatur.vala
src/sernatur-window.vala
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 ""
"Project-Id-Version: sernatur\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-12-23 16:09-0300\n"
"PO-Revision-Date: 2018-12-23 16:10-0300\n"
"POT-Creation-Date: 2018-12-23 19:19-0300\n"
"PO-Revision-Date: 2018-12-23 19:21-0300\n"
"Last-Translator: Chris Cromer <chris@cromer.cl>\n"
"Language-Team: none\n"
"Language: es\n"
@ -18,73 +18,81 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\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"
msgstr "Error"
#: src/sernatur-window.vala:91
#: src/sernatur-window.vala:125
msgid "Server version:"
msgstr "Versión del servidor:"
#: data/ui/sernatur.window.ui:40
#: data/ui/sernatur.window.ui:42
msgid "_File"
msgstr ""
#: data/ui/sernatur.window.ui:105
#: data/ui/sernatur.window.ui:107
msgid "_Edit"
msgstr ""
#: data/ui/sernatur.window.ui:155
#: data/ui/sernatur.window.ui:157
msgid "_View"
msgstr ""
#: data/ui/sernatur.window.ui:163
#: data/ui/sernatur.window.ui:165
msgid "_Help"
msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:5
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:6
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:6
msgid "Host to connect to"
msgstr "Servidor a conectar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:12
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:13
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:12
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:13
msgid "Port number to use"
msgstr "Número de puerto a usar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:19
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:20
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:19
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:20
msgid "Options to use"
msgstr "Opciones a usar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:26
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:27
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:26
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:27
msgid "tty to send debug info (ignored)"
msgstr "tty para enviar datos de depuración (ignorado)"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:33
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:34
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:33
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:34
msgid "Database to use"
msgstr "Base de dato a usar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:40
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:41
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:40
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:41
msgid "Username to use"
msgstr "Nombre de usuario a usar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:47
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:48
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:47
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:48
msgid "Password to use"
msgstr "Contraseña a usar"
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:54
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:55
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:5
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:6
msgid "Should the program open maximized or not"
msgstr "Si el programa debe abrir maximizado ó no"
#, fuzzy
#~ msgid "The file '%s' doesn't exist.\n"
#~ msgstr "El archivo '%s' no existe.\n"
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:12
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:13
msgid "Window width"
msgstr "El ancho de la ventana"
#~ msgid "Connection failed"
#~ msgstr "Conexión falló"
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:19
#: 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 ""
"Project-Id-Version: sernatur\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"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,66 +17,81 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\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"
msgstr ""
#: src/sernatur-window.vala:91
#: src/sernatur-window.vala:125
msgid "Server version:"
msgstr ""
#: data/ui/sernatur.window.ui:40
#: data/ui/sernatur.window.ui:42
msgid "_File"
msgstr ""
#: data/ui/sernatur.window.ui:105
#: data/ui/sernatur.window.ui:107
msgid "_Edit"
msgstr ""
#: data/ui/sernatur.window.ui:155
#: data/ui/sernatur.window.ui:157
msgid "_View"
msgstr ""
#: data/ui/sernatur.window.ui:163
#: data/ui/sernatur.window.ui:165
msgid "_Help"
msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:5
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:6
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:6
msgid "Host to connect to"
msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:12
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:13
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:12
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:13
msgid "Port number to use"
msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:19
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:20
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:19
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:20
msgid "Options to use"
msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:26
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:27
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:26
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:27
msgid "tty to send debug info (ignored)"
msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:33
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:34
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:33
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:34
msgid "Database to use"
msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:40
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:41
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:40
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:41
msgid "Username to use"
msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:47
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:48
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:47
#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:48
msgid "Password to use"
msgstr ""
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:54
#: data/gschema/cl.cromer.ubb.sernatur.gschema.xml:55
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:5
#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:6
msgid "Should the program open maximized or not"
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
* @param widget The widget that called this GtkCallback
* @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]
private bool state_handler(Gtk.Widget widget, Gdk.EventWindowState state) {
Settings settings = new Settings ("cl.cromer.ubb.sernatur");
private bool maximize_window(Gtk.Widget widget, Gdk.EventWindowState state) {
Settings settings = new Settings ("cl.cromer.ubb.sernatur.window");
if (state.changed_mask == Gdk.WindowState.MAXIMIZED && (state.new_window_state & Gdk.WindowState.MAXIMIZED) != 0) {
// Maximized
settings.set_boolean ("maximized", true);
@ -44,6 +44,20 @@ namespace Sernatur {
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
* @param application The application used to make the GLib object
@ -52,7 +66,7 @@ namespace Sernatur {
GLib.Object (application: application);
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 port = settings.get_string ("port");
string options = settings.get_string ("options");

View File

@ -39,16 +39,19 @@ namespace Sernatur {
*/
public override void activate () {
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")) {
window.maximize ();
}
try {
window.icon = IconTheme.get_default ().load_icon ("sernatur", 48, 0);
}
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 ();
}