~zeitgeist-sharp/zeitgeist-sharp/experiments

« back to all changes in this revision

Viewing changes to Zeitgeist/ZeitgeistClient.cs

  • Committer: Manish Sinha
  • Date: 2010-09-06 21:01:31 UTC
  • Revision ID: manishsinha.tech@gmail.com-20100906210131-xn3ba8jfefghr9aj
Created DataSourceClient and RawDataModel

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections.Generic;
 
3
using Zeitgeist.Client;
 
4
using NDesk.DBus;
 
5
using Zeitgeist.Datamodel;
 
6
 
 
7
namespace Zeitgeist
 
8
{
 
9
        public class DataSourceClient
 
10
        {
 
11
                public static List<DataSource> GetDataSources()
 
12
                {
 
13
                        IDataSource srcInterface = GetDBusObject();
 
14
                        RawDataSource[] srcs = srcInterface.GetDataSources();
 
15
                        
 
16
                        List<DataSource> srcList = new List<DataSource>();
 
17
                        
 
18
                        foreach(RawDataSource src in srcs)
 
19
                        {
 
20
                                DataSource et = DataSource.FromRaw(src);
 
21
                                srcList.Add(et);
 
22
                        }
 
23
                        
 
24
                        return srcList;
 
25
                }
 
26
                
 
27
                public static bool RegisterDataSources(string uniqueId, string name, string description, List<Event> events)
 
28
                {
 
29
                        IDataSource srcInterface = GetDBusObject();
 
30
                        
 
31
                        
 
32
                        List<RawEvent> rawEventList = new List<RawEvent>();
 
33
                        foreach(Event src in events)
 
34
                        {
 
35
                                RawEvent evnt = src.GetRawEvent();
 
36
                                rawEventList.Add(evnt);
 
37
                        }
 
38
                        
 
39
                        return srcInterface.RegisterDataSources(uniqueId, name, description, rawEventList.ToArray());
 
40
                }
 
41
                
 
42
                void SetDataSourceEnabled(string uniqueId, bool enabled)
 
43
                {
 
44
                        IDataSource srcInterface = GetDBusObject();
 
45
                        
 
46
                        srcInterface.SetDataSourceEnabled(uniqueId, enabled);
 
47
                }
 
48
                
 
49
                private static IDataSource GetDBusObject()
 
50
                {
 
51
                        ObjectPath objPath = new ObjectPath("/org/gnome/zeitgeist/data_source_registry");
 
52
                        IDataSource log = Bus.Session.GetObject<IDataSource>("org.gnome.zeitgeist.Engine", objPath);
 
53
                        
 
54
                        return log;
 
55
                }
 
56
        }
 
57
}
 
58