kptagspage.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., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "kptagspage.h"
00021 
00022 #include <qtable.h>
00023 #include <qheader.h>
00024 #include <qlayout.h>
00025 #include <qlabel.h>
00026 #include <qregexp.h>
00027 #include <qwhatsthis.h>
00028 
00029 #include <klocale.h>
00030 
00031 KPTagsPage::KPTagsPage(bool ro, QWidget *parent, const char *name)
00032 : KPrintDialogPage(parent, name)
00033 {
00034 
00035     //WhatsThis strings.... (added by pfeifle@kde.org)
00036     QString whatsThisAdditionalTagsTable = i18n(" <qt><p><b>Additional Tags</b></p>"
00037                         " You may send additional commands to the CUPS server via this editable list. "
00038                         " There are 3 purposes for this:"
00039                         " <ul>"
00040                         " <li>Use any current or future standard CUPS job option not supported by the "
00041                         " KDEPrint GUI. </li>"
00042                         " <li>Control any custom job option you may want to support in custom CUPS filters "
00043                         " and backends plugged into the CUPS filtering chain.</li> "
00044                         " <li>Send short messages to the operators of your production printers in your "
00045                         " <em>Central Repro Department</em>."
00046                         " </ul> "
00047                         " <p><b>Standard CUPS job options:</b> A complete list of standard CUPS job "
00048                         " options is in the <a href=\"http://localhost:631/sum.html\">CUPS User Manual</a>. "
00049                         " Mappings of the kprinter user interface widgets to respective CUPS job option "
00050                         " names are named in the various <em>WhatsThis</em> help items..</p>"
00051                         " <p><b>Custom CUPS job options:</b> CUPS print servers may be customized with additional "
00052                         " print filters and backends which understand custom job options. You can specify such "
00053                         " custom job options here. If in doubt, ask your system administrator..</p>"
00054                         " <p><b> </b></p>"
00055                         " <p><b>Operator Messages:</b> You may send additional messages to the operator(s) of your"
00056                         " production printers (e.g. in your <em>Central Repro Department</p>)"
00057                         " Messages can be read by the operator(s) (or yourself) by viewing"
00058                         " the <em>\"Job IPP Report\"</em> for the job.</p>"
00059                         " <b>Examples:</b><br>"
00060                         " <pre>"
00061                         " A standard CUPS job option:<br> "
00062                         "   <em>(Name) number-up</em>                -- <em>(Value) 9</em>                     <br>"
00063                         " <br>"
00064                         " A job option for custom CUPS filters or backends:<br> "
00065                         "   <em>(Name) DANKA_watermark</em>          -- <em>(Value) Company_Confidential</em>   <br>"
00066                         " <br>"
00067                         " A message to the operator(s):<br> "
00068                         "   <em>(Name) Deliver_after_completion</em> -- <em>(Value) to_Marketing_Departm.</em><br>"
00069                         " </pre>"
00070                         " <p><b>Note:</b> the fields must not include spaces, tabs or quotes. You may need to "
00071                         " double-click on a field to edit it."
00072                         " <p><b>Warning:</b> Do not use such standard CUPS option names which also can be used "
00073                         " through the KDEPrint GUI. Results may be  unpredictable if they conflict, "
00074                         " or if they are sent multiple times. For all options supported by the GUI, please do use "
00075                         " the GUI. (Each GUI element's  'WhatsThis' names the related CUPS option name.) </p> "
00076                         " </qt>" );
00077     setTitle(i18n("Additional Tags"));
00078     setOnlyRealPrinters(true);
00079 
00080     m_tags = new QTable(10, 2, this);
00081     m_tags->horizontalHeader()->setStretchEnabled(true);
00082     m_tags->horizontalHeader()->setLabel(0, i18n("Name"));
00083     m_tags->horizontalHeader()->setLabel(1, i18n("Value"));
00084     m_tags->setReadOnly(ro);
00085     QWhatsThis::add(m_tags, whatsThisAdditionalTagsTable);
00086 
00087     QVBoxLayout *l0 = new QVBoxLayout(this, 0, 5);
00088     l0->addWidget(m_tags);
00089 
00090     if (ro)
00091     {
00092         QLabel  *lab = new QLabel(i18n("Read-Only"), this);
00093         QFont   f = lab->font();
00094         f.setBold(true);
00095         lab->setFont(f);
00096         lab->setAlignment(AlignVCenter|AlignRight);
00097         l0->addWidget(lab);
00098     }
00099 }
00100 
00101 KPTagsPage::~KPTagsPage()
00102 {
00103 }
00104 
00105 bool KPTagsPage::isValid(QString& msg)
00106 {
00107     QRegExp re("\\s");
00108     for (int r=0; r<m_tags->numCols(); r++)
00109     {
00110         QString tag(m_tags->text(r, 0));
00111         if (tag.isEmpty())
00112             continue;
00113         else if (tag.find(re) != -1)
00114         {
00115             msg = i18n("The tag name must not contain any spaces, tabs or quotes: <b>%1</b>.").arg(tag);
00116             return false;
00117         }
00118     }
00119     return true;
00120 }
00121 
00122 void KPTagsPage::setOptions(const QMap<QString,QString>& opts)
00123 {
00124     int r(0);
00125     QRegExp re("^\"|\"$");
00126     for (QMap<QString,QString>::ConstIterator it=opts.begin(); it!=opts.end() && r<m_tags->numRows(); ++it)
00127     {
00128         if (it.key().startsWith("KDEPrint-"))
00129         {
00130             m_tags->setText(r, 0, it.key().mid(9));
00131             QString data = it.data();
00132             m_tags->setText(r, 1, data.replace(re, ""));
00133             r++;
00134         }
00135     }
00136     for (; r<m_tags->numRows(); r++)
00137     {
00138         m_tags->setText(r, 0, QString::null);
00139         m_tags->setText(r, 1, QString::null);
00140     }
00141 }
00142 
00143 void KPTagsPage::getOptions(QMap<QString,QString>& opts, bool)
00144 {
00145     for (int r=0; r<m_tags->numRows(); r++)
00146     {
00147         QString tag(m_tags->text(r, 0)), val(m_tags->text(r, 1));
00148         if (!tag.isEmpty())
00149         {
00150             tag.prepend("KDEPrint-");
00151             opts[tag] = val.prepend("\"").append("\"");
00152         }
00153     }
00154 }
00155 
00156 QSize KPTagsPage::sizeHint() const
00157 {
00158     return QSize(-1, -1);
00159 }
00160 
00161 QSize KPTagsPage::minimumSizeHint() const
00162 {
00163     return QSize(-1, -1);
00164 }
KDE Home | KDE Accessibility Home | Description of Access Keys