Merge branch 'master' into master

This commit is contained in:
attah 2020-01-03 11:13:41 +01:00 committed by GitHub
commit b4f5155a3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 153 additions and 87 deletions

View file

@ -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
} }
} }

View file

@ -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 {

View file

@ -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();

View file

@ -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;
}; };

View file

@ -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>

View file

@ -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&apos;imprimante</translation> <translation>Supprimer l&apos;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&apos;imprimante</translation> <translation>Suppression de l&apos;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>

View file

@ -5,59 +5,59 @@
<name>AboutPage</name> <name>AboutPage</name>
<message> <message>
<source>GitHub repository</source> <source>GitHub repository</source>
<translation type="unfinished"></translation> <translation>Github </translation>
</message> </message>
<message> <message>
<source>Report an Issue</source> <source>Report an Issue</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>About</source> <source>About</source>
<translation type="unfinished"></translation> <translation><关于/translation>
</message> </message>
<message> <message>
<source>Network printing for Sailfish OS.</source> <source>Network printing for Sailfish OS.</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Icons</source> <source>Icons</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Icon made by Gregguh.</source> <source>Icon made by Gregguh.</source>
<translation type="unfinished"></translation> <translation> Gregguh </translation>
</message> </message>
<message> <message>
<source>General contributions</source> <source>General contributions</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Translations</source> <source>Translations</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Chinese</source> <source>Chinese</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Licensing</source> <source>Licensing</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Source code is available at GitHub. Translations, bug reports and other contributions are welcome!</source> <source>Source code is available at GitHub. Translations, bug reports and other contributions are welcome!</source>
<translation type="unfinished"></translation> <translation> Github </translation>
</message> </message>
<message> <message>
<source>SeaPrint licencing is still TBD, but will be some flavor of open.</source> <source>SeaPrint licencing is still TBD, but will be some flavor of open.</source>
<translation type="unfinished"></translation> <translation>Seaprint TBD 使</translation>
</message> </message>
<message> <message>
<source>French</source> <source>French</source>
<translation type="unfinished"></translation> <translation><法语/translation>
</message> </message>
<message> <message>
<source>Code and Testing - Rudi Timmermans</source> <source>Code and Testing - Rudi Timmermans</source>
<translation type="unfinished"></translation> <translation type="unfinished"> - Rudi Timmermans</translation>
</message> </message>
</context> </context>
<context> <context>
@ -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>
@ -130,7 +134,7 @@
<name>CoverPage</name> <name>CoverPage</name>
<message> <message>
<source>SeaPrint</source> <source>SeaPrint</source>
<translation type="unfinished"></translation> <translation>SeaPrint</translation>
</message> </message>
</context> </context>
<context> <context>
@ -161,22 +165,26 @@
</message> </message>
<message> <message>
<source>About SeaPrint</source> <source>About SeaPrint</source>
<translation type="unfinished"></translation> <translation> SeaPrint</translation>
</message> </message>
<message> <message>
<source>Unknown</source> <source>Unknown</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>View jobs</source> <source>View jobs</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Remove printer</source> <source>Remove printer</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Removing printer</source> <source>Removing printer</source>
<translation></translation>
</message>
<message>
<source>Unknown</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
@ -184,27 +192,27 @@
<name>JobsPage</name> <name>JobsPage</name>
<message> <message>
<source>Refresh</source> <source>Refresh</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>job</source> <source>job</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>jobs</source> <source>jobs</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Untitled job</source> <source>Untitled job</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Cancel job</source> <source>Cancel job</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Cancelling job</source> <source>Cancelling job</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
</context> </context>
<context> <context>
@ -235,15 +243,15 @@
</message> </message>
<message> <message>
<source>Unknown</source> <source>Unknown</source>
<translation type="unfinished"></translation> <translation></translation>
</message> </message>
<message> <message>
<source>Print success: </source> <source>Print success: </source>
<translation type="unfinished"></translation> <translation>:</translation>
</message> </message>
<message> <message>
<source>Print failed: </source> <source>Print failed: </source>
<translation type="unfinished"></translation> <translation>:</translation>
</message> </message>
</context> </context>
</TS> </TS>

View file

@ -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>