kdeprint Library API Documentation

kmwquota.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@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., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 00018 **/ 00019 00020 #include <config.h> 00021 00022 #include "kmwquota.h" 00023 #include "kmwizard.h" 00024 #include "kmprinter.h" 00025 00026 #include <qspinbox.h> 00027 #include <qlabel.h> 00028 #include <qcombobox.h> 00029 #include <qlayout.h> 00030 #include <klocale.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(QWidget *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 QSpinBox(this); 00083 m_period->setRange(-1, INT_MAX); 00084 m_period->setSpecialValueText(i18n("No quota")); 00085 m_sizelimit = new QSpinBox(this); 00086 m_sizelimit->setRange(0, INT_MAX); 00087 m_sizelimit->setSpecialValueText(i18n("None")); 00088 m_pagelimit = new QSpinBox(this); 00089 m_pagelimit->setRange(0, INT_MAX); 00090 m_pagelimit->setSpecialValueText(i18n("None")); 00091 m_timeunit = new QComboBox(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 QLabel *lab1 = new QLabel(i18n("&Period:"), this); 00097 QLabel *lab2 = new QLabel(i18n("&Size limit (KB):"), this); 00098 QLabel *lab3 = new QLabel(i18n("&Page limit:"), this); 00099 00100 lab1->setBuddy(m_period); 00101 lab2->setBuddy(m_sizelimit); 00102 lab3->setBuddy(m_pagelimit); 00103 00104 QLabel *lab4 = new QLabel(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 QGridLayout *l0 = new QGridLayout(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(QString& 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", QString::number(qu)); 00168 p->setOption("job-k-limit", QString::number(si)); 00169 p->setOption("job-page-limit", QString::number(pa)); 00170 } 00171 #include "kmwquota.moc"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 14 00:34:40 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003