start work on assign vehicle
This commit is contained in:
parent
b3dcb8119b
commit
e6a7d9e1a7
@ -92,14 +92,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
|
||||||
<object class="GtkMenuItem" id="vehicles">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="label" translatable="yes">Vehicles</property>
|
|
||||||
<signal name="activate" handler="on_activate_menu" swapped="no"/>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkSeparatorMenuItem">
|
<object class="GtkSeparatorMenuItem">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
165
data/ui/tour.assign.vehicle.ui
Normal file
165
data/ui/tour.assign.vehicle.ui
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
<?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"/>
|
||||||
|
<template class="SernaturTourAssignVehicle" parent="GtkApplicationWindow">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="type">popup</property>
|
||||||
|
<property name="title" translatable="yes">Tour Editor</property>
|
||||||
|
<property name="resizable">False</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">Vehicle</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</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="save">
|
||||||
|
<property name="label" translatable="yes">Assign</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 this vehicle to the 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">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">2</property>
|
||||||
|
<property name="width">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">Chofer</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkEntry" id="chofer">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="sensitive">False</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="caps_lock_warning">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkComboBoxText" id="vehicle">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="tooltip_text" translatable="yes">The licence plate, make, year, and capacity of the vehicle.</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_frame">False</property>
|
||||||
|
<property name="popup_fixed_width">False</property>
|
||||||
|
<signal name="changed" handler="on_changed_combobox" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</template>
|
||||||
|
</interface>
|
@ -319,6 +319,25 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</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>
|
<child>
|
||||||
<object class="GtkButton" id="save">
|
<object class="GtkButton" id="save">
|
||||||
<property name="label" translatable="yes">Save</property>
|
<property name="label" translatable="yes">Save</property>
|
||||||
@ -335,7 +354,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">2</property>
|
<property name="position">3</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
@ -18,5 +18,6 @@
|
|||||||
<file preprocess="xml-stripblanks">tour.editor.ui</file>
|
<file preprocess="xml-stripblanks">tour.editor.ui</file>
|
||||||
<file preprocess="xml-stripblanks">tour.places.ui</file>
|
<file preprocess="xml-stripblanks">tour.places.ui</file>
|
||||||
<file preprocess="xml-stripblanks">tour.place.editor.ui</file>
|
<file preprocess="xml-stripblanks">tour.place.editor.ui</file>
|
||||||
|
<file preprocess="xml-stripblanks">tour.assign.vehicle.ui</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
@ -17,6 +17,8 @@ data/ui/main.splash.ui
|
|||||||
data/ui/tour.list.ui
|
data/ui/tour.list.ui
|
||||||
data/ui/tour.editor.ui
|
data/ui/tour.editor.ui
|
||||||
data/ui/tour.places.ui
|
data/ui/tour.places.ui
|
||||||
|
data/ui/tour.place.editor.ui
|
||||||
|
data/ui/tour.assign.vehicle.ui
|
||||||
data/ui/place.editor.ui
|
data/ui/place.editor.ui
|
||||||
data/ui/query.window.ui
|
data/ui/query.window.ui
|
||||||
data/ui/query.tree.ui
|
data/ui/query.tree.ui
|
||||||
|
@ -20,6 +20,7 @@ vala_sources = files(
|
|||||||
'tour_editor.vala',
|
'tour_editor.vala',
|
||||||
'tour_places.vala',
|
'tour_places.vala',
|
||||||
'tour_place_editor.vala',
|
'tour_place_editor.vala',
|
||||||
|
'tour_assign_vehicle.vala',
|
||||||
'place_editor.vala',
|
'place_editor.vala',
|
||||||
'queries.vala',
|
'queries.vala',
|
||||||
'query_window.vala')
|
'query_window.vala')
|
||||||
|
307
src/tour_assign_vehicle.vala
Normal file
307
src/tour_assign_vehicle.vala
Normal file
@ -0,0 +1,307 @@
|
|||||||
|
/*
|
||||||
|
* 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 tour assign vehicle window class
|
||||||
|
*/
|
||||||
|
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/tour.assign.vehicle.ui")]
|
||||||
|
public class TourAssignVehicle : Gtk.ApplicationWindow {
|
||||||
|
/**
|
||||||
|
* The open database connection
|
||||||
|
*/
|
||||||
|
private Connection conn;
|
||||||
|
/**
|
||||||
|
* The tour to associate with the vehicle
|
||||||
|
*/
|
||||||
|
private Tour tour;
|
||||||
|
/**
|
||||||
|
* The vehicle data stored in the list store
|
||||||
|
*/
|
||||||
|
private enum Column {
|
||||||
|
/**
|
||||||
|
* The details of the vehicle
|
||||||
|
*/
|
||||||
|
VEHICLE_DETAILS,
|
||||||
|
/**
|
||||||
|
* The vehicle object
|
||||||
|
*/
|
||||||
|
VEHICLE,
|
||||||
|
/**
|
||||||
|
* The number of colums in this enum
|
||||||
|
*/
|
||||||
|
N_COLUMNS
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* The chofer of the vehicle
|
||||||
|
*/
|
||||||
|
[GtkChild]
|
||||||
|
private Gtk.Entry chofer;
|
||||||
|
/**
|
||||||
|
* The vehicle comboxbox
|
||||||
|
*/
|
||||||
|
[GtkChild]
|
||||||
|
private Gtk.ComboBoxText vehicle;
|
||||||
|
/**
|
||||||
|
* The save button
|
||||||
|
*/
|
||||||
|
[GtkChild]
|
||||||
|
private Gtk.Button save;
|
||||||
|
/**
|
||||||
|
* The cancel button
|
||||||
|
*/
|
||||||
|
[GtkChild]
|
||||||
|
private Gtk.Button cancel;
|
||||||
|
/**
|
||||||
|
* A list of the vehicles from the database
|
||||||
|
*/
|
||||||
|
private List<Vehiculo> vehicles;
|
||||||
|
/**
|
||||||
|
* The list that stores the vehicles for the combo box
|
||||||
|
*/
|
||||||
|
private Gtk.ListStore vehicle_list_store;
|
||||||
|
/**
|
||||||
|
* This signal is called when a vehicle is assigned
|
||||||
|
*/
|
||||||
|
public signal void save_vehicle (Vehiculo vehicle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the car data before trying to insert it into the database
|
||||||
|
* @return Returns true if the data is valid
|
||||||
|
*/
|
||||||
|
private bool validate_car_data () {
|
||||||
|
/*if (tour.nombre_tour.strip () == "") {
|
||||||
|
var msg = new Gtk.MessageDialog (this,
|
||||||
|
Gtk.DialogFlags.MODAL,
|
||||||
|
Gtk.MessageType.ERROR,
|
||||||
|
Gtk.ButtonsType.CLOSE,
|
||||||
|
_ ("Error: Tour name cannot be left blank!"));
|
||||||
|
msg.response.connect ((response_id) => {
|
||||||
|
msg.destroy ();
|
||||||
|
});
|
||||||
|
msg.set_title (_ ("Error"));
|
||||||
|
msg.run ();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool list_success = true;
|
||||||
|
try {
|
||||||
|
List<Tour> list = Tour.get_all_tours (conn);
|
||||||
|
list.foreach ((entry) => {
|
||||||
|
if (tour.nombre_tour.down () == entry.nombre_tour.down () && tour.id_tour != entry.id_tour) {
|
||||||
|
var msg = new Gtk.MessageDialog (this,
|
||||||
|
Gtk.DialogFlags.MODAL,
|
||||||
|
Gtk.MessageType.ERROR,
|
||||||
|
Gtk.ButtonsType.CLOSE,
|
||||||
|
_ ("Error: A tour named \"%s\" already exists!"), entry.nombre_tour);
|
||||||
|
msg.response.connect ((response_id) => {
|
||||||
|
msg.destroy ();
|
||||||
|
});
|
||||||
|
msg.set_title (_ ("Error"));
|
||||||
|
msg.run ();
|
||||||
|
list_success = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Error e) {
|
||||||
|
#if DEBUG
|
||||||
|
error (e.message);
|
||||||
|
#else
|
||||||
|
warning (e.message);
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return list_success;*/
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a combobox changes
|
||||||
|
* @param combobox The combobox that changed
|
||||||
|
*/
|
||||||
|
[GtkCallback]
|
||||||
|
public void on_changed_combobox (Gtk.ComboBox combobox) {
|
||||||
|
if (combobox == vehicle) {
|
||||||
|
if (vehicle.get_active () > 0) {
|
||||||
|
Gtk.TreeIter iter;
|
||||||
|
vehicle.get_active_iter (out iter);
|
||||||
|
Vehiculo temp_vehicle;
|
||||||
|
vehicle_list_store.get (iter,
|
||||||
|
Column.VEHICLE, out temp_vehicle);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Unassigned
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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_tour_instance () && validate_tour_data ()) {
|
||||||
|
if (tour.id_tour == 0) {
|
||||||
|
try {
|
||||||
|
Tour.insert_tour (conn, tour);
|
||||||
|
if (list_asociado != null) {
|
||||||
|
// Insert all the pending associations
|
||||||
|
list_asociado.foreach ((entry) => {
|
||||||
|
try {
|
||||||
|
Asociado.insert_asociado (conn, entry);
|
||||||
|
}
|
||||||
|
catch (Error e) {
|
||||||
|
#if DEBUG
|
||||||
|
error (e.message);
|
||||||
|
#else
|
||||||
|
warning (e.message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
save_tour (); // Signal the parent to update itself
|
||||||
|
this.close ();
|
||||||
|
}
|
||||||
|
catch (Error e) {
|
||||||
|
#if DEBUG
|
||||||
|
error (e.message);
|
||||||
|
#else
|
||||||
|
warning (e.message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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 == cancel) {
|
||||||
|
this.close ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the the vehicle object with new info from the editor
|
||||||
|
*/
|
||||||
|
private bool update_vehicle_instance () {
|
||||||
|
/*tour.nombre_tour = tour_name.get_text ().strip ();
|
||||||
|
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 ();
|
||||||
|
if (region.get_active () == -1) {
|
||||||
|
Region new_region = new Region (0, region.get_active_text ().strip ());
|
||||||
|
try {
|
||||||
|
if (validate_region_data (new_region)) {
|
||||||
|
new_region.id_region = Region.insert_region (conn, new_region);
|
||||||
|
return update_tour_instance_city (new_region);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Error e) {
|
||||||
|
#if DEBUG
|
||||||
|
error (e.message);
|
||||||
|
#else
|
||||||
|
warning (e.message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Region new_region;
|
||||||
|
Gtk.TreeIter iter;
|
||||||
|
region.get_active_iter (out iter);
|
||||||
|
if (region_list_store.iter_is_valid (iter)) {
|
||||||
|
region_list_store.get (iter,
|
||||||
|
RegionColumn.REGION, out new_region);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_region = new Region ();
|
||||||
|
}
|
||||||
|
return update_tour_instance_city (new_region);
|
||||||
|
}*/
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the tour editor class
|
||||||
|
* @param application The application used to make the GLib object
|
||||||
|
* @param conn The database connection to use
|
||||||
|
* @param tour The tour to edit
|
||||||
|
*/
|
||||||
|
public TourAssignVehicle (Gtk.Application application, Connection conn, Tour tour) {
|
||||||
|
Object (application: application);
|
||||||
|
this.conn = conn;
|
||||||
|
this.tour = tour;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize what is needed for this window
|
||||||
|
*/
|
||||||
|
public void initialize () {
|
||||||
|
try {
|
||||||
|
vehicles = Vehiculo.get_all_vehiculos (conn);
|
||||||
|
}
|
||||||
|
catch (Error e) {
|
||||||
|
#if DEBUG
|
||||||
|
error (e.message);
|
||||||
|
#else
|
||||||
|
warning (e.message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
vehicles.sort_with_data ((a, b) => {
|
||||||
|
return strcmp (a.patente, b.patente);
|
||||||
|
});
|
||||||
|
|
||||||
|
vehicle_list_store = new Gtk.ListStore (Column.N_COLUMNS,
|
||||||
|
typeof (string),
|
||||||
|
typeof (Vehiculo));
|
||||||
|
|
||||||
|
vehicle.set_model (vehicle_list_store);
|
||||||
|
|
||||||
|
Gtk.TreeIter iter;
|
||||||
|
vehicle_list_store.append (out iter);
|
||||||
|
vehicle_list_store.set (iter,
|
||||||
|
Column.VEHICLE_DETAILS, _ ("Unassigned"),
|
||||||
|
Column.VEHICLE, new Vehiculo ());
|
||||||
|
vehicle.set_active (0);
|
||||||
|
vehicles.foreach ((entry) => {
|
||||||
|
vehicle_list_store.append (out iter);
|
||||||
|
vehicle_list_store.set (iter,
|
||||||
|
Column.VEHICLE_DETAILS, entry.patente + " " + entry.marca + " " + entry.ano_vehiculo.to_string () + " " + entry.capacidad.to_string (),
|
||||||
|
Column.VEHICLE, entry);
|
||||||
|
/*if (entry.patente == assigned_vehicle.patente) {
|
||||||
|
vehicle.set_active_iter (iter);
|
||||||
|
}*/
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -97,6 +97,11 @@ namespace Sernatur {
|
|||||||
*/
|
*/
|
||||||
[GtkChild]
|
[GtkChild]
|
||||||
private Gtk.Button places;
|
private Gtk.Button places;
|
||||||
|
/**
|
||||||
|
* The vehicle button
|
||||||
|
*/
|
||||||
|
[GtkChild]
|
||||||
|
private Gtk.Button vehicle;
|
||||||
/**
|
/**
|
||||||
* The cancel button
|
* The cancel button
|
||||||
*/
|
*/
|
||||||
@ -132,11 +137,19 @@ namespace Sernatur {
|
|||||||
* A list of associated places, this is only used in the case of a new tour
|
* A list of associated places, this is only used in the case of a new tour
|
||||||
*/
|
*/
|
||||||
private List<Asociado> list_asociado = null;
|
private List<Asociado> list_asociado = null;
|
||||||
|
/**
|
||||||
|
* The vehicle to be inserted if the new tour is saved
|
||||||
|
*/
|
||||||
|
private Vehiculo vehiculo = null;
|
||||||
/**
|
/**
|
||||||
* This signal is called when a tour is saved
|
* This signal is called when a tour is saved
|
||||||
*/
|
*/
|
||||||
public signal void save_tour ();
|
public signal void save_tour ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a combobox changes
|
||||||
|
* @param combobox The combobox that changed
|
||||||
|
*/
|
||||||
[GtkCallback]
|
[GtkCallback]
|
||||||
public void on_changed_combobox (Gtk.ComboBox combobox) {
|
public void on_changed_combobox (Gtk.ComboBox combobox) {
|
||||||
if (combobox == region) {
|
if (combobox == region) {
|
||||||
@ -409,6 +422,13 @@ namespace Sernatur {
|
|||||||
tour_places.show_all ();
|
tour_places.show_all ();
|
||||||
tour_places.save_places.connect (on_save_places);
|
tour_places.save_places.connect (on_save_places);
|
||||||
}
|
}
|
||||||
|
else if (button == vehicle) {
|
||||||
|
var tour_assign_vehicle = new TourAssignVehicle (application, conn, tour);
|
||||||
|
tour_assign_vehicle.set_transient_for (this); // Set this window as the parent of the new window
|
||||||
|
tour_assign_vehicle.initialize ();
|
||||||
|
tour_assign_vehicle.show_all ();
|
||||||
|
tour_assign_vehicle.save_vehicle.connect (on_save_vehicle);
|
||||||
|
}
|
||||||
else if (button == cancel) {
|
else if (button == cancel) {
|
||||||
this.close ();
|
this.close ();
|
||||||
}
|
}
|
||||||
@ -424,6 +444,15 @@ namespace Sernatur {
|
|||||||
places.sensitive = false;
|
places.sensitive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a vehcile is assigned to the tour, and the tour is not in the database yet
|
||||||
|
* @param tour_assign_vehicle The TourAssignVehicle instance that called this signal
|
||||||
|
* @param vehicle The vehicle to assign to this tour
|
||||||
|
*/
|
||||||
|
private void on_save_vehicle (TourAssignVehicle tour_assign_vehicle, Vehiculo vehiculo) {
|
||||||
|
this.vehiculo = vehiculo;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the the tour object with new info from the editor
|
* Update the the tour object with new info from the editor
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user