• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

kmwquota.cpp
00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include <config.h>
00021 
00022 #include "kmwquota.h"
00023 #include "kmwizard.h"
00024 #include "kmprinter.h"
00025 
00026 #include <tqspinbox.h>
00027 #include <tqlabel.h>
00028 #include <tqcombobox.h>
00029 #include <tqlayout.h>
00030 #include <tdelocale.h>
00031 
00032 #ifdef HAVE_LIMITS_H
00033 #include <limits.h>
00034 #endif
00035 
00036 #define N_TIME_LIMITS   6
00037 static int time_periods[] = {
00038     1,      // second
00039     60,     // minute
00040     3600,       // hour
00041     86400,      // day
00042     604800,     // week
00043     2592000     // month (30 days)
00044 };
00045 static const char* time_keywords[] = {
00046     I18N_NOOP("second(s)"),
00047     I18N_NOOP("minute(s)"),
00048     I18N_NOOP("hour(s)"),
00049     I18N_NOOP("day(s)"),
00050     I18N_NOOP("week(s)"),
00051     I18N_NOOP("month(s)")
00052 };
00053 
00054 int findUnit(int& period)
00055 {
00056     int unit(0);
00057     for (int i=N_TIME_LIMITS-1;i>=0;i--)
00058     {
00059         if (period < time_periods[i])
00060             continue;
00061         int d = period / time_periods[i];
00062         if ((d*time_periods[i]) == period)
00063         {
00064             unit = i;
00065             break;
00066         }
00067     }
00068     period /= time_periods[unit];
00069     return unit;
00070 }
00071 
00072 const char* unitKeyword(int i)
00073 { return time_keywords[i]; }
00074 
00075 KMWQuota::KMWQuota(TQWidget *parent, const char *name)
00076 : KMWizardPage(parent, name)
00077 {
00078     m_ID = KMWizard::Custom+3;
00079     m_title = i18n("Printer Quota Settings");
00080     m_nextpage = KMWizard::Custom+4;
00081 
00082     m_period = new TQSpinBox(this);
00083     m_period->setRange(-1, INT_MAX);
00084     m_period->setSpecialValueText(i18n("No quota"));
00085     m_sizelimit = new TQSpinBox(this);
00086     m_sizelimit->setRange(0, INT_MAX);
00087     m_sizelimit->setSpecialValueText(i18n("None"));
00088     m_pagelimit = new TQSpinBox(this);
00089     m_pagelimit->setRange(0, INT_MAX);
00090     m_pagelimit->setSpecialValueText(i18n("None"));
00091     m_timeunit = new TQComboBox(this);
00092     for (int i=0;i<N_TIME_LIMITS;i++)
00093         m_timeunit->insertItem(i18n(time_keywords[i]));
00094     m_timeunit->setCurrentItem(3);
00095 
00096     TQLabel *lab1 = new TQLabel(i18n("&Period:"), this);
00097     TQLabel *lab2 = new TQLabel(i18n("&Size limit (KB):"), this);
00098     TQLabel *lab3 = new TQLabel(i18n("&Page limit:"), this);
00099 
00100     lab1->setBuddy(m_period);
00101     lab2->setBuddy(m_sizelimit);
00102     lab3->setBuddy(m_pagelimit);
00103 
00104     TQLabel *lab4 = new TQLabel(i18n("<p>Set here the quota for this printer. Using limits of <b>0</b> means "
00105                     "that no quota will be used. This is equivalent to set quota period to "
00106                     "<b><nobr>No quota</nobr></b> (-1). Quota limits are defined on a per-user base and "
00107                     "applied to all users.</p>"), this);
00108 
00109     TQGridLayout    *l0 = new TQGridLayout(this, 5, 3, 0, 10);
00110     l0->setRowStretch(4, 1);
00111     l0->setColStretch(1, 1);
00112     l0->addMultiCellWidget(lab4, 0, 0, 0, 2);
00113     l0->addWidget(lab1, 1, 0);
00114     l0->addWidget(lab2, 2, 0);
00115     l0->addWidget(lab3, 3, 0);
00116     l0->addWidget(m_period, 1, 1);
00117     l0->addWidget(m_timeunit, 1, 2);
00118     l0->addMultiCellWidget(m_sizelimit, 2, 2, 1, 2);
00119     l0->addMultiCellWidget(m_pagelimit, 3, 3, 1, 2);
00120 }
00121 
00122 KMWQuota::~KMWQuota()
00123 {
00124 }
00125 
00126 bool KMWQuota::isValid(TQString& msg)
00127 {
00128     if (m_period->value() >= 0 && m_sizelimit->value() == 0 && m_pagelimit->value() == 0)
00129     {
00130         msg = i18n("You must specify at least one quota limit.");
00131         return false;
00132     }
00133     return true;
00134 }
00135 
00136 void KMWQuota::initPrinter(KMPrinter *p)
00137 {
00138     int qu(-1), si(0), pa(0), un(3);
00139     qu = p->option("job-quota-period").toInt();
00140     si = p->option("job-k-limit").toInt();
00141     pa = p->option("job-page-limit").toInt();
00142     if (si == 0 && pa == 0)
00143         // no quota
00144         qu = -1;
00145     m_sizelimit->setValue(si);
00146     m_pagelimit->setValue(pa);
00147     if (qu > 0)
00148     {
00149         un = findUnit(qu);
00150     }
00151     m_timeunit->setCurrentItem(un);
00152     m_period->setValue(qu);
00153 }
00154 
00155 void KMWQuota::updatePrinter(KMPrinter *p)
00156 {
00157     int qu(m_period->value()), si(m_sizelimit->value()), pa(m_pagelimit->value());
00158     if (qu == -1)
00159     {
00160         // no quota, set limits to 0
00161         si = 0;
00162         pa = 0;
00163         qu = 0;
00164     }
00165     qu *= time_periods[m_timeunit->currentItem()];
00166 
00167     p->setOption("job-quota-period", TQString::number(qu));
00168     p->setOption("job-k-limit", TQString::number(si));
00169     p->setOption("job-page-limit", TQString::number(pa));
00170 }
00171 #include "kmwquota.moc"

tdeprint

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

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.