KDECore
kmimesourcefactory.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <kdebug.h>
00022 #include <kglobal.h>
00023 #include <kinstance.h>
00024 #include <kiconloader.h>
00025
00026 #include "kmimesourcefactory.h"
00027
00028 class KMimeSourceFactoryPrivate
00029 {
00030 public:
00031 inline KMimeSourceFactoryPrivate (KIconLoader* loader) : m_iconLoader(loader), m_instance(0L) {}
00032 inline KIconLoader *iconLoader()
00033 {
00034
00035 Q_ASSERT(m_instance || m_iconLoader);
00036
00037 if (m_iconLoader)
00038 return m_iconLoader;
00039
00040 return m_instance->iconLoader();
00041 }
00042
00043 KIconLoader *m_iconLoader;
00044 KInstance *m_instance;
00045 };
00046
00047 KMimeSourceFactory::KMimeSourceFactory (KIconLoader* loader)
00048 : QMimeSourceFactory (),
00049 d (new KMimeSourceFactoryPrivate (loader))
00050 {
00051 }
00052
00053 KMimeSourceFactory::~KMimeSourceFactory()
00054 {
00055 delete d;
00056 }
00057
00058 QString KMimeSourceFactory::makeAbsolute (const QString& absOrRelName, const QString& context) const
00059 {
00060 QString myName;
00061 QString myContext;
00062
00063 const int pos = absOrRelName.find ('|');
00064 if (pos > -1)
00065 {
00066 myContext = absOrRelName.left (pos);
00067 myName = absOrRelName.right (absOrRelName.length() - myContext.length() - 1);
00068 }
00069
00070 QString result;
00071
00072 if (myContext == "desktop")
00073 {
00074 result = d->iconLoader()->iconPath (myName, KIcon::Desktop);
00075 }
00076 else if (myContext == "toolbar")
00077 {
00078 result = d->iconLoader()->iconPath (myName, KIcon::Toolbar);
00079 }
00080 else if (myContext == "maintoolbar")
00081 {
00082 result = d->iconLoader()->iconPath (myName, KIcon::MainToolbar);
00083 }
00084 else if (myContext == "small")
00085 {
00086 result = d->iconLoader()->iconPath (myName, KIcon::Small);
00087 }
00088 else if (myContext == "user")
00089 {
00090 result = d->iconLoader()->iconPath (myName, KIcon::User);
00091 }
00092
00093 if (result.isEmpty())
00094 result = QMimeSourceFactory::makeAbsolute (absOrRelName, context);
00095
00096 return result;
00097 }
00098
00099 void KMimeSourceFactory::setInstance(KInstance *instance)
00100 {
00101 d->m_instance = instance;
00102 }
00103
00104 void KMimeSourceFactory::virtual_hook( int, void* )
00105 { }
00106