~elementary-os/elementaryos/os-patch-notify-osd-precise

« back to all changes in this revision

Viewing changes to examples/update-notifications.c

  • Committer: Sergey "Shnatsel" Davidoff
  • Date: 2012-06-18 21:08:31 UTC
  • Revision ID: shnatsel@gmail.com-20120618210831-g6k5y7vecjdylgic
Initial import, version 0.9.34-0ubuntu2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
**3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
 
3
**      10        20        30        40        50        60        70        80
 
4
**
 
5
** Info: 
 
6
**    Example of how to use libnotify correctly and at the same time comply to
 
7
**    the new jaunty notification spec (read: visual guidelines)
 
8
**
 
9
** Compile:
 
10
**    gcc -O0 -ggdb -Wall -Werror `pkg-config --cflags --libs libnotify \
 
11
**    glib-2.0` update-notifications.c example-util.c -o update-notifications
 
12
**
 
13
** Copyright 2009 Canonical Ltd.
 
14
**
 
15
** Author:
 
16
**    Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
 
17
**
 
18
** This program is free software: you can redistribute it and/or modify it
 
19
** under the terms of the GNU General Public License version 3, as published
 
20
** by the Free Software Foundation.
 
21
**
 
22
** This program is distributed in the hope that it will be useful, but
 
23
** WITHOUT ANY WARRANTY; without even the implied warranties of
 
24
** MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
25
** PURPOSE.  See the GNU General Public License for more details.
 
26
**
 
27
** You should have received a copy of the GNU General Public License along
 
28
** with this program.  If not, see <http://www.gnu.org/licenses/>.
 
29
**
 
30
*******************************************************************************/
 
31
 
 
32
#include "example-util.h"
 
33
 
 
34
int 
 
35
main (int    argc,
 
36
      char** argv)
 
37
{
 
38
        NotifyNotification* notification;
 
39
        gboolean            success;
 
40
        GError*             error = NULL;
 
41
 
 
42
        if (!notify_init ("update-notifications"))
 
43
                return 1;
 
44
 
 
45
        /* call this so we can savely use has_cap(CAP_SOMETHING) later */
 
46
        init_caps ();
 
47
 
 
48
        /* show what's supported */
 
49
        print_caps ();
 
50
 
 
51
        /* try the icon-summary-body case */
 
52
        notification = notify_notification_new (
 
53
                                "Inital notification",
 
54
                                "This is the original content of "
 
55
                                "this notification-bubble.",
 
56
                                "notification-message-im");
 
57
        error = NULL;
 
58
        success = notify_notification_show (notification, &error);
 
59
        if (!success)
 
60
        {
 
61
                g_print ("That did not work ... \"%s\".\n", error->message);
 
62
                g_error_free (error);
 
63
        }
 
64
 
 
65
        g_signal_connect (G_OBJECT (notification),
 
66
                          "closed",
 
67
                          G_CALLBACK (closed_handler),
 
68
                          NULL);
 
69
 
 
70
        sleep (3); /* simulate some app activity */
 
71
 
 
72
        /* update the current notification with new content */
 
73
        success = notify_notification_update (notification,
 
74
                                "Updated notification",
 
75
                                "Here the same bubble with new "
 
76
                                "title- and body-text, even the "
 
77
                                "icon can be changed on the update.",
 
78
                                "notification-message-email");
 
79
        error = NULL;
 
80
        success = notify_notification_show (notification, &error);
 
81
        if (!success)
 
82
        {
 
83
                g_print ("That did not work ... \"%s\".\n", error->message);
 
84
                g_error_free (error);
 
85
        }
 
86
 
 
87
        g_signal_connect (G_OBJECT (notification),
 
88
                          "closed",
 
89
                          G_CALLBACK (closed_handler),
 
90
                          NULL);
 
91
 
 
92
        sleep (6); /* wait long enough to have the current bubble expire */
 
93
 
 
94
        /* create a new bubble using the icon-summary-body layout */
 
95
        notification = notify_notification_new (
 
96
                                "Initial layout",
 
97
                                "This bubble uses the icon-title-body "
 
98
                                "layout.",
 
99
                                "notification-message-im");
 
100
        error = NULL;
 
101
        success = notify_notification_show (notification, &error);
 
102
        if (!success)
 
103
        {
 
104
                g_print ("That did not work ... \"%s\".\n", error->message);
 
105
                g_error_free (error);
 
106
        }
 
107
 
 
108
        g_signal_connect (G_OBJECT (notification),
 
109
                          "closed",
 
110
                          G_CALLBACK (closed_handler),
 
111
                          NULL);
 
112
 
 
113
        sleep (3); /* again simulate some app activity */
 
114
 
 
115
        /* now update current bubble again, but change the layout */
 
116
        success = notify_notification_update (notification,
 
117
                                "Updated layout",
 
118
                                "After the update we now have a "
 
119
                                "bubble using the title-body layout.",
 
120
                                " ");
 
121
        error = NULL;
 
122
        success = notify_notification_show (notification, &error);
 
123
        if (!success)
 
124
        {
 
125
                g_print ("That did not work ... \"%s\".\n", error->message);
 
126
                g_error_free (error);
 
127
        }
 
128
 
 
129
        g_signal_connect (G_OBJECT (notification),
 
130
                          "closed",
 
131
                          G_CALLBACK (closed_handler),
 
132
                          NULL);
 
133
 
 
134
        notify_uninit ();
 
135
 
 
136
        return 0;
 
137
}
 
138