[gnome-packagekit/app-installer] Some very early work on the new local-package-installer



commit ee15c84351fe394acc5bd5b4363c4ea5e7261265
Author: Matthias Klumpp <matthias tenstral net>
Date:   Wed Apr 24 22:47:39 2013 +0200

    Some very early work on the new local-package-installer

 configure.ac                 |   14 +++
 data/Makefile.am             |    1 +
 data/gpk-install-local.ui    |  267 +++++++++++++++++++++++------------------
 src/gpk-install-local-file.c |  201 +++++++++++++++++++++++++-------
 4 files changed, 323 insertions(+), 160 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 09e4c86..c33936c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -138,6 +138,20 @@ fi
 AM_CONDITIONAL(HAVE_GUDEV, test x$HAVE_GUDEV = xyes)
 
 dnl ---------------------------------------------------------------------------
+dnl - Check if we can build with Listaller
+dnl ---------------------------------------------------------------------------
+LISTALLER_REQUIRED=0.5.7
+AC_ARG_ENABLE(listaller, AS_HELP_STRING([--enable-listaller],[Build with Listaller support]),
+             enable_listaller=$enableval,enable_listaller=yes)
+if test x$enable_listaller = xyes; then
+       PKG_CHECK_MODULES(LISTALLER, listaller-glib >= $LISTALLER_REQUIRED,,
+                               [AC_MSG_ERROR([Can't find Listaller -- please install 
Listaller>=$LISTALLER_REQUIRED!])])
+       PKG_CHECK_MODULES(GEE, gee-1.0 >= 0.6,,
+                               [AC_MSG_ERROR([Can't find Gee -- please install libgee to continue!])])
+fi
+AM_CONDITIONAL(HAVE_LISTALLER, test $enable_listaller = "yes")
+
+dnl ---------------------------------------------------------------------------
 dnl systemd integration
 dnl ---------------------------------------------------------------------------
 AC_ARG_ENABLE([systemd],
diff --git a/data/Makefile.am b/data/Makefile.am
index 315ce52..050d20f 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -33,6 +33,7 @@ pkgdata_DATA =                                                \
        gpk-error.ui                                    \
        gpk-log.ui                                      \
        gpk-client.ui                                   \
+       gpk-install-local.ui                            \
        $(NULL)
 
 servicedir = $(datadir)/dbus-1/services
diff --git a/data/gpk-install-local.ui b/data/gpk-install-local.ui
index 1c1d009..c6d654f 100644
--- a/data/gpk-install-local.ui
+++ b/data/gpk-install-local.ui
@@ -3,25 +3,71 @@
   <!-- interface-requires gtk+ 3.0 -->
   <object class="GtkWindow" id="window_install">
     <property name="can_focus">False</property>
+    <property name="margin_left">4</property>
+    <property name="margin_right">4</property>
+    <property name="margin_top">4</property>
+    <property name="margin_bottom">4</property>
     <property name="title" translatable="yes">Install package</property>
     <property name="modal">True</property>
+    <property name="window_position">center</property>
     <property name="icon_name">system-software-update</property>
     <child>
-      <object class="GtkBox" id="box1">
+      <object class="GtkPaned" id="paned1">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
         <child>
-          <object class="GtkBox" id="box2">
+          <object class="GtkTreeView" id="treeview1">
+            <property name="width_request">94</property>
             <property name="visible">True</property>
             <property name="can_focus">False</property>
+            <child internal-child="selection">
+              <object class="GtkTreeSelection" id="treeview-selection1"/>
+            </child>
+          </object>
+          <packing>
+            <property name="resize">False</property>
+            <property name="shrink">True</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="box1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">2</property>
             <child>
-              <object class="GtkImage" id="image_app">
+              <object class="GtkBox" id="box2">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="pixel_size">64</property>
-                <property name="icon_name">package-x-generic</property>
+                <property name="spacing">4</property>
+                <child>
+                  <object class="GtkImage" id="image_app">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="pixel_size">64</property>
+                    <property name="icon_name">package-x-generic</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label_appname">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Package Name</property>
+                    <attributes>
+                      <attribute name="scale" value="1.5"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -30,153 +76,140 @@
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label_appname">
+              <object class="GtkLabel" id="label_description">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Package Name</property>
-                <attributes>
-                  <attribute name="scale" value="1.5"/>
-                </attributes>
+                <property name="label" translatable="yes">Package description</property>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
+                <property name="padding">2</property>
                 <property name="position">1</property>
               </packing>
             </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label_description">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes">Package description</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkFrame" id="frame_security">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label_xalign">0</property>
-            <property name="shadow_type">none</property>
             <child>
-              <object class="GtkAlignment" id="alignment1">
+              <object class="GtkFrame" id="frame_security">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="left_padding">12</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
                 <child>
-                  <object class="GtkBox" id="box3">
+                  <object class="GtkAlignment" id="alignment1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
+                    <property name="left_padding">12</property>
                     <child>
-                      <object class="GtkImage" id="image_security">
+                      <object class="GtkBox" id="box3">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="pixel_size">48</property>
-                        <property name="icon_name">security-low</property>
+                        <child>
+                          <object class="GtkImage" id="image_security">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="pixel_size">48</property>
+                            <property name="icon_name">security-low</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label_secinfo_text">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">Security info text.</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
                       </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="label_secinfo_text">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Security info text.</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
                     </child>
                   </object>
                 </child>
-              </object>
-            </child>
-            <child type="label">
-              <object class="GtkLabel" id="label_secinfo">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">&lt;b&gt;Security details&lt;/b&gt;</property>
-                <property name="use_markup">True</property>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkButtonBox" id="dialog-action_area1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="button_help">
-                <property name="label">gtk-help</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-                <property name="secondary">True</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button_close">
-                <property name="label">gtk-close</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
+                <child type="label">
+                  <object class="GtkLabel" id="label_secinfo">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Security details&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="pack_type">end</property>
-                <property name="position">1</property>
+                <property name="fill">True</property>
+                <property name="padding">4</property>
+                <property name="position">2</property>
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="button_install">
-                <property name="label" translatable="yes">Install now</property>
+              <object class="GtkButtonBox" id="dialog-action_area1">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
+                <property name="can_focus">False</property>
+                <property name="layout_style">end</property>
+                <child>
+                  <object class="GtkButton" id="button_help">
+                    <property name="label">gtk-help</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_stock">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                    <property name="secondary">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button_close">
+                    <property name="label">gtk-close</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_stock">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="pack_type">end</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button_install">
+                    <property name="label" translatable="yes">Install now</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="pack_type">end</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
-                <property name="fill">False</property>
+                <property name="fill">True</property>
+                <property name="padding">6</property>
                 <property name="pack_type">end</property>
-                <property name="position">2</property>
+                <property name="position">3</property>
               </packing>
             </child>
           </object>
           <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">3</property>
+            <property name="resize">True</property>
+            <property name="shrink">True</property>
           </packing>
         </child>
       </object>
diff --git a/src/gpk-install-local-file.c b/src/gpk-install-local-file.c
index 7498f1b..2f1bd38 100644
--- a/src/gpk-install-local-file.c
+++ b/src/gpk-install-local-file.c
@@ -1,6 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
  * Copyright (C) 2007-2008 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2012-2013 Matthias Klumpp <matthias tenstral net>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -19,18 +20,143 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
-#include <glib.h>
 #include <glib/gi18n.h>
-#include <gtk/gtk.h>
 #include <locale.h>
+#include <gtk/gtk.h>
+#include <packagekit-glib2/packagekit.h>
 #include <dbus/dbus-glib.h>
 
 #include "gpk-common.h"
-#include "gpk-error.h"
-#include "gpk-dbus.h"
 #include "gpk-debug.h"
+#include "gpk-enum.h"
+#include "gpk-error.h"
+#include "gpk-gnome.h"
+
+typedef struct {
+       GCancellable            *cancellable;
+       GtkApplication          *application;
+       GSettings               *settings_gpk;
+       GtkBuilder              *builder;
+       GtkWidget               *main_window;
+       gchar                   **files;
+} GpkInstallLocalPrivate;
+
+/**
+ * gpk_install_local_help_cb:
+ **/
+static void
+gpk_install_local_run_installation_cb (GtkWidget *widget, GpkInstallLocalPrivate *priv)
+{
+       gboolean ret;
+       GError *error = NULL;
+       DBusGConnection *connection;
+       DBusGProxy *proxy = NULL;
+
+       /* check dbus connections, exit if not valid */
+       connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+       if (connection == NULL) {
+               g_warning ("%s", error->message);
+               goto out;
+       }
+
+       /* get a connection */
+       proxy = dbus_g_proxy_new_for_name (connection,
+                                          "org.freedesktop.PackageKit",
+                                          "/org/freedesktop/PackageKit",
+                                          "org.freedesktop.PackageKit.Modify");
+       if (proxy == NULL) {
+               g_warning ("Cannot connect to session service");
+               goto out;
+       }
+
+       /* don't timeout, as dbus-glib sets the timeout ~25 seconds */
+       dbus_g_proxy_set_default_timeout (proxy, INT_MAX);
+
+       /* hide the application main window (UI is provided by the session-installer now) */
+       gtk_widget_hide (priv->main_window);
+
+       /* do method */
+       ret = dbus_g_proxy_call (proxy, "InstallPackageFiles", &error,
+                                G_TYPE_UINT, 0, /* xid */
+                                G_TYPE_STRV, priv->files, /* data */
+                                G_TYPE_STRING, "hide-finished,show-warnings", /* interaction */
+                                G_TYPE_INVALID,
+                                G_TYPE_INVALID);
+       if (!ret) {
+               g_warning ("%s", error->message);
+               goto out;
+       }
+out:
+       if (error != NULL)
+               g_error_free (error);
+       if (proxy != NULL)
+               g_object_unref (proxy);
+
+       /* quit application */
+       g_application_release (G_APPLICATION (priv->application));
+}
+
+/**
+ * gpk_install_local_help_cb:
+ **/
+static void
+gpk_install_local_help_cb (GtkWidget *widget, GpkInstallLocalPrivate *priv)
+{
+       gpk_gnome_help ("install-files");
+}
+
+/**
+ * gpk_install_local_close_cb:
+ **/
+static void
+gpk_install_local_close_cb (GtkWidget *widget, gpointer data)
+{
+       GpkInstallLocalPrivate *priv = (GpkInstallLocalPrivate *) data;
+       g_application_release (G_APPLICATION (priv->application));
+}
+
+/**
+ * gpk_install_local_startup_cb:
+ **/
+static void
+gpk_install_local_startup_cb (GtkApplication *application, GpkInstallLocalPrivate *priv)
+{
+       GError *error = NULL;
+
+       GtkWidget *widget;
+       guint retval;
+
+       /* add application specific icons to search path */
+       gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
+                                          GPK_DATA G_DIR_SEPARATOR_S "icons");
+
+       /* get UI */
+       retval = gtk_builder_add_from_file (priv->builder, GPK_DATA "/gpk-install-local.ui", &error);
+       if (retval == 0) {
+               g_warning ("failed to load ui: %s", error->message);
+               g_error_free (error);
+               return;
+       }
+
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_close"));
+       g_signal_connect (widget, "clicked",
+                         G_CALLBACK (gpk_install_local_close_cb), priv);
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_help"));
+       g_signal_connect (widget, "clicked",
+                         G_CALLBACK (gpk_install_local_help_cb), priv);
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_install"));
+       g_signal_connect (widget, "clicked",
+                         G_CALLBACK (gpk_install_local_run_installation_cb), priv);
+
+       priv->main_window = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_install"));
+       gtk_application_add_window (application, GTK_WINDOW (priv->main_window));
+
+       gtk_widget_show (priv->main_window);
+}
 
 /**
  * main:
@@ -40,11 +166,9 @@ main (int argc, char *argv[])
 {
        GOptionContext *context;
        gboolean ret;
-       GError *error = NULL;
+       gint status = 0;
        gchar **files = NULL;
-       DBusGConnection *connection;
-       DBusGProxy *proxy = NULL;
-
+       GpkInstallLocalPrivate *priv = NULL;
        const GOptionEntry options[] = {
                { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
                  /* TRANSLATORS: command line option: a list of files to install */
@@ -72,53 +196,44 @@ main (int argc, char *argv[])
 
        /* TRANSLATORS: title to pass to to the user if there are not enough privs */
        ret = gpk_check_privileged_user (_("Local file installer"), TRUE);
+       status = !ret;
        if (!ret)
                goto out;
 
        if (files == NULL) {
-               /* TRANSLATORS: could not install a package that contained the file we wanted */
-               gpk_error_dialog (_("Failed to install a package to provide a file"),
+               /* TRANSLATORS: could not install a package file */
+               gpk_error_dialog (_("Failed to install a package file"),
                                  /* TRANSLATORS: nothing selected */
                                  _("You need to specify a file to install"), NULL);
+               status = 1;
                goto out;
        }
 
-       /* check dbus connections, exit if not valid */
-       connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-       if (connection == NULL) {
-               g_warning ("%s", error->message);
-               goto out;
-       }
+       priv = g_new0 (GpkInstallLocalPrivate, 1);
+       priv->cancellable = g_cancellable_new ();
+       priv->builder = gtk_builder_new ();
+       priv->settings_gpk = g_settings_new (GPK_SETTINGS_SCHEMA);
+       priv->files = files;
 
-       /* get a connection */
-       proxy = dbus_g_proxy_new_for_name (connection,
-                                          "org.freedesktop.PackageKit",
-                                          "/org/freedesktop/PackageKit",
-                                          "org.freedesktop.PackageKit.Modify");
-       if (proxy == NULL) {
-               g_warning ("Cannot connect to session service");
-               goto out;
-       }
+       /* are we already activated? */
+       priv->application = gtk_application_new ("org.freedesktop.PackageKit.LocalInstaller",
+                                                G_APPLICATION_NON_UNIQUE);
+       g_signal_connect (priv->application, "startup",
+                         G_CALLBACK (gpk_install_local_startup_cb), priv);
 
-       /* don't timeout, as dbus-glib sets the timeout ~25 seconds */
-       dbus_g_proxy_set_default_timeout (proxy, INT_MAX);
+       /* run */
+       status = g_application_run (G_APPLICATION (priv->application), argc, argv);
 
-       /* do method */
-       ret = dbus_g_proxy_call (proxy, "InstallPackageFiles", &error,
-                                G_TYPE_UINT, 0, /* xid */
-                                G_TYPE_STRV, files, /* data */
-                                G_TYPE_STRING, "hide-finished,show-warnings", /* interaction */
-                                G_TYPE_INVALID,
-                                G_TYPE_INVALID);
-       if (!ret) {
-               g_warning ("%s", error->message);
-               goto out;
+       if (priv != NULL) {
+               g_cancellable_cancel (priv->cancellable);
+               g_object_unref (priv->cancellable);
+               g_object_unref (priv->builder);
+               g_object_unref (priv->settings_gpk);
+               g_free (priv);
        }
+
 out:
-       if (error != NULL)
-               g_error_free (error);
-       if (proxy != NULL)
-               g_object_unref (proxy);
        g_strfreev (files);
-       return !ret;
+
+       return status;
 }


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