diff --git a/data/ui/asignatura.editor.ui b/data/ui/asignatura.editor.ui index 2a73deb..d9ce6c6 100644 --- a/data/ui/asignatura.editor.ui +++ b/data/ui/asignatura.editor.ui @@ -1,5 +1,5 @@ - + + + + diff --git a/data/ui/horario.gresource.xml b/data/ui/horario.gresource.xml new file mode 100644 index 0000000..4576c50 --- /dev/null +++ b/data/ui/horario.gresource.xml @@ -0,0 +1,20 @@ + + + + + horario.list.ui + horario.editor.ui + + diff --git a/data/ui/horario.list.ui b/data/ui/horario.list.ui new file mode 100644 index 0000000..49d4dac --- /dev/null +++ b/data/ui/horario.list.ui @@ -0,0 +1,189 @@ + + + + + + + diff --git a/data/ui/main.window.ui b/data/ui/main.window.ui index 706afdb..f563e0e 100644 --- a/data/ui/main.window.ui +++ b/data/ui/main.window.ui @@ -53,10 +53,11 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - + True False - Horario + Horarios + @@ -64,6 +65,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND True False Registro + @@ -71,6 +73,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND True False Curso + diff --git a/data/ui/meson.build b/data/ui/meson.build index 80b0152..a7f5cac 100644 --- a/data/ui/meson.build +++ b/data/ui/meson.build @@ -11,6 +11,12 @@ asignatura_gresource = gnome.compile_resources('asignatura_gresource', c_name: meson.project_name() + '_resource_asignatura', export: true, install_header: true) +horario_gresource = gnome.compile_resources('horario_gresource', + 'horario.gresource.xml', + source_dir: '.', + c_name: meson.project_name() + '_resource_horario', + export: true, + install_header: true) query_gresource = gnome.compile_resources('query_gresource', 'query.gresource.xml', source_dir: '.', diff --git a/src/asignatura_editor.vala b/src/asignatura_editor.vala index 7b27ab2..abccb03 100644 --- a/src/asignatura_editor.vala +++ b/src/asignatura_editor.vala @@ -187,7 +187,7 @@ FROM asignatura private void update_instance () { asignatura.nombre = asignatura_name.get_text ().strip (); - Profesor new_profesor = new Profesor(); + Profesor new_profesor = new Profesor (); Gtk.TreeIter iter; profesor.get_active_iter (out iter); if (profesor_list_store.iter_is_valid (iter)) { @@ -260,6 +260,10 @@ FROM profesor profesor.set_active_iter (iter); } }); + + if (asignatura.id_asignatura == 0) { + profesor.set_active (0); + } } } } diff --git a/src/db/asignatura.vala b/src/db/asignatura.vala index 4df3ae1..c01de71 100644 --- a/src/db/asignatura.vala +++ b/src/db/asignatura.vala @@ -5,7 +5,7 @@ namespace Colegio { public string nombre { get; set; default = ""; } public Profesor profesor { get; set; default = new Profesor(); } - public Asignatura (int id_asignatura = 0, string nombre = "", Profesor profesor = new Profesor()) { + public Asignatura (int id_asignatura = 0, string nombre = "", Profesor profesor = new Profesor ()) { this.id_asignatura = id_asignatura; this.nombre = nombre; this.profesor = profesor; diff --git a/src/db/bloque.vala b/src/db/bloque.vala new file mode 100644 index 0000000..513446a --- /dev/null +++ b/src/db/bloque.vala @@ -0,0 +1,13 @@ +namespace Colegio { + namespace DB { + public class Bloque : Object { + public int id_bloque { get; set; default = 0; } + public string descripcion { get; set; default = ""; } + + public Bloque (int id_bloque = 0, string descripcion = "") { + this.id_bloque = id_bloque; + this.descripcion = descripcion; + } + } + } +} diff --git a/src/db/horario.vala b/src/db/horario.vala new file mode 100644 index 0000000..e522797 --- /dev/null +++ b/src/db/horario.vala @@ -0,0 +1,15 @@ +namespace Colegio { + namespace DB { + public class Horario : Object { + public Asignatura asignatura { get; set; default = new Asignatura (); } + public Bloque bloque { get; set; default = new Bloque (); } + public string sala { get; set; default = ""; } + + public Horario (Asignatura asignatura = new Asignatura (), Bloque bloque = new Bloque (), string sala = "") { + this.asignatura = asignatura; + this.bloque = bloque; + this.sala = sala; + } + } + } +} diff --git a/src/horario_editor.vala b/src/horario_editor.vala new file mode 100644 index 0000000..4edb7dd --- /dev/null +++ b/src/horario_editor.vala @@ -0,0 +1,347 @@ +/* + * Copyright 2019 Chris Cromer + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace Colegio { + using Constants; + using Misc; + using DB; + using DB.Wrapper; + using Postgres; + + [GtkTemplate (ui = "/cl/cromer/ubb/colegio/horario.editor.ui")] + public class HorarioEditor : Gtk.ApplicationWindow { + private Connection conn; + private Horario horario; + private bool new_horario = false; + + private List asignaturas; + private Gtk.ListStore asignatura_list_store; + private List bloques; + private Gtk.ListStore bloque_list_store; + + public signal void save_horario (); + + private enum AsignaturaColumn { + NAME, + ASIGNATURA, + N_COLUMNS + } + private enum BloqueColumn { + DESCRIPCION, + BLOQUE, + N_COLUMNS + } + + [GtkChild] + private Gtk.ComboBoxText asignatura; + + [GtkChild] + private Gtk.ComboBoxText bloque; + + [GtkChild] + private Gtk.Entry sala; + + [GtkChild] + private Gtk.Button save; + + [GtkChild] + private Gtk.Button cancel; + + public HorarioEditor (Gtk.Application application, Connection conn, Horario? horario) { + Object (application: application); + this.conn = conn; + this.horario = horario; + } + + [GtkCallback] + public void on_clicked_button (Gtk.Button button) { + if (button == cancel) { + this.close (); + } + else if (button == save) { + update_instance (); + if (validate_data ()) { + if (new_horario) { + try { + var res = conn.db.exec (" +INSERT INTO horario +(id_asignatura, id_bloque, sala) +VALUES +( +'" + horario.asignatura.id_asignatura.to_string () + "', +'" + horario.bloque.id_bloque.to_string () + "', +'" + conn.escape (horario.sala) + "' +) + "); + if (res.get_status () != ExecStatus.COMMAND_OK) { + #if DEBUG + error (conn.db.get_error_message ()); + #else + warning (conn.db.get_error_message ()); + #endif + } + } + catch (PostgresError e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + finally { + save_horario (); // Signal the parent to update itself + this.close (); + } + } + else { + try { + var res = conn.db.exec (" +UPDATE horario SET + sala = '" + conn.escape (horario.sala) + "' +WHERE id_asignatura = " + horario.asignatura.id_asignatura.to_string () + " AND +id_bloque = " + horario.bloque.id_bloque.to_string () + ); + if (res.get_status () != ExecStatus.COMMAND_OK) { + #if DEBUG + error (conn.db.get_error_message ()); + #else + warning (conn.db.get_error_message ()); + #endif + } + } + catch (PostgresError e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + finally { + save_horario (); // Signal the parent to update itself + this.close (); + } + } + } + } + } + + private bool validate_data () { + if (horario.sala.strip () == "") { + var msg = new Gtk.MessageDialog (this, + Gtk.DialogFlags.MODAL, + Gtk.MessageType.ERROR, + Gtk.ButtonsType.CLOSE, + "Error: No se puede dejar la sala en blanco!"); + msg.response.connect ((response_id) => { + msg.destroy (); + }); + msg.set_title ("Error"); + msg.run (); + return false; + } + var res = conn.db.exec (" +SELECT id_asignatura, id_bloque +FROM horario + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.db.get_error_message ()); + #else + warning (conn.db.get_error_message ()); + return false; + #endif + } + else { + var wra = new ResultWrapper (res); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + if (new_horario && + wra.get_int_n (i, "id_asignatura") == horario.asignatura.id_asignatura && + wra.get_int_n (i, "id_bloque") == horario.bloque.id_bloque) { + var msg = new Gtk.MessageDialog (this, + Gtk.DialogFlags.MODAL, + Gtk.MessageType.ERROR, + Gtk.ButtonsType.CLOSE, + "Error: Un horario con la asignatura \"%s\" y bloque \"%s\" ya existe!", + horario.asignatura.nombre, horario.bloque.descripcion); + msg.response.connect ((response_id) => { + msg.destroy (); + }); + msg.set_title ("Error"); + msg.run (); + return false; + } + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + } + return true; + } + + private void update_instance () { + horario.sala = sala.get_text ().strip (); + + Asignatura new_asignatura = new Asignatura (); + Gtk.TreeIter iter; + asignatura.get_active_iter (out iter); + if (asignatura_list_store.iter_is_valid (iter)) { + asignatura_list_store.get (iter, + AsignaturaColumn.ASIGNATURA, out new_asignatura); + } + horario.asignatura = new_asignatura; + + Bloque new_bloque = new Bloque (); + bloque.get_active_iter (out iter); + if (bloque_list_store.iter_is_valid (iter)) { + bloque_list_store.get (iter, + BloqueColumn.BLOQUE, out new_bloque); + } + horario.bloque = new_bloque; + } + + public void initialize () { + var res = conn.db.exec (" +SELECT id_asignatura, nombre +FROM asignatura + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.db.get_error_message ()); + #else + warning (conn.db.get_error_message ()); + #endif + } + else { + var wra = new ResultWrapper (res); + asignaturas = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var result = new Asignatura ( + wra.get_int_n (i, "id_asignatura"), + wra.get_string_n (i, "nombre") + ); + asignaturas.append (result); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + } + + res = conn.db.exec (" +SELECT id_bloque, descripcion +FROM bloque + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.db.get_error_message ()); + #else + warning (conn.db.get_error_message ()); + #endif + } + else { + var wra = new ResultWrapper (res); + bloques = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var result = new Bloque ( + wra.get_int_n (i, "id_bloque"), + wra.get_string_n (i, "descripcion") + ); + bloques.append (result); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + } + + asignaturas.sort_with_data ((a, b) => { + return strcmp (a.nombre, b.nombre); + }); + + bloques.sort_with_data ((a, b) => { + return strcmp (a.descripcion, b.descripcion); + }); + + asignatura_list_store = new Gtk.ListStore (AsignaturaColumn.N_COLUMNS, + typeof (string), + typeof (Asignatura)); + + bloque_list_store = new Gtk.ListStore (BloqueColumn.N_COLUMNS, + typeof (string), + typeof (Bloque)); + + asignatura.set_model (asignatura_list_store); + + bloque.set_model (bloque_list_store); + + if (horario != null) { + sala.set_text (horario.sala); + asignatura.set_sensitive (false); + bloque.set_sensitive (false); + } + else { + new_horario = true; + horario = new Horario (); + horario.asignatura = new Asignatura (); + horario.bloque = new Bloque (); + } + + asignaturas.foreach ((entry) => { + Gtk.TreeIter iter; + asignatura_list_store.append (out iter); + asignatura_list_store.set (iter, + AsignaturaColumn.NAME, entry.nombre, + AsignaturaColumn.ASIGNATURA, entry); + if (entry.id_asignatura == horario.asignatura.id_asignatura) { + asignatura.set_active_iter (iter); + } + }); + + bloques.foreach ((entry) => { + Gtk.TreeIter iter; + bloque_list_store.append (out iter); + bloque_list_store.set (iter, + BloqueColumn.DESCRIPCION, entry.descripcion, + BloqueColumn.BLOQUE, entry); + if (entry.id_bloque == horario.bloque.id_bloque) { + bloque.set_active_iter (iter); + } + }); + + if (horario.asignatura.id_asignatura == 0 && horario.bloque.id_bloque == 0) { + asignatura.set_active (0); + bloque.set_active (0); + } + } + } +} diff --git a/src/horario_list.vala b/src/horario_list.vala new file mode 100644 index 0000000..4debdc7 --- /dev/null +++ b/src/horario_list.vala @@ -0,0 +1,339 @@ +/* + * Copyright 2019 Chris Cromer + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace Colegio { + using Constants; + using Misc; + using DB; + using DB.Wrapper; + using Postgres; + + [GtkTemplate (ui = "/cl/cromer/ubb/colegio/horario.list.ui")] + public class HorarioList : Gtk.ApplicationWindow { + private Connection conn; + private enum Column { + ASIGNATURA, + BLOQUE, + SALA, + HORARIO, + N_COLUMNS + } + private Gtk.ListStore list_store; + private List horario_list; + + [GtkChild] + private Gtk.TreeView horario_tree; + + [GtkChild] + private Gtk.Button new_horario; + + [GtkChild] + private Gtk.Button edit_horario; + + [GtkChild] + private Gtk.Button delete_horario; + + [GtkChild] + private Gtk.Button close_horario; + + [GtkChild] + private Gtk.TreeViewColumn asignatura; + + [GtkChild] + private Gtk.TreeViewColumn bloque; + + [GtkChild] + private Gtk.TreeViewColumn sala; + + [GtkChild] + private Gtk.TreeSelection selection; + + public HorarioList (Gtk.Application application, Connection conn) { + Object (application: application); + this.conn = conn; + + this.set_visible (true); // This fixes: Gtk-CRITICAL **: 23:58:22.139: gtk_box_gadget_distribute: assertion 'size >= 0' failed in GtkScrollbar + } + + [GtkCallback] + public void on_clicked_button (Gtk.Button button) { + if (button == close_horario) { + this.close (); + } + if (button == new_horario) { + var horario_editor = new HorarioEditor (application, conn, null); + horario_editor.set_transient_for (this); // Set this window as the parent of the new window + horario_editor.initialize (); + horario_editor.show_all (); + horario_editor.save_horario.connect (on_save); + } + else if (button == edit_horario) { + Gtk.TreeModel model; + var path = selection.get_selected_rows (out model); + path.foreach ((entry) => { + var tree_row_reference = new Gtk.TreeRowReference (model, entry); + Gtk.TreeIter iter; + list_store.get_iter (out iter, tree_row_reference.get_path ()); + Horario horario; + model.get (iter, + Column.HORARIO, out horario); + var horario_editor = new HorarioEditor (application, conn, horario); + horario_editor.set_transient_for (this); // Set this window as the parent of the new window + horario_editor.initialize (); + horario_editor.show_all (); + horario_editor.save_horario.connect (on_save); + }); + } + else if (button == delete_horario) { + Gtk.MessageDialog msg; + if (selection.count_selected_rows () == 1) { + msg = new Gtk.MessageDialog (this, + Gtk.DialogFlags.MODAL, + Gtk.MessageType.ERROR, + Gtk.ButtonsType.YES_NO, + "¿Está seguro que quiere eliminar este horario?"); + } + else { + msg = new Gtk.MessageDialog (this, + Gtk.DialogFlags.MODAL, + Gtk.MessageType.ERROR, + Gtk.ButtonsType.YES_NO, + "¿Está seguro que quiere eliminar estos horarios?"); + } + msg.response.connect ((response_id) => { + switch (response_id) { + case Gtk.ResponseType.YES: + Gtk.TreeModel model; + var path = selection.get_selected_rows (out model); + path.foreach ((entry) => { + var tree_row_reference = new Gtk.TreeRowReference (model, entry); + Gtk.TreeIter iter; + list_store.get_iter (out iter, tree_row_reference.get_path ()); + Horario horario; + model.get (iter, + Column.HORARIO, out horario); + var res = conn.db.exec (" +DELETE FROM horario +WHERE id_asignatura = " + horario.asignatura.id_asignatura.to_string () + " AND +id_bloque = " + horario.bloque.id_bloque.to_string ()); + if (res.get_status () != ExecStatus.COMMAND_OK) { + #if DEBUG + error (conn.db.get_error_message ()); + #else + warning (conn.db.get_error_message ()); + #endif + } + }); + edit_horario.sensitive = false; + delete_horario.sensitive = false; + reset_columns (); + + list_store.clear (); + + update_list_store (); + break; + } + msg.destroy (); + }); + msg.show (); + } + } + + [GtkCallback] + private void on_changed_selection(Gtk.TreeSelection selection) { + if (selection.count_selected_rows () == 1) { + edit_horario.sensitive = true; + delete_horario.sensitive =true; + } + else if (selection.count_selected_rows () > 1) { + edit_horario.sensitive = false; + delete_horario.sensitive = true; + } + else { + edit_horario.sensitive = false; + delete_horario.sensitive = false; + } + } + + [GtkCallback] + private void on_clicked_column (Gtk.TreeViewColumn column) { + edit_horario.sensitive = false; + delete_horario.sensitive = false; + if (column == asignatura) { + if (!asignatura.sort_indicator) { + reset_columns (); + asignatura.sort_indicator = true; + } + + if (asignatura.sort_order == Gtk.SortType.ASCENDING) { + asignatura.sort_order = Gtk.SortType.DESCENDING; + } + else { + asignatura.sort_order = Gtk.SortType.ASCENDING; + } + + horario_list.sort_with_data ((a, b) => { + if (asignatura.sort_order == Gtk.SortType.ASCENDING) { + return strcmp (a.asignatura.nombre, b.asignatura.nombre); + } + else { + return strcmp (b.asignatura.nombre, a.asignatura.nombre); + } + }); + } + else if (column == bloque) { + if (!bloque.sort_indicator) { + reset_columns (); + bloque.sort_indicator = true; + } + + if (bloque.sort_order == Gtk.SortType.ASCENDING) { + bloque.sort_order = Gtk.SortType.DESCENDING; + } + else { + bloque.sort_order = Gtk.SortType.ASCENDING; + } + + horario_list.sort_with_data ((a, b) => { + if (bloque.sort_order == Gtk.SortType.ASCENDING) { + return strcmp (a.bloque.descripcion, b.bloque.descripcion); + } + else { + return strcmp (b.bloque.descripcion, a.bloque.descripcion); + } + }); + } + else if (column == sala) { + if (!sala.sort_indicator) { + reset_columns (); + sala.sort_indicator = true; + } + + if (sala.sort_order == Gtk.SortType.ASCENDING) { + sala.sort_order = Gtk.SortType.DESCENDING; + } + else { + sala.sort_order = Gtk.SortType.ASCENDING; + } + + horario_list.sort_with_data ((a, b) => { + if (sala.sort_order == Gtk.SortType.ASCENDING) { + return strcmp (a.sala, b.sala); + } + else { + return strcmp (b.sala, a.sala); + } + }); + } + + list_store.clear (); + horario_list.foreach ((entry) => { + Gtk.TreeIter iter; + list_store.append (out iter); + list_store.set (iter, + Column.ASIGNATURA, entry.asignatura.nombre, + Column.BLOQUE, entry.bloque.descripcion, + Column.SALA, entry.sala, + Column.HORARIO, entry); + }); + } + + private void reset_columns () { + asignatura.sort_indicator = false; + asignatura.sort_order = Gtk.SortType.DESCENDING; + bloque.sort_indicator = false; + bloque.sort_order = Gtk.SortType.DESCENDING; + sala.sort_indicator = false; + sala.sort_order = Gtk.SortType.DESCENDING; + } + + public void on_save(HorarioEditor horario_editor) { + edit_horario.sensitive = false; + delete_horario.sensitive = false; + reset_columns (); + + list_store.clear (); + + update_list_store (); + } + + private void update_list_store () { + var res = conn.db.exec (" +SELECT H.sala, + A.id_asignatura, A.nombre, + B.id_bloque, B.descripcion +FROM horario H +JOIN asignatura A on (A.id_asignatura = H.id_asignatura) +JOIN bloque B on (B.id_bloque = H.id_bloque) + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.db.get_error_message ()); + #else + warning (conn.db.get_error_message ()); + #endif + } + else { + var wra = new ResultWrapper (res); + horario_list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var result = new Horario ( + new Asignatura ( + wra.get_int_n (i, "id_asignatura"), + wra.get_string_n (i, "nombre") + ), + new Bloque ( + wra.get_int_n (i, "id_bloque"), + wra.get_string_n (i, "descripcion") + ), + wra.get_string_n (i, "sala") + ); + horario_list.append (result); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + + horario_list.foreach ((entry) => { + Gtk.TreeIter iter; + list_store.append (out iter); + list_store.set (iter, + Column.ASIGNATURA, entry.asignatura.nombre, + Column.BLOQUE, entry.bloque.descripcion, + Column.SALA, entry.sala, + Column.HORARIO, entry); + }); + } + } + + public void initialize () { + list_store = new Gtk.ListStore (Column.N_COLUMNS, + typeof (string), + typeof (string), + typeof (string), + typeof (Horario)); + + update_list_store (); + + horario_tree.set_model (list_store); + } + } +} diff --git a/src/main_window.vala b/src/main_window.vala index cd9df08..3f89979 100644 --- a/src/main_window.vala +++ b/src/main_window.vala @@ -27,6 +27,9 @@ namespace Colegio { [GtkChild] private Gtk.MenuItem asignaturas; + [GtkChild] + private Gtk.MenuItem horarios; + [GtkChild] private Gtk.MenuItem q1; @@ -61,6 +64,12 @@ namespace Colegio { asignatura_window.initialize (); asignatura_window.show_all (); } + else if (menu_item == horarios) { + var horarios_window = new HorarioList (application, conn); + horarios_window.set_transient_for (this); // Set this window as the parent of the new window + horarios_window.initialize (); + horarios_window.show_all (); + } else if (menu_item == q1) { var query_window = new QueryWindow (application, conn, QueryWindow.Query.Q1); query_window.set_transient_for (this); // Set this window as the parent of the new window diff --git a/src/meson.build b/src/meson.build index 04002db..84ae1b2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -19,12 +19,16 @@ vala_sources = files( 'colegio.vala', 'db.vala', 'dbwrapper.vala', + 'horario_editor.vala', + 'horario_list.vala', 'misc.vala', 'main_window.vala', 'queries.vala', 'query_window.vala', 'db/asignatura.vala', + 'db/bloque.vala', 'db/ciudad.vala', + 'db/horario.vala', 'db/profesor.vala', 'db/q1.vala', 'db/q2.vala', @@ -37,6 +41,7 @@ vala_sources = files( sources = vala_sources sources += main_gresource sources += asignatura_gresource +sources += horario_gresource sources += query_gresource sources += config_data_file