-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,71 +1,72 @@ | |||
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 |
@@ -494,133 +495,134 @@ void OGenericPluginLoader::setPluginDir( const QString& str) { | |||
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 | */ |