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

lokalize

  • sources
  • kde-4.14
  • kdesdk
  • lokalize
  • src
  • catalog
pos.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2007 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  In addition, as a special exception, the copyright holders give
21  permission to link the code of this program with any edition of
22  the Qt library by Trolltech AS, Norway (or with modified versions
23  of Qt that use the same license as Qt), and distribute linked
24  combinations including the two. You must obey the GNU General
25  Public License in all respects for all of the code used other than
26  Qt. If you modify this file, you may extend this exception to
27  your version of the file, but you are not obligated to do so. If
28  you do not wish to do so, delete this exception statement from
29  your version.
30 
31 **************************************************************************** */
32 
33 #include "pos.h"
34 #include "catalog.h"
35 
36 #include <QDBusArgument>
37 
38 bool switchPrev(Catalog*& catalog,DocPosition& pos,int parts)
39 {
40  bool switchEntry=false;
41  bool switchCommentIndex=false;
42  if (pos.part==DocPosition::Comment)
43  switchCommentIndex=true;
44  else if (pos.part==DocPosition::Target)
45  {
46  if (parts&DocPosition::Source)
47  pos.part=DocPosition::Source;
48  switchEntry=!(parts&DocPosition::Source);
49  }
50  else if (pos.part==DocPosition::Source)
51  switchEntry=true;
52 
53  bool skipCommentThisTime=false;
54  if (switchCommentIndex)
55  {
56  if (pos.form)
57  pos.form--;
58  switchEntry=pos.form; //pos.form is zero again
59  skipCommentThisTime=pos.form;
60  }
61 
62  if (!switchEntry)
63  return true;
64 
65  if (KDE_ISUNLIKELY( pos.form>0
66  && catalog->isPlural(pos.entry)))
67  pos.form--;
68  else if (KDE_ISUNLIKELY( pos.entry==0 ))
69  return false;
70  else
71  {
72  pos.entry--;
73  pos.form=catalog->isPlural(pos.entry)*(catalog->numberOfPluralForms()-1);
74  }
75  pos.offset=0;
76 
77  if (parts&DocPosition::Comment && !skipCommentThisTime && pos.form==0 && catalog->notes(pos).size())
78  {
79  pos.part=DocPosition::Comment;
80  pos.form=catalog->notes(pos).size()-1;
81  }
82  else
83  pos.part=DocPosition::Target;
84 
85  return true;
86 }
87 
88 bool switchNext(Catalog*& catalog,DocPosition& pos,int parts)
89 {
90  bool switchEntry=false;
91  bool switchCommentIndex=false;
92  if (pos.part==DocPosition::Source)
93  pos.part=DocPosition::Target;
94  else if (pos.part==DocPosition::Target)
95  {
96  if (parts&DocPosition::Comment && pos.form==0 && catalog->notes(pos).size())
97  pos.part=DocPosition::Comment;
98  else
99  switchEntry=true;
100  }
101  else if (pos.part==DocPosition::Comment)
102  switchCommentIndex=true;
103 
104  if (switchCommentIndex)
105  {
106  pos.form++;
107  if (catalog->notes(pos).size()==pos.form)
108  {
109  pos.form=0;
110  switchEntry=true;
111  }
112  }
113 
114  if (!switchEntry)
115  return true;
116 
117 
118  if (KDE_ISUNLIKELY( pos.entry!=-1
119  && pos.form+1 < catalog->numberOfPluralForms()
120  && catalog->isPlural(pos.entry)))
121  pos.form++;
122  else if (KDE_ISUNLIKELY( pos.entry==catalog->numberOfEntries()-1 ))
123  return false;
124  else
125  {
126  pos.entry++;
127  pos.form=0;
128  }
129  pos.offset=0;
130 
131  pos.part=(parts&DocPosition::Source)?DocPosition::Source:DocPosition::Target;
132 
133  return true;
134 }
135 
136 const QDBusArgument &operator>>(const QDBusArgument &argument, DocPosition& pos)
137 {
138  int entry;
139  int form;
140  uint offset;
141 
142  argument.beginStructure();
143  argument >> entry >> form >> offset;
144  argument.endStructure();
145 
146  pos.entry=entry;
147  pos.form=form;
148  pos.offset=offset;
149 
150  return argument;
151 }
152 
153 QDBusArgument &operator<<(QDBusArgument &argument, const DocPosition &pos)
154 {
155  int entry=pos.entry;
156  int form=pos.form;
157  uint offset=pos.offset;
158 
159  argument.beginStructure();
160  argument << entry << form << offset;
161  argument.endStructure();
162 
163  return argument;
164 }
165 
DocPosition::part
Part part
Definition: pos.h:49
operator<<
QDBusArgument & operator<<(QDBusArgument &argument, const DocPosition &pos)
Definition: pos.cpp:153
Catalog::numberOfPluralForms
int numberOfPluralForms() const
Definition: catalog.h:150
operator>>
const QDBusArgument & operator>>(const QDBusArgument &argument, DocPosition &pos)
Definition: pos.cpp:136
DocPosition::Target
Definition: pos.h:44
switchNext
bool switchNext(Catalog *&catalog, DocPosition &pos, int parts)
Definition: pos.cpp:88
QDBusArgument::beginStructure
void beginStructure()
pos.h
DocPosition::offset
uint offset
Definition: pos.h:51
DocPosition::entry
int entry
Definition: pos.h:48
DocPosition
This struct represents a position in a catalog.
Definition: pos.h:38
catalog.h
DocPosition::form
char form
Definition: pos.h:50
Catalog::isPlural
bool isPlural(uint index) const
Definition: catalog.cpp:405
QDBusArgument
DocPosition::Source
Definition: pos.h:43
Catalog::numberOfEntries
int numberOfEntries() const
Definition: catalog.cpp:171
Catalog
This class represents a catalog It uses CatalogStorage interface to work with catalogs in different f...
Definition: catalog.h:74
Catalog::notes
QVector< Note > notes(const DocPosition &pos) const
Definition: catalog.cpp:228
QDBusArgument::endStructure
void endStructure()
switchPrev
bool switchPrev(Catalog *&catalog, DocPosition &pos, int parts)
Definition: pos.cpp:38
DocPosition::Comment
Definition: pos.h:45
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:07 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
  • 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