• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
kcatalogue.cpp
1 /* This file is part of the KDE libraries
2  Copyright (c) 2001 Hans Petter Bieker <bieker@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <config.h>
21 
22 #include <tqfile.h>
23 
24 #include <kdebug.h>
25 
26 #include "kcatalogue.h"
27 #include "kstandarddirs.h"
28 
29 char *k_nl_find_msg(struct kde_loaded_l10nfile *domain_file,
30  const char *msgid);
31 void k_nl_unload_domain (struct loaded_domain *domain);
32 
33 #ifndef KDE_USE_FINAL // with --enable-final, we're getting this from libintl.cpp
34 struct kde_loaded_l10nfile
35 {
36  const char *filename;
37  int decided;
38 
39  const void *data;
40 
41  kde_loaded_l10nfile() : filename(0), decided(0), data(0) {}
42 };
43 #endif
44 
45 class KCataloguePrivate
46 {
47 public:
48  TQString name;
49  TQString language;
50  int pluralType;
51 
52  kde_loaded_l10nfile domain;
53 };
54 
55 KCatalogue::KCatalogue(const TQString & name, const TQString & language )
56  : d( new KCataloguePrivate )
57 {
58  d->name = name;
59  d->language = language;
60  // at the moment we do not know more. To find out the plural type we first have to look into
61  // tdelibs.mo for the language. And for this we already need a catalog object. So this data
62  // has to be set after we have the first catalog objects.
63  d->pluralType = -1;
64 
65  TQString path = TQString::fromLatin1("%1/LC_MESSAGES/%2.mo")
66  .arg( d->language )
67  .arg( d->name );
68 
69  TQString fileName = locate( "locale", path );
70  if (fileName.isEmpty())
71  fileName = locate( "locale-bundle", path );
72 
73  setFileName( fileName );
74 
75 }
76 
77 KCatalogue::KCatalogue(const KCatalogue & rhs)
78  : d( new KCataloguePrivate )
79 {
80  *this = rhs;
81 }
82 
83 KCatalogue & KCatalogue::operator=(const KCatalogue & rhs)
84 {
85  d->name = rhs.d->name;
86  d->language = rhs.d->language;
87  d->pluralType = rhs.d->pluralType;
88  setFileName( rhs.fileName() );
89 
90  return *this;
91 }
92 
93 KCatalogue::~KCatalogue()
94 {
95  doUnload();
96 
97  delete d;
98 }
99 
100 TQString KCatalogue::name() const
101 {
102  return d->name;
103 }
104 
105 TQString KCatalogue::language() const
106 {
107  return d->language;
108 }
109 
110 void KCatalogue::setPluralType( int pluralType)
111 {
112  d->pluralType = pluralType;
113 }
114 
115 int KCatalogue::pluralType() const
116 {
117  return d->pluralType;
118 }
119 
120 
121 void KCatalogue::setFileName( const TQString & fileName )
122 {
123  // nothing to do if the file name is already the same
124  if ( this->fileName() == fileName ) return;
125 
126  doUnload();
127 
128  TQCString newFileName = TQFile::encodeName( fileName );
129 
130  if ( !fileName.isEmpty() )
131  {
132  // set file name
133  char *filename = new char[ newFileName.length() + 1 ];
134  ::qstrcpy( filename, newFileName );
135  d->domain.filename = filename;
136  }
137 }
138 
139 TQString KCatalogue::fileName() const
140 {
141  return TQFile::decodeName( d->domain.filename );
142 }
143 
144 const char * KCatalogue::translate(const char * msgid) const
145 {
146  return ::k_nl_find_msg( &d->domain, msgid );
147 }
148 
149 void KCatalogue::doUnload()
150 {
151  // use gettext's unloader
152  if ( d->domain.data )
153  ::k_nl_unload_domain( (struct loaded_domain *)d->domain.data );
154  d->domain.data = 0;
155 
156  // free name
157  delete [] const_cast<char *>(d->domain.filename);
158  d->domain.filename = 0;
159 
160  d->domain.decided = 0;
161 }
KCatalogue::setPluralType
void setPluralType(int pluralType)
Sets the plural type for the catalog.
Definition: kcatalogue.cpp:110
KCatalogue::translate
const char * translate(const char *msgid) const
Retrieves a translation of the specified message id.
Definition: kcatalogue.cpp:144
KCatalogue::name
TQString name() const
Returns the name of the catalog.
Definition: kcatalogue.cpp:100
KCatalogue::pluralType
int pluralType() const
Returns the plural type for the catalog.
Definition: kcatalogue.cpp:115
KCatalogue
This class abstracts a gettext message catalog.
Definition: kcatalogue.h:37
KCatalogue::language
TQString language() const
Returns the language of the catalog.
Definition: kcatalogue.cpp:105
KStdAction::name
const char * name(StdAction id)
KCatalogue::KCatalogue
KCatalogue(const TQString &name=TQString::null, const TQString &language=TQString::null)
Constructor.
Definition: kcatalogue.cpp:55
KCatalogue::~KCatalogue
virtual ~KCatalogue()
Destructor.
Definition: kcatalogue.cpp:93
KCatalogue::operator=
KCatalogue & operator=(const KCatalogue &rhs)
Assignment operator.
Definition: kcatalogue.cpp:83

tdecore

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

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.