[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: DNS-SD discovery for krdc
From:       Jakub Stachowski <stachowski () hypair ! net>
Date:       2004-11-30 22:29:21
Message-ID: 200411302329.22022.stachowski () hypair ! net
[Download RAW message or body]

Dnia poniedziałek, 29 listopada 2004 07:54, Brad Hards napisał:
> On Mon, 29 Nov 2004 08:59 am, Jakub Stachowski wrote:
> > Well, there is always chance. After quick look at kdeprint code I imagine
> > kded module running query for _ipp._tcp and _printer._tcp , adding and
> > removing printers as necessary. There is one problem though: add/remove
> > operation requires root privileges. Is dialog box asking for root
> > password acceptable everytime when someone (un)plugs printer or network
> > cable?
>
> It would be enough that the kprinter "add printer wizard" could detect a
> zeroconf printer.

I have attached quick&dirty patch for that. For now it should detect IPP and 
LPD printers, right drivers (might need some work), name, location and queue 
name.  It is not finished yet, for example it removes backend selection page 
from add printer wizard completely.

I don't know too much about kdeprint, so I would be very glad for help with 
following:
 - how and where this listbox with printer list should be placed 
 - printers advertise list of mimetypes they can accept. Should it be set 
somewhere?

>
> > Second problem: I have no way to do any testing: I have no networked
> > printer nor computer running MacOSX (I also don't know anybody having one
> > of these).
>
> I have such a test environment (OSX 10.2, but I could upgrade it if
> necessary, plus a HP2510 printer). I can do some tests if you like.

That is really great. Way to test this patch:
1) build and install mDNSResponder (I suppose it is already installed on Mac), 
if not see kdenonbeta/kdnssd/README
2) build and install libkdnssd from kdenonbeta/kdnssd
3) apply patch to kdelibs (it should go into kdelibs/kdeprint), rebuild 
kdeprint and install
4) start add printer wizard - its second page contains listbox with detected 
printers, updated in real time

>
> Brad

["dnssdprint.patch" (text/x-diff)]

diff -urdN management-old/dnssdlist.cpp management/dnssdlist.cpp
--- management-old/dnssdlist.cpp	1970-01-01 01:00:00.000000000 +0100
+++ management/dnssdlist.cpp	2004-11-30 23:05:35.000000000 +0100
@@ -0,0 +1,47 @@
+#include <dnssdlist.h>
+#include <kdebug.h>
+
+DNSSDList::DNSSDList(QWidget *parent) : QListBox(parent)
+{
+	ipp = new DNSSD::ServiceBrowser("_ipp._tcp",0,true);
+	connect(ipp,SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)),SLOT(serviceAdded(DNSSD::RemoteService::Ptr)));
 +	connect(ipp,SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)),SLOT(serviceRemoved(DNSSD::RemoteService::Ptr)));
 +	lpd = new DNSSD::ServiceBrowser("_printer._tcp",0,true);
+	connect(lpd,SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)),SLOT(serviceAdded(DNSSD::RemoteService::Ptr)));
 +	connect(lpd,SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)),SLOT(serviceRemoved(DNSSD::RemoteService::Ptr)));
 +	lpd->startBrowse();
+	ipp->startBrowse();
+}
+
+DNSSDList::~DNSSDList()
+{
+	delete ipp;
+}
+
+DNSSD::RemoteService::Ptr DNSSDList::getSelected() 
+{
+DNSSDListItem* itm = static_cast<DNSSDListItem*>(selectedItem());
+if (itm) return itm->m_srv;
+	else return 0;
+}
+
+void DNSSDList::serviceAdded(DNSSD::RemoteService::Ptr srv)
+{
+	if (!checkService(srv)) kdDebug() << "Bad txtvers\n";
+	new DNSSDListItem(this,srv);
+}
+
+void DNSSDList::serviceRemoved(DNSSD::RemoteService::Ptr srv)
+{
+ for (unsigned int i=0; i < count() ; i++) 
+ 	if ((static_cast<DNSSDListItem*>(item(i)))->m_srv == srv) { removeItem(i); return; \
} +}
+
+bool DNSSDList::checkService(DNSSD::RemoteService::Ptr srv)
+{
+	if (!srv->textData()["txtvers"].isEmpty() && srv->textData()["txtvers"]!="1") \
return false; +	return true;
+}
+
+DNSSDListItem::DNSSDListItem(QListBox *listBox, DNSSD::RemoteService::Ptr \
srv):QListBoxText(listBox,srv->serviceName()), m_srv(srv) +{};
diff -urdN management-old/dnssdlist.h management/dnssdlist.h
--- management-old/dnssdlist.h	1970-01-01 01:00:00.000000000 +0100
+++ management/dnssdlist.h	2004-11-30 22:44:50.000000000 +0100
@@ -0,0 +1,27 @@
+#include <qlistbox.h>
+#include <dnssd/servicebrowser.h>
+#include <dnssd/remoteservice.h>
+
+class DNSSDList : public QListBox
+{
+Q_OBJECT
+
+public:
+	DNSSDList(QWidget *parent = 0);
+	~DNSSDList();
+	DNSSD::RemoteService::Ptr getSelected();
+private:
+	DNSSD::ServiceBrowser *ipp;
+	DNSSD::ServiceBrowser *lpd;
+	bool checkService(DNSSD::RemoteService::Ptr srv);
+private slots:
+	void serviceAdded(DNSSD::RemoteService::Ptr srv);
+	void serviceRemoved(DNSSD::RemoteService::Ptr srv);
+};
+
+class DNSSDListItem : public QListBoxText
+{ 
+public: 
+	DNSSDListItem(QListBox* listBox, DNSSD::RemoteService::Ptr srv);
+	const DNSSD::RemoteService::Ptr m_srv;
+};
diff -urdN management-old/kmwbackend.cpp management/kmwbackend.cpp
--- management-old/kmwbackend.cpp	2004-07-05 12:57:43.000000000 +0200
+++ management/kmwbackend.cpp	2004-11-30 23:12:20.000000000 +0100
@@ -26,12 +26,16 @@
 #include <qbuttongroup.h>
 #include <qradiobutton.h>
 #include <qwhatsthis.h>
+#include <qlistbox.h>
 
 #include <kcursor.h>
 #include <klocale.h>
 #include <kseparator.h>
 #include <kdialog.h>
 #include <kdebug.h>
+#include <kmessagebox.h>
+
+
 
 class KRadioButton : public QRadioButton
 {
@@ -59,6 +63,7 @@
 	m_layout = new QVBoxLayout(this, 0, KDialog::spacingHint());
 	m_layout->addStretch(1);
 	m_count = 0;
+	
 }
 
 bool KMWBackend::isValid(QString& msg)
@@ -66,7 +71,7 @@
 	if (!m_buttons->selected())
 	{
 		msg = i18n("You must select a backend.");
-		return false;
+//		return false;
 	}
 	return true;
 }
@@ -93,11 +98,15 @@
 
 	if (m_buttons->find(ID))
 		m_buttons->setButton(ID);
+	m_dnssd = new DNSSDList(this);
+	m_dnssd->show();
+	m_layout->insertWidget(0,m_dnssd);
+	m_dnssd->resize(200,100);
 }
 
 void KMWBackend::updatePrinter(KMPrinter *p)
 {
-	int	ID = m_buttons->id(m_buttons->selected());
+/*	int	ID = m_buttons->id(m_buttons->selected());
 	if (ID == KMWizard::Class) p->setType(KMPrinter::Class);
 	else p->setType(KMPrinter::Printer);
 	p->setOption("kde-backend",QString::number(ID));
@@ -105,6 +114,21 @@
 	s.replace(QRegExp("&(?=\\w)"), QString::fromLatin1(""));
 	p->setOption("kde-backend-description",s);
 	setNextPage((m_map.contains(ID) ? m_map[ID] : KMWizard::Error));
+*/
+	if (m_dnssd->currentItem() == -1) return;
+	DNSSD::RemoteService::Ptr srv = m_dnssd->getSelected();
+	p->setType(KMPrinter::Printer);
+	QString protocol = "lpd";
+	if (srv->type() == "_ipp._tcp") protocol = "ipp";
+	p->setDevice(protocol+QString("://%1:%2/%3").arg(srv->hostName()).arg(srv->port()).arg(srv->textData()["rp"]));
 +	p->setPrinterName(srv->serviceName());
+	const QString& prod = srv->textData()["product"];
+	if (!srv->textData()["usb_MFG"].isEmpty() && !srv->textData()["usb_MDL"].isEmpty()) \
 +	   p->setOption("kde-autodetect",srv->textData()["usb_MFG"].upper()+" \
"+srv->textData()["usb_MDL"]); +	   else if (prod[0]=='(' && \
prod[prod.length()-1]==')') \
p->setOption("kde-autodetect",prod.mid(1,prod.length()-2)); \
+	p->setLocation(srv->textData()["note"]); \
+	p->setDescription(srv->textData()["ty"]); +	setNextPage(KMWizard::Driver);
 }
 
 void KMWBackend::addBackend( int ID, bool on, int nextpage )
@@ -158,13 +182,15 @@
 	}
 	else
 	{
-		KRadioButton	*btn = new KRadioButton(txt, this);
-		btn->setEnabled(on);
-		if ( !whatsThis.isEmpty() )
-			QWhatsThis::add( btn, whatsThis );
-		m_buttons->insert(btn, ID);
-		m_map[ID] = (nextpage == -1 ? ID : nextpage);	// use nextpage if specified, \
                default to ID
-		m_layout->insertWidget(m_count, btn);
+//		KRadioButton	*btn = new KRadioButton(txt, this);
+//		connect(btn,SIGNAL(selected()),m_dnssd,SLOT(clearSelection()));
+//		connect(m_dnssd,SIGNAL(highlighted()),btn,SLOT(
+//		btn->setEnabled(on);
+//		if ( !whatsThis.isEmpty() )
+//			QWhatsThis::add( btn, whatsThis );
+//		m_buttons->insert(btn, ID);
+//		m_map[ID] = (nextpage == -1 ? ID : nextpage);	// use nextpage if specified, \
default to ID +//		m_layout->insertWidget(m_count, btn);
 	}
 	m_count++;
 }
diff -urdN management-old/kmwbackend.h management/kmwbackend.h
--- management-old/kmwbackend.h	2004-11-20 15:18:45.000000000 +0100
+++ management/kmwbackend.h	2004-11-29 17:58:54.000000000 +0100
@@ -23,6 +23,7 @@
 #include "kmwizardpage.h"
 #include <kdelibs_export.h>
 #include <qmap.h>
+#include "dnssdlist.h"
 
 class QButtonGroup;
 class QVBoxLayout;
@@ -49,6 +50,7 @@
 	// used by default.
 	QMap<int,int>	m_map;
 	int 		m_count;
+	DNSSDList	*m_dnssd;
 };
 
 #endif
diff -urdN management-old/kmwdriver.cpp management/kmwdriver.cpp
--- management-old/kmwdriver.cpp	2004-03-15 11:27:48.000000000 +0100
+++ management/kmwdriver.cpp	2004-11-30 22:13:37.000000000 +0100
@@ -22,6 +22,7 @@
 #include "kmprinter.h"
 #include "kmdriverdbwidget.h"
 #include "kmdriverdb.h"
+#include <kmessagebox.h>
 
 #include <qlayout.h>
 #include <klocale.h>
@@ -54,6 +55,7 @@
 			{
 				QString manu = autoDetect.left( p ), model = autoDetect.mid( p+1 );
 				KMDBEntryList *l = KMDriverDB::self()->findPnpEntry( manu, model );
+				if (!l || l->count() == 0) l = KMDriverDB::self()->findEntry( manu, model ); // \
try harder  if ( l && l->count() > 0 )
 				{
 					m_widget->setDriver( l->getFirst()->manufacturer, l->getFirst()->model );
diff -urdN management-old/Makefile.am management/Makefile.am
--- management-old/Makefile.am	2004-02-15 20:52:39.000000000 +0100
+++ management/Makefile.am	2004-11-29 22:19:37.000000000 +0100
@@ -24,9 +24,9 @@
 	kmwsmb.cpp smbview.cpp kmconfigdialog.cpp kmconfigpage.cpp kmconfiggeneral.cpp \
kmspecialprinterdlg.cpp \  kmwlocal.cpp kiconselectaction.cpp kmconfigpreview.cpp \
sidepixmap.cpp \  pluginaction.cpp kxmlcommanddlg.cpp kxmlcommandselector.cpp \
                kmconfigcommand.cpp \
-	kmconfigfilter.cpp kmconfigfonts.cpp kmconfigjobs.cpp networkscanner.cpp
+	kmconfigfilter.cpp kmconfigfonts.cpp kmconfigjobs.cpp networkscanner.cpp \
dnssdlist.cpp  libkdeprint_management_la_LDFLAGS = $(all_libraries) -version-info \
                6:0:2 -no-undefined
-libkdeprint_management_la_LIBADD = ../libkdeprint.la
+libkdeprint_management_la_LIBADD = ../libkdeprint.la -lkdnssd
 libkdeprint_management_la_METASOURCES = AUTO
 
 libkdeprint_management_module_la_SOURCES = kdeprint_management_module.cpp



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic