kdecore Library API Documentation

kcatalogue.cpp

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., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include <config.h> 00021 00022 #include <qfile.h> 00023 00024 #include <kdebug.h> 00025 00026 #include "kcatalogue.h" 00027 00028 char *k_nl_find_msg(struct kde_loaded_l10nfile *domain_file, 00029 const char *msgid); 00030 void k_nl_unload_domain (struct loaded_domain *domain); 00031 00032 #ifndef KDE_USE_FINAL // with --enable-final, we're getting this from libintl.cpp 00033 struct kde_loaded_l10nfile 00034 { 00035 const char *filename; 00036 int decided; 00037 00038 const void *data; 00039 00040 kde_loaded_l10nfile() : filename(0), decided(0), data(0) {} 00041 }; 00042 #endif 00043 00044 class KCataloguePrivate 00045 { 00046 public: 00047 QString name; 00048 00049 kde_loaded_l10nfile domain; 00050 }; 00051 00052 KCatalogue::KCatalogue(const QString & name) 00053 : d( new KCataloguePrivate ) 00054 { 00055 d->name = name; 00056 } 00057 00058 KCatalogue::KCatalogue(const KCatalogue & rhs) 00059 : d( new KCataloguePrivate ) 00060 { 00061 *this = rhs; 00062 } 00063 00064 KCatalogue & KCatalogue::operator=(const KCatalogue & rhs) 00065 { 00066 d->name = rhs.d->name; 00067 setFileName( rhs.fileName() ); 00068 00069 return *this; 00070 } 00071 00072 KCatalogue::~KCatalogue() 00073 { 00074 doUnload(); 00075 00076 delete d; 00077 } 00078 00079 QString KCatalogue::name() const 00080 { 00081 return d->name; 00082 } 00083 00084 void KCatalogue::setFileName( const QString & fileName ) 00085 { 00086 // nothing to do if the file name is already the same 00087 if ( this->fileName() == fileName ) return; 00088 00089 doUnload(); 00090 00091 QCString newFileName = QFile::encodeName( fileName ); 00092 00093 if ( !fileName.isEmpty() ) 00094 { 00095 // set file name 00096 char *filename = new char[ newFileName.length() + 1 ]; 00097 ::qstrcpy( filename, newFileName ); 00098 d->domain.filename = filename; 00099 } 00100 } 00101 00102 QString KCatalogue::fileName() const 00103 { 00104 return QFile::decodeName( d->domain.filename ); 00105 } 00106 00107 const char * KCatalogue::translate(const char * msgid) const 00108 { 00109 return ::k_nl_find_msg( &d->domain, msgid ); 00110 } 00111 00112 void KCatalogue::doUnload() 00113 { 00114 // use gettext's unloader 00115 if ( d->domain.data ) 00116 ::k_nl_unload_domain( (struct loaded_domain *)d->domain.data ); 00117 d->domain.data = 0; 00118 00119 // free name 00120 delete [] const_cast<char *>(d->domain.filename); 00121 d->domain.filename = 0; 00122 00123 d->domain.decided = 0; 00124 }
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 16 17:21:41 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003