~do-plugins/do-plugins/trunk

« back to all changes in this revision

Viewing changes to Tasque/TasqueDBus.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
// TasqueDBus.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
 
 
20
using System;
 
21
using System.Collections;
 
22
using NDesk.DBus;
 
23
using org.freedesktop.DBus;
 
24
 
 
25
using Do.Universe;
 
26
 
 
27
 
 
28
namespace Tasque.DBus
 
29
{
 
30
        [Interface("org.gnome.Tasque.RemoteControl")]
 
31
        public interface ITasque
 
32
        {
 
33
                string CreateTask (string categoryName, string taskName, bool enterEditMode);
 
34
                string[] GetCategoryNames ();
 
35
                void ShowTasks ();
 
36
        }
 
37
 
 
38
        public class TasqueDBus
 
39
        {
 
40
                
 
41
                private const string OBJECT_PATH = "/org/gnome/Tasque/RemoteControl";
 
42
                private const string BUS_NAME = "org.gnome.Tasque";
 
43
                private static ITasque Tasque;
 
44
 
 
45
                public TasqueDBus ()
 
46
                {
 
47
                        try {
 
48
                                Tasque = FindInstance ();
 
49
                        } catch (Exception) {
 
50
                                Console.Error.WriteLine ("Could not locate Tasque on D-Bus. Make sure Tasque is running");
 
51
                        }
 
52
                
 
53
                        BusG.Init();
 
54
                }
 
55
        
 
56
                static private ITasque FindInstance () 
 
57
                {
 
58
                        if (!Bus.Session.NameHasOwner (BUS_NAME)) 
 
59
                                throw new Exception (String.Format("Name {0} has no owner", BUS_NAME));
 
60
            
 
61
                        return Bus.Session.GetObject<ITasque> (BUS_NAME, new ObjectPath (OBJECT_PATH));
 
62
                }
 
63
                
 
64
                
 
65
                public ArrayList GetCategoryNames () 
 
66
                {
 
67
                        string[] categories = null;
 
68
                        categories = Tasque.GetCategoryNames ();
 
69
                        ArrayList CategoryNames = new ArrayList ();
 
70
                        
 
71
                        foreach (string category in categories) 
 
72
                                CategoryNames.Add (category);
 
73
                        
 
74
                        return CategoryNames;
 
75
                }
 
76
 
 
77
                
 
78
                public string CreateTask (string category, string task) 
 
79
                {
 
80
                        ArrayList list = GetCategoryNames ();
 
81
                        
 
82
                        if (list.Contains (category)) 
 
83
                                return Tasque.CreateTask (category, task,false);
 
84
                        else 
 
85
                                return Tasque.CreateTask (list[0].ToString(), task, false);
 
86
                        
 
87
                }
 
88
                
 
89
                public void ShowTasks ()
 
90
                {
 
91
                        Tasque.ShowTasks ();
 
92
                }
 
93
        }
 
94
}