sernatur/src/tour_window.vala

104 lines
3.8 KiB
Vala
Raw Normal View History

2019-01-05 19:08:51 -03:00
/*
2019-01-05 19:37:57 -03:00
* Copyright 2018-2019 Chris Cromer
2019-01-05 19:08:51 -03:00
*
* 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.
*/
/**
* The main Sernatur namespace
*/
namespace Sernatur {
using LibSernatur.Person;
using LibSernatur.DB;
/**
* The TourWindow class
*/
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/tour.window.ui")]
public class TourWindow : Gtk.ApplicationWindow {
2019-01-06 02:04:22 -03:00
private unowned Postgres.Database conn;
private enum Columns {
TOGGLE,
TOUR_NAME,
INDIV_COST,
GROUP_COST,
MINIMUM_PEOPLE,
CITY,
REGION,
N_COLUMNS
}
private Gtk.ListStore list_store;
[GtkChild]
private Gtk.TreeView tour_tree;
[GtkCallback]
private void toggled(Gtk.CellRendererToggle toggle, string path) {
Gtk.TreeModelForeachFunc deselect_all = (model, path, iter) => {
list_store.set (iter, Columns.TOGGLE, false);
return false;
};
// Backup the previous state
var tree_path = new Gtk.TreePath.from_string (path);
Gtk.TreeIter iter;
bool old_val;
list_store.get_iter (out iter, tree_path);
list_store.get (iter, Columns.TOGGLE, out old_val);
// Deselect all states
list_store.foreach (deselect_all);
// Invert previous state
list_store.get_iter (out iter, tree_path);
list_store.set (iter, Columns.TOGGLE, !old_val);
}
2019-01-05 19:08:51 -03:00
/**
* Initialize the main window class
* @param application The application used to make the GLib object
*/
2019-01-06 02:04:22 -03:00
public TourWindow (Gtk.Application application, Postgres.Database conn) {
2019-01-05 19:08:51 -03:00
GLib.Object (application: application);
2019-01-06 02:04:22 -03:00
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
list_store = new Gtk.ListStore (Columns.N_COLUMNS,
typeof (bool),
typeof (string),
typeof (string),
typeof (string),
typeof (uint),
typeof (string),
typeof (string));
Gtk.TreeIter iter;
var tour = Tour.get_all_tours (conn);
for (int i = 0; i < tour.length - 1; i++) {
list_store.append (out iter);
list_store.set (iter,
Columns.TOGGLE, false,
Columns.TOUR_NAME, tour[i].nombre_tour,
Columns.INDIV_COST, tour[i].costo_indiv.to_string (),
Columns.GROUP_COST, tour[i].costo_grupal.to_string (),
Columns.MINIMUM_PEOPLE, tour[i].minima_personas,
Columns.CITY, tour[i].ciudad.nombre_ciudad,
Columns.REGION, tour[i].ciudad.region.nombre_region);
}
tour_tree.set_model (list_store);
2019-01-05 19:08:51 -03:00
}
}
}