summaryrefslogtreecommitdiffstats
path: root/kvoctrain/kvoctrain/common-dialogs/kvoctrainprefs.cpp
blob: dc18ac4e324e101c8cd8449fe5a2e074ae5c8d36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/***************************************************************************
             kvoctrainprefs.cpp  -  KVocTrain configuration dialog

                             -------------------
    begin                : Fri Mar 25 2005

    copyright            : (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <tqwidgetstack.h>
#include <tqlayout.h>
#include <tqradiobutton.h>
#include <tqcheckbox.h>
#include <tqlistview.h>
#include <tqlabel.h>

#include <tdelocale.h>
#include <kstandarddirs.h>
#include <kiconloader.h>
#include <krestrictedline.h>
#include <tdemessagebox.h>
#include <kpushbutton.h>
#include <kdebug.h>
#include <tdeconfigskeleton.h>
#include <kcolorbutton.h>
#include <tdefontrequester.h>
#include <kcombobox.h>

#include "kvoctrainprefs.h"
#include "kvoctraindoc.h"
#include "generaloptions.h"
#include "languageoptions.h"
#include "viewoptions.h"
#include "pasteoptions.h"
#include "groupoptions.h"
#include "queryoptions.h"
#include "thresholdoptions.h"
#include "blockoptions.h"
#include "langset.h"
#include "QueryManager.h"
#include "profilesdialog.h"

static const char unapplied[] = I18N_NOOP(
    "You have made changes that are not yet applied.\n"
    "If you save a profile, those changes will not be included.\n"
    "Do you wish to continue?");

KVocTrainPrefs::KVocTrainPrefs(LangSet & ls, kvoctrainDoc * doc, KComboBox * lessons, QueryManager * m, TQWidget *parent,
  const char *name,  TDEConfigSkeleton *config, DialogType dialogType, int /*dialogButtons*/, ButtonCode /*defaultButton*/,
  bool /*modal*/)
  : TDEConfigDialog(parent, name, config, dialogType, Default|Ok|Apply|Cancel|Help|User1, Ok, true), m_langSet(ls)
{
  m_config = config;
  m_queryManager = m;

  m_generalOptions = new GeneralOptions(0, "General Settings");
  addPage(m_generalOptions, i18n("General"), "kvoctrain", i18n("General Settings"), true);

  m_languageOptions = new LanguageOptions(m_langSet, 0, "Language Settings");
  addPage(m_languageOptions, i18n("Languages"), "set_language", i18n("Language Settings"), true);
  connect(m_languageOptions, TQT_SIGNAL(widgetModified()), this, TQT_SLOT(updateButtons()));

  m_viewOptions = new ViewOptions(0, "View Settings");
  addPage(m_viewOptions, i18n("View"), "view_choose", i18n("View Settings"), true);

  m_pasteOptions = new PasteOptions(m_langSet, doc, 0, "Copy & Paste Settings");
  addPage(m_pasteOptions, i18n("Copy & Paste"), "editpaste", i18n("Copy & Paste Settings"), true);
  connect(m_pasteOptions, TQT_SIGNAL(widgetModified()), this, TQT_SLOT(updateButtons()));

  m_queryOptions = new QueryOptions(0, "Query Settings");
  addPage(m_queryOptions, i18n("Query"), "run_query", i18n("Query Settings"), true);

  m_thresholdOptions = new ThresholdOptions(lessons, m_queryManager, 0, "Threshold Settings");
  addPage(m_thresholdOptions, i18n("Thresholds"), "configure", i18n("Threshold Settings"), true);
  connect(m_thresholdOptions, TQT_SIGNAL(widgetModified()), this, TQT_SLOT(updateButtons()));

  m_blockOptions = new BlockOptions(0, "Blocking Settings");
  addPage(m_blockOptions, i18n("Blocking"), "configure", i18n("Blocking Settings"), true);
  connect(m_blockOptions, TQT_SIGNAL(widgetModified()), this, TQT_SLOT(updateButtons()));
  connect(m_blockOptions, TQT_SIGNAL(blockExpireChanged(bool, bool)), m_thresholdOptions, TQT_SLOT(slotBlockExpire(bool, bool)));

  setButtonGuiItem(KDialogBase::User1, KGuiItem(i18n("&Profiles...")));
  setButtonTip(KDialogBase::User1, i18n("Save or load specific Query settings which consist in a profile"));
  setButtonWhatsThis(KDialogBase::User1, i18n("A Profile is a set of settings (settings related to queries) which you can save/load in order to use again later. This button allows you to see existing profiles, to load a new profile and to save your current settings in a  new profile."));
}

void KVocTrainPrefs::selectPage(int index)
{
  showPage(index);
}

bool KVocTrainPrefs::hasChanged()
{
  return m_pasteOptions->hasChanged() |
         m_languageOptions->hasChanged() |
         m_thresholdOptions->hasChanged() |
         m_blockOptions->hasChanged();
}

bool KVocTrainPrefs::isDefault()
{
  return m_pasteOptions->isDefault() &&
         m_languageOptions->isDefault() &&
         m_thresholdOptions->isDefault() &&
         m_blockOptions->isDefault();
}

void KVocTrainPrefs::updateSettings()
{
  m_pasteOptions->updateSettings();
  m_languageOptions->updateSettings();
  m_thresholdOptions->updateSettings();
  m_blockOptions->updateSettings();
  emit settingsChanged();
}

void KVocTrainPrefs::updateWidgetsDefault()
{
  bool bUseDefaults = m_config->useDefaults(true);
  m_pasteOptions->updateWidgets();
  m_languageOptions->updateWidgets();
  m_thresholdOptions->updateWidgets();
  m_blockOptions->updateWidgets();
  m_config->useDefaults(bUseDefaults);
}

void KVocTrainPrefs::slotUser1()
{
  bool showDlg = true;
  if (hasChanged())
    if (KMessageBox::Yes != KMessageBox::questionYesNo(this, i18n(unapplied), i18n("Unapplied Changes")))
      showDlg = false;

  if (showDlg)
  {
    ProfilesDialog * dlg = new ProfilesDialog(m_queryManager, this, 0, true);
    connect(dlg, TQT_SIGNAL(profileActivated()), this, TQT_SLOT(updateWidgets()));
    dlg->show();
  }
}

void KVocTrainPrefs::updateWidgets()
{
  m_queryOptions->updateWidgets();
  m_thresholdOptions->updateWidgets();
  m_blockOptions->updateWidgets();
}

#include "kvoctrainprefs.moc"