From 3770dec9b54d35c2bbdf3f2d233aa3aa4e9846d0 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 8 Sep 2014 17:11:01 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20plugin=20para=20SQLite.=20VnLogi?= =?UTF-8?q?n:=20=09-=20Ahora=20utiliza=20SQLite=20para=20guardar=20la=20co?= =?UTF-8?q?nfiguracion.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile.decl | 2 + db/db-iterator.c | 295 ++++++++++++++++-------- db/db-model.c | 2 + gvn/gvn-param.c | 147 ++++++++---- gvn/gvn-param.h | 15 ++ gvn/gvn-value.c | 110 ++++++++- gvn/gvn-value.h | 36 ++- main/main.c | 2 +- module/data/consulter.glade | 30 +-- vn/Makefile.am | 5 +- vn/gui/login.glade | 418 +++++++++++++++++------------------ vn/image/logo.svg | 268 ++++++++++------------ vn/schema/hedera.gschema.xml | 20 +- vn/vn-column.c | 2 +- vn/vn-grid.c | 56 ++--- vn/vn-handler.c | 5 +- vn/vn-login.c | 373 ++++++++++++++++++------------- vn/vn-login.h | 11 +- 18 files changed, 1062 insertions(+), 735 deletions(-) diff --git a/Makefile.decl b/Makefile.decl index 21d26c0..a6be468 100644 --- a/Makefile.decl +++ b/Makefile.decl @@ -62,9 +62,11 @@ vn_guidir = $(vn_datadir)/gui module_querydir = $(hedera_datadir)/module/sql if ENABLE_INSTALL + vn_configdir = $(vn_datadir) vn_xmldir = $(datadir)/xml/$(PACKAGE) module_datadir = $(hedera_datadir)/module else + vn_configdir = $(vn_datadir)/schema vn_xmldir = $(vn_datadir)/schema module_datadir = $(hedera_datadir)/module/data endif diff --git a/db/db-iterator.c b/db/db-iterator.c index 4823316..47a2643 100644 --- a/db/db-iterator.c +++ b/db/db-iterator.c @@ -178,11 +178,10 @@ static void db_iterator_on_model_status_changed (DbModel * model, DbModelStatus if (status == DB_MODEL_STATUS_READY) { DbIter iter; - gint nrows = db_model_get_nrows (model); g_signal_emit (self, signals[STATUS_CHANGED], 0, IS_READY(self)); - - if (self->row >= 0 && self->row < nrows + + if (self->row >= 0 && self->row < db_model_get_nrows (model) && db_model_get_iter (model, &iter, self->row)) db_iterator_set_iter (self, &iter); else @@ -636,98 +635,6 @@ gint db_iterator_get_column_index (DbIterator * self, const gchar * name) g_return_val_if_fail (IS_READY (self), -1); return db_model_get_column_index (self->model, name); -} - -/** - * db_iterator_get_value: - * @self: a #DbIterator - * @column_name: the column name. - * - * Gets the value of the specified column name. - * - * Return value: (transfer none) (allow-none): the value or %NULL if - * can't get it because the model isn't ready. - **/ -const GValue * db_iterator_get_value (DbIterator * self, const gchar * column_name) -{ - g_return_val_if_fail (DB_IS_ITERATOR (self), NULL); - - if (!self->row_selected) - { - gint column = db_model_get_column_index (self->model, column_name); - - if (column != -1) - return db_model_get_value (self->model, &self->iter, column, NULL); - } - - return NULL; -} - -/** - * db_iterator_set_value: - * @self: a #DbIterator - * @column: the column name. - * @value: a #GValue with the new value. - * @err: (out) (allow-none): the return location for a #GError or %NULL. - * - * Sets the value of the specified column name. - * - * Return value: %TRUE if the value was changed, %FALSE otherwise - **/ -gboolean db_iterator_set_value (DbIterator * self, const gchar * column_name, const GValue * value, GError ** err) -{ - g_return_val_if_fail (DB_IS_ITERATOR (self), FALSE); - - if (db_iterator_check_row_selected (self)) - { - gint column = db_model_get_column_index (self->model, column_name); - - if (column != -1) - return db_model_set_value (self->model, &self->iter, column, value, err); - } - - return FALSE; -} - -/** - * db_iterator_get_value_by_index: - * @self: a #DbIterator - * @column: the column index. - * - * Gets the value of the specified column index. - * - * Return value: (transfer none) (allow-none): the value or %NULL if - * can't get it because the model isn't ready. - **/ -const GValue * db_iterator_get_value_by_index (DbIterator * self, gint column) -{ - g_return_val_if_fail (DB_IS_ITERATOR (self), NULL); - - if (self->row_selected) - return db_model_get_value (self->model, &self->iter, column, NULL); - - return NULL; -} - -/** - * db_iterator_set_value_by_index: - * @self: a #DbIterator - * @column: the column index. - * @value: a #GValue with the new value. - * @err: (out) (allow-none): the return location for a #GError or %NULL. - * - * Sets the value of the specified column index. - * - * Return value: %TRUE if the value was changed, %FALSE otherwise - **/ -gboolean db_iterator_set_value_by_index (DbIterator * self, gint column, const GValue * value, GError ** err) -{ - g_return_val_if_fail (DB_IS_ITERATOR (self), FALSE); - - if (db_iterator_check_row_selected (self)) - return db_model_set_value (self->model, &self->iter, column, value, err); - - return FALSE; } /** @@ -951,6 +858,204 @@ gboolean db_iterator_has_pending_operations (DbIterator * self) return FALSE; } +/** + * db_iterator_get_value: + * @self: a #DbIterator + * @column_name: the column name. + * + * Gets the value of the specified column name. + * + * Return value: (transfer none) (allow-none): the value or %NULL if + * can't get it because the model isn't ready. + **/ +const GValue * db_iterator_get_value (DbIterator * self, const gchar * column_name) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), NULL); + + if (self->row_selected) + { + gint column = db_model_get_column_index (self->model, column_name); + + if (column != -1) + return db_model_get_value (self->model, &self->iter, column, NULL); + } + + return NULL; +} + +/** + * db_iterator_set_value: + * @self: a #DbIterator + * @column: the column name. + * @value: a #GValue with the new value. + * @err: (out) (allow-none): the return location for a #GError or %NULL. + * + * Sets the value of the specified column name. + * + * Return value: %TRUE if the value was changed, %FALSE otherwise + **/ +gboolean db_iterator_set_value (DbIterator * self, const gchar * column_name, const GValue * value, GError ** err) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), FALSE); + + if (db_iterator_check_row_selected (self)) + { + gint column = db_model_get_column_index (self->model, column_name); + + if (column != -1) + return db_model_set_value (self->model, &self->iter, column, value, err); + } + + return FALSE; +} + +/** + * db_iterator_get_value_by_index: + * @self: a #DbIterator + * @column: the column index. + * + * Gets the value of the specified column index. + * + * Return value: (transfer none) (allow-none): the value or %NULL if + * can't get it because the model isn't ready. + **/ +const GValue * db_iterator_get_value_by_index (DbIterator * self, gint column) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), NULL); + + if (self->row_selected) + return db_model_get_value (self->model, &self->iter, column, NULL); + + return NULL; +} + +/** + * db_iterator_set_value_by_index: + * @self: a #DbIterator + * @column: the column index. + * @value: a #GValue with the new value. + * @err: (out) (allow-none): the return location for a #GError or %NULL. + * + * Sets the value of the specified column index. + * + * Return value: %TRUE if the value was changed, %FALSE otherwise + **/ +gboolean db_iterator_set_value_by_index (DbIterator * self, gint column, const GValue * value, GError ** err) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), FALSE); + + if (db_iterator_check_row_selected (self)) + return db_model_set_value (self->model, &self->iter, column, value, err); + + return FALSE; +} + +// Useful methods +/* +static void db_iterator_take_value (DbIterator * self, const gchar * column_name, GValue * value) +{ + db_iterator_set_value (self, const gchar * column_name, value); + gvn_value_free (value); +} + +gboolean db_iterator_is_null (DbIterator * self, const gchar * column_name) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), TRUE); + + return gvn_value_is_null (db_iterator_get_value (self, column_name)); +} + +void db_iterator_set_null (DbIterator * self, const gchar * column_name) +{ + g_return_if_fail (DB_IS_ITERATOR (self)); + + db_iterator_take_value (self, column_name, gvn_value_new_null ()); +} + +gboolean db_iterator_get_boolean (DbIterator * self, const gchar * column_name) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), FALSE); + + return gvn_value_get_boolean (db_iterator_get_value (self, column_name)); +} + +void db_iterator_set_boolean (DbIterator * self, const gchar * column_name, gboolean value) +{ + g_return_if_fail (DB_IS_ITERATOR (self)); + + db_iterator_take_value (self, column_name, gvn_value_new_boolean (value)); +} + +gint db_iterator_get_int (DbIterator * self, const gchar * column_name) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), 0); + + return gvn_value_get_int (db_iterator_get_value (self, column_name));; +} + +void db_iterator_set_int (DbIterator * self, const gchar * column_name, gint value) +{ + g_return_if_fail (DB_IS_ITERATOR (self)); + + db_iterator_take_value (self, column_name, gvn_value_new_int (value)); +} + +glong db_iterator_get_long (DbIterator * self, const gchar * column_name) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), 0); + + return gvn_value_get_long (db_iterator_get_value (self, column_name)); +} + +void db_iterator_set_long (DbIterator * self, const gchar * column_name, glong value) +{ + g_return_if_fail (DB_IS_ITERATOR (self)); + + db_iterator_take_value (self, column_name, gvn_value_new_long (value)); +} + +gdouble db_iterator_get_double (DbIterator * self, const gchar * column_name) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), 0); + + return gvn_value_get_double (db_iterator_get_value (self, column_name)); +} + +void db_iterator_set_double (DbIterator * self, const gchar * column_name, gdouble value) +{ + g_return_if_fail (DB_IS_ITERATOR (self)); + + db_iterator_take_value (self, column_name, gvn_value_new_double (value)); +} + +const gchar * db_iterator_get_string (DbIterator * self, const gchar * column_name) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), NULL); + + return gvn_value_get_string (db_iterator_get_value (self, column_name)); +} + +void db_iterator_set_string (DbIterator * self, const gchar * column_name, const gchar * value) +{ + g_return_if_fail (DB_IS_ITERATOR (self)); + + db_iterator_take_value (self, column_name, gvn_value_new_string (value)); +} + +gpointer db_iterator_get_boxed (DbIterator * self, const gchar * column_name) +{ + g_return_val_if_fail (DB_IS_ITERATOR (self), NULL); + + return gvn_value_get_boxed (db_iterator_get_value (self, column_name)); +} + +void db_iterator_set_boxed (DbIterator * self, const gchar * column_name, gpointer value) +{ + g_return_if_fail (DB_IS_ITERATOR (self)); + + db_iterator_take_value (self, column_name, gvn_value_new_boxed (value)); +} +*/ //+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties enum diff --git a/db/db-model.c b/db/db-model.c index 48a1b92..3b2cf32 100644 --- a/db/db-model.c +++ b/db/db-model.c @@ -1335,6 +1335,8 @@ gint db_model_get_column_index (DbModel * self, const gchar * name) if (name && self->priv->column_index && g_hash_table_lookup_extended (self->priv->column_index, name, NULL, &column)) return GPOINTER_TO_INT (column); + else + g_warning ("DbModel: Column '%s' doesn't exists", name); return -1; } diff --git a/gvn/gvn-param.c b/gvn/gvn-param.c index bb07419..bda3b76 100644 --- a/gvn/gvn-param.c +++ b/gvn/gvn-param.c @@ -86,47 +86,6 @@ void gvn_param_set_value (GvnParam * self, const GValue * value) gvn_param_request_value (self, value, NULL); } -gboolean gvn_param_get_boolean (GvnParam * self) -{ - if (!gvn_value_is_null (self->value)) - return g_value_get_boolean (self->value); - - return FALSE; -} - -gint gvn_param_get_int (GvnParam * self) -{ - if (!gvn_value_is_null (self->value)) - return g_value_get_int (self->value); - - return 0; -} - -glong gvn_param_get_long (GvnParam * self) -{ - if (!gvn_value_is_null (self->value)) - return g_value_get_long (self->value); - - return 0L; -} - -gdouble gvn_param_get_double (GvnParam * self) -{ - if (!gvn_value_is_null (self->value)) - return g_value_get_double (self->value); - - return 0.0; -} - -const gchar * gvn_param_get_string (GvnParam * self) -{ - if (!gvn_value_is_null (self->value)) - return g_value_get_string (self->value); - - return NULL; -} - - /** * gvn_param_get_master: * @self: a #GvnParam where be took the value @@ -198,6 +157,112 @@ void gvn_param_value_changed (GvnParam * self) g_signal_emit (self, signals[VALUE_CHANGED], 0, gvn_param_get_value (self)); } +// Useful methods + +static void gvn_param_take_value (GvnParam * self, GValue * value) +{ + gvn_param_set_value (self, value); + gvn_value_free (value); +} + +gboolean gvn_param_is_null (GvnParam * self) +{ + g_return_val_if_fail (GVN_IS_PARAM (self), TRUE); + + return gvn_value_is_null (gvn_param_get_value (self)); +} + +void gvn_param_set_null (GvnParam * self) +{ + g_return_if_fail (GVN_IS_PARAM (self)); + + gvn_param_take_value (self, gvn_value_new_null ()); +} + +gboolean gvn_param_get_boolean (GvnParam * self) +{ + g_return_val_if_fail (GVN_IS_PARAM (self), FALSE); + + return gvn_value_get_boolean (gvn_param_get_value (self)); +} + +void gvn_param_set_boolean (GvnParam * self, gboolean value) +{ + g_return_if_fail (GVN_IS_PARAM (self)); + + gvn_param_take_value (self, gvn_value_new_boolean (value)); +} + +gint gvn_param_get_int (GvnParam * self) +{ + g_return_val_if_fail (GVN_IS_PARAM (self), 0); + + return gvn_value_get_int (gvn_param_get_value (self));; +} + +void gvn_param_set_int (GvnParam * self, gint value) +{ + g_return_if_fail (GVN_IS_PARAM (self)); + + gvn_param_take_value (self, gvn_value_new_int (value)); +} + +glong gvn_param_get_long (GvnParam * self) +{ + g_return_val_if_fail (GVN_IS_PARAM (self), 0); + + return gvn_value_get_long (gvn_param_get_value (self)); +} + +void gvn_param_set_long (GvnParam * self, glong value) +{ + g_return_if_fail (GVN_IS_PARAM (self)); + + gvn_param_take_value (self, gvn_value_new_long (value)); +} + +gdouble gvn_param_get_double (GvnParam * self) +{ + g_return_val_if_fail (GVN_IS_PARAM (self), 0); + + return gvn_value_get_double (gvn_param_get_value (self)); +} + +void gvn_param_set_double (GvnParam * self, gdouble value) +{ + g_return_if_fail (GVN_IS_PARAM (self)); + + gvn_param_take_value (self, gvn_value_new_double (value)); +} + +const gchar * gvn_param_get_string (GvnParam * self) +{ + g_return_val_if_fail (GVN_IS_PARAM (self), NULL); + + return gvn_value_get_string (gvn_param_get_value (self)); +} + +void gvn_param_set_string (GvnParam * self, const gchar * value) +{ + g_return_if_fail (GVN_IS_PARAM (self)); + + gvn_param_take_value (self, gvn_value_new_string (value)); +} + +gpointer gvn_param_get_boxed (GvnParam * self) +{ + g_return_val_if_fail (GVN_IS_PARAM (self), NULL); + + return gvn_value_get_boxed (gvn_param_get_value (self)); +} + +void gvn_param_set_boxed (GvnParam * self, gpointer value) +{ + g_return_if_fail (GVN_IS_PARAM (self)); + + gvn_param_take_value (self, gvn_value_new_boxed (value)); +} + //+++++++++++++++++++++++++++++++++++++++++++++++++++ Class static void gvn_param_default_init (GvnParamInterface * iface) diff --git a/gvn/gvn-param.h b/gvn/gvn-param.h index 7de9660..108fcd0 100644 --- a/gvn/gvn-param.h +++ b/gvn/gvn-param.h @@ -82,4 +82,19 @@ const GvnParamSpec * gvn_param_get_spec (GvnParam * self); GvnParamStatus gvn_param_get_status (GvnParam * self); void gvn_param_value_changed (GvnParam * self); +gboolean gvn_param_is_null (GvnParam * self); +void gvn_param_set_null (GvnParam * self); +gboolean gvn_param_get_boolean (GvnParam * self); +void gvn_param_set_boolean (GvnParam * self, gboolean value); +gint gvn_param_get_int (GvnParam * self); +void gvn_param_set_int (GvnParam * self, gint value); +glong gvn_param_get_long (GvnParam * self); +void gvn_param_set_long (GvnParam * self, glong value); +gdouble gvn_param_get_double (GvnParam * self); +void gvn_param_set_double (GvnParam * self, gdouble value); +const gchar * gvn_param_get_string (GvnParam * self); +void gvn_param_set_string (GvnParam * self, const gchar * value); +gpointer gvn_param_get_boxed (GvnParam * self); +void gvn_param_set_boxed (GvnParam * self, gpointer value); + #endif \ No newline at end of file diff --git a/gvn/gvn-value.c b/gvn/gvn-value.c index c5f7804..f676379 100644 --- a/gvn/gvn-value.c +++ b/gvn/gvn-value.c @@ -115,7 +115,10 @@ static void gvn_value_transform_string_to_any (const GValue * src, GValue * dst) G_VALUE_TYPE (dst), g_value_get_string (src), -1); } -static void gvn_value_transform_null_to_any (const GValue * src, GValue * dst) {} +static void gvn_value_transform_null_to_any (const GValue * src, GValue * dst) +{ + g_value_reset (dst); +} static void gvn_value_transform_any_to_null (const GValue * src, GValue * dst) { @@ -298,7 +301,7 @@ void gvn_value_new_with_content (GValue * value, GType type, gpointer content) /** * gvn_value_get_valist: - * @value: the type of value + * @value: the #GValue * @va: a string to be converted * * Sets the value of the initilized @value with the value of next @@ -597,6 +600,109 @@ void gvn_value_to_format_string (const GValue * src, const gchar * format, GValu } } +// Useful methods + +void gvn_value_free (GValue * value) +{ + g_value_unset (value); + g_free (value); +} + +GValue * gvn_value_new_null () +{ + return g_value_init (g_new0 (GValue, 1), GVN_TYPE_NULL); +} + +gboolean gvn_value_get_boolean (const GValue * value) +{ + if (!gvn_value_is_null (value)) + return g_value_get_boolean (value); + + return FALSE; +} + +GValue * gvn_value_new_boolean (gboolean value) +{ + GValue * gvalue = g_new0 (GValue, 1); + g_value_set_boolean (g_value_init (gvalue, G_TYPE_BOOLEAN), value); + return gvalue; +} + +gint gvn_value_get_int (const GValue * value) +{ + if (!gvn_value_is_null (value)) + return g_value_get_int (value); + + return 0; +} + +GValue * gvn_value_new_int (gint value) +{ + GValue * gvalue = g_new0 (GValue, 1); + g_value_set_int (g_value_init (gvalue, G_TYPE_INT), value); + return gvalue; +} + +glong gvn_value_get_long (const GValue * value) +{ + if (!gvn_value_is_null (value)) + return g_value_get_long (value); + + return 0L; +} + +GValue * gvn_value_new_long (glong value) +{ + GValue * gvalue = g_new0 (GValue, 1); + g_value_set_long (g_value_init (gvalue, G_TYPE_LONG), value); + return gvalue; +} + +gdouble gvn_value_get_double (const GValue * value) +{ + if (!gvn_value_is_null (value)) + return g_value_get_double (value); + + return 0.0; +} + +GValue * gvn_value_new_double (gdouble value) +{ + GValue * gvalue = g_new0 (GValue, 1); + g_value_set_double (g_value_init (gvalue, G_TYPE_DOUBLE), value); + return gvalue; +} + +const gchar * gvn_value_get_string (const GValue * value) +{ + if (!gvn_value_is_null (value)) + return g_value_get_string (value); + + return NULL; +} + +GValue * gvn_value_new_string (const gchar * value) +{ + GValue * gvalue = g_new0 (GValue, 1); + g_value_set_string (g_value_init (gvalue, G_TYPE_STRING), value); + return gvalue; +} + +gpointer gvn_value_get_boxed (const GValue * value) +{ + if (!gvn_value_is_null (value)) + return g_value_get_boxed (value); + + return NULL; +} + +GValue * gvn_value_new_boxed (gpointer value) +{ + GValue * gvalue = g_new0 (GValue, 1); + g_value_set_string (g_value_init (gvalue, G_TYPE_BOXED), value); + return gvalue; +} + /** * gvn_type_init: * diff --git a/gvn/gvn-value.h b/gvn/gvn-value.h index c685808..5b54166 100644 --- a/gvn/gvn-value.h +++ b/gvn/gvn-value.h @@ -24,15 +24,31 @@ #define gvn_value_compare(a, b) (!gvn_value_compare0 (a, b)) #define gvn_value_is_null(value) (G_VALUE_TYPE (value) == GVN_TYPE_NULL) -GValue * gvn_value_new (GType type); -void gvn_value_new_with_content (GValue * value, GType type, gpointer content); -void gvn_value_new_from_string (GValue * value, GType type, const gchar * string, gsize length); -void gvn_value_set_null (GValue * value); -void gvn_value_get_valist (const GValue * value, va_list va); -gint gvn_value_compare0 (const GValue * a, const GValue * b); -void gvn_value_copy (const GValue * src, GValue * dst); -gboolean gvn_value_ccopy (const GValue * src, GValue * dst); -void gvn_value_to_format_string (const GValue * src, const gchar * format, GValue * dst); -void gvn_type_init (); +GValue * gvn_value_new (GType type); +void gvn_value_new_with_content (GValue * value, GType type, gpointer content); +void gvn_value_new_from_string (GValue * value, GType type, const gchar * string, gsize length); +void gvn_value_set_null (GValue * value); +void gvn_value_get_valist (const GValue * value, va_list va); +gint gvn_value_compare0 (const GValue * a, const GValue * b); +void gvn_value_copy (const GValue * src, GValue * dst); +gboolean gvn_value_ccopy (const GValue * src, GValue * dst); +void gvn_value_to_format_string (const GValue * src, const gchar * format, GValue * dst); + +void gvn_value_free (GValue * value); +GValue * gvn_value_new_null (); +gboolean gvn_value_get_boolean (const GValue * value); +GValue * gvn_value_new_boolean (gboolean value); +gint gvn_value_get_int (const GValue * value); +GValue * gvn_value_new_int (gint value); +glong gvn_value_get_long (const GValue * value); +GValue * gvn_value_new_long (glong value); +gdouble gvn_value_get_double (const GValue * value); +GValue * gvn_value_new_double (gdouble value); +const gchar * gvn_value_get_string (const GValue * value); +GValue * gvn_value_new_string (const gchar * value); +gpointer gvn_value_get_boxed (const GValue * value); +GValue * gvn_value_new_boxed (gpointer value); + +void gvn_type_init (); #endif diff --git a/main/main.c b/main/main.c index 9da3a71..8a610c4 100644 --- a/main/main.c +++ b/main/main.c @@ -39,7 +39,7 @@ int main (int argc, char * argv[]) gvn_type_init (); gtk_init (&argc, &argv); - app = gtk_application_new ("apps.hedera", G_APPLICATION_FLAGS_NONE); + app = gtk_application_new ("org.hedera", G_APPLICATION_FLAGS_NONE); login = vn_login_new (app); if (g_application_register (G_APPLICATION (app), NULL, NULL)) diff --git a/module/data/consulter.glade b/module/data/consulter.glade index 9de6610..d469055 100644 --- a/module/data/consulter.glade +++ b/module/data/consulter.glade @@ -1,7 +1,7 @@ - + @@ -31,6 +31,12 @@ + + + + + + True False @@ -79,8 +85,8 @@ True False - 4 - start + True + expand Send @@ -92,8 +98,8 @@ True - False - False + True + True 0 @@ -108,8 +114,8 @@ True - False - False + True + True 1 @@ -123,8 +129,8 @@ - False - False + True + True 2 @@ -251,10 +257,4 @@ - - - - - - diff --git a/vn/Makefile.am b/vn/Makefile.am index 2f7c70c..8d6e982 100644 --- a/vn/Makefile.am +++ b/vn/Makefile.am @@ -69,6 +69,8 @@ vn_gui_DATA = \ gui/main.glade \ gui/date-chooser.glade \ gui/menu.glade +vn_config_DATA = \ + schema/config.db gsettings_SCHEMAS = $(top_srcdir)/vn/schema/$(PACKAGE).gschema.xml @GSETTINGS_RULES@ @@ -79,7 +81,8 @@ DEFINES = \ -D_VN_MODULE_DATA_DIR=\"$(module_datadir)\" \ -D_VN_MODULE_QUERY_DIR=\"$(module_querydir)\" \ -D_HEDERA_LOCALE_DIR=\"$(datadir)/locale\" \ - -D_DTD_DIR=\"$(vn_xmldir)\" + -D_DTD_DIR=\"$(vn_xmldir)\" \ + -D_VN_CONFIG_DIR=\"$(vn_configdir)\" EXTRA_DIST = vn.pc.in diff --git a/vn/gui/login.glade b/vn/gui/login.glade index c819b39..d40e4c7 100644 --- a/vn/gui/login.glade +++ b/vn/gui/login.glade @@ -6,227 +6,103 @@ - - SELECT rowid, name FROM connection - DB_MODEL_INSERT | DB_MODEL_UPDATE + + SELECT rowid, last_connection FROM config LIMIT 1 + DB_MODEL_INSERT | DB_MODEL_DELETE | DB_MODEL_UPDATE - + SELECT rowid, name, plugin, schema, host, ssl_ca, user, password FROM connection WHERE #link DB_MODEL_UPDATE - + + + + SELECT rowid, name, plugin, schema, host, ssl_ca, user, password FROM connection + DB_MODEL_INSERT | DB_MODEL_DELETE | DB_MODEL_UPDATE + + + + + model-last-conn + on-demand + + + + + + model-login + on-demand + + + model-connections + on-iter - name + rowid - - - model-connection - on-demand - - - + False - 15 + 5 Access False center ../image/icon.svg - + True False vertical 10 - - 40 + + 32 True False - center - 15 - - - True - False - ../image/logo.svg - - - False - True - 0 - - - - - 25 - False - True - True - - - False - True - 1 - - + ../image/logo.svg - True + False True 0 - + True False - 6 - 6 - True - - - Remember - True - True - False - 0 - True - - - 1 - 3 - - - - - True - False - 1 - Password: - - - - - - 0 - 2 - - - - - True - True - False - - edit-find-symbolic - Press here to see the password - - - - - 1 - 2 - - - - - True - True - - - - 1 - 1 - - - - - True - False - 1 - User: - - - - - - 0 - 1 - - - - - True - False - 1 - Server: - - - - - - 0 - 0 - - + vertical + 4 + True True False + iterator-last-conn + last_connection + False model-connections - + False - - 1 - 0 - - - - - - - - False - False - 1 - - - - - True - False - 8 - spread - - - gtk-edit - True - False - True - True - - False True @@ -234,15 +110,15 @@ - - gtk-connect + True - True - True - True - - - + False + + + True + User + + False @@ -250,11 +126,100 @@ 1 + + + True + False + + + True + False + edit-find-symbolic + Password + + + + + + + False + True + 2 + + + + + True + False + False + + + Remember + True + False + True + 0 + True + True + + + + + False + True + 3 + + + + + True + False + True + expand + + + gtk-preferences + True + True + True + True + + + + True + True + 0 + + + + + gtk-connect + True + True + True + True + + + + + + False + True + 1 + + + + + False + True + 4 + + False True - 3 + 1 @@ -262,7 +227,6 @@ False - 5 Configuration False True @@ -271,13 +235,14 @@ window - + False vertical 2 - + False + top spread @@ -286,9 +251,9 @@ True True True - - + + False @@ -308,6 +273,7 @@ True False + 5 6 @@ -327,9 +293,7 @@ True iterator-connections - - multiple - + @@ -434,12 +398,15 @@ True False - iterator-conection + iterator-connections ssl_ca - + + True True dialog-information-symbolic + Path to the file containing the CA certificate, if this is empty SSL won't be used + Path to the file containing the CA certificate, if this is empty SSL won't be used @@ -452,10 +419,11 @@ True False - iterator-conection + iterator-connections schema - + + True True @@ -469,10 +437,11 @@ True False - iterator-conection + iterator-connections host - + + True True @@ -482,23 +451,6 @@ 2 - - - True - False - iterator-conection - plugin - - - False - - - - - 1 - 1 - - True @@ -515,10 +467,11 @@ True False - iterator-conection + iterator-connections name - + + True True @@ -528,6 +481,53 @@ 0 + + + True + False + iterator-connections + plugin + + + True + True + + + + + 1 + 1 + + + + + True + False + 1 + User: + + + 0 + 5 + + + + + True + False + iterator-connections + user + + + True + + + + + 1 + 5 + + False @@ -539,7 +539,7 @@ True False - iterator-conection + iterator-connections VN_HANDLER_SHOW_UNDO | VN_HANDLER_SHOW_SAVE diff --git a/vn/image/logo.svg b/vn/image/logo.svg index aeaea8e..d43b08a 100644 --- a/vn/image/logo.svg +++ b/vn/image/logo.svg @@ -12,161 +12,121 @@ version="1.1" x="0px" y="0px" - width="196.80357" - height="26.799999" - viewBox="0 0 196.80357 26.799999" + width="180" + height="24.694674" + viewBox="0 0 180 24.694674" enable-background="new 0 0 226.229 31.038" xml:space="preserve" id="svg2" - inkscape:version="0.48.1 r9760" + inkscape:version="0.48.5 r10040" sodipodi:docname="logo.svg">image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + id="metadata61">image/svg+xml \ No newline at end of file diff --git a/vn/schema/hedera.gschema.xml b/vn/schema/hedera.gschema.xml index 2f71881..9691644 100644 --- a/vn/schema/hedera.gschema.xml +++ b/vn/schema/hedera.gschema.xml @@ -1,23 +1,5 @@ - - - "" - - - "localhost" - - - "" - - - "" - - - "" - - - "" - + diff --git a/vn/vn-column.c b/vn/vn-column.c index ca05e5e..bae9023 100644 --- a/vn/vn-column.c +++ b/vn/vn-column.c @@ -104,7 +104,7 @@ static void vn_column_update_column_index (VnColumn * obj) { DbModel * model = vn_column_get_model (obj); - if (model) + if (model && db_model_is_ready (model)) { obj->column_index = db_model_get_column_index (model, obj->column_name); diff --git a/vn/vn-grid.c b/vn/vn-grid.c index cd16deb..e9265c3 100644 --- a/vn/vn-grid.c +++ b/vn/vn-grid.c @@ -71,27 +71,36 @@ static void vn_grid_on_selection_changed (GtkTreeSelection * selection, GtkTreeV g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); } -static void vn_grid_on_cursor_changed (GtkTreeView * obj, DbIterator * iterator) +static void vn_grid_on_cursor_changed (GtkTreeView * tree_view, VnGrid * obj) { - GtkTreeIter iter; - GtkTreePath * path; - - if (gtk_tree_selection_count_selected_rows (gtk_tree_view_get_selection (obj)) > 1) + gint selected_rows; + + if (!db_iterator_is_ready (obj->iterator)) return; - gtk_tree_view_get_cursor (obj, &path, NULL); + selected_rows = gtk_tree_selection_count_selected_rows (gtk_tree_view_get_selection (tree_view)); - if (path && gtk_tree_model_get_iter (gtk_tree_view_get_model (obj), &iter, path)) + if (selected_rows == 1) { - DbIter dbiter; - vn_gtk_tree_iter_to_db_iter (&iter, &dbiter); + GtkTreeIter iter; + GtkTreePath * path; - g_signal_handlers_block_by_func (iterator, vn_grid_on_iter_changed, obj); - db_iterator_move_iter (iterator, &dbiter); - g_signal_handlers_unblock_by_func (iterator, vn_grid_on_iter_changed, obj); + gtk_tree_view_get_cursor (tree_view, &path, NULL); + + if (path && gtk_tree_model_get_iter (gtk_tree_view_get_model (tree_view), &iter, path)) + { + DbIter dbiter; + vn_gtk_tree_iter_to_db_iter (&iter, &dbiter); + + g_signal_handlers_block_by_func (obj->iterator, vn_grid_on_iter_changed, obj); + db_iterator_move_iter (obj->iterator, &dbiter); + g_signal_handlers_unblock_by_func (obj->iterator, vn_grid_on_iter_changed, obj); + } + + gtk_tree_path_free (path); } - - gtk_tree_path_free (path); + else if (selected_rows == 0) + db_iterator_move_iter (obj->iterator, NULL); } static void vn_grid_on_iter_changed (DbIterator * iterator, GtkTreeView * obj) @@ -305,9 +314,6 @@ void vn_grid_set_iterator (VnGrid * obj, DbIterator * iterator) if (obj->iterator) { - g_signal_handlers_disconnect_by_func (obj, - vn_grid_on_cursor_changed, obj->iterator); - g_object_disconnect (obj->iterator ,"any-signal", vn_grid_on_iter_changed, obj ,"any-signal", vn_grid_on_status_changed, obj @@ -328,9 +334,6 @@ void vn_grid_set_iterator (VnGrid * obj, DbIterator * iterator) vn_grid_on_status_changed (iterator, db_iterator_is_ready (iterator), obj); - - g_signal_connect_after (obj, "cursor-changed", - G_CALLBACK (vn_grid_on_cursor_changed), iterator); } } @@ -394,12 +397,13 @@ static void vn_grid_init (VnGrid * obj) g_signal_connect (selection, "changed", G_CALLBACK (vn_grid_on_selection_changed), obj); - g_signal_connect (obj, "notify::model", - G_CALLBACK (vn_grid_on_model_changed), NULL); - g_signal_connect (obj, "key-press-event", - G_CALLBACK (vn_grid_on_cursor_key_pressed), NULL); - g_signal_connect (obj, "key-press-event", - G_CALLBACK (vn_grid_on_escape_pressed), NULL); + g_object_connect (obj + ,"signal::notify::model", vn_grid_on_model_changed, obj + ,"signal::key-press-event", vn_grid_on_cursor_key_pressed, obj + ,"signal::key-press-event", vn_grid_on_escape_pressed, obj + ,"signal-after::cursor-changed", vn_grid_on_cursor_changed, obj + ,NULL + ); } static void vn_grid_finalize (VnGrid * obj) diff --git a/vn/vn-handler.c b/vn/vn-handler.c index 35d8254..505775b 100644 --- a/vn/vn-handler.c +++ b/vn/vn-handler.c @@ -77,10 +77,7 @@ static void vn_handler_on_remove_activated (GSimpleAction * a, GVariant * p, gpo static void vn_handler_on_save_activated (GSimpleAction * a, GVariant * p, gpointer obj) { - if (db_iterator_get_mode (VN_HANDLER (obj)->iterator) != DB_ITERATOR_MODE_ON_DEMAND) - db_iterator_perform_operations (VN_HANDLER (obj)->iterator); - else if (vn_handler_dialog (obj, _("Are you sure you want to save the changes?"))) - db_iterator_perform_operations (VN_HANDLER (obj)->iterator); + db_iterator_perform_operations (VN_HANDLER (obj)->iterator); } static void vn_handler_on_undo_activated (GSimpleAction * a, GVariant * p, gpointer obj) diff --git a/vn/vn-login.c b/vn/vn-login.c index 13936e9..7480aca 100644 --- a/vn/vn-login.c +++ b/vn/vn-login.c @@ -16,8 +16,10 @@ */ #include "vn-login.h" +#include "vn-set.h" #define LOGIN_UI _GUI_DIR"/login.glade" +#define CONFIG_DB _VN_CONFIG_DIR"/config.db" #define IS_DEFINED(string) (string && g_strcmp0 (string, "")) #define BUILDER_GET(self, name) ((gpointer) gtk_builder_get_object (self, name)) @@ -25,12 +27,6 @@ typedef struct { VnLogin * self; - gchar * user; - gchar * pass; - gchar * plugin; - gchar * host; - gchar * schema; - gchar * ssl_ca; DbConn * conn; GThread * thread; gboolean connected; @@ -65,12 +61,6 @@ void connect_data_free (ConnectData * connect_data) if (connect_data->error) g_error_free (connect_data->error); - g_free (connect_data->user); - g_free (connect_data->pass); - g_free (connect_data->plugin); - g_free (connect_data->host); - g_free (connect_data->schema); - g_free (connect_data->ssl_ca); g_object_unref (connect_data->conn); g_object_unref (connect_data->self); g_thread_unref (connect_data->thread); @@ -83,26 +73,38 @@ void connect_data_free (ConnectData * connect_data) static void vn_login_load (VnLogin * self) { GError * err = NULL; - GtkBuilder * builder; + gchar * cfg_dir; gchar * cfg_file; + GFile * src_file; + GFile * dst_file; // Initializing SQLite connection - cfg_file = g_build_filename (g_get_user_config_dir (), "config.db", NULL); + cfg_dir = g_build_filename (g_get_user_config_dir (), "hedera", NULL); + cfg_file = g_build_filename (cfg_dir, "config.db", NULL); + + src_file = g_file_new_for_path (CONFIG_DB); + dst_file = g_file_new_for_path (cfg_file); + + if (!g_file_query_exists (dst_file, NULL)) + { + g_mkdir_with_parents (cfg_dir, 0700); + + if (!g_file_copy (src_file, dst_file, 0, NULL, NULL, NULL, &err)) + goto exit; + } self->cfg_conn = db_conn_new (); if (!db_conn_load_plugin (self->cfg_conn, "sqlite", &err) || !db_conn_open (self->cfg_conn, NULL, cfg_file, NULL, NULL, &err)) goto exit; - - // Loading interface - - builder = gtk_builder_new (); - if (gtk_builder_add_from_file (builder, LOGIN_UI, &err)) + // Loading interface + + if (gtk_builder_add_from_file (self->builder, LOGIN_UI, &err)) { - GSList * i; + const GList * i; VnSet * models; models = BUILDER_GET (self->builder, "models"); @@ -111,21 +113,22 @@ static void vn_login_load (VnLogin * self) for (i = vn_set_get_objects (models); i; i = i->next) db_model_set_conn (i->data, self->cfg_conn); - self->window = BUILDER_GET (builder, "window"); - self->user = BUILDER_GET (builder, "user"); - self->pass = BUILDER_GET (builder, "password"); - self->remember = BUILDER_GET (builder, "remember"); - self->connect = BUILDER_GET (builder, "connect"); - self->settings_button = BUILDER_GET (builder, "settings"); - self->spinner = BUILDER_GET (builder, "spinner"); - self->settings_dialog = BUILDER_GET (builder, "settings-dialog"); - gtk_builder_connect_signals (builder, self); - + self->window = BUILDER_GET (self->builder, "window"); + self->user = BUILDER_GET (self->builder, "user"); + self->pass = BUILDER_GET (self->builder, "password"); + self->remember = BUILDER_GET (self->builder, "remember"); + self->connect = BUILDER_GET (self->builder, "connect"); + self->settings_button = BUILDER_GET (self->builder, "settings"); + self->settings_dialog = BUILDER_GET (self->builder, "settings-dialog"); + self->login_data = BUILDER_GET (self->builder, "iterator-login"); + self->last_conn = BUILDER_GET (self->builder, "iterator-last-conn"); + self->connections = BUILDER_GET (self->builder, "iterator-connections"); + self->settings_button = BUILDER_GET (self->builder, "settings-button"); + gtk_builder_connect_signals (self->builder, self); + gtk_application_add_window (self->app, self->window); } - g_object_unref (builder); - // Freeing resources exit: @@ -136,7 +139,10 @@ static void vn_login_load (VnLogin * self) g_clear_error (&err); } + g_free (cfg_dir); g_free (cfg_file); + g_object_unref (src_file); + g_object_unref (dst_file); } /* @@ -144,21 +150,13 @@ static void vn_login_load (VnLogin * self) */ static void vn_login_show (VnLogin * self) { - gboolean autologin = FALSE; - if (!self->window) - { vn_login_load (self); - autologin = TRUE; - } if (self->window) { gtk_widget_show_all (GTK_WIDGET (self->window)); gtk_widget_grab_focus (GTK_WIDGET (self->user)); - - if (autologin) - gtk_button_clicked (self->connect); } } @@ -173,16 +171,21 @@ static void vn_login_set_loading (VnLogin * self, gboolean loading) gtk_widget_set_sensitive (GTK_WIDGET (self->pass), !loading); gtk_widget_set_sensitive (GTK_WIDGET (self->remember), !loading); + gtk_button_set_label (self->connect, NULL); + gtk_container_remove (GTK_CONTAINER (self->connect), + gtk_bin_get_child (GTK_BIN (self->connect))); + if (loading) { - gtk_widget_show (self->spinner); - gtk_widget_hide (GTK_WIDGET (self->connect)); + GtkWidget * spinner = gtk_spinner_new (); + gtk_spinner_start (GTK_SPINNER (spinner)); + gtk_container_add (GTK_CONTAINER (self->connect), spinner); + gtk_widget_show_all (spinner); } else - { - gtk_widget_hide (self->spinner); - gtk_widget_show (GTK_WIDGET (self->connect)); - } + gtk_button_set_label (self->connect, "gtk-connect"); + + gtk_widget_set_sensitive (GTK_WIDGET (self->connect), !loading); } /* @@ -201,44 +204,16 @@ static void vn_login_free_gui (VnLogin * self) } } -/* - * Shows the settings dialog. - */ -void vn_login_on_settings_clicked (GtkButton * button, VnLogin * self) -{ - gtk_dialog_run (self->settings_dialog); -} - -/* - * Hides the settings dialog. - */ -void vn_login_on_settings_cancel_clicked (GtkButton * button, VnLogin * self) -{ - gtk_widget_hide (GTK_WIDGET (self->settings_dialog)); -} - -/* - * Hides the settings dialog when escape is pressed. - */ -void vn_login_settings_on_delete_event (GtkWidget * settings_dialog) -{ - gtk_widget_hide (settings_dialog); -} - -/* - * Applies the changes made on settings dialog. - */ -void vn_login_on_settings_apply_clicked (GtkButton * button, VnLogin * self) -{ - gtk_widget_hide (GTK_WIDGET (self->settings_dialog)); -} - /* * Shows the login dialog when user logout from GUI. */ void vn_login_on_gui_logout (VnGui * gui, VnLogin * self) { - g_settings_set_string (self->settings, "pass", ""); + GValue * null_pass = gvn_value_new_null (); + db_iterator_set_value (self->login_data, "password", null_pass, NULL); + db_iterator_perform_operations (self->login_data); + gvn_value_free (null_pass); + vn_login_free_gui (self); vn_login_show (self); } @@ -252,6 +227,92 @@ void vn_login_on_gui_exit (VnGui * gui, VnLogin * self) gtk_widget_destroy (GTK_WIDGET (self->window)); } +/* + * Checks if exists a configuration record, if not, creates it. + */ +void vn_login_on_last_conn_ready (DbIterator * iterator, gboolean ready, VnLogin * self) +{ + if (ready && db_iterator_get_nrows (iterator) == 0) + db_iterator_insert (iterator); +} + +/* + * Sets the default user and password for selected configuration. + */ +void vn_login_on_server_changed (DbIterator * iterator, VnLogin * self) +{ + gboolean first_login; + gboolean remember = FALSE; + + if (db_iterator_get_row (self->login_data) != -1) + { + const gchar * pass = gvn_value_get_string (db_iterator_get_value (self->login_data, "password")); + + gvn_param_set_value (self->user, db_iterator_get_value (self->login_data, "user")); + + if (pass) + { + gchar * decoded = gvn_decode (pass); + gvn_param_set_string (self->pass, decoded); + g_free (decoded); + + remember = TRUE; + } + else + gvn_param_set_null (self->pass); + } + else + { + gvn_param_set_null (self->user); + gvn_param_set_null (self->pass); + } + + first_login = gvn_param_is_null (self->remember); + gvn_param_set_boolean (self->remember, remember); + + if (remember && first_login) + gtk_button_clicked (self->connect); +} + +/* + * Closes the application when login window is destroyed. + */ +void vn_login_on_destroyed (GtkWidget * window, VnLogin * self) +{ + self->window = NULL; + gtk_main_quit (); +} + +void vn_login_on_pass_show (GtkEntry * entry, GtkEntryIconPosition * pos, + GdkEvent * event, VnLogin * self) +{ + gtk_entry_set_visibility (entry, TRUE); +} + +void vn_login_on_pass_hide (GtkEntry * entry, GtkEntryIconPosition * pos, + GdkEvent * event, VnLogin * self) +{ + gtk_entry_set_visibility (entry, FALSE); +} + +static void vn_login_on_startup (GApplication * app, VnLogin * self) +{ +// g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL); +} + +static void vn_login_on_activate (GApplication * app, VnLogin * self) +{ + if (gtk_main_level () == 0) + { + vn_login_show (self); + gtk_main (); + } + else if (!self->gui) + gtk_window_present (self->window); +} + +//------------------------------------ Login process + /* * Saves the login information and opens the main GUI. */ @@ -259,19 +320,24 @@ static gboolean vn_login_done (ConnectData * connect_data) { VnLogin * self = connect_data->self; + g_signal_handlers_block_by_func (self->login_data, + vn_login_on_server_changed, self); + if (connect_data->connected) { - db_iterator_set_value (self->config, "user", gvn_param_get_value (self->user), NULL); - db_iterator_set_value (self->config, "remember", gvn_param_get_value (self->remember), NULL); + db_iterator_set_value (self->login_data, "user", gvn_param_get_value (self->user), NULL); if (gvn_param_get_boolean (self->remember)) { GValue encoded = G_VALUE_INIT; + g_value_init (&encoded, G_TYPE_STRING); g_value_take_string (&encoded, gvn_encode (gvn_param_get_string (self->pass))); - db_iterator_set_value (self->config, "password", &encoded, NULL); + db_iterator_set_value (self->login_data, "password", &encoded, NULL); g_value_unset (&encoded); } - + + db_iterator_perform_operations (self->last_conn); + db_iterator_perform_operations (self->login_data); gvn_param_set_null (self->pass); gtk_widget_hide (GTK_WIDGET (self->window)); @@ -301,7 +367,7 @@ static gboolean vn_login_done (ConnectData * connect_data) "%s", connect_data->error->message); if (connect_data->error->code == DB_CONN_ERROR_BAD_LOGIN) - gtk_entry_set_text (self->pass, ""); + gvn_param_set_null (self->pass); } gtk_dialog_run (GTK_DIALOG (dialog)); @@ -309,6 +375,9 @@ static gboolean vn_login_done (ConnectData * connect_data) vn_login_show (self); } + g_signal_handlers_unblock_by_func (self->login_data, + vn_login_on_server_changed, self); + vn_login_set_loading (self, FALSE); return G_SOURCE_REMOVE; } @@ -320,18 +389,26 @@ static void vn_login_thread (ConnectData * connect_data) { VnLogin * self = connect_data->self; - if (IS_DEFINED (connect_data->plugin) && IS_DEFINED (connect_data->schema)) + // FIXME: Thread unsafe functions + const gchar * user = gvn_param_get_string (self->user); + const gchar * pass = gvn_param_get_string (self->pass); + const gchar * plugin = gvn_value_get_string (db_iterator_get_value (self->login_data, "plugin")); + const gchar * host = gvn_value_get_string (db_iterator_get_value (self->login_data, "host")); + const gchar * schema = gvn_value_get_string (db_iterator_get_value (self->login_data, "schema")); + const gchar * ssl_ca = gvn_value_get_string (db_iterator_get_value (self->login_data, "ssl_ca")); + + if (IS_DEFINED (plugin) && IS_DEFINED (schema)) { - if (db_conn_load_plugin (connect_data->conn, connect_data->plugin, &connect_data->error)) + if (db_conn_load_plugin (connect_data->conn, plugin, &connect_data->error)) { - if (IS_DEFINED (connect_data->ssl_ca)) - db_conn_set_ssl (connect_data->conn, connect_data->ssl_ca); + if (IS_DEFINED (ssl_ca)) + db_conn_set_ssl (connect_data->conn, ssl_ca); connect_data->connected = db_conn_open (connect_data->conn - ,connect_data->host - ,connect_data->schema - ,connect_data->user - ,connect_data->pass + ,host + ,schema + ,user + ,pass ,&connect_data->error ); } @@ -354,79 +431,67 @@ void vn_login_on_connect_clicked (GtkButton * button, VnLogin * self) { ConnectData * connect_data; - vn_login_set_loading (self, TRUE); - - connect_data = g_new (ConnectData, 1); - connect_data->self = g_object_ref (self); - connect_data->user = g_strdup (gvn_param_get_string (self->user)); - connect_data->pass = g_strdup (gvn_param_get_string (self->pass)); - connect_data->plugin = g_strdup (db_iterator_get_string (self->config, "plugin")); - connect_data->host = g_strdup (db_iterator_get_string (self->config, "host")); - connect_data->schema = g_strdup (db_iterator_get_string (self->config, "schema")); - connect_data->ssl_ca = g_strdup (db_iterator_get_string (self->config, "ssl_ca")); - connect_data->conn = db_conn_new (); - connect_data->connected = FALSE; - connect_data->error = NULL; - connect_data->thread = g_thread_new ("vn-login", - (GThreadFunc) vn_login_thread, connect_data); -} - -/* - * Sets the default user and password for selected configuration. - */ -static void vn_login_on_server_changed (VnLogin * self) -{ - const GValue * pass = db_iterator_get_value (self->config, "password"); - - gvn_param_set_value (self->user, db_iterator_get_value (self->config, "user")); - gvn_param_set_value (self->remember, db_iterator_get_value (self->config, "remember")); - - if (!gvn_value_is_null (pass)) + if (db_iterator_get_row (self->login_data) != -1) { - GValue decoded = G_VALUE_INIT; - g_value_take_string (&decoded, gvn_decode (g_value_get_string (pass))); - gvn_param_set_value (self->pass, &decoded); - g_value_unset (&decoded); + vn_login_set_loading (self, TRUE); + + connect_data = g_new (ConnectData, 1); + connect_data->self = g_object_ref (self); + connect_data->conn = db_conn_new (); + connect_data->connected = FALSE; + connect_data->error = NULL; + connect_data->thread = g_thread_new ("vn-login", + (GThreadFunc) vn_login_thread, connect_data); } else - gvn_param_set_value (self->pass, pass); + { + GtkWidget * dialog = gtk_message_dialog_new (self->window + ,GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT + ,GTK_MESSAGE_ERROR + ,GTK_BUTTONS_OK + ,_("Please select a connection") + ); + gtk_window_set_title (GTK_WINDOW (dialog), _("Login error")); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (GTK_WIDGET (dialog)); + } +} + +//------------------------------------ Settings dialog + +/* + * Shows the settings dialog. + */ +void vn_login_on_settings_clicked (GtkButton * button, VnLogin * self) +{ + db_iterator_refresh (self->connections); + gtk_widget_show_all (GTK_WIDGET (self->settings_dialog)); + gtk_dialog_run (self->settings_dialog); } /* - * Closes the application when login window is destroyed. + * Hides the settings dialog. */ -void vn_login_on_destroyed (GtkWidget * window, VnLogin * self) +void vn_login_hide_settings (VnLogin * self) { - self->window = NULL; - gtk_main_quit (); + db_iterator_refresh (self->login_data); + gtk_widget_hide (GTK_WIDGET (self->settings_dialog)); } -void vn_login_on_pass_show (GtkEntry * entry, GtkEntryIconPosition * pos, - GdkEvent * event, VnLogin * self) +/* + * Hides the settings dialog when close is clicked. + */ +void vn_login_on_settings_close_clicked (GtkButton * button, VnLogin * self) { - gtk_entry_set_visibility (entry, TRUE); + vn_login_hide_settings (self); } -void vn_login_on_pass_hide (GtkEntry * entry, GtkEntryIconPosition * pos, - GdkEvent * event, VnLogin * self) +/* + * Hides the settings dialog when escape is pressed. + */ +void vn_login_settings_on_delete_event (GtkWidget * settings_dialog, GdkEvent * event, VnLogin * self) { - gtk_entry_set_visibility (entry, FALSE); -} - -static void vn_login_on_startup (GApplication * app, VnLogin * self) -{ - g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL); -} - -static void vn_login_on_activate (GApplication * app, VnLogin * self) -{ - if (gtk_main_level () == 0) - { - vn_login_show (self); - gtk_main (); - } - else if (!self->gui) - gtk_window_present (self->window); + vn_login_hide_settings (self); } //+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties @@ -450,8 +515,8 @@ static void vn_login_set_property (VnLogin * self, guint id, ,NULL ); - self->settings = g_settings_new ( - g_application_get_application_id (G_APPLICATION (self->app))); +// self->settings = g_settings_new ( +// g_application_get_application_id (G_APPLICATION (self->app))); break; } default: @@ -478,6 +543,7 @@ static void vn_login_init (VnLogin * self) self->settings = NULL; self->app = NULL; self->cfg_conn = NULL; + self->builder = gtk_builder_new (); } static void vn_login_finalize (VnLogin * self) @@ -489,6 +555,7 @@ static void vn_login_finalize (VnLogin * self) ,NULL ); + g_clear_object (&self->builder); g_clear_object (&self->cfg_conn); g_clear_object (&self->settings); g_clear_object (&self->app); diff --git a/vn/vn-login.h b/vn/vn-login.h index 5599550..319d1c5 100644 --- a/vn/vn-login.h +++ b/vn/vn-login.h @@ -39,17 +39,20 @@ struct _VnLogin { GObject parent; + GtkBuilder * builder; GtkApplication * app; VnGui * gui; GtkWindow * window; - GtkEntry * user; - GtkEntry * pass; - GtkToggleButton * remember; + GvnParam * user; + GvnParam * pass; + GvnParam * remember; GtkButton * connect; GtkWidget * stop; GtkButton * settings_button; - GtkWidget * spinner; DbConn * cfg_conn; + DbIterator * login_data; + DbIterator * last_conn; + DbIterator * connections; GtkDialog * settings_dialog; GtkEntry * plugin;