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

lokalize

  • sources
  • kde-4.12
  • 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  }
127  ThreadWeaver::Weaver::instance()->finish();//more safety
128 
129  kDebug()<<"5...";
130 
131  setSharedConfig(KSharedConfig::openConfig(newProjectPath, KConfig::NoGlobals));
132  kDebug()<<"4...";
133  readConfig();
134  m_path=newProjectPath;
135  m_desirablePath.clear();
136 
137  //cache:
138  m_projectDir=KUrl(m_path).directory();
139 
140  kDebug()<<"3...";
141  m_localConfig->setSharedConfig(KSharedConfig::openConfig(projectID()+".local", KConfig::NoGlobals,"appdata"));
142  m_localConfig->readConfig();
143 
144  if (langCode().isEmpty())
145  setLangCode(KGlobal::locale()->language());
146  kDebug()<<"2...";
147 
148  //KConfig config;
149  //delete m_localConfig; m_localConfig=new KConfigGroup(&config,"Project-"+path());
150 
151  populateDirModel();
152 
153  kDebug()<<"1...";
154 
155  //put 'em into thread?
156  //QTimer::singleShot(0,this,SLOT(populateGlossary()));
157  populateGlossary();//we cant postpone it because project load can be called from define new term function
158 
159  if (newProjectPath.isEmpty())
160  return;
161 
162  //NOTE do we need to explicitly call it when project id changes?
163  TM::DBFilesModel::instance()->openDB(projectID());
164 
165  if (QaModel::isInstantiated())
166  {
167  QaModel::instance()->saveRules();
168  QaModel::instance()->loadRules(qaPath());
169  }
170 
171  kDebug()<<"until emitting signal"<<a.elapsed();
172 
173  emit loaded();
174  kDebug()<<"loaded!"<<a.elapsed();
175 }
176 
177 QString Project::absolutePath(const QString& possiblyRelPath) const
178 {
179  if (KUrl::isRelativeUrl(possiblyRelPath))
180  {
181  KUrl url(m_path);
182  url.setFileName(QString());
183  url.cd(possiblyRelPath);
184  return url.toLocalFile(KUrl::RemoveTrailingSlash);
185  }
186  return possiblyRelPath;
187 }
188 
189 void Project::populateDirModel()
190 {
191  if (KDE_ISUNLIKELY( m_path.isEmpty() || !QFile::exists(poDir()) ))
192  return;
193 
194  KUrl potUrl;
195  if (QFile::exists(potDir()))
196  potUrl=KUrl::fromLocalFile(potDir());
197  model()->setUrl(KUrl(poDir()), potUrl);
198 }
199 
200 void Project::populateGlossary()
201 {
202  m_glossary->load(glossaryPath());
203 }
204 
205 GlossaryNS::GlossaryWindow* Project::showGlossary()
206 {
207  return defineNewTerm();
208 }
209 
210 GlossaryNS::GlossaryWindow* Project::defineNewTerm(QString en, QString target)
211 {
212  if (!SettingsController::instance()->ensureProjectIsLoaded())
213  return 0;
214 
215  if (!m_glossaryWindow)
216  m_glossaryWindow=new GlossaryNS::GlossaryWindow(SettingsController::instance()->mainWindowPtr());
217  m_glossaryWindow->show();
218  m_glossaryWindow->activateWindow();
219  if (!en.isEmpty()||!target.isEmpty())
220  m_glossaryWindow->newTermEntry(en,target);
221 
222  return m_glossaryWindow;
223 }
224 
225 bool Project::queryCloseForAuxiliaryWindows()
226 {
227  if (m_glossaryWindow && m_glossaryWindow->isVisible())
228  return m_glossaryWindow->queryClose();
229 
230  return true;
231 }
232 
233 bool Project::isTmSupported() const
234 {
235  QStringList drivers=QSqlDatabase::drivers();
236  return drivers.contains("QSQLITE");
237 }
238 
239 void Project::showTMManager()
240 {
241  if (!m_tmManagerWindow)
242  {
243  if (!isTmSupported())
244  {
245  KMessageBox::information(0, i18n("TM facility requires SQLite Qt module."), i18n("No SQLite module available"));
246  return;
247  }
248 
249  m_tmManagerWindow=new TM::TMManagerWin(SettingsController::instance()->mainWindowPtr());
250  }
251  m_tmManagerWindow->show();
252  m_tmManagerWindow->activateWindow();
253 }
254 
255 void Project::save()
256 {
257  m_localConfig->setFirstRun(false);
258 
259  ProjectBase::setTargetLangCode(langCode());
260  writeConfig();
261  m_localConfig->writeConfig();
262 }
263 
264 ProjectModel* Project::model()
265 {
266  if (KDE_ISUNLIKELY(!m_model))
267  m_model=new ProjectModel(this);
268 
269  return m_model;
270 }
271 
272 void Project::setDefaults()
273 {
274  ProjectBase::setDefaults();
275  setLangCode(KGlobal::locale()->language());
276 }
277 
278 void Project::init(const QString& path, const QString& kind, const QString& id,
279  const QString& sourceLang, const QString& targetLang)
280 {
281  setDefaults();
282  bool stop=false;
283  while(true)
284  {
285  setKind(kind);setSourceLangCode(sourceLang);setLangCode(targetLang);setProjectID(id);
286  if (stop) break;
287  else {load(path);stop=true;}
288  }
289  save();
290 }
291 
292 
293 #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:278
Project::qaPath
QString qaPath() const
Definition: project.h:72
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:189
Project::instance
static Project * instance()
Definition: project.cpp:67
ProjectBase::langCode
QString langCode() const
Get LangCode.
Definition: projectbase.h:65
editortab.h
prefs.h
dbfilesmodel.h
Project::potDir
QString potDir() const
Definition: project.h:69
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:233
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
Project::defineNewTerm
GlossaryNS::GlossaryWindow * defineNewTerm(QString en=QString(), QString target=QString())
Definition: project.cpp:210
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:255
ProjectBase::setLangCode
void setLangCode(const QString &v)
Set LangCode.
Definition: projectbase.h:56
Project::showGlossary
GlossaryNS::GlossaryWindow * showGlossary()
Definition: project.cpp:205
glossarywindow.h
ProjectBase::setSourceLangCode
void setSourceLangCode(const QString &v)
Set SourceLangCode.
Definition: projectbase.h:90
ProjectModel::setUrl
void setUrl(const KUrl &poUrl, const KUrl &potUrl)
Definition: projectmodel.cpp:112
Project::model
ProjectModel * model()
Definition: project.cpp:264
projectlocal.h
Project::queryCloseForAuxiliaryWindows
bool queryCloseForAuxiliaryWindows()
Definition: project.cpp:225
ProjectBase::setProjectID
void setProjectID(const QString &v)
Set ProjectID.
Definition: projectbase.h:22
glossary.h
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:177
Project::setDefaults
void setDefaults()
Definition: project.cpp:272
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:200
QaModel::isInstantiated
static bool isInstantiated()
Definition: qamodel.cpp:64
Project::showTMManager
void showTMManager()
Definition: project.cpp:239
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-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:45 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
  • okteta
  • 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