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

parley

  • sources
  • kde-4.14
  • kdeedu
  • parley
  • src
  • practice
  • configure
blockoptions.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  blocking options for Parley
4 
5  -----------------------------------------------------------------------
6 
7  begin : Tue Apr 5 2005
8 
9  copyright :(C) 2005 Peter Hedlund <peter.hedlund@kdemail.net>
10 
11  -----------------------------------------------------------------------
12 
13  ***************************************************************************/
14 
15 /***************************************************************************
16  * *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or *
20  * (at your option) any later version. *
21  * *
22  ***************************************************************************/
23 
24 #include "blockoptions.h"
25 
26 #include <QCheckBox>
27 
28 #include <klocale.h>
29 #include <kmessagebox.h>
30 #include <KComboBox>
31 
32 #include "prefs.h"
33 
34 struct ListRef
35 {
36  const char *text;
37  long int num;
38 };
39 
40 static ListRef date_itemlist [] = {
41  {
42  I18N_NOOP("Do not Care"), 0
43  },
44 
45  {I18N_NOOP("30 Min"), 30 * 60},
46  {I18N_NOOP("1 Hour"), 1 * 60 * 60},
47  {I18N_NOOP("2 Hours"), 2 * 60 * 60},
48  {I18N_NOOP("4 Hours"), 4 * 60 * 60},
49  {I18N_NOOP("8 Hours"), 8 * 60 * 60},
50  {I18N_NOOP("12 Hours"), 12 * 60 * 60},
51  {I18N_NOOP("18 Hours"), 18 * 60 * 60},
52 
53  {I18N_NOOP("1 Day"), 1 * 60 * 60 * 24},
54  {I18N_NOOP("2 Days"), 2 * 60 * 60 * 24},
55  {I18N_NOOP("3 Days"), 3 * 60 * 60 * 24},
56  {I18N_NOOP("4 Days"), 4 * 60 * 60 * 24},
57  {I18N_NOOP("5 Days"), 5 * 60 * 60 * 24},
58  {I18N_NOOP("6 Days"), 6 * 60 * 60 * 24},
59 
60  {I18N_NOOP("1 Week"), 1 * 60 * 60 * 24 * 7},
61  {I18N_NOOP("2 Weeks"), 2 * 60 * 60 * 24 * 7},
62  {I18N_NOOP("3 Weeks"), 3 * 60 * 60 * 24 * 7},
63  {I18N_NOOP("4 Weeks"), 4 * 60 * 60 * 24 * 7},
64 
65  {I18N_NOOP("1 Month"), 1 * 60 * 60 * 24 * 30},
66  {I18N_NOOP("2 Months"), 2 * 60 * 60 * 24 * 30},
67  {I18N_NOOP("3 Months"), 3 * 60 * 60 * 24 * 30},
68  {I18N_NOOP("4 Months"), 4 * 60 * 60 * 24 * 30},
69  {I18N_NOOP("5 Months"), 5 * 60 * 60 * 24 * 30},
70  {I18N_NOOP("6 Months"), 6 * 60 * 60 * 24 * 30},
71  {I18N_NOOP("10 Months"), 10 * 60 * 60 * 24 * 30},
72  {I18N_NOOP("12 Months"), 12 * 60 * 60 * 24 * 30},
73  {0 , 0}
74 };
75 
76 
77 BlockOptions::BlockOptions(QWidget* parent): QWidget(parent)
78 {
79  setupUi(this);
80  connect(expire1, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
81  connect(block1, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
82  connect(expire2, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
83  connect(block2, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
84  connect(expire3, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
85  connect(block3, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
86  connect(expire4, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
87  connect(block4, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
88  connect(expire5, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
89  connect(block5, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
90  connect(expire6, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
91  connect(block6, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
92  connect(expire7, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
93  connect(block7, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
94 
95  connect(kcfg_Block, SIGNAL(toggled(bool)), this, SLOT(slotBlockToggled(bool)));
96  connect(kcfg_Expire, SIGNAL(toggled(bool)), this, SLOT(slotExpireToggled(bool)));
97 
98  fillWidgets();
99  updateWidgets();
100 }
101 
102 void BlockOptions::fillWidgets()
103 {
104  fillComboBox(block1);
105  fillComboBox(block2);
106  fillComboBox(block3);
107  fillComboBox(block4);
108  fillComboBox(block5);
109  fillComboBox(block6);
110  fillComboBox(block7);
111 
112  m_blockComboList.append(block1);
113  m_blockComboList.append(block2);
114  m_blockComboList.append(block3);
115  m_blockComboList.append(block4);
116  m_blockComboList.append(block5);
117  m_blockComboList.append(block6);
118  m_blockComboList.append(block7);
119 
120  fillComboBox(expire1);
121  fillComboBox(expire2);
122  fillComboBox(expire3);
123  fillComboBox(expire4);
124  fillComboBox(expire5);
125  fillComboBox(expire6);
126  fillComboBox(expire7);
127 
128  m_expireComboList.append(expire1);
129  m_expireComboList.append(expire2);
130  m_expireComboList.append(expire3);
131  m_expireComboList.append(expire4);
132  m_expireComboList.append(expire5);
133  m_expireComboList.append(expire6);
134  m_expireComboList.append(expire7);
135 }
136 
137 void BlockOptions::updateWidgets()
138 {
139  updateComboBox(Prefs::blockItem(KV_LEV1_GRADE), block1);
140  updateComboBox(Prefs::blockItem(KV_LEV2_GRADE), block2);
141  updateComboBox(Prefs::blockItem(KV_LEV3_GRADE), block3);
142  updateComboBox(Prefs::blockItem(KV_LEV4_GRADE), block4);
143  updateComboBox(Prefs::blockItem(KV_LEV5_GRADE), block5);
144  updateComboBox(Prefs::blockItem(KV_LEV6_GRADE), block6);
145  updateComboBox(Prefs::blockItem(KV_LEV7_GRADE), block7);
146 
147  updateComboBox(Prefs::expireItem(KV_LEV1_GRADE), expire1);
148  updateComboBox(Prefs::expireItem(KV_LEV2_GRADE), expire2);
149  updateComboBox(Prefs::expireItem(KV_LEV3_GRADE), expire3);
150  updateComboBox(Prefs::expireItem(KV_LEV4_GRADE), expire4);
151  updateComboBox(Prefs::expireItem(KV_LEV5_GRADE), expire5);
152  updateComboBox(Prefs::expireItem(KV_LEV6_GRADE), expire6);
153  updateComboBox(Prefs::expireItem(KV_LEV7_GRADE), expire7);
154 
155  bool block = Prefs::block();
156  kcfg_Block->setChecked(block);
157  block1->setEnabled(block);
158  block2->setEnabled(block);
159  block3->setEnabled(block);
160  block4->setEnabled(block);
161  block5->setEnabled(block);
162  block6->setEnabled(block);
163  block7->setEnabled(block);
164 
165  bool expire = Prefs::expire();
166  kcfg_Expire->setChecked(expire);
167  expire1->setEnabled(expire);
168  expire2->setEnabled(expire);
169  expire3->setEnabled(expire);
170  expire4->setEnabled(expire);
171  expire5->setEnabled(expire);
172  expire6->setEnabled(expire);
173  expire7->setEnabled(expire);
174 }
175 
176 void BlockOptions::fillComboBox(KComboBox * cb)
177 {
178  ListRef *ref = date_itemlist;
179 
180  cb->clear();
181  while (ref->text != 0) {
182  cb->addItem(i18n(ref->text));
183  ref++;
184  }
185 }
186 
187 void BlockOptions::updateComboBox(int value, KComboBox * cb)
188 {
189  ListRef *ref = date_itemlist;
190  int index = 0;
191 
192  while (ref->text != 0) {
193  if (value == ref->num)
194  index = ref - date_itemlist;
195  ref++;
196  }
197  cb->setCurrentIndex(index);
198 }
199 
200 void BlockOptions::slotBlockToggled(bool state)
201 {
202  block1->setEnabled(state);
203  block2->setEnabled(state);
204  block3->setEnabled(state);
205  block4->setEnabled(state);
206  block5->setEnabled(state);
207  block6->setEnabled(state);
208  block7->setEnabled(state);
209 }
210 
211 void BlockOptions::slotExpireToggled(bool state)
212 {
213  expire1->setEnabled(state);
214  expire2->setEnabled(state);
215  expire3->setEnabled(state);
216  expire4->setEnabled(state);
217  expire5->setEnabled(state);
218  expire6->setEnabled(state);
219  expire7->setEnabled(state);
220 }
221 
222 void BlockOptions::slotComboBoxActivated(int)
223 {
224  emit widgetModified();
225  checkValidity();
226 }
227 
228 
229 void BlockOptions::checkValidity()
230 {
231  QString message;
232  bool found = false;
233  for (int i = 1; i <= 6; i++) {
234  if (kcfg_Block->isChecked()) {
235  /*if (Prefs::blockItem(i-1) != 0 &&
236  Prefs::blockItem(i) != 0 &&
237  Prefs::blockItem(i-1) >= Prefs::blockItem(i))*/
238  if (date_itemlist[m_blockComboList[i - 1]->currentIndex()].num != 0 &&
239  date_itemlist[m_blockComboList[i]->currentIndex()].num != 0 &&
240  date_itemlist[m_blockComboList[i - 1]->currentIndex()].num >= date_itemlist[m_blockComboList[i]->currentIndex()].num) {
241  QString format;
242  if (!found)
243  message.append(i18n("Illogical blocking times.\n"));
244  found = true;
245  message.append(i18n("The time for level %1 should be lower than the time for level %2.\n", i, i + 1));
246  }
247  }
248  }
249 
250  for (int i = 1; i <= 6; i++) {
251  found = false;
252  if (kcfg_Expire->isChecked()) {
253  if (date_itemlist[m_expireComboList[i - 1]->currentIndex()].num != 0 &&
254  date_itemlist[m_expireComboList[i]->currentIndex()].num != 0 &&
255  date_itemlist[m_expireComboList[i - 1]->currentIndex()].num >=
256  date_itemlist[m_expireComboList[i]->currentIndex()].num) {
257  QString format;
258  if (!found)
259  message.append(i18n("\nIllogical expiration times.\n"));
260  found = true;
261  message.append(i18n("The time for level %1 should be lower than the time for level %2.\n", i, i + 1));
262  }
263  }
264  }
265 
266  if (message.length() == 0) {
267  found = false;
268  for (int i = 0; i <= 6; i++) {
269  if (kcfg_Block->isChecked() &&
270  kcfg_Expire->isChecked() &&
271  m_expireComboList[i]->currentIndex() >= 0 &&
272  m_blockComboList[i]->currentIndex() >= 0 &&
273  date_itemlist[m_expireComboList[i]->currentIndex()].num != 0 &&
274  date_itemlist[m_blockComboList[i]->currentIndex()].num != 0 &&
275  date_itemlist[m_blockComboList[i]->currentIndex()].num >= date_itemlist[m_expireComboList[i]->currentIndex()].num) {
276  QString format;
277  if (!found)
278  message.append(i18n("\nIllogical blocking vs. expiration times.\n"));
279  found = true;
280  message.append(i18n("The blocking time at level %1 should be lower than the expiration time.\n", i + 1));
281  }
282  }
283  }
284 
285  if (message.length() != 0)
286  KMessageBox::sorry(this, message, i18n("Illogical Values"));
287 }
288 
289 
290 bool BlockOptions::isDefault()
291 {
292  if (block7->currentIndex() < 0 ||
293  block6->currentIndex() < 0 ||
294  block5->currentIndex() < 0 ||
295  block4->currentIndex() < 0 ||
296  block3->currentIndex() < 0 ||
297  block2->currentIndex() < 0 ||
298  block1->currentIndex() < 0 ||
299  expire7->currentIndex() < 0 ||
300  expire6->currentIndex() < 0 ||
301  expire5->currentIndex() < 0 ||
302  expire4->currentIndex() < 0 ||
303  expire3->currentIndex() < 0 ||
304  expire2->currentIndex() < 0 ||
305  expire1->currentIndex() < 0)
306  return false;
307 
308  return date_itemlist[block7->currentIndex()].num == 5184000 &&
309  date_itemlist[block6->currentIndex()].num == 2592000 &&
310  date_itemlist[block5->currentIndex()].num == 1209600 &&
311  date_itemlist[block4->currentIndex()].num == 604800 &&
312  date_itemlist[block3->currentIndex()].num == 345600 &&
313  date_itemlist[block2->currentIndex()].num == 172800 &&
314  date_itemlist[block1->currentIndex()].num == 86400 &&
315  date_itemlist[expire7->currentIndex()].num == 10368000 &&
316  date_itemlist[expire6->currentIndex()].num == 5184000 &&
317  date_itemlist[expire5->currentIndex()].num == 2592000 &&
318  date_itemlist[expire4->currentIndex()].num == 1209600 &&
319  date_itemlist[expire3->currentIndex()].num == 604800 &&
320  date_itemlist[expire2->currentIndex()].num == 345600 &&
321  date_itemlist[expire1->currentIndex()].num == 172800;
322 }
323 
324 
325 void BlockOptions::updateSettings()
326 {
327  if (block7->currentIndex() < 0 ||
328  block6->currentIndex() < 0 ||
329  block5->currentIndex() < 0 ||
330  block4->currentIndex() < 0 ||
331  block3->currentIndex() < 0 ||
332  block2->currentIndex() < 0 ||
333  block1->currentIndex() < 0 ||
334  expire7->currentIndex() < 0 ||
335  expire6->currentIndex() < 0 ||
336  expire5->currentIndex() < 0 ||
337  expire4->currentIndex() < 0 ||
338  expire3->currentIndex() < 0 ||
339  expire2->currentIndex() < 0 ||
340  expire1->currentIndex() < 0)
341  return;
342 
343  Prefs::setBlockItem(KV_LEV7_GRADE, date_itemlist[qMax(block7->currentIndex(), 0)].num);
344  Prefs::setBlockItem(KV_LEV6_GRADE, date_itemlist[qMax(block6->currentIndex(), 0)].num);
345  Prefs::setBlockItem(KV_LEV5_GRADE, date_itemlist[qMax(block5->currentIndex(), 0)].num);
346  Prefs::setBlockItem(KV_LEV4_GRADE, date_itemlist[qMax(block4->currentIndex(), 0)].num);
347  Prefs::setBlockItem(KV_LEV3_GRADE, date_itemlist[qMax(block3->currentIndex(), 0)].num);
348  Prefs::setBlockItem(KV_LEV2_GRADE, date_itemlist[qMax(block2->currentIndex(), 0)].num);
349  Prefs::setBlockItem(KV_LEV1_GRADE, date_itemlist[qMax(block1->currentIndex(), 0)].num);
350 
351  Prefs::setExpireItem(KV_LEV7_GRADE, date_itemlist[qMax(expire7->currentIndex(), 0)].num);
352  Prefs::setExpireItem(KV_LEV6_GRADE, date_itemlist[qMax(expire6->currentIndex(), 0)].num);
353  Prefs::setExpireItem(KV_LEV5_GRADE, date_itemlist[qMax(expire5->currentIndex(), 0)].num);
354  Prefs::setExpireItem(KV_LEV4_GRADE, date_itemlist[qMax(expire4->currentIndex(), 0)].num);
355  Prefs::setExpireItem(KV_LEV3_GRADE, date_itemlist[qMax(expire3->currentIndex(), 0)].num);
356  Prefs::setExpireItem(KV_LEV2_GRADE, date_itemlist[qMax(expire2->currentIndex(), 0)].num);
357  Prefs::setExpireItem(KV_LEV1_GRADE, date_itemlist[qMax(expire1->currentIndex(), 0)].num);
358 }
359 
360 bool BlockOptions::hasChanged()
361 {
362  if (block7->currentIndex() < 0 ||
363  block6->currentIndex() < 0 ||
364  block5->currentIndex() < 0 ||
365  block4->currentIndex() < 0 ||
366  block3->currentIndex() < 0 ||
367  block2->currentIndex() < 0 ||
368  block1->currentIndex() < 0 ||
369  expire7->currentIndex() < 0 ||
370  expire6->currentIndex() < 0 ||
371  expire5->currentIndex() < 0 ||
372  expire4->currentIndex() < 0 ||
373  expire3->currentIndex() < 0 ||
374  expire2->currentIndex() < 0 ||
375  expire1->currentIndex() < 0)
376  return false;
377 
378  return date_itemlist[block7->currentIndex()].num != Prefs::blockItem(KV_LEV7_GRADE) ||
379  date_itemlist[block6->currentIndex()].num != Prefs::blockItem(KV_LEV6_GRADE) ||
380  date_itemlist[block5->currentIndex()].num != Prefs::blockItem(KV_LEV5_GRADE) ||
381  date_itemlist[block4->currentIndex()].num != Prefs::blockItem(KV_LEV4_GRADE) ||
382  date_itemlist[block3->currentIndex()].num != Prefs::blockItem(KV_LEV3_GRADE) ||
383  date_itemlist[block2->currentIndex()].num != Prefs::blockItem(KV_LEV2_GRADE) ||
384  date_itemlist[block1->currentIndex()].num != Prefs::blockItem(KV_LEV1_GRADE) ||
385  date_itemlist[expire7->currentIndex()].num != Prefs::expireItem(KV_LEV7_GRADE) ||
386  date_itemlist[expire6->currentIndex()].num != Prefs::expireItem(KV_LEV6_GRADE) ||
387  date_itemlist[expire5->currentIndex()].num != Prefs::expireItem(KV_LEV5_GRADE) ||
388  date_itemlist[expire4->currentIndex()].num != Prefs::expireItem(KV_LEV4_GRADE) ||
389  date_itemlist[expire3->currentIndex()].num != Prefs::expireItem(KV_LEV3_GRADE) ||
390  date_itemlist[expire2->currentIndex()].num != Prefs::expireItem(KV_LEV2_GRADE) ||
391  date_itemlist[expire1->currentIndex()].num != Prefs::expireItem(KV_LEV1_GRADE);
392 }
393 
394 #include "blockoptions.moc"
BlockOptions::updateWidgets
void updateWidgets()
Definition: blockoptions.cpp:137
Prefs::setExpireItem
static void setExpireItem(int i, int v)
Set Amount of time after which different confidence levels should expire.
Definition: prefs.h:1371
QWidget
QString::append
QString & append(QChar ch)
BlockOptions::widgetModified
void widgetModified()
QWidget::setupUi
void setupUi(QWidget *widget)
BlockOptions::hasChanged
bool hasChanged()
Definition: blockoptions.cpp:360
Prefs::expireItem
static int expireItem(int i)
Get Amount of time after which different confidence levels should expire.
Definition: prefs.h:1381
prefs.h
BlockOptions::BlockOptions
BlockOptions(QWidget *parent=0)
Definition: blockoptions.cpp:77
BlockOptions::slotComboBoxActivated
void slotComboBoxActivated(int)
Definition: blockoptions.cpp:222
Prefs::blockItem
static int blockItem(int i)
Get Amount of time different confidence levels should be blocked.
Definition: prefs.h:1362
Prefs::setBlockItem
static void setBlockItem(int i, int v)
Set Amount of time different confidence levels should be blocked.
Definition: prefs.h:1352
BlockOptions::slotBlockToggled
void slotBlockToggled(bool)
Definition: blockoptions.cpp:200
QList::append
void append(const T &value)
date_itemlist
static ListRef date_itemlist[]
Definition: blockoptions.cpp:40
Prefs::expire
static bool expire()
Get In Blocking Query Tab Dialog, if checked then the Query accepts an expiring time.
Definition: prefs.h:317
Prefs::block
static bool block()
Get In Blocking Query Tab Dialog, if checked then the Query is blocked.
Definition: prefs.h:298
QString
blockoptions.h
BlockOptions::slotExpireToggled
void slotExpireToggled(bool)
Definition: blockoptions.cpp:211
BlockOptions::isDefault
bool isDefault()
Definition: blockoptions.cpp:290
QString::length
int length() const
BlockOptions::updateSettings
void updateSettings()
Definition: blockoptions.cpp:325
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 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
  • 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