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