• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • twin/lib
 

twin/lib

  • twin
  • lib
kdecoration_plugins_p.cpp
1/*****************************************************************
2This file is part of the KDE project.
3
4Copyright (C) 1999, 2000 Daniel M. Duley <mosfet@kde.org>
5Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
6
7Permission is hereby granted, free of charge, to any person obtaining a
8copy of this software and associated documentation files (the "Software"),
9to deal in the Software without restriction, including without limitation
10the rights to use, copy, modify, merge, publish, distribute, sublicense,
11and/or sell copies of the Software, and to permit persons to whom the
12Software is furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in
15all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23DEALINGS IN THE SOFTWARE.
24******************************************************************/
25
26#include "kdecoration_plugins_p.h"
27
28#include <tdeconfig.h>
29#include <kdebug.h>
30#include <tdelocale.h>
31#include <klibloader.h>
32#include <assert.h>
33
34#include <tqdir.h>
35#include <tqfile.h>
36
37#include "kdecorationfactory.h"
38
39KDecorationPlugins::KDecorationPlugins( TDEConfig* cfg )
40 : create_ptr( NULL ),
41 library( NULL ),
42 fact( NULL ),
43 old_library( NULL ),
44 old_fact( NULL ),
45 pluginStr( "twin_undefined " ),
46 config( cfg )
47 {
48 }
49
50KDecorationPlugins::~KDecorationPlugins()
51 {
52 if(library)
53 {
54 assert( fact != NULL );
55 delete fact;
56 library->unload();
57 }
58 if(old_library)
59 {
60 assert( old_fact != NULL );
61 delete old_fact;
62 old_library->unload();
63 }
64 }
65
66bool KDecorationPlugins::reset( unsigned long changed )
67 {
68 TQString oldPlugin = pluginStr;
69 config->reparseConfiguration();
70 bool ret = false;
71 if(( !loadPlugin( "" ) && library ) // "" = read the one in cfg file
72 || oldPlugin == pluginStr )
73 { // no new plugin loaded, reset the old one
74 assert( fact != NULL );
75 ret = fact->reset( changed );
76 }
77 return ret || oldPlugin != pluginStr;
78 }
79
80KDecorationFactory* KDecorationPlugins::factory()
81 {
82 return fact;
83 }
84
85// convenience
86KDecoration* KDecorationPlugins::createDecoration( KDecorationBridge* bridge )
87 {
88 if( fact != NULL )
89 return fact->createDecoration( bridge );
90 return NULL;
91 }
92
93// returns true if plugin was loaded successfully
94bool KDecorationPlugins::loadPlugin( TQString nameStr )
95 {
96 if( nameStr.isEmpty())
97 {
98 TDEConfigGroupSaver saver( config, "Style" );
99 nameStr = config->readEntry("PluginLib", defaultPlugin );
100 }
101
102 KLibrary *oldLibrary = library;
103 KDecorationFactory* oldFactory = fact;
104
105 TQString path = KLibLoader::findLibrary(TQFile::encodeName(nameStr));
106
107 // If the plugin was not found, try to find the default
108 if (path.isEmpty())
109 {
110 nameStr = defaultPlugin;
111 path = KLibLoader::findLibrary(TQFile::encodeName(nameStr));
112 }
113
114 // If no library was found, exit twin with an error message
115 if (path.isEmpty())
116 {
117 error( i18n("No window decoration plugin library was found." ));
118 return false;
119 }
120
121 // Check if this library is not already loaded.
122 if(pluginStr == nameStr)
123 return true;
124
125 // Try loading the requested plugin
126 library = KLibLoader::self()->library(TQFile::encodeName(path));
127
128 // If that fails, fall back to the default plugin
129 if (!library)
130 {
131 kdDebug() << " could not load library, try default plugin again" << endl;
132 nameStr = defaultPlugin;
133 if ( pluginStr == nameStr )
134 return true;
135 path = KLibLoader::findLibrary(TQFile::encodeName(nameStr));
136 if (!path.isEmpty())
137 library = KLibLoader::self()->library(TQFile::encodeName(path));
138 }
139
140 if (!library)
141 {
142 error( i18n("The default decoration plugin is corrupt "
143 "and could not be loaded." ));
144 return false;
145 }
146
147 create_ptr = NULL;
148 if( library->hasSymbol("create_factory"))
149 {
150 void* create_func = library->symbol("create_factory");
151 if(create_func)
152 create_ptr = (KDecorationFactory* (*)())create_func;
153 }
154 if(!create_ptr)
155 {
156 error( i18n( "The library %1 is not a TWin plugin." ).arg( path ));
157 library->unload();
158 return false;
159 }
160 fact = create_ptr();
161 fact->checkRequirements( this ); // let it check what is supported
162
163 pluginStr = nameStr;
164
165 // For clients in tdeartwork
166 TQString catalogue = nameStr;
167 catalogue.replace( "twin3_", "twin_" );
168 TDEGlobal::locale()->insertCatalogue( catalogue );
169 // For KCommonDecoration based clients
170 TDEGlobal::locale()->insertCatalogue( "twin_lib" );
171 // For clients in tdebase
172 TDEGlobal::locale()->insertCatalogue( "twin_clients" );
173 // For clients in tdeartwork
174 TDEGlobal::locale()->insertCatalogue( "twin_art_clients" );
175
176 old_library = oldLibrary; // save for delayed destroying
177 old_fact = oldFactory;
178
179 return true;
180}
181
182void KDecorationPlugins::destroyPreviousPlugin()
183{
184 // Destroy the old plugin
185 if(old_library)
186 {
187 delete old_fact;
188 old_fact = NULL;
189 old_library->unload();
190 old_library = NULL;
191 }
192}
193
194void KDecorationPlugins::error( const TQString& )
195 {
196 }
KDecoration
This is the base class for a decoration object.
Definition: kdecoration.h:315

twin/lib

Skip menu "twin/lib"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

twin/lib

Skip menu "twin/lib"
  • kate
  • libkonq
  • twin
  •   lib
Generated for twin/lib by doxygen 1.9.4
This website is maintained by Timothy Pearson.