author | zecke <zecke> | 2003-05-12 13:07:37 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-05-12 13:07:37 (UTC) |
commit | 4765c92ba3dcbd829cb2adde4a097dfe6283d7cc (patch) (unidiff) | |
tree | 7a13062058737af1564863f9caec692f145fdfaa /library | |
parent | 65a043f4ac4b43967947c1e8d99c629bb993f065 (diff) | |
download | opie-4765c92ba3dcbd829cb2adde4a097dfe6283d7cc.zip opie-4765c92ba3dcbd829cb2adde4a097dfe6283d7cc.tar.gz opie-4765c92ba3dcbd829cb2adde4a097dfe6283d7cc.tar.bz2 |
Hospital Hacking Session
Install libopie.qm make apps fully translatable...
refactor installing trans into a method instead of having the same code copy
and pasted three times
-rw-r--r-- | library/qpeapplication.cpp | 30 | ||||
-rw-r--r-- | library/qpeapplication.h | 3 |
2 files changed, 18 insertions, 15 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index e5da48c..f4db1ab 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -574,80 +574,68 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t ) | |||
574 | f.remove(); | 574 | f.remove(); |
575 | } | 575 | } |
576 | 576 | ||
577 | for ( int a = 0; a < argc; a++ ) { | 577 | for ( int a = 0; a < argc; a++ ) { |
578 | if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { | 578 | if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { |
579 | argv[ a ] = argv[ a + 1 ]; | 579 | argv[ a ] = argv[ a + 1 ]; |
580 | a++; | 580 | a++; |
581 | d->preloaded = TRUE; | 581 | d->preloaded = TRUE; |
582 | argc -= 1; | 582 | argc -= 1; |
583 | } | 583 | } |
584 | else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { | 584 | else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { |
585 | argv[ a ] = argv[ a + 1 ]; | 585 | argv[ a ] = argv[ a + 1 ]; |
586 | a++; | 586 | a++; |
587 | d->preloaded = TRUE; | 587 | d->preloaded = TRUE; |
588 | d->forceshow = TRUE; | 588 | d->forceshow = TRUE; |
589 | argc -= 1; | 589 | argc -= 1; |
590 | } | 590 | } |
591 | } | 591 | } |
592 | 592 | ||
593 | /* overide stored arguments */ | 593 | /* overide stored arguments */ |
594 | setArgs( argc, argv ); | 594 | setArgs( argc, argv ); |
595 | 595 | ||
596 | #endif | 596 | #endif |
597 | 597 | ||
598 | // qwsSetDecoration( new QPEDecoration() ); | 598 | // qwsSetDecoration( new QPEDecoration() ); |
599 | 599 | ||
600 | #ifndef QT_NO_TRANSLATION | 600 | #ifndef QT_NO_TRANSLATION |
601 | 601 | ||
602 | QStringList langs = Global::languageList(); | 602 | QStringList langs = Global::languageList(); |
603 | for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) { | 603 | for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) { |
604 | QString lang = *it; | 604 | QString lang = *it; |
605 | 605 | ||
606 | QTranslator * trans; | 606 | installTranslation( lang + "/libopie.qm"); |
607 | QString tfn; | 607 | installTranslation( lang + "/libqpe.qm" ); |
608 | installTranslation( lang + "/" + d->appName + ".qm" ); | ||
608 | 609 | ||
609 | trans = new QTranslator( this ); | ||
610 | tfn = qpeDir() + "/i18n/" + lang + "/libqpe.qm"; | ||
611 | if ( trans->load( tfn ) ) | ||
612 | installTranslator( trans ); | ||
613 | else | ||
614 | delete trans; | ||
615 | |||
616 | trans = new QTranslator( this ); | ||
617 | tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm"; | ||
618 | if ( trans->load( tfn ) ) | ||
619 | installTranslator( trans ); | ||
620 | else | ||
621 | delete trans; | ||
622 | 610 | ||
623 | //###language/font hack; should look it up somewhere | 611 | //###language/font hack; should look it up somewhere |
624 | #ifdef QWS | 612 | #ifdef QWS |
625 | 613 | ||
626 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { | 614 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { |
627 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); | 615 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); |
628 | setFont( fn ); | 616 | setFont( fn ); |
629 | } | 617 | } |
630 | #endif | 618 | #endif |
631 | 619 | ||
632 | } | 620 | } |
633 | #endif | 621 | #endif |
634 | 622 | ||
635 | applyStyle(); | 623 | applyStyle(); |
636 | 624 | ||
637 | if ( type() == GuiServer ) { | 625 | if ( type() == GuiServer ) { |
638 | setVolume(); | 626 | setVolume(); |
639 | } | 627 | } |
640 | 628 | ||
641 | installEventFilter( this ); | 629 | installEventFilter( this ); |
642 | 630 | ||
643 | QPEMenuToolFocusManager::initialize(); | 631 | QPEMenuToolFocusManager::initialize(); |
644 | 632 | ||
645 | #ifdef QT_NO_QWS_CURSOR | 633 | #ifdef QT_NO_QWS_CURSOR |
646 | // if we have no cursor, probably don't want tooltips | 634 | // if we have no cursor, probably don't want tooltips |
647 | QToolTip::setEnabled( FALSE ); | 635 | QToolTip::setEnabled( FALSE ); |
648 | #endif | 636 | #endif |
649 | } | 637 | } |
650 | 638 | ||
651 | static QPtrDict<void>* inputMethodDict = 0; | 639 | static QPtrDict<void>* inputMethodDict = 0; |
652 | static void createInputMethodDict() | 640 | static void createInputMethodDict() |
653 | { | 641 | { |
@@ -1698,64 +1686,76 @@ int QPEApplication::exec() | |||
1698 | { | 1686 | { |
1699 | QCopEnvelope e( "QPE/System", "closing(QString)" ); | 1687 | QCopEnvelope e( "QPE/System", "closing(QString)" ); |
1700 | e << d->appName; | 1688 | e << d->appName; |
1701 | } | 1689 | } |
1702 | #endif | 1690 | #endif |
1703 | processEvents(); | 1691 | processEvents(); |
1704 | return 0; | 1692 | return 0; |
1705 | } | 1693 | } |
1706 | 1694 | ||
1707 | /*! | 1695 | /*! |
1708 | \internal | 1696 | \internal |
1709 | External request for application to quit. Quits if possible without | 1697 | External request for application to quit. Quits if possible without |
1710 | loosing state. | 1698 | loosing state. |
1711 | */ | 1699 | */ |
1712 | void QPEApplication::tryQuit() | 1700 | void QPEApplication::tryQuit() |
1713 | { | 1701 | { |
1714 | if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) | 1702 | if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) |
1715 | return ; // Inside modal loop or konsole. Too hard to save state. | 1703 | return ; // Inside modal loop or konsole. Too hard to save state. |
1716 | #ifndef QT_NO_COP | 1704 | #ifndef QT_NO_COP |
1717 | 1705 | ||
1718 | { | 1706 | { |
1719 | QCopEnvelope e( "QPE/System", "closing(QString)" ); | 1707 | QCopEnvelope e( "QPE/System", "closing(QString)" ); |
1720 | e << d->appName; | 1708 | e << d->appName; |
1721 | } | 1709 | } |
1722 | #endif | 1710 | #endif |
1723 | processEvents(); | 1711 | processEvents(); |
1724 | 1712 | ||
1725 | quit(); | 1713 | quit(); |
1726 | } | 1714 | } |
1727 | 1715 | ||
1728 | /*! | 1716 | /*! |
1729 | \internal | 1717 | \internal |
1718 | */ | ||
1719 | void QPEApplication::installTranslation( const QString& baseName ) { | ||
1720 | QTranslator* trans = new QTranslator(this); | ||
1721 | QString tfn = qpeDir() + "/i18n/"+baseName; | ||
1722 | if ( trans->load( tfn ) ) | ||
1723 | installTranslator( trans ); | ||
1724 | else | ||
1725 | delete trans; | ||
1726 | } | ||
1727 | |||
1728 | /*! | ||
1729 | \internal | ||
1730 | User initiated quit. Makes the window 'Go Away'. If preloaded this means | 1730 | User initiated quit. Makes the window 'Go Away'. If preloaded this means |
1731 | hiding the window. If not it means quitting the application. | 1731 | hiding the window. If not it means quitting the application. |
1732 | As this is user initiated we don't need to check state. | 1732 | As this is user initiated we don't need to check state. |
1733 | */ | 1733 | */ |
1734 | void QPEApplication::hideOrQuit() | 1734 | void QPEApplication::hideOrQuit() |
1735 | { | 1735 | { |
1736 | processEvents(); | 1736 | processEvents(); |
1737 | 1737 | ||
1738 | // If we are a preloaded application we don't actually quit, so emit | 1738 | // If we are a preloaded application we don't actually quit, so emit |
1739 | // a System message indicating we're quasi-closing. | 1739 | // a System message indicating we're quasi-closing. |
1740 | if ( d->preloaded && d->qpe_main_widget ) | 1740 | if ( d->preloaded && d->qpe_main_widget ) |
1741 | #ifndef QT_NO_COP | 1741 | #ifndef QT_NO_COP |
1742 | 1742 | ||
1743 | { | 1743 | { |
1744 | QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); | 1744 | QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); |
1745 | e << d->appName; | 1745 | e << d->appName; |
1746 | d->qpe_main_widget->hide(); | 1746 | d->qpe_main_widget->hide(); |
1747 | } | 1747 | } |
1748 | #endif | 1748 | #endif |
1749 | else | 1749 | else |
1750 | quit(); | 1750 | quit(); |
1751 | } | 1751 | } |
1752 | 1752 | ||
1753 | 1753 | ||
1754 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) | 1754 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) |
1755 | 1755 | ||
1756 | // The libraries with the skiff package (and possibly others) have | 1756 | // The libraries with the skiff package (and possibly others) have |
1757 | // completely useless implementations of builtin new and delete that | 1757 | // completely useless implementations of builtin new and delete that |
1758 | // use about 50% of your CPU. Here we revert to the simple libc | 1758 | // use about 50% of your CPU. Here we revert to the simple libc |
1759 | // functions. | 1759 | // functions. |
1760 | 1760 | ||
1761 | void* operator new[]( size_t size ) | 1761 | void* operator new[]( size_t size ) |
diff --git a/library/qpeapplication.h b/library/qpeapplication.h index 0bad8b7..e35c008 100644 --- a/library/qpeapplication.h +++ b/library/qpeapplication.h | |||
@@ -93,64 +93,67 @@ public: | |||
93 | signals: | 93 | signals: |
94 | void clientMoused(); | 94 | void clientMoused(); |
95 | void timeChanged(); | 95 | void timeChanged(); |
96 | void clockChanged( bool pm ); | 96 | void clockChanged( bool pm ); |
97 | void micChanged( bool muted ); | 97 | void micChanged( bool muted ); |
98 | void volumeChanged( bool muted ); | 98 | void volumeChanged( bool muted ); |
99 | void appMessage( const QCString& msg, const QByteArray& data); | 99 | void appMessage( const QCString& msg, const QByteArray& data); |
100 | void weekChanged( bool startOnMonday ); | 100 | void weekChanged( bool startOnMonday ); |
101 | void dateFormatChanged( DateFormat ); | 101 | void dateFormatChanged( DateFormat ); |
102 | void flush(); | 102 | void flush(); |
103 | void reload(); | 103 | void reload(); |
104 | 104 | ||
105 | private slots: | 105 | private slots: |
106 | void systemMessage( const QCString &msg, const QByteArray &data ); | 106 | void systemMessage( const QCString &msg, const QByteArray &data ); |
107 | void pidMessage( const QCString &msg, const QByteArray &data ); | 107 | void pidMessage( const QCString &msg, const QByteArray &data ); |
108 | void removeSenderFromStylusDict(); | 108 | void removeSenderFromStylusDict(); |
109 | void hideOrQuit(); | 109 | void hideOrQuit(); |
110 | 110 | ||
111 | protected: | 111 | protected: |
112 | bool qwsEventFilter( QWSEvent * ); | 112 | bool qwsEventFilter( QWSEvent * ); |
113 | void internalSetStyle( const QString &style ); | 113 | void internalSetStyle( const QString &style ); |
114 | void prepareForTermination(bool willrestart); | 114 | void prepareForTermination(bool willrestart); |
115 | virtual void restart(); | 115 | virtual void restart(); |
116 | virtual void shutdown(); | 116 | virtual void shutdown(); |
117 | bool eventFilter( QObject *, QEvent * ); | 117 | bool eventFilter( QObject *, QEvent * ); |
118 | void timerEvent( QTimerEvent * ); | 118 | void timerEvent( QTimerEvent * ); |
119 | bool raiseAppropriateWindow(); | 119 | bool raiseAppropriateWindow(); |
120 | virtual void tryQuit(); | 120 | virtual void tryQuit(); |
121 | 121 | ||
122 | virtual void polish ( QWidget * ); // this is actually implemented in qt_override.cpp (!) | 122 | virtual void polish ( QWidget * ); // this is actually implemented in qt_override.cpp (!) |
123 | 123 | ||
124 | private: | 124 | private: |
125 | #ifndef QT_NO_TRANSLATION | ||
126 | void installTranslation( const QString& baseName ); | ||
127 | #endif | ||
125 | void mapToDefaultAction( QWSKeyEvent *ke, int defKey ); | 128 | void mapToDefaultAction( QWSKeyEvent *ke, int defKey ); |
126 | 129 | ||
127 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 130 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
128 | QCopChannel *sysChannel; | 131 | QCopChannel *sysChannel; |
129 | QCopChannel *pidChannel; | 132 | QCopChannel *pidChannel; |
130 | #endif | 133 | #endif |
131 | QPEApplicationData *d; | 134 | QPEApplicationData *d; |
132 | 135 | ||
133 | bool reserved_sh; | 136 | bool reserved_sh; |
134 | 137 | ||
135 | 138 | ||
136 | 139 | ||
137 | }; | 140 | }; |
138 | 141 | ||
139 | inline void QPEApplication::showDialog( QDialog* d, bool nomax ) | 142 | inline void QPEApplication::showDialog( QDialog* d, bool nomax ) |
140 | { | 143 | { |
141 | QSize sh = d->sizeHint(); | 144 | QSize sh = d->sizeHint(); |
142 | int w = QMAX(sh.width(),d->width()); | 145 | int w = QMAX(sh.width(),d->width()); |
143 | int h = QMAX(sh.height(),d->height()); | 146 | int h = QMAX(sh.height(),d->height()); |
144 | if ( !nomax | 147 | if ( !nomax |
145 | && ( w > qApp->desktop()->width()*3/4 | 148 | && ( w > qApp->desktop()->width()*3/4 |
146 | || h > qApp->desktop()->height()*3/4 ) ) | 149 | || h > qApp->desktop()->height()*3/4 ) ) |
147 | { | 150 | { |
148 | d->showMaximized(); | 151 | d->showMaximized(); |
149 | } else { | 152 | } else { |
150 | d->resize(w,h); | 153 | d->resize(w,h); |
151 | d->show(); | 154 | d->show(); |
152 | } | 155 | } |
153 | } | 156 | } |
154 | 157 | ||
155 | inline int QPEApplication::execDialog( QDialog* d, bool nomax ) | 158 | inline int QPEApplication::execDialog( QDialog* d, bool nomax ) |
156 | { | 159 | { |