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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
/*
* Copyright (C) 2002, 2003 David Faure <faure@kde.org>
*
* This library 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 library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <kdebug.h>
#include <kuserprofile.h>
#include <ktrader.h>
#include <kservice.h>
#include <kmimetype.h>
#include <assert.h>
#include <kstandarddirs.h>
#include <kservicegroup.h>
#include <kimageio.h>
#include <kprotocolinfo.h>
#include <kiconloader.h>
#include <tdeapplication.h>
#include <stdio.h>
#include <stdlib.h>
bool check(TQString txt, TQString a, TQString b)
{
if (a.isEmpty())
a = TQString::null;
if (b.isEmpty())
b = TQString::null;
if (a == b) {
kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
}
else {
kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl
;
exit(1);
}
return true;
}
void debug(TQString txt)
{
fprintf(stderr, "%s\n", txt.ascii());
}
void debug(const char *txt)
{
fprintf(stderr, "%s\n", txt);
}
void debug(const char *format, const char *txt)
{
fprintf(stderr, format, txt);
fprintf(stderr, "\n");
}
int main(int argc, char *argv[])
{
TDEApplication k(argc,argv,"whatever",false/*noGUI*/); // KMessageBox needs KApp for makeStdCaption
TQCString instname = "kword";
TQString desktopPath = TQString::fromLatin1( "Office/%1.desktop" ).arg( instname );
tqDebug( "Looking for %s", desktopPath.latin1() );
KService::Ptr service = KService::serviceByDesktopPath( desktopPath );
if ( service )
tqDebug( "found: %s", service->desktopEntryPath().latin1() );
else
tqDebug( "not found" );
tqDebug( "Looking for desktop name = %s", instname.data() );
service = KService::serviceByDesktopName( instname );
if ( service )
tqDebug( "found: %s", service->desktopEntryPath().latin1() );
else
tqDebug( "not found" );
debug("Trying to look for text/plain");
KMimeType::Ptr s1 = KMimeType::mimeType("text/plain");
if ( s1 )
{
debug("Found it !");
debug(TQString("Comment is %1").arg(s1->comment(KURL(),false)));
}
else
{
debug("Not found !");
exit(1);
}
debug("Trying to look for application/x-zerosize");
KMimeType::Ptr s0 = KMimeType::mimeType("application/x-zerosize");
if ( s0 )
{
debug("Found it !");
debug(TQString("Comment is %1").arg(s0->comment(KURL(),false)));
}
else
{
debug("Not found !");
exit(1);
}
debug("Trying to look for Desktop Pager");
KService::Ptr se = KService::serviceByName("Desktop Pager");
if ( se )
{
debug("Found it !");
debug(TQString("Comment is %1").arg(se->comment()));
}
else
{
debug("Not found !");
}
debug("Trying to look for kpager");
se = KService::serviceByDesktopName("kpager");
if ( se )
{
debug("Found it !");
debug(TQString("Comment is %1").arg(se->comment()));
TQVariant qv = se->property("X-DocPath");
debug(TQString("Property type is %1").arg(qv.typeName()));
debug(TQString("Property value is %1").arg(qv.toString()));
}
else
{
debug("Not found !");
}
debug("Trying to look for System/kpager.desktop");
se = KService::serviceByDesktopPath("System/kpager.desktop");
if ( se )
{
debug("Found it !");
debug(TQString("Comment is %1").arg(se->comment()));
}
else
{
debug("Not found !");
}
debug("Trying to look for System/fake-entry.desktop");
se = KService::serviceByDesktopPath("System/fake-entry.desktop");
if ( se )
{
debug("Found it !");
debug(TQString("Comment is %1").arg(se->comment()));
}
else
{
debug("Not found !");
}
#if 1
debug("Querying userprofile for services associated with text/plain");
KServiceTypeProfile::OfferList offers = KServiceTypeProfile::offers("text/plain");
debug(TQString("got %1 offers").arg(offers.count()));
KServiceTypeProfile::OfferList::Iterator it = offers.begin();
for ( ; it != offers.end() ; it++ )
{
debug((*it).service()->name());
}
debug("Querying userprofile for services associated with KOfficeFilter");
offers = KServiceTypeProfile::offers("KOfficeFilter");
debug(TQString("got %1 offers").arg(offers.count()));
it = offers.begin();
for ( ; it != offers.end() ; it++ )
{
debug((*it).service()->name());
}
debug("Querying trader for Konqueror/Plugin");
TDETrader::OfferList traderoffers = TDETrader::self()->query("Konqueror/Plugin");
debug(TQString("got %1 offers").arg(traderoffers.count()));
TDETrader::OfferList::Iterator trit = traderoffers.begin();
for ( ; trit != traderoffers.end() ; trit++ )
{
debug((*trit)->name());
}
#endif
//
debug("\nTrying findByURL for $TDEDIR/bin/kdesktop");
KMimeType::Ptr mf = KMimeType::findByURL( TDEStandardDirs::findExe( "kdesktop" ), 0,
true, false );
assert( mf );
check( "A binary's mimetype", mf->name(), "application/x-executable" );
//
debug("\nTrying findByURL for folder_home.png");
TQString fh;
(void)k.iconLoader()->loadIcon("folder_home.png",TDEIcon::Desktop,0,TDEIcon::DefaultState,&fh);
mf = KMimeType::findByURL( fh, 0, true, false );
assert( mf );
check( "A PNG's mimetype", mf->name(), "image/png" );
//
//debug("\nTrying findByURL for Makefile.am");
//mf = KMimeType::findByURL( KURL("/tmp/Makefile.am"), 0, true, false );
//assert( mf );
//debug(TQString("Name is %1").arg(mf->name()));
//debug(TQString("Comment is %1").arg(mf->comment(KURL(),false)));
debug("\nTrying findByURL for man:/ls");
mf = KMimeType::findByURL( KURL("man:/ls") );
assert( mf );
check( "man:/ls", mf->name(), "text/html" );
check( "man:/ls/", mf->name(), "text/html" );
mf = KMimeType::findByURL( KURL("http://foo/bar.png") );
check( "HTTP URL", mf->name(), "application/octet-stream" ); // HTTP can't know before downloading
#if 1
KMimeType::List mtl;
mtl = KMimeType::allMimeTypes( );
assert( mtl.count() );
debug(TQString("Found %1 mime types.").arg(mtl.count()));
for(int i = 0; i < (int)mtl.count(); i++)
{
debug(TQString("Mime type %1: %2.").arg(i).arg(mtl[i]->name()));
}
KService::List sl;
sl = KService::allServices( );
assert( sl.count() );
debug(TQString("Found %1 services.").arg(sl.count()));
KServiceGroup::Ptr root = KServiceGroup::root();
KServiceGroup::List list = root->entries();
//KServiceGroup::Ptr topGroup = KServiceGroup::childGroup( "kview" );
//Q_ASSERT( topGroup );
//KServiceGroup::List list = topGroup->entries();
KServiceGroup::Ptr first;
debug(TQString("Found %1 entries").arg(list.count()));
for( KServiceGroup::List::ConstIterator it = list.begin();
it != list.end(); it++)
{
KSycocaEntry *p = (*it);
if (p->isType(KST_KService))
{
KService *service = static_cast<KService *>(p);
debug(service->name());
debug(service->desktopEntryPath());
}
else if (p->isType(KST_KServiceGroup))
{
KServiceGroup *serviceGroup = static_cast<KServiceGroup *>(p);
debug(TQString(" %1 -->").arg(serviceGroup->caption()));
if (!first) first = serviceGroup;
}
else
{
debug("KServiceGroup: Unexpected object in list!");
}
}
if (first)
{
list = first->entries();
debug(TQString("Found %1 entries").arg(list.count()));
for( KServiceGroup::List::ConstIterator it = list.begin();
it != list.end(); it++)
{
KSycocaEntry *p = (*it);
if (p->isType(KST_KService))
{
KService *service = static_cast<KService *>(p);
debug(TQString(" %1").arg(service->name()));
}
else if (p->isType(KST_KServiceGroup))
{
KServiceGroup *serviceGroup = static_cast<KServiceGroup *>(p);
debug(TQString(" %1 -->").arg(serviceGroup->caption()));
}
else
{
debug("KServiceGroup: Unexpected object in list!");
}
}
}
debug("--services that require initialisation--");
sl = KService::allInitServices();
for( KService::List::ConstIterator it = sl.begin();
it != sl.end(); it++)
{
KService *service = static_cast<KService *>(*it);
debug(service->name());
}
debug("--End of list--");
debug("--protocols--");
TQStringList stringL = KProtocolInfo::protocols();
for( TQStringList::ConstIterator it = stringL.begin();
it != stringL.end(); it++)
{
debug((*it).ascii());
}
debug("--End of list--");
#endif
#if 0
KImageIO::registerFormats();
TQStringList types;
types = KImageIO::types(KImageIO::Reading);
debug("Can read:");
for(TQStringList::ConstIterator it = types.begin();
it != types.end(); ++it)
debug(TQString(" %1").arg((*it)));
types = KImageIO::types(KImageIO::Writing);
debug("Can write:");
for(TQStringList::ConstIterator it = types.begin();
it != types.end(); ++it)
debug(TQString(" %1").arg((*it)));
TQString rPattern = KImageIO::pattern( KImageIO::Reading );
debug("Read pattern:\n%s", rPattern.ascii());
TQString wPattern = KImageIO::pattern( KImageIO::Writing );
debug("Write pattern:\n%s", wPattern.ascii());
TQString suffix = KImageIO::suffix("JPEG");
debug("Standard suffix for JPEG: %s", suffix.ascii());
types = KImageIO::mimeTypes(KImageIO::Reading);
debug("Can read (mimetypes):");
for(TQStringList::ConstIterator it = types.begin();
it != types.end(); ++it)
debug(" %s", (*it).ascii());
types = KImageIO::mimeTypes(KImageIO::Writing);
debug("Can write (mimetypes):");
for(TQStringList::ConstIterator it = types.begin();
it != types.end(); ++it)
debug(" %s", (*it).ascii());
debug("done");
#endif
return 0;
}
|