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

parley

blockoptions.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003                       blocking options for Parley
00004 
00005     -----------------------------------------------------------------------
00006 
00007     begin                : Tue Apr 5 2005
00008 
00009     copyright            :(C) 2005 Peter Hedlund <peter.hedlund@kdemail.net>
00010 
00011     -----------------------------------------------------------------------
00012 
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "blockoptions.h"
00025 
00026 #include <QCheckBox>
00027 
00028 #include <klocale.h>
00029 #include <kmessagebox.h>
00030 #include <KComboBox>
00031 
00032 #include "prefs.h"
00033 
00034 struct ListRef
00035 {
00036     const char *text;
00037     long int num;
00038 };
00039 
00040 static ListRef date_itemlist [] =
00041     {
00042         {
00043             I18N_NOOP("Do not Care"),    0
00044         },
00045 
00046         {I18N_NOOP("30 Min"),        30*60},
00047         {I18N_NOOP("1 Hour"),    1 * 60*60},
00048         {I18N_NOOP("2 Hours"),   2 * 60*60},
00049         {I18N_NOOP("4 Hours"),   4 * 60*60},
00050         {I18N_NOOP("8 Hours"),   8 * 60*60},
00051         {I18N_NOOP("12 Hours"), 12 * 60*60},
00052         {I18N_NOOP("18 Hours"), 18 * 60*60},
00053 
00054         {I18N_NOOP("1 Day"),    1 * 60*60*24},
00055         {I18N_NOOP("2 Days"),   2 * 60*60*24},
00056         {I18N_NOOP("3 Days"),   3 * 60*60*24},
00057         {I18N_NOOP("4 Days"),   4 * 60*60*24},
00058         {I18N_NOOP("5 Days"),   5 * 60*60*24},
00059         {I18N_NOOP("6 Days"),   6 * 60*60*24},
00060 
00061         {I18N_NOOP("1 Week"),   1 * 60*60*24*7},
00062         {I18N_NOOP("2 Weeks"),  2 * 60*60*24*7},
00063         {I18N_NOOP("3 Weeks"),  3 * 60*60*24*7},
00064         {I18N_NOOP("4 Weeks"),  4 * 60*60*24*7},
00065 
00066         {I18N_NOOP("1 Month"),  1 * 60*60*24*30},
00067         {I18N_NOOP("2 Months"), 2 * 60*60*24*30},
00068         {I18N_NOOP("3 Months"), 3 * 60*60*24*30},
00069         {I18N_NOOP("4 Months"), 4 * 60*60*24*30},
00070         {I18N_NOOP("5 Months"), 5 * 60*60*24*30},
00071         {I18N_NOOP("6 Months"), 6 * 60*60*24*30},
00072         {I18N_NOOP("10 Months"), 10 * 60*60*24*30},
00073         {I18N_NOOP("12 Months"), 12 * 60*60*24*30},
00074         {0 ,  0}
00075     };
00076 
00077 
00078 BlockOptions::BlockOptions(QWidget* parent): QWidget(parent)
00079 {
00080     setupUi(this);
00081     connect(expire1, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00082     connect(block1, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00083     connect(expire2, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00084     connect(block2, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00085     connect(expire3, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00086     connect(block3, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00087     connect(expire4, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00088     connect(block4, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00089     connect(expire5, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00090     connect(block5, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00091     connect(expire6, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00092     connect(block6, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00093     connect(expire7, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00094     connect(block7, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int)));
00095 
00096     connect(kcfg_Block, SIGNAL(toggled(bool)), this, SLOT(slotBlockToggled(bool)));
00097     connect(kcfg_Expire, SIGNAL(toggled(bool)), this, SLOT(slotExpireToggled(bool)));
00098 
00099     fillWidgets();
00100     updateWidgets();
00101 }
00102 
00103 void BlockOptions::fillWidgets()
00104 {
00105     fillComboBox(block1);
00106     fillComboBox(block2);
00107     fillComboBox(block3);
00108     fillComboBox(block4);
00109     fillComboBox(block5);
00110     fillComboBox(block6);
00111     fillComboBox(block7);
00112 
00113     m_blockComboList.append(block1);
00114     m_blockComboList.append(block2);
00115     m_blockComboList.append(block3);
00116     m_blockComboList.append(block4);
00117     m_blockComboList.append(block5);
00118     m_blockComboList.append(block6);
00119     m_blockComboList.append(block7);
00120 
00121     fillComboBox(expire1);
00122     fillComboBox(expire2);
00123     fillComboBox(expire3);
00124     fillComboBox(expire4);
00125     fillComboBox(expire5);
00126     fillComboBox(expire6);
00127     fillComboBox(expire7);
00128 
00129     m_expireComboList.append(expire1);
00130     m_expireComboList.append(expire2);
00131     m_expireComboList.append(expire3);
00132     m_expireComboList.append(expire4);
00133     m_expireComboList.append(expire5);
00134     m_expireComboList.append(expire6);
00135     m_expireComboList.append(expire7);
00136 }
00137 
00138 void BlockOptions::updateWidgets()
00139 {
00140     updateComboBox(Prefs::blockItem(KV_LEV1_GRADE), block1);
00141     updateComboBox(Prefs::blockItem(KV_LEV2_GRADE), block2);
00142     updateComboBox(Prefs::blockItem(KV_LEV3_GRADE), block3);
00143     updateComboBox(Prefs::blockItem(KV_LEV4_GRADE), block4);
00144     updateComboBox(Prefs::blockItem(KV_LEV5_GRADE), block5);
00145     updateComboBox(Prefs::blockItem(KV_LEV6_GRADE), block6);
00146     updateComboBox(Prefs::blockItem(KV_LEV7_GRADE), block7);
00147 
00148     updateComboBox(Prefs::expireItem(KV_LEV1_GRADE), expire1);
00149     updateComboBox(Prefs::expireItem(KV_LEV2_GRADE), expire2);
00150     updateComboBox(Prefs::expireItem(KV_LEV3_GRADE), expire3);
00151     updateComboBox(Prefs::expireItem(KV_LEV4_GRADE), expire4);
00152     updateComboBox(Prefs::expireItem(KV_LEV5_GRADE), expire5);
00153     updateComboBox(Prefs::expireItem(KV_LEV6_GRADE), expire6);
00154     updateComboBox(Prefs::expireItem(KV_LEV7_GRADE), expire7);
00155 
00156     bool block = Prefs::block();
00157     kcfg_Block->setChecked(block);
00158     block1->setEnabled(block);
00159     block2->setEnabled(block);
00160     block3->setEnabled(block);
00161     block4->setEnabled(block);
00162     block5->setEnabled(block);
00163     block6->setEnabled(block);
00164     block7->setEnabled(block);
00165 
00166     bool expire = Prefs::expire();
00167     kcfg_Expire->setChecked(expire);
00168     expire1->setEnabled(expire);
00169     expire2->setEnabled(expire);
00170     expire3->setEnabled(expire);
00171     expire4->setEnabled(expire);
00172     expire5->setEnabled(expire);
00173     expire6->setEnabled(expire);
00174     expire7->setEnabled(expire);
00175 }
00176 
00177 void BlockOptions::fillComboBox(KComboBox * cb)
00178 {
00179     ListRef *ref = date_itemlist;
00180 
00181     cb->clear();
00182     while (ref->text != 0) {
00183         cb->addItem(i18n(ref->text));
00184         ref++;
00185     }
00186 }
00187 
00188 void BlockOptions::updateComboBox(int value, KComboBox * cb)
00189 {
00190     ListRef *ref = date_itemlist;
00191     int index = 0;
00192 
00193     while (ref->text != 0) {
00194         if (value == ref->num)
00195             index = ref - date_itemlist;
00196         ref++;
00197     }
00198     cb->setCurrentIndex(index);
00199 }
00200 
00201 void BlockOptions::slotBlockToggled(bool state)
00202 {
00203     block1->setEnabled(state);
00204     block2->setEnabled(state);
00205     block3->setEnabled(state);
00206     block4->setEnabled(state);
00207     block5->setEnabled(state);
00208     block6->setEnabled(state);
00209     block7->setEnabled(state);
00210 }
00211 
00212 void BlockOptions::slotExpireToggled(bool state)
00213 {
00214     expire1->setEnabled(state);
00215     expire2->setEnabled(state);
00216     expire3->setEnabled(state);
00217     expire4->setEnabled(state);
00218     expire5->setEnabled(state);
00219     expire6->setEnabled(state);
00220     expire7->setEnabled(state);
00221 }
00222 
00223 void BlockOptions::slotComboBoxActivated(int)
00224 {
00225     emit widgetModified();
00226     checkValidity();
00227 }
00228 
00229 
00230 void BlockOptions::checkValidity()
00231 {
00232     QString message;
00233     bool found = false;
00234     for (int i = 1; i <= 6; i++) {
00235         if (kcfg_Block->isChecked()) {
00236             /*if (Prefs::blockItem(i-1) != 0  &&
00237               Prefs::blockItem(i) != 0 &&
00238               Prefs::blockItem(i-1) >= Prefs::blockItem(i))*/
00239             if (date_itemlist[m_blockComboList[i - 1]->currentIndex()].num != 0 &&
00240                     date_itemlist[m_blockComboList[i]->currentIndex()].num != 0 &&
00241                     date_itemlist[m_blockComboList[i - 1]->currentIndex()].num >= date_itemlist[m_blockComboList[i]->currentIndex()].num) {
00242                 QString format;
00243                 if (!found)
00244                     message.append(i18n("Illogical blocking times.\n"));
00245                 found = true;
00246                 message.append(i18n("The time for level %1 should be lower than the time for level %2.\n", i, i + 1));
00247             }
00248         }
00249     }
00250 
00251     for (int i = 1; i <= 6; i++) {
00252         found = false;
00253         if (kcfg_Expire->isChecked()) {
00254             if (date_itemlist[m_expireComboList[i - 1]->currentIndex()].num != 0 &&
00255                     date_itemlist[m_expireComboList[i]->currentIndex()].num != 0 &&
00256                     date_itemlist[m_expireComboList[i - 1]->currentIndex()].num >=
00257                     date_itemlist[m_expireComboList[i]->currentIndex()].num) {
00258                 QString format;
00259                 if (!found)
00260                     message.append(i18n("\nIllogical expiration times.\n"));
00261                 found = true;
00262                 message.append(i18n("The time for level %1 should be lower than the time for level %2.\n", i, i + 1));
00263             }
00264         }
00265     }
00266 
00267     if (message.length() == 0) {
00268         found = false;
00269         for (int i = 0; i <= 6; i++) {
00270             if (kcfg_Block->isChecked() &&
00271                     kcfg_Expire->isChecked() &&
00272                     m_expireComboList[i]->currentIndex() >= 0 &&
00273                     m_blockComboList[i]->currentIndex() >= 0 &&
00274                     date_itemlist[m_expireComboList[i]->currentIndex()].num != 0 &&
00275                     date_itemlist[m_blockComboList[i]->currentIndex()].num != 0 &&
00276                     date_itemlist[m_blockComboList[i]->currentIndex()].num >= date_itemlist[m_expireComboList[i]->currentIndex()].num) {
00277                 QString format;
00278                 if (!found)
00279                     message.append(i18n("\nIllogical blocking vs. expiration times.\n"));
00280                 found = true;
00281                 message.append(i18n("The blocking time at level %1 should be lower than the expiration time.\n", i + 1));
00282             }
00283         }
00284     }
00285 
00286     if (message.length() != 0)
00287         KMessageBox::sorry(this, message, i18n("Illogical Values"));
00288 }
00289 
00290 
00291 bool BlockOptions::isDefault()
00292 {
00293     if (block7->currentIndex() < 0 ||
00294             block6->currentIndex() < 0 ||
00295             block5->currentIndex() < 0 ||
00296             block4->currentIndex() < 0 ||
00297             block3->currentIndex() < 0 ||
00298             block2->currentIndex() < 0 ||
00299             block1->currentIndex() < 0 ||
00300             expire7->currentIndex() < 0 ||
00301             expire6->currentIndex() < 0 ||
00302             expire5->currentIndex() < 0 ||
00303             expire4->currentIndex() < 0 ||
00304             expire3->currentIndex() < 0 ||
00305             expire2->currentIndex() < 0 ||
00306             expire1->currentIndex() < 0)
00307         return false;
00308 
00309     return date_itemlist[block7->currentIndex()].num == 5184000 &&
00310            date_itemlist[block6->currentIndex()].num == 2592000 &&
00311            date_itemlist[block5->currentIndex()].num == 1209600 &&
00312            date_itemlist[block4->currentIndex()].num == 604800 &&
00313            date_itemlist[block3->currentIndex()].num == 345600 &&
00314            date_itemlist[block2->currentIndex()].num == 172800 &&
00315            date_itemlist[block1->currentIndex()].num == 86400 &&
00316            date_itemlist[expire7->currentIndex()].num == 10368000 &&
00317            date_itemlist[expire6->currentIndex()].num == 5184000 &&
00318            date_itemlist[expire5->currentIndex()].num == 2592000 &&
00319            date_itemlist[expire4->currentIndex()].num == 1209600 &&
00320            date_itemlist[expire3->currentIndex()].num == 604800 &&
00321            date_itemlist[expire2->currentIndex()].num == 345600 &&
00322            date_itemlist[expire1->currentIndex()].num == 172800;
00323 }
00324 
00325 
00326 void BlockOptions::updateSettings()
00327 {
00328     if (block7->currentIndex() < 0 ||
00329             block6->currentIndex() < 0 ||
00330             block5->currentIndex() < 0 ||
00331             block4->currentIndex() < 0 ||
00332             block3->currentIndex() < 0 ||
00333             block2->currentIndex() < 0 ||
00334             block1->currentIndex() < 0 ||
00335             expire7->currentIndex() < 0 ||
00336             expire6->currentIndex() < 0 ||
00337             expire5->currentIndex() < 0 ||
00338             expire4->currentIndex() < 0 ||
00339             expire3->currentIndex() < 0 ||
00340             expire2->currentIndex() < 0 ||
00341             expire1->currentIndex() < 0)
00342         return;
00343 
00344     Prefs::setBlockItem(KV_LEV7_GRADE, date_itemlist[qMax(block7->currentIndex(),0)].num);
00345     Prefs::setBlockItem(KV_LEV6_GRADE, date_itemlist[qMax(block6->currentIndex(),0)].num);
00346     Prefs::setBlockItem(KV_LEV5_GRADE, date_itemlist[qMax(block5->currentIndex(),0)].num);
00347     Prefs::setBlockItem(KV_LEV4_GRADE, date_itemlist[qMax(block4->currentIndex(),0)].num);
00348     Prefs::setBlockItem(KV_LEV3_GRADE, date_itemlist[qMax(block3->currentIndex(),0)].num);
00349     Prefs::setBlockItem(KV_LEV2_GRADE, date_itemlist[qMax(block2->currentIndex(),0)].num);
00350     Prefs::setBlockItem(KV_LEV1_GRADE, date_itemlist[qMax(block1->currentIndex(),0)].num);
00351 
00352     Prefs::setExpireItem(KV_LEV7_GRADE, date_itemlist[qMax(expire7->currentIndex(),0)].num);
00353     Prefs::setExpireItem(KV_LEV6_GRADE, date_itemlist[qMax(expire6->currentIndex(),0)].num);
00354     Prefs::setExpireItem(KV_LEV5_GRADE, date_itemlist[qMax(expire5->currentIndex(),0)].num);
00355     Prefs::setExpireItem(KV_LEV4_GRADE, date_itemlist[qMax(expire4->currentIndex(),0)].num);
00356     Prefs::setExpireItem(KV_LEV3_GRADE, date_itemlist[qMax(expire3->currentIndex(),0)].num);
00357     Prefs::setExpireItem(KV_LEV2_GRADE, date_itemlist[qMax(expire2->currentIndex(),0)].num);
00358     Prefs::setExpireItem(KV_LEV1_GRADE, date_itemlist[qMax(expire1->currentIndex(),0)].num);
00359 }
00360 
00361 bool BlockOptions::hasChanged()
00362 {
00363     if (block7->currentIndex() < 0 ||
00364             block6->currentIndex() < 0 ||
00365             block5->currentIndex() < 0 ||
00366             block4->currentIndex() < 0 ||
00367             block3->currentIndex() < 0 ||
00368             block2->currentIndex() < 0 ||
00369             block1->currentIndex() < 0 ||
00370             expire7->currentIndex() < 0 ||
00371             expire6->currentIndex() < 0 ||
00372             expire5->currentIndex() < 0 ||
00373             expire4->currentIndex() < 0 ||
00374             expire3->currentIndex() < 0 ||
00375             expire2->currentIndex() < 0 ||
00376             expire1->currentIndex() < 0)
00377         return false;
00378 
00379     return date_itemlist[block7->currentIndex()].num != Prefs::blockItem(KV_LEV7_GRADE) ||
00380            date_itemlist[block6->currentIndex()].num != Prefs::blockItem(KV_LEV6_GRADE) ||
00381            date_itemlist[block5->currentIndex()].num != Prefs::blockItem(KV_LEV5_GRADE) ||
00382            date_itemlist[block4->currentIndex()].num != Prefs::blockItem(KV_LEV4_GRADE) ||
00383            date_itemlist[block3->currentIndex()].num != Prefs::blockItem(KV_LEV3_GRADE) ||
00384            date_itemlist[block2->currentIndex()].num != Prefs::blockItem(KV_LEV2_GRADE) ||
00385            date_itemlist[block1->currentIndex()].num != Prefs::blockItem(KV_LEV1_GRADE) ||
00386            date_itemlist[expire7->currentIndex()].num != Prefs::expireItem(KV_LEV7_GRADE) ||
00387            date_itemlist[expire6->currentIndex()].num != Prefs::expireItem(KV_LEV6_GRADE) ||
00388            date_itemlist[expire5->currentIndex()].num != Prefs::expireItem(KV_LEV5_GRADE) ||
00389            date_itemlist[expire4->currentIndex()].num != Prefs::expireItem(KV_LEV4_GRADE) ||
00390            date_itemlist[expire3->currentIndex()].num != Prefs::expireItem(KV_LEV3_GRADE) ||
00391            date_itemlist[expire2->currentIndex()].num != Prefs::expireItem(KV_LEV2_GRADE) ||
00392            date_itemlist[expire1->currentIndex()].num != Prefs::expireItem(KV_LEV1_GRADE);
00393 }
00394 
00395 #include "blockoptions.moc"

parley

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

kdeedu

Skip menu "kdeedu"
  •     lib
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal