~cszikszoy/do-plugins/pastebin

« back to all changes in this revision

Viewing changes to Pidgin/src/PidginChatCommand.cs

  • Committer: djsiegel at gmail
  • Date: 2007-11-07 17:13:21 UTC
  • Revision ID: djsiegel@gmail.com-20071107171321-zgu46ukqlpdx1ypa
Initial files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  PidginChatCommand.cs (requires package libpurple-bin to use purple-remote)
 
2
//
 
3
//  GNOME Do is the legal property of its developers, whose names are too numerous
 
4
//  to list here.  Please refer to the COPYRIGHT file distributed with this
 
5
//  source distribution.
 
6
//
 
7
//  This program is free software: you can redistribute it and/or modify
 
8
//  it under the terms of the GNU General Public License as published by
 
9
//  the Free Software Foundation, either version 3 of the License, or
 
10
//  (at your option) any later version.
 
11
//
 
12
//  This program is distributed in the hope that it will be useful,
 
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
//  GNU General Public License for more details.
 
16
//
 
17
//  You should have received a copy of the GNU General Public License
 
18
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
using System;
 
21
using System.Threading;
 
22
using System.Diagnostics;
 
23
 
 
24
using Do.Addins;
 
25
 
 
26
namespace Do.Universe
 
27
{
 
28
        
 
29
        public class PidginChatCommand : ICommand
 
30
        {
 
31
                
 
32
                public PidginChatCommand ()
 
33
                {
 
34
                }
 
35
                
 
36
                public string Name {
 
37
                        get { return "Chat"; }
 
38
                }
 
39
                
 
40
                public string Description {
 
41
                        get { return "Send an instant message to a friend."; }
 
42
                }
 
43
                
 
44
                public string Icon {
 
45
                        get { return "internet-group-chat"; }
 
46
                }
 
47
                
 
48
                public Type[] SupportedItemTypes {
 
49
                        get {
 
50
                                return new Type[] {
 
51
                                        typeof (ContactItem),
 
52
                                };
 
53
                        }
 
54
                }
 
55
                
 
56
                public Type[] SupportedModifierItemTypes {
 
57
                        get { return null; }
 
58
                }
 
59
 
 
60
                public bool SupportsItem (IItem item)
 
61
                {
 
62
                        bool has_im;
 
63
                        ContactItem c;
 
64
                        
 
65
                        c = item as ContactItem;
 
66
                        has_im = c.AIMs.Count > 0 ||
 
67
                                     c.Jabbers.Count > 0;
 
68
                        return has_im;
 
69
                }
 
70
                
 
71
                public bool SupportsModifierItemForItems (IItem[] items, IItem modItem)
 
72
                {
 
73
                        return false;
 
74
                }
 
75
                
 
76
                public void Perform (IItem[] items, IItem[] modifierItems)
 
77
                {
 
78
                        string protocol, screenname, dbus_instruction;
 
79
                        ContactItem c;
 
80
 
 
81
                        protocol = screenname = "";
 
82
                        foreach (IItem item in items) {
 
83
                                if (item is ContactItem) {
 
84
                                        c = item as ContactItem;
 
85
                                        if (c.Jabbers.Count > 0) {
 
86
                                                protocol = "jabber";
 
87
                                                screenname = c.Jabbers[0];
 
88
                                        } else if (c.AIMs.Count > 0) {
 
89
                                                protocol = "aim";
 
90
                                                screenname = c.AIMs[0];
 
91
                                        }
 
92
 
 
93
                                        new Thread ((ThreadStart) delegate {
 
94
                                                if (!Pidgin.InstanceIsRunning ()) {
 
95
                                                        Process.Start ("pidgin");
 
96
                                                        Thread.Sleep (4 * 1000);
 
97
                                                }
 
98
                                                dbus_instruction = string.Format ("\"{0}:goim?screenname={1}\"", protocol, screenname);
 
99
                                                Process.Start ("purple-remote", dbus_instruction);
 
100
                                        }).Start ();
 
101
                                }
 
102
                        }
 
103
                }
 
104
                
 
105
        }
 
106
}