~iwarford/do-plugins/autofoo

« back to all changes in this revision

Viewing changes to NX/src/NXAction.cs

  • Committer: Christopher Halse Rogers
  • Date: 2009-01-06 05:37:26 UTC
  • mfrom: (395.1.18 do-plugins)
  • Revision ID: raof@ubuntu.com-20090106053726-f21k3lsuypkcul4i
Merge again.  Stop it!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* SSHAction.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * 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
 
 
21
using System;
 
22
using System.IO;
 
23
using System.Collections.Generic;
 
24
using System.Linq;
 
25
using Do;
 
26
using Do.Universe;
 
27
using System.Diagnostics;
 
28
 
 
29
using Mono.Unix;
 
30
 
 
31
namespace NX 
 
32
{
 
33
    public class NXAction : Act
 
34
    {
 
35
        
 
36
        public override string Name {
 
37
            get { return Catalog.GetString ("Connect with NX"); }
 
38
        }
 
39
        
 
40
        public override string Description {
 
41
            get { return Catalog.GetString ("Connect with NX"); }
 
42
        }
 
43
        
 
44
        public override string Icon {
 
45
            get { return "network-server"; }
 
46
        }
 
47
        
 
48
        public override IEnumerable<Type> SupportedItemTypes {
 
49
            get { yield return typeof (NXHostItem); }
 
50
        }
 
51
        
 
52
 
 
53
        public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems) 
 
54
        {
 
55
            EnsureInPath ("/usr/NX/bin");
 
56
            
 
57
            string exec = "nxclient";
 
58
            NXHostItem hostitem = items.First () as NXHostItem;
 
59
 
 
60
            Process nxclient = new Process ();
 
61
            nxclient.StartInfo.FileName = exec;
 
62
            nxclient.StartInfo.Arguments = "--session " + hostitem.Path;
 
63
            nxclient.Start ();
 
64
            
 
65
            yield break;
 
66
        }
 
67
 
 
68
                void EnsureInPath(string path) 
 
69
                {
 
70
            char[] splitters = {':'};
 
71
            String[] paths = Environment.GetEnvironmentVariable ("PATH").Split (splitters);
 
72
            if (Array.IndexOf (paths, path) < 0) {
 
73
                Environment.SetEnvironmentVariable ("PATH", Environment.GetEnvironmentVariable ("PATH") + ":" + path);
 
74
            }
 
75
        }
 
76
    }
 
77
}