~do-plugins/do-plugins/trunk

« back to all changes in this revision

Viewing changes to Tasque/TasqueAction.cs

  • Committer: Christopher James Halse Rogers
  • Date: 2008-04-03 22:32:04 UTC
  • mto: This revision was merged to the branch mainline in revision 87.
  • Revision ID: chalserogers@gmail.com-20080403223204-yh7zudzdzs3xwi7r
Revert deleted GNOME-Screenshot, GNOME-Terminal, GmailContactItemSource, and Tasque plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// TasqueAction.cs
 
2
//
 
3
// This program is free software; you can redistribute it and/or modify
 
4
// it under the terms of the GNU General Public License as published by
 
5
// the Free Software Foundation; either version 3 of the License, or
 
6
// (at your option) any later version.
 
7
//
 
8
// This program is distributed in the hope that it will be useful,
 
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
11
// GNU General Public License for more details.
 
12
// 
 
13
// You should have received a copy of the GNU General Public License
 
14
// along with this program; if not, see <http://www.gnu.org/licenses/> or 
 
15
// write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 
16
// Boston, MA 02111-1307 USA
 
17
//
 
18
 
 
19
using System;
 
20
using System.Collections;
 
21
using System.Collections.Generic;
 
22
using GConf;
 
23
 
 
24
using Do.Universe;
 
25
using Tasque;
 
26
using Tasque.DBus;
 
27
using Tasque.Category.Item;
 
28
 
 
29
namespace Tasque
 
30
{
 
31
        
 
32
        public class TasqueCreateTask : AbstractAction
 
33
        {
 
34
                
 
35
                public TasqueCreateTask ()
 
36
                {
 
37
                }
 
38
                
 
39
                public override string Name {
 
40
                        get { return "Create a new task"; }
 
41
                }
 
42
                
 
43
                public override string Description {
 
44
                        get { return " Create a new task in Tasque"; }
 
45
                }
 
46
                
 
47
                public override string Icon {
 
48
                        get { return "tasque"; } 
 
49
                }
 
50
                
 
51
                public override Type[] SupportedItemTypes {
 
52
                        get {
 
53
                                return new Type[] {
 
54
                                        typeof (ITextItem),
 
55
                                };
 
56
                        }
 
57
                }
 
58
                        
 
59
                public override bool SupportsItem (IItem item) {
 
60
                        return true;
 
61
                }
 
62
                
 
63
                public override Type[] SupportedModifierItemTypes {
 
64
                        get {
 
65
                                return new Type[] {
 
66
                                        typeof(TasqueCategoryItem),
 
67
                                };
 
68
                        }
 
69
                }
 
70
                        
 
71
                public override IItem[] DynamicModifierItemsForItem (IItem item)
 
72
                {
 
73
                        List<IItem> items = new List<IItem> ();
 
74
                        
 
75
                        try {
 
76
                                items = Tasque.GetCategoryItems ();
 
77
                                return items.ToArray();
 
78
                        } catch {
 
79
                                return null;
 
80
                        }
 
81
                        
 
82
                }
 
83
                
 
84
                public override bool ModifierItemsOptional {
 
85
                        get { return true; }
 
86
                }
 
87
 
 
88
                public override IItem[] Perform ( IItem[] items, IItem[] modifierItems )
 
89
                {
 
90
                        if ( modifierItems.Length > 0 ) 
 
91
                                TextItemPerform (items[0] as ITextItem, modifierItems[0] as TasqueCategoryItem);
 
92
                        else 
 
93
                                TextItemPerform (items[0] as ITextItem, new TasqueCategoryItem (""));
 
94
                        
 
95
                        return null;
 
96
                }
 
97
                
 
98
                protected IItem[] TextItemPerform (ITextItem item, TasqueCategoryItem category)
 
99
                {
 
100
                        string defaultCategory;
 
101
 
 
102
                        ArrayList list = new ArrayList ();
 
103
                        GConf.Client conf = new GConf.Client ();
 
104
                        TasqueDBus tasque = new TasqueDBus ();
 
105
                        
 
106
                        try {
 
107
                                defaultCategory = conf.Get ("/apps/gnome-do/plugins/tasque/default_category") as string;
 
108
                        } catch (GConf.NoSuchKeyException) {
 
109
                                conf.Set ("/apps/gnome-do/plugins/tasque/default_category", "");
 
110
                                return null;
 
111
                        }
 
112
                        
 
113
                        if (category.Name != "" ) {
 
114
                                tasque.CreateTask(category.Name, item.Text);
 
115
                        }
 
116
                        else if (defaultCategory == String.Empty) {
 
117
                                
 
118
                                string[] split = item.Text.Split (':');
 
119
                                if (split.GetValue(0).ToString() == item.Text) {
 
120
                                        list = tasque.GetCategoryNames ();
 
121
                                        tasque.CreateTask (list[0].ToString(), item.Text);
 
122
                                }
 
123
                                else {
 
124
                                        tasque.CreateTask (split.GetValue(0).ToString(), split.GetValue(1).ToString());
 
125
                                }
 
126
                        }
 
127
                        else {
 
128
                                
 
129
                                string[] split = item.Text.Split (':');
 
130
                                
 
131
                                if (split.GetValue(0).ToString() == item.Text)
 
132
                                        tasque.CreateTask (defaultCategory, item.Text);
 
133
                                else 
 
134
                                        tasque.CreateTask (split.GetValue(0).ToString(), split.GetValue(1).ToString());
 
135
                        }
 
136
                        return null;
 
137
                }
 
138
 
 
139
        }
 
140
}