• 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
  • mergemode
mergecatalog.h
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2007-2009 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License or (at your option) version 3 or any later version
10  accepted by the membership of KDE e.V. (or its successor approved
11  by the membership of KDE e.V.), which shall act as a proxy
12  defined in Section 14 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
21 
22 **************************************************************************** */
23 
24 #ifndef MERGECATALOG_H
25 #define MERGECATALOG_H
26 
27 #include "catalog.h"
28 
29 #include <QVector>
30 #include <QLinkedList>
31 
32 struct MatchItem
33 {
34  short mergeEntry:16;
35  short baseEntry:16;
36  short score:16;
37  short translationIsDifferent:16;
38 
39  MatchItem()
40  : mergeEntry(0)
41  , baseEntry(0)
42  , score(0)
43  , translationIsDifferent(false)
44  {}
45 
46  MatchItem(short m, short b, bool d)
47  : mergeEntry(m)
48  , baseEntry(b)
49  , score(0)
50  , translationIsDifferent(d)
51  {}
52 
53  bool operator<(const MatchItem& other) const
54  {
55  return score<other.score;
56  }
57 
58 };
59 
60 
71 class MergeCatalog: public Catalog
72 {
73  Q_OBJECT
74 public:
75  MergeCatalog(QObject* parent, Catalog* baseCatalog, bool saveChanges=true);
76  ~MergeCatalog(){};
77 
78  int loadFromUrl(const KUrl& url);
79 
80  int firstChangedIndex() const {return m_mergeDiffIndex.isEmpty()?numberOfEntries():m_mergeDiffIndex.first();}
81  int lastChangedIndex() const {return m_mergeDiffIndex.isEmpty()?-1:m_mergeDiffIndex.last();}
82  int nextChangedIndex(uint index) const {return findNextInList(m_mergeDiffIndex,index);}
83  int prevChangedIndex(uint index) const {return findPrevInList(m_mergeDiffIndex,index);}
84  int isDifferent(uint index) const {return m_mergeDiffIndex.contains(index);}
85  QLinkedList<int> differentEntries()const {return m_mergeDiffIndex;}
86 
87  //override to use map
88  QString msgstr(const DocPosition&) const;
89  bool isApproved(uint index) const;
90  bool isPlural(uint index) const;
91  TargetState state(const DocPosition& pos) const;
92 
93  int unmatchedCount()const{return m_unmatchedCount;}
94 
96  bool isPresent(const short int& entry) const;
97  bool isModified(DocPos)const;
98 
100  void copyToBaseCatalog(DocPosition& pos);
101  enum CopyToBaseOptions {EmptyOnly=1, HigherOnly=2};
102  void copyToBaseCatalog(int options=0);
103 
104  inline void removeFromDiffIndex(uint index){m_mergeDiffIndex.removeAll(index);}
105  enum CopyFromBaseOptions {EvenIfNotInDiffIndex=1};
106  void copyFromBaseCatalog(const DocPosition&, int options);
107  void copyFromBaseCatalog(const DocPosition& pos){copyFromBaseCatalog(pos, EvenIfNotInDiffIndex);}
108 public slots:
109  void copyFromBaseCatalogIfInDiffIndex(const DocPosition& pos){copyFromBaseCatalog(pos, 0);}
110 
111  bool save(); //reimplement to do save only when changes were actually done to this catalog
112 
113 private:
114  MatchItem calcMatchItem(const DocPosition& basePos,const DocPosition& mergePos);
115  KAutoSaveFile* checkAutoSave(const KUrl&){return 0;}//rely on basecatalog restore
116 
117 
118 private:
119  QVector<int> m_map; //maps entries: m_baseCatalog -> this
120  Catalog* m_baseCatalog;
121  QLinkedList<int> m_mergeDiffIndex;//points to baseCatalog entries
122  QMap<DocPos, uint> m_originalHashes; //for modified units only
123  int m_unmatchedCount;
124  bool m_modified; //need own var here cause we don't use qundostack system for merging
125 };
126 
127 #endif
MergeCatalog::state
TargetState state(const DocPosition &pos) const
Definition: mergecatalog.cpp:89
MergeCatalog
Merge source container.
Definition: mergecatalog.h:71
Catalog::url
const KUrl & url() const
Definition: catalog.h:189
MergeCatalog::msgstr
QString msgstr(const DocPosition &) const
Definition: mergecatalog.cpp:76
MergeCatalog::CopyFromBaseOptions
CopyFromBaseOptions
Definition: mergecatalog.h:105
QMap< DocPos, uint >
MatchItem::score
short score
Definition: mergecatalog.h:36
MatchItem::translationIsDifferent
short translationIsDifferent
Definition: mergecatalog.h:37
MergeCatalog::differentEntries
QLinkedList< int > differentEntries() const
Definition: mergecatalog.h:85
MergeCatalog::isPresent
bool isPresent(const short int &entry) const
whether 'merge source' has entry with such msgid
Definition: mergecatalog.cpp:110
MergeCatalog::HigherOnly
Definition: mergecatalog.h:101
MergeCatalog::nextChangedIndex
int nextChangedIndex(uint index) const
Definition: mergecatalog.h:82
MatchItem::MatchItem
MatchItem()
Definition: mergecatalog.h:39
MergeCatalog::EvenIfNotInDiffIndex
Definition: mergecatalog.h:105
MergeCatalog::unmatchedCount
int unmatchedCount() const
Definition: mergecatalog.h:93
MatchItem::baseEntry
short baseEntry
Definition: mergecatalog.h:35
findPrevInList
int findPrevInList(const QLinkedList< int > &list, int index)
Definition: catalog.cpp:964
MatchItem::mergeEntry
short mergeEntry
Definition: mergecatalog.h:34
DocPosition
This struct represents a position in a catalog.
Definition: pos.h:38
QLinkedList< int >
MergeCatalog::isDifferent
int isDifferent(uint index) const
Definition: mergecatalog.h:84
QLinkedList::isEmpty
bool isEmpty() const
QObject
catalog.h
MatchItem
Definition: mergecatalog.h:32
MergeCatalog::removeFromDiffIndex
void removeFromDiffIndex(uint index)
Definition: mergecatalog.h:104
QString
MergeCatalog::copyFromBaseCatalog
void copyFromBaseCatalog(const DocPosition &, int options)
Definition: mergecatalog.cpp:48
MergeCatalog::save
bool save()
Definition: mergecatalog.cpp:255
MergeCatalog::MergeCatalog
MergeCatalog(QObject *parent, Catalog *baseCatalog, bool saveChanges=true)
Definition: mergecatalog.cpp:35
MergeCatalog::copyFromBaseCatalog
void copyFromBaseCatalog(const DocPosition &pos)
Definition: mergecatalog.h:107
QLinkedList::last
T & last()
QVector< int >
QUndoStack::index
int index() const
MergeCatalog::~MergeCatalog
~MergeCatalog()
Definition: mergecatalog.h:76
MergeCatalog::isModified
bool isModified(DocPos) const
Definition: mergecatalog.cpp:250
MatchItem::operator<
bool operator<(const MatchItem &other) const
Definition: mergecatalog.h:53
Catalog::numberOfEntries
int numberOfEntries() const
Definition: catalog.cpp:171
DocPos
simpler version of DocPosition for use in QMap
Definition: pos.h:82
MergeCatalog::isPlural
bool isPlural(uint index) const
Definition: mergecatalog.cpp:98
MergeCatalog::lastChangedIndex
int lastChangedIndex() const
Definition: mergecatalog.h:81
Catalog
This class represents a catalog It uses CatalogStorage interface to work with catalogs in different f...
Definition: catalog.h:74
findNextInList
int findNextInList(const QLinkedList< int > &list, int index)
Definition: catalog.cpp:950
QLinkedList::first
T & first()
MatchItem::MatchItem
MatchItem(short m, short b, bool d)
Definition: mergecatalog.h:46
MergeCatalog::prevChangedIndex
int prevChangedIndex(uint index) const
Definition: mergecatalog.h:83
QLinkedList::removeAll
int removeAll(const T &value)
QObject::parent
QObject * parent() const
TargetState
TargetState
Definition: state.h:30
MergeCatalog::EmptyOnly
Definition: mergecatalog.h:101
MergeCatalog::isApproved
bool isApproved(uint index) const
Definition: mergecatalog.cpp:84
MergeCatalog::CopyToBaseOptions
CopyToBaseOptions
Definition: mergecatalog.h:101
MergeCatalog::copyFromBaseCatalogIfInDiffIndex
void copyFromBaseCatalogIfInDiffIndex(const DocPosition &pos)
Definition: mergecatalog.h:109
MergeCatalog::firstChangedIndex
int firstChangedIndex() const
Definition: mergecatalog.h:80
QLinkedList::contains
bool contains(const T &value) const
MergeCatalog::loadFromUrl
int loadFromUrl(const KUrl &url)
Definition: mergecatalog.cpp:163
MergeCatalog::copyToBaseCatalog
void copyToBaseCatalog(DocPosition &pos)
Definition: mergecatalog.cpp:263
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