[anjuta] Patch from Debarishi. Added functions anjuta_util_install_files() and anjuta_util_package_is_install



commit d9f043bdbcb3ce8add3d641eadcaafbc240fc02e
Author: Naba Kumar <naba gnome org>
Date:   Sat Jan 23 21:45:04 2010 +0200

    Patch from Debarishi. Added functions anjuta_util_install_files() and
    anjuta_util_package_is_installed() to install new packages via packagekit.

 libanjuta/Makefile.am    |    2 +
 libanjuta/anjuta-utils.c |   71 ++++++++++++++++++++++++++++++++++++++++++++++
 libanjuta/anjuta-utils.h |    2 +
 3 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/libanjuta/Makefile.am b/libanjuta/Makefile.am
index b4dbe67..15994d5 100644
--- a/libanjuta/Makefile.am
+++ b/libanjuta/Makefile.am
@@ -6,6 +6,7 @@ AM_CPPFLAGS = \
 	-I . \
 	$(WARN_CFLAGS) \
 	$(DEPRECATED_FLAGS) \
+	$(DBUS_GLIB_CFLAGS) \
 	$(GTK_CFLAGS) \
 	$(GCONF_CFLAGS) \
 	$(GLADE_DEPRECATED_CFLAGS) \
@@ -21,6 +22,7 @@ lib_LTLIBRARIES = libanjuta.la
 libanjuta_la_LDFLAGS = $(ANJUTA_LDFLAGS) 
 libanjuta_la_LIBADD = \
 	interfaces/libanjuta-interfaces.la \
+	$(DBUS_GLIB_LIBS) \
 	$(GTK_LIBS) \
 	$(GCONF_LIBS) \
 	$(GLADE_DEPRECATED_LIBS) \
diff --git a/libanjuta/anjuta-utils.c b/libanjuta/anjuta-utils.c
index 44e958a..e2f4da7 100644
--- a/libanjuta/anjuta-utils.c
+++ b/libanjuta/anjuta-utils.c
@@ -40,6 +40,7 @@
 #include <sys/types.h>
 #include <sys/fcntl.h>
 #include <sys/termios.h>
+#include <sys/wait.h>
 #include <dirent.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -48,9 +49,11 @@
 #include <pwd.h>
 #endif
 
+#include <dbus/dbus-glib.h>
 #include <glib/gi18n.h>
 #include <glib.h>
 #include <glib/gstdio.h>
+#include <gtk/gtk.h>
 
 #include <gconf/gconf-client.h>
 
@@ -481,6 +484,74 @@ anjuta_util_dialog_input (GtkWindow *parent, const gchar *prompt,
 }
 
 gboolean
+anjuta_util_install_files (const gchar * const names)
+{
+	DBusGConnection * connection;
+	DBusGProxy * proxy;
+	GError * error = NULL;
+	gboolean ret;
+	guint32 xid = 0;
+	gchar ** pkgv;
+
+	if (!names)
+		return FALSE;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+	if (!connection)
+		return FALSE;
+
+	proxy = dbus_g_proxy_new_for_name (connection,
+									   "org.freedesktop.PackageKit",
+									   "/org/freedesktop/PackageKit",
+									   "org.freedesktop.PackageKit.Modify");
+	if (!proxy)
+		return FALSE;
+
+	pkgv = g_strsplit (names, ", ", 0);
+	ret = dbus_g_proxy_call_with_timeout (proxy, "InstallProvideFiles",
+										  100, &error,
+										  G_TYPE_UINT, xid,
+										  G_TYPE_STRV, pkgv,
+										  G_TYPE_STRING, "",
+										  G_TYPE_INVALID, G_TYPE_INVALID);
+	if (!ret)
+	{
+		g_warning ("failed: %s", error->message);
+		g_error_free (error);
+	}
+
+	g_strfreev (pkgv);
+	return TRUE;
+}
+
+gboolean
+anjuta_util_package_is_installed (const gchar * package, gboolean show)
+{
+	gboolean installed = FALSE;
+	int status;
+	int exit_status;
+	pid_t pid;
+
+	if ((pid = fork()) == 0)
+		execlp ("pkg-config", "pkg-config", "--exists", package, NULL);
+
+	waitpid (pid, &status, 0);
+	exit_status = WEXITSTATUS (status);
+	installed = (exit_status == 0) ? TRUE : FALSE;
+	if (installed)
+		return TRUE;
+
+	if (show)
+	{
+		anjuta_util_dialog_error (NULL,
+								  _("The \"%s\" package is not installed.\n"
+									"Please install it."), package);
+	}
+
+	return FALSE;
+}
+
+gboolean
 anjuta_util_prog_is_installed (const gchar * prog, gboolean show)
 {
 	gchar* prog_path = g_find_program_in_path (prog);
diff --git a/libanjuta/anjuta-utils.h b/libanjuta/anjuta-utils.h
index 48e3135..c5ef85e 100644
--- a/libanjuta/anjuta-utils.h
+++ b/libanjuta/anjuta-utils.h
@@ -53,6 +53,8 @@ gboolean anjuta_util_dialog_boolean_question (GtkWindow *parent,
 gboolean anjuta_util_dialog_input (GtkWindow *parent, const gchar *label,
 								   const gchar *default_value, gchar **value);
 
+gboolean anjuta_util_install_files (const gchar * const names);
+gboolean anjuta_util_package_is_installed (const gchar * lib, gboolean show);
 gboolean anjuta_util_prog_is_installed (const gchar * prog, gboolean show);
 
 gchar* anjuta_util_get_a_tmp_file (void);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]