~iwarford/do-plugins/fart-plugin-fwiw

« back to all changes in this revision

Viewing changes to VirtualBox/src/OffAction.cs

  • Committer: Jason Jones
  • Date: 2008-12-24 04:45:02 UTC
  • mfrom: (335.1.9 do-plugins)
  • Revision ID: jasonedwardjones@gmail.com-20081224044502-ra56ym06cp1iqs7t
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  OffAction.cs
 
2
//
 
3
//  GNOME Do is the legal property of its developers.
 
4
//  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
 
 
21
using System;
 
22
using System.Linq;
 
23
using System.Diagnostics;
 
24
using System.Collections.Generic;
 
25
using System.Threading;
 
26
using Mono.Unix;
 
27
 
 
28
using Do.Universe;
 
29
 
 
30
namespace VirtualBox
 
31
{
 
32
        //Power Off VM State
 
33
        public class PowerOffVM : Act
 
34
        {
 
35
                public PowerOffVM()
 
36
                {
 
37
                }
 
38
 
 
39
                public override string Name {
 
40
                        get { return Catalog.GetString("Power Off Virtual Machine"); }
 
41
                }
 
42
 
 
43
                public override string Description {
 
44
                        get { return Catalog.GetString("Powers off the selected Virtual Machine"); }
 
45
                }
 
46
 
 
47
                public override string Icon {
 
48
                        get { return "vm_delete_32px.png@"+GetType().Assembly.FullName; }
 
49
                }
 
50
 
 
51
                public override IEnumerable<Type> SupportedItemTypes {
 
52
                        get {
 
53
                                return new Type[] { typeof (VMItem) };
 
54
                        }
 
55
                }
 
56
 
 
57
                public override bool SupportsItem (Item item) {
 
58
                        //only allow "poweringoff" of a machine if it is running
 
59
                        VMItem v = item as VMItem;
 
60
                        if ((v.Status == VMState.on) || (v.Status == VMState.headless))
 
61
                                return true;
 
62
                        else return false;
 
63
                }
 
64
                
 
65
                
 
66
                public override IEnumerable<Item> DynamicModifierItemsForItem (Item item)
 
67
                {                       
 
68
                        List<Item> DynItems = new List<Item> ();
 
69
                        VMItem vm = (item as VMItem);
 
70
                        
 
71
                        DynItems.Add(
 
72
                                     new VMDynItm(Catalog.GetString("Discard State"),
 
73
                                                  Catalog.GetString("Restore VM state to current Snapshot"),
 
74
                                                  "vm_discard_32px.png@"+GetType().Assembly.FullName,
 
75
                                                  VMState.off
 
76
                                                  )
 
77
                                     );                 
 
78
                        try 
 
79
                        { 
 
80
                                if (vm.HasSavedStates)
 
81
                                        return DynItems.ToArray(); 
 
82
                                else return null;
 
83
                        }
 
84
                        catch { return null; }
 
85
 
 
86
                }
 
87
                
 
88
                public override IEnumerable<Type> SupportedModifierItemTypes
 
89
                {
 
90
                        get {
 
91
                                return new Type[] { typeof (VMDynItm) };
 
92
                        }
 
93
                }
 
94
                
 
95
                public override bool ModifierItemsOptional
 
96
                {
 
97
                        get { return true; }
 
98
                }
 
99
 
 
100
                public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
 
101
                {
 
102
                        foreach (Item i in items)
 
103
                        {
 
104
                                VMItem vm = (i as VMItem);
 
105
                                VMThread thread;
 
106
                                Thread t;
 
107
                                if (modItems.Any ())
 
108
                                {
 
109
                                        thread = new VMThread(ref vm);
 
110
                                        t = new Thread (new ThreadStart(thread.DoShutdownRestoreAction));
 
111
                                }
 
112
                                else 
 
113
                                {
 
114
                                        thread = new VMThread(VMState.off, ref vm);
 
115
                                        t = new Thread (new ThreadStart(thread.DoAction));
 
116
                                }
 
117
                                t.IsBackground = true;
 
118
                                t.Start();
 
119
                        }
 
120
                        return null;
 
121
                }
 
122
        }
 
123
}