• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KDECore

kcatalogue.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (c) 2001 Hans Petter Bieker <bieker@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
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   // at the moment we do not know more. To find out the plural type we first have to look into
00061   // kdelibs.mo for the language. And for this we already need a catalog object. So this data
00062   // has to be set after we have the first catalog objects.
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   // nothing to do if the file name is already the same
00120   if ( this->fileName() == fileName ) return;
00121 
00122   doUnload();
00123 
00124   QCString newFileName = QFile::encodeName( fileName );
00125 
00126   if ( !fileName.isEmpty() )
00127     {
00128       // set file name
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   // use gettext's unloader
00148   if ( d->domain.data )
00149     ::k_nl_unload_domain( (struct loaded_domain *)d->domain.data );
00150   d->domain.data = 0;
00151 
00152   // free name
00153   delete [] const_cast<char *>(d->domain.filename);
00154   d->domain.filename = 0;
00155 
00156   d->domain.decided = 0;
00157 }

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal