28#include <tqcombobox.h> 
   36#define N_TIME_LIMITS   6 
   37static int time_periods[] = {
 
   45static const char* time_keywords[] = {
 
   46    I18N_NOOP(
"second(s)"),
 
   47    I18N_NOOP(
"minute(s)"),
 
   54int findUnit(
int& period)
 
   57    for (
int i=N_TIME_LIMITS-1;i>=0;i--)
 
   59        if (period < time_periods[i])
 
   61        int d = period / time_periods[i];
 
   62        if ((d*time_periods[i]) == period)
 
   68    period /= time_periods[unit];
 
   72const char* unitKeyword(
int i)
 
   73{ 
return time_keywords[i]; }
 
   75KMWQuota::KMWQuota(TQWidget *parent, 
const char *name)
 
   76: KMWizardPage(parent, name)
 
   78    m_ID = KMWizard::Custom+3;
 
   79    m_title = i18n(
"Printer Quota Settings");
 
   80    m_nextpage = KMWizard::Custom+4;
 
   82    m_period = 
new TQSpinBox(
this);
 
   83    m_period->setRange(-1, INT_MAX);
 
   84    m_period->setSpecialValueText(i18n(
"No quota"));
 
   85    m_sizelimit = 
new TQSpinBox(
this);
 
   86    m_sizelimit->setRange(0, INT_MAX);
 
   87    m_sizelimit->setSpecialValueText(i18n(
"None"));
 
   88    m_pagelimit = 
new TQSpinBox(
this);
 
   89    m_pagelimit->setRange(0, INT_MAX);
 
   90    m_pagelimit->setSpecialValueText(i18n(
"None"));
 
   91    m_timeunit = 
new TQComboBox(
this);
 
   92    for (
int i=0;i<N_TIME_LIMITS;i++)
 
   93        m_timeunit->insertItem(i18n(time_keywords[i]));
 
   94    m_timeunit->setCurrentItem(3);
 
   96    TQLabel *lab1 = 
new TQLabel(i18n(
"&Period:"), 
this);
 
   97    TQLabel *lab2 = 
new TQLabel(i18n(
"&Size limit (KB):"), 
this);
 
   98    TQLabel *lab3 = 
new TQLabel(i18n(
"&Page limit:"), 
this);
 
  100    lab1->setBuddy(m_period);
 
  101    lab2->setBuddy(m_sizelimit);
 
  102    lab3->setBuddy(m_pagelimit);
 
  104    TQLabel *lab4 = 
new TQLabel(i18n(
"<p>Set here the quota for this printer. Using limits of <b>0</b> means " 
  105                    "that no quota will be used. This is equivalent to set quota period to " 
  106                    "<b><nobr>No quota</nobr></b> (-1). Quota limits are defined on a per-user base and " 
  107                    "applied to all users.</p>"), 
this);
 
  109    TQGridLayout    *l0 = 
new TQGridLayout(
this, 5, 3, 0, 10);
 
  110    l0->setRowStretch(4, 1);
 
  111    l0->setColStretch(1, 1);
 
  112    l0->addMultiCellWidget(lab4, 0, 0, 0, 2);
 
  113    l0->addWidget(lab1, 1, 0);
 
  114    l0->addWidget(lab2, 2, 0);
 
  115    l0->addWidget(lab3, 3, 0);
 
  116    l0->addWidget(m_period, 1, 1);
 
  117    l0->addWidget(m_timeunit, 1, 2);
 
  118    l0->addMultiCellWidget(m_sizelimit, 2, 2, 1, 2);
 
  119    l0->addMultiCellWidget(m_pagelimit, 3, 3, 1, 2);
 
  126bool KMWQuota::isValid(TQString& msg)
 
  128    if (m_period->value() >= 0 && m_sizelimit->value() == 0 && m_pagelimit->value() == 0)
 
  130        msg = i18n(
"You must specify at least one quota limit.");
 
  136void KMWQuota::initPrinter(KMPrinter *p)
 
  138    int qu(-1), si(0), pa(0), un(3);
 
  139    qu = p->option(
"job-quota-period").toInt();
 
  140    si = p->option(
"job-k-limit").toInt();
 
  141    pa = p->option(
"job-page-limit").toInt();
 
  142    if (si == 0 && pa == 0)
 
  145    m_sizelimit->setValue(si);
 
  146    m_pagelimit->setValue(pa);
 
  151    m_timeunit->setCurrentItem(un);
 
  152    m_period->setValue(qu);
 
  155void KMWQuota::updatePrinter(KMPrinter *p)
 
  157    int qu(m_period->value()), si(m_sizelimit->value()), pa(m_pagelimit->value());
 
  165    qu *= time_periods[m_timeunit->currentItem()];
 
  167    p->setOption(
"job-quota-period", TQString::number(qu));
 
  168    p->setOption(
"job-k-limit", TQString::number(si));
 
  169    p->setOption(
"job-page-limit", TQString::number(pa));
 
  171#include "kmwquota.moc"