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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
/*
* Copyright (C) 2006
* Siraj Razick <siraj@kdemail.net>
* PhobosK <phobosk@mail.kbfx.org>
* see Also AUTHORS
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2 as
* published by the Free Software Foundation
*
* 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 Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <kapplication.h>
#include <kservice.h>
#include <kservicegroup.h>
#include <kdebug.h>
#include <tqdir.h>
#include <tqfileinfo.h>
#include <kurl.h>
#include "kbfxstrigiplugin.h"
bool
stopDaemon ()
{
return true;
}
bool
startDaemon ()
{
stopDaemon ();
// TODO: add the actual code to start the daemon process
return true;
}
void
init ()
{}
void
poll ()
{
}
KbfxDataStack *
view ()
{
KbfxDataGroup *appGroup = new KbfxDataGroup ();
KbfxDataGroupList *glist = new KbfxDataGroupList ();
KbfxDataStack *gstack = new KbfxDataStack ();
init ();
glist->setName ( "Configure" );
appGroup->setName ( "Strigi Options" );
KbfxDataSource *m_source = new KbfxDataSource ();
m_source->setName ( "Start Indexing" );
m_source->setCommand ( "kfmclient exec strigi:/status/startindexing" );
m_source->setComment ( "Starts Building an Index" );
m_source->setIconPath ( "enhanced_browsing.png" );
appGroup->addItem ( m_source );
m_source = new KbfxDataSource ();
m_source->setName ( "Stop Indexing" );
m_source->setCommand ( "kfmclient exec strigi:/status/stopindexing" );
m_source->setComment ( "Stop Index Building Process" );
m_source->setIconPath ( "enhanced_browsing.png" );
appGroup->addItem ( m_source );
m_source = new KbfxDataSource ();
m_source->setName ( "Stop Daemon" );
m_source->setCommand ( "kfmclient exec strigi:/status/stop" );
m_source->setComment ( "Stop Search Engine" );
m_source->setIconPath ( "enhanced_browsing.png" );
appGroup->addItem ( m_source );
m_source = new KbfxDataSource ();
m_source->setName ( "Advanced Searching" );
m_source->setCommand ( "kfmclient exec strigi:/" );
m_source->setComment ( "Detailed Search Results" );
m_source->setIconPath ( "enhanced_browsing.png" );
appGroup->addItem ( m_source );
m_source = new KbfxDataSource ();
m_source->setName ( "Start Daemon" );
m_source->setCommand ( "kfmclient exec strigi:/status/start" );
m_source->setComment ( "Start Search Engine" );
m_source->setIconPath ( "enhanced_browsing.png" );
appGroup->addItem ( m_source );
glist->addGroup ( appGroup );
gstack->addGroupList ( glist );
gstack->setName ( "Strigi" );
return gstack;
}
TQString
name ()
{
return TQString ( "Strigi" );
}
TQString
type ()
{
return TQString ( "Stub Type" );
}
uint
id ()
{
return 1; //TODO see what can be done... maybe rand()?
}
KbfxDataGroup *
search ( TQString _keyword )
{
KbfxDataGroup *datagroup = new KbfxDataGroup ();
datagroup->setName ( "Strigi" );
TQString socketpath = TQDir::homeDirPath () + "/.strigi/socket";
startDaemon ();
kdDebug() << socketpath << endl;
AsyncSocketClient socket;
ClientInterface::Hits hits;
socket.setSocketPath ( ( const char * ) socketpath.utf8 () );
bool ok = socket.query ( _keyword.ascii (), 5, 0 );
if ( ok == true )
{
while ( !socket.statusChanged () )
{
struct timespec sleeptime;
sleeptime.tv_sec = 0;
sleeptime.tv_nsec = 1;
nanosleep ( &sleeptime, 0 );
}
hits = socket.getHits ();
jstreams::IndexedDocument hit;
// int last = ( hits.hits.size () > 5 ) ? 5 : hits.hits.size ();
for ( uint i = 0; i < socket.getHits ().hits.size (); ++i )
{
jstreams::IndexedDocument hit = hits.hits[i];
KbfxDataSource *data = new KbfxDataSource ();
TQString name;
std::map < std::string, std::string >::const_iterator it =
hits.hits[i].properties.find ( "title" );
TQString filename ( hits.hits[i].uri.c_str () );
if ( filename.contains ( ".tar." ) > 0 )
{
filename = "tar:" + filename;
kdDebug() << filename << endl;
}
if ( it != hits.hits[i].properties.end () )
{
name = it->second;
}
else
{
uint pos = hits.hits[i].uri.rfind ( '/' );
if ( pos == std::string::npos )
{
name = hits.hits[i].uri;
}
else
{
name = hits.hits[i].uri.substr ( pos + 1 );
}
}
data->setName ( name );
data->setCommand ( "kfmclient exec " + filename );
TQString iconname =
KMimeType::mimeType ( hits.hits[i].mimetype.c_str () )->
icon ( TQString(), 0 );
data->setIconPath ( iconname );
datagroup->addItem ( data );
}
}
else
{
KbfxDataSource *data = new KbfxDataSource ();
data->setName ( "Start Strigi" );
data->setComment ( "Strigi Daemon down" );
data->setCommand ( "strigidaemon &" );
}
return datagroup;
}
|