[dia] Port xslt plugin to GtkComboBoxText
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] Port xslt plugin to GtkComboBoxText
- Date: Tue, 14 May 2019 16:02:24 +0000 (UTC)
commit 8d7fc4f4a2a54f91faecda065894a14fedbe1afb
Author: Zander Brown <zbrown gnome org>
Date: Tue May 14 17:01:54 2019 +0100
Port xslt plugin to GtkComboBoxText
One less use of dep widgets
plug-ins/xslt/xslt.c | 589 ++++++++++++++++++++++-----------------------
plug-ins/xslt/xslt.h | 32 ++-
plug-ins/xslt/xsltdialog.c | 276 +++++++++------------
3 files changed, 411 insertions(+), 486 deletions(-)
---
diff --git a/plug-ins/xslt/xslt.c b/plug-ins/xslt/xslt.c
index 88f9695d..574695de 100644
--- a/plug-ins/xslt/xslt.c
+++ b/plug-ins/xslt/xslt.c
@@ -1,27 +1,29 @@
/*
* File: plug-ins/xslt/xslt.c
- *
+ *
* Made by Matthieu Sozeau <mattam netcourrier com>
- *
+ *
* Started on Thu May 16 23:21:43 2002 Matthieu Sozeau
* Last update Tue Jun 4 21:00:30 2002 Matthieu Sozeau
- *
+ *
* 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.
*
*/
+#define G_LOG_DOMAIN "DiaXslt"
+
#include <config.h>
#include <stdio.h>
#include <string.h>
@@ -43,7 +45,7 @@
/* Possible stylesheets */
-fromxsl_t *froms = NULL;
+GPtrArray *froms = NULL;
/* Selected stylesheets */
toxsl_t *xsl_to;
@@ -54,269 +56,254 @@ static char *diafilename = NULL;
static char *filename = NULL;
static gboolean
-export_xslt(DiagramData *data, DiaContext *ctx,
- const gchar *f, const gchar *diaf, void* user_data)
+export_xslt (DiagramData *data,
+ DiaContext *ctx,
+ const gchar *f,
+ const gchar *diaf,
+ void *user_data)
{
- if(filename != NULL)
- g_free(filename);
-
- filename = g_strdup(f);
- if(diafilename != NULL)
- g_free(diafilename);
+ if (filename != NULL)
+ g_free (filename);
- diafilename = g_strdup(diaf);
+ filename = g_strdup (f);
+ if (diafilename != NULL)
+ g_free (diafilename);
- xslt_dialog_create();
+ diafilename = g_strdup (diaf);
- /* assume the dialog does all the error reporting */
- return TRUE;
-}
+ xslt_dialog_create ();
+ /* assume the dialog does all the error reporting */
+ return TRUE;
+}
void
-xslt_ok(void)
+xslt_ok (void)
{
- FILE *file, *out;
- int err;
- gchar *stylefname;
- char *params[] = { "directory", NULL, NULL };
- xsltStylesheetPtr style, codestyle;
- xmlDocPtr doc, res;
- xmlErrorPtr error_xml = NULL;
- gchar *directory = g_path_get_dirname(filename);
- gchar *uri = g_filename_to_uri (directory, NULL, NULL);
- g_free (directory);
-
- /* strange: requires an uri, but the last char is platform specifc?! */
- params[1] = g_strconcat("'", uri, G_DIR_SEPARATOR_S, "'", NULL);
- g_free (uri);
-
- file = g_fopen(diafilename, "r");
-
- if (file == NULL) {
- message_error(_("Couldn't open: '%s' for reading.\n"),
- dia_message_filename(diafilename));
- return;
- }
-
- out = g_fopen(filename, "w+");
-
- if (out == NULL) {
- message_error(_("Can't open output file %s: %s\n"),
- dia_message_filename(filename), strerror(errno));
- return;
- }
-
- xmlSubstituteEntitiesDefault(0);
- doc = xmlDoParseFile(diafilename, &error_xml);
-
- if(doc == NULL) {
- message_error(_("Error while parsing %s\n%s"),
- dia_message_filename(diafilename),
- error_xml ? error_xml->message : "");
- return;
- }
-
- stylefname = xsl_from->xsl;
-
- style = xsltParseStylesheetFile((const xmlChar *) stylefname);
- if(style == NULL) {
- message_error(_("Error while parsing stylesheet %s\n"),
- dia_message_filename(stylefname));
- return;
- }
-
- res = xsltApplyStylesheet(style, doc, NULL);
- if(res == NULL) {
- message_error(_("Error while applying stylesheet %s\n"),
- dia_message_filename(stylefname));
- return;
- }
-
- stylefname = xsl_to->xsl;
-
- codestyle = xsltParseStylesheetFile((const xmlChar *) stylefname);
- if(codestyle == NULL) {
- message_error(_("Error while parsing stylesheet: %s\n"),
- dia_message_filename(stylefname));
- return;
- }
-
- xmlFreeDoc(doc);
-
- doc = xsltApplyStylesheet(codestyle, res, (const char **) params);
- if(doc == NULL) {
- message_error(_("Error while applying stylesheet: %s\n"),
- dia_message_filename(stylefname));
- return;
- }
-
- /* Returns the number of byte written or -1 in case of failure. */
- err = xsltSaveResultToFile(out, doc, codestyle);
- if(err < 0) {
- message_error(_("Error while saving result: %s\n"),
- dia_message_filename(filename));
- return;
- }
-
- fprintf (out, "From:\t%s\n", diafilename);
- fprintf (out, "With:\t%s\n", stylefname);
- fprintf (out, "To:\t%s=%s\n", params[0], params[1]);
-
- fclose(out);
- fclose(file);
-
- xsltFreeStylesheet(codestyle);
- xsltFreeStylesheet(style);
- xmlFreeDoc(res);
- xmlFreeDoc(doc);
- xsltCleanupGlobals();
-
- xslt_clear();
+ FILE *file, *out;
+ int err;
+ gchar *stylefname;
+ char *params[] = { "directory", NULL, NULL };
+ xsltStylesheetPtr style, codestyle;
+ xmlDocPtr doc, res;
+ xmlErrorPtr error_xml = NULL;
+ gchar *directory = g_path_get_dirname (filename);
+ gchar *uri = g_filename_to_uri (directory, NULL, NULL);
+ g_free (directory);
+
+ /* strange: requires an uri, but the last char is platform specifc?! */
+ params[1] = g_strconcat ("'", uri, G_DIR_SEPARATOR_S, "'", NULL);
+ g_free (uri);
+
+ file = g_fopen (diafilename, "r");
+
+ if (file == NULL) {
+ message_error (_("Couldn't open: '%s' for reading.\n"),
+ dia_message_filename (diafilename));
+ return;
+ }
+
+ out = g_fopen (filename, "w+");
+
+ if (out == NULL) {
+ message_error (_("Can't open output file %s: %s\n"),
+ dia_message_filename (filename), strerror (errno));
+ return;
+ }
+
+ xmlSubstituteEntitiesDefault (0);
+ doc = xmlDoParseFile (diafilename, &error_xml);
+
+ if (doc == NULL) {
+ message_error (_("Error while parsing %s\n%s"),
+ dia_message_filename (diafilename),
+ error_xml ? error_xml->message : "");
+ return;
+ }
+
+ stylefname = xsl_from->xsl;
+
+ style = xsltParseStylesheetFile ((const xmlChar *) stylefname);
+ if(style == NULL) {
+ message_error (_("Error while parsing stylesheet %s\n"),
+ dia_message_filename (stylefname));
+ return;
+ }
+
+ res = xsltApplyStylesheet (style, doc, NULL);
+ if(res == NULL) {
+ message_error (_("Error while applying stylesheet %s\n"),
+ dia_message_filename (stylefname));
+ return;
+ }
+
+ stylefname = xsl_to->xsl;
+
+ codestyle = xsltParseStylesheetFile ((const xmlChar *) stylefname);
+ if(codestyle == NULL) {
+ message_error (_("Error while parsing stylesheet: %s\n"),
+ dia_message_filename (stylefname));
+ return;
+ }
+
+ xmlFreeDoc (doc);
+
+ doc = xsltApplyStylesheet (codestyle, res, (const char **) params);
+ if(doc == NULL) {
+ message_error (_("Error while applying stylesheet: %s\n"),
+ dia_message_filename (stylefname));
+ return;
+ }
+
+ /* Returns the number of byte written or -1 in case of failure. */
+ err = xsltSaveResultToFile (out, doc, codestyle);
+ if(err < 0) {
+ message_error (_("Error while saving result: %s\n"),
+ dia_message_filename (filename));
+ return;
+ }
+
+ fprintf (out, "From:\t%s\n", diafilename);
+ fprintf (out, "With:\t%s\n", stylefname);
+ fprintf (out, "To:\t%s=%s\n", params[0], params[1]);
+
+ fclose (out);
+ fclose (file);
+
+ xsltFreeStylesheet (codestyle);
+ xsltFreeStylesheet (style);
+ xmlFreeDoc (res);
+ xmlFreeDoc (doc);
+ xsltCleanupGlobals ();
+
+ xslt_clear ();
}
-static toxsl_t *read_implementations(xmlNodePtr cur, gchar *path)
+static toxsl_t *
+read_implementations (xmlNodePtr cur, gchar *path)
{
- toxsl_t *first, *curto;
- first = curto = NULL;
-
- cur = cur->xmlChildrenNode;
-
- while (cur) {
- toxsl_t *to;
- if (xmlIsBlankNode(cur) || xmlNodeIsText(cur)) { cur = cur->next; continue; }
- to = g_malloc(sizeof(toxsl_t));
- to->next = NULL;
-
- to->name = (gchar *)xmlGetProp(cur, (const xmlChar *) "name");
- to->xsl = (gchar *)xmlGetProp(cur, (const xmlChar *) "stylesheet");
-
- if (!(to->name && to->xsl)) {
- g_warning ("Name and stylesheet attributes are required for the implementation element %s in XSLT
plugin configuration file", cur->name);
- if (to->name) xmlFree(to->name);
- if (to->xsl) xmlFree(to->xsl);
- g_free(to);
- to = NULL;
- } else {
- if (first == NULL) {
- first = curto = to;
- } else {
- curto->next = to;
- curto = to;
- }
- /* make filename absolute */
- {
- gchar *fname = g_strconcat(path, G_DIR_SEPARATOR_S, to->xsl, NULL);
- xmlFree(to->xsl);
- to->xsl = fname;
- }
- }
- cur = cur->next;
+ toxsl_t *first, *curto;
+ first = curto = NULL;
+
+ cur = cur->xmlChildrenNode;
+
+ while (cur) {
+ toxsl_t *to;
+ if (xmlIsBlankNode(cur) || xmlNodeIsText(cur)) {
+ cur = cur->next;
+ continue;
+ }
+ to = g_malloc (sizeof (toxsl_t));
+ to->next = NULL;
+ to->name = (gchar *) xmlGetProp (cur, (const xmlChar *) "name");
+ to->xsl = (gchar *) xmlGetProp (cur, (const xmlChar *) "stylesheet");
+
+ if (!(to->name && to->xsl)) {
+ g_warning ("Name and stylesheet attributes are required for the implementation element %s in XSLT
plugin configuration file", cur->name);
+ if (to->name) {
+ xmlFree(to->name);
+ }
+ if (to->xsl) {
+ xmlFree(to->xsl);
+ }
+ g_free(to);
+ to = NULL;
+ } else {
+ if (first == NULL) {
+ first = curto = to;
+ } else {
+ curto->next = to;
+ curto = to;
+ }
+ /* make filename absolute */
+ {
+ gchar *fname = g_strconcat(path, G_DIR_SEPARATOR_S, to->xsl, NULL);
+ xmlFree(to->xsl);
+ to->xsl = fname;
+ }
}
-
- return first;
+ cur = cur->next;
+ }
+
+ return first;
}
-static PluginInitResult read_configuration(const char *config)
+static PluginInitResult
+read_configuration(const char *config)
{
- xmlDocPtr doc;
- xmlNodePtr cur;
- xmlErrorPtr error_xml = NULL;
- /* Primary xsl */
- fromxsl_t *cur_from = NULL;
- gchar *path = NULL;
-
- if (!g_file_test(config, G_FILE_TEST_EXISTS))
- return DIA_PLUGIN_INIT_ERROR;
-
- doc = xmlDoParseFile(config, &error_xml);
-
- if (doc == NULL)
- {
- g_error ("Couldn't parse XSLT plugin's configuration file %s\n%s",
- config, error_xml ? error_xml->message : "");
- return DIA_PLUGIN_INIT_ERROR;
- }
-
- cur = xmlDocGetRootElement(doc);
- if (cur == NULL)
- {
- g_error ("XSLT plugin's configuration file %s is empty", config);
- return DIA_PLUGIN_INIT_ERROR;
- }
-
- path = g_path_get_dirname(config);
-
- /* We don't care about the top level element's name */
-
- cur = cur->xmlChildrenNode;
-
- while (cur) {
- if (xmlIsBlankNode(cur) || xmlNodeIsText(cur)) { cur = cur->next; continue; }
- else if (!xmlStrcmp(cur->name, (const xmlChar *)"language")) {
- fromxsl_t *new_from = g_new(fromxsl_t,1);
- new_from->next = NULL;
-
- new_from->name = (gchar *)xmlGetProp(cur, (const xmlChar *) "name");
- new_from->xsl = (gchar *)xmlGetProp(cur, (const xmlChar *) "stylesheet");
-
- if (!(new_from->name && new_from->xsl)) {
- g_warning ("'name' and 'stylesheet' attributes are required for the language element %s in
XSLT plugin configuration file", cur->name);
- g_free(new_from);
- new_from = NULL;
- } else {
- if (froms == NULL)
- froms = cur_from = new_from;
- else {
- if (!cur_from)
- cur_from = froms;
- while (cur_from->next)
- cur_from = cur_from->next;
- cur_from->next = new_from;
- cur_from = new_from;
- }
- /* make filename absolute */
- {
- gchar *fname = g_strconcat(path, G_DIR_SEPARATOR_S, new_from->xsl, NULL);
- xmlFree(new_from->xsl);
- new_from->xsl = fname;
- }
-
- cur_from->xsls = read_implementations(cur, path);
- if (cur_from->xsls == NULL) {
- g_warning ("No implementation stylesheet for language %s in XSLT plugin configuration
file", cur_from->name);
- }
- }
- } else {
- g_warning ("Wrong node name %s in XSLT plugin configuration file, 'language' expected",
cur->name);
- }
- cur = cur -> next;
+ xmlDocPtr doc;
+ xmlNodePtr cur;
+ xmlErrorPtr error_xml = NULL;
+ /* Primary xsl */
+ gchar *path = NULL;
+
+ if (!g_file_test (config, G_FILE_TEST_EXISTS))
+ return DIA_PLUGIN_INIT_ERROR;
+
+ doc = xmlDoParseFile (config, &error_xml);
+
+ if (doc == NULL) {
+ g_critical ("Couldn't parse XSLT plugin's configuration file %s\n%s",
+ config, error_xml ? error_xml->message : "");
+ return DIA_PLUGIN_INIT_ERROR;
+ }
+
+ cur = xmlDocGetRootElement(doc);
+ if (cur == NULL) {
+ g_critical ("XSLT plugin's configuration file %s is empty", config);
+ return DIA_PLUGIN_INIT_ERROR;
+ }
+
+ path = g_path_get_dirname(config);
+
+ /* We don't care about the top level element's name */
+
+ cur = cur->xmlChildrenNode;
+
+ while (cur) {
+ if (xmlIsBlankNode (cur) || xmlNodeIsText (cur)) {
+ cur = cur->next;
+ continue;
+ } else if (!xmlStrcmp (cur->name, (const xmlChar *) "language")) {
+ fromxsl_t *new_from = g_new (fromxsl_t, 1);
+
+ new_from->name = (gchar *)xmlGetProp (cur, (const xmlChar *) "name");
+ new_from->xsl = (gchar *)xmlGetProp (cur, (const xmlChar *) "stylesheet");
+
+ if (!(new_from->name && new_from->xsl)) {
+ g_warning ("'name' and 'stylesheet' attributes are required for the language element %s in XSLT
plugin configuration file", cur->name);
+ g_free (new_from);
+ new_from = NULL;
+ } else {
+ /* make filename absolute */
+ {
+ gchar *fname = g_strconcat (path, G_DIR_SEPARATOR_S, new_from->xsl, NULL);
+ xmlFree (new_from->xsl);
+ new_from->xsl = fname;
+ }
+
+ new_from->xsls = read_implementations (cur, path);
+ if (new_from->xsls == NULL) {
+ g_warning ("No implementation stylesheet for language %s in XSLT plugin configuration file",
new_from->name);
+ }
+
+ g_ptr_array_add (froms, new_from);
+ }
+ } else {
+ g_warning ("Wrong node name %s in XSLT plugin configuration file, 'language' expected", cur->name);
}
-
- if (froms == NULL) {
- g_warning ("No stylesheets configured in %s for XSLT plugin", config);
- }
-
- /*cur_from = froms;
-
- printf("XSLT plugin configuration: \n");
- while(cur_from != NULL)
- {
- printf("From: %s (%s)\n", cur_from->name, cur_from->xsl);
-
- cur_to = cur_from->xsls;
- while(cur_to != NULL) {
- printf("\tTo: %s (%s)\n", cur_to->name, cur_to->xsl);
- cur_to = cur_to->next;
- }
- cur_from = cur_from->next;
- }
- */
- g_free(path);
- xmlFreeDoc(doc);
- xmlCleanupParser();
+ cur = cur -> next;
+ }
- return DIA_PLUGIN_INIT_OK;
+ if (froms->len == 0) {
+ g_warning ("No stylesheets configured in %s for XSLT plugin", config);
+ }
+
+ g_free (path);
+ xmlFreeDoc (doc);
+ xmlCleanupParser ();
+
+ return DIA_PLUGIN_INIT_OK;
}
@@ -326,69 +313,61 @@ static PluginInitResult read_configuration(const char *config)
static const gchar *extensions[] = { "code", NULL };
static DiaExportFilter my_export_filter = {
- N_(MY_RENDERER_NAME),
- extensions,
- export_xslt
+ N_(MY_RENDERER_NAME),
+ extensions,
+ export_xslt
};
DIA_PLUGIN_CHECK_INIT
PluginInitResult
-dia_plugin_init(PluginInfo *info)
+dia_plugin_init (PluginInfo *info)
{
- gchar *path;
- PluginInitResult global_res, user_res;
-
- if (!dia_plugin_info_init(info, "XSLT",
- _("XSL Transformation filter"),
- NULL, NULL))
- {
- return DIA_PLUGIN_INIT_ERROR;
- }
-
- if (g_getenv ("DIA_XSLT_PATH") != NULL)
- path = g_build_path (G_DIR_SEPARATOR_S, g_getenv ("DIA_XSLT_PATH"), "stylesheets.xml", NULL);
- else
- path = dia_get_data_directory("xslt" G_DIR_SEPARATOR_S "stylesheets.xml");
-
- global_res = read_configuration(path);
- g_free (path);
-
- path = dia_config_filename("xslt" G_DIR_SEPARATOR_S
- "stylesheets.xml");
- user_res = read_configuration(path);
- g_free (path);
-
- if (global_res == DIA_PLUGIN_INIT_OK || user_res == DIA_PLUGIN_INIT_OK)
- {
- xsl_from = froms;
- xsl_to = xsl_from->xsls;
-
- filter_register_export(&my_export_filter);
- return DIA_PLUGIN_INIT_OK;
- } else {
- message_error (_("No valid configuration files found for the XSLT plugin; not loading."));
- return DIA_PLUGIN_INIT_ERROR;
- }
+ gchar *path;
+ PluginInitResult global_res, user_res;
+
+ froms = g_ptr_array_new_with_free_func (g_free);
+
+ if (!dia_plugin_info_init (info,
+ "XSLT",
+ _("XSL Transformation filter"),
+ NULL, NULL)) {
+ return DIA_PLUGIN_INIT_ERROR;
+ }
+
+ if (g_getenv ("DIA_XSLT_PATH") != NULL) {
+ path = g_build_path (G_DIR_SEPARATOR_S, g_getenv ("DIA_XSLT_PATH"), "stylesheets.xml", NULL);
+ } else {
+ path = dia_get_data_directory ("xslt" G_DIR_SEPARATOR_S "stylesheets.xml");
+ }
+
+ global_res = read_configuration (path);
+ g_free (path);
+
+ path = dia_config_filename ("xslt" G_DIR_SEPARATOR_S "stylesheets.xml");
+ user_res = read_configuration(path);
+ g_free (path);
+
+ if (global_res == DIA_PLUGIN_INIT_OK || user_res == DIA_PLUGIN_INIT_OK) {
+ xsl_from = g_ptr_array_index (froms, 0);
+ xsl_to = xsl_from->xsls;
+
+ filter_register_export (&my_export_filter);
+ return DIA_PLUGIN_INIT_OK;
+ } else {
+ message_error (_("No valid configuration files found for the XSLT plugin; not loading."));
+ return DIA_PLUGIN_INIT_ERROR;
+ }
}
-gboolean xslt_can_unload(PluginInfo *info)
+gboolean
+xslt_can_unload (PluginInfo *info)
{
- return 1;
+ return TRUE;
}
-void xslt_unload(PluginInfo *info)
+void
+xslt_unload(PluginInfo *info)
{
-#if 0
- language_t *cur = languages, *next;
-
- /*printf("Unloading xslt\n"); */
-
- while(cur != NULL) {
- next = cur->next;
- g_free(cur);
- cur = next;
- }
-#endif
-
+ g_ptr_array_unref (froms);
}
diff --git a/plug-ins/xslt/xslt.h b/plug-ins/xslt/xslt.h
index 18decafc..85eb6047 100644
--- a/plug-ins/xslt/xslt.h
+++ b/plug-ins/xslt/xslt.h
@@ -1,11 +1,11 @@
/*
* File: plug-ins/xslt/xslt.h
- *
+ *
* Made by Matthieu Sozeau <mattam netcourrier com>
- *
+ *
* Started on Thu May 16 23:22:12 2002 Matthieu Sozeau
* Last update Mon Jun 3 19:36:32 2002 Matthieu Sozeau
- *
+ *
* 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
@@ -38,29 +38,27 @@
/* Stylesheets for a specific primary stylesheet */
typedef struct toxsl_s {
- gchar *name;
- gchar *xsl;
- GtkWidget *item;
- struct toxsl_s *next;
+ gchar *name;
+ gchar *xsl;
+ struct toxsl_s *next;
} toxsl_t;
/* Primary stylesheet for a dia object type */
typedef struct fromxsl_s {
- gchar *name;
- gchar *xsl;
- toxsl_t *xsls;
- struct fromxsl_s *next;
+ gchar *name;
+ gchar *xsl;
+ toxsl_t *xsls;
} fromxsl_t;
/* Possible stylesheets */
-extern fromxsl_t *froms;
+extern GPtrArray *froms;
/* Selected stylesheets */
extern toxsl_t *xsl_to;
extern fromxsl_t *xsl_from;
-void xslt_dialog_create(void);
-void xslt_ok(void);
-void xslt_clear(void);
-void xslt_unload(PluginInfo *info);
-gboolean xslt_can_unload(PluginInfo *info);
+void xslt_dialog_create (void);
+void xslt_ok (void);
+void xslt_clear (void);
+void xslt_unload (PluginInfo *info);
+gboolean xslt_can_unload (PluginInfo *info);
diff --git a/plug-ins/xslt/xsltdialog.c b/plug-ins/xslt/xsltdialog.c
index 3b03f305..adaf1462 100644
--- a/plug-ins/xslt/xsltdialog.c
+++ b/plug-ins/xslt/xsltdialog.c
@@ -1,21 +1,21 @@
/*
* File: plug-ins/xslt/xsltdialog.c
- *
+ *
* Made by Matthieu Sozeau <mattam netcourrier com>
- *
+ *
* Started on Thu May 16 20:30:42 2002 Matthieu Sozeau
* Last update Fri May 17 00:30:24 2002 Matthieu Sozeau
- *
+ *
* 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.
@@ -26,188 +26,136 @@
* Opens a dialog for export options
*/
-#undef GTK_DISABLE_DEPRECATED /* GTK_OPTION_MENU, ... */
#include "xslt.h"
#include <stdio.h>
#include <gtk/gtk.h>
+static GtkWidget *dialog;
-static void
-from_deactivate(fromxsl_t *xsls);
-
+static void xslt_dialog_respond (GtkWidget *widget,
+ gint response_id,
+ gpointer user_data);
static void
-from_activate(GtkWidget *widget, fromxsl_t *xsls)
+from_changed (GtkComboBox *combo,
+ GtkComboBox *to)
{
- toxsl_t *to_f = xsls->xsls;
-
- from_deactivate(xsl_from);
-
- xsl_from = xsls;
- xsl_to = to_f;
-
- gtk_menu_item_activate(GTK_MENU_ITEM(to_f->item));
- while(to_f != NULL)
- {
- gtk_widget_set_sensitive(to_f->item, 1);
- to_f = to_f->next;
- }
+ toxsl_t *cur_to;
+ fromxsl_t *from = g_ptr_array_index (froms,
+ gtk_combo_box_get_active (combo));
+ GtkListStore *store;
+
+ // GTK3: gtk_combo_box_text_remove_all
+ store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (to)));
+ gtk_list_store_clear (store);
+
+ xsl_from = from;
+
+ cur_to = from->xsls;
+ while(cur_to != NULL) {
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (to), cur_to->name);
+
+ cur_to = cur_to->next;
+ }
}
static void
-from_deactivate(fromxsl_t *xsls)
+to_changed (GtkComboBox *combo,
+ gpointer data)
{
- toxsl_t *to_f = xsls->xsls;
-
- while(to_f != NULL)
- {
- gtk_widget_set_sensitive(to_f->item, 0);
- to_f = to_f->next;
- }
-}
+ toxsl_t *to = xsl_from->xsls + gtk_combo_box_get_active (combo);
+ xsl_to = to;
+}
-static void
-to_update(GtkWidget *widget, toxsl_t *lng)
+void
+xslt_dialog_create (void)
{
- /* printf("To: %s\n", lng->name); */
- xsl_to = lng;
-}
+ GtkWidget *box, *vbox;
+ GtkWidget *label;
+ GtkWidget *from, *to;
-static GtkWidget *dialog;
+ g_return_if_fail (froms != NULL);
-static void xslt_dialog_respond(GtkWidget *widget,
- gint response_id,
- gpointer user_data);
+ dialog = gtk_dialog_new_with_buttons (_("Export through XSLT"),
+ NULL, 0,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("_Okay"), GTK_RESPONSE_OK,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-void
-xslt_dialog_create(void) {
- GtkWidget *box, *vbox;
-
- GtkWidget *omenu, *menu, *menuitem;
- GSList *group;
- GtkWidget *label;
-
- fromxsl_t *cur_f = froms;
- toxsl_t *cur_to = NULL;
-
- g_return_if_fail(froms != NULL);
-
- dialog = gtk_dialog_new_with_buttons(
- _("Export through XSLT"),
- NULL, 0,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OK, GTK_RESPONSE_OK,
- NULL);
-
- gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_OK);
-
-
- box = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
-
- vbox = gtk_vbox_new(FALSE, 5);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
- gtk_container_set_border_width (GTK_CONTAINER (box), 10);
-
- label = gtk_label_new(_("From:"));
-
- omenu = gtk_option_menu_new ();
- menu = gtk_menu_new ();
- group = NULL;
-
- while(cur_f != NULL)
- {
- menuitem = gtk_radio_menu_item_new_with_label (group, cur_f->name);
- g_signal_connect (G_OBJECT (menuitem), "activate",
- G_CALLBACK (from_activate), cur_f);
- group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
- gtk_menu_append (GTK_MENU (menu), menuitem);
- gtk_widget_show (menuitem);
- cur_f = cur_f->next;
- }
-
-
- gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
- gtk_widget_show(menu);
- gtk_widget_show(omenu);
- gtk_widget_show(label);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), omenu, FALSE, TRUE, 0);
-
- gtk_widget_show_all(vbox);
-
- gtk_box_pack_start (GTK_BOX (box), vbox, FALSE, TRUE, 0);
-
- cur_f = froms;
-
- vbox = gtk_vbox_new(FALSE, 5);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
- gtk_container_set_border_width (GTK_CONTAINER (box), 10);
-
- label = gtk_label_new(_("To:"));
-
- omenu = gtk_option_menu_new ();
- menu = gtk_menu_new ();
- group = NULL;
-
- while(cur_f != NULL)
- {
- cur_to = cur_f->xsls;
- while(cur_to != NULL)
- {
- menuitem = gtk_radio_menu_item_new_with_label (group, cur_to->name);
- g_signal_connect (G_OBJECT (menuitem), "activate",
- G_CALLBACK (to_update), cur_to );
- group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
- gtk_menu_append (GTK_MENU (menu), menuitem);
- gtk_widget_show (menuitem);
- cur_to->item = menuitem;
- cur_to = cur_to->next;
- }
- cur_f = cur_f->next;
- }
-
- gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
- gtk_widget_show(menu);
- gtk_widget_show(omenu);
- gtk_widget_show(label);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), omenu, FALSE, TRUE, 0);
-
- gtk_widget_show_all(vbox);
-
- gtk_box_pack_start (GTK_BOX (box), vbox, FALSE, TRUE, 0);
-
- gtk_widget_show_all(box);
-
- g_signal_connect(G_OBJECT(dialog), "response",
- G_CALLBACK(xslt_dialog_respond),
- NULL);
- g_signal_connect(G_OBJECT(dialog), "delete_event",
- G_CALLBACK(gtk_widget_hide), NULL);
-
-
- gtk_widget_show(dialog);
-
- cur_f = froms->next;
- while(cur_f != NULL)
- {
- from_deactivate(cur_f);
- cur_f = cur_f->next;
- }
+ box = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-}
+ vbox = gtk_vbox_new (FALSE, 5);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
+ gtk_container_set_border_width (GTK_CONTAINER (box), 10);
+
+ label = gtk_label_new (_("From:"));
-void xslt_clear(void) {
- gtk_widget_destroy(dialog);
+ from = gtk_combo_box_text_new ();
+ to = gtk_combo_box_text_new ();
+
+ g_signal_connect (from, "changed", G_CALLBACK (from_changed), to);
+ g_signal_connect (to, "changed", G_CALLBACK (to_changed), NULL);
+
+ for (int i = 0; i < froms->len; i++) {
+ fromxsl_t *cur_f = g_ptr_array_index (froms, i);
+
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (from), cur_f->name);
+ }
+
+ // Select the first item
+ gtk_combo_box_set_active (GTK_COMBO_BOX (from), 0);
+
+ gtk_widget_show (from);
+ gtk_widget_show (label);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), from, FALSE, TRUE, 0);
+
+ gtk_widget_show_all (vbox);
+
+ gtk_box_pack_start (GTK_BOX (box), vbox, FALSE, TRUE, 0);
+
+ vbox = gtk_vbox_new (FALSE, 5);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
+ gtk_container_set_border_width (GTK_CONTAINER (box), 10);
+
+ label = gtk_label_new (_("To:"));
+
+ gtk_widget_show (to);
+ gtk_widget_show (label);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), to, FALSE, TRUE, 0);
+
+ gtk_widget_show_all (vbox);
+
+ gtk_box_pack_start (GTK_BOX (box), vbox, FALSE, TRUE, 0);
+
+ gtk_widget_show_all (box);
+
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (xslt_dialog_respond), NULL);
+ g_signal_connect (G_OBJECT (dialog), "delete_event",
+ G_CALLBACK (gtk_widget_hide), NULL);
+
+ gtk_widget_show (dialog);
}
-void xslt_dialog_respond(GtkWidget *widget,
- gint response_id,
- gpointer user_data) {
+void
+xslt_clear (void)
+{
+ gtk_widget_destroy (dialog);
+}
- gtk_widget_hide(dialog);
- if (response_id == GTK_RESPONSE_OK) xslt_ok();
+void
+xslt_dialog_respond (GtkWidget *widget,
+ gint response_id,
+ gpointer user_data)
+{
+ gtk_widget_hide (dialog);
+ if (response_id == GTK_RESPONSE_OK) {
+ xslt_ok ();
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]