• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDE3Support

  • sources
  • kde-4.14
  • kdelibs
  • kde3support
  • kdecore
k3mimesourcefactory.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE libraries
3  Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "k3mimesourcefactory.h"
22 
23 #include <kdebug.h>
24 #include <kiconloader.h>
25 
26 class K3MimeSourceFactoryPrivate
27 {
28 public:
29  inline K3MimeSourceFactoryPrivate (KIconLoader* loader)
30  : kil (loader)
31  {}
32 
33  KIconLoader* kil;
34 };
35 
36 void K3MimeSourceFactory::install()
37 {
38  // Set default mime-source factory
39  // XXX: This is a hack. Make our factory the default factory, but add the
40  // previous default factory to the list of factories. Why? When the default
41  // factory can't resolve something, it iterates in the list of factories.
42  // But it QWhatsThis only uses the default factory. So if there was already
43  // a default factory (which happens when using an image library using uic),
44  // we prefer KDE's factory and so we put that old default factory in the
45  // list and use KDE as the default. This may speed up things as well.
46  Q3MimeSourceFactory* oldDefaultFactory = Q3MimeSourceFactory::takeDefaultFactory();
47  K3MimeSourceFactory* mimeSourceFactory = new K3MimeSourceFactory(KIconLoader::global());
48  Q3MimeSourceFactory::setDefaultFactory( mimeSourceFactory );
49  if ( oldDefaultFactory ) {
50  Q3MimeSourceFactory::addFactory( oldDefaultFactory );
51  }
52 }
53 
54 K3MimeSourceFactory::K3MimeSourceFactory (KIconLoader* loader)
55  : Q3MimeSourceFactory (),
56  d (new K3MimeSourceFactoryPrivate (loader ? loader : KIconLoader::global()))
57 {
58 }
59 
60 K3MimeSourceFactory::~K3MimeSourceFactory()
61 {
62  delete d;
63 }
64 
65 QString K3MimeSourceFactory::makeAbsolute (const QString& absOrRelName, const QString& context) const
66 {
67  QString myName;
68  QString myContext;
69 
70  const int pos = absOrRelName.indexOf ('|');
71  if (pos > -1)
72  {
73  myContext = absOrRelName.left (pos);
74  myName = absOrRelName.right (absOrRelName.length() - myContext.length() - 1);
75  }
76 
77  QString result;
78 
79  if (myContext == "desktop")
80  {
81  result = d->kil->iconPath (myName, KIconLoader::Desktop);
82  }
83  else if (myContext == "toolbar")
84  {
85  result = d->kil->iconPath (myName, KIconLoader::Toolbar);
86  }
87  else if (myContext == "maintoolbar")
88  {
89  result = d->kil->iconPath (myName, KIconLoader::MainToolbar);
90  }
91  else if (myContext == "small")
92  {
93  result = d->kil->iconPath (myName, KIconLoader::Small);
94  }
95  else if (myContext == "user")
96  {
97  result = d->kil->iconPath (myName, KIconLoader::User);
98  }
99 
100  if (result.isEmpty())
101  result = Q3MimeSourceFactory::makeAbsolute (absOrRelName, context);
102 
103  return result;
104 }
105 
106 void K3MimeSourceFactory::virtual_hook( int, void* )
107 { /*BASE::virtual_hook( id, data );*/ }
108 
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
kdebug.h
KIconLoader::global
static KIconLoader * global()
k3mimesourcefactory.h
kiconloader.h
K3MimeSourceFactory::~K3MimeSourceFactory
virtual ~K3MimeSourceFactory()
Destructor.
Definition: k3mimesourcefactory.cpp:60
Q3MimeSourceFactory::takeDefaultFactory
Q3MimeSourceFactory * takeDefaultFactory()
KIconLoader::Desktop
Q3MimeSourceFactory::addFactory
void addFactory(Q3MimeSourceFactory *f)
Q3MimeSourceFactory::setDefaultFactory
void setDefaultFactory(Q3MimeSourceFactory *factory)
Q3MimeSourceFactory
KIconLoader::Small
QString::isEmpty
bool isEmpty() const
QString
K3MimeSourceFactory::makeAbsolute
virtual QString makeAbsolute(const QString &abs_or_rel_name, const QString &context) const
This function is maps an absolute or relative name for a resource to the absolute one...
Definition: k3mimesourcefactory.cpp:65
QString::right
QString right(int n) const
K3MimeSourceFactory::virtual_hook
virtual void virtual_hook(int id, void *data)
Virtual hook, used to add new "virtual" functions while maintaining binary compatibility.
Definition: k3mimesourcefactory.cpp:106
KIconLoader::MainToolbar
KIconLoader::Toolbar
K3MimeSourceFactory::K3MimeSourceFactory
K3MimeSourceFactory(KIconLoader *loader=0)
Constructor.
Definition: k3mimesourcefactory.cpp:54
K3MimeSourceFactory
An extension to QMimeSourceFactory that uses KIconLoader to find images.
Definition: k3mimesourcefactory.h:42
QString::length
int length() const
KIconLoader::User
QString::left
QString left(int n) const
KIconLoader
Q3MimeSourceFactory::makeAbsolute
virtual QString makeAbsolute(const QString &abs_or_rel_name, const QString &context) const
K3MimeSourceFactory::install
static void install()
Set up a K3MimeSourceFactory instance as the default mimesource factory.
Definition: k3mimesourcefactory.cpp:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDE3Support

Skip menu "KDE3Support"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal