Get printer strings
This commit is contained in:
parent
6c4e48d69c
commit
0684e677ec
8 changed files with 70 additions and 17 deletions
|
@ -11,14 +11,15 @@ Setting {
|
|||
|
||||
property int num_large_choices: 8
|
||||
|
||||
displayValue: Utils.ippName(name, choice != undefined ? choice : default_choice)
|
||||
displayValue: Utils.ippName(name, choice != undefined ? choice : default_choice, strings)
|
||||
|
||||
onClicked: {
|
||||
if(actual_choices.length>num_large_choices)
|
||||
{
|
||||
var dialog = pageStack.push("LargeChoiceDialog.qml",
|
||||
{name:name, choice: choice != undefined ? choice : default_choice, choices: actual_choices,
|
||||
preferred_choices: preferred_choices, preferred_choice_suffix: preferred_choice_suffix})
|
||||
preferred_choices: preferred_choices, preferred_choice_suffix: preferred_choice_suffix,
|
||||
strings: strings})
|
||||
dialog.accepted.connect(function() {
|
||||
choice = dialog.choice
|
||||
})
|
||||
|
@ -33,7 +34,7 @@ Setting {
|
|||
Repeater {
|
||||
model: actual_choices.length>num_large_choices ? 0 : actual_choices
|
||||
MenuItem {
|
||||
text: Utils.ippName(name, actual_choices[index])
|
||||
text: Utils.ippName(name, actual_choices[index], strings)
|
||||
+ (Utils.has(preferred_choices, actual_choices[index]) ? " "+preferred_choice_suffix : "")
|
||||
onClicked:
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@ Dialog {
|
|||
property var choices
|
||||
property var preferred_choices
|
||||
property string preferred_choice_suffix
|
||||
property var strings
|
||||
canAccept: false
|
||||
|
||||
SilicaListView
|
||||
|
@ -30,7 +31,7 @@ Dialog {
|
|||
x: Theme.paddingLarge
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
highlighted: choices[index]==new_choice
|
||||
text: Utils.ippName(name, choices[index])
|
||||
text: Utils.ippName(name, choices[index], strings)
|
||||
+ (Utils.has(preferred_choices, choices[index]) ? " "+preferred_choice_suffix : "")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ Item {
|
|||
property var choice
|
||||
property var default_choice: parent.getDefaultChoice(name)
|
||||
|
||||
property var strings: parent.printer.strings
|
||||
|
||||
Component.onCompleted: parent.setInitialChoice(this)
|
||||
|
||||
onChoiceChanged: parent.choiceMade(this)
|
||||
|
|
|
@ -59,7 +59,7 @@ function has(arrayish, what)
|
|||
return arrayish.indexOf(what) != -1;
|
||||
}
|
||||
|
||||
function ippName(name, value)
|
||||
function ippName(name, value, strings)
|
||||
{
|
||||
if(value==undefined)
|
||||
{
|
||||
|
@ -143,6 +143,10 @@ function ippName(name, value)
|
|||
{
|
||||
return mediaType[value];
|
||||
}
|
||||
else if(strings != undefined && strings.hasOwnProperty("media-type."+value))
|
||||
{
|
||||
return strings["media-type."+value];
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
|
|
|
@ -25,6 +25,9 @@ IppPrinter::IppPrinter()
|
|||
connect(this, &IppPrinter::doConvertImage, _worker, &PrinterWorker::convertImage);
|
||||
connect(this, &IppPrinter::doConvertOfficeDocument, _worker, &PrinterWorker::convertOfficeDocument);
|
||||
connect(this, &IppPrinter::doConvertPlaintext, _worker, &PrinterWorker::convertPlaintext);
|
||||
|
||||
connect(this, &IppPrinter::doGetStrings, _worker, &PrinterWorker::getStrings);
|
||||
|
||||
connect(_worker, &PrinterWorker::progress, this, &IppPrinter::setProgress);
|
||||
connect(_worker, &PrinterWorker::busyMessage, this, &IppPrinter::setBusyMessage);
|
||||
connect(_worker, &PrinterWorker::failed, this, &IppPrinter::convertFailed);
|
||||
|
@ -90,12 +93,6 @@ void IppPrinter::onUrlChanged()
|
|||
}
|
||||
|
||||
void IppPrinter::refresh() {
|
||||
// _attrs = QJsonObject();
|
||||
// emit attrsChanged();
|
||||
|
||||
// _additionalDocumentFormats = QStringList();
|
||||
// emit additionalDocumentFormatsChanged();
|
||||
|
||||
|
||||
if(_url.scheme() == "file")
|
||||
{
|
||||
|
@ -113,6 +110,8 @@ void IppPrinter::refresh() {
|
|||
Overrider::instance()->apply(_attrs);
|
||||
}
|
||||
emit attrsChanged();
|
||||
|
||||
MaybeGetStrings();
|
||||
UpdateAdditionalDocumentFormats();
|
||||
}
|
||||
else
|
||||
|
@ -124,6 +123,15 @@ void IppPrinter::refresh() {
|
|||
}
|
||||
}
|
||||
|
||||
void IppPrinter::MaybeGetStrings()
|
||||
{
|
||||
// TODO: resolve .local
|
||||
if(_attrs.contains("printer-strings-uri") && _strings.empty())
|
||||
{
|
||||
emit doGetStrings(QUrl(_attrs["printer-strings-uri"].toObject()["value"].toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void IppPrinter::UpdateAdditionalDocumentFormats()
|
||||
{
|
||||
_additionalDocumentFormats = QStringList();
|
||||
|
@ -175,6 +183,7 @@ void IppPrinter::getPrinterAttributesFinished(CURLcode res, Bytestream data)
|
|||
|
||||
emit attrsChanged();
|
||||
|
||||
MaybeGetStrings();
|
||||
UpdateAdditionalDocumentFormats();
|
||||
}
|
||||
|
||||
|
@ -247,6 +256,25 @@ void IppPrinter::cancelJobFinished(CURLcode res, Bytestream data)
|
|||
getJobs();
|
||||
}
|
||||
|
||||
void IppPrinter::getStringsFinished(CURLcode res, Bytestream data)
|
||||
{
|
||||
qDebug() << res << data.size();
|
||||
if(res == CURLE_OK)
|
||||
{
|
||||
QByteArray ba((char*)data.raw(), data.size());
|
||||
// "media-type.com.epson-coated" = "Epson Photo Quality Ink Jet";
|
||||
QRegularExpression re("^\\\"(.*)\\\"\\s*=\\s*\\\"(.*)\\\";");
|
||||
QList<QByteArray> bl = ba.split('\n');
|
||||
foreach(QByteArray l, bl)
|
||||
{
|
||||
QRegularExpressionMatch match = re.match(l);
|
||||
if(match.hasMatch())
|
||||
{
|
||||
_strings[match.captured(1)] = match.captured(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IppPrinter::ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@ class IppPrinter : public QObject
|
|||
Q_PROPERTY(QJsonObject attrs MEMBER _attrs NOTIFY attrsChanged)
|
||||
Q_PROPERTY(QJsonObject jobAttrs MEMBER _jobAttrs NOTIFY jobAttrsChanged)
|
||||
Q_PROPERTY(QJsonArray jobs MEMBER _jobs NOTIFY jobsChanged)
|
||||
Q_PROPERTY(QJsonObject strings MEMBER _strings NOTIFY stringsChanged)
|
||||
Q_PROPERTY(QStringList additionalDocumentFormats MEMBER _additionalDocumentFormats NOTIFY additionalDocumentFormatsChanged)
|
||||
Q_PROPERTY(QString busyMessage MEMBER _busyMessage NOTIFY busyMessageChanged)
|
||||
Q_PROPERTY(QString progress MEMBER _progress NOTIFY progressChanged)
|
||||
|
@ -47,6 +48,8 @@ signals:
|
|||
void jobAttrsChanged();
|
||||
void jobsChanged();
|
||||
|
||||
void stringsChanged();
|
||||
|
||||
void jobFinished(bool status);
|
||||
void cancelStatus(bool status);
|
||||
|
||||
|
@ -74,6 +77,8 @@ signals:
|
|||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||
quint32 HwResX, quint32 HwResY, bool TwoSided, bool Tumble, bool BackHFlip, bool BackVFlip);
|
||||
|
||||
void doGetStrings(QUrl url);
|
||||
|
||||
void additionalDocumentFormatsChanged();
|
||||
void busyMessageChanged();
|
||||
void progressChanged();
|
||||
|
@ -83,12 +88,15 @@ public slots:
|
|||
|
||||
|
||||
void onUrlChanged();
|
||||
void MaybeGetStrings();
|
||||
void UpdateAdditionalDocumentFormats();
|
||||
void getPrinterAttributesFinished(CURLcode res, Bytestream data);
|
||||
void printRequestFinished(CURLcode res, Bytestream data);
|
||||
void getJobsRequestFinished(CURLcode res, Bytestream data);
|
||||
void cancelJobFinished(CURLcode res, Bytestream data);
|
||||
|
||||
void getStringsFinished(CURLcode res, Bytestream data);
|
||||
|
||||
static void ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
|
||||
|
||||
void convertFailed(QString message);
|
||||
|
@ -113,6 +121,8 @@ private:
|
|||
QJsonObject _jobAttrs;
|
||||
QJsonArray _jobs;
|
||||
|
||||
QJsonObject _strings;
|
||||
|
||||
QStringList _additionalDocumentFormats;
|
||||
|
||||
QString _busyMessage;
|
||||
|
|
|
@ -20,24 +20,30 @@ PrinterWorker::PrinterWorker(IppPrinter* parent)
|
|||
_printer = parent;
|
||||
}
|
||||
|
||||
void PrinterWorker::getStrings(QUrl url)
|
||||
{
|
||||
CurlRequester cr(url, CurlRequester::HttpGetRequest);
|
||||
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::getStringsFinished);
|
||||
}
|
||||
|
||||
void PrinterWorker::getPrinterAttributes(Bytestream msg)
|
||||
{
|
||||
CurlRequester cr(_printer->httpUrl());
|
||||
cr.setFinishedCallback(_printer, &IppPrinter::getPrinterAttributesFinished);
|
||||
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::getPrinterAttributesFinished);
|
||||
cr.write((char*)msg.raw(), msg.size());
|
||||
}
|
||||
|
||||
void PrinterWorker::getJobs(Bytestream msg)
|
||||
{
|
||||
CurlRequester cr(_printer->httpUrl());
|
||||
cr.setFinishedCallback(_printer, &IppPrinter::getJobsRequestFinished);
|
||||
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::getJobsRequestFinished);
|
||||
cr.write((char*)msg.raw(), msg.size());
|
||||
}
|
||||
|
||||
void PrinterWorker::cancelJob(Bytestream msg)
|
||||
{
|
||||
CurlRequester cr(_printer->httpUrl());
|
||||
cr.setFinishedCallback(_printer, &IppPrinter::cancelJobFinished);
|
||||
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::cancelJobFinished);
|
||||
cr.write((char*)msg.raw(), msg.size());
|
||||
}
|
||||
|
||||
|
@ -47,7 +53,7 @@ try {
|
|||
emit busyMessage(tr("Printing"));
|
||||
|
||||
CurlRequester cr(_printer->httpUrl());
|
||||
cr.setFinishedCallback(_printer, &IppPrinter::printRequestFinished);
|
||||
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::printRequestFinished);
|
||||
|
||||
QFile file(filename);
|
||||
file.open(QFile::ReadOnly);
|
||||
|
@ -100,7 +106,7 @@ try {
|
|||
}
|
||||
|
||||
CurlRequester cr(_printer->httpUrl());
|
||||
cr.setFinishedCallback(_printer, &IppPrinter::printRequestFinished);
|
||||
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::printRequestFinished);
|
||||
|
||||
OK(cr.write((char*)header.raw(), header.size()));
|
||||
|
||||
|
@ -287,7 +293,7 @@ try {
|
|||
}
|
||||
|
||||
CurlRequester cr(_printer->httpUrl());
|
||||
cr.setFinishedCallback(_printer, &IppPrinter::printRequestFinished);
|
||||
connect(&cr, &CurlRequester::done, _printer, &IppPrinter::printRequestFinished);
|
||||
|
||||
OK(cr.write((char*)header.raw(), header.size()));
|
||||
OK(cr.write((char*)(outBts.raw()), outBts.size()));
|
||||
|
|
|
@ -31,6 +31,7 @@ private:
|
|||
PrinterWorker();
|
||||
|
||||
public slots:
|
||||
void getStrings(QUrl url);
|
||||
void getPrinterAttributes(Bytestream msg);
|
||||
void getJobs(Bytestream msg);
|
||||
void cancelJob(Bytestream msg);
|
||||
|
|
Loading…
Reference in a new issue