-rw-r--r-- | library/global.cpp | 55 | ||||
-rw-r--r-- | library/qpeapplication.cpp | 40 |
2 files changed, 60 insertions, 35 deletions
diff --git a/library/global.cpp b/library/global.cpp index fd7579a..dd15eb7 100644 --- a/library/global.cpp +++ b/library/global.cpp @@ -1,43 +1,44 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ +#define QTOPIA_INTERNAL_LANGLIST #include <qpe/qpedebug.h> #include <qpe/global.h> #include <qpe/qdawg.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/storage.h> #include <qpe/applnk.h> #if defined(Q_WS_QWS) && !defined(QT_NO_COP) #include "qpe/qcopenvelope_qws.h" #endif #include <qfile.h> #include <qlabel.h> #include <qtimer.h> #include <qmap.h> #include <qdict.h> #include <qdir.h> #include <qmessagebox.h> #include <qregexp.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/wait.h> #include <sys/types.h> @@ -149,54 +150,60 @@ static QString dictDir() \brief The Global class collects application-wide global functions. */ /*! \internal */ Global::Global() { } /*! Returns the unchangeable QDawg that contains general words for the current locale. \sa addedDawg() */ const QDawg& Global::fixedDawg() { if ( !fixed_dawg ) { if ( !docDirCreated ) createDocDir(); fixed_dawg = new QDawg; QString dawgfilename = dictDir() + "/dawg"; - QString lang = getenv( "LANG" ); - QString dawgfilename_lang = dawgfilename + "." + lang; - QString words_lang = dictDir() + "/words." + lang; - if ( QFile::exists(dawgfilename_lang) || - QFile::exists(words_lang) ) - dawgfilename = dawgfilename_lang; + QString words_lang; + QStringList langs = Global::languageList(); + for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { + QString lang = *it; + words_lang = dictDir() + "/words." + lang; + QString dawgfilename_lang = dawgfilename + "." + lang; + if ( QFile::exists(dawgfilename_lang) || + QFile::exists(words_lang) ) { + dawgfilename = dawgfilename_lang; + break; + } + } QFile dawgfile(dawgfilename); if ( !dawgfile.exists() ) { QString fn = dictDir() + "/words"; if ( QFile::exists(words_lang) ) fn = words_lang; QFile in(fn); if ( in.open(IO_ReadOnly) ) { fixed_dawg->createFromWords(&in); dawgfile.open(IO_WriteOnly); fixed_dawg->write(&dawgfile); dawgfile.close(); } } else { fixed_dawg->readFile(dawgfilename); } } return *fixed_dawg; } /*! Returns the changeable QDawg that contains general words for the current locale. @@ -618,27 +625,63 @@ QString Global::stringQuote(const QString& s) } /*! Finds all documents on the system's document directories which match the filter \a mimefilter, and appends the resulting DocLnk objects to \a folder. */ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) { QString homedocs = QString(getenv("HOME")) + "/Documents"; DocLnkSet d(homedocs,mimefilter); folder->appendFrom(d); StorageInfo storage; const QList<FileSystem> &fs = storage.fileSystems(); QListIterator<FileSystem> it ( fs ); for ( ; it.current(); ++it ) { if ( (*it)->isRemovable() ) { QString path = (*it)->path(); DocLnkSet ide( path, mimefilter ); folder->appendFrom(ide); } } } +QStringList Global::languageList() +{ + QString lang = getenv("LANG"); + QStringList langs; + langs.append(lang); + int i = lang.find("."); + if ( i > 0 ) + lang = lang.left( i ); + i = lang.find( "_" ); + if ( i > 0 ) + langs.append(lang.left(i)); + return langs; +} + +QStringList Global::helpPath() +{ + QStringList path; + QStringList langs = Global::languageList(); + for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { + QString lang = *it; + if ( !lang.isEmpty() ) + path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; + } + path += QPEApplication::qpeDir() + "/pics"; + path += QPEApplication::qpeDir() + "/help/en/html"; + path += QPEApplication::qpeDir() + "/docs"; + QString dir = QDir::current().canonicalPath(); + if ( dir == "/" ) + dir += "/docs"; + else { + path += dir + "/../pics"; + dir += "/../docs"; + path += dir; + } + return path; +} #include "global.moc" diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index 70ffec1..4dbfbd8 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp @@ -1,45 +1,46 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** ** $Id$ ** **********************************************************************/ +#define QTOPIA_INTERNAL_LANGLIST #include <stdlib.h> #include <unistd.h> #include <qfile.h> #ifdef Q_WS_QWS #ifndef QT_NO_COP #if QT_VERSION <= 231 #define private public #define sendLocally processEvent #include "qcopenvelope_qws.h" #undef private #else #include "qcopenvelope_qws.h" #endif #endif #include <qwindowsystem_qws.h> #endif #include <qtextstream.h> #include <qpalette.h> #include <qbuffer.h> #include <qptrdict.h> #include <qregexp.h> #include <qdir.h> #include <qlabel.h> #include <qdialog.h> @@ -116,64 +117,49 @@ public: bool forceshow; bool nomaximize; QWidget* qpe_main_widget; bool keep_running; QList<QCopRec> qcopq; void enqueueQCop(const QCString &ch, const QCString &msg, const QByteArray &data) { qcopq.append(new QCopRec(ch,msg,data)); } void sendQCopQ() { QCopRec* r; for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it) QCopChannel::sendLocally(r->channel,r->message,r->data); qcopq.clear(); } }; class ResourceMimeFactory : public QMimeSourceFactory { public: ResourceMimeFactory() { - QStringList path; - QString lang = getenv("LANG"); - if ( !lang.isEmpty() ) - path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; - path += QPEApplication::qpeDir() + "/pics"; - path += QPEApplication::qpeDir() + "/help/en/html"; - path += QPEApplication::qpeDir() + "/docs"; - QString dir = QDir::current().canonicalPath(); - if ( dir == "/" ) - dir += "/docs"; - else { - path += dir + "/../pics"; - dir += "/../docs"; - path += dir; - } - setFilePath( path ); + setFilePath( Global::helpPath() ); setExtensionType("html","text/html;charset=UTF-8"); } const QMimeSource* data(const QString& abs_name) const { const QMimeSource* r = QMimeSourceFactory::data(abs_name); if ( !r ) { int sl = abs_name.length(); do { sl = abs_name.findRev('/',sl-1); QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name; int dot = name.findRev('.'); if ( dot >= 0 ) name = name.left(dot); QImage img = Resource::loadImage(name); if ( !img.isNull() ) r = new QImageDrag(img); } while (!r && sl>0); } return r; } }; static int muted=0; @@ -516,74 +502,70 @@ QPEApplication::QPEApplication( int& argc, char **argv, Type t ) for (int a=0; a<argc; a++) { if ( qstrcmp(argv[a],"-preload")==0 ) { argv[a] = argv[a+1]; a++; d->preloaded = TRUE; argc-=1; } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { argv[a] = argv[a+1]; a++; d->preloaded = TRUE; d->forceshow = TRUE; argc-=1; } } /* overide stored arguments */ setArgs(argc, argv); #endif qwsSetDecoration( new QPEDecoration() ); #ifndef QT_NO_TRANSLATION - char *l = getenv( "LANG" ); - QString lang; - if ( l ) { - lang = l; + QStringList langs = Global::languageList(); + for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { + QString lang = *it; - /* - Config config("qpe"); - config.setGroup( "Appearance" ); - lang = config.readEntry( "Language", lang ); - */ + QTranslator * trans; + QString tfn; - QTranslator * trans = new QTranslator(this); - QString tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm"; + trans = new QTranslator(this); + tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm"; if ( trans->load( tfn )) installTranslator( trans ); else delete trans; trans = new QTranslator(this); - tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm"; + tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm"; if ( trans->load( tfn )) installTranslator( trans ); else delete trans; - //###language/font hack; should look it up somewhere + //###language/font hack; should look it up somewhere if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { QFont fn = FontManager::unicodeFont( FontManager::Proportional ); setFont( fn ); } } #endif applyStyle(); if ( type() == GuiServer ) { setScreenSaverInterval(-1); setVolume(); QWSServer::setScreenSaver(new QPEScreenSaver); } installEventFilter( this ); QPEMenuToolFocusManager::initialize(); #ifdef QT_NO_QWS_CURSOR // if we have no cursor, probably don't want tooltips QToolTip::setEnabled( FALSE ); #endif } |