show the tours
This commit is contained in:
@@ -24,7 +24,8 @@ namespace Sernatur {
|
||||
*/
|
||||
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/main.window.ui")]
|
||||
public class MainWindow : Gtk.ApplicationWindow {
|
||||
private TourWindow tour_window;
|
||||
private Postgres.Database conn;
|
||||
|
||||
private Gtk.Grid content;
|
||||
[GtkChild]
|
||||
private Gtk.Box mainbox;
|
||||
@@ -76,9 +77,9 @@ namespace Sernatur {
|
||||
|
||||
[GtkCallback]
|
||||
private void menu_tours(Gtk.MenuItem menu_item) {
|
||||
tour_window = new TourWindow (application);
|
||||
var tour_window = new TourWindow (application, conn);
|
||||
tour_window.set_transient_for (this); // Set this window as the parent of the new window
|
||||
tour_window.present ();
|
||||
tour_window.show_all ();
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
@@ -117,7 +118,7 @@ namespace Sernatur {
|
||||
var username = settings.get_string ("username");
|
||||
var password = settings.get_string ("password");
|
||||
|
||||
var conn = Postgres.set_db_login (host, port, options, tty, database, username, password);
|
||||
conn = Postgres.set_db_login (host, port, options, tty, database, username, password);
|
||||
if (conn.get_status () != Postgres.ConnectionStatus.OK) {
|
||||
#if DEBUG
|
||||
error (conn.get_error_message ());
|
||||
@@ -145,37 +146,6 @@ namespace Sernatur {
|
||||
#endif
|
||||
}
|
||||
print (dgettext (null, "Postgresql server version:") + " %d\n", conn.get_server_version ());
|
||||
|
||||
/*var tour = Tour.get_all_tours (conn);
|
||||
print (tour[0].ciudad.region.nombre_region + "\n");
|
||||
var tiene_enfermedad = TieneEnfermedad.get_all_tiene_enfermedades (conn);
|
||||
print (tiene_enfermedad[0].turista.contacto_emergencia.nombre_emergencia + "\n");
|
||||
var descuento = Descuento.get_all_descuentos (conn);
|
||||
print (descuento[0].porcentaje.to_string () + "\n");
|
||||
var realiza = Realiza.get_all_realizas (conn);
|
||||
print (realiza[0].turista.contacto_emergencia.nombre_emergencia + "\n");
|
||||
var posee = Posee.get_all_posees (conn);
|
||||
print (posee[0].guia.ciudad.region.nombre_region + "\n");
|
||||
var region = Region.get_all_regiones (conn);
|
||||
print (region[0].nombre_region + "\n");
|
||||
var participa = Participa.get_all_participas (conn);
|
||||
print (participa[0].guia.ciudad.region.nombre_region + "\n");
|
||||
print (participa[0].tour.ciudad.region.nombre_region + "\n");
|
||||
var requerir_auto = RequerirAuto.get_all_requerir_autos (conn);
|
||||
print (requerir_auto[0].vehiculo.marca + "\n");
|
||||
try {
|
||||
var rut = new Rut ("23.660.457-8");
|
||||
print (rut.get_rut () + "\n");
|
||||
if (rut.type () == Rut.Type.RUN) {
|
||||
print ("person\n");
|
||||
}
|
||||
else {
|
||||
print ("company\n");
|
||||
}
|
||||
}
|
||||
catch (InvalidRut e) {
|
||||
print ("Rut is invalid");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ namespace Sernatur {
|
||||
}
|
||||
|
||||
window.icon = new Image.from_resource ("/cl/cromer/ubb/sernatur/pixdata/icon-sernatur.png").get_pixbuf ();
|
||||
window.present ();
|
||||
window.show_all ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -24,12 +24,80 @@ namespace Sernatur {
|
||||
*/
|
||||
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/tour.window.ui")]
|
||||
public class TourWindow : Gtk.ApplicationWindow {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the main window class
|
||||
* @param application The application used to make the GLib object
|
||||
*/
|
||||
public TourWindow (Gtk.Application application) {
|
||||
public TourWindow (Gtk.Application application, Postgres.Database conn) {
|
||||
GLib.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
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user