kservice.h
00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef __kservices_h__ 00021 #define __kservices_h__ 00022 00023 #include <qstringlist.h> 00024 #include <qmap.h> 00025 #include <qvariant.h> 00026 #include <kicontheme.h> 00027 00028 #include "ksycocaentry.h" 00029 00030 class QDataStream; 00031 class KDesktopFile; 00032 class KService; 00033 class KBuildSycoca; 00034 class QWidget; 00035 00048 class KIO_EXPORT KService : public KSycocaEntry 00049 { 00050 K_SYCOCATYPE( KST_KService, KSycocaEntry ) 00051 00052 friend class KBuildSycoca; 00053 00054 public: 00055 typedef KSharedPtr<KService> Ptr; 00056 typedef QValueList<Ptr> List; 00057 public: 00064 KService( const QString & _name, const QString &_exec, const QString &_icon); 00065 00071 explicit KService( const QString & _fullpath ); 00072 00077 KService( KDesktopFile *config ); // KDE-4.0: make explicit 00078 00084 KService( QDataStream& _str, int offset ); 00085 00086 virtual ~KService(); 00087 00092 virtual QString type() const { return m_strType; } 00098 virtual QString name() const { return m_strName; } 00104 QString exec() const { return m_strExec; } 00111 QString library() const { return m_strLibrary; } 00118 QString init() const { return m_strInit; } 00119 00125 QString icon() const { return m_strIcon; } 00132 QPixmap pixmap( KIcon::Group _group, int _force_size = 0, int _state = 0, 00133 QString * _path = 0L ) const; 00138 bool terminal() const { return m_bTerminal; } 00147 QString terminalOptions() const { return m_strTerminalOptions; } 00153 bool substituteUid() const; 00161 QString username() const; 00162 00174 QString desktopEntryPath() const { return entryPath(); } 00175 00182 QString desktopEntryName() const { return m_strDesktopEntryName; } 00183 00190 QString menuId() const; 00191 00199 QString storageId() const; 00200 00213 enum DCOPServiceType_t { DCOP_None = 0, DCOP_Unique, DCOP_Multi, DCOP_Wait }; 00214 00219 DCOPServiceType_t DCOPServiceType() const { return m_DCOPServiceType; } 00220 00226 QString path() const { return m_strPath; } 00227 00233 QString comment() const { return m_strComment; } 00234 00241 QString genericName() const { return m_strGenName; } 00242 00251 QString untranslatedGenericName() const; 00252 00257 QStringList keywords() const { return m_lstKeywords; } 00258 00264 QStringList categories() const; 00265 00270 QStringList serviceTypes() const { return m_lstServiceTypes; } 00271 00280 bool hasServiceType( const QString& _service ) const; 00281 00292 bool allowAsDefault() const { return m_bAllowAsDefault; } 00293 00300 bool allowMultipleFiles() const; 00301 00308 int initialPreference() const { return m_initialPreference; } 00309 00318 int initialPreferenceForMimeType( const QString& mimeType ) const; 00319 00323 void setInitialPreference( int i ) { m_initialPreference = i; } 00324 00329 bool noDisplay() const; 00330 00337 QString parentApp() const; 00338 00351 virtual QVariant property( const QString& _name ) const; 00352 00362 QVariant property( const QString& _name, QVariant::Type t ) const; 00363 00369 virtual QStringList propertyNames() const; 00370 00375 bool isValid() const { return m_bValid; } 00376 00383 QString locateLocal(); 00384 00389 virtual void load( QDataStream& ); 00394 virtual void save( QDataStream& ); 00399 void setMenuId(const QString &menuId); 00404 void setTerminal(bool b) { m_bTerminal = b; } 00409 void setTerminalOptions(const QString &options) { m_strTerminalOptions = options; } 00410 00420 static Ptr serviceByName( const QString& _name ); 00421 00431 static Ptr serviceByDesktopPath( const QString& _path ); 00432 00447 static Ptr serviceByDesktopName( const QString& _name ); 00448 00458 static Ptr serviceByMenuId( const QString& _menuId ); 00459 00470 static Ptr serviceByStorageId( const QString& _storageId ); 00471 00481 static List allServices(); 00482 00489 static List allInitServices(); 00490 00506 static QString newServicePath(bool showInMenu, const QString &suggestedName, 00507 QString *menuId = 0, 00508 const QStringList *reservedMenuIds = 0); 00509 00510 00516 static void rebuildKSycoca(QWidget *parent); 00517 00518 protected: 00519 00520 void init(KDesktopFile *config); 00521 00522 QStringList &accessServiceTypes() { return m_lstServiceTypes; } 00523 00524 00525 private: 00526 KService( const KService& ); // forbidden 00527 KService& operator=(const KService&); 00528 00529 QString m_strType; 00530 QString m_strName; 00531 QString m_strExec; 00532 QString m_strIcon; 00533 QString m_strTerminalOptions; 00534 QString m_strPath; 00535 QString m_strComment; 00536 QString m_strLibrary; 00537 QStringList m_lstServiceTypes; 00538 bool m_bAllowAsDefault; 00539 int m_initialPreference; 00540 bool m_bTerminal; 00541 //bool m_bSuid; 00542 //QString m_strUsername; 00543 QString m_strDesktopEntryName; 00544 //QString m_docPath; 00545 //bool m_bHideFromPanel; 00546 DCOPServiceType_t m_DCOPServiceType; 00547 QMap<QString,QVariant> m_mapProps; 00548 bool m_bValid; 00549 QStringList m_lstKeywords; 00550 QString m_strInit; 00551 QString m_strGenName; 00552 protected: 00553 virtual void virtual_hook( int id, void* data ); 00554 private: 00555 class KServicePrivate; 00556 KServicePrivate* d; 00557 }; 00558 #endif