add asignatura list

This commit is contained in:
Chris Cromer 2019-07-16 10:40:44 -04:00
parent dd99fe116b
commit cfd4e9ccff
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
12 changed files with 919 additions and 39 deletions

View File

@ -0,0 +1,370 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1
Copyright 2018-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.
-->
<interface domain="sernatur">
<requires lib="gtk+" version="3.20"/>
<object class="GtkAdjustment" id="minimum_people_adjustment">
<property name="lower">1</property>
<property name="upper">1000</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<template class="SernaturTourEditor" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="type">popup</property>
<property name="title" translatable="yes">Tour Editor</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="skip_pager_hint">True</property>
<property name="show_menubar">False</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Tour Name</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="tour_name">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="hexpand">True</property>
<property name="max_length">50</property>
<property name="caps_lock_warning">False</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Individual Cost</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Group Cost</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Minimum People</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Region</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="indiv_cost">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="hexpand">True</property>
<property name="max_length">10</property>
<property name="caps_lock_warning">False</property>
<property name="input_purpose">number</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="group_cost">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="hexpand">True</property>
<property name="max_length">10</property>
<property name="caps_lock_warning">False</property>
<property name="input_purpose">number</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">City</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="minimum_people">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="hexpand">True</property>
<property name="max_length">4</property>
<property name="width_chars">4</property>
<property name="caps_lock_warning">False</property>
<property name="input_purpose">digits</property>
<property name="adjustment">minimum_people_adjustment</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="update_policy">if-valid</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="region">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="hexpand">True</property>
<property name="has_entry">True</property>
<property name="popup_fixed_width">False</property>
<signal name="changed" handler="on_changed_combobox" swapped="no"/>
<child internal-child="entry">
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Create a new region by typing here.</property>
<property name="hexpand">True</property>
<property name="max_length">50</property>
<property name="caps_lock_warning">False</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="city">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="hexpand">True</property>
<property name="has_entry">True</property>
<property name="popup_fixed_width">False</property>
<child internal-child="entry">
<object class="GtkEntry" id="city_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Create a new city by typing here.</property>
<property name="hexpand">True</property>
<property name="max_length">50</property>
<property name="caps_lock_warning">False</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="hexpand">True</property>
<property name="spacing">25</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton" id="cancel">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Cancel the modification of this tour.</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="places">
<property name="label" translatable="yes">Places</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Add or edit places.</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="vehicle">
<property name="label" translatable="yes">Vehicle</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Assign a vehicle to this tour.</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="save">
<property name="label" translatable="yes">Save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Save this tour.</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
<property name="width">2</property>
</packing>
</child>
</object>
</child>
</template>
</interface>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<gresources>
<gresource prefix="/cl/cromer/ubb/colegio">
<file preprocess="xml-stripblanks">asignatura.list.ui</file>
<file preprocess="xml-stripblanks">asignatura.editor.ui</file>
</gresource>
</gresources>

179
data/ui/asignatura.list.ui Normal file
View File

@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1
Copyright 2018-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.
-->
<interface domain="sernatur">
<requires lib="gtk+" version="3.20"/>
<object class="GtkListStore" id="liststore1"/>
<template class="ColegioAsignaturaList" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="type">popup</property>
<property name="title">Asignatura</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="default_height">240</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="skip_pager_hint">True</property>
<property name="show_menubar">False</property>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="asignatura_tree">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="hscroll_policy">natural</property>
<property name="vscroll_policy">natural</property>
<property name="model">liststore1</property>
<property name="fixed_height_mode">True</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="selection">
<property name="mode">multiple</property>
<signal name="changed" handler="on_changed_selection" swapped="no"/>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="asignatura_name">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Nombre de Asignatura</property>
<property name="clickable">True</property>
<signal name="clicked" handler="on_clicked_column" swapped="no"/>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="teacher">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Profesor</property>
<property name="clickable">True</property>
<signal name="clicked" handler="on_clicked_column" swapped="no"/>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="hexpand">True</property>
<property name="column_spacing">25</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkButton" id="edit_asignatura">
<property name="label" translatable="yes">Edit</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Edit selected tour.</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="new_asignatura">
<property name="label" translatable="yes">New</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Create a new tour.</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="delete_asignatura">
<property name="label" translatable="yes">Delete</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Delete selected tour.</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="close_asignatura">
<property name="label" translatable="yes">Close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Close this window.</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
</child>
</template>
</interface>

View File

@ -5,6 +5,12 @@ main_gresource = gnome.compile_resources('main_gresource',
c_name: meson.project_name() + '_resource_main', c_name: meson.project_name() + '_resource_main',
export: true, export: true,
install_header: true) install_header: true)
asignatura_gresource = gnome.compile_resources('asignatura_gresource',
'asignatura.gresource.xml',
source_dir: '.',
c_name: meson.project_name() + '_resource_asignatura',
export: true,
install_header: true)
query_gresource = gnome.compile_resources('query_gresource', query_gresource = gnome.compile_resources('query_gresource',
'query.gresource.xml', 'query.gresource.xml',
source_dir: '.', source_dir: '.',

274
src/asignatura_list.vala Normal file
View File

@ -0,0 +1,274 @@
/*
* 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/asignatura.list.ui")]
public class AsignaturaList : Gtk.ApplicationWindow {
private Connection conn;
private enum Column {
NAME,
PROFESOR,
ASIGNATURA,
N_COLUMNS
}
private Gtk.ListStore list_store;
private List<Asignatura> asignatura_list;
[GtkChild]
private Gtk.TreeView asignatura_tree;
[GtkChild]
private Gtk.Button edit_asignatura;
[GtkChild]
private Gtk.Button delete_asignatura;
[GtkChild]
private Gtk.Button close_asignatura;
[GtkChild]
private Gtk.TreeViewColumn asignatura_name;
[GtkChild]
private Gtk.TreeViewColumn teacher;
[GtkChild]
private Gtk.TreeSelection selection;
[GtkCallback]
public void on_clicked_button (Gtk.Button button) {
if (button == close_asignatura) {
this.close ();
}
else if (button == delete_asignatura) {
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 esta asignatura?");
}
else {
msg = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.YES_NO,
"¿Está seguro que quiere eliminar estas asignaturas?");
}
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 ());
Asignatura asignatura;
model.get (iter,
Column.ASIGNATURA, out asignatura);
var res = conn.db.exec ("
DELETE FROM asignatura
WHERE id_asignatura = " + asignatura.id_asignatura.to_string ());
if (res.get_status () != ExecStatus.COMMAND_OK) {
if (res.get_error_field (FieldCode.SQLSTATE) == "23503") {
warning (res.get_error_field (FieldCode.MESSAGE_PRIMARY));
var msg2 = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE,
"Error: No se puede eleminar la asignatura \"%s\" porque todavia está asociado a cursos, alumnos y actividades!", asignatura.nombre);
msg2.response.connect ((response_id) => {
msg2.destroy ();
});
msg2.set_title ("Error");
msg2.run ();
}
}
});
edit_asignatura.sensitive = false;
delete_asignatura.sensitive = false;
reset_columns ();
list_store.clear ();
update_list_store ();
break;
}
msg.destroy ();
});
msg.show ();
}
}
public AsignaturaList (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]
private void on_changed_selection(Gtk.TreeSelection selection) {
if (selection.count_selected_rows () == 1) {
edit_asignatura.sensitive = true;
delete_asignatura.sensitive =true;
}
else if (selection.count_selected_rows () > 1) {
edit_asignatura.sensitive = false;
delete_asignatura.sensitive = true;
}
else {
edit_asignatura.sensitive = false;
delete_asignatura.sensitive = false;
}
}
[GtkCallback]
private void on_clicked_column (Gtk.TreeViewColumn column) {
edit_asignatura.sensitive = false;
delete_asignatura.sensitive = false;
if (column == asignatura_name) {
if (!asignatura_name.sort_indicator) {
reset_columns ();
asignatura_name.sort_indicator = true;
}
if (asignatura_name.sort_order == Gtk.SortType.ASCENDING) {
asignatura_name.sort_order = Gtk.SortType.DESCENDING;
}
else {
asignatura_name.sort_order = Gtk.SortType.ASCENDING;
}
asignatura_list.sort_with_data ((a, b) => {
if (asignatura_name.sort_order == Gtk.SortType.ASCENDING) {
return strcmp (a.nombre, b.nombre);
}
else {
return strcmp (b.nombre, a.nombre);
}
});
}
else if (column == teacher) {
if (!teacher.sort_indicator) {
reset_columns ();
teacher.sort_indicator = true;
}
if (teacher.sort_order == Gtk.SortType.ASCENDING) {
teacher.sort_order = Gtk.SortType.DESCENDING;
}
else {
teacher.sort_order = Gtk.SortType.ASCENDING;
}
asignatura_list.sort_with_data ((a, b) => {
if (teacher.sort_order == Gtk.SortType.ASCENDING) {
return strcmp (a.profesor.nombres, b.profesor.nombres);
}
else {
return strcmp (b.profesor.nombres, a.profesor.nombres);
}
});
}
list_store.clear ();
asignatura_list.foreach ((entry) => {
Gtk.TreeIter iter;
list_store.append (out iter);
list_store.set (iter,
Column.NAME, entry.nombre,
Column.PROFESOR, entry.profesor.nombres + " " + entry.profesor.apellidos,
Column.ASIGNATURA, entry);
});
}
private void reset_columns () {
asignatura_name.sort_indicator = false;
asignatura_name.sort_order = Gtk.SortType.DESCENDING;
teacher.sort_indicator = false;
teacher.sort_order = Gtk.SortType.DESCENDING;
}
private void update_list_store () {
var res = conn.db.exec ("
SELECT A.id_asignatura, A.nombre,
P.rut_profesor, P.nombres, P.apellidos
FROM asignatura A
JOIN profesor P ON (P.rut_profesor = A.rut_profesor)
");
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);
asignatura_list = new List<Asignatura> ();
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"),
new Profesor (
wra.get_string_n (i, "rut_profesor"),
wra.get_string_n (i, "nombres"),
wra.get_string_n (i, "apellidos")
)
);
asignatura_list.append (result);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
asignatura_list.foreach ((entry) => {
Gtk.TreeIter iter;
list_store.append (out iter);
list_store.set (iter,
Column.NAME, entry.nombre,
Column.PROFESOR, entry.profesor.nombres + " " + entry.profesor.apellidos,
Column.ASIGNATURA, entry);
});
}
}
public void initialize () {
list_store = new Gtk.ListStore (Column.N_COLUMNS,
typeof (string),
typeof (string),
typeof (Asignatura));
update_list_store ();
asignatura_tree.set_model (list_store);
}
}
}

View File

@ -1,36 +0,0 @@
/*
* 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/query.window.ui")]
public class AsignaturaWindow : Gtk.ApplicationWindow {
private Connection conn;
public AsignaturaWindow (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
}
public void initialize () {
}
}
}

15
src/db/asignatura.vala Normal file
View File

@ -0,0 +1,15 @@
namespace Colegio {
namespace DB {
public class Asignatura : Object {
public int id_asignatura { get; set; default = 0; }
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()) {
this.id_asignatura = id_asignatura;
this.nombre = nombre;
this.profesor = profesor;
}
}
}
}

15
src/db/ciudad.vala Normal file
View File

@ -0,0 +1,15 @@
namespace Colegio {
namespace DB {
public class Ciudad : Object {
public int id_ciudad { get; set; default = 0; }
public string nombre_ciudad { get; set; default = ""; }
public Region region { get; set; default = new Region(); }
public Ciudad (int id_ciudad = 0, string nombre_ciudad = "", Region region = new Region()) {
this.id_ciudad = id_ciudad;
this.nombre_ciudad = nombre_ciudad;
this.region = region;
}
}
}
}

19
src/db/profesor.vala Normal file
View File

@ -0,0 +1,19 @@
namespace Colegio {
namespace DB {
public class Profesor : Object {
public string rut_profesor { get; set; default = ""; }
public string nombres { get; set; default = ""; }
public string apellidos { get; set; default = ""; }
public string direcion { get; set; default = ""; }
public Ciudad ciudad { get; set; default = new Ciudad(); }
public Profesor (string rut_profesor = "", string nombres = "", string apellidos = "", string direcion = "", Ciudad ciudad = new Ciudad()) {
this.rut_profesor = rut_profesor;
this.nombres = nombres;
this.apellidos = apellidos;
this.direcion = direcion;
this.ciudad = ciudad;
}
}
}
}

13
src/db/region.vala Normal file
View File

@ -0,0 +1,13 @@
namespace Colegio {
namespace DB {
public class Region : Object {
public int id_region { get; set; default = 0; }
public string nombre_region { get; set; default = ""; }
public Region (int id_region = 0, string nombre_region = "") {
this.id_region = id_region;
this.nombre_region = nombre_region;
}
}
}
}

View File

@ -56,7 +56,7 @@ namespace Colegio {
[GtkCallback] [GtkCallback]
private void on_activate_menu(Gtk.MenuItem menu_item) { private void on_activate_menu(Gtk.MenuItem menu_item) {
if (menu_item == asignaturas) { if (menu_item == asignaturas) {
var asignatura_window = new AsignaturaWindow (application, conn); var asignatura_window = new AsignaturaList (application, conn);
asignatura_window.set_transient_for (this); // Set this window as the parent of the new window asignatura_window.set_transient_for (this); // Set this window as the parent of the new window
asignatura_window.initialize (); asignatura_window.initialize ();
asignatura_window.show_all (); asignatura_window.show_all ();

View File

@ -14,7 +14,7 @@ config_data_file = configure_file(input: 'config.vala.in',
configuration: config_data) configuration: config_data)
vala_sources = files( vala_sources = files(
'asignatura_window.vala', 'asignatura_list.vala',
'colegio.vala', 'colegio.vala',
'db.vala', 'db.vala',
'dbwrapper.vala', 'dbwrapper.vala',
@ -22,15 +22,20 @@ vala_sources = files(
'main_window.vala', 'main_window.vala',
'queries.vala', 'queries.vala',
'query_window.vala', 'query_window.vala',
'db/asignatura.vala',
'db/ciudad.vala',
'db/profesor.vala',
'db/q1.vala', 'db/q1.vala',
'db/q2.vala', 'db/q2.vala',
'db/q3.vala', 'db/q3.vala',
'db/q4.vala', 'db/q4.vala',
'db/q5.vala', 'db/q5.vala',
'db/q6.vala') 'db/q6.vala',
'db/region.vala')
sources = vala_sources sources = vala_sources
sources += main_gresource sources += main_gresource
sources += asignatura_gresource
sources += query_gresource sources += query_gresource
sources += config_data_file sources += config_data_file