Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 6aed7b9bccb106c0b6e59fd1de7c52956446be36 @Daniel15 committed Nov 25, 2011
20 NTelepathy.sln
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NTelepathy", "src\NTelepathy.csproj", "{720E9292-263C-449C-B4FC-C199926DBBCD}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {720E9292-263C-449C-B4FC-C199926DBBCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {720E9292-263C-449C-B4FC-C199926DBBCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {720E9292-263C-449C-B4FC-C199926DBBCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {720E9292-263C-449C-B4FC-C199926DBBCD}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = src\NTelepathy.csproj
+ EndGlobalSection
+EndGlobal
27 README.md
@@ -0,0 +1,27 @@
+NTelepathy
+==========
+
+NTelepathy is C# bindings for the [Telepathy communications framework](http://telepathy.freedesktop.org/).
+Basically, it lets you use Telepathy's features from Mono/.NET.
+
+Currently it only supports updating the status message.
+
+Dependencies
+============
+ - [dbus-sharp](http://mono.github.com/dbus-sharp/)
+ This can be installed on Ubuntu by running `apt-get install libdbus1.0-cil`
+
+Licence
+=======
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
27 src/AssemblyInfo.cs
@@ -0,0 +1,27 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("NTelepathy")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("Daniel15 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("0.0.1")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
24 src/Dbus/AccountManagerProperties.cs
@@ -0,0 +1,24 @@
+using DBus;
+
+namespace NTelepathy.Dbus
+{
+ /// <summary>
+ /// Properties for AccountManager interface
+ /// </summary>
+ /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Account_Manager.html</remarks>
+ public abstract class AccountManagerProperties : PropertiesBase
+ {
+ /// <summary>
+ /// Get all the valid accounts this account manager knows about
+ /// </summary>
+ /// <value>The accounts</value>
+ public ObjectPath[] ValidAccounts
+ {
+ get
+ {
+ return (ObjectPath[])Get(Constants.ACCOUNTMANAGER_INTERFACE, "ValidAccounts");
+ }
+ }
+ }
+}
+
24 src/Dbus/AccountProperties.cs
@@ -0,0 +1,24 @@
+using DBus;
+
+namespace NTelepathy.Dbus
+{
+ /// <summary>
+ /// Properties for the Account interface
+ /// </summary>
+ /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Account.html</remarks>
+ public abstract class AccountProperties : PropertiesBase
+ {
+ /// <summary>
+ /// Gets the path to the connection for this account
+ /// </summary>
+ /// <value>The connection</value>
+ public ObjectPath Connection
+ {
+ get
+ {
+ return (ObjectPath)Get(Constants.ACCOUNT_INTERFACE, "Connection");
+ }
+ }
+ }
+}
+
28 src/Dbus/Constants.cs
@@ -0,0 +1,28 @@
+using System;
+
+namespace NTelepathy.Dbus
+{
+ /// <summary>
+ /// Various DBus constants
+ /// </summary>
+ public abstract class Constants
+ {
+ /// <summary>
+ /// Bus for the account manager.
+ /// </summary>
+ public const string ACCOUNTMANAGER_BUS = "org.freedesktop.Telepathy.AccountManager";
+ /// <summary>
+ /// Path for the account manager.
+ /// </summary>
+ public const string ACCOUNTMANAGER_PATH = "/org/freedesktop/Telepathy/AccountManager";
+ /// <summary>
+ /// Interface for the account manager.
+ /// </summary>
+ public const string ACCOUNTMANAGER_INTERFACE = "org.freedesktop.Telepathy.AccountManager";
+ /// <summary>
+ /// Interface for accounts.
+ /// </summary>
+ public const string ACCOUNT_INTERFACE = "org.freedesktop.Telepathy.Account";
+ }
+}
+
21 src/Dbus/ISimplePresence.cs
@@ -0,0 +1,21 @@
+using System;
+using DBus;
+
+namespace NTelepathy.Dbus
+{
+ /// <summary>
+ /// Telepathy SimplePresence interface
+ /// </summary>
+ /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Connection_Interface_Simple_Presence.html</remarks>
+ [Interface("org.freedesktop.Telepathy.Connection.Interface.SimplePresence")]
+ public interface ISimplePresence
+ {
+ /// <summary>
+ /// Sets the current presence
+ /// </summary>
+ /// <param name='status'>Status (eg. "available", "busy")</param>
+ /// <param name='statusMessage'>Status message</param>
+ void SetPresence(string status, string statusMessage);
+ }
+}
+
17 src/Dbus/PropertiesBase.cs
@@ -0,0 +1,17 @@
+using System.Collections.Generic;
+
+namespace NTelepathy.Dbus
+{
+ /// <summary>
+ /// Base class for all properties classes
+ /// </summary>
+ public abstract class PropertiesBase : org.freedesktop.DBus.Properties
+ {
+ // Below three methods are from Properties interface. They are
+ // implemented by the DBus proxy classes.
+ public abstract object Get (string @interface, string propname);
+ public abstract void Set (string @interface, string propname, object value);
+ public abstract IDictionary<string, object> GetAll (string @interface);
+ }
+}
+
48 src/NTelepathy.csproj
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>10.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{720E9292-263C-449C-B4FC-C199926DBBCD}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>NTelepathy</RootNamespace>
+ <AssemblyName>NTelepathy</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="dbus-sharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5675b0c3093115b5">
+ <Package>dbus-sharp-1.0</Package>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AssemblyInfo.cs" />
+ <Compile Include="Status.cs" />
+ <Compile Include="Dbus\AccountManagerProperties.cs" />
+ <Compile Include="Dbus\AccountProperties.cs" />
+ <Compile Include="Dbus\Constants.cs" />
+ <Compile Include="Dbus\ISimplePresence.cs" />
+ <Compile Include="Dbus\PropertiesBase.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>
64 src/Status.cs
@@ -0,0 +1,64 @@
+using DBus;
+using NTelepathy.Dbus;
+
+namespace NTelepathy
+{
+ /// <summary>
+ /// Handles status updating
+ /// </summary>
+ public class Status
+ {
+ /// <summary>
+ /// The DBUS connection
+ /// </summary>
+ private Connection _connection = Bus.Session;
+
+ /// <summary>
+ /// Update the status message of all accounts
+ /// </summary>
+ /// <param name='statusMessage'>Status message to set</param>
+ public void UpdateAllAccounts(string statusMessage)
+ {
+ // Get all the valid accounts via the account manager
+ AccountManagerProperties props = _connection.GetObject<AccountManagerProperties>(Constants.ACCOUNTMANAGER_BUS, new ObjectPath(Constants.ACCOUNTMANAGER_PATH));
+
+ foreach (ObjectPath path in props.ValidAccounts)
+ {
+ UpdateAccount(path, statusMessage);
+ }
+ }
+
+ /// <summary>
+ /// Update the status message of the specified account
+ /// </summary>
+ /// <param name='account'>The account to update</param>
+ /// <param name='statusMessage'>Status message to set</param>
+ private void UpdateAccount(ObjectPath account, string statusMessage)
+ {
+ AccountProperties props = _connection.GetObject<AccountProperties>(Constants.ACCOUNTMANAGER_BUS, account);
+
+ // Get the connection for this account
+ ObjectPath connection = props.Connection;
+ // Update the presence
+ ISimplePresence presence = _connection.GetObject<ISimplePresence>(ConnectionManagerBusName(connection), connection);
+ presence.SetPresence("available", statusMessage);
+ }
+
+ /// <summary>
+ /// Gets the bus name for the specified connection manager object path
+ /// </summary>
+ /// <returns>The bus name</returns>
+ /// <param name='objectPath'>The object path</param>
+ private static string ConnectionManagerBusName(ObjectPath objectPath)
+ {
+ // TODO: Is there a better (proper?) way to do this?
+
+ // ObjectPath is eg. /org/freedesktop/Telepathy/Connection/gabble/jabber/daniel_40d15_2ebiz_2f3e9348f3
+ // Connection manager type is 5th item (eg. "gabble")
+ string connType = objectPath.ToString().Split('/')[5];
+
+ return string.Format("org.freedesktop.Telepathy.ConnectionManager.{0}", connType);
+ }
+ }
+}
+

0 comments on commit 6aed7b9

Please sign in to comment.