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

tdeprint

  • tdeprint
  • management
kminstancepage.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 "kminstancepage.h"
21 #include "kmprinter.h"
22 #include "kmfactory.h"
23 #include "kmvirtualmanager.h"
24 #include "kmmanager.h"
25 #include "kprinterpropertydialog.h"
26 #include "kprinter.h"
27 #include "kmtimer.h"
28 
29 #include <tqlayout.h>
30 #include <tqregexp.h>
31 #include <tqwhatsthis.h>
32 #include <tqpushbutton.h>
33 #include <tdemessagebox.h>
34 #include <kinputdialog.h>
35 #include <tdelistbox.h>
36 #include <tdelocale.h>
37 #include <kiconloader.h>
38 #include <kstandarddirs.h>
39 #include <kdebug.h>
40 
41 KMInstancePage::KMInstancePage(TQWidget *parent, const char *name)
42 : TQWidget(parent,name)
43 {
44  m_view = new TDEListBox(this);
45  m_printer = 0;
46 
47  initActions();
48 
49  TQHBoxLayout *main_ = new TQHBoxLayout(this, 0, 0);
50  main_->addWidget(m_view);
51  TQVBoxLayout *sub_ = new TQVBoxLayout(0, 0, 0);
52  main_->addLayout(sub_);
53  for (TQValueList<TQButton*>::Iterator it=m_buttons.begin(); it!=m_buttons.end(); ++it)
54  if (*it)
55  sub_->addWidget(*it);
56  else
57  sub_->addSpacing(10);
58  sub_->addStretch(1);
59 
60  TQWhatsThis::add(this,
61  i18n("Define/Edit here instances for the current selected "
62  "printer. An instance is a combination of a real "
63  "(physical) printer and a set of predefined options. "
64  "For a single InkJet printer, you could define different "
65  "print formats like <i>DraftQuality</i>, <i>PhotoQuality</i> "
66  "or <i>TwoSided</i>. Those instances appear as normal "
67  "printers in the print dialog and allow you to quickly "
68  "select the print format you want."));
69 }
70 
71 KMInstancePage::~KMInstancePage()
72 {
73 }
74 
75 void KMInstancePage::addButton(const TQString& txt, const TQString& pixmap, const char *receiver)
76 {
77  TQPushButton *btn = new TQPushButton(this, 0L);
78  btn->setText(txt);
79  btn->setIconSet(BarIconSet(pixmap));
80  btn->setFlat(true);
81  connect(btn, TQ_SIGNAL(clicked()), receiver);
82  m_buttons.append(btn);
83 }
84 
85 void KMInstancePage::initActions()
86 {
87  addButton(i18n("New..."), "document-new", TQ_SLOT(slotNew()));
88  addButton(i18n("Copy..."), "edit-copy", TQ_SLOT(slotCopy()));
89  addButton(i18n("Remove"), "edittrash", TQ_SLOT(slotRemove()));
90  m_buttons.append(0);
91  addButton(i18n("Set as Default"), "application-x-executable", TQ_SLOT(slotDefault()));
92  addButton(i18n("Settings"), "configure", TQ_SLOT(slotSettings()));
93  m_buttons.append(0);
94  addButton(i18n("Test..."), "document-print", TQ_SLOT(slotTest()));
95 }
96 
97 void KMInstancePage::setPrinter(KMPrinter *p)
98 {
99  TQString oldText = m_view->currentText();
100 
101  m_view->clear();
102  m_printer = p;
103  //bool ok = (p && !p->isSpecial());
104  bool ok = (p != 0);
105  if (ok)
106  {
107  TQPtrList<KMPrinter> list;
108  KMFactory::self()->virtualManager()->virtualList(list,p->name());
109  TQPtrListIterator<KMPrinter> it(list);
110  for (;it.current();++it)
111  {
112  TQStringList pair = TQStringList::split('/',it.current()->name(),false);
113  m_view->insertItem(SmallIcon((it.current()->isSoftDefault() ? "application-x-executable" : "document-print")),(pair.count() > 1 ? pair[1] : i18n("(Default)")));
114  }
115  m_view->sort();
116  }
117 
118  for (TQValueList<TQButton*>::ConstIterator it=m_buttons.begin(); it!=m_buttons.end(); ++it)
119  if (*it)
120  (*it)->setEnabled(ok);
121 
122  //iif (!oldText.isEmpty())
123  //{
124  TQListBoxItem *item = m_view->findItem(oldText);
125  if (!item)
126  item = m_view->findItem(i18n("(Default)"));
127  if (item)
128  m_view->setSelected(item,true);
129  //}
130 }
131 
132 void KMInstancePage::slotNew()
133 {
134  KMTimer::self()->hold();
135 
136  bool ok(false);
137  TQString name = KInputDialog::getText(i18n("Instance Name"),i18n("Enter name for new instance (leave untouched for default):"),
138  i18n("(Default)"),&ok,this);
139  if (ok)
140  {
141  if (name.find(TQRegExp("[/\\s]")) != -1)
142  KMessageBox::error(this, i18n("Instance name must not contain any spaces or slashes."));
143  else
144  {
145  if (name == i18n("(Default)"))
146  name = TQString();
147  KMFactory::self()->virtualManager()->create(m_printer,name);
148  setPrinter(m_printer);
149  }
150  }
151 
152  KMTimer::self()->release();
153 }
154 
155 void KMInstancePage::slotRemove()
156 {
157  KMTimer::self()->hold();
158  bool reload(false);
159 
160  TQString src = m_view->currentText();
161  TQString msg = (src != i18n("(Default)") ? i18n("Do you really want to remove instance %1?") : i18n("You can't remove the default instance. However all settings of %1 will be discarded. Continue?"));
162  if (!src.isEmpty() && KMessageBox::warningContinueCancel(this,msg.arg(src),TQString(),KStdGuiItem::del()) == KMessageBox::Continue)
163  {
164  if (src == i18n("(Default)"))
165  src = TQString();
166  reload = KMFactory::self()->virtualManager()->isDefault(m_printer,src);
167  KMFactory::self()->virtualManager()->remove(m_printer,src);
168  setPrinter(m_printer);
169  }
170 
171  KMTimer::self()->release(reload);
172 }
173 
174 void KMInstancePage::slotCopy()
175 {
176  KMTimer::self()->hold();
177 
178  TQString src = m_view->currentText();
179  if (!src.isEmpty())
180  {
181  bool ok(false);
182  TQString name = KInputDialog::getText(i18n("Instance Name"),i18n("Enter name for new instance (leave untouched for default):"),
183  i18n("(Default)"),&ok,this);
184  if (ok)
185  {
186  if (name.find(TQRegExp("[/\\s]")) != -1)
187  KMessageBox::error(this, i18n("Instance name must not contain any spaces or slashes."));
188  else
189  {
190  if (src == i18n("(Default)"))
191  src = TQString();
192  if (name == i18n("(Default)"))
193  name = TQString();
194  KMFactory::self()->virtualManager()->copy(m_printer,src,name);
195  setPrinter(m_printer);
196  }
197  }
198  }
199 
200  KMTimer::self()->release();
201 }
202 
203 void KMInstancePage::slotSettings()
204 {
205  KMTimer::self()->hold();
206 
207  TQString src = m_view->currentText();
208  if (!src.isEmpty())
209  {
210  if (src == i18n("(Default)")) src = TQString();
211  KMPrinter *pr = KMFactory::self()->virtualManager()->findInstance(m_printer,src);
212  if ( !pr )
213  KMessageBox::error( this, i18n( "Unable to find instance %1." ).arg( m_view->currentText() ) );
214  else if ( !pr->isSpecial() && !KMFactory::self()->manager()->completePrinterShort( pr ) )
215  KMessageBox::error( this, i18n( "Unable to retrieve printer information. Message from printing system: %1." ).arg( KMFactory::self()->manager()->errorMsg() ) );
216  else
217  {
218  int oldAppType = KMFactory::self()->settings()->application;
219  KMFactory::self()->settings()->application = -1;
220  KPrinterPropertyDialog::setupPrinter(pr, this);
221  KMFactory::self()->settings()->application = oldAppType;
222  if (pr->isEdited())
223  { // printer edited, need to save changes
224  pr->setDefaultOptions(pr->editedOptions());
225  pr->setEditedOptions(TQMap<TQString,TQString>());
226  pr->setEdited(false);
227  KMFactory::self()->virtualManager()->triggerSave();
228  }
229  }
230  }
231  else
232  KMessageBox::error( this, i18n( "The instance name is empty. Please select an instance." ) );
233 
234  KMTimer::self()->release();
235 }
236 
237 void KMInstancePage::slotDefault()
238 {
239  KMTimer::self()->hold();
240 
241  TQString src = m_view->currentText();
242  if (!src.isEmpty())
243  {
244  if (src == i18n("(Default)"))
245  src = TQString();
246  KMFactory::self()->virtualManager()->setAsDefault(m_printer,src);
247  setPrinter(m_printer);
248  }
249 
250  KMTimer::self()->release(true);
251 }
252 
253 void KMInstancePage::slotTest()
254 {
255  KMTimer::self()->hold();
256 
257  TQString src = m_view->currentText();
258  if (!src.isEmpty())
259  {
260  if (src == i18n("(Default)"))
261  src = TQString();
262  KMPrinter *mpr = KMFactory::self()->virtualManager()->findInstance(m_printer,src);
263  if (!mpr)
264  KMessageBox::error(this,i18n("Internal error: printer not found."));
265  else if (KMessageBox::warningContinueCancel(this, i18n("You are about to print a test page on %1. Do you want to continue?").arg(mpr->printerName()), TQString(), i18n("Print Test Page"), "printTestPage") == KMessageBox::Continue)
266  {
267  if (!KMFactory::self()->virtualManager()->testInstance(mpr))
268  KMessageBox::error(this, i18n("Unable to send test page to %1.").arg(mpr->printerName()));
269  else
270  KMessageBox::information(this,i18n("Test page successfully sent to printer %1.").arg(mpr->printerName()));
271  }
272  }
273 
274  KMTimer::self()->release(false);
275 }
276 #include "kminstancepage.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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.1
This website is maintained by Timothy Pearson.