diff --git a/data/ui/main.window.ui b/data/ui/main.window.ui index d7ab732..2484dca 100644 --- a/data/ui/main.window.ui +++ b/data/ui/main.window.ui @@ -20,7 +20,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND False SERNATUR center - sernatur diff --git a/data/ui/query.window.ui b/data/ui/query.window.ui index 0c93b5a..d73bc23 100644 --- a/data/ui/query.window.ui +++ b/data/ui/query.window.ui @@ -24,7 +24,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 800 600 True - sernatur dialog True True diff --git a/data/ui/tour.editor.ui b/data/ui/tour.editor.ui index 275f3ba..d5ab5ed 100644 --- a/data/ui/tour.editor.ui +++ b/data/ui/tour.editor.ui @@ -30,7 +30,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND True center-on-parent True - sernatur dialog True True @@ -301,6 +300,25 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 0 + + + Places + True + True + True + Add or edit places. + 5 + 5 + 5 + 5 + + + + False + True + 1 + + Save @@ -317,7 +335,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND False True - 1 + 2 diff --git a/data/ui/tour.gresource.xml b/data/ui/tour.gresource.xml index 6fd11f1..b1bbe8d 100644 --- a/data/ui/tour.gresource.xml +++ b/data/ui/tour.gresource.xml @@ -16,5 +16,6 @@ tour.list.ui tour.editor.ui + tour.places.ui diff --git a/data/ui/tour.list.ui b/data/ui/tour.list.ui index 7453577..ac072be 100644 --- a/data/ui/tour.list.ui +++ b/data/ui/tour.list.ui @@ -25,7 +25,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND center-on-parent 480 True - sernatur dialog True True @@ -59,6 +58,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND True + multiple @@ -198,10 +198,10 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND Delete True + False True True Delete selected tour. - baseline @@ -215,6 +215,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND True True True + Close this window. diff --git a/data/ui/tour.places.ui b/data/ui/tour.places.ui new file mode 100644 index 0000000..d390332 --- /dev/null +++ b/data/ui/tour.places.ui @@ -0,0 +1,262 @@ + + + + + + + diff --git a/lib/db.vala b/lib/db.vala index 7071579..f29931c 100644 --- a/lib/db.vala +++ b/lib/db.vala @@ -29,7 +29,11 @@ namespace LibSernatur { /** * Connection error */ - CONNECT + CONNECT, + /** + * Escape error + */ + ESCAPE } /** @@ -49,7 +53,7 @@ namespace LibSernatur { /** * Class to handle database connections */ - public class Connection : GLib.Object { + public class Connection : Object { /** * The database connection */ @@ -71,7 +75,26 @@ namespace LibSernatur { if (db.get_status () != Postgres.ConnectionStatus.OK) { throw new PostgresError.CONNECT (db.get_error_message ()); } - GLib.print (dgettext (null, "Postgresql server version:") + " %d\n", db.get_server_version ()); + GLib.print (_ ("Postgresql server version:") + " %d\n", db.get_server_version ()); + } + + /** + * Escape a string to be safe to use in Postgresql queries + * @param str The string to escape + * @return Returns the escaped string + * @throws PostgresError Thrown if there was some problem escaping the string + */ + public string escape (string str) throws PostgresError { + string* to = malloc ((sizeof (string) * str.length * 2) + 1); // to has to be double the size of str + 1 + int error_code; + db.escape_string_conn (to, str, str.length, out error_code); + if (error_code != 0) { + throw new PostgresError.ESCAPE (db.get_error_message ()); + } + + string result = to; + free (to); + return result; } } } diff --git a/lib/db/arrienda.vala b/lib/db/arrienda.vala index 06fe72c..7cf898a 100644 --- a/lib/db/arrienda.vala +++ b/lib/db/arrienda.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Arrienda class based on the database table */ - public class Arrienda : GLib.Object { + public class Arrienda : Object { /** * The price */ @@ -54,11 +54,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Arrienda */ - public static List get_all_arriendas (Database conn) { - var res = conn.exec (" + public static List get_all_arriendas (Connection conn) { + var res = conn.db.exec (" SELECT A.precio, A.fecha_devolucion, V.patente, V.ano_vehiculo, V.marca, V.capacidad, E.rut_empresa, E.nombre_empresa, E.contacto, E.telefono @@ -68,9 +68,9 @@ JOIN empresa E ON (A.rut_empresa = E.rut_empresa) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/asociado.vala b/lib/db/asociado.vala index 7518aa0..4db5e80 100644 --- a/lib/db/asociado.vala +++ b/lib/db/asociado.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Asociado class based on the database table */ - public class Asociado : GLib.Object { + public class Asociado : Object { public string fecha_llegada { get; set; default = ""; } public string hora_llegada { get; set; default = ""; } public string fecha_salida { get; set; default = ""; } @@ -48,11 +48,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Asociado */ - public static List get_all_asociados (Database conn) { - var res = conn.exec (" + public static List get_all_asociados (Connection conn) { + var res = conn.db.exec (" SELECT A.fecha_llegada, A.hora_llegada, A.fecha_salida, A.hora_salida, T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas, C.id_ciudad, C.nombre_ciudad, @@ -70,9 +70,9 @@ JOIN region R2 ON (C2.id_region = R2.id_region) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } @@ -99,7 +99,72 @@ JOIN region R2 ON (C2.id_region = R2.id_region) ) ), new Lugar (wra.get_int_n (i, "id_lugar"), + wra.get_string_n (i, "nombre_lugar"), + wra.get_int_n (i, "valor_entrada"), + wra.get_int_n (i, "nivel"), + new Ciudad (wra.get_int_n (i, "id_ciudad_lugar"), + wra.get_string_n (i, "nombre_ciudad_lugar"), + new Region (wra.get_int_n (i, "id_region_lugar"), + wra.get_string_n (i, "nombre_region_lugar") + ) + ) + ) + ); + list.append (asociado); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + + /** + * Get all tuples and fields from database + * @param conn.db.The database conn.db.ction to use + * @return Returns a list of Asociado based off a tour id + */ + public static List get_all_asociados_by_tour (Connection conn, Tour tour) throws PostgresError, DBError { + if (tour.id_tour == 0) { + throw new DBError.INVALID_VALUE (dgettext (null, "The id of the tour is invalid!")); + } + var res = conn.db.exec (Query.get_query (conn, Query.Type.SELECT_ALL_ASSOCIATED_BY_TOUR, tour)); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.db.get_error_message ()); + #else + warning (conn.db.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var asociado = new Asociado (wra.get_string_n (i, "fecha_llegada"), + wra.get_string_n (i, "hora_llegada"), + wra.get_string_n (i, "fecha_salida"), + wra.get_string_n (i, "hora_salida"), + new Tour (wra.get_int_n (i, "id_tour"), wra.get_string_n (i, "nombre_tour"), + wra.get_int_n (i, "costo_indiv"), + wra.get_int_n (i, "costo_grupal"), + wra.get_int_n (i, "minima_personas"), + new Ciudad (wra.get_int_n (i, "id_ciudad"), + wra.get_string_n (i, "nombre_ciudad"), + new Region (wra.get_int_n (i, "id_region"), + wra.get_string_n (i, "nombre_region") + ) + ) + ), + new Lugar (wra.get_int_n (i, "id_lugar"), + wra.get_string_n (i, "nombre_lugar"), wra.get_int_n (i, "valor_entrada"), wra.get_int_n (i, "nivel"), new Ciudad (wra.get_int_n (i, "id_ciudad_lugar"), diff --git a/lib/db/categoria.vala b/lib/db/categoria.vala index a026d76..c34d2d9 100644 --- a/lib/db/categoria.vala +++ b/lib/db/categoria.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Categoria class based on the database table */ - public class Categoria : GLib.Object { + public class Categoria : Object { /** * The id of the category */ @@ -42,18 +42,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Categoria */ - public static List get_all_categorias (Database conn) { - var res = conn.exec (" + public static List get_all_categorias (Connection conn) { + var res = conn.db.exec (" SELECT id_categoria, descripcion_categoria FROM categoria "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/ciudad.vala b/lib/db/ciudad.vala index efa1322..f227f93 100644 --- a/lib/db/ciudad.vala +++ b/lib/db/ciudad.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Ciudad class based on the database table */ - public class Ciudad : GLib.Object { + public class Ciudad : Object { /** * The id of the city */ @@ -48,11 +48,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Ciudad */ - public static List get_all_ciudades (Database conn) { - var res = conn.exec (" + public static List get_all_ciudades (Connection conn) { + var res = conn.db.exec (" SELECT C.id_ciudad, C.nombre_ciudad, R.id_region, R.nombre_region FROM ciudad C @@ -60,9 +60,9 @@ JOIN region R ON (C.id_region = R.id_region) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } @@ -93,12 +93,12 @@ JOIN region R ON (C.id_region = R.id_region) /** * Get all tuples and fields from database that are within a certain region - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @param region_id The id of the region to filter that results * @return Returns a list of Ciudad */ - public static List get_all_ciudades_in_region(Database conn, uint region_id) { - var res = conn.exec (" + public static List get_all_ciudades_in_region(Connection conn, uint region_id) { + var res = conn.db.exec (" SELECT C.id_ciudad, C.nombre_ciudad, R.id_region, R.nombre_region FROM ciudad C @@ -107,9 +107,9 @@ WHERE (R.id_region = " + region_id.to_string () + ") "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/contacto_emergencia.vala b/lib/db/contacto_emergencia.vala index a37534c..db398a9 100644 --- a/lib/db/contacto_emergencia.vala +++ b/lib/db/contacto_emergencia.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The ContactoEmergencia class based on the database table */ - public class ContactoEmergencia : GLib.Object { + public class ContactoEmergencia : Object { /** * The id of the contact */ @@ -48,16 +48,16 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of ContactoEmergencia */ - public static List get_all_contactos (Database conn) { - var res = conn.exec ("SELECT id_contacto, telefono_emergencia, nombre_emergencia FROM contacto_emergencia"); + public static List get_all_contactos (Connection conn) { + var res = conn.db.exec ("SELECT id_contacto, telefono_emergencia, nombre_emergencia FROM contacto_emergencia"); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/descuento.vala b/lib/db/descuento.vala index 0213403..08d13ba 100644 --- a/lib/db/descuento.vala +++ b/lib/db/descuento.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Descuento class based on the database table */ - public class Descuento : GLib.Object { + public class Descuento : Object { /** * The id of the discount */ @@ -48,18 +48,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Descuento */ - public static List get_all_descuentos (Database conn) { - var res = conn.exec (" + public static List get_all_descuentos (Connection conn) { + var res = conn.db.exec (" SELECT id_descuento, descripcion_descuento, porcentaje FROM descuento "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/empresa.vala b/lib/db/empresa.vala index 3f306c4..91ec1fa 100644 --- a/lib/db/empresa.vala +++ b/lib/db/empresa.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Empresa class based on the database table */ - public class Empresa : GLib.Object { + public class Empresa : Object { /** * The RUT of the company */ @@ -54,18 +54,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Empresa */ - public static List get_all_empresas (Database conn) { - var res = conn.exec (" + public static List get_all_empresas (Connection conn) { + var res = conn.db.exec (" SELECT rut_empresa, nombre_empresa, contacto, telefono FROM empresa "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/enfermedad.vala b/lib/db/enfermedad.vala index b7c9795..03897d0 100644 --- a/lib/db/enfermedad.vala +++ b/lib/db/enfermedad.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Enfermedad class based on the database table */ - public class Enfermedad : GLib.Object { + public class Enfermedad : Object { /** * The id of the illness */ @@ -42,18 +42,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Enfermedad */ - public static List get_all_enfermedades (Database conn) { - var res = conn.exec (" + public static List get_all_enfermedades (Connection conn) { + var res = conn.db.exec (" SELECT id_enfermedad, descripcion_enfermedad FROM enfermedad "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/especialidad.vala b/lib/db/especialidad.vala index 1bdb0ea..6cecd4c 100644 --- a/lib/db/especialidad.vala +++ b/lib/db/especialidad.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Esepcialidad class based on the database table */ - public class Especialidad : GLib.Object { + public class Especialidad : Object { /** * The id of the specialty */ @@ -42,18 +42,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Especialidad */ - public static List get_all_especialidades (Database conn) { - var res = conn.exec (" + public static List get_all_especialidades (Connection conn) { + var res = conn.db.exec (" SELECT id_especialidad, descripcion_especialidad FROM especialidad "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/guia.vala b/lib/db/guia.vala index 6b2dd05..44cd2ce 100644 --- a/lib/db/guia.vala +++ b/lib/db/guia.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Guia class based on the database table */ - public class Guia : GLib.Object { + public class Guia : Object { /** * The RUT of the guide */ @@ -60,11 +60,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Guia */ - public static List get_all_guias (Database conn) { - var res = conn.exec (" + public static List get_all_guias (Connection conn) { + var res = conn.db.exec (" SELECT G.rut_guia, G.nombre_guia, G.calle, G.numero, C.id_ciudad, C.nombre_ciudad, R.id_region, R.nombre_region @@ -74,9 +74,9 @@ JOIN region R ON (C.id_region = R.id_region) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/lugar.vala b/lib/db/lugar.vala index c1d1569..6e2205a 100644 --- a/lib/db/lugar.vala +++ b/lib/db/lugar.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Lugar class based on the database table */ - public class Lugar : GLib.Object { + public class Lugar : Object { /** * The id of the place */ @@ -60,11 +60,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Lugar */ - public static List get_all_lugares (Database conn) { - var res = conn.exec (" + public static List get_all_lugares (Connection conn) { + var res = conn.db.exec (" SELECT L.id_lugar, L.nombre_lugar, L.valor_entrada, L.nivel, C.id_ciudad, C.nombre_ciudad, R.id_region, R.nombre_region @@ -74,9 +74,9 @@ JOIN region R ON (C.id_region = R.id_region) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/participa.vala b/lib/db/participa.vala index ddba6e4..01c8203 100644 --- a/lib/db/participa.vala +++ b/lib/db/participa.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Participa class based on the database table */ - public class Participa : GLib.Object { + public class Participa : Object { /** * The tour */ @@ -48,11 +48,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Participa */ - public static List get_all_participas (Database conn) { - var res = conn.exec (" + public static List get_all_participas (Connection conn) { + var res = conn.db.exec (" SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas, C.id_ciudad, C.nombre_ciudad, R.id_region, R.nombre_region, @@ -71,9 +71,9 @@ JOIN categoria C3 ON (P.id_categoria = C3.id_categoria) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/posee.vala b/lib/db/posee.vala index 975e420..55c6983 100644 --- a/lib/db/posee.vala +++ b/lib/db/posee.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Posee class based on the database table */ - public class Posee : GLib.Object { + public class Posee : Object { /** * The specialty level */ @@ -48,11 +48,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Posee */ - public static List get_all_posees (Database conn) { - var res = conn.exec (" + public static List get_all_posees (Connection conn) { + var res = conn.db.exec (" SELECT P.nivel_especialidad, G.rut_guia, G.nombre_guia, G.calle, G.numero, C.id_ciudad, C.nombre_ciudad, @@ -66,9 +66,9 @@ JOIN especialidad E ON (P.id_especialidad = E.id_especialidad) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/realiza.vala b/lib/db/realiza.vala index 166d828..942eaff 100644 --- a/lib/db/realiza.vala +++ b/lib/db/realiza.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Realiza class based on the database table */ - public class Realiza : GLib.Object { + public class Realiza : Object { /** * The tour */ @@ -48,11 +48,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Realiza */ - public static List get_all_realizas (Database conn) { - var res = conn.exec (" + public static List get_all_realizas (Connection conn) { + var res = conn.db.exec (" SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas, C.id_ciudad, C.nombre_ciudad, R.id_region, R.nombre_region, @@ -69,9 +69,9 @@ JOIN descuento D ON (RE.id_descuento = D.id_descuento) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/region.vala b/lib/db/region.vala index 90c27e3..c881074 100644 --- a/lib/db/region.vala +++ b/lib/db/region.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Region class based on the database table */ - public class Region : GLib.Object { + public class Region : Object { /** * The id of the region */ @@ -42,18 +42,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Region */ - public static List get_all_regiones (Database conn) { - var res = conn.exec (" + public static List get_all_regiones (Connection conn) { + var res = conn.db.exec (" SELECT id_region, nombre_region FROM region "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/regiones_sin_descuento.vala b/lib/db/regiones_sin_descuento.vala index 550c8aa..ddb7b37 100644 --- a/lib/db/regiones_sin_descuento.vala +++ b/lib/db/regiones_sin_descuento.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The RegionesSinDescuento class based on the database table */ - public class RegionesSinDescuento : GLib.Object { + public class RegionesSinDescuento : Object { /** * The name of the region */ @@ -41,18 +41,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of RegionesSinDescuento */ - public static List get_all_regions_without_discount (Database conn) { - var res = conn.exec (" + public static List get_all_regions_without_discount (Connection conn) { + var res = conn.db.exec (" SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/requerir_auto.vala b/lib/db/requerir_auto.vala index 64de523..ca2e141 100644 --- a/lib/db/requerir_auto.vala +++ b/lib/db/requerir_auto.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The RequerirAuto class based on the database table */ - public class RequerirAuto : GLib.Object { + public class RequerirAuto : Object { /** * The chofer */ @@ -48,11 +48,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of RequerirAuto */ - public static List get_all_requerir_autos (Database conn) { - var res = conn.exec (" + public static List get_all_requerir_autos (Connection conn) { + var res = conn.db.exec (" SELECT R.chofer, T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas, C.id_ciudad, C.nombre_ciudad, @@ -66,9 +66,9 @@ Join vehiculo V ON (R.patente = V.patente) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/tiene_enfermedad.vala b/lib/db/tiene_enfermedad.vala index 517580d..3eb8bd6 100644 --- a/lib/db/tiene_enfermedad.vala +++ b/lib/db/tiene_enfermedad.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The TieneEnfermedad class based on the database table */ - public class TieneEnfermedad : GLib.Object { + public class TieneEnfermedad : Object { /** * The tourist */ @@ -42,11 +42,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of TieneEnfermedad */ - public static List get_all_tiene_enfermedades (Database conn) { - var res = conn.exec (" + public static List get_all_tiene_enfermedades (Connection conn) { + var res = conn.db.exec (" SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento, C.id_contacto, C.telefono_emergencia, C.nombre_emergencia, E.id_enfermedad, E.descripcion_enfermedad @@ -57,9 +57,9 @@ JOIN enfermedad E ON (TE.id_enfermedad = E.id_enfermedad) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/total_arriendos.vala b/lib/db/total_arriendos.vala index fc67006..050f486 100644 --- a/lib/db/total_arriendos.vala +++ b/lib/db/total_arriendos.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The TotalArriendos class based on the database table */ - public class TotalArriendos : GLib.Object { + public class TotalArriendos : Object { /** * The total of rented vehicles */ @@ -36,18 +36,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of TotalArriendos */ - public static List get_all_rent_totals (Database conn) { - var res = conn.exec (" + public static List get_all_rent_totals (Connection conn) { + var res = conn.db.exec (" SELECT TotalArriendo FROM TOTAL_ARRIENDOS "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/total_coordinadores.vala b/lib/db/total_coordinadores.vala index c187a3b..d5f7ba0 100644 --- a/lib/db/total_coordinadores.vala +++ b/lib/db/total_coordinadores.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The TotalCoordinadores class based on the database table */ - public class TotalCoordinadores : GLib.Object { + public class TotalCoordinadores : Object { /** * The id of the region */ @@ -48,18 +48,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of TotalCoordinadores */ - public static List get_all_coordinator_totals (Database conn) { - var res = conn.exec (" + public static List get_all_coordinator_totals (Connection conn) { + var res = conn.db.exec (" SELECT idT, nombreT, TotalCoordinadores FROM TOTAL_COORDINADORES "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/total_turistas.vala b/lib/db/total_turistas.vala index 0f31600..6e73907 100644 --- a/lib/db/total_turistas.vala +++ b/lib/db/total_turistas.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The TotalTuristas class based on the database table */ - public class TotalTuristas : GLib.Object { + public class TotalTuristas : Object { /** * The id of the tour */ @@ -48,18 +48,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of TotalTuristas */ - public static List get_all_tourist_totals (Database conn) { - var res = conn.exec (" + public static List get_all_tourist_totals (Connection conn) { + var res = conn.db.exec (" SELECT idT, nombreT, TotalTuristas FROM TOTAL_TURISTAS "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/total_vehiculos.vala b/lib/db/total_vehiculos.vala index 483b539..7b9b6fe 100644 --- a/lib/db/total_vehiculos.vala +++ b/lib/db/total_vehiculos.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The TotalVehiculos class based on the database table */ - public class TotalVehiculos : GLib.Object { + public class TotalVehiculos : Object { /** * The total of vehicles */ @@ -36,18 +36,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of TotalVehiculos */ - public static List get_all_vehicle_totals (Database conn) { - var res = conn.exec (" + public static List get_all_vehicle_totals (Connection conn) { + var res = conn.db.exec (" SELECT TotalVeh FROM TOTAL_VEHICULOS "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/tour.vala b/lib/db/tour.vala index 720bb70..1578b7b 100644 --- a/lib/db/tour.vala +++ b/lib/db/tour.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Tour class based on the database table */ - public class Tour : GLib.Object { + public class Tour : Object { /** * The tour id */ @@ -69,13 +69,13 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Tour */ - public static List get_all_tours (Database conn) { - var res = conn.exec (Query.get_query (Query.Type.SELECT_ALL_TOURS, null)); + public static List get_all_tours (Connection conn) throws PostgresError { + var res = conn.db.exec (Query.get_query (conn, Query.Type.SELECT_ALL_TOURS, null)); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } @@ -116,16 +116,51 @@ namespace LibSernatur { * @param tour The tour to update * @throws DBError Thrown if the data in the object is invalid */ - public static void update_tour (Database conn, Tour tour) throws DBError { + public static void update_tour (Connection conn, Tour tour) throws PostgresError, DBError { if (tour.id_tour == 0) { throw new DBError.INVALID_VALUE (dgettext (null, "The id of the tour is invalid!")); } - var res = conn.exec (Query.get_query (Query.Type.UPDATE_TOUR, tour)); + var res = conn.db.exec (Query.get_query (conn, Query.Type.UPDATE_TOUR, tour)); if (res.get_status () != ExecStatus.COMMAND_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); + #endif + } + } + + /** + * Insert a tour in the database + * @param conn The database connection + * @param tour The tour to insert + * @return Returns the id of the tuple inserted + * @throws DBError Thrown if the data in the object is invalid + */ + public static uint insert_tour (Connection conn, Tour tour) throws PostgresError, DBError { + if (tour.id_tour != 0) { + throw new DBError.INVALID_VALUE (dgettext (null, "The id of the tour is invalid!")); + } + var res = conn.db.exec (Query.get_query (conn, Query.Type.INSERT_TOUR, tour)); + // This uses TUPLES_OK because it returns a result which is hte id of the inserted tour + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.db.get_error_message ()); + #else + warning (conn.db.get_error_message ()); + #endif + } + + var wra = new ResultWrapper (res); + try { + return wra.get_int_n (0, "id_tour"); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + return 0; #endif } } @@ -136,19 +171,19 @@ namespace LibSernatur { * @param tour The tour to update * @throws DBError Thrown if the data in the object is invalid */ - public static void delete_tour (Database conn, Tour tour) throws DBError { + public static void delete_tour (Connection conn, Tour tour) throws PostgresError, DBError { if (tour.id_tour == 0) { throw new DBError.INVALID_VALUE (dgettext (null, "The id of the tour is invalid!")); } - var res = conn.exec (Query.get_query (Query.Type.DELETE_TOUR, tour)); + var res = conn.db.exec (Query.get_query (conn, Query.Type.DELETE_TOUR, tour)); if (res.get_status () != ExecStatus.COMMAND_OK) { if (res.get_error_field (FieldCode.SQLSTATE) == "23503") { throw new DBError.FOREIGN_KEY_CONSTAINT (res.get_error_field (FieldCode.MESSAGE_PRIMARY)); } #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); #endif } } diff --git a/lib/db/turista.vala b/lib/db/turista.vala index 995e880..0dbe697 100644 --- a/lib/db/turista.vala +++ b/lib/db/turista.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Turista class based on the database table */ - public class Turista : GLib.Object { + public class Turista : Object { /** * The RUT of the tourist */ @@ -54,11 +54,11 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Turista */ - public static List get_all_turistas (Database conn) { - var res = conn.exec (" + public static List get_all_turistas (Connection conn) { + var res = conn.db.exec (" SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento, C.id_contacto, C.telefono_emergencia, C.nombre_emergencia FROM turista T @@ -66,9 +66,9 @@ JOIN contacto_emergencia C ON (T.id_contacto = C.id_contacto) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/valores_tours.vala b/lib/db/valores_tours.vala index 10436b7..e28f0a0 100644 --- a/lib/db/valores_tours.vala +++ b/lib/db/valores_tours.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The ValoresTours class based on the database table */ - public class ValoresTours : GLib.Object { + public class ValoresTours : Object { /** * The id of the tour */ @@ -48,18 +48,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of ValoresTours */ - public static List get_all_tour_sales (Database conn) { - var res = conn.exec (" + public static List get_all_tour_sales (Connection conn) { + var res = conn.db.exec (" SELECT idT, nombreT, TotalVentas FROM VALORES_TOURS "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/vehiculo.vala b/lib/db/vehiculo.vala index e57f3a9..255c53b 100644 --- a/lib/db/vehiculo.vala +++ b/lib/db/vehiculo.vala @@ -20,7 +20,7 @@ namespace LibSernatur { /** * The Vehiculo class based on the database table */ - public class Vehiculo : GLib.Object { + public class Vehiculo : Object { /** * The license plate */ @@ -54,18 +54,18 @@ namespace LibSernatur { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Vehiculo */ - public static List get_all_vehiculos (Database conn) { - var res = conn.exec (" + public static List get_all_vehiculos (Connection conn) { + var res = conn.db.exec (" SELECT patente, ano_vehiculo, marca, capacidad FROM vehiculo "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/db/views.vala b/lib/db/views.vala index 30730af..dce46b3 100644 --- a/lib/db/views.vala +++ b/lib/db/views.vala @@ -24,21 +24,21 @@ namespace LibSernatur { /** * The Q1 class based on the database table */ - public class Q1 : GLib.Object { + public class Q1 : Object { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of RegionesSinDescuento */ - public static List get_regions_without_discount (Database conn) { - var res = conn.exec (" + public static List get_regions_without_discount (Connection conn) { + var res = conn.db.exec (" SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELECT MAX(cantidad) FROM REGIONES_SINDESCUENTO)) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } @@ -68,7 +68,7 @@ SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELE /** * The Q2 class based on the database table */ - public class Q2 : GLib.Object { + public class Q2 : Object { /** * The name of the tour */ @@ -90,19 +90,19 @@ SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELE /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Q2 */ - public static List get_value_received (Database conn) { - var res = conn.exec (" + public static List get_value_received (Connection conn) { + var res = conn.db.exec (" SELECT V.nombreT, (V.TotalVentas - COALESCE(MAX(T.TotalDescuentos), 0)) AS ValorTotalRecibido FROM VALORES_TOURS V FULL JOIN TOUR_DESCUENTOS T ON (T.idT = V.idT) GROUP BY (V.nombreT, V.TotalVentas) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } @@ -132,22 +132,22 @@ FROM VALORES_TOURS V FULL JOIN TOUR_DESCUENTOS T ON (T.idT = V.idT) GROUP BY (V. /** * The Q3 class based on the database table */ - public class Q3 : GLib.Object { + public class Q3 : Object { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of TotalCoordinadores */ - public static List get_total_coordinators (Database conn) { - var res = conn.exec (" + public static List get_total_coordinators (Connection conn) { + var res = conn.db.exec (" SELECT nombreT, TotalCoordinadores FROM TOTAL_COORDINADORES WHERE (TotalCoordinadores = (SELECT MAX(TotalCoordinadores) FROM TOTAL_COORDINADORES)) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } @@ -178,21 +178,21 @@ FROM TOTAL_COORDINADORES WHERE (TotalCoordinadores = (SELECT MAX(TotalCoordinado /** * The Q4 class based on the database table */ - public class Q4 : GLib.Object { + public class Q4 : Object { /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of TotalTuristas */ - public static List get_total_tourists (Database conn) { - var res = conn.exec (" + public static List get_total_tourists (Connection conn) { + var res = conn.db.exec (" SELECT nombreT, TotalTuristas FROM TOTAL_TURISTAS WHERE (TotalTuristas = (SELECT MAX(TotalTuristas) FROM TOTAL_TURISTAS)) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } @@ -223,7 +223,7 @@ SELECT nombreT, TotalTuristas FROM TOTAL_TURISTAS WHERE (TotalTuristas = (SELECT /** * The Q5 class based on the database table */ - public class Q5 : GLib.Object { + public class Q5 : Object { /** * The percentage of cars that were rented and used */ @@ -239,20 +239,20 @@ SELECT nombreT, TotalTuristas FROM TOTAL_TURISTAS WHERE (TotalTuristas = (SELECT /** * Get all tuples and fields from database - * @param conn The database connection to use + * @param conn.db.The database conn.db.ction to use * @return Returns a list of Q5 */ - public static List get_percentage (Database conn) { - var res = conn.exec (" + public static List get_percentage (Connection conn) { + var res = conn.db.exec (" SELECT (cast(T1.totalarriendo AS DECIMAL(3,2)) / cast(T2.totalveh AS DECIMAL(3,2))) AS porcentaje FROM total_arriendos AS T1, total_vehiculos AS T2 "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG - error (conn.get_error_message ()); + error (conn.db.get_error_message ()); #else - warning (conn.get_error_message ()); + warning (conn.db.get_error_message ()); return new List (); #endif } diff --git a/lib/dbwrapper.vala b/lib/dbwrapper.vala index b33966e..648e704 100644 --- a/lib/dbwrapper.vala +++ b/lib/dbwrapper.vala @@ -33,7 +33,7 @@ namespace LibSernatur { /** * This is a wrapper for Postgresql results */ - public class ResultWrapper : GLib.Object { + public class ResultWrapper : Object { /** * The result that this is wrapped around */ @@ -135,7 +135,7 @@ namespace LibSernatur { */ private int check_field_found (int field_num, string name) throws Field { if (field_num == -1) { - throw new Field.NOTFOUND (dgettext (null, "The field %s was not found in the query results!"), name); + throw new Field.NOTFOUND (_ ("The field %s was not found in the query results!"), name); } return field_num; } diff --git a/lib/misc.vala b/lib/misc.vala index d1f136b..e54e001 100644 --- a/lib/misc.vala +++ b/lib/misc.vala @@ -39,7 +39,7 @@ namespace LibSernatur { /** * This class converts a float or double into a percentage string */ - public class Percentage : GLib.Object { + public class Percentage : Object { /** * Format a float into a percentage string * @param value The value to convert @@ -63,7 +63,7 @@ namespace LibSernatur { /** * This class handles making money look pretty */ - public class Money : GLib.Object { + public class Money : Object { /** * Format an int to look pretty * @param value The value to format @@ -131,7 +131,7 @@ namespace LibSernatur { /** * This class handles parsing and validation of RUTs */ - public class Rut : GLib.Object { + public class Rut : Object { /** * The cleaned RUT */ @@ -177,7 +177,7 @@ namespace LibSernatur { try { var regex = new Regex ("^[ ]*([0-9.]{0,11}[\\-]?[0-9kK])?[ ]*$"); if (!regex.match (rut)) { - throw new InvalidRut.INVALID (dgettext (null, "The RUT %s has an invalid character!"), rut); + throw new InvalidRut.INVALID (_ ("The RUT %s has an invalid character!"), rut); } } catch (Error e) { @@ -193,12 +193,12 @@ namespace LibSernatur { new_rut = new_rut.strip (); rut = regex.replace (new_rut, new_rut.length, 0, ""); if (int.parse (rut.substring (0, rut.length - 1)) > 100000000) { - throw new InvalidRut.TOOLARGE (dgettext (null, "The RUT %s is too big!"), rut); + throw new InvalidRut.TOOLARGE (_ ("The RUT %s is too big!"), rut); } this.verifier = rut.get_char (rut.length - 1); this.clean_rut = rut.substring (0, rut.length - 1); if (generate_verfifier (this.clean_rut) != this.verifier) { - throw new InvalidRut.INVALIDVERIFIER (dgettext (null, "The verifier %C is invalid!"), this.verifier); + throw new InvalidRut.INVALIDVERIFIER (_ ("The verifier %C is invalid!"), this.verifier); } pretty(); } diff --git a/lib/queries.vala b/lib/queries.vala index 11b69c9..0aaef9e 100644 --- a/lib/queries.vala +++ b/lib/queries.vala @@ -17,15 +17,16 @@ namespace LibSernatur { /** * The queries to use to work in the database */ - public class Query < T > : GLib.Object { + public class Query < T > : Object { public enum Type { SELECT_ALL_TOURS, INSERT_TOUR, UPDATE_TOUR, - DELETE_TOUR + DELETE_TOUR, + SELECT_ALL_ASSOCIATED_BY_TOUR } - public static string get_query (Type type, T? t) { + public static string get_query (Connection conn, Type type, T? t) throws PostgresError { switch (type) { case SELECT_ALL_TOURS: return " @@ -39,16 +40,49 @@ JOIN region R ON (C.id_region = R.id_region)"; Tour tour = (Tour) t; return " UPDATE tour SET - nombre_tour = '" + tour.nombre_tour + "', + nombre_tour = '" + conn.escape (tour.nombre_tour) + "', costo_indiv = " + tour.costo_indiv.to_string () + ", costo_grupal = " + tour.costo_grupal.to_string () + ", - minima_personas = " + tour.minima_personas.to_string () + " + minima_personas = " + tour.minima_personas.to_string () + ", + id_ciudad = " + tour.ciudad.id_ciudad.to_string () + " WHERE id_tour = " + tour.id_tour.to_string (); + case INSERT_TOUR: + Tour tour = (Tour) t; + return " +INSERT INTO tour +(nombre_tour, costo_indiv, costo_grupal, minima_personas, id_ciudad) +VALUES +( +'" + conn.escape (tour.nombre_tour) + "', +" + tour.costo_indiv.to_string () + ", +" + tour.costo_grupal.to_string () + ", +" + tour.minima_personas.to_string () + ", +" + tour.ciudad.id_ciudad.to_string () + " +) +RETURNING id_tour"; case DELETE_TOUR: Tour tour = (Tour) t; return " DELETE FROM tour WHERE id_tour = " + tour.id_tour.to_string (); + case SELECT_ALL_ASSOCIATED_BY_TOUR: + Tour tour = (Tour) t; + return " +SELECT A.fecha_llegada, A.hora_llegada, A.fecha_salida, A.hora_salida, +T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas, +C.id_ciudad, C.nombre_ciudad, +R.id_region, R.nombre_region, +L.id_lugar, L.nombre_lugar, L.valor_entrada, L.nivel, +C2.id_ciudad AS id_ciudad_lugar, C2.nombre_ciudad AS nombre_ciudad_lugar, +R2.id_region AS id_region_lugar, R2.nombre_region AS nombre_region_lugar +FROM asociado A +JOIN tour T ON (A.id_tour = T.id_tour) +JOIN ciudad C ON (T.id_ciudad = C.id_ciudad) +JOIN region R ON (C.id_region = R.id_region) +JOIN lugar L ON (A.id_lugar = L.id_lugar) +JOIN ciudad C2 ON (L.id_ciudad = C2.id_ciudad) +JOIN region R2 ON (C2.id_region = R2.id_region) +WHERE t.id_tour = " + tour.id_tour.to_string (); default: return ""; } diff --git a/po/LINGUAS b/po/LINGUAS index 8357fca..2cd6c1f 100644 --- a/po/LINGUAS +++ b/po/LINGUAS @@ -1 +1 @@ -es +es es_CL diff --git a/po/POTFILES b/po/POTFILES index dceb23c..8a0eb27 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -5,11 +5,13 @@ src/sernatur.vala src/main_window.vala src/tour_list.vala src/tour_editor.vala +src/tour_places.vala src/query_window.vala data/ui/main.window.ui data/ui/main.splash.ui data/ui/tour.list.ui data/ui/tour.editor.ui +data/ui/tour.places.ui data/ui/query.window.ui data/ui/query.tree.ui data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml diff --git a/po/es.po b/po/es.po index b3f3d6b..bc81e24 100644 --- a/po/es.po +++ b/po/es.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: sernatur\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-17 09:59-0300\n" -"PO-Revision-Date: 2019-01-17 10:01-0300\n" +"POT-Creation-Date: 2019-01-18 17:59-0300\n" +"PO-Revision-Date: 2019-01-18 18:02-0300\n" "Last-Translator: Chris Cromer \n" "Language-Team: none\n" "Language: es\n" @@ -47,7 +47,7 @@ msgstr "El verificador %C es invalido!" #: src/sernatur.vala:88 #, c-format msgid "Error: %s\n" -msgstr "Error %s\n" +msgstr "Error: %s\n" #: src/sernatur.vala:89 #, c-format @@ -65,39 +65,44 @@ msgstr "Versión de SERNATUR: " msgid "Error: Could not connect to the database!" msgstr "Error: No se puede conectar al base de datos!" -#: src/main_window.vala:228 src/tour_list.vala:205 src/tour_list.vala:220 +#: src/main_window.vala:228 src/tour_list.vala:215 src/tour_list.vala:231 msgid "Error" msgstr "Error" -#: src/tour_list.vala:181 +#: src/tour_list.vala:185 msgid "Are you sure you wish to delete this tour?" msgstr "¿Usted está seguro que quiere borrar este tour?" -#: src/tour_list.vala:201 -msgid "" -"Error: Could not delete tour because there are still associated arrival and " -"departure dates and times!" -msgstr "" -"Error: No se puede borrar el tour porque todavía hay fechas y horas de " -"llegada y salida asociado al tour!" +#: src/tour_list.vala:192 +msgid "Are you sure you wish to delete these tours?" +msgstr "¿Usted está seguro que quiere borrar estos tour?" -#: src/query_window.vala:290 data/ui/main.window.ui:143 +#: src/tour_list.vala:211 +#, c-format +msgid "" +"Error: Could not delete tour \"%s\" because either this tour has been taken " +"or is still associated with a place or vehicle!" +msgstr "" +"Error: No se puede borrar el tour \"%s\" porque este tour ya fue realizado " +"o todavía esta asociado con lugares ó vehículos!" + +#: src/query_window.vala:290 data/ui/main.window.ui:136 msgid "(Q1) Regions with discounts" msgstr "(Q1) Regiones sin descuentos" -#: src/query_window.vala:303 data/ui/main.window.ui:151 +#: src/query_window.vala:303 data/ui/main.window.ui:144 msgid "(Q2) Tour values" msgstr "(Q2) Valores tour" -#: src/query_window.vala:316 data/ui/main.window.ui:159 +#: src/query_window.vala:316 data/ui/main.window.ui:152 msgid "(Q3) Coordinator total" msgstr "(Q3) Total de coordinadores" -#: src/query_window.vala:329 data/ui/main.window.ui:167 +#: src/query_window.vala:329 data/ui/main.window.ui:160 msgid "(Q4) Tourist total" msgstr "(Q4) Total de turistas" -#: src/query_window.vala:342 data/ui/main.window.ui:175 +#: src/query_window.vala:342 data/ui/main.window.ui:168 msgid "(Q5) Vehicle total" msgstr "(Q5) Total de vehículos" @@ -110,34 +115,30 @@ msgid "Tours" msgstr "Tours" #: data/ui/main.window.ui:62 -msgid "Places" -msgstr "Lugares" - -#: data/ui/main.window.ui:69 msgid "Staff" msgstr "Empleados" -#: data/ui/main.window.ui:77 +#: data/ui/main.window.ui:70 msgid "Tourists" msgstr "Turistas" -#: data/ui/main.window.ui:87 +#: data/ui/main.window.ui:80 msgid "Illnesses" msgstr "Enfermedades" -#: data/ui/main.window.ui:95 +#: data/ui/main.window.ui:88 msgid "Participate" msgstr "Participar" -#: data/ui/main.window.ui:107 +#: data/ui/main.window.ui:100 msgid "Vehicles" msgstr "Vehículos" -#: data/ui/main.window.ui:121 +#: data/ui/main.window.ui:114 msgid "Quit" msgstr "Salir" -#: data/ui/main.window.ui:133 +#: data/ui/main.window.ui:126 msgid "_Views" msgstr "_Vistas" @@ -145,59 +146,64 @@ msgstr "_Vistas" msgid "Christopher Cromer" msgstr "Christopher Cromer" -#: data/ui/tour.list.ui:68 data/ui/tour.editor.ui:54 data/ui/query.tree.ui:80 +#: data/ui/tour.list.ui:69 data/ui/tour.editor.ui:54 data/ui/query.tree.ui:80 #: data/ui/query.tree.ui:120 data/ui/query.tree.ui:160 msgid "Tour Name" msgstr "Nombre del Tour" -#: data/ui/tour.list.ui:82 data/ui/tour.editor.ui:87 +#: data/ui/tour.list.ui:83 data/ui/tour.editor.ui:87 msgid "Individual Cost" msgstr "Costo Individual" -#: data/ui/tour.list.ui:96 data/ui/tour.editor.ui:103 +#: data/ui/tour.list.ui:97 data/ui/tour.editor.ui:103 msgid "Group Cost" msgstr "Costo Grupal" -#: data/ui/tour.list.ui:110 data/ui/tour.editor.ui:119 +#: data/ui/tour.list.ui:111 data/ui/tour.editor.ui:119 msgid "Minimum People" msgstr "Mínima Personas" -#: data/ui/tour.list.ui:124 data/ui/tour.editor.ui:187 +#: data/ui/tour.list.ui:125 data/ui/tour.editor.ui:187 msgid "City" msgstr "Ciudad" -#: data/ui/tour.list.ui:138 data/ui/tour.editor.ui:135 +#: data/ui/tour.list.ui:139 data/ui/tour.editor.ui:135 msgid "Region" msgstr "Región" -#: data/ui/tour.list.ui:170 +#: data/ui/tour.list.ui:171 data/ui/tour.places.ui:185 msgid "Edit" msgstr "Editar" -#: data/ui/tour.list.ui:175 +#: data/ui/tour.list.ui:176 msgid "Edit selected tour." msgstr "Editar el tour seleccionado." -#: data/ui/tour.list.ui:185 +#: data/ui/tour.list.ui:186 data/ui/tour.places.ui:243 msgid "New" msgstr "Nuevo" -#: data/ui/tour.list.ui:189 +#: data/ui/tour.list.ui:190 msgid "Create a new tour." msgstr "Crear un tour nuevo." -#: data/ui/tour.list.ui:199 +#: data/ui/tour.list.ui:200 data/ui/tour.places.ui:214 msgid "Delete" msgstr "Borrar" -#: data/ui/tour.list.ui:203 +#: data/ui/tour.list.ui:205 msgid "Delete selected tour." msgstr "Borrar el tour seleccionado." -#: data/ui/tour.list.ui:214 data/ui/query.window.ui:67 +#: data/ui/tour.list.ui:215 data/ui/tour.places.ui:229 +#: data/ui/query.window.ui:67 msgid "Close" msgstr "Cerrar" +#: data/ui/tour.list.ui:219 data/ui/tour.places.ui:233 +msgid "Close this window." +msgstr "Cerrar esta ventana." + #: data/ui/tour.editor.ui:29 msgid "Tour Editor" msgstr "Editor de Tour" @@ -218,14 +224,70 @@ msgstr "Cancelar" msgid "Cancel the modification of this tour." msgstr "Cancelar la modificación de este tour." -#: data/ui/tour.editor.ui:306 +#: data/ui/tour.editor.ui:306 data/ui/tour.places.ui:23 +msgid "Places" +msgstr "Lugares" + +#: data/ui/tour.editor.ui:310 +msgid "Add or edit places." +msgstr "Agregar o editar places." + +#: data/ui/tour.editor.ui:325 msgid "Save" msgstr "Guardar" -#: data/ui/tour.editor.ui:310 +#: data/ui/tour.editor.ui:329 msgid "Save this tour." msgstr "Guardar este tour." +#: data/ui/tour.places.ui:69 +msgid "Place Name" +msgstr "Nombre de Lugar" + +#: data/ui/tour.places.ui:83 +msgid "Ticket Price" +msgstr "Valor Entrada" + +#: data/ui/tour.places.ui:97 +msgid "Difficulty" +msgstr "Dificultad" + +#: data/ui/tour.places.ui:111 +msgid "Arrival Date" +msgstr "Fecha de Llegada" + +#: data/ui/tour.places.ui:125 +msgid "Arrival Time" +msgstr "Hora de Llegada" + +#: data/ui/tour.places.ui:139 +msgid "Departure Date" +msgstr "Fecha de Salida" + +#: data/ui/tour.places.ui:153 +msgid "Departure Time" +msgstr "Hora de Salida" + +#: data/ui/tour.places.ui:190 +msgid "Edit associated place." +msgstr "Edit lugar asociado." + +#: data/ui/tour.places.ui:200 +msgid "Add" +msgstr "Agregar" + +#: data/ui/tour.places.ui:204 +msgid "Associate this tour with an existing place." +msgstr "Asociar este tour con un lugar que ya existe." + +#: data/ui/tour.places.ui:219 +msgid "Delete associated place." +msgstr "Borrar lugar asociado." + +#: data/ui/tour.places.ui:247 +msgid "Create a new place to associate." +msgstr "Crear un lugar nuevo para asociar con el tour." + #: data/ui/query.window.ui:85 msgid "Run" msgstr "Correr" diff --git a/po/es_CL.po b/po/es_CL.po new file mode 100644 index 0000000..5e8d198 --- /dev/null +++ b/po/es_CL.po @@ -0,0 +1,374 @@ +# Spanish translations for sernatur package. +# Copyright (C) 2018-2019 THE sernatur'S COPYRIGHT HOLDER +# This file is distributed under the same license as the sernatur package. +# Automatically generated, 2019. +# +msgid "" +msgstr "" +"Project-Id-Version: sernatur\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-01-18 17:59-0300\n" +"PO-Revision-Date: 2019-01-18 18:02-0300\n" +"Last-Translator: Chris Cromer \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.0.6\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-Basepath: .\n" + +#: lib/db.vala:74 +msgid "Postgresql server version:" +msgstr "Versión de la wea de Postgresql:" + +#: lib/dbwrapper.vala:138 +#, c-format +msgid "The field %s was not found in the query results!" +msgstr "La wea %s no estaba en los resultados de la wea!" + +#: lib/misc.vala:180 +#, c-format +msgid "The RUT %s has an invalid character!" +msgstr "La wea %s tiene una wea invalido!" + +#: lib/misc.vala:196 +#, c-format +msgid "The RUT %s is too big!" +msgstr "La wea %s es demasiado grande!" + +#: lib/misc.vala:201 +#, c-format +msgid "The verifier %C is invalid!" +msgstr "La wea %C es invalido!" + +#: src/sernatur.vala:88 +#, c-format +msgid "Error: %s\n" +msgstr "Puta la wea: %s\n" + +#: src/sernatur.vala:89 +#, c-format +msgid "Run '%s --help' to see a full list of available command line options.\n" +msgstr "" +"Correr '%s --help' para ver una lista completa de las weas que se puede usar " +"en la consola.\n" + +#: src/sernatur.vala:94 +msgid "SERNATUR version: " +msgstr "Versión de SERNATUR: " + +#: src/main_window.vala:216 +msgid "Error: Could not connect to the database!" +msgstr "Puta la wea: No se puede conectar al base de datos!" + +#: src/main_window.vala:228 src/tour_list.vala:215 src/tour_list.vala:231 +msgid "Error" +msgstr "Puta la wea" + +#: src/tour_list.vala:185 +msgid "Are you sure you wish to delete this tour?" +msgstr "¿Weon, está seguro que quiere borrar esta wea?" + +#: src/tour_list.vala:192 +msgid "Are you sure you wish to delete these tours?" +msgstr "¿Weon, está seguro que quiere borrar estas weas?" + +#: src/tour_list.vala:211 +#, c-format +msgid "" +"Error: Could not delete tour \"%s\" because either this tour has been taken " +"or is still associated with a place or vehicle!" +msgstr "" +"Puta la wea: No se puede borrar la wea \"%s\" porque esta wea ya fue " +"realizada o la wea todavía esta asociado con lugares ó vehículos!" + +#: src/query_window.vala:290 data/ui/main.window.ui:136 +msgid "(Q1) Regions with discounts" +msgstr "(Q1) Regiones sin descuentos" + +#: src/query_window.vala:303 data/ui/main.window.ui:144 +msgid "(Q2) Tour values" +msgstr "(Q2) Valores tour" + +#: src/query_window.vala:316 data/ui/main.window.ui:152 +msgid "(Q3) Coordinator total" +msgstr "(Q3) Total de coordinadores" + +#: src/query_window.vala:329 data/ui/main.window.ui:160 +msgid "(Q4) Tourist total" +msgstr "(Q4) Total de turistas" + +#: src/query_window.vala:342 data/ui/main.window.ui:168 +msgid "(Q5) Vehicle total" +msgstr "(Q5) Total de vehículos" + +#: data/ui/main.window.ui:44 +msgid "_Menu" +msgstr "_Menú" + +#: data/ui/main.window.ui:54 data/ui/tour.list.ui:23 +msgid "Tours" +msgstr "Tours" + +#: data/ui/main.window.ui:62 +msgid "Staff" +msgstr "Weones flojos" + +#: data/ui/main.window.ui:70 +msgid "Tourists" +msgstr "Weones visitores" + +#: data/ui/main.window.ui:80 +msgid "Illnesses" +msgstr "Enfermedades" + +#: data/ui/main.window.ui:88 +msgid "Participate" +msgstr "Participar" + +#: data/ui/main.window.ui:100 +msgid "Vehicles" +msgstr "Vehículos" + +#: data/ui/main.window.ui:114 +msgid "Quit" +msgstr "Salir de la wea" + +#: data/ui/main.window.ui:126 +msgid "_Views" +msgstr "_Vistas" + +#: data/ui/main.splash.ui:46 +msgid "Christopher Cromer" +msgstr "Christopher Cromer (El Weon Gringo)" + +#: data/ui/tour.list.ui:69 data/ui/tour.editor.ui:54 data/ui/query.tree.ui:80 +#: data/ui/query.tree.ui:120 data/ui/query.tree.ui:160 +msgid "Tour Name" +msgstr "Nombre de la Wea" + +#: data/ui/tour.list.ui:83 data/ui/tour.editor.ui:87 +msgid "Individual Cost" +msgstr "Costo Individual" + +#: data/ui/tour.list.ui:97 data/ui/tour.editor.ui:103 +msgid "Group Cost" +msgstr "Costo Grupal" + +#: data/ui/tour.list.ui:111 data/ui/tour.editor.ui:119 +msgid "Minimum People" +msgstr "Mínima de Weones" + +#: data/ui/tour.list.ui:125 data/ui/tour.editor.ui:187 +msgid "City" +msgstr "Ciudad" + +#: data/ui/tour.list.ui:139 data/ui/tour.editor.ui:135 +msgid "Region" +msgstr "Región" + +#: data/ui/tour.list.ui:171 data/ui/tour.places.ui:185 +msgid "Edit" +msgstr "Editar la wea" + +#: data/ui/tour.list.ui:176 +msgid "Edit selected tour." +msgstr "Editar la wea seleccionado." + +#: data/ui/tour.list.ui:186 data/ui/tour.places.ui:243 +msgid "New" +msgstr "Nueva wea" + +#: data/ui/tour.list.ui:190 +msgid "Create a new tour." +msgstr "Crear una wea nueva." + +#: data/ui/tour.list.ui:200 data/ui/tour.places.ui:214 +msgid "Delete" +msgstr "Borrar la wea" + +#: data/ui/tour.list.ui:205 +msgid "Delete selected tour." +msgstr "Borrar la wea seleccionado." + +#: data/ui/tour.list.ui:215 data/ui/tour.places.ui:229 +#: data/ui/query.window.ui:67 +msgid "Close" +msgstr "Cerrar la wea" + +#: data/ui/tour.list.ui:219 data/ui/tour.places.ui:233 +msgid "Close this window." +msgstr "Cerrar la wea." + +#: data/ui/tour.editor.ui:29 +msgid "Tour Editor" +msgstr "Editor de la Wea" + +#: data/ui/tour.editor.ui:234 +msgid "Create a new region by typing here." +msgstr "Crear una nueva wea con escribir aquí." + +#: data/ui/tour.editor.ui:262 +msgid "Create a new city by typing here." +msgstr "Crear una nueva wea con escribir aquí." + +#: data/ui/tour.editor.ui:287 +msgid "Cancel" +msgstr "Cancelar la wea" + +#: data/ui/tour.editor.ui:291 +msgid "Cancel the modification of this tour." +msgstr "Cancelar la modificación de esta wea." + +#: data/ui/tour.editor.ui:306 data/ui/tour.places.ui:23 +msgid "Places" +msgstr "Lugares" + +#: data/ui/tour.editor.ui:310 +msgid "Add or edit places." +msgstr "Agregar o editar places." + +#: data/ui/tour.editor.ui:325 +msgid "Save" +msgstr "Guardar la wea" + +#: data/ui/tour.editor.ui:329 +msgid "Save this tour." +msgstr "Guardar esta wea." + +#: data/ui/tour.places.ui:69 +msgid "Place Name" +msgstr "Nombre de la Wea" + +#: data/ui/tour.places.ui:83 +msgid "Ticket Price" +msgstr "Valor de la Wea" + +#: data/ui/tour.places.ui:97 +msgid "Difficulty" +msgstr "Dificultad" + +#: data/ui/tour.places.ui:111 +msgid "Arrival Date" +msgstr "Fecha de Llegada" + +#: data/ui/tour.places.ui:125 +msgid "Arrival Time" +msgstr "Hora de Llegada" + +#: data/ui/tour.places.ui:139 +msgid "Departure Date" +msgstr "Fecha de Salida" + +#: data/ui/tour.places.ui:153 +msgid "Departure Time" +msgstr "Hora de Salida" + +#: data/ui/tour.places.ui:190 +msgid "Edit associated place." +msgstr "Edit lugar asociado." + +#: data/ui/tour.places.ui:200 +msgid "Add" +msgstr "Agregar una wea" + +#: data/ui/tour.places.ui:204 +msgid "Associate this tour with an existing place." +msgstr "Asociar esta wea con un lugar que ya existe." + +#: data/ui/tour.places.ui:219 +msgid "Delete associated place." +msgstr "Borrar la wea asociado." + +#: data/ui/tour.places.ui:247 +msgid "Create a new place to associate." +msgstr "Crear una wea nueva para asociar con el tour." + +#: data/ui/query.window.ui:85 +msgid "Run" +msgstr "Correr la wea" + +#: data/ui/query.window.ui:127 +msgid "Statement" +msgstr "Enunciado" + +#: data/ui/query.window.ui:157 +msgid "View and Query" +msgstr "Vista y Consulta" + +#: data/ui/query.tree.ui:40 +msgid "Region Name" +msgstr "Nombre de Región" + +#: data/ui/query.tree.ui:52 +msgid "Quantity" +msgstr "Cantidad" + +#: data/ui/query.tree.ui:92 +msgid "Total Value" +msgstr "Valor Total" + +#: data/ui/query.tree.ui:132 +msgid "Coordinator Total" +msgstr "Total de Weones" + +#: data/ui/query.tree.ui:172 +msgid "Tourist Total" +msgstr "Total de Weones" + +#: data/ui/query.tree.ui:200 +msgid "Percentage" +msgstr "Porcentaje" + +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:5 +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:6 +msgid "Host to connect to" +msgstr "Servidor a conectar" + +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:12 +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:13 +msgid "Port number to use" +msgstr "Número de puerto a usar" + +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:19 +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:20 +msgid "Options to use" +msgstr "Opciones a usar" + +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:26 +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:27 +msgid "tty to send debug info (ignored)" +msgstr "tty para enviar datos de depuración (ignorado)" + +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:33 +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:34 +msgid "Database to use" +msgstr "Base de dato a usar" + +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:40 +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:41 +msgid "Username to use" +msgstr "Nombre del weon a usar" + +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:47 +#: data/gschema/cl.cromer.ubb.sernatur.db.gschema.xml:48 +msgid "Password to use" +msgstr "Contraseña a usar" + +#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:5 +#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:6 +msgid "Should the program open maximized or not" +msgstr "Si la wea debe abrir maximizado ó no" + +#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:12 +#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:13 +msgid "Window width" +msgstr "El ancho de la wea" + +#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:19 +#: data/gschema/cl.cromer.ubb.sernatur.window.gschema.xml:20 +msgid "Window height" +msgstr "La altura de la wea" diff --git a/po/sernatur.pot b/po/sernatur.pot index a0457bc..6da222f 100644 --- a/po/sernatur.pot +++ b/po/sernatur.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: sernatur\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-17 09:59-0300\n" +"POT-Creation-Date: 2019-01-18 17:59-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -59,37 +59,42 @@ msgstr "" msgid "Error: Could not connect to the database!" msgstr "" -#: src/main_window.vala:228 src/tour_list.vala:205 src/tour_list.vala:220 +#: src/main_window.vala:228 src/tour_list.vala:215 src/tour_list.vala:231 msgid "Error" msgstr "" -#: src/tour_list.vala:181 +#: src/tour_list.vala:185 msgid "Are you sure you wish to delete this tour?" msgstr "" -#: src/tour_list.vala:201 -msgid "" -"Error: Could not delete tour because there are still associated arrival and " -"departure dates and times!" +#: src/tour_list.vala:192 +msgid "Are you sure you wish to delete these tours?" msgstr "" -#: src/query_window.vala:290 data/ui/main.window.ui:143 +#: src/tour_list.vala:211 +#, c-format +msgid "" +"Error: Could not delete tour \"%s\" because either this tour has been taken " +"or is still associated with a place or vehicle!" +msgstr "" + +#: src/query_window.vala:290 data/ui/main.window.ui:136 msgid "(Q1) Regions with discounts" msgstr "" -#: src/query_window.vala:303 data/ui/main.window.ui:151 +#: src/query_window.vala:303 data/ui/main.window.ui:144 msgid "(Q2) Tour values" msgstr "" -#: src/query_window.vala:316 data/ui/main.window.ui:159 +#: src/query_window.vala:316 data/ui/main.window.ui:152 msgid "(Q3) Coordinator total" msgstr "" -#: src/query_window.vala:329 data/ui/main.window.ui:167 +#: src/query_window.vala:329 data/ui/main.window.ui:160 msgid "(Q4) Tourist total" msgstr "" -#: src/query_window.vala:342 data/ui/main.window.ui:175 +#: src/query_window.vala:342 data/ui/main.window.ui:168 msgid "(Q5) Vehicle total" msgstr "" @@ -102,34 +107,30 @@ msgid "Tours" msgstr "" #: data/ui/main.window.ui:62 -msgid "Places" -msgstr "" - -#: data/ui/main.window.ui:69 msgid "Staff" msgstr "" -#: data/ui/main.window.ui:77 +#: data/ui/main.window.ui:70 msgid "Tourists" msgstr "" -#: data/ui/main.window.ui:87 +#: data/ui/main.window.ui:80 msgid "Illnesses" msgstr "" -#: data/ui/main.window.ui:95 +#: data/ui/main.window.ui:88 msgid "Participate" msgstr "" -#: data/ui/main.window.ui:107 +#: data/ui/main.window.ui:100 msgid "Vehicles" msgstr "" -#: data/ui/main.window.ui:121 +#: data/ui/main.window.ui:114 msgid "Quit" msgstr "" -#: data/ui/main.window.ui:133 +#: data/ui/main.window.ui:126 msgid "_Views" msgstr "" @@ -137,59 +138,64 @@ msgstr "" msgid "Christopher Cromer" msgstr "" -#: data/ui/tour.list.ui:68 data/ui/tour.editor.ui:54 data/ui/query.tree.ui:80 +#: data/ui/tour.list.ui:69 data/ui/tour.editor.ui:54 data/ui/query.tree.ui:80 #: data/ui/query.tree.ui:120 data/ui/query.tree.ui:160 msgid "Tour Name" msgstr "" -#: data/ui/tour.list.ui:82 data/ui/tour.editor.ui:87 +#: data/ui/tour.list.ui:83 data/ui/tour.editor.ui:87 msgid "Individual Cost" msgstr "" -#: data/ui/tour.list.ui:96 data/ui/tour.editor.ui:103 +#: data/ui/tour.list.ui:97 data/ui/tour.editor.ui:103 msgid "Group Cost" msgstr "" -#: data/ui/tour.list.ui:110 data/ui/tour.editor.ui:119 +#: data/ui/tour.list.ui:111 data/ui/tour.editor.ui:119 msgid "Minimum People" msgstr "" -#: data/ui/tour.list.ui:124 data/ui/tour.editor.ui:187 +#: data/ui/tour.list.ui:125 data/ui/tour.editor.ui:187 msgid "City" msgstr "" -#: data/ui/tour.list.ui:138 data/ui/tour.editor.ui:135 +#: data/ui/tour.list.ui:139 data/ui/tour.editor.ui:135 msgid "Region" msgstr "" -#: data/ui/tour.list.ui:170 +#: data/ui/tour.list.ui:171 data/ui/tour.places.ui:185 msgid "Edit" msgstr "" -#: data/ui/tour.list.ui:175 +#: data/ui/tour.list.ui:176 msgid "Edit selected tour." msgstr "" -#: data/ui/tour.list.ui:185 +#: data/ui/tour.list.ui:186 data/ui/tour.places.ui:243 msgid "New" msgstr "" -#: data/ui/tour.list.ui:189 +#: data/ui/tour.list.ui:190 msgid "Create a new tour." msgstr "" -#: data/ui/tour.list.ui:199 +#: data/ui/tour.list.ui:200 data/ui/tour.places.ui:214 msgid "Delete" msgstr "" -#: data/ui/tour.list.ui:203 +#: data/ui/tour.list.ui:205 msgid "Delete selected tour." msgstr "" -#: data/ui/tour.list.ui:214 data/ui/query.window.ui:67 +#: data/ui/tour.list.ui:215 data/ui/tour.places.ui:229 +#: data/ui/query.window.ui:67 msgid "Close" msgstr "" +#: data/ui/tour.list.ui:219 data/ui/tour.places.ui:233 +msgid "Close this window." +msgstr "" + #: data/ui/tour.editor.ui:29 msgid "Tour Editor" msgstr "" @@ -210,14 +216,70 @@ msgstr "" msgid "Cancel the modification of this tour." msgstr "" -#: data/ui/tour.editor.ui:306 -msgid "Save" +#: data/ui/tour.editor.ui:306 data/ui/tour.places.ui:23 +msgid "Places" msgstr "" #: data/ui/tour.editor.ui:310 +msgid "Add or edit places." +msgstr "" + +#: data/ui/tour.editor.ui:325 +msgid "Save" +msgstr "" + +#: data/ui/tour.editor.ui:329 msgid "Save this tour." msgstr "" +#: data/ui/tour.places.ui:69 +msgid "Place Name" +msgstr "" + +#: data/ui/tour.places.ui:83 +msgid "Ticket Price" +msgstr "" + +#: data/ui/tour.places.ui:97 +msgid "Difficulty" +msgstr "" + +#: data/ui/tour.places.ui:111 +msgid "Arrival Date" +msgstr "" + +#: data/ui/tour.places.ui:125 +msgid "Arrival Time" +msgstr "" + +#: data/ui/tour.places.ui:139 +msgid "Departure Date" +msgstr "" + +#: data/ui/tour.places.ui:153 +msgid "Departure Time" +msgstr "" + +#: data/ui/tour.places.ui:190 +msgid "Edit associated place." +msgstr "" + +#: data/ui/tour.places.ui:200 +msgid "Add" +msgstr "" + +#: data/ui/tour.places.ui:204 +msgid "Associate this tour with an existing place." +msgstr "" + +#: data/ui/tour.places.ui:219 +msgid "Delete associated place." +msgstr "" + +#: data/ui/tour.places.ui:247 +msgid "Create a new place to associate." +msgstr "" + #: data/ui/query.window.ui:85 msgid "Run" msgstr "" diff --git a/src/main_window.vala b/src/main_window.vala index e00f1a7..272951e 100644 --- a/src/main_window.vala +++ b/src/main_window.vala @@ -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 } } diff --git a/src/meson.build b/src/meson.build index 4793f18..0048cab 100644 --- a/src/meson.build +++ b/src/meson.build @@ -18,6 +18,7 @@ vala_sources = files( 'main_window.vala', 'tour_list.vala', 'tour_editor.vala', + 'tour_places.vala', 'queries.vala', 'query_window.vala') diff --git a/src/query_window.vala b/src/query_window.vala index 3d86190..9355527 100644 --- a/src/query_window.vala +++ b/src/query_window.vala @@ -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)); diff --git a/src/sernatur.vala b/src/sernatur.vala index 95824ce..b643259 100644 --- a/src/sernatur.vala +++ b/src/sernatur.vala @@ -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 { diff --git a/src/tour_editor.vala b/src/tour_editor.vala index be54b19..e1e4a29 100644 --- a/src/tour_editor.vala +++ b/src/tour_editor.vala @@ -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) => { diff --git a/src/tour_list.vala b/src/tour_list.vala index ccbf51d..58d2b09 100644 --- a/src/tour_list.vala +++ b/src/tour_list.vala @@ -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 diff --git a/src/tour_places.vala b/src/tour_places.vala new file mode 100644 index 0000000..fde6fdc --- /dev/null +++ b/src/tour_places.vala @@ -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 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); + } + } +} diff --git a/test/meson.build b/test/meson.build index 2993b63..560c6a5 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,5 +1,8 @@ +test_inc = include_directories('../lib', '../src', './') + sernatur_test = executable('sernatur_test', 'sernatur_test.vala', + include_directories : test_inc, dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, lib_dep], install : false)