kmimesourcefactory.cpp
00001 /* 00002 This file is part of the KDE libraries 00003 Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) 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 Library 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 #include <kdebug.h> 00022 #include <tdeglobal.h> 00023 #include <kinstance.h> 00024 #include <kiconloader.h> 00025 00026 #include "kmimesourcefactory.h" 00027 00028 class KMimeSourceFactoryPrivate 00029 { 00030 public: 00031 inline KMimeSourceFactoryPrivate (TDEIconLoader* loader) : m_iconLoader(loader), m_instance(0L) {} 00032 inline TDEIconLoader *iconLoader() 00033 { 00034 // If we don't have either of these, things are looking grim. 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 TDEIconLoader *m_iconLoader; 00044 TDEInstance *m_instance; 00045 }; 00046 00047 KMimeSourceFactory::KMimeSourceFactory (TDEIconLoader* loader) 00048 : TQMimeSourceFactory (), 00049 d (new KMimeSourceFactoryPrivate (loader)) 00050 { 00051 } 00052 00053 KMimeSourceFactory::~KMimeSourceFactory() 00054 { 00055 delete d; 00056 } 00057 00058 TQString KMimeSourceFactory::makeAbsolute (const TQString& absOrRelName, const TQString& context) const 00059 { 00060 TQString myName; 00061 TQString 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 TQString result; 00071 00072 if (myContext == "desktop") 00073 { 00074 result = d->iconLoader()->iconPath (myName, TDEIcon::Desktop); 00075 } 00076 else if (myContext == "toolbar") 00077 { 00078 result = d->iconLoader()->iconPath (myName, TDEIcon::Toolbar); 00079 } 00080 else if (myContext == "maintoolbar") 00081 { 00082 result = d->iconLoader()->iconPath (myName, TDEIcon::MainToolbar); 00083 } 00084 else if (myContext == "small") 00085 { 00086 result = d->iconLoader()->iconPath (myName, TDEIcon::Small); 00087 } 00088 else if (myContext == "user") 00089 { 00090 result = d->iconLoader()->iconPath (myName, TDEIcon::User); 00091 } 00092 00093 if (result.isEmpty()) 00094 result = TQMimeSourceFactory::makeAbsolute (absOrRelName, context); 00095 00096 return result; 00097 } 00098 00099 void KMimeSourceFactory::setInstance(TDEInstance *instance) 00100 { 00101 d->m_instance = instance; 00102 } 00103 00104 void KMimeSourceFactory::virtual_hook( int, void* ) 00105 { /*BASE::virtual_hook( id, data );*/ } 00106