KDED
kmimeassociations.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 * Copyright 2008 David Faure <faure@kde.org> 00003 * 00004 * This library is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License or ( at 00007 * your option ) version 3 or, at the discretion of KDE e.V. ( which shall 00008 * act as a proxy as in section 14 of the GPLv3 ), any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef KDED_KMIMEASSOCIATIONS_H 00022 #define KDED_KMIMEASSOCIATIONS_H 00023 00024 #include <QSet> 00025 #include <QStringList> 00026 #include <QHash> 00027 #include <kserviceoffer.h> 00028 class KMimeTypeFactory; 00029 class KConfigGroup; 00030 00031 struct ServiceTypeOffersData { 00032 QList<KServiceOffer> offers; // service + initial preference + allow as default 00033 QSet<KService::Ptr> offerSet; // for quick contains() check 00034 QSet<KService::Ptr> removedOffers; // remember removed offers explicitly 00035 }; 00036 00037 class KOfferHash 00038 { 00039 public: 00040 KOfferHash() {} 00041 QList<KServiceOffer> offersFor(const QString& serviceType) const { 00042 QHash<QString, ServiceTypeOffersData>::const_iterator it = m_serviceTypeData.find(serviceType); 00043 if (it != m_serviceTypeData.end()) 00044 return (*it).offers; 00045 return QList<KServiceOffer>(); 00046 } 00047 void addServiceOffer(const QString& serviceType, const KServiceOffer& offer); 00048 void removeServiceOffer(const QString& serviceType, KService::Ptr service); 00049 bool hasRemovedOffer(const QString& serviceType, KService::Ptr service) const; 00050 00051 private: 00052 KOfferHash(const KOfferHash&); // forbidden 00053 QHash<QString, ServiceTypeOffersData> m_serviceTypeData; 00054 }; 00055 00056 00062 class KMimeAssociations 00063 { 00064 public: 00065 explicit KMimeAssociations(KOfferHash& offerHash); 00066 00067 // Read mimeapps.list files 00068 bool parseAllMimeAppsList(); 00069 00070 void parseMimeAppsList(const QString& file, int basePreference); 00071 00072 private: 00073 void parseAddedAssociations(const KConfigGroup& group, const QString& file, int basePreference); 00074 void parseRemovedAssociations(const KConfigGroup& group, const QString& file); 00075 00076 KOfferHash& m_offerHash; 00077 }; 00078 00079 #endif /* KMIMEASSOCIATIONS_H */
KDE 4.6 API Reference