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

tdeprint

  • tdeprint
  • cups
kmwquota.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include <config.h>
21 
22 #include "kmwquota.h"
23 #include "kmwizard.h"
24 #include "kmprinter.h"
25 
26 #include <tqspinbox.h>
27 #include <tqlabel.h>
28 #include <tqcombobox.h>
29 #include <tqlayout.h>
30 #include <tdelocale.h>
31 
32 #ifdef HAVE_LIMITS_H
33 #include <limits.h>
34 #endif
35 
36 #define N_TIME_LIMITS 6
37 static int time_periods[] = {
38  1, // second
39  60, // minute
40  3600, // hour
41  86400, // day
42  604800, // week
43  2592000 // month (30 days)
44 };
45 static const char* time_keywords[] = {
46  I18N_NOOP("second(s)"),
47  I18N_NOOP("minute(s)"),
48  I18N_NOOP("hour(s)"),
49  I18N_NOOP("day(s)"),
50  I18N_NOOP("week(s)"),
51  I18N_NOOP("month(s)")
52 };
53 
54 int findUnit(int& period)
55 {
56  int unit(0);
57  for (int i=N_TIME_LIMITS-1;i>=0;i--)
58  {
59  if (period < time_periods[i])
60  continue;
61  int d = period / time_periods[i];
62  if ((d*time_periods[i]) == period)
63  {
64  unit = i;
65  break;
66  }
67  }
68  period /= time_periods[unit];
69  return unit;
70 }
71 
72 const char* unitKeyword(int i)
73 { return time_keywords[i]; }
74 
75 KMWQuota::KMWQuota(TQWidget *parent, const char *name)
76 : KMWizardPage(parent, name)
77 {
78  m_ID = KMWizard::Custom+3;
79  m_title = i18n("Printer Quota Settings");
80  m_nextpage = KMWizard::Custom+4;
81 
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);
95 
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);
99 
100  lab1->setBuddy(m_period);
101  lab2->setBuddy(m_sizelimit);
102  lab3->setBuddy(m_pagelimit);
103 
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);
108 
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);
120 }
121 
122 KMWQuota::~KMWQuota()
123 {
124 }
125 
126 bool KMWQuota::isValid(TQString& msg)
127 {
128  if (m_period->value() >= 0 && m_sizelimit->value() == 0 && m_pagelimit->value() == 0)
129  {
130  msg = i18n("You must specify at least one quota limit.");
131  return false;
132  }
133  return true;
134 }
135 
136 void KMWQuota::initPrinter(KMPrinter *p)
137 {
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)
143  // no quota
144  qu = -1;
145  m_sizelimit->setValue(si);
146  m_pagelimit->setValue(pa);
147  if (qu > 0)
148  {
149  un = findUnit(qu);
150  }
151  m_timeunit->setCurrentItem(un);
152  m_period->setValue(qu);
153 }
154 
155 void KMWQuota::updatePrinter(KMPrinter *p)
156 {
157  int qu(m_period->value()), si(m_sizelimit->value()), pa(m_pagelimit->value());
158  if (qu == -1)
159  {
160  // no quota, set limits to 0
161  si = 0;
162  pa = 0;
163  qu = 0;
164  }
165  qu *= time_periods[m_timeunit->currentItem()];
166 
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));
170 }
171 #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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.