1 /*****************************************************************
2 // vim: sw=4 sts=4 et tw=100
3 This file is part of the KDE project.
5 Copyright (C) 1999, 2000 Daniel M. Duley <mosfet@kde.org>
6 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 and/or sell copies of the Software, and to permit persons to whom the
13 Software is furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 DEALINGS IN THE SOFTWARE.
25 ******************************************************************/
27 #include "kdecoration_plugins_p.h"
32 #include <klibloader.h>
33 #include <kconfiggroup.h>
39 #include "kdecorationfactory.h"
41 KDecorationPlugins::KDecorationPlugins(const KSharedConfigPtr
&cfg
)
47 pluginStr( "kwin3_undefined " ),
52 KDecorationPlugins::~KDecorationPlugins()
56 assert( fact
!= NULL
);
62 assert( old_fact
!= NULL
);
64 old_library
->unload();
68 QString
KDecorationPlugins::currentPlugin()
73 bool KDecorationPlugins::reset( unsigned long changed
)
75 QString oldPlugin
= pluginStr
;
76 config
->reparseConfiguration();
78 if(( !loadPlugin( "" ) && library
) // "" = read the one in cfg file
79 || oldPlugin
== pluginStr
)
80 { // no new plugin loaded, reset the old one
81 assert( fact
!= NULL
);
82 ret
= fact
->reset( changed
);
84 return ret
|| oldPlugin
!= pluginStr
;
87 KDecorationFactory
* KDecorationPlugins::factory()
93 KDecoration
* KDecorationPlugins::createDecoration( KDecorationBridge
* bridge
)
96 return fact
->createDecoration( bridge
);
100 // returns true if plugin was loaded successfully
101 bool KDecorationPlugins::loadPlugin( QString nameStr
)
103 if( nameStr
.isEmpty())
105 KConfigGroup
group( config
, QString("Style") );
106 nameStr
= group
.readEntry("PluginLib", defaultPlugin
);
108 // make sure people can switch between HEAD and kwin_iii branch
109 if( nameStr
.startsWith( "kwin_" ))
110 nameStr
= "kwin3_" + nameStr
.mid( 5 );
112 KLibrary
*oldLibrary
= library
;
113 KDecorationFactory
* oldFactory
= fact
;
115 QString path
= KLibLoader::findLibrary(nameStr
);
116 kDebug(1212) << "kwin : path " << path
<< " for " << nameStr
;
118 // If the plugin was not found, try to find the default
121 nameStr
= defaultPlugin
;
122 path
= KLibLoader::findLibrary(nameStr
);
125 // If no library was found, exit kwin with an error message
128 error( i18n("No window decoration plugin library was found." ));
132 // Check if this library is not already loaded.
133 if(pluginStr
== nameStr
)
136 // Try loading the requested plugin
137 library
= KLibLoader::self()->library(path
);
139 // If that fails, fall back to the default plugin
142 kDebug(1212) << " could not load library, try default plugin again";
143 nameStr
= defaultPlugin
;
144 if ( pluginStr
== nameStr
)
146 path
= KLibLoader::findLibrary(nameStr
);
148 library
= KLibLoader::self()->library(path
);
153 error( i18n("The default decoration plugin is corrupt "
154 "and could not be loaded." ));
159 KLibrary::void_function_ptr create_func
= library
->resolveFunction("create_factory");
161 create_ptr
= (KDecorationFactory
* (*)())create_func
;
165 error( i18n( "The library %1 is not a KWin plugin.", path
));
170 fact
->checkRequirements( this ); // let it check what is supported
174 // For clients in kdeartwork
175 QString catalog
= nameStr
;
176 catalog
.replace( "kwin3_", "kwin_" );
177 KGlobal::locale()->insertCatalog( catalog
);
178 // For KCommonDecoration based clients
179 KGlobal::locale()->insertCatalog( "kwin_lib" );
180 // For clients in kdebase
181 KGlobal::locale()->insertCatalog( "kwin_clients" );
182 // For clients in kdeartwork
183 KGlobal::locale()->insertCatalog( "kwin_art_clients" );
185 old_library
= oldLibrary
; // save for delayed destroying
186 old_fact
= oldFactory
;
191 void KDecorationPlugins::destroyPreviousPlugin()
193 // Destroy the old plugin
198 old_library
->unload();
203 void KDecorationPlugins::error( const QString
& )