diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | Makefile.am | 14 | ||||
-rw-r--r-- | NEWS | 0 | ||||
-rw-r--r-- | README | 0 | ||||
-rwxr-xr-x | autogen.sh | 159 | ||||
-rw-r--r-- | configure.ac | 47 | ||||
-rw-r--r-- | po/Makefile.in.in | 218 | ||||
-rw-r--r-- | po/POTFILES.in | 2 | ||||
-rw-r--r-- | src/Makefile.am | 52 | ||||
-rw-r--r-- | src/anjuta-plugin-sdk.plugin.in | 5 | ||||
-rw-r--r-- | src/anjuta-plugin-sdk.png | bin | 0 -> 3056 bytes | |||
-rw-r--r-- | src/plugin.c | 472 | ||||
-rw-r--r-- | src/plugin.h | 50 |
13 files changed, 1020 insertions, 0 deletions
@@ -0,0 +1 @@ +Rob Bradford <rob@o-hand.com> diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..20e9c4b --- /dev/null +++ b/Makefile.am @@ -0,0 +1,14 @@ +SUBDIRS = src po + +INTLTOOL_BUILT = \ + intltool-extract \ + intltool-merge \ + intltool-update + +EXTRA_DIST = $(INTLTOOL_BUILT:=.in) + +DISTCLEANFILES = $(INTLTOOL_BUILT) +MAINTAINERCLEANFILES = aclocal.m4 compile config.guess config.sub configure \ + depcomp $(INTLTOOL_BUILT:=.in) install-sh ltmain.sh \ + mkinstalldirs Makefile.in missing + diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..9ab346a --- /dev/null +++ b/autogen.sh @@ -0,0 +1,159 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +DIE=0 + +if [ -n "$GNOME2_DIR" ]; then + ACLOCAL_FLAGS="-I $GNOME2_DIR/share/aclocal $ACLOCAL_FLAGS" + LD_LIBRARY_PATH="$GNOME2_DIR/lib:$LD_LIBRARY_PATH" + PATH="$GNOME2_DIR/bin:$PATH" + export PATH + export LD_LIBRARY_PATH +fi + +(test -f $srcdir/configure.ac) || { + echo -n "**Error**: Directory "\`$srcdir\'" does not look like the" + echo " top-level package directory" + exit 1 +} + +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`autoconf' installed." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" + DIE=1 +} + +(grep "^IT_PROG_INTLTOOL" $srcdir/configure.ac >/dev/null) && { + (intltoolize --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`intltool' installed." + echo "You can get it from:" + echo " ftp://ftp.gnome.org/pub/GNOME/" + DIE=1 + } +} + +(grep "^AM_PROG_XML_I18N_TOOLS" $srcdir/configure.ac >/dev/null) && { + (xml-i18n-toolize --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`xml-i18n-toolize' installed." + echo "You can get it from:" + echo " ftp://ftp.gnome.org/pub/GNOME/" + DIE=1 + } +} + +(grep "^AM_PROG_LIBTOOL" $srcdir/configure.ac >/dev/null) && { + (libtool --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`libtool' installed." + echo "You can get it from: ftp://ftp.gnu.org/pub/gnu/" + DIE=1 + } +} + +(grep "^AM_GLIB_GNU_GETTEXT" $srcdir/configure.ac >/dev/null) && { + (grep "sed.*POTFILES" $srcdir/configure.ac) > /dev/null || \ + (glib-gettextize --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`glib' installed." + echo "You can get it from: ftp://ftp.gtk.org/pub/gtk" + DIE=1 + } +} + +(automake --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`automake' installed." + echo "You can get it from: ftp://ftp.gnu.org/pub/gnu/" + DIE=1 + NO_AUTOMAKE=yes +} + + +# if no automake, don't bother testing for aclocal +test -n "$NO_AUTOMAKE" || (aclocal --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: Missing \`aclocal'. The version of \`automake'" + echo "installed doesn't appear recent enough." + echo "You can get automake from ftp://ftp.gnu.org/pub/gnu/" + DIE=1 +} + +if test "$DIE" -eq 1; then + exit 1 +fi + +if test -z "$*"; then + echo "**Warning**: I am going to run \`configure' with no arguments." + echo "If you wish to pass any to it, please specify them on the" + echo \`$0\'" command line." + echo +fi + +case $CC in +xlc ) + am_opt=--include-deps;; +esac + +for coin in `find $srcdir -path $srcdir/CVS -prune -o -name configure.ac -print` +do + dr=`dirname $coin` + if test -f $dr/NO-AUTO-GEN; then + echo skipping $dr -- flagged as no auto-gen + else + echo processing $dr + ( cd $dr + + aclocalinclude="$ACLOCAL_FLAGS" + + if grep "^AM_GLIB_GNU_GETTEXT" configure.ac >/dev/null; then + echo "Creating $dr/aclocal.m4 ..." + test -r $dr/aclocal.m4 || touch $dr/aclocal.m4 + echo "Running glib-gettextize... Ignore non-fatal messages." + echo "no" | glib-gettextize --force --copy + echo "Making $dr/aclocal.m4 writable ..." + test -r $dr/aclocal.m4 && chmod u+w $dr/aclocal.m4 + fi + if grep "^IT_PROG_INTLTOOL" configure.ac >/dev/null; then + echo "Running intltoolize..." + intltoolize --copy --force --automake + fi + if grep "^AM_PROG_XML_I18N_TOOLS" configure.ac >/dev/null; then + echo "Running xml-i18n-toolize..." + xml-i18n-toolize --copy --force --automake + fi + if grep "^AM_PROG_LIBTOOL" configure.ac >/dev/null; then + if test -z "$NO_LIBTOOLIZE" ; then + echo "Running libtoolize..." + libtoolize --force --copy + fi + fi + echo "Running aclocal $aclocalinclude ..." + aclocal $aclocalinclude + if grep "^AM_CONFIG_HEADER" configure.ac >/dev/null; then + echo "Running autoheader..." + autoheader + fi + echo "Running automake --gnu $am_opt ..." + automake --add-missing --gnu $am_opt + echo "Running autoconf ..." + autoconf + ) + fi +done + +conf_flags="--enable-maintainer-mode" + +if test x$NOCONFIGURE = x; then + echo Running $srcdir/configure $conf_flags "$@" ... + $srcdir/configure $conf_flags "$@" \ + && echo Now type \`make\' to compile. || exit 1 +else + echo Skipping configure process. +fi diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..b818b1e --- /dev/null +++ b/configure.ac @@ -0,0 +1,47 @@ +dnl Process this file with autoconf to produce a configure script. + +AC_INIT(anjuta-plugin-sdk, 0.1) + +AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) +AM_CONFIG_HEADER(config.h) +AM_MAINTAINER_MODE + +AC_ISC_POSIX +AC_PROG_CC +AM_PROG_CC_STDC +AC_HEADER_STDC + +GETTEXT_PACKAGE=anjuta-plugin-sdk +AC_SUBST(GETTEXT_PACKAGE) +AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [GETTEXT package name]) +AM_GLIB_GNU_GETTEXT +IT_PROG_INTLTOOL([0.35.0]) + +AM_PROG_LIBTOOL + +PKG_CHECK_MODULES(LIBANJUTA, [libanjuta-1.0]) +AC_SUBST(LIBANJUTA_CFLAGS) +AC_SUBST(LIBANJUTA_LIBS) + +dnl Setup Plugin directories +dnl ------------------------ +anjutalibdir=`pkg-config --variable=libdir libanjuta-1.0` +anjutadatadir=`pkg-config --variable=datadir libanjuta-1.0` +AC_SUBST(anjutalibdir) +AC_SUBST(anjutadatadir) +anjuta_plugin_dir='$(anjutalibdir)/anjuta' +anjuta_data_dir='$(anjutadatadir)/anjuta' +anjuta_ui_dir='$(anjutadatadir)/anjuta/ui' +anjuta_glade_dir='$(anjutadatadir)/anjuta/glade' +anjuta_image_dir='$(anjutadatadir)/pixmaps/anjuta' +AC_SUBST(anjuta_plugin_dir) +AC_SUBST(anjuta_data_dir) +AC_SUBST(anjuta_ui_dir) +AC_SUBST(anjuta_glade_dir) +AC_SUBST(anjuta_image_dir) + +AC_OUTPUT([ +Makefile +src/Makefile +po/Makefile.in +]) diff --git a/po/Makefile.in.in b/po/Makefile.in.in new file mode 100644 index 0000000..b630d54 --- /dev/null +++ b/po/Makefile.in.in @@ -0,0 +1,218 @@ +# Makefile for program source directory in GNU NLS utilities package. +# Copyright (C) 1995, 1996, 1997 by Ulrich Drepper <drepper@gnu.ai.mit.edu> +# +# This file file be copied and used freely without restrictions. It can +# be used in projects which are not available under the GNU Public License +# but which still want to provide support for the GNU gettext functionality. +# Please note that the actual code is *not* freely available. +# +# - Modified by Owen Taylor <otaylor@redhat.com> to use GETTEXT_PACKAGE +# instead of PACKAGE and to look for po2tbl in ./ not in intl/ +# +# - Modified by jacob berkman <jacob@ximian.com> to install +# Makefile.in.in and po2tbl.sed.in for use with glib-gettextize +# +# - Modified by Rodney Dawes <dobey@novell.com> for use with intltool +# +# We have the following line for use by intltoolize: +# INTLTOOL_MAKEFILE + +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +PACKAGE = @PACKAGE@ +VERSION = @VERSION@ + +SHELL = /bin/sh + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ +VPATH = @srcdir@ + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +datadir = @datadir@ +datarootdir = @datarootdir@ +libdir = @libdir@ +DATADIRNAME = @DATADIRNAME@ +itlocaledir = $(prefix)/$(DATADIRNAME)/locale +subdir = po +install_sh = @install_sh@ +# Automake >= 1.8 provides @mkdir_p@. +# Until it can be supposed, use the safe fallback: +mkdir_p = $(install_sh) -d + +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ + +GMSGFMT = @GMSGFMT@ +MSGFMT = @MSGFMT@ +XGETTEXT = @XGETTEXT@ +INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ +MSGMERGE = INTLTOOL_EXTRACT=$(INTLTOOL_EXTRACT) srcdir=$(srcdir) $(INTLTOOL_UPDATE) --gettext-package $(GETTEXT_PACKAGE) --dist +GENPOT = INTLTOOL_EXTRACT=$(INTLTOOL_EXTRACT) srcdir=$(srcdir) $(INTLTOOL_UPDATE) --gettext-package $(GETTEXT_PACKAGE) --pot + +ALL_LINGUAS = @ALL_LINGUAS@ + +PO_LINGUAS=$(shell if test -r $(srcdir)/LINGUAS; then grep -v "^\#" $(srcdir)/LINGUAS; fi) + +USER_LINGUAS=$(shell if test -n "$(LINGUAS)"; then LLINGUAS="$(LINGUAS)"; ALINGUAS="$(ALL_LINGUAS)"; for lang in $$LLINGUAS; do if test -n "`grep ^$$lang$$ $(srcdir)/LINGUAS`" -o -n "`echo $$ALINGUAS|grep ' ?$$lang ?'`"; then printf "$$lang "; fi; done; fi) + +USE_LINGUAS=$(shell if test -n "$(USER_LINGUAS)"; then LLINGUAS="$(USER_LINGUAS)"; else if test -n "$(PO_LINGUAS)"; then LLINGUAS="$(PO_LINGUAS)"; else LLINGUAS="$(ALL_LINGUAS)"; fi; fi; for lang in $$LLINGUAS; do printf "$$lang "; done) + +POFILES=$(shell LINGUAS="$(USE_LINGUAS)"; for lang in $$LINGUAS; do printf "$$lang.po "; done) + +DISTFILES = ChangeLog Makefile.in.in POTFILES.in $(POFILES) +EXTRA_DISTFILES = POTFILES.skip Makevars LINGUAS + +POTFILES = \ +# This comment gets stripped out + +CATALOGS=$(shell LINGUAS="$(USE_LINGUAS)"; for lang in $$LINGUAS; do printf "$$lang.gmo "; done) + +.SUFFIXES: +.SUFFIXES: .po .pox .gmo .mo .msg .cat + +.po.pox: + $(MAKE) $(GETTEXT_PACKAGE).pot + $(MSGMERGE) $< $(GETTEXT_PACKAGE).pot -o $*.pox + +.po.mo: + $(MSGFMT) -o $@ $< + +.po.gmo: + file=`echo $* | sed 's,.*/,,'`.gmo \ + && rm -f $$file && $(GMSGFMT) -o $$file $< + +.po.cat: + sed -f ../intl/po2msg.sed < $< > $*.msg \ + && rm -f $@ && gencat $@ $*.msg + + +all: all-@USE_NLS@ + +all-yes: $(CATALOGS) +all-no: + +$(GETTEXT_PACKAGE).pot: $(POTFILES) + $(GENPOT) + +install: install-data +install-data: install-data-@USE_NLS@ +install-data-no: all +install-data-yes: all + $(mkdir_p) $(DESTDIR)$(itlocaledir) + linguas="$(USE_LINGUAS)"; \ + for lang in $$linguas; do \ + dir=$(DESTDIR)$(itlocaledir)/$$lang/LC_MESSAGES; \ + $(mkdir_p) $$dir; \ + if test -r $$lang.gmo; then \ + $(INSTALL_DATA) $$lang.gmo $$dir/$(GETTEXT_PACKAGE).mo; \ + echo "installing $$lang.gmo as $$dir/$(GETTEXT_PACKAGE).mo"; \ + else \ + $(INSTALL_DATA) $(srcdir)/$$lang.gmo $$dir/$(GETTEXT_PACKAGE).mo; \ + echo "installing $(srcdir)/$$lang.gmo as" \ + "$$dir/$(GETTEXT_PACKAGE).mo"; \ + fi; \ + if test -r $$lang.gmo.m; then \ + $(INSTALL_DATA) $$lang.gmo.m $$dir/$(GETTEXT_PACKAGE).mo.m; \ + echo "installing $$lang.gmo.m as $$dir/$(GETTEXT_PACKAGE).mo.m"; \ + else \ + if test -r $(srcdir)/$$lang.gmo.m ; then \ + $(INSTALL_DATA) $(srcdir)/$$lang.gmo.m \ + $$dir/$(GETTEXT_PACKAGE).mo.m; \ + echo "installing $(srcdir)/$$lang.gmo.m as" \ + "$$dir/$(GETTEXT_PACKAGE).mo.m"; \ + else \ + true; \ + fi; \ + fi; \ + done + +# Empty stubs to satisfy archaic automake needs +dvi info tags TAGS ID: + +# Define this as empty until I found a useful application. +install-exec installcheck: + +uninstall: + linguas="$(USE_LINGUAS)"; \ + for lang in $$linguas; do \ + rm -f $(DESTDIR)$(itlocaledir)/$$lang/LC_MESSAGES/$(GETTEXT_PACKAGE).mo; \ + rm -f $(DESTDIR)$(itlocaledir)/$$lang/LC_MESSAGES/$(GETTEXT_PACKAGE).mo.m; \ + done + +check: all $(GETTEXT_PACKAGE).pot + rm -f missing notexist + srcdir=$(srcdir) $(INTLTOOL_UPDATE) -m + if [ -r missing -o -r notexist ]; then \ + exit 1; \ + fi + +mostlyclean: + rm -f *.pox $(GETTEXT_PACKAGE).pot *.old.po cat-id-tbl.tmp + rm -f .intltool-merge-cache + +clean: mostlyclean + +distclean: clean + rm -f Makefile Makefile.in POTFILES stamp-it + rm -f *.mo *.msg *.cat *.cat.m *.gmo + +maintainer-clean: distclean + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + rm -f Makefile.in.in + +distdir = ../$(PACKAGE)-$(VERSION)/$(subdir) +dist distdir: $(DISTFILES) + dists="$(DISTFILES)"; \ + extra_dists="$(EXTRA_DISTFILES)"; \ + for file in $$extra_dists; do \ + test -f $(srcdir)/$$file && dists="$$dists $(srcdir)/$$file"; \ + done; \ + for file in $$dists; do \ + test -f $$file || file="$(srcdir)/$$file"; \ + ln $$file $(distdir) 2> /dev/null \ + || cp -p $$file $(distdir); \ + done + +update-po: Makefile + $(MAKE) $(GETTEXT_PACKAGE).pot + tmpdir=`pwd`; \ + linguas="$(USE_LINGUAS)"; \ + for lang in $$linguas; do \ + echo "$$lang:"; \ + result="`$(MSGMERGE) -o $$tmpdir/$$lang.new.po $$lang`"; \ + if $$result; then \ + if cmp $(srcdir)/$$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \ + rm -f $$tmpdir/$$lang.new.po; \ + else \ + if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \ + :; \ + else \ + echo "msgmerge for $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \ + rm -f $$tmpdir/$$lang.new.po; \ + exit 1; \ + fi; \ + fi; \ + else \ + echo "msgmerge for $$lang.gmo failed!"; \ + rm -f $$tmpdir/$$lang.new.po; \ + fi; \ + done + +Makefile POTFILES: stamp-it + @if test ! -f $@; then \ + rm -f stamp-it; \ + $(MAKE) stamp-it; \ + fi + +stamp-it: Makefile.in.in $(top_builddir)/config.status POTFILES.in + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/Makefile.in CONFIG_HEADERS= CONFIG_LINKS= \ + $(SHELL) ./config.status + +# Tell versions [3.59,3.63) of GNU make not to export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..a39f44a --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,2 @@ +src/plugin.c + diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..fc54af5 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,52 @@ +# Sample Makefile for a anjuta plugin. + +# Plugin Icon file +anjuta_plugin_sdk_pixmapsdir = $(anjuta_image_dir) +anjuta_plugin_sdk_pixmaps_DATA = anjuta-plugin-sdk.png + +# Plugin description file +plugin_in_files = anjuta-plugin-sdk.plugin.in +%.plugin: %.plugin.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache + +anjuta_plugin_sdk_plugindir = $(anjuta_plugin_dir) +anjuta_plugin_sdk_plugin_DATA = $(plugin_in_files:.plugin.in=.plugin) + +# NOTE : +# The naming convention is very intentional +# We are forced to use the prefix 'lib' by automake and libtool +# There is probably a way to avoid it but it is not worth to effort +# to find out. +# The 'anjuta_' prfix is a safety measure to avoid conflicts where the +# plugin 'libpython.so' needs to link with the real 'libpython.so' + +# Include paths +INCLUDES = \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \ + -DANJUTA_DATA_DIR=\"$(anjuta_data_dir)\" \ + -DANJUTA_PLUGIN_DIR=\"$(anjuta_plugin_dir)\" \ + -DANJUTA_IMAGE_DIR=\"$(anjuta_image_dir)\" \ + -DANJUTA_GLADE_DIR=\"$(anjuta_glade_dir)\" \ + -DANJUTA_UI_DIR=\"$(anjuta_ui_dir)\" \ + -DPACKAGE_DATA_DIR=\"$(datadir)\" \ + -DPACKAGE_SRC_DIR=\"$(srcdir)\" \ + $(LIBANJUTA_CFLAGS) + +# Where to install the plugin +plugindir = $(anjuta_plugin_dir) + +# The plugin +plugin_LTLIBRARIES = libanjuta-plugin-sdk.la + +# Plugin sources +libanjuta_plugin_sdk_la_SOURCES = plugin.c plugin.h + +# Plugin dependencies +libanjuta_plugin_sdk_la_LIBADD = \ + $(LIBANJUTA_LIBS) + +EXTRA_DIST = \ + $(plugin_in_files) \ + $(anjuta_plugin_sdk_plugin_DATA) \ + $(anjuta_plugin_sdk_ui_DATA) \ + $(anjuta_plugin_sdk_glade_DATA) \ + $(anjuta_plugin_sdk_pixmaps_DATA) diff --git a/src/anjuta-plugin-sdk.plugin.in b/src/anjuta-plugin-sdk.plugin.in new file mode 100644 index 0000000..edcbb17 --- /dev/null +++ b/src/anjuta-plugin-sdk.plugin.in @@ -0,0 +1,5 @@ +[Anjuta Plugin] +Location=anjuta-plugin-sdk:AnjutaPluginSdk +Icon=anjuta-plugin-sdk.png +_Name=Anjuta external SDK plugin +_Description=A plugin that allows integration with an external SDK. diff --git a/src/anjuta-plugin-sdk.png b/src/anjuta-plugin-sdk.png Binary files differnew file mode 100644 index 0000000..3cd250b --- /dev/null +++ b/src/anjuta-plugin-sdk.png diff --git a/src/plugin.c b/src/plugin.c new file mode 100644 index 0000000..076cc31 --- /dev/null +++ b/src/plugin.c @@ -0,0 +1,472 @@ +/* + * Copyright (C) 2007 OpenedHand Ltd. + * Authored by: Rob Bradford <rob@o-hand.com> + * + * This is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, version 2 of the License. + * + * This software is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <config.h> +#include <libanjuta/anjuta-shell.h> +#include <libanjuta/anjuta-debug.h> +#include <libanjuta/interfaces/ianjuta-document-manager.h> + +#include "plugin.h" + +#define PREFS_PROP_SDK_ROOT "sdk.root" +#define PREFS_PROP_TRIPLET "sdk.triplet" + +static gpointer anjuta_plugin_sdk_parent_class; + +static gchar * +file_chooser_property_get_cb (AnjutaProperty *prop) +{ + GtkWidget *chooser = NULL; + gchar *filename = NULL; + + chooser = anjuta_property_get_widget (prop); + filename = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (chooser)); + + return filename; +} + +static void +file_chooser_property_set_cb (AnjutaProperty *prop, const gchar *value) +{ + GtkWidget *chooser = NULL; + + chooser = anjuta_property_get_widget (prop); + + if (value != NULL && chooser != NULL) + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser), value); +} + +static void +sdk_root_file_chooser_changed_cb (GtkFileChooserButton *button, gpointer userdata) +{ + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + gchar *filename = NULL; + + filename = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button)); + + anjuta_preferences_set (ANJUTA_PREFERENCES (sp->prefs), PREFS_PROP_SDK_ROOT, + filename); + g_free (filename); +} + +static void +update_path (AnjutaPluginSdk *sp) +{ + char *path = NULL; + gchar **pathv = NULL; + gchar **new_pathv = NULL; + + gchar **path_it = NULL; + gchar **new_path_it = NULL; + + gchar *new_path_component = NULL; + + if (sp->triplet != NULL && sp->sdk_root != NULL) + { + new_path_component = g_build_filename (sp->sdk_root, "bin", NULL); + } + + g_debug ("New path component: %s", new_path_component); + + /* get current path. do not free */ + path = getenv ("PATH"); + + g_debug ("Current path: %s", path); + + /* split old path up */ + pathv = g_strsplit (path, ":", -1); + + /* allocate memory for new pathv */ + new_pathv = g_malloc0 ((g_strv_length (pathv) + 2) * (sizeof (gchar *))); + + /* new pathv iterator */ + new_path_it = new_pathv; + + /* insert at the front if we have something to insert */ + if (new_path_component) + { + *new_path_it = new_path_component; + new_path_it++; + } + + /* iterate through */ + for (path_it = pathv; *path_it != NULL; path_it++) + { + /* Check for the old component */ + if (sp->path_component && g_str_equal (*path_it, sp->path_component)) + { + path_it++; /* skip over */ + } + + *new_path_it = *path_it; + new_path_it++; + } + + + /* Create our new path */ + path = g_strjoinv (":", new_pathv); + setenv ("PATH", path, 1); + + g_debug ("New path: %s", path); + + /* Save the component */ + g_free (sp->path_component); + sp->path_component = new_path_component; +} + +static void +update_environment (AnjutaPluginSdk *sp) +{ + gchar *tmp = NULL; + + g_free (sp->sdk_root); + g_free (sp->triplet); + + sp->sdk_root = anjuta_preferences_get (ANJUTA_PREFERENCES (sp->prefs), + PREFS_PROP_SDK_ROOT); + sp->triplet = anjuta_preferences_get (ANJUTA_PREFERENCES (sp->prefs), + PREFS_PROP_TRIPLET); + + if (sp->triplet == NULL || sp->sdk_root == NULL) + { + /* unset environment keys */ + unsetenv ("PKG_CONFIG_SYSROOT_DIR"); + unsetenv ("PKG_CONFIG_PATH"); + unsetenv ("CONFIG_SITE"); + } + + update_path (sp); + + tmp = g_build_filename (sp->sdk_root, sp->triplet, NULL); + setenv ("PKG_CONFIG_SYSROOT_DIR", tmp, 1); + g_free (tmp); + + tmp = g_build_filename (sp->sdk_root, sp->triplet, "lib", "pkgconfig", NULL); + setenv ("PKG_CONFIG_PATH", tmp, 1); + g_free (tmp); + + tmp = g_build_filename (sp->sdk_root, "site-config", NULL); + setenv ("CONFIG_SITE", tmp, 1); + g_free (tmp); +} + +static void +cleanup_environment (AnjutaPluginSdk *sp) +{ + g_free (sp->triplet); + g_free (sp->sdk_root); + + sp->triplet = NULL; + sp->sdk_root = NULL; + + update_path (sp); +} + +static void +update_configure_opts (AnjutaPluginSdk *sp) +{ + /* + * can't do anything to update the option. must instead do it in the + * session-load signal + */ +} + +/* idle callback used to aggregate updates */ +static gboolean +update_environment_idle_cb (gpointer userdata) +{ + update_environment ((AnjutaPluginSdk *)userdata); + return FALSE; +} + +static void +sdk_root_preference_notify_cb (GConfClient *client, guint cnxn_id, + GConfEntry *entry, gpointer userdata) +{ + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + + if (!sp->update_environment_idle) + g_idle_add (update_environment_idle_cb, sp); +} + +static void +triplet_preference_notify_cb (GConfClient *client, guint cnxn_id, + GConfEntry *entry, gpointer userdata) +{ + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + + if (!sp->update_environment_idle) + g_idle_add (update_environment_idle_cb, sp); + + update_configure_opts (sp); +} + +/* + * cb that gets fired when the session is loaded up, we use this fiddle with + * the configure option to add our --host option for cross compiling + */ +static void +load_session_cb (AnjutaShell *shell, AnjutaSessionPhase phase, + AnjutaSession *session, gpointer userdata) +{ + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + gchar *tmp = NULL; + gchar *configure_opts = NULL; + + tmp = anjuta_session_get_string (session, "Build", + "Configure parameters"); + + if (sp->triplet) + { + if (tmp != NULL) + { + /* check if already present */ + if (strstr (tmp, "--host=") == NULL) + { + configure_opts = g_strdup_printf ("%s --host=%s", tmp, sp->triplet); + } + } else { + configure_opts = g_strdup_printf ("--host=%s", sp->triplet); + } + + anjuta_session_set_string (session, "Build", + "Configure parameters", configure_opts); + } + + g_free (configure_opts); + g_free (tmp); +} + +static void +anjuta_plugin_sdk_setup_preferences (AnjutaPluginSdk *sp) +{ + GtkWidget *vbox; + GtkSizeGroup *opts_labels_group; + GtkSizeGroup *opts_fields_group; + GtkWidget *frame; + GtkWidget *inner_vbox; + GtkWidget *hbox; + GtkWidget *label; + GtkWidget *chooser; + GtkWidget *entry; + GtkWidget *inner_alignment; + gboolean res; + + sp->prefs = anjuta_preferences_new (); + + /* Create main vbox */ + vbox = gtk_vbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); + + /* Frame for options */ + frame = gtk_frame_new (_("<b>SDK options</b>")); + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 2); + label = gtk_frame_get_label_widget (GTK_FRAME (frame)); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + + /* size groups for files */ + opts_labels_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + opts_fields_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + + /* Pack inner vbox */ + inner_vbox = gtk_vbox_new (FALSE, 6); + inner_alignment = gtk_alignment_new (0, 0.5, 1, 1); + g_object_set (inner_alignment, "left-padding", 12, "top-padding", 6, NULL); + gtk_container_add (GTK_CONTAINER (inner_alignment), inner_vbox); + gtk_container_add (GTK_CONTAINER (frame), inner_alignment); + + /* Widgets for sdk root */ + hbox = gtk_hbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (inner_vbox), hbox, TRUE, FALSE, 0); + + /* label */ + label = gtk_label_new (_("SDK root: ")); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_size_group_add_widget (opts_labels_group, label); + gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5); + + /* chooser */ + chooser = gtk_file_chooser_button_new (_("Select SDK root"), + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); + sp->sdk_root_chooser = chooser; + gtk_box_pack_start (GTK_BOX (hbox), chooser, TRUE, TRUE, 0); + gtk_size_group_add_widget (opts_fields_group, label); + + /* register prop */ + res = anjuta_preferences_register_property_custom (ANJUTA_PREFERENCES (sp->prefs), + chooser, + PREFS_PROP_SDK_ROOT, + NULL, + ANJUTA_PROPERTY_DATA_TYPE_TEXT, + 0, + file_chooser_property_set_cb, + file_chooser_property_get_cb); + + if (!res) + g_warning ("Error adding preference for SDK root"); + + /* signal for file changed */ + g_signal_connect (chooser, "current-folder-changed", + (GCallback)sdk_root_file_chooser_changed_cb, sp); + + /* Widgets for toolchain triplet */ + hbox = gtk_hbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (inner_vbox), hbox, TRUE, FALSE, 0); + + /* label */ + label = gtk_label_new (_("Toolchain triplet: ")); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_size_group_add_widget (opts_labels_group, label); + gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5); + + /* entry */ + entry = gtk_entry_new (); + sp->triplet_entry = entry; + gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); + gtk_size_group_add_widget (opts_fields_group, label); + + /* register prop */ + res = anjuta_preferences_register_property_raw (ANJUTA_PREFERENCES (sp->prefs), + entry, + PREFS_PROP_TRIPLET, + NULL, + 0, + ANJUTA_PROPERTY_OBJECT_TYPE_ENTRY, + ANJUTA_PROPERTY_DATA_TYPE_TEXT); + + if (!res) + g_warning ("Error adding preference for triplet"); + + /* Add a label requesting restart */ + label = gtk_label_new (_("<i>Anjuta must be restarted for these changes to take effect</i>")); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 2); + gtk_widget_show_all (vbox); + + /* add page */ + anjuta_preferences_dialog_add_page (ANJUTA_PREFERENCES_DIALOG (sp->prefs), + _("SDK"), "SDK", NULL, + vbox); + + /* callbacks for when the preferences are changed */ + sp->sdk_root_notifyid = anjuta_preferences_notify_add (ANJUTA_PREFERENCES (sp->prefs), + PREFS_PROP_SDK_ROOT, + sdk_root_preference_notify_cb, + sp, + NULL); + sp->triplet_notifyid = anjuta_preferences_notify_add (ANJUTA_PREFERENCES (sp->prefs), + PREFS_PROP_TRIPLET, + triplet_preference_notify_cb, + sp, + NULL); +} + +static void +anjuta_plugin_sdk_unsetup_preferences (AnjutaPluginSdk *sp) +{ + /* remove page */ + anjuta_preferences_dialog_remove_page (ANJUTA_PREFERENCES_DIALOG (sp->prefs), + "SDK"); + + /* remove callbacks */ + anjuta_preferences_notify_remove (ANJUTA_PREFERENCES (sp->prefs), + sp->sdk_root_notifyid); + anjuta_preferences_notify_remove (ANJUTA_PREFERENCES (sp->prefs), + sp->triplet_notifyid); +} + +static gboolean +anjuta_plugin_sdk_activate (AnjutaPlugin *plugin) +{ + AnjutaUI *ui; + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)plugin; + + ui = anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin)->shell, NULL); + + anjuta_plugin_sdk_setup_preferences (sp); + + update_environment (sp); + + /* hook up a signal for session loading */ + + g_signal_connect (ANJUTA_PLUGIN (plugin)->shell, + "load-session", (GCallback)load_session_cb, sp); + + return TRUE; +} + +static gboolean +anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin) +{ + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)plugin; + + anjuta_plugin_sdk_unsetup_preferences (sp); + cleanup_environment (sp); + + g_signal_handlers_disconnect_by_func (ANJUTA_PLUGIN (plugin)->shell, + load_session_cb, sp); + + g_free (sp->sdk_root); + g_free (sp->triplet); + g_free (sp->path_component); + + return TRUE; +} + +static void +anjuta_plugin_sdk_finalize (GObject *obj) +{ + if (G_OBJECT_CLASS (anjuta_plugin_sdk_parent_class)->finalize) + G_OBJECT_CLASS (anjuta_plugin_sdk_parent_class)->finalize (obj); +} + +static void +anjuta_plugin_sdk_dispose (GObject *obj) +{ + AnjutaPluginSdk *sp = (AnjutaPluginSdk *)obj; + + if (sp->prefs) + { + gtk_widget_destroy (sp->prefs); + sp->prefs = NULL; + } + + if (G_OBJECT_CLASS (anjuta_plugin_sdk_parent_class)->dispose) + G_OBJECT_CLASS (anjuta_plugin_sdk_parent_class)->dispose (obj); +} + +static void +anjuta_plugin_sdk_instance_init (GObject *obj) +{ +} + +static void +anjuta_plugin_sdk_class_init (GObjectClass *klass) +{ + AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass); + + anjuta_plugin_sdk_parent_class = g_type_class_peek_parent (klass); + + plugin_class->activate = anjuta_plugin_sdk_activate; + plugin_class->deactivate = anjuta_plugin_sdk_deactivate; + klass->finalize = anjuta_plugin_sdk_finalize; + klass->dispose = anjuta_plugin_sdk_dispose; +} + +ANJUTA_PLUGIN_BOILERPLATE (AnjutaPluginSdk, anjuta_plugin_sdk); +ANJUTA_SIMPLE_PLUGIN (AnjutaPluginSdk, anjuta_plugin_sdk); diff --git a/src/plugin.h b/src/plugin.h new file mode 100644 index 0000000..56bcaca --- /dev/null +++ b/src/plugin.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2007 OpenedHand Ltd. + * Authored by: Rob Bradford <rob@o-hand.com> + * + * This is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, version 2 of the License. + * + * This software is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _ANJUTA_PLUGIN_SDK_H_ +#define _ANJUTA_PLUGIN_SDK_H_ + +#include <libanjuta/anjuta-plugin.h> + +typedef struct _AnjutaPluginSdk AnjutaPluginSdk; +typedef struct _AnjutaPluginSdkClass AnjutaPluginSdkClass; + +struct _AnjutaPluginSdk +{ + AnjutaPlugin parent; + + GtkWidget *prefs; + + GtkWidget *sdk_root_chooser; + GtkWidget *triplet_entry; + + guint sdk_root_notifyid; + guint triplet_notifyid; + + guint update_environment_idle; + + gchar *triplet; + gchar *sdk_root; + + gchar *path_component; +}; + +struct _AnjutaPluginSdkClass +{ + AnjutaPluginClass parent_class; +}; +#endif |