diff options
author | Ted Gould <ted@gould.cx> | 2011-02-24 15:04:39 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2011-02-24 15:04:39 -0600 |
commit | f8fed10917f0f2ebba16d2d6628fad2d2d46c04e (patch) | |
tree | 38af9ba8014eff7907c5ae06bcad13f441787abf /libdbusmenu-glib | |
parent | 44927e6da03d633f0958ce5e04e62e752a43d201 (diff) | |
parent | f5ef3600b66047f13796972ee40acf7b50b81790 (diff) | |
download | libdbusmenu-f8fed10917f0f2ebba16d2d6628fad2d2d46c04e.tar.gz libdbusmenu-f8fed10917f0f2ebba16d2d6628fad2d2d46c04e.tar.bz2 libdbusmenu-f8fed10917f0f2ebba16d2d6628fad2d2d46c04e.zip |
Import upstream version 0.3.99
Diffstat (limited to 'libdbusmenu-glib')
29 files changed, 2648 insertions, 542 deletions
diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index e6877b6..8b523aa 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -1,6 +1,7 @@ -CLEANFILES = - +BUILT_SOURCES = +CLEANFILES = +DISTCLEANFILES = EXTRA_DIST = \ clean-namespaces.xslt \ dbusmenu-glib-0.4.pc.in \ @@ -9,6 +10,8 @@ EXTRA_DIST = \ menuitem-marshal.list \ server-marshal.list +include $(top_srcdir)/Makefile.am.enum + lib_LTLIBRARIES = \ libdbusmenu-glib.la @@ -19,11 +22,16 @@ libdbusmenu_glibinclude_HEADERS = \ menuitem.h \ menuitem-proxy.h \ server.h \ - client.h + client.h \ + types.h libdbusmenu_glib_la_SOURCES = \ dbus-menu-clean.xml.h \ dbus-menu-clean.xml.c \ + defaults.h \ + defaults.c \ + enum-types.h \ + enum-types.c \ menuitem.h \ menuitem.c \ menuitem-marshal.h \ @@ -39,6 +47,7 @@ libdbusmenu_glib_la_SOURCES = \ client-marshal.c \ client-menuitem.h \ client-menuitem.c \ + client-private.h \ client.h \ client.c @@ -56,6 +65,14 @@ libdbusmenu_glib_la_LIBADD = \ pkgconfig_DATA = dbusmenu-glib-0.4.pc pkgconfigdir = $(libdir)/pkgconfig +glib_enum_h = enum-types.h +glib_enum_c = enum-types.c +glib_enum_headers = $(addprefix $(srcdir)/, $(libdbusmenu_glibinclude_HEADERS)) + +DISTCLEANFILES += \ + enum-types.c \ + enum-types.h + %.xml.h: %.xml echo "extern const char * $(subst -,_,$(subst .,_,$(basename $(notdir $@))));" > $@ @@ -69,7 +86,7 @@ dbus-menu-clean.xml: dbus-menu.xml CLEANFILES += dbus-menu-clean.xml -BUILT_SOURCES = \ +BUILT_SOURCES += \ dbus-menu-clean.xml.c \ dbus-menu-clean.xml.h \ client-marshal.h \ @@ -122,21 +139,21 @@ if INTROSPECTION_TEN INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --warn-all \ --add-include-path=$(srcdir) \ - $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) \ + $(addprefix --c-include=libdbusmenu-glib/, $(libdbusmenu_glibinclude_HEADERS)) \ --symbol-prefix=dbusmenu \ --identifier-prefix=Dbusmenu else INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --warn-all \ --add-include-path=$(srcdir) \ - $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) + $(addprefix --c-include=libdbusmenu-glib/, $(libdbusmenu_glibinclude_HEADERS)) endif INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) if HAVE_INTROSPECTION -introspection_sources = $(libdbusmenu_glibinclude_HEADERS) +introspection_sources = $(libdbusmenu_glibinclude_HEADERS) $(libdbusmenu_glib_la_SOURCES) Dbusmenu-0.4.gir: libdbusmenu-glib.la Dbusmenu_0_4_gir_INCLUDES = \ diff --git a/libdbusmenu-glib/Makefile.in b/libdbusmenu-glib/Makefile.in index 29386df..f81497b 100644 --- a/libdbusmenu-glib/Makefile.in +++ b/libdbusmenu-glib/Makefile.in @@ -15,6 +15,23 @@ @SET_MAKE@ +# Rules for generating enumeration types using glib-mkenums +# +# Define: +# glib_enum_h = header template file +# glib_enum_c = source template file +# glib_enum_headers = list of headers to parse +# +# before including Makefile.am.enums. You will also need to have +# the following targets already defined: +# +# CLEANFILES +# DISTCLEANFILES +# BUILT_SOURCES +# EXTRA_DIST +# +# Author: Emmanuele Bassi <ebassi@linux.intel.com> + VPATH = @srcdir@ @@ -36,12 +53,13 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ +DIST_COMMON = $(libdbusmenu_glibinclude_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in $(srcdir)/dbusmenu-glib-0.4.pc.in \ + $(top_srcdir)/Makefile.am.enum @HAVE_INTROSPECTION_TRUE@am__append_1 = Dbusmenu-0.4.gir @HAVE_INTROSPECTION_TRUE@am__append_2 = $(gir_DATA) $(typelib_DATA) \ @HAVE_INTROSPECTION_TRUE@ $(vapi_DATA) subdir = libdbusmenu-glib -DIST_COMMON = $(libdbusmenu_glibinclude_HEADERS) $(srcdir)/Makefile.am \ - $(srcdir)/Makefile.in $(srcdir)/dbusmenu-glib-0.4.pc.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/gnome-doc-utils.m4 \ $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/intltool.m4 \ @@ -85,6 +103,8 @@ am__DEPENDENCIES_1 = libdbusmenu_glib_la_DEPENDENCIES = $(am__DEPENDENCIES_1) am_libdbusmenu_glib_la_OBJECTS = \ libdbusmenu_glib_la-dbus-menu-clean.xml.lo \ + libdbusmenu_glib_la-defaults.lo \ + libdbusmenu_glib_la-enum-types.lo \ libdbusmenu_glib_la-menuitem.lo \ libdbusmenu_glib_la-menuitem-marshal.lo \ libdbusmenu_glib_la-menuitem-proxy.lo \ @@ -173,6 +193,7 @@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GLIB_MKENUMS = @GLIB_MKENUMS@ GMOFILES = @GMOFILES@ GMSGFMT = @GMSGFMT@ GREP = @GREP@ @@ -302,15 +323,19 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -CLEANFILES = dbus-menu-clean.xml $(BUILT_SOURCES) $(am__append_2) -EXTRA_DIST = \ - clean-namespaces.xslt \ - dbusmenu-glib-0.4.pc.in \ - dbus-menu.xml \ - client-marshal.list \ - menuitem-marshal.list \ - server-marshal.list - +BUILT_SOURCES = $(glib_enum_h) $(glib_enum_c) dbus-menu-clean.xml.c \ + dbus-menu-clean.xml.h client-marshal.h client-marshal.c \ + menuitem-marshal.h menuitem-marshal.c server-marshal.h \ + server-marshal.c +CLEANFILES = stamp-enum-types dbus-menu-clean.xml $(BUILT_SOURCES) \ + $(am__append_2) +DISTCLEANFILES = $(glib_enum_h) $(glib_enum_c) enum-types.c \ + enum-types.h +EXTRA_DIST = clean-namespaces.xslt dbusmenu-glib-0.4.pc.in \ + dbus-menu.xml client-marshal.list menuitem-marshal.list \ + server-marshal.list $(enum_tmpl_h) $(enum_tmpl_c) +enum_tmpl_h = $(glib_enum_h:.h=.h.in) +enum_tmpl_c = $(glib_enum_c:.c=.c.in) lib_LTLIBRARIES = \ libdbusmenu-glib.la @@ -320,11 +345,16 @@ libdbusmenu_glibinclude_HEADERS = \ menuitem.h \ menuitem-proxy.h \ server.h \ - client.h + client.h \ + types.h libdbusmenu_glib_la_SOURCES = \ dbus-menu-clean.xml.h \ dbus-menu-clean.xml.c \ + defaults.h \ + defaults.c \ + enum-types.h \ + enum-types.c \ menuitem.h \ menuitem.c \ menuitem-marshal.h \ @@ -340,6 +370,7 @@ libdbusmenu_glib_la_SOURCES = \ client-marshal.c \ client-menuitem.h \ client-menuitem.c \ + client-private.h \ client.h \ client.c @@ -356,31 +387,24 @@ libdbusmenu_glib_la_LIBADD = \ pkgconfig_DATA = dbusmenu-glib-0.4.pc pkgconfigdir = $(libdir)/pkgconfig -BUILT_SOURCES = \ - dbus-menu-clean.xml.c \ - dbus-menu-clean.xml.h \ - client-marshal.h \ - client-marshal.c \ - menuitem-marshal.h \ - menuitem-marshal.c \ - server-marshal.h \ - server-marshal.c - +glib_enum_h = enum-types.h +glib_enum_c = enum-types.c +glib_enum_headers = $(addprefix $(srcdir)/, $(libdbusmenu_glibinclude_HEADERS)) INTROSPECTION_GIRS = $(am__append_1) @INTROSPECTION_TEN_FALSE@INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ @INTROSPECTION_TEN_FALSE@ --warn-all \ @INTROSPECTION_TEN_FALSE@ --add-include-path=$(srcdir) \ -@INTROSPECTION_TEN_FALSE@ $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) +@INTROSPECTION_TEN_FALSE@ $(addprefix --c-include=libdbusmenu-glib/, $(libdbusmenu_glibinclude_HEADERS)) @INTROSPECTION_TEN_TRUE@INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ @INTROSPECTION_TEN_TRUE@ --warn-all \ @INTROSPECTION_TEN_TRUE@ --add-include-path=$(srcdir) \ -@INTROSPECTION_TEN_TRUE@ $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) \ +@INTROSPECTION_TEN_TRUE@ $(addprefix --c-include=libdbusmenu-glib/, $(libdbusmenu_glibinclude_HEADERS)) \ @INTROSPECTION_TEN_TRUE@ --symbol-prefix=dbusmenu \ @INTROSPECTION_TEN_TRUE@ --identifier-prefix=Dbusmenu INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) -@HAVE_INTROSPECTION_TRUE@introspection_sources = $(libdbusmenu_glibinclude_HEADERS) +@HAVE_INTROSPECTION_TRUE@introspection_sources = $(libdbusmenu_glibinclude_HEADERS) $(libdbusmenu_glib_la_SOURCES) @HAVE_INTROSPECTION_TRUE@Dbusmenu_0_4_gir_INCLUDES = \ @HAVE_INTROSPECTION_TRUE@ GObject-2.0 @@ -406,7 +430,7 @@ all: $(BUILT_SOURCES) .SUFFIXES: .SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/Makefile.am.enum $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -482,6 +506,8 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdbusmenu_glib_la-client-menuitem.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdbusmenu_glib_la-client.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdbusmenu_glib_la-dbus-menu-clean.xml.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdbusmenu_glib_la-defaults.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdbusmenu_glib_la-enum-types.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdbusmenu_glib_la-menuitem-marshal.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdbusmenu_glib_la-menuitem-proxy.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdbusmenu_glib_la-menuitem.Plo@am__quote@ @@ -520,6 +546,22 @@ libdbusmenu_glib_la-dbus-menu-clean.xml.lo: dbus-menu-clean.xml.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdbusmenu_glib_la_CFLAGS) $(CFLAGS) -c -o libdbusmenu_glib_la-dbus-menu-clean.xml.lo `test -f 'dbus-menu-clean.xml.c' || echo '$(srcdir)/'`dbus-menu-clean.xml.c +libdbusmenu_glib_la-defaults.lo: defaults.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdbusmenu_glib_la_CFLAGS) $(CFLAGS) -MT libdbusmenu_glib_la-defaults.lo -MD -MP -MF $(DEPDIR)/libdbusmenu_glib_la-defaults.Tpo -c -o libdbusmenu_glib_la-defaults.lo `test -f 'defaults.c' || echo '$(srcdir)/'`defaults.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libdbusmenu_glib_la-defaults.Tpo $(DEPDIR)/libdbusmenu_glib_la-defaults.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='defaults.c' object='libdbusmenu_glib_la-defaults.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdbusmenu_glib_la_CFLAGS) $(CFLAGS) -c -o libdbusmenu_glib_la-defaults.lo `test -f 'defaults.c' || echo '$(srcdir)/'`defaults.c + +libdbusmenu_glib_la-enum-types.lo: enum-types.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdbusmenu_glib_la_CFLAGS) $(CFLAGS) -MT libdbusmenu_glib_la-enum-types.lo -MD -MP -MF $(DEPDIR)/libdbusmenu_glib_la-enum-types.Tpo -c -o libdbusmenu_glib_la-enum-types.lo `test -f 'enum-types.c' || echo '$(srcdir)/'`enum-types.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libdbusmenu_glib_la-enum-types.Tpo $(DEPDIR)/libdbusmenu_glib_la-enum-types.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='enum-types.c' object='libdbusmenu_glib_la-enum-types.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdbusmenu_glib_la_CFLAGS) $(CFLAGS) -c -o libdbusmenu_glib_la-enum-types.lo `test -f 'enum-types.c' || echo '$(srcdir)/'`enum-types.c + libdbusmenu_glib_la-menuitem.lo: menuitem.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdbusmenu_glib_la_CFLAGS) $(CFLAGS) -MT libdbusmenu_glib_la-menuitem.lo -MD -MP -MF $(DEPDIR)/libdbusmenu_glib_la-menuitem.Tpo -c -o libdbusmenu_glib_la-menuitem.lo `test -f 'menuitem.c' || echo '$(srcdir)/'`menuitem.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libdbusmenu_glib_la-menuitem.Tpo $(DEPDIR)/libdbusmenu_glib_la-menuitem.Plo @@ -803,6 +845,7 @@ clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @@ -906,6 +949,26 @@ uninstall-am: uninstall-girDATA uninstall-libLTLIBRARIES \ uninstall-vapiDATA +stamp-enum-types: $(glib_enum_headers) + $(QUIET_GEN)mkdir -p `dirname $(builddir)/$(glib_enum_h)` + $(QUIET_GEN)$(GLIB_MKENUMS) \ + --template $(srcdir)/$(enum_tmpl_h) \ + $(glib_enum_headers) > xgen-eh \ + && (cmp -s xgen-eh $(builddir)/$(glib_enum_h) || cp -f xgen-eh $(builddir)/$(glib_enum_h)) \ + && rm -f xgen-eh \ + && echo timestamp > $(@F) + +$(glib_enum_h): stamp-enum-types + @true + +$(glib_enum_c): $(glib_enum_h) + $(QUIET_GEN)mkdir -p `dirname $(builddir)/$(glib_enum_c)` + $(QUIET_GEN)$(GLIB_MKENUMS) \ + --template $(srcdir)/$(enum_tmpl_c) \ + $(glib_enum_headers) > xgen-ec \ + && cp -f xgen-ec $(builddir)/$(glib_enum_c) \ + && rm -f xgen-ec + %.xml.h: %.xml echo "extern const char * $(subst -,_,$(subst .,_,$(basename $(notdir $@))));" > $@ diff --git a/libdbusmenu-glib/client-marshal.c b/libdbusmenu-glib/client-marshal.c index 1fabb99..60d7bd6 100644 --- a/libdbusmenu-glib/client-marshal.c +++ b/libdbusmenu-glib/client-marshal.c @@ -129,3 +129,5 @@ _dbusmenu_client_marshal_VOID__OBJECT_STRING_VARIANT_UINT_POINTER (GClosure data2); } +/* VOID:ENUM (./client-marshal.list:3) */ + diff --git a/libdbusmenu-glib/client-marshal.h b/libdbusmenu-glib/client-marshal.h index f12ddde..c12af7c 100644 --- a/libdbusmenu-glib/client-marshal.h +++ b/libdbusmenu-glib/client-marshal.h @@ -22,6 +22,9 @@ extern void _dbusmenu_client_marshal_VOID__OBJECT_STRING_VARIANT_UINT_POINTER (G gpointer invocation_hint, gpointer marshal_data); +/* VOID:ENUM (./client-marshal.list:3) */ +#define _dbusmenu_client_marshal_VOID__ENUM g_cclosure_marshal_VOID__ENUM + G_END_DECLS #endif /* ___dbusmenu_client_marshal_MARSHAL_H__ */ diff --git a/libdbusmenu-glib/client-marshal.list b/libdbusmenu-glib/client-marshal.list index 866dfa8..96f9302 100644 --- a/libdbusmenu-glib/client-marshal.list +++ b/libdbusmenu-glib/client-marshal.list @@ -1,2 +1,3 @@ VOID: OBJECT, UINT VOID: OBJECT, STRING, VARIANT, UINT, POINTER +VOID: ENUM diff --git a/libdbusmenu-glib/client-menuitem.c b/libdbusmenu-glib/client-menuitem.c index 0f14b85..60f8637 100644 --- a/libdbusmenu-glib/client-menuitem.c +++ b/libdbusmenu-glib/client-menuitem.c @@ -30,6 +30,7 @@ License version 3 and version 2.1 along with this program. If not, see #endif #include "client-menuitem.h" +#include "client-private.h" typedef struct _DbusmenuClientMenuitemPrivate DbusmenuClientMenuitemPrivate; @@ -39,7 +40,7 @@ struct _DbusmenuClientMenuitemPrivate }; #define DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_CLIENT_MENUITEM_TYPE, DbusmenuClientMenuitemPrivate)) +(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_CLIENT_MENUITEM, DbusmenuClientMenuitemPrivate)) static void dbusmenu_client_menuitem_class_init (DbusmenuClientMenuitemClass *klass); static void dbusmenu_client_menuitem_init (DbusmenuClientMenuitem *self); @@ -94,7 +95,7 @@ dbusmenu_client_menuitem_finalize (GObject *object) DbusmenuClientMenuitem * dbusmenu_client_menuitem_new (gint id, DbusmenuClient * client) { - DbusmenuClientMenuitem * mi = g_object_new(DBUSMENU_CLIENT_MENUITEM_TYPE, "id", id, NULL); + DbusmenuClientMenuitem * mi = g_object_new(DBUSMENU_TYPE_CLIENT_MENUITEM, "id", id, NULL); DbusmenuClientMenuitemPrivate * priv = DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(mi); priv->client = client; return mi; diff --git a/libdbusmenu-glib/client-menuitem.h b/libdbusmenu-glib/client-menuitem.h index ef61213..a89cb11 100644 --- a/libdbusmenu-glib/client-menuitem.h +++ b/libdbusmenu-glib/client-menuitem.h @@ -35,12 +35,12 @@ License version 3 and version 2.1 along with this program. If not, see G_BEGIN_DECLS -#define DBUSMENU_CLIENT_MENUITEM_TYPE (dbusmenu_client_menuitem_get_type ()) -#define DBUSMENU_CLIENT_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DBUSMENU_CLIENT_MENUITEM_TYPE, DbusmenuClientMenuitem)) -#define DBUSMENU_CLIENT_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUSMENU_CLIENT_MENUITEM_TYPE, DbusmenuClientMenuitemClass)) -#define DBUSMENU_IS_CLIENT_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DBUSMENU_CLIENT_MENUITEM_TYPE)) -#define DBUSMENU_IS_CLIENT_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_CLIENT_MENUITEM_TYPE)) -#define DBUSMENU_CLIENT_MENUITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_CLIENT_MENUITEM_TYPE, DbusmenuClientMenuitemClass)) +#define DBUSMENU_TYPE_CLIENT_MENUITEM (dbusmenu_client_menuitem_get_type ()) +#define DBUSMENU_CLIENT_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DBUSMENU_TYPE_CLIENT_MENUITEM, DbusmenuClientMenuitem)) +#define DBUSMENU_CLIENT_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUSMENU_TYPE_CLIENT_MENUITEM, DbusmenuClientMenuitemClass)) +#define DBUSMENU_IS_CLIENT_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DBUSMENU_TYPE_CLIENT_MENUITEM)) +#define DBUSMENU_IS_CLIENT_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_CLIENT_MENUITEM)) +#define DBUSMENU_CLIENT_MENUITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_CLIENT_MENUITEM, DbusmenuClientMenuitemClass)) typedef struct _DbusmenuClientMenuitem DbusmenuClientMenuitem; typedef struct _DbusmenuClientMenuitemClass DbusmenuClientMenuitemClass; diff --git a/libdbusmenu-glib/client-private.h b/libdbusmenu-glib/client-private.h new file mode 100644 index 0000000..f6df372 --- /dev/null +++ b/libdbusmenu-glib/client-private.h @@ -0,0 +1,48 @@ +/* +A library to communicate a menu object set accross DBus and +track updates and maintain consistency. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#ifndef __DBUSMENU_CLIENT_PRIVATE_H__ +#define __DBUSMENU_CLIENT_PRIVATE_H__ + +#include "client.h" + +G_BEGIN_DECLS + +void dbusmenu_client_send_event (DbusmenuClient * client, + gint id, + const gchar * name, + GVariant * variant, + guint timestamp); +void dbusmenu_client_send_about_to_show(DbusmenuClient * client, + gint id, + void (*cb) (gpointer user_data), + gpointer cb_data); + +G_END_DECLS + +#endif diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index ba4ae7e..d368a0e 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -33,12 +33,14 @@ License version 3 and version 2.1 along with this program. If not, see #include <gio/gio.h> #include "client.h" +#include "client-private.h" #include "menuitem.h" #include "menuitem-private.h" #include "client-menuitem.h" #include "server-marshal.h" #include "client-marshal.h" #include "dbus-menu-clean.xml.h" +#include "enum-types.h" /* How many property requests should we queue before sending the message on dbus */ @@ -48,7 +50,9 @@ License version 3 and version 2.1 along with this program. If not, see enum { PROP_0, PROP_DBUSOBJECT, - PROP_DBUSNAME + PROP_DBUSNAME, + PROP_STATUS, + PROP_TEXT_DIRECTION }; /* Signals */ @@ -79,6 +83,7 @@ struct _DbusmenuClientPrivate GCancellable * menuproxy_cancel; GCancellable * layoutcall; + GVariant * layout_props; gint current_revision; gint my_revision; @@ -90,6 +95,9 @@ struct _DbusmenuClientPrivate GArray * delayed_property_list; GArray * delayed_property_listeners; gint delayed_idle; + + DbusmenuTextDirection text_direction; + DbusmenuStatus status; }; typedef struct _newItemPropData newItemPropData; @@ -157,6 +165,7 @@ static void get_properties_globber (DbusmenuClient * client, gint id, const gcha static GQuark error_domain (void); static void item_activated (GDBusProxy * proxy, gint id, guint timestamp, DbusmenuClient * client); static void menuproxy_build_cb (GObject * object, GAsyncResult * res, gpointer user_data); +static void menuproxy_prop_changed_cb (GDBusProxy * proxy, GVariant * properties, GStrv invalidated, gpointer user_data); static void menuproxy_name_changed_cb (GObject * object, GParamSpec * pspec, gpointer user_data); static void menuproxy_signal_cb (GDBusProxy * proxy, gchar * sender, gchar * signal, GVariant * params, gpointer user_data); static void type_handler_destroy (gpointer user_data); @@ -274,6 +283,16 @@ dbusmenu_client_class_init (DbusmenuClientClass *klass) "Name of the DBus client we're connecting to.", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, PROP_STATUS, + g_param_spec_enum(DBUSMENU_CLIENT_PROP_STATUS, "Status of viewing the menus", + "Whether the menus should be given special visuals", + DBUSMENU_TYPE_STATUS, DBUSMENU_STATUS_NORMAL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, PROP_TEXT_DIRECTION, + g_param_spec_enum(DBUSMENU_CLIENT_PROP_TEXT_DIRECTION, "Direction text values have", + "Signals which direction the default text direction is for the menus", + DBUSMENU_TYPE_TEXT_DIRECTION, DBUSMENU_TEXT_DIRECTION_NONE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); if (dbusmenu_node_info == NULL) { GError * error = NULL; @@ -316,6 +335,15 @@ dbusmenu_client_init (DbusmenuClient *self) priv->layoutcall = NULL; + gchar * layout_props[5]; + layout_props[0] = DBUSMENU_MENUITEM_PROP_TYPE; + layout_props[1] = DBUSMENU_MENUITEM_PROP_LABEL; + layout_props[2] = DBUSMENU_MENUITEM_PROP_VISIBLE; + layout_props[3] = DBUSMENU_MENUITEM_PROP_ENABLED; + layout_props[4] = NULL; + priv->layout_props = g_variant_new_strv((const gchar * const *)layout_props, 4); + g_variant_ref_sink(priv->layout_props); + priv->current_revision = 0; priv->my_revision = 0; @@ -328,6 +356,9 @@ dbusmenu_client_init (DbusmenuClient *self) priv->delayed_property_list = g_array_new(TRUE, FALSE, sizeof(gchar *)); priv->delayed_property_listeners = g_array_new(FALSE, FALSE, sizeof(properties_listener_t)); + priv->text_direction = DBUSMENU_TEXT_DIRECTION_NONE; + priv->status = DBUSMENU_STATUS_NORMAL; + return; } @@ -380,6 +411,11 @@ dbusmenu_client_dispose (GObject *object) priv->layoutcall = NULL; } + if (priv->layout_props != NULL) { + g_variant_unref(priv->layout_props); + priv->layout_props = NULL; + } + /* Bring down the menu proxy, ensure we're not looking for one at the same time. */ if (priv->menuproxy_cancel != NULL) { @@ -472,6 +508,12 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) case PROP_DBUSOBJECT: g_value_set_string(value, priv->dbus_object); break; + case PROP_STATUS: + g_value_set_enum(value, priv->status); + break; + case PROP_TEXT_DIRECTION: + g_value_set_enum(value, priv->text_direction); + break; default: g_warning("Unknown property %d.", id); return; @@ -983,6 +1025,19 @@ menuproxy_build_cb (GObject * object, GAsyncResult * res, gpointer user_data) priv->menuproxy_cancel = NULL; } + /* Check the text direction if available */ + GVariant * textdir = g_dbus_proxy_get_cached_property(priv->menuproxy, "text-direction"); + if (textdir != NULL) { + GVariant * str = textdir; + if (g_variant_is_of_type(str, G_VARIANT_TYPE_VARIANT)) { + str = g_variant_get_variant(str); + } + + priv->text_direction = dbusmenu_text_direction_get_value_from_nick(g_variant_get_string(str, NULL)); + + g_variant_unref(textdir); + } + /* If we get here, we don't need the DBus proxy */ if (priv->dbusproxy != 0) { g_bus_unwatch_name(priv->dbusproxy); @@ -991,6 +1046,7 @@ menuproxy_build_cb (GObject * object, GAsyncResult * res, gpointer user_data) g_signal_connect(priv->menuproxy, "g-signal", G_CALLBACK(menuproxy_signal_cb), client); g_signal_connect(priv->menuproxy, "notify::g-name-owner", G_CALLBACK(menuproxy_name_changed_cb), client); + g_signal_connect(priv->menuproxy, "g-properties-changed", G_CALLBACK(menuproxy_prop_changed_cb), client); gchar * name_owner = g_dbus_proxy_get_name_owner(priv->menuproxy); if (name_owner != NULL) { @@ -1001,6 +1057,63 @@ menuproxy_build_cb (GObject * object, GAsyncResult * res, gpointer user_data) return; } +/* Handle the properites changing */ +static void +menuproxy_prop_changed_cb (GDBusProxy * proxy, GVariant * properties, GStrv invalidated, gpointer user_data) +{ + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(user_data); + DbusmenuTextDirection olddir = priv->text_direction; + DbusmenuStatus oldstatus = priv->status; + + /* Invalidate first */ + gchar * invalid; + gint i = 0; + for (invalid = invalidated[i]; invalid != NULL; invalid = invalidated[++i]) { + if (g_strcmp0(invalid, "text-direction") == 0) { + priv->text_direction = DBUSMENU_TEXT_DIRECTION_NONE; + } + if (g_strcmp0(invalid, "status") == 0) { + priv->status = DBUSMENU_STATUS_NORMAL; + } + } + + /* Check updates */ + GVariantIter iters; + gchar * key; GVariant * value; + g_variant_iter_init(&iters, properties); + while (g_variant_iter_next(&iters, "{sv}", &key, &value)) { + if (g_strcmp0(key, "text-direction") == 0) { + GVariant * str = value; + if (g_variant_is_of_type(str, G_VARIANT_TYPE_VARIANT)) { + str = g_variant_get_variant(str); + } + + priv->text_direction = dbusmenu_text_direction_get_value_from_nick(g_variant_get_string(str, NULL)); + } + if (g_strcmp0(key, "status") == 0) { + GVariant * str = value; + if (g_variant_is_of_type(str, G_VARIANT_TYPE_VARIANT)) { + str = g_variant_get_variant(str); + } + + priv->status = dbusmenu_status_get_value_from_nick(g_variant_get_string(str, NULL)); + } + + g_variant_unref(value); + g_free(key); + } + + if (olddir != priv->text_direction) { + g_object_notify(G_OBJECT(user_data), DBUSMENU_CLIENT_PROP_TEXT_DIRECTION); + } + + if (oldstatus != priv->status) { + g_object_notify(G_OBJECT(user_data), DBUSMENU_CLIENT_PROP_STATUS); + } + + return; +} + /* Handle the case where we change owners */ static void menuproxy_name_changed_cb (GObject * object, GParamSpec * pspec, gpointer user_data) @@ -1473,6 +1586,33 @@ parse_layout_xml(DbusmenuClient * client, GVariant * layout, DbusmenuMenuitem * parse_layout_update(childmi, client); } + /* Apply known properties sent in the structure to the + menu item. Sometimes they may just be copies */ + if (childmi != NULL) { + GVariantIter iter; + gchar * prop; + GVariant * value; + + /* Set the type first as it can manage the behavior of + all other properties. */ + g_variant_iter_init(&iter, g_variant_get_child_value(child, 1)); + while (g_variant_iter_next(&iter, "{sv}", &prop, &value)) { + if (g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_TYPE) == 0) { + dbusmenu_menuitem_property_set_variant(childmi, prop, value); + } + g_free(prop); + g_variant_unref(value); + } + + /* Now go through and do all the properties. */ + g_variant_iter_init(&iter, g_variant_get_child_value(child, 1)); + while (g_variant_iter_next(&iter, "{sv}", &prop, &value)) { + dbusmenu_menuitem_property_set_variant(childmi, prop, value); + g_free(prop); + g_variant_unref(value); + } + } + position++; } @@ -1662,7 +1802,7 @@ update_layout (DbusmenuClient * client) g_variant_builder_add_value(&tupleb, g_variant_new_int32(0)); // root g_variant_builder_add_value(&tupleb, g_variant_new_int32(-1)); // recurse - g_variant_builder_add_value(&tupleb, g_variant_new_array(G_VARIANT_TYPE_STRING, NULL, 0)); // props + g_variant_builder_add_value(&tupleb, priv->layout_props); // props GVariant * args = g_variant_builder_end(&tupleb); // g_debug("Args (type: %s): %s", g_variant_get_type_string(args), g_variant_print(args, TRUE)); @@ -1682,17 +1822,17 @@ update_layout (DbusmenuClient * client) /* Public API */ /** - dbusmenu_client_new: - @name: The DBus name for the server to connect to - @object: The object on the server to monitor - - This function creates a new client that connects to a specific - server on DBus. That server is at a specific location sharing - a known object. The interface is assumed by the code to be - the DBus menu interface. The newly created client will start - sending out events as it syncs up with the server. - - Return value: A brand new #DbusmenuClient + * dbusmenu_client_new: + * @name: The DBus name for the server to connect to + * @object: The object on the server to monitor + * + * This function creates a new client that connects to a specific + * server on DBus. That server is at a specific location sharing + * a known object. The interface is assumed by the code to be + * the DBus menu interface. The newly created client will start + * sending out events as it syncs up with the server. + * + * Return value: A brand new #DbusmenuClient */ DbusmenuClient * dbusmenu_client_new (const gchar * name, const gchar * object) @@ -1706,21 +1846,21 @@ dbusmenu_client_new (const gchar * name, const gchar * object) } /** - dbusmenu_client_get_root: - @client: The #DbusmenuClient to get the root node from - - Grabs the root node for the specified client @client. This - function may block. It will block if there is currently a - call to update the layout, it will block on that layout - updated and then return the newly updated layout. Chances - are that this update is in the queue for the mainloop as - it would have been requested some time ago, but in theory - it could block longer. - - Return value: A #DbusmenuMenuitem representing the root of - menu on the server. If there is no server or there is - an error receiving its layout it'll return #NULL. -*/ + * dbusmenu_client_get_root: + * @client: The #DbusmenuClient to get the root node from + * + * Grabs the root node for the specified client @client. This + * function may block. It will block if there is currently a + * call to update the layout, it will block on that layout + * updated and then return the newly updated layout. Chances + * are that this update is in the queue for the mainloop as + * it would have been requested some time ago, but in theory + * it could block longer. + * + * Return value: (transfer none): A #DbusmenuMenuitem representing the root of + * menu on the server. If there is no server or there is + * an error receiving its layout it'll return #NULL. + */ DbusmenuMenuitem * dbusmenu_client_get_root (DbusmenuClient * client) { @@ -1749,25 +1889,25 @@ type_handler_destroy (gpointer user_data) } /** - dbusmenu_client_add_type_handler: - @client: Client where we're getting types coming in - @type: A text string that will be matched with the 'type' - property on incoming menu items - @newfunc: The function that will be executed with those new - items when they come in. - - This function connects into the type handling of the #DbusmenuClient. - Every new menuitem that comes in immediately gets asked for it's - properties. When we get those properties we check the 'type' - property and look to see if it matches a handler that is known - by the client. If so, the @newfunc function is executed on that - #DbusmenuMenuitem. If not, then the DbusmenuClient::new-menuitem - signal is sent. - - In the future the known types will be sent to the server so that it - can make choices about the menu item types availble. - - Return value: If registering the new type was successful. + * dbusmenu_client_add_type_handler: + * @client: Client where we're getting types coming in + * @type: A text string that will be matched with the 'type' + * property on incoming menu items + * @newfunc: The function that will be executed with those new + * items when they come in. + * + * This function connects into the type handling of the #DbusmenuClient. + * Every new menuitem that comes in immediately gets asked for it's + * properties. When we get those properties we check the 'type' + * property and look to see if it matches a handler that is known + * by the client. If so, the @newfunc function is executed on that + * #DbusmenuMenuitem. If not, then the DbusmenuClient::new-menuitem + * signal is sent. + * + * In the future the known types will be sent to the server so that it + * can make choices about the menu item types availble. + * + * Return value: If registering the new type was successful. */ gboolean dbusmenu_client_add_type_handler (DbusmenuClient * client, const gchar * type, DbusmenuClientTypeHandler newfunc) @@ -1776,29 +1916,29 @@ dbusmenu_client_add_type_handler (DbusmenuClient * client, const gchar * type, D } /** - dbusmenu_client_add_type_handler_full: - @client: Client where we're getting types coming in - @type: A text string that will be matched with the 'type' - property on incoming menu items - @newfunc: The function that will be executed with those new - items when they come in. - @user_data: Data passed to @newfunc when it is called - @destroy_func: A function that is called when the type handler is - removed (usually on client destruction) which will free - the resources in @user_data. - - This function connects into the type handling of the #DbusmenuClient. - Every new menuitem that comes in immediately gets asked for it's - properties. When we get those properties we check the 'type' - property and look to see if it matches a handler that is known - by the client. If so, the @newfunc function is executed on that - #DbusmenuMenuitem. If not, then the DbusmenuClient::new-menuitem - signal is sent. - - In the future the known types will be sent to the server so that it - can make choices about the menu item types availble. - - Return value: If registering the new type was successful. + * dbusmenu_client_add_type_handler_full: + * @client: Client where we're getting types coming in + * @type: A text string that will be matched with the 'type' + * property on incoming menu items + * @newfunc: The function that will be executed with those new + * items when they come in. + * @user_data: Data passed to @newfunc when it is called + * @destroy_func: A function that is called when the type handler is + * removed (usually on client destruction) which will free + * the resources in @user_data. + * + * This function connects into the type handling of the #DbusmenuClient. + * Every new menuitem that comes in immediately gets asked for it's + * properties. When we get those properties we check the 'type' + * property and look to see if it matches a handler that is known + * by the client. If so, the @newfunc function is executed on that + * #DbusmenuMenuitem. If not, then the DbusmenuClient::new-menuitem + * signal is sent. + * + * In the future the known types will be sent to the server so that it + * can make choices about the menu item types availble. + * + * Return value: If registering the new type was successful. */ gboolean dbusmenu_client_add_type_handler_full (DbusmenuClient * client, const gchar * type, DbusmenuClientTypeHandler newfunc, gpointer user_data, DbusmenuClientTypeDestroyHandler destroy_func) @@ -1834,3 +1974,42 @@ dbusmenu_client_add_type_handler_full (DbusmenuClient * client, const gchar * ty return TRUE; } +/** + dbusmenu_client_get_text_direction: + @client: #DbusmenuClient to check the text direction on + + Gets the text direction that the server is exporting. If + the server is not exporting a direction then the value + #DBUSMENU_TEXT_DIRECTION_NONE will be returned. + + Return value: Text direction being exported. +*/ +DbusmenuTextDirection +dbusmenu_client_get_text_direction (DbusmenuClient * client) +{ + g_return_val_if_fail(DBUSMENU_IS_CLIENT(client), DBUSMENU_TEXT_DIRECTION_NONE); + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); + return priv->text_direction; +} + +/** + dbusmenu_client_get_status: + @client: #DbusmenuClient to check the status on + + Gets the recommended current status that the server + is exporting for the menus. In situtations where the + value is #DBUSMENU_STATUS_NOTICE it is recommended that + the client show the menus to the user an a more noticible + way. + + Return value: Status being exported. +*/ +DbusmenuStatus +dbusmenu_client_get_status (DbusmenuClient * client) +{ + g_return_val_if_fail(DBUSMENU_IS_CLIENT(client), DBUSMENU_STATUS_NORMAL); + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); + return priv->status; +} + + diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index 6d78edf..28d4dd3 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -33,6 +33,7 @@ License version 3 and version 2.1 along with this program. If not, see #include <glib-object.h> #include "menuitem.h" +#include "types.h" G_BEGIN_DECLS @@ -43,17 +44,89 @@ G_BEGIN_DECLS #define DBUSMENU_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_CLIENT)) #define DBUSMENU_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_CLIENT, DbusmenuClientClass)) +/** + * DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED: + * + * String to attach to signal #DbusmenuClient::layout-updated + */ #define DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED "layout-updated" +/** + * DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED: + * + * String to attach to signal #DbusmenuClient::root-changed + */ #define DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED "root-changed" +/** + * DBUSMENU_CLIENT_SIGNAL_NEW_MENUITEM: + * + * String to attach to signal #DbusmenuClient::new-menuitem + */ #define DBUSMENU_CLIENT_SIGNAL_NEW_MENUITEM "new-menuitem" +/** + * DBUSMENU_CLIENT_SIGNAL_ITEM_ACTIVATE: + * + * String to attach to signal #DbusmenuClient::item-activate + */ #define DBUSMENU_CLIENT_SIGNAL_ITEM_ACTIVATE "item-activate" +/** + * DBUSMENU_CLIENT_SIGNAL_EVENT_RESULT: + * + * String to attach to signal #DbusmenuClient::event-result + */ #define DBUSMENU_CLIENT_SIGNAL_EVENT_RESULT "event-result" +/** + * DBUSMENU_CLIENT_SIGNAL_TEXT_DIRECTION_CHANGED: + * + * String to attach to signal #DbusmenuClient::text-direction-changed + */ +#define DBUSMENU_CLIENT_SIGNAL_TEXT_DIRECTION_CHANGED "text-direction-changed" +/** + * DBUSMENU_CLIENT_PROP_DBUS_NAME: + * + * String to access property #DbusmenuClient:dbus-name + */ #define DBUSMENU_CLIENT_PROP_DBUS_NAME "dbus-name" +/** + * DBUSMENU_CLIENT_PROP_DBUS_OBJECT: + * + * String to access property #DbusmenuClient:dbus-object + */ #define DBUSMENU_CLIENT_PROP_DBUS_OBJECT "dbus-object" +/** + * DBUSMENU_CLIENT_PROP_STATUS: + * + * String to access property #DbusmenuClient:status + */ +#define DBUSMENU_CLIENT_PROP_STATUS "status" +/** + * DBUSMENU_CLIENT_PROP_TEXT_DIRECTION: + * + * String to access property #DbusmenuClient:text-direction + */ +#define DBUSMENU_CLIENT_PROP_TEXT_DIRECTION "text-direction" +/** + * DBUSMENU_CLIENT_TYPES_DEFAULT: + * + * Used to set the 'type' property on a menu item to create + * a standard menu item. + */ #define DBUSMENU_CLIENT_TYPES_DEFAULT "standard" +/** + * DBUSMENU_CLIENT_TYPES_SEPARATOR: + * + * Used to set the 'type' property on a menu item to create + * a separator menu item. + */ #define DBUSMENU_CLIENT_TYPES_SEPARATOR "separator" +/** + * DBUSMENU_CLIENT_TYPES_IMAGE: + * + * Used to set the 'type' property on a menu item to create + * an image menu item. Deprecated as standard menu items now + * support images as well. + */ #define DBUSMENU_CLIENT_TYPES_IMAGE "standard" typedef struct _DbusmenuClientPrivate DbusmenuClientPrivate; @@ -62,6 +135,7 @@ typedef struct _DbusmenuClientPrivate DbusmenuClientPrivate; DbusmenuClientClass: @parent_class: #GObjectClass @layout_updated: Slot for #DbusmenuClient::layout-updated. + @root_changed: Slot for #DbusmenuClient::root-changed. @new_menuitem: Slot for #DbusmenuClient::new-menuitem. @item_activate: Slot for #DbusmenuClient::item-activate. @event_result: Slot for #DbusmenuClient::event-error. @@ -97,7 +171,6 @@ struct _DbusmenuClientClass { /** DbusmenuClient: - @parent: #GObject. The client for a #DbusmenuServer creating a shared object set of #DbusmenuMenuitem objects. @@ -119,6 +192,9 @@ struct _DbusmenuClient { The type handler is called when a dbusmenu item is created with a matching type as setup in #dbusmenu_client_add_type_handler + + Return value: #TRUE if the type has been handled. #FALSE if this + function was somehow unable to handle it. */ typedef gboolean (*DbusmenuClientTypeHandler) (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); @@ -145,16 +221,9 @@ gboolean dbusmenu_client_add_type_handler_full (DbusmenuClient * cli const gchar * type, DbusmenuClientTypeHandler newfunc, gpointer user_data, - DbusmenuClientTypeDestroyHandler destory_func); -void dbusmenu_client_send_event (DbusmenuClient * client, - gint id, - const gchar * name, - GVariant * variant, - guint timestamp); -void dbusmenu_client_send_about_to_show(DbusmenuClient * client, - gint id, - void (*cb) (gpointer user_data), - gpointer cb_data); + DbusmenuClientTypeDestroyHandler destroy_func); +DbusmenuTextDirection dbusmenu_client_get_text_direction (DbusmenuClient * client); +DbusmenuStatus dbusmenu_client_get_status (DbusmenuClient * client); /** SECTION:client diff --git a/libdbusmenu-glib/dbus-menu-clean.xml.c b/libdbusmenu-glib/dbus-menu-clean.xml.c index 475adb5..215c19c 100644 --- a/libdbusmenu-glib/dbus-menu-clean.xml.c +++ b/libdbusmenu-glib/dbus-menu-clean.xml.c @@ -10,6 +10,14 @@ const char * dbus_menu_clean_xml = " \n" " </property>\n" "\n" +" <property name=\"text-direction\" type=\"s\" access=\"read\">\n" +" \n" +" </property>\n" +"\n" +" <property name=\"status\" type=\"s\" access=\"read\">\n" +" \n" +" </property>\n" +"\n" "\n" "\n" " <method name=\"GetLayout\">\n" @@ -88,8 +96,8 @@ const char * dbus_menu_clean_xml = "\n" " <signal name=\"ItemsPropertiesUpdated\">\n" " \n" -" <arg type=\"a(ia(sv))\" name=\"props\" direction=\"out\"/>\n" -" <arg type=\"a(ia(s))\" name=\"props_removed\" direction=\"out\"/>\n" +" <arg type=\"a(ia{sv})\" name=\"updatedProps\" direction=\"out\"/>\n" +" <arg type=\"a(ias)\" name=\"removedProps\" direction=\"out\"/>\n" " </signal>\n" " <signal name=\"LayoutUpdated\">\n" " \n" diff --git a/libdbusmenu-glib/dbus-menu.xml b/libdbusmenu-glib/dbus-menu.xml index da14c63..0d2a2d6 100644 --- a/libdbusmenu-glib/dbus-menu.xml +++ b/libdbusmenu-glib/dbus-menu.xml @@ -171,6 +171,24 @@ License version 3 and version 2.1 along with this program. If not, see </dox:d> </property> + <property name="text-direction" type="s" access="read"> + <dox:d> + Represents the way the text direction of the application. This + allows the server to handle mismatches intelligently. For left- + to-right the string is "ltr" for right-to-left it is "rtl". + </dox:d> + </property> + + <property name="status" type="s" access="read"> + <dox:d> + Tells if the menus are in a normal state or they believe that they + could use some attention. Cases for showing them would be if help + were referring to them or they accessors were being highlighted. + This property can have two values: "normal" in almost all cases and + "notice" when they should have a higher priority to be shown. + </dox:d> + </property> + <!-- Functions --> <method name="GetLayout"> @@ -308,8 +326,8 @@ License version 3 and version 2.1 along with this program. If not, see the ID of the item with a hashtable of names and values for those properties. </dox:d> - <arg type="a(ia(sv))" name="props" direction="out" /> - <arg type="a(ia(s))" name="props_removed" direction="out" /> + <arg type="a(ia{sv})" name="updatedProps" direction="out" /> + <arg type="a(ias)" name="removedProps" direction="out" /> </signal> <signal name="LayoutUpdated"> <dox:d> diff --git a/libdbusmenu-glib/defaults.c b/libdbusmenu-glib/defaults.c new file mode 100644 index 0000000..c05ef38 --- /dev/null +++ b/libdbusmenu-glib/defaults.c @@ -0,0 +1,291 @@ +/* +A library to communicate a menu object set accross DBus and +track updates and maintain consistency. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <glib/gi18n.h> + +#include "defaults.h" +#include "menuitem.h" +#include "client.h" + +struct _DbusmenuDefaultsPrivate { + GHashTable * types; +}; + +typedef struct _DefaultEntry DefaultEntry; +struct _DefaultEntry { + GVariantType * type; + GVariant * value; +}; + +#define DBUSMENU_DEFAULTS_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_DEFAULTS, DbusmenuDefaultsPrivate)) + +static void dbusmenu_defaults_class_init (DbusmenuDefaultsClass *klass); +static void dbusmenu_defaults_init (DbusmenuDefaults *self); +static void dbusmenu_defaults_dispose (GObject *object); +static void dbusmenu_defaults_finalize (GObject *object); + +static DefaultEntry * entry_create (const GVariantType * type, GVariant * variant); +static void entry_destroy (gpointer entry); + +G_DEFINE_TYPE (DbusmenuDefaults, dbusmenu_defaults, G_TYPE_OBJECT); + +static void +dbusmenu_defaults_class_init (DbusmenuDefaultsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (DbusmenuDefaultsPrivate)); + + object_class->dispose = dbusmenu_defaults_dispose; + object_class->finalize = dbusmenu_defaults_finalize; + return; +} + +static void +dbusmenu_defaults_init (DbusmenuDefaults *self) +{ + self->priv = DBUSMENU_DEFAULTS_GET_PRIVATE(self); + + self->priv->types = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_hash_table_destroy); + + /* Standard defaults */ + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_VISIBLE, G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(TRUE)); + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_ENABLED, G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(TRUE)); + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_LABEL, G_VARIANT_TYPE_STRING, g_variant_new_string(_("Label Empty"))); + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_ICON_NAME, G_VARIANT_TYPE_STRING, NULL); + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, G_VARIANT_TYPE_STRING, NULL); + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, G_VARIANT_TYPE_INT32, NULL); + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_SHORTCUT, G_VARIANT_TYPE_ARRAY, NULL); + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_DEFAULT, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY, G_VARIANT_TYPE_STRING, NULL); + + /* Separator defaults */ + dbusmenu_defaults_default_set(self, DBUSMENU_CLIENT_TYPES_SEPARATOR, DBUSMENU_MENUITEM_PROP_VISIBLE, G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean(TRUE)); + + return; +} + +static void +dbusmenu_defaults_dispose (GObject *object) +{ + DbusmenuDefaults * self = DBUSMENU_DEFAULTS(object); + + if (self->priv->types != NULL) { + g_hash_table_destroy(self->priv->types); + self->priv->types = NULL; + } + + G_OBJECT_CLASS (dbusmenu_defaults_parent_class)->dispose (object); + return; +} + +static void +dbusmenu_defaults_finalize (GObject *object) +{ + + G_OBJECT_CLASS (dbusmenu_defaults_parent_class)->finalize (object); + return; +} + +/* Create a new entry based on the info provided */ +static DefaultEntry * +entry_create (const GVariantType * type, GVariant * variant) +{ + DefaultEntry * defentry = g_new0(DefaultEntry, 1); + + if (type != NULL) { + defentry->type = g_variant_type_copy(type); + } + + if (variant != NULL) { + defentry->value = variant; + g_variant_ref_sink(variant); + } + + return defentry; +} + +/* Destroy an entry */ +static void +entry_destroy (gpointer entry) +{ + DefaultEntry * defentry = (DefaultEntry *)entry; + + if (defentry->type != NULL) { + g_variant_type_free(defentry->type); + defentry->type = NULL; + } + + if (defentry->value != NULL) { + g_variant_unref(defentry->value); + defentry->value = NULL; + } + + g_free(defentry); + return; +} + +static DbusmenuDefaults * default_defaults = NULL; + +/* + * dbusmenu_defaults_ref_default: + * + * Get a reference to the default instance. If it doesn't exist this + * function will create it. + * + * Return value: (transfer full): A reference to the defaults + */ +DbusmenuDefaults * +dbusmenu_defaults_ref_default (void) +{ + if (default_defaults == NULL) { + default_defaults = DBUSMENU_DEFAULTS(g_object_new(DBUSMENU_TYPE_DEFAULTS, NULL)); + g_object_add_weak_pointer(G_OBJECT(default_defaults), (gpointer *)&default_defaults); + } else { + g_object_ref(default_defaults); + } + + return default_defaults; +} + +/* + * dbusmenu_defaults_default_set: + * @defaults: The #DbusmenuDefaults object to add to + * @type: (allow-none): The #DbusmenuMenuitem type for this default if #NULL will default to #DBUSMENU_CLIENT_TYPE_DEFAULT + * @property: Property name for the default + * @prop_type: (allow-none): Type of the property for runtime checking. To disable checking set to #NULL. + * @value: (allow-none): Default value for @property. #NULL if by default it is unset, but you want type checking from @prop_type. + * + * Sets up an entry in the defaults database for a given @property + * and menuitem type @type. @prop_type and @value can both be #NULL + * but both of them can not. + */ +void +dbusmenu_defaults_default_set (DbusmenuDefaults * defaults, const gchar * type, const gchar * property, const GVariantType * prop_type, GVariant * value) +{ + g_return_if_fail(DBUSMENU_IS_DEFAULTS(defaults)); + g_return_if_fail(property != NULL); + g_return_if_fail(prop_type != NULL || value != NULL); + + if (type == NULL) { + type = DBUSMENU_CLIENT_TYPES_DEFAULT; + } + + GHashTable * prop_table = (GHashTable *)g_hash_table_lookup(defaults->priv->types, type); + + /* We've never had a default for this type, so we need + to create a table for it. */ + if (prop_table == NULL) { + prop_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, entry_destroy); + + g_hash_table_insert(prop_table, g_strdup(property), entry_create(prop_type, value)); + g_hash_table_insert(defaults->priv->types, g_strdup(type), prop_table); + } else { + g_hash_table_replace(prop_table, g_strdup(property), entry_create(prop_type, value)); + } + + return; +} + +/* + * dbusmenu_defaults_default_get: + * @defaults: The default database to use + * @type: (allow-none): The #DbusmenuMenuitem type for this default if #NULL will default to #DBUSMENU_CLIENT_TYPE_DEFAULT + * @property: Property name to lookup + * + * Gets an entry in the database for a give @property and @type. + * + * Return value: (transfer none): Returns a variant that does not + * have it's ref count increased. If you want to keep it, you should + * do that. + */ +GVariant * +dbusmenu_defaults_default_get (DbusmenuDefaults * defaults, const gchar * type, const gchar * property) +{ + g_return_val_if_fail(DBUSMENU_IS_DEFAULTS(defaults), NULL); + g_return_val_if_fail(property != NULL, NULL); + + if (type == NULL) { + type = DBUSMENU_CLIENT_TYPES_DEFAULT; + } + + GHashTable * prop_table = (GHashTable *)g_hash_table_lookup(defaults->priv->types, type); + + if (prop_table == NULL) { + return NULL; + } + + DefaultEntry * entry = (DefaultEntry *)g_hash_table_lookup(prop_table, property); + + if (entry == NULL) { + return NULL; + } + + return entry->value; +} + +/* + * dbusmenu_defaults_default_get_type: + * @defaults: The default database to use + * @type: (allow-none): The #DbusmenuMenuitem type for this default if #NULL will default to #DBUSMENU_CLIENT_TYPE_DEFAULT + * @property: Property name to lookup + * + * Gets the type for an entry in the database for a give @property and @type. + * + * Return value: (transfer none): Returns a type for the given + * @property value. + */ +GVariantType * +dbusmenu_defaults_default_get_type (DbusmenuDefaults * defaults, const gchar * type, const gchar * property) +{ + g_return_val_if_fail(DBUSMENU_IS_DEFAULTS(defaults), NULL); + g_return_val_if_fail(property != NULL, NULL); + + if (type == NULL) { + type = DBUSMENU_CLIENT_TYPES_DEFAULT; + } + + GHashTable * prop_table = (GHashTable *)g_hash_table_lookup(defaults->priv->types, type); + + if (prop_table == NULL) { + return NULL; + } + + DefaultEntry * entry = (DefaultEntry *)g_hash_table_lookup(prop_table, property); + + if (entry == NULL) { + return NULL; + } + + return entry->type; +} + diff --git a/libdbusmenu-glib/defaults.h b/libdbusmenu-glib/defaults.h new file mode 100644 index 0000000..a1a8158 --- /dev/null +++ b/libdbusmenu-glib/defaults.h @@ -0,0 +1,86 @@ +/* +A library to communicate a menu object set accross DBus and +track updates and maintain consistency. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#ifndef __DBUSMENU_DEFAULTS_H__ +#define __DBUSMENU_DEFAULTS_H__ + +#include <glib.h> +#include <glib-object.h> + +G_BEGIN_DECLS + +#define DBUSMENU_TYPE_DEFAULTS (dbusmenu_defaults_get_type ()) +#define DBUSMENU_DEFAULTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DBUSMENU_TYPE_DEFAULTS, DbusmenuDefaults)) +#define DBUSMENU_DEFAULTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUSMENU_TYPE_DEFAULTS, DbusmenuDefaultsClass)) +#define DBUSMENU_IS_DEFAULTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DBUSMENU_TYPE_DEFAULTS)) +#define DBUSMENU_IS_DEFAULTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_DEFAULTS)) +#define DBUSMENU_DEFAULTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_DEFAULTS, DbusmenuDefaultsClass)) + +typedef struct _DbusmenuDefaults DbusmenuDefaults; +typedef struct _DbusmenuDefaultsClass DbusmenuDefaultsClass; +typedef struct _DbusmenuDefaultsPrivate DbusmenuDefaultsPrivate; + +/* + * DbusmenuDefaultsClass: + * + * All of the signals and functions for #DbusmenuDefaults + */ +struct _DbusmenuDefaultsClass { + GObjectClass parent_class; +}; + +/* + * DbusmenuDefaults: + * + * A singleton to hold all of the defaults for the menuitems + * so they can use those easily. + */ +struct _DbusmenuDefaults { + GObject parent; + + /*< Private >*/ + DbusmenuDefaultsPrivate * priv; +}; + +GType dbusmenu_defaults_get_type (void); +DbusmenuDefaults * dbusmenu_defaults_ref_default (void); +void dbusmenu_defaults_default_set (DbusmenuDefaults * defaults, + const gchar * type, + const gchar * property, + const GVariantType * prop_type, + GVariant * value); +GVariant * dbusmenu_defaults_default_get (DbusmenuDefaults * defaults, + const gchar * type, + const gchar * property); +GVariantType * dbusmenu_defaults_default_get_type (DbusmenuDefaults * defaults, + const gchar * type, + const gchar * property); + +G_END_DECLS + +#endif diff --git a/libdbusmenu-glib/enum-types.c b/libdbusmenu-glib/enum-types.c new file mode 100644 index 0000000..dae615c --- /dev/null +++ b/libdbusmenu-glib/enum-types.c @@ -0,0 +1,183 @@ + +/* Generated data (by glib-mkenums) */ + +/* +Enums from the dbusmenu headers + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the + Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by + the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#include "enum-types.h" + +#include "./types.h" +/** + dbusmenu_text_direction_get_type: + + Builds a GLib type for the #DbusmenuTextDirection enumeration. + + Return value: A unique #GType for the #DbusmenuTextDirection enum. +*/ +GType +dbusmenu_text_direction_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY(etype == 0)) { + static const GEnumValue values[] = { + { DBUSMENU_TEXT_DIRECTION_NONE, "DBUSMENU_TEXT_DIRECTION_NONE", "none" }, + { DBUSMENU_TEXT_DIRECTION_LTR, "DBUSMENU_TEXT_DIRECTION_LTR", "ltr" }, + { DBUSMENU_TEXT_DIRECTION_RTL, "DBUSMENU_TEXT_DIRECTION_RTL", "rtl" }, + { 0, NULL, NULL} + }; + + etype = g_enum_register_static (g_intern_static_string("DbusmenuTextDirection"), values); + } + + return etype; +} + +/** + dbusmenu_text_direction_get_nick: + @value: The value of DbusmenuTextDirection to get the nick of + + Looks up in the enum table for the nick of @value. + + Return value: The nick for the given value or #NULL on error +*/ +const gchar * +dbusmenu_text_direction_get_nick (DbusmenuTextDirection value) +{ + GEnumClass * class = G_ENUM_CLASS(g_type_class_ref(dbusmenu_text_direction_get_type())); + g_return_val_if_fail(class != NULL, NULL); + + const gchar * ret = NULL; + GEnumValue * val = g_enum_get_value(class, value); + if (val != NULL) { + ret = val->value_nick; + } + + g_type_class_unref(class); + return ret; +} + +/** + dbusmenu_text_direction_get_value_from_nick: + @nick: The enum nick to lookup + + Looks up in the enum table for the value of @nick. + + Return value: The value for the given @nick +*/ +DbusmenuTextDirection +dbusmenu_text_direction_get_value_from_nick (const gchar * nick) +{ + GEnumClass * class = G_ENUM_CLASS(g_type_class_ref(dbusmenu_text_direction_get_type())); + g_return_val_if_fail(class != NULL, 0); + + DbusmenuTextDirection ret = 0; + GEnumValue * val = g_enum_get_value_by_nick(class, nick); + if (val != NULL) { + ret = val->value; + } + + g_type_class_unref(class); + return ret; +} + + +/** + dbusmenu_status_get_type: + + Builds a GLib type for the #DbusmenuStatus enumeration. + + Return value: A unique #GType for the #DbusmenuStatus enum. +*/ +GType +dbusmenu_status_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY(etype == 0)) { + static const GEnumValue values[] = { + { DBUSMENU_STATUS_NORMAL, "DBUSMENU_STATUS_NORMAL", "normal" }, + { DBUSMENU_STATUS_NOTICE, "DBUSMENU_STATUS_NOTICE", "notice" }, + { 0, NULL, NULL} + }; + + etype = g_enum_register_static (g_intern_static_string("DbusmenuStatus"), values); + } + + return etype; +} + +/** + dbusmenu_status_get_nick: + @value: The value of DbusmenuStatus to get the nick of + + Looks up in the enum table for the nick of @value. + + Return value: The nick for the given value or #NULL on error +*/ +const gchar * +dbusmenu_status_get_nick (DbusmenuStatus value) +{ + GEnumClass * class = G_ENUM_CLASS(g_type_class_ref(dbusmenu_status_get_type())); + g_return_val_if_fail(class != NULL, NULL); + + const gchar * ret = NULL; + GEnumValue * val = g_enum_get_value(class, value); + if (val != NULL) { + ret = val->value_nick; + } + + g_type_class_unref(class); + return ret; +} + +/** + dbusmenu_status_get_value_from_nick: + @nick: The enum nick to lookup + + Looks up in the enum table for the value of @nick. + + Return value: The value for the given @nick +*/ +DbusmenuStatus +dbusmenu_status_get_value_from_nick (const gchar * nick) +{ + GEnumClass * class = G_ENUM_CLASS(g_type_class_ref(dbusmenu_status_get_type())); + g_return_val_if_fail(class != NULL, 0); + + DbusmenuStatus ret = 0; + GEnumValue * val = g_enum_get_value_by_nick(class, nick); + if (val != NULL) { + ret = val->value; + } + + g_type_class_unref(class); + return ret; +} + + + +/* Generated data ends here */ + diff --git a/libdbusmenu-glib/enum-types.c.in b/libdbusmenu-glib/enum-types.c.in new file mode 100644 index 0000000..9395f5f --- /dev/null +++ b/libdbusmenu-glib/enum-types.c.in @@ -0,0 +1,116 @@ +/*** BEGIN file-header ***/ +/* +Enums from the dbusmenu headers + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the + Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by + the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#include "enum-types.h" + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +#include "@filename@" +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +/** + @enum_name@_get_type: + + Builds a GLib type for the #@EnumName@ enumeration. + + Return value: A unique #GType for the #@EnumName@ enum. +*/ +GType +@enum_name@_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY(etype == 0)) { + static const G@Type@Value values[] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL} + }; + + etype = g_@type@_register_static (g_intern_static_string("@EnumName@"), values); + } + + return etype; +} + +/** + @enum_name@_get_nick: + @value: The value of @EnumName@ to get the nick of + + Looks up in the enum table for the nick of @value. + + Return value: The nick for the given value or #NULL on error +*/ +const gchar * +@enum_name@_get_nick (@EnumName@ value) +{ + GEnumClass * class = G_ENUM_CLASS(g_type_class_ref(@enum_name@_get_type())); + g_return_val_if_fail(class != NULL, NULL); + + const gchar * ret = NULL; + GEnumValue * val = g_enum_get_value(class, value); + if (val != NULL) { + ret = val->value_nick; + } + + g_type_class_unref(class); + return ret; +} + +/** + @enum_name@_get_value_from_nick: + @nick: The enum nick to lookup + + Looks up in the enum table for the value of @nick. + + Return value: The value for the given @nick +*/ +@EnumName@ +@enum_name@_get_value_from_nick (const gchar * nick) +{ + GEnumClass * class = G_ENUM_CLASS(g_type_class_ref(@enum_name@_get_type())); + g_return_val_if_fail(class != NULL, 0); + + @EnumName@ ret = 0; + GEnumValue * val = g_enum_get_value_by_nick(class, nick); + if (val != NULL) { + ret = val->value; + } + + g_type_class_unref(class); + return ret; +} + + +/*** END value-tail ***/ diff --git a/libdbusmenu-glib/enum-types.h b/libdbusmenu-glib/enum-types.h new file mode 100644 index 0000000..f75ec64 --- /dev/null +++ b/libdbusmenu-glib/enum-types.h @@ -0,0 +1,68 @@ + +/* Generated data (by glib-mkenums) */ + +/* +Enums from the dbusmenu headers + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the + Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by + the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#ifndef __DBUSMENU_ENUM_TYPES_H__ +#define __DBUSMENU_ENUM_TYPES_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +/* Enumerations from file: "./types.h" */ +#include "./types.h" +GType dbusmenu_text_direction_get_type (void) G_GNUC_CONST; +const gchar * dbusmenu_text_direction_get_nick (DbusmenuTextDirection value) G_GNUC_CONST; +DbusmenuTextDirection dbusmenu_text_direction_get_value_from_nick (const gchar * nick) G_GNUC_CONST; +/** + DBUSMENU_TYPE_TEXT_DIRECTION: + + Gets the #GType value for the type associated with the + #DbusmenuTextDirection enumerated type. +*/ +#define DBUSMENU_TYPE_TEXT_DIRECTION (dbusmenu_text_direction_get_type()) + +GType dbusmenu_status_get_type (void) G_GNUC_CONST; +const gchar * dbusmenu_status_get_nick (DbusmenuStatus value) G_GNUC_CONST; +DbusmenuStatus dbusmenu_status_get_value_from_nick (const gchar * nick) G_GNUC_CONST; +/** + DBUSMENU_TYPE_STATUS: + + Gets the #GType value for the type associated with the + #DbusmenuStatus enumerated type. +*/ +#define DBUSMENU_TYPE_STATUS (dbusmenu_status_get_type()) + + +G_END_DECLS + +#endif /* __DBUSMENU_ENUM_TYPES_H__ */ + +/* Generated data ends here */ + diff --git a/libdbusmenu-glib/enum-types.h.in b/libdbusmenu-glib/enum-types.h.in new file mode 100644 index 0000000..488b615 --- /dev/null +++ b/libdbusmenu-glib/enum-types.h.in @@ -0,0 +1,62 @@ +/*** BEGIN file-header ***/ +/* +Enums from the dbusmenu headers + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the + Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by + the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#ifndef __DBUSMENU_ENUM_TYPES_H__ +#define __DBUSMENU_ENUM_TYPES_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +/*** END file-header ***/ + +/*** BEGIN file-tail ***/ + +G_END_DECLS + +#endif /* __DBUSMENU_ENUM_TYPES_H__ */ +/*** END file-tail ***/ + +/*** BEGIN file-production ***/ +/* Enumerations from file: "@filename@" */ +#include "@filename@" +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType @enum_name@_get_type (void) G_GNUC_CONST; +const gchar * @enum_name@_get_nick (@EnumName@ value) G_GNUC_CONST; +@EnumName@ @enum_name@_get_value_from_nick (const gchar * nick) G_GNUC_CONST; +/** + DBUSMENU_TYPE_@ENUMSHORT@: + + Gets the #GType value for the type associated with the + #@EnumName@ enumerated type. +*/ +#define DBUSMENU_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) + +/*** END value-header ***/ diff --git a/libdbusmenu-glib/menuitem-marshal.c b/libdbusmenu-glib/menuitem-marshal.c index bb2b6d7..de227fd 100644 --- a/libdbusmenu-glib/menuitem-marshal.c +++ b/libdbusmenu-glib/menuitem-marshal.c @@ -168,3 +168,46 @@ _dbusmenu_menuitem_marshal_VOID__OBJECT_UINT (GClosure *closure, /* VOID:UINT (./menuitem-marshal.list:6) */ +/* BOOLEAN:STRING,VARIANT,UINT (./menuitem-marshal.list:7) */ +void +_dbusmenu_menuitem_marshal_BOOLEAN__STRING_VARIANT_UINT (GClosure *closure, + GValue *return_value G_GNUC_UNUSED, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint G_GNUC_UNUSED, + gpointer marshal_data) +{ + typedef gboolean (*GMarshalFunc_BOOLEAN__STRING_VARIANT_UINT) (gpointer data1, + gpointer arg_1, + gpointer arg_2, + guint arg_3, + gpointer data2); + register GMarshalFunc_BOOLEAN__STRING_VARIANT_UINT callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + gboolean v_return; + + g_return_if_fail (return_value != NULL); + g_return_if_fail (n_param_values == 4); + + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } + else + { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GMarshalFunc_BOOLEAN__STRING_VARIANT_UINT) (marshal_data ? marshal_data : cc->callback); + + v_return = callback (data1, + g_marshal_value_peek_string (param_values + 1), + g_marshal_value_peek_variant (param_values + 2), + g_marshal_value_peek_uint (param_values + 3), + data2); + + g_value_set_boolean (return_value, v_return); +} + diff --git a/libdbusmenu-glib/menuitem-marshal.h b/libdbusmenu-glib/menuitem-marshal.h index 0cde7ad..0315ae8 100644 --- a/libdbusmenu-glib/menuitem-marshal.h +++ b/libdbusmenu-glib/menuitem-marshal.h @@ -39,6 +39,14 @@ extern void _dbusmenu_menuitem_marshal_VOID__OBJECT_UINT (GClosure *closure, /* VOID:UINT (./menuitem-marshal.list:6) */ #define _dbusmenu_menuitem_marshal_VOID__UINT g_cclosure_marshal_VOID__UINT +/* BOOLEAN:STRING,VARIANT,UINT (./menuitem-marshal.list:7) */ +extern void _dbusmenu_menuitem_marshal_BOOLEAN__STRING_VARIANT_UINT (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + G_END_DECLS #endif /* ___dbusmenu_menuitem_marshal_MARSHAL_H__ */ diff --git a/libdbusmenu-glib/menuitem-marshal.list b/libdbusmenu-glib/menuitem-marshal.list index e3cb272..4382ed7 100644 --- a/libdbusmenu-glib/menuitem-marshal.list +++ b/libdbusmenu-glib/menuitem-marshal.list @@ -4,3 +4,4 @@ VOID: OBJECT, UINT VOID: OBJECT VOID: VOID VOID: UINT +BOOLEAN: STRING, VARIANT, UINT diff --git a/libdbusmenu-glib/menuitem-private.h b/libdbusmenu-glib/menuitem-private.h index 89319dc..336769d 100644 --- a/libdbusmenu-glib/menuitem-private.h +++ b/libdbusmenu-glib/menuitem-private.h @@ -38,6 +38,7 @@ gboolean dbusmenu_menuitem_realized (DbusmenuMenuitem * mi); void dbusmenu_menuitem_set_realized (DbusmenuMenuitem * mi); GVariant * dbusmenu_menuitem_properties_variant (DbusmenuMenuitem * mi, const gchar ** properties); gboolean dbusmenu_menuitem_property_is_default (DbusmenuMenuitem * mi, const gchar * property); +gboolean dbusmenu_menuitem_exposed (DbusmenuMenuitem * mi); G_END_DECLS diff --git a/libdbusmenu-glib/menuitem-proxy.c b/libdbusmenu-glib/menuitem-proxy.c index 1d97c4c..ae6a334 100644 --- a/libdbusmenu-glib/menuitem-proxy.c +++ b/libdbusmenu-glib/menuitem-proxy.c @@ -325,14 +325,14 @@ remove_menuitem (DbusmenuMenuitemProxy * pmi) } /** - dbusmenu_menuitem_proxy_new: - @mi: The #DbusmenuMenuitem to proxy - - Builds a new #DbusmenuMenuitemProxy object that proxies - all of the values for @mi. - - Return value: A new #DbusmenuMenuitemProxy object. -*/ + * dbusmenu_menuitem_proxy_new: + * @mi: The #DbusmenuMenuitem to proxy + * + * Builds a new #DbusmenuMenuitemProxy object that proxies + * all of the values for @mi. + * + * Return value: A new #DbusmenuMenuitemProxy object. + */ DbusmenuMenuitemProxy * dbusmenu_menuitem_proxy_new (DbusmenuMenuitem * mi) { @@ -344,15 +344,15 @@ dbusmenu_menuitem_proxy_new (DbusmenuMenuitem * mi) } /** - dbusmenu_menuitem_proxy_get_wrapped: - @pmi: #DbusmenuMenuitemProxy to look into - - Accesses the private variable of which #DbusmenuMenuitem - we are doing the proxying for. - - Return value: A #DbusmenuMenuitem object or a #NULL if we - don't have one or there is an error. -*/ + * dbusmenu_menuitem_proxy_get_wrapped: + * @pmi: #DbusmenuMenuitemProxy to look into + * + * Accesses the private variable of which #DbusmenuMenuitem + * we are doing the proxying for. + * + * Return value: (transfer none): A #DbusmenuMenuitem object or a #NULL if we + * don't have one or there is an error. + */ DbusmenuMenuitem * dbusmenu_menuitem_proxy_get_wrapped (DbusmenuMenuitemProxy * pmi) { diff --git a/libdbusmenu-glib/menuitem-proxy.h b/libdbusmenu-glib/menuitem-proxy.h index 2a22efe..ee988d8 100644 --- a/libdbusmenu-glib/menuitem-proxy.h +++ b/libdbusmenu-glib/menuitem-proxy.h @@ -67,8 +67,7 @@ struct _DbusmenuMenuitemProxyClass { }; /** - DbusmeneMenuitemProxy: - @parent: The instance of #DbusmenuMenuitem + DbusmenuMenuitemProxy: Public instance data for a #DbusmenuMenuitemProxy. */ @@ -83,6 +82,17 @@ GType dbusmenu_menuitem_proxy_get_type (void); DbusmenuMenuitemProxy * dbusmenu_menuitem_proxy_new (DbusmenuMenuitem * mi); DbusmenuMenuitem * dbusmenu_menuitem_proxy_get_wrapped (DbusmenuMenuitemProxy * pmi); +/** + * SECTION:menuitem-proxy + * @short_description: A menuitem that proxies from another menuitem + * @stability: Unstable + * @include: libdbusmenu-glib/menuitem-proxy.h + * + * This small object allows for proxying all the properties from a remote + * menuitem to a new object that can be moved around appropriately within + * the new menu structure. + */ + G_END_DECLS #endif diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 54d2540..5202aa1 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -33,6 +33,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "menuitem.h" #include "menuitem-marshal.h" #include "menuitem-private.h" +#include "defaults.h" #ifdef MASSIVEDEBUGGING #define LABEL(x) dbusmenu_menuitem_property_get(DBUSMENU_MENUITEM(x), DBUSMENU_MENUITEM_PROP_LABEL) @@ -59,6 +60,9 @@ struct _DbusmenuMenuitemPrivate GHashTable * properties; gboolean root; gboolean realized; + DbusmenuDefaults * defaults; + gboolean exposed; + DbusmenuMenuitem * parent; }; /* Signals */ @@ -71,6 +75,7 @@ enum { REALIZED, SHOW_TO_USER, ABOUT_TO_SHOW, + EVENT, LAST_SIGNAL }; @@ -95,7 +100,7 @@ static void set_property (GObject * obj, guint id, const GValue * value, GParamS static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec); static void g_value_transform_STRING_BOOLEAN (const GValue * in, GValue * out); static void g_value_transform_STRING_INT (const GValue * in, GValue * out); -static void handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * value, guint timestamp); +static void handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * variant, guint timestamp); static void send_about_to_show (DbusmenuMenuitem * mi, void (*cb) (DbusmenuMenuitem * mi, gpointer user_data), gpointer cb_data); /* GObject stuff */ @@ -244,6 +249,23 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) NULL, NULL, _dbusmenu_menuitem_marshal_VOID__VOID, G_TYPE_BOOLEAN, 0, G_TYPE_NONE); + /** + DbusmenuMenuitem::event: + @arg0: The #DbusmenuMenuitem object. + @arg1: Name of the event + @arg2: Information passed along with the event + @arg3: X11 timestamp of when the event happened + + Emitted when an event is passed through. The event is signalled + after handle_event is called. + */ + signals[EVENT] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_EVENT, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, + G_STRUCT_OFFSET(DbusmenuMenuitemClass, event), + g_signal_accumulator_true_handled, NULL, + _dbusmenu_menuitem_marshal_BOOLEAN__STRING_VARIANT_UINT, + G_TYPE_BOOLEAN, 3, G_TYPE_STRING, G_TYPE_VARIANT, G_TYPE_UINT); g_object_class_install_property (object_class, PROP_ID, g_param_spec_int(PROP_ID_S, "ID for the menu item", @@ -312,6 +334,9 @@ dbusmenu_menuitem_init (DbusmenuMenuitem *self) priv->root = FALSE; priv->realized = FALSE; + + priv->defaults = dbusmenu_defaults_ref_default(); + priv->exposed = FALSE; return; } @@ -328,6 +353,16 @@ dbusmenu_menuitem_dispose (GObject *object) g_list_free(priv->children); priv->children = NULL; + if (priv->defaults != NULL) { + g_object_unref(priv->defaults); + priv->defaults = NULL; + } + + if (priv->parent) { + g_object_remove_weak_pointer(G_OBJECT(priv->parent), (gpointer *)&priv->parent); + priv->parent = NULL; + } + G_OBJECT_CLASS (dbusmenu_menuitem_parent_class)->dispose (object); return; } @@ -425,15 +460,28 @@ send_about_to_show (DbusmenuMenuitem * mi, void (*cb) (DbusmenuMenuitem * mi, gp return; } +/* A helper function to get the type of the menuitem, this might + be a candidate for optimization in the future. */ +static const gchar * +menuitem_get_type (DbusmenuMenuitem * mi) +{ + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + GVariant * currentval = (GVariant *)g_hash_table_lookup(priv->properties, DBUSMENU_MENUITEM_PROP_TYPE); + if (currentval != NULL) { + return g_variant_get_string(currentval, NULL); + } + return NULL; +} + /* Public interface */ /** - dbusmenu_menuitem_new: - - Create a new #DbusmenuMenuitem with all default values. - - Return value: A newly allocated #DbusmenuMenuitem. -*/ + * dbusmenu_menuitem_new: + * + * Create a new #DbusmenuMenuitem with all default values. + * + * Return value: A newly allocated #DbusmenuMenuitem. + */ DbusmenuMenuitem * dbusmenu_menuitem_new (void) { @@ -441,13 +489,13 @@ dbusmenu_menuitem_new (void) } /** - dbusmenu_menuitem_new_with_id: - @id: ID to use for this menuitem - - This creates a blank #DbusmenuMenuitem with a specific ID. - - Return value: A newly allocated #DbusmenuMenuitem. -*/ + * dbusmenu_menuitem_new_with_id: + * @id: ID to use for this menuitem + * + * This creates a blank #DbusmenuMenuitem with a specific ID. + * + * Return value: A newly allocated #DbusmenuMenuitem. + */ DbusmenuMenuitem * dbusmenu_menuitem_new_with_id (gint id) { @@ -457,13 +505,13 @@ dbusmenu_menuitem_new_with_id (gint id) } /** - dbusmenu_menuitem_get_id: - @mi: The #DbusmenuMenuitem to query. - - Gets the unique ID for @mi. - - Return value: The ID of the @mi. -*/ + * dbusmenu_menuitem_get_id: + * @mi: The #DbusmenuMenuitem to query. + * + * Gets the unique ID for @mi. + * + * Return value: The ID of the @mi. + */ gint dbusmenu_menuitem_get_id (DbusmenuMenuitem * mi) { @@ -480,17 +528,17 @@ dbusmenu_menuitem_get_id (DbusmenuMenuitem * mi) } /** - dbusmenu_menuitem_realized: - @mi: #DbusmenuMenuitem to check on - - This function returns whether the menuitem has been realized or - not. This is significant mostly in client implementations that - can use this additional state to see if the second layers of - the implementation have been built yet. - - Return value: Returns whether or not the menu item has been realized - yet or not. -*/ + * dbusmenu_menuitem_realized: + * @mi: #DbusmenuMenuitem to check on + * + * This function returns whether the menuitem has been realized or + * not. This is significant mostly in client implementations that + * can use this additional state to see if the second layers of + * the implementation have been built yet. + * + * Return value: Returns whether or not the menu item has been realized + * yet or not. + */ gboolean dbusmenu_menuitem_realized (DbusmenuMenuitem * mi) { @@ -500,12 +548,12 @@ dbusmenu_menuitem_realized (DbusmenuMenuitem * mi) } /** - dbusmenu_menuitem_set_realized: - @mi: #DbusmenuMenuitem to realize - - Sets the internal variable tracking whether it's been realized and - signals the DbusmenuMenuitem::realized event. -*/ + * dbusmenu_menuitem_set_realized: + * @mi: #DbusmenuMenuitem to realize + * + * Sets the internal variable tracking whether it's been realized and + * signals the DbusmenuMenuitem::realized event. + */ void dbusmenu_menuitem_set_realized (DbusmenuMenuitem * mi) { @@ -520,15 +568,15 @@ dbusmenu_menuitem_set_realized (DbusmenuMenuitem * mi) } /** - dbusmenu_menuitem_get_children: - @mi: The #DbusmenuMenuitem to query. - - Returns simply the list of children that this menu item - has. The list is valid until another child related function - is called, where it might be changed. - - Return value: A #GList of pointers to #DbusmenuMenuitem objects. -*/ + * dbusmenu_menuitem_get_children: + * @mi: The #DbusmenuMenuitem to query. + * + * Returns simply the list of children that this menu item + * has. The list is valid until another child related function + * is called, where it might be changed. + * + * Return value: (transfer none): A #GList of pointers to #DbusmenuMenuitem objects. + */ GList * dbusmenu_menuitem_get_children (DbusmenuMenuitem * mi) { @@ -541,28 +589,29 @@ dbusmenu_menuitem_get_children (DbusmenuMenuitem * mi) /* For all the taken children we need to signal that they were removed */ static void -take_children_signal (gpointer data, gpointer user_data) +take_children_helper (gpointer data, gpointer user_data) { #ifdef MASSIVEDEBUGGING g_debug("Menuitem %d (%s) signalling child removed %d (%s)", ID(user_data), LABEL(user_data), ID(data), LABEL(data)); #endif + dbusmenu_menuitem_unparent(DBUSMENU_MENUITEM(data)); g_signal_emit(G_OBJECT(user_data), signals[CHILD_REMOVED], 0, DBUSMENU_MENUITEM(data), TRUE); return; } /** - dbusmenu_menuitem_take_children: - @mi: The #DbusmenMenuitem to take the children from. - - While the name sounds devious that's exactly what this function - does. It takes the list of children from the @mi and clears the - internal list. The calling function is now in charge of the ref's - on the children it has taken. A lot of responsibility involved - in taking children. - - Return value: (transfer full) (array) (element-type Dbusmenu.Menuitem) - A #GList of pointers to #DbusmenuMenuitem objects. -*/ + * dbusmenu_menuitem_take_children: + * @mi: The #DbusmenMenuitem to take the children from. + * + * While the name sounds devious that's exactly what this function + * does. It takes the list of children from the @mi and clears the + * internal list. The calling function is now in charge of the ref's + * on the children it has taken. A lot of responsibility involved + * in taking children. + * + * Return value: (transfer full) (element-type Dbusmenu.Menuitem): + * A #GList of pointers to #DbusmenuMenuitem objects. + */ GList * dbusmenu_menuitem_take_children (DbusmenuMenuitem * mi) { @@ -571,7 +620,7 @@ dbusmenu_menuitem_take_children (DbusmenuMenuitem * mi) DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); GList * children = priv->children; priv->children = NULL; - g_list_foreach(children, take_children_signal, mi); + g_list_foreach(children, take_children_helper, mi); dbusmenu_menuitem_property_remove(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY); @@ -579,16 +628,16 @@ dbusmenu_menuitem_take_children (DbusmenuMenuitem * mi) } /** - dbusmenu_menuitem_get_position: - @mi: The #DbusmenuMenuitem to find the position of - @parent: The #DbusmenuMenuitem who's children contain @mi - - This function returns the position of the menu item @mi - in the children of @parent. It will return zero if the - menu item can't be found. - - Return value: The position of @mi in the children of @parent. -*/ + * dbusmenu_menuitem_get_position: + * @mi: The #DbusmenuMenuitem to find the position of + * @parent: The #DbusmenuMenuitem who's children contain @mi + * + * This function returns the position of the menu item @mi + * in the children of @parent. It will return zero if the + * menu item can't be found. + * + * Return value: The position of @mi in the children of @parent. + */ guint dbusmenu_menuitem_get_position (DbusmenuMenuitem * mi, DbusmenuMenuitem * parent) { @@ -618,15 +667,15 @@ dbusmenu_menuitem_get_position (DbusmenuMenuitem * mi, DbusmenuMenuitem * parent } /** - dbusmenu_menuitem_get_position_realized: - @mi: The #DbusmenuMenuitem to find the position of - @parent: The #DbusmenuMenuitem who's children contain @mi - - This function is very similar to #dbusmenu_menuitem_get_position - except that it only counts in the children that have been realized. - - Return value: The position of @mi in the realized children of @parent. -*/ + * dbusmenu_menuitem_get_position_realized: + * @mi: The #DbusmenuMenuitem to find the position of + * @parent: The #DbusmenuMenuitem who's children contain @mi + * + * This function is very similar to #dbusmenu_menuitem_get_position + * except that it only counts in the children that have been realized. + * + * Return value: The position of @mi in the realized children of @parent. + */ guint dbusmenu_menuitem_get_position_realized (DbusmenuMenuitem * mi, DbusmenuMenuitem * parent) { @@ -662,15 +711,15 @@ dbusmenu_menuitem_get_position_realized (DbusmenuMenuitem * mi, DbusmenuMenuitem } /** - dbusmenu_menuitem_child_append: - @mi: The #DbusmenuMenuitem which will become a new parent - @child: The #DbusmenMenuitem that will be a child - - This function adds @child to the list of children on @mi at - the end of that list. - - Return value: Whether the child has been added successfully. -*/ + * dbusmenu_menuitem_child_append: + * @mi: The #DbusmenuMenuitem which will become a new parent + * @child: The #DbusmenMenuitem that will be a child + * + * This function adds @child to the list of children on @mi at + * the end of that list. + * + * Return value: Whether the child has been added successfully. + */ gboolean dbusmenu_menuitem_child_append (DbusmenuMenuitem * mi, DbusmenuMenuitem * child) { @@ -680,6 +729,10 @@ dbusmenu_menuitem_child_append (DbusmenuMenuitem * mi, DbusmenuMenuitem * child) DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); g_return_val_if_fail(g_list_find(priv->children, child) == NULL, FALSE); + if (!dbusmenu_menuitem_set_parent(child, mi)) { + return FALSE; + } + if (priv->children == NULL && !dbusmenu_menuitem_property_exist(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY)) { dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY, DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU); } @@ -694,15 +747,15 @@ dbusmenu_menuitem_child_append (DbusmenuMenuitem * mi, DbusmenuMenuitem * child) } /** - dbusmenu_menuitem_child_prepend: - @mi: The #DbusmenuMenuitem which will become a new parent - @child: The #DbusmenMenuitem that will be a child - - This function adds @child to the list of children on @mi at - the beginning of that list. - - Return value: Whether the child has been added successfully. -*/ + * dbusmenu_menuitem_child_prepend: + * @mi: The #DbusmenuMenuitem which will become a new parent + * @child: The #DbusmenMenuitem that will be a child + * + * This function adds @child to the list of children on @mi at + * the beginning of that list. + * + * Return value: Whether the child has been added successfully. + */ gboolean dbusmenu_menuitem_child_prepend (DbusmenuMenuitem * mi, DbusmenuMenuitem * child) { @@ -712,6 +765,10 @@ dbusmenu_menuitem_child_prepend (DbusmenuMenuitem * mi, DbusmenuMenuitem * child DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); g_return_val_if_fail(g_list_find(priv->children, child) == NULL, FALSE); + if (!dbusmenu_menuitem_set_parent(child, mi)) { + return FALSE; + } + if (priv->children == NULL && !dbusmenu_menuitem_property_exist(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY)) { dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY, DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU); } @@ -726,24 +783,30 @@ dbusmenu_menuitem_child_prepend (DbusmenuMenuitem * mi, DbusmenuMenuitem * child } /** - dbusmenu_menuitem_child_delete: - @mi: The #DbusmenuMenuitem which has @child as a child - @child: The child #DbusmenuMenuitem that you want to no longer - be a child of @mi. - - This function removes @child from the children list of @mi. It does - not call #g_object_unref on @child. - - Return value: If we were able to delete @child. -*/ + * dbusmenu_menuitem_child_delete: + * @mi: The #DbusmenuMenuitem which has @child as a child + * @child: The child #DbusmenuMenuitem that you want to no longer + * be a child of @mi. + * + * This function removes @child from the children list of @mi. It does + * not call #g_object_unref on @child. + * + * Return value: If we were able to delete @child. + */ gboolean dbusmenu_menuitem_child_delete (DbusmenuMenuitem * mi, DbusmenuMenuitem * child) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE); g_return_val_if_fail(DBUSMENU_IS_MENUITEM(child), FALSE); + if (dbusmenu_menuitem_get_parent(child) != mi) { + g_warning("Trying to remove a child that doesn't believe we're it's parent."); + return FALSE; + } + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); priv->children = g_list_remove(priv->children, child); + dbusmenu_menuitem_unparent(child); #ifdef MASSIVEDEBUGGING g_debug("Menuitem %d (%s) signalling child removed %d (%s)", ID(mi), LABEL(mi), ID(child), LABEL(child)); #endif @@ -758,17 +821,17 @@ dbusmenu_menuitem_child_delete (DbusmenuMenuitem * mi, DbusmenuMenuitem * child) } /** - dbusmenu_menuitem_child_add_position: - @mi: The #DbusmenuMenuitem that we're adding the child @child to. - @child: The #DbusmenuMenuitem to make a child of @mi. - @position: Where in @mi object's list of chidren @child should be placed. - - Puts @child in the list of children for @mi at the location - specified in @position. If there is not enough entires available - then @child will be placed at the end of the list. - - Return value: Whether @child was added successfully. -*/ + * dbusmenu_menuitem_child_add_position: + * @mi: The #DbusmenuMenuitem that we're adding the child @child to. + * @child: The #DbusmenuMenuitem to make a child of @mi. + * @position: Where in @mi object's list of chidren @child should be placed. + * + * Puts @child in the list of children for @mi at the location + * specified in @position. If there is not enough entires available + * then @child will be placed at the end of the list. + * + * Return value: Whether @child was added successfully. + */ gboolean dbusmenu_menuitem_child_add_position (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint position) { @@ -778,6 +841,10 @@ dbusmenu_menuitem_child_add_position (DbusmenuMenuitem * mi, DbusmenuMenuitem * DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); g_return_val_if_fail(g_list_find(priv->children, child) == NULL, FALSE); + if (!dbusmenu_menuitem_set_parent(child, mi)) { + return FALSE; + } + if (priv->children == NULL && !dbusmenu_menuitem_property_exist(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY)) { dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY, DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU); } @@ -792,17 +859,17 @@ dbusmenu_menuitem_child_add_position (DbusmenuMenuitem * mi, DbusmenuMenuitem * } /** - dbusmenu_menuitem_child_reorder: - @base: The #DbusmenuMenuitem that has children needing realignment - @child: The #DbusmenuMenuitem that is a child needing to be moved - @position: The position in the list to place it in - - This function moves a child on the list of children. It is - for a child that is already in the list, but simply needs a - new location. - - Return value: Whether the move was successful. -*/ + * dbusmenu_menuitem_child_reorder: + * @mi: The #DbusmenuMenuitem that has children needing realignment + * @child: The #DbusmenuMenuitem that is a child needing to be moved + * @position: The position in the list to place it in + * + * This function moves a child on the list of children. It is + * for a child that is already in the list, but simply needs a + * new location. + * + * Return value: Whether the move was successful. + */ gboolean dbusmenu_menuitem_child_reorder(DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint position) { @@ -832,16 +899,16 @@ dbusmenu_menuitem_child_reorder(DbusmenuMenuitem * mi, DbusmenuMenuitem * child, } /** - dbusmenu_menuitem_child_find: - @mi: The #DbusmenuMenuitem who's children to look on - @id: The ID of the child that we're looking for. - - Search the children of @mi to find one with the ID of @id. - If it doesn't exist then we return #NULL. - - Return value: The menu item with the ID @id or #NULL if it - can't be found. -*/ + * dbusmenu_menuitem_child_find: + * @mi: The #DbusmenuMenuitem who's children to look on + * @id: The ID of the child that we're looking for. + * + * Search the children of @mi to find one with the ID of @id. + * If it doesn't exist then we return #NULL. + * + * Return value: (transfer none): The menu item with the ID @id or #NULL if it + * can't be found. + */ DbusmenuMenuitem * dbusmenu_menuitem_child_find (DbusmenuMenuitem * mi, gint id) { @@ -885,18 +952,18 @@ find_id_helper (gpointer in_mi, gpointer in_find_id) } /** - dbusmenu_menuitem_find_id: - @mi: #DbusmenuMenuitem at the top of the tree to search - @id: ID of the #DbusmenuMenuitem to search for - - This function searchs the whole tree of children that - are attached to @mi. This could be quite a few nodes, all - the way down the tree. It is a depth first search. - - Return value: The #DbusmenuMenuitem with the ID of @id - or #NULL if there isn't such a menu item in the tree - represented by @mi. -*/ + * dbusmenu_menuitem_find_id: + * @mi: #DbusmenuMenuitem at the top of the tree to search + * @id: ID of the #DbusmenuMenuitem to search for + * + * This function searchs the whole tree of children that + * are attached to @mi. This could be quite a few nodes, all + * the way down the tree. It is a depth first search. + * + * Return value: (transfer none): The #DbusmenuMenuitem with the ID of @id + * or #NULL if there isn't such a menu item in the tree + * represented by @mi. + */ DbusmenuMenuitem * dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, gint id) { @@ -913,20 +980,98 @@ dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, gint id) } /** - dbusmenu_menuitem_property_set: - @mi: The #DbusmenuMenuitem to set the property on. - @property: Name of the property to set. - @value: The value of the property. - - Takes the pair of @property and @value and places them as a - property on @mi. If a property already exists by that name, - then the value is set to the new value. If not, the property - is added. If the value is changed or the property was previously - unset then the signal #DbusmenuMenuitem::prop-changed will be - emitted by this function. - - Return value: A boolean representing if the property value was set. -*/ + * dbusmenu_menuitem_set_parent: + * @mi: The #DbusmenuMenuitem for which to set the parent + * @parent: The new parent #DbusmenuMenuitem + * + * Sets the parent of @mi to @parent. If @mi already + * has a parent, then this call will fail. The parent will + * be set automatically when using the usual methods to add a + * child menuitem, so this function should not normally be + * called directly + * + * Return value: Whether the parent was set successfully + */ +gboolean +dbusmenu_menuitem_set_parent (DbusmenuMenuitem * mi, DbusmenuMenuitem * parent) +{ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE); + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE); + + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + + if (priv->parent != NULL) { + g_warning ("Menu item already has a parent"); + return FALSE; + } + + priv->parent = parent; + g_object_add_weak_pointer(G_OBJECT(priv->parent), (gpointer *)&priv->parent); + + return TRUE; +} + +/** + * dbusmenu_menuitem_unparent: + * @mi: The #DbusmenuMenuitem to unparent + * + * Unparents the menu item @mi. If @mi doesn't have a + * parent, then this call will fail. The menuitem will + * be unparented automatically when using the usual methods + * to delete a child menuitem, so this function should not + * normally be called directly + * + * Return value: Whether the menu item was unparented successfully + */ +gboolean +dbusmenu_menuitem_unparent (DbusmenuMenuitem * mi) +{ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE); + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + + if (priv->parent == NULL) { + g_warning("Menu item doesn't have a parent"); + return FALSE; + } + + g_object_remove_weak_pointer(G_OBJECT(priv->parent), (gpointer *)&priv->parent); + priv->parent = NULL; + + return TRUE; +} + +/** + * dbusmenu_menuitem_get_parent: + * @mi: The #DbusmenuMenuitem for which to inspect the parent + * + * This function looks up the parent of @mi + * + * Return value: (transfer none): The parent of this menu item + */ +DbusmenuMenuitem * +dbusmenu_menuitem_get_parent (DbusmenuMenuitem * mi) +{ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL); + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + + return priv->parent; +} + +/** + * dbusmenu_menuitem_property_set: + * @mi: The #DbusmenuMenuitem to set the property on. + * @property: Name of the property to set. + * @value: The value of the property. + * + * Takes the pair of @property and @value and places them as a + * property on @mi. If a property already exists by that name, + * then the value is set to the new value. If not, the property + * is added. If the value is changed or the property was previously + * unset then the signal #DbusmenuMenuitem::prop-changed will be + * emitted by this function. + * + * Return value: A boolean representing if the property value was set. + */ gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, const gchar * value) { @@ -938,20 +1083,20 @@ dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, c } /** - dbusmenu_menuitem_property_set_bool: - @mi: The #DbusmenuMenuitem to set the property on. - @property: Name of the property to set. - @value: The value of the property. - - Takes a boolean @value and sets it on @property as a - property on @mi. If a property already exists by that name, - then the value is set to the new value. If not, the property - is added. If the value is changed or the property was previously - unset then the signal #DbusmenuMenuitem::prop-changed will be - emitted by this function. - - Return value: A boolean representing if the property value was set. -*/ + * dbusmenu_menuitem_property_set_bool: + * @mi: The #DbusmenuMenuitem to set the property on. + * @property: Name of the property to set. + * @value: The value of the property. + * + * Takes a boolean @value and sets it on @property as a + * property on @mi. If a property already exists by that name, + * then the value is set to the new value. If not, the property + * is added. If the value is changed or the property was previously + * unset then the signal #DbusmenuMenuitem::prop-changed will be + * emitted by this function. + * + * Return value: A boolean representing if the property value was set. + */ gboolean dbusmenu_menuitem_property_set_bool (DbusmenuMenuitem * mi, const gchar * property, const gboolean value) { @@ -960,20 +1105,20 @@ dbusmenu_menuitem_property_set_bool (DbusmenuMenuitem * mi, const gchar * proper } /** - dbusmenu_menuitem_property_set_int: - @mi: The #DbusmenuMenuitem to set the property on. - @property: Name of the property to set. - @value: The value of the property. - - Takes a boolean @value and sets it on @property as a - property on @mi. If a property already exists by that name, - then the value is set to the new value. If not, the property - is added. If the value is changed or the property was previously - unset then the signal #DbusmenuMenuitem::prop-changed will be - emitted by this function. - - Return value: A boolean representing if the property value was set. -*/ + * dbusmenu_menuitem_property_set_int: + * @mi: The #DbusmenuMenuitem to set the property on. + * @property: Name of the property to set. + * @value: The value of the property. + * + * Takes a boolean @value and sets it on @property as a + * property on @mi. If a property already exists by that name, + * then the value is set to the new value. If not, the property + * is added. If the value is changed or the property was previously + * unset then the signal #DbusmenuMenuitem::prop-changed will be + * emitted by this function. + * + * Return value: A boolean representing if the property value was set. + */ gboolean dbusmenu_menuitem_property_set_int (DbusmenuMenuitem * mi, const gchar * property, const gint value) { @@ -982,20 +1127,20 @@ dbusmenu_menuitem_property_set_int (DbusmenuMenuitem * mi, const gchar * propert } /** - dbusmenu_menuitem_property_set_variant: - @mi: The #DbusmenuMenuitem to set the property on. - @property: Name of the property to set. - @value: The value of the property. - - Takes the pair of @property and @value and places them as a - property on @mi. If a property already exists by that name, - then the value is set to the new value. If not, the property - is added. If the value is changed or the property was previously - unset then the signal #DbusmenuMenuitem::prop-changed will be - emitted by this function. - - Return value: A boolean representing if the property value was set. -*/ + * dbusmenu_menuitem_property_set_variant: + * @mi: The #DbusmenuMenuitem to set the property on. + * @property: Name of the property to set. + * @value: The value of the property. + * + * Takes the pair of @property and @value and places them as a + * property on @mi. If a property already exists by that name, + * then the value is set to the new value. If not, the property + * is added. If the value is changed or the property was previously + * unset then the signal #DbusmenuMenuitem::prop-changed will be + * emitted by this function. + * + * Return value: A boolean representing if the property value was set. + */ gboolean dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * property, GVariant * value) { @@ -1003,18 +1148,53 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro g_return_val_if_fail(property != NULL, FALSE); DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + GVariant * default_value = NULL; + + if (value != NULL) { + const gchar * type = menuitem_get_type(mi); + + /* Check the expected type to see if we want to have a warning */ + GVariantType * default_type = dbusmenu_defaults_default_get_type(priv->defaults, type, property); + if (default_type != NULL) { + /* If we have an expected type we should check to see if + the value we've been given is of the same type and generate + a warning if it isn't */ + if (!g_variant_is_of_type(value, default_type)) { + g_warning("Setting menuitem property '%s' with value of type '%s' when expecting '%s'", property, g_variant_get_type_string(value), g_variant_type_peek_string(default_type)); + } + } + + /* Check the defaults database to see if we have a default + for this property. */ + default_value = dbusmenu_defaults_default_get(priv->defaults, type, property); + if (default_value != NULL) { + /* Now see if we're setting this to the same value as the + default. If we are then we just want to swallow this variant + and make the function behave like we're clearing it. */ + if (g_variant_equal(default_value, value)) { + g_variant_ref_sink(value); + g_variant_unref(value); + value = NULL; + } + } + } gboolean replaced = FALSE; gpointer currentval = g_hash_table_lookup(priv->properties, property); if (value != NULL) { - gchar * lprop = g_strdup(property); - g_variant_ref_sink(value); - + /* NOTE: We're only marking this as replaced if this is true + but we're actually replacing it no matter. This is so that + the variant passed in sticks around which the caller may + expect. They shouldn't, but it's low cost to remove bugs. */ if (currentval == NULL || !g_variant_equal((GVariant*)currentval, value)) { - g_hash_table_replace(priv->properties, lprop, value); replaced = TRUE; } + + gchar * lprop = g_strdup(property); + g_variant_ref_sink(value); + + g_hash_table_replace(priv->properties, lprop, value); } else { if (currentval != NULL) { g_hash_table_remove(priv->properties, property); @@ -1027,25 +1207,33 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro table. But the fact that there was a value is the imporant part. */ if (currentval == NULL || replaced) { - g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, property, value, TRUE); + GVariant * signalval = value; + + if (signalval == NULL) { + /* Might also be NULL, but if it is we're definitely + clearing this thing. */ + signalval = default_value; + } + + g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, property, signalval, TRUE); } return TRUE; } /** - dbusmenu_menuitem_property_get: - @mi: The #DbusmenuMenuitem to look for the property on. - @property: The property to grab. - - Look up a property on @mi and return the value of it if - it exits. #NULL will be returned if the property doesn't - exist. - - Return value: A string with the value of the property - that shouldn't be free'd. Or #NULL if the property - is not set or is not a string. -*/ + * dbusmenu_menuitem_property_get: + * @mi: The #DbusmenuMenuitem to look for the property on. + * @property: The property to grab. + * + * Look up a property on @mi and return the value of it if + * it exits. #NULL will be returned if the property doesn't + * exist. + * + * Return value: (transfer none): A string with the value of the property + * that shouldn't be free'd. Or #NULL if the property + * is not set or is not a string. + */ const gchar * dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property) { @@ -1056,16 +1244,16 @@ dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property) } /** - dbusmenu_menuitem_property_get_variant: - @mi: The #DbusmenuMenuitem to look for the property on. - @property: The property to grab. - - Look up a property on @mi and return the value of it if - it exits. #NULL will be returned if the property doesn't - exist. - - Return value: A GVariant for the property. -*/ + * dbusmenu_menuitem_property_get_variant: + * @mi: The #DbusmenuMenuitem to look for the property on. + * @property: The property to grab. + * + * Look up a property on @mi and return the value of it if + * it exits. #NULL will be returned if the property doesn't + * exist. + * + * Return value: (transfer none): A GVariant for the property. + */ GVariant * dbusmenu_menuitem_property_get_variant (DbusmenuMenuitem * mi, const gchar * property) { @@ -1074,19 +1262,25 @@ dbusmenu_menuitem_property_get_variant (DbusmenuMenuitem * mi, const gchar * pro DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); - return (GVariant *)g_hash_table_lookup(priv->properties, property); -} + GVariant * currentval = (GVariant *)g_hash_table_lookup(priv->properties, property); -/** - dbusmenu_menuitem_property_get_bool: - @mi: The #DbusmenuMenuitem to look for the property on. - @property: The property to grab. + if (currentval == NULL) { + currentval = dbusmenu_defaults_default_get(priv->defaults, menuitem_get_type(mi), property); + } - Look up a property on @mi and return the value of it if - it exits. Returns #FALSE if the property doesn't exist. + return currentval; +} - Return value: The value of the property or #FALSE. -*/ +/** + * dbusmenu_menuitem_property_get_bool: + * @mi: The #DbusmenuMenuitem to look for the property on. + * @property: The property to grab. + * + * Look up a property on @mi and return the value of it if + * it exits. Returns #FALSE if the property doesn't exist. + * + * Return value: The value of the property or #FALSE. + */ gboolean dbusmenu_menuitem_property_get_bool (DbusmenuMenuitem * mi, const gchar * property) { @@ -1112,15 +1306,15 @@ dbusmenu_menuitem_property_get_bool (DbusmenuMenuitem * mi, const gchar * proper } /** - dbusmenu_menuitem_property_get_int: - @mi: The #DbusmenuMenuitem to look for the property on. - @property: The property to grab. - - Look up a property on @mi and return the value of it if - it exits. Returns zero if the property doesn't exist. - - Return value: The value of the property or zero. -*/ + * dbusmenu_menuitem_property_get_int: + * @mi: The #DbusmenuMenuitem to look for the property on. + * @property: The property to grab. + * + * Look up a property on @mi and return the value of it if + * it exits. Returns zero if the property doesn't exist. + * + * Return value: The value of the property or zero. + */ gint dbusmenu_menuitem_property_get_int (DbusmenuMenuitem * mi, const gchar * property) { @@ -1142,15 +1336,15 @@ dbusmenu_menuitem_property_get_int (DbusmenuMenuitem * mi, const gchar * propert /** - dbusmenu_menuitem_property_exit: - @mi: The #DbusmenuMenuitem to look for the property on. - @property: The property to look for. - - Checkes to see if a particular property exists on @mi and - returns #TRUE if so. - - Return value: A boolean checking to see if the property is available -*/ + * dbusmenu_menuitem_property_exist: + * @mi: The #DbusmenuMenuitem to look for the property on. + * @property: The property to look for. + * + * Checkes to see if a particular property exists on @mi and + * returns #TRUE if so. + * + * Return value: A boolean checking to see if the property is available + */ gboolean dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property) { @@ -1165,12 +1359,12 @@ dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property) } /** - dbusmenu_menuitem_property_remove: - @mi: The #DbusmenuMenuitem to remove the property on. - @property: The property to look for. - - Removes a property from the menuitem. -*/ + * dbusmenu_menuitem_property_remove: + * @mi: The #DbusmenuMenuitem to remove the property on. + * @property: The property to look for. + * + * Removes a property from the menuitem. + */ void dbusmenu_menuitem_property_remove (DbusmenuMenuitem * mi, const gchar * property) { @@ -1185,15 +1379,16 @@ dbusmenu_menuitem_property_remove (DbusmenuMenuitem * mi, const gchar * property } /** - dbusmenu_menuitem_properties_list: - @mi: #DbusmenuMenuitem to list the properties on - - This functiong gets a list of the names of all the properties - that are set on this menu item. This data on the list is owned - by the menuitem but the list is not and should be freed using - g_list_free() when the calling function is done with it. - - Return value: A list of strings or NULL if there are none. + * dbusmenu_menuitem_properties_list: + * @mi: #DbusmenuMenuitem to list the properties on + * + * This functiong gets a list of the names of all the properties + * that are set on this menu item. This data on the list is owned + * by the menuitem but the list is not and should be freed using + * g_list_free() when the calling function is done with it. + * + * Return value: (transfer container): A list of strings or NULL if there are + * none. */ GList * dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi) @@ -1219,18 +1414,18 @@ copy_helper (gpointer in_key, gpointer in_value, gpointer in_data) } /** - dbusmenu_menuitem_properties_copy: - @mi: #DbusmenuMenuitem that we're interested in the properties of - - This function takes the properties of a #DbusmenuMenuitem - and puts them into a #GHashTable that is referenced by the - key of a string and has the value of a string. The hash - table may not have any entries if there aren't any or there - is an error in processing. It is the caller's responsibility - to destroy the created #GHashTable. - - Return value: A brand new #GHashTable that contains all of the - properties that are on this #DbusmenuMenuitem @mi. + * dbusmenu_menuitem_properties_copy: + * @mi: #DbusmenuMenuitem that we're interested in the properties of + * + * This function takes the properties of a #DbusmenuMenuitem + * and puts them into a #GHashTable that is referenced by the + * key of a string and has the value of a string. The hash + * table may not have any entries if there aren't any or there + * is an error in processing. It is the caller's responsibility + * to destroy the created #GHashTable. + * + * Return value: (transfer full): A brand new #GHashTable that contains all of + * theroperties that are on this #DbusmenuMenuitem @mi. */ GHashTable * dbusmenu_menuitem_properties_copy (DbusmenuMenuitem * mi) @@ -1257,14 +1452,14 @@ variant_helper (gpointer in_key, gpointer in_value, gpointer user_data) } /** - dbusmenu_menuitem_properties_variant: - @mi: #DbusmenuMenuitem to get properties from - - Grabs the properties of the menuitem as a GVariant with the - type "a{sv}". - - Return Value: A GVariant of type "a{sv}" or NULL on error. -*/ + * dbusmenu_menuitem_properties_variant: + * @mi: #DbusmenuMenuitem to get properties from + * + * Grabs the properties of the menuitem as a GVariant with the + * type "a{sv}". + * + * Return Value: (transfer full): A GVariant of type "a{sv}" or NULL on error. + */ GVariant * dbusmenu_menuitem_properties_variant (DbusmenuMenuitem * mi, const gchar ** properties) { @@ -1274,7 +1469,7 @@ dbusmenu_menuitem_properties_variant (DbusmenuMenuitem * mi, const gchar ** prop GVariant * final_variant = NULL; - if (g_hash_table_size(priv->properties) > 0) { + if ((properties == NULL || properties[0] == NULL) && g_hash_table_size(priv->properties) > 0) { GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); @@ -1283,19 +1478,46 @@ dbusmenu_menuitem_properties_variant (DbusmenuMenuitem * mi, const gchar ** prop final_variant = g_variant_builder_end(&builder); } + if (properties != NULL) { + GVariantBuilder builder; + gboolean builder_init = FALSE; + int i = 0; const gchar * prop; + + for (prop = properties[i]; prop != NULL; prop = properties[++i]) { + GVariant * propvalue = dbusmenu_menuitem_property_get_variant(mi, prop); + + if (propvalue == NULL) { + continue; + } + + if (!builder_init) { + builder_init = TRUE; + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); + } + + GVariant * dict = g_variant_new_dict_entry(g_variant_new_string((gchar *)prop), + g_variant_new_variant((GVariant *)propvalue)); + g_variant_builder_add_value(&builder, dict); + } + + if (builder_init) { + final_variant = g_variant_builder_end(&builder); + } + } + return final_variant; } /** - dbusmenu_menuitem_set_root: - @mi: #DbusmenuMenuitem to set whether it's root - @root: Whether @mi is a root node or not - - This function sets the internal value of whether this is a - root node or not. - - Return value: None -*/ + * dbusmenu_menuitem_set_root: + * @mi: #DbusmenuMenuitem to set whether it's root + * @root: Whether @mi is a root node or not + * + * This function sets the internal value of whether this is a + * root node or not. + * + * Return value: None + */ void dbusmenu_menuitem_set_root (DbusmenuMenuitem * mi, gboolean root) { @@ -1306,14 +1528,14 @@ dbusmenu_menuitem_set_root (DbusmenuMenuitem * mi, gboolean root) } /** - dbusmenu_menuitem_get_root: - @mi: #DbusmenuMenuitem to see whether it's root - - This function returns the internal value of whether this is a - root node or not. - - Return value: #TRUE if this is a root node -*/ + * dbusmenu_menuitem_get_root: + * @mi: #DbusmenuMenuitem to see whether it's root + * + * This function returns the internal value of whether this is a + * root node or not. + * + * Return value: #TRUE if this is a root node + */ gboolean dbusmenu_menuitem_get_root (DbusmenuMenuitem * mi) { @@ -1324,20 +1546,24 @@ dbusmenu_menuitem_get_root (DbusmenuMenuitem * mi) /** - dbusmenu_menuitem_buildvariant: - @mi: #DbusmenuMenuitem to represent in XML - @array: (element-type utf8): A list of string that will be turned into an XML file - - This function will add strings to the array @array. It will put - at least one entry if this menu item has no children. If it has - children it will put two for this entry, one representing the - start tag and one that is a closing tag. It will allow it's - children to place their own tags in the array in between those two. + * dbusmenu_menuitem_buildvariant: + * @mi: #DbusmenuMenuitem to represent in a variant + * @properties: (element-type utf8): A list of string that will be put into + * a variant + * + * This function will put at least one entry if this menu item has no children. + * If it has children it will put two for this entry, one representing the + * start tag and one that is a closing tag. It will allow it's + * children to place their own tags in the array in between those two. + * + * Return value: (transfer full): Variant representing @properties */ GVariant * dbusmenu_menuitem_build_variant (DbusmenuMenuitem * mi, const gchar ** properties, gint recurse) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL); + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + priv->exposed = TRUE; gint id = 0; if (!dbusmenu_menuitem_get_root(mi)) { @@ -1362,7 +1588,7 @@ dbusmenu_menuitem_build_variant (DbusmenuMenuitem * mi, const gchar ** propertie /* Pillage the children */ GList * children = dbusmenu_menuitem_get_children(mi); - if (children == NULL && recurse != 0) { + if (children == NULL || recurse == 0) { g_variant_builder_add_value(&tupleb, g_variant_new_array(G_VARIANT_TYPE_VARIANT, NULL, 0)); } else { GVariantBuilder childrenbuilder; @@ -1393,15 +1619,15 @@ foreach_helper (gpointer data, gpointer user_data) } /** - dbusmenu_menuitem_foreach: - @mi: The #DbusmenItem to start from - @func: Function to call on every node in the tree - @data: (closure): User data to pass to the function - - This calls the function @func on this menu item and all - of the children of this item. And their children. And - their children. And... you get the point. It will get - called on the whole tree. + * dbusmenu_menuitem_foreach: + * @mi: The #DbusmenItem to start from + * @func: Function to call on every node in the tree + * @data: (closure): User data to pass to the function + * + * This calls the function @func on this menu item and all + * of the children of this item. And their children. And + * their children. And... you get the point. It will get + * called on the whole tree. */ void dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data) @@ -1417,23 +1643,23 @@ dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem } /** - dbusmenu_menuitem_handle_event: - @mi: The #DbusmenuMenuitem to send the signal on. - @name: The name of the signal - @variant: A value that could be set for the event - @timestamp: The timestamp of when the event happened - - This function is called to create an event. It is likely - to be overrided by subclasses. The default menu item - will respond to the activate signal and do: - - Emits the #DbusmenuMenuitem::item-activate signal on this - menu item. Called by server objects when they get the - appropriate DBus signals from the client. - - If you subclass this function you should really think - about calling the parent function unless you have a good - reason not to. + * dbusmenu_menuitem_handle_event: + * @mi: The #DbusmenuMenuitem to send the signal on. + * @name: The name of the signal + * @variant: A value that could be set for the event + * @timestamp: The timestamp of when the event happened + * + * This function is called to create an event. It is likely + * to be overrided by subclasses. The default menu item + * will respond to the activate signal and do: + * + * Emits the #DbusmenuMenuitem::item-activate signal on this + * menu item. Called by server objects when they get the + * appropriate DBus signals from the client. + * + * If you subclass this function you should really think + * about calling the parent function unless you have a good + * reason not to. */ void dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * variant, guint timestamp) @@ -1444,23 +1670,27 @@ dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, GVari #endif DbusmenuMenuitemClass * class = DBUSMENU_MENUITEM_GET_CLASS(mi); - if (class->handle_event != NULL) { + gboolean handled = FALSE; + g_signal_emit(G_OBJECT(mi), signals[EVENT], g_quark_from_string(name), name, variant, timestamp, &handled); + + if (!handled && class->handle_event != NULL) { return class->handle_event(mi, name, variant, timestamp); } + return; } /** - dbusmenu_menuitem_send_about_to_show: - @mi: The #DbusmenuMenuitem to send the signal on. - @cb: Callback to call when the call has returned. - @cb_data: (closure): Data to pass to the callback. - - This function is used to send the even that the submenu - of this item is about to be shown. Callers to this event - should delay showing the menu until their callback is - called if possible. -*/ + * dbusmenu_menuitem_send_about_to_show: + * @mi: The #DbusmenuMenuitem to send the signal on. + * @cb: Callback to call when the call has returned. + * @cb_data: (closure): Data to pass to the callback. + * + * This function is used to send the even that the submenu + * of this item is about to be shown. Callers to this event + * should delay showing the menu until their callback is + * called if possible. + */ void dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem * mi, void (*cb) (DbusmenuMenuitem * mi, gpointer user_data), gpointer cb_data) { @@ -1480,14 +1710,14 @@ dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem * mi, void (*cb) (Dbusmen } /** - dbusmenu_menuitem_show_to_user: - @mi: #DbusmenuMenuitem to show - @timestamp: The time that the user requested it to be shown - - Signals that this menu item should be shown to the user. If this is - server side the server will then take it and send it over the - bus. -*/ + * dbusmenu_menuitem_show_to_user: + * @mi: #DbusmenuMenuitem to show + * @timestamp: The time that the user requested it to be shown + * + * Signals that this menu item should be shown to the user. If this is + * server side the server will then take it and send it over the + * bus. + */ void dbusmenu_menuitem_show_to_user (DbusmenuMenuitem * mi, guint timestamp) { @@ -1500,10 +1730,33 @@ dbusmenu_menuitem_show_to_user (DbusmenuMenuitem * mi, guint timestamp) /* Checks to see if the value of this property is unique or just the default value. */ -/* TODO: Implement this */ gboolean dbusmenu_menuitem_property_is_default (DbusmenuMenuitem * mi, const gchar * property) { - /* No defaults system yet */ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE); + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + + GVariant * currentval = (GVariant *)g_hash_table_lookup(priv->properties, property); + if (currentval != NULL) { + /* If we're storing it locally, then it shouldn't be a default */ + return FALSE; + } + + currentval = dbusmenu_defaults_default_get(priv->defaults, menuitem_get_type(mi), property); + if (currentval != NULL) { + return TRUE; + } + + g_warn_if_reached(); return FALSE; } + +/* Check to see if this menu item has been sent into the bus yet or + not. If no one cares we can give less info */ +gboolean +dbusmenu_menuitem_exposed (DbusmenuMenuitem * mi) +{ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE); + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + return priv->exposed; +} diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index c36e0e9..f4eb989 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -42,47 +42,237 @@ G_BEGIN_DECLS #define DBUSMENU_MENUITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_MENUITEM, DbusmenuMenuitemClass)) +/** + * DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED: + * + * String to attach to signal #DbusmenuServer::property-changed + */ #define DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED "property-changed" +/** + * DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED: + * + * String to attach to signal #DbusmenuServer::item-activated + */ #define DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED "item-activated" +/** + * DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED: + * + * String to attach to signal #DbusmenuServer::child-added + */ #define DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED "child-added" +/** + * DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED: + * + * String to attach to signal #DbusmenuServer::child-removed + */ #define DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED "child-removed" +/** + * DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED: + * + * String to attach to signal #DbusmenuServer::child-moved + */ #define DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED "child-moved" +/** + * DBUSMENU_MENUITEM_SIGNAL_REALIZED: + * + * String to attach to signal #DbusmenuServer::realized + */ #define DBUSMENU_MENUITEM_SIGNAL_REALIZED "realized" +/** + * DBUSMENU_MENUITEM_SIGNAL_REALIZED_ID: + * + * ID to attach to signal #DbusmenuServer::realized + */ #define DBUSMENU_MENUITEM_SIGNAL_REALIZED_ID (g_signal_lookup(DBUSMENU_MENUITEM_SIGNAL_REALIZED, DBUSMENU_TYPE_MENUITEM)) +/** + * DBUSMENU_MENUITEM_SIGNAL_SHOW_TO_USER: + * + * String to attach to signal #DbusmenuServer::show-to-user + */ #define DBUSMENU_MENUITEM_SIGNAL_SHOW_TO_USER "show-to-user" +/** + * DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW: + * + * String to attach to signal #DbusmenuServer::about-to-show + */ #define DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW "about-to-show" +/** + * DBUSMENU_MENUITEM_SIGNAL_EVENT: + * + * String to attach to signal #DbusmenuServer::event + */ +#define DBUSMENU_MENUITEM_SIGNAL_EVENT "event" +/** + * DBUSMENU_MENUITEM_PROP_TYPE: + * + * #DbusmenuMenuitem property used to represent what type of menuitem + * this object represents. Type: #G_VARIANT_TYPE_STRING. + */ #define DBUSMENU_MENUITEM_PROP_TYPE "type" +/** + * DBUSMENU_MENUITEM_PROP_VISIBLE: + * + * #DbusmenuMenuitem property used to represent whether the menuitem + * should be shown or not. Type: #G_VARIANT_TYPE_BOOLEAN. + */ #define DBUSMENU_MENUITEM_PROP_VISIBLE "visible" +/** + * DBUSMENU_MENUITEM_PROP_ENABLED: + * + * #DbusmenuMenuitem property used to represent whether the menuitem + * is clickable or not. Type: #G_VARIANT_TYPE_BOOLEAN. + */ #define DBUSMENU_MENUITEM_PROP_ENABLED "enabled" +/** + * DBUSMENU_MENUITEM_PROP_LABEL: + * + * #DbusmenuMenuitem property used for the text on the menu item. + * Type: #G_VARIANT_TYPE_STRING + */ #define DBUSMENU_MENUITEM_PROP_LABEL "label" +/** + * DBUSMENU_MENUITEM_PROP_ICON_NAME: + * + * #DbusmenuMenuitem property that is the name of the icon under the + * Freedesktop.org icon naming spec. Type: #G_VARIANT_TYPE_STRING + */ #define DBUSMENU_MENUITEM_PROP_ICON_NAME "icon-name" +/** + * DBUSMENU_MENUITEM_PROP_ICON_DATA: + * + * #DbusmenuMenuitem property that is the raw data of a custom icon + * used in the application. Type: #G_VARIANT_TYPE_VARIANT + * + * It is recommended that this is not set directly but instead the + * libdbusmenu-gtk library is used with the function dbusmenu_menuitem_property_set_image() + */ #define DBUSMENU_MENUITEM_PROP_ICON_DATA "icon-data" +/** + * DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE: + * + * #DbusmenuMenuitem property that says what type of toggle entry should + * be shown in the menu. Should be either #DBUSMENU_MENUITEM_TOGGLE_CHECK + * or #DBUSMENU_MENUITEM_TOGGLE_RADIO. Type: #G_VARIANT_TYPE_STRING + */ #define DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE "toggle-type" +/** + * DBUSMENU_MENUITEM_PROP_TOGGLE_STATE: + * + * #DbusmenuMenuitem property that says what state a toggle entry should + * be shown as the menu. Should be either #DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED + * #DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED or #DBUSMENU_MENUITEM_TOGGLE_STATUE_UNKNOWN. + * Type: #G_VARIANT_TYPE_INT32 + */ #define DBUSMENU_MENUITEM_PROP_TOGGLE_STATE "toggle-state" +/** + * DBUSMENU_MENUITEM_PROP_SHORTCUT: + * + * #DbusmenuMenuitem property that is the entries that represent a shortcut + * to activate the menuitem. It is an array of arrays of strings. + * Type: #G_VARIANT_TYPE_ARRAY + * + * It is recommended that this is not set directly but instead the + * libdbusmenu-gtk library is used with the function dbusmenu_menuitem_property_set_shortcut() + */ #define DBUSMENU_MENUITEM_PROP_SHORTCUT "shortcut" +/** + * DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY: + * + * #DbusmenuMenuitem property that tells how the children of this menuitem + * should be displayed. Most likely this will be unset or of the value + * #DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU. Type: #G_VARIANT_TYPE_STRING + */ #define DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY "children-display" +/** + * DBUSMENU_MENUITEM_TOGGLE_CHECK: + * + * Used to set #DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE to be a standard + * check mark item. + */ #define DBUSMENU_MENUITEM_TOGGLE_CHECK "checkmark" +/** + * DBUSMENU_MENUITEM_TOGGLE_RADIO: + * + * Used to set #DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE to be a standard + * radio item. + */ #define DBUSMENU_MENUITEM_TOGGLE_RADIO "radio" +/** + * DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED: + * + * Used to set #DBUSMENU_MENUITEM_PROP_TOGGLE_STATE so that the menu's + * toggle item is empty. + */ #define DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED 0 +/** + * DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED: + * + * Used to set #DBUSMENU_MENUITEM_PROP_TOGGLE_STATE so that the menu's + * toggle item is filled. + */ #define DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED 1 +/** + * DBUSMENU_MENUITEM_TOGGLE_STATE_UNKNOWN: + * + * Used to set #DBUSMENU_MENUITEM_PROP_TOGGLE_STATE so that the menu's + * toggle item is undecided. + */ #define DBUSMENU_MENUITEM_TOGGLE_STATE_UNKNOWN -1 +/** + * DBUSMENU_MENUITEM_ICON_NAME_BLANK: + * + * Used to set #DBUSMENU_MENUITEM_PROP_TOGGLE_STATE so that the menu's + * toggle item is undecided. + */ #define DBUSMENU_MENUITEM_ICON_NAME_BLANK "blank-icon" +/** + * DBUSMENU_MENUITEM_SHORTCUT_CONTROL: + * + * Used in #DBUSMENU_MENUITEM_PROP_SHORTCUT to represent the + * control key. + */ #define DBUSMENU_MENUITEM_SHORTCUT_CONTROL "Control" +/** + * DBUSMENU_MENUITEM_SHORTCUT_ALT: + * + * Used in #DBUSMENU_MENUITEM_PROP_SHORTCUT to represent the + * alternate key. + */ #define DBUSMENU_MENUITEM_SHORTCUT_ALT "Alt" +/** + * DBUSMENU_MENUITEM_SHORTCUT_SHIFT: + * + * Used in #DBUSMENU_MENUITEM_PROP_SHORTCUT to represent the + * shift key. + */ #define DBUSMENU_MENUITEM_SHORTCUT_SHIFT "Shift" +/** + * DBUSMENU_MENUITEM_SHORTCUT_SUPER: + * + * Used in #DBUSMENU_MENUITEM_PROP_SHORTCUT to represent the + * super key. + */ #define DBUSMENU_MENUITEM_SHORTCUT_SUPER "Super" +/** + * DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU: + * + * Used in #DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY to have the + * subitems displayed as a submenu. + */ #define DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU "submenu" typedef struct _DbusmenuMenuitemPrivate DbusmenuMenuitemPrivate; /** * DbusmenuMenuitem: + * @parent: Parent object + * @priv: Private data * * This is the #GObject based object that represents a menu * item. It gets created the same on both the client and @@ -113,16 +303,18 @@ typedef void (*dbusmenu_menuitem_about_to_show_cb) (DbusmenuMenuitem * mi, gpoin /** * dbusmenu_menuitem_buildvariant_slot_t: * @mi: (in): Menu item that should be built from + * @properties: (allow-none): A list of properties that should be the only ones in the resulting variant structure * * This is the function that is called to represent this menu item * as a variant. Should call it's own children. * - * Return value: (transfer full) A variant representing this item and it's children + * Return value: (transfer full): A variant representing this item and it's children */ typedef GVariant * (*dbusmenu_menuitem_buildvariant_slot_t) (DbusmenuMenuitem * mi, gchar ** properties); /** * DbusmenuMenuitemClass: + * @parent_class: Functions and signals from our parent * @property_changed: Slot for #DbusmenuMenuitem::property-changed. * @item_activated: Slot for #DbusmenuMenuitem::item-activated. * @child_added: Slot for #DbusmenuMenuitem::child-added. @@ -130,17 +322,19 @@ typedef GVariant * (*dbusmenu_menuitem_buildvariant_slot_t) (DbusmenuMenuitem * * @child_moved: Slot for #DbusmenuMenuitem::child-moved. * @realized: Slot for #DbusmenuMenuitem::realized. * @about_to_show: Slot for #DbusmenuMenuitem::about-to-show. - * @buildxml: Virtual function that appends the strings required to represent this menu item in the menu XML file. + * @buildvariant: Virtual function that appends the strings required to represent this menu item in the menu variant. * @handle_event: This function is to override how events are handled by subclasses. Look at #dbusmenu_menuitem_handle_event for lots of good information. * @send_about_to_show: Virtual function that notifies server that the client is about to show a menu. * @show_to_user: Slot for #DbusmenuMenuitem::show-to-user. - * + * @event: Slot for #DbsumenuMenuitem::event. * @reserved1: Reserved for future use. * @reserved2: Reserved for future use. * @reserved3: Reserved for future use. * @reserved4: Reserved for future use. * @reserved5: Reserved for future use. - * @reserved6: Reserved for future use. + * + * Functions and signals that every menuitem should know something + * about. */ typedef struct _DbusmenuMenuitemClass DbusmenuMenuitemClass; struct _DbusmenuMenuitemClass @@ -157,19 +351,20 @@ struct _DbusmenuMenuitemClass /* Virtual functions */ dbusmenu_menuitem_buildvariant_slot_t buildvariant; - void (*handle_event) (DbusmenuMenuitem * mi, const gchar * name, GVariant * value, guint timestamp); + void (*handle_event) (DbusmenuMenuitem * mi, const gchar * name, GVariant * variant, guint timestamp); void (*send_about_to_show) (DbusmenuMenuitem * mi, void (*cb) (DbusmenuMenuitem * mi, gpointer user_data), gpointer cb_data); void (*show_to_user) (DbusmenuMenuitem * mi, guint timestamp, gpointer cb_data); gboolean (*about_to_show) (void); + void (*event) (const gchar * name, GVariant * value, guint timestamp); + /*< Private >*/ void (*reserved1) (void); void (*reserved2) (void); void (*reserved3) (void); void (*reserved4) (void); void (*reserved5) (void); - void (*reserved6) (void); }; GType dbusmenu_menuitem_get_type (void); @@ -191,6 +386,10 @@ gboolean dbusmenu_menuitem_child_reorder (DbusmenuMenuitem * mi, DbusmenuMenuite DbusmenuMenuitem * dbusmenu_menuitem_child_find (DbusmenuMenuitem * mi, gint id); DbusmenuMenuitem * dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, gint id); +gboolean dbusmenu_menuitem_set_parent (DbusmenuMenuitem * mi, DbusmenuMenuitem * parent); +gboolean dbusmenu_menuitem_unparent (DbusmenuMenuitem *mi); +DbusmenuMenuitem * dbusmenu_menuitem_get_parent (DbusmenuMenuitem * mi); + gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, const gchar * value); gboolean dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * property, GVariant * value); gboolean dbusmenu_menuitem_property_set_bool (DbusmenuMenuitem * mi, const gchar * property, const gboolean value); @@ -208,7 +407,7 @@ void dbusmenu_menuitem_set_root (DbusmenuMenuitem * mi, gboolean root); gboolean dbusmenu_menuitem_get_root (DbusmenuMenuitem * mi); void dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data); -void dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * value, guint timestamp); +void dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * variant, guint timestamp); void dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem * mi, void (*cb) (DbusmenuMenuitem * mi, gpointer user_data), gpointer cb_data); void dbusmenu_menuitem_show_to_user (DbusmenuMenuitem * mi, guint timestamp); diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index aa39991..056d6cb 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -30,11 +30,13 @@ License version 3 and version 2.1 along with this program. If not, see #include "config.h" #endif +#include <glib/gi18n.h> #include <gio/gio.h> #include "menuitem-private.h" #include "server.h" #include "server-marshal.h" +#include "enum-types.h" #include "dbus-menu-clean.xml.h" @@ -55,6 +57,9 @@ struct _DbusmenuServerPrivate GCancellable * bus_lookup; guint dbus_registration; + DbusmenuTextDirection text_direction; + DbusmenuStatus status; + GArray * prop_array; guint property_idle; }; @@ -77,7 +82,9 @@ enum { PROP_0, PROP_DBUS_OBJECT, PROP_ROOT_NODE, - PROP_VERSION + PROP_VERSION, + PROP_TEXT_DIRECTION, + PROP_STATUS }; /* Errors */ @@ -124,6 +131,7 @@ static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec); +static void default_text_direction (DbusmenuServer * server); static void register_object (DbusmenuServer * server); static void bus_got_cb (GObject * obj, GAsyncResult * result, @@ -289,6 +297,16 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) "The version of the DBusmenu API that we're implementing.", DBUSMENU_VERSION_NUMBER, DBUSMENU_VERSION_NUMBER, DBUSMENU_VERSION_NUMBER, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, PROP_TEXT_DIRECTION, + g_param_spec_enum(DBUSMENU_SERVER_PROP_TEXT_DIRECTION, "The default direction of text", + "The object that represents this set of menus on DBus", + DBUSMENU_TYPE_TEXT_DIRECTION, DBUSMENU_TEXT_DIRECTION_NONE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, PROP_STATUS, + g_param_spec_enum(DBUSMENU_SERVER_PROP_STATUS, "Status of viewing the menus", + "Exports over DBus whether the menus should be given special visuals", + DBUSMENU_TYPE_STATUS, DBUSMENU_STATUS_NORMAL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); if (dbusmenu_node_info == NULL) { GError * error = NULL; @@ -348,6 +366,9 @@ dbusmenu_server_init (DbusmenuServer *self) priv->bus_lookup = NULL; priv->dbus_registration = 0; + default_text_direction(self); + priv->status = DBUSMENU_STATUS_NORMAL; + return; } @@ -463,6 +484,64 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) } layout_update_signal(DBUSMENU_SERVER(obj)); break; + case PROP_TEXT_DIRECTION: { + DbusmenuTextDirection indir = g_value_get_enum(value); + DbusmenuTextDirection olddir = priv->text_direction; + + /* If being set to none we need to go back to default, otherwise + we'll set things the way that we've been told */ + if (indir == DBUSMENU_TEXT_DIRECTION_NONE) { + default_text_direction(DBUSMENU_SERVER(obj)); + } else { + priv->text_direction = indir; + } + + /* If the value has changed we need to signal that on DBus */ + if (priv->text_direction != olddir && priv->bus != NULL && priv->dbusobject != NULL) { + GVariantBuilder params; + g_variant_builder_init(¶ms, G_VARIANT_TYPE_ARRAY); + g_variant_builder_add_value(¶ms, g_variant_new_string(DBUSMENU_INTERFACE)); + GVariant * dict = g_variant_new_dict_entry(g_variant_new_string("text-direction"), g_variant_new_string(dbusmenu_text_direction_get_nick(priv->text_direction))); + g_variant_builder_add_value(¶ms, g_variant_new_array(NULL, &dict, 1)); + g_variant_builder_add_value(¶ms, g_variant_new_array(G_VARIANT_TYPE_STRING, NULL, 0)); + GVariant * vparams = g_variant_builder_end(¶ms); + + g_dbus_connection_emit_signal(priv->bus, + NULL, + priv->dbusobject, + "org.freedesktop.DBus.Properties", + "PropertiesChanged", + vparams, + NULL); + } + + break; + } + case PROP_STATUS: { + DbusmenuStatus instatus = g_value_get_enum(value); + + /* If the value has changed we need to signal that on DBus */ + if (priv->status != instatus && priv->bus != NULL && priv->dbusobject != NULL) { + GVariantBuilder params; + g_variant_builder_init(¶ms, G_VARIANT_TYPE_ARRAY); + g_variant_builder_add_value(¶ms, g_variant_new_string(DBUSMENU_INTERFACE)); + GVariant * dict = g_variant_new_dict_entry(g_variant_new_string("status"), g_variant_new_string(dbusmenu_status_get_nick(instatus))); + g_variant_builder_add_value(¶ms, g_variant_new_array(NULL, &dict, 1)); + g_variant_builder_add_value(¶ms, g_variant_new_array(G_VARIANT_TYPE_STRING, NULL, 0)); + GVariant * vparams = g_variant_builder_end(¶ms); + + g_dbus_connection_emit_signal(priv->bus, + NULL, + priv->dbusobject, + "org.freedesktop.DBus.Properties", + "PropertiesChanged", + vparams, + NULL); + } + + priv->status = instatus; + break; + } default: g_return_if_reached(); break; @@ -486,6 +565,12 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) case PROP_VERSION: g_value_set_uint(value, DBUSMENU_VERSION_NUMBER); break; + case PROP_TEXT_DIRECTION: + g_value_set_enum(value, priv->text_direction); + break; + case PROP_STATUS: + g_value_set_enum(value, priv->status); + break; default: g_return_if_reached(); break; @@ -494,6 +579,49 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) return; } +/* Determines the default text direction */ +static void +default_text_direction (DbusmenuServer * server) +{ + DbusmenuTextDirection dir = DBUSMENU_TEXT_DIRECTION_NONE; + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + const gchar * env = g_getenv("DBUSMENU_TEXT_DIRECTION"); + if (env != NULL) { + if (g_strcmp0(env, "ltr") == 0) { + dir = DBUSMENU_TEXT_DIRECTION_LTR; + } else if (g_strcmp0(env, "rtl") == 0) { + dir = DBUSMENU_TEXT_DIRECTION_RTL; + } else { + g_warning("Value of 'DBUSMENU_TEXT_DIRECTION' is '%s' which is not one of 'rtl' or 'ltr'", env); + } + } + + if (dir == DBUSMENU_TEXT_DIRECTION_NONE) { + /* TRANSLATORS: This is the direction of the text and can + either be the value 'ltr' for left-to-right text (English) + or 'rtl' for right-to-left (Arabic). */ + const gchar * default_dir = C_("default text direction", "ltr"); + + if (g_strcmp0(default_dir, "ltr") == 0) { + dir = DBUSMENU_TEXT_DIRECTION_LTR; + } else if (g_strcmp0(default_dir, "rtl") == 0) { + dir = DBUSMENU_TEXT_DIRECTION_RTL; + } else { + g_warning("Translation has an invalid value '%s' for default text direction. Defaulting to left-to-right.", default_dir); + dir = DBUSMENU_TEXT_DIRECTION_LTR; + } + } + + /* Shouldn't happen, but incase future patches make a mistake + this'll catch them */ + g_return_if_fail(dir != DBUSMENU_TEXT_DIRECTION_NONE); + + priv->text_direction = dir; + + return; +} + /* Register the object on the dbus bus */ static void register_object (DbusmenuServer * server) @@ -611,9 +739,18 @@ bus_get_prop (GDBusConnection * connection, const gchar * sender, const gchar * /* None of these should happen */ g_return_val_if_fail(g_strcmp0(interface, DBUSMENU_INTERFACE) == 0, NULL); g_return_val_if_fail(g_strcmp0(path, priv->dbusobject) == 0, NULL); - g_return_val_if_fail(g_strcmp0(property, "version") == 0, NULL); - return g_variant_new_uint32(DBUSMENU_VERSION_NUMBER); + if (g_strcmp0(property, "version") == 0) { + return g_variant_new_uint32(DBUSMENU_VERSION_NUMBER); + } else if (g_strcmp0(property, "text-direction") == 0) { + return g_variant_new_string(dbusmenu_text_direction_get_nick(priv->text_direction)); + } else if (g_strcmp0(property, "status") == 0) { + return g_variant_new_string(dbusmenu_status_get_nick(priv->status)); + } else { + g_warning("Unknown property '%s'", property); + } + + return NULL; } /* Handle actually signalling in the idle loop. This way we collect all @@ -656,7 +793,7 @@ layout_update_signal (DbusmenuServer * server) typedef struct _prop_idle_item_t prop_idle_item_t; struct _prop_idle_item_t { - gint id; + DbusmenuMenuitem * mi; GArray * array; }; @@ -686,6 +823,7 @@ prop_array_teardown (GArray * prop_array) } } + g_object_unref(G_OBJECT(iitem->mi)); g_array_free(iitem->array, TRUE); } @@ -719,6 +857,12 @@ menuitem_property_idle (gpointer user_data) for (i = 0; i < priv->prop_array->len; i++) { prop_idle_item_t * iitem = &g_array_index(priv->prop_array, prop_idle_item_t, i); + /* if it's not exposed we're going to block it's properties + from getting into the dbus message */ + if (dbusmenu_menuitem_exposed(iitem->mi) == FALSE) { + continue; + } + GVariantBuilder dictbuilder; gboolean dictinit = FALSE; @@ -756,7 +900,7 @@ menuitem_property_idle (gpointer user_data) GVariantBuilder tuplebuilder; g_variant_builder_init(&tuplebuilder, G_VARIANT_TYPE_TUPLE); - g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(iitem->id)); + g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(dbusmenu_menuitem_get_id(iitem->mi))); g_variant_builder_add_value(&tuplebuilder, g_variant_builder_end(&dictbuilder)); if (!item_init) { @@ -773,7 +917,7 @@ menuitem_property_idle (gpointer user_data) GVariantBuilder tuplebuilder; g_variant_builder_init(&tuplebuilder, G_VARIANT_TYPE_TUPLE); - g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(iitem->id)); + g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(dbusmenu_menuitem_get_id(iitem->mi))); g_variant_builder_add_value(&tuplebuilder, g_variant_builder_end(&removedictbuilder)); if (!removeitem_init) { @@ -786,9 +930,11 @@ menuitem_property_idle (gpointer user_data) } GVariant * megadata[2]; + gboolean gotsomething = FALSE; if (item_init) { megadata[0] = g_variant_builder_end(&itembuilder); + gotsomething = TRUE; } else { GError * error = NULL; megadata[0] = g_variant_parse(G_VARIANT_TYPE("a(ia{sv})"), "[ ]", NULL, NULL, &error); @@ -801,6 +947,7 @@ menuitem_property_idle (gpointer user_data) if (removeitem_init) { megadata[1] = g_variant_builder_end(&removeitembuilder); + gotsomething = TRUE; } else { GError * error = NULL; megadata[1] = g_variant_parse(G_VARIANT_TYPE("a(ia(s))"), "[ ]", NULL, NULL, &error); @@ -811,7 +958,7 @@ menuitem_property_idle (gpointer user_data) } } - if (priv->dbusobject != NULL && priv->bus != NULL) { + if (gotsomething && priv->dbusobject != NULL && priv->bus != NULL) { g_dbus_connection_emit_signal(priv->bus, NULL, priv->dbusobject, @@ -854,7 +1001,7 @@ menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GVariant * v prop_idle_item_t * item = NULL; for (i = 0; i < priv->prop_array->len; i++) { prop_idle_item_t * iitem = &g_array_index(priv->prop_array, prop_idle_item_t, i); - if (iitem->id == item_id) { + if (iitem->mi == mi) { item = iitem; break; } @@ -864,7 +1011,8 @@ menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GVariant * v /* If not, we'll need to build ourselves one */ if (item == NULL) { prop_idle_item_t myitem; - myitem.id = item_id; + myitem.mi = mi; + g_object_ref(G_OBJECT(mi)); myitem.array = g_array_new(FALSE, FALSE, sizeof(prop_idle_prop_t)); g_array_append_val(priv->prop_array, myitem); @@ -892,7 +1040,9 @@ menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GVariant * v /* If so, we need to swap the value */ if (prop != NULL) { - g_variant_unref(prop->variant); + if (prop->variant != NULL) { + g_variant_unref(prop->variant); + } prop->variant = variant; } else { /* else we need to add it */ @@ -1458,5 +1608,97 @@ dbusmenu_server_set_root (DbusmenuServer * self, DbusmenuMenuitem * root) return; } +/** + dbusmenu_server_get_text_direction: + @server: The #DbusmenuServer object to get the text direction from + + Returns the value of the text direction that is being exported + over DBus for this server. It should relate to the direction + of the labels and other text fields that are being exported by + this server. + + Return value: Text direction exported for this server. +*/ +DbusmenuTextDirection +dbusmenu_server_get_text_direction (DbusmenuServer * server) +{ + g_return_val_if_fail(DBUSMENU_IS_SERVER(server), DBUSMENU_TEXT_DIRECTION_NONE); + + GValue val = {0}; + g_value_init(&val, DBUSMENU_TYPE_TEXT_DIRECTION); + g_object_get_property(G_OBJECT(server), DBUSMENU_SERVER_PROP_TEXT_DIRECTION, &val); + + DbusmenuTextDirection retval = g_value_get_enum(&val); + g_value_unset(&val); + return retval; +} + +/** + dbusmenu_server_set_text_direction: + @server: The #DbusmenuServer object to set the text direction on + @dir: Direction of the text + + Sets the text direction that should be exported over DBus for + this server. If the value is set to #DBUSMENU_TEXT_DIRECTION_NONE + the default detection will be used for setting the value and + exported over DBus. +*/ +void +dbusmenu_server_set_text_direction (DbusmenuServer * server, DbusmenuTextDirection dir) +{ + g_return_if_fail(DBUSMENU_IS_SERVER(server)); + g_return_if_fail(dir == DBUSMENU_TEXT_DIRECTION_NONE || dir == DBUSMENU_TEXT_DIRECTION_LTR || dir == DBUSMENU_TEXT_DIRECTION_RTL); + + GValue newval = {0}; + g_value_init(&newval, DBUSMENU_TYPE_TEXT_DIRECTION); + g_value_set_enum(&newval, dir); + g_object_set_property(G_OBJECT(server), DBUSMENU_SERVER_PROP_TEXT_DIRECTION, &newval); + g_value_unset(&newval); + return; +} +/** + dbusmenu_server_get_status: + @server: The #DbusmenuServer to get the status from + + Gets the current statust hat the server is sending out over + DBus. + + Return value: The current status the server is sending +*/ +DbusmenuStatus +dbusmenu_server_get_status (DbusmenuServer * server) +{ + g_return_val_if_fail(DBUSMENU_IS_SERVER(server), DBUSMENU_STATUS_NORMAL); + + GValue val = {0}; + g_value_init(&val, DBUSMENU_TYPE_STATUS); + g_object_get_property(G_OBJECT(server), DBUSMENU_SERVER_PROP_STATUS, &val); + + DbusmenuStatus retval = g_value_get_enum(&val); + g_value_unset(&val); + + return retval; +} + +/** + dbusmenu_server_set_status: + @server: The #DbusmenuServer to set the status on + @status: Status value to set on the server + + Changes the status of the server. +*/ +void +dbusmenu_server_set_status (DbusmenuServer * server, DbusmenuStatus status) +{ + g_return_if_fail(DBUSMENU_IS_SERVER(server)); + + GValue val = {0}; + g_value_init(&val, DBUSMENU_TYPE_STATUS); + g_value_set_enum(&val, status); + g_object_set_property(G_OBJECT(server), DBUSMENU_SERVER_PROP_STATUS, &val); + g_value_unset(&val); + + return; +} diff --git a/libdbusmenu-glib/server.h b/libdbusmenu-glib/server.h index 5668258..80b7abb 100644 --- a/libdbusmenu-glib/server.h +++ b/libdbusmenu-glib/server.h @@ -33,6 +33,7 @@ License version 3 and version 2.1 along with this program. If not, see #include <glib-object.h> #include "menuitem.h" +#include "types.h" G_BEGIN_DECLS @@ -43,15 +44,67 @@ G_BEGIN_DECLS #define DBUSMENU_IS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_SERVER)) #define DBUSMENU_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_SERVER, DbusmenuServerClass)) +/** + * DBUSMENU_SERVER_SIGNAL_ID_PROP_UPDATE: + * + * String to attach to signal #DbusmenuServer::item-property-updated + */ #define DBUSMENU_SERVER_SIGNAL_ID_PROP_UPDATE "item-property-updated" +/** + * DBUSMENU_SERVER_SIGNAL_ID_UPDATE: + * + * String to attach to signal #DbusmenuServer::item-updated + */ #define DBUSMENU_SERVER_SIGNAL_ID_UPDATE "item-updated" +/** + * DBUSMENU_SERVER_SIGNAL_LAYOUT_UPDATED: + * + * String to attach to signal #DbusmenuServer::layout-updated + */ #define DBUSMENU_SERVER_SIGNAL_LAYOUT_UPDATED "layout-updated" +/** + * DBUSMENU_SERVER_SIGNAL_ITEM_ACTIVATION: + * + * String to attach to signal #DbusmenuServer::item-activation-requested + */ #define DBUSMENU_SERVER_SIGNAL_ITEM_ACTIVATION "item-activation-requested" +/** + * DBUSMENU_SERVER_SIGNAL_LAYOUT_UPDATE: + * + * String to attach to signal #DbusmenuServer::layout-updated + */ #define DBUSMENU_SERVER_SIGNAL_LAYOUT_UPDATE DBUSMENU_SERVER_SIGNAL_LAYOUT_UPDATED +/** + * DBUSMENU_SERVER_PROP_DBUS_OBJECT: + * + * String to access property #DbusmenuServer:dbus-object + */ #define DBUSMENU_SERVER_PROP_DBUS_OBJECT "dbus-object" +/** + * DBUSMENU_SERVER_PROP_ROOT_NODE: + * + * String to access property #DbusmenuServer:root-node + */ #define DBUSMENU_SERVER_PROP_ROOT_NODE "root-node" +/** + * DBUSMENU_SERVER_PROP_VERSION: + * + * String to access property #DbusmenuServer:version + */ #define DBUSMENU_SERVER_PROP_VERSION "version" +/** + * DBUSMENU_SERVER_PROP_TEXT_DIRECTION: + * + * String to access property #DbusmenuServer:text-direction + */ +#define DBUSMENU_SERVER_PROP_TEXT_DIRECTION "text-direction" +/** + * DBUSMENU_SERVER_PROP_STATUS: + * + * String to access property #DbusmenuServer:status + */ +#define DBUSMENU_SERVER_PROP_STATUS "status" typedef struct _DbusmenuServerPrivate DbusmenuServerPrivate; @@ -61,8 +114,7 @@ typedef struct _DbusmenuServerPrivate DbusmenuServerPrivate; @id_prop_update: Slot for #DbusmenuServer::id-prop-update. @id_update: Slot for #DbusmenuServer::id-update. @layout_updated: Slot for #DbusmenuServer::layout-update. - @item_activation_requested: Slot for #DbusmenuServer::item-activation-requested. - + @item_activation: Slot for #DbusmenuServer::item-activation-requested. @reserved1: Reserved for future use. @reserved2: Reserved for future use. @reserved3: Reserved for future use. @@ -93,7 +145,6 @@ struct _DbusmenuServerClass { /** DbusmenuServer: - @parent: #GObject A server which represents a sharing of a set of #DbusmenuMenuitems across DBus to a #DbusmenuClient. @@ -106,12 +157,19 @@ struct _DbusmenuServer { DbusmenuServerPrivate * priv; }; -GType dbusmenu_server_get_type (void); -DbusmenuServer * dbusmenu_server_new (const gchar * object); -void dbusmenu_server_set_root (DbusmenuServer * server, DbusmenuMenuitem * root); +GType dbusmenu_server_get_type (void); +DbusmenuServer * dbusmenu_server_new (const gchar * object); +void dbusmenu_server_set_root (DbusmenuServer * self, + DbusmenuMenuitem * root); +DbusmenuTextDirection dbusmenu_server_get_text_direction (DbusmenuServer * server); +void dbusmenu_server_set_text_direction (DbusmenuServer * server, + DbusmenuTextDirection dir); +DbusmenuStatus dbusmenu_server_get_status (DbusmenuServer * server); +void dbusmenu_server_set_status (DbusmenuServer * server, + DbusmenuStatus status); /** - SECIONT:server + SECTION:server @short_description: The server signals changed and updates on a tree of #DbusmenuMenuitem objecs. @stability: Unstable diff --git a/libdbusmenu-glib/types.h b/libdbusmenu-glib/types.h new file mode 100644 index 0000000..03ae801 --- /dev/null +++ b/libdbusmenu-glib/types.h @@ -0,0 +1,76 @@ +/* +Types that are used in several objects. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould <ted@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#ifndef __DBUSMENU_TYPES_H__ +#define __DBUSMENU_TYPES_H__ + +#include <glib.h> + +G_BEGIN_DECLS + +/** + DbusmenuTextDirection: + @DBUSMENU_TEXT_DIRECTION_NONE: Unspecified text direction + @DBUSMENU_TEXT_DIRECTION_LTR: Left-to-right text direction + @DBUSMENU_TEXT_DIRECTION_RTL: Right-to-left text direction + + The direction of text that the strings that this server + will be sending strings as. +*/ +typedef enum { /*< prefix=DBUSMENU_TEXT_DIRECTION >*/ + DBUSMENU_TEXT_DIRECTION_NONE, /*< nick=none >*/ + DBUSMENU_TEXT_DIRECTION_LTR, /*< nick=ltr >*/ + DBUSMENU_TEXT_DIRECTION_RTL /*< nick=rtl >*/ +} DbusmenuTextDirection; + +/** + DbusmenuStatus: + @DBUSMENU_STATUS_NORMAL: Everything is normal + @DBUSMENU_STATUS_NOTICE: The menus should be shown at a higher priority + + Tracks how the menus should be presented to the user. +*/ +typedef enum { /*< prefix=DBUSMENU_STATUS >*/ + DBUSMENU_STATUS_NORMAL, /*< nick=normal >*/ + DBUSMENU_STATUS_NOTICE /*< nick=notice >*/ +} DbusmenuStatus; + +/** + SECTION:types + @short_description: Types that are used by both client and + server. + @stability: Unstable + @include: libdbusmenu-glib/types.h + + Enums that are used to describe states of the server across the + bus. They are sent over dbus using their nicks but then turned + back into enums by the client. +*/ +G_END_DECLS + +#endif /* __DBUSMENU_TYPES_H__ */ + |