~c-franke/do/XesamSearch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// DoXesamSearchAction.cs 
// User: kraut (c.franke@muenchen-mail.de) at 22:23 21.02.2008
//
//  GNOME Do is the legal property of its developers, whose names are too numerous
//  to list here.  Please refer to the COPYRIGHT file distributed with this
//  source distribution.
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//gmcs -target:library -r:System -r:/usr/lib/gnome-do/Do.Addins.dll -r:/usr/lib/mono/gac/NDesk.DBus/1.0.0.0__f6716e4f9b2ed099/NDesk.DBus.dll *.cs -out:XSearch.dll 


using System;
using System.Collections.Generic;
using Do.Universe;

namespace Do.Addins.DoXesam
{
	public class DoXesamSearchAction: AbstractAction
	{
		public DoXesamSearchAction()
		{
		}
		
		public  override string Name
		{
			get { return "XSearch"; }
		}
		
		public  override string Description
		{
			get { return "Searching with Beagle / Tracker / Strigi / Pinot "; }
		} 
		
		public  override string Icon
		{
			get { return "system-search"; }
		}
		
		public override Type[] SupportedItemTypes
		{
			get {
				return new Type[] {
					typeof (ITextItem)
				};
			}
		}
		
		public override IItem[] Perform (IItem[] items, IItem[] modifierItems)
		{
			IItem item = items[0];
				//To Group by ResultType
				List<IItem> files = new List<IItem>();
				List<IItem> attachment = new List<IItem>();
				List<IItem> email = new List<IItem>();
				List<IItem> imMsg = new List<IItem>();
				List<IItem> errors = new List<IItem>();
				string searchstr = (item as ITextItem).Text;
				List<Dictionary<string,string>> result=DoXesamDriver.GetSearchResults(searchstr,1000);
				
				
				foreach(Dictionary<string,string> ss in result)
				{	
					if(result.Count>1){  //dictionary.length	
                //    Console.WriteLine("0000\n");
					if((ss["xesam:url"]).StartsWith("file://")  /** & ss["beagle:protocol"]==""**/)
					{	
						files.Add(new FileItem(""+ss["xesam:url"]));
					
					}
              //      	Console.WriteLine("1111111111\n");

					if(DoXesamDriver.BInterface)
						{
							if((ss["xesam:url"]).StartsWith("email://")&(ss["beagle:hasAttachments"]=="true"))
							{
                                Console.WriteLine("URL: {0}", ss["xesam:url"]);
								attachment.Add(new BeagleEmailAttachItem(ss));
					
							}
            //                Console.WriteLine("22222222221111111111\n");

				  		 	if((ss["xesam:url"]).StartsWith("email://")&(ss["beagle:hasAttachments"]!="true"))
				  		 	{	//Emails without Name and Description would be excluded!
                               //  Console.WriteLine("344444444444444444444");
						        BeagleEmailItem mail=new BeagleEmailItem(ss);
						        if((mail.Name.Trim() !="" | mail.Description.Trim()!=""))
									email.Add(mail);				
  							}else if((ss["beagle:protocol"])!=""){
                                //Console.WriteLine("protocaö344444444444444444444");
                                Console.WriteLine("prot: {0}", ss["beagle:protocol"]);
								imMsg.Add(new BeaglePidginItem(ss));
							}
					}else{
						if(ss["xesam:url"].StartsWith("email://")){
							email.Add(new XesamEmailItem(ss));
						}
					}
}
					//Console.WriteLine("323331111111111\n");

				//	if(ss["error"]!=""){
				//	errors.Add(new TextItem(ss["error"]));
				//    }			
                    //Console.WriteLine("3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333331111111111\n");

				}	
				//Add result groups
			//	files.AddRange(errors);
				files.AddRange(attachment);
				files.AddRange(email);
				files.AddRange(imMsg);
				return files.ToArray();		
		}
	}
}