summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/opluginloader.cpp
Unidiff
Diffstat (limited to 'libopie2/opiecore/opluginloader.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/opluginloader.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opiecore/opluginloader.cpp b/libopie2/opiecore/opluginloader.cpp
index 2a6e369..d33eac6 100644
--- a/libopie2/opiecore/opluginloader.cpp
+++ b/libopie2/opiecore/opluginloader.cpp
@@ -380,358 +380,358 @@ OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const {
380 OPluginItem::List lst; 380 OPluginItem::List lst;
381 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) 381 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it )
382 lst += plugins( *it, sorted, false ); 382 lst += plugins( *it, sorted, false );
383 383
384 if ( sorted ) 384 if ( sorted )
385 qHeapSort( lst ); 385 qHeapSort( lst );
386 return lst; 386 return lst;
387} 387}
388 388
389/** 389/**
390 * \brief Return only the enabled plugins 390 * \brief Return only the enabled plugins
391 * Return only activated plugins. 391 * Return only activated plugins.
392 * 392 *
393 * @param sorted If the list should be sorted 393 * @param sorted If the list should be sorted
394 */ 394 */
395OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const { 395OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const {
396 OPluginItem::List lst; 396 OPluginItem::List lst;
397 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) 397 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it )
398 lst += plugins( *it, sorted, true ); 398 lst += plugins( *it, sorted, true );
399 399
400 if ( sorted ) 400 if ( sorted )
401 qHeapSort( lst ); 401 qHeapSort( lst );
402 return lst; 402 return lst;
403} 403}
404 404
405 405
406/** 406/**
407 * \brief Load a OPluginItem for the specified interface 407 * \brief Load a OPluginItem for the specified interface
408 * This will open the resource of the OPluginItem::path() and then will query 408 * This will open the resource of the OPluginItem::path() and then will query
409 * if the Interface specified in the uuid is available and then will manage the 409 * if the Interface specified in the uuid is available and then will manage the
410 * resource and Interface. 410 * resource and Interface.
411 * 411 *
412 * @param item The OPluginItem that should be loaded 412 * @param item The OPluginItem that should be loaded
413 * @param uuid The Interface to query for 413 * @param uuid The Interface to query for
414 * 414 *
415 * @return Either 0 in case of failure or the Plugin as QUnknownInterface* 415 * @return Either 0 in case of failure or the Plugin as QUnknownInterface*
416 */ 416 */
417QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) { 417QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) {
418 /* 418 /*
419 * Check if there could be a library 419 * Check if there could be a library
420 */ 420 */
421 QString pa = item.path(); 421 QString pa = item.path();
422 if ( pa.isEmpty() ) 422 if ( pa.isEmpty() )
423 return 0l; 423 return 0l;
424 424
425 /* 425 /*
426 * See if we get a library 426 * See if we get a library
427 * return if we've none 427 * return if we've none
428 */ 428 */
429 setSafeMode( pa, true ); 429 setSafeMode( pa, true );
430 QLibrary *lib = Internal::OPluginLibraryHolder::self()->ref( pa ); 430 QLibrary *lib = Internal::OPluginLibraryHolder::self()->ref( pa );
431 if ( !lib ) { 431 if ( !lib ) {
432 setSafeMode(); 432 setSafeMode();
433 return 0l; 433 return 0l;
434 } 434 }
435 435
436 /** 436 /**
437 * try to load the plugin and just in case initialize the pointer to a pointer again 437 * try to load the plugin and just in case initialize the pointer to a pointer again
438 */ 438 */
439 QUnknownInterface* iface=0; 439 QUnknownInterface* iface=0;
440 if ( lib->queryInterface( uuid, &iface ) == QS_OK ) { 440 if ( lib->queryInterface( uuid, &iface ) == QS_OK ) {
441 installTranslators( item.name() ); 441 installTranslators( item.name() );
442 m_library.insert( iface, lib ); 442 m_library.insert( iface, lib );
443 }else 443 }else
444 iface = 0; 444 iface = 0;
445 445
446 setSafeMode(); 446 setSafeMode();
447 447
448 return iface; 448 return iface;
449} 449}
450 450
451/** 451/**
452 * @internal and reads in the safe mode 452 * @internal and reads in the safe mode
453 */ 453 */
454void OGenericPluginLoader::readConfig() { 454void OGenericPluginLoader::readConfig() {
455 455
456 456
457/* read the config for SafeMode */ 457/* read the config for SafeMode */
458 OConfig conf( m_dir + "-odpplugins" ); 458 OConfig conf( m_dir + "-odpplugins" );
459 conf.setGroup( "General" ); 459 conf.setGroup( "General" );
460 m_isSafeMode = conf.readBoolEntry( "SafeMode", false ); 460 m_isSafeMode = conf.readBoolEntry( "SafeMode", false );
461} 461}
462 462
463/** 463/**
464 * @internal Enter or leave SafeMode 464 * @internal Enter or leave SafeMode
465 */ 465 */
466void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { 466void OGenericPluginLoader::setSafeMode(const QString& str, bool b) {
467 OConfig conf( m_dir + "-odpplugins" ); 467 OConfig conf( m_dir + "-odpplugins" );
468 conf.setGroup( "General" ); 468 conf.setGroup( "General" );
469 conf.writeEntry( "SafeMode", b ); 469 conf.writeEntry( "SafeMode", b );
470 conf.writeEntry( "CrashedPlugin", str ); 470 conf.writeEntry( "CrashedPlugin", str );
471} 471}
472 472
473/** 473/**
474 * @internal 474 * @internal
475 * 475 *
476 * Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"/plugins/"+mytype 476 * Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"plugins/"+mytype
477 * is used as plugin dir 477 * is used as plugin dir
478 */ 478 */
479void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) { 479void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) {
480 m_plugDirs = lst; 480 m_plugDirs = lst;
481} 481}
482 482
483/** 483/**
484 * 484 *
485 * @internal 485 * @internal
486 * Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs 486 * Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs
487 */ 487 */
488void OGenericPluginLoader::setPluginDir( const QString& str) { 488void OGenericPluginLoader::setPluginDir( const QString& str) {
489 m_plugDirs.clear(); 489 m_plugDirs.clear();
490 m_plugDirs.append( str ); 490 m_plugDirs.append( str );
491} 491}
492 492
493 493
494/** 494/**
495 * @internal 495 * @internal
496 */ 496 */
497bool OGenericPluginLoader::isSorted()const{ 497bool OGenericPluginLoader::isSorted()const{
498 return m_isSorted; 498 return m_isSorted;
499} 499}
500 500
501/* 501/*
502 * make libfoo.so.1.0.0 -> foo on UNIX 502 * make libfoo.so.1.0.0 -> foo on UNIX
503 * make libfoo.dylib -> foo on MAC OS X Unix 503 * make libfoo.dylib -> foo on MAC OS X Unix
504 * windows is obviously missing 504 * windows is obviously missing
505 */ 505 */
506/** 506/**
507 * @internal 507 * @internal
508 */ 508 */
509QString OGenericPluginLoader::unlibify( const QString& str ) { 509QString OGenericPluginLoader::unlibify( const QString& str ) {
510 QString st = str.mid( str.find( "lib" )+3 ); 510 QString st = str.mid( str.find( "lib" )+3 );
511#ifdef Q_OS_MACX 511#ifdef Q_OS_MACX
512 return st.left( st.findRev( ".dylib" ) ); 512 return st.left( st.findRev( ".dylib" ) );
513#else 513#else
514 return st.left( st.findRev( ".so" ) ); 514 return st.left( st.findRev( ".so" ) );
515#endif 515#endif
516} 516}
517 517
518/** 518/**
519 * @internal 519 * @internal
520 * 520 *
521 * \brief method to return available plugins. Internal and for reeimplementations 521 * \brief method to return available plugins. Internal and for reeimplementations
522 * 522 *
523 *Return a List of Plugins for a dir and add positions and remove disabled. 523 *Return a List of Plugins for a dir and add positions and remove disabled.
524 * If a plugin is on the excluded list assign position -2 524 * If a plugin is on the excluded list assign position -2
525 * 525 *
526 * @param _dir The dir to look in 526 * @param _dir The dir to look in
527 * @param sorted Should positions be read? 527 * @param sorted Should positions be read?
528 * @param disabled Remove excluded from the list 528 * @param disabled Remove excluded from the list
529 */ 529 */
530OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { 530OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const {
531#ifdef Q_OS_MACX 531#ifdef Q_OS_MACX
532 QDir dir( _dir, "lib*.dylib" ); 532 QDir dir( _dir, "lib*.dylib" );
533#else 533#else
534 QDir dir( _dir, "lib*.so" ); 534 QDir dir( _dir, "lib*.so" );
535#endif 535#endif
536 536
537 537
538 OPluginItem::List lst; 538 OPluginItem::List lst;
539 539
540 /* 540 /*
541 * get excluded list and then iterate over them 541 * get excluded list and then iterate over them
542 * Excluded list contains the name 542 * Excluded list contains the name
543 * Position is a list with 'name.pos.name.pos.name.pos' 543 * Position is a list with 'name.pos.name.pos.name.pos'
544 * 544 *
545 * For the look up we will create two QMap<QString,pos> 545 * For the look up we will create two QMap<QString,pos>
546 */ 546 */
547 QMap<QString, int> positionMap; 547 QMap<QString, int> positionMap;
548 QMap<QString, int> excludedMap; 548 QMap<QString, int> excludedMap;
549 549
550 550
551 OConfig cfg( m_dir+"-odpplugins" ); 551 OConfig cfg( m_dir+"-odpplugins" );
552 cfg.setGroup( _dir ); 552 cfg.setGroup( _dir );
553 553
554 554
555 QStringList excludes = cfg.readListEntry( "Excluded", ',' ); 555 QStringList excludes = cfg.readListEntry( "Excluded", ',' );
556 for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it ) 556 for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it )
557 excludedMap.insert( *it, -2 ); 557 excludedMap.insert( *it, -2 );
558 558
559 if ( sorted ) { 559 if ( sorted ) {
560 QStringList pos = cfg.readListEntry( "Positions", '.' ); 560 QStringList pos = cfg.readListEntry( "Positions", '.' );
561 QStringList::Iterator it = pos.begin(); 561 QStringList::Iterator it = pos.begin();
562 QString tmp; int i; 562 QString tmp; int i;
563 while ( it != pos.end() ) { 563 while ( it != pos.end() ) {
564 tmp = *it++; i = (*it++).toInt(); 564 tmp = *it++; i = (*it++).toInt();
565 positionMap.insert( tmp, i ); 565 positionMap.insert( tmp, i );
566 } 566 }
567 567
568 } 568 }
569 569
570 570
571 571
572 572
573 QStringList list = dir.entryList(); 573 QStringList list = dir.entryList();
574 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 574 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
575 QString str = unlibify( *it ); 575 QString str = unlibify( *it );
576 OPluginItem item( str, _dir + "/" + *it ); 576 OPluginItem item( str, _dir + "/" + *it );
577 577
578 bool ex = excludedMap.contains( str ); 578 bool ex = excludedMap.contains( str );
579 /* 579 /*
580 * if disabled but we should show all mark it as disabled 580 * if disabled but we should show all mark it as disabled
581 * else continue because we don't want to add the item 581 * else continue because we don't want to add the item
582 * else if sorted we assign the right position 582 * else if sorted we assign the right position
583 */ 583 */
584 if ( ex && !disabled) 584 if ( ex && !disabled)
585 item.setEnabled( false ); 585 item.setEnabled( false );
586 else if ( ex && disabled ) 586 else if ( ex && disabled )
587 continue; 587 continue;
588 else if ( sorted ) 588 else if ( sorted )
589 item.setPosition( positionMap[str] ); 589 item.setPosition( positionMap[str] );
590 590
591 591
592 lst.append( item ); 592 lst.append( item );
593 } 593 }
594 594
595 return lst; 595 return lst;
596} 596}
597 597
598/** 598/**
599 * @internal generate a list of languages from $LANG 599 * @internal generate a list of languages from $LANG
600 */ 600 */
601QStringList OGenericPluginLoader::languageList() { 601QStringList OGenericPluginLoader::languageList() {
602 if ( m_languages.isEmpty() ) { 602 if ( m_languages.isEmpty() ) {
603 /* 603 /*
604 * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be 604 * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be
605 * to our list of languages. 605 * to our list of languages.
606 * Also for de_DE@euro we will add de_DE@eurp, de_DE, de 606 * Also for de_DE@euro we will add de_DE@eurp, de_DE, de
607 * to our list of languages 607 * to our list of languages
608 */ 608 */
609 QString str = ::getenv( "LANG" ); 609 QString str = ::getenv( "LANG" );
610 m_languages += str; 610 m_languages += str;
611 int pos = str.find( '@' ); 611 int pos = str.find( '@' );
612 if( pos > 0 ) 612 if( pos > 0 )
613 m_languages += str.left( pos ); 613 m_languages += str.left( pos );
614 614
615 615
616 pos = str.find( '.' ); 616 pos = str.find( '.' );
617 if ( pos > 0 ) 617 if ( pos > 0 )
618 m_languages += str.left( pos ); 618 m_languages += str.left( pos );
619 619
620 int n_pos = str.find( '_' ); 620 int n_pos = str.find( '_' );
621 if ( n_pos > 0 ) 621 if ( n_pos > 0 )
622 m_languages += str.left( n_pos ); 622 m_languages += str.left( n_pos );
623 623
624 } 624 }
625 return m_languages; 625 return m_languages;
626} 626}
627 627
628/** 628/**
629 * @internal 629 * @internal
630 * Tries to install languages using the languageList for the type 630 * Tries to install languages using the languageList for the type
631 */ 631 */
632void OGenericPluginLoader::installTranslators(const QString& type) { 632void OGenericPluginLoader::installTranslators(const QString& type) {
633 QStringList lst = languageList(); 633 QStringList lst = languageList();
634 634
635 /* 635 /*
636 * for each language and maybe later for each language dir... 636 * for each language and maybe later for each language dir...
637 * try to load a Translator 637 * try to load a Translator
638 */ 638 */
639 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { 639 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
640 QTranslator* trans = new QTranslator( qApp ); 640 QTranslator* trans = new QTranslator( qApp );
641 QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/lib" + type + ".qm" ; 641 QString tfn = QPEApplication::qpeDir()+"i18n/" + *it + "/lib" + type + ".qm" ;
642 642
643 /* 643 /*
644 * If loaded then install else clean up and don't leak 644 * If loaded then install else clean up and don't leak
645 */ 645 */
646 if ( trans->load( tfn ) ) 646 if ( trans->load( tfn ) )
647 qApp->installTranslator( trans ); 647 qApp->installTranslator( trans );
648 else 648 else
649 delete trans; 649 delete trans;
650 } 650 }
651} 651}
652 652
653/** 653/**
654 * \brief Simple c'tor. 654 * \brief Simple c'tor.
655 * 655 *
656 * Simple C'tor same as the one of the base class. Additional this 656 * Simple C'tor same as the one of the base class. Additional this
657 * class can cast for you if you nee it. 657 * class can cast for you if you nee it.
658 * 658 *
659 * 659 *
660 * @param name The name of your plugin class 660 * @param name The name of your plugin class
661 * @param sorted If plugins are sorted 661 * @param sorted If plugins are sorted
662 * 662 *
663 * @see OGenericPluginLoader 663 * @see OGenericPluginLoader
664 */ 664 */
665OPluginLoader::OPluginLoader( const QString& name, bool sorted ) 665OPluginLoader::OPluginLoader( const QString& name, bool sorted )
666 : OGenericPluginLoader( name, sorted ) 666 : OGenericPluginLoader( name, sorted )
667{ 667{
668} 668}
669 669
670/** 670/**
671 * d'tor 671 * d'tor
672 * @see OGenericPluginLoader::~OGenericPluginLoader 672 * @see OGenericPluginLoader::~OGenericPluginLoader
673 */ 673 */
674OPluginLoader::~OPluginLoader() { 674OPluginLoader::~OPluginLoader() {
675} 675}
676 676
677/** 677/**
678 * \brief C'Tor using a OGenericPluginLoader 678 * \brief C'Tor using a OGenericPluginLoader
679 * The C'tor. Pass your OGenericPluginLoader to manage 679 * The C'tor. Pass your OGenericPluginLoader to manage
680 * OGenericPluginLoader::allAvailable plugins. 680 * OGenericPluginLoader::allAvailable plugins.
681 * 681 *
682 * 682 *
683 * @param loader A Pointer to your OGenericPluginLoader 683 * @param loader A Pointer to your OGenericPluginLoader
684 */ 684 */
685OPluginManager::OPluginManager( OGenericPluginLoader* loader) 685OPluginManager::OPluginManager( OGenericPluginLoader* loader)
686 : m_loader( loader ), m_isSorted( false ) 686 : m_loader( loader ), m_isSorted( false )
687{ 687{
688} 688}
689 689
690/** 690/**
691 * \brief Overloaded c'tor using a List of Plugins and a type name 691 * \brief Overloaded c'tor using a List of Plugins and a type name
692 * Overloaded Constructor to work with a 'Type' of plugins 692 * Overloaded Constructor to work with a 'Type' of plugins
693 * and a correspending list of those. In this case calling load 693 * and a correspending list of those. In this case calling load
694 * is a no operation. 694 * is a no operation.
695 * 695 *
696 * @param name The name of your plugin ('today','inputmethods','applets') 696 * @param name The name of your plugin ('today','inputmethods','applets')
697 * @param lst A List with plugins of your type to manage 697 * @param lst A List with plugins of your type to manage
698 * @param isSorted If the List should be treated sorted 698 * @param isSorted If the List should be treated sorted
699 */ 699 */
700OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) 700OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted)
701 : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted ) 701 : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted )
702{ 702{
703} 703}
704 704
705/** 705/**
706 * \brief A simple d'tor 706 * \brief A simple d'tor
707 */ 707 */
708OPluginManager::~OPluginManager() { 708OPluginManager::~OPluginManager() {
709} 709}
710 710
711/** 711/**
712 * \brief Return the OPluginItem where loading is likely to have crashed on. 712 * \brief Return the OPluginItem where loading is likely to have crashed on.
713 713
714 * Return the Item that made the OGenericPluginLoader crash 714 * Return the Item that made the OGenericPluginLoader crash
715 * the returned OPluginItem could be empty if no crash occured 715 * the returned OPluginItem could be empty if no crash occured
716 * which should apply most of the time. It could also be empty if the crashed 716 * which should apply most of the time. It could also be empty if the crashed
717 * plugin is not in the current list of available/managed plugins 717 * plugin is not in the current list of available/managed plugins
718 * 718 *
719 * @see OPluginItem::isEmpty 719 * @see OPluginItem::isEmpty
720 * @return OPluginItem that crashed the loader 720 * @return OPluginItem that crashed the loader
721 */ 721 */
722OPluginItem OPluginManager::crashedPlugin()const { 722OPluginItem OPluginManager::crashedPlugin()const {
723 return m_crashed; 723 return m_crashed;
724} 724}
725 725
726/** 726/**
727 * \brief Return a list of plugins that are managed by this OPluginManager 727 * \brief Return a list of plugins that are managed by this OPluginManager
728 * 728 *
729 * Return the list of managed plugins. This could either result 729 * Return the list of managed plugins. This could either result
730 * from passing a OGenericPluginLoader and calling load or by 730 * from passing a OGenericPluginLoader and calling load or by
731 * giving name and a list of plugins. 731 * giving name and a list of plugins.
732 */ 732 */
733OPluginItem::List OPluginManager::managedPlugins()const { 733OPluginItem::List OPluginManager::managedPlugins()const {
734 return m_plugins; 734 return m_plugins;
735} 735}
736 736
737/** 737/**