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

parley

  • sources
  • kde-4.12
  • kdeedu
  • parley
  • src
parleymainwindow.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  main part of parley
4 
5  -----------------------------------------------------------------------
6 
7  begin : Thu Mar 11 20:50:53 MET 1999
8 
9  copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
10  (C) 2004-2007 Peter Hedlund <peter.hedlund@kdemail.net>
11  (C) 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
12  (C) 2008 Daniel Laidig <d.laidig@gmx.de>
13  -----------------------------------------------------------------------
14 
15  ***************************************************************************/
16 
17 /***************************************************************************
18  * *
19  * This program is free software; you can redistribute it and/or modify *
20  * it under the terms of the GNU General Public License as published by *
21  * the Free Software Foundation; either version 2 of the License, or *
22  * (at your option) any later version. *
23  * *
24  ***************************************************************************/
25 
26 #include "parleymainwindow.h"
27 
28 #include "../config-parley.h"
29 #include "editor/editor.h"
30 #include "statistics/statisticsmainwindow.h"
31 #include "settings/parleyprefs.h"
32 #include "configure-practice/configurepracticedialog.h"
33 #include "practice/guifrontend.h"
34 #include "practice/practiceoptions.h"
35 #include "practice/practicesummarycomponent.h"
36 
37 #include "parleyactions.h"
38 
39 #include "prefs.h"
40 #include "welcomescreen/welcomescreen.h"
41 
42 #include <KActionCollection>
43 #include <KRecentFilesAction>
44 #include <KMessageBox>
45 #include <KTipDialog>
46 #include <KXMLGUIFactory>
47 #include <KXmlGuiWindow>
48 #include <KToolBar>
49 #include <KMenuBar>
50 
51 #include <QtCore/QTimer>
52 
53 using namespace Editor;
54 
55 ParleyMainWindow* ParleyMainWindow::s_instance = 0;
56 ParleyMainWindow* ParleyMainWindow::instance()
57 {
58  return s_instance;
59 }
60 
61 ParleyMainWindow::ParleyMainWindow(const KUrl& filename)
62  :KXmlGuiWindow(0)
63  ,m_currentComponent(NoComponent)
64  ,m_currentComponentWindow(0)
65  ,m_testEntryManager(this)
66 {
67  s_instance = this;
68  m_document = new ParleyDocument(this);
69 
70  setCentralWidget(new QWidget());
71  centralWidget()->setLayout(new QHBoxLayout());
72  centralWidget()->layout()->setMargin(0);
73 
74  initActions();
75 
76  bool startWithWelcomeScreen = false;
77 
78  setupGUI(ToolBar | Keys | Create);
79 
80  if ( !filename.url().isEmpty() ) {
81  m_document->open(filename);
82  } else {
83  bool openLastFile = Prefs::autoOpenLast();
84  if (openLastFile && m_recentFilesAction->actions().count() > 0
85  && m_recentFilesAction->action(m_recentFilesAction->actions().count()-1)->isEnabled() ) {
86  m_recentFilesAction->action(m_recentFilesAction->actions().count()-1)->trigger();
87  } else {
88  startWithWelcomeScreen = true;
89  }
90  }
91 
92  // save position of dock windows etc
93  setAutoSaveSettings();
94 
95  if (startWithWelcomeScreen) {
96  showWelcomeScreen();
97  } else {
98  showEditor();
99  }
100 
101  connect(this, SIGNAL(preferencesChanged()), this, SLOT(slotApplyPreferences()));
102  menuBar()->show();
103 
104  // finally show tip-of-day (if the user wants it)
105  //QTimer::singleShot( 0, this, SLOT( startupTipOfDay() ) );
106 }
107 
108 ParleyMainWindow::~ParleyMainWindow()
109 {
110  guiFactory()->removeClient(m_currentComponentWindow);
111  centralWidget()->layout()->removeWidget(m_currentComponentWindow);
112  delete m_currentComponentWindow;
113  delete m_document;
114 }
115 
116 void ParleyMainWindow::addRecentFile(const KUrl &url, const QString &name)
117 {
118  m_recentFilesAction->addUrl(url, name);
119  m_recentFilesAction->saveEntries(KGlobal::config()->group("Recent Files"));
120 }
121 
122 void ParleyMainWindow::updateRecentFilesModel()
123 {
124  emit recentFilesChanged();
125 }
126 
127 void ParleyMainWindow::saveOptions()
128 {
129  Prefs::self()->writeConfig();
130 }
131 
132 void ParleyMainWindow::slotUpdateWindowCaption()
133 {
134  QString title;
135  bool modified = false;
136  if (m_document->document()) {
137  title = m_document->document()->title();
138  modified = m_document->document()->isModified();
139  if (title == i18n("Untitled")) {
140  title.clear();
141  }
142  }
143  setCaption(title, modified);
144 }
145 
146 void ParleyMainWindow::slotGeneralOptions()
147 {
148  ParleyPrefs* dialog = new ParleyPrefs(m_document->document(), this, "settings", Prefs::self());
149  connect(dialog, SIGNAL(settingsChanged(const QString &)), this, SIGNAL(preferencesChanged()));
150  dialog->show();
151 }
152 
153 void ParleyMainWindow::slotApplyPreferences()
154 {
155  m_document->enableAutoBackup((m_currentComponent != WelcomeComponent) && Prefs::autoBackup());
156 }
157 
158 void ParleyMainWindow::slotCloseDocument()
159 {
160  if (!queryClose()) {
161  return;
162  }
163  showWelcomeScreen();
164  m_document->close();
165 }
166 
167 void ParleyMainWindow::configurePractice()
168 {
169  ConfigurePracticeDialog configurePracticeDialog(m_document->document(), this, "practice settings", Prefs::self());
170  configurePracticeDialog.exec();
171 }
172 
173 void ParleyMainWindow::startPractice()
174 {
175  switchComponent(PracticeComponent);
176 }
177 
178 void ParleyMainWindow::practiceFinished()
179 {
180  switchComponent(m_componentBeforePractice);
181 }
182 
183 bool ParleyMainWindow::queryClose()
184 {
185  bool erg = queryExit();
186  if (erg && m_document->document()) {
187  m_document->document()->setModified(false); // avoid double query on exit via system menu
188  }
189  return erg;
190 }
191 
192 bool ParleyMainWindow::queryExit()
193 {
194  if (!m_document->document() || !m_document->document()->isModified()) {
195  return true;
196  }
197  saveOptions();
198 
199  bool save = Prefs::autoSave(); //save without asking
200 
201  if (!save) {
202  int exit = KMessageBox::warningYesNoCancel(this, i18n("Vocabulary is modified.\n\nSave file before exit?\n"),
203  "", KStandardGuiItem::save(), KStandardGuiItem::discard());
204  if (exit == KMessageBox::Yes) {
205  save = true; // save and exit
206  } else if (exit == KMessageBox::No) {
207  save = false; // don't save but exit
208  } else {
209  return false; // continue work
210  }
211  }
212 
213  if (save) {
214  m_document->save(); // save and exit
215  }
216  return true;
217 }
218 
219 QSize ParleyMainWindow::sizeHint() const
220 {
221  return QSize(800, 600).expandedTo(KXmlGuiWindow::minimumSizeHint());
222 }
223 
224 void ParleyMainWindow::tipOfDay()
225 {
226  KTipDialog::showTip(this, "parley/tips", true);
227 }
228 
229 void ParleyMainWindow::startupTipOfDay()
230 {
231  KTipDialog::showTip(this, "parley/tips");
232 }
233 
234 void ParleyMainWindow::initActions()
235 {
236  ParleyActions::create(ParleyActions::FileNew, m_document, SLOT(slotFileNew()), actionCollection());
237  ParleyActions::create(ParleyActions::FileOpen, m_document, SLOT(slotFileOpen()), actionCollection());
238  ParleyActions::createDownloadAction(m_document, SLOT(slotGHNS()), actionCollection());
239  ParleyActions::create(ParleyActions::FileOpenDownloaded, m_document, SLOT(openGHNS()), actionCollection());
240 
241  m_recentFilesAction = ParleyActions::createRecentFilesAction(
242  m_document, SLOT(slotFileOpenRecent(const KUrl&)), actionCollection());
243 
244  m_recentFilesAction->loadEntries(KGlobal::config()->group("Recent Files"));
245 
246  ParleyActions::create(ParleyActions::FileSave, m_document, SLOT(save()), actionCollection());
247  ParleyActions::create(ParleyActions::FileSaveAs, m_document, SLOT(saveAs()), actionCollection());
248  #ifdef HAVE_LIBXSLT
249  ParleyActions::create(ParleyActions::FileExport, m_document, SLOT(exportDialog()), actionCollection());
250  #endif
251 
252  ParleyActions::create(ParleyActions::FileProperties, m_document, SLOT(documentProperties()), actionCollection());
253 
254  ParleyActions::create(ParleyActions::FileClose, this, SLOT(slotCloseDocument()), actionCollection());
255  ParleyActions::create(ParleyActions::FileQuit, this, SLOT(close()), actionCollection());
256  ParleyActions::create(ParleyActions::Preferences, this, SLOT(slotGeneralOptions()), actionCollection());
257 
258  actionCollection()->addAction(KStandardAction::TipofDay, "help_tipofday", this, SLOT( tipOfDay() ));
259 }
260 
261 void ParleyMainWindow::showWelcomeScreen()
262 {
263  switchComponent(WelcomeComponent);
264 }
265 
266 void ParleyMainWindow::showEditor()
267 {
268  switchComponent(EditorComponent);
269 }
270 
271 void ParleyMainWindow::showPracticeConfiguration()
272 {
273  switchComponent(ConfigurePracticeComponent);
274 }
275 
276 void ParleyMainWindow::showPractice()
277 {
278  switchComponent(PracticeComponent);
279 }
280 
281 void ParleyMainWindow::showPracticeSummary()
282 {
283  switchComponent(PracticeSummary);
284 }
285 
286 void ParleyMainWindow::switchComponent(Component component)
287 {
288  if (component == PracticeComponent) {
289 
290  StatisticsMainWindow *statisticsWidget = qobject_cast<StatisticsMainWindow*>(m_currentComponentWindow);
291  if (statisticsWidget) {
292  statisticsWidget->syncConfig();
293  }
294 
295  // Don't start a practice when there are no words to practice.
296  // This has to be checked before deleting the old component.
297  m_testEntryManager.setDocument(m_document->document());
298  if (!m_testEntryManager.totalEntryCount()) {
299  return;
300  }
301  }
302 
303  // Remove and delete the old component window if there is one active.
304  if (m_currentComponentWindow) {
305  guiFactory()->removeClient(m_currentComponentWindow);
306  centralWidget()->layout()->removeWidget(m_currentComponentWindow);
307  delete(m_currentComponentWindow);
308  }
309 
310  switch (component) {
311  case WelcomeComponent: {
312  WelcomeScreen *welcome = new WelcomeScreen(this);
313  m_currentComponentWindow = welcome;
314  showDocumentActions(true, false);
315  welcome->updateRecentFilesModel();
316  break;
317  }
318  case ConfigurePracticeComponent: {
319  StatisticsMainWindow *statisticsWidget = new StatisticsMainWindow(m_document->document(), this);
320  m_currentComponentWindow = statisticsWidget;
321  showDocumentActions(true, true);
322  break;
323  }
324  case EditorComponent: {
325  EditorWindow *editor = new EditorWindow(this);
326  m_currentComponentWindow = editor;
327  showDocumentActions(true, true);
328  editor->updateDocument(m_document->document());
329  break;
330  }
331  case PracticeComponent: {
332  m_document->document()->setModified(true);
333  Practice::PracticeMainWindow *practiceWindow = new Practice::PracticeMainWindow(&m_testEntryManager, this);
334  connect(practiceWindow, SIGNAL(stopPractice()), this, SLOT(showPracticeSummary()));
335  m_currentComponentWindow = practiceWindow;
336  showDocumentActions(false, false);
337  practiceWindow->startPractice();
338  break;
339  }
340  case PracticeSummary: {
341  Practice::PracticeSummaryComponent* summary = new Practice::PracticeSummaryComponent(&m_testEntryManager, this);
342  m_currentComponentWindow = summary;
343  showDocumentActions(true, true);
344  break;
345  }
346  default:
347  break;
348  }
349  //kDebug() << "new component" << m_currentComponentWindow;
350 
351  guiFactory()->addClient(m_currentComponentWindow);
352  centralWidget()->layout()->addWidget(m_currentComponentWindow);
353  m_currentComponentWindow->show();
354  switch (component) {
355  case WelcomeComponent: {
356  setVisibleToolbar(QString());
357  break;
358  }
359  case ConfigurePracticeComponent: {
360  setVisibleToolbar("statisticsToolBar");
361  break;
362  }
363  case EditorComponent: {
364  setVisibleToolbar("editorToolBar");
365  break;
366  }
367  case PracticeComponent: {
368  setVisibleToolbar("practiceToolBar");
369  break;
370  }
371  case PracticeSummary: {
372  setVisibleToolbar("practiceSummaryToolBar");
373  break;
374  }
375  default:
376  break;
377  }
378  m_currentComponent = component;
379  setupToolbarMenuActions();
380 }
381 
382 void ParleyMainWindow::showDocumentActions(bool open, bool edit)
383 {
384  actionCollection()->action("file_new")->setVisible(open);
385  actionCollection()->action("file_open")->setVisible(open);
386  actionCollection()->action("file_open_recent")->setVisible(open);
387  actionCollection()->action("file_ghns")->setVisible(open);
388  actionCollection()->action("file_open_downloaded")->setVisible(open);
389 
390  actionCollection()->action("file_save")->setVisible(edit);
391  actionCollection()->action("file_save_as")->setVisible(edit);
392  actionCollection()->action("file_close")->setVisible(edit);
393 #ifdef HAVE_LIBXSLT
394  actionCollection()->action("file_export")->setVisible(edit);
395 #endif
396  actionCollection()->action("file_properties")->setVisible(edit);
397  actionCollection()->action("file_close")->setVisible(edit);
398 }
399 
400 void ParleyMainWindow::setVisibleToolbar(const QString& name)
401 {
402  Q_FOREACH(KToolBar *toolbar, toolBars()) {
403  if (toolbar && toolbar->objectName() == name) {
404  toolbar->show();
405  }
406  else if (toolbar) {
407  toolbar->hide();
408  }
409  }
410 }
411 
412 ParleyDocument* ParleyMainWindow::parleyDocument()
413 {
414  return m_document;
415 }
416 
417 ParleyMainWindow::Component ParleyMainWindow::currentComponent()
418 {
419  return m_currentComponent;
420 }
421 
422 #include "parleymainwindow.moc"
statisticsmainwindow.h
ParleyMainWindow::saveOptions
void saveOptions()
save the app-specific options on slotAppExit or by an Options dialog
Definition: parleymainwindow.cpp:127
ParleyMainWindow::currentComponent
Component currentComponent()
Definition: parleymainwindow.cpp:417
ParleyActions::create
KAction * create(ParleyAction id, const QObject *recvr, const char *slot, QObject *parent)
Definition: parleyactions.cpp:62
practiceoptions.h
ParleyMainWindow::showPractice
void showPractice()
Definition: parleymainwindow.cpp:276
ParleyActions::FileNew
Definition: parleyactions.h:24
Prefs::autoSave
static bool autoSave()
Get If true, vocabularies are automatically saved on close and exit.
Definition: prefs.h:160
ParleyMainWindow::showEditor
void showEditor()
Definition: parleymainwindow.cpp:266
ParleyMainWindow::queryClose
bool queryClose()
When quitting, ask for confirmation if the doc has not been saved.
Definition: parleymainwindow.cpp:183
ParleyMainWindow
Definition: parleymainwindow.h:68
ConfigurePracticeDialog
Definition: configurepracticedialog.h:32
QWidget
configurepracticedialog.h
ParleyMainWindow::practiceFinished
void practiceFinished()
Definition: parleymainwindow.cpp:178
ParleyDocument::document
KEduVocDocument * document()
Definition: parleydocument.cpp:93
prefs.h
ParleyMainWindow::showWelcomeScreen
void showWelcomeScreen()
Definition: parleymainwindow.cpp:261
ParleyMainWindow::PracticeSummary
Definition: parleymainwindow.h:84
ParleyMainWindow::setVisibleToolbar
void setVisibleToolbar(const QString &name)
Definition: parleymainwindow.cpp:400
ParleyMainWindow::showDocumentActions
void showDocumentActions(bool open, bool edit)
Shows or hides actions that are only relevant when a document is opened.
Definition: parleymainwindow.cpp:382
welcomescreen.h
Practice::TestEntryManager::setDocument
void setDocument(KEduVocDocument *doc)
Definition: testentrymanager.cpp:50
ParleyMainWindow::showPracticeSummary
void showPracticeSummary()
Definition: parleymainwindow.cpp:281
ParleyActions::FileOpen
Definition: parleyactions.h:25
editor.h
parleyactions.h
Prefs::autoOpenLast
static bool autoOpenLast()
Get If true, on each application start the last opened file will be loaded.
Definition: prefs.h:141
ParleyMainWindow::switchComponent
void switchComponent(Component component)
Definition: parleymainwindow.cpp:286
Prefs::self
static Prefs * self()
Definition: prefs.cpp:17
ParleyActions::FileProperties
Definition: parleyactions.h:28
ParleyDocument::save
void save()
save a document
Definition: parleydocument.cpp:235
ParleyMainWindow::EditorComponent
Definition: parleymainwindow.h:81
ParleyActions::FileExport
Definition: parleyactions.h:27
ParleyMainWindow::slotApplyPreferences
void slotApplyPreferences()
Definition: parleymainwindow.cpp:153
ParleyDocument
Definition: parleydocument.h:29
parleyprefs.h
WelcomeScreen::updateRecentFilesModel
void updateRecentFilesModel()
Definition: welcomescreen.cpp:89
KXmlGuiWindow
ParleyMainWindow::instance
static ParleyMainWindow * instance()
Definition: parleymainwindow.cpp:56
ParleyMainWindow::queryExit
bool queryExit()
overloaded for Message box on last window exit
Definition: parleymainwindow.cpp:192
ParleyMainWindow::preferencesChanged
void preferencesChanged()
ParleyMainWindow::showPracticeConfiguration
void showPracticeConfiguration()
Definition: parleymainwindow.cpp:271
ParleyMainWindow::ConfigurePracticeComponent
Definition: parleymainwindow.h:82
StatisticsMainWindow
Definition: statisticsmainwindow.h:30
ParleyActions::FileClose
Definition: parleyactions.h:29
ParleyPrefs
Definition: parleyprefs.h:35
ParleyDocument::enableAutoBackup
void enableAutoBackup(bool enable)
Definition: parleydocument.cpp:482
Practice::PracticeMainWindow
Definition: practicemainwindow.h:29
ParleyMainWindow::sizeHint
QSize sizeHint() const
Definition: parleymainwindow.cpp:219
Practice::TestEntryManager::totalEntryCount
int totalEntryCount()
The number of entries in the practice.
Definition: testentrymanager.cpp:134
ParleyMainWindow::slotGeneralOptions
void slotGeneralOptions()
set up options
Definition: parleymainwindow.cpp:146
Editor::EditorWindow::updateDocument
void updateDocument(KEduVocDocument *doc)
Set the current doc (after creating a new one or opening a file)
Definition: editor.cpp:98
ParleyActions::FileSave
Definition: parleyactions.h:26
ParleyMainWindow::startupTipOfDay
void startupTipOfDay()
Show the tip of the day - the startup version that can be disabled.
Definition: parleymainwindow.cpp:229
ParleyActions::createDownloadAction
KAction * createDownloadAction(const QObject *recvr, const char *slot, KActionCollection *collection)
Definition: parleyactions.cpp:181
ParleyActions::createRecentFilesAction
KRecentFilesAction * createRecentFilesAction(const QObject *recvr, const char *slot, QObject *parent)
Definition: parleyactions.cpp:176
ParleyMainWindow::Component
Component
enum for the different components that can be displayed
Definition: parleymainwindow.h:78
ParleyMainWindow::slotCloseDocument
void slotCloseDocument()
Definition: parleymainwindow.cpp:158
parleymainwindow.h
ParleyMainWindow::PracticeComponent
Definition: parleymainwindow.h:83
ParleyActions::Preferences
Definition: parleyactions.h:30
WelcomeScreen
Definition: welcomescreen.h:30
ParleyMainWindow::updateRecentFilesModel
void updateRecentFilesModel()
update the list of recent files in the welcome screen
Definition: parleymainwindow.cpp:122
ParleyActions::FileSaveAs
Definition: parleyactions.h:26
guifrontend.h
Practice::PracticeSummaryComponent
Definition: practicesummarycomponent.h:24
ParleyActions::FileQuit
Definition: parleyactions.h:29
ParleyMainWindow::initActions
void initActions()
setup the action (menus etc)
Definition: parleymainwindow.cpp:234
Prefs::autoBackup
static bool autoBackup()
Get If true, a backup is saved every BackupTime minutes.
Definition: prefs.h:198
Editor::EditorWindow
Definition: editor.h:46
practicesummarycomponent.h
ParleyMainWindow::WelcomeComponent
Definition: parleymainwindow.h:80
Practice::PracticeMainWindow::startPractice
void startPractice()
Definition: practicemainwindow.cpp:150
ParleyMainWindow::addRecentFile
void addRecentFile(const KUrl &url, const QString &name)
add a new entry to the list of recent files
Definition: parleymainwindow.cpp:116
ParleyMainWindow::recentFilesChanged
void recentFilesChanged()
ParleyMainWindow::~ParleyMainWindow
~ParleyMainWindow()
Definition: parleymainwindow.cpp:108
ParleyDocument::open
bool open(const KUrl &)
Opens the given url, displays an error message and returns false on failure.
Definition: parleydocument.cpp:182
ParleyMainWindow::tipOfDay
void tipOfDay()
Show the tip of the day (force it to be shown)
Definition: parleymainwindow.cpp:224
ParleyMainWindow::configurePractice
void configurePractice()
Definition: parleymainwindow.cpp:167
ParleyMainWindow::parleyDocument
ParleyDocument * parleyDocument()
Return the ParleyDocument member object.
Definition: parleymainwindow.cpp:412
ParleyDocument::close
void close()
Definition: parleydocument.cpp:209
StatisticsMainWindow::syncConfig
void syncConfig()
Definition: statisticsmainwindow.cpp:78
ParleyMainWindow::startPractice
void startPractice()
Definition: parleymainwindow.cpp:173
ParleyActions::FileOpenDownloaded
Definition: parleyactions.h:25
ParleyMainWindow::slotUpdateWindowCaption
void slotUpdateWindowCaption()
Update the title bar of the main window with the current document.
Definition: parleymainwindow.cpp:132
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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