kuserprofile.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., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #ifndef __kuserprofile_h__ 00021 #define __kuserprofile_h__ 00022 00023 #include <qmap.h> 00024 #include <qstring.h> 00025 #include <qptrlist.h> 00026 #include <qvaluelist.h> 00027 00028 #include <kservice.h> 00029 00037 class KServiceOffer 00038 { 00039 public: 00040 KServiceOffer(); 00041 KServiceOffer( const KServiceOffer& ); 00042 KServiceOffer( KService::Ptr _service, 00043 int _pref, bool _default ); 00044 00045 bool operator< ( const KServiceOffer& ) const; 00050 bool allowAsDefault() const { return m_bAllowAsDefault; } 00054 int preference() const { return m_iPreference; } 00058 KService::Ptr service() const { return m_pService; } 00062 bool isValid() const { return m_iPreference >= 0; } 00063 00064 private: 00065 int m_iPreference; 00066 bool m_bAllowAsDefault; 00067 KService::Ptr m_pService; 00068 private: 00069 class KServiceOfferPrivate; 00070 }; 00071 00076 class KServiceTypeProfile 00077 { 00078 public: 00079 typedef QValueList<KServiceOffer> OfferList; 00080 00081 ~KServiceTypeProfile(); 00082 00087 int preference( const QString& _service ) const; 00088 bool allowAsDefault( const QString& _service ) const; 00089 00090 OfferList offers() const; 00091 00100 static KService::Ptr preferredService( const QString & serviceType, const QString & genericServiceType ); 00101 00105 static KServiceTypeProfile* serviceTypeProfile( const QString& servicetype, const QString & genericServiceType = QString::null ); 00106 00120 static OfferList offers( const QString& servicetype, const QString& genericServiceType = QString::null ); 00121 00122 static const QPtrList<KServiceTypeProfile>& serviceTypeProfiles() { return *s_lstProfiles; } 00123 00127 static void clear() { delete s_lstProfiles; s_lstProfiles = 0L; } 00128 00134 static void setConfigurationMode() { s_configurationMode = true; } 00138 static bool configurationMode() { return s_configurationMode; } 00139 00140 protected: 00145 KServiceTypeProfile( const QString& _servicetype, const QString& _genericServiceType = QString::null ); 00146 00150 void addService( const QString& _service, int _preference = 1, bool _allow_as_default = TRUE ); 00151 00152 private: 00156 struct Service 00157 { 00161 int m_iPreference; 00165 bool m_bAllowAsDefault; 00166 }; 00167 00171 QMap<QString,Service> m_mapServices; 00172 00176 QString m_strServiceType; 00177 00181 QString m_strGenericServiceType; 00182 00183 static void initStatic(); 00184 static QPtrList<KServiceTypeProfile>* s_lstProfiles; 00185 static bool s_configurationMode; 00186 private: 00187 class KServiceTypeProfilePrivate* d; 00188 }; 00189 00190 #endif