SQLite plugin, inestable
This commit is contained in:
parent
dd589deb9c
commit
bd9ea66567
|
@ -1,5 +1,7 @@
|
|||
# Definition of the install directories
|
||||
|
||||
# Libraries
|
||||
|
||||
if ENABLE_INSTALL
|
||||
hedera_libdir = $(pkglibdir)
|
||||
hedera_datadir = $(pkgdatadir)
|
||||
|
@ -23,13 +25,12 @@ else
|
|||
module_libdir = $(hedera_libdir)/module/src/.libs
|
||||
endif
|
||||
|
||||
mysql_libdir = $(plugin_libdir)/mysql
|
||||
pg_libdir = $(plugin_libdir)/pg
|
||||
|
||||
# Binaries (programs)
|
||||
|
||||
hedera_bindir = $(bindir)
|
||||
|
||||
# Headers and development files
|
||||
|
||||
hedera_includedir = $(pkgincludedir)
|
||||
|
||||
gvn_includedir = $(hedera_includedir)/gvn
|
||||
|
@ -53,6 +54,7 @@ gladevn_libdir = $(prefix)/lib/glade/modules
|
|||
gladevn_datadir = $(datadir)/glade/catalogs
|
||||
|
||||
# Data
|
||||
|
||||
vn_datadir = $(hedera_datadir)/vn
|
||||
vn_imagedir = $(vn_datadir)/image
|
||||
vn_guidir = $(vn_datadir)/gui
|
||||
|
|
|
@ -16,6 +16,7 @@ AC_PROG_CC
|
|||
# Check for additional packages
|
||||
PKG_CHECK_MODULES([glib], [glib-2.0])
|
||||
PKG_CHECK_MODULES([gdome], [gdome2])
|
||||
PKG_CHECK_MODULES([sqlite], [sqlite3])
|
||||
PKG_CHECK_MODULES([gtk], [gtk+-3.0])
|
||||
PKG_CHECK_MODULES([gladeui], [gladeui-2.0])
|
||||
PKG_CHECK_MODULES([gtksourceview], [gtksourceview-3.0]
|
||||
|
@ -89,6 +90,7 @@ AC_CONFIG_FILES([
|
|||
sql/parser/Makefile
|
||||
db/Makefile
|
||||
plugin/Makefile
|
||||
plugin/sqlite/Makefile
|
||||
plugin/pg/Makefile
|
||||
plugin/mysql/Makefile
|
||||
vn/Makefile
|
||||
|
|
17
db/db-calc.c
17
db/db-calc.c
|
@ -324,10 +324,10 @@ void db_calc_set_model (DbCalc * self, DbModel * model)
|
|||
if (self->model)
|
||||
{
|
||||
g_object_disconnect (self->model
|
||||
,"any_signal::line-updated", db_calc_on_update, self
|
||||
,"any_signal::line-updated", db_calc_on_update_after, self
|
||||
,"any_signal::line-deleted", db_calc_on_delete, self
|
||||
,"any_signal::status-changed", db_calc_on_model_refresh, self
|
||||
,"any_signal", db_calc_on_update, self
|
||||
,"any_signal", db_calc_on_update_after, self
|
||||
,"any_signal", db_calc_on_delete, self
|
||||
,"any_signal", db_calc_on_model_refresh, self
|
||||
,NULL
|
||||
);
|
||||
g_clear_object (&self->model);
|
||||
|
@ -449,10 +449,14 @@ static void db_calc_init (DbCalc * self)
|
|||
g_value_init (self->value, GVN_TYPE_NULL);
|
||||
}
|
||||
|
||||
static void db_calc_dispose (DbCalc * self)
|
||||
{
|
||||
db_calc_set_master (self, NULL);
|
||||
db_calc_set_model (self, NULL);
|
||||
}
|
||||
|
||||
static void db_calc_finalize (DbCalc * self)
|
||||
{
|
||||
db_calc_set_model (self, NULL);
|
||||
db_calc_set_master (self, NULL);
|
||||
g_value_unset (self->value);
|
||||
gvn_param_spec_free (self->spec);
|
||||
g_free (self->value);
|
||||
|
@ -463,6 +467,7 @@ static void db_calc_finalize (DbCalc * self)
|
|||
static void db_calc_class_init (DbCalcClass * klass)
|
||||
{
|
||||
GObjectClass * k = G_OBJECT_CLASS (klass);
|
||||
k->dispose = (GObjectFinalizeFunc) db_calc_dispose;
|
||||
k->finalize = (GObjectFinalizeFunc) db_calc_finalize;
|
||||
k->set_property = (GObjectSetPropertyFunc) db_calc_set_property;
|
||||
k->get_property = (GObjectGetPropertyFunc) db_calc_get_property;
|
||||
|
|
100
db/db-iterator.c
100
db/db-iterator.c
|
@ -402,10 +402,11 @@ void db_iterator_move_iter (DbIterator * self, DbIter * iter)
|
|||
|
||||
if (self->mode != DB_ITERATOR_MODE_ON_DEMAND)
|
||||
{
|
||||
if (db_model_get_row_operations (self->model, &self->iter) == DB_MODEL_ROW_OP_INSERT)
|
||||
if (self->row_selected
|
||||
&& db_model_get_row_operations (self->model, &self->iter) == DB_MODEL_ROW_OP_INSERT)
|
||||
db_model_reverse_operations (self->model);
|
||||
|
||||
db_model_perform_operations (self->model, FALSE);
|
||||
else
|
||||
db_model_perform_operations (self->model, FALSE);
|
||||
}
|
||||
|
||||
db_iterator_set_iter (self, iter);
|
||||
|
@ -619,26 +620,6 @@ const GvnParamSpec * db_iterator_get_spec (DbIterator * self, gint column)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* db_iterator_get_value:
|
||||
* @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 (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_get_column_index:
|
||||
* @self: a #DbIterator
|
||||
|
@ -655,11 +636,82 @@ 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.
|
||||
|
@ -668,7 +720,7 @@ gint db_iterator_get_column_index (DbIterator * self, const gchar * name)
|
|||
*
|
||||
* Return value: %TRUE if the value was changed, %FALSE otherwise
|
||||
**/
|
||||
gboolean db_iterator_set_value (DbIterator * self, gint column, const GValue * value, GError ** err)
|
||||
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);
|
||||
|
||||
|
|
|
@ -1555,16 +1555,15 @@ void db_model_set_batch (DbModel * self, SqlBatch * batch)
|
|||
{
|
||||
g_signal_handlers_disconnect_by_func (priv->batch,
|
||||
db_model_on_batch_changed, self);
|
||||
g_object_unref (priv->batch);
|
||||
g_clear_object (&priv->batch);
|
||||
}
|
||||
if (batch)
|
||||
{
|
||||
priv->batch = g_object_ref_sink (batch);
|
||||
g_signal_connect (batch, "changed",
|
||||
G_CALLBACK (db_model_on_batch_changed), self);
|
||||
g_object_ref_sink (batch);
|
||||
db_model_on_batch_changed (NULL, self);
|
||||
}
|
||||
|
||||
priv->batch = batch;
|
||||
}
|
||||
|
||||
static ColumnDef * db_model_create_column_def (DbModel * self, const gchar * field_str)
|
||||
|
@ -2737,7 +2736,7 @@ void db_model_refresh (DbModel * self)
|
|||
|
||||
if (sql_list_length (link_operands) > 0)
|
||||
sql_batch_add (tmp_batch, "link", link_op);
|
||||
|
||||
|
||||
// Executes the statement if its ready
|
||||
|
||||
if (sql_batch_is_ready (tmp_batch))
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <glib.h>
|
||||
#include <glib/gi18n-lib.h>
|
||||
|
||||
void gvn_key_file_save (GKeyFile * obj, const gchar * file);
|
||||
void gvn_key_file_save (GKeyFile * self, const gchar * file);
|
||||
gchar * gvn_encode (const gchar * string);
|
||||
gchar * gvn_decode (const gchar * string);
|
||||
|
||||
|
|
|
@ -30,14 +30,6 @@
|
|||
|
||||
typedef struct _GvnParam GvnParam;
|
||||
typedef struct _GvnParamInterface GvnParamInterface;
|
||||
typedef enum _GvnParamStatus GvnParamStatus;
|
||||
|
||||
typedef const GValue * (* GvnParamGetValueFunc) (GvnParam * self);
|
||||
typedef gboolean (* GvnParamRequestValueFunc) (GvnParam * self, const GValue * value, GError ** err);
|
||||
typedef GvnParam * (* GvnParamGetMasterFunc) (GvnParam * self);
|
||||
typedef void (* GvnParamSetMasterFunc) (GvnParam * self, GvnParam * master);
|
||||
typedef const GvnParamSpec * (* GvnParamGetSpecFunc) (GvnParam * self);
|
||||
typedef GvnParamStatus (* GvnParamGetStatusFunc) (GvnParam * self);
|
||||
|
||||
/**
|
||||
* GvnParamStatus:
|
||||
|
@ -47,12 +39,20 @@ typedef GvnParamStatus (* GvnParamGetStatusFunc) (GvnParam * self);
|
|||
*
|
||||
* The status of the param.
|
||||
**/
|
||||
enum _GvnParamStatus
|
||||
typedef enum
|
||||
{
|
||||
GVN_PARAM_STATUS_OK
|
||||
,GVN_PARAM_STATUS_BUSY
|
||||
,GVN_PARAM_STATUS_ERROR
|
||||
};
|
||||
}
|
||||
GvnParamStatus;
|
||||
|
||||
typedef const GValue * (* GvnParamGetValueFunc) (GvnParam * self);
|
||||
typedef gboolean (* GvnParamRequestValueFunc) (GvnParam * self, const GValue * value, GError ** err);
|
||||
typedef GvnParam * (* GvnParamGetMasterFunc) (GvnParam * self);
|
||||
typedef void (* GvnParamSetMasterFunc) (GvnParam * self, GvnParam * master);
|
||||
typedef const GvnParamSpec * (* GvnParamGetSpecFunc) (GvnParam * self);
|
||||
typedef GvnParamStatus (* GvnParamGetStatusFunc) (GvnParam * self);
|
||||
|
||||
/**
|
||||
* GvnParam:
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<requires lib="gtk+" version="3.0"/>
|
||||
<requires lib="vn" version="0.0"/>
|
||||
<!-- interface-local-resource-path ../image -->
|
||||
<object class="VnBatch" id="models">
|
||||
<object class="VnSet" id="models">
|
||||
<child>
|
||||
<object class="VnModel" id="object-model">
|
||||
<property name="sql">SELECT id, object FROM object</property>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
SUBDIRS = \
|
||||
sqlite \
|
||||
pg \
|
||||
mysql
|
||||
mysql
|
||||
|
|
|
@ -15,6 +15,8 @@ libdbmysql_la_SOURCES = \
|
|||
db-mysql.h \
|
||||
db-mysql.c
|
||||
|
||||
mysql_libdir = $(plugin_libdir)/mysql
|
||||
|
||||
install-data-hook:
|
||||
rm -f $(DESTDIR)$(mysql_libdir)/libdbmysql.la
|
||||
rm -f $(DESTDIR)$(mysql_libdir)/libdbmysql.a
|
||||
rm -f $(DESTDIR)$(mysql_libdir)/libdbmysql.a
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
/**
|
||||
* SECTION: db-mysql
|
||||
* @Short_description: manages a connection to a PostgreSQL database.
|
||||
* @Short_description: manages a connection to a MySQL database.
|
||||
* @Title: DbMysql
|
||||
* @See_also: #DbConn
|
||||
*
|
||||
|
|
|
@ -15,6 +15,8 @@ libdbpg_la_SOURCES = \
|
|||
db-pg.h \
|
||||
db-pg.c
|
||||
|
||||
pg_libdir = $(plugin_libdir)/pg
|
||||
|
||||
# FIXME error durante la ejecucion del parser:
|
||||
# llama a la funcion Parse en gram.c de sql en vez de en db-pg-gram.c
|
||||
# db-pg-parser.h \
|
||||
|
@ -38,4 +40,4 @@ libdbpg_la_SOURCES = \
|
|||
|
||||
install-data-hook:
|
||||
rm -f $(DESTDIR)$(pg_libdir)/libdbpg.la
|
||||
rm -f $(DESTDIR)$(pg_libdir)/libdbpg.a
|
||||
rm -f $(DESTDIR)$(pg_libdir)/libdbpg.a
|
||||
|
|
|
@ -133,7 +133,7 @@ static void sql_value_render (SqlValue * self, SqlRender * render)
|
|||
switch (type)
|
||||
{
|
||||
case G_TYPE_BOOLEAN:
|
||||
sql_render_add_token (render, g_value_get_boolean (value) ? "TRUE" : "FALSE");
|
||||
sql_render_add_token (render, g_value_get_boolean (value) ? "1" : "0");
|
||||
break;
|
||||
case G_TYPE_CHAR:
|
||||
sql_render_printf (render, "'%c'", g_value_get_schar (value));
|
||||
|
|
|
@ -1,8 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.18.3 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.0"/>
|
||||
<requires lib="gtk+" version="3.12"/>
|
||||
<requires lib="vn" version="1.0"/>
|
||||
<!-- interface-local-resource-path ../image -->
|
||||
<object class="VnSet" id="models">
|
||||
<child>
|
||||
<object class="VnModel" id="model-connections">
|
||||
<property name="sql">SELECT rowid, name FROM connection</property>
|
||||
<property name="update_flags">DB_MODEL_INSERT | DB_MODEL_UPDATE</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnModel" id="model-connection">
|
||||
<property name="sql">SELECT rowid, name, plugin, schema, host, ssl_ca, user, password
|
||||
FROM connection WHERE #link</property>
|
||||
<property name="update_flags">DB_MODEL_UPDATE</property>
|
||||
<links>
|
||||
<link field="connection.rowid" param="edit-connection" linked="True"/>
|
||||
</links>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="VnSet" id="iterators">
|
||||
<child>
|
||||
<object class="VnIterator" id="iterator-connections">
|
||||
<property name="model">model-connections</property>
|
||||
<child>
|
||||
<object class="DbParam" id="edit-connection">
|
||||
<property name="column_name">name</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnIterator" id="iterator-conection">
|
||||
<property name="model">model-connection</property>
|
||||
<property name="mode">on-demand</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkWindow" id="window">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">15</property>
|
||||
|
@ -22,6 +59,7 @@
|
|||
<property name="height_request">40</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="spacing">15</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image2">
|
||||
|
@ -56,40 +94,28 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkGrid" id="grid1">
|
||||
<object class="GtkGrid" id="login-grid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="row_spacing">6</property>
|
||||
<property name="column_spacing">6</property>
|
||||
<property name="row_homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="user">
|
||||
<object class="GtkCheckButton" id="remember">
|
||||
<property name="label" translatable="yes">Remember</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
<property name="top_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label6">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">User:</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label7">
|
||||
<object class="GtkLabel" id="password-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
|
@ -100,7 +126,7 @@
|
|||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -114,23 +140,66 @@
|
|||
<signal name="icon-press" handler="vn_login_on_pass_show" swapped="no"/>
|
||||
<signal name="icon-release" handler="vn_login_on_pass_hide" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="user">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="remember">
|
||||
<property name="label" translatable="yes">Remember</property>
|
||||
<object class="GtkLabel" id="user-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">User:</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="connection-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">Server:</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnCombo" id="connection">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="model">model-connections</property>
|
||||
<child internal-child="widget">
|
||||
<object class="GtkComboBox" id="connection-widget">
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -172,8 +241,8 @@
|
|||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="clicked" handler="vn_login_on_connect_clicked" swapped="no"/>
|
||||
<accelerator key="KP_Enter" signal="clicked"/>
|
||||
<accelerator key="Return" signal="clicked"/>
|
||||
<accelerator key="KP_Enter" signal="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -202,39 +271,24 @@
|
|||
<property name="transient_for">window</property>
|
||||
<signal name="delete-event" handler="vn_login_settings_on_delete_event" swapped="no"/>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkBox" id="dialog-vbox1">
|
||||
<object class="GtkBox" id="settings-vbox">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">2</property>
|
||||
<child internal-child="action_area">
|
||||
<object class="GtkButtonBox" id="dialog-action_area1">
|
||||
<object class="GtkButtonBox" id="settings-actions">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">spread</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="cancel">
|
||||
<property name="label">gtk-cancel</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="clicked" handler="vn_login_on_settings_cancel_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="apply">
|
||||
<property name="label">gtk-apply</property>
|
||||
<object class="GtkButton" id="close">
|
||||
<property name="label">gtk-close</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="clicked" handler="vn_login_on_settings_apply_clicked" swapped="no"/>
|
||||
<accelerator key="KP_Enter" signal="clicked"/>
|
||||
<accelerator key="Return" signal="clicked"/>
|
||||
<accelerator key="KP_Enter" signal="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -251,104 +305,254 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkGrid" id="grid2">
|
||||
<object class="GtkBox" id="settings-box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="row_spacing">6</property>
|
||||
<property name="column_spacing">6</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="plugin">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="host">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="plugin-label">
|
||||
<object class="GtkBox" id="connections-box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">Plugin:</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolledwindow">
|
||||
<property name="width_request">130</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="VnGrid" id="connections-grid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="iterator">iterator-connections</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="grid-selection">
|
||||
<property name="mode">multiple</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnColumnEntry" id="column-connections">
|
||||
<property name="title" translatable="yes">Connections</property>
|
||||
<property name="column_name">name</property>
|
||||
<child internal-child="cell">
|
||||
<object class="GtkCellRendererText" id="column-entry-cell"/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnHandler" id="connections-handler">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="iterator">iterator-connections</property>
|
||||
<property name="show_flags">VN_HANDLER_SHOW_REMOVE | VN_HANDLER_SHOW_ADD</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="host-label">
|
||||
<object class="GtkBox" id="connetion-box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">Host:</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkGrid" id="connection-grid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="row_spacing">6</property>
|
||||
<property name="column_spacing">6</property>
|
||||
<property name="row_homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="ssl-ca-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">SSL CA:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="schema-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">Schema:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="host-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">Host:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="plugin-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">Plugin:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnEntry" id="ssl-ca">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="iterator">iterator-conection</property>
|
||||
<property name="column_name">ssl_ca</property>
|
||||
<child internal-child="widget">
|
||||
<object class="GtkEntry" id="ssl-ca-child">
|
||||
<property name="can_focus">True</property>
|
||||
<property name="secondary_icon_name">dialog-information-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnEntry" id="schema">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="iterator">iterator-conection</property>
|
||||
<property name="column_name">schema</property>
|
||||
<child internal-child="widget">
|
||||
<object class="GtkEntry" id="schema-child">
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnEntry" id="host">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="iterator">iterator-conection</property>
|
||||
<property name="column_name">host</property>
|
||||
<child internal-child="widget">
|
||||
<object class="GtkEntry" id="host-child">
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnCombo" id="plugin">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="iterator">iterator-conection</property>
|
||||
<property name="column_name">plugin</property>
|
||||
<child internal-child="widget">
|
||||
<object class="GtkComboBox" id="plugin-child">
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="name-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">Name:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnEntry" id="name">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="iterator">iterator-conection</property>
|
||||
<property name="column_name">name</property>
|
||||
<child internal-child="widget">
|
||||
<object class="GtkEntry" id="name-child">
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="VnHandler" id="handler-connection">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="iterator">iterator-conection</property>
|
||||
<property name="show_flags">VN_HANDLER_SHOW_UNDO | VN_HANDLER_SHOW_SAVE</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="schema-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">Schema:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="schema">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="ca-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">SSL CA:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="ssl-ca">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
<property name="secondary_icon_name">dialog-information-symbolic</property>
|
||||
<property name="secondary_icon_activatable">False</property>
|
||||
<property name="secondary_icon_sensitive">False</property>
|
||||
<property name="secondary_icon_tooltip_text" translatable="yes">Path to the file containing the CA certificate, if this is empty SSL won't be used</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
|
@ -361,8 +565,7 @@
|
|||
</object>
|
||||
</child>
|
||||
<action-widgets>
|
||||
<action-widget response="0">cancel</action-widget>
|
||||
<action-widget response="0">apply</action-widget>
|
||||
<action-widget response="0">close</action-widget>
|
||||
</action-widgets>
|
||||
</object>
|
||||
</interface>
|
||||
|
|
|
@ -540,12 +540,16 @@ static void vn_field_init (VnField * self)
|
|||
GTK_STATE_FLAG_NORMAL, &color);
|
||||
}
|
||||
|
||||
static void vn_field_dispose (VnField * self)
|
||||
{
|
||||
vn_field_set_master (self, NULL);
|
||||
}
|
||||
|
||||
static void vn_field_finalize (VnField * self)
|
||||
{
|
||||
gvn_param_spec_free (self->spec);
|
||||
gvn_param_spec_free (self->user_spec);
|
||||
g_clear_object (&self->iterator);
|
||||
vn_field_set_master (self, NULL);
|
||||
g_value_unset (self->value);
|
||||
g_free (self->value);
|
||||
g_free (self->column_name);
|
||||
|
@ -555,6 +559,7 @@ static void vn_field_finalize (VnField * self)
|
|||
static void vn_field_class_init (VnFieldClass * klass)
|
||||
{
|
||||
GObjectClass * k = G_OBJECT_CLASS (klass);
|
||||
k->dispose = (GObjectFinalizeFunc) vn_field_dispose;
|
||||
k->finalize = (GObjectFinalizeFunc) vn_field_finalize;
|
||||
k->set_property = (GObjectSetPropertyFunc) vn_field_set_property;
|
||||
k->get_property = (GObjectGetPropertyFunc) vn_field_get_property;
|
||||
|
|
409
vn/vn-login.c
409
vn/vn-login.c
|
@ -20,13 +20,17 @@
|
|||
#define LOGIN_UI _GUI_DIR"/login.glade"
|
||||
|
||||
#define IS_DEFINED(string) (string && g_strcmp0 (string, ""))
|
||||
#define BUILDER_GET(obj, name) ((gpointer) gtk_builder_get_object (obj, name))
|
||||
#define BUILDER_GET(self, name) ((gpointer) gtk_builder_get_object (self, name))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
VnLogin * obj;
|
||||
VnLogin * self;
|
||||
gchar * user;
|
||||
gchar * pass;
|
||||
gchar * plugin;
|
||||
gchar * host;
|
||||
gchar * schema;
|
||||
gchar * ssl_ca;
|
||||
DbConn * conn;
|
||||
GThread * thread;
|
||||
gboolean connected;
|
||||
|
@ -34,8 +38,8 @@ typedef struct
|
|||
}
|
||||
ConnectData;
|
||||
|
||||
void vn_login_on_gui_logout (VnGui * gui, VnLogin * obj);
|
||||
void vn_login_on_gui_exit (VnGui * gui, VnLogin * obj);
|
||||
void vn_login_on_gui_logout (VnGui * gui, VnLogin * self);
|
||||
void vn_login_on_gui_exit (VnGui * gui, VnLogin * self);
|
||||
|
||||
G_DEFINE_TYPE (VnLogin, vn_login, G_TYPE_OBJECT);
|
||||
|
||||
|
@ -63,146 +67,154 @@ void connect_data_free (ConnectData * connect_data)
|
|||
|
||||
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->obj);
|
||||
g_object_unref (connect_data->self);
|
||||
g_thread_unref (connect_data->thread);
|
||||
g_free (connect_data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Shows the login window to the user.
|
||||
* Loads the resources used by the login.
|
||||
*/
|
||||
static void vn_login_show (VnLogin * obj)
|
||||
static void vn_login_load (VnLogin * self)
|
||||
{
|
||||
gboolean autologin = FALSE;
|
||||
GError * err = NULL;
|
||||
GtkBuilder * builder;
|
||||
gchar * cfg_file;
|
||||
|
||||
// Initializing SQLite connection
|
||||
|
||||
cfg_file = g_build_filename (g_get_user_config_dir (), "config.db", NULL);
|
||||
|
||||
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 (!obj->window)
|
||||
if (gtk_builder_add_from_file (builder, LOGIN_UI, &err))
|
||||
{
|
||||
gchar * user;
|
||||
gchar * pass;
|
||||
GError * err = NULL;
|
||||
GtkBuilder * builder = gtk_builder_new ();
|
||||
GSList * i;
|
||||
VnSet * models;
|
||||
|
||||
models = BUILDER_GET (self->builder, "models");
|
||||
|
||||
if (gtk_builder_add_from_file (builder, LOGIN_UI, &err))
|
||||
{
|
||||
obj->window = BUILDER_GET (builder, "window");
|
||||
obj->user = BUILDER_GET (builder, "user");
|
||||
obj->pass = BUILDER_GET (builder, "password");
|
||||
obj->remember = BUILDER_GET (builder, "remember");
|
||||
obj->connect = BUILDER_GET (builder, "connect");
|
||||
obj->settings_button = BUILDER_GET (builder, "settings");
|
||||
obj->spinner = BUILDER_GET (builder, "spinner");
|
||||
obj->settings_dialog = BUILDER_GET (builder, "settings-dialog");
|
||||
obj->plugin = BUILDER_GET (builder, "plugin");
|
||||
obj->host = BUILDER_GET (builder, "host");
|
||||
obj->schema = BUILDER_GET (builder, "schema");
|
||||
obj->ssl_ca = BUILDER_GET (builder, "ssl-ca");
|
||||
gtk_builder_connect_signals (builder, obj);
|
||||
if (models)
|
||||
for (i = vn_set_get_objects (models); i; i = i->next)
|
||||
db_model_set_conn (i->data, self->cfg_conn);
|
||||
|
||||
user = g_settings_get_string (obj->settings, "user");
|
||||
pass = g_settings_get_string (obj->settings, "pass");
|
||||
|
||||
if (user && g_strcmp0 (user, ""))
|
||||
gtk_entry_set_text (obj->user, user);
|
||||
|
||||
if (pass && g_strcmp0 (pass, ""))
|
||||
{
|
||||
gchar * aux = pass;
|
||||
pass = gvn_decode (aux);
|
||||
gtk_entry_set_text (obj->pass, pass);
|
||||
gtk_toggle_button_set_active (obj->remember, TRUE);
|
||||
g_free (aux);
|
||||
autologin = TRUE;
|
||||
}
|
||||
|
||||
g_free (user);
|
||||
g_free (pass);
|
||||
|
||||
gtk_application_add_window (obj->app, obj->window);
|
||||
}
|
||||
else if (err)
|
||||
{
|
||||
g_warning ("VnLogin: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
}
|
||||
|
||||
g_object_unref (builder);
|
||||
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);
|
||||
|
||||
gtk_application_add_window (self->app, self->window);
|
||||
}
|
||||
|
||||
gtk_widget_show_all (GTK_WIDGET (obj->window));
|
||||
gtk_widget_grab_focus (GTK_WIDGET (obj->user));
|
||||
|
||||
if (autologin)
|
||||
gtk_button_clicked (obj->connect);
|
||||
|
||||
g_object_unref (builder);
|
||||
|
||||
// Freeing resources
|
||||
|
||||
exit:
|
||||
|
||||
if (err)
|
||||
{
|
||||
g_warning ("VnLogin: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
}
|
||||
|
||||
g_free (cfg_file);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enables/disables the #GtkSpinner at login dialog.
|
||||
* Shows the login window to the user.
|
||||
*/
|
||||
static void vn_login_set_loading (VnLogin * obj, gboolean loading)
|
||||
static void vn_login_show (VnLogin * self)
|
||||
{
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (obj->connect), !loading);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (obj->settings_button), !loading);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (obj->user), !loading);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (obj->pass), !loading);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (obj->remember), !loading);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Enables/disables the spinner at login dialog.
|
||||
*/
|
||||
static void vn_login_set_loading (VnLogin * self, gboolean loading)
|
||||
{
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (self->connect), !loading);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (self->settings_button), !loading);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (self->user), !loading);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (self->pass), !loading);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (self->remember), !loading);
|
||||
|
||||
if (loading)
|
||||
{
|
||||
gtk_widget_show (obj->spinner);
|
||||
gtk_widget_hide (GTK_WIDGET (obj->connect));
|
||||
gtk_widget_show (self->spinner);
|
||||
gtk_widget_hide (GTK_WIDGET (self->connect));
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (obj->spinner);
|
||||
gtk_widget_show (GTK_WIDGET (obj->connect));
|
||||
gtk_widget_hide (self->spinner);
|
||||
gtk_widget_show (GTK_WIDGET (self->connect));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Frees the GUI object.
|
||||
*/
|
||||
static void vn_login_free_gui (VnLogin * obj)
|
||||
static void vn_login_free_gui (VnLogin * self)
|
||||
{
|
||||
if (obj->gui)
|
||||
if (self->gui)
|
||||
{
|
||||
g_object_disconnect (obj->gui
|
||||
,"any_signal", vn_login_on_gui_exit, obj
|
||||
,"any_signal", vn_login_on_gui_logout, obj
|
||||
g_object_disconnect (self->gui
|
||||
,"any_signal", vn_login_on_gui_exit, self
|
||||
,"any_signal", vn_login_on_gui_logout, self
|
||||
,NULL
|
||||
);
|
||||
g_clear_object (&obj->gui);
|
||||
g_clear_object (&self->gui);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Shows the settings dialog.
|
||||
*/
|
||||
void vn_login_on_settings_clicked (GtkButton * button, VnLogin * obj)
|
||||
void vn_login_on_settings_clicked (GtkButton * button, VnLogin * self)
|
||||
{
|
||||
gchar * plugin = g_settings_get_string (obj->settings, "plugin");
|
||||
gchar * host = g_settings_get_string (obj->settings, "host");
|
||||
gchar * schema = g_settings_get_string (obj->settings, "schema");
|
||||
gchar * ssl_ca = g_settings_get_string (obj->settings, "ssl-ca");
|
||||
|
||||
gtk_entry_set_text (obj->plugin, plugin);
|
||||
gtk_entry_set_text (obj->host, host);
|
||||
gtk_entry_set_text (obj->schema, schema);
|
||||
gtk_entry_set_text (obj->ssl_ca, ssl_ca);
|
||||
gtk_dialog_run (obj->settings_dialog);
|
||||
|
||||
g_free (plugin);
|
||||
g_free (host);
|
||||
g_free (schema);
|
||||
g_free (ssl_ca);
|
||||
gtk_dialog_run (self->settings_dialog);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hides the settings dialog.
|
||||
*/
|
||||
void vn_login_on_settings_cancel_clicked (GtkButton * button, VnLogin * obj)
|
||||
void vn_login_on_settings_cancel_clicked (GtkButton * button, VnLogin * self)
|
||||
{
|
||||
gtk_widget_hide (GTK_WIDGET (obj->settings_dialog));
|
||||
gtk_widget_hide (GTK_WIDGET (self->settings_dialog));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -216,37 +228,28 @@ void vn_login_settings_on_delete_event (GtkWidget * settings_dialog)
|
|||
/*
|
||||
* Applies the changes made on settings dialog.
|
||||
*/
|
||||
void vn_login_on_settings_apply_clicked (GtkButton * button, VnLogin * obj)
|
||||
void vn_login_on_settings_apply_clicked (GtkButton * button, VnLogin * self)
|
||||
{
|
||||
const gchar * plugin = gtk_entry_get_text (obj->plugin);
|
||||
const gchar * host = gtk_entry_get_text (obj->host);
|
||||
const gchar * schema = gtk_entry_get_text (obj->schema);
|
||||
const gchar * ssl_ca = gtk_entry_get_text (obj->ssl_ca);
|
||||
|
||||
g_settings_set_string (obj->settings, "plugin", plugin);
|
||||
g_settings_set_string (obj->settings, "host", host);
|
||||
g_settings_set_string (obj->settings, "schema", schema);
|
||||
g_settings_set_string (obj->settings, "ssl-ca", ssl_ca);
|
||||
gtk_widget_hide (GTK_WIDGET (obj->settings_dialog));
|
||||
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 * obj)
|
||||
void vn_login_on_gui_logout (VnGui * gui, VnLogin * self)
|
||||
{
|
||||
g_settings_set_string (obj->settings, "pass", "");
|
||||
vn_login_free_gui (obj);
|
||||
vn_login_show (obj);
|
||||
g_settings_set_string (self->settings, "pass", "");
|
||||
vn_login_free_gui (self);
|
||||
vn_login_show (self);
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroys the login dialog when user exits from GUI.
|
||||
*/
|
||||
void vn_login_on_gui_exit (VnGui * gui, VnLogin * obj)
|
||||
void vn_login_on_gui_exit (VnGui * gui, VnLogin * self)
|
||||
{
|
||||
vn_login_free_gui (obj);
|
||||
gtk_widget_destroy (GTK_WIDGET (obj->window));
|
||||
vn_login_free_gui (self);
|
||||
gtk_widget_destroy (GTK_WIDGET (self->window));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -254,40 +257,37 @@ void vn_login_on_gui_exit (VnGui * gui, VnLogin * obj)
|
|||
*/
|
||||
static gboolean vn_login_done (ConnectData * connect_data)
|
||||
{
|
||||
VnLogin * obj = connect_data->obj;
|
||||
VnLogin * self = connect_data->self;
|
||||
|
||||
if (connect_data->connected)
|
||||
{
|
||||
const gchar * user;
|
||||
|
||||
user = gtk_entry_get_text (obj->user);
|
||||
g_settings_set_string (obj->settings, "user", user);
|
||||
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);
|
||||
|
||||
if (gtk_toggle_button_get_active (obj->remember))
|
||||
if (gvn_param_get_boolean (self->remember))
|
||||
{
|
||||
const gchar * pass = gtk_entry_get_text (obj->pass);
|
||||
gchar * aux = gvn_encode (pass);
|
||||
|
||||
gtk_toggle_button_set_active (obj->remember, FALSE);
|
||||
g_settings_set_string (obj->settings, "pass", aux);
|
||||
g_free (aux);
|
||||
GValue encoded = G_VALUE_INIT;
|
||||
g_value_take_string (&encoded, gvn_encode (gvn_param_get_string (self->pass)));
|
||||
db_iterator_set_value (self->config, "password", &encoded, NULL);
|
||||
g_value_unset (&encoded);
|
||||
}
|
||||
|
||||
gtk_entry_set_text (obj->pass, "");
|
||||
gtk_widget_hide (GTK_WIDGET (obj->window));
|
||||
obj->gui = vn_gui_new (obj->app, connect_data->conn);
|
||||
g_object_connect (obj->gui
|
||||
,"signal::logout", vn_login_on_gui_logout, obj
|
||||
,"signal::exit", vn_login_on_gui_exit, obj
|
||||
gvn_param_set_null (self->pass);
|
||||
|
||||
gtk_widget_hide (GTK_WIDGET (self->window));
|
||||
self->gui = vn_gui_new (self->app, connect_data->conn);
|
||||
g_object_connect (self->gui
|
||||
,"signal::logout", vn_login_on_gui_logout, self
|
||||
,"signal::exit", vn_login_on_gui_exit, self
|
||||
,NULL
|
||||
);
|
||||
vn_gui_open (obj->gui);
|
||||
vn_gui_open (self->gui);
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkWidget * dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (obj->window
|
||||
dialog = gtk_message_dialog_new (self->window
|
||||
,GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT
|
||||
,GTK_MESSAGE_ERROR
|
||||
,GTK_BUTTONS_OK
|
||||
|
@ -301,15 +301,15 @@ 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 (obj->pass, "");
|
||||
gtk_entry_set_text (self->pass, "");
|
||||
}
|
||||
|
||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
gtk_widget_destroy (GTK_WIDGET (dialog));
|
||||
vn_login_show (obj);
|
||||
vn_login_show (self);
|
||||
}
|
||||
|
||||
vn_login_set_loading (obj, FALSE);
|
||||
vn_login_set_loading (self, FALSE);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
|
@ -318,27 +318,18 @@ static gboolean vn_login_done (ConnectData * connect_data)
|
|||
*/
|
||||
static void vn_login_thread (ConnectData * connect_data)
|
||||
{
|
||||
gchar * plugin;
|
||||
gchar * host;
|
||||
gchar * schema;
|
||||
gchar * ssl_ca;
|
||||
VnLogin * obj = connect_data->obj;
|
||||
VnLogin * self = connect_data->self;
|
||||
|
||||
plugin = g_settings_get_string (obj->settings, "plugin");
|
||||
host = g_settings_get_string (obj->settings, "host");
|
||||
schema = g_settings_get_string (obj->settings, "schema");
|
||||
ssl_ca = g_settings_get_string (obj->settings, "ssl-ca");
|
||||
|
||||
if (IS_DEFINED (plugin) && IS_DEFINED (host) && IS_DEFINED (schema))
|
||||
if (IS_DEFINED (connect_data->plugin) && IS_DEFINED (connect_data->schema))
|
||||
{
|
||||
if (db_conn_load_plugin (connect_data->conn, plugin, &connect_data->error))
|
||||
if (db_conn_load_plugin (connect_data->conn, connect_data->plugin, &connect_data->error))
|
||||
{
|
||||
if (IS_DEFINED (ssl_ca))
|
||||
db_conn_set_ssl (connect_data->conn, ssl_ca);
|
||||
if (IS_DEFINED (connect_data->ssl_ca))
|
||||
db_conn_set_ssl (connect_data->conn, connect_data->ssl_ca);
|
||||
|
||||
connect_data->connected = db_conn_open (connect_data->conn
|
||||
,host
|
||||
,schema
|
||||
,connect_data->host
|
||||
,connect_data->schema
|
||||
,connect_data->user
|
||||
,connect_data->pass
|
||||
,&connect_data->error
|
||||
|
@ -351,11 +342,6 @@ static void vn_login_thread (ConnectData * connect_data)
|
|||
,VN_LOGIN_ERR_BAD_SETTINGS
|
||||
,_("Bad connection settings, please check it.")
|
||||
);
|
||||
|
||||
g_free (plugin);
|
||||
g_free (host);
|
||||
g_free (schema);
|
||||
g_free (ssl_ca);
|
||||
|
||||
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
|
||||
(GSourceFunc) vn_login_done, connect_data, (GDestroyNotify) connect_data_free);
|
||||
|
@ -364,16 +350,20 @@ static void vn_login_thread (ConnectData * connect_data)
|
|||
/*
|
||||
* Opens the connection.
|
||||
*/
|
||||
void vn_login_on_connect_clicked (GtkButton * button, VnLogin * obj)
|
||||
void vn_login_on_connect_clicked (GtkButton * button, VnLogin * self)
|
||||
{
|
||||
ConnectData * connect_data;
|
||||
|
||||
vn_login_set_loading (obj, TRUE);
|
||||
vn_login_set_loading (self, TRUE);
|
||||
|
||||
connect_data = g_new (ConnectData, 1);
|
||||
connect_data->obj = g_object_ref (obj);
|
||||
connect_data->user = g_strdup (gtk_entry_get_text (obj->user));
|
||||
connect_data->pass = g_strdup (gtk_entry_get_text (obj->pass));
|
||||
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;
|
||||
|
@ -381,43 +371,62 @@ void vn_login_on_connect_clicked (GtkButton * button, VnLogin * obj)
|
|||
(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))
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
gvn_param_set_value (self->pass, pass);
|
||||
}
|
||||
|
||||
/*
|
||||
* Closes the application when login window is destroyed.
|
||||
*/
|
||||
void vn_login_on_destroyed (GtkWidget * window, VnLogin * obj)
|
||||
void vn_login_on_destroyed (GtkWidget * window, VnLogin * self)
|
||||
{
|
||||
obj->window = NULL;
|
||||
self->window = NULL;
|
||||
gtk_main_quit ();
|
||||
}
|
||||
|
||||
void vn_login_on_pass_show (GtkEntry * entry, GtkEntryIconPosition * pos,
|
||||
GdkEvent * event, VnLogin * obj)
|
||||
GdkEvent * event, VnLogin * self)
|
||||
{
|
||||
gtk_entry_set_visibility (entry, TRUE);
|
||||
}
|
||||
|
||||
void vn_login_on_pass_hide (GtkEntry * entry, GtkEntryIconPosition * pos,
|
||||
GdkEvent * event, VnLogin * obj)
|
||||
GdkEvent * event, VnLogin * self)
|
||||
{
|
||||
gtk_entry_set_visibility (entry, FALSE);
|
||||
}
|
||||
|
||||
static void vn_login_on_startup (GApplication * app, VnLogin * obj)
|
||||
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 * obj)
|
||||
static void vn_login_on_activate (GApplication * app, VnLogin * self)
|
||||
{
|
||||
g_message ("Activated!");
|
||||
|
||||
if (gtk_main_level () == 0)
|
||||
{
|
||||
vn_login_show (obj);
|
||||
vn_login_show (self);
|
||||
gtk_main ();
|
||||
}
|
||||
else if (!obj->gui)
|
||||
gtk_window_present (obj->window);
|
||||
else if (!self->gui)
|
||||
gtk_window_present (self->window);
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
||||
|
@ -427,62 +436,64 @@ enum
|
|||
PROP_APPLICATION = 1
|
||||
};
|
||||
|
||||
static void vn_login_set_property (VnLogin * obj, guint id,
|
||||
static void vn_login_set_property (VnLogin * self, guint id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case PROP_APPLICATION:
|
||||
{
|
||||
obj->app = g_value_dup_object (value);
|
||||
g_object_connect (obj->app
|
||||
,"signal::startup", vn_login_on_startup, obj
|
||||
,"signal::activate", vn_login_on_activate, obj
|
||||
self->app = g_value_dup_object (value);
|
||||
g_object_connect (self->app
|
||||
,"signal::startup", vn_login_on_startup, self
|
||||
,"signal::activate", vn_login_on_activate, self
|
||||
,NULL
|
||||
);
|
||||
|
||||
obj->settings = g_settings_new (
|
||||
g_application_get_application_id (G_APPLICATION (obj->app)));
|
||||
self->settings = g_settings_new (
|
||||
g_application_get_application_id (G_APPLICATION (self->app)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void vn_login_get_property (VnLogin * obj, guint id,
|
||||
static void vn_login_get_property (VnLogin * self, guint id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
||||
|
||||
static void vn_login_init (VnLogin * obj)
|
||||
static void vn_login_init (VnLogin * self)
|
||||
{
|
||||
obj->gui = NULL;
|
||||
obj->window = NULL;
|
||||
obj->settings = NULL;
|
||||
obj->app = NULL;
|
||||
self->gui = NULL;
|
||||
self->window = NULL;
|
||||
self->settings = NULL;
|
||||
self->app = NULL;
|
||||
self->cfg_conn = NULL;
|
||||
}
|
||||
|
||||
static void vn_login_finalize (VnLogin * obj)
|
||||
static void vn_login_finalize (VnLogin * self)
|
||||
{
|
||||
vn_login_free_gui (obj);
|
||||
g_clear_object (&obj->settings);
|
||||
|
||||
g_object_disconnect (obj->app
|
||||
,"any_signal", vn_login_on_startup, obj
|
||||
,"any_signal", vn_login_on_activate, obj
|
||||
vn_login_free_gui (self);
|
||||
g_object_disconnect (self->app
|
||||
,"any_signal", vn_login_on_startup, self
|
||||
,"any_signal", vn_login_on_activate, self
|
||||
,NULL
|
||||
);
|
||||
g_clear_object (&obj->app);
|
||||
|
||||
G_OBJECT_CLASS (vn_login_parent_class)->finalize (G_OBJECT (obj));
|
||||
g_clear_object (&self->cfg_conn);
|
||||
g_clear_object (&self->settings);
|
||||
g_clear_object (&self->app);
|
||||
|
||||
G_OBJECT_CLASS (vn_login_parent_class)->finalize (G_OBJECT (self));
|
||||
}
|
||||
|
||||
static void vn_login_class_init (VnLoginClass * k)
|
||||
|
|
|
@ -24,11 +24,11 @@
|
|||
#define VN_LOGIN_LOG_DOMAIN (g_quark_from_string ("VnLogin"))
|
||||
|
||||
#define VN_TYPE_LOGIN (vn_login_get_type ())
|
||||
#define VN_LOGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, VN_TYPE_LOGIN, VnLogin))
|
||||
#define VN_IS_LOGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, VN_TYPE_LOGIN))
|
||||
#define VN_LOGIN(self) (G_TYPE_CHECK_INSTANCE_CAST (self, VN_TYPE_LOGIN, VnLogin))
|
||||
#define VN_IS_LOGIN(self) (G_TYPE_CHECK_INSTANCE_TYPE (self, VN_TYPE_LOGIN))
|
||||
#define VN_LOGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, VN_TYPE_LOGIN, VnLoginClass))
|
||||
#define VN_IS_LOGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE (klass, VN_TYPE_LOGIN))
|
||||
#define VN_LOGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS (obj, VN_TYPE_LOGIN, VnLoginClass))
|
||||
#define VN_LOGIN_GET_CLASS(self) (G_TYPE_INSTANCE_GET_CLASS (self, VN_TYPE_LOGIN, VnLoginClass))
|
||||
|
||||
typedef struct _VnLogin VnLogin;
|
||||
typedef struct _VnLoginClass VnLoginClass;
|
||||
|
@ -49,6 +49,7 @@ struct _VnLogin
|
|||
GtkWidget * stop;
|
||||
GtkButton * settings_button;
|
||||
GtkWidget * spinner;
|
||||
DbConn * cfg_conn;
|
||||
|
||||
GtkDialog * settings_dialog;
|
||||
GtkEntry * plugin;
|
||||
|
|
Reference in New Issue