20 #include "cupsaddsmb2.h"
21 #include "cupsinfos.h"
22 #include "sidepixmap.h"
25 #include <tqprogressbar.h>
28 #include <tqlineedit.h>
29 #include <tdelocale.h>
30 #include <tdemessagebox.h>
31 #include <tqmessagebox.h>
33 #include <tdeio/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>
45 CupsAddSmb::CupsAddSmb(TQWidget *parent,
const char *name)
46 : KDialog(parent, name)
51 connect(&m_proc, TQ_SIGNAL(receivedStdout(TDEProcess*,
char*,
int)), TQ_SLOT(slotReceived(TDEProcess*,
char*,
int)));
52 connect(&m_proc, TQ_SIGNAL(receivedStderr(TDEProcess*,
char*,
int)), TQ_SLOT(slotReceived(TDEProcess*,
char*,
int)));
53 connect(&m_proc, TQ_SIGNAL(processExited(TDEProcess*)), TQ_SLOT(slotProcessExited(TDEProcess*)));
55 m_side =
new SidePixmap(
this);
56 m_doit =
new TQPushButton(i18n(
"&Export"),
this);
57 m_cancel =
new KPushButton(KStdGuiItem::cancel(),
this);
58 connect(m_cancel, TQ_SIGNAL(clicked()), TQ_SLOT(reject()));
59 connect(m_doit, TQ_SIGNAL(clicked()), TQ_SLOT(slotActionClicked()));
60 m_bar =
new TQProgressBar(
this);
61 m_text =
new KActiveLabel(
this);
62 TQLabel *m_title =
new TQLabel(i18n(
"Export Printer Driver to Windows Clients"),
this);
63 setCaption(m_title->text());
64 TQFont f(m_title->font());
67 KSeparator *m_sep =
new KSeparator(TQt::Horizontal,
this);
68 m_textinfo =
new TQLabel(
this );
69 m_logined =
new TQLineEdit(
this );
70 m_passwded =
new TQLineEdit(
this );
71 m_passwded->setEchoMode( TQLineEdit::Password );
72 m_servered =
new TQLineEdit(
this );
73 TQLabel *m_loginlab =
new TQLabel( i18n(
"&Username:" ),
this );
74 TQLabel *m_serverlab =
new TQLabel( i18n(
"&Samba server:" ),
this );
75 TQLabel *m_passwdlab =
new TQLabel( i18n(
"&Password:" ),
this );
76 m_loginlab->setBuddy( m_logined );
77 m_serverlab->setBuddy( m_servered );
78 m_passwdlab->setBuddy( m_passwded );
80 TQString txt = i18n(
"<p><b>Samba server</b></p>"
81 "Adobe Windows PostScript driver files plus the CUPS printer PPD will be "
82 "exported to the <tt>[print$]</tt> special share of the Samba server (to change "
83 "the source CUPS server, use the <nobr><i>Configure Manager -> CUPS server</i></nobr> first). "
84 "The <tt>[print$]</tt> share must exist on the Samba side prior to clicking the "
85 "<b>Export</b> button below." );
86 TQWhatsThis::add( m_serverlab, txt );
87 TQWhatsThis::add( m_servered, txt );
89 txt = i18n(
"<p><b>Samba username</b></p>"
90 "User needs to have write access to the <tt>[print$]</tt> share on the Samba server. "
91 "<tt>[print$]</tt> holds printer drivers prepared for download to Windows clients. "
92 "This dialog does not work for Samba servers configured with <tt>security = share</tt> "
93 "(but works fine with <tt>security = user</tt>)." );
94 TQWhatsThis::add( m_loginlab, txt );
95 TQWhatsThis::add( m_logined, txt );
97 txt = i18n(
"<p><b>Samba password</b></p>"
98 "The Samba setting <tt>encrypt passwords = yes</tt> "
99 "(default) requires prior use of <tt>smbpasswd -a [username]</tt> command, "
100 "to create an encrypted Samba password and have Samba recognize it." );
101 TQWhatsThis::add( m_passwdlab, txt );
102 TQWhatsThis::add( m_passwded, txt );
104 TQHBoxLayout *l0 =
new TQHBoxLayout(
this, 10, 10);
105 TQVBoxLayout *l1 =
new TQVBoxLayout(0, 0, 10);
106 l0->addWidget(m_side);
108 l1->addWidget(m_title);
109 l1->addWidget(m_sep);
110 l1->addWidget(m_text);
111 TQGridLayout *l3 =
new TQGridLayout( 0, 3, 2, 0, 10 );
113 l3->addWidget( m_loginlab, 1, 0 );
114 l3->addWidget( m_passwdlab, 2, 0 );
115 l3->addWidget( m_serverlab, 0, 0 );
116 l3->addWidget( m_logined, 1, 1 );
117 l3->addWidget( m_passwded, 2, 1 );
118 l3->addWidget( m_servered, 0, 1 );
119 l3->setColStretch( 1, 1 );
120 l1->addSpacing( 10 );
121 l1->addWidget(m_bar);
122 l1->addWidget( m_textinfo );
124 TQHBoxLayout *l2 =
new TQHBoxLayout(0, 0, 10);
127 l2->addWidget(m_doit);
128 l2->addWidget(m_cancel);
130 m_logined->setText( CupsInfos::self()->login() );
131 m_passwded->setText( CupsInfos::self()->password() );
132 m_servered->setText( cupsServer() );
134 setMinimumHeight(400);
137 CupsAddSmb::~CupsAddSmb()
141 void CupsAddSmb::slotActionClicked()
145 else if (m_proc.isRunning())
149 void CupsAddSmb::slotReceived(TDEProcess*,
char *buf,
int buflen)
154 static bool incomplete(
false);
156 kdDebug(500) <<
"slotReceived()" << endl;
160 line = TQString::fromLatin1(
"");
162 while (index < buflen)
164 TQChar c(buf[index++]);
170 else if (c.isPrint())
176 kdDebug(500) <<
"NOTHING TO READ" << endl;
180 kdDebug(500) <<
"ANSWER = " << line <<
" (END = " << line.length() <<
")" << endl;
183 if (incomplete && m_buffer.count() > 0)
184 m_buffer[m_buffer.size()-1].append(line);
188 kdDebug(500) <<
"COMPLETE LINE READ (" << m_buffer.count() <<
")" << endl;
192 if (line.startsWith(
"smb:") || line.startsWith(
"rpcclient $"))
194 kdDebug(500) <<
"END OF ACTION" << endl;
201 kdDebug(500) <<
"EXITING PROGRAM..." << endl;
202 m_proc.writeStdin(
"quit\n", 5);
203 kdDebug(500) <<
"SENT" << endl;
209 if (incomplete && m_buffer.count() > 0)
210 m_buffer[m_buffer.size()-1].append(line);
214 kdDebug(500) <<
"INCOMPLETE LINE READ (" << m_buffer.count() <<
")" << endl;
220 void CupsAddSmb::checkActionStatus()
232 m_status = (m_buffer.count() == 0);
235 m_status = (m_buffer.count() == 1 || m_buffer[1].find(
"ERRfilexists") != -1);
239 m_status = (m_buffer.count() == 1 || !m_buffer[1].startsWith(
"result"));
242 kdDebug(500) <<
"ACTION STATUS = " << m_status << endl;
245 void CupsAddSmb::nextAction()
247 if (m_actionindex < (
int)(m_actions.count()))
248 TQTimer::singleShot(1,
this, TQ_SLOT(doNextAction()));
251 void CupsAddSmb::doNextAction()
255 if (m_proc.isRunning())
257 TQCString s = m_actions[m_actionindex++].latin1();
258 m_bar->setProgress(m_bar->progress()+1);
259 kdDebug(500) <<
"NEXT ACTION = " << s << endl;
264 else if (s ==
"mkdir")
268 m_textinfo->setText(i18n(
"Creating folder %1").arg(m_actions[m_actionindex]));
269 s.append(
" ").append(m_actions[m_actionindex].latin1());
276 m_textinfo->setText(i18n(
"Uploading %1").arg(m_actions[m_actionindex+1]));
277 s.append(
" ").append(TQFile::encodeName(m_actions[m_actionindex]).data()).append(
" ").append(m_actions[m_actionindex+1].latin1());
280 else if (s ==
"adddriver")
284 m_textinfo->setText(i18n(
"Installing driver for %1").arg(m_actions[m_actionindex]));
285 s.append(
" \"").append(m_actions[m_actionindex].latin1()).append(
"\" \"").append(m_actions[m_actionindex+1].latin1()).append(
"\"");
288 else if (s ==
"addprinter" || s ==
"setdriver")
290 m_state = AddPrinter;
292 m_textinfo->setText(i18n(
"Installing printer %1").arg(m_actions[m_actionindex]));
293 TQCString dest = m_actions[m_actionindex].local8Bit();
294 if (s ==
"addprinter")
295 s.append(
" ").append(dest).append(
" ").append(dest).append(
" \"").append(dest).append(
"\" \"\"");
297 s.append(
" ").append(dest).append(
" ").append(dest);
302 kdDebug(500) <<
"ACTION = unknown action" << endl;
307 kdDebug(500) <<
"ACTION = " << s << endl;
309 m_proc.writeStdin(s.data(), s.length());
313 void CupsAddSmb::slotProcessExited(TDEProcess*)
315 kdDebug(500) <<
"PROCESS EXITED (" << m_state <<
")" << endl;
316 if (m_proc.normalExit() && m_state != Start && m_status)
319 if (tqstrncmp(m_proc.args().first(),
"smbclient", 9) == 0)
326 m_doit->setEnabled(
false);
327 m_cancel->setEnabled(
true);
328 m_cancel->setText(i18n(
"&Close"));
329 m_cancel->setDefault(
true);
330 m_cancel->setFocus();
331 m_logined->setEnabled(
true );
332 m_servered->setEnabled(
true );
333 m_passwded->setEnabled(
true );
334 m_text->setText(i18n(
"Driver successfully exported."));
336 m_textinfo->setText( TQString::null );
341 if (m_proc.normalExit())
344 i18n(
"Operation failed. Possible reasons are: permission denied "
345 "or invalid Samba configuration (see <a href=\"man:/cupsaddsmb\">"
346 "cupsaddsmb</a> manual page for detailed information, you need "
347 "<a href=\"http://www.cups.org\">CUPS</a> version 1.1.11 or higher). "
348 "You may want to try again with another login/password."));
353 showError(i18n(
"Operation aborted (process killed)."));
357 void CupsAddSmb::showError(
const TQString& msg)
359 m_text->setText(i18n(
"<h3>Operation failed.</h3><p>%1</p>").arg(msg));
360 m_cancel->setEnabled(
true);
361 m_logined->setEnabled(
true );
362 m_servered->setEnabled(
true );
363 m_passwded->setEnabled(
true );
364 m_doit->setText(i18n(
"&Export"));
368 bool CupsAddSmb::exportDest(
const TQString &dest,
const TQString& datadir)
372 dlg.m_datadir = datadir;
374 i18n(
"You are about to prepare the <b>%1</b> driver to be "
375 "shared out to Windows clients through Samba. This operation "
376 "requires the <a href=\"http://www.adobe.com/products/printerdrivers/main.html\">Adobe PostScript Driver</a>, a recent version of "
377 "Samba 2.2.x and a running SMB service on the target server. "
378 "Click <b>Export</b> to start the operation. Read the <a href=\"man:/cupsaddsmb\">cupsaddsmb</a> "
379 "manual page in Konqueror or type <tt>man cupsaddsmb</tt> in a "
380 "console window to learn more about this functionality." ).arg( dest ) );
385 bool CupsAddSmb::doExport()
390 if (!TQFile::exists(m_datadir+
"/drivers/ADOBEPS5.DLL") ||
391 !TQFile::exists(m_datadir+
"/drivers/ADOBEPS4.DRV"))
394 i18n(
"Some driver files are missing. You can get them on "
395 "<a href=\"http://www.adobe.com\">Adobe</a> web site. "
396 "See <a href=\"man:/cupsaddsmb\">cupsaddsmb</a> manual "
397 "page for more details (you need <a href=\"http://www.cups.org\">CUPS</a> "
398 "version 1.1.11 or higher)."));
402 m_bar->setTotalSteps(18);
403 m_bar->setProgress(0);
405 m_textinfo->setText(i18n(
"Preparing to upload driver to host %1").arg(m_servered->text()));
406 m_cancel->setEnabled(
false);
407 m_logined->setEnabled(
false );
408 m_servered->setEnabled(
false );
409 m_passwded->setEnabled(
false );
410 m_doit->setText(i18n(
"&Abort"));
414 if ((ppdfile = cupsGetPPD(m_dest.local8Bit())) == NULL)
416 showError(i18n(
"The driver for printer <b>%1</b> could not be found.").arg(m_dest));
421 m_actions <<
"mkdir" <<
"W32X86";
422 m_actions <<
"put" << ppdfile <<
"W32X86/"+m_dest+
".PPD";
423 m_actions <<
"put" << m_datadir+
"/drivers/ADOBEPS5.DLL" <<
"W32X86/ADOBEPS5.DLL";
424 m_actions <<
"put" << m_datadir+
"/drivers/ADOBEPSU.DLL" <<
"W32X86/ADOBEPSU.DLL";
425 m_actions <<
"put" << m_datadir+
"/drivers/ADOBEPSU.HLP" <<
"W32X86/ADOBEPSU.HLP";
426 m_actions <<
"mkdir" <<
"WIN40";
427 m_actions <<
"put" << ppdfile <<
"WIN40/"+m_dest+
".PPD";
428 m_actions <<
"put" << m_datadir+
"/drivers/ADFONTS.MFM" <<
"WIN40/ADFONTS.MFM";
429 m_actions <<
"put" << m_datadir+
"/drivers/ADOBEPS4.DRV" <<
"WIN40/ADOBEPS4.DRV";
430 m_actions <<
"put" << m_datadir+
"/drivers/ADOBEPS4.HLP" <<
"WIN40/ADOBEPS4.HLP";
431 m_actions <<
"put" << m_datadir+
"/drivers/DEFPRTR2.PPD" <<
"WIN40/DEFPRTR2.PPD";
432 m_actions <<
"put" << m_datadir+
"/drivers/ICONLIB.DLL" <<
"WIN40/ICONLIB.DLL";
433 m_actions <<
"put" << m_datadir+
"/drivers/PSMON.DLL" <<
"WIN40/PSMON.DLL";
436 m_proc.clearArguments();
437 m_proc <<
"smbclient" << TQString::fromLatin1(
"//")+m_servered->text()+
"/print$";
438 return startProcess();
441 bool CupsAddSmb::doInstall()
447 m_actions <<
"adddriver" <<
"Windows NT x86" << m_dest+
":ADOBEPS5.DLL:"+m_dest+
".PPD:ADOBEPSU.DLL:ADOBEPSU.HLP:NULL:RAW:NULL";
450 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";
452 m_actions <<
"setdriver" << m_dest;
456 m_textinfo->setText(i18n(
"Preparing to install driver on host %1").arg(m_servered->text()));
458 m_proc.clearArguments();
459 m_proc <<
"rpcclient" << m_servered->text();
460 return startProcess();
463 bool CupsAddSmb::startProcess()
465 m_proc <<
"-d" <<
"0" <<
"-N" <<
"-U";
466 if (m_passwded->text().isEmpty())
467 m_proc << m_logined->text();
469 m_proc << m_logined->text()+
"%"+m_passwded->text();
473 kdDebug(500) <<
"PROCESS STARTED = " << m_proc.args()[0] << endl;
474 return m_proc.start(TDEProcess::NotifyOnExit, TDEProcess::All);
477 #include "cupsaddsmb2.moc"