author | zecke <zecke> | 2004-08-25 21:53:50 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-08-25 21:53:50 (UTC) |
commit | a64c92819cd3106584d9005e42ed972726081a94 (patch) (unidiff) | |
tree | f8ac45c7154db71a988cc5a9596587a30b9d9cce | |
parent | df3e4c8b13c16aeb96e70dbaa2d409f83eed988e (diff) | |
download | opie-a64c92819cd3106584d9005e42ed972726081a94.zip opie-a64c92819cd3106584d9005e42ed972726081a94.tar.gz opie-a64c92819cd3106584d9005e42ed972726081a94.tar.bz2 |
Respect the value passed to the method
-rw-r--r-- | libopie2/opiecore/opluginloader.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libopie2/opiecore/opluginloader.cpp b/libopie2/opiecore/opluginloader.cpp index e7eddc2..1edf3a1 100644 --- a/libopie2/opiecore/opluginloader.cpp +++ b/libopie2/opiecore/opluginloader.cpp | |||
@@ -1,103 +1,104 @@ | |||
1 | /* | 1 | /* |
2 | * LGPLv2 or later | 2 | * LGPLv2 or later |
3 | * zecke@handhelds.org | 3 | * zecke@handhelds.org |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "opluginloader.h" | 6 | #include "opluginloader.h" |
7 | #include "oconfig.h" | 7 | #include "oconfig.h" |
8 | #include "odebug.h" | ||
8 | 9 | ||
9 | #include <qpe/qpeapplication.h> | 10 | #include <qpe/qpeapplication.h> |
10 | 11 | ||
11 | #include <qdir.h> | 12 | #include <qdir.h> |
12 | #include <qdict.h> | 13 | #include <qdict.h> |
13 | #include <qtl.h> | 14 | #include <qtl.h> |
14 | #include <qfile.h> | 15 | #include <qfile.h> |
15 | 16 | ||
16 | #include <stdlib.h> | 17 | #include <stdlib.h> |
17 | 18 | ||
18 | 19 | ||
19 | 20 | ||
20 | namespace Opie { | 21 | namespace Opie { |
21 | namespace Core { | 22 | namespace Core { |
22 | namespace Internal { | 23 | namespace Internal { |
23 | struct OPluginLibraryHolder { | 24 | struct OPluginLibraryHolder { |
24 | static OPluginLibraryHolder *self(); | 25 | static OPluginLibraryHolder *self(); |
25 | QLibrary *ref( const QString& ); | 26 | QLibrary *ref( const QString& ); |
26 | void deref( QLibrary* ); | 27 | void deref( QLibrary* ); |
27 | private: | 28 | private: |
28 | 29 | ||
29 | OPluginLibraryHolder(); | 30 | OPluginLibraryHolder(); |
30 | ~OPluginLibraryHolder(); | 31 | ~OPluginLibraryHolder(); |
31 | QDict<QLibrary> m_libs; | 32 | QDict<QLibrary> m_libs; |
32 | static OPluginLibraryHolder* m_self; | 33 | static OPluginLibraryHolder* m_self; |
33 | }; | 34 | }; |
34 | 35 | ||
35 | OPluginLibraryHolder* OPluginLibraryHolder::m_self = 0; | 36 | OPluginLibraryHolder* OPluginLibraryHolder::m_self = 0; |
36 | OPluginLibraryHolder* OPluginLibraryHolder::self() { | 37 | OPluginLibraryHolder* OPluginLibraryHolder::self() { |
37 | if ( !m_self ) | 38 | if ( !m_self ) |
38 | m_self = new OPluginLibraryHolder; | 39 | m_self = new OPluginLibraryHolder; |
39 | 40 | ||
40 | return m_self; | 41 | return m_self; |
41 | } | 42 | } |
42 | 43 | ||
43 | OPluginLibraryHolder::OPluginLibraryHolder() {} | 44 | OPluginLibraryHolder::OPluginLibraryHolder() {} |
44 | OPluginLibraryHolder::~OPluginLibraryHolder() {} | 45 | OPluginLibraryHolder::~OPluginLibraryHolder() {} |
45 | 46 | ||
46 | /* | 47 | /* |
47 | * We do simple ref counting... We will add the QLibrary again | 48 | * We do simple ref counting... We will add the QLibrary again |
48 | * and again to the dictionary and on deref we will pop and pop it | 49 | * and again to the dictionary and on deref we will pop and pop it |
49 | * until there are no more library and we will unload and delete the library | 50 | * until there are no more library and we will unload and delete the library |
50 | * luckily dlopen does some ref counting as well so we don't need | 51 | * luckily dlopen does some ref counting as well so we don't need |
51 | * to hack QPEApplication | 52 | * to hack QPEApplication |
52 | */ | 53 | */ |
53 | QLibrary* OPluginLibraryHolder::ref(const QString& str) { | 54 | QLibrary* OPluginLibraryHolder::ref(const QString& str) { |
54 | QLibrary *lib = m_libs[str]; | 55 | QLibrary *lib = m_libs[str]; |
55 | 56 | ||
56 | /* if not in the dict try to load it */ | 57 | /* if not in the dict try to load it */ |
57 | if ( !lib ) { | 58 | if ( !lib ) { |
58 | lib = new QLibrary( str, QLibrary::Immediately ); | 59 | lib = new QLibrary( str, QLibrary::Immediately ); |
59 | if ( !lib->isLoaded() ) { | 60 | if ( !lib->isLoaded() ) { |
60 | delete lib; | 61 | delete lib; |
61 | return 0l; | 62 | return 0l; |
62 | } | 63 | } |
63 | } | 64 | } |
64 | 65 | ||
65 | /* now refcount one up */ | 66 | /* now refcount one up */ |
66 | m_libs.insert( str, lib ); | 67 | m_libs.insert( str, lib ); |
67 | return lib; | 68 | return lib; |
68 | } | 69 | } |
69 | 70 | ||
70 | /* | 71 | /* |
71 | * 'unshadow' the items until we're the last then unload and delete | 72 | * 'unshadow' the items until we're the last then unload and delete |
72 | */ | 73 | */ |
73 | void OPluginLibraryHolder::deref( QLibrary* lib ) { | 74 | void OPluginLibraryHolder::deref( QLibrary* lib ) { |
74 | if ( !lib ) | 75 | if ( !lib ) |
75 | return; | 76 | return; |
76 | 77 | ||
77 | QString str = lib->library(); | 78 | QString str = lib->library(); |
78 | /* no need to check if the lib was inserted or such */ | 79 | /* no need to check if the lib was inserted or such */ |
79 | (void) m_libs.take( str ); | 80 | (void) m_libs.take( str ); |
80 | if ( !m_libs[str] ) { | 81 | if ( !m_libs[str] ) { |
81 | lib->unload(); | 82 | lib->unload(); |
82 | delete lib; | 83 | delete lib; |
83 | } | 84 | } |
84 | } | 85 | } |
85 | } | 86 | } |
86 | 87 | ||
87 | /** | 88 | /** |
88 | * We want values with 30,29,28 at the beginning of the list | 89 | * We want values with 30,29,28 at the beginning of the list |
89 | */ | 90 | */ |
90 | 91 | ||
91 | bool operator<( const OPluginItem& l, const OPluginItem& r ) { | 92 | bool operator<( const OPluginItem& l, const OPluginItem& r ) { |
92 | return l.position() > r.position(); | 93 | return l.position() > r.position(); |
93 | } | 94 | } |
94 | 95 | ||
95 | bool operator>( const OPluginItem& l, const OPluginItem& r ) { | 96 | bool operator>( const OPluginItem& l, const OPluginItem& r ) { |
96 | return l.position() < r.position(); | 97 | return l.position() < r.position(); |
97 | } | 98 | } |
98 | 99 | ||
99 | bool operator<=( const OPluginItem& l, const OPluginItem& r ) { | 100 | bool operator<=( const OPluginItem& l, const OPluginItem& r ) { |
100 | return l.position() >= r.position(); | 101 | return l.position() >= r.position(); |
101 | } | 102 | } |
102 | 103 | ||
103 | /** | 104 | /** |
@@ -462,197 +463,198 @@ void OGenericPluginLoader::readConfig() { | |||
462 | /** | 463 | /** |
463 | * @internal Enter or leave SafeMode | 464 | * @internal Enter or leave SafeMode |
464 | */ | 465 | */ |
465 | void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { | 466 | void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { |
466 | OConfig conf( m_dir + "-odpplugins" ); | 467 | OConfig conf( m_dir + "-odpplugins" ); |
467 | conf.setGroup( "General" ); | 468 | conf.setGroup( "General" ); |
468 | conf.writeEntry( "SafeMode", b ); | 469 | conf.writeEntry( "SafeMode", b ); |
469 | conf.writeEntry( "CrashedPlugin", str ); | 470 | conf.writeEntry( "CrashedPlugin", str ); |
470 | } | 471 | } |
471 | 472 | ||
472 | /** | 473 | /** |
473 | * @internal | 474 | * @internal |
474 | * | 475 | * |
475 | * 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 |
476 | * is used as plugin dir | 477 | * is used as plugin dir |
477 | */ | 478 | */ |
478 | void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) { | 479 | void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) { |
479 | m_plugDirs = lst; | 480 | m_plugDirs = lst; |
480 | } | 481 | } |
481 | 482 | ||
482 | /** | 483 | /** |
483 | * | 484 | * |
484 | * @internal | 485 | * @internal |
485 | * 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 |
486 | */ | 487 | */ |
487 | void OGenericPluginLoader::setPluginDir( const QString& str) { | 488 | void OGenericPluginLoader::setPluginDir( const QString& str) { |
488 | m_plugDirs.clear(); | 489 | m_plugDirs.clear(); |
489 | m_plugDirs.append( str ); | 490 | m_plugDirs.append( str ); |
490 | } | 491 | } |
491 | 492 | ||
492 | 493 | ||
493 | /** | 494 | /** |
494 | * @internal | 495 | * @internal |
495 | */ | 496 | */ |
496 | bool OGenericPluginLoader::isSorted()const{ | 497 | bool OGenericPluginLoader::isSorted()const{ |
497 | return m_isSorted; | 498 | return m_isSorted; |
498 | } | 499 | } |
499 | 500 | ||
500 | /* | 501 | /* |
501 | * make libfoo.so.1.0.0 -> foo on UNIX | 502 | * make libfoo.so.1.0.0 -> foo on UNIX |
502 | * make libfoo.dylib -> foo on MAC OS X Unix | 503 | * make libfoo.dylib -> foo on MAC OS X Unix |
503 | * windows is obviously missing | 504 | * windows is obviously missing |
504 | */ | 505 | */ |
505 | /** | 506 | /** |
506 | * @internal | 507 | * @internal |
507 | */ | 508 | */ |
508 | QString OGenericPluginLoader::unlibify( const QString& str ) { | 509 | QString OGenericPluginLoader::unlibify( const QString& str ) { |
509 | QString st = str.mid( str.find( "lib" )+3 ); | 510 | QString st = str.mid( str.find( "lib" )+3 ); |
510 | #ifdef Q_OS_MACX | 511 | #ifdef Q_OS_MACX |
511 | return st.left( st.findRev( ".dylib" ) ); | 512 | return st.left( st.findRev( ".dylib" ) ); |
512 | #else | 513 | #else |
513 | return st.left( st.findRev( ".so" ) ); | 514 | return st.left( st.findRev( ".so" ) ); |
514 | #endif | 515 | #endif |
515 | } | 516 | } |
516 | 517 | ||
517 | /** | 518 | /** |
518 | * @internal | 519 | * @internal |
519 | * | 520 | * |
520 | * \brief method to return available plugins. Internal and for reeimplementations | 521 | * \brief method to return available plugins. Internal and for reeimplementations |
521 | * | 522 | * |
522 | *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. |
523 | * If a plugin is on the excluded list assign position -2 | 524 | * If a plugin is on the excluded list assign position -2 |
524 | * | 525 | * |
525 | * @param dir The dir to look in | 526 | * @param dir The dir to look in |
526 | * @param sorted Should positions be read? | 527 | * @param sorted Should positions be read? |
527 | * @param disabled Remove excluded from the list | 528 | * @param disabled Remove excluded from the list |
528 | */ | 529 | */ |
529 | OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { | 530 | OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { |
530 | #ifdef Q_OS_MACX | 531 | #ifdef Q_OS_MACX |
531 | QDir dir( _dir, "lib*.dylib" ); | 532 | QDir dir( _dir, "lib*.dylib" ); |
532 | #else | 533 | #else |
533 | QDir dir( _dir, "lib*.so" ); | 534 | QDir dir( _dir, "lib*.so" ); |
534 | #endif | 535 | #endif |
535 | 536 | ||
536 | 537 | ||
537 | OPluginItem::List lst; | 538 | OPluginItem::List lst; |
538 | 539 | ||
539 | /* | 540 | /* |
540 | * get excluded list and then iterate over them | 541 | * get excluded list and then iterate over them |
541 | * Excluded list contains the name | 542 | * Excluded list contains the name |
542 | * Position is a list with 'name.pos.name.pos.name.pos' | 543 | * Position is a list with 'name.pos.name.pos.name.pos' |
543 | * | 544 | * |
544 | * For the look up we will create two QMap<QString,pos> | 545 | * For the look up we will create two QMap<QString,pos> |
545 | */ | 546 | */ |
546 | QMap<QString, int> positionMap; | 547 | QMap<QString, int> positionMap; |
547 | QMap<QString, int> excludedMap; | 548 | QMap<QString, int> excludedMap; |
548 | 549 | ||
549 | 550 | ||
550 | OConfig cfg( m_dir+"-odpplugins" ); | 551 | OConfig cfg( m_dir+"-odpplugins" ); |
551 | cfg.setGroup( _dir ); | 552 | cfg.setGroup( _dir ); |
552 | 553 | ||
553 | 554 | ||
554 | QStringList excludes = cfg.readListEntry( "Excluded", ',' ); | 555 | QStringList excludes = cfg.readListEntry( "Excluded", ',' ); |
555 | for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it ) | 556 | for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it ) |
556 | excludedMap.insert( *it, -2 ); | 557 | excludedMap.insert( *it, -2 ); |
557 | 558 | ||
558 | if ( m_isSorted ) { | 559 | if ( sorted ) { |
559 | QStringList pos = cfg.readListEntry( "Positions", '.' ); | 560 | QStringList pos = cfg.readListEntry( "Positions", '.' ); |
560 | QStringList::Iterator it = pos.begin(); | 561 | QStringList::Iterator it = pos.begin(); |
561 | while ( it != pos.end() ) | 562 | while ( it != pos.end() ) |
562 | positionMap.insert( *it++, (*it++).toInt() ); | 563 | positionMap.insert( *it++, (*it++).toInt() ); |
564 | |||
563 | } | 565 | } |
564 | 566 | ||
565 | 567 | ||
566 | 568 | ||
567 | 569 | ||
568 | QStringList list = dir.entryList(); | 570 | QStringList list = dir.entryList(); |
569 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 571 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
570 | QString str = unlibify( *it ); | 572 | QString str = unlibify( *it ); |
571 | OPluginItem item( str, _dir + "/" + *it ); | 573 | OPluginItem item( str, _dir + "/" + *it ); |
572 | 574 | ||
573 | bool ex = excludedMap.contains( str ); | 575 | bool ex = excludedMap.contains( str ); |
574 | /* | 576 | /* |
575 | * if disabled but we should show all mark it as disabled | 577 | * if disabled but we should show all mark it as disabled |
576 | * else continue because we don't want to add the item | 578 | * else continue because we don't want to add the item |
577 | * else if sorted we assign the right position | 579 | * else if sorted we assign the right position |
578 | */ | 580 | */ |
579 | if ( ex && !disabled) | 581 | if ( ex && !disabled) |
580 | item.setEnabled( false ); | 582 | item.setEnabled( false ); |
581 | else if ( ex && disabled ) | 583 | else if ( ex && disabled ) |
582 | continue; | 584 | continue; |
583 | else if ( sorted ) | 585 | else if ( sorted ) |
584 | item.setPosition( positionMap[str] ); | 586 | item.setPosition( positionMap[str] ); |
585 | 587 | ||
586 | lst.append( item ); | 588 | lst.append( item ); |
587 | } | 589 | } |
588 | 590 | ||
589 | return lst; | 591 | return lst; |
590 | } | 592 | } |
591 | 593 | ||
592 | /** | 594 | /** |
593 | * @internal generate a list of languages from $LANG | 595 | * @internal generate a list of languages from $LANG |
594 | */ | 596 | */ |
595 | QStringList OGenericPluginLoader::languageList() { | 597 | QStringList OGenericPluginLoader::languageList() { |
596 | if ( m_languages.isEmpty() ) { | 598 | if ( m_languages.isEmpty() ) { |
597 | /* | 599 | /* |
598 | * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be | 600 | * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be |
599 | * to our list of languages. | 601 | * to our list of languages. |
600 | */ | 602 | */ |
601 | QString str = ::getenv( "LANG" ); | 603 | QString str = ::getenv( "LANG" ); |
602 | m_languages += str; | 604 | m_languages += str; |
603 | int pos = str.find( '.' ); | 605 | int pos = str.find( '.' ); |
604 | 606 | ||
605 | if ( pos > 0 ) | 607 | if ( pos > 0 ) |
606 | m_languages += str.left( pos ); | 608 | m_languages += str.left( pos ); |
607 | 609 | ||
608 | int n_pos = str.find( '_' ); | 610 | int n_pos = str.find( '_' ); |
609 | if ( pos > 0 && n_pos >= pos ) | 611 | if ( pos > 0 && n_pos >= pos ) |
610 | m_languages += str.left( n_pos ); | 612 | m_languages += str.left( n_pos ); |
611 | 613 | ||
612 | } | 614 | } |
613 | return m_languages; | 615 | return m_languages; |
614 | } | 616 | } |
615 | 617 | ||
616 | /** | 618 | /** |
617 | * @internal | 619 | * @internal |
618 | * Tries to install languages using the languageList for the type | 620 | * Tries to install languages using the languageList for the type |
619 | */ | 621 | */ |
620 | void OGenericPluginLoader::installTranslators(const QString& type) { | 622 | void OGenericPluginLoader::installTranslators(const QString& type) { |
621 | QStringList lst = languageList(); | 623 | QStringList lst = languageList(); |
622 | 624 | ||
623 | /* | 625 | /* |
624 | * for each language and maybe later for each language dir... | 626 | * for each language and maybe later for each language dir... |
625 | * try to load a Translator | 627 | * try to load a Translator |
626 | */ | 628 | */ |
627 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | 629 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { |
628 | QTranslator* trans = new QTranslator( qApp ); | 630 | QTranslator* trans = new QTranslator( qApp ); |
629 | QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ; | 631 | QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ; |
630 | 632 | ||
631 | /* | 633 | /* |
632 | * If loaded then install else clean up and don't leak | 634 | * If loaded then install else clean up and don't leak |
633 | */ | 635 | */ |
634 | if ( trans->load( tfn ) ) | 636 | if ( trans->load( tfn ) ) |
635 | qApp->installTranslator( trans ); | 637 | qApp->installTranslator( trans ); |
636 | else | 638 | else |
637 | delete trans; | 639 | delete trans; |
638 | } | 640 | } |
639 | } | 641 | } |
640 | 642 | ||
641 | /** | 643 | /** |
642 | * \brief Simple c'tor. | 644 | * \brief Simple c'tor. |
643 | * | 645 | * |
644 | * Simple C'tor same as the one of the base class. Additional this | 646 | * Simple C'tor same as the one of the base class. Additional this |
645 | * class can cast for you if you nee it. | 647 | * class can cast for you if you nee it. |
646 | * | 648 | * |
647 | * | 649 | * |
648 | * @param name The name of your plugin class | 650 | * @param name The name of your plugin class |
649 | * @param sorted If plugins are sorted | 651 | * @param sorted If plugins are sorted |
650 | * | 652 | * |
651 | * @see OGenericPluginLoader | 653 | * @see OGenericPluginLoader |
652 | */ | 654 | */ |
653 | OPluginLoader::OPluginLoader( const QString& name, bool sorted ) | 655 | OPluginLoader::OPluginLoader( const QString& name, bool sorted ) |
654 | : OGenericPluginLoader( name, sorted ) | 656 | : OGenericPluginLoader( name, sorted ) |
655 | { | 657 | { |
656 | } | 658 | } |
657 | 659 | ||
658 | /** | 660 | /** |