NotificationDevelopmentGuidelines

Attachment 'append-hint-example.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 append-hint-example.cs \
  11 //    -out:append-hint-example.exe
  12 //    mono append-hint-example.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 AppendHintExample
  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 append-hint
 166 		if (m_capabilities[(int) Capability.CAP_APPEND])
 167 		{
 168 			Notification n = new Notification ("Cole Raby",
 169 							   "Hey Bro Coly!",
 170 							   "notification-message-IM");
 171 			n.AddHint ("append", "allowed");
 172 			n.Show ();
 173 			Mono.Unix.Native.Syscall.sleep (2); // simulate typing
 174 
 175 			n.Body = "What's up dude?";
 176 			n.Show ();
 177 			Mono.Unix.Native.Syscall.sleep (2); // simulate typing
 178 
 179 			n.Body = "Did you watch the air-race in Oshkosh last week?";
 180 			n.Show ();
 181 			Mono.Unix.Native.Syscall.sleep (2); // simulate typing
 182 
 183 			n.Body = "Phil owned the place like no one before him!";
 184 			n.Show ();
 185 			Mono.Unix.Native.Syscall.sleep (2); // simulate typing
 186 		}
 187 		else
 188 			Console.WriteLine ("The daemon does not support the append-hint!");
 189 	}
 190 }

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.