Merge branch 'master' into patch-3
This commit is contained in:
commit
7eb2421cb3
8 changed files with 125 additions and 59 deletions
|
@ -7,7 +7,8 @@ Dialog {
|
||||||
|
|
||||||
property string value
|
property string value
|
||||||
property string ssid
|
property string ssid
|
||||||
canAccept: printer_label.text != ""
|
property var printerName: false
|
||||||
|
canAccept: printerName != false
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
@ -43,12 +44,12 @@ Dialog {
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: found_label
|
id: found_label
|
||||||
text: printer_label.text != "" ? qsTr("Found:") : qsTr("No printer found")
|
text: printerName != false ? qsTr("Found:") : qsTr("No printer found")
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
id: printer_label
|
id: printer_label
|
||||||
color: Theme.secondaryColor
|
color: Theme.secondaryColor
|
||||||
text: ""
|
text: printerName ? printerName : ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IppPrinter {
|
IppPrinter {
|
||||||
|
@ -56,11 +57,11 @@ Dialog {
|
||||||
url: valueField.text
|
url: valueField.text
|
||||||
onAttrsChanged: {
|
onAttrsChanged: {
|
||||||
if(printer.attrs["printer-name"]) {
|
if(printer.attrs["printer-name"]) {
|
||||||
printer_label.text = printer.attrs["printer-name"].value
|
printerName = printer.attrs["printer-name"].value == "" ? qsTr("Unknown") : printer.attrs["printer-name"].value
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printer_label.text = ""
|
printerName = false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@ Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
onSsidChanged: {
|
||||||
|
discovery.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signal refreshed()
|
signal refreshed()
|
||||||
|
@ -84,7 +87,7 @@ Page {
|
||||||
|
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
property string name: printer.attrs["printer-name"] ? printer.attrs["printer-name"].value : qsTr("Unknown")
|
property string name: printer.attrs["printer-name"].value != "" ? printer.attrs["printer-name"].value : qsTr("Unknown")
|
||||||
property bool canPrint: Utils.can_print(printer, selectedFile)
|
property bool canPrint: Utils.can_print(printer, selectedFile)
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#define AAAA 28
|
#define AAAA 28
|
||||||
#define SRV 33
|
#define SRV 33
|
||||||
|
|
||||||
|
#define ALL 255 //for querying
|
||||||
|
|
||||||
void put_addr(Bytestream& bts, QStringList addr)
|
void put_addr(Bytestream& bts, QStringList addr)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < addr.length(); i++)
|
for(int i = 0; i < addr.length(); i++)
|
||||||
|
@ -55,8 +57,24 @@ IppDiscovery::~IppDiscovery() {
|
||||||
delete socket;
|
delete socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IppDiscovery::discover() {
|
void IppDiscovery::discover() {
|
||||||
|
sendQuery(PTR, {"_ipp","_tcp","local"});
|
||||||
|
}
|
||||||
|
|
||||||
|
void IppDiscovery::reset() {
|
||||||
|
_ipp = QStringList();
|
||||||
|
_rps = QMap<QString,QString>();
|
||||||
|
_ports = QMap<QString,quint16>();
|
||||||
|
_targets = QMap<QString,QString>();
|
||||||
|
|
||||||
|
_AAs = QMultiMap<QString,QString>();
|
||||||
|
_AAAAs = QMultiMap<QString,QString>();
|
||||||
|
|
||||||
|
discover();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IppDiscovery::sendQuery(quint16 qtype, QStringList addr) {
|
||||||
|
qDebug() << "discovering" << qtype << addr;
|
||||||
|
|
||||||
Bytestream query;
|
Bytestream query;
|
||||||
quint16 transactionid = 0;
|
quint16 transactionid = 0;
|
||||||
|
@ -64,20 +82,42 @@ void IppDiscovery::discover() {
|
||||||
quint16 questions = 1;
|
quint16 questions = 1;
|
||||||
|
|
||||||
query << transactionid << flags << questions << (quint16)0 << (quint16)0 << (quint16)0;
|
query << transactionid << flags << questions << (quint16)0 << (quint16)0 << (quint16)0;
|
||||||
put_addr(query, {"_ipp","_tcp","local"});
|
put_addr(query, addr);
|
||||||
query << (quint16)0x000C << (quint16)0x0001;
|
query << qtype << (quint16)0x0001;
|
||||||
|
|
||||||
QByteArray bytes((char*)(query.raw()), query.size());
|
QByteArray bytes((char*)(query.raw()), query.size());
|
||||||
socket->writeDatagram(bytes, QHostAddress("224.0.0.251"), 5353);
|
socket->writeDatagram(bytes, QHostAddress("224.0.0.251"), 5353);
|
||||||
|
|
||||||
qDebug() << "discovering";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IppDiscovery::update()
|
void IppDiscovery::update()
|
||||||
{
|
{
|
||||||
qDebug() << _favourites << _found;
|
QStringList found;
|
||||||
this->setStringList(_favourites+_found);
|
|
||||||
|
for(QStringList::Iterator it = _ipp.begin(); it != _ipp.end(); it++)
|
||||||
|
{
|
||||||
|
quint16 port = _ports[*it];
|
||||||
|
QString target = _targets[*it];
|
||||||
|
QString rp = _rps[*it];
|
||||||
|
|
||||||
|
for(QMultiMap<QString,QString>::Iterator ait = _AAs.begin(); ait != _AAs.end(); ait++)
|
||||||
|
{
|
||||||
|
if(ait.key() == target)
|
||||||
|
{
|
||||||
|
QString ip = ait.value();
|
||||||
|
QString addr = ip+":"+QString::number(port)+"/"+rp;
|
||||||
|
if(!found.contains(addr))
|
||||||
|
{
|
||||||
|
found.append(addr);
|
||||||
|
found.sort(Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << _favourites << found;
|
||||||
|
this->setStringList(_favourites+found);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IppDiscovery::readPendingDatagrams()
|
void IppDiscovery::readPendingDatagrams()
|
||||||
|
@ -89,12 +129,7 @@ void IppDiscovery::readPendingDatagrams()
|
||||||
QHostAddress sender;
|
QHostAddress sender;
|
||||||
quint16 senderPort;
|
quint16 senderPort;
|
||||||
|
|
||||||
QMap<QString,QString> ptrs;
|
QStringList ipp_ptrs;
|
||||||
QMap<QString,QString> rps;
|
|
||||||
QMap<QString,quint16> ports;
|
|
||||||
QMap<QString,QString> targets;
|
|
||||||
QMultiMap<QString,QString> AAs;
|
|
||||||
QMultiMap<QString,QString> AAAAs;
|
|
||||||
|
|
||||||
socket->readDatagram((char*)(resp.raw()), size, &sender, &senderPort);
|
socket->readDatagram((char*)(resp.raw()), size, &sender, &senderPort);
|
||||||
sender = QHostAddress(sender.toIPv4Address());
|
sender = QHostAddress(sender.toIPv4Address());
|
||||||
|
@ -121,7 +156,10 @@ void IppDiscovery::readPendingDatagrams()
|
||||||
if (atype == PTR)
|
if (atype == PTR)
|
||||||
{
|
{
|
||||||
QString tmpname = get_addr(resp).join(".");
|
QString tmpname = get_addr(resp).join(".");
|
||||||
ptrs[aaddr] = tmpname;
|
if(aaddr.endsWith("_ipp._tcp.local"))
|
||||||
|
{
|
||||||
|
ipp_ptrs.append(tmpname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(atype == TXT)
|
else if(atype == TXT)
|
||||||
{
|
{
|
||||||
|
@ -133,7 +171,7 @@ void IppDiscovery::readPendingDatagrams()
|
||||||
{
|
{
|
||||||
std::string tmprp;
|
std::string tmprp;
|
||||||
tmp/tmp.remaining() >> tmprp;
|
tmp/tmp.remaining() >> tmprp;
|
||||||
rps[aaddr] = tmprp.c_str();
|
_rps[aaddr] = tmprp.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,15 +180,15 @@ void IppDiscovery::readPendingDatagrams()
|
||||||
quint16 prio, w, port;
|
quint16 prio, w, port;
|
||||||
resp >> prio >> w >> port;
|
resp >> prio >> w >> port;
|
||||||
QString target = get_addr(resp).join(".");
|
QString target = get_addr(resp).join(".");
|
||||||
ports[aaddr] = port;
|
_ports[aaddr] = port;
|
||||||
targets[aaddr] = target;
|
_targets[aaddr] = target;
|
||||||
}
|
}
|
||||||
else if(atype == A)
|
else if(atype == A)
|
||||||
{
|
{
|
||||||
quint32 addr;
|
quint32 addr;
|
||||||
resp >> addr;
|
resp >> addr;
|
||||||
QHostAddress haddr(addr);
|
QHostAddress haddr(addr);
|
||||||
AAs.insert(aaddr, haddr.toString());
|
_AAs.insert(aaddr, haddr.toString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -160,33 +198,26 @@ void IppDiscovery::readPendingDatagrams()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "ptrs" << ptrs;
|
qDebug() << "new ipp ptrs" << ipp_ptrs;
|
||||||
qDebug() << "rps" << rps;
|
qDebug() << "ipp ptrs" << _ipp;
|
||||||
qDebug() << "ports" << ports;
|
qDebug() << "rps" << _rps;
|
||||||
qDebug() << "targets" << targets;
|
qDebug() << "ports" << _ports;
|
||||||
qDebug() << "AAs" << AAs;
|
qDebug() << "targets" << _targets;
|
||||||
qDebug() << "AAAAs" << AAAAs;
|
qDebug() << "AAs" << _AAs;
|
||||||
|
qDebug() << "AAAAs" << _AAAAs;
|
||||||
|
|
||||||
for(QMap<QString,QString>::Iterator it = ptrs.begin(); it != ptrs.end(); it++)
|
for(QStringList::Iterator it = ipp_ptrs.begin(); it != ipp_ptrs.end(); it++)
|
||||||
{
|
{
|
||||||
quint16 port = ports[it.value()];
|
if(!_ipp.contains(*it))
|
||||||
QString target = targets[it.value()];
|
|
||||||
QString rp = rps[it.value()];
|
|
||||||
|
|
||||||
for(QMultiMap<QString,QString>::Iterator ait = AAs.begin(); ait != AAs.end(); ait++)
|
|
||||||
{
|
{
|
||||||
if(ait.key() == target)
|
_ipp.append(*it);
|
||||||
{
|
}
|
||||||
QString ip = ait.value();
|
if(!_ports.contains(*it) || !_targets.contains(*it) || !_rps.contains(*it))
|
||||||
QString addr = ip+":"+QString::number(port)+"/"+rp;
|
{ // if the PTR doesn't already resolve, ask for everything about it
|
||||||
if(!_found.contains(addr))
|
sendQuery(ALL, it->split('.'));
|
||||||
{
|
|
||||||
_found.append(addr);
|
|
||||||
_found.sort(Qt::CaseInsensitive);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
this->update();
|
this->update();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ public:
|
||||||
~IppDiscovery();
|
~IppDiscovery();
|
||||||
Q_PROPERTY(QStringList favourites MEMBER _favourites NOTIFY favouritesChanged)
|
Q_PROPERTY(QStringList favourites MEMBER _favourites NOTIFY favouritesChanged)
|
||||||
Q_INVOKABLE void discover();
|
Q_INVOKABLE void discover();
|
||||||
|
Q_INVOKABLE void reset();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void favouritesChanged();
|
void favouritesChanged();
|
||||||
|
@ -19,10 +20,20 @@ signals:
|
||||||
public slots:
|
public slots:
|
||||||
void readPendingDatagrams();
|
void readPendingDatagrams();
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
|
void sendQuery(quint16 qtype, QStringList addr);
|
||||||
|
|
||||||
|
QStringList _ipp;
|
||||||
|
QMap<QString,QString> _rps;
|
||||||
|
QMap<QString,quint16> _ports;
|
||||||
|
QMap<QString,QString> _targets;
|
||||||
|
|
||||||
|
QMultiMap<QString,QString> _AAs;
|
||||||
|
QMultiMap<QString,QString> _AAAAs;
|
||||||
|
|
||||||
QStringList _favourites;
|
QStringList _favourites;
|
||||||
QStringList _found;
|
|
||||||
QUdpSocket* socket;
|
QUdpSocket* socket;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,10 @@
|
||||||
<source>No printer found</source>
|
<source>No printer found</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChoiceSetting</name>
|
<name>ChoiceSetting</name>
|
||||||
|
@ -167,10 +171,6 @@
|
||||||
<source>Remove printer</source>
|
<source>Remove printer</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
|
||||||
<source>Unknown</source>
|
|
||||||
<translation type="unfinished"></translation>
|
|
||||||
</message>
|
|
||||||
<message>
|
<message>
|
||||||
<source>Removing printer</source>
|
<source>Removing printer</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
|
@ -179,6 +179,10 @@
|
||||||
<source>About SeaPrint</source>
|
<source>About SeaPrint</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>JobsPage</name>
|
<name>JobsPage</name>
|
||||||
|
|
|
@ -78,6 +78,10 @@
|
||||||
<source>No printer found</source>
|
<source>No printer found</source>
|
||||||
<translation>Aucune imprimante détectée</translation>
|
<translation>Aucune imprimante détectée</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished">Inconnu</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChoiceSetting</name>
|
<name>ChoiceSetting</name>
|
||||||
|
@ -167,10 +171,6 @@
|
||||||
<source>Remove printer</source>
|
<source>Remove printer</source>
|
||||||
<translation>Supprimer l'imprimante</translation>
|
<translation>Supprimer l'imprimante</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
|
||||||
<source>Unknown</source>
|
|
||||||
<translation>Inconnu</translation>
|
|
||||||
</message>
|
|
||||||
<message>
|
<message>
|
||||||
<source>Removing printer</source>
|
<source>Removing printer</source>
|
||||||
<translation>Suppression de l'imprimante</translation>
|
<translation>Suppression de l'imprimante</translation>
|
||||||
|
@ -179,6 +179,10 @@
|
||||||
<source>About SeaPrint</source>
|
<source>About SeaPrint</source>
|
||||||
<translation>À propos de SeaPrint</translation>
|
<translation>À propos de SeaPrint</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished">Inconnu</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>JobsPage</name>
|
<name>JobsPage</name>
|
||||||
|
|
|
@ -78,6 +78,10 @@
|
||||||
<source>No printer found</source>
|
<source>No printer found</source>
|
||||||
<translation>没有找到打印机</translation>
|
<translation>没有找到打印机</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChoiceSetting</name>
|
<name>ChoiceSetting</name>
|
||||||
|
@ -179,6 +183,10 @@
|
||||||
<source>Removing printer</source>
|
<source>Removing printer</source>
|
||||||
<translation>正在移除打印机</translation>
|
<translation>正在移除打印机</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>JobsPage</name>
|
<name>JobsPage</name>
|
||||||
|
|
|
@ -78,6 +78,10 @@
|
||||||
<source>No printer found</source>
|
<source>No printer found</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChoiceSetting</name>
|
<name>ChoiceSetting</name>
|
||||||
|
@ -167,10 +171,6 @@
|
||||||
<source>Remove printer</source>
|
<source>Remove printer</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
|
||||||
<source>Unknown</source>
|
|
||||||
<translation type="unfinished"></translation>
|
|
||||||
</message>
|
|
||||||
<message>
|
<message>
|
||||||
<source>Removing printer</source>
|
<source>Removing printer</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
|
@ -179,6 +179,10 @@
|
||||||
<source>About SeaPrint</source>
|
<source>About SeaPrint</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>JobsPage</name>
|
<name>JobsPage</name>
|
||||||
|
|
Loading…
Reference in a new issue