From f4f9184388013189b0961837b47cb6ca94ca7de2 Mon Sep 17 00:00:00 2001 From: Bradford Hovinen Date: Wed, 23 Aug 2000 14:29:23 +0000 Subject: [PATCH] Add XML cflags/libs 2000-08-23 Bradford Hovinen * capplets/wm-properties/Makefile.am (INCLUDES): (wm_properties_capplet_LDADD): Add XML cflags/libs * capplets/wm-properties/wm-properties-capplet.c (do_get_xml): (do_set_xml): Implement (main): Call do_{get|set}_xml() on --get and --set * capplets/wm-properties/wm-list.c (wm_read_from_xml): (wm_list_read_from_xml): (wm_write_to_xml): (wm_list_write_to_xml): Implement --- ChangeLog | 14 +++ capplets/wm-properties/Makefile.am | 5 +- capplets/wm-properties/wm-list.c | 109 +++++++++++++++++- .../wm-properties/wm-properties-capplet.c | 39 ++++++- capplets/wm-properties/wm-properties.h | 8 +- 5 files changed, 170 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2862de445..07b34126e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2000-08-23 Bradford Hovinen + + * capplets/wm-properties/Makefile.am (INCLUDES): + (wm_properties_capplet_LDADD): Add XML cflags/libs + + * capplets/wm-properties/wm-properties-capplet.c (do_get_xml): + (do_set_xml): Implement + (main): Call do_{get|set}_xml() on --get and --set + + * capplets/wm-properties/wm-list.c (wm_read_from_xml): + (wm_list_read_from_xml): + (wm_write_to_xml): + (wm_list_write_to_xml): Implement + 2000-08-18 Bradford Hovinen * capplets/keyboard-properties/Makefile.am (INCLUDES): diff --git a/capplets/wm-properties/Makefile.am b/capplets/wm-properties/Makefile.am index 57783d141..67e5001d9 100644 --- a/capplets/wm-properties/Makefile.am +++ b/capplets/wm-properties/Makefile.am @@ -2,7 +2,8 @@ INCLUDES = -I. -I$(srcdir) \ -I$(top_srcdir)/intl -I$(top_builddir)/intl \ -I$(srcdir)/../../libcapplet \ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ - -I$(includedir) $(GNOME_INCLUDEDIR) $(IMLIB_CFLAGS) + -I$(includedir) $(GNOME_INCLUDEDIR) $(IMLIB_CFLAGS) \ + $(XML_CFLAGS) bin_PROGRAMS = wm-properties-capplet @@ -16,7 +17,7 @@ wm_properties_capplet_SOURCES = \ wm_properties_capplet_LDADD = \ ../../libcapplet/libcapplet.la \ $(GNOME_LIBS) $(ORBIT_LIBS) $(GNOMEUI_LIBS) $(GNOME_LIBDIR) $(INTLLIBS) \ -$(IMLIB_LIBS) +$(IMLIB_LIBS) $(GNOME_XML_LIB) EXTRA_DIST = wm-properties.desktop diff --git a/capplets/wm-properties/wm-list.c b/capplets/wm-properties/wm-list.c index 7c7d06e63..231ccd81c 100644 --- a/capplets/wm-properties/wm-list.c +++ b/capplets/wm-properties/wm-list.c @@ -1,7 +1,8 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* Copyright (C) 1998 Redhat Software Inc. * Code available under the Gnu GPL. - * Authors: Owen Taylor + * Authors: Owen Taylor , + * Bradford Hovinen */ #include @@ -405,3 +406,109 @@ wm_list_get_revert (void) return NULL; } +static WindowManager * +wm_read_from_xml (xmlNodePtr wm_node) +{ + xmlNodePtr node; + WindowManager *wm; + gboolean is_current = FALSE; + + if (strcmp (wm_node->name, "window-manager")) return NULL; + + wm = g_new0 (WindowManager, 1); + + for (node = wm_node->childs; node; node = node->next) { + if (!strcmp (node->name, "desktop-entry")) + wm->dentry = + gnome_desktop_entry_load_unconditional + (xmlNodeGetContent (node)); + else if (!strcmp (node->name, "config-exec")) + wm->config_exec = xmlNodeGetContent (node); + else if (!strcmp (node->name, "config-tryexec")) + wm->config_tryexec = xmlNodeGetContent (node); + else if (!strcmp (node->name, "session-managed")) + wm->session_managed = TRUE; + else if (!strcmp (node->name, "is-user")) + wm->is_user = TRUE; + else if (!strcmp (node->name, "is-current")) + is_current = TRUE; /* FIXME: sanity check */ + } + + wm_check_present (wm); + + if (wm->dentry == NULL || + (wm->config_exec != NULL && is_blank (wm->config_exec)) || + wm->dentry->name == NULL || wm->dentry->exec == NULL || + !(wm->is_user || wm->is_present)) + { + g_free (wm); + return NULL; + } + + if (is_current) current_wm = wm; + + return wm; +} + +void +wm_list_read_from_xml (xmlDocPtr doc) +{ + xmlNodePtr root_node, node; + WindowManager *wm; + + root_node = xmlDocGetRootElement (doc); + if (strcmp (root_node->name, "wm-prefs")) return; + + for (node = root_node; node; node = node->next) { + if (!strcmp (node->name, "window-manager")) { + wm = wm_read_from_xml (node); + if (wm) window_managers = + g_list_insert_sorted + (window_managers, wm, wm_compare); + } + } +} + +static xmlNodePtr +wm_write_to_xml (WindowManager *wm) +{ + xmlNodePtr node; + + node = xmlNewNode (NULL, "window-manager"); + + xmlNewChild (node, NULL, "desktop-entry", wm->dentry->location); + + if (wm->config_exec != NULL) + xmlNewChild (node, NULL, "config-exec", wm->config_exec); + + if (wm->session_managed) + xmlNewChild (node, NULL, "session-managed", NULL); + + if (wm->is_user) + xmlNewChild (node, NULL, "is-user", NULL); + + if (wm == current_wm) + xmlNewChild (node, NULL, "is-current", NULL); + + return node; +} + +xmlDocPtr +wm_list_write_to_xml (void) +{ + xmlDocPtr doc; + xmlNodePtr root_node, node; + GList *wm_node; + + doc = xmlNewDoc ("1.0"); + root_node = xmlNewDocNode (doc, NULL, "wm-prefs", NULL); + + for (wm_node = window_managers; wm_node; wm_node = wm_node->next) { + node = wm_write_to_xml ((WindowManager *) wm_node->data); + if (node) xmlAddChild (root_node, node); + } + + xmlDocSetRootElement (doc, root_node); + + return doc; +} diff --git a/capplets/wm-properties/wm-properties-capplet.c b/capplets/wm-properties/wm-properties-capplet.c index 8586f4044..a497b3ff6 100644 --- a/capplets/wm-properties/wm-properties-capplet.c +++ b/capplets/wm-properties/wm-properties-capplet.c @@ -6,6 +6,7 @@ */ #include #include +#include #include "wm-properties.h" #include "capplet-widget.h" #include "gnome.h" @@ -1103,6 +1104,35 @@ wm_setup (void) update_gui(); } +static void do_get_xml (void) +{ + xmlDocPtr doc; + + doc = wm_list_write_to_xml (); + xmlDocDump (stdout, doc); +} + +static void do_set_xml (void) +{ + xmlDocPtr doc; + char *buffer; + int len = 0; + + while (!feof (stdin)) { + if (!len) buffer = g_new (char, 16384); + else buffer = g_renew (char, buffer, len + 16384); + fread (buffer + len, 1, 16384, stdin); + len += 16384; + } + + doc = xmlParseMemory (buffer, strlen (buffer)); + + init_session (); + wm_list_read_from_xml (doc); + wm_list_save (); + update_session (); +} + int main (int argc, char **argv) { @@ -1156,7 +1186,14 @@ main (int argc, char **argv) update_session (); } - } else { + } + else if (init_results == 3) { + do_get_xml (); + } + else if (init_results == 4) { + do_set_xml (); + } + else { if (selected_wm && !selected_wm->session_managed && !wm_is_running()) { diff --git a/capplets/wm-properties/wm-properties.h b/capplets/wm-properties/wm-properties.h index c194c12ef..9092d8ca7 100644 --- a/capplets/wm-properties/wm-properties.h +++ b/capplets/wm-properties/wm-properties.h @@ -1,12 +1,15 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* Copyright (C) 1998 Redhat Software Inc. * Code available under the Gnu GPL. - * Authors: Owen Taylor + * Authors: Owen Taylor , + * Bradford Hovinen */ #include #include +#include + typedef struct _WindowManager WindowManager; struct _WindowManager { @@ -36,6 +39,9 @@ void wm_list_set_current (WindowManager *window_manager); WindowManager *wm_list_get_current (void); WindowManager *wm_list_get_revert (void); +void wm_list_read_from_xml (xmlDocPtr doc); +xmlDocPtr wm_list_write_to_xml (void); + extern GList *window_managers; /* Management of current window manager */