KDECore
kcatalogue.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <qfile.h>
00023
00024 #include <kdebug.h>
00025
00026 #include "kcatalogue.h"
00027 #include "kstandarddirs.h"
00028
00029 char *k_nl_find_msg(struct kde_loaded_l10nfile *domain_file,
00030 const char *msgid);
00031 void k_nl_unload_domain (struct loaded_domain *domain);
00032
00033 #ifndef KDE_USE_FINAL // with --enable-final, we're getting this from libintl.cpp
00034 struct kde_loaded_l10nfile
00035 {
00036 const char *filename;
00037 int decided;
00038
00039 const void *data;
00040
00041 kde_loaded_l10nfile() : filename(0), decided(0), data(0) {}
00042 };
00043 #endif
00044
00045 class KCataloguePrivate
00046 {
00047 public:
00048 QString name;
00049 QString language;
00050 int pluralType;
00051
00052 kde_loaded_l10nfile domain;
00053 };
00054
00055 KCatalogue::KCatalogue(const QString & name, const QString & language )
00056 : d( new KCataloguePrivate )
00057 {
00058 d->name = name;
00059 d->language = language;
00060
00061
00062
00063 d->pluralType = -1;
00064
00065 QString path = QString::fromLatin1("%1/LC_MESSAGES/%2.mo")
00066 .arg( d->language )
00067 .arg( d->name );
00068
00069 setFileName( locate( "locale", path ) );
00070
00071 }
00072
00073 KCatalogue::KCatalogue(const KCatalogue & rhs)
00074 : d( new KCataloguePrivate )
00075 {
00076 *this = rhs;
00077 }
00078
00079 KCatalogue & KCatalogue::operator=(const KCatalogue & rhs)
00080 {
00081 d->name = rhs.d->name;
00082 d->language = rhs.d->language;
00083 d->pluralType = rhs.d->pluralType;
00084 setFileName( rhs.fileName() );
00085
00086 return *this;
00087 }
00088
00089 KCatalogue::~KCatalogue()
00090 {
00091 doUnload();
00092
00093 delete d;
00094 }
00095
00096 QString KCatalogue::name() const
00097 {
00098 return d->name;
00099 }
00100
00101 QString KCatalogue::language() const
00102 {
00103 return d->language;
00104 }
00105
00106 void KCatalogue::setPluralType( int pluralType)
00107 {
00108 d->pluralType = pluralType;
00109 }
00110
00111 int KCatalogue::pluralType() const
00112 {
00113 return d->pluralType;
00114 }
00115
00116
00117 void KCatalogue::setFileName( const QString & fileName )
00118 {
00119
00120 if ( this->fileName() == fileName ) return;
00121
00122 doUnload();
00123
00124 QCString newFileName = QFile::encodeName( fileName );
00125
00126 if ( !fileName.isEmpty() )
00127 {
00128
00129 char *filename = new char[ newFileName.length() + 1 ];
00130 ::qstrcpy( filename, newFileName );
00131 d->domain.filename = filename;
00132 }
00133 }
00134
00135 QString KCatalogue::fileName() const
00136 {
00137 return QFile::decodeName( d->domain.filename );
00138 }
00139
00140 const char * KCatalogue::translate(const char * msgid) const
00141 {
00142 return ::k_nl_find_msg( &d->domain, msgid );
00143 }
00144
00145 void KCatalogue::doUnload()
00146 {
00147
00148 if ( d->domain.data )
00149 ::k_nl_unload_domain( (struct loaded_domain *)d->domain.data );
00150 d->domain.data = 0;
00151
00152
00153 delete [] const_cast<char *>(d->domain.filename);
00154 d->domain.filename = 0;
00155
00156 d->domain.decided = 0;
00157 }