00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "config.h"
00022
00023 #include <QPaintDevice>
00024 #include <QFont>
00025 #include <QFontInfo>
00026 #ifdef Q_WS_X11
00027 #include <QX11Info>
00028 #endif
00029
00030 #include <KoGlobal.h>
00031 #include <kdebug.h>
00032 #include <kglobalsettings.h>
00033 #include <kglobal.h>
00034 #include <klocale.h>
00035 #include <ksimpleconfig.h>
00036 #include <kstandarddirs.h>
00037 #include <kstaticdeleter.h>
00038 #include <kimageio.h>
00039 #include <kiconloader.h>
00040 #include <kstandarddirs.h>
00041
00042
00043 KoGlobal* KoGlobal::s_global = 0L;
00044 static KStaticDeleter<KoGlobal> sdg;
00045
00046 KoGlobal* KoGlobal::self()
00047 {
00048 if ( !s_global )
00049 sdg.setObject( s_global, new KoGlobal );
00050 return s_global;
00051 }
00052
00053 KoGlobal::KoGlobal()
00054 : m_pointSize( -1 ), m_kofficeConfig( 0L )
00055 {
00056
00057 KGlobal::locale()->insertCatalog("koffice");
00058
00059
00060 KGlobal::dirs()->addPrefix(PREFIX);
00061
00062
00063 KGlobal::iconLoader()->addAppDir("koffice");
00064
00065
00066
00067
00068 #ifdef Q_WS_X11
00069 m_dpiX = QX11Info::appDpiX();
00070 m_dpiY = QX11Info::appDpiY();
00071 #else
00072 m_dpiX = 75;
00073 m_dpiY = 75;
00074 #endif
00075 }
00076
00077 KoGlobal::~KoGlobal()
00078 {
00079 delete m_kofficeConfig;
00080 }
00081
00082 QFont KoGlobal::_defaultFont()
00083 {
00084 QFont font = KGlobalSettings::generalFont();
00085
00086 if ( font.pointSize() == -1 )
00087 {
00088
00089 if ( m_pointSize == -1 )
00090 m_pointSize = QFontInfo(font).pointSize();
00091 Q_ASSERT( m_pointSize != -1 );
00092 font.setPointSize( m_pointSize );
00093 }
00094
00095
00096 return font;
00097 }
00098
00099 QStringList KoGlobal::_listOfLanguageTags()
00100 {
00101 if ( m_langMap.isEmpty() )
00102 createListOfLanguages();
00103 return m_langMap.values();
00104 }
00105
00106 QStringList KoGlobal::_listOfLanguages()
00107 {
00108 if ( m_langMap.empty() )
00109 createListOfLanguages();
00110 return m_langMap.keys();
00111 }
00112
00113 void KoGlobal::createListOfLanguages()
00114 {
00115 KConfig config( "all_languages", true, false, "locale" );
00116
00117
00118 QMap<QString, bool> seenLanguages;
00119 const QStringList langlist = config.groupList();
00120 for ( QStringList::ConstIterator itall = langlist.begin();
00121 itall != langlist.end(); ++itall )
00122 {
00123 const QString tag = *itall;
00124 config.setGroup( tag );
00125 const QString name = config.readEntry("Name", tag);
00126
00127
00128
00129
00130 m_langMap.insert( name, tag );
00131
00132 seenLanguages.insert( tag, true );
00133 }
00134
00135
00136
00137
00138
00139 const QStringList translationList = KGlobal::dirs()->findAllResources("locale",
00140 QString::fromLatin1("*/entry.desktop"));
00141 for ( QStringList::ConstIterator it = translationList.begin();
00142 it != translationList.end(); ++it )
00143 {
00144
00145 QString tag = *it;
00146 int index = tag.lastIndexOf('/');
00147 tag = tag.left(index);
00148 index = tag.lastIndexOf('/');
00149 tag = tag.mid(index+1);
00150
00151 if ( seenLanguages.find( tag ) == seenLanguages.end() ) {
00152 KSimpleConfig entry(*it);
00153 entry.setGroup("KCM Locale");
00154
00155 const QString name = entry.readEntry("Name", tag);
00156
00157 m_langMap.insert( name, tag );
00158
00159
00160
00161 }
00162
00163 }
00164
00165
00166
00167
00168 }
00169
00170 QString KoGlobal::tagOfLanguage( const QString & _lang)
00171 {
00172 const LanguageMap& map = self()->m_langMap;
00173 QMap<QString,QString>::ConstIterator it = map.find( _lang );
00174 if ( it != map.end() )
00175 return *it;
00176 return QString();
00177 }
00178
00179 QString KoGlobal::languageFromTag( const QString &langTag )
00180 {
00181 const LanguageMap& map = self()->m_langMap;
00182 QMap<QString,QString>::ConstIterator it = map.begin();
00183 const QMap<QString,QString>::ConstIterator end = map.end();
00184 for ( ; it != end; ++it )
00185 if ( it.value() == langTag )
00186 return it.key();
00187
00188
00189 return langTag;
00190 }
00191
00192 KConfig* KoGlobal::_kofficeConfig()
00193 {
00194 if ( !m_kofficeConfig ) {
00195 m_kofficeConfig = new KConfig( "kofficerc" );
00196 }
00197 return m_kofficeConfig;
00198 }
00199
00200 void KoGlobal::setDPI( int x, int y )
00201 {
00202
00203 KoGlobal* s = self();
00204 s->m_dpiX = x;
00205 s->m_dpiY = y;
00206 }