diff --git a/qml/pages/AddPrinterDialog.qml b/qml/pages/AddPrinterDialog.qml index e3d21eb..bbc2714 100644 --- a/qml/pages/AddPrinterDialog.qml +++ b/qml/pages/AddPrinterDialog.qml @@ -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 } } diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 24407b4..d67eebb 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -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 { diff --git a/src/ippdiscovery.cpp b/src/ippdiscovery.cpp index 30b81c0..823b224 100644 --- a/src/ippdiscovery.cpp +++ b/src/ippdiscovery.cpp @@ -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(); + _ports = QMap(); + _targets = QMap(); + + _AAs = QMultiMap(); + _AAAAs = QMultiMap(); + + 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::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 ptrs; - QMap rps; - QMap ports; - QMap targets; - QMultiMap AAs; - QMultiMap 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::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()]; - - for(QMultiMap::Iterator ait = AAs.begin(); ait != AAs.end(); ait++) + if(!_ipp.contains(*it)) { - 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); - } - } + _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('.')); } } + } this->update(); diff --git a/src/ippdiscovery.h b/src/ippdiscovery.h index f988eaa..d0d59e8 100644 --- a/src/ippdiscovery.h +++ b/src/ippdiscovery.h @@ -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 _rps; + QMap _ports; + QMap _targets; + + QMultiMap _AAs; + QMultiMap _AAAAs; + QStringList _favourites; - QStringList _found; QUdpSocket* socket; }; diff --git a/translations/harbour-seaprint-de.ts b/translations/harbour-seaprint-de.ts index 9b5fbea..42ad3c1 100644 --- a/translations/harbour-seaprint-de.ts +++ b/translations/harbour-seaprint-de.ts @@ -78,6 +78,10 @@ No printer found + + Unknown + + ChoiceSetting @@ -167,10 +171,6 @@ Remove printer - - Unknown - - Removing printer @@ -179,6 +179,10 @@ About SeaPrint + + Unknown + + JobsPage diff --git a/translations/harbour-seaprint-fr.ts b/translations/harbour-seaprint-fr.ts index 1b0ae2f..8eba296 100644 --- a/translations/harbour-seaprint-fr.ts +++ b/translations/harbour-seaprint-fr.ts @@ -78,6 +78,10 @@ No printer found Aucune imprimante détectée + + Unknown + Inconnu + ChoiceSetting @@ -167,10 +171,6 @@ Remove printer Supprimer l'imprimante - - Unknown - Inconnu - Removing printer Suppression de l'imprimante @@ -179,6 +179,10 @@ About SeaPrint À propos de SeaPrint + + Unknown + Inconnu + JobsPage diff --git a/translations/harbour-seaprint-zh_CN.ts b/translations/harbour-seaprint-zh_CN.ts index d63f268..f88111d 100644 --- a/translations/harbour-seaprint-zh_CN.ts +++ b/translations/harbour-seaprint-zh_CN.ts @@ -78,6 +78,10 @@ No printer found 没有找到打印机 + + Unknown + + ChoiceSetting @@ -179,6 +183,10 @@ Removing printer 正在移除打印机 + + Unknown + + JobsPage diff --git a/translations/harbour-seaprint.ts b/translations/harbour-seaprint.ts index 9b5fbea..42ad3c1 100644 --- a/translations/harbour-seaprint.ts +++ b/translations/harbour-seaprint.ts @@ -78,6 +78,10 @@ No printer found + + Unknown + + ChoiceSetting @@ -167,10 +171,6 @@ Remove printer - - Unknown - - Removing printer @@ -179,6 +179,10 @@ About SeaPrint + + Unknown + + JobsPage