Add ConvertChecker

This commit is contained in:
Anton Thomasson 2020-05-11 20:44:53 +02:00
parent aa6daa1d77
commit 16e6d8d766
12 changed files with 189 additions and 7 deletions

View file

@ -22,6 +22,7 @@ VERSION_H = \
write_file($$$$OUT_PWD/seaprint_version.h, VERSION_H) write_file($$$$OUT_PWD/seaprint_version.h, VERSION_H)
SOURCES += src/harbour-seaprint.cpp \ SOURCES += src/harbour-seaprint.cpp \
src/convertchecker.cpp \
src/convertworker.cpp \ src/convertworker.cpp \
src/ippdiscovery.cpp \ src/ippdiscovery.cpp \
src/ippmsg.cpp \ src/ippmsg.cpp \
@ -61,6 +62,7 @@ TRANSLATIONS += translations/harbour-seaprint-de.ts \
translations/harbour-seaprint-es.ts translations/harbour-seaprint-es.ts
HEADERS += \ HEADERS += \
src/convertchecker.h \
src/convertworker.h \ src/convertworker.h \
src/ippdiscovery.h \ src/ippdiscovery.h \
src/ippmsg.h \ src/ippmsg.h \

View file

@ -1,5 +1,6 @@
import QtQuick 2.0 import QtQuick 2.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import seaprint.convertchecker 1.0
import "../components" import "../components"
Page { Page {
@ -90,7 +91,15 @@ Page {
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
text: qsTr("Chinese")+" - dashinfantry\n"+ text: qsTr("Chinese")+" - dashinfantry\n"+
qsTr("French")+" - ensag-dev, Quentí\n"+ qsTr("French")+" - ensag-dev, Quentí\n"+
qsTr("Spanish")+" - carmenfdezb" qsTr("Spanish")+" - carmenfdezb\n"+
qsTr("Polish")+" - atlochowski"
}
SectionHeader { text: qsTr("Optional dependencies") }
AboutLabel {
font.pixelSize: Theme.fontSizeSmall
text: qsTr("pdftoppm (from poppler-utils)")+" - "+(ConvertChecker.pdf ? qsTr("Installed") : qsTr("Not installed"))
} }
SectionHeader { text: qsTr("Licensing") } SectionHeader { text: qsTr("Licensing") }

View file

@ -2,6 +2,7 @@ import QtQuick 2.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import Sailfish.Pickers 1.0 import Sailfish.Pickers 1.0
import seaprint.ippdiscovery 1.0 import seaprint.ippdiscovery 1.0
import seaprint.convertchecker 1.0
import seaprint.ippprinter 1.0 import seaprint.ippprinter 1.0
import seaprint.mimer 1.0 import seaprint.mimer 1.0
import "utils.js" as Utils import "utils.js" as Utils
@ -45,6 +46,7 @@ Page {
signal refreshed() signal refreshed()
Component.onCompleted: { Component.onCompleted: {
console.log("Can convert from PDF:", ConvertChecker.pdf)
IppDiscovery.discover(); IppDiscovery.discover();
if(selectedFile != "") if(selectedFile != "")
{ {
@ -100,7 +102,7 @@ Page {
visible: false visible: false
property string name: printer.attrs["printer-name"].value != "" ? 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.supported_formats(printer).mimetypes.indexOf(selectedFileType) != -1 property bool canPrint: Utils.supported_formats(printer, ConvertChecker).mimetypes.indexOf(selectedFileType) != -1
Connections { Connections {
target: printer target: printer
@ -137,7 +139,8 @@ Page {
property int debugCount: 0 property int debugCount: 0
onClicked: { onClicked: {
console.log(Utils.supported_formats(printer).mimetypes, selectedFileType, Utils.supported_formats(printer).mimetypes.indexOf(selectedFileType) != -1) console.log(Utils.supported_formats(printer, ConvertChecker).mimetypes, selectedFileType,
Utils.supported_formats(printer, ConvertChecker).mimetypes.indexOf(selectedFileType) != -1)
if(++debugCount == 5) if(++debugCount == 5)
{ {
@ -215,14 +218,14 @@ Page {
id: format_label id: format_label
color: selectedFile == "" ? Theme.secondaryColor : canPrint ? Theme.primaryColor : "red" color: selectedFile == "" ? Theme.secondaryColor : canPrint ? Theme.primaryColor : "red"
font.pixelSize: Theme.fontSizeExtraSmall font.pixelSize: Theme.fontSizeExtraSmall
text: Utils.supported_formats(printer).supported text: Utils.supported_formats(printer, ConvertChecker).supported
} }
Label { Label {
id: maybe_format_label id: maybe_format_label
color: selectedFile == "" ? Theme.secondaryColor : canPrint ? Theme.secondaryColor : "red" color: selectedFile == "" ? Theme.secondaryColor : canPrint ? Theme.secondaryColor : "red"
font.pixelSize: Theme.fontSizeExtraSmall font.pixelSize: Theme.fontSizeExtraSmall
font.italic: true font.italic: true
text: Utils.supported_formats(printer).maybe text: Utils.supported_formats(printer, ConvertChecker).maybe
} }
} }

View file

@ -1,9 +1,9 @@
function supported_formats(printer) function supported_formats(printer, ConvertChecker)
{ {
var formats = printer.attrs["document-format-supported"].value; var formats = printer.attrs["document-format-supported"].value;
var mimetypes = []; var mimetypes = [];
var supported = []; var supported = [];
if(has(formats, "application/pdf") || has(formats, "image/pwg-raster") || has(formats, "image/urf") ) if(has(formats, "application/pdf") || (ConvertChecker.pdf && ( has(formats, "image/pwg-raster") || has(formats, "image/urf"))) )
{ {
mimetypes.push("application/pdf"); mimetypes.push("application/pdf");
supported.push("PDF"); supported.push("PDF");

40
src/convertchecker.cpp Normal file
View file

@ -0,0 +1,40 @@
#include "convertchecker.h"
#include <QProcess>
ConvertChecker::ConvertChecker()
{
_pdf = false;
QProcess* pdftoppm = new QProcess(this);
pdftoppm->setProgram("pdftoppm");
pdftoppm->setArguments({"-h"});
pdftoppm->start();
if(pdftoppm->waitForFinished(2000))
{
if(pdftoppm->exitStatus() == QProcess::NormalExit && pdftoppm->exitCode() == 0)
{
_pdf = true;
}
}
}
ConvertChecker::~ConvertChecker() {
}
ConvertChecker* ConvertChecker::m_Instance = 0;
ConvertChecker* ConvertChecker::instance()
{
static QMutex mutex;
if (!m_Instance)
{
mutex.lock();
if (!m_Instance)
m_Instance = new ConvertChecker;
mutex.unlock();
}
return m_Instance;
}

26
src/convertchecker.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef CONVERTCHECKER_H
#define CONVERTCHECKER_H
#include <QObject>
#include <QMutex>
class ConvertChecker : public QObject
{
Q_OBJECT
public:
static ConvertChecker* instance();
Q_PROPERTY(bool pdf MEMBER _pdf)
signals:
protected:
private:
static ConvertChecker* m_Instance;
ConvertChecker();
~ConvertChecker();
ConvertChecker(const ConvertChecker &);
ConvertChecker& operator=(const ConvertChecker &);
bool _pdf;
};
#endif // CONVERTCHECKER_H

View file

@ -5,6 +5,7 @@
#include <src/ippdiscovery.h> #include <src/ippdiscovery.h>
#include <src/ippprinter.h> #include <src/ippprinter.h>
#include <src/mimer.h> #include <src/mimer.h>
#include <src/convertchecker.h>
#define PPM2PWG_MAIN ppm2pwg_main #define PPM2PWG_MAIN ppm2pwg_main
#include <ppm2pwg/ppm2pwg.cpp> #include <ppm2pwg/ppm2pwg.cpp>
@ -34,6 +35,7 @@ int main(int argc, char *argv[])
qmlRegisterSingletonType<IppDiscovery>("seaprint.ippdiscovery", 1, 0, "IppDiscovery", singletontype_provider<IppDiscovery>); qmlRegisterSingletonType<IppDiscovery>("seaprint.ippdiscovery", 1, 0, "IppDiscovery", singletontype_provider<IppDiscovery>);
qmlRegisterSingletonType<Mimer>("seaprint.mimer", 1, 0, "Mimer", singletontype_provider<Mimer>); qmlRegisterSingletonType<Mimer>("seaprint.mimer", 1, 0, "Mimer", singletontype_provider<Mimer>);
qmlRegisterSingletonType<ConvertChecker>("seaprint.convertchecker", 1, 0, "ConvertChecker", singletontype_provider<ConvertChecker>);
qmlRegisterType<IppPrinter>("seaprint.ippprinter", 1, 0, "IppPrinter"); qmlRegisterType<IppPrinter>("seaprint.ippprinter", 1, 0, "IppPrinter");
QQuickView* view = SailfishApp::createView(); QQuickView* view = SailfishApp::createView();

View file

@ -63,6 +63,26 @@
<source>Spanish</source> <source>Spanish</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Polish</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Optional dependencies</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>pdftoppm (from poppler-utils)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Installed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Not installed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>AddPrinterDialog</name> <name>AddPrinterDialog</name>

View file

@ -63,6 +63,26 @@
<source>Spanish</source> <source>Spanish</source>
<translation>Español</translation> <translation>Español</translation>
</message> </message>
<message>
<source>Polish</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Optional dependencies</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>pdftoppm (from poppler-utils)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Installed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Not installed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>AddPrinterDialog</name> <name>AddPrinterDialog</name>

View file

@ -63,6 +63,26 @@
<source>Spanish</source> <source>Spanish</source>
<translation>Espagnol</translation> <translation>Espagnol</translation>
</message> </message>
<message>
<source>Polish</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Optional dependencies</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>pdftoppm (from poppler-utils)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Installed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Not installed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>AddPrinterDialog</name> <name>AddPrinterDialog</name>

View file

@ -63,6 +63,26 @@
<source>Spanish</source> <source>Spanish</source>
<translation>西</translation> <translation>西</translation>
</message> </message>
<message>
<source>Polish</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Optional dependencies</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>pdftoppm (from poppler-utils)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Installed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Not installed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>AddPrinterDialog</name> <name>AddPrinterDialog</name>

View file

@ -63,6 +63,26 @@
<source>Spanish</source> <source>Spanish</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Polish</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Optional dependencies</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>pdftoppm (from poppler-utils)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Installed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Not installed</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>AddPrinterDialog</name> <name>AddPrinterDialog</name>