• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
kservice.cpp
1/* This file is part of the KDE libraries
2 * Copyright (C) 1999 - 2001 Waldo Bastian <bastian@kde.org>
3 * Copyright (C) 1999 David Faure <faure@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation;
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20// $Id$
21
22#include <config.h>
23
24#include "kservice.h"
25#include "kservice_p.h"
26
27#include <sys/types.h>
28#include <sys/stat.h>
29
30#include <stddef.h>
31#include <unistd.h>
32#include <stdlib.h>
33
34#include <tqregexp.h>
35#include <tqstring.h>
36#include <tqfile.h>
37#include <tqdir.h>
38#include <tqtl.h>
39
40#include <tdesimpleconfig.h>
41#include <tdeapplication.h>
42#include <kdebug.h>
43#include <tdedesktopfile.h>
44#include <tdeglobal.h>
45#include <kiconloader.h>
46#include <tdelocale.h>
47#include <tdeconfigbase.h>
48#include <tdestandarddirs.h>
49#include <dcopclient.h>
50
51#include "kservicefactory.h"
52#include "kservicetypefactory.h"
53#include "kservicetype.h"
54#include "kuserprofile.h"
55#include "tdesycoca.h"
56
57class KService::KServicePrivate
58{
59public:
60 TQStringList categories;
61 TQString menuId;
62};
63
64KService::KService( const TQString & _name, const TQString &_exec, const TQString &_icon)
65 : KSycocaEntry( TQString::null)
66{
67 d = new KServicePrivate;
68 m_bValid = true;
69 m_bDeleted = false;
70 m_strType = "Application";
71 m_strName = _name;
72 m_strExec = _exec;
73 m_strIcon = _icon;
74 m_bTerminal = false;
75 m_bAllowAsDefault = true;
76 m_initialPreference = 10;
77}
78
79
80KService::KService( const TQString & _fullpath )
81 : KSycocaEntry( _fullpath)
82{
83 TDEDesktopFile config( _fullpath );
84
85 init(&config);
86}
87
88KService::KService( TDEDesktopFile *config )
89 : KSycocaEntry( config->fileName())
90{
91 init(config);
92}
93
94void
95KService::init( TDEDesktopFile *config )
96{
97 d = new KServicePrivate;
98 m_bValid = true;
99
100 bool absPath = !TQDir::isRelativePath(entryPath());
101 bool kde4application = config->fileName().contains("/share/applications/kde4/");
102 TQString kde4applicationprefix;
103 if (kde4application) {
104 // extract prefix
105 kde4applicationprefix = config->fileName();
106 int pos = kde4applicationprefix.find("/share/applications/kde4/");
107 kde4applicationprefix.truncate(pos);
108 }
109
110 config->setDesktopGroup();
111
112 TQMap<TQString, TQString> entryMap = config->entryMap(config->group());
113
114 entryMap.remove("Encoding"); // reserved as part of Desktop Entry Standard
115 entryMap.remove("Version"); // reserved as part of Desktop Entry Standard
116
117 m_bDeleted = config->readBoolEntry( "Hidden", false );
118 entryMap.remove("Hidden");
119 if (m_bDeleted)
120 {
121 //kdDebug() << "Hidden=true for " << entryPath() << endl;
122 m_bValid = false;
123 return;
124 }
125
126 m_strName = config->readName();
127 entryMap.remove("Name");
128 if ( m_strName.isEmpty() )
129 {
130 if (config->readEntry( "Exec" ).isEmpty())
131 {
132 //kdWarning(7012) << "The desktop entry file " << entryPath()
133 // << " has no Name and no Exec" << endl;
134 m_bValid = false;
135 return;
136 }
137 // Try to make up a name.
138 m_strName = entryPath();
139 int i = m_strName.findRev('/');
140 m_strName = m_strName.mid(i+1);
141 i = m_strName.findRev('.');
142 if (i != -1)
143 m_strName = m_strName.left(i);
144 }
145
146 m_strType = config->readType();
147 entryMap.remove("Type");
148 if ( m_strType.isEmpty() )
149 {
150 /*kdWarning(7012) << "The desktop entry file " << entryPath()
151 << " has no Type=... entry."
152 << " It should be \"Application\" or \"Service\"" << endl;
153 m_bValid = false;
154 return;*/
155 m_strType = "Application";
156 } else if ( m_strType != "Application" && m_strType != "Service" )
157 {
158 kdWarning(7012) << "The desktop entry file " << entryPath()
159 << " has Type=" << m_strType
160 << " instead of \"Application\" or \"Service\"" << endl;
161 m_bValid = false;
162 return;
163 }
164
165 // In case Try Exec is set, check if the application is available
166 if (!config->tryExec()) {
167 //kdDebug(7012) << "tryExec said false for " << entryPath() << endl;
168 m_bDeleted = true;
169 m_bValid = false;
170 return;
171 }
172
173 TQString resource = config->resource();
174
175 if ( (m_strType == "Application") &&
176 (!resource.isEmpty()) &&
177 (resource != "apps") &&
178 !absPath)
179 {
180 kdWarning(7012) << "The desktop entry file " << entryPath()
181 << " has Type=" << m_strType << " but is located under \"" << resource
182 << "\" instead of \"apps\"" << endl;
183 m_bValid = false;
184 return;
185 }
186
187 if ( (m_strType == "Service") &&
188 (!resource.isEmpty()) &&
189 (resource != "services") &&
190 !absPath)
191 {
192 kdWarning(7012) << "The desktop entry file " << entryPath()
193 << " has Type=" << m_strType << " but is located under \"" << resource
194 << "\" instead of \"services\"" << endl;
195 m_bValid = false;
196 return;
197 }
198
199 TQString name = entryPath();
200 int pos = name.findRev('/');
201 if (pos != -1)
202 name = name.mid(pos+1);
203 pos = name.find('.');
204 if (pos != -1)
205 name = name.left(pos);
206
207 m_strExec = config->readPathEntry( "Exec" );
208 if (kde4application && !m_strExec.startsWith("/")) {
209 m_strExec = "XDG_DATA_DIRS=" + kde4applicationprefix + "/share XDG_CONFIG_DIRS=/etc/xdg/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$PATH "+m_strExec;
210 }
211 else if (config->readBoolEntry("X-TDE-SubstituteUID") || config->readBoolEntry("X-KDE-SubstituteUID")) {
212 TQString path = TQString::fromLocal8Bit(getenv("PATH"));
213 TQString command;
214 TQString params;
215 int space = m_strExec.find(" ");
216 if (space==-1) {
217 command = m_strExec;
218 }
219 else {
220 command = m_strExec.left(space);
221 params = m_strExec.mid(space);
222 }
223 path.replace(TQRegExp("(^|:)(/usr/local|/usr)/bin($|:)"), "\\1\\2/sbin:\\2/bin\\3");
224 path.replace(TQRegExp("(^|:)/bin($|:)"), "\\1/sbin:/bin\\2");
225 m_strExec = TDEStandardDirs::findExe(command, path);
226 if (!m_strExec.isEmpty() && !params.isEmpty()) {
227 m_strExec += params;
228 }
229 }
230
231 entryMap.remove("Exec");
232
233 m_strIcon = config->readEntry( "Icon", "unknown" );
234 if (kde4application) {
235 if (TQFile::exists(kde4applicationprefix + "/share/icons/oxygen/22x22/apps/" + m_strIcon + ".png")) {
236 m_strIcon = kde4applicationprefix + "/share/icons/oxygen/22x22/apps/" + m_strIcon + ".png";
237 } else if (TQFile::exists(kde4applicationprefix + "/share/icons/hicolor/22x22/apps/" + m_strIcon + ".png")) {
238 m_strIcon = kde4applicationprefix + "/share/icons/hicolor/22x22/apps/" + m_strIcon + ".png";
239 }
240 }
241 entryMap.remove("Icon");
242 m_bTerminal = (config->readBoolEntry( "Terminal" )); // should be a property IMHO
243 entryMap.remove("Terminal");
244 m_strTerminalOptions = config->readEntry( "TerminalOptions" ); // should be a property IMHO
245 entryMap.remove("TerminalOptions");
246 m_strPath = config->readPath();
247 entryMap.remove("Path");
248 m_strComment = config->readComment();
249 entryMap.remove("Comment");
250 m_strGenName = config->readGenericName();
251#ifdef KDE4_MENU_SUFFIX
252 if (kde4application) {
253 m_strGenName += " [KDE4]";
254 }
255#endif
256 entryMap.remove("GenericName");
257 TQString untranslatedGenericName = config->readEntryUntranslated( "GenericName" );
258 if (!untranslatedGenericName.isEmpty())
259 entryMap.insert("UntranslatedGenericName", untranslatedGenericName);
260
261 m_lstKeywords = config->readListEntry("Keywords", ';');
262 entryMap.remove("Keywords");
263 d->categories = config->readListEntry("Categories", ';');
264 entryMap.remove("Categories");
265 m_strLibrary = config->readEntry( "X-TDE-Library" );
266 entryMap.remove("X-TDE-Library");
267 m_strInit = config->readEntry("X-TDE-Init" );
268 entryMap.remove("X-TDE-Init");
269
270 m_lstServiceTypes = config->readListEntry( "X-TDE-ServiceTypes" );
271 entryMap.remove("X-TDE-ServiceTypes");
272 // For compatibility with KDE 1.x
273 if (!kde4application)
274 m_lstServiceTypes += config->readListEntry( "MimeType", ';' );
275 entryMap.remove("MimeType");
276
277 if ( m_strType == "Application" && !m_lstServiceTypes.contains("Application") )
278 // Applications implement the service type "Application" ;-)
279 m_lstServiceTypes += "Application";
280
281 TQString dcopServiceType = config->readEntry("X-DCOP-ServiceType").lower();
282 entryMap.remove("X-DCOP-ServiceType");
283 if (dcopServiceType == "unique")
284 m_DCOPServiceType = DCOP_Unique;
285 else if (dcopServiceType == "multi")
286 m_DCOPServiceType = DCOP_Multi;
287 else if (dcopServiceType == "wait")
288 m_DCOPServiceType = DCOP_Wait;
289 else
290 m_DCOPServiceType = DCOP_None;
291
292 m_strDesktopEntryName = name.lower();
293 if (kde4application)
294 m_strDesktopEntryName = "kde4-" + m_strDesktopEntryName;
295
296 m_bAllowAsDefault = config->readBoolEntry( "AllowDefault", true );
297 entryMap.remove("AllowDefault");
298
299 m_initialPreference = config->readNumEntry( "X-TDE-InitialPreference", 1 );
300 entryMap.remove("X-TDE-InitialPreference");
301 if ( m_initialPreference == 1 )
302 m_initialPreference = config->readNumEntry( "X-TDE-InitialPreference", 1 );
303 entryMap.remove("X-TDE-InitialPreference");
304
305 // Store all additional entries in the property map.
306 // A TQMap<TQString,TQString> would be easier for this but we can't
307 // brake BC, so we have to store it in m_mapProps.
308// tqWarning("Path = %s", entryPath().latin1());
309 TQMap<TQString,TQString>::ConstIterator it = entryMap.begin();
310 for( ; it != entryMap.end();++it)
311 {
312 //tqDebug(" Key = %s Data = %s", it.key().latin1(), it.data().latin1());
313 TQString key = it.key();
314 if (kde4application && key=="OnlyShowIn" && it.data()=="KDE;")
315 key = "NotShowIn";
316 m_mapProps.insert( key, TQVariant( it.data()));
317 }
318}
319
320KService::KService( TQDataStream& _str, int offset ) : KSycocaEntry( _str, offset )
321{
322 d = new KServicePrivate;
323 load( _str );
324}
325
326KService::~KService()
327{
328 //debug("KService::~KService()");
329 delete d;
330}
331
332TQPixmap KService::pixmap( TDEIcon::Group _group, int _force_size, int _state, TQString * _path ) const
333{
334 TDEIconLoader *iconLoader=TDEGlobal::iconLoader();
335 if (!iconLoader->extraDesktopThemesAdded())
336 {
337 TQPixmap pixmap=iconLoader->loadIcon( m_strIcon, _group, _force_size, _state, _path, true );
338 if (!pixmap.isNull() ) return pixmap;
339
340 iconLoader->addExtraDesktopThemes();
341 }
342
343 return iconLoader->loadIcon( m_strIcon, _group, _force_size, _state, _path );
344}
345
346void KService::load( TQDataStream& s )
347{
348 // dummies are here because of fields that were removed, to keep bin compat.
349 // Feel free to re-use, but fields for Applications only (not generic services)
350 // should rather be added to application.desktop
351 TQ_INT8 def, term, dummy1, dummy2;
352 TQ_INT8 dst, initpref;
353 TQString dummyStr1, dummyStr2;
354 int dummyI1, dummyI2;
355 TQ_UINT32 dummyUI32;
356
357 // WARNING: IN KDE 3.x THIS NEEDS TO REMAIN COMPATIBLE WITH KDE 2.x!
358 // !! This data structure should remain binary compatible at all times !!
359 // You may add new fields at the end. Make sure to update the version
360 // number in tdesycoca.h
361 s >> m_strType >> m_strName >> m_strExec >> m_strIcon
362 >> term >> m_strTerminalOptions
363 >> m_strPath >> m_strComment >> m_lstServiceTypes >> def >> m_mapProps
364 >> m_strLibrary >> dummyI1 >> dummyI2
365 >> dst
366 >> m_strDesktopEntryName
367 >> dummy1 >> dummyStr1 >> initpref >> dummyStr2 >> dummy2
368 >> m_lstKeywords >> m_strInit >> dummyUI32 >> m_strGenName
369 >> d->categories >> d->menuId;
370
371 m_bAllowAsDefault = def;
372 m_bTerminal = term;
373 m_DCOPServiceType = (DCOPServiceType_t) dst;
374 m_initialPreference = initpref;
375
376 m_bValid = true;
377}
378
379void KService::save( TQDataStream& s )
380{
381 KSycocaEntry::save( s );
382 TQ_INT8 def = m_bAllowAsDefault, initpref = m_initialPreference;
383 TQ_INT8 term = m_bTerminal;
384 TQ_INT8 dst = (TQ_INT8) m_DCOPServiceType;
385 TQ_INT8 dummy1 = 0, dummy2 = 0; // see ::load
386 TQString dummyStr1, dummyStr2;
387 int dummyI1 = 0, dummyI2 = 0;
388 TQ_UINT32 dummyUI32 = 0;
389
390 // WARNING: IN KDE 3.x THIS NEEDS TO REMAIN COMPATIBLE WITH KDE 2.x!
391 // !! This data structure should remain binary compatible at all times !!
392 // You may add new fields at the end. Make sure to update the version
393 // number in tdesycoca.h
394 s << m_strType << m_strName << m_strExec << m_strIcon
395 << term << m_strTerminalOptions
396 << m_strPath << m_strComment << m_lstServiceTypes << def << m_mapProps
397 << m_strLibrary << dummyI1 << dummyI2
398 << dst
399 << m_strDesktopEntryName
400 << dummy1 << dummyStr1 << initpref << dummyStr2 << dummy2
401 << m_lstKeywords << m_strInit << dummyUI32 << m_strGenName
402 << d->categories << d->menuId;
403}
404
405bool KService::hasServiceType( const TQString& _servicetype ) const
406{
407 if (!m_bValid) return false; // safety test
408
409 //kdDebug(7012) << "Testing " << m_strDesktopEntryName << " for " << _servicetype << endl;
410
411 KMimeType::Ptr mimePtr = KMimeType::mimeType( _servicetype );
412 if ( mimePtr && mimePtr == KMimeType::defaultMimeTypePtr() )
413 mimePtr = 0;
414
415 bool isNumber;
416 // For each service type we are associated with, if it doesn't
417 // match then we try its parent service types.
418 TQStringList::ConstIterator it = m_lstServiceTypes.begin();
419 for( ; it != m_lstServiceTypes.end(); ++it )
420 {
421 (*it).toInt(&isNumber);
422 if (isNumber)
423 continue;
424 //kdDebug(7012) << " has " << (*it) << endl;
425 KServiceType::Ptr ptr = KServiceType::serviceType( *it );
426 if ( ptr && ptr->inherits( _servicetype ) )
427 return true;
428
429 // The mimetype inheritance ("is also") works the other way.
430 // e.g. if we're looking for a handler for mimePtr==smb-workgroup
431 // then a handler for inode/directory is ok.
432 if ( mimePtr && mimePtr->is( *it ) )
433 return true;
434 }
435 return false;
436}
437
438int KService::initialPreferenceForMimeType( const TQString& mimeType ) const
439{
440 if (!m_bValid) return 0; // safety test
441
442 bool isNumber;
443
444 // For each service type we are associated with
445 TQStringList::ConstIterator it = m_lstServiceTypes.begin();
446 for( ; it != m_lstServiceTypes.end(); ++it )
447 {
448 (*it).toInt(&isNumber);
449 if (isNumber)
450 continue;
451 //kdDebug(7012) << " has " << (*it) << endl;
452 KServiceType::Ptr ptr = KServiceType::serviceType( *it );
453 if ( !ptr || !ptr->inherits( mimeType ) )
454 continue;
455
456 int initalPreference = m_initialPreference;
457 ++it;
458 if (it != m_lstServiceTypes.end())
459 {
460 int i = (*it).toInt(&isNumber);
461 if (isNumber)
462 initalPreference = i;
463 }
464 return initalPreference;
465 }
466
467 KMimeType::Ptr mimePtr = KMimeType::mimeType( mimeType );
468 if ( mimePtr && mimePtr == KMimeType::defaultMimeTypePtr() )
469 mimePtr = 0;
470
471 // Try its parent service types.
472 it = m_lstServiceTypes.begin();
473 for( ; it != m_lstServiceTypes.end(); ++it )
474 {
475 (*it).toInt(&isNumber);
476 if (isNumber)
477 continue;
478
479 // The mimetype inheritance ("is also") works the other way.
480 // e.g. if we're looking for a handler for mimePtr==smb-workgroup
481 // then a handler for inode/directory is ok.
482 if ( !mimePtr || !mimePtr->is( *it ) )
483 continue;
484
485 int initalPreference = m_initialPreference;
486 ++it;
487 if (it != m_lstServiceTypes.end())
488 {
489 int i = (*it).toInt(&isNumber);
490 if (isNumber)
491 initalPreference = i;
492 }
493 return initalPreference;
494 }
495 return 0;
496}
497
498class KServiceReadProperty : public TDEConfigBase
499{
500public:
501 KServiceReadProperty(const TQString &_key, const TQCString &_value)
502 : key(_key), value(_value) { }
503
504 bool internalHasGroup(const TQCString &) const { /*tqDebug("hasGroup(const TQCString &)");*/ return false; }
505
506 TQStringList groupList() const { return TQStringList(); }
507
508 TQMap<TQString,TQString> entryMap(const TQString &group) const
509 { Q_UNUSED(group); return TQMap<TQString,TQString>(); }
510
511 void reparseConfiguration() { }
512
513 KEntryMap internalEntryMap( const TQString &pGroup) const
514 { Q_UNUSED(pGroup); return KEntryMap(); }
515
516 KEntryMap internalEntryMap() const { return KEntryMap(); }
517
518 void putData(const KEntryKey &_key, const KEntry& _data, bool _checkGroup)
519 { Q_UNUSED(_key); Q_UNUSED(_data); Q_UNUSED(_checkGroup); }
520
521 KEntry lookupData(const KEntryKey &_key) const
522 { Q_UNUSED(_key); KEntry entry; entry.mValue = value; return entry; }
523protected:
524 TQString key;
525 TQCString value;
526};
527
528TQVariant KService::property( const TQString& _name) const
529{
530 return property( _name, TQVariant::Invalid);
531}
532
533// Return a string TQVariant if string isn't null, and invalid variant otherwise
534// (the variant must be invalid if the field isn't in the .desktop file)
535// This allows trader queries like "exist Library" to work.
536static TQVariant makeStringVariant( const TQString& string )
537{
538 // Using isEmpty here would be wrong.
539 // Empty is "specified but empty", null is "not specified" (in the .desktop file)
540 return string.isNull() ? TQVariant() : TQVariant( string );
541}
542
543TQVariant KService::property( const TQString& _name, TQVariant::Type t ) const
544{
545 if ( _name == "Type" )
546 return TQVariant( m_strType ); // can't be null
547 else if ( _name == "Name" )
548 return TQVariant( m_strName ); // can't be null
549 else if ( _name == "Exec" )
550 return makeStringVariant( m_strExec );
551 else if ( _name == "Icon" )
552 return makeStringVariant( m_strIcon );
553 else if ( _name == "Terminal" )
554 return TQVariant( static_cast<int>(m_bTerminal) );
555 else if ( _name == "TerminalOptions" )
556 return makeStringVariant( m_strTerminalOptions );
557 else if ( _name == "Path" )
558 return makeStringVariant( m_strPath );
559 else if ( _name == "Comment" )
560 return makeStringVariant( m_strComment );
561 else if ( _name == "GenericName" )
562 return makeStringVariant( m_strGenName );
563 else if ( _name == "ServiceTypes" )
564 return TQVariant( m_lstServiceTypes );
565 else if ( _name == "AllowAsDefault" )
566 return TQVariant( static_cast<int>(m_bAllowAsDefault) );
567 else if ( _name == "InitialPreference" )
568 return TQVariant( m_initialPreference );
569 else if ( _name == "Library" )
570 return makeStringVariant( m_strLibrary );
571 else if ( _name == "DesktopEntryPath" ) // can't be null
572 return TQVariant( entryPath() );
573 else if ( _name == "DesktopEntryName")
574 return TQVariant( m_strDesktopEntryName ); // can't be null
575 else if ( _name == "Categories")
576 return TQVariant( d->categories );
577 else if ( _name == "Keywords")
578 return TQVariant( m_lstKeywords );
579
580 // Ok we need to convert the property from a TQString to its real type.
581 // Maybe the caller helped us.
582 if (t == TQVariant::Invalid)
583 {
584 // No luck, let's ask KServiceTypeFactory what the type of this property
585 // is supposed to be.
586 t = KServiceTypeFactory::self()->findPropertyTypeByName(_name);
587 if (t == TQVariant::Invalid)
588 {
589 kdDebug(7012) << "Request for unknown property '" << _name << "'\n";
590 return TQVariant(); // Unknown property: Invalid variant.
591 }
592 }
593
594 // Then we use a homebuild class based on TDEConfigBase to convert the TQString.
595 // For some often used property types we do the conversion ourselves.
596 TQStringVariantMap::ConstIterator it = m_mapProps.find( _name );
597 if ( (it == m_mapProps.end()) || (!it.data().isValid()))
598 {
599 //kdDebug(7012) << "Property not found " << _name << endl;
600 return TQVariant(); // No property set.
601 }
602
603 switch(t)
604 {
605 case TQVariant::String:
606 return it.data();
607 case TQVariant::Bool:
608 case TQVariant::Int:
609 {
610 TQString aValue = it.data().toString();
611 int val = 0;
612 if (aValue == "true" || aValue == "on" || aValue == "yes")
613 val = 1;
614 else
615 {
616 bool bOK;
617 val = aValue.toInt( &bOK );
618 if( !bOK )
619 val = 0;
620 }
621 if (t == TQVariant::Bool)
622 {
623 return TQVariant((bool)val);
624 }
625 return TQVariant(val);
626 }
627 default:
628 // All others
629 KServiceReadProperty ksrp(_name, it.data().toString().utf8());
630 return ksrp.readPropertyEntry(_name, t);
631 }
632}
633
634TQStringList KService::propertyNames() const
635{
636 TQStringList res;
637
638 TQStringVariantMap::ConstIterator it = m_mapProps.begin();
639 for( ; it != m_mapProps.end(); ++it )
640 res.append( it.key() );
641
642 res.append( "Type" );
643 res.append( "Name" );
644 res.append( "Comment" );
645 res.append( "GenericName" );
646 res.append( "Icon" );
647 res.append( "Exec" );
648 res.append( "Terminal" );
649 res.append( "TerminalOptions" );
650 res.append( "Path" );
651 res.append( "ServiceTypes" );
652 res.append( "AllowAsDefault" );
653 res.append( "InitialPreference" );
654 res.append( "Library" );
655 res.append( "DesktopEntryPath" );
656 res.append( "DesktopEntryName" );
657 res.append( "Keywords" );
658 res.append( "Categories" );
659
660 return res;
661}
662
663KService::List KService::allServices()
664{
665 return KServiceFactory::self()->allServices();
666}
667
668KService::Ptr KService::serviceByName( const TQString& _name )
669{
670 KService * s = KServiceFactory::self()->findServiceByName( _name );
671 return KService::Ptr( s );
672}
673
674KService::Ptr KService::serviceByDesktopPath( const TQString& _name )
675{
676 KService * s = KServiceFactory::self()->findServiceByDesktopPath( _name );
677 return KService::Ptr( s );
678}
679
680KService::Ptr KService::serviceByDesktopName( const TQString& _name )
681{
682 KService * s = KServiceFactory::self()->findServiceByDesktopName( _name.lower() );
683 if (!s && !_name.startsWith("tde-"))
684 s = KServiceFactory::self()->findServiceByDesktopName( "tde-"+_name.lower() );
685 return KService::Ptr( s );
686}
687
688KService::Ptr KService::serviceByMenuId( const TQString& _name )
689{
690 KService * s = KServiceFactory::self()->findServiceByMenuId( _name );
691 return KService::Ptr( s );
692}
693
694KService::Ptr KService::serviceByStorageId( const TQString& _storageId )
695{
696 KService::Ptr service = KService::serviceByMenuId( _storageId );
697 if (service)
698 return service;
699
700 service = KService::serviceByDesktopPath(_storageId);
701 if (service)
702 return service;
703
704 if (!TQDir::isRelativePath(_storageId) && TQFile::exists(_storageId))
705 return new KService(_storageId);
706
707 TQString tmp = _storageId;
708 tmp = tmp.mid(tmp.findRev('/')+1); // Strip dir
709
710 if (tmp.endsWith(".desktop"))
711 tmp.truncate(tmp.length()-8);
712
713 if (tmp.endsWith(".kdelnk"))
714 tmp.truncate(tmp.length()-7);
715
716 service = KService::serviceByDesktopName(tmp);
717
718 return service;
719}
720
721KService::List KService::allInitServices()
722{
723 return KServiceFactory::self()->allInitServices();
724}
725
726bool KService::substituteUid() const {
727 bool suid = false;
728 TQVariant v;
729 v = property("X-TDE-SubstituteUID", TQVariant::Bool);
730 if (v.isValid()) {
731 if (v.toBool()) suid = true;
732 }
733 v = property("X-KDE-SubstituteUID", TQVariant::Bool);
734 if (v.isValid()) {
735 if (v.toBool()) suid = true;
736 }
737 return suid;
738}
739
740TQString KService::username() const {
741 // See also TDEDesktopFile::tryExec()
742 TQString user;
743 TQVariant v = property("X-TDE-Username", TQVariant::String);
744 user = v.isValid() ? v.toString() : TQString::null;
745 if (user.isEmpty())
746 user = ::getenv("ADMIN_ACCOUNT");
747 if (user.isEmpty())
748 user = "root";
749 return user;
750}
751
752bool KService::noDisplay() const {
753 TQStringVariantMap::ConstIterator it = m_mapProps.find( "NoDisplay" );
754 if ( (it != m_mapProps.end()) && (it.data().isValid()))
755 {
756 TQString aValue = it.data().toString().lower();
757 if (aValue == "true" || aValue == "on" || aValue == "yes")
758 return true;
759 }
760
761 it = m_mapProps.find( "OnlyShowIn" );
762 if ( (it != m_mapProps.end()) && (it.data().isValid()))
763 {
764 TQString aValue = it.data().toString();
765 TQStringList aList = TQStringList::split(';', aValue);
766#ifdef WITH_OLD_XDG_STD
767 if ((!aList.contains("TDE")) && (!aList.contains("KDE")))
768 return true;
769#else
770 if (!aList.contains("TDE"))
771 return true;
772#endif
773 }
774
775 it = m_mapProps.find( "NotShowIn" );
776 if ( (it != m_mapProps.end()) && (it.data().isValid()))
777 {
778 TQString aValue = it.data().toString();
779 TQStringList aList = TQStringList::split(';', aValue);
780#ifdef WITH_OLD_XDG_STD
781 if ((aList.contains("TDE")) || (aList.contains("KDE")))
782 return true;
783#else
784 if (aList.contains("TDE"))
785 return true;
786#endif
787 }
788
789 if (!tdeApp->authorizeControlModule(d->menuId))
790 return true;
791
792 return false;
793}
794
795TQString KService::untranslatedGenericName() const {
796 TQVariant v = property("UntranslatedGenericName", TQVariant::String);
797 return v.isValid() ? v.toString() : TQString::null;
798}
799
800bool KService::SuSEunimportant() const {
801 TQStringVariantMap::ConstIterator it = m_mapProps.find( "X-SuSE-Unimportant" );
802 if ( (it == m_mapProps.end()) || (!it.data().isValid()))
803 {
804 return false;
805 }
806
807 TQString aValue = it.data().toString();
808 if (aValue == "true" || aValue == "on" || aValue == "yes")
809 return true;
810 else
811 return false;
812}
813
814TQString KService::parentApp() const {
815 TQStringVariantMap::ConstIterator it = m_mapProps.find( "X-TDE-ParentApp" );
816 if ( (it == m_mapProps.end()) || (!it.data().isValid()))
817 {
818 return TQString::null;
819 }
820
821 return it.data().toString();
822}
823
824bool KService::allowMultipleFiles() const {
825 // Can we pass multiple files on the command line or do we have to start the application for every single file ?
826 if ( m_strExec.find( "%F" ) != -1 || m_strExec.find( "%U" ) != -1 ||
827 m_strExec.find( "%N" ) != -1 || m_strExec.find( "%D" ) != -1 )
828 return true;
829 else
830 return false;
831}
832
833TQStringList KService::categories() const
834{
835 return d->categories;
836}
837
838TQString KService::menuId() const
839{
840 return d->menuId;
841}
842
843void KService::setMenuId(const TQString &menuId)
844{
845 d->menuId = menuId;
846}
847
848TQString KService::storageId() const
849{
850 if (!d->menuId.isEmpty())
851 return d->menuId;
852 return entryPath();
853}
854
855TQString KService::locateLocal()
856{
857 if (d->menuId.isEmpty() || desktopEntryPath().startsWith(".hidden") ||
858 (TQDir::isRelativePath(desktopEntryPath()) && d->categories.isEmpty()))
859 return TDEDesktopFile::locateLocal(desktopEntryPath());
860
861 return ::locateLocal("xdgdata-apps", d->menuId);
862}
863
864TQString KService::newServicePath(bool showInMenu, const TQString &suggestedName,
865 TQString *menuId, const TQStringList *reservedMenuIds)
866{
867 TQString base = suggestedName;
868 if (!showInMenu)
869 base.prepend("tde-");
870
871 TQString result;
872 for(int i = 1; true; i++)
873 {
874 if (i == 1)
875 result = base + ".desktop";
876 else
877 result = base + TQString("-%1.desktop").arg(i);
878
879 if (reservedMenuIds && reservedMenuIds->contains(result))
880 continue;
881
882 // Lookup service by menu-id
883 KService::Ptr s = serviceByMenuId(result);
884 if (s)
885 continue;
886
887 if (showInMenu)
888 {
889 if (!locate("xdgdata-apps", result).isEmpty())
890 continue;
891 }
892 else
893 {
894 TQString file = result.mid(4); // Strip "tde-"
895 if (!locate("apps", ".hidden/"+file).isEmpty())
896 continue;
897 }
898
899 break;
900 }
901 if (menuId)
902 *menuId = result;
903
904 if (showInMenu)
905 {
906 return ::locateLocal("xdgdata-apps", result);
907 }
908 else
909 {
910 TQString file = result.mid(4); // Strip "tde-"
911 return ::locateLocal("apps", ".hidden/"+file);
912 }
913}
914
915
916void KService::virtual_hook( int id, void* data )
917{ KSycocaEntry::virtual_hook( id, data ); }
918
919
920void KService::rebuildKSycoca(TQWidget *parent)
921{
922 KServiceProgressDialog dlg(parent, "tdesycoca_progress",
923 i18n("Updating System Configuration"),
924 i18n("Updating system configuration."));
925
926 TQByteArray data;
927 DCOPClient *client = tdeApp->dcopClient();
928
929 int result = client->callAsync("kded", "tdebuildsycoca", "recreate()",
930 data, &dlg, TQ_SLOT(slotFinished()));
931
932 if (result)
933 {
934 dlg.exec();
935 }
936}
937
938KServiceProgressDialog::KServiceProgressDialog(TQWidget *parent, const char *name,
939 const TQString &caption, const TQString &text)
940 : KProgressDialog(parent, name, caption, text, true)
941{
942 connect(&m_timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(slotProgress()));
943 progressBar()->setTotalSteps(20);
944 m_timeStep = 700;
945 m_timer.start(m_timeStep);
946 setAutoClose(false);
947}
948
949void
950KServiceProgressDialog::slotProgress()
951{
952 int p = progressBar()->progress();
953 if (p == 18)
954 {
955 progressBar()->reset();
956 progressBar()->setProgress(1);
957 m_timeStep = m_timeStep * 2;
958 m_timer.start(m_timeStep);
959 }
960 else
961 {
962 progressBar()->setProgress(p+1);
963 }
964}
965
966void
967KServiceProgressDialog::slotFinished()
968{
969 progressBar()->setProgress(20);
970 m_timer.stop();
971 TQTimer::singleShot(1000, this, TQ_SLOT(close()));
972}
973
974#include "kservice_p.moc"
KMimeType::defaultMimeTypePtr
static KMimeType::Ptr defaultMimeTypePtr()
Returns the default mimetype.
Definition: kmimetype.cpp:89
KMimeType::mimeType
static Ptr mimeType(const TQString &_name)
Retrieve a pointer to the mime type _name or a pointer to the default mime type "application/octet-st...
Definition: kmimetype.cpp:141
KServiceType::serviceType
static Ptr serviceType(const TQString &_name)
Returns a pointer to the servicetype '_name' or 0L if the service type is unknown.
Definition: kservicetype.cpp:227
KService
Represent a service, i.e.
Definition: kservice.h:49
KService::rebuildKSycoca
static void rebuildKSycoca(TQWidget *parent)
Rebuild KSycoca and show a progress dialog while doing so.
Definition: kservice.cpp:920
KService::path
TQString path() const
Returns the working directory to run the program in.
Definition: kservice.h:226
KService::newServicePath
static TQString newServicePath(bool showInMenu, const TQString &suggestedName, TQString *menuId=0, const TQStringList *reservedMenuIds=0)
Returns a path that can be used to create a new KService based on suggestedName.
Definition: kservice.cpp:864
KService::serviceByName
static Ptr serviceByName(const TQString &_name)
Find a service by name, i.e.
Definition: kservice.cpp:668
KService::username
TQString username() const
Returns the user name, if the service runs with a different user id.
Definition: kservice.cpp:740
KService::allowMultipleFiles
bool allowMultipleFiles() const
Checks whether this service can handle several files as startup arguments.
Definition: kservice.cpp:824
KService::substituteUid
bool substituteUid() const
Checks whether the service runs with a different user id.
Definition: kservice.cpp:726
KService::property
virtual TQVariant property(const TQString &_name) const
Returns the requested property.
Definition: kservice.cpp:528
KService::locateLocal
TQString locateLocal()
Returns a path that can be used for saving changes to this service.
Definition: kservice.cpp:855
KService::desktopEntryPath
TQString desktopEntryPath() const
Returns the path to the location where the service desktop entry is stored.
Definition: kservice.h:174
KService::DCOPServiceType_t
DCOPServiceType_t
Describes the DCOP type of the service.
Definition: kservice.h:213
KService::allServices
static List allServices()
Returns the whole list of services.
Definition: kservice.cpp:663
KService::noDisplay
bool noDisplay() const
Whether the entry should be suppressed in menus.
Definition: kservice.cpp:752
KService::serviceByMenuId
static Ptr serviceByMenuId(const TQString &_menuId)
Find a service by its menu-id.
Definition: kservice.cpp:688
KService::hasServiceType
bool hasServiceType(const TQString &_service) const
Checks whether the service supports this service type.
Definition: kservice.cpp:405
KService::parentApp
TQString parentApp() const
Name of the application this service belongs to.
Definition: kservice.cpp:814
KService::init
TQString init() const
Returns the name of the init function to call (KControl modules).
Definition: kservice.h:118
KService::menuId
TQString menuId() const
Returns the menu ID of the service desktop entry.
Definition: kservice.cpp:838
KService::serviceByStorageId
static Ptr serviceByStorageId(const TQString &_storageId)
Find a service by its storage-id or desktop-file path.
Definition: kservice.cpp:694
KService::initialPreferenceForMimeType
int initialPreferenceForMimeType(const TQString &mimeType) const
What preference to associate with this service initially for handling the specified mimetype.
Definition: kservice.cpp:438
KService::name
virtual TQString name() const
Returns the name of the service.
Definition: kservice.h:98
KService::allInitServices
static List allInitServices()
Returns all services that require initialisation.
Definition: kservice.cpp:721
KService::pixmap
TQPixmap pixmap(TDEIcon::Group _group, int _force_size=0, int _state=0, TQString *_path=0L) const
Returns the pixmap that represents the icon.
Definition: kservice.cpp:332
KService::KService
KService(const TQString &_name, const TQString &_exec, const TQString &_icon)
Construct a temporary service with a given name, exec-line and icon.
Definition: kservice.cpp:64
KService::untranslatedGenericName
TQString untranslatedGenericName() const
Returns the untranslated (US English) generic name for the service, if there is one (e....
Definition: kservice.cpp:795
KService::storageId
TQString storageId() const
Returns a normalized ID suitable for storing in configuration files.
Definition: kservice.cpp:848
KService::serviceByDesktopName
static Ptr serviceByDesktopName(const TQString &_name)
Find a service by the name of its desktop file, not depending on its actual location (as long as it's...
Definition: kservice.cpp:680
KService::SuSEunimportant
bool SuSEunimportant() const
check if the application entry is important
Definition: kservice.cpp:800
KService::categories
TQStringList categories() const
Returns a list of VFolder categories.
Definition: kservice.cpp:833
KService::serviceByDesktopPath
static Ptr serviceByDesktopPath(const TQString &_path)
Find a service based on its path as returned by desktopEntryPath().
Definition: kservice.cpp:674
KService::propertyNames
virtual TQStringList propertyNames() const
Returns the list of all properties that this service can have.
Definition: kservice.cpp:634

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.4
This website is maintained by Timothy Pearson.