~indicator-applet-developers/notify-osd/trunk

« back to all changes in this revision

Viewing changes to examples/icon-only.cs

  • Committer: Mirco Müller
  • Date: 2009-04-23 14:26:48 UTC
  • Revision ID: mirco.mueller@ubuntu.com-20090423142648-i7mnrg1yolkgt1yz
added examples form development-guidelines

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 and run:
 
10
//    gmcs -pkg:notify-sharp icon-only.cs -out:icon-only.exe
 
11
//    mono icon-only.exe
 
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
using System;
 
33
using Notifications;
 
34
 
 
35
public class IconOnly
 
36
{
 
37
        enum Capability {
 
38
                CAP_ACTIONS = 0,
 
39
                CAP_BODY,
 
40
                CAP_BODY_HYPERLINKS,
 
41
                CAP_BODY_IMAGES,
 
42
                CAP_BODY_MARKUP,
 
43
                CAP_ICON_MULTI,
 
44
                CAP_ICON_STATIC,
 
45
                CAP_SOUND,
 
46
                CAP_IMAGE_SVG,
 
47
                CAP_SYNCHRONOUS,
 
48
                CAP_APPEND,
 
49
                CAP_LAYOUT_ICON_ONLY,
 
50
                CAP_TRUNCATION,
 
51
                CAP_MAX}
 
52
 
 
53
        static bool[] m_capabilities = {false,  // actions
 
54
                                        false,  // body
 
55
                                        false,  // body-hyperlinks
 
56
                                        false,  // body-imges
 
57
                                        false,  // body-markup
 
58
                                        false,  // icon-multi
 
59
                                        false,  // icon-static
 
60
                                        false,  // sound
 
61
                                        false,  // image/svg+xml
 
62
                                        false,  // synchronous-hint
 
63
                                        false,  // append-hint
 
64
                                        false,  // icon-only-hint
 
65
                                        false}; // truncation-hint
 
66
 
 
67
        private static void InitCaps ()
 
68
        {
 
69
 
 
70
                if (Global.Capabilities == null)
 
71
                        return;
 
72
 
 
73
                if (Array.IndexOf (Global.Capabilities, "actions") > -1)
 
74
                        m_capabilities[(int) Capability.CAP_ACTIONS] = true;
 
75
 
 
76
                if (Array.IndexOf (Global.Capabilities, "body") > -1)
 
77
                        m_capabilities[(int) Capability.CAP_BODY] = true;
 
78
 
 
79
                if (Array.IndexOf (Global.Capabilities, "body-hyperlinks") > -1)
 
80
                        m_capabilities[(int) Capability.CAP_BODY_HYPERLINKS] = true;
 
81
 
 
82
                if (Array.IndexOf (Global.Capabilities, "body-images") > -1)
 
83
                        m_capabilities[(int) Capability.CAP_BODY_IMAGES] = true;
 
84
 
 
85
                if (Array.IndexOf (Global.Capabilities, "body-markup") > -1)
 
86
                        m_capabilities[(int) Capability.CAP_BODY_MARKUP] = true;
 
87
 
 
88
                if (Array.IndexOf (Global.Capabilities, "icon-multi") > -1)
 
89
                        m_capabilities[(int) Capability.CAP_ICON_MULTI] = true;
 
90
 
 
91
                if (Array.IndexOf (Global.Capabilities, "icon-static") > -1)
 
92
                        m_capabilities[(int) Capability.CAP_ICON_STATIC] = true;
 
93
 
 
94
                if (Array.IndexOf (Global.Capabilities, "sound") > -1)
 
95
                        m_capabilities[(int) Capability.CAP_SOUND] = true;
 
96
 
 
97
                if (Array.IndexOf (Global.Capabilities, "image/svg+xml") > -1)
 
98
                        m_capabilities[(int) Capability.CAP_IMAGE_SVG] = true;
 
99
 
 
100
                if (Array.IndexOf (Global.Capabilities, "x-canonical-private-synchronous") > -1)
 
101
                        m_capabilities[(int) Capability.CAP_SYNCHRONOUS] = true;
 
102
 
 
103
                if (Array.IndexOf (Global.Capabilities, "x-canonical-append") > -1)
 
104
                        m_capabilities[(int) Capability.CAP_APPEND] = true;
 
105
 
 
106
                if (Array.IndexOf (Global.Capabilities, "x-canonical-private-icon-only") > -1)
 
107
                        m_capabilities[(int) Capability.CAP_LAYOUT_ICON_ONLY] = true;
 
108
 
 
109
                if (Array.IndexOf (Global.Capabilities, "x-canonical-truncation") > -1)
 
110
                        m_capabilities[(int) Capability.CAP_TRUNCATION] = true;
 
111
        }
 
112
 
 
113
        private static void PrintCaps ()
 
114
        {
 
115
                Console.WriteLine ("Name:          "
 
116
                                   + Global.ServerInformation.Name);
 
117
                Console.WriteLine ("Vendor:        "
 
118
                                   + Global.ServerInformation.Vendor);
 
119
                Console.WriteLine ("Version:       "
 
120
                                   + Global.ServerInformation.Version);
 
121
                Console.WriteLine ("Spec. Version: "
 
122
                                   + Global.ServerInformation.SpecVersion);
 
123
 
 
124
                Console.WriteLine ("Supported capabilities/hints:");
 
125
                if (m_capabilities[(int) Capability.CAP_ACTIONS])
 
126
                        Console.WriteLine ("\tactions");
 
127
                if (m_capabilities[(int) Capability.CAP_BODY])
 
128
                        Console.WriteLine ("\tbody");
 
129
                if (m_capabilities[(int) Capability.CAP_BODY_HYPERLINKS])
 
130
                        Console.WriteLine ("\tbody-hyperlinks");
 
131
                if (m_capabilities[(int) Capability.CAP_BODY_IMAGES])
 
132
                        Console.WriteLine ("\tbody-images");
 
133
                if (m_capabilities[(int) Capability.CAP_BODY_MARKUP])
 
134
                        Console.WriteLine ("\tbody-markup");
 
135
                if (m_capabilities[(int) Capability.CAP_ICON_MULTI])
 
136
                        Console.WriteLine ("\ticon-multi");
 
137
                if (m_capabilities[(int) Capability.CAP_ICON_STATIC])
 
138
                        Console.WriteLine ("\ticon-static");
 
139
                if (m_capabilities[(int) Capability.CAP_SOUND])
 
140
                        Console.WriteLine ("\tsound");
 
141
                if (m_capabilities[(int) Capability.CAP_IMAGE_SVG])
 
142
                        Console.WriteLine ("\timage/svg+xml");
 
143
                if (m_capabilities[(int) Capability.CAP_SYNCHRONOUS])
 
144
                        Console.WriteLine ("\tx-canonical-private-synchronous");
 
145
                if (m_capabilities[(int) Capability.CAP_APPEND])
 
146
                        Console.WriteLine ("\tx-canonical-append");
 
147
                if (m_capabilities[(int) Capability.CAP_LAYOUT_ICON_ONLY])
 
148
                        Console.WriteLine ("\tx-canonical-private-icon-only");
 
149
                if (m_capabilities[(int) Capability.CAP_TRUNCATION])
 
150
                        Console.WriteLine ("\tx-canonical-truncation");
 
151
 
 
152
                Console.WriteLine ("Notes:");
 
153
                if (Global.ServerInformation.Name == "notify-osd")
 
154
                {
 
155
                        Console.WriteLine ("\tx- and y-coordinates hints are ignored");
 
156
                        Console.WriteLine ("\texpire-timeout is ignored");
 
157
                        Console.WriteLine ("\tbody-markup is accepted but filtered");                   
 
158
                }
 
159
                else
 
160
                        Console.WriteLine ("\tnone");
 
161
        }
 
162
 
 
163
        public static void Main ()
 
164
        {
 
165
                // call this so we can savely use the m_capabilities array later
 
166
                InitCaps ();
 
167
 
 
168
                // show what's supported
 
169
                PrintCaps ();
 
170
 
 
171
                // try the icon-sonly case
 
172
                if (m_capabilities[(int) Capability.CAP_LAYOUT_ICON_ONLY])
 
173
                {
 
174
                        Notification n = new Notification ("Eject", // for a11y-reasons supply something meaning full
 
175
                                                           "",      // this needs to be empty!
 
176
                                                           "notification-device-eject");
 
177
                        n.AddHint ("x-canonical-private-icon-only", "");
 
178
                        n.Show ();
 
179
                }
 
180
                else
 
181
                        Console.WriteLine ("The daemon does not support the x-canonical-private-icon-only hint!");
 
182
        }
 
183
}