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 KConfigGroup; 00029 00030 struct ServiceTypeOffersData { 00031 QList<KServiceOffer> offers; // service + initial preference + allow as default 00032 QSet<KService::Ptr> offerSet; // for quick contains() check 00033 QSet<KService::Ptr> removedOffers; // remember removed offers explicitely 00034 }; 00035 00036 class KOfferHash 00037 { 00038 public: 00039 KOfferHash() {} 00040 QList<KServiceOffer> offersFor(const QString& serviceType) const { 00041 QHash<QString, ServiceTypeOffersData>::const_iterator it = m_serviceTypeData.find(serviceType); 00042 if (it != m_serviceTypeData.end()) 00043 return (*it).offers; 00044 return QList<KServiceOffer>(); 00045 } 00046 void addServiceOffer(const QString& serviceType, const KServiceOffer& offer); 00047 void removeServiceOffer(const QString& serviceType, KService::Ptr service); 00048 bool hasRemovedOffer(const QString& serviceType, KService::Ptr service) const; 00049 00050 private: 00051 KOfferHash(const KOfferHash&); // forbidden 00052 QHash<QString, ServiceTypeOffersData> m_serviceTypeData; 00053 }; 00054 00055 00061 class KMimeAssociations 00062 { 00063 public: 00064 explicit KMimeAssociations(KOfferHash& offerHash); 00065 00066 // Read mimeapps.list files 00067 bool parseAllMimeAppsList(); 00068 00069 void parseMimeAppsList(const QString& file, int basePreference); 00070 00071 private: 00072 void parseAddedAssociations(const KConfigGroup& group, const QString& file, int basePreference); 00073 void parseRemovedAssociations(const KConfigGroup& group, const QString& file); 00074 00075 KOfferHash& m_offerHash; 00076 }; 00077 00078 #endif /* KMIMEASSOCIATIONS_H */