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

twin/lib

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

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.8.1.2
This website is maintained by Timothy Pearson.