← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~mterry/indicator-datetime/gtk3-again into lp:indicator-datetime

 

Michael Terry has proposed merging lp:~mterry/indicator-datetime/gtk3-again into lp:indicator-datetime.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)

For more details, see:
https://code.launchpad.net/~mterry/indicator-datetime/gtk3-again/+merge/64697

The existing GTK 3 port was a bit incomplete.  It still used libpolkit-gtk which was GTK 2 only.  And it needlessly allowed you to compile the daemon/prefs dialog either way.

Here's a port to finish that up, including having daemon and prefs be GTK 3 only, and only allow switching whether the indicator itself is GTK 2.

This involved porting from libpolkit-gtk's PolkitButton to GTK 3.1.4's GtkLockButton as well as some odds and ends.
-- 
https://code.launchpad.net/~mterry/indicator-datetime/gtk3-again/+merge/64697
Your team ayatana-commits is subscribed to branch lp:indicator-datetime.
=== modified file 'configure.ac'
--- configure.ac	2011-04-14 19:34:15 +0000
+++ configure.ac	2011-06-15 14:48:33 +0000
@@ -43,9 +43,9 @@
 
 AC_ARG_WITH([gtk],
   [AS_HELP_STRING([--with-gtk],
-    [Which version of gtk to use @<:@default=2@:>@])],
+    [Which version of gtk to use for the indicator @<:@default=3@:>@])],
   [],
-  [with_gtk=2])
+  [with_gtk=3])
 
 ###########################
 # Dependencies
@@ -55,7 +55,6 @@
 DBUSMENUGLIB_REQUIRED_VERSION=0.1.1
 DBUSMENUGTK_REQUIRED_VERSION=0.3.94
 GIO_REQUIRED_VERSION=2.25.11
-# Note: the GIO check below also ensures the proper glib with gsettings support is present
 INDICATOR_DISPLAY_OBJECTS=0.2.2
 GEOCLUE_REQUIRED_VERSION=0.12.0
 ECAL_REQUIRED_VERSION=2.30
@@ -64,8 +63,7 @@
 CAIRO_REQUIRED_VERSION=1.10
 GDK_REQUIRED_VERSION=2.22
 GLIB_REQUIRED_VERSION=2.26
-GTK_REQUIRED_VERSION=2.12
-GTK3_REQUIRED_VERSION=3.0
+GTK3_REQUIRED_VERSION=3.1.4
 GCONF_REQUIRED_VERSION=2.31
 
 AS_IF([test "x$with_gtk" = x3],
@@ -85,69 +83,30 @@
     [AC_MSG_FAILURE([Value for --with-gtk was neither 2 nor 3])]
 )
 
-AS_IF([test "x$with_gtk" = x3],
-	[PKG_CHECK_MODULES(SERVICE,  indicator >= $INDICATOR_REQUIRED_VERSION
-                                 glib-2.0 >= $GLIB_REQUIRED_VERSION
-	                             dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION
-                                 dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION
-	                             libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS
-	                             gio-2.0 >= $GIO_REQUIRED_VERSION
-	                             geoclue >= $GEOCLUE_REQUIRED_VERSION
-	                             libecal-1.2 >= $ECAL_REQUIRED_VERSION
-	                             libical >= $ICAL_REQUIRED_VERSION
-	                             libedataserver-1.2 >= EDS_REQUIRED_VERSION
-	                             libedataserverui-1.2 >= EDS_REQUIRED_VERSION
-	                             cairo >= CAIRO_REQUIRED_VERSION
-	                             gdk-2.0 >= GDK_REQUIRED_VERSION
-	                             gconf-2.0 >= GCONF_REQUIRED_VERSION)
-		],
-      [test "x$with_gtk" = x2],
-	[PKG_CHECK_MODULES(SERVICE,  indicator >= $INDICATOR_REQUIRED_VERSION
-                                 glib-2.0 >= $GLIB_REQUIRED_VERSION
-	                             dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION
-                                 dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION
-	                             libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS
-	                             gio-2.0 >= $GIO_REQUIRED_VERSION
-	                             geoclue >= $GEOCLUE_REQUIRED_VERSION
-	                             libecal-1.2 >= $ECAL_REQUIRED_VERSION
-	                             libical >= $ICAL_REQUIRED_VERSION
-	                             libedataserver-1.2 >= EDS_REQUIRED_VERSION
-	                             libedataserverui-1.2 >= EDS_REQUIRED_VERSION
-	                             cairo >= CAIRO_REQUIRED_VERSION
-	                             gdk-2.0 >= GDK_REQUIRED_VERSION
-	                             gconf-2.0 >= GCONF_REQUIRED_VERSION)
-        ],
-    [AC_MSG_FAILURE([Value for --with-gtk was neither 2 nor 3])]
-)
-
-# FIXME: polkit-gtk-1 isn't gtk3-compatible
-AS_IF([test "x$with_gtk" = x3],
-	[PKG_CHECK_MODULES(PREF, gio-2.0 >= $GIO_REQUIRED_VERSION
-	                         gtk+-3.0 >= $GTK3_REQUIRED_VERSION
-                                 unique-3.0
-                                 json-glib-1.0
-                                 polkit-gtk-1)
-		],
-      [test "x$with_gtk" = x2],
-	[PKG_CHECK_MODULES(PREF, gio-2.0 >= $GIO_REQUIRED_VERSION
-	                         gtk+-2.0 >= $GTK_REQUIRED_VERSION
-                                 unique-1.0
-                                 json-glib-1.0
-                                 polkit-gtk-1)
-        ],
-    [AC_MSG_FAILURE([Value for --with-gtk was neither 2 nor 3])]
-)
-
-AS_IF([test "x$with_gtk" = x3],
-	[PKG_CHECK_MODULES(LIBMAP, gio-2.0 >= $GIO_REQUIRED_VERSION
-	                           gtk+-3.0 >= $GTK3_REQUIRED_VERSION)
-		],
-      [test "x$with_gtk" = x2],
-	[PKG_CHECK_MODULES(LIBMAP, gio-2.0 >= $GIO_REQUIRED_VERSION
-	                           gtk+-2.0 >= $GTK_REQUIRED_VERSION)
-        ],
-    [AC_MSG_FAILURE([Value for --with-gtk was neither 2 nor 3])]
-)
+PKG_CHECK_MODULES(SERVICE, indicator3 >= $INDICATOR_REQUIRED_VERSION
+                           glib-2.0 >= $GLIB_REQUIRED_VERSION
+                           dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION
+                           dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION
+                           libido3-0.1 >= $INDICATOR_DISPLAY_OBJECTS
+                           gio-2.0 >= $GIO_REQUIRED_VERSION
+                           geoclue >= $GEOCLUE_REQUIRED_VERSION
+                           libecal-1.2 >= $ECAL_REQUIRED_VERSION
+                           libical >= $ICAL_REQUIRED_VERSION
+                           libedataserver-1.2 >= EDS_REQUIRED_VERSION
+                           libedataserverui-3.0 >= EDS_REQUIRED_VERSION
+                           cairo >= CAIRO_REQUIRED_VERSION
+                           gdk-3.0 >= GDK_REQUIRED_VERSION
+                           gconf-2.0 >= GCONF_REQUIRED_VERSION)
+
+PKG_CHECK_MODULES(PREF, gio-2.0 >= $GIO_REQUIRED_VERSION
+	                      gtk+-3.0 >= $GTK3_REQUIRED_VERSION
+	                      unique-3.0
+	                      json-glib-1.0
+	                      polkit-gobject-1)
+
+PKG_CHECK_MODULES(LIBMAP, gio-2.0 >= $GIO_REQUIRED_VERSION
+                          gtk+-3.0 >= $GTK3_REQUIRED_VERSION)
+
 AC_SUBST(INDICATOR_CFLAGS)
 AC_SUBST(INDICATOR_LIBS)
 

=== modified file 'libmap/cc-timezone-map.c'
--- libmap/cc-timezone-map.c	2011-03-29 16:14:40 +0000
+++ libmap/cc-timezone-map.c	2011-06-15 14:48:33 +0000
@@ -601,7 +601,6 @@
 }
 
 /* GtkWidget functions */
-#ifdef CCGTK3
 static void
 cc_timezone_map_get_preferred_width (GtkWidget *widget,
                                      gint      *minimum,
@@ -634,25 +633,6 @@
     *natural = size;
 }
 
-#else
-
-static void
-cc_timezone_map_size_request (GtkWidget *widget,
-                              GtkRequisition *requisition)
-{
-  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
-
-  if (!requisition)
-    return;
-
-  /* The + 20 here is a slight tweak to make the map fill the
-   * panel better without causing horizontal growing
-   */
-  requisition->height = 300 * gdk_pixbuf_get_height (priv->orig_background) / gdk_pixbuf_get_width (priv->orig_background) + 20;
-  requisition->width = 300;
-}
-#endif
-
 static void
 cc_timezone_map_size_allocate (GtkWidget     *widget,
                                GtkAllocation *allocation)
@@ -853,21 +833,6 @@
   return TRUE;
 }
 
-#ifndef CCGTK3
-static gboolean
-cc_timezone_map_expose_event (GtkWidget *widget,
-                              GdkEventExpose  *event)
-{
-  gboolean   rv;
-  cairo_t   *cr;
-  cr = gdk_cairo_create (widget->window);
-  rv = cc_timezone_map_draw (widget, cr);
-  cairo_destroy (cr);
-  return rv;
-}
-#endif
-
-
 static void
 cc_timezone_map_class_init (CcTimezoneMapClass *klass)
 {
@@ -881,19 +846,11 @@
   object_class->dispose = cc_timezone_map_dispose;
   object_class->finalize = cc_timezone_map_finalize;
 
-#ifdef CCGTK3
   widget_class->get_preferred_width = cc_timezone_map_get_preferred_width;
   widget_class->get_preferred_height = cc_timezone_map_get_preferred_height;
-#else
-  widget_class->size_request = cc_timezone_map_size_request;
-#endif
   widget_class->size_allocate = cc_timezone_map_size_allocate;
   widget_class->realize = cc_timezone_map_realize;
-#ifdef CCGTK3
   widget_class->draw = cc_timezone_map_draw;
-#else
-  widget_class->expose_event = cc_timezone_map_expose_event;
-#endif
 
   signals[LOCATION_CHANGED] = g_signal_new ("location-changed",
                                             CC_TYPE_TIMEZONE_MAP,
@@ -1015,6 +972,13 @@
 }
 
 static void
+state_flags_changed (GtkWidget *widget)
+{
+  // To catch sensitivity changes
+  gtk_widget_queue_draw (widget);
+}
+
+static void
 load_backward_tz (CcTimezoneMap *self)
 {
   GError *error = NULL;
@@ -1108,6 +1072,8 @@
 
   g_signal_connect (self, "button-press-event", G_CALLBACK (button_press_event),
                     NULL);
+  g_signal_connect (self, "state-flags-changed", G_CALLBACK (state_flags_changed),
+                    NULL);
 
   load_backward_tz (self);
 }

=== modified file 'src/datetime-prefs.c'
--- src/datetime-prefs.c	2011-04-07 15:48:50 +0000
+++ src/datetime-prefs.c	2011-06-15 14:48:33 +0000
@@ -33,7 +33,7 @@
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 #include <unique/unique.h>
-#include <polkitgtk/polkitgtk.h>
+#include <polkit/polkit.h>
 
 #include "dbus-shared.h"
 #include "settings-shared.h"
@@ -115,23 +115,49 @@
 }
 
 static void
-polkit_dependency_cb (GtkWidget * parent, GParamSpec *pspec, GtkWidget * dependent)
-{
-  gboolean authorized, sensitive;
-  g_object_get (G_OBJECT (parent),
-                "is-authorized", &authorized,
-                "sensitive", &sensitive, NULL);
-  gtk_widget_set_sensitive (dependent, authorized && sensitive);
+polkit_dependency_cb (GPermission * permission, GParamSpec *pspec, GtkWidget * dependent)
+{
+  gboolean allowed = FALSE;
+
+  g_object_get (G_OBJECT (permission),
+                "allowed", &allowed, NULL);
+
+  gtk_widget_set_sensitive (dependent, allowed);
+}
+
+static void
+add_polkit_dependency_helper (GtkWidget * parent, GParamSpec *pspec, GtkWidget * dependent)
+{
+  GtkLockButton * button = GTK_LOCK_BUTTON (parent);
+  GPermission * permission = gtk_lock_button_get_permission (button);
+  g_signal_connect (permission, "notify::allowed",
+                    G_CALLBACK(polkit_dependency_cb), dependent);
+  polkit_dependency_cb (permission, NULL, dependent);
 }
 
 static void
 add_polkit_dependency (GtkWidget * parent, GtkWidget * dependent)
 {
-  g_signal_connect (parent, "notify::is-authorized", G_CALLBACK(polkit_dependency_cb),
-                    dependent);
-  g_signal_connect (parent, "notify::sensitive", G_CALLBACK(polkit_dependency_cb),
-                    dependent);
-  polkit_dependency_cb (parent, NULL, dependent);
+  /* polkit async hasn't finished at this point, so wait for permission to come in */
+  g_signal_connect (parent, "notify::permission", G_CALLBACK(add_polkit_dependency_helper),
+                    dependent);
+  gtk_widget_set_sensitive (dependent, FALSE);
+}
+
+static void
+polkit_perm_ready (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  GError * error = NULL;
+  GPermission * permission = polkit_permission_new_finish (res, &error);
+
+  if (error != NULL) {
+    g_warning ("Could not get permission object: %s", error->message);
+    g_error_free (error);
+    return;
+  }
+
+  GtkLockButton * button = GTK_LOCK_BUTTON (user_data);
+  gtk_lock_button_set_permission (button, permission);
 }
 
 static void
@@ -594,21 +620,6 @@
 }
 
 static GtkWidget *
-get_child_of_type (GtkContainer * parent, GType type)
-{
-  GList * children, * iter;
-
-  children = gtk_container_get_children (parent);
-  for (iter = children; iter; iter = iter->next) {
-    if (G_TYPE_CHECK_INSTANCE_TYPE (iter->data, type)) {
-      return GTK_WIDGET (iter->data);
-    }
-  }
-
-  return NULL;
-}
-
-static GtkWidget *
 create_dialog (void)
 {
   GError * error = NULL;
@@ -629,15 +640,17 @@
 #define WIG(name) GTK_WIDGET (gtk_builder_get_object (builder, name))
 
   /* Add policykit button */
-  GtkWidget * polkit_button = polkit_lock_button_new ("org.gnome.settingsdaemon.datetimemechanism.configure");
-  polkit_lock_button_set_unlock_text (POLKIT_LOCK_BUTTON (polkit_button), _("Unlock to change these settings"));
-  polkit_lock_button_set_lock_text (POLKIT_LOCK_BUTTON (polkit_button), _("Lock to prevent further changes"));
-  gtk_box_pack_start (GTK_BOX (WIG ("timeDateBox")), polkit_button, FALSE, TRUE, 0);
-  /* Make sure border around button is visible */
-  GtkWidget * polkit_button_button = get_child_of_type (GTK_CONTAINER (polkit_button), GTK_TYPE_BUTTON);
-  if (polkit_button_button != NULL) {
-    gtk_button_set_relief (GTK_BUTTON (polkit_button_button), GTK_RELIEF_NORMAL);
-  }
+  GtkWidget * polkit_button = gtk_lock_button_new (NULL);
+  g_object_set (G_OBJECT (polkit_button),
+                "text-unlock", _("Unlock to change these settings"),
+                "text-lock", _("Lock to prevent further changes"),
+                NULL);
+  GtkWidget * alignment = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
+  gtk_container_add (GTK_CONTAINER (alignment), polkit_button);
+  gtk_box_pack_start (GTK_BOX (WIG ("timeDateBox")), alignment, FALSE, TRUE, 0);
+
+  const gchar * polkit_name = "org.gnome.settingsdaemon.datetimemechanism.configure";
+  polkit_permission_new (polkit_name, NULL, NULL, polkit_perm_ready, polkit_button);
 
   /* Add map */
   tzmap = cc_timezone_map_new ();

=== modified file 'src/timezone-completion.c'
--- src/timezone-completion.c	2011-04-06 21:52:08 +0000
+++ src/timezone-completion.c	2011-06-15 14:48:33 +0000
@@ -455,9 +455,9 @@
 static gboolean
 entry_keypress (GtkEntry * entry, GdkEventKey  *event, TimezoneCompletion * completion)
 {
-  if (event->keyval == GDK_ISO_Enter ||
-      event->keyval == GDK_KP_Enter ||
-	    event->keyval == GDK_Return) {
+  if (event->keyval == GDK_KEY_ISO_Enter ||
+      event->keyval == GDK_KEY_KP_Enter ||
+	    event->keyval == GDK_KEY_Return) {
     /* Make sure that user has a selection to choose, otherwise ignore */
     GtkTreeModel * model = gtk_entry_completion_get_model (GTK_ENTRY_COMPLETION (completion));
     GtkTreeView * view = find_popup_treeview (GTK_WIDGET (entry), model);


Follow ups