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

tdeprint

  • tdeprint
  • management
kmspecialprinterdlg.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 "kmspecialprinterdlg.h"
21 #include "kmprinter.h"
22 #include "tdeprintcheck.h"
23 #include "kmfactory.h"
24 #include "kmspecialmanager.h"
25 #include "kxmlcommandselector.h"
26 #include "kxmlcommand.h"
27 #include "driver.h"
28 
29 #include <tqpushbutton.h>
30 #include <tqlineedit.h>
31 #include <tqcheckbox.h>
32 #include <tqcombobox.h>
33 #include <tqlabel.h>
34 #include <tqlayout.h>
35 #include <tqwhatsthis.h>
36 #include <tqgroupbox.h>
37 #include <tdelocale.h>
38 #include <tdemessagebox.h>
39 #include <kicondialog.h>
40 #include <tdefiledialog.h>
41 #include <kseparator.h>
42 
43 KMSpecialPrinterDlg::KMSpecialPrinterDlg(TQWidget *parent, const char *name)
44 : KDialogBase(parent, name, true, TQString::null, Ok|Cancel, Ok)
45 {
46  setCaption(i18n("Add Special Printer"));
47 
48  TQWidget *dummy = new TQWidget(this);
49  setMainWidget(dummy);
50 
51  // widget creation
52  m_name = new TQLineEdit(dummy);
53  connect(m_name, TQT_SIGNAL(textChanged ( const TQString & )),this,TQT_SLOT(slotTextChanged(const TQString & )));
54  m_description = new TQLineEdit(dummy);
55  m_location = new TQLineEdit(dummy);
56  TQLabel *m_namelabel = new TQLabel(i18n("&Name:"), dummy);
57  TQLabel *m_desclabel = new TQLabel(i18n("&Description:"), dummy);
58  TQLabel *m_loclabel = new TQLabel(i18n("&Location:"), dummy);
59  m_namelabel->setBuddy(m_name);
60  m_desclabel->setBuddy(m_description);
61  m_loclabel->setBuddy(m_location);
62 
63  KSeparator* sep = new KSeparator( KSeparator::HLine, dummy);
64 
65  sep->setFixedHeight(10);
66  TQGroupBox *m_gb = new TQGroupBox(1, Qt::Horizontal, i18n("Command &Settings"), dummy);
67  m_command = new KXmlCommandSelector(true, m_gb, "CommandSelector", this);
68 
69  TQGroupBox *m_outfile_gb = new TQGroupBox( 0, Qt::Horizontal, i18n( "Outp&ut File" ), dummy );
70 
71  m_usefile = new TQCheckBox( i18n("&Enable output file"), m_outfile_gb);
72 
73  m_mimetype = new TQComboBox(m_outfile_gb);
74  KMimeType::List list = KMimeType::allMimeTypes();
75  for (TQValueList<KMimeType::Ptr>::ConstIterator it=list.begin(); it!=list.end(); ++it)
76  {
77  TQString mimetype = (*it)->name();
78  m_mimelist << mimetype;
79  }
80  m_mimelist.sort();
81  m_mimetype->insertStringList(m_mimelist);
82 
83  TQLabel *m_mimetypelabel = new TQLabel(i18n("&Format:"), m_outfile_gb);
84  m_mimetypelabel->setBuddy (m_mimetype);
85 
86  m_extension = new TQLineEdit(m_outfile_gb);
87 
88  TQLabel *m_extensionlabel = new TQLabel(i18n("Filename e&xtension:"), m_outfile_gb);
89  m_extensionlabel->setBuddy(m_extension);
90 
91  m_icon = new TDEIconButton(dummy);
92  m_icon->setIcon("document-print");
93  m_icon->setFixedSize(TQSize(48,48));
94 
95  connect( m_usefile, TQT_SIGNAL( toggled( bool ) ), m_mimetype, TQT_SLOT( setEnabled( bool ) ) );
96  connect( m_usefile, TQT_SIGNAL( toggled( bool ) ), m_extension, TQT_SLOT( setEnabled( bool ) ) );
97  connect( m_usefile, TQT_SIGNAL( toggled( bool ) ), m_mimetypelabel, TQT_SLOT( setEnabled( bool ) ) );
98  connect( m_usefile, TQT_SIGNAL( toggled( bool ) ), m_extensionlabel, TQT_SLOT( setEnabled( bool ) ) );
99  m_mimetypelabel->setEnabled( false );
100  m_mimetype->setEnabled( false );
101  m_extensionlabel->setEnabled( false );
102  m_extension->setEnabled( false );
103 
104  TQWhatsThis::add(m_usefile,
105  i18n("<p>The command will use an output file. If checked, make sure the "
106  "command contains an output tag.</p>"));
107  TQWhatsThis::add(m_command,
108  i18n("<p>The command to execute when printing on this special printer. Either enter "
109  "the command to execute directly, or associate/create a command object with/for "
110  "this special printer. The command object is the preferred method as it provides "
111  "support for advanced settings like mime type checking, configurable options and "
112  "requirement list (the plain command is only provided for backward compatibility). "
113  "When using a plain command, the following tags are recognized:</p>"
114  "<ul><li><b>%in</b>: the input file (required).</li>"
115  "<li><b>%out</b>: the output file (required if using an output file).</li>"
116  "<li><b>%psl</b>: the paper size in lower case.</li>"
117  "<li><b>%psu</b>: the paper size with the first letter in upper case.</li></ul>"));
118  TQString mimetypeWhatsThis = i18n("<p>The default mimetype for the output file (e.g. application/postscript).</p>");
119  TQWhatsThis::add(m_mimetypelabel, mimetypeWhatsThis);
120  TQWhatsThis::add(m_mimetype, mimetypeWhatsThis);
121  TQString extensionWhatsThis = i18n("<p>The default extension for the output file (e.g. ps, pdf, ps.gz).</p>");
122  TQWhatsThis::add(m_extensionlabel, extensionWhatsThis);
123  TQWhatsThis::add(m_extension, extensionWhatsThis);
124 
125  // layout creation
126  TQVBoxLayout *l0 = new TQVBoxLayout(dummy, 0, 10);
127  TQGridLayout *l1 = new TQGridLayout(0, 3, 3, 0, 5);
128  l0->addLayout(TQT_TQLAYOUT(l1));
129  l1->setColStretch(2,1);
130  l1->addColSpacing(0,60);
131  l1->addMultiCellWidget(m_icon, 0, 2, 0, 0, Qt::AlignCenter);
132  l1->addWidget(m_namelabel, 0, 1);
133  l1->addWidget(m_desclabel, 1, 1);
134  l1->addWidget(m_loclabel, 2, 1);
135  l1->addWidget(m_name, 0, 2);
136  l1->addWidget(m_description, 1, 2);
137  l1->addWidget(m_location, 2, 2);
138  l0->addWidget(sep);
139  l0->addWidget(m_gb);
140  l0->addWidget(m_outfile_gb);
141  TQGridLayout *l6 = new TQGridLayout(m_outfile_gb->layout(), 3, 2, 10);
142  l6->addMultiCellWidget( m_usefile, 0, 0, 0, 1 );
143  l6->addWidget(m_mimetypelabel, 1, 0);
144  l6->addWidget(m_mimetype, 1, 1);
145  l6->addWidget(m_extensionlabel, 2, 0);
146  l6->addWidget(m_extension, 2, 1);
147 
148  enableButton(Ok, !m_name->text().isEmpty());
149 
150  // resize dialog
151  resize(400,100);
152 }
153 
154 void KMSpecialPrinterDlg::slotTextChanged(const TQString & )
155 {
156  enableButton(Ok, !m_name->text().isEmpty());
157 }
158 
159 void KMSpecialPrinterDlg::slotOk()
160 {
161  if (!checkSettings())
162  return;
163  KDialogBase::slotOk();
164 }
165 
166 bool KMSpecialPrinterDlg::checkSettings()
167 {
168  TQString msg;
169  if (m_name->text().isEmpty())
170  msg = i18n("You must provide a non-empty name.");
171  else
172  KXmlCommandManager::self()->checkCommand(m_command->command(),
173  KXmlCommandManager::Basic,
174  (m_usefile->isChecked() ? KXmlCommandManager::Basic : KXmlCommandManager::None),
175  &msg);
176 
177  if (!msg.isEmpty())
178  KMessageBox::error(this, i18n("Invalid settings. %1.").arg(msg));
179 
180  return (msg.isEmpty());
181 }
182 
183 void KMSpecialPrinterDlg::setPrinter(KMPrinter *printer)
184 {
185  if (printer && printer->isSpecial())
186  {
187  m_command->setCommand(printer->option("kde-special-command"));
188  m_usefile->setChecked(printer->option("kde-special-file") == "1");
189  int index = m_mimelist.findIndex(printer->option("kde-special-mimetype"));
190  m_mimetype->setCurrentItem(index == -1 ? 0 : index);
191  m_extension->setText(printer->option("kde-special-extension"));
192  m_name->setText(printer->name());
193  m_description->setText(printer->description());
194  m_location->setText(printer->location());
195  m_icon->setIcon(printer->pixmap());
196 
197  setCaption(i18n("Configuring %1").arg(printer->name()));
198  }
199 }
200 
201 KMPrinter* KMSpecialPrinterDlg::printer()
202 {
203  KMPrinter *printer = new KMPrinter();
204  printer->setName(m_name->text());
205  printer->setPrinterName(m_name->text());
206  printer->setPixmap(m_icon->icon());
207  printer->setDescription(m_description->text());
208  printer->setLocation(m_location->text());
209  printer->setOption("kde-special-command",m_command->command());
210  printer->setOption("kde-special-file",(m_usefile->isChecked() ? "1" : "0"));
211  if (m_usefile->isChecked ())
212  {
213  if (m_mimetype->currentText() != "all/all")
214  printer->setOption("kde-special-mimetype", m_mimetype->currentText());
215  printer->setOption("kde-special-extension",m_extension->text());
216  }
217  printer->setType(KMPrinter::Special);
218  printer->setState(KMPrinter::Idle);
219  return printer;
220 }
221 
222 #include "kmspecialprinterdlg.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.