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
=== modified file 'NEWS'
--- NEWS 2010-01-19 22:02:50 +0000
+++ NEWS 2012-08-22 01:08:21 +0000
@@ -0,0 +1,2 @@
112.10.0:
2 * new widget IdoSwitchMenuItem
03
=== modified file 'configure.ac'
--- configure.ac 2012-04-25 20:24:26 +0000
+++ configure.ac 2012-08-22 01:08:21 +0000
@@ -1,9 +1,9 @@
1#1#
2# shamelessly stolen from clutter-gtk2# shamelessly stolen from clutter-gtk
3#3#
4m4_define([ido_major_version], [0])4m4_define([ido_major_version], [12])
5m4_define([ido_minor_version], [3])5m4_define([ido_minor_version], [10])
6m4_define([ido_micro_version], [4])6m4_define([ido_micro_version], [0])
77
8m4_define([ido_api_version],8m4_define([ido_api_version],
9 [ido_major_version.ido_minor_version])9 [ido_major_version.ido_minor_version])
@@ -78,6 +78,8 @@
78AC_FUNC_MMAP78AC_FUNC_MMAP
79AC_CHECK_FUNCS([memset munmap strcasecmp strdup])79AC_CHECK_FUNCS([memset munmap strcasecmp strdup])
8080
81GLIB_REQUIRED_VERSION=2.32.0
82
81AC_ARG_WITH([gtk],83AC_ARG_WITH([gtk],
82 [AS_HELP_STRING([--with-gtk],84 [AS_HELP_STRING([--with-gtk],
83 [Which version of gtk to use @<:@default=3@:>@])],85 [Which version of gtk to use @<:@default=3@:>@])],
@@ -86,9 +88,11 @@
86AM_CONDITIONAL(USE_GTK3, [test "x$with_gtk" = x3])88AM_CONDITIONAL(USE_GTK3, [test "x$with_gtk" = x3])
8789
88if test "x$with_gtk" = "x2"; then90if test "x$with_gtk" = "x2"; then
89 PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.19.7)91 PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.19.7
92 glib-2.0 >= GLIB_REQUIRED_VERSION])
90else93else
91 PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.0.0)94 PKG_CHECK_MODULES(GTK, [gtk+-3.0 >= 3.0.0
95 glib-2.0 >= GLIB_REQUIRED_VERSION])
92 AC_DEFINE_UNQUOTED(USE_GTK3, , [Use GTK3])96 AC_DEFINE_UNQUOTED(USE_GTK3, , [Use GTK3])
93fi97fi
94AC_SUBST(GTK_CFLAGS)98AC_SUBST(GTK_CFLAGS)
9599
=== modified file 'example/menus.c'
--- example/menus.c 2011-12-14 17:19:26 +0000
+++ example/menus.c 2012-08-22 01:08:21 +0000
@@ -3,6 +3,7 @@
3#include "idoscalemenuitem.h"3#include "idoscalemenuitem.h"
4#include "idocalendarmenuitem.h"4#include "idocalendarmenuitem.h"
5#include "idoentrymenuitem.h"5#include "idoentrymenuitem.h"
6#include "idoswitchmenuitem.h"
6#include "config.h"7#include "config.h"
78
8static void9static void
@@ -27,6 +28,7 @@
27 GtkWidget *root;28 GtkWidget *root;
28 GtkWidget *menubar;29 GtkWidget *menubar;
29 GtkWidget *image;30 GtkWidget *image;
31 GtkWidget *label;
3032
31 g_unsetenv ("UBUNTU_MENUPROXY");33 g_unsetenv ("UBUNTU_MENUPROXY");
3234
@@ -76,6 +78,12 @@
76 menuitem = ido_entry_menu_item_new ();78 menuitem = ido_entry_menu_item_new ();
77 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);79 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
7880
81 menuitem = ido_switch_menu_item_new ();
82 label = gtk_label_new ("This is a switch");
83 gtk_widget_show(label);
84 gtk_container_add (ido_switch_menu_item_get_content_area(IDO_SWITCH_MENU_ITEM(menuitem)), label);
85 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
86
79 menuitem = ido_calendar_menu_item_new ();87 menuitem = ido_calendar_menu_item_new ();
80 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);88 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
8189
8290
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2012-04-12 15:18:01 +0000
+++ src/Makefile.am 2012-08-22 01:08:21 +0000
@@ -19,6 +19,7 @@
19 idomessagedialog.h \19 idomessagedialog.h \
20 idorange.h \20 idorange.h \
21 idoscalemenuitem.h \21 idoscalemenuitem.h \
22 idoswitchmenuitem.h \
22 idotimeline.h \23 idotimeline.h \
23 libido.h 24 libido.h
2425
@@ -67,6 +68,7 @@
67 idomessagedialog.c \68 idomessagedialog.c \
68 idorange.c \69 idorange.c \
69 idoscalemenuitem.c \70 idoscalemenuitem.c \
71 idoswitchmenuitem.c \
70 idotimeline.c 72 idotimeline.c
7173
72libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES)74libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES)
@@ -79,6 +81,7 @@
79 idomessagedialog.h \81 idomessagedialog.h \
80 idorange.h \82 idorange.h \
81 idoscalemenuitem.h \83 idoscalemenuitem.h \
84 idoswitchmenuitem.h \
82 idotimeline.h \85 idotimeline.h \
83 libido.h86 libido.h
8487
8588
=== added file 'src/idoswitchmenuitem.c'
--- src/idoswitchmenuitem.c 1970-01-01 00:00:00 +0000
+++ src/idoswitchmenuitem.c 2012-08-22 01:08:21 +0000
@@ -0,0 +1,120 @@
1/*
2 * A GtkCheckMenuItem that uses a GtkSwitch to show its 'active' property
3 *
4 * Copyright © 2012 Canonical Ltd.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author: Charles Kerr <charles.kerr@canonical.com>
19 */
20
21#include "config.h"
22
23#include "idoswitchmenuitem.h"
24
25static gboolean ido_switch_menu_button_release_event (GtkWidget * widget,
26 GdkEventButton * event);
27
28
29struct _IdoSwitchMenuItemPrivate
30{
31 GtkWidget * box;
32 GtkWidget * content_area;
33 GtkWidget * switch_w;
34};
35
36/***
37**** Life Cycle
38***/
39
40G_DEFINE_TYPE (IdoSwitchMenuItem, ido_switch_menu_item, GTK_TYPE_CHECK_MENU_ITEM)
41
42static void
43ido_switch_menu_item_class_init (IdoSwitchMenuItemClass *klass)
44{
45 GObjectClass * gobject_class;
46 GtkWidgetClass * widget_class;
47 GtkCheckMenuItemClass * check_class;
48
49 gobject_class = G_OBJECT_CLASS (klass);
50 g_type_class_add_private (gobject_class, sizeof (IdoSwitchMenuItemPrivate));
51
52 widget_class = GTK_WIDGET_CLASS (klass);
53 widget_class->button_release_event = ido_switch_menu_button_release_event;
54
55 check_class = GTK_CHECK_MENU_ITEM_CLASS (klass);
56 check_class->draw_indicator = NULL;
57}
58
59static void
60ido_switch_menu_item_init (IdoSwitchMenuItem *item)
61{
62 IdoSwitchMenuItemPrivate *priv;
63
64 priv = item->priv = G_TYPE_INSTANCE_GET_PRIVATE (item, IDO_TYPE_SWITCH_MENU_ITEM, IdoSwitchMenuItemPrivate);
65 priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
66 priv->content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
67 priv->switch_w = gtk_switch_new ();
68
69 gtk_box_pack_start (GTK_BOX (priv->box), priv->content_area, TRUE, TRUE, 0);
70 gtk_box_pack_end (GTK_BOX (priv->box), priv->switch_w, FALSE, FALSE, 0);
71 gtk_container_add (GTK_CONTAINER (item), priv->box);
72 gtk_widget_show_all (priv->box);
73
74 g_object_bind_property (item, "active",
75 priv->switch_w, "active",
76 G_BINDING_SYNC_CREATE);
77}
78
79/***
80**** Don't popdown the menu immediately after clicking on a switch...
81**** wait a moment so the user can see the GtkSwitch be toggled.
82***/
83
84static gboolean
85popdown_later_cb (gpointer widget)
86{
87 GtkWidget * parent = gtk_widget_get_parent (widget);
88 if (GTK_IS_MENU (parent))
89 {
90 gtk_menu_shell_deactivate (GTK_MENU_SHELL(parent));
91 }
92 g_object_unref (widget);
93 return FALSE; /* only call this cb once */
94}
95
96static gboolean
97ido_switch_menu_button_release_event (GtkWidget * widget, GdkEventButton * event)
98{
99 gtk_menu_item_activate (GTK_MENU_ITEM(widget));
100 g_timeout_add (500, popdown_later_cb, g_object_ref(widget));
101 return TRUE; /* stop the event so that it doesn't trigger popdown() */
102}
103
104/***
105**** Public API
106***/
107
108GtkWidget *
109ido_switch_menu_item_new (void)
110{
111 return g_object_new (IDO_TYPE_SWITCH_MENU_ITEM, NULL);
112}
113
114GtkContainer *
115ido_switch_menu_item_get_content_area (IdoSwitchMenuItem * item)
116{
117 g_return_val_if_fail (IDO_IS_SWITCH_MENU_ITEM(item), NULL);
118
119 return GTK_CONTAINER (item->priv->content_area);
120}
0121
=== added file 'src/idoswitchmenuitem.h'
--- src/idoswitchmenuitem.h 1970-01-01 00:00:00 +0000
+++ src/idoswitchmenuitem.h 2012-08-22 01:08:21 +0000
@@ -0,0 +1,57 @@
1/*
2 * A GtkCheckMenuItem that uses a GtkSwitch to show its 'active' property.
3 *
4 * Copyright © 2012 Canonical Ltd.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author: Charles Kerr <charles.kerr@canonical.com>
19 */
20
21#ifndef __IDO_SWITCH_MENU_ITEM_H__
22#define __IDO_SWITCH_MENU_ITEM_H__
23
24#include <gtk/gtk.h>
25
26G_BEGIN_DECLS
27
28#define IDO_TYPE_SWITCH_MENU_ITEM (ido_switch_menu_item_get_type ())
29#define IDO_SWITCH_MENU_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), IDO_TYPE_SWITCH_MENU_ITEM, IdoSwitchMenuItem))
30#define IDO_SWITCH_MENU_ITEM_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), IDO_TYPE_SWITCH_MENU_ITEM, IdoSwitchMenuItemClass))
31#define IDO_IS_SWITCH_MENU_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), IDO_TYPE_SWITCH_MENU_ITEM))
32#define IDO_IS_SWITCH_MENU_ITEM_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), IDO_TYPE_SWITCH_MENU_ITEM))
33#define IDO_SWITCH_MENU_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), IDO_TYPE_SWITCH_MENU_ITEM, IdoSwitchMenuItemClass))
34
35typedef struct _IdoSwitchMenuItem IdoSwitchMenuItem;
36typedef struct _IdoSwitchMenuItemClass IdoSwitchMenuItemClass;
37typedef struct _IdoSwitchMenuItemPrivate IdoSwitchMenuItemPrivate;
38
39struct _IdoSwitchMenuItem
40{
41 GtkCheckMenuItem parent_instance;
42
43 IdoSwitchMenuItemPrivate *priv;
44};
45
46struct _IdoSwitchMenuItemClass
47{
48 GtkCheckMenuItemClass parent_class;
49};
50
51GType ido_switch_menu_item_get_type (void) G_GNUC_CONST;
52GtkWidget *ido_switch_menu_item_new (void);
53GtkContainer *ido_switch_menu_item_get_content_area (IdoSwitchMenuItem * item);
54
55G_END_DECLS
56
57#endif /* __IDO_SWITCH_MENU_ITEM_H__ */

Subscribers

People subscribed via source and target branches