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

tdeprint

  • tdeprint
  • management
kxmlcommandselector.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 "kxmlcommandselector.h"
21#include "kxmlcommand.h"
22#include "kxmlcommanddlg.h"
23#include "tdeprintcheck.h"
24
25#include <tqcombobox.h>
26#include <kpushbutton.h>
27#include <tqlabel.h>
28#include <tqcheckbox.h>
29#include <tqlayout.h>
30#include <tqtooltip.h>
31#include <tqlineedit.h>
32#include <kinputdialog.h>
33#include <tdelocale.h>
34#include <kiconloader.h>
35#include <tdemessagebox.h>
36#include <tdefiledialog.h>
37#include <kseparator.h>
38#include <kguiitem.h>
39#include <kactivelabel.h>
40#include <kdatetbl.h>
41#include <kdialogbase.h>
42
43KXmlCommandSelector::KXmlCommandSelector(bool canBeNull, TQWidget *parent, const char *name, KDialogBase *dlg)
44: TQWidget(parent, name)
45{
46 m_cmd = new TQComboBox(this);
47 connect(m_cmd, TQ_SIGNAL(activated(int)), TQ_SLOT(slotCommandSelected(int)));
48 TQPushButton *m_add = new KPushButton(this);
49 TQPushButton *m_edit = new KPushButton(this);
50 m_add->setPixmap(SmallIcon("document-new"));
51 m_edit->setPixmap(SmallIcon("configure"));
52 connect(m_add, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddCommand()));
53 connect(m_edit, TQ_SIGNAL(clicked()), TQ_SLOT(slotEditCommand()));
54 TQToolTip::add(m_add, i18n("New command"));
55 TQToolTip::add(m_edit, i18n("Edit command"));
56 m_shortinfo = new TQLabel(this);
57 m_helpbtn = new KPushButton( this );
58 m_helpbtn->setIconSet( SmallIconSet( "help" ) );
59 connect( m_helpbtn, TQ_SIGNAL( clicked() ), TQ_SLOT( slotHelpCommand() ) );
60 TQToolTip::add( m_helpbtn, i18n( "Information" ) );
61 m_helpbtn->setEnabled( false );
62
63 m_line = 0;
64 m_usefilter = 0;
65 TQPushButton *m_browse = 0;
66
67 TQVBoxLayout *l0 = new TQVBoxLayout(this, 0, 10);
68
69 if (canBeNull)
70 {
71 m_line = new TQLineEdit(this);
72 m_browse = new KPushButton(KGuiItem(i18n("&Browse..."), "document-open"), this);
73 m_usefilter = new TQCheckBox(i18n("Use co&mmand:"), this);
74 connect(m_browse, TQ_SIGNAL(clicked()), TQ_SLOT(slotBrowse()));
75 connect(m_usefilter, TQ_SIGNAL(toggled(bool)), m_line, TQ_SLOT(setDisabled(bool)));
76 connect(m_usefilter, TQ_SIGNAL(toggled(bool)), m_browse, TQ_SLOT(setDisabled(bool)));
77 connect(m_usefilter, TQ_SIGNAL(toggled(bool)), m_cmd, TQ_SLOT(setEnabled(bool)));
78 connect(m_usefilter, TQ_SIGNAL(toggled(bool)), m_add, TQ_SLOT(setEnabled(bool)));
79 connect(m_usefilter, TQ_SIGNAL(toggled(bool)), m_edit, TQ_SLOT(setEnabled(bool)));
80 connect(m_usefilter, TQ_SIGNAL(toggled(bool)), m_shortinfo, TQ_SLOT(setEnabled(bool)));
81 connect( m_usefilter, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( slotXmlCommandToggled( bool ) ) );
82 m_usefilter->setChecked(true);
83 m_usefilter->setChecked(false);
84 //setFocusProxy(m_line);
85 setTabOrder(m_usefilter, m_cmd);
86 setTabOrder(m_cmd, m_add);
87 setTabOrder(m_add, m_edit);
88
89 TQHBoxLayout *l1 = new TQHBoxLayout(0, 0, 10);
90 l0->addLayout(l1);
91 l1->addWidget(m_line);
92 l1->addWidget(m_browse);
93
94 KSeparator *sep = new KSeparator(TQt::Horizontal, this);
95 l0->addWidget(sep);
96 }
97 else
98 setFocusProxy(m_cmd);
99
100 TQGridLayout *l2 = new TQGridLayout(0, 2, (m_usefilter?3:2), 0, 5);
101 int c(0);
102 l0->addLayout(l2);
103 if (m_usefilter)
104 {
105 l2->addWidget(m_usefilter, 0, c++);
106 }
107 l2->addWidget(m_cmd, 0, c);
108 TQHBoxLayout *l4 = new TQHBoxLayout( 0, 0, 5 );
109 l2->addLayout( l4, 1, c );
110 l4->addWidget( m_helpbtn, 0 );
111 l4->addWidget( m_shortinfo, 1 );
112 TQHBoxLayout *l3 = new TQHBoxLayout(0, 0, 0);
113 l2->addLayout(l3, 0, c+1);
114 l3->addWidget(m_add);
115 l3->addWidget(m_edit);
116
117 if ( dlg )
118 connect( this, TQ_SIGNAL( commandValid( bool ) ), dlg, TQ_SLOT( enableButtonOK( bool ) ) );
119
120 loadCommands();
121}
122
123void KXmlCommandSelector::loadCommands()
124{
125 TQString thisCmd = (m_cmd->currentItem() != -1 ? m_cmdlist[m_cmd->currentItem()] : TQString::null);
126
127 m_cmd->clear();
128 m_cmdlist.clear();
129
130 TQStringList list = KXmlCommandManager::self()->commandListWithDescription();
131 TQStringList desclist;
132 for (TQStringList::Iterator it=list.begin(); it!=list.end(); ++it)
133 {
134 m_cmdlist << (*it);
135 ++it;
136 desclist << (*it);
137 }
138 m_cmd->insertStringList(desclist);
139
140 int index = m_cmdlist.findIndex(thisCmd);
141 if (index != -1)
142 m_cmd->setCurrentItem(index);
143 if (m_cmd->currentItem() != -1 && m_cmd->isEnabled())
144 slotCommandSelected(m_cmd->currentItem());
145}
146
147TQString KXmlCommandSelector::command() const
148{
149 TQString cmd;
150 if (m_line && !m_usefilter->isChecked())
151 cmd = m_line->text();
152 else
153 cmd = m_cmdlist[m_cmd->currentItem()];
154 return cmd;
155}
156
157void KXmlCommandSelector::setCommand(const TQString& cmd)
158{
159 int index = m_cmdlist.findIndex(cmd);
160
161 if (m_usefilter)
162 m_usefilter->setChecked(index != -1);
163 if (m_line)
164 m_line->setText((index == -1 ? cmd : TQString::null));
165 if (index != -1)
166 m_cmd->setCurrentItem(index);
167 if (m_cmd->currentItem() != -1 && m_cmd->isEnabled())
168 slotCommandSelected(m_cmd->currentItem());
169}
170
171void KXmlCommandSelector::slotAddCommand()
172{
173 bool ok(false);
174 TQString cmdId = KInputDialog::getText(i18n("Command Name"), i18n("Enter an identification name for the new command:"), TQString::null, &ok, this);
175 if (ok)
176 {
177 bool added(true);
178
179 if (m_cmdlist.findIndex(cmdId) != -1)
180 {
181 if (KMessageBox::warningContinueCancel(
182 this,
183 i18n("A command named %1 already exists. Do you want "
184 "to continue and edit the existing one?").arg(cmdId),
185 TQString::null,
186 KStdGuiItem::cont()) == KMessageBox::Cancel)
187 {
188 return;
189 }
190 else
191 added = false;
192 }
193
194 KXmlCommand *xmlCmd = KXmlCommandManager::self()->loadCommand(cmdId);
195 if (KXmlCommandDlg::editCommand(xmlCmd, this))
196 KXmlCommandManager::self()->saveCommand(xmlCmd);
197
198 if (added)
199 loadCommands();
200 }
201}
202
203void KXmlCommandSelector::slotEditCommand()
204{
205 TQString xmlId = m_cmdlist[m_cmd->currentItem()];
206 KXmlCommand *xmlCmd = KXmlCommandManager::self()->loadCommand(xmlId);
207 if (xmlCmd)
208 {
209 if (KXmlCommandDlg::editCommand(xmlCmd, this))
210 {
211 // force to load the driver if not already done
212 xmlCmd->driver();
213 KXmlCommandManager::self()->saveCommand(xmlCmd);
214 }
215 m_cmd->changeItem(xmlCmd->description(), m_cmd->currentItem());
216 delete xmlCmd;
217 slotCommandSelected(m_cmd->currentItem());
218 }
219 else
220 KMessageBox::error(this, i18n("Internal error. The XML driver for the command %1 could not be found.").arg(xmlId));
221}
222
223void KXmlCommandSelector::slotBrowse()
224{
225 TQString filename = KFileDialog::getOpenFileName(TQString::null, TQString::null, this);
226 if (!filename.isEmpty() && m_line)
227 m_line->setText(filename);
228}
229
230void KXmlCommandSelector::slotCommandSelected(int ID)
231{
232 KXmlCommand *xmlCmd = KXmlCommandManager::self()->loadCommand(m_cmdlist[ID], true);
233 if (xmlCmd)
234 {
235 TQString msg;
236 if ( xmlCmd->isValid() && KdeprintChecker::check( xmlCmd->requirements() ) )
237 {
238 msg = TQString::fromLocal8Bit("(ID = %1, %2 = ").arg(xmlCmd->name()).arg(i18n("output"));
239 if (KXmlCommandManager::self()->checkCommand(xmlCmd->name(), KXmlCommandManager::None, KXmlCommandManager::Basic))
240 {
241 if (xmlCmd->mimeType() == "all/all")
242 msg.append(i18n("undefined"));
243 else
244 msg.append(xmlCmd->mimeType());
245 }
246 else
247 msg.append(i18n("not allowed"));
248 msg.append(")");
249 emit commandValid( true );
250 }
251 else
252 {
253 msg = "<font color=\"red\">" + i18n( "(Unavailable: requirements not satisfied)" ) + "</font>";
254 emit commandValid( false );
255 }
256 m_shortinfo->setText(msg);
257 m_help = xmlCmd->comment();
258 m_helpbtn->setEnabled( !m_help.isEmpty() );
259 }
260 delete xmlCmd;
261}
262
263void KXmlCommandSelector::slotXmlCommandToggled( bool on )
264{
265 if ( on )
266 slotCommandSelected( m_cmd->currentItem() );
267 else
268 {
269 emit commandValid( true );
270 m_shortinfo->setText( TQString::null );
271 }
272}
273
274void KXmlCommandSelector::slotHelpCommand()
275{
276 TDEPopupFrame *pop = new TDEPopupFrame( m_helpbtn );
277 KActiveLabel *lab = new KActiveLabel( m_help, pop );
278 lab->resize( lab->sizeHint() );
279 pop->setMainWidget( lab );
280 pop->exec( m_helpbtn->mapToGlobal( TQPoint( m_helpbtn->width(), 0 ) ) );
281 pop->close( 0 );
282 delete pop;
283}
284
285#include "kxmlcommandselector.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.4
This website is maintained by Timothy Pearson.