~ubuntu-branches/ubuntu/utopic/gossip/utopic

« back to all changes in this revision

Viewing changes to src/gossip-hint.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2007-05-30 21:16:05 UTC
  • mfrom: (1.1.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20070530211605-fwsaooscfnmujkqd
Tags: 0.26-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 * Copyright (C) 2002-2007 Imendio AB
 
4
 
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License as
 
7
 * published by the Free Software Foundation; either version 2 of the
 
8
 * License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public
 
16
 * License along with this program; if not, write to the
 
17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
 * Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include <glib/gi18n.h>
 
22
#include <gtk/gtk.h>
 
23
 
 
24
#include <libgossip/gossip-conf.h>
 
25
 
 
26
#include "gossip-hint.h"
 
27
 
 
28
static void
 
29
hint_dialog_response_cb (GtkWidget *widget,
 
30
                         gint       response,
 
31
                         GtkWidget *checkbutton)
 
32
{
 
33
        GFunc        func;
 
34
        gpointer     user_data;
 
35
        const gchar *conf_path;
 
36
        gboolean     hide_hint;
 
37
 
 
38
        conf_path = g_object_get_data (G_OBJECT (widget), "conf_path");
 
39
        func = g_object_get_data (G_OBJECT (widget), "func");
 
40
        user_data = g_object_get_data (G_OBJECT (widget), "user_data");
 
41
 
 
42
        hide_hint = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton));
 
43
        gossip_conf_set_bool (gossip_conf_get (), conf_path, !hide_hint);
 
44
 
 
45
        gtk_widget_destroy (widget);
 
46
 
 
47
        if (func) {
 
48
                (func) ((gpointer) conf_path, user_data);
 
49
        }
 
50
}
 
51
 
 
52
 
 
53
gboolean
 
54
gossip_hint_dialog_show (const gchar         *conf_path,
 
55
                         const gchar         *message1,
 
56
                         const gchar         *message2,
 
57
                         GtkWindow           *parent,
 
58
                         GFunc                func,
 
59
                         gpointer             user_data)
 
60
{
 
61
        GtkWidget *dialog;
 
62
        GtkWidget *checkbutton;
 
63
        GtkWidget *vbox;
 
64
        gboolean   ok;
 
65
        gboolean   show_hint = TRUE;
 
66
 
 
67
        g_return_val_if_fail (conf_path != NULL, FALSE);
 
68
        g_return_val_if_fail (message1 != NULL, FALSE);
 
69
 
 
70
        ok = gossip_conf_get_bool (gossip_conf_get (),
 
71
                                   conf_path,
 
72
                                   &show_hint);
 
73
 
 
74
        if (ok && !show_hint) {
 
75
                return FALSE;
 
76
        }
 
77
 
 
78
        dialog = gtk_message_dialog_new_with_markup (parent,
 
79
                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
 
80
                                                     GTK_MESSAGE_INFO,
 
81
                                                     GTK_BUTTONS_CLOSE,
 
82
                                                     "<b>%s</b>",
 
83
                                                     message1);
 
84
 
 
85
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
 
86
                                                  "%s", message2);
 
87
        checkbutton = gtk_check_button_new_with_label (_("Do not show this again"));
 
88
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton), TRUE);
 
89
 
 
90
        vbox = gtk_vbox_new (FALSE, 6);
 
91
        gtk_container_set_border_width  (GTK_CONTAINER (vbox), 6);
 
92
        gtk_box_pack_start (GTK_BOX (vbox), checkbutton, FALSE, FALSE, 0);
 
93
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, FALSE, FALSE, 0);
 
94
 
 
95
        g_object_set_data_full (G_OBJECT (dialog), "conf_path", g_strdup (conf_path), g_free);
 
96
        g_object_set_data (G_OBJECT (dialog), "user_data", user_data);
 
97
        g_object_set_data (G_OBJECT (dialog), "func", func);
 
98
 
 
99
        g_signal_connect (dialog, "response",
 
100
                          G_CALLBACK (hint_dialog_response_cb),
 
101
                          checkbutton);
 
102
 
 
103
        gtk_widget_show_all (dialog);
 
104
 
 
105
        return TRUE;
 
106
}
 
107
 
 
108
gboolean 
 
109
gossip_hint_show (const gchar         *conf_path,
 
110
                  const gchar         *message1,
 
111
                  const gchar         *message2,
 
112
                  GtkWindow           *parent,
 
113
                  GFunc                func,
 
114
                  gpointer             user_data)
 
115
{
 
116
#ifdef HAVE_LIBNOTIFY
 
117
        return gossip_notify_hint_show (conf_path,
 
118
                                        message1, message2,
 
119
                                        func, user_data);
 
120
#else
 
121
        return gossip_hint_dialog_show (conf_path,
 
122
                                        message1, message2,
 
123
                                        parent,
 
124
                                        func, user_data);
 
125
#endif
 
126
}
 
127