Merge lp:~charlesk/ido/switch into lp:ido/12.10

Proposed by Charles Kerr
Status: Merged
Approved by: Charles Kerr
Approved revision: 118
Merged at revision: 110
Proposed branch: lp:~charlesk/ido/switch
Merge into: lp:ido/12.10
Diff against target: 294 lines (+199/-5)
6 files modified
NEWS (+2/-0)
configure.ac (+9/-5)
example/menus.c (+8/-0)
src/Makefile.am (+3/-0)
src/idoswitchmenuitem.c (+120/-0)
src/idoswitchmenuitem.h (+57/-0)
To merge this branch: bzr merge lp:~charlesk/ido/switch
Reviewer Review Type Date Requested Status
jenkins (community) continuous-integration Needs Fixing
Lars Karlitski (community) Approve
Sebastien Bacher Needs Fixing
Review via email: mp+120621@code.launchpad.net

Description of the change

Adds the GtkSwitchMenuItem

To post a comment you must log in.
Revision history for this message
jenkins (martin-mrazik+qa) wrote :

FAILED: Continuous integration, rev:110
http://jenkins.qa.ubuntu.com/job/ido-ci/5/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/ido-ci/./label=quantal/5/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Sebastien Bacher (seb128) wrote :

seems mostly fine to me, small comment, you use g_object_clear(), you should add a glib >= 2.28 check in configure

review: Needs Fixing
Revision history for this message
jenkins (martin-mrazik+qa) wrote :

FAILED: Continuous integration, rev:111
http://jenkins.qa.ubuntu.com/job/ido-ci/6/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/ido-ci/./label=quantal/6/console

review: Needs Fixing (continuous-integration)
Revision history for this message
jenkins (martin-mrazik+qa) wrote :

FAILED: Continuous integration, rev:112
http://jenkins.qa.ubuntu.com/job/ido-ci/7/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/ido-ci/./label=quantal/7/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

Nice hack!

Three problems:

(1) the mouse capture isn't removed after the menu is closed
(2) the menu title is still painted as if the menu was open
(3) the switch handle can also be dragged, this doesn't work in the menu item

I tried for a little bit, but I haven't found a satisfactory solution for (1) and (2) yet. (3) can be solved by forwarding mouse button events from the menu item to the widget (cf. IdoScaleMenuItem).

The get_content_area API is a bit weird. Do we need to put anything other than a label in there?

Also, there's no need to keep the GBinding object around, it will be destroyed automatically.

Revision history for this message
jenkins (martin-mrazik+qa) wrote :

FAILED: Continuous integration, rev:115
http://jenkins.qa.ubuntu.com/job/ido-ci/8/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/ido-ci/./label=quantal/8/console

review: Needs Fixing (continuous-integration)
Revision history for this message
jenkins (martin-mrazik+qa) wrote :

FAILED: Continuous integration, rev:116
http://jenkins.qa.ubuntu.com/job/ido-ci/9/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/ido-ci/./label=quantal/9/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

Approved, but please file a bug with the unfinished event propagation patches so that we don't lose the work you've already done.

review: Approve
Revision history for this message
jenkins (martin-mrazik+qa) wrote :

FAILED: Continuous integration, rev:117
http://jenkins.qa.ubuntu.com/job/ido-ci/10/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/ido-ci/./label=quantal/10/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

event propagation's been filed in a new ticket at Bug #1039840

the CI build is failing because of the gtk2 build in the debian rules, seb128 is working on that.

Revision history for this message
jenkins (martin-mrazik+qa) wrote :

FAILED: Continuous integration, rev:118
http://jenkins.qa.ubuntu.com/job/ido-ci/11/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/ido-ci/./label=quantal/11/console

review: Needs Fixing (continuous-integration)
Revision history for this message
jenkins (martin-mrazik+qa) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
http://jenkins.qa.ubuntu.com/job/ido-autolanding/5/

review: Needs Fixing (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

Thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-01-19 22:02:50 +0000
3+++ NEWS 2012-08-22 01:08:21 +0000
4@@ -0,0 +1,2 @@
5+12.10.0:
6+ * new widget IdoSwitchMenuItem
7
8=== modified file 'configure.ac'
9--- configure.ac 2012-04-25 20:24:26 +0000
10+++ configure.ac 2012-08-22 01:08:21 +0000
11@@ -1,9 +1,9 @@
12 #
13 # shamelessly stolen from clutter-gtk
14 #
15-m4_define([ido_major_version], [0])
16-m4_define([ido_minor_version], [3])
17-m4_define([ido_micro_version], [4])
18+m4_define([ido_major_version], [12])
19+m4_define([ido_minor_version], [10])
20+m4_define([ido_micro_version], [0])
21
22 m4_define([ido_api_version],
23 [ido_major_version.ido_minor_version])
24@@ -78,6 +78,8 @@
25 AC_FUNC_MMAP
26 AC_CHECK_FUNCS([memset munmap strcasecmp strdup])
27
28+GLIB_REQUIRED_VERSION=2.32.0
29+
30 AC_ARG_WITH([gtk],
31 [AS_HELP_STRING([--with-gtk],
32 [Which version of gtk to use @<:@default=3@:>@])],
33@@ -86,9 +88,11 @@
34 AM_CONDITIONAL(USE_GTK3, [test "x$with_gtk" = x3])
35
36 if test "x$with_gtk" = "x2"; then
37- PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.19.7)
38+ PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.19.7
39+ glib-2.0 >= GLIB_REQUIRED_VERSION])
40 else
41- PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.0.0)
42+ PKG_CHECK_MODULES(GTK, [gtk+-3.0 >= 3.0.0
43+ glib-2.0 >= GLIB_REQUIRED_VERSION])
44 AC_DEFINE_UNQUOTED(USE_GTK3, , [Use GTK3])
45 fi
46 AC_SUBST(GTK_CFLAGS)
47
48=== modified file 'example/menus.c'
49--- example/menus.c 2011-12-14 17:19:26 +0000
50+++ example/menus.c 2012-08-22 01:08:21 +0000
51@@ -3,6 +3,7 @@
52 #include "idoscalemenuitem.h"
53 #include "idocalendarmenuitem.h"
54 #include "idoentrymenuitem.h"
55+#include "idoswitchmenuitem.h"
56 #include "config.h"
57
58 static void
59@@ -27,6 +28,7 @@
60 GtkWidget *root;
61 GtkWidget *menubar;
62 GtkWidget *image;
63+ GtkWidget *label;
64
65 g_unsetenv ("UBUNTU_MENUPROXY");
66
67@@ -76,6 +78,12 @@
68 menuitem = ido_entry_menu_item_new ();
69 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
70
71+ menuitem = ido_switch_menu_item_new ();
72+ label = gtk_label_new ("This is a switch");
73+ gtk_widget_show(label);
74+ gtk_container_add (ido_switch_menu_item_get_content_area(IDO_SWITCH_MENU_ITEM(menuitem)), label);
75+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
76+
77 menuitem = ido_calendar_menu_item_new ();
78 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
79
80
81=== modified file 'src/Makefile.am'
82--- src/Makefile.am 2012-04-12 15:18:01 +0000
83+++ src/Makefile.am 2012-08-22 01:08:21 +0000
84@@ -19,6 +19,7 @@
85 idomessagedialog.h \
86 idorange.h \
87 idoscalemenuitem.h \
88+ idoswitchmenuitem.h \
89 idotimeline.h \
90 libido.h
91
92@@ -67,6 +68,7 @@
93 idomessagedialog.c \
94 idorange.c \
95 idoscalemenuitem.c \
96+ idoswitchmenuitem.c \
97 idotimeline.c
98
99 libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES)
100@@ -79,6 +81,7 @@
101 idomessagedialog.h \
102 idorange.h \
103 idoscalemenuitem.h \
104+ idoswitchmenuitem.h \
105 idotimeline.h \
106 libido.h
107
108
109=== added file 'src/idoswitchmenuitem.c'
110--- src/idoswitchmenuitem.c 1970-01-01 00:00:00 +0000
111+++ src/idoswitchmenuitem.c 2012-08-22 01:08:21 +0000
112@@ -0,0 +1,120 @@
113+/*
114+ * A GtkCheckMenuItem that uses a GtkSwitch to show its 'active' property
115+ *
116+ * Copyright © 2012 Canonical Ltd.
117+ *
118+ * This program is free software: you can redistribute it and/or modify it
119+ * under the terms of the GNU General Public License version 3, as
120+ * published by the Free Software Foundation.
121+ *
122+ * This program is distributed in the hope that it will be useful, but
123+ * WITHOUT ANY WARRANTY; without even the implied warranties of
124+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
125+ * PURPOSE. See the GNU General Public License for more details.
126+ *
127+ * You should have received a copy of the GNU General Public License along
128+ * with this program. If not, see <http://www.gnu.org/licenses/>.
129+ *
130+ * Author: Charles Kerr <charles.kerr@canonical.com>
131+ */
132+
133+#include "config.h"
134+
135+#include "idoswitchmenuitem.h"
136+
137+static gboolean ido_switch_menu_button_release_event (GtkWidget * widget,
138+ GdkEventButton * event);
139+
140+
141+struct _IdoSwitchMenuItemPrivate
142+{
143+ GtkWidget * box;
144+ GtkWidget * content_area;
145+ GtkWidget * switch_w;
146+};
147+
148+/***
149+**** Life Cycle
150+***/
151+
152+G_DEFINE_TYPE (IdoSwitchMenuItem, ido_switch_menu_item, GTK_TYPE_CHECK_MENU_ITEM)
153+
154+static void
155+ido_switch_menu_item_class_init (IdoSwitchMenuItemClass *klass)
156+{
157+ GObjectClass * gobject_class;
158+ GtkWidgetClass * widget_class;
159+ GtkCheckMenuItemClass * check_class;
160+
161+ gobject_class = G_OBJECT_CLASS (klass);
162+ g_type_class_add_private (gobject_class, sizeof (IdoSwitchMenuItemPrivate));
163+
164+ widget_class = GTK_WIDGET_CLASS (klass);
165+ widget_class->button_release_event = ido_switch_menu_button_release_event;
166+
167+ check_class = GTK_CHECK_MENU_ITEM_CLASS (klass);
168+ check_class->draw_indicator = NULL;
169+}
170+
171+static void
172+ido_switch_menu_item_init (IdoSwitchMenuItem *item)
173+{
174+ IdoSwitchMenuItemPrivate *priv;
175+
176+ priv = item->priv = G_TYPE_INSTANCE_GET_PRIVATE (item, IDO_TYPE_SWITCH_MENU_ITEM, IdoSwitchMenuItemPrivate);
177+ priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
178+ priv->content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
179+ priv->switch_w = gtk_switch_new ();
180+
181+ gtk_box_pack_start (GTK_BOX (priv->box), priv->content_area, TRUE, TRUE, 0);
182+ gtk_box_pack_end (GTK_BOX (priv->box), priv->switch_w, FALSE, FALSE, 0);
183+ gtk_container_add (GTK_CONTAINER (item), priv->box);
184+ gtk_widget_show_all (priv->box);
185+
186+ g_object_bind_property (item, "active",
187+ priv->switch_w, "active",
188+ G_BINDING_SYNC_CREATE);
189+}
190+
191+/***
192+**** Don't popdown the menu immediately after clicking on a switch...
193+**** wait a moment so the user can see the GtkSwitch be toggled.
194+***/
195+
196+static gboolean
197+popdown_later_cb (gpointer widget)
198+{
199+ GtkWidget * parent = gtk_widget_get_parent (widget);
200+ if (GTK_IS_MENU (parent))
201+ {
202+ gtk_menu_shell_deactivate (GTK_MENU_SHELL(parent));
203+ }
204+ g_object_unref (widget);
205+ return FALSE; /* only call this cb once */
206+}
207+
208+static gboolean
209+ido_switch_menu_button_release_event (GtkWidget * widget, GdkEventButton * event)
210+{
211+ gtk_menu_item_activate (GTK_MENU_ITEM(widget));
212+ g_timeout_add (500, popdown_later_cb, g_object_ref(widget));
213+ return TRUE; /* stop the event so that it doesn't trigger popdown() */
214+}
215+
216+/***
217+**** Public API
218+***/
219+
220+GtkWidget *
221+ido_switch_menu_item_new (void)
222+{
223+ return g_object_new (IDO_TYPE_SWITCH_MENU_ITEM, NULL);
224+}
225+
226+GtkContainer *
227+ido_switch_menu_item_get_content_area (IdoSwitchMenuItem * item)
228+{
229+ g_return_val_if_fail (IDO_IS_SWITCH_MENU_ITEM(item), NULL);
230+
231+ return GTK_CONTAINER (item->priv->content_area);
232+}
233
234=== added file 'src/idoswitchmenuitem.h'
235--- src/idoswitchmenuitem.h 1970-01-01 00:00:00 +0000
236+++ src/idoswitchmenuitem.h 2012-08-22 01:08:21 +0000
237@@ -0,0 +1,57 @@
238+/*
239+ * A GtkCheckMenuItem that uses a GtkSwitch to show its 'active' property.
240+ *
241+ * Copyright © 2012 Canonical Ltd.
242+ *
243+ * This program is free software: you can redistribute it and/or modify it
244+ * under the terms of the GNU General Public License version 3, as
245+ * published by the Free Software Foundation.
246+ *
247+ * This program is distributed in the hope that it will be useful, but
248+ * WITHOUT ANY WARRANTY; without even the implied warranties of
249+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
250+ * PURPOSE. See the GNU General Public License for more details.
251+ *
252+ * You should have received a copy of the GNU General Public License along
253+ * with this program. If not, see <http://www.gnu.org/licenses/>.
254+ *
255+ * Author: Charles Kerr <charles.kerr@canonical.com>
256+ */
257+
258+#ifndef __IDO_SWITCH_MENU_ITEM_H__
259+#define __IDO_SWITCH_MENU_ITEM_H__
260+
261+#include <gtk/gtk.h>
262+
263+G_BEGIN_DECLS
264+
265+#define IDO_TYPE_SWITCH_MENU_ITEM (ido_switch_menu_item_get_type ())
266+#define IDO_SWITCH_MENU_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), IDO_TYPE_SWITCH_MENU_ITEM, IdoSwitchMenuItem))
267+#define IDO_SWITCH_MENU_ITEM_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), IDO_TYPE_SWITCH_MENU_ITEM, IdoSwitchMenuItemClass))
268+#define IDO_IS_SWITCH_MENU_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), IDO_TYPE_SWITCH_MENU_ITEM))
269+#define IDO_IS_SWITCH_MENU_ITEM_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), IDO_TYPE_SWITCH_MENU_ITEM))
270+#define IDO_SWITCH_MENU_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), IDO_TYPE_SWITCH_MENU_ITEM, IdoSwitchMenuItemClass))
271+
272+typedef struct _IdoSwitchMenuItem IdoSwitchMenuItem;
273+typedef struct _IdoSwitchMenuItemClass IdoSwitchMenuItemClass;
274+typedef struct _IdoSwitchMenuItemPrivate IdoSwitchMenuItemPrivate;
275+
276+struct _IdoSwitchMenuItem
277+{
278+ GtkCheckMenuItem parent_instance;
279+
280+ IdoSwitchMenuItemPrivate *priv;
281+};
282+
283+struct _IdoSwitchMenuItemClass
284+{
285+ GtkCheckMenuItemClass parent_class;
286+};
287+
288+GType ido_switch_menu_item_get_type (void) G_GNUC_CONST;
289+GtkWidget *ido_switch_menu_item_new (void);
290+GtkContainer *ido_switch_menu_item_get_content_area (IdoSwitchMenuItem * item);
291+
292+G_END_DECLS
293+
294+#endif /* __IDO_SWITCH_MENU_ITEM_H__ */

Subscribers

People subscribed via source and target branches