a lot of work

This commit is contained in:
2019-01-19 13:44:30 -03:00
parent 404b68b791
commit 3aaf811190
50 changed files with 1959 additions and 378 deletions

View File

@@ -170,7 +170,7 @@ namespace Sernatur {
* @param application The application used to make the GLib object
*/
public MainWindow (Gtk.Application application) {
GLib.Object (application: application);
Object (application: application);
// Load logo
var builder = new Gtk.Builder ();
@@ -225,9 +225,8 @@ namespace Sernatur {
}
msg.destroy ();
});
msg.set_title (dgettext (null, "Error"));
msg.show ();
return;
msg.set_title (_ ("Error"));
msg.run ();
#endif
}
}

View File

@@ -18,6 +18,7 @@ vala_sources = files(
'main_window.vala',
'tour_list.vala',
'tour_editor.vala',
'tour_places.vala',
'queries.vala',
'query_window.vala')

View File

@@ -179,7 +179,7 @@ namespace Sernatur {
if (button == run_query) {
list_store.clear ();
if (query == Query.Q1) {
var region_list = Views.Q1.get_regions_without_discount (conn.db);
var region_list = Views.Q1.get_regions_without_discount (conn);
region_list.foreach ((entry) => {
Gtk.TreeIter iter;
@@ -190,7 +190,7 @@ namespace Sernatur {
});
}
else if (query == Query.Q2) {
var value_list = Views.Q2.get_value_received (conn.db);
var value_list = Views.Q2.get_value_received (conn);
value_list.foreach ((entry) => {
Gtk.TreeIter iter;
@@ -201,7 +201,7 @@ namespace Sernatur {
});
}
else if (query == Query.Q3) {
var value_list = Views.Q3.get_total_coordinators (conn.db);
var value_list = Views.Q3.get_total_coordinators (conn);
value_list.foreach ((entry) => {
Gtk.TreeIter iter;
@@ -212,7 +212,7 @@ namespace Sernatur {
});
}
else if (query == Query.Q4) {
var value_list = Views.Q4.get_total_tourists (conn.db);
var value_list = Views.Q4.get_total_tourists (conn);
value_list.foreach ((entry) => {
Gtk.TreeIter iter;
@@ -223,7 +223,7 @@ namespace Sernatur {
});
}
else if (query == Query.Q5) {
var value_list = Views.Q5.get_percentage (conn.db);
var value_list = Views.Q5.get_percentage (conn);
value_list.foreach ((entry) => {
Gtk.TreeIter iter;
@@ -245,7 +245,7 @@ namespace Sernatur {
* @param query The query to show
*/
public QueryWindow (Gtk.Application application, Connection conn, Query query) {
GLib.Object (application: application);
Object (application: application);
this.conn = conn;
this.query = query;
@@ -287,7 +287,7 @@ namespace Sernatur {
*/
public void initialize () {
if (query == Query.Q1) {
this.set_title (dgettext (null, "(Q1) Regions with discounts"));
this.set_title (_ ("(Q1) Regions with discounts"));
list_store = new Gtk.ListStore (Q1Column.N_COLUMNS,
typeof (string),
@@ -300,7 +300,7 @@ namespace Sernatur {
sql.set_text (Q1_SQL);
}
else if (query == Query.Q2) {
this.set_title (dgettext (null, "(Q2) Tour values"));
this.set_title (_ ("(Q2) Tour values"));
list_store = new Gtk.ListStore (Q2Column.N_COLUMNS,
typeof (string),
@@ -313,7 +313,7 @@ namespace Sernatur {
sql.set_text (Q2_SQL);
}
else if (query == Query.Q3) {
this.set_title (dgettext (null, "(Q3) Coordinator total"));
this.set_title (_ ("(Q3) Coordinator total"));
list_store = new Gtk.ListStore (Q3Column.N_COLUMNS,
typeof (string),
@@ -326,7 +326,7 @@ namespace Sernatur {
sql.set_text (Q3_SQL);
}
else if (query == Query.Q4) {
this.set_title (dgettext (null, "(Q4) Tourist total"));
this.set_title (_ ("(Q4) Tourist total"));
list_store = new Gtk.ListStore (Q4Column.N_COLUMNS,
typeof (string),
@@ -339,7 +339,7 @@ namespace Sernatur {
sql.set_text (Q4_SQL);
}
else if (query == Query.Q5) {
this.set_title (dgettext (null, "(Q5) Vehicle total"));
this.set_title (_ ("(Q5) Vehicle total"));
list_store = new Gtk.ListStore (Q5Column.N_COLUMNS,
typeof (string));

View File

@@ -17,7 +17,6 @@
*/
namespace Sernatur {
using Constants;
using Gtk;
/**
* If version is passed as an option on the console line
*/
@@ -48,13 +47,13 @@ namespace Sernatur {
var window = new MainWindow (this);
var settings = new GLib.Settings ("cl.cromer.ubb.sernatur.window");
window.set_default_size (settings.get_int("width"), settings.get_int("height"));
window.set_default_size (settings.get_int ("width"), settings.get_int ("height"));
if (settings.get_boolean ("maximized")) {
window.maximize ();
}
window.icon = new Image.from_resource ("/cl/cromer/ubb/sernatur/pixdata/icon-sernatur.png").get_pixbuf ();
window.icon = new Gtk.Image.from_resource ("/cl/cromer/ubb/sernatur/pixdata/icon-sernatur.png").get_pixbuf ();
window.show_all ();
window.initialize ();
}
@@ -85,13 +84,13 @@ namespace Sernatur {
opt_context.parse (ref args);
}
catch (OptionError e) {
print (dgettext (null, "Error: %s\n"), e.message);
print (dgettext (null, "Run '%s --help' to see a full list of available command line options.\n"), args[0]);
print (_ ("Error: %s\n"), e.message);
print (_ ("Run '%s --help' to see a full list of available command line options.\n"), args[0]);
return 1;
}
if (version) {
print (dgettext (null, "SERNATUR version: ") + VERSION + "\n");
print (_ ("SERNATUR version: ") + VERSION + "\n");
return 0;
}
else {

View File

@@ -92,6 +92,11 @@ namespace Sernatur {
*/
[GtkChild]
private Gtk.Button save;
/**
* The places button
*/
[GtkChild]
private Gtk.Button places;
/**
* The cancel button
*/
@@ -149,7 +154,7 @@ namespace Sernatur {
}
private void reset_city () {
cities = Ciudad.get_all_ciudades_in_region (conn.db, tour.ciudad.region.id_region);
cities = Ciudad.get_all_ciudades_in_region (conn, tour.ciudad.region.id_region);
if (cities.length () > 0) {
cities.sort_with_data ((a, b) => {
@@ -190,25 +195,12 @@ namespace Sernatur {
public void on_clicked_button (Gtk.Button button) {
if (button == save) {
if (tour.id_tour == 0) {
print (city.get_active_text () + "\n");
Gtk.TreeIter iter;
Ciudad ciudad;
city.get_active_iter (out iter);
if (city_list_store.iter_is_valid (iter)) {
city_list_store.get (iter,
CityColumn.CITY, out ciudad);
print (ciudad.nombre_ciudad + "\n");
}
}
else {
tour.nombre_tour = tour_name.get_text ();
tour.costo_indiv = (uint) int.parse (indiv_cost.get_text ());
tour.costo_grupal = (uint) int.parse (group_cost.get_text ());
tour.minima_personas = (uint) minimum_people.get_value_as_int ();
// This is if they typed a new city, TODO
/*print (city.get_active_text () + "\n");*/
update_tour_instance ();
try {
Tour.update_tour (conn.db, tour);
save_tour ();
this.close ();
Tour.insert_tour (conn, tour);
}
catch (Error e) {
#if DEBUG
@@ -217,13 +209,62 @@ namespace Sernatur {
warning (e.message);
#endif
}
finally {
save_tour (); // Signal the parent to update itself
this.close ();
}
}
else {
update_tour_instance ();
try {
Tour.update_tour (conn, tour);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
finally {
save_tour (); // Signal the parent to update itself
this.close ();
}
}
}
else if (button == places) {
var tour_places = new TourPlaces (application, conn, tour);
tour_places.set_transient_for (this); // Set this window as the parent of the new window
tour_places.initialize ();
tour_places.show_all ();
}
else if (button == cancel) {
this.close ();
}
}
private void update_tour_instance () {
tour.nombre_tour = tour_name.get_text ();
tour.costo_indiv = (uint) int.parse (indiv_cost.get_text ());
tour.costo_grupal = (uint) int.parse (group_cost.get_text ());
tour.minima_personas = (uint) minimum_people.get_value_as_int ();
Gtk.TreeIter iter;
Ciudad ciudad;
city.get_active_iter (out iter);
if (city_list_store.iter_is_valid (iter)) {
city_list_store.get (iter,
CityColumn.CITY, out ciudad);
tour.ciudad = ciudad;
}
Region new_region;
region.get_active_iter (out iter);
if (region_list_store.iter_is_valid (iter)) {
region_list_store.get (iter,
RegionColumn.REGION, out new_region);
tour.ciudad.region = new_region;
}
}
/**
* Initialize the tour editor class
* @param application The application used to make the GLib object
@@ -231,7 +272,7 @@ namespace Sernatur {
* @param tour The tour to edit
*/
public TourEditor (Gtk.Application application, Connection conn, Tour? tour) {
GLib.Object (application: application);
Object (application: application);
this.conn = conn;
this.tour = tour;
}
@@ -240,7 +281,7 @@ namespace Sernatur {
* Initialize what is needed for this window
*/
public void initialize () {
regions = Region.get_all_regiones (conn.db);
regions = Region.get_all_regiones (conn);
regions.sort_with_data ((a, b) => {
return strcmp (a.nombre_region, b.nombre_region);
@@ -283,7 +324,7 @@ namespace Sernatur {
city.set_model (city_list_store);
cities = Ciudad.get_all_ciudades_in_region (conn.db, tour.ciudad.region.id_region);
cities = Ciudad.get_all_ciudades_in_region (conn, tour.ciudad.region.id_region);
if (cities.length () > 0) {
cities.sort_with_data ((a, b) => {

View File

@@ -137,10 +137,14 @@ namespace Sernatur {
*/
[GtkCallback]
private void on_changed_selection(Gtk.TreeSelection selection) {
if (selection.count_selected_rows () > 0) {
if (selection.count_selected_rows () == 1) {
edit_tour.sensitive = true;
delete_tour.sensitive =true;
}
else if (selection.count_selected_rows () > 1) {
edit_tour.sensitive = false;
delete_tour.sensitive = true;
}
else {
edit_tour.sensitive = false;
delete_tour.sensitive = false;
@@ -158,12 +162,16 @@ namespace Sernatur {
tour_editor.set_transient_for (this); // Set this window as the parent of the new window
tour_editor.initialize ();
tour_editor.show_all ();
tour_editor.save_tour.connect (on_save);
}
else if (button == edit_tour) {
Gtk.TreeModel model;
Gtk.TreeIter iter;
Tour tour;
if (selection.get_selected (out model, out iter)) {
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 ());
Tour tour;
model.get (iter,
Column.TOUR, out tour);
var tour_editor = new TourEditor (application, conn, tour);
@@ -171,54 +179,87 @@ namespace Sernatur {
tour_editor.initialize ();
tour_editor.show_all ();
tour_editor.save_tour.connect (on_save);
}
});
}
else if (button == delete_tour) {
var msg = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.YES_NO,
dgettext(null, "Are you sure you wish to delete this tour?"));
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 tour?"));
}
else {
msg = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.YES_NO,
_ ("Are you sure you wish to delete these tours?"));
}
msg.response.connect ((response_id) => {
switch (response_id) {
case Gtk.ResponseType.YES:
try {
Gtk.TreeModel model;
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 ());
Tour tour;
if (selection.get_selected (out model, out iter)) {
model.get (iter,
Column.TOUR, out tour);
Tour.delete_tour (conn.db, tour);
model.get (iter,
Column.TOUR, out tour);
try {
Tour.delete_tour (conn, tour);
}
}
catch (DBError e) {
if (e.code == 1) {
var msg2 = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE,
dgettext(null, "Error: Could not delete tour because there are still associated arrival and departure dates and times!"));
msg2.response.connect ((response_id) => {
msg2.destroy ();
});
msg2.set_title (dgettext (null, "Error"));
msg2.show ();
}
else {
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 tour \"%s\" because either this tour has been taken or is still associated with a place or vehicle!"), tour.nombre_tour);
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_tour.sensitive = false;
delete_tour.sensitive = false;
reset_columns ();
list_store.clear ();
update_list_store ();
break;
}
msg.destroy ();
});
msg.set_title (dgettext (null, "Error"));
msg.set_title (_ ("Error"));
msg.show ();
selection.selected_foreach ((model, path, iter) => {
Tour tour;
model.get (iter,
Column.TOUR, out tour);
});
}
else if (button == close_tour) {
this.close ();
@@ -465,7 +506,16 @@ namespace Sernatur {
* Update the list store with the data from the database
*/
private void update_list_store () {
tour_list = Tour.get_all_tours (conn.db);
try {
tour_list = Tour.get_all_tours (conn);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
tour_list.foreach ((entry) => {
Gtk.TreeIter iter;
@@ -487,7 +537,7 @@ namespace Sernatur {
* @param conn The database connection to use
*/
public TourList (Gtk.Application application, Connection conn) {
GLib.Object (application: application);
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

551
src/tour_places.vala Normal file
View File

@@ -0,0 +1,551 @@
/*
* 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 tour list window class
*/
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/tour.places.ui")]
public class TourPlaces : Gtk.ApplicationWindow {
/**
* The open database connection
*/
private Connection conn;
/**
* The tour to edit
*/
private Tour tour;
/**
* The columns of the tree view
*/
private enum Column {
/**
* The name of the place
*/
PLACE_NAME,
/**
* The individual cost
*/
TICKET_PRICE,
/**
* The level of difficulty
*/
DIFFICULTY,
/**
* The date of arrival
*/
ARRIVAL_DATE,
/**
* The time of arrival
*/
ARRIVAL_TIME,
/**
* The date of departure
*/
DEPARTURE_DATE,
/**
* The departure time
*/
DEPARTURE_TIME,
/**
* The associated object
*/
ASSOCIATED,
/**
* 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 tours
*/
private List<Asociado> associated_list;
/**
* The tree view widget
*/
[GtkChild]
private Gtk.TreeView place_tree;
/**
* The row selection
*/
[GtkChild]
private Gtk.TreeSelection selection;
/**
* The place name column
*/
[GtkChild]
private Gtk.TreeViewColumn place_name;
/**
* The ticket price column
*/
[GtkChild]
private Gtk.TreeViewColumn ticket_price;
/**
* The difficulty column
*/
[GtkChild]
private Gtk.TreeViewColumn difficulty;
/**
* The arrival date column
*/
[GtkChild]
private Gtk.TreeViewColumn arrival_date;
/**
* The arrival time column
*/
[GtkChild]
private Gtk.TreeViewColumn arrival_time;
/**
* The departure date column
*/
[GtkChild]
private Gtk.TreeViewColumn departure_date;
/**
* The departure time column
*/
[GtkChild]
private Gtk.TreeViewColumn departure_time;
/**
* Thew new place button
*/
[GtkChild]
private Gtk.Button new_place;
/**
* The edit place button
*/
[GtkChild]
private Gtk.Button edit_place;
/**
* The delete place button
*/
[GtkChild]
private Gtk.Button delete_place;
/**
* The close place button
*/
[GtkChild]
private Gtk.Button close_place;
/**
* The add place button
*/
[GtkChild]
private Gtk.Button add_place;
/**
* 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_place.sensitive = true;
delete_place.sensitive =true;
}
else if (selection.count_selected_rows () > 1) {
edit_place.sensitive = false;
delete_place.sensitive = true;
}
else {
edit_place.sensitive = false;
delete_place.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_place) {
/*var tour_editor = new TourEditor (application, conn, null);
tour_editor.set_transient_for (this); // Set this window as the parent of the new window
tour_editor.initialize ();
tour_editor.show_all ();*/
}
else if (button == add_place) {
}
else if (button == edit_place) {
selection.selected_foreach ((model, path, iter) => {
Asociado associated;
model.get (iter,
Column.ASSOCIATED, out associated);
print (associated.lugar.nombre_lugar + "\n");
});
/*if (selection.get_selected (out model, out iter)) {
Asociado associated;
model.get (iter,
Column.ASSOCIATED, out associated);
var tour_editor = new TourEditor (application, conn, tour);
tour_editor.set_transient_for (this); // Set this window as the parent of the new window
tour_editor.initialize ();
tour_editor.show_all ();
tour_editor.save_tour.connect (on_save);
}*/
}
else if (button == delete_place) {
/*var msg = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.YES_NO,
dgettext(null, "Are you sure you wish to delete this tour?"));
msg.response.connect ((response_id) => {
switch (response_id) {
case Gtk.ResponseType.YES:
try {
Gtk.TreeModel model;
Gtk.TreeIter iter;
Tour tour;
if (selection.get_selected (out model, out iter)) {
model.get (iter,
Column.TOUR, out tour);
Tour.delete_tour (conn, tour);
}
}
catch (DBError e) {
if (e.code == 1) {
var msg2 = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE,
dgettext(null, "Error: Could not delete tour because there are still associated arrival and departure dates and times!"));
msg2.response.connect ((response_id) => {
msg2.destroy ();
});
msg2.set_title (_ ("Error"));
msg2.show ();
}
else {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
break;
}
msg.destroy ();
});
msg.set_title (_ ("Error"));
msg.show ();*/
}
else if (button == close_place) {
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) {
edit_place.sensitive = false;
delete_place.sensitive = false;
if (column == place_name) {
if (!place_name.sort_indicator) {
reset_columns ();
place_name.sort_indicator = true;
}
if (place_name.sort_order == Gtk.SortType.ASCENDING) {
place_name.sort_order = Gtk.SortType.DESCENDING;
}
else {
place_name.sort_order = Gtk.SortType.ASCENDING;
}
associated_list.sort_with_data ((a, b) => {
if (place_name.sort_order == Gtk.SortType.ASCENDING) {
return strcmp (a.lugar.nombre_lugar, b.lugar.nombre_lugar);
}
else {
return strcmp (b.lugar.nombre_lugar, a.lugar.nombre_lugar);
}
});
}
else if (column == ticket_price) {
if (!ticket_price.sort_indicator) {
reset_columns ();
ticket_price.sort_indicator = true;
}
if (ticket_price.sort_order == Gtk.SortType.ASCENDING) {
ticket_price.sort_order = Gtk.SortType.DESCENDING;
}
else {
ticket_price.sort_order = Gtk.SortType.ASCENDING;
}
associated_list.sort_with_data ((a, b) => {
if (ticket_price.sort_order == Gtk.SortType.ASCENDING) {
if (a.lugar.valor_entrada < b.lugar.valor_entrada) {
return -1;
}
else if (a.lugar.valor_entrada == b.lugar.valor_entrada) {
return 0;
}
else {
return 1;
}
}
else {
if (a.lugar.valor_entrada < b.lugar.valor_entrada) {
return 1;
}
else if (a.lugar.valor_entrada == b.lugar.valor_entrada) {
return 0;
}
else {
return -1;
}
}
});
}
else if (column == difficulty) {
if (!difficulty.sort_indicator) {
reset_columns ();
difficulty.sort_indicator = true;
}
if (difficulty.sort_order == Gtk.SortType.ASCENDING) {
difficulty.sort_order = Gtk.SortType.DESCENDING;
}
else {
difficulty.sort_order = Gtk.SortType.ASCENDING;
}
associated_list.sort_with_data ((a, b) => {
if (difficulty.sort_order == Gtk.SortType.ASCENDING) {
if (a.lugar.nivel < b.lugar.nivel) {
return -1;
}
else if (a.lugar.nivel == b.lugar.nivel) {
return 0;
}
else {
return 1;
}
}
else {
if (a.lugar.nivel < b.lugar.nivel) {
return 1;
}
else if (a.lugar.nivel == b.lugar.nivel) {
return 0;
}
else {
return -1;
}
}
});
}
else if (column == arrival_date) {
if (!arrival_date.sort_indicator) {
reset_columns ();
arrival_date.sort_indicator = true;
}
if (arrival_date.sort_order == Gtk.SortType.ASCENDING) {
arrival_date.sort_order = Gtk.SortType.DESCENDING;
}
else {
arrival_date.sort_order = Gtk.SortType.ASCENDING;
}
associated_list.sort_with_data ((a, b) => {
if (arrival_date.sort_order == Gtk.SortType.ASCENDING) {
return strcmp (a.fecha_llegada, b.fecha_llegada);
}
else {
return strcmp (b.fecha_llegada, a.fecha_llegada);
}
});
}
else if (column == arrival_time) {
if (!arrival_time.sort_indicator) {
reset_columns ();
arrival_time.sort_indicator = true;
}
if (arrival_time.sort_order == Gtk.SortType.ASCENDING) {
arrival_time.sort_order = Gtk.SortType.DESCENDING;
}
else {
arrival_time.sort_order = Gtk.SortType.ASCENDING;
}
associated_list.sort_with_data ((a, b) => {
if (arrival_time.sort_order == Gtk.SortType.ASCENDING) {
return strcmp (a.hora_llegada, b.hora_llegada);
}
else {
return strcmp (b.hora_llegada, a.hora_llegada);
}
});
}
else if (column == departure_date) {
if (!departure_date.sort_indicator) {
reset_columns ();
departure_date.sort_indicator = true;
}
if (departure_date.sort_order == Gtk.SortType.ASCENDING) {
departure_date.sort_order = Gtk.SortType.DESCENDING;
}
else {
departure_date.sort_order = Gtk.SortType.ASCENDING;
}
associated_list.sort_with_data ((a, b) => {
if (departure_date.sort_order == Gtk.SortType.ASCENDING) {
return strcmp (a.fecha_salida, b.fecha_salida);
}
else {
return strcmp (b.fecha_salida, a.fecha_salida);
}
});
}
else if (column == departure_time) {
if (!departure_time.sort_indicator) {
reset_columns ();
departure_time.sort_indicator = true;
}
if (departure_time.sort_order == Gtk.SortType.ASCENDING) {
departure_time.sort_order = Gtk.SortType.DESCENDING;
}
else {
departure_time.sort_order = Gtk.SortType.ASCENDING;
}
associated_list.sort_with_data ((a, b) => {
if (departure_time.sort_order == Gtk.SortType.ASCENDING) {
return strcmp (a.hora_salida, b.hora_salida);
}
else {
return strcmp (b.hora_salida, a.hora_salida);
}
});
}
list_store.clear ();
associated_list.foreach ((entry) => {
Gtk.TreeIter iter;
list_store.append (out iter);
list_store.set (iter,
Column.PLACE_NAME, entry.lugar.nombre_lugar,
Column.TICKET_PRICE, Money.format_uint (entry.lugar.valor_entrada),
Column.DIFFICULTY, entry.lugar.nivel,
Column.ARRIVAL_DATE, entry.fecha_llegada,
Column.ARRIVAL_TIME, entry.hora_llegada,
Column.DEPARTURE_DATE, entry.fecha_salida,
Column.DEPARTURE_TIME, entry.hora_salida,
Column.ASSOCIATED, entry);
});
}
/**
* Reset the sort indicator and order of all the columns
*/
private void reset_columns () {
place_name.sort_indicator = false;
place_name.sort_order = Gtk.SortType.DESCENDING;
ticket_price.sort_indicator = false;
ticket_price.sort_order = Gtk.SortType.DESCENDING;
difficulty.sort_indicator = false;
difficulty.sort_order = Gtk.SortType.DESCENDING;
arrival_date.sort_indicator = false;
arrival_date.sort_order = Gtk.SortType.DESCENDING;
arrival_time.sort_indicator = false;
arrival_time.sort_order = Gtk.SortType.DESCENDING;
departure_date.sort_indicator = false;
departure_date.sort_order = Gtk.SortType.DESCENDING;
departure_time.sort_indicator = false;
departure_time.sort_order = Gtk.SortType.DESCENDING;
}
/**
* Update the list store with the data from the database
*/
private void update_list_store () {
try {
associated_list = Asociado.get_all_asociados_by_tour (conn, tour);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
associated_list.foreach ((entry) => {
Gtk.TreeIter iter;
list_store.append (out iter);
list_store.set (iter,
Column.PLACE_NAME, entry.lugar.nombre_lugar,
Column.TICKET_PRICE, Money.format_uint (entry.lugar.valor_entrada),
Column.DIFFICULTY, entry.lugar.nivel,
Column.ARRIVAL_DATE, entry.fecha_llegada,
Column.ARRIVAL_TIME, entry.hora_llegada,
Column.DEPARTURE_DATE, entry.fecha_salida,
Column.DEPARTURE_TIME, entry.hora_salida,
Column.ASSOCIATED, entry);
});
}
/**
* Initialize the tour list class
* @param application The application used to make the GLib object
* @param conn The database connection to use
* @param tour The tour which is the parent of this window
*/
public TourPlaces (Gtk.Application application, Connection conn, Tour tour) {
Object (application: application);
this.conn = conn;
this.tour = tour;
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 (uint),
typeof (string),
typeof (string),
typeof (string),
typeof (string),
typeof (Asociado));
update_list_store ();
place_tree.set_model (list_store);
}
}
}