start the 3rd assignment
This commit is contained in:
@@ -3,21 +3,7 @@ gobject_dep = dependency('gobject-2.0')
|
||||
gtk_dep = dependency('gtk+-3.0', version: '>=3.0.0')
|
||||
# gmodule-export-2.0 is needed to connect the handlers
|
||||
gmodule_dep = dependency('gmodule-2.0', version: '>=2.0')
|
||||
pq_dep = dependency('libpq', version: '>=10.0')
|
||||
posix_dep = meson.get_compiler('vala').find_library('posix')
|
||||
|
||||
# this is how to link against a c lib
|
||||
#libsystemd_lib = meson.get_compiler('c').find_library('libsystemd')
|
||||
|
||||
#cc = meson.get_compiler('c')
|
||||
# -no-pie so that the executable is double clickable in gui
|
||||
#if cc.get_id() == 'gcc'
|
||||
# c_args = ['-no-pie']
|
||||
# link_args = ['-no-pie']
|
||||
#else
|
||||
# c_args ''
|
||||
# link_args ''
|
||||
#endif
|
||||
pq_dep = dependency('libpq', version: '>=9.0')
|
||||
|
||||
vala_sources = files(
|
||||
'sernatur.vala',
|
||||
@@ -29,11 +15,13 @@ c_sources = [sernatur_gresource_c]
|
||||
sources = vala_sources
|
||||
sources += c_sources
|
||||
|
||||
vala_args = ['--vapidir='+join_paths(meson.source_root(),'src/vapi')]
|
||||
vala_args = ['--vapidir='+join_paths(meson.source_root(),'vapi')]
|
||||
vala_args += ['--gresources='+join_paths(meson.source_root(),'data/ui/sernatur.gresource.xml')]
|
||||
|
||||
sernatur_dep = declare_dependency(link_with: sernatur_lib, include_directories: include_directories('../lib'))
|
||||
|
||||
exe = executable('sernatur',
|
||||
sources,
|
||||
vala_args: vala_args,
|
||||
dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, posix_dep],
|
||||
dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, sernatur_dep],
|
||||
install: true)
|
||||
|
@@ -16,13 +16,16 @@
|
||||
* The main Sernatur namespace
|
||||
*/
|
||||
namespace Sernatur {
|
||||
using Postgres;
|
||||
using DB;
|
||||
|
||||
/**
|
||||
* The MainWindow class
|
||||
*/
|
||||
[GtkTemplate (ui = "/cl/cromer/ubb/sernatur/sernatur.window.ui")]
|
||||
public class MainWindow : Gtk.ApplicationWindow {
|
||||
Gtk.Grid content;
|
||||
[GtkChild]
|
||||
private Gtk.Box mainbox;
|
||||
|
||||
/**
|
||||
* This is a callback for when the window is maximized or unmaximized
|
||||
@@ -32,7 +35,7 @@ namespace Sernatur {
|
||||
*/
|
||||
[GtkCallback]
|
||||
private bool maximize_window(Gtk.Widget widget, Gdk.EventWindowState state) {
|
||||
Settings settings = new Settings ("cl.cromer.ubb.sernatur.window");
|
||||
var settings = new Settings ("cl.cromer.ubb.sernatur.window");
|
||||
if (state.changed_mask == Gdk.WindowState.MAXIMIZED && (state.new_window_state & Gdk.WindowState.MAXIMIZED) != 0) {
|
||||
// Maximized
|
||||
settings.set_boolean ("maximized", true);
|
||||
@@ -52,7 +55,7 @@ namespace Sernatur {
|
||||
*/
|
||||
[GtkCallback]
|
||||
private bool resize_window(Gtk.Widget widget, Gdk.Event event) {
|
||||
Settings settings = new Settings ("cl.cromer.ubb.sernatur.window");
|
||||
var settings = new Settings ("cl.cromer.ubb.sernatur.window");
|
||||
if (event.get_event_type () == Gdk.EventType.CONFIGURE && !settings.get_boolean ("maximized")) {
|
||||
if (settings.get_int ("width") != event.get_window ().get_width ()) {
|
||||
settings.set_int ("width", event.get_window ().get_width ());
|
||||
@@ -64,71 +67,101 @@ namespace Sernatur {
|
||||
return false;
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
private void menu_quit(Gtk.MenuItem menu_item) {
|
||||
application.quit ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the main window class
|
||||
* @param application The application used to make the GLib object
|
||||
*/
|
||||
public MainWindow (Gtk.Application application) {
|
||||
GLib.Object (application: application);
|
||||
Database conn;
|
||||
|
||||
Settings settings = new Settings ("cl.cromer.ubb.sernatur.db");
|
||||
string host = settings.get_string ("host");
|
||||
string port = settings.get_string ("port");
|
||||
string options = settings.get_string ("options");
|
||||
string tty = settings.get_string ("tty");
|
||||
string database = settings.get_string ("database");
|
||||
string username = settings.get_string ("username");
|
||||
string password = settings.get_string ("password");
|
||||
// Load logo
|
||||
var builder = new Gtk.Builder ();
|
||||
try {
|
||||
builder.add_from_resource ("/cl/cromer/ubb/sernatur/splash.ui");
|
||||
builder.connect_signals (null);
|
||||
content = builder.get_object ("content_grid") as Gtk.Grid;
|
||||
|
||||
conn = set_db_login (host, port, options, tty, database, username, password);
|
||||
if (conn.get_status () != ConnectionStatus.OK) {
|
||||
stderr.printf ("%s\n", conn.get_error_message ());
|
||||
Gtk.MessageDialog msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.CLOSE,
|
||||
conn.get_error_message ());
|
||||
msg.response.connect ((response_id) => {
|
||||
switch (response_id) {
|
||||
case Gtk.ResponseType.CLOSE:
|
||||
application.quit ();
|
||||
break;
|
||||
case Gtk.ResponseType.DELETE_EVENT:
|
||||
application.quit ();
|
||||
break;
|
||||
}
|
||||
msg.destroy();
|
||||
});
|
||||
msg.set_title (dgettext (null, "Error"));
|
||||
msg.show ();
|
||||
return;
|
||||
// Add logo to main main box
|
||||
mainbox.pack_start (content, true, false, 0);
|
||||
}
|
||||
catch (Error e) {
|
||||
// This error is not fatal, so let's keep going
|
||||
warning (e.message);
|
||||
}
|
||||
|
||||
/*Result res = conn.exec ("CREATE DATABASE bdd;");
|
||||
if (res.get_status () != ExecStatus.COMMAND_OK) {
|
||||
stderr.printf ("%s\n", conn.get_error_message ());
|
||||
application.quit ();
|
||||
return;
|
||||
var settings = new Settings ("cl.cromer.ubb.sernatur.db");
|
||||
var host = settings.get_string ("host");
|
||||
var port = settings.get_string ("port");
|
||||
var options = settings.get_string ("options");
|
||||
var tty = settings.get_string ("tty");
|
||||
var database = settings.get_string ("database");
|
||||
var username = settings.get_string ("username");
|
||||
var password = settings.get_string ("password");
|
||||
|
||||
var conn = Postgres.set_db_login (host, port, options, tty, database, username, password);
|
||||
if (conn.get_status () != Postgres.ConnectionStatus.OK) {
|
||||
#if DEBUG
|
||||
error (conn.get_error_message ());
|
||||
#else
|
||||
warning (conn.get_error_message ());
|
||||
var msg = new Gtk.MessageDialog (this,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.CLOSE,
|
||||
conn.get_error_message ());
|
||||
msg.response.connect ((response_id) => {
|
||||
switch (response_id) {
|
||||
case Gtk.ResponseType.CLOSE:
|
||||
application.quit ();
|
||||
break;
|
||||
case Gtk.ResponseType.DELETE_EVENT:
|
||||
application.quit ();
|
||||
break;
|
||||
}
|
||||
msg.destroy();
|
||||
});
|
||||
msg.set_title (dgettext (null, "Error"));
|
||||
msg.show ();
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
print (dgettext (null, "Postgresql server version:") + " %d\n", conn.get_server_version ());
|
||||
|
||||
string password = encrypt_password ("bdd", "bdd");
|
||||
|
||||
res = conn.exec ("CREATE USER bdd WITH ENCRYPTED PASSWORD '" + password + "';");
|
||||
if (res.get_status () != ExecStatus.COMMAND_OK) {
|
||||
stderr.printf ("%s\n", conn.get_error_message ());
|
||||
application.quit ();
|
||||
return;
|
||||
/*var tour = Tour.get_all_tours (conn);
|
||||
print (tour[0].ciudad.region.nombre_region + "\n");
|
||||
var tiene_enfermedad = TieneEnfermedad.get_all_tiene_enfermedades (conn);
|
||||
print (tiene_enfermedad[0].turista.contacto_emergencia.nombre_emergencia + "\n");
|
||||
var descuento = Descuento.get_all_descuentos (conn);
|
||||
print (descuento[0].porcentaje.to_string () + "\n");
|
||||
var realiza = Realiza.get_all_realizas (conn);
|
||||
print (realiza[0].turista.contacto_emergencia.nombre_emergencia + "\n");
|
||||
var posee = Posee.get_all_posees (conn);
|
||||
print (posee[0].guia.ciudad.region.nombre_region + "\n");
|
||||
var region = Region.get_all_regiones (conn);
|
||||
print (region[0].nombre_region + "\n");
|
||||
var participa = Participa.get_all_participas (conn);
|
||||
print (participa[0].guia.ciudad.region.nombre_region + "\n");
|
||||
print (participa[0].tour.ciudad.region.nombre_region + "\n");
|
||||
var requerir_auto = RequerirAuto.get_all_requerir_autos (conn);
|
||||
print (requerir_auto[0].vehiculo.marca + "\n");
|
||||
try {
|
||||
var rut = new Person.Rut ("23.660.457-8");
|
||||
print (rut.get_rut () + "\n");
|
||||
if (rut.type () == Person.Rut.Type.RUN) {
|
||||
print ("person\n");
|
||||
}
|
||||
else {
|
||||
print ("company\n");
|
||||
}
|
||||
}
|
||||
|
||||
res = conn.exec ("GRANT ALL PRIVILEGES ON DATABASE bdd TO bdd;");
|
||||
if (res.get_status () != ExecStatus.COMMAND_OK) {
|
||||
stderr.printf ("%s\n", conn.get_error_message ());
|
||||
application.quit ();
|
||||
return;
|
||||
catch (Person.InvalidRut e) {
|
||||
print ("Rut is invalid");
|
||||
}*/
|
||||
|
||||
GLib.print (dgettext (null, "Server version:") + " %d\n", conn.get_server_version ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -39,19 +39,19 @@ namespace Sernatur {
|
||||
*/
|
||||
public override void activate () {
|
||||
window = new MainWindow (this);
|
||||
GLib.Settings settings = new GLib.Settings ("cl.cromer.ubb.sernatur.window");
|
||||
var settings = new GLib.Settings ("cl.cromer.ubb.sernatur.window");
|
||||
|
||||
window.set_default_size (settings.get_int("width"), settings.get_int("height"));
|
||||
|
||||
if (settings.get_boolean ("maximized")) {
|
||||
window.maximize ();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
window.icon = IconTheme.get_default ().load_icon ("sernatur", 48, 0);
|
||||
}
|
||||
catch (Error e) {
|
||||
stderr.printf (dgettext (null, "Could not load application icon: %s\n"), e.message);
|
||||
warning (e.message);
|
||||
}
|
||||
window.present ();
|
||||
}
|
||||
|
Reference in New Issue
Block a user