tourist and illness finished
This commit is contained in:
@@ -38,6 +38,11 @@ namespace Sernatur {
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.MenuItem tours;
|
||||
/**
|
||||
* The tourists menu item
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.MenuItem tourists;
|
||||
/**
|
||||
* The Q1 menu item
|
||||
*/
|
||||
@@ -130,6 +135,12 @@ namespace Sernatur {
|
||||
tour_list.initialize ();
|
||||
tour_list.show_all ();
|
||||
}
|
||||
if (menu_item == tourists) {
|
||||
var tourist_list = new TouristList (application, conn);
|
||||
tourist_list.set_transient_for (this); // Set this window as the parent of the new window
|
||||
tourist_list.initialize ();
|
||||
tourist_list.show_all ();
|
||||
}
|
||||
else if (menu_item == q1) {
|
||||
var query_window = new QueryWindow (application, conn, Query.Q1);
|
||||
query_window.set_transient_for (this); // Set this window as the parent of the new window
|
||||
|
@@ -21,6 +21,10 @@ vala_sources = files(
|
||||
'tour_places.vala',
|
||||
'tour_place_editor.vala',
|
||||
'tour_assign_vehicle.vala',
|
||||
'tourist_list.vala',
|
||||
'tourist_editor.vala',
|
||||
'tourist_illnesses.vala',
|
||||
'tourist_illness_editor.vala',
|
||||
'place_editor.vala',
|
||||
'queries.vala',
|
||||
'query_window.vala')
|
||||
@@ -28,6 +32,7 @@ vala_sources = files(
|
||||
sources = vala_sources
|
||||
sources += main_gresource
|
||||
sources += tour_gresource
|
||||
sources += tourist_gresource
|
||||
sources += place_gresource
|
||||
sources += query_gresource
|
||||
sources += config_data_file
|
||||
@@ -35,6 +40,7 @@ sources += config_data_file
|
||||
vala_args = ['--vapidir=' + join_paths(meson.source_root(), 'vapi')]
|
||||
vala_args += ['--gresources=' + join_paths(meson.source_root(), 'data/ui/main.gresource.xml')]
|
||||
vala_args += ['--gresources=' + join_paths(meson.source_root(), 'data/ui/tour.gresource.xml')]
|
||||
vala_args += ['--gresources=' + join_paths(meson.source_root(), 'data/ui/tourist.gresource.xml')]
|
||||
vala_args += ['--gresources=' + join_paths(meson.source_root(), 'data/ui/place.gresource.xml')]
|
||||
vala_args += ['--gresources=' + join_paths(meson.source_root(), 'data/ui/query.gresource.xml')]
|
||||
|
||||
|
@@ -17,7 +17,7 @@ namespace Sernatur {
|
||||
using LibSernatur.DB;
|
||||
|
||||
/**
|
||||
* The tour list window class
|
||||
* The tour place window class
|
||||
*/
|
||||
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/tour.places.ui")]
|
||||
public class TourPlaces : Gtk.ApplicationWindow {
|
||||
|
322
src/tourist_editor.vala
Normal file
322
src/tourist_editor.vala
Normal file
@@ -0,0 +1,322 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace Sernatur {
|
||||
using LibSernatur.DB;
|
||||
using LibSernatur.Misc;
|
||||
|
||||
/**
|
||||
* The tourist editor window class
|
||||
*/
|
||||
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/tourist.editor.ui")]
|
||||
public class TouristEditor : Gtk.ApplicationWindow {
|
||||
/**
|
||||
* The open database connection
|
||||
*/
|
||||
private Connection conn;
|
||||
/**
|
||||
* The tourist to edit
|
||||
*/
|
||||
private Turista tourist;
|
||||
/**
|
||||
* The tourist run
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Entry run;
|
||||
/**
|
||||
* The tourist name
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Entry tourist_name;
|
||||
/**
|
||||
* The birth year
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.SpinButton year;
|
||||
/**
|
||||
* The birth day
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.SpinButton day;
|
||||
/**
|
||||
* The birth month
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.ComboBoxText month;
|
||||
/**
|
||||
* The save button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button save;
|
||||
/**
|
||||
* The illnesses button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button illnesses;
|
||||
/**
|
||||
* The cancel button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button cancel;
|
||||
/**
|
||||
* A list of associated places, this is only used in the case of a new tourist
|
||||
*/
|
||||
//private List<Asociado> list_asociado = null;
|
||||
/**
|
||||
* A saved copy of the original RUN
|
||||
*/
|
||||
private string original_run;
|
||||
/**
|
||||
* This signal is called when a tourist is saved
|
||||
*/
|
||||
public signal void save_tourist ();
|
||||
|
||||
/**
|
||||
* Validate the tourist data before trying to insert it into the database
|
||||
* @return Returns true if the data is valid
|
||||
*/
|
||||
private bool validate_tourist_data () {
|
||||
if (tourist.nombre_turista.strip () == "") {
|
||||
var msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.CLOSE,
|
||||
_ ("Error: Tourist name cannot be left blank!"));
|
||||
msg.response.connect ((response_id) => {
|
||||
msg.destroy ();
|
||||
});
|
||||
msg.set_title (_ ("Error"));
|
||||
msg.run ();
|
||||
return false;
|
||||
}
|
||||
if (tourist.rut_turista.strip () == "") {
|
||||
var msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.CLOSE,
|
||||
_ ("Error: Tourist RUN cannot be left blank!"));
|
||||
msg.response.connect ((response_id) => {
|
||||
msg.destroy ();
|
||||
});
|
||||
msg.set_title (_ ("Error"));
|
||||
msg.run ();
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
new Rut (tourist.rut_turista.strip ());
|
||||
}
|
||||
catch (Error e) {
|
||||
var msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.CLOSE,
|
||||
_ ("Error: The RUN entered is invalid!"));
|
||||
msg.response.connect ((response_id) => {
|
||||
msg.destroy ();
|
||||
});
|
||||
msg.set_title (_ ("Error"));
|
||||
msg.run ();
|
||||
return false;
|
||||
}
|
||||
if (tourist_exists () && tourist.rut_turista != original_run) {
|
||||
var msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.CLOSE,
|
||||
_ ("Error: A tourist with the RUN \"%s\" already exists!"), tourist.rut_turista);
|
||||
msg.response.connect ((response_id) => {
|
||||
msg.destroy ();
|
||||
});
|
||||
msg.set_title (_ ("Error"));
|
||||
msg.run ();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool tourist_exists () {
|
||||
try {
|
||||
tourist.rut_turista = new Rut (run.get_text ().strip ()).get_clean_rut ();
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
try {
|
||||
Turista turista = Turista.get_turista_by_run (conn, tourist.rut_turista);
|
||||
if (turista == null) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback is called when a button is clicked
|
||||
* @param button The button that was clicked
|
||||
*/
|
||||
[GtkCallback]
|
||||
public void on_clicked_button (Gtk.Button button) {
|
||||
if (button == save) {
|
||||
if (update_tourist_instance () && validate_tourist_data ()) {
|
||||
if (!tourist_exists () && original_run == null) {
|
||||
try {
|
||||
Turista.insert_tourist (conn, tourist);
|
||||
/*if (list_asociado != null) {
|
||||
// Not enough time
|
||||
// Insert all the pending illnesses
|
||||
list_asociado.foreach ((entry) => {
|
||||
try {
|
||||
//Asociado.insert_asociado (conn, entry);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
});
|
||||
}*/
|
||||
save_tourist (); // Signal the parent to update itself
|
||||
this.close ();
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Turista.update_tourist (conn, tourist, original_run);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
finally {
|
||||
save_tourist (); // Signal the parent to update itself
|
||||
this.close ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (button == illnesses) {
|
||||
var tourist_illnesses = new TouristIllnesses (application, conn, tourist);
|
||||
tourist_illnesses.set_transient_for (this); // Set this window as the parent of the new window
|
||||
tourist_illnesses.initialize ();
|
||||
tourist_illnesses.show_all ();
|
||||
//tourist_illnesses.save_places.connect (on_save_places);
|
||||
}
|
||||
else if (button == cancel) {
|
||||
this.close ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when some associated places are saved and a tourist id doesn't exist yet
|
||||
* @param tourist_places The TouristPlaces instance that called this signal
|
||||
* @param list_asociado The list of new associations
|
||||
*/
|
||||
/*private void on_save_places (TouristPlaces tourist_places, List<Asociado> list_asociado) {
|
||||
this.list_asociado = list_asociado.copy ();
|
||||
places.sensitive = false;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Called when a vehcile is assigned to the tourist, and the tourist is not in the database yet
|
||||
* @param tourist_assign_vehicle The TouristAssignVehicle instance that called this signal
|
||||
* @param requerir_auto The vehicle to assign to this tourist
|
||||
*/
|
||||
/*private void on_save_vehicle (TouristAssignVehicle tourist_assign_vehicle, RequerirAuto? requerir_auto) {
|
||||
if (requerir_auto != null) {
|
||||
this.requerir_auto = requerir_auto;
|
||||
vehicle.sensitive = false;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Update the the tourist object with new info from the editor
|
||||
* @return Returns false if the information is not valid
|
||||
*/
|
||||
private bool update_tourist_instance () {
|
||||
tourist.rut_turista = run.get_text ().strip ();
|
||||
tourist.nombre_turista = tourist_name.get_text ().strip ();
|
||||
tourist.fecha_nacimento = year.get_value ().to_string () + "-" +
|
||||
(month.get_active () + 1).to_string () + "-" +
|
||||
day.get_value ().to_string ();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the tourist editor class
|
||||
* @param application The application used to make the GLib object
|
||||
* @param conn The database connection to use
|
||||
* @param tourist The tourist to edit
|
||||
*/
|
||||
public TouristEditor (Gtk.Application application, Connection conn, Turista? tourist) {
|
||||
Object (application: application);
|
||||
this.conn = conn;
|
||||
this.tourist = tourist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize what is needed for this window
|
||||
*/
|
||||
public void initialize () {
|
||||
if (tourist != null) {
|
||||
original_run = tourist.rut_turista;
|
||||
try {
|
||||
run.set_text (new Rut (tourist.rut_turista).get_rut ());
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
tourist_name.set_text (tourist.nombre_turista);
|
||||
|
||||
string[] birth_date = tourist.fecha_nacimento.split ("-", 3);
|
||||
year.set_value (double.parse (birth_date[0]));
|
||||
month.set_active (int.parse (birth_date[1]) - 1);
|
||||
day.set_value (double.parse (birth_date[2]));
|
||||
}
|
||||
else {
|
||||
illnesses.destroy ();
|
||||
tourist = new Turista ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
180
src/tourist_illness_editor.vala
Normal file
180
src/tourist_illness_editor.vala
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace Sernatur {
|
||||
using LibSernatur.DB;
|
||||
|
||||
/**
|
||||
* The tourist add illness window class
|
||||
*/
|
||||
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/tourist.illness.editor.ui")]
|
||||
public class TouristIllnessEditor : Gtk.ApplicationWindow {
|
||||
/**
|
||||
* The open database connection
|
||||
*/
|
||||
private Connection conn;
|
||||
/**
|
||||
* The place data stored in the list store
|
||||
*/
|
||||
private enum Column {
|
||||
/**
|
||||
* The illness description
|
||||
*/
|
||||
ILLNESS_DESCRIPTION,
|
||||
/**
|
||||
* The illness object
|
||||
*/
|
||||
ILLNESS,
|
||||
/**
|
||||
* The number of colums in this enum
|
||||
*/
|
||||
N_COLUMNS
|
||||
}
|
||||
/**
|
||||
* The add illness button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button add_illness;
|
||||
/**
|
||||
* The close button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button close_illness;
|
||||
/**
|
||||
* The illness
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.ComboBoxText illness;
|
||||
/**
|
||||
* A list of the illnesses from the database
|
||||
*/
|
||||
private List<Enfermedad> illnesses;
|
||||
/**
|
||||
* The list that stores the illnesses for the combo box
|
||||
*/
|
||||
private Gtk.ListStore illness_list_store;
|
||||
/**
|
||||
* This signal is called when an illness is saved
|
||||
*/
|
||||
public signal void save_illness ();
|
||||
/**
|
||||
* The illness to be added
|
||||
*/
|
||||
private TieneEnfermedad tiene_enfermedad;
|
||||
|
||||
/**
|
||||
* This callback is called when a button is clicked
|
||||
* @param button The button that was clicked
|
||||
*/
|
||||
[GtkCallback]
|
||||
public void on_clicked_button (Gtk.Button button) {
|
||||
if (button == add_illness) {
|
||||
// Insert is all that is needed
|
||||
update_illness_instance ();
|
||||
try {
|
||||
TieneEnfermedad.insert_illness (conn, tiene_enfermedad);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
save_illness (); // Signal the parent to update itself
|
||||
this.close ();
|
||||
}
|
||||
else if (button == close_illness) {
|
||||
this.close ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the the illness object with new info from the editor
|
||||
*/
|
||||
private void update_illness_instance () {
|
||||
Enfermedad enfermedad;
|
||||
Gtk.TreeIter iter;
|
||||
illness.get_active_iter (out iter);
|
||||
illness_list_store.get (iter,
|
||||
Column.ILLNESS, out enfermedad);
|
||||
tiene_enfermedad.enfermedad = enfermedad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the tour illness editor class
|
||||
* @param application The application used to make the GLib object
|
||||
* @param conn The database connection to use
|
||||
* @param tiene_enfermedad The place to edit
|
||||
*/
|
||||
public TouristIllnessEditor (Gtk.Application application, Connection conn, TieneEnfermedad tiene_enfermedad) {
|
||||
Object (application: application);
|
||||
this.conn = conn;
|
||||
this.tiene_enfermedad = tiene_enfermedad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize what is needed for this window
|
||||
*/
|
||||
public void initialize () {
|
||||
try {
|
||||
illnesses = Enfermedad.get_all_enfermedades (conn);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
|
||||
illnesses.sort_with_data ((a, b) => {
|
||||
return strcmp (a.descripcion_enfermedad, b.descripcion_enfermedad);
|
||||
});
|
||||
|
||||
illness_list_store = new Gtk.ListStore (Column.N_COLUMNS,
|
||||
typeof (string),
|
||||
typeof (Enfermedad));
|
||||
|
||||
illness.set_model (illness_list_store);
|
||||
|
||||
try {
|
||||
var has_illness_list = TieneEnfermedad.get_all_tiene_enfermedades_by_run (conn, tiene_enfermedad.turista.rut_turista);
|
||||
illnesses.foreach ((entry) => {
|
||||
var can_add = true;
|
||||
has_illness_list.foreach ((entry2) => {
|
||||
if (entry.id_enfermedad == entry2.enfermedad.id_enfermedad) {
|
||||
can_add = false;
|
||||
}
|
||||
});
|
||||
if (can_add) {
|
||||
Gtk.TreeIter iter;
|
||||
illness_list_store.append (out iter);
|
||||
illness_list_store.set (iter,
|
||||
Column.ILLNESS_DESCRIPTION, entry.descripcion_enfermedad,
|
||||
Column.ILLNESS, entry);
|
||||
}
|
||||
});
|
||||
illness.set_active (0);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
297
src/tourist_illnesses.vala
Normal file
297
src/tourist_illnesses.vala
Normal file
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace Sernatur {
|
||||
using LibSernatur.Misc;
|
||||
using LibSernatur.DB;
|
||||
|
||||
/**
|
||||
* The tourist illness window class
|
||||
*/
|
||||
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/tourist.illnesses.ui")]
|
||||
public class TouristIllnesses : Gtk.ApplicationWindow {
|
||||
/**
|
||||
* The open database connection
|
||||
*/
|
||||
private Connection conn;
|
||||
/**
|
||||
* The tourist to edit
|
||||
*/
|
||||
private Turista tourist;
|
||||
/**
|
||||
* The columns of the tree view
|
||||
*/
|
||||
private enum Column {
|
||||
/**
|
||||
* The illness description
|
||||
*/
|
||||
ILLNESS_DESCRIPTION,
|
||||
/**
|
||||
* The illness object
|
||||
*/
|
||||
ILLNESS,
|
||||
/**
|
||||
* The number of colums in this enum
|
||||
*/
|
||||
N_COLUMNS
|
||||
}
|
||||
/**
|
||||
* The list that stores the contents in the tree view
|
||||
*/
|
||||
private Gtk.ListStore list_store;
|
||||
/**
|
||||
* The list of illnesses
|
||||
*/
|
||||
private List<TieneEnfermedad> illness_list;
|
||||
/**
|
||||
* The tree view widget
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.TreeView illness_tree;
|
||||
/**
|
||||
* The illness column
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.TreeViewColumn illness;
|
||||
/**
|
||||
* The add button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button add_illness;
|
||||
/**
|
||||
* The close button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button close_illness;
|
||||
/**
|
||||
* The delete button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button delete_illness;
|
||||
/**
|
||||
* The row selection
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.TreeSelection selection;
|
||||
/**
|
||||
* The associated tours to save if the user decides to save the tour
|
||||
*/
|
||||
private List<TieneEnfermedad> new_illness_list = new List<TieneEnfermedad> ();
|
||||
|
||||
/**
|
||||
* This callback is called when the user clicks on a row
|
||||
* @param selection The selection object
|
||||
*/
|
||||
[GtkCallback]
|
||||
private void on_changed_selection(Gtk.TreeSelection selection) {
|
||||
if (selection.count_selected_rows () == 1) {
|
||||
delete_illness.sensitive =true;
|
||||
}
|
||||
else if (selection.count_selected_rows () > 1) {
|
||||
delete_illness.sensitive = true;
|
||||
}
|
||||
else {
|
||||
delete_illness.sensitive = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback is run when the user clicks on a button
|
||||
* @param button The button that was clicked
|
||||
*/
|
||||
[GtkCallback]
|
||||
private void on_clicked_button (Gtk.Button button) {
|
||||
if (button == add_illness) {
|
||||
var illness_editor = new TouristIllnessEditor (application, conn, new TieneEnfermedad (tourist));
|
||||
illness_editor.set_transient_for (this); // Set this window as the parent of the new window
|
||||
illness_editor.initialize ();
|
||||
illness_editor.show_all ();
|
||||
illness_editor.save_illness.connect (on_save_tourist_illness);
|
||||
}
|
||||
else if (button == delete_illness) {
|
||||
Gtk.MessageDialog msg;
|
||||
if (selection.count_selected_rows () == 1) {
|
||||
msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.YES_NO,
|
||||
_ ("Are you sure you wish to delete this illness from this tourist?"));
|
||||
}
|
||||
else {
|
||||
msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.YES_NO,
|
||||
_ ("Are you sure you wish to delete these illnesses from this tourist?"));
|
||||
}
|
||||
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 ());
|
||||
TieneEnfermedad has_illness;
|
||||
model.get (iter,
|
||||
Column.ILLNESS, out has_illness);
|
||||
try {
|
||||
TieneEnfermedad.delete_illness (conn, has_illness);
|
||||
}
|
||||
catch (PostgresError e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
});
|
||||
delete_illness.sensitive = false;
|
||||
reset_columns ();
|
||||
|
||||
list_store.clear ();
|
||||
|
||||
update_list_store ();
|
||||
break;
|
||||
}
|
||||
msg.destroy ();
|
||||
});
|
||||
msg.show ();
|
||||
}
|
||||
else if (button == close_illness) {
|
||||
this.close ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback is run when the user clicks on a column to reorder the rows
|
||||
* @param column The column that was clicked
|
||||
*/
|
||||
[GtkCallback]
|
||||
private void on_clicked_column (Gtk.TreeViewColumn column) {
|
||||
delete_illness.sensitive = false;
|
||||
if (column == illness) {
|
||||
if (!illness.sort_indicator) {
|
||||
reset_columns ();
|
||||
illness.sort_indicator = true;
|
||||
}
|
||||
|
||||
if (illness.sort_order == Gtk.SortType.ASCENDING) {
|
||||
illness.sort_order = Gtk.SortType.DESCENDING;
|
||||
}
|
||||
else {
|
||||
illness.sort_order = Gtk.SortType.ASCENDING;
|
||||
}
|
||||
|
||||
illness_list.sort_with_data ((a, b) => {
|
||||
if (illness.sort_order == Gtk.SortType.ASCENDING) {
|
||||
return strcmp (a.enfermedad.descripcion_enfermedad, b.enfermedad.descripcion_enfermedad);
|
||||
}
|
||||
else {
|
||||
return strcmp (b.enfermedad.descripcion_enfermedad, a.enfermedad.descripcion_enfermedad);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
list_store.clear ();
|
||||
illness_list.foreach ((entry) => {
|
||||
Gtk.TreeIter iter;
|
||||
list_store.append (out iter);
|
||||
list_store.set (iter,
|
||||
Column.ILLNESS_DESCRIPTION, entry.enfermedad.descripcion_enfermedad,
|
||||
Column.ILLNESS, entry);
|
||||
});
|
||||
new_illness_list.foreach ((entry) => {
|
||||
Gtk.TreeIter iter;
|
||||
list_store.append (out iter);
|
||||
list_store.set (iter,
|
||||
Column.ILLNESS_DESCRIPTION, entry.enfermedad.descripcion_enfermedad,
|
||||
Column.ILLNESS, entry);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the sort indicator and order of all the columns
|
||||
*/
|
||||
private void reset_columns () {
|
||||
illness.sort_indicator = false;
|
||||
illness.sort_order = Gtk.SortType.DESCENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a illness is saved
|
||||
* @param illness_editor The editor that saved the illness
|
||||
*/
|
||||
public void on_save_tourist_illness (TouristIllnessEditor illness_editor) {
|
||||
reset_columns ();
|
||||
|
||||
list_store.clear ();
|
||||
update_list_store ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the list store with the data from the database
|
||||
*/
|
||||
private void update_list_store () {
|
||||
try {
|
||||
illness_list = TieneEnfermedad.get_all_tiene_enfermedades_by_run (conn, tourist.rut_turista);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
|
||||
illness_list.foreach ((entry) => {
|
||||
Gtk.TreeIter iter;
|
||||
list_store.append (out iter);
|
||||
list_store.set (iter,
|
||||
Column.ILLNESS_DESCRIPTION, entry.enfermedad.descripcion_enfermedad,
|
||||
Column.ILLNESS, entry);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the tour list class
|
||||
* @param application The application used to make the GLib object
|
||||
* @param conn The database connection to use
|
||||
* @param tourist The tourist which is the parent of this window
|
||||
*/
|
||||
public TouristIllnesses (Gtk.Application application, Connection conn, Turista? tourist) {
|
||||
Object (application: application);
|
||||
this.conn = conn;
|
||||
this.tourist = tourist;
|
||||
|
||||
this.set_visible (true); // This fixes: Gtk-CRITICAL **: 23:58:22.139: gtk_box_gadget_distribute: assertion 'size >= 0' failed in GtkScrollbar
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize what is needed for this window
|
||||
*/
|
||||
public void initialize () {
|
||||
list_store = new Gtk.ListStore (Column.N_COLUMNS,
|
||||
typeof (string),
|
||||
typeof (TieneEnfermedad));
|
||||
|
||||
if (tourist != null) {
|
||||
update_list_store ();
|
||||
}
|
||||
|
||||
illness_tree.set_model (list_store);
|
||||
}
|
||||
}
|
||||
}
|
420
src/tourist_list.vala
Normal file
420
src/tourist_list.vala
Normal file
@@ -0,0 +1,420 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace Sernatur {
|
||||
using LibSernatur.Misc;
|
||||
using LibSernatur.DB;
|
||||
|
||||
/**
|
||||
* The tourist list window class
|
||||
*/
|
||||
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/tourist.list.ui")]
|
||||
public class TouristList : Gtk.ApplicationWindow {
|
||||
/**
|
||||
* The open database connection
|
||||
*/
|
||||
private Connection conn;
|
||||
/**
|
||||
* The columns of the tree view
|
||||
*/
|
||||
private enum Column {
|
||||
/**
|
||||
* The tourist's run
|
||||
*/
|
||||
RUN,
|
||||
/**
|
||||
* The tourist's name
|
||||
*/
|
||||
NAME,
|
||||
/**
|
||||
* The tourist's birthdate
|
||||
*/
|
||||
BIRTHDATE,
|
||||
/**
|
||||
* The tourist object
|
||||
*/
|
||||
TOURIST,
|
||||
/**
|
||||
* The number of colums in this enum
|
||||
*/
|
||||
N_COLUMNS
|
||||
}
|
||||
/**
|
||||
* The list that stores the contents in the tree view
|
||||
*/
|
||||
private Gtk.ListStore list_store;
|
||||
/**
|
||||
* The list of tourists
|
||||
*/
|
||||
private List<Turista> tourist_list;
|
||||
/**
|
||||
* The tree view widget
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.TreeView tourist_tree;
|
||||
/**
|
||||
* Thew new tourist button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button new_tourist;
|
||||
/**
|
||||
* The edit tourist button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button edit_tourist;
|
||||
/**
|
||||
* The delete tourist button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button delete_tourist;
|
||||
/**
|
||||
* The close tourist button
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.Button close_tourist;
|
||||
/**
|
||||
* The tourist's RUN
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.TreeViewColumn run;
|
||||
/**
|
||||
* The tourist's name
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.TreeViewColumn tourist_name;
|
||||
/**
|
||||
* The birthdate
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.TreeViewColumn birthdate;
|
||||
/**
|
||||
* The row selection
|
||||
*/
|
||||
[GtkChild]
|
||||
private Gtk.TreeSelection selection;
|
||||
|
||||
/**
|
||||
* This callback is called when the user clicks on a row
|
||||
* @param selection The selection object
|
||||
*/
|
||||
[GtkCallback]
|
||||
private void on_changed_selection(Gtk.TreeSelection selection) {
|
||||
if (selection.count_selected_rows () == 1) {
|
||||
edit_tourist.sensitive = true;
|
||||
delete_tourist.sensitive =true;
|
||||
}
|
||||
else if (selection.count_selected_rows () > 1) {
|
||||
edit_tourist.sensitive = false;
|
||||
delete_tourist.sensitive = true;
|
||||
}
|
||||
else {
|
||||
edit_tourist.sensitive = false;
|
||||
delete_tourist.sensitive = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback is run when the user clicks on a button
|
||||
* @param button The button that was clicked
|
||||
*/
|
||||
[GtkCallback]
|
||||
private void on_clicked_button (Gtk.Button button) {
|
||||
if (button == new_tourist) {
|
||||
var tourist_editor = new TouristEditor (application, conn, null);
|
||||
tourist_editor.set_transient_for (this); // Set this window as the parent of the new window
|
||||
tourist_editor.initialize ();
|
||||
tourist_editor.show_all ();
|
||||
tourist_editor.save_tourist.connect (on_save);
|
||||
}
|
||||
else if (button == edit_tourist) {
|
||||
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 ());
|
||||
Turista tourist;
|
||||
model.get (iter,
|
||||
Column.TOURIST, out tourist);
|
||||
var tourist_editor = new TouristEditor (application, conn, tourist);
|
||||
tourist_editor.set_transient_for (this); // Set this window as the parent of the new window
|
||||
tourist_editor.initialize ();
|
||||
tourist_editor.show_all ();
|
||||
tourist_editor.save_tourist.connect (on_save);
|
||||
});
|
||||
}
|
||||
else if (button == delete_tourist) {
|
||||
Gtk.MessageDialog msg;
|
||||
if (selection.count_selected_rows () == 1) {
|
||||
msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.YES_NO,
|
||||
_ ("Are you sure you wish to delete this tourist?"));
|
||||
}
|
||||
else {
|
||||
msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.YES_NO,
|
||||
_ ("Are you sure you wish to delete these tourists?"));
|
||||
}
|
||||
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 ());
|
||||
Turista tourist;
|
||||
model.get (iter,
|
||||
Column.TOURIST, out tourist);
|
||||
try {
|
||||
Turista.delete_tourist (conn, tourist);
|
||||
}
|
||||
catch (PostgresError e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
catch (DBError e) {
|
||||
if (e.code == 1) {
|
||||
warning (e.message);
|
||||
var msg2 = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.CLOSE,
|
||||
_ ("Error: Could not delete tourist \"%s\" because there is still information associated with them!"), tourist.nombre_turista);
|
||||
msg2.response.connect ((response_id) => {
|
||||
msg2.destroy ();
|
||||
});
|
||||
msg2.set_title (_ ("Error"));
|
||||
msg2.run ();
|
||||
}
|
||||
else {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
});
|
||||
edit_tourist.sensitive = false;
|
||||
delete_tourist.sensitive = false;
|
||||
reset_columns ();
|
||||
|
||||
list_store.clear ();
|
||||
|
||||
update_list_store ();
|
||||
break;
|
||||
}
|
||||
msg.destroy ();
|
||||
});
|
||||
msg.show ();
|
||||
}
|
||||
else if (button == close_tourist) {
|
||||
this.close ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a new or old tourist is saved
|
||||
* @param tourist_editor The editor that saved the tourist
|
||||
*/
|
||||
public void on_save(TouristEditor tourist_editor) {
|
||||
edit_tourist.sensitive = false;
|
||||
delete_tourist.sensitive = false;
|
||||
reset_columns ();
|
||||
|
||||
list_store.clear ();
|
||||
|
||||
update_list_store ();
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback is run when the user clicks on a column to reorder the rows
|
||||
* @param column The column that was clicked
|
||||
*/
|
||||
[GtkCallback]
|
||||
private void on_clicked_column (Gtk.TreeViewColumn column) {
|
||||
edit_tourist.sensitive = false;
|
||||
delete_tourist.sensitive = false;
|
||||
if (column == run) {
|
||||
if (!run.sort_indicator) {
|
||||
reset_columns ();
|
||||
run.sort_indicator = true;
|
||||
}
|
||||
|
||||
if (run.sort_order == Gtk.SortType.ASCENDING) {
|
||||
run.sort_order = Gtk.SortType.DESCENDING;
|
||||
}
|
||||
else {
|
||||
run.sort_order = Gtk.SortType.ASCENDING;
|
||||
}
|
||||
|
||||
tourist_list.sort_with_data ((a, b) => {
|
||||
if (run.sort_order == Gtk.SortType.ASCENDING) {
|
||||
return strcmp (a.rut_turista, b.rut_turista);
|
||||
}
|
||||
else {
|
||||
return strcmp (b.rut_turista, a.rut_turista);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (column == tourist_name) {
|
||||
if (!tourist_name.sort_indicator) {
|
||||
reset_columns ();
|
||||
tourist_name.sort_indicator = true;
|
||||
}
|
||||
|
||||
if (tourist_name.sort_order == Gtk.SortType.ASCENDING) {
|
||||
tourist_name.sort_order = Gtk.SortType.DESCENDING;
|
||||
}
|
||||
else {
|
||||
tourist_name.sort_order = Gtk.SortType.ASCENDING;
|
||||
}
|
||||
|
||||
tourist_list.sort_with_data ((a, b) => {
|
||||
if (tourist_name.sort_order == Gtk.SortType.ASCENDING) {
|
||||
return strcmp (a.nombre_turista, b.nombre_turista);
|
||||
}
|
||||
else {
|
||||
return strcmp (b.nombre_turista, a.nombre_turista);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (column == birthdate) {
|
||||
if (!birthdate.sort_indicator) {
|
||||
reset_columns ();
|
||||
birthdate.sort_indicator = true;
|
||||
}
|
||||
|
||||
if (birthdate.sort_order == Gtk.SortType.ASCENDING) {
|
||||
birthdate.sort_order = Gtk.SortType.DESCENDING;
|
||||
}
|
||||
else {
|
||||
birthdate.sort_order = Gtk.SortType.ASCENDING;
|
||||
}
|
||||
|
||||
tourist_list.sort_with_data ((a, b) => {
|
||||
if (birthdate.sort_order == Gtk.SortType.ASCENDING) {
|
||||
return strcmp (a.fecha_nacimento, b.fecha_nacimento);
|
||||
}
|
||||
else {
|
||||
return strcmp (b.fecha_nacimento, a.fecha_nacimento);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
list_store.clear ();
|
||||
tourist_list.foreach ((entry) => {
|
||||
Gtk.TreeIter iter;
|
||||
list_store.append (out iter);
|
||||
try {
|
||||
list_store.set (iter,
|
||||
Column.RUN, new Rut (entry.rut_turista).get_rut (),
|
||||
Column.NAME, entry.nombre_turista,
|
||||
Column.BIRTHDATE, entry.fecha_nacimento,
|
||||
Column.TOURIST, entry);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the sort indicator and order of all the columns
|
||||
*/
|
||||
private void reset_columns () {
|
||||
run.sort_indicator = false;
|
||||
run.sort_order = Gtk.SortType.DESCENDING;
|
||||
tourist_name.sort_indicator = false;
|
||||
tourist_name.sort_order = Gtk.SortType.DESCENDING;
|
||||
birthdate.sort_indicator = false;
|
||||
birthdate.sort_order = Gtk.SortType.DESCENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the list store with the data from the database
|
||||
*/
|
||||
private void update_list_store () {
|
||||
try {
|
||||
tourist_list = Turista.get_all_turistas (conn);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
|
||||
tourist_list.foreach ((entry) => {
|
||||
Gtk.TreeIter iter;
|
||||
list_store.append (out iter);
|
||||
try {
|
||||
list_store.set (iter,
|
||||
Column.RUN, new Rut (entry.rut_turista).get_rut (),
|
||||
Column.NAME, entry.nombre_turista,
|
||||
Column.BIRTHDATE, entry.fecha_nacimento,
|
||||
Column.TOURIST, entry);
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
#endif
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the tourist list class
|
||||
* @param application The application used to make the GLib object
|
||||
* @param conn The database connection to use
|
||||
*/
|
||||
public TouristList (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
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize what is needed for this window
|
||||
*/
|
||||
public void initialize () {
|
||||
list_store = new Gtk.ListStore (Column.N_COLUMNS,
|
||||
typeof (string),
|
||||
typeof (string),
|
||||
typeof (string),
|
||||
typeof (Turista));
|
||||
|
||||
update_list_store ();
|
||||
|
||||
tourist_tree.set_model (list_store);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user