~crisoagf/do-plugins/do-music

« back to all changes in this revision

Viewing changes to Empathy/src/EmpathyChatAction.cs

  • Committer: Christopher James Halse Rogers
  • Date: 2011-02-06 08:01:08 UTC
  • mfrom: (687.1.12 empathy)
  • Revision ID: raof@ubuntu.com-20110206080108-cuzq3femqkmsiagy
Merge the long-sought Empathy plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  EmpathyChatAction.cs
 
2
//
 
3
//  Author:
 
4
//       Xavier Calland <xavier.calland@gmail.com>
 
5
//
 
6
//  Copyright © 2010
 
7
//
 
8
//  This program is free software: you can redistribute it and/or modify
 
9
//  it under the terms of the GNU Lesser General Public License as published by
 
10
//  the Free Software Foundation, either version 3 of the License, or
 
11
//  (at your option) any later version.
 
12
//
 
13
//  This program is distributed in the hope that it will be useful,
 
14
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
//  GNU Lesser General Public License for more details.
 
17
//
 
18
//  You should have received a copy of the GNU Lesser General Public License
 
19
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
using System;
 
22
using System.Linq;
 
23
using System.Threading;
 
24
using System.Collections.Generic;
 
25
using Mono.Addins;
 
26
using Do.Platform;
 
27
using Do.Universe;
 
28
 
 
29
namespace EmpathyPlugin
 
30
{
 
31
        public class EmpathyChatAction : Act
 
32
        {
 
33
                public EmpathyChatAction ()
 
34
                {
 
35
                }
 
36
 
 
37
                public override string Name
 
38
                {
 
39
                        get { return AddinManager.CurrentLocalizer.GetString ("Chat"); }
 
40
                }
 
41
 
 
42
                public override string Description
 
43
                {
 
44
                        get { return AddinManager.CurrentLocalizer.GetString ("Send an instant message to a friend."); }
 
45
                }
 
46
 
 
47
                public override string Icon
 
48
                {
 
49
                        get { return EmpathyPlugin.ChatIcon; }
 
50
                }
 
51
 
 
52
                public override IEnumerable<Type> SupportedItemTypes
 
53
                {
 
54
                        get {
 
55
                                yield return typeof (ContactItem);
 
56
                        }
 
57
                }
 
58
 
 
59
                public override bool SupportsItem (Item item)
 
60
                {
 
61
                        if (item is ContactItem) {
 
62
                                ContactItem contact = item as ContactItem;
 
63
 
 
64
                                return contact.Details.Contains("is-empathy");
 
65
                        }
 
66
                        return true;
 
67
                }
 
68
 
 
69
                public override IEnumerable<Type> SupportedModifierItemTypes
 
70
                {
 
71
                        get { yield return typeof (ITextItem); }
 
72
                }
 
73
 
 
74
                public override bool ModifierItemsOptional
 
75
                {
 
76
                        get { return true; }
 
77
                }
 
78
 
 
79
                public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
 
80
                {
 
81
                        string message = "";
 
82
 
 
83
                        if (modItems.Any ())
 
84
                                message = (modItems.First () as ITextItem).Text;
 
85
 
 
86
                        foreach (Item item in items) {
 
87
                                if (item is ContactItem) {
 
88
                                        ContactItem contactItem = item as ContactItem;
 
89
                                        string contactId = contactItem["email"];
 
90
 
 
91
                                        if (!string.IsNullOrEmpty (message))
 
92
                                                EmpathyPlugin.OpenConversationWithBuddy (contactId, message);
 
93
                                        else
 
94
                                                EmpathyPlugin.OpenConversationWithBuddy (contactId);
 
95
                                }
 
96
                        }
 
97
                        yield break;
 
98
                }
 
99
        }
 
100
}