NotificationDevelopmentGuidelines

Attachment 'update-notifications.cs'

Download

   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 -r:Mono.Posix.dll update-notifications.cs \
  11 //    -out:update-notifications.exe
  12 //    mono update-notifications.exe
  13 //
  14 // Copyright 2009 Canonical Ltd.
  15 //
  16 // Author:
  17 //    Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
  18 //
  19 // This program is free software: you can redistribute it and/or modify it
  20 // under the terms of the GNU General Public License version 3, as published
  21 // by the Free Software Foundation.
  22 //
  23 // This program is distributed in the hope that it will be useful, but
  24 // WITHOUT ANY WARRANTY; without even the implied warranties of
  25 // MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
  26 // PURPOSE.  See the GNU General Public License for more details.
  27 //
  28 // You should have received a copy of the GNU General Public License along
  29 // with this program.  If not, see <http://www.gnu.org/licenses/>.
  30 //
  31 ////////////////////////////////////////////////////////////////////////////////
  32 
  33 using System;
  34 using Notifications;
  35 
  36 public class UpdateNotifications
  37 {
  38 	enum Capability {
  39 		CAP_ACTIONS = 0,
  40 		CAP_BODY,
  41 		CAP_BODY_HYPERLINKS,
  42 		CAP_BODY_IMAGES,
  43 		CAP_BODY_MARKUP,
  44 		CAP_ICON_MULTI,
  45 		CAP_ICON_STATIC,
  46 		CAP_SOUND,
  47 		CAP_IMAGE_SVG,
  48 		CAP_SYNCHRONOUS,
  49 		CAP_APPEND,
  50 		CAP_LAYOUT_ICON_ONLY,
  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 
  66 	private static void InitCaps ()
  67 	{
  68 
  69 		if (Global.Capabilities == null)
  70 			return;
  71 
  72 		if (Array.IndexOf (Global.Capabilities, "actions") > -1)
  73 			m_capabilities[(int) Capability.CAP_ACTIONS] = true;
  74 
  75 		if (Array.IndexOf (Global.Capabilities, "body") > -1)
  76 			m_capabilities[(int) Capability.CAP_BODY] = true;
  77 
  78 		if (Array.IndexOf (Global.Capabilities, "body-hyperlinks") > -1)
  79 			m_capabilities[(int) Capability.CAP_BODY_HYPERLINKS] = true;
  80 
  81 		if (Array.IndexOf (Global.Capabilities, "body-images") > -1)
  82 			m_capabilities[(int) Capability.CAP_BODY_IMAGES] = true;
  83 
  84 		if (Array.IndexOf (Global.Capabilities, "body-markup") > -1)
  85 			m_capabilities[(int) Capability.CAP_BODY_MARKUP] = true;
  86 
  87 		if (Array.IndexOf (Global.Capabilities, "icon-multi") > -1)
  88 			m_capabilities[(int) Capability.CAP_ICON_MULTI] = true;
  89 
  90 		if (Array.IndexOf (Global.Capabilities, "icon-static") > -1)
  91 			m_capabilities[(int) Capability.CAP_ICON_STATIC] = true;
  92 
  93 		if (Array.IndexOf (Global.Capabilities, "sound") > -1)
  94 			m_capabilities[(int) Capability.CAP_SOUND] = true;
  95 
  96 		if (Array.IndexOf (Global.Capabilities, "image/svg+xml") > -1)
  97 			m_capabilities[(int) Capability.CAP_IMAGE_SVG] = true;
  98 
  99 		if (Array.IndexOf (Global.Capabilities, "private-synchronous") > -1)
 100 			m_capabilities[(int) Capability.CAP_SYNCHRONOUS] = true;
 101 
 102 		if (Array.IndexOf (Global.Capabilities, "append") > -1)
 103 			m_capabilities[(int) Capability.CAP_APPEND] = true;
 104 
 105 		if (Array.IndexOf (Global.Capabilities, "private-icon-only") > -1)
 106 			m_capabilities[(int) Capability.CAP_LAYOUT_ICON_ONLY] = true;
 107 	}
 108 
 109 	private static void PrintCaps ()
 110 	{
 111 		Console.WriteLine ("Name:          "
 112 		                   + Global.ServerInformation.Name);
 113 		Console.WriteLine ("Vendor:        "
 114 		                   + Global.ServerInformation.Vendor);
 115 		Console.WriteLine ("Version:       "
 116 		                   + Global.ServerInformation.Version);
 117 		Console.WriteLine ("Spec. Version: "
 118 		                   + Global.ServerInformation.SpecVersion);
 119 
 120 		Console.WriteLine ("Supported capabilities/hints:");
 121 		if (m_capabilities[(int) Capability.CAP_ACTIONS])
 122 			Console.WriteLine ("\tactions");
 123 		if (m_capabilities[(int) Capability.CAP_BODY])
 124 			Console.WriteLine ("\tbody");
 125 		if (m_capabilities[(int) Capability.CAP_BODY_HYPERLINKS])
 126 			Console.WriteLine ("\tbody-hyperlinks");
 127 		if (m_capabilities[(int) Capability.CAP_BODY_IMAGES])
 128 			Console.WriteLine ("\tbody-images");
 129 		if (m_capabilities[(int) Capability.CAP_BODY_MARKUP])
 130 			Console.WriteLine ("\tbody-markup");
 131 		if (m_capabilities[(int) Capability.CAP_ICON_MULTI])
 132 			Console.WriteLine ("\ticon-multi");
 133 		if (m_capabilities[(int) Capability.CAP_ICON_STATIC])
 134 			Console.WriteLine ("\ticon-static");
 135 		if (m_capabilities[(int) Capability.CAP_SOUND])
 136 			Console.WriteLine ("\tsound");
 137 		if (m_capabilities[(int) Capability.CAP_IMAGE_SVG])
 138 			Console.WriteLine ("\timage/svg+xml");
 139 		if (m_capabilities[(int) Capability.CAP_SYNCHRONOUS])
 140 			Console.WriteLine ("\tprivate-synchronous");
 141 		if (m_capabilities[(int) Capability.CAP_APPEND])
 142 			Console.WriteLine ("\tappend");
 143 		if (m_capabilities[(int) Capability.CAP_LAYOUT_ICON_ONLY])
 144 			Console.WriteLine ("\tprivate-icon-only");
 145 
 146 		Console.WriteLine ("Notes:");
 147 		if (Global.ServerInformation.Name == "notify-osd")
 148 		{
 149 			Console.WriteLine ("\tx- and y-coordinates hints are ignored");
 150 			Console.WriteLine ("\texpire-timeout is ignored");
 151 			Console.WriteLine ("\tbody-markup is accepted but filtered");			
 152 		}
 153 		else
 154 			Console.WriteLine ("\tnone");
 155 	}
 156 
 157 	public static void Main ()
 158 	{
 159 		// call this so we can savely use the m_capabilities array later
 160 		InitCaps ();
 161 
 162 		// show what's supported
 163 		PrintCaps ();
 164 
 165 		// try the icon-summary-body case
 166 		Notification n = new Notification (
 167 				"Inital notification",
 168 				"This is the original content of this notification-bubble.",
 169 				"notification-message-IM");
 170 		n.Show ();
 171 		Mono.Unix.Native.Syscall.sleep (3); // simulate app activity
 172 
 173 		// update the current notification with new content
 174 		n.Summary  = "Updated notification";
 175 		n.Body     = "Here the same bubble with new title- and body-text, even the icon can be changed on the update.";
 176 		n.IconName = "notification-message-email";
 177 		n.Show ();
 178 		Mono.Unix.Native.Syscall.sleep (6); // wait longer now
 179 
 180 		// create a new bubble using the icon-summary-body layout
 181 		n = new Notification (
 182 				"Initial layout",
 183 				"This bubble uses the icon-title-body layout.",
 184 				"notification-message-IM");
 185 		n.Show ();
 186 		Mono.Unix.Native.Syscall.sleep (3); // simulate app activity
 187 
 188 		// now update current bubble again, but change the layout
 189 		n.Summary  = "Updated layout";
 190 		n.Body     = "After the update we now have a bubble using the title-body layout.";
 191 		n.IconName = "";
 192 		n.Show ();
 193 	}
 194 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-02-25 22:40:59, 8.2 KB) [[attachment:append-hint-example.c]]
  • [get | view] (2009-02-25 22:41:05, 6.3 KB) [[attachment:append-hint-example.cs]]
  • [get | view] (2009-02-25 15:44:14, 931.0 KB) [[attachment:append-hint-example.ogg]]
  • [get | view] (2009-02-25 22:41:10, 4.1 KB) [[attachment:append-hint-example.py]]
  • [get | view] (2009-02-25 22:41:58, 6.8 KB) [[attachment:icon-summary-body.c]]
  • [get | view] (2009-02-25 22:42:06, 5.8 KB) [[attachment:icon-summary-body.cs]]
  • [get | view] (2009-02-25 23:32:31, 25.9 KB) [[attachment:icon-summary-body.png]]
  • [get | view] (2010-01-13 10:26:42, 3.6 KB) [[attachment:icon-summary-body.py]]
  • [get | view] (2009-02-25 22:41:37, 6.7 KB) [[attachment:icon-summary.c]]
  • [get | view] (2009-02-25 22:41:42, 5.7 KB) [[attachment:icon-summary.cs]]
  • [get | view] (2009-02-25 23:32:25, 21.8 KB) [[attachment:icon-summary.png]]
  • [get | view] (2009-02-25 22:41:48, 3.5 KB) [[attachment:icon-summary.py]]
  • [get | view] (2009-02-25 17:28:21, 39.8 KB) [[attachment:small_append-hint-example_ogg.png]]
  • [get | view] (2009-03-02 00:26:37, 31.5 KB) [[attachment:small_update-notifications_ogg.png]]
  • [get | view] (2009-02-25 22:42:54, 6.7 KB) [[attachment:summary-body.c]]
  • [get | view] (2009-02-25 22:43:06, 5.7 KB) [[attachment:summary-body.cs]]
  • [get | view] (2009-02-25 23:32:55, 22.4 KB) [[attachment:summary-body.png]]
  • [get | view] (2009-02-25 22:43:22, 3.5 KB) [[attachment:summary-body.py]]
  • [get | view] (2009-02-25 22:43:29, 6.7 KB) [[attachment:summary-only.c]]
  • [get | view] (2009-02-25 22:43:35, 5.6 KB) [[attachment:summary-only.cs]]
  • [get | view] (2009-02-25 23:33:04, 20.3 KB) [[attachment:summary-only.png]]
  • [get | view] (2009-02-25 22:43:42, 3.5 KB) [[attachment:summary-only.py]]
  • [get | view] (2009-03-01 07:01:45, 8.5 KB) [[attachment:update-notifications.c]]
  • [get | view] (2009-03-01 07:01:53, 6.6 KB) [[attachment:update-notifications.cs]]
  • [get | view] (2009-03-01 07:02:38, 1226.6 KB) [[attachment:update-notifications.ogg]]
  • [get | view] (2009-03-01 07:01:59, 4.3 KB) [[attachment:update-notifications.py]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.