[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Virtual MimeTypes support patch
From:       Albert Astals Cid <aacid () kde ! org>
Date:       2006-10-21 17:10:33
Message-ID: 200610211910.34040.aacid () kde ! org
[Download RAW message or body]

Hi, this patch adds virtual mimetypes support for KDE.

Virtual mimetypes basically add the possibility of having plugins that add 
supported mimetypes to those the application supports.

We need it for okular behaving properly, that is, not advertising it has pdf 
support when the pdf plugin was not compiled.

See http://lists.kde.org/?l=kde-core-devel&m=116023261725717&w=2 for the whole 
explanation.

Comments?

Albert

["virtualMimeTypes.patch" (text/x-diff)]

Index: kdecore/kservice/kservice.cpp
===================================================================
--- kdecore/kservice/kservice.cpp	(revision 597741)
+++ kdecore/kservice/kservice.cpp	(working copy)
@@ -659,6 +659,13 @@ QStringList KService::categories() const
   return d->categories;
 }
 
+QString KService::virtualMimeType() const
+{
+  QMap<QString,QVariant>::const_iterator it = m_mapProps.find( \
QLatin1String("X-KDE-Virtual-MimeType") ); +  if (it != m_mapProps.end()) return \
it.value().toString(); +  else return QString();
+}
+
 QString KService::menuId() const
 {
   return d->menuId;
Index: kdecore/kservice/kservice.h
===================================================================
--- kdecore/kservice/kservice.h	(revision 597741)
+++ kdecore/kservice/kservice.h	(working copy)
@@ -55,6 +55,7 @@ class KDECORE_EXPORT KService : public K
   K_SYCOCATYPE( KST_KService, KSycocaEntry )
 
   friend class KBuildSycoca;
+  friend class KBuildServiceFactory;
 
 public:
   typedef KSharedPtr<KService> Ptr;
@@ -259,6 +260,24 @@ public:
   QStringList categories() const;
 
   /**
+   * Returns the virtual mimetype of the service.
+   * Virtual mimetypes are a KDE extension to the .desktop mimetype system
+   * They are directed towards applications that use plugins and the mimetypes
+   * they support depend on the installed plugins.
+   *
+   * To make an Application use the virtual mimetype system, put
+   * MimeType=virtual/foo
+   * in its .desktop file
+   * Then each plugin has to install a .desktop file like this
+   * [Desktop Entry]
+   * Name=anyName
+   * Type=Application
+   * MimeType=mimetypes this plugins adds support for
+   * X-KDE-Virtual-MimeType=virtual/foo
+   */
+  QString virtualMimeType() const;
+
+  /**
    * Returns the service types that this service supports.
    * @return the list of service types that are supported
    * Note that this doesn't include inherited servicetypes or mimetypes,
Index: kded/kbuildservicefactory.cpp
===================================================================
--- kded/kbuildservicefactory.cpp	(revision 597741)
+++ kded/kbuildservicefactory.cpp	(working copy)
@@ -134,6 +134,25 @@ KBuildServiceFactory::save(QDataStream &
 
 void KBuildServiceFactory::populateServiceTypes()
 {
+   // resolve the virtual mimetypes
+   QHash<QString, KService::Ptr>::const_iterator it, itEnd;
+   it = m_virtualMimeTypeDict.begin();
+   itEnd = m_virtualMimeTypeDict.end();
+   for ( ; it != itEnd; ++it )
+   {
+      foreach(KService::Ptr service, m_serviceDict)
+      {
+         if (service->serviceTypes().contains(it.key()))
+         {
+            // remove the Application service as it.value()->serviceTypes() already \
has one +            service->accessServiceTypes().removeLast();
+            service->accessServiceTypes().removeAll(it.key()); // remove the \
virtual/ service +            service->accessServiceTypes() += \
it.value()->serviceTypes(); +         }
+      }
+   }
+   m_virtualMimeTypeDict.clear();
+
    kDebug() << k_funcinfo << endl;
    bool isNumber;
    // For every service...
@@ -321,9 +340,19 @@ KBuildServiceFactory::addEntry(const KSy
    if (m_dupeDict.contains(newEntry))
       return;
 
+   const KService::Ptr service = KService::Ptr::staticCast( newEntry );
+   QString virtualMimeType = service->virtualMimeType();
+   if (!virtualMimeType.isEmpty())
+   {
+     if (virtualMimeType.startsWith("virtual/"))
+     {
+        m_virtualMimeTypeDict.insert(virtualMimeType, service);
+     }
+     return;
+   }
+
    KSycocaFactory::addEntry(newEntry);
 
-   const KService::Ptr service = KService::Ptr::staticCast( newEntry );
    m_dupeDict.insert(newEntry);
 
    if (!service->isDeleted())
Index: kded/kbuildservicefactory.h
===================================================================
--- kded/kbuildservicefactory.h	(revision 597741)
+++ kded/kbuildservicefactory.h	(working copy)
@@ -86,6 +86,7 @@ private:
   void addServiceOffer( const QString& serviceType, const KServiceOffer& offer );
 
   QHash<QString, KService::Ptr> m_serviceDict;
+  QHash<QString, KService::Ptr> m_virtualMimeTypeDict;
   QSet<KSycocaEntry::Ptr> m_dupeDict;
 
   struct ServiceTypeOffersData {



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic