• 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
  • prefs
prefs.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2007-2011 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 "prefs.h"
25 #include "prefs_lokalize.h"
26 #include "project.h"
27 #include "projectlocal.h"
28 #include "projectmodel.h"
29 #include "languagelistmodel.h"
30 #include "dbfilesmodel.h"
31 
32 #include "ui_prefs_identity.h"
33 #include "ui_prefs_editor.h"
34 #include "ui_prefs_appearance.h"
35 #include "ui_prefs_tm.h"
36 #include "ui_prefs_projectmain.h"
37 #include "ui_prefs_project_advanced.h"
38 #include "ui_prefs_project_local.h"
39 
40 
41 #include <kconfigdialog.h>
42 #include <kglobal.h>
43 #include <kstandarddirs.h>
44 #include <klocale.h>
45 #include <kicon.h>
46 #include <kstatusbar.h>
47 #include <kdebug.h>
48 
49 #include <kurl.h>
50 #include <kfiledialog.h>
51 #include <kmessagebox.h>
52 
53 #include <kross/core/manager.h>
54 #include <kross/core/actioncollection.h>
55 #include <kross/ui/model.h>
56 #include <threadweaver/ThreadWeaver.h>
57 #include <QBoxLayout>
58 #include <QDragEnterEvent>
59 #include <QDropEvent>
60 
61 //#include <sonnet/configwidget.h>
62 
63 SettingsController* SettingsController::_instance=0;
64 void SettingsController::cleanupSettingsController()
65 {
66  delete SettingsController::_instance;
67  SettingsController::_instance = 0;
68 }
69 
70 SettingsController* SettingsController::instance()
71 {
72  if (_instance==0){
73  _instance=new SettingsController;
74  qAddPostRoutine(SettingsController::cleanupSettingsController);
75  }
76 
77  return _instance;
78 }
79 
80 SettingsController::SettingsController()
81  : QObject(Project::instance())
82  , dirty(false)
83  , m_projectActionsView(0)
84  , m_mainWindowPtr(0)
85 {}
86 
87 SettingsController::~SettingsController()
88 {}
89 
90 
91 void SettingsController::showSettingsDialog()
92 {
93  if (KConfigDialog::showDialog("lokalize_settings"))
94  return;
95 
96  KConfigDialog *dialog = new KConfigDialog(m_mainWindowPtr, "lokalize_settings", Settings::self());
97  dialog->setFaceType(KPageDialog::List);
98 
99 // Identity
100  QWidget *w = new QWidget(dialog);
101  Ui_prefs_identity ui_prefs_identity;
102  ui_prefs_identity.setupUi(w);
103 
104 
105  KConfigGroup grp = Settings::self()->config()->group("Identity");
106 
107  ui_prefs_identity.DefaultLangCode->setModel(LanguageListModel::instance()->sortModel());
108  ui_prefs_identity.DefaultLangCode->setCurrentIndex(LanguageListModel::instance()->sortModelRowForLangCode( grp.readEntry("DefaultLangCode",KGlobal::locale()->language()) ));
109 
110  connect(ui_prefs_identity.DefaultLangCode,SIGNAL(activated(int)),ui_prefs_identity.kcfg_DefaultLangCode,SLOT(setLangCode(int)));
111  ui_prefs_identity.kcfg_DefaultLangCode->hide();
112 
113  dialog->addPage(w, i18nc("@title:tab","Identity"), "preferences-desktop-user");
114 
115 //Editor
116  w = new QWidget(dialog);
117  Ui_prefs_editor ui_prefs_editor;
118  ui_prefs_editor.setupUi(w);
119  dialog->addPage(w, i18nc("@title:tab","Editing"), "accessories-text-editor");
120 
121 //Font
122  w = new QWidget(dialog);
123  Ui_prefs_appearance ui_prefs_appearance;
124  ui_prefs_appearance.setupUi(w);
125  dialog->addPage(w, i18nc("@title:tab","Appearance"), "preferences-desktop-font");
126 
127 //TM
128  w = new QWidget(dialog);
129  Ui_prefs_tm ui_prefs_tm;
130  ui_prefs_tm.setupUi(w);
131  dialog->addPage(w, i18nc("@title:tab","Translation Memory"), "configure");
132 
133  connect(dialog,SIGNAL(settingsChanged(QString)),this,SIGNAL(generalSettingsChanged()));
134 
135 
136 //Spellcheck
137 #if 0
138  w = new Sonnet::ConfigWidget(Settings::self()->config(),dialog);
139  w->setParent(this);
140  dialog->addPage(w, i18nc("@title:tab","Spellcheck"), "spellcheck_setting");
141  connect(dialog,SIGNAL(okClicked()),w,SLOT(save()));
142  connect(dialog,SIGNAL(applyClicked()),w,SLOT(save()));
143  connect(dialog,SIGNAL(defaultClicked()),w,SLOT(slotDefault()));
144 #endif
145 
146 
147 
148 
149  //connect(dialog,SIGNAL(settingsChanged(const QString&)),m_view, SLOT(settingsChanged()));
150 
151  dialog->show();
152 // dialog->addPage(new General(0, "General"), i18n("General") );
153 // dialog->addPage(new Appearance(0, "Style"), i18n("Appearance") );
154 // connect(dialog, SIGNAL(settingsChanged(const QString&)), mainWidget, SLOT(loadSettings()));
155 // connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(loadSettings()));
156 
157 }
158 
159 
160 
161 
162 ScriptsView::ScriptsView(QWidget* parent):Kross::ActionCollectionView(parent)
163 {
164  setAcceptDrops(true);
165 }
166 
167 void ScriptsView::dragEnterEvent(QDragEnterEvent* event)
168 {
169  if (!event->mimeData()->urls().isEmpty() && event->mimeData()->urls().first().path().endsWith(QLatin1String(".rc")))
170  event->accept();
171 }
172 
173 void ScriptsView::dropEvent(QDropEvent* event)
174 {
175  Kross::ActionCollectionModel* scriptsModel=static_cast<Kross::ActionCollectionModel*>(model());
176  foreach(const QUrl& url, event->mimeData()->urls())
177  if (url.path().endsWith(".rc"))
178  scriptsModel->rootCollection()->readXmlFile(url.path());
179 }
180 
181 bool SettingsController::ensureProjectIsLoaded()
182 {
183  if (Project::instance()->isLoaded())
184  return true;
185 
186  int answer=KMessageBox::questionYesNoCancel(m_mainWindowPtr, i18n("You have accessed a feature that requires a project to be loaded. Do you want to create a new project or open an existing project?"),
187  QString(), KGuiItem(i18nc("@action","New"),KIcon("document-new")), KGuiItem(i18nc("@action","Open"),KIcon("project-open"))
188  );
189  if (answer==KMessageBox::Yes)
190  return projectCreate();
191  if (answer==KMessageBox::No)
192  return !projectOpen().isEmpty();
193  return false;
194 }
195 
196 QString SettingsController::projectOpen(QString path, bool doOpen)
197 {
198  if (path.isEmpty())
199  {
200  Project::instance()->model()->weaver()->suspend();
201  path=KFileDialog::getOpenFileName(KUrl()/*_catalog->url().directory()*/,
202  i18n("*.lokalize *.ktp|Lokalize translation project")/*"text/x-lokalize-project"*/,
203  m_mainWindowPtr);
204  Project::instance()->model()->weaver()->resume();
205  }
206 
207  if (!path.isEmpty() && doOpen)
208  Project::instance()->load(path);
209 
210  return path;
211 }
212 
213 bool SettingsController::projectCreate()
214 {
215  Project::instance()->model()->weaver()->suspend();
216  QString desirablePath=Project::instance()->desirablePath();
217  if (desirablePath.isEmpty())
218  desirablePath=QDir::homePath()+"/index.lokalize";
219  QString path=KFileDialog::getSaveFileName(KUrl(desirablePath), i18n("*.lokalize|Lokalize translation project") /*"text/x-lokalize-project"*/,m_mainWindowPtr);
220  Project::instance()->model()->weaver()->resume();
221  if (path.isEmpty())
222  return false;
223 
224  if (m_projectActionsView && m_projectActionsView->model())
225  {
226  //ActionCollectionModel is known to be have bad for the usecase of reinitializing krossplugin
227  m_projectActionsView->model()->deleteLater();
228  m_projectActionsView->setModel(0);
229  }
230 
231  //TODO ask-n-save
232  Project::instance()->load(path);
233  Project::instance()->setDefaults(); //NOTE will this be an obstacle?
234 
235  QTimer::singleShot(500, this, SLOT(projectConfigure()));
236  return true;
237 }
238 
239 void SettingsController::projectConfigure()
240 {
241  if (KConfigDialog::showDialog("project_settings"))
242  {
243  if (!m_projectActionsView->model())
244  m_projectActionsView->setModel(new Kross::ActionCollectionModel(m_projectActionsView,Kross::Manager::self().actionCollection()->collection(Project::instance()->kind())));
245  return;
246  }
247 
248  KConfigDialog *dialog = new KConfigDialog(m_mainWindowPtr, "project_settings", Project::instance());
249  dialog->setFaceType(KPageDialog::List);
250 
251 
252 // Main
253  QWidget *w = new QWidget(dialog);
254  Ui_prefs_projectmain ui_prefs_projectmain;
255  ui_prefs_projectmain.setupUi(w);
256  dialog->addPage(w, i18nc("@title:tab","General"), "preferences-desktop-locale");
257 
258  ui_prefs_projectmain.kcfg_LangCode->hide();
259  ui_prefs_projectmain.kcfg_PoBaseDir->hide();
260  ui_prefs_projectmain.kcfg_GlossaryTbx->hide();
261 
262  Project& p=*(Project::instance());
263  ui_prefs_projectmain.LangCode->setModel(LanguageListModel::instance()->sortModel());
264  ui_prefs_projectmain.LangCode->setCurrentIndex(LanguageListModel::instance()->sortModelRowForLangCode(p.langCode()));
265  connect(ui_prefs_projectmain.LangCode,SIGNAL(activated(int)),
266  ui_prefs_projectmain.kcfg_LangCode,SLOT(setLangCode(int)));
267 
268  ui_prefs_projectmain.poBaseDir->setMode(KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly);
269  ui_prefs_projectmain.glossaryTbx->setMode(KFile::File|KFile::ExistingOnly|KFile::LocalOnly);
270  ui_prefs_projectmain.glossaryTbx->setFilter("*.tbx\n*.xml");
271  connect(ui_prefs_projectmain.poBaseDir,SIGNAL(textChanged(QString)),
272  ui_prefs_projectmain.kcfg_PoBaseDir,SLOT(setText(QString)));
273  connect(ui_prefs_projectmain.glossaryTbx,SIGNAL(textChanged(QString)),
274  ui_prefs_projectmain.kcfg_GlossaryTbx,SLOT(setText(QString)));
275  ui_prefs_projectmain.poBaseDir->setUrl(p.poDir());
276  ui_prefs_projectmain.glossaryTbx->setUrl(p.glossaryPath());
277 
278 
279 
280 
281 
282  // RegExps
283  w = new QWidget(dialog);
284  Ui_project_advanced ui_project_advanced;
285  ui_project_advanced.setupUi(w);
286  ui_project_advanced.kcfg_PotBaseDir->hide();
287  ui_project_advanced.kcfg_BranchDir->hide();
288  ui_project_advanced.kcfg_AltDir->hide();
289  ui_project_advanced.potBaseDir->setMode(KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly);
290  ui_project_advanced.branchDir->setMode(KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly);
291  ui_project_advanced.altDir->setMode(KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly);
292  connect(ui_project_advanced.potBaseDir,SIGNAL(textChanged(QString)), ui_project_advanced.kcfg_PotBaseDir,SLOT(setText(QString)));
293  connect(ui_project_advanced.branchDir,SIGNAL(textChanged(QString)), ui_project_advanced.kcfg_BranchDir,SLOT(setText(QString)));
294  connect(ui_project_advanced.altDir,SIGNAL(textChanged(QString)), ui_project_advanced.kcfg_AltDir,SLOT(setText(QString)));
295  ui_project_advanced.potBaseDir->setUrl(p.potDir());
296  ui_project_advanced.branchDir->setUrl(p.branchDir());
297  ui_project_advanced.altDir->setUrl(p.altTransDir());
298  dialog->addPage(w, i18nc("@title:tab","Advanced"), "applications-development-translation");
299 
300  //Scripts
301  w = new QWidget(dialog);
302  QVBoxLayout* layout = new QVBoxLayout(w);
303  layout->setSpacing(6);
304  layout->setMargin(11);
305 
306 
307  //m_projectActionsEditor=new Kross::ActionCollectionEditor(Kross::Manager::self().actionCollection()->collection(Project::instance()->projectID()),w);
308  m_projectActionsView=new ScriptsView(w);
309  layout->addWidget(m_projectActionsView);
310  m_projectActionsView->setModel(new Kross::ActionCollectionModel(w,Kross::Manager::self().actionCollection()->collection(Project::instance()->kind())));
311 
312  QHBoxLayout* btns = new QHBoxLayout();
313  layout->addLayout(btns);
314  btns->addWidget(m_projectActionsView->createButton(w, "edit"));
315 
316 
317  dialog->addPage(w, i18nc("@title:tab","Scripts"), "preferences-system-windows-actions");
318 
319 
320  w = new QWidget(dialog);
321  Ui_prefs_project_local ui_prefs_project_local;
322  ui_prefs_project_local.setupUi(w);
323  dialog->addPage(w, Project::local(), i18nc("@title:tab","Personal"), "preferences-desktop-user");
324 
325 
326  connect(dialog, SIGNAL(settingsChanged(QString)),Project::instance(), SLOT(populateGlossary()));
327  connect(dialog, SIGNAL(settingsChanged(QString)),Project::instance(), SLOT(populateDirModel()));
328  connect(dialog, SIGNAL(settingsChanged(QString)),TM::DBFilesModel::instance(), SLOT( updateProjectTmIndex()));
329  connect(dialog, SIGNAL(settingsChanged(QString)),this, SLOT(reflectProjectConfigChange()));
330 
331  dialog->show();
332 }
333 
334 void SettingsController::reflectProjectConfigChange()
335 {
336  //TODO check target language change: reflect changes in TM and glossary
337  TM::DBFilesModel::instance()->openDB(Project::instance()->projectID());
338 }
339 
340 void SettingsController::reflectRelativePathsHack()
341 {
342  //m_scriptsRelPrefWidget->clear();
343  QStringList actionz(m_scriptsPrefWidget->items());
344  QString projectDir(Project::instance()->projectDir());
345  int i=actionz.size();
346  while(--i>=0)
347  actionz[i]=KUrl::relativePath(projectDir,actionz.at(i));
348  m_scriptsRelPrefWidget->setItems(actionz);
349 }
350 
351 void LangCodeSaver::setLangCode(int index)
352 {
353  setText(LanguageListModel::instance()->langCodeForSortModelRow(index));
354 }
355 
356 void RelPathSaver::setText (const QString& txt)
357 {
358  QLineEdit::setText(KUrl::relativePath(Project::instance()->projectDir(),
359  txt));
360 }
361 
362 
363 
364 
365 #include "prefs.moc"
SettingsController::projectCreate
bool projectCreate()
Definition: prefs.cpp:213
RelPathSaver::setText
void setText(const QString &)
Definition: prefs.cpp:356
LanguageListModel::instance
static LanguageListModel * instance()
Definition: languagelistmodel.cpp:46
project.h
QWidget
SettingsController::reflectRelativePathsHack
void reflectRelativePathsHack()
Definition: prefs.cpp:340
ScriptsView::ScriptsView
ScriptsView(QWidget *parent)
Definition: prefs.cpp:162
ScriptsView::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *event)
Definition: prefs.cpp:167
QDropEvent::mimeData
const QMimeData * mimeData() const
SettingsController::projectConfigure
void projectConfigure()
Definition: prefs.cpp:239
ProjectModel::weaver
ThreadWeaver::Weaver * weaver()
Definition: projectmodel.h:167
QLineEdit::setText
void setText(const QString &)
Project::instance
static Project * instance()
Definition: project.cpp:67
QHBoxLayout
ProjectBase::langCode
QString langCode() const
Get LangCode.
Definition: projectbase.h:65
languagelistmodel.h
Project::local
static ProjectLocal * local()
Definition: project.h:116
prefs.h
dbfilesmodel.h
Project::potDir
QString potDir() const
Definition: project.h:69
QDir::homePath
QString homePath()
QWidget::setParent
void setParent(QWidget *parent)
Settings::self
static Settings * self()
Definition: prefs_lokalize.cpp:19
SettingsController::SettingsController
SettingsController()
Definition: prefs.cpp:80
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
Project
Singleton object that represents project.
Definition: project.h:51
QDragMoveEvent::accept
void accept()
setText
void setText(QDomElement element, QString text)
Definition: domroutines.cpp:26
QObject
QDropEvent
QString::isEmpty
bool isEmpty() const
Project::model
ProjectModel * model()
Definition: project.cpp:265
projectlocal.h
QUrl::path
QString path() const
Project::desirablePath
Q_SCRIPTABLE QString desirablePath() const
Definition: project.h:96
QVBoxLayout
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
ScriptsView
Definition: prefs.h:105
QString
QLayout::setMargin
void setMargin(int margin)
QStringList
TM::DBFilesModel::openDB
void openDB(const QString &name)
Definition: dbfilesmodel.cpp:117
QUrl
ScriptsView::dropEvent
void dropEvent(QDropEvent *event)
Definition: prefs.cpp:173
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
SettingsController::reflectProjectConfigChange
void reflectProjectConfigChange()
Definition: prefs.cpp:334
SettingsController::projectOpen
QString projectOpen(QString path=QString(), bool doOpen=true)
Definition: prefs.cpp:196
Project::poDir
QString poDir() const
Definition: project.h:68
Project::altTransDir
QString altTransDir() const
Definition: project.h:74
projectmodel.h
Project::branchDir
QString branchDir() const
Definition: project.h:70
QDragEnterEvent
prefs_lokalize.h
Project::setDefaults
void setDefaults()
Definition: project.cpp:273
QLatin1String
SettingsController
Singleton that manages cfgs for Lokalize and projects.
Definition: prefs.h:36
QMimeData::urls
QList< QUrl > urls() const
LangCodeSaver::setLangCode
void setLangCode(int)
Definition: prefs.cpp:351
SettingsController::showSettingsDialog
void showSettingsDialog()
Definition: prefs.cpp:91
SettingsController::~SettingsController
~SettingsController()
Definition: prefs.cpp:87
SettingsController::ensureProjectIsLoaded
bool ensureProjectIsLoaded()
Definition: prefs.cpp:181
SettingsController::generalSettingsChanged
void generalSettingsChanged()
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QBoxLayout::setSpacing
void setSpacing(int spacing)
TM::DBFilesModel::instance
static DBFilesModel * instance()
Definition: dbfilesmodel.cpp:46
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
QTimer::singleShot
singleShot
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