Merge branch 'master' into patch-3

This commit is contained in:
attah 2020-01-02 22:17:21 +01:00 committed by GitHub
commit 7eb2421cb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 125 additions and 59 deletions

View file

@ -7,7 +7,8 @@ Dialog {
property string value
property string ssid
canAccept: printer_label.text != ""
property var printerName: false
canAccept: printerName != false
Column {
width: parent.width
@ -43,12 +44,12 @@ Dialog {
Label {
id: found_label
text: printer_label.text != "" ? qsTr("Found:") : qsTr("No printer found")
text: printerName != false ? qsTr("Found:") : qsTr("No printer found")
}
Label {
id: printer_label
color: Theme.secondaryColor
text: ""
text: printerName ? printerName : ""
}
}
IppPrinter {
@ -56,11 +57,11 @@ Dialog {
url: valueField.text
onAttrsChanged: {
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
{
printer_label.text = ""
printerName = false
}
}

View file

@ -31,6 +31,9 @@ Page {
}
}
onSsidChanged: {
discovery.reset();
}
}
signal refreshed()
@ -84,7 +87,7 @@ Page {
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)
Connections {

View file

@ -5,6 +5,8 @@
#define AAAA 28
#define SRV 33
#define ALL 255 //for querying
void put_addr(Bytestream& bts, QStringList addr)
{
for(int i = 0; i < addr.length(); i++)
@ -55,8 +57,24 @@ IppDiscovery::~IppDiscovery() {
delete socket;
}
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;
quint16 transactionid = 0;
@ -64,20 +82,42 @@ void IppDiscovery::discover() {
quint16 questions = 1;
query << transactionid << flags << questions << (quint16)0 << (quint16)0 << (quint16)0;
put_addr(query, {"_ipp","_tcp","local"});
query << (quint16)0x000C << (quint16)0x0001;
put_addr(query, addr);
query << qtype << (quint16)0x0001;
QByteArray bytes((char*)(query.raw()), query.size());
socket->writeDatagram(bytes, QHostAddress("224.0.0.251"), 5353);
qDebug() << "discovering";
}
void IppDiscovery::update()
{
qDebug() << _favourites << _found;
this->setStringList(_favourites+_found);
QStringList 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()
@ -89,12 +129,7 @@ void IppDiscovery::readPendingDatagrams()
QHostAddress sender;
quint16 senderPort;
QMap<QString,QString> ptrs;
QMap<QString,QString> rps;
QMap<QString,quint16> ports;
QMap<QString,QString> targets;
QMultiMap<QString,QString> AAs;
QMultiMap<QString,QString> AAAAs;
QStringList ipp_ptrs;
socket->readDatagram((char*)(resp.raw()), size, &sender, &senderPort);
sender = QHostAddress(sender.toIPv4Address());
@ -121,7 +156,10 @@ void IppDiscovery::readPendingDatagrams()
if (atype == PTR)
{
QString tmpname = get_addr(resp).join(".");
ptrs[aaddr] = tmpname;
if(aaddr.endsWith("_ipp._tcp.local"))
{
ipp_ptrs.append(tmpname);
}
}
else if(atype == TXT)
{
@ -133,7 +171,7 @@ void IppDiscovery::readPendingDatagrams()
{
std::string 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;
resp >> prio >> w >> port;
QString target = get_addr(resp).join(".");
ports[aaddr] = port;
targets[aaddr] = target;
_ports[aaddr] = port;
_targets[aaddr] = target;
}
else if(atype == A)
{
quint32 addr;
resp >> addr;
QHostAddress haddr(addr);
AAs.insert(aaddr, haddr.toString());
_AAs.insert(aaddr, haddr.toString());
}
else
{
@ -160,33 +198,26 @@ void IppDiscovery::readPendingDatagrams()
}
qDebug() << "ptrs" << ptrs;
qDebug() << "rps" << rps;
qDebug() << "ports" << ports;
qDebug() << "targets" << targets;
qDebug() << "AAs" << AAs;
qDebug() << "AAAAs" << AAAAs;
qDebug() << "new ipp ptrs" << ipp_ptrs;
qDebug() << "ipp ptrs" << _ipp;
qDebug() << "rps" << _rps;
qDebug() << "ports" << _ports;
qDebug() << "targets" << _targets;
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()];
QString target = targets[it.value()];
QString rp = rps[it.value()];
if(!_ipp.contains(*it))
{
_ipp.append(*it);
}
if(!_ports.contains(*it) || !_targets.contains(*it) || !_rps.contains(*it))
{ // if the PTR doesn't already resolve, ask for everything about it
sendQuery(ALL, it->split('.'));
}
}
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);
}
}
}
}
}
this->update();

View file

@ -12,6 +12,7 @@ public:
~IppDiscovery();
Q_PROPERTY(QStringList favourites MEMBER _favourites NOTIFY favouritesChanged)
Q_INVOKABLE void discover();
Q_INVOKABLE void reset();
signals:
void favouritesChanged();
@ -19,10 +20,20 @@ signals:
public slots:
void readPendingDatagrams();
void update();
protected:
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 _found;
QUdpSocket* socket;
};

View file

@ -78,6 +78,10 @@
<source>No printer found</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChoiceSetting</name>
@ -167,10 +171,6 @@
<source>Remove printer</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Removing printer</source>
<translation type="unfinished"></translation>
@ -179,6 +179,10 @@
<source>About SeaPrint</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>JobsPage</name>

View file

@ -78,6 +78,10 @@
<source>No printer found</source>
<translation>Aucune imprimante détectée</translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished">Inconnu</translation>
</message>
</context>
<context>
<name>ChoiceSetting</name>
@ -167,10 +171,6 @@
<source>Remove printer</source>
<translation>Supprimer l&apos;imprimante</translation>
</message>
<message>
<source>Unknown</source>
<translation>Inconnu</translation>
</message>
<message>
<source>Removing printer</source>
<translation>Suppression de l&apos;imprimante</translation>
@ -179,6 +179,10 @@
<source>About SeaPrint</source>
<translation>À propos de SeaPrint</translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished">Inconnu</translation>
</message>
</context>
<context>
<name>JobsPage</name>

View file

@ -78,6 +78,10 @@
<source>No printer found</source>
<translation></translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChoiceSetting</name>
@ -179,6 +183,10 @@
<source>Removing printer</source>
<translation></translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>JobsPage</name>

View file

@ -78,6 +78,10 @@
<source>No printer found</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChoiceSetting</name>
@ -167,10 +171,6 @@
<source>Remove printer</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Removing printer</source>
<translation type="unfinished"></translation>
@ -179,6 +179,10 @@
<source>About SeaPrint</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>JobsPage</name>