GNOME Goal #1: Move from popt to GOption
Since GNOME 2.10, GLib provides GOption, a commandline option parser. The help output of your program will be much nicer And it will enable us to slowly get rid of popt (even if libgnome will still have to depend on it for compatibility reasons).
The documentation is fairly complete, so go read it!
To know if a module uses popt and is concerned by this migration, you can grep for POPT in the whole module. If there's no result, you can be 95% sure that it's not used by the module. |
Try to put a descriptive string as argument of g_option_context_new(). A good string might be the one you have as comment in the .desktop file for the module. Are we sure that this is the right usage of this argument? See bug #336085 -- ClaudioSaavedra.
Note that you don't have to call g_option_context_free() since GnomeProgram will do it when you unref it.
GOption will also automatically call g_set_progname() for you.
The most noticable difference is the change in the structure:
struct poptOption { const char * longName; /* may be NULL */ char shortName; /* may be '\0' */ int argInfo; void * arg; /* depends on argInfo */ int val; /* 0 means don't return, just update flag */ char * descrip; /* description for autohelp -- may be NULL */ char * argDescrip; /* argument description for autohelp */ }; typedef struct { const gchar *long_name; gchar short_name; gint flags; GOptionArg arg; gpointer arg_data; const gchar *description; const gchar *arg_description; } GOptionEntry;
Also, don't forget to look at G_OPTION_REMAINING if you used to parse argv yourself (looking for filename arguments, eg).
libgnome 2.14 supports GOption and makes it easy to use it. Here's a short example:
static const GOptionEntry options[] = { { "size", 0, 0, G_OPTION_ARG_STRING, &size, N_("Specify the size"), NULL}, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &files, NULL, N_("[FILE...]") }, { NULL} }; int main (int argc, char **argv) { GnomeProgram *program; GOptionContext *context; /* do what you want to do before */ /* gettext needs to be initialised here, at the latest */ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); context = g_option_context_new (_("- Show how to use GOption")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); program = gnome_program_init (argv [0], "0.0.0.0", LIBGNOMEUI_MODULE, argc, argv, GNOME_PARAM_GOPTION_CONTEXT, context, GNOME_PARAM_NONE); /* you can now use the size and files variables */ g_object_unref (program); exit (0); }
Note that you can ignore unknown options with g_option_context_set_ignore_unknown_options (context, TRUE);
Also because GOption support for libgnome was added in 2.14 (in GLib much earlier), you need to update configure.(ac|in) to require libgnome 2.14 like this:
LIBGNOME_REQUIRED=2.14.0 PKG_CHECK_MODULES([MYLIBS],[libgnome-2.0 >= $LIBGNOME_REQUIRED])
Status of this goal
1 module remaining
State |
Markup |
todo |
<: #ff8080> todo |
patch |
<: #ffc849> [[wiki:GnomeBug:xxxxx|patch]] |
done |
<: #80ff80> [[wiki:GnomeBug:xxxxx|done]] |
not needed |
<: #80ff80> not needed |
Above are the states and corresponding markup to update the modules state table below.
Tarball |
Status |
|
Desktop |
||
alacarte |
not needed |
|
bug-buddy |
||
cheese |
done |
|
dasher |
done |
|
not needed |
||
eel |
done |
|
done |
||
done |
||
done |
||
evolution-data-server |
done |
|
evolution-exchange |
not needed |
|
evolution-webcal |
||
fast-user-switch-applet |
not needed |
|
file-roller |
||
gcalctool |
not needed |
|
gconf-editor |
||
done |
||
done |
||
gnome-backgrounds |
not needed |
|
gnome-desktop |
not needed |
|
not needed |
||
done |
||
gnome-icon-theme |
not needed |
|
gnome-keyring |
not needed |
|
gnome-netstatus |
not needed |
|
gnome-nettool |
done |
|
gnome-mag |
||
done |
||
gnome-menus |
not needed |
|
done |
||
gnome-power-manager |
done |
|
gnome-python-desktop |
not needed |
|
done |
||
gnome-session |
done |
|
gnome-settings-daemon |
done |
|
not needed |
||
gnome-system-monitor |
not needed |
|
done |
||
gnome-terminal |
||
not needed |
||
gnome-user-docs |
not needed |
|
done |
||
gnome-volume-manager |
||
done |
||
gst-plugins |
not needed |
|
not needed |
||
gtkhtml |
||
not needed |
||
done |
||
gvfs |
done |
|
libgail-gnome |
not needed |
|
libgtop |
||
libgweather |
done |
|
liboobs |
not needed |
|
librsvg |
done |
|
libsoup |
not needed |
|
libwnck |
not needed |
|
metacity |
done |
|
mousetweaks |
done |
|
nautilus-cd-burner |
done |
|
orca |
not needed |
|
pygtksourceview |
not needed |
|
scrollkeeper |
not needed |
|
done |
||
swfdec-gnome |
done |
|
tomboy |
not needed |
|
totem-pl-parser |
done |
|
vinagre |
done |
|
vino |
not needed |
|
vte |
not needed |
|
done |
||
done |
||
Desktop (to be deprecated) |
||
gnome-keyring-manager |
||
libgnomeprint |
||
libgnomeprintui |
||
Platform |
||
GConf |
||
at-spi |
||
atk |
not needed |
|
gail |
not needed |
|
glib |
not needed |
|
gnome-mime-data |
not needed |
|
gnome-vfs |
||
done |
||
gtk-doc |
not needed |
|
intltool |
not needed |
|
libglade |
not needed |
|
libxml2 |
not needed |
|
libxslt |
not needed |
|
pango |
done |
|
pkgconfig |
not needed |
Has its own copy of popt |
Platform (to be deprecated) |
||
ORBit2 |
||
audiofile |
not needed |
|
esound |
not needed |
|
libIDL |
not needed |
|
libart_lgpl |
not needed |
|
libbonobo |
done |
|
libbonoboui |
||
libgnome |
done |
|
libgnomecanvas |
not needed |
|
libgnomeui |
done |
|
Admin |
||
not needed |
||
sabayon |
not needed |
|
Development Tools |
||
accerciser |
not needed |
|
anjuta |
||
devhelp |
done |
|
gdl |
not needed |
|
glade3 |
done |
|
gnome-build |
||
gnome-devel-docs |
not needed |
|
Bindings (C++) |
||
glibmm |
not needed |
|
gtkmm |
not needed |
|
libglademm |
not needed |
|
gconfmm |
not needed |
|
libgnomecanvasmm |
not needed |
|
libgnome-vfsmm |
not needed |
|
libgnomemm |
done |
|
libgnomeuimm |
done |
|
libxml++ |
not needed |
|
Bindings (java) |
||
glib-java (jg-common) |
not needed |
|
libgtk-java |
not needed |
|
libgnome-java |
not needed |
|
libgconf-java |
not needed |
|
libglade-java |
not needed |
|
Bindings (perl) |
||
Glib |
not needed |
|
Gtk2 |
not needed |
|
Gtk2-GladeXML |
not needed |
|
Gnome2-GConf |
not needed |
|
Gnome2-Canvas |
not needed |
|
Gnome2-VFS |
not needed |
|
Gnome2 |
not needed |
|
Bindings (python) |
||
pygobject |
||
not needed |
||
GnomePython |
||
Other |
||
camorama |
to do |
|
gnome-cups-manager |
||
gthumb |
done |
|
libgda |
||
startup-notification |
not needed |