• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

lokalize

  • sources
  • kde-4.12
  • kdesdk
  • lokalize
  • src
  • catalog
  • gettext
importplugin.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of KAider
3  This file is based on the one from KBabel
4 
5  Copyright (C) 2002-2003 by Stanislav Visnovsky <visnovsky@kde.org>
6  2007 by Nick Shaforostoff <shafff@ukr.net>
7 
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 
23  In addition, as a special exception, the copyright holders give
24  permission to link the code of this program with any edition of
25  the Qt library by Trolltech AS, Norway (or with modified versions
26  of Qt that use the same license as Qt), and distribute linked
27  combinations including the two. You must obey the GNU General
28  Public License in all respects for all of the code used other than
29  Qt. If you modify this file, you may extend this exception to
30  your version of the file, but you are not obligated to do so. If
31  you do not wish to do so, delete this exception statement from
32  your version.
33 
34 **************************************************************************** */
35 
36 #include "catalogfileplugin.h"
37 #include "importplugin_private.h"
38 
39 #include "gettextstorage.h"
40 
41 #include <QStringList>
42 #include <QLinkedList>
43 
44 #include <kdebug.h>
45 #include <kmessagebox.h>
46 //#include <kservicetypetrader.h>
47 
48 namespace GettextCatalog
49 {
50 
51 CatalogImportPlugin::CatalogImportPlugin()
52  : _maxLineLength(0)
53  , d(new CatalogImportPluginPrivate)
54 {
55 }
56 
57 CatalogImportPlugin::~CatalogImportPlugin()
58 {
59  delete d;
60 }
61 
62 void CatalogImportPlugin::appendCatalogItem( const CatalogItem& item, const bool obsolete )
63 {
64  if (item.msgid().isEmpty())
65  return;
66  if( obsolete )
67  d->_obsoleteEntries.append(item);
68  else
69  d->_entries.append(item);
70 }
71 
72 void CatalogImportPlugin::setCatalogExtraData( const QStringList& data )
73 {
74  d->_catalogExtraData=data;
75  d->_updateCatalogExtraData=true;
76 }
77 
78 void CatalogImportPlugin::setGeneratedFromDocbook( const bool generated )
79 {
80  d->_generatedFromDocbook = generated;
81  d->_updateGeneratedFromDocbook = true;
82 }
83 
84 void CatalogImportPlugin::setErrorIndex(const QList<int>& errors)
85 {
86  d->_errorList = errors;
87  d->_updateErrorList = true;
88 }
89 
90 void CatalogImportPlugin::setHeader( const CatalogItem& item )
91 {
92  d->_header=item;
93  d->_updateHeader=true;
94 }
95 
96 void CatalogImportPlugin::setCodec( QTextCodec* codec )
97 {
98  d->_codec = codec;
99 }
100 
101 ConversionStatus CatalogImportPlugin::open(QIODevice* device, GettextStorage* catalog, int* line)
102 {
103  d->_catalog=catalog;
104  startTransaction();
105 
106  ConversionStatus result = load(device);
107 
108  if( result == OK || result == RECOVERED_PARSE_ERROR || result == RECOVERED_HEADER_ERROR )
109  commitTransaction();
110  if (line)
111  (*line)=_errorLine;
112  return result;
113 }
114 
115 void CatalogImportPlugin::startTransaction()
116 {
117  d->_updateCodec = false;
118  d->_updateCatalogExtraData = false;
119  d->_updateGeneratedFromDocbook = false;
120  d->_updateErrorList = false;
121  d->_updateHeader = false;
122  d->_entries.clear();
123 }
124 
125 void CatalogImportPlugin::commitTransaction()
126 {
127  GettextStorage* catalog=d->_catalog;
128 
129  //catalog->clear();
130 
131  // fill in the entries
132  QVector<CatalogItem>& entries=catalog->m_entries;
133  entries.reserve( d->_entries.count() ); //d->_catalog->setEntries( e );
134  for( QLinkedList<CatalogItem>::const_iterator it = d->_entries.begin(); it != d->_entries.end(); ++it/*,++i*/ )
135  entries.append( *it );
136 
137  // The codec is specified in the header, so it must be updated before the header is.
138  catalog->setCodec(d->_codec);
139 
140  catalog->m_catalogExtraData=d->_catalogExtraData;
141  catalog->m_generatedFromDocbook=d->_generatedFromDocbook;
142  catalog->setHeader(d->_header);
143  //if( d->_updateErrorList ) d->_catalog->setErrorIndex(d->_errorList);
144 
145  catalog->m_maxLineLength=_maxLineLength;
146  catalog->m_trailingNewLines=_trailingNewLines;
147 }
148 
149 }
GettextCatalog::CatalogImportPluginPrivate::_updateCatalogExtraData
bool _updateCatalogExtraData
Definition: importplugin_private.h:55
GettextCatalog::CatalogImportPlugin::setCatalogExtraData
void setCatalogExtraData(const QStringList &data)
set extra data for the catalog, which can't be stored in CatalogItem.
Definition: importplugin.cpp:72
GettextCatalog::CatalogImportPluginPrivate::_header
CatalogItem _header
Definition: importplugin_private.h:60
GettextCatalog::CatalogItem::msgid
const QString & msgid(const int form=0) const
Definition: catalogitem.cpp:73
GettextCatalog::CatalogImportPluginPrivate::_catalog
GettextStorage * _catalog
Definition: importplugin_private.h:50
GettextCatalog::CatalogItem
This class represents an entry in a catalog.
Definition: catalogitem.h:55
GettextCatalog::CatalogImportPluginPrivate::_errorList
QList< int > _errorList
Definition: importplugin_private.h:62
GettextCatalog::CatalogImportPluginPrivate::_obsoleteEntries
QLinkedList< CatalogItem > _obsoleteEntries
Definition: importplugin_private.h:59
GettextCatalog::CatalogImportPlugin::~CatalogImportPlugin
virtual ~CatalogImportPlugin()
Definition: importplugin.cpp:57
GettextCatalog::RECOVERED_PARSE_ERROR
Definition: catalogfileplugin.h:59
GettextCatalog::CatalogImportPlugin::load
virtual ConversionStatus load(QIODevice *)=0
Reimplement this method to load the local file passed as an argument.
GettextCatalog::CatalogImportPlugin::CatalogImportPlugin
CatalogImportPlugin()
Definition: importplugin.cpp:51
GettextCatalog::CatalogImportPluginPrivate::_updateCodec
bool _updateCodec
Definition: importplugin_private.h:53
GettextCatalog::CatalogImportPlugin::commitTransaction
void commitTransaction()
commit the data in the current transaction.
Definition: importplugin.cpp:125
GettextCatalog::RECOVERED_HEADER_ERROR
Header error that could be recovered.
Definition: catalogfileplugin.h:63
GettextCatalog::CatalogImportPlugin::setErrorIndex
void setErrorIndex(const QList< int > &errors)
set the list of parse error indexes
Definition: importplugin.cpp:84
GettextCatalog::CatalogImportPlugin::appendCatalogItem
void appendCatalogItem(const CatalogItem &item, const bool obsolete=false)
Append a new catalog item, either as normal or as an obsolete one.
Definition: importplugin.cpp:62
GettextCatalog::ConversionStatus
ConversionStatus
Result of the conversion.
Definition: catalogfileplugin.h:53
GettextCatalog::CatalogImportPluginPrivate::_updateErrorList
bool _updateErrorList
Definition: importplugin_private.h:54
GettextCatalog::CatalogImportPlugin::setCodec
void setCodec(QTextCodec *codec)
Set the character encoding used in the catalog file.
Definition: importplugin.cpp:96
GettextCatalog::CatalogImportPluginPrivate::_generatedFromDocbook
bool _generatedFromDocbook
Definition: importplugin_private.h:57
GettextCatalog::CatalogImportPluginPrivate
Definition: importplugin_private.h:47
GettextCatalog::CatalogImportPlugin::_errorLine
int _errorLine
Definition: catalogfileplugin.h:142
GettextCatalog::CatalogImportPlugin::_maxLineLength
short _maxLineLength
Definition: catalogfileplugin.h:140
importplugin_private.h
GettextCatalog::CatalogImportPluginPrivate::_catalogExtraData
QStringList _catalogExtraData
Definition: importplugin_private.h:63
GettextCatalog::CatalogImportPluginPrivate::_codec
QTextCodec * _codec
Definition: importplugin_private.h:61
GettextCatalog::CatalogImportPluginPrivate::_updateGeneratedFromDocbook
bool _updateGeneratedFromDocbook
Definition: importplugin_private.h:52
GettextCatalog::CatalogImportPlugin::setGeneratedFromDocbook
void setGeneratedFromDocbook(const bool fromDocbook)
set flag that the file is generated from DocBook
Definition: importplugin.cpp:78
GettextCatalog::CatalogImportPluginPrivate::_entries
QLinkedList< CatalogItem > _entries
Definition: importplugin_private.h:58
GettextCatalog::CatalogImportPlugin::setHeader
void setHeader(const CatalogItem &header)
set the header catalog item
Definition: importplugin.cpp:90
gettextstorage.h
GettextCatalog::CatalogImportPluginPrivate::_updateHeader
bool _updateHeader
Definition: importplugin_private.h:51
GettextCatalog::CatalogImportPlugin::startTransaction
void startTransaction()
start a new transaction.
Definition: importplugin.cpp:115
catalogfileplugin.h
GettextCatalog::GettextStorage
Implementation of storage for Gettext PO.
Definition: gettextstorage.h:39
GettextCatalog::CatalogImportPlugin::open
ConversionStatus open(QIODevice *, GettextStorage *catalog, int *errorLine)
Load the file and fill the corresponding catalog.
Definition: importplugin.cpp:101
GettextCatalog::CatalogImportPlugin::_trailingNewLines
short _trailingNewLines
Definition: catalogfileplugin.h:141
GettextCatalog::OK
Definition: catalogfileplugin.h:54
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:45 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal