From: Alejandro PiƱeiro Date: Wed, 20 May 2009 13:51:38 +0000 (+0200) Subject: Add a new method hildon_banner_show_information_override_dnd X-Git-Tag: 2.1.76-1~18 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=9d721b72583bf60bb3418fbc8724d754f5f04511;p=hildon Add a new method hildon_banner_show_information_override_dnd * hildon/hildon-banner-private.h: new require_override_dnd and overrides_dnd variables * hildon/hildon-banner.h: (hildon_banner_show_information_override_dnd): new method, that shows the information but sets the override flag, in order to show important messages * hildon/hildon-banner.c (hildon_banner_show_information_override_dnd): new method (hildon_banner_set_override_flag): new utility function (hildon_banner_real_show_information): new utility function, in order to generalize the current hildon_banner_show_information_override_dnd and hildon_banner_show_information_override_dnd * examples/Makefile.am * examples/hildon-banner-dnd-example.c: New example that show how to use the new hildon_banner_show_information_override_dnd Fixes: NB#114874 (There is no possibility to show hildon banners with DND flag set) --- diff --git a/ChangeLog b/ChangeLog index 24973ac..e58b307 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2009-05-21 Alejandro Pinheiro + + * hildon/hildon-banner-private.h: new require_override_dnd and + overrides_dnd variables + * hildon/hildon-banner.h: + (hildon_banner_show_information_override_dnd): new method, that shows + the information but sets the override flag, in order to show important + messages + * hildon/hildon-banner.c + (hildon_banner_show_information_override_dnd): new method + (hildon_banner_set_override_flag): new utility function + (hildon_banner_real_show_information): new utility function, in order to + generalize the current hildon_banner_show_information_override_dnd and + hildon_banner_show_information_override_dnd + * examples/Makefile.am + * examples/hildon-banner-dnd-example.c: New example that show how to + use the new hildon_banner_show_information_override_dnd + + Fixes: NB#114874 (There is no possibility to show hildon banners with + DND flag set) + 2009-05-20 Claudio Saavedra * hildon/hildon-pannable-area.c: Add a comment explaining the math diff --git a/examples/Makefile.am b/examples/Makefile.am index 0368bdf..6de44f6 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -3,6 +3,7 @@ MAINTAINERCLEANFILES = Makefile.in if BUILD_EXAMPLES EXAMPLES = hildon-window-example \ hildon-banner-example \ + hildon-banner-dnd-example \ hildon-banner-long-example \ hildon-caption-example \ hildon-note-example \ @@ -140,6 +141,12 @@ hildon_banner_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ $(EXTRA_CFLAGS) hildon_banner_example_SOURCES = hildon-banner-example.c +# Hildon banner +hildon_banner_dnd_example_LDADD = $(HILDON_OBJ_LIBS) +hildon_banner_dnd_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ + $(EXTRA_CFLAGS) +hildon_banner_dnd_example_SOURCES = hildon-banner-dnd-example.c + # Hildon banner long hildon_banner_long_example_LDADD = $(HILDON_OBJ_LIBS) hildon_banner_long_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ diff --git a/examples/hildon-banner-dnd-example.c b/examples/hildon-banner-dnd-example.c new file mode 100644 index 0000000..290627e --- /dev/null +++ b/examples/hildon-banner-dnd-example.c @@ -0,0 +1,80 @@ +/* + * This file is a part of hildon examples + * + * Copyright (C) 2005, 2009 Nokia Corporation, all rights reserved. + * + * Author: Alejandro Pinheiro + * + * Based on hildon-banner-example.c + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#include +#include +#include +#include +#include + + +static gboolean +on_information_clicked (GtkWidget *widget) +{ + GtkWidget* banner = NULL; + + banner = hildon_banner_show_information_override_dnd (widget, NULL, + "Real important information!!"); + + hildon_banner_set_timeout (HILDON_BANNER (banner), 5000); + return TRUE; +} + + +int +main (int argc, + char **argv) +{ + hildon_gtk_init (&argc, &argv); + + HildonProgram *program = hildon_program_get_instance (); + + GtkWidget *window = hildon_window_new (); + + hildon_gtk_window_set_do_not_disturb (GTK_WINDOW (window), TRUE); + hildon_program_add_window (program, HILDON_WINDOW (window)); + + gtk_container_set_border_width (GTK_CONTAINER (window), 6); + + GtkVBox *vbox = GTK_VBOX (gtk_vbox_new (6, FALSE)); + GtkButton *button1 = + GTK_BUTTON (gtk_button_new_with_label ("We are on DND mode\nPress here to show real important information")); + + g_signal_connect (G_OBJECT (button1), "clicked", G_CALLBACK (on_information_clicked), NULL); + + g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL); + + gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (button1), TRUE, TRUE, 0); + + gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vbox)); + + gtk_widget_show_all (GTK_WIDGET (window)); + + gtk_main (); + return 0; +} + + diff --git a/hildon/hildon-banner-private.h b/hildon/hildon-banner-private.h index 8f4f581..925d807 100644 --- a/hildon/hildon-banner-private.h +++ b/hildon/hildon-banner-private.h @@ -42,6 +42,9 @@ struct _HildonBannerPrivate guint is_timed : 1, has_been_wrapped : 1, has_been_truncated : 1; guint timeout; GtkWindow *parent; + + gboolean require_override_dnd; + gboolean overrides_dnd; }; /* For internal use of hildon libraries only */ diff --git a/hildon/hildon-banner.c b/hildon/hildon-banner.c index aeaac58..8889fd8 100644 --- a/hildon/hildon-banner.c +++ b/hildon/hildon-banner.c @@ -36,6 +36,13 @@ * hildon_banner_show_information(), hildon_banner_show_informationf() * or hildon_banner_show_information_with_markup(). * + * If the application window has set the _HILDON_DO_NOT_DISTURB flag (using + * hildon_gtk_window_set_do_not_disturb() for example), the banner will not + * be showed. If you need to override this flag for important information, + * you can use the method hildon_banner_show_information_override_dnd(). + * Please, take into account that this is only for important information. + * + * * Two more kinds of banners are maintained for backward compatibility * but are no longer recommended in Hildon 2.2. These are the animated * banner (created with hildon_banner_show_animation()) and the @@ -187,6 +194,15 @@ static HildonBanner* hildon_banner_get_instance_for_widget (GtkWidget *widget, gboolean timed); +static void +hildon_banner_set_override_flag (HildonBanner *banner); + +static GtkWidget* +hildon_banner_real_show_information (GtkWidget *widget, + const gchar *text, + gboolean override_dnd); + + G_DEFINE_TYPE (HildonBanner, hildon_banner, GTK_TYPE_WINDOW) static GQuark @@ -688,6 +704,12 @@ hildon_banner_realize (GtkWidget *widget) atom = gdk_atom_intern ("_HILDON_PORTRAIT_MODE_SUPPORT", FALSE); gdk_property_change (gdkwin, atom, gdk_x11_xatom_to_atom (XA_CARDINAL), 32, GDK_PROP_MODE_REPLACE, (gpointer) &portrait, 1); + + /* Manage override flag */ + if ((priv->require_override_dnd)&&(!priv->overrides_dnd)) { + hildon_banner_set_override_flag (HILDON_BANNER (widget)); + priv->overrides_dnd = TRUE; + } } static void @@ -768,6 +790,8 @@ hildon_banner_init (HildonBanner *self) g_assert (priv); priv->parent = NULL; + priv->overrides_dnd = FALSE; + priv->require_override_dnd = FALSE; /* Initialize the common layout inside banner */ priv->layout = gtk_hbox_new (FALSE, HILDON_MARGIN_DEFAULT); @@ -903,20 +927,76 @@ hildon_banner_show_information (GtkWidget *widget, const gchar *icon_name, const gchar *text) { + return hildon_banner_real_show_information (widget, text, FALSE); +} + +/** + * hildon_banner_show_information_override_dnd: + * @widget: the #GtkWidget that is the owner of the banner + * @icon_name: since Hildon 2.2 this parameter is not used anymore and + * any value that you pass will be ignored + * @text: Text to display + * + * Equivalent to hildon_banner_show_information() but it overrides the do not + * disturb flag, in the special cases that could be needed. It is required + * because this method calls internally gtk_widget_show before returns the banner, + * but the do not disturb flag is checked on the mapping of the widget + * + * + * Returns: The newly created banner + * + * Since: 2.2 + * + */ +GtkWidget* +hildon_banner_show_information_override_dnd (GtkWidget *widget, + const gchar *icon_name, + const gchar *text) +{ + return hildon_banner_real_show_information (widget, text, TRUE); +} + +static void +hildon_banner_set_override_flag (HildonBanner *banner) +{ + guint32 state = 1; + + gdk_property_change (GTK_WIDGET (banner)->window, + gdk_atom_intern_static_string ("_HILDON_DO_NOT_DISTURB_OVERRIDE"), + gdk_x11_xatom_to_atom (XA_INTEGER), + 32, + GDK_PROP_MODE_REPLACE, + (const guchar*) &state, + 1); +} + + +static GtkWidget* +hildon_banner_real_show_information (GtkWidget *widget, + const gchar *text, + gboolean override_dnd) +{ HildonBanner *banner; + HildonBannerPrivate *priv = NULL; g_return_val_if_fail (text != NULL, NULL); /* Prepare banner */ banner = hildon_banner_get_instance_for_widget (widget, TRUE); + priv = HILDON_BANNER_GET_PRIVATE (banner); hildon_banner_set_text (banner, text); hildon_banner_bind_style (banner, "information"); + if (override_dnd) { + /* so on the realize it will set the property */ + priv->require_override_dnd = TRUE; + } + /* Show the banner, since caller cannot do that */ gtk_widget_show_all (GTK_WIDGET (banner)); - return (GtkWidget *) banner; + return GTK_WIDGET (banner); } /** diff --git a/hildon/hildon-banner.h b/hildon/hildon-banner.h index bdd16a5..b1e5bf2 100644 --- a/hildon/hildon-banner.h +++ b/hildon/hildon-banner.h @@ -68,6 +68,11 @@ hildon_banner_show_informationf (GtkWidget *widget, const gchar *format, ...); +GtkWidget* +hildon_banner_show_information_override_dnd (GtkWidget *widget, + const gchar *icon_name, + const gchar *text); + GtkWidget* hildon_banner_show_information_with_markup (GtkWidget *widget, const gchar *icon_name,