summaryrefslogtreecommitdiff
authorzecke <zecke>2004-05-29 18:43:13 (UTC)
committer zecke <zecke>2004-05-29 18:43:13 (UTC)
commit43c1ce80bc5faf16fe9d86c4685512659f5180bc (patch) (side-by-side diff)
treeebd64b019954d702a39bad96d3324bbe79d7f9b6
parentf568ff9c68bdc61cbc4482f9b2c6e1096cecaae0 (diff)
downloadopie-43c1ce80bc5faf16fe9d86c4685512659f5180bc.zip
opie-43c1ce80bc5faf16fe9d86c4685512659f5180bc.tar.gz
opie-43c1ce80bc5faf16fe9d86c4685512659f5180bc.tar.bz2
Make Enabled/Disabled work.
Problem was /home/ich/foo//plugins/foo where /home/ich/foo/ was OPIEDIR and we added /
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/opluginloader.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/libopie2/opiecore/opluginloader.cpp b/libopie2/opiecore/opluginloader.cpp
index 3d286e5..e7eddc2 100644
--- a/libopie2/opiecore/opluginloader.cpp
+++ b/libopie2/opiecore/opluginloader.cpp
@@ -188,193 +188,193 @@ QString OPluginItem::path()const {
/**
* \brief Return if this item is enabled.
*/
bool OPluginItem::isEnabled()const {
return m_enabled;
}
/**
* \brief return the position of a plugin.
* return the position of the item
* -1 is the default value and means normally that the whole items are unsorted.
* Higher numbers belong to an upper position. With plugins with the postions 20,19,5,3
* the item with pos 20 would be the first in the list returned by the OGenericPluginLoader
*
* @see OGenericPluginLoader::allAvailable
* @see OGenericPluginLoader::filtered
*/
int OPluginItem::position()const{
return m_pos;
}
/**
* \brief set the name of a plugin
* Set the name of the Plugin Item
* @param name
*/
void OPluginItem::setName( const QString& name ) {
m_name = name;
}
/**
* \brief set the path of a plugin
* Set the path of Plugin Item. The path must be absolute.
* @param name The path of the plugin
*/
void OPluginItem::setPath( const QString& name ) {
m_path = name;
}
/**
* \brief enable or disable the to load attribute
* Set the Enabled attribute. Such changes won't be saved. If you want to save it
* use a OPluginManager to configure your plugins manually or Opie::Ui::OPluginConfig
* for a graphical frontend.
*
* @param enabled Enable or Disable the Enabled Attribute
*/
void OPluginItem::setEnabled( bool enabled ) {
m_enabled = enabled;
}
/**
* \brief Set the position.
* Set the position
* @param pos The position
*
* @see position()
*/
void OPluginItem::setPosition( int pos ) {
m_pos = pos;
}
/**
* \brief create a PluginLoader
*
* Create a PluginLoader autoDelete is set to false
*
* \code
* Opie::Core::OGenericPluginLoader loader("myapp-plugin");
* Opie::Core::OPluginItem::List lst = loader.filtered();
* for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){
* MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface));
* }
* \endcode
*
* \code
* Opie::Core::OGenericPluginLoader loader("myapp-plugin");
* Opie::Core::OPluginItem::List lst = loader.filtered();
* for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){
* MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface));
* }
* ...
* loader.clear();
*
* \endcode
*
* @param name The name of the plugin directory.
* @param isSorted Tell the PluginLoader if your Plugins are sorted
*/
OGenericPluginLoader::OGenericPluginLoader( const QString& name, bool isSorted)
: m_dir( name ), m_autoDelete( false ), m_isSafeMode( false ),
m_isSorted( isSorted )
{
- setPluginDir( QPEApplication::qpeDir() + "/plugins/"+name );
+ setPluginDir( QPEApplication::qpeDir() + "plugins/"+name );
readConfig();
}
/**
* \brief simple d'tor that cleans up depending on autoDelete
*
* calls clear if autoDelete is true. This will release all interfaces
* and remove the library from this process if the refcount falls to zero
*/
OGenericPluginLoader::~OGenericPluginLoader() {
if ( m_autoDelete )
clear();
}
/**
* \brief Enable or disable autoDelete on destruction
*
* enable autoDelete. This will call clear on the d'tor
*
* @see ~OGenericPluginLoader
* @see clear()
*/
void OGenericPluginLoader::setAutoDelete( bool t ) {
m_autoDelete = t;
}
/**
* \brief See if autoDelete is enabled.
*/
bool OGenericPluginLoader::autoDelete()const{
return m_autoDelete;
}
/**
* \brief unload all loaded Plugins
*
* This will unload all returned QUnknownInterfaces by load. Unload
* will be called.
*/
void OGenericPluginLoader::clear() {
QPtrDictIterator<QLibrary> it( m_library );
for ( ;it.current(); )
unload( static_cast<QUnknownInterface*>( it.currentKey() ) );
}
/**
* \brief unload the Plugin and the accompanied Resources.
*
* This will take the iface from the internal QPtrDict, Release it,
* and deref the libray used.
* The visibility depends on the QPtrDict.
* @see QPtrDict::insert
*/
void OGenericPluginLoader::unload( QUnknownInterface* iface ) {
if ( !iface )
return;
iface->release();
Internal::OPluginLibraryHolder::self()->deref( m_library.take( iface ) );
}
/**
* \brief The name of the plugins.
*
* Return the name/type you specified in the constructor.
* This is at least used by the OPluginManager to find the right config
*/
QString OGenericPluginLoader::name()const {
return m_dir;
}
/**
* \brief See if loading of a plugin segfaulted
* This tells you
* if by previous tries to load, loading crashed your application.
* If isInSafeMode you can use the GUI to configure the plugins prior to loading
*
* @return true if prior loading failed
*/
bool OGenericPluginLoader::isInSafeMode()const {
return m_isSafeMode;
}
/**
* \brief Return all Plugins found in the plugins dirs.
* Return the list of all available plugins. This will go through all plugin
* directories and search for your type of plugins ( by subdir )
*
* @param sorted Tell if you want to have the positions sorted. This only makes sense if you
*/
OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const {
OPluginItem::List lst;
for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it )
@@ -440,192 +440,193 @@ QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QU
installTranslators(pa.left( pa.find(".")));
m_library.insert( iface, lib );
}else
iface = 0;
setSafeMode();
return iface;
}
/**
* @internal and reads in the safe mode
*/
void OGenericPluginLoader::readConfig() {
/* read the config for SafeMode */
OConfig conf( m_dir + "-odpplugins" );
conf.setGroup( "General" );
m_isSafeMode = conf.readBoolEntry( "SafeMode", false );
}
/**
* @internal Enter or leave SafeMode
*/
void OGenericPluginLoader::setSafeMode(const QString& str, bool b) {
OConfig conf( m_dir + "-odpplugins" );
conf.setGroup( "General" );
conf.writeEntry( "SafeMode", b );
conf.writeEntry( "CrashedPlugin", str );
}
/**
* @internal
*
* Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"/plugins/"+mytype
* is used as plugin dir
*/
void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) {
m_plugDirs = lst;
}
/**
*
* @internal
* Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs
*/
void OGenericPluginLoader::setPluginDir( const QString& str) {
m_plugDirs.clear();
m_plugDirs.append( str );
}
/**
* @internal
*/
bool OGenericPluginLoader::isSorted()const{
return m_isSorted;
}
/*
* make libfoo.so.1.0.0 -> foo on UNIX
* make libfoo.dylib -> foo on MAC OS X Unix
* windows is obviously missing
*/
/**
* @internal
*/
QString OGenericPluginLoader::unlibify( const QString& str ) {
QString st = str.mid( str.find( "lib" )+3 );
#ifdef Q_OS_MACX
return st.left( st.findRev( ".dylib" ) );
#else
return st.left( st.findRev( ".so" ) );
#endif
}
/**
* @internal
*
* \brief method to return available plugins. Internal and for reeimplementations
*
*Return a List of Plugins for a dir and add positions and remove disabled.
* If a plugin is on the excluded list assign position -2
*
* @param dir The dir to look in
* @param sorted Should positions be read?
* @param disabled Remove excluded from the list
*/
OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const {
#ifdef Q_OS_MACX
QDir dir( _dir, "lib*.dylib" );
#else
QDir dir( _dir, "lib*.so" );
#endif
+
OPluginItem::List lst;
/*
* get excluded list and then iterate over them
* Excluded list contains the name
* Position is a list with 'name.pos.name.pos.name.pos'
*
* For the look up we will create two QMap<QString,pos>
*/
QMap<QString, int> positionMap;
QMap<QString, int> excludedMap;
OConfig cfg( m_dir+"-odpplugins" );
cfg.setGroup( _dir );
QStringList excludes = cfg.readListEntry( "Excluded", ',' );
for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it )
excludedMap.insert( *it, -2 );
if ( m_isSorted ) {
QStringList pos = cfg.readListEntry( "Positions", '.' );
QStringList::Iterator it = pos.begin();
while ( it != pos.end() )
positionMap.insert( *it++, (*it++).toInt() );
}
QStringList list = dir.entryList();
for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
QString str = unlibify( *it );
OPluginItem item( str, _dir + "/" + *it );
bool ex = excludedMap.contains( str );
/*
* if disabled but we should show all mark it as disabled
* else continue because we don't want to add the item
* else if sorted we assign the right position
*/
if ( ex && !disabled)
item.setEnabled( false );
else if ( ex && disabled )
continue;
else if ( sorted )
item.setPosition( positionMap[str] );
lst.append( item );
}
return lst;
}
/**
* @internal generate a list of languages from $LANG
*/
QStringList OGenericPluginLoader::languageList() {
if ( m_languages.isEmpty() ) {
/*
* be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be
* to our list of languages.
*/
QString str = ::getenv( "LANG" );
m_languages += str;
int pos = str.find( '.' );
if ( pos > 0 )
m_languages += str.left( pos );
int n_pos = str.find( '_' );
if ( pos > 0 && n_pos >= pos )
m_languages += str.left( n_pos );
}
return m_languages;
}
/**
* @internal
* Tries to install languages using the languageList for the type
*/
void OGenericPluginLoader::installTranslators(const QString& type) {
QStringList lst = languageList();
/*
* for each language and maybe later for each language dir...
* try to load a Translator
*/
for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
QTranslator* trans = new QTranslator( qApp );
QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ;
/*
* If loaded then install else clean up and don't leak