~crisoagf/do-plugins/do-music

« back to all changes in this revision

Viewing changes to Empathy/src/EmpathySetStatusAction.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
//  EmpathySetStatusAction.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
 
 
24
using System.Collections.Generic;
 
25
 
 
26
using Mono.Addins;
 
27
 
 
28
using Do.Universe;
 
29
using Do.Platform;
 
30
using EmpathyPlugin;
 
31
using Telepathy;
 
32
 
 
33
namespace EmpathyPlugin
 
34
{
 
35
        public class EmpathySetStatusAction : Act
 
36
        {
 
37
                public EmpathySetStatusAction ()
 
38
                {
 
39
                }
 
40
 
 
41
                public override string Name
 
42
                {
 
43
                        get { return AddinManager.CurrentLocalizer.GetString ("Set status"); }
 
44
                }
 
45
 
 
46
                public override string Description
 
47
                {
 
48
                        get { return AddinManager.CurrentLocalizer.GetString ("Set empathy status message"); }
 
49
                }
 
50
 
 
51
                public override string Icon
 
52
                {
 
53
                        get { return "empathy"; }
 
54
                }
 
55
 
 
56
                public override IEnumerable<Type> SupportedItemTypes
 
57
                {
 
58
                        get {
 
59
                                yield return typeof (EmpathyStatusItem);
 
60
                                yield return typeof (ITextItem);
 
61
                        }
 
62
                }
 
63
 
 
64
                public override IEnumerable<Type> SupportedModifierItemTypes
 
65
                {
 
66
                        get { 
 
67
                                yield return typeof (ITextItem); 
 
68
                                yield return typeof (EmpathyStatusItem);
 
69
                        }
 
70
                }
 
71
 
 
72
                public override bool ModifierItemsOptional
 
73
                {
 
74
                        get { return true; }
 
75
                }
 
76
 
 
77
                public override bool SupportsModifierItemForItems (IEnumerable<Item> items, Item modItem)
 
78
                {
 
79
                        if (items.First () is EmpathySavedStatusItem || modItem is EmpathySavedStatusItem)
 
80
                                return false;
 
81
                        if (items.First () is EmpathyStatusItem && modItem is ITextItem)
 
82
                                return true;
 
83
                        if (items.First () is ITextItem && modItem is EmpathyStatusItem)
 
84
                                return true;
 
85
                        return false;
 
86
                }
 
87
 
 
88
                public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
 
89
                {
 
90
                        ConnectionPresenceType status;
 
91
                        string message = "";
 
92
                        try
 
93
                        {
 
94
 
 
95
                                if (items.First () is EmpathySavedStatusItem)
 
96
                                {
 
97
                                        status = (items.First () as EmpathySavedStatusItem).Status;
 
98
                                        message = (items.First () as EmpathySavedStatusItem).Message;
 
99
                                        EmpathyPlugin.SetAvailabilityStatus(status, message);
 
100
                                } 
 
101
                                else if (items.First () is EmpathyStatusItem)
 
102
                                {
 
103
                                        status = (items.First () as EmpathyStatusItem).Status;
 
104
                                        if (modItems.Any ())
 
105
                                                message = (modItems.First () as ITextItem).Text;
 
106
                                        EmpathyPlugin.SetAvailabilityStatus(status, message);
 
107
                                } 
 
108
                                else if (items.First () is ITextItem)
 
109
                                {
 
110
                                        if (modItems.Any ())
 
111
                                                status = (modItems.First () as EmpathyStatusItem).Status;
 
112
                                        else            
 
113
                                                status = ConnectionPresenceType.Available;
 
114
                                        message = (items.First () as ITextItem).Text;
 
115
                                        EmpathyPlugin.SetAvailabilityStatus(status, message);
 
116
                                }
 
117
                        }
 
118
                        catch (Exception e)
 
119
                        {
 
120
                                Log<EmpathySetStatusAction>.Error ("Could not set Empathy status: {0}", e.Message);
 
121
                                Log<EmpathySetStatusAction>.Debug (e.StackTrace);
 
122
                        } 
 
123
                        yield break;
 
124
                }
 
125
        }
 
126
}