Commit 21672a2d authored by Colin Walters's avatar Colin Walters Committed by Vincent Untz

Convert to GObject, drop static Python bindings

GMenuTree is now a GObject.  Drop the static Python bindings, since
introspection gives us coverage of most of the API now.

https://bugzilla.gnome.org/show_bug.cgi?id=647968
parent 0a7e4736
SUBDIRS = libmenu desktop-directories layout util po SUBDIRS = libmenu desktop-directories layout util po
if HAVE_PYTHON SUBDIRS += simple-editor
SUBDIRS += python simple-editor
endif
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
DISTCHECK_CONFIGURE_FLAGS = --enable-introspection --enable-python DISTCHECK_CONFIGURE_FLAGS = --enable-introspection
EXTRA_DIST = \ EXTRA_DIST = \
HACKING \ HACKING \
......
...@@ -72,39 +72,8 @@ else ...@@ -72,39 +72,8 @@ else
fi fi
AC_SUBST(DEBUG_CFLAGS) AC_SUBST(DEBUG_CFLAGS)
AC_ARG_ENABLE(python, AM_PATH_PYTHON(2.3)
[AC_HELP_STRING([--enable-python], AM_CONDITIONAL(HAVE_PYTHON, test x$PYTHON != xyes)
[build python bindings @<:@default=auto@:>@])],
[enable_deprecations=$enableval],
[enable_deprecations=auto])
# Detect if we can build Python bindings (need python and python headers)
if test "x$enable_python" = "xno" ; then
have_python=no
else
AC_MSG_NOTICE([Checking to see if we can build Python bindings])
have_python=no
AM_PATH_PYTHON(2.3)
if test "x$PYTHON" = "x" ; then
AC_MSG_WARN([Python not found])
else
AM_CHECK_PYTHON_HEADERS(have_python_headers=yes, have_python_headers=no)
if test "x$have_python_headers" = "xyes" ; then
have_python=yes
fi
fi
if test "x$have_python" = "xno" ; then
if test "x$enable_python" = "xyes" ; then
AC_MSG_ERROR([Building python explicitly requested, but can't build python bindings])
else
AC_MSG_WARN([Couldn't find the Python headers, not building Python bindings])
fi
fi
fi
AM_CONDITIONAL(HAVE_PYTHON, test x$have_python = xyes)
# Because of the way Python implements polymorphism, we get the following warning: # Because of the way Python implements polymorphism, we get the following warning:
# "warning: dereferencing type-punned pointer will break strict-aliasing rules" # "warning: dereferencing type-punned pointer will break strict-aliasing rules"
...@@ -136,7 +105,6 @@ libmenu/libgnome-menu-uninstalled.pc ...@@ -136,7 +105,6 @@ libmenu/libgnome-menu-uninstalled.pc
layout/Makefile layout/Makefile
desktop-directories/Makefile desktop-directories/Makefile
util/Makefile util/Makefile
python/Makefile
simple-editor/Makefile simple-editor/Makefile
simple-editor/GMenuSimpleEditor/Makefile simple-editor/GMenuSimpleEditor/Makefile
po/Makefile.in po/Makefile.in
...@@ -165,7 +133,6 @@ echo " ...@@ -165,7 +133,6 @@ echo "
Use *_DISABLE_DEPRECATED: ${enable_deprecation_flags} Use *_DISABLE_DEPRECATED: ${enable_deprecation_flags}
Turn on debugging: ${enable_debug} Turn on debugging: ${enable_debug}
Build python bindings: ${have_python}
Build introspection support: ${found_introspection} Build introspection support: ${found_introspection}
" "
...@@ -29,9 +29,24 @@ ...@@ -29,9 +29,24 @@
#include "menu-util.h" #include "menu-util.h"
#include "canonicalize.h" #include "canonicalize.h"
struct GMenuTree enum {
PROP_0,
PROP_NAME,
PROP_FLAGS
};
/* Signals */
enum
{
LAST_SIGNAL
};
static guint gmenu_tree_signals [LAST_SIGNAL] = { 0 };
struct _GMenuTree
{ {
guint refcount; GObject parent_instance;
char *basename; char *basename;
char *canonical_path; char *canonical_path;
...@@ -43,14 +58,11 @@ struct GMenuTree ...@@ -43,14 +58,11 @@ struct GMenuTree
MenuLayoutNode *layout; MenuLayoutNode *layout;
GMenuTreeDirectory *root; GMenuTreeDirectory *root;
GSList *monitors;
gpointer user_data;
GDestroyNotify dnotify;
guint canonical : 1; guint canonical : 1;
}; };
G_DEFINE_TYPE (GMenuTree, gmenu_tree, G_TYPE_OBJECT)
typedef struct typedef struct
{ {
GMenuTreeChangedFunc callback; GMenuTreeChangedFunc callback;
...@@ -419,45 +431,61 @@ gmenu_tree_force_recanonicalize (GMenuTree *tree) ...@@ -419,45 +431,61 @@ gmenu_tree_force_recanonicalize (GMenuTree *tree)
* Returns: (transfer full): A new #GMenuTree instance * Returns: (transfer full): A new #GMenuTree instance
*/ */
GMenuTree * GMenuTree *
gmenu_tree_new (const char *menu_file, gmenu_tree_new (const char *name,
GMenuTreeFlags flags) GMenuTreeFlags flags)
{ {
GMenuTree *tree; g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (menu_file != NULL, NULL); return g_object_new (GMENU_TYPE_TREE, "name", name, "flags", flags, NULL);
tree = g_new0 (GMenuTree, 1);
tree->flags = flags;
tree->refcount = 1;
tree->basename = g_strdup (menu_file);
return tree;
} }
GMenuTree * static void
gmenu_tree_ref (GMenuTree *tree) gmenu_tree_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{ {
g_return_val_if_fail (tree != NULL, NULL); GMenuTree *self = GMENU_TREE (object);
g_return_val_if_fail (tree->refcount > 0, NULL);
tree->refcount++; switch (prop_id)
{
case PROP_NAME:
self->basename = g_value_dup_string (value);
break;
return tree; case PROP_FLAGS:
self->flags = g_value_get_flags (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
} }
void static void
gmenu_tree_unref (GMenuTree *tree) gmenu_tree_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{ {
g_return_if_fail (tree != NULL); GMenuTree *self = GMENU_TREE (object);
g_return_if_fail (tree->refcount >= 1);
if (--tree->refcount > 0) switch (prop_id)
return; {
case PROP_NAME:
g_value_set_string (value, self->basename);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
if (tree->dnotify) static void
tree->dnotify (tree->user_data); gmenu_tree_finalize (GObject *object)
tree->user_data = NULL; {
tree->dnotify = NULL; GMenuTree *tree = GMENU_TREE (object);
gmenu_tree_force_recanonicalize (tree); gmenu_tree_force_recanonicalize (tree);
...@@ -469,35 +497,49 @@ gmenu_tree_unref (GMenuTree *tree) ...@@ -469,35 +497,49 @@ gmenu_tree_unref (GMenuTree *tree)
g_free (tree->canonical_path); g_free (tree->canonical_path);
tree->canonical_path = NULL; tree->canonical_path = NULL;
g_slist_foreach (tree->monitors, (GFunc) g_free, NULL); G_OBJECT_CLASS (gmenu_tree_parent_class)->finalize (object);
g_slist_free (tree->monitors);
tree->monitors = NULL;
g_free (tree);
} }
void static void
gmenu_tree_set_user_data (GMenuTree *tree, gmenu_tree_init (GMenuTree *self)
gpointer user_data,
GDestroyNotify dnotify)
{ {
g_return_if_fail (tree != NULL);
if (tree->dnotify != NULL)
tree->dnotify (tree->user_data);
tree->dnotify = dnotify;
tree->user_data = user_data;
} }
gpointer static void
gmenu_tree_get_user_data (GMenuTree *tree) gmenu_tree_class_init (GMenuTreeClass *klass)
{ {
g_return_val_if_fail (tree != NULL, NULL); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = gmenu_tree_get_property;
gobject_class->set_property = gmenu_tree_set_property;
gobject_class->finalize = gmenu_tree_finalize;
/**
* GMenuTree:name
*
* The name of the menu file; must be a relative path. See
* the Desktop Menu specification.
*/
g_object_class_install_property (gobject_class,
PROP_NAME,
g_param_spec_string ("name", "", "",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/**
* GMenuTree:flags
*
* Flags controlling the content of the menu.
*/
g_object_class_install_property (gobject_class,
PROP_FLAGS,
g_param_spec_flags ("flags", "", "",
GMENU_TYPE_TREE_FLAGS,
GMENU_TREE_FLAGS_NONE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
return tree->user_data;
} }
const char * const char *
gmenu_tree_get_menu_file (GMenuTree *tree) gmenu_tree_get_menu_file (GMenuTree *tree)
{ {
...@@ -825,7 +867,7 @@ gmenu_tree_directory_get_tree (GMenuTreeDirectory *directory) ...@@ -825,7 +867,7 @@ gmenu_tree_directory_get_tree (GMenuTreeDirectory *directory)
root = (GMenuTreeDirectoryRoot *) directory; root = (GMenuTreeDirectoryRoot *) directory;
if (root->tree) if (root->tree)
gmenu_tree_ref (root->tree); g_object_ref (root->tree);
return root->tree; return root->tree;
} }
......
...@@ -28,7 +28,23 @@ ...@@ -28,7 +28,23 @@
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct GMenuTree GMenuTree; #define GMENU_TYPE_TREE (gmenu_tree_get_type ())
#define GMENU_TREE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GMENU_TYPE_TREE, GMenuTree))
#define GMENU_TREE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GMENU_TYPE_TREE, GMenuTreeClass))
#define GMENU_IS_TREE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GMENU_TYPE_TREE))
#define GMENU_IS_TREE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GMENU_TYPE_TREE))
#define GMENU_TREE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_DESKTOP_APP_INFO, GMenuTreeClass))
typedef struct _GMenuTree GMenuTree;
typedef struct _GMenuTreeClass GMenuTreeClass;
struct _GMenuTreeClass
{
GObjectClass parent_class;
};
GType gmenu_tree_get_type (void) G_GNUC_CONST;
typedef struct GMenuTreeItem GMenuTreeItem; typedef struct GMenuTreeItem GMenuTreeItem;
typedef struct GMenuTreeDirectory GMenuTreeDirectory; typedef struct GMenuTreeDirectory GMenuTreeDirectory;
typedef struct GMenuTreeEntry GMenuTreeEntry; typedef struct GMenuTreeEntry GMenuTreeEntry;
...@@ -71,14 +87,6 @@ GType gmenu_tree_flags_get_type (void); ...@@ -71,14 +87,6 @@ GType gmenu_tree_flags_get_type (void);
GMenuTree *gmenu_tree_new (const char *menu_file, GMenuTree *gmenu_tree_new (const char *menu_file,
GMenuTreeFlags flags); GMenuTreeFlags flags);
GMenuTree *gmenu_tree_ref (GMenuTree *tree);
void gmenu_tree_unref (GMenuTree *tree);
void gmenu_tree_set_user_data (GMenuTree *tree,
gpointer user_data,
GDestroyNotify dnotify);
gpointer gmenu_tree_get_user_data (GMenuTree *tree);
const char *gmenu_tree_get_menu_file (GMenuTree *tree); const char *gmenu_tree_get_menu_file (GMenuTree *tree);
GMenuTreeDirectory *gmenu_tree_get_root_directory (GMenuTree *tree); GMenuTreeDirectory *gmenu_tree_get_root_directory (GMenuTree *tree);
GMenuTreeDirectory *gmenu_tree_get_directory_from_path (GMenuTree *tree, GMenuTreeDirectory *gmenu_tree_get_directory_from_path (GMenuTree *tree,
......
...@@ -203,18 +203,9 @@ static MenuMonitor * ...@@ -203,18 +203,9 @@ static MenuMonitor *
register_monitor (const char *path, register_monitor (const char *path,
gboolean is_directory) gboolean is_directory)
{ {
static gboolean initted = FALSE;
MenuMonitor *retval; MenuMonitor *retval;
GFile *file; GFile *file;
if (!initted)
{
/* This is the only place where we're using GObject and the app can't
* know we're using it, so we need to init the type system ourselves. */
g_type_init ();
initted = TRUE;
}
retval = g_new0 (MenuMonitor, 1); retval = g_new0 (MenuMonitor, 1);
retval->path = g_strdup (path); retval->path = g_strdup (path);
......
AM_CPPFLAGS = \
$(GIO_UNIX_CFLAGS) \
$(PYTHON_INCLUDES) \
-I$(srcdir)/../libmenu \
-DGMENU_I_KNOW_THIS_IS_UNSTABLE \
$(DISABLE_DEPRECATED_CFLAGS) \
$(DEBUG_CFLAGS)
AM_CFLAGS =
$(WARN_CFLAGS) \
$(NO_STRICT_ALIASING_CFLAGS)
gmenudir = $(pyexecdir)
gmenu_LTLIBRARIES = gmenu.la
gmenu_la_SOURCES = gmenu.c
gmenu_la_LDFLAGS = -module -avoid-version -fPIC -export-symbols-regex initgmenu
gmenu_la_LIBADD = $(GIO_UNIX_LIBS) $(PYTHON_LIBS) $(top_builddir)/libmenu/libgnome-menu.la
-include $(top_srcdir)/git.mk
This diff is collapsed.
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
import optparse import optparse
import sys import sys
import gmenu import gi.GMenu
def print_entry(entry, path): def print_entry(entry, path):
if entry.get_is_excluded(): if entry.get_is_excluded():
......
...@@ -188,6 +188,8 @@ main (int argc, char **argv) ...@@ -188,6 +188,8 @@ main (int argc, char **argv)
GMenuTreeDirectory *root; GMenuTreeDirectory *root;
GMenuTreeFlags flags; GMenuTreeFlags flags;
g_type_init ();
#if 0 #if 0
/* See comment when defining _() at the top of this file. */ /* See comment when defining _() at the top of this file. */
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
...@@ -238,7 +240,7 @@ main (int argc, char **argv) ...@@ -238,7 +240,7 @@ main (int argc, char **argv)
} }
gmenu_tree_unref (tree); g_object_unref (tree);
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment