From f16867e1466b2651a3ec8373d4e79f28dafaaa26 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 20 May 2009 16:48:43 +0200 Subject: [PATCH 1/1] Initial import --- .in | 22 + AUTHORS | 1 + ChangeLog | 5 + Makefile.am | 3 + NEWS | 0 README | 22 + TODO | 5 + autogen.sh | 70 ++ configure.ac | 39 + data/Makefile.am | 1 + data/gconfi/Makefile.am | 1 + data/gconfi/glade/Makefile.am | 5 + data/gconfi/glade/gconfi.glade | 1554 ++++++++++++++++++++++++++++++++ schema_examples/config1.xml | 18 + schema_examples/config2.xml | 16 + schema_examples/gconfi.dtd | 9 + schema_examples/key2.xml | 6 + schema_examples/test.xml | 5 + src/Makefile.am | 11 + src/main.c | 1449 +++++++++++++++++++++++++++++ 20 files changed, 3242 insertions(+) create mode 100644 .in create mode 100644 AUTHORS create mode 100644 ChangeLog create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100644 TODO create mode 100755 autogen.sh create mode 100644 configure.ac create mode 100644 data/Makefile.am create mode 100644 data/gconfi/Makefile.am create mode 100644 data/gconfi/glade/Makefile.am create mode 100644 data/gconfi/glade/gconfi.glade create mode 100644 schema_examples/config1.xml create mode 100644 schema_examples/config2.xml create mode 100644 schema_examples/gconfi.dtd create mode 100644 schema_examples/key2.xml create mode 100644 schema_examples/test.xml create mode 100644 src/Makefile.am create mode 100644 src/main.c diff --git a/.in b/.in new file mode 100644 index 0000000..0d1e77c --- /dev/null +++ b/.in @@ -0,0 +1,22 @@ +/* .in. Generated from configure.ac by autoheader. */ + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Version number of package */ +#undef VERSION diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..948556f --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Andrea Zagli diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..d47d1e4 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,5 @@ +2006-08-18 Andrea Zagli + + * configure.ac: + * src/Makefile.am: some improvement + * src/main.c: bugfixes on load_xml_configuration_schema() diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..b37c6a6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = src data + +EXTRA_DIST = schema_examples diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README b/README new file mode 100644 index 0000000..91bbd34 --- /dev/null +++ b/README @@ -0,0 +1,22 @@ +Configurations' database can be created with this sql commands + +CREATE TABLE configs ( + id integer NOT NULL, + name varchar(100) DEFAULT '', + description varchar(255) DEFAULT '', + CONSTRAINT configs_pkey PRIMARY KEY (id), + CONSTRAINT name_unique UNIQUE (name) +); + +CREATE TABLE "values" ( + id_configs integer NOT NULL, + id integer NOT NULL, + id_parent integer, + "key" varchar(50) DEFAULT '', + value text DEFAULT '', + description varchar(255) DEFAULT '', + CONSTRAINT values_pkey PRIMARY KEY (id_configs, id), + CONSTRAINT values_name_unique UNIQUE (id_configs, id_parent, "key") +); + +or from gConfi diff --git a/TODO b/TODO new file mode 100644 index 0000000..9ef0beb --- /dev/null +++ b/TODO @@ -0,0 +1,5 @@ +- recent provider/connection string +- gettext support +- expand/shrink all; expand/shrink node +- toolbar +- copy/paste diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..6b2c713 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd $srcdir +PROJECT=gconfi +TEST_TYPE=-f +FILE=configure.ac + +DIE=0 + +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/autoconf/" + DIE=1 +} + +if automake --version < /dev/null > /dev/null 2>&1 ; then + AUTOMAKE=automake + ACLOCAL=aclocal +else + echo + echo "You must have automake 1.7.x installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/" + DIE=1 +fi + +if test "$DIE" -eq 1; then + exit 1 +fi + +test $TEST_TYPE $FILE || { + echo "You must run this script in the top-level $PROJECT directory" + exit 1 +} + +if test -z "$AUTOGEN_SUBDIR_MODE"; then + if test -z "$*"; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." + fi +fi + +rm -rf autom4te.cache + +# README and INSTALL are required by automake, but may be deleted by clean +# up rules. to get automake to work, simply touch these here, they will be +# regenerated from their corresponding *.in files by ./configure anyway. +touch README INSTALL + +$ACLOCAL || exit $? + +autoheader || exit $? + +$AUTOMAKE --add-missing || exit $? +autoconf || exit $? +cd $ORIGDIR || exit $? + +if test -z "$AUTOGEN_SUBDIR_MODE"; then + $srcdir/configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $? + + echo + echo "Now type 'make' to compile $PROJECT." +fi diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..eb5a9cb --- /dev/null +++ b/configure.ac @@ -0,0 +1,39 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) +AC_INIT([gConfi], [0.0.2], [azagli@inwind.it]) +AC_CONFIG_SRCDIR([src/main.c]) + +AM_INIT_AUTOMAKE +AM_MAINTAINER_MODE + +AC_CANONICAL_SYSTEM + +# Checks for programs. +AC_PROG_CC + +# Checks for libraries. +PKG_CHECK_MODULES(GCONFI, [gtk+-2.0 >= 2.8.0 + libglade-2.0 >= 2.5.0 + libxml-2.0 >= 2.6.0 + libconfi >= 0.0.2]) + +AC_SUBST(GCONFI_CFLAGS) +AC_SUBST(GCONFI_LIBS) + +# Checks for header files. + +# Checks for typedefs, structures, and compiler characteristics. + +# Checks for library functions. + +AC_CONFIG_FILES([ + Makefile + src/Makefile + data/Makefile + data/gconfi/Makefile + data/gconfi/glade/Makefile +]) + +AC_OUTPUT diff --git a/data/Makefile.am b/data/Makefile.am new file mode 100644 index 0000000..36537bb --- /dev/null +++ b/data/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = gconfi diff --git a/data/gconfi/Makefile.am b/data/gconfi/Makefile.am new file mode 100644 index 0000000..21cc77b --- /dev/null +++ b/data/gconfi/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = glade diff --git a/data/gconfi/glade/Makefile.am b/data/gconfi/glade/Makefile.am new file mode 100644 index 0000000..86969b6 --- /dev/null +++ b/data/gconfi/glade/Makefile.am @@ -0,0 +1,5 @@ +gladedir = $(datadir)/gconfi/glade + +glade_DATA = gconfi.glade + +EXTRA_DIST = $(glade_DATA) diff --git a/data/gconfi/glade/gconfi.glade b/data/gconfi/glade/gconfi.glade new file mode 100644 index 0000000..a18c28e --- /dev/null +++ b/data/gconfi/glade/gconfi.glade @@ -0,0 +1,1554 @@ + + + + + + + 1 + True + gConfi + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 600 + 400 + True + False + + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + False + + + + + True + False + 0 + + + + True + GTK_PACK_DIRECTION_LTR + GTK_PACK_DIRECTION_LTR + + + + True + _Database + True + + + + + + + True + gtk-new + True + + + + + + + True + gtk-open + True + + + + + + + True + gtk-close + True + + + + + + + True + + + + + + True + gtk-refresh + True + + + + + + + True + + + + + + True + gtk-quit + True + + + + + + + + + + + True + _Configuration + True + + + + + + + True + gtk-new + True + + + + + + + True + New from _schema + True + + + + + + + True + gtk-edit + True + + + + + + + True + gtk-delete + True + + + + + + + True + E_xport + True + + + + + True + gtk-save-as + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + + + + + True + _Key + True + + + + + + + True + gtk-new + True + + + + + + + True + New from _schema + True + + + + + + + True + gtk-edit + True + + + + + + + True + gtk-delete + True + + + + + + + True + E_xport + True + + + + + True + gtk-save-as + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + + + + + True + _Help + True + + + + + + + True + gtk-about + True + + + + + + + + + + 0 + False + False + + + + + + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + False + False + False + + + + + + + + 0 + True + True + + + + + + True + True + + + 0 + False + False + + + + + + + + True + False + gConfi + Copyright (C) 2005 Andrea Zagli + gConfi is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +gConfi is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + False + Andrea Zagli <azagli@inwind.it> + translator-credits + + + + True + Open - gConfi + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + 300 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 3 + True + 3 + 2 + False + 3 + 3 + + + + True + Provider ID + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Connection String + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + False + True + + + 1 + 2 + 0 + 1 + fill + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 1 + 2 + + + + + + + True + Configurations Filter + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 2 + 3 + + + + + + 0 + True + True + + + + + + + + True + Configuration - gConfi + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 3 + True + 3 + 2 + False + 3 + 3 + + + + True + ID + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Name + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + Description + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + True + False + True + 0 + + True + * + False + + + 1 + 2 + 0 + 1 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 1 + 2 + + + + + + + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_WORD + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 1 + 2 + 2 + 3 + fill + + + + + 0 + True + True + + + + + + + + True + Key - gConfi + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 3 + True + 6 + 2 + False + 3 + 3 + + + + True + Configuration + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + ID + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + Parent + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + True + False + True + 0 + + True + * + False + + + 1 + 2 + 1 + 2 + + + + + + + True + Name + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 3 + 4 + + + + + + + True + Value + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 4 + 5 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 4 + 5 + + + + + + + True + Description + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 5 + 6 + fill + + + + + + + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_WORD + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 1 + 2 + 5 + 6 + fill + + + + + + True + False + 0 + + + + True + True + False + True + 0 + + True + * + False + + + 0 + False + False + + + + + + True + True + False + True + 0 + + True + * + False + + + 0 + True + True + + + + + 1 + 2 + 2 + 3 + fill + fill + + + + + + True + False + 0 + + + + True + True + False + True + 0 + + True + * + False + + + 0 + False + False + + + + + + True + True + False + True + 0 + + True + * + False + + + 0 + True + True + + + + + 1 + 2 + 0 + 1 + fill + fill + + + + + 0 + True + True + + + + + + + + True + New - gConfi + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + 300 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 3 + True + 4 + 2 + False + 3 + 3 + + + + True + Provider ID + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + 1° Connection String + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + False + True + + + 1 + 2 + 0 + 1 + fill + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 1 + 2 + + + + + + + True + Database Name + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 2 + 3 + + + + + + + True + 2° Connection String + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 3 + 4 + + + + + + 0 + True + True + + + + + + + diff --git a/schema_examples/config1.xml b/schema_examples/config1.xml new file mode 100644 index 0000000..4c4f2b7 --- /dev/null +++ b/schema_examples/config1.xml @@ -0,0 +1,18 @@ + + + configuration1 + the configuration description + + + key1 + key number 1 + the value of the key1 + + + key1-1 + another + + + + + diff --git a/schema_examples/config2.xml b/schema_examples/config2.xml new file mode 100644 index 0000000..f4ad05c --- /dev/null +++ b/schema_examples/config2.xml @@ -0,0 +1,16 @@ + + + configuration2 + the configuration description number 2 + + + key2cfg2 + key number 2 of confg 2 + + + + key1cfg2 + key number 1 of configuration 2 + key1cfg2 value string + + diff --git a/schema_examples/gconfi.dtd b/schema_examples/gconfi.dtd new file mode 100644 index 0000000..c64fa49 --- /dev/null +++ b/schema_examples/gconfi.dtd @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/schema_examples/key2.xml b/schema_examples/key2.xml new file mode 100644 index 0000000..0000007 --- /dev/null +++ b/schema_examples/key2.xml @@ -0,0 +1,6 @@ + + + key2 + key number 2 + no value + diff --git a/schema_examples/test.xml b/schema_examples/test.xml new file mode 100644 index 0000000..1e892c2 --- /dev/null +++ b/schema_examples/test.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..0b63e72 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,11 @@ +gladedir = $(datadir)/gconfi/glade + +AM_CPPFLAGS = $(GCONFI_CFLAGS) \ + -DGLADEDIR=\""$(gladedir)"\" + +LIBS = $(GCONFI_LIBS) \ + -export-dynamic + +bin_PROGRAMS = gconfi + +gconfi_SOURCES = main.c diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..ce25b13 --- /dev/null +++ b/src/main.c @@ -0,0 +1,1449 @@ +/* + * Copyright (C) 2005-2006 Andrea Zagli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include + +enum +{ + FOLDERS_COL_ID, + FOLDERS_COL_NAME, + FOLDERS_COL_VALUE, + FOLDERS_COL_DESCRIPTION, + FOLDERS_COL_OBJPTR, + FOLDERS_COLS +}; + +static GtkWidget *w, + *trFolders, + *mnuConfigs, + *mnuConfigsEdit, + *mnuKeys, + *mnuKeysEdit, + *mnuDbClose, + *mnuDbRefresh, + *stbar; + +static GtkTreeStore *storeFolders; + +static GtkTreeSelection *selFolders; + +static gchar *provider_id, + *cnc_string, + *filter; + +void on_mnuConfigsNew_activate (GtkMenuItem *menuitem, gpointer user_data); +void on_mnuConfigsEdit_activate (GtkMenuItem *menuitem, gpointer user_data); +void on_mnuConfigsDelete_activate (GtkMenuItem *menuitem, gpointer user_data); +void on_mnuKeysNew_activate (GtkMenuItem *menuitem, gpointer user_data); +void on_mnuKeysEdit_activate (GtkMenuItem *menuitem, gpointer user_data); +void on_mnuKeysDelete_activate (GtkMenuItem *menuitem, gpointer user_data); + +/* PRIVATE */ +static gboolean +create_trFolders () +{ + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + + storeFolders = gtk_tree_store_new (FOLDERS_COLS, + G_TYPE_INT, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_POINTER); + + gtk_tree_view_set_model (GTK_TREE_VIEW (trFolders), GTK_TREE_MODEL (storeFolders)); + + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("Name", + renderer, + "text", FOLDERS_COL_NAME, + NULL); + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (trFolders), column); + + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("Value", + renderer, + "text", FOLDERS_COL_VALUE, + NULL); + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (trFolders), column); + + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("Description", + renderer, + "text", FOLDERS_COL_DESCRIPTION, + NULL); + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (trFolders), column); + + selFolders = gtk_tree_view_get_selection (GTK_TREE_VIEW (trFolders)); + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (storeFolders), FOLDERS_COL_NAME, GTK_SORT_ASCENDING); +} + +static void +fill_trFolders_Keys (GNode *node, GtkTreeIter parent) +{ + GtkTreeIter child; + ConfiKey *ck; + + if (node == NULL) return; + + node = node->children; + while (node != NULL) + { + ck = (ConfiKey *)node->data; + + gtk_tree_store_append (storeFolders, &child, &parent); + gtk_tree_store_set (storeFolders, &child, + FOLDERS_COL_ID, ck->id, + FOLDERS_COL_NAME, ck->key, + FOLDERS_COL_DESCRIPTION, ck->description, + FOLDERS_COL_VALUE, ck->value, + FOLDERS_COL_OBJPTR, ck, + -1); + + fill_trFolders_Keys (node, child); + + node = node->next; + } +} + +static gboolean +fill_trFolders (const gchar *provider_id, const gchar *cnc_string, const gchar *filter) +{ + gboolean ret = FALSE; + + GList *lstConfigs = confi_get_configs_list (NULL, provider_id, cnc_string, filter); + + gtk_tree_store_clear (storeFolders); + + if (lstConfigs != NULL) + { + GtkTreeIter iter; + Confi *confi; + GdaDataModel *dmKeys; + gint id; + gchar *name, + *description; + GNode *tree; + + lstConfigs = g_list_first (lstConfigs); + while (lstConfigs && IS_CONFI (lstConfigs->data)) + { + confi = (Confi *)lstConfigs->data; + + g_object_get (G_OBJECT (confi), + "id_config", &id, + "name", &name, + "description", &description, + NULL); + + gtk_tree_store_append (storeFolders, &iter, NULL); + gtk_tree_store_set (storeFolders, &iter, + FOLDERS_COL_ID, id, + FOLDERS_COL_NAME, name, + FOLDERS_COL_DESCRIPTION, description, + FOLDERS_COL_OBJPTR, confi, + -1); + + tree = confi_get_tree (confi); + if (tree != NULL) + { + fill_trFolders_Keys (tree, iter); + } + + lstConfigs = g_list_next (lstConfigs); + } + + ret = TRUE; + } + + return ret; +} + +static void +view_trFolders_popup_menu (GdkEventButton *event) +{ + GtkWidget *menu = gtk_menu_new (), + *mnuitem; + + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) + { + GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); + if (path != NULL) + { + mnuitem = gtk_menu_item_new_with_mnemonic ("New _Config"); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mnuitem); + g_signal_connect (G_OBJECT (mnuitem), "activate", + G_CALLBACK (on_mnuConfigsNew_activate), NULL); + + mnuitem = gtk_menu_item_new_with_mnemonic ("New _Key"); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mnuitem); + g_signal_connect (G_OBJECT (mnuitem), "activate", + G_CALLBACK (on_mnuKeysNew_activate), NULL); + + mnuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_EDIT, NULL); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mnuitem); + if (gtk_tree_path_get_depth (path) == 1) + { + g_signal_connect (G_OBJECT (mnuitem), "activate", + G_CALLBACK (on_mnuConfigsEdit_activate), NULL); + } + else + { + g_signal_connect (G_OBJECT (mnuitem), "activate", + G_CALLBACK (on_mnuKeysEdit_activate), NULL); + } + + mnuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mnuitem); + if (gtk_tree_path_get_depth (path) == 1) + { + g_signal_connect (G_OBJECT (mnuitem), "activate", + G_CALLBACK (on_mnuConfigsDelete_activate), NULL); + } + else + { + g_signal_connect (G_OBJECT (mnuitem), "activate", + G_CALLBACK (on_mnuKeysDelete_activate), NULL); + } + } + + gtk_widget_show_all (menu); + + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, + (event != NULL) ? event->button : 0, + gdk_event_get_time ((GdkEvent*)event)); + } +} + +static void +save_key_to_xml (Confi *confi, xmlNodePtr xnodeParent, GNode *node) +{ + xmlNodePtr xnodeChild; + ConfiKey *ck; + + if (node == NULL) return; + + node = node->children; + while (node != NULL) + { + ck = (ConfiKey *)node->data; + + xnodeChild = xmlNewNode (NULL, (xmlChar *)"gconfi-key"); + xmlAddChild (xnodeParent, xnodeChild); + + xmlNewTextChild (xnodeChild, NULL, (xmlChar *)"name", (xmlChar *)ck->key); + xmlNewTextChild (xnodeChild, NULL, (xmlChar *)"description", (xmlChar *)ck->description); + + save_key_to_xml (confi, xnodeChild, node); + + node = node->next; + } +} + +static void +save_configuration_to_xml (Confi *confi, xmlNodePtr xroot) +{ + xmlNodePtr xnode; + gchar *name, + *description; + + g_object_get (G_OBJECT (confi), + "name", &name, + "description", &description, + NULL); + + xnode = xmlNewNode (NULL, (xmlChar *)"gconfi-configuration"); + xmlAddChild (xroot, xnode); + + xmlNewTextChild (xnode, NULL, (xmlChar *)"name", (xmlChar *)name); + xmlNewTextChild (xnode, NULL, (xmlChar *)"description", (xmlChar *)description); + + GNode *tree = confi_get_tree (confi); + if (tree != NULL) + { + save_key_to_xml (confi, xnode, tree); + } +} + +static void +create_key_from_xml (Confi *confi, + const gchar *pathParent, + GtkTreeIter *iterParent, + xmlNode *xnode, + xmlXPathContextPtr xpcontext) +{ + xmlXPathObjectPtr xpresult; + ConfiKey *ck; + + xpcontext->node = xnode; + + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::name", xpcontext); + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + { + xmlNodeSetPtr xnodeset = xpresult->nodesetval; + if (xnodeset->nodeNr == 1) + { + GtkTreeIter iter; + + ck = confi_add_key (confi, pathParent, (const gchar *)xmlNodeGetContent (xnodeset->nodeTab[0])); + + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::description", xpcontext); + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + { + xnodeset = xpresult->nodesetval; + if (xnodeset->nodeNr == 1) + { + ck->description = g_strdup ((gchar *)xmlNodeGetContent (xnodeset->nodeTab[0])); + + confi_key_set_key (confi, ck); + } + } + + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::value", xpcontext); + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + { + xnodeset = xpresult->nodesetval; + if (xnodeset->nodeNr == 1) + { + ck->value = g_strdup ((gchar *)xmlNodeGetContent (xnodeset->nodeTab[0])); + + confi_key_set_key (confi, ck); + } + } + + gtk_tree_store_append (storeFolders, &iter, iterParent); + gtk_tree_store_set (storeFolders, &iter, + FOLDERS_COL_ID, ck->id, + FOLDERS_COL_NAME, ck->key, + FOLDERS_COL_VALUE, ck->value, + FOLDERS_COL_DESCRIPTION, ck->description, + FOLDERS_COL_OBJPTR, ck, + -1); + + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::gconfi-key", xpcontext); + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + { + gint i; + + xnodeset = xpresult->nodesetval; + for (i = 0; i < xnodeset->nodeNr; i++) + { + create_key_from_xml (confi, + g_strjoin (NULL, ck->path, (strcmp (ck->path, "") == 0 ? "" : "/"), ck->key, NULL), + &iter, + xnodeset->nodeTab[i], xpcontext); + } + } + } + } +} + +static void +create_config_from_xml (xmlNode *xnode, xmlXPathContextPtr xpcontext) +{ + xmlXPathObjectPtr xpresult; + Confi *confi; + + xpcontext->node = xnode; + + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::name", xpcontext); + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + { + xmlNodeSetPtr xnodeset = xpresult->nodesetval; + if (xnodeset->nodeNr == 1) + { + + confi = confi_new (NULL, provider_id, cnc_string, + (const gchar *)xmlNodeGetContent (xnodeset->nodeTab[0]), NULL, TRUE); + if (confi != NULL) + { + GtkTreeIter iter; + gint id; + gchar *name, + *description; + + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::description", xpcontext); + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + { + xnodeset = xpresult->nodesetval; + if (xnodeset->nodeNr == 1) + { + g_object_set (G_OBJECT (confi), + "description", xmlNodeGetContent (xnodeset->nodeTab[0]), + NULL); + } + } + + g_object_get (G_OBJECT (confi), + "id_config", &id, + "name", &name, + "description", &description, + NULL); + + gtk_tree_store_append (storeFolders, &iter, NULL); + gtk_tree_store_set (storeFolders, &iter, + FOLDERS_COL_ID, id, + FOLDERS_COL_NAME, name, + FOLDERS_COL_DESCRIPTION, description, + FOLDERS_COL_OBJPTR, confi, + -1); + + xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::gconfi-key", xpcontext); + if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval)) + { + gint i; + + xnodeset = xpresult->nodesetval; + for (i = 0; i < xnodeset->nodeNr; i++) + { + create_key_from_xml (confi, "", &iter, xnodeset->nodeTab[i], xpcontext); + } + } + } + } + } +} + +static void +load_xml_configuration_schema (const gchar *filename) +{ + GNode *tree = NULL; + + xmlDocPtr xdoc = xmlParseFile (filename); + if (xdoc != NULL) + { + if (xmlXIncludeProcess (xdoc) == -1) + { + g_warning ("Error on xmlXIncludeProcess.\n"); + return; + } + + xmlXPathContextPtr xpcontext = xmlXPathNewContext (xdoc); + if (xpcontext != NULL) + { + xmlNode *xnode = xmlDocGetRootElement (xdoc); + if (xnode != NULL) + { + if (strcmp (xnode->name, "gconfi") == 0) + { + xnode = xnode->children; + while (xnode != NULL) + { + if (strcmp (xnode->name, "gconfi-configuration") == 0) + { + create_config_from_xml (xnode, xpcontext); + } + + xnode = xnode->next; + } + } + else if (strcmp (xnode->name, "gconfi-configuration") == 0) + { + create_config_from_xml (xnode, xpcontext); + } + else if (strcmp (xnode->name, "gconfi-key") == 0) + { + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) + { + GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); + if (path != NULL) + { + if (gtk_tree_path_get_depth (path) == 1) + { + Confi *confi; + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, + FOLDERS_COL_OBJPTR, &confi, + -1); + + create_key_from_xml (confi, "", &iter, xnode, xpcontext); + } + else /* if (gtk_tree_path_get_depth (path) > 1 */ + { + GtkTreeIter iterConfi; + + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (storeFolders), &iterConfi, + gtk_tree_path_new_from_indices (gtk_tree_path_get_indices (path)[0], -1))) + { + Confi *confi; + ConfiKey *ck; + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iterConfi, + FOLDERS_COL_OBJPTR, &confi, + -1); + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, + FOLDERS_COL_OBJPTR, &ck, + -1); + + if (IS_CONFI (confi)) + { + create_key_from_xml (confi, g_strconcat (ck->path, "/", ck->key, NULL), &iter, xnode, xpcontext); + } + } + } + } + } + } + else + { + g_warning ("%s is not a valid gConfi schema for configurations.", filename); + } + } + else + { + g_warning ("%s is not a valid gConfi schema for configurations.", filename); + } + } + else + { + g_warning ("Error on xmlXPathNewContext."); + } + } + else + { + g_warning ("Error on xml parsing file %s.", filename); + } +} + +/* CALLBACKS */ +void +on_mnuDbNew_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GladeXML *glaOpenDbCfg = glade_xml_new (GLADEDIR "/gconfi.glade", "diagNewDbCfg", NULL); + GtkWidget *diag = glade_xml_get_widget (glaOpenDbCfg, "diagNewDbCfg"); + + GtkWidget *cbProvider = glade_xml_get_widget (glaOpenDbCfg, "cbProvider"), + *txtCncString1 = glade_xml_get_widget (glaOpenDbCfg, "txtCncString1"), + *txtDbName = glade_xml_get_widget (glaOpenDbCfg, "txtDbName"), + *txtCncString2 = glade_xml_get_widget (glaOpenDbCfg, "txtCncString2"); + + GtkListStore *store; + GtkTreeIter iter; + GtkCellRenderer *renderer; + + store = gtk_list_store_new (1, G_TYPE_STRING); + gtk_combo_box_set_model (GTK_COMBO_BOX (cbProvider), GTK_TREE_MODEL (store)); + + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbProvider), renderer, FALSE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (cbProvider), renderer, + "text", 0); + + /* fill providers list */ + GList *providers = gda_config_get_provider_list (); + if (providers != NULL) + { + do { + GdaProviderInfo *pi = (GdaProviderInfo *)providers->data; + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, pi->id, -1); + } while ((providers = g_list_next (providers)) != NULL); + + gda_config_free_provider_list (providers); + } + + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_OK) + { + provider_id = g_strstrip (g_strdup (gtk_combo_box_get_active_text (GTK_COMBO_BOX (cbProvider)))); + cnc_string = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txtCncString1)))); + gchar *dbName = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txtDbName)))); + if (strcmp (provider_id, "") != 0 && + strcmp (cnc_string, "") != 0) + { + GdaO *gdao = gdao_new_from_string (NULL, provider_id, cnc_string); + if (gdao != NULL) + { + GdaConnection *gdaConn = (GdaConnection *)gdao_get_gdaconnection (gdao); + if (gdaConn == NULL) + { + /* TO DO */ + g_fprintf(stderr,"error on first connection\n"); + } + else + { + if (strcmp (dbName, "") != 0) + { + cnc_string = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txtCncString2)))); + if (strcmp (cnc_string, "") != 0) + { + if (!gda_connection_create_database (gdaConn, dbName)) + { + /* TO DO */ + g_fprintf(stderr,"error on database creation\n"); + gdao = NULL; + } + else + { + if (!gda_connection_change_database (gdaConn, dbName)) + { + gda_connection_close (gdaConn); + gdao = gdao_new_from_string (NULL, provider_id, cnc_string); + if (gdao == NULL) + { + /* TO DO */ + g_fprintf(stderr,"error on second connection\n"); + gdao = NULL; + } + } + } + } + else + { + /* TO DO */ + g_fprintf(stderr,"second connection must be specified\n"); + gdao = NULL; + } + } + + if (gdao != NULL) + { + if (gdao_execute (gdao, "CREATE TABLE configs " + "(" + " id integer NOT NULL, " + " name varchar(100) DEFAULT '', " + " description varchar(255) DEFAULT '', " + " CONSTRAINT configs_pkey PRIMARY KEY (id), " + " CONSTRAINT name_unique UNIQUE (name)" + ")") == -1) + { + /* TO DO */ + gdao = NULL; + } + else + { + gchar chrquot = '\"'; + gchar *sql; + + if (strcmp (provider_id, "MySQL") == 0) + { + chrquot = '`'; + } + + sql = g_strdup_printf ("CREATE TABLE %cvalues%c " + "(" + " id_configs integer NOT NULL, " + " id integer NOT NULL, " + " id_parent integer, " + " %ckey%c varchar(50) DEFAULT '', " + " value text DEFAULT '', " + " description varchar(255) DEFAULT '', " + " CONSTRAINT values_pkey PRIMARY KEY (id_configs, id), " + " CONSTRAINT values_name_unique UNIQUE (id_configs, id_parent, %ckey%c)" + ")", + chrquot, chrquot, chrquot, chrquot, chrquot, chrquot); + + if (gdao_execute (gdao, sql) == -1) + { + /* TO DO */ + gdao = NULL; + } + else + { + if (fill_trFolders (provider_id, cnc_string, NULL)) + { + gtk_widget_set_sensitive (mnuDbClose, TRUE); + gtk_widget_set_sensitive (mnuDbRefresh, TRUE); + gtk_widget_set_sensitive (mnuConfigs, TRUE); + gtk_widget_set_sensitive (mnuKeys, TRUE); + + gtk_statusbar_pop (GTK_STATUSBAR (stbar), 0); + gtk_statusbar_push (GTK_STATUSBAR (stbar), 0, + g_strconcat ("Provider: ", provider_id, " - Connection string: ", cnc_string, NULL)); + } + } + } + } + } + } + } + } + + gtk_widget_destroy (diag); +} + +void +on_mnuDbOpen_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GladeXML *glaOpenDbCfg = glade_xml_new (GLADEDIR "/gconfi.glade", "diagOpenDbCfg", NULL); + GtkWidget *diag = glade_xml_get_widget (glaOpenDbCfg, "diagOpenDbCfg"); + + GtkWidget *cbProvider = glade_xml_get_widget (glaOpenDbCfg, "cbProvider"), + *txtCncString = glade_xml_get_widget (glaOpenDbCfg, "txtCncString"), + *txtConfigsFilter = glade_xml_get_widget (glaOpenDbCfg, "txtConfigsFilter"); + + GtkListStore *store; + GtkTreeIter iter; + GtkCellRenderer *renderer; + + store = gtk_list_store_new (1, G_TYPE_STRING); + gtk_combo_box_set_model (GTK_COMBO_BOX (cbProvider), GTK_TREE_MODEL (store)); + + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbProvider), renderer, FALSE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (cbProvider), renderer, + "text", 0); + + /* fill providers list */ + GList *providers = gda_config_get_provider_list (); + if (providers != NULL) + { + do { + GdaProviderInfo *pi = (GdaProviderInfo *)providers->data; + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, pi->id, -1); + + } while ((providers = g_list_next (providers)) != NULL); + + gda_config_free_provider_list (providers); + } + + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_OK) + { + provider_id = g_strdup (gtk_combo_box_get_active_text (GTK_COMBO_BOX (cbProvider))); + cnc_string = g_strdup (gtk_entry_get_text (GTK_ENTRY (txtCncString))); + if (provider_id != NULL && cnc_string != NULL) + { + filter = (gchar *)gtk_entry_get_text (GTK_ENTRY (txtConfigsFilter)); + if (fill_trFolders (provider_id, cnc_string, filter)) + { + gtk_widget_set_sensitive (mnuDbClose, TRUE); + gtk_widget_set_sensitive (mnuDbRefresh, TRUE); + gtk_widget_set_sensitive (mnuConfigs, TRUE); + gtk_widget_set_sensitive (mnuKeys, TRUE); + + gtk_statusbar_pop (GTK_STATUSBAR (stbar), 0); + gtk_statusbar_push (GTK_STATUSBAR (stbar), 0, + g_strconcat ("Provider: ", provider_id, " - Connection string: ", cnc_string, NULL)); + } + } + } + + gtk_widget_destroy (diag); +} + +void +on_mnuDbClose_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + provider_id = g_strdup (""); + cnc_string = g_strdup (""); + + /* TO DO */ + /* deallocate first every Confi object */ + + gtk_tree_store_clear (storeFolders); + + gtk_widget_set_sensitive (mnuDbClose, FALSE); + gtk_widget_set_sensitive (mnuDbRefresh, FALSE); + gtk_widget_set_sensitive (mnuConfigs, FALSE); + gtk_widget_set_sensitive (mnuKeys, FALSE); + + gtk_statusbar_pop (GTK_STATUSBAR (stbar), 0); +} + +void +on_mnuDbRefresh_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + fill_trFolders (provider_id, cnc_string, filter); +} + +void +on_mnuConfigsNew_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GladeXML *glaCNew = glade_xml_new (GLADEDIR "/gconfi.glade", "wConfiguration", NULL); + GtkWidget *diag = glade_xml_get_widget (glaCNew, "wConfiguration"); + + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_OK) + { + GtkWidget *txtName, + *txtvDescription, + *fcbSchema; + GtkTextBuffer *buffer; + GtkTextIter iter1, iter2; + gchar *name, + *description; + Confi *confi; + + txtName = glade_xml_get_widget (glaCNew, "txtName"); + txtvDescription = glade_xml_get_widget (glaCNew, "txtvDescription"); + + name = (gchar *)gtk_entry_get_text (GTK_ENTRY (txtName)); + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvDescription)); + gtk_text_buffer_get_bounds (buffer, &iter1, &iter2); + description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE); + + confi = confi_new (NULL, provider_id, cnc_string, + name, + NULL, TRUE); + if (confi != NULL) + { + GtkTreeIter iter; + gint id; + + g_object_set (G_OBJECT (confi), + "description", description, + NULL); + + g_object_get (G_OBJECT (confi), + "id_config", &id, + NULL); + + gtk_tree_store_append (storeFolders, &iter, NULL); + gtk_tree_store_set (storeFolders, &iter, + FOLDERS_COL_ID, id, + FOLDERS_COL_NAME, name, + FOLDERS_COL_DESCRIPTION, description, + FOLDERS_COL_OBJPTR, confi, + -1); + } + } + + gtk_widget_destroy (diag); +} + +void +on_mnuConfigsNewFromSchema_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkWidget *diag = gtk_file_chooser_dialog_new ("Choose a schema file - gConfi", + GTK_WINDOW (w), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_ACCEPT) + { + const gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (diag)); + load_xml_configuration_schema (filename); + } + + gtk_widget_destroy (diag); +} + +void +on_mnuConfigsEdit_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) + { + GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); + if (path != NULL && gtk_tree_path_get_depth (path) == 1) + { + Confi *confi; + + GladeXML *glaConfig = glade_xml_new (GLADEDIR "/gconfi.glade", "wConfiguration", NULL); + GtkWidget *diag = glade_xml_get_widget (glaConfig, "wConfiguration"), + *txtID = glade_xml_get_widget (glaConfig, "txtID"), + *txtName = glade_xml_get_widget (glaConfig, "txtName"), + *txtvDescription = glade_xml_get_widget (glaConfig, "txtvDescription"); + GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvDescription)); + + gint id; + gchar *name, + *description; + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, + FOLDERS_COL_OBJPTR, &confi, + -1); + + g_object_get (G_OBJECT (confi), + "id_config", &id, + "name", &name, + "description", &description, + NULL); + + gtk_entry_set_text (GTK_ENTRY (txtID), g_strdup_printf ("%d", id)); + gtk_entry_set_text (GTK_ENTRY (txtName), name); + gtk_text_buffer_set_text (buffer, description, strlen (description)); + + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_OK) + { + GtkTextIter iter1, iter2; + + name = g_strdup (gtk_entry_get_text (GTK_ENTRY (txtName))); + gtk_text_buffer_get_bounds (buffer, &iter1, &iter2); + description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE); + + g_object_set (G_OBJECT (confi), + "name", name, + "description", description, + NULL); + + gtk_tree_store_set (storeFolders, &iter, + FOLDERS_COL_NAME, name, + FOLDERS_COL_DESCRIPTION, description, + FOLDERS_COL_OBJPTR, confi, + -1); + } + + gtk_widget_destroy (diag); + } + } +} + +void +on_mnuConfigsDelete_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) + { + GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); + if (path != NULL && gtk_tree_path_get_depth (path) == 1) + { + Confi *confi; + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, + FOLDERS_COL_OBJPTR, &confi, + -1); + if (IS_CONFI (confi)) + { + GtkWidget *diag = gtk_message_dialog_new (GTK_WINDOW (w), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + "Are you sure you want to delete the selected configuration from database?"); + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_YES) + { + if (confi_remove (confi)) + { + gtk_tree_store_remove (storeFolders, &iter); + } + } + + gtk_widget_destroy (diag); + } + } + } +} + +void +on_mnuConfigsExport_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkWidget *diag = gtk_file_chooser_dialog_new ("Export Configurations - gConfi", + GTK_WINDOW (w), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_ACCEPT) + { + Confi *confi; + gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (diag)); + + GtkTreeIter iter; + if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) + { + /* saving only selected configuration */ + GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); + if (gtk_tree_path_get_depth (path) > 1) + { + path = gtk_tree_path_new_from_indices (gtk_tree_path_get_indices (path)[0], -1); + gtk_tree_model_get_iter (GTK_TREE_MODEL (storeFolders), &iter, path); + } + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, + FOLDERS_COL_OBJPTR, &confi, + -1); + if (IS_CONFI (confi)) + { + xmlDocPtr xdoc; + xmlNodePtr xnode; + + xdoc = xmlNewDoc ((xmlChar *)"1.0"); + xnode = xmlNewNode (NULL, (xmlChar *)"gconfi"); + xmlDocSetRootElement (xdoc, xnode); + + save_configuration_to_xml (confi, xnode); + + xmlSaveFile (filename, xdoc); + } + + gtk_tree_path_free (path); + } + else + { + /* saving all configurations */ + GList *configs = confi_get_configs_list (NULL, provider_id, cnc_string, filter); + if (configs != NULL) + { + xmlDocPtr xdoc; + xmlNodePtr xnode; + + xdoc = xmlNewDoc ((xmlChar *)"1.0"); + xnode = xmlNewNode (NULL, (xmlChar *)"gconfi"); + xmlDocSetRootElement (xdoc, xnode); + + configs = g_list_first (configs); + while (configs != NULL) + { + confi = (Confi *)configs->data; + + save_configuration_to_xml (confi, xnode); + + configs = g_list_next (configs); + } + + xmlSaveFile (filename, xdoc); + } + } + + g_free (filename); + } + + gtk_widget_destroy (diag); +} + +void +on_mnuKeysNew_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) + { + GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); + if (path != NULL) + { + Confi *confi; + ConfiKey *ck; + GladeXML *glaKey = glade_xml_new (GLADEDIR "/gconfi.glade", "wKey", NULL); + GtkWidget *diag = glade_xml_get_widget (glaKey, "wKey"), + *txtIDConfig = glade_xml_get_widget (glaKey, "txtIDConfig"), + *txtConfig = glade_xml_get_widget (glaKey, "txtConfig"), + *txtID = glade_xml_get_widget (glaKey, "txtID"), + *txtIDParent = glade_xml_get_widget (glaKey, "txtIDParent"), + *txtParent = glade_xml_get_widget (glaKey, "txtParent"), + *txtName = glade_xml_get_widget (glaKey, "txtName"), + *txtValue = glade_xml_get_widget (glaKey, "txtValue"), + *txtvDescription = glade_xml_get_widget (glaKey, "txtvDescription"); + GtkTreeIter iterConfi; + gint id_config; + gchar *name, + *keyPath = ""; + + if (gtk_tree_path_get_depth (path) == 1) + { + iterConfi = iter; + gtk_entry_set_text (GTK_ENTRY (txtIDParent), "0"); + } + else + { + gtk_tree_model_get_iter (GTK_TREE_MODEL (storeFolders), &iterConfi, + gtk_tree_path_new_from_indices (gtk_tree_path_get_indices (path)[0], -1)); + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, + FOLDERS_COL_OBJPTR, &ck, + -1); + + keyPath = g_strjoin (NULL, ck->path, "/", ck->key, NULL); + gtk_entry_set_text (GTK_ENTRY (txtIDParent), g_strdup_printf ("%d", ck->id)); + gtk_entry_set_text (GTK_ENTRY (txtParent), ck->key); + } + + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iterConfi, + FOLDERS_COL_OBJPTR, &confi, + -1); + + g_object_get (G_OBJECT (confi), + "id_config", &id_config, + "name", &name, + NULL); + + gtk_entry_set_text (GTK_ENTRY (txtIDConfig), g_strdup_printf ("%d", id_config)); + gtk_entry_set_text (GTK_ENTRY (txtConfig), name); + + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_OK) + { + GtkTextIter iter1, iter2; + GtkTreeIter parent = iter; + + gint id; + gchar *name = (gchar *)gtk_entry_get_text (GTK_ENTRY (txtName)), + *value = (gchar *)gtk_entry_get_text (GTK_ENTRY (txtValue)), + *description; + GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvDescription)); + + gtk_text_buffer_get_bounds (buffer, &iter1, &iter2); + description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE); + + ck = confi_add_key (confi, keyPath, name); + if (ck != NULL) + { + ck->value = value; + ck->description = description; + confi_key_set_key (confi, ck); + + gtk_tree_store_append (storeFolders, &iter, &parent); + gtk_tree_store_set (storeFolders, &iter, + FOLDERS_COL_ID, ck->id, + FOLDERS_COL_NAME, name, + FOLDERS_COL_VALUE, value, + FOLDERS_COL_DESCRIPTION, description, + FOLDERS_COL_OBJPTR, ck, + -1); + } + } + + gtk_widget_destroy (diag); + } + } +} + +void +on_mnuKeysNewFromSchema_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkWidget *diag = gtk_file_chooser_dialog_new ("Choose a key's schema file - gConfi", + GTK_WINDOW (w), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_ACCEPT) + { + const gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (diag)); + load_xml_configuration_schema (filename); + } + + gtk_widget_destroy (diag); +} + +void +on_mnuKeysEdit_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) + { + GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); + if (path != NULL && gtk_tree_path_get_depth (path) > 1) + { + Confi *confi; + GladeXML *glaKey = glade_xml_new (GLADEDIR "/gconfi.glade", "wKey", NULL); + GtkWidget *diag = glade_xml_get_widget (glaKey, "wKey"), + *txtIDConfig = glade_xml_get_widget (glaKey, "txtIDConfig"), + *txtConfig = glade_xml_get_widget (glaKey, "txtConfig"), + *txtID = glade_xml_get_widget (glaKey, "txtID"), + *txtIDParent = glade_xml_get_widget (glaKey, "txtIDParent"), + *txtParent = glade_xml_get_widget (glaKey, "txtParent"), + *txtName = glade_xml_get_widget (glaKey, "txtName"), + *txtValue = glade_xml_get_widget (glaKey, "txtValue"), + *txtvDescription = glade_xml_get_widget (glaKey, "txtvDescription"); + GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvDescription)); + + ConfiKey *ck; + + GtkTreeIter iterConfi, + iterParent; + + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (storeFolders), &iterConfi, + gtk_tree_path_new_from_indices (gtk_tree_path_get_indices (path)[0], -1))) + { + gchar *name; + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iterConfi, + FOLDERS_COL_OBJPTR, &confi, + -1); + + g_object_get (G_OBJECT (confi), + "name", &name, + NULL); + + gtk_entry_set_text (GTK_ENTRY (txtConfig), name); + } + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, + FOLDERS_COL_OBJPTR, &ck, + -1); + + if (ck != NULL) + { + gtk_entry_set_text (GTK_ENTRY (txtIDConfig), g_strdup_printf ("%d", ck->id_config)); + gtk_entry_set_text (GTK_ENTRY (txtID), g_strdup_printf ("%d", ck->id)); + gtk_entry_set_text (GTK_ENTRY (txtIDParent), g_strdup_printf ("%d", ck->id_parent)); + gtk_entry_set_text (GTK_ENTRY (txtName), ck->key); + gtk_entry_set_text (GTK_ENTRY (txtValue), ck->value); + gtk_text_buffer_set_text (buffer, ck->description, strlen (ck->description)); + + if (ck->id_parent > 0 && gtk_tree_model_iter_parent (GTK_TREE_MODEL (storeFolders), &iterParent, &iter)) + { + ConfiKey *ckParent; + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iterParent, + FOLDERS_COL_OBJPTR, &ckParent, + -1); + + gtk_entry_set_text (GTK_ENTRY (txtParent), ckParent->key); + } + + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_OK) + { + GtkTextIter iter1, iter2; + + ck->key = g_strdup (gtk_entry_get_text (GTK_ENTRY (txtName))); + ck->value = g_strdup (gtk_entry_get_text (GTK_ENTRY (txtValue))); + + gtk_text_buffer_get_bounds (buffer, &iter1, &iter2); + ck->description = gtk_text_buffer_get_text (buffer, &iter1, &iter2, FALSE); + + confi_key_set_key (confi, ck); + + gtk_tree_store_set (storeFolders, &iter, + FOLDERS_COL_NAME, ck->key, + FOLDERS_COL_VALUE, ck->value, + FOLDERS_COL_DESCRIPTION, ck->description, + FOLDERS_COL_OBJPTR, ck, + -1); + } + } + + gtk_widget_destroy (diag); + } + } +} + +void +on_mnuKeysDelete_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) + { + GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); + if (path != NULL && gtk_tree_path_get_depth (path) > 1) + { + GtkWidget *diag = gtk_message_dialog_new (GTK_WINDOW (w), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + "Are you sure you want to delete the selected key from database?"); + if (gtk_dialog_run (GTK_DIALOG (diag)) == GTK_RESPONSE_YES) + { + Confi *confi; + + GtkTreeIter iterConfig; + gtk_tree_model_get_iter (GTK_TREE_MODEL (storeFolders), &iterConfig, + gtk_tree_path_new_from_indices (gtk_tree_path_get_indices (path)[0], -1)); + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iterConfig, + FOLDERS_COL_OBJPTR, &confi, + -1); + + if (IS_CONFI (confi)) + { + ConfiKey *ck; + + gtk_tree_model_get (GTK_TREE_MODEL (storeFolders), &iter, + FOLDERS_COL_OBJPTR, &ck, + -1); + + if (confi_remove_path (confi, g_strconcat (ck->path, "/", ck->key, NULL))) + { + gtk_tree_store_remove (storeFolders, &iter); + } + } + } + + gtk_widget_destroy (diag); + } + } +} + +void +on_mnuKeysExport_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ +} + +void +on_mnuHelpAbout_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GladeXML *glaAbout = glade_xml_new (GLADEDIR "/gconfi.glade", "diagAbout", NULL); + GtkWidget *diag = glade_xml_get_widget (glaAbout, "diagAbout"); + gtk_dialog_run (GTK_DIALOG (diag)); + gtk_widget_destroy (diag); +} + +gboolean +on_trFolders_button_press_event (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data) +{ + /* single click with the right mouse button? */ + if (event->type == GDK_BUTTON_PRESS && event->button == 3) + { + /* select row if no row is selected */ + if (gtk_tree_selection_count_selected_rows (selFolders) <= 1) + { + GtkTreePath *path; + if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (trFolders), + (gint) event->x, + (gint) event->y, + &path, NULL, NULL, NULL)) + { + gtk_tree_selection_unselect_all (selFolders); + gtk_tree_selection_select_path (selFolders, path); + gtk_tree_path_free (path); + } + } + + view_trFolders_popup_menu (event); + return TRUE; + } + + return FALSE; +} + +gboolean +on_trFolders_popup_menu (GtkWidget *widget, + gpointer user_data) +{ + view_trFolders_popup_menu (NULL); + + return TRUE; +} + +void +on_trFolders_row_activated (GtkTreeView *tree_view, + GtkTreePath *path, + GtkTreeViewColumn *column, + gpointer user_data) +{ + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected (selFolders, NULL, &iter)) + { + GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (storeFolders), &iter); + if (path != NULL) + { + if (gtk_tree_path_get_depth (path) == 1) + { + g_signal_emit_by_name (mnuConfigsEdit, "activate"); + } + else + { + g_signal_emit_by_name (mnuKeysEdit, "activate"); + } + } + } +} + +int +main (int argc, char **argv) +{ + GladeXML *glaMain; + + GOptionEntry entries[] = + { + { "provider_id", 'p', 0, G_OPTION_ARG_STRING, &provider_id, "Provider ID", NULL }, + { "cnc_string", 'c', 0, G_OPTION_ARG_STRING, &cnc_string, "Connection string", NULL }, + { "filter", 'f', 0, G_OPTION_ARG_STRING, &filter, "Configurations filter", NULL }, + { NULL } + }; + + GOptionContext *context; + GError *error = NULL; + + gtk_init (&argc, &argv); + + glaMain = glade_xml_new (GLADEDIR "/gconfi.glade", "wMain", NULL); + glade_xml_signal_autoconnect (glaMain); + + w = glade_xml_get_widget (glaMain, "wMain"); + trFolders = glade_xml_get_widget (glaMain, "trFolders"); + mnuDbClose = glade_xml_get_widget (glaMain, "mnuDbClose"); + mnuDbRefresh = glade_xml_get_widget (glaMain, "mnuDbRefresh"); + mnuConfigs = glade_xml_get_widget (glaMain, "mnuConfigs"); + mnuConfigsEdit = glade_xml_get_widget (glaMain, "mnuConfigsEdit"); + mnuKeys = glade_xml_get_widget (glaMain, "mnuKeys"); + mnuKeysEdit = glade_xml_get_widget (glaMain, "mnuKeysEdit"); + stbar = glade_xml_get_widget (glaMain, "stbar"); + + gtk_widget_set_sensitive (mnuDbClose, FALSE); + gtk_widget_set_sensitive (mnuDbRefresh, FALSE); + gtk_widget_set_sensitive (mnuConfigs, FALSE); + gtk_widget_set_sensitive (mnuKeys, FALSE); + + create_trFolders (); + + /* command line options */ + context = g_option_context_new (""); + g_option_context_add_main_entries (context, entries, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + /* TO DO */ + return 0; + } + + if (provider_id != NULL && cnc_string != NULL) + { + if (fill_trFolders (provider_id, cnc_string, filter)) + { + gtk_widget_set_sensitive (mnuDbClose, TRUE); + gtk_widget_set_sensitive (mnuDbRefresh, TRUE); + gtk_widget_set_sensitive (mnuConfigs, TRUE); + gtk_widget_set_sensitive (mnuKeys, TRUE); + + gtk_statusbar_pop (GTK_STATUSBAR (stbar), 0); + gtk_statusbar_push (GTK_STATUSBAR (stbar), 0, + g_strconcat ("Provider: ", provider_id, " - Connection string: ", cnc_string, NULL)); + } + } + + gtk_main (); + + return 0; +} -- 2.49.0