• 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
phase.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 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 #include "phase.h"
25 #include "cmd.h"
26 #include "catalog.h"
27 #include "project.h"
28 #include "prefs_lokalize.h"
29 
30 #include <QSet>
31 
32 const char* const* processes()
33 {
34  static const char* const processes[]={"translation","review","approval"};
35  return processes;
36 }
37 
38 //guess role
39 ProjectLocal::PersonRole roleForProcess(const QString& process)
40 {
41  int i=ProjectLocal::Undefined;
42  while (i>=0 && !process.startsWith(processes()[--i]))
43  ;
44  return (i==-1)?Project::local()->role():ProjectLocal::PersonRole(i);
45 }
46 
47 void generatePhaseForCatalogIfNeeded(Catalog* catalog)
48 {
49  if (KDE_ISLIKELY( !(catalog->capabilities()&Phases) || catalog->activePhaseRole()==ProjectLocal::Undefined ))
50  return;
51 
52  Phase phase;
53  phase.process=processes()[Project::local()->role()];
54 
55  if (initPhaseForCatalog(catalog, phase))
56  static_cast<QUndoStack*>(catalog)->push(new UpdatePhaseCmd(catalog, phase));
57 
58  catalog->setActivePhase(phase.name, roleForProcess(phase.process));
59 }
60 
61 
62 bool initPhaseForCatalog(Catalog* catalog, Phase& phase, int options)
63 {
64  phase.contact=Settings::authorName();
65 
66  QSet<QString> names;
67  QList<Phase> phases=catalog->allPhases();
68  qSort(phases.begin(), phases.end(), qGreater<Phase>());
69  foreach (const Phase& p, phases)
70  {
71  if (!(options&ForceAdd) && p.contact==phase.contact && p.process==phase.process)
72  {
73  phase=p;
74  break;
75  }
76  names.insert(p.name);
77  }
78 
79  if (phase.name.isEmpty())
80  {
81  int i=0;
82  while (names.contains(phase.name=phase.process+QString("-%1").arg(++i)))
83  ;
84  phase.date=QDate::currentDate();
85  phase.email=Settings::authorEmail();
86  return true;
87  }
88  return false;
89 }
ProjectLocal::role
PersonRole role() const
Get Role.
Definition: projectlocal.h:30
project.h
ProjectLocal::PersonRole
PersonRole
Definition: projectlocal.h:13
Phase::contact
QString contact
Definition: phase.h:40
phase.h
generatePhaseForCatalogIfNeeded
void generatePhaseForCatalogIfNeeded(Catalog *catalog)
Definition: phase.cpp:47
roleForProcess
ProjectLocal::PersonRole roleForProcess(const QString &process)
Definition: phase.cpp:39
Catalog::activePhaseRole
ProjectLocal::PersonRole activePhaseRole() const
Definition: catalog.h:120
ProjectLocal::Undefined
Definition: projectlocal.h:13
Settings::authorEmail
static QString authorEmail()
Get authorEmail.
Definition: prefs_lokalize.h:61
Project::local
static ProjectLocal * local()
Definition: project.h:116
cmd.h
QSet::insert
const_iterator insert(const T &value)
Catalog::setActivePhase
void setActivePhase(const QString &phase, ProjectLocal::PersonRole role=ProjectLocal::Approver)
Definition: catalog.cpp:339
Catalog::allPhases
QList< Phase > allPhases() const
Definition: catalog.cpp:385
initPhaseForCatalog
bool initPhaseForCatalog(Catalog *catalog, Phase &phase, int options)
Definition: phase.cpp:62
Settings::authorName
static QString authorName()
Get authorName.
Definition: prefs_lokalize.h:25
Phase::date
QDate date
Definition: phase.h:39
Phase::name
QString name
Definition: phase.h:36
Phase::email
QString email
Definition: phase.h:41
catalog.h
QString::isEmpty
bool isEmpty() const
processes
const char *const * processes()
Definition: phase.cpp:32
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QSet
QString
QList< Phase >
Phase
Definition: phase.h:34
names
static const QString names[]
Definition: tsstorage.cpp:45
QList::end
iterator end()
Catalog::capabilities
int capabilities() const
Definition: catalog.cpp:164
QSet::contains
bool contains(const T &value) const
prefs_lokalize.h
QDate::currentDate
QDate currentDate()
QUndoStack
Phase::process
QString process
Definition: phase.h:37
Catalog
This class represents a catalog It uses CatalogStorage interface to work with catalogs in different f...
Definition: catalog.h:74
Phases
Definition: catalogcapabilities.h:31
QList::begin
iterator begin()
UpdatePhaseCmd
Add or remove (if content is empty) a phase.
Definition: cmd.h:180
ForceAdd
Definition: phase.h:78
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