• 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
  • project
projectmodel.h
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2007-2013 by Nick Shaforostoff <shafff@ukr.net>
5  Copyright (C) 2009 by Viesturs Zarins <viesturs.zarins@mii.lu.lv>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License or (at your option) version 3 or any later version
11  accepted by the membership of KDE e.V. (or its successor approved
12  by the membership of KDE e.V.), which shall act as a proxy
13  defined in Section 14 of version 3 of the license.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23 **************************************************************************** */
24 
25 #ifndef PROJECTMODEL_H
26 #define PROJECTMODEL_H
27 
28 #include <threadweaver/Job.h>
29 
30 #include <kdirmodel.h>
31 #include <kdirlister.h>
32 #include <kicon.h>
33 #include <QHash>
34 #include <QList>
35 #include <kdebug.h>
36 
37 #include "project.h"
38 #include "projectlocal.h"
39 
40 class QTimer;
41 class UpdateStatsJob;
42 namespace ThreadWeaver {class Weaver;}
43 
54 class ProjectModel: public QAbstractItemModel
55 {
56  Q_OBJECT
57 
58  class ProjectNode
59  {
60  public:
61  ProjectNode(ProjectNode* parent, int rowNum, int poIndex, int potIndex);
62  ~ProjectNode();
63  void calculateDirStats();
64  void setFileStats(const KFileMetaInfo& info);
65 
66  int translatedAsPerRole() const
67  {
68  switch (Project::local()->role())
69  {
70  case ProjectLocal::Translator:
71  case ProjectLocal::Undefined:
72  return translated;
73  case ProjectLocal::Reviewer:
74  return translated_reviewer;
75  case ProjectLocal::Approver:
76  return translated_approver;
77  }
78  return -1;
79  }
80 
81  int fuzzyAsPerRole() const
82  {
83  switch (Project::local()->role())
84  {
85  case ProjectLocal::Translator:
86  case ProjectLocal::Undefined:
87  return fuzzy;
88  case ProjectLocal::Reviewer:
89  return fuzzy_reviewer;
90  case ProjectLocal::Approver:
91  return fuzzy_approver;
92  }
93  return -1;
94  }
95 
96  ProjectNode* parent;
97  short rowNumber; //in parent's list
98 
99  short poRowNumber; //row number in po model, -1 if this has no po item.
100  short potRowNumber; //row number in pot model, -1 if this has no pot item.
101 
102  short poCount; //number of items from PO in rows. The others will be form POT exclusively.
103  QVector<ProjectNode*> rows; //rows from po and pot, pot rows start from poCount;
104 
105  int translated;
106  int translated_reviewer;
107  int translated_approver;
108  int untranslated;
109  int fuzzy;
110  int fuzzy_reviewer;
111  int fuzzy_approver;
112  QString sourceDate;
113  QString lastTranslator;
114  QString translationDate;
115  };
116 
117 
118 public:
119 
120  enum ProjectModelColumns
121  {
122  FileName,
123  Graph,
124  TotalCount,
125  TranslatedCount,
126  FuzzyCount,
127  UntranslatedCount,
128  SourceDate,
129  TranslationDate,
130  LastTranslator,
131  ProjectModelColumnCount
132  };
133 
134  enum AdditionalRoles {
135  FuzzyUntrCountRole = Qt::UserRole,
136  FuzzyCountRole,
137  UntransCountRole,
138  TemplateOnlyRole,
139  TransOnlyRole,
140  TotalRole
141  };
142 
143  ProjectModel(QObject *parent);
144  ~ProjectModel();
145 
146  void setUrl(const KUrl &poUrl, const KUrl &potUrl);
147  QModelIndex indexForUrl(const KUrl& url);
148  KFileItem itemForIndex(const QModelIndex& index) const;
149  KUrl beginEditing(const QModelIndex& index); //copies POT file to PO file and returns url of the PO file
150 
151  // QAbstractItemModel methods
152  int columnCount(const QModelIndex& parent = QModelIndex()) const;
153  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
154  Qt::ItemFlags flags(const QModelIndex& index) const;
155 
156  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
157  QModelIndex parent(const QModelIndex& index) const ;
158 
159  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
160  int rowCount(const QModelIndex& parent = QModelIndex()) const;
161  bool hasChildren(const QModelIndex& parent = QModelIndex()) const;
162 
163  bool canFetchMore(const QModelIndex& parent) const;
164  void fetchMore(const QModelIndex& parent);
165 
166 
167  ThreadWeaver::Weaver* weaver(){return m_weaver;}
168  void setCompleteScan(bool enable){m_completeScan=enable;}
169 
170 signals:
171  void totalsChanged(int fuzzy, int translated, int untranslated, bool done);
172  void loading();
173 
174 private slots:
175  void po_dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
176  void po_rowsInserted(const QModelIndex& parent, int start, int end);
177  void po_rowsRemoved(const QModelIndex& parent, int start, int end);
178 
179  void pot_dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
180  void pot_rowsInserted(const QModelIndex& parent, int start, int end);
181  void pot_rowsRemoved(const QModelIndex& parent, int start, int end);
182 
183  void finishMetadataUpdate(ThreadWeaver::Job*);
184  void finishSingleMetadataUpdate(ThreadWeaver::Job*);
185 
186  void updateTotalsChanged();
187 
188 public slots:
189  void slotFileSaved(const KUrl&);
190 
191 private:
192  ProjectNode* nodeForIndex(const QModelIndex& index) const;
193  QModelIndex indexForNode(const ProjectNode* node);
194 
195  enum IndexType {PoIndex, PotIndex};
196  QModelIndex indexForOuter(const QModelIndex& outerIndex, IndexType type) const;
197  QModelIndex poIndexForOuter(const QModelIndex& outerIndex) const;
198  QModelIndex potIndexForOuter(const QModelIndex& outerIndex) const;
199  QModelIndex poOrPotIndexForOuter(const QModelIndex& outerIndex) const;
200 
201  QModelIndex indexForPoIndex(const QModelIndex& poIndex) const;
202  QModelIndex indexForPotIndex(const QModelIndex& potIndex) const;
203  void generatePOTMapping(QVector<int> & result, const QModelIndex& poParent, const QModelIndex& potParent) const;
204 
205  KUrl poToPot(const KUrl& path) const;
206  KUrl potToPo(const KUrl& path) const;
207 
208  void enqueueNodeForMetadataUpdate(ProjectNode* node);
209  void deleteSubtree(ProjectNode* node);
210 
211  void startNewMetadataJob();
212  void setMetadataForDir(ProjectNode* node, const QList<KFileMetaInfo>& data);
213  void updateDirStats(ProjectNode* node);
214  bool updateDone(const QModelIndex& index, const KDirModel& model);
215 
216  KUrl m_poUrl;
217  KUrl m_potUrl;
218  KDirModel m_poModel;
219  KDirModel m_potModel;
220 
221  ProjectNode m_rootNode;
222 
223  QVariant m_dirIcon;
224  QVariant m_poIcon;
225  QVariant m_poComplIcon;
226  QVariant m_potIcon;
227 
228  //for updating stats
229  QSet<ProjectNode *> m_dirsWaitingForMetadata;
230  UpdateStatsJob* m_activeJob;
231  ProjectNode* m_activeNode;
232  QTimer* m_doneTimer;
233 
234  ThreadWeaver::Weaver* m_weaver;
235 
236  bool m_completeScan;
237 };
238 
239 
240 
241 class UpdateStatsJob: public ThreadWeaver::Job
242 {
243  Q_OBJECT
244 public:
245  explicit UpdateStatsJob(QList<KFileItem> files, QObject* owner=0);
246  ~UpdateStatsJob();
247  int priority()const{return 35;} //SEE jobs.h
248 
249  void setStatus(int status);
250 
251  QList<KFileItem> m_files;
252  QList<KFileMetaInfo> m_info;
253  volatile int m_status; // 0 = running; -1 = cancel; -2 = abort
254 
255 protected:
256  void run();
257 
258 };
259 
260 
261 #endif
ProjectModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: projectmodel.cpp:519
ProjectModel::beginEditing
KUrl beginEditing(const QModelIndex &index)
Definition: projectmodel.cpp:158
UpdateStatsJob::setStatus
void setStatus(int status)
Definition: projectmodel.cpp:1396
ProjectModel::totalsChanged
void totalsChanged(int fuzzy, int translated, int untranslated, bool done)
QModelIndex
project.h
ProjectModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: projectmodel.cpp:688
ProjectModel::TotalRole
Definition: projectmodel.h:140
ProjectModel::setCompleteScan
void setCompleteScan(bool enable)
Definition: projectmodel.h:168
ProjectModel::TransOnlyRole
Definition: projectmodel.h:139
ProjectModel::FileName
Definition: projectmodel.h:122
ProjectModel::FuzzyUntrCountRole
Definition: projectmodel.h:135
UpdateStatsJob::priority
int priority() const
Definition: projectmodel.h:247
ProjectModel::weaver
ThreadWeaver::Weaver * weaver()
Definition: projectmodel.h:167
UpdateStatsJob::~UpdateStatsJob
~UpdateStatsJob()
Definition: projectmodel.cpp:1265
ProjectModel::hasChildren
bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Definition: projectmodel.cpp:555
ProjectLocal::Undefined
Definition: projectlocal.h:13
ProjectModel::canFetchMore
bool canFetchMore(const QModelIndex &parent) const
Definition: projectmodel.cpp:567
ProjectModel::AdditionalRoles
AdditionalRoles
Definition: projectmodel.h:134
Project::local
static ProjectLocal * local()
Definition: project.h:116
ProjectModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const
Definition: projectmodel.cpp:540
ProjectModel::fetchMore
void fetchMore(const QModelIndex &parent)
Definition: projectmodel.cpp:579
ProjectModel::TranslationDate
Definition: projectmodel.h:129
ProjectModel
Some notes: Uses two KDirModels for template and translations dir.
Definition: projectmodel.h:54
ProjectModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: projectmodel.cpp:513
QTimer
QObject
ProjectLocal::Translator
Definition: projectlocal.h:13
ProjectModel::ProjectModelColumns
ProjectModelColumns
Definition: projectmodel.h:120
UpdateStatsJob::m_files
QList< KFileItem > m_files
Definition: projectmodel.h:251
ProjectModel::setUrl
void setUrl(const KUrl &poUrl, const KUrl &potUrl)
Definition: projectmodel.cpp:112
projectlocal.h
ProjectModel::~ProjectModel
~ProjectModel()
Definition: projectmodel.cpp:99
ProjectModel::ProjectModelColumnCount
Definition: projectmodel.h:131
ProjectModel::UntransCountRole
Definition: projectmodel.h:137
ProjectModel::FuzzyCount
Definition: projectmodel.h:126
UpdateStatsJob::m_info
QList< KFileMetaInfo > m_info
Definition: projectmodel.h:252
ProjectModel::FuzzyCountRole
Definition: projectmodel.h:136
QSet< ProjectNode * >
ProjectLocal::Approver
Definition: projectlocal.h:13
QString
QList< KFileMetaInfo >
ProjectModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
we use QRect to pass data through QVariant tunnel
Definition: projectmodel.cpp:611
ProjectModel::TemplateOnlyRole
Definition: projectmodel.h:138
ProjectLocal::Reviewer
Definition: projectlocal.h:13
ProjectModel::loading
void loading()
UpdateStatsJob::m_status
volatile int m_status
Definition: projectmodel.h:253
QVector< ProjectNode * >
ProjectModel::LastTranslator
Definition: projectmodel.h:130
ProjectModel::ProjectModel
ProjectModel(QObject *parent)
Definition: projectmodel.cpp:51
UpdateStatsJob
Definition: projectmodel.h:241
ProjectModel::indexForUrl
QModelIndex indexForUrl(const KUrl &url)
Definition: projectmodel.cpp:757
QAbstractItemModel
ProjectModel::TranslatedCount
Definition: projectmodel.h:125
UpdateStatsJob::UpdateStatsJob
UpdateStatsJob(QList< KFileItem > files, QObject *owner=0)
Definition: projectmodel.cpp:1258
ProjectModel::SourceDate
Definition: projectmodel.h:128
ProjectModel::slotFileSaved
void slotFileSaved(const KUrl &)
Definition: projectmodel.cpp:1067
ProjectModel::Graph
Definition: projectmodel.h:123
QObject::parent
QObject * parent() const
UpdateStatsJob::run
void run()
Definition: projectmodel.cpp:1355
ProjectModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: projectmodel.cpp:549
ProjectModel::itemForIndex
KFileItem itemForIndex(const QModelIndex &index) const
Definition: projectmodel.cpp:701
QVariant
ProjectModel::UntranslatedCount
Definition: projectmodel.h:127
ProjectModel::TotalCount
Definition: projectmodel.h:124
Qt::ItemFlags
typedef ItemFlags
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