• 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
project.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2007-2012 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 "project.h"
25 #include "projectmodel.h"
26 #include "projectlocal.h"
27 
28 #include "prefs.h"
29 #include "webquerycontroller.h"
30 #include "jobs.h"
31 #include "glossary.h"
32 
33 #include "tmmanager.h"
34 #include "glossarywindow.h"
35 #include "editortab.h"
36 #include "dbfilesmodel.h"
37 #include "qamodel.h"
38 
39 #include <QTimer>
40 #include <QTime>
41 
42 #include <kurl.h>
43 #include <kdirlister.h>
44 #include <kdebug.h>
45 #include <klocale.h>
46 #include <kstandarddirs.h>
47 
48 #include <kross/core/action.h>
49 #include <kross/core/actioncollection.h>
50 #include <kross/core/manager.h>
51 #include <kpassivepopup.h>
52 #include <kmessagebox.h>
53 
54 #include <threadweaver/ThreadWeaver.h>
55 
56 #include <QDBusArgument>
57 
58 
59 using namespace Kross;
60 
61 Project* Project::_instance=0;
62 void Project::cleanupProject()
63 {
64  delete Project::_instance; Project::_instance = 0;
65 }
66 
67 Project* Project::instance()
68 {
69  if (_instance==0 )
70  {
71  _instance=new Project();
72  qAddPostRoutine(Project::cleanupProject);
73  }
74  return _instance;
75 }
76 
77 Project::Project()
78  : ProjectBase()
79  , m_localConfig(new ProjectLocal())
80  , m_model(0)
81  , m_glossary(new GlossaryNS::Glossary(this))
82  , m_glossaryWindow(0)
83  , m_tmManagerWindow(0)
84 {
85  ThreadWeaver::Weaver::instance()->setMaximumNumberOfThreads(1);
86 
87  setDefaults();
88 /*
89  qRegisterMetaType<DocPosition>("DocPosition");
90  qDBusRegisterMetaType<DocPosition>();
91 */
92  //QTimer::singleShot(66,this,SLOT(initLater()));
93 }
94 /*
95 void Project::initLater()
96 {
97  if (isLoaded())
98  return;
99 
100  KConfig cfg;
101  KConfigGroup gr(&cfg,"State");
102  QString file=gr.readEntry("Project");
103  if (!file.isEmpty())
104  load(file);
105 
106 }
107 */
108 
109 Project::~Project()
110 {
111  delete m_localConfig;
112  //Project::save()
113 }
114 
115 void Project::load(const QString &newProjectPath)
116 {
117  QTime a;a.start();
118 
119  ThreadWeaver::Weaver::instance()->dequeue();
120  kDebug()<<"loading"<<newProjectPath<<"Finishing jobs...";
121 
122  if (!m_path.isEmpty())
123  {
124  TM::CloseDBJob* closeDBJob=new TM::CloseDBJob(projectID(),this);
125  connect(closeDBJob,SIGNAL(done(ThreadWeaver::Job*)),closeDBJob,SLOT(deleteLater()));
126  ThreadWeaver::Weaver::instance()->enqueue(closeDBJob);
127  }
128  ThreadWeaver::Weaver::instance()->finish();//more safety
129 
130  kDebug()<<"5...";
131 
132  setSharedConfig(KSharedConfig::openConfig(newProjectPath, KConfig::NoGlobals));
133  kDebug()<<"4...";
134  readConfig();
135  m_path=newProjectPath;
136  m_desirablePath.clear();
137 
138  //cache:
139  m_projectDir=KUrl(m_path).directory();
140 
141  kDebug()<<"3...";
142  m_localConfig->setSharedConfig(KSharedConfig::openConfig(projectID()+".local", KConfig::NoGlobals,"appdata"));
143  m_localConfig->readConfig();
144 
145  if (langCode().isEmpty())
146  setLangCode(KGlobal::locale()->language());
147  kDebug()<<"2...";
148 
149  //KConfig config;
150  //delete m_localConfig; m_localConfig=new KConfigGroup(&config,"Project-"+path());
151 
152  populateDirModel();
153 
154  kDebug()<<"1...";
155 
156  //put 'em into thread?
157  //QTimer::singleShot(0,this,SLOT(populateGlossary()));
158  populateGlossary();//we cant postpone it because project load can be called from define new term function
159 
160  if (newProjectPath.isEmpty())
161  return;
162 
163  //NOTE do we need to explicitly call it when project id changes?
164  TM::DBFilesModel::instance()->openDB(projectID());
165 
166  if (QaModel::isInstantiated())
167  {
168  QaModel::instance()->saveRules();
169  QaModel::instance()->loadRules(qaPath());
170  }
171 
172  kDebug()<<"until emitting signal"<<a.elapsed();
173 
174  emit loaded();
175  kDebug()<<"loaded!"<<a.elapsed();
176 }
177 
178 QString Project::absolutePath(const QString& possiblyRelPath) const
179 {
180  if (KUrl::isRelativeUrl(possiblyRelPath))
181  {
182  KUrl url(m_path);
183  url.setFileName(QString());
184  url.cd(possiblyRelPath);
185  return url.toLocalFile(KUrl::RemoveTrailingSlash);
186  }
187  return possiblyRelPath;
188 }
189 
190 void Project::populateDirModel()
191 {
192  if (KDE_ISUNLIKELY( m_path.isEmpty() || !QFile::exists(poDir()) ))
193  return;
194 
195  KUrl potUrl;
196  if (QFile::exists(potDir()))
197  potUrl=KUrl::fromLocalFile(potDir());
198  model()->setUrl(KUrl(poDir()), potUrl);
199 }
200 
201 void Project::populateGlossary()
202 {
203  m_glossary->load(glossaryPath());
204 }
205 
206 GlossaryNS::GlossaryWindow* Project::showGlossary()
207 {
208  return defineNewTerm();
209 }
210 
211 GlossaryNS::GlossaryWindow* Project::defineNewTerm(QString en, QString target)
212 {
213  if (!SettingsController::instance()->ensureProjectIsLoaded())
214  return 0;
215 
216  if (!m_glossaryWindow)
217  m_glossaryWindow=new GlossaryNS::GlossaryWindow(SettingsController::instance()->mainWindowPtr());
218  m_glossaryWindow->show();
219  m_glossaryWindow->activateWindow();
220  if (!en.isEmpty()||!target.isEmpty())
221  m_glossaryWindow->newTermEntry(en,target);
222 
223  return m_glossaryWindow;
224 }
225 
226 bool Project::queryCloseForAuxiliaryWindows()
227 {
228  if (m_glossaryWindow && m_glossaryWindow->isVisible())
229  return m_glossaryWindow->queryClose();
230 
231  return true;
232 }
233 
234 bool Project::isTmSupported() const
235 {
236  QStringList drivers=QSqlDatabase::drivers();
237  return drivers.contains("QSQLITE");
238 }
239 
240 void Project::showTMManager()
241 {
242  if (!m_tmManagerWindow)
243  {
244  if (!isTmSupported())
245  {
246  KMessageBox::information(0, i18n("TM facility requires SQLite Qt module."), i18n("No SQLite module available"));
247  return;
248  }
249 
250  m_tmManagerWindow=new TM::TMManagerWin(SettingsController::instance()->mainWindowPtr());
251  }
252  m_tmManagerWindow->show();
253  m_tmManagerWindow->activateWindow();
254 }
255 
256 void Project::save()
257 {
258  m_localConfig->setFirstRun(false);
259 
260  ProjectBase::setTargetLangCode(langCode());
261  writeConfig();
262  m_localConfig->writeConfig();
263 }
264 
265 ProjectModel* Project::model()
266 {
267  if (KDE_ISUNLIKELY(!m_model))
268  m_model=new ProjectModel(this);
269 
270  return m_model;
271 }
272 
273 void Project::setDefaults()
274 {
275  ProjectBase::setDefaults();
276  setLangCode(KGlobal::locale()->language());
277 }
278 
279 void Project::init(const QString& path, const QString& kind, const QString& id,
280  const QString& sourceLang, const QString& targetLang)
281 {
282  setDefaults();
283  bool stop=false;
284  while(true)
285  {
286  setKind(kind);setSourceLangCode(sourceLang);setLangCode(targetLang);setProjectID(id);
287  if (stop) break;
288  else {load(path);stop=true;}
289  }
290  save();
291 }
292 
293 
294 #include "project.moc"
Project::Project
Project()
Definition: project.cpp:77
GlossaryNS::GlossaryWindow::queryClose
bool queryClose()
Definition: glossarywindow.cpp:496
project.h
Project::init
Q_SCRIPTABLE void init(const QString &path, const QString &kind, const QString &id, const QString &sourceLang, const QString &targetLang)
Definition: project.cpp:279
Project::qaPath
QString qaPath() const
Definition: project.h:72
QSqlDatabase::drivers
QStringList drivers()
ProjectBase::setKind
void setKind(const QString &v)
Set Kind.
Definition: projectbase.h:39
GlossaryNS::GlossaryWindow
Definition: glossarywindow.h:69
ProjectLocal::setFirstRun
void setFirstRun(bool v)
Set FirstRun.
Definition: projectlocal.h:38
Project::populateDirModel
void populateDirModel()
Definition: project.cpp:190
Project::instance
static Project * instance()
Definition: project.cpp:67
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
ProjectBase::langCode
QString langCode() const
Get LangCode.
Definition: projectbase.h:65
editortab.h
prefs.h
QFile::exists
bool exists() const
dbfilesmodel.h
Project::potDir
QString potDir() const
Definition: project.h:69
QTime
stop
static bool stop
Definition: jobs.cpp:57
TM::TMManagerWin
Window for managing Translation Memory databases.
Definition: tmmanager.h:50
Project::isTmSupported
Q_SCRIPTABLE bool isTmSupported() const
Definition: project.cpp:234
ProjectBase
Definition: projectbase.h:12
ProjectModel
Some notes: Uses two KDirModels for template and translations dir.
Definition: projectmodel.h:54
GlossaryNS::GlossaryWindow::newTermEntry
void newTermEntry(QString _english=QString(), QString _target=QString())
Definition: glossarywindow.cpp:450
QString::clear
void clear()
Project::defineNewTerm
GlossaryNS::GlossaryWindow * defineNewTerm(QString en=QString(), QString target=QString())
Definition: project.cpp:211
QTime::elapsed
int elapsed() const
Project
Singleton object that represents project.
Definition: project.h:51
Project::loaded
Q_SCRIPTABLE void loaded()
tmmanager.h
GlossaryNS::Glossary::load
bool load(const QString &)
Definition: glossary.cpp:66
QaModel::saveRules
bool saveRules(QString filename=QString())
Definition: qamodel.cpp:170
Project::save
void save()
Definition: project.cpp:256
ProjectBase::setLangCode
void setLangCode(const QString &v)
Set LangCode.
Definition: projectbase.h:56
Project::showGlossary
GlossaryNS::GlossaryWindow * showGlossary()
Definition: project.cpp:206
glossarywindow.h
ProjectBase::setSourceLangCode
void setSourceLangCode(const QString &v)
Set SourceLangCode.
Definition: projectbase.h:90
QString::isEmpty
bool isEmpty() const
ProjectModel::setUrl
void setUrl(const KUrl &poUrl, const KUrl &potUrl)
Definition: projectmodel.cpp:112
Project::model
ProjectModel * model()
Definition: project.cpp:265
projectlocal.h
Project::queryCloseForAuxiliaryWindows
bool queryCloseForAuxiliaryWindows()
Definition: project.cpp:226
ProjectBase::setProjectID
void setProjectID(const QString &v)
Set ProjectID.
Definition: projectbase.h:22
QString
glossary.h
QStringList
TM::DBFilesModel::openDB
void openDB(const QString &name)
Definition: dbfilesmodel.cpp:117
SettingsController::instance
static SettingsController * instance()
Definition: prefs.cpp:70
Project::glossaryPath
QString glossaryPath() const
Definition: project.h:71
Project::load
void load(const QString &file)
Definition: project.cpp:115
Project::poDir
QString poDir() const
Definition: project.h:68
jobs.h
projectmodel.h
Project::absolutePath
Q_SCRIPTABLE QString absolutePath(const QString &) const
Definition: project.cpp:178
Project::setDefaults
void setDefaults()
Definition: project.cpp:273
ProjectBase::projectID
QString projectID() const
Get ProjectID.
Definition: projectbase.h:31
ProjectLocal
Definition: projectlocal.h:10
QaModel::loadRules
bool loadRules(const QString &filename)
Definition: qamodel.cpp:145
TM::CloseDBJob
Definition: jobs.h:110
webquerycontroller.h
Project::populateGlossary
void populateGlossary()
Definition: project.cpp:201
QTime::start
void start()
QaModel::isInstantiated
static bool isInstantiated()
Definition: qamodel.cpp:64
Project::showTMManager
void showTMManager()
Definition: project.cpp:240
QaModel::instance
static QaModel * instance()
Definition: qamodel.cpp:69
Project::~Project
virtual ~Project()
Definition: project.cpp:109
ProjectBase::setTargetLangCode
void setTargetLangCode(const QString &v)
Set TargetLangCode.
Definition: projectbase.h:73
qamodel.h
TM::DBFilesModel::instance
static DBFilesModel * instance()
Definition: dbfilesmodel.cpp:46
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