20 #include "cupsaddsmb2.h"
21 #include "cupsinfos.h"
22 #include "sidepixmap.h"
25 #include <tqprogressbar.h>
28 #include <tqlineedit.h>
30 #include <kmessagebox.h>
31 #include <tqmessagebox.h>
33 #include <kio/passdlg.h>
35 #include <kseparator.h>
36 #include <kactivelabel.h>
37 #include <tqwhatsthis.h>
38 #include <kpushbutton.h>
39 #include <kstdguiitem.h>
41 #include <cups/cups.h>
44 CupsAddSmb::CupsAddSmb(TQWidget *parent,
const char *name)
45 : KDialog(parent, name)
50 connect(&m_proc, TQT_SIGNAL(receivedStdout(KProcess*,
char*,
int)), TQT_SLOT(slotReceived(KProcess*,
char*,
int)));
51 connect(&m_proc, TQT_SIGNAL(receivedStderr(KProcess*,
char*,
int)), TQT_SLOT(slotReceived(KProcess*,
char*,
int)));
52 connect(&m_proc, TQT_SIGNAL(processExited(KProcess*)), TQT_SLOT(slotProcessExited(KProcess*)));
54 m_side =
new SidePixmap(
this);
55 m_doit =
new TQPushButton(i18n(
"&Export"),
this);
56 m_cancel =
new KPushButton(KStdGuiItem::cancel(),
this);
57 connect(m_cancel, TQT_SIGNAL(clicked()), TQT_SLOT(reject()));
58 connect(m_doit, TQT_SIGNAL(clicked()), TQT_SLOT(slotActionClicked()));
59 m_bar =
new TQProgressBar(
this);
60 m_text =
new KActiveLabel(
this);
61 TQLabel *m_title =
new TQLabel(i18n(
"Export Printer Driver to Windows Clients"),
this);
62 setCaption(m_title->text());
63 TQFont f(m_title->font());
66 KSeparator *m_sep =
new KSeparator(Qt::Horizontal,
this);
67 m_textinfo =
new TQLabel(
this );
68 m_logined =
new TQLineEdit(
this );
69 m_passwded =
new TQLineEdit(
this );
70 m_passwded->setEchoMode( TQLineEdit::Password );
71 m_servered =
new TQLineEdit(
this );
72 TQLabel *m_loginlab =
new TQLabel( i18n(
"&Username:" ),
this );
73 TQLabel *m_serverlab =
new TQLabel( i18n(
"&Samba server:" ),
this );
74 TQLabel *m_passwdlab =
new TQLabel( i18n(
"&Password:" ),
this );
75 m_loginlab->setBuddy( m_logined );
76 m_serverlab->setBuddy( m_servered );
77 m_passwdlab->setBuddy( m_passwded );
79 TQString txt = i18n(
"<p><b>Samba server</b></p>"
80 "Adobe Windows PostScript driver files plus the CUPS printer PPD will be "
81 "exported to the <tt>[print$]</tt> special share of the Samba server (to change "
82 "the source CUPS server, use the <nobr><i>Configure Manager -> CUPS server</i></nobr> first). "
83 "The <tt>[print$]</tt> share must exist on the Samba side prior to clicking the "
84 "<b>Export</b> button below." );
85 TQWhatsThis::add( m_serverlab, txt );
86 TQWhatsThis::add( m_servered, txt );
88 txt = i18n(
"<p><b>Samba username</b></p>"
89 "User needs to have write access to the <tt>[print$]</tt> share on the Samba server. "
90 "<tt>[print$]</tt> holds printer drivers prepared for download to Windows clients. "
91 "This dialog does not work for Samba servers configured with <tt>security = share</tt> "
92 "(but works fine with <tt>security = user</tt>)." );
93 TQWhatsThis::add( m_loginlab, txt );
94 TQWhatsThis::add( m_logined, txt );
96 txt = i18n(
"<p><b>Samba password</b></p>"
97 "The Samba setting <tt>encrypt passwords = yes</tt> "
98 "(default) requires prior use of <tt>smbpasswd -a [username]</tt> command, "
99 "to create an encrypted Samba password and have Samba recognize it." );
100 TQWhatsThis::add( m_passwdlab, txt );
101 TQWhatsThis::add( m_passwded, txt );
103 TQHBoxLayout *l0 =
new TQHBoxLayout(
this, 10, 10);
104 TQVBoxLayout *l1 =
new TQVBoxLayout(0, 0, 10);
105 l0->addWidget(m_side);
107 l1->addWidget(m_title);
108 l1->addWidget(m_sep);
109 l1->addWidget(m_text);
110 TQGridLayout *l3 =
new TQGridLayout( 0, 3, 2, 0, 10 );
111 l1->addLayout( TQT_TQLAYOUT(l3) );
112 l3->addWidget( m_loginlab, 1, 0 );
113 l3->addWidget( m_passwdlab, 2, 0 );
114 l3->addWidget( m_serverlab, 0, 0 );
115 l3->addWidget( m_logined, 1, 1 );
116 l3->addWidget( m_passwded, 2, 1 );
117 l3->addWidget( m_servered, 0, 1 );
118 l3->setColStretch( 1, 1 );
119 l1->addSpacing( 10 );
120 l1->addWidget(m_bar);
121 l1->addWidget( m_textinfo );
123 TQHBoxLayout *l2 =
new TQHBoxLayout(0, 0, 10);
126 l2->addWidget(m_doit);
127 l2->addWidget(m_cancel);
129 m_logined->setText( CupsInfos::self()->login() );
130 m_passwded->setText( CupsInfos::self()->password() );
131 m_servered->setText( cupsServer() );
133 setMinimumHeight(400);
136 CupsAddSmb::~CupsAddSmb()
140 void CupsAddSmb::slotActionClicked()
144 else if (m_proc.isRunning())
148 void CupsAddSmb::slotReceived(KProcess*,
char *buf,
int buflen)
153 static bool incomplete(
false);
155 kdDebug(500) <<
"slotReceived()" << endl;
159 line = TQString::fromLatin1(
"");
161 while (index < buflen)
163 TQChar c(buf[index++]);
169 else if (c.isPrint())
175 kdDebug(500) <<
"NOTHING TO READ" << endl;
179 kdDebug(500) <<
"ANSWER = " << line <<
" (END = " << line.length() <<
")" << endl;
182 if (incomplete && m_buffer.count() > 0)
183 m_buffer[m_buffer.size()-1].append(line);
187 kdDebug(500) <<
"COMPLETE LINE READ (" << m_buffer.count() <<
")" << endl;
191 if (line.startsWith(
"smb:") || line.startsWith(
"rpcclient $"))
193 kdDebug(500) <<
"END OF ACTION" << endl;
200 kdDebug(500) <<
"EXITING PROGRAM..." << endl;
201 m_proc.writeStdin(
"quit\n", 5);
202 kdDebug(500) <<
"SENT" << endl;
208 if (incomplete && m_buffer.count() > 0)
209 m_buffer[m_buffer.size()-1].append(line);
213 kdDebug(500) <<
"INCOMPLETE LINE READ (" << m_buffer.count() <<
")" << endl;
219 void CupsAddSmb::checkActionStatus()
231 m_status = (m_buffer.count() == 0);
234 m_status = (m_buffer.count() == 1 || m_buffer[1].find(
"ERRfilexists") != -1);
238 m_status = (m_buffer.count() == 1 || !m_buffer[1].startsWith(
"result"));
241 kdDebug(500) <<
"ACTION STATUS = " << m_status << endl;
244 void CupsAddSmb::nextAction()
246 if (m_actionindex < (
int)(m_actions.count()))
247 TQTimer::singleShot(1,
this, TQT_SLOT(doNextAction()));
250 void CupsAddSmb::doNextAction()
254 if (m_proc.isRunning())
256 TQCString s = m_actions[m_actionindex++].latin1();
257 m_bar->setProgress(m_bar->progress()+1);
258 kdDebug(500) <<
"NEXT ACTION = " << s << endl;
263 else if (s ==
"mkdir")
267 m_textinfo->setText(i18n(
"Creating folder %1").arg(m_actions[m_actionindex]));
268 s.append(
" ").append(m_actions[m_actionindex].latin1());
275 m_textinfo->setText(i18n(
"Uploading %1").arg(m_actions[m_actionindex+1]));
276 s.append(
" ").append(TQFile::encodeName(m_actions[m_actionindex]).data()).append(
" ").append(m_actions[m_actionindex+1].latin1());
279 else if (s ==
"adddriver")
283 m_textinfo->setText(i18n(
"Installing driver for %1").arg(m_actions[m_actionindex]));
284 s.append(
" \"").append(m_actions[m_actionindex].latin1()).append(
"\" \"").append(m_actions[m_actionindex+1].latin1()).append(
"\"");
287 else if (s ==
"addprinter" || s ==
"setdriver")
289 m_state = AddPrinter;
291 m_textinfo->setText(i18n(
"Installing printer %1").arg(m_actions[m_actionindex]));
292 TQCString dest = m_actions[m_actionindex].local8Bit();
293 if (s ==
"addprinter")
294 s.append(
" ").append(dest).append(
" ").append(dest).append(
" \"").append(dest).append(
"\" \"\"");
296 s.append(
" ").append(dest).append(
" ").append(dest);
301 kdDebug(500) <<
"ACTION = unknown action" << endl;
306 kdDebug(500) <<
"ACTION = " << s << endl;
308 m_proc.writeStdin(s.data(), s.length());
312 void CupsAddSmb::slotProcessExited(KProcess*)
314 kdDebug(500) <<
"PROCESS EXITED (" << m_state <<
")" << endl;
315 if (m_proc.normalExit() && m_state != Start && m_status)
318 if (tqstrncmp(m_proc.args().first(),
"smbclient", 9) == 0)
325 m_doit->setEnabled(
false);
326 m_cancel->setEnabled(
true);
327 m_cancel->setText(i18n(
"&Close"));
328 m_cancel->setDefault(
true);
329 m_cancel->setFocus();
330 m_logined->setEnabled(
true );
331 m_servered->setEnabled(
true );
332 m_passwded->setEnabled(
true );
333 m_text->setText(i18n(
"Driver successfully exported."));
335 m_textinfo->setText( TQString::null );
340 if (m_proc.normalExit())
343 i18n(
"Operation failed. Possible reasons are: permission denied "
344 "or invalid Samba configuration (see <a href=\"man:/cupsaddsmb\">"
345 "cupsaddsmb</a> manual page for detailed information, you need "
346 "<a href=\"http://www.cups.org\">CUPS</a> version 1.1.11 or higher). "
347 "You may want to try again with another login/password."));
352 showError(i18n(
"Operation aborted (process killed)."));
356 void CupsAddSmb::showError(
const TQString& msg)
358 m_text->setText(i18n(
"<h3>Operation failed.</h3><p>%1</p>").arg(msg));
359 m_cancel->setEnabled(
true);
360 m_logined->setEnabled(
true );
361 m_servered->setEnabled(
true );
362 m_passwded->setEnabled(
true );
363 m_doit->setText(i18n(
"&Export"));
367 bool CupsAddSmb::exportDest(
const TQString &dest,
const TQString& datadir)
371 dlg.m_datadir = datadir;
373 i18n(
"You are about to prepare the <b>%1</b> driver to be "
374 "shared out to Windows clients through Samba. This operation "
375 "requires the <a href=\"http://www.adobe.com/products/printerdrivers/main.html\">Adobe PostScript Driver</a>, a recent version of "
376 "Samba 2.2.x and a running SMB service on the target server. "
377 "Click <b>Export</b> to start the operation. Read the <a href=\"man:/cupsaddsmb\">cupsaddsmb</a> "
378 "manual page in Konqueror or type <tt>man cupsaddsmb</tt> in a "
379 "console window to learn more about this functionality." ).arg( dest ) );
384 bool CupsAddSmb::doExport()
389 if (!TQFile::exists(m_datadir+
"/drivers/ADOBEPS5.DLL") ||
390 !TQFile::exists(m_datadir+
"/drivers/ADOBEPS4.DRV"))
393 i18n(
"Some driver files are missing. You can get them on "
394 "<a href=\"http://www.adobe.com\">Adobe</a> web site. "
395 "See <a href=\"man:/cupsaddsmb\">cupsaddsmb</a> manual "
396 "page for more details (you need <a href=\"http://www.cups.org\">CUPS</a> "
397 "version 1.1.11 or higher)."));
401 m_bar->setTotalSteps(18);
402 m_bar->setProgress(0);
404 m_textinfo->setText(i18n(
"Preparing to upload driver to host %1").arg(m_servered->text()));
405 m_cancel->setEnabled(
false);
406 m_logined->setEnabled(
false );
407 m_servered->setEnabled(
false );
408 m_passwded->setEnabled(
false );
409 m_doit->setText(i18n(
"&Abort"));
413 if ((ppdfile = cupsGetPPD(m_dest.local8Bit())) == NULL)
415 showError(i18n(
"The driver for printer <b>%1</b> could not be found.").arg(m_dest));
420 m_actions <<
"mkdir" <<
"W32X86";
421 m_actions <<
"put" << ppdfile <<
"W32X86/"+m_dest+
".PPD";
422 m_actions <<
"put" << m_datadir+
"/drivers/ADOBEPS5.DLL" <<
"W32X86/ADOBEPS5.DLL";
423 m_actions <<
"put" << m_datadir+
"/drivers/ADOBEPSU.DLL" <<
"W32X86/ADOBEPSU.DLL";
424 m_actions <<
"put" << m_datadir+
"/drivers/ADOBEPSU.HLP" <<
"W32X86/ADOBEPSU.HLP";
425 m_actions <<
"mkdir" <<
"WIN40";
426 m_actions <<
"put" << ppdfile <<
"WIN40/"+m_dest+
".PPD";
427 m_actions <<
"put" << m_datadir+
"/drivers/ADFONTS.MFM" <<
"WIN40/ADFONTS.MFM";
428 m_actions <<
"put" << m_datadir+
"/drivers/ADOBEPS4.DRV" <<
"WIN40/ADOBEPS4.DRV";
429 m_actions <<
"put" << m_datadir+
"/drivers/ADOBEPS4.HLP" <<
"WIN40/ADOBEPS4.HLP";
430 m_actions <<
"put" << m_datadir+
"/drivers/DEFPRTR2.PPD" <<
"WIN40/DEFPRTR2.PPD";
431 m_actions <<
"put" << m_datadir+
"/drivers/ICONLIB.DLL" <<
"WIN40/ICONLIB.DLL";
432 m_actions <<
"put" << m_datadir+
"/drivers/PSMON.DLL" <<
"WIN40/PSMON.DLL";
435 m_proc.clearArguments();
436 m_proc <<
"smbclient" << TQString::fromLatin1(
"//")+m_servered->text()+
"/print$";
437 return startProcess();
440 bool CupsAddSmb::doInstall()
446 m_actions <<
"adddriver" <<
"Windows NT x86" << m_dest+
":ADOBEPS5.DLL:"+m_dest+
".PPD:ADOBEPSU.DLL:ADOBEPSU.HLP:NULL:RAW:NULL";
449 m_actions <<
"adddriver" <<
"Windows 4.0" << m_dest+
":ADOBEPS4.DRV:"+m_dest+
".PPD:NULL:ADOBEPS4.HLP:PSMON.DLL:RAW:ADFONTS.MFM,DEFPRTR2.PPD,ICONLIB.DLL";
451 m_actions <<
"setdriver" << m_dest;
455 m_textinfo->setText(i18n(
"Preparing to install driver on host %1").arg(m_servered->text()));
457 m_proc.clearArguments();
458 m_proc <<
"rpcclient" << m_servered->text();
459 return startProcess();
462 bool CupsAddSmb::startProcess()
464 m_proc <<
"-d" <<
"0" <<
"-N" <<
"-U";
465 if (m_passwded->text().isEmpty())
466 m_proc << m_logined->text();
468 m_proc << m_logined->text()+
"%"+m_passwded->text();
472 kdDebug(500) <<
"PROCESS STARTED = " << m_proc.args()[0] << endl;
473 return m_proc.start(KProcess::NotifyOnExit, KProcess::All);
476 #include "cupsaddsmb2.moc"