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

kio/kio

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

kio/kio

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

kio/kio

Skip menu "kio/kio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kio by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |