Merge lp:~jonas-drange/ubuntu-printing-app/soft-depend-on-printjob into lp:ubuntu-printing-app

Proposed by Jonas G. Drange
Status: Superseded
Proposed branch: lp:~jonas-drange/ubuntu-printing-app/soft-depend-on-printjob
Merge into: lp:ubuntu-printing-app
Diff against target: 6026 lines (+3783/-1507)
66 files modified
CMakeLists.txt (+34/-34)
backend/CMakeLists.txt (+12/-21)
backend/UbuntuPrintingApp/backend.cpp (+22/-16)
backend/UbuntuPrintingApp/backend.h (+20/-1)
backend/UbuntuPrintingApp/document.cpp (+80/-275)
backend/UbuntuPrintingApp/document.h (+35/-6)
backend/UbuntuPrintingApp/pagehelper.cpp (+104/-0)
backend/UbuntuPrintingApp/pagehelper.h (+55/-0)
backend/UbuntuPrintingApp/popplerimageprovider.cpp (+58/-18)
backend/UbuntuPrintingApp/popplerimageprovider.h (+19/-0)
backend/UbuntuPrintingApp/qmldir (+2/-2)
backend/Ubuntu_Printing_App/printer.cpp (+0/-355)
backend/Ubuntu_Printing_App/printer.h (+0/-94)
backend/Ubuntu_Printing_App/printerinfo.cpp (+0/-39)
backend/Ubuntu_Printing_App/printerinfo.h (+0/-30)
backend/tests/unit/tst_mytype.qml (+0/-49)
debian/changelog (+1/-1)
debian/control (+15/-6)
debian/copyright (+1/-1)
manifest.json.in (+0/-16)
po/CMakeLists.txt (+44/-0)
po/ubuntu-printing-app.pot (+122/-0)
runner/CMakeLists.txt (+5/-2)
runner/ubuntu-printing-app (+0/-3)
runner/ubuntu-printing-app.in (+3/-0)
setup/gui/ubuntu-printing-app.desktop (+8/-0)
snapcraft.yaml (+75/-0)
tests/CMakeLists.txt (+3/-0)
tests/qmltests/CMakeLists.txt (+46/-0)
tests/qmltests/tst_CheckBoxRow.qml (+87/-0)
tests/qmltests/tst_LabelRow.qml (+73/-0)
tests/qmltests/tst_PreviewRow.qml (+316/-0)
tests/qmltests/tst_PrintPage.qml (+437/-0)
tests/qmltests/tst_PrintRow.qml (+110/-0)
tests/qmltests/tst_SelectorRow.qml (+136/-0)
tests/qmltests/tst_TextFieldRow.qml (+174/-0)
tests/resources/CMakeLists.txt (+6/-0)
tests/resources/pdf/CMakeLists.txt (+3/-0)
tests/resources/pdf/corrupt.pdf (+3/-0)
tests/unittests/CMakeLists.txt (+1/-0)
tests/unittests/backend/CMakeLists.txt (+19/-0)
tests/unittests/backend/tst_document.cpp (+301/-0)
tests/unittests/backend/tst_pagehelper.cpp (+171/-0)
tests/unittests/backend/tst_popplerimageprovider.cpp (+127/-0)
ubuntu-printing-app/CMakeLists.txt (+2/-1)
ubuntu-printing-app/Main.qml (+113/-281)
ubuntu-printing-app/components/AlertDialog.qml (+32/-0)
ubuntu-printing-app/components/CMakeLists.txt (+6/-1)
ubuntu-printing-app/components/CheckBoxRow.qml (+76/-0)
ubuntu-printing-app/components/ExpandableListItem.qml (+0/-82)
ubuntu-printing-app/components/LabelRow.qml (+52/-0)
ubuntu-printing-app/components/PreviewRow.qml (+142/-0)
ubuntu-printing-app/components/PrintRow.qml (+20/-1)
ubuntu-printing-app/components/PrintingHelper.qml (+38/-0)
ubuntu-printing-app/components/SelectorRow.qml (+43/-3)
ubuntu-printing-app/components/TextFieldRow.qml (+54/-0)
ubuntu-printing-app/pages/CMakeLists.txt (+9/-0)
ubuntu-printing-app/pages/ContentPeerPickerPage.qml (+138/-0)
ubuntu-printing-app/pages/PrintPage.qml (+299/-0)
ubuntu-printing-app/tests/autopilot/run (+0/-11)
ubuntu-printing-app/tests/autopilot/ubuntu_printing_app/__init__.py (+0/-41)
ubuntu-printing-app/tests/autopilot/ubuntu_printing_app/tests/__init__.py (+0/-54)
ubuntu-printing-app/tests/autopilot/ubuntu_printing_app/tests/test_main.py (+0/-21)
ubuntu-printing-app/tests/unit/tst_main.qml (+0/-41)
ubuntu-printing-app/ubuntu-printing-app-apparmor.manifest (+29/-0)
ubuntu-printing-app/ubuntu-printing-app.desktop.in.in (+2/-1)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-printing-app/soft-depend-on-printjob
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+316775@code.launchpad.net

Commit message

* stops instantiating printerjob directly
* create printerjobs from Printers.createJob(printerName)

To post a comment you must log in.

Unmerged revisions

67. By Jonas G. Drange

set job values before page is pushed

66. By Jonas G. Drange

update to latest usc printing api

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2016-12-13 23:40:36 +0000
+++ CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -17,52 +17,41 @@
17set(APP_HARDCODE ubuntu-printing-app)17set(APP_HARDCODE ubuntu-printing-app)
18set(CMAKE_AUTOMOC ON)18set(CMAKE_AUTOMOC ON)
19set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") # -fno-permissive -pedantic -Wall -Wextra")19set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") # -fno-permissive -pedantic -Wall -Wextra")
20set(UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Tell QtCreator the location and name o the manifest file")
21set(DESKTOP_FILE "${APP_NAME}.desktop")20set(DESKTOP_FILE "${APP_NAME}.desktop")
22set(ICON_FILE ubuntu-printing-app.png)21set(ICON_FILE ubuntu-printing-app.png)
23set(MAIN_QML Main.qml)22set(MAIN_QML Main.qml)
23set(RUNNER ${APP_HARDCODE})
24set(SNAP_DESKTOP_FILE setup/gui/${DESKTOP_FILE})
2425
25# Set the options26# Set the options
26option(CLICK_MODE "Build as a click package" off)27option(SNAP_MODE "Build as a snap package" off)
2728
28# Find packages29# Find packages
29find_package(Qt5Core)30find_package(Qt5Core REQUIRED)
30find_package(Qt5Qml)31find_package(Qt5Qml REQUIRED)
31find_package(Qt5Quick)32find_package(Qt5Quick REQUIRED)
32find_package(Qt5PrintSupport)33find_package(Qt5PrintSupport REQUIRED)
3334
34include(GNUInstallDirs)35include(GNUInstallDirs)
3536
3637
37# Set the path for the QML files and the backend38# Set the path for the QML files and the backend
38if(CLICK_MODE)39set(UBUNTU_PRINTING_APP_DATA_DIR "${CMAKE_INSTALL_DATADIR}/${APP_HARDCODE}")
39 message("CLICK_MODE is not supported at this time!")40execute_process(
40else(CLICK_MODE)41COMMAND qmake -query QT_INSTALL_QML
41 set(UBUNTU_PRINTING_APP_DATA_DIR "${CMAKE_INSTALL_DATADIR}/${APP_HARDCODE}")42 OUTPUT_VARIABLE QT_IMPORTS_DIR
42 execute_process(43 OUTPUT_STRIP_TRAILING_WHITESPACE
43 COMMAND qmake -query QT_INSTALL_QML44)
44 OUTPUT_VARIABLE QT_IMPORTS_DIR45set(MODULE_PATH ${QT_IMPORTS_DIR}/UbuntuPrintingApp)
45 OUTPUT_STRIP_TRAILING_WHITESPACE46
46 )47# Set the exec path
48if(SNAP_MODE)
49 set(EXEC "APP_ID=${APP_HARDCODE} qmlscene $@ -I $SNAP/${MODULE_PATH} $SNAP/${CMAKE_INSTALL_PREFIX}/${UBUNTU_PRINTING_APP_DATA_DIR}/${MAIN_QML}")
50 set(ICON "$SNAP/${CMAKE_INSTALL_PREFIX}/${UBUNTU_PRINTING_APP_DATA_DIR}/${ICON_FILE}")
51else(SNAP_MODE)
52 set(EXEC "APP_ID=${APP_HARDCODE} qmlscene $@ -I ${MODULE_PATH} ${CMAKE_INSTALL_PREFIX}/${UBUNTU_PRINTING_APP_DATA_DIR}/${MAIN_QML}")
47 set(ICON ${CMAKE_INSTALL_PREFIX}/${UBUNTU_PRINTING_APP_DATA_DIR}/${ICON_FILE})53 set(ICON ${CMAKE_INSTALL_PREFIX}/${UBUNTU_PRINTING_APP_DATA_DIR}/${ICON_FILE})
48 set(MODULE_PATH ${QT_IMPORTS_DIR}/Ubuntu_Printing_App)54endif(SNAP_MODE)
49endif(CLICK_MODE)
50
51# Set the exec path
52if (CLICK_MODE)
53 message("CLICK_MODE is not supported at this time!")
54else(CLICK_MODE)
55 # FIXME should this point to the runner?
56 set(EXEC "qmlscene $@ -I ${MODULE_PATH} ${CMAKE_INSTALL_PREFIX}/${UBUNTU_PRINTING_APP_DATA_DIR}/${MAIN_QML}")
57endif(CLICK_MODE)
58
59
60# Find translatable files
61file(GLOB_RECURSE I18N_SRC_FILES
62 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/po
63 *.qml *.js *.cpp)
64list(APPEND I18N_SRC_FILES ${DESKTOP_FILE}.in.in.h)
65list(SORT I18N_SRC_FILES)
6655
6756
68# Add subdirs57# Add subdirs
@@ -70,10 +59,21 @@
70add_subdirectory(runner)59add_subdirectory(runner)
71add_subdirectory(ubuntu-printing-app)60add_subdirectory(ubuntu-printing-app)
7261
62# Setup gettext defs and include po directory
63set(GETTEXT_PACKAGE "ubuntu-printing-app")
64add_definitions(-DI18N_DOMAIN="${GETTEXT_PACKAGE}")
65
66add_subdirectory(po)
67
68# Add tests
69find_package(Qt5Test REQUIRED)
70enable_testing()
71add_subdirectory(tests)
72
7373
74# Add run command for QtC74# Add run command for QtC
75add_custom_target("run" /usr/bin/qmlscene -I ${CMAKE_BINARY_DIR}/backend ${CMAKE_SOURCE_DIR}/ubuntu-printing-app/Main.qml75add_custom_target("run" /usr/bin/qmlscene -I ${CMAKE_BINARY_DIR}/backend ${CMAKE_SOURCE_DIR}/ubuntu-printing-app/Main.qml
76 DEPENDS Ubuntu_Printing_App Ubuntu_Printing_App_qmldir76 DEPENDS UbuntuPrintingApp UbuntuPrintingAppqmldir
77 WORKING_DIRECTORY ./ubuntu-printing-app)77 WORKING_DIRECTORY ./ubuntu-printing-app)
7878
79# Show files in QtC79# Show files in QtC
8080
=== modified file 'backend/CMakeLists.txt'
--- backend/CMakeLists.txt 2016-12-13 23:40:36 +0000
+++ backend/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -1,43 +1,34 @@
1include_directories(1include_directories(
2 ${CMAKE_CURRENT_SOURCE_DIR}2 ${CMAKE_CURRENT_SOURCE_DIR}
3 /usr/include/cups/
4 /usr/include/poppler/qt5/3 /usr/include/poppler/qt5/
5 ${Qt5PrintSupport_INCLUDE_DIRS}
6)4)
75
8#add_definitions(6set(LIBNAME UbuntuPrintingAppbackend)
9# -DGETTEXT_PACKAGE=\"${PROJECT_NAME}\"
10# -DGETTEXT_LOCALEDIR=\"${CMAKE_INSTALL_LOCALEDIR}\"
11#)
12
13set(LIBNAME Ubuntu_Printing_Appbackend)
147
15set(8set(
16 Ubuntu_Printing_App_SRC9 UbuntuPrintingAppSRC
17 Ubuntu_Printing_App/backend.cpp10 UbuntuPrintingApp/backend.cpp
18 Ubuntu_Printing_App/document.cpp11 UbuntuPrintingApp/document.cpp
19 Ubuntu_Printing_App/popplerimageprovider.cpp12 UbuntuPrintingApp/popplerimageprovider.cpp
20 Ubuntu_Printing_App/printer.cpp13 UbuntuPrintingApp/pagehelper.cpp
21 Ubuntu_Printing_App/printerinfo.cpp
22)14)
2315
24add_library(${LIBNAME} SHARED ${Ubuntu_Printing_App_SRC})16add_library(${LIBNAME} SHARED ${UbuntuPrintingAppSRC})
2517
26qt5_use_modules(${LIBNAME} Core Gui Qml Quick PrintSupport)18qt5_use_modules(${LIBNAME} Core Gui Qml Quick)
27target_link_libraries(${LIBNAME}19target_link_libraries(${LIBNAME}
28 cups
29 poppler-qt520 poppler-qt5
30)21)
3122
32set_target_properties(${LIBNAME} PROPERTIES23set_target_properties(${LIBNAME} PROPERTIES
33 LIBRARY_OUTPUT_DIRECTORY Ubuntu_Printing_App24 LIBRARY_OUTPUT_DIRECTORY UbuntuPrintingApp
34)25)
3526
36# Copy the qmldir file to the build dir27# Copy the qmldir file to the build dir
37add_custom_target(Ubuntu_Printing_App_qmldir ALL28add_custom_target(UbuntuPrintingApp_qmldir ALL
38 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Ubuntu_Printing_App/qmldir ${CMAKE_CURRENT_BINARY_DIR}/Ubuntu_Printing_App29 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/UbuntuPrintingApp/qmldir ${CMAKE_CURRENT_BINARY_DIR}/UbuntuPrintingApp
39 DEPENDS ${QMLFILES})30 DEPENDS ${QMLFILES})
4031
41# Install the plugin file32# Install the plugin file
42install(TARGETS ${LIBNAME} DESTINATION ${MODULE_PATH})33install(TARGETS ${LIBNAME} DESTINATION ${MODULE_PATH})
43install(FILES Ubuntu_Printing_App/qmldir DESTINATION ${MODULE_PATH})34install(FILES UbuntuPrintingApp/qmldir DESTINATION ${MODULE_PATH})
4435
=== renamed directory 'backend/Ubuntu_Printing_App' => 'backend/UbuntuPrintingApp'
=== modified file 'backend/UbuntuPrintingApp/backend.cpp'
--- backend/Ubuntu_Printing_App/backend.cpp 2016-12-13 12:37:45 +0000
+++ backend/UbuntuPrintingApp/backend.cpp 2017-02-08 21:32:20 +0000
@@ -1,30 +1,36 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
1#include <QtQml>20#include <QtQml>
2#include <QtQml/QQmlContext>21#include <QtQml/QQmlContext>
3#include "backend.h"22#include "backend.h"
423
5#include "document.h"24#include "document.h"
25#include "pagehelper.h"
6#include "popplerimageprovider.h"26#include "popplerimageprovider.h"
7#include "printer.h"
8#include "printerinfo.h"
9
10
11#define MAKE_SINGLETON_FACTORY(type) \
12 static QObject* type##_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine) { \
13 Q_UNUSED(engine); \
14 Q_UNUSED(scriptEngine); \
15 return new type(); \
16 }
17
18MAKE_SINGLETON_FACTORY(PrinterInfo)
19
2027
21void BackendPlugin::registerTypes(const char *uri)28void BackendPlugin::registerTypes(const char *uri)
22{29{
23 Q_ASSERT(uri == QLatin1String("Ubuntu_Printing_App"));30 Q_ASSERT(uri == QLatin1String("UbuntuPrintingApp"));
2431
25 qmlRegisterType<Document>(uri, 1, 0, "Document");32 qmlRegisterType<Document>(uri, 1, 0, "Document");
26 qmlRegisterType<Printer>(uri, 1, 0, "Printer");33 qmlRegisterType<PageHelper>(uri, 1, 0, "PageHelper");
27 qmlRegisterSingletonType<PrinterInfo>(uri, 1, 0, "PrinterInfo", PrinterInfo_singleton_factory);
28}34}
2935
30void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)36void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
3137
=== modified file 'backend/UbuntuPrintingApp/backend.h'
--- backend/Ubuntu_Printing_App/backend.h 2016-12-13 12:37:45 +0000
+++ backend/UbuntuPrintingApp/backend.h 2017-02-08 21:32:20 +0000
@@ -1,3 +1,22 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
1#ifndef BACKEND_PLUGIN_H20#ifndef BACKEND_PLUGIN_H
2#define BACKEND_PLUGIN_H21#define BACKEND_PLUGIN_H
322
@@ -7,7 +26,7 @@
7/*26/*
8 ----8<-----27 ----8<-----
928
10 import Ubuntu_Printing_App 1.029 import UbuntuPrintingApp 1.0
1130
12 Rectangle {31 Rectangle {
13 width: 20032 width: 200
1433
=== modified file 'backend/UbuntuPrintingApp/document.cpp'
--- backend/Ubuntu_Printing_App/document.cpp 2016-12-13 12:08:15 +0000
+++ backend/UbuntuPrintingApp/document.cpp 2017-02-08 21:32:20 +0000
@@ -1,3 +1,22 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
1#include "document.h"20#include "document.h"
221
3#include <QtCore/QDebug>22#include <QtCore/QDebug>
@@ -18,7 +37,7 @@
18 : QObject(parent),37 : QObject(parent),
19 m_count(0),38 m_count(0),
20 m_document(Q_NULLPTR),39 m_document(Q_NULLPTR),
21 m_url("")40 m_url(QStringLiteral(""))
22{41{
2342
24}43}
@@ -49,6 +68,21 @@
49 return fmin(destDPI.width(), destDPI.height());68 return fmin(destDPI.width(), destDPI.height());
50}69}
5170
71QSizeF Document::getPageSize(int pageNumber)
72{
73 QSizeF size;
74
75 if (m_document) {
76 Poppler::Page *page = m_document->page(pageNumber);
77
78 if (page) {
79 size = page->pageSizeF();
80 }
81 }
82
83 return size;
84}
85
52QImage Document::makeImage(QSizeF size, int pageNumber)86QImage Document::makeImage(QSizeF size, int pageNumber)
53{87{
54 if (pageNumber < 0) {88 if (pageNumber < 0) {
@@ -61,8 +95,9 @@
61 return QImage();95 return QImage();
62 }96 }
6397
64 // Splash backend has much better rendering98 if (size == QSize(0, 0)) {
65 m_document->setRenderBackend(Poppler::Document::SplashBackend);99 return QImage();
100 }
66101
67 Poppler::Page *page = m_document->page(pageNumber);102 Poppler::Page *page = m_document->page(pageNumber);
68103
@@ -74,17 +109,16 @@
74 // Calculate the DPI to render at109 // Calculate the DPI to render at
75 float res = getDpi(page->pageSizeF(), size);110 float res = getDpi(page->pageSizeF(), size);
76111
77 qDebug() << "Making image with res of" << res;
78
79 // Make the image112 // Make the image
80 QImage image = page->renderToImage(res, res, 0, 0, size.width(), size.height());113 QImage image = page->renderToImage(res, res, 0, 0, size.width(), size.height());
81114
115 delete page;
116
82 if (image.isNull()) {117 if (image.isNull()) {
83 qWarning() << "Image is null";118 qWarning() << "Image is null";
119 return QImage();
84 }120 }
85121
86 delete page;
87
88 return image;122 return image;
89}123}
90124
@@ -100,13 +134,10 @@
100 return QImage();134 return QImage();
101 }135 }
102136
103 // Splash backend has much better rendering
104 m_document->setRenderBackend(Poppler::Document::SplashBackend);
105
106 Poppler::Page *page = m_document->page(pageNumber);137 Poppler::Page *page = m_document->page(pageNumber);
107138
108 if (!page) {139 if (!page) {
109 qWarning() << "Invalid page";140 qWarning() << "Invalid page:" << pageNumber;
110 return QImage();141 return QImage();
111 }142 }
112143
@@ -120,17 +151,13 @@
120151
121 // Make the image152 // Make the image
122 QImage image = makeImage(scaledSize, pageNumber);153 QImage image = makeImage(scaledSize, pageNumber);
123// image.setDotsPerMeterX(6000);
124// image.setDotsPerMeterY(6000);
125154
126 if (!color) {155 if (!color) {
127 image = image.convertToFormat(QImage::Format_Grayscale8);156 image = image.convertToFormat(QImage::Format_Grayscale8);
128 }157 }
129158
130 qDebug() << "i" << image.width() << scaledSize.width() << image.dotsPerMeterX();
131
132 // Make a container then put the content image inside159 // Make a container then put the content image inside
133 QImage container(size.toSize(), QImage::Format_ARGB32_Premultiplied); //QImage::Format_Grayscale8); //QImage::Format_ARGB32);160 QImage container(size.toSize(), QImage::Format_ARGB32_Premultiplied);
134 QPainter painter;161 QPainter painter;
135162
136 container.fill(QColor(0, 0, 0, 0));163 container.fill(QColor(0, 0, 0, 0));
@@ -141,6 +168,7 @@
141 painter.drawImage((size.width() - scaledSize.width()) / 2, (size.height() - scaledSize.height()) / 2, image);168 painter.drawImage((size.width() - scaledSize.width()) / 2, (size.height() - scaledSize.height()) / 2, image);
142 } else {169 } else {
143 qWarning() << "Image is null";170 qWarning() << "Image is null";
171 return QImage();
144 }172 }
145173
146 painter.end();174 painter.end();
@@ -148,197 +176,12 @@
148 return container;176 return container;
149}177}
150178
151QPixmap Document::makePixmap(QSize size, int pageNumber)
152{
153 if (pageNumber < 0) {
154 qWarning() << "Invalid page number";
155 }
156
157 if (!m_document) {
158 qWarning() << "No document loaded";
159 }
160
161 // Splash backend has much better rendering
162 m_document->setRenderBackend(Poppler::Document::SplashBackend);
163
164 Poppler::Page *page = m_document->page(pageNumber);
165
166 if (!page) {
167 qWarning() << "Invalid page";
168 }
169
170 float res = getDpi(page->pageSizeF(), size);
171
172 qDebug() << "Making image with res of" << res;
173
174 // Make QPixmap
175 QPixmap pixmap(size);
176
177 // If using ArthurBackend can do
178 // QPainter painter(&pixmap);
179 // if (!page->renderToPainter(painter, res, res)) {
180 // qWarning() << "Failed to render to painter";
181 // }
182
183 QImage image = page->renderToImage(res, res);
184
185 if (image.isNull()) {
186 qWarning() << "Image is null";
187 }
188
189 pixmap = QPixmap::fromImage(image);
190
191 delete page;
192
193 return pixmap;
194}
195
196QImage Document::renderImage(QSize size, int pageNumber)
197{
198 if (pageNumber < 0) {
199 qWarning() << "Invalid page number";
200 }
201
202 if (!m_document) {
203 qWarning() << "No document loaded";
204 }
205
206// m_document->setRenderBackend(Poppler::Document::SplashBackend);
207
208 Poppler::Page *page = m_document->page(pageNumber);
209
210 if (!page) {
211 qWarning() << "Invalid page";
212 }
213
214 /*
215 * width / res width / res
216 */
217
218// int res = size.width() / (page->pageSize().width() / 72);
219
220// qDebug() << "Res:" << res;
221
222
223
224 QSizeF sourceSizeInch(page->pageSizeF().width() / 72, page->pageSizeF().height() / 72);
225
226 QSizeF destDPI(size.width() / sourceSizeInch.width(), size.height()/ sourceSizeInch.height());
227
228 float res;
229
230 if (destDPI.width() > destDPI.height()) {
231 res = destDPI.height();
232 } else {
233 res = destDPI.width();
234 }
235
236 qDebug() << "Making image with res of" << res;
237
238 QImage image = page->renderToImage(res, res);
239
240 if (image.isNull()) {
241 qWarning() << "Image is null";
242 }
243
244 delete page;
245
246 return image;
247}
248
249bool Document::renderPage(QPainter *painter, int pageNumber)
250{
251 if (!painter) {
252 qWarning() << "Invalid painter";
253 return false;
254 }
255
256 if (pageNumber < 0) {
257 qWarning() << "Invalid page number";
258 return false;
259 }
260
261 if (!m_document) {
262 qWarning() << "No document loaded";
263 return false;
264 }
265
266 Poppler::Page *page = m_document->page(pageNumber);
267
268 m_document->setRenderBackend(Poppler::Document::ArthurBackend);
269
270 if (!page) {
271 qWarning() << "Invalid page";
272 return false;
273 }
274
275 /*
276A4
277DPI: 96 1200
278Device Size: 767 1097
279Doc Size: 595 842
280
281A5
282DPI: 96 1200
283Device Size: 534 767
284Doc Size: 595 842
285 */
286
287 QSizeF sourceSizeInch(page->pageSizeF().width() / 72, page->pageSizeF().height() / 72);
288
289 QSizeF destDPI(painter->device()->width() / sourceSizeInch.width(), painter->device()->height()/ sourceSizeInch.height());
290
291 float res;
292
293 if (destDPI.width() > destDPI.height()) {
294 res = destDPI.height();
295 } else {
296 res = destDPI.width();
297 }
298
299// Poppler::PSConverter *psConv = m_document->psConverter();
300
301// psConv->setLeftMargin(5);
302// psConv->setRightMargin(1);
303// psConv->setOutputFileName("/tmp/out.ps");
304// psConv->setPaperHeight(painter->device()->height());
305// psConv->setPaperWidth(painter->device()->width());
306
307// QList<int> pages = { 1 };
308
309// psConv->setPageList(pages);
310
311// qDebug() << "PS" << psConv->convert();
312
313
314// float res = painter->device()->width() / (page->pageSize().width() / 72); //painter->device()->logicalDpiX());
315
316 //res = 70;
317
318 qDebug() << "DPI:" << painter->device()->logicalDpiX() << painter->device()->physicalDpiX() << res;
319
320 qDebug() << "Device Size:" << painter->device()->width() << painter->device()->height();
321 qDebug() << "Doc Size:" << page->pageSize().width() << page->pageSize().height();
322
323 // Create Image same dimensions as PageSize
324 // Render to the image
325 // Render the image to the printer
326 // Image can also be used for preview?
327
328 if (!page->renderToPainter(painter, res, res)) {
329// if (!page->renderToPainter(painter, painter->device()->logicalDpiX(), painter->device()->logicalDpiY(),
330// 0, 0, page->pageSize().width(), page->pageSize().height())) {
331 qWarning() << "Rendering failed";
332 return false;
333 }
334
335 delete page;
336
337 return true;
338}
339
340Document::Orientation Document::orientation() const179Document::Orientation Document::orientation() const
341{180{
181 if (!m_document) {
182 return Portrait;
183 }
184
342 Poppler::Page *page = m_document->page(0);185 Poppler::Page *page = m_document->page(0);
343186
344 if (page) {187 if (page) {
@@ -350,102 +193,64 @@
350 return Portrait;193 return Portrait;
351 }194 }
352195
353 qDebug() << "DOC" << page->orientation() << Portrait << Landscape;196 // TODO: page orientation seems to be wrong?
354197// qDebug() << "DOC" << page->orientation() << Portrait << Landscape;
355 if (page->orientation() == Poppler::Page::Landscape) {198// if (page->orientation() == Poppler::Page::Landscape) {
356 return Landscape;199// return Landscape;
357 } else if (page->orientation() == Poppler::Page::Portrait) {200// } else if (page->orientation() == Poppler::Page::Portrait) {
358 return Portrait;201// return Portrait;
359 } else {202// } else {
360 qWarning() << "Other orientation:" << page->orientation() << "using Portrait";203// qWarning() << "Other orientation:" << page->orientation() << "using Portrait";
361 return Portrait;204// return Portrait;
362 }205// }
363 } else {206 } else {
364 return Portrait;207 return Portrait;
365 }208 }
366}209}
367210
368bool Document::printFromImage(QPainter *painter, int pageNumber, QRect pageRect, double resolution)
369{
370 // Ensure we are using the right render hints
371 m_document->setRenderBackend(Poppler::Document::SplashBackend);
372
373 m_document->setRenderHint(Poppler::Document::Antialiasing, true);
374 m_document->setRenderHint(Poppler::Document::TextAntialiasing, true);
375 m_document->setRenderHint(Poppler::Document::TextHinting, true);
376
377 Poppler::Page *page = m_document->page(pageNumber);
378
379 if (!page) {
380 qWarning() << "Invalid page!";
381 return false;
382 }
383
384 // Render at given resolution
385 QImage image = page->renderToImage(resolution, resolution);
386
387 // Get the scalar for the image to fit within the pageRect
388 double ratioX = (double) image.width() / (double) pageRect.width();
389 double ratioY = (double) image.height() / (double) pageRect.height();
390
391 image.setDevicePixelRatio(fmax(ratioX, ratioY));
392
393 // Check that image isn't null
394 if (image.isNull()) {
395 return false;
396 }
397
398 // Draw the image to the painter, should we scale? the image should be correct aspect
399 // Here we should check if the image aspect is different and position in the centre?
400 painter->drawImage(0, 0, image);
401 //painter->drawImage(QRect(QPoint(0, 0), QSize(pageRect.width(), pageRect.height())), image, image.rect());
402
403 qDebug() << "Device Width:" << pageRect.width() << "LogicalDPI:" << painter->device()->logicalDpiX(); // << "RenderDPI:" << renderDPI.width();
404 qDebug() << "RatioX" << ratioX << "RatioY" << ratioY;
405
406 qDebug() << "PageRect:" << pageRect.width() << pageRect.height();
407 qDebug() << "Image:" << image.width() << image.height() << image.dotsPerMeterX();
408
409 return true;
410}
411
412void Document::setUrl(QUrl url)211void Document::setUrl(QUrl url)
413{212{
414 if (m_url != url) {213 if (m_url != url) {
415 if (url.isLocalFile() && QFileInfo::exists(url.toLocalFile())) {214 if (url.isLocalFile() && QFileInfo::exists(url.toLocalFile())) {
416 if (QMimeDatabase().mimeTypeForUrl(url).name() == "application/pdf") {215 if (QMimeDatabase().mimeTypeForUrl(url).name() == "application/pdf") {
417 m_url = url;216 // Attempt to Load document
418217 m_document = Poppler::Document::load(url.toLocalFile());
419 // Load document
420 m_document = Poppler::Document::load(m_url.toLocalFile());
421 m_document->setRenderBackend(Poppler::Document::ArthurBackend);
422
423 m_document->setRenderHint(Poppler::Document::Antialiasing, true);
424 m_document->setRenderHint(Poppler::Document::TextAntialiasing, true);
425 m_document->setRenderHint(Poppler::Document::TextHinting, true);
426// m_document->setRenderHint(Poppler::Document::TextSlightHinting, true);
427// m_document->setRenderHint(Poppler::Document::OverprintPreview, true);
428// m_document->setRenderHint(Poppler::Document::ThinLineSolid, true);
429// m_document->setRenderHint(Poppler::Document::ThinLineShape, true);
430218
431 if (!m_document || m_document->isLocked()) {219 if (!m_document || m_document->isLocked()) {
432 qWarning() << "Invalid Document";220 qWarning() << "Invalid Document";
433 delete m_document;221 delete m_document;
434 m_document = Q_NULLPTR;222 m_document = Q_NULLPTR;
223
224 Q_EMIT error(Errors::ErrorDocumentInvalid);
435 } else {225 } else {
226 m_url = url;
227
228 m_document->setRenderBackend(Poppler::Document::SplashBackend);
229
230 m_document->setRenderHint(Poppler::Document::Antialiasing, true);
231 m_document->setRenderHint(Poppler::Document::TextAntialiasing, true);
232 m_document->setRenderHint(Poppler::Document::TextHinting, true);
233 m_document->setRenderHint(Poppler::Document::TextSlightHinting, true);
234
235 Q_EMIT urlChanged();
236
436 if (m_count != m_document->numPages()) {237 if (m_count != m_document->numPages()) {
437 m_count = m_document->numPages();238 m_count = m_document->numPages();
438239
439 Q_EMIT countChanged();240 Q_EMIT countChanged();
440 }241 }
242
243 Q_EMIT orientationChanged();
244 Q_EMIT titleChanged();
441 }245 }
442
443 Q_EMIT urlChanged();
444 } else {246 } else {
445 qWarning() << "File is not a PDF:" << url;247 qWarning() << "File is not a PDF:" << url;
248 Q_EMIT error(Errors::ErrorNotPdf);
446 }249 }
447 } else {250 } else {
448 qWarning() << "Url is not a local file:" << url;251 qWarning() << "Url is not a local file:" << url;
252
253 Q_EMIT error(Errors::ErrorNotFound);
449 }254 }
450 }255 }
451}256}
@@ -455,7 +260,7 @@
455 if (m_document) {260 if (m_document) {
456 return m_document->info("Title");261 return m_document->info("Title");
457 } else {262 } else {
458 return "";263 return QStringLiteral("");
459 }264 }
460}265}
461266
462267
=== modified file 'backend/UbuntuPrintingApp/document.h'
--- backend/Ubuntu_Printing_App/document.h 2016-12-13 12:08:15 +0000
+++ backend/UbuntuPrintingApp/document.h 2017-02-08 21:32:20 +0000
@@ -1,7 +1,27 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
1#ifndef DOCUMENT_H20#ifndef DOCUMENT_H
2#define DOCUMENT_H21#define DOCUMENT_H
322
4#include <QtCore/QObject>23#include <QtCore/QObject>
24#include <QtCore/QSizeF>
5#include <QtCore/QUrl>25#include <QtCore/QUrl>
626
7#include <QtGui/QPainter>27#include <QtGui/QPainter>
@@ -13,30 +33,39 @@
13 Q_OBJECT33 Q_OBJECT
1434
15 Q_PROPERTY(int count READ count NOTIFY countChanged)35 Q_PROPERTY(int count READ count NOTIFY countChanged)
36 Q_PROPERTY(Orientation orientation READ orientation NOTIFY orientationChanged)
37 Q_PROPERTY(QString title READ title NOTIFY titleChanged)
16 Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)38 Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
17public:39public:
40 enum class Errors {
41 ErrorDocumentInvalid,
42 ErrorNotFound,
43 ErrorNotPdf,
44 };
45
46 Q_ENUM(Errors)
47
18 enum Orientation {48 enum Orientation {
19 Portrait,49 Portrait,
20 Landscape,50 Landscape,
21 };51 };
52 Q_ENUM(Orientation)
2253
23 explicit Document(QObject *parent = 0);54 explicit Document(QObject *parent = 0);
24 ~Document();55 ~Document();
25 int count() const;56 int count() const;
57 QSizeF getPageSize(int pageNumber);
26 Orientation orientation() const;58 Orientation orientation() const;
27 QString title() const;59 QString title() const;
28 QUrl url() const;60 QUrl url() const;
2961
30 QImage makeImage(QSizeF size, int pageNumber);62 QImage makeImage(QSizeF size, int pageNumber);
31 QImage makeImageToFit(QSizeF size, int pageNumber, bool color);63 QImage makeImageToFit(QSizeF size, int pageNumber, bool color);
32 QPixmap makePixmap(QSize size, int pageNumber);
33
34 Q_INVOKABLE QImage renderImage(QSize size, int pageNumber);
35 Q_INVOKABLE bool renderPage(QPainter *painter, int pageNumber);
36
37 bool printFromImage(QPainter *painter, int pageNumber, QRect pageRect, double resolution);
38signals:64signals:
39 void countChanged();65 void countChanged();
66 void error(Document::Errors errorType);
67 void orientationChanged();
68 void titleChanged();
40 void urlChanged();69 void urlChanged();
41public slots:70public slots:
42 void setUrl(QUrl url);71 void setUrl(QUrl url);
4372
=== added file 'backend/UbuntuPrintingApp/pagehelper.cpp'
--- backend/UbuntuPrintingApp/pagehelper.cpp 1970-01-01 00:00:00 +0000
+++ backend/UbuntuPrintingApp/pagehelper.cpp 2017-02-08 21:32:20 +0000
@@ -0,0 +1,104 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20#include <QtCore/QSizeF>
21
22#include <poppler/qt5/poppler-qt5.h>
23
24#include "pagehelper.h"
25
26#define A4_ASPECT_RATIO 595.0 / 842.0
27
28PageHelper::PageHelper(QObject *parent)
29 : QObject(parent)
30 , m_aspect(A4_ASPECT_RATIO)
31 , m_document(Q_NULLPTR)
32 , m_page(0)
33{
34
35}
36
37double PageHelper::aspect() const
38{
39 return m_aspect;
40}
41
42Document *PageHelper::document() const
43{
44 return m_document;
45}
46
47void PageHelper::loadAspect()
48{
49 if (!m_document) {
50 setAspect(A4_ASPECT_RATIO);
51 }
52
53 QSizeF pageSize = m_document->getPageSize(m_page);
54
55 if (pageSize.isValid()) {
56 setAspect(pageSize.width() / pageSize.height());
57 } else {
58 setAspect(A4_ASPECT_RATIO);
59 }
60}
61
62int PageHelper::page() const
63{
64 return m_page;
65}
66
67void PageHelper::setAspect(double aspect)
68{
69 if (m_aspect != aspect) {
70 m_aspect = aspect;
71
72 Q_EMIT aspectChanged();
73 }
74}
75
76void PageHelper::setDocument(Document *document)
77{
78 if (m_document != document) {
79 if (m_document) { // disconnect old signals
80 m_document->disconnect();
81 }
82
83 m_document = document;
84
85 // If the document URL changes reload the aspect
86 PageHelper::connect(m_document, SIGNAL(urlChanged()), this, SLOT(loadAspect()));
87
88 Q_EMIT documentChanged();
89
90 loadAspect();
91 }
92}
93
94void PageHelper::setPage(int page)
95{
96 if (m_page != page) {
97 m_page = page;
98
99 Q_EMIT pageChanged();
100
101 loadAspect();
102 }
103}
104
0105
=== added file 'backend/UbuntuPrintingApp/pagehelper.h'
--- backend/UbuntuPrintingApp/pagehelper.h 1970-01-01 00:00:00 +0000
+++ backend/UbuntuPrintingApp/pagehelper.h 2017-02-08 21:32:20 +0000
@@ -0,0 +1,55 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20#ifndef PAGEHELPER_H
21#define PAGEHELPER_H
22
23#include <QtCore/QObject>
24
25#include "document.h"
26
27class PageHelper : public QObject
28{
29 Q_OBJECT
30
31 Q_PROPERTY(double aspect READ aspect NOTIFY aspectChanged)
32 Q_PROPERTY(Document *document READ document WRITE setDocument NOTIFY documentChanged)
33 Q_PROPERTY(int page READ page WRITE setPage NOTIFY pageChanged)
34public:
35 explicit PageHelper(QObject *parent = 0);
36 double aspect() const;
37 Document *document() const;
38 int page() const;
39signals:
40 void aspectChanged();
41 void documentChanged();
42 void pageChanged();
43public slots:
44 void setDocument(Document *document);
45 void setPage(int page);
46private slots:
47 void setAspect(double aspect);
48 void loadAspect();
49private:
50 double m_aspect;
51 Document *m_document;
52 int m_page;
53};
54
55#endif // PAGEGELPER_H
056
=== modified file 'backend/UbuntuPrintingApp/popplerimageprovider.cpp'
--- backend/Ubuntu_Printing_App/popplerimageprovider.cpp 2016-12-12 17:09:39 +0000
+++ backend/UbuntuPrintingApp/popplerimageprovider.cpp 2017-02-08 21:32:20 +0000
@@ -1,9 +1,27 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
1#include "popplerimageprovider.h"20#include "popplerimageprovider.h"
221
3#include <QDebug>22#include <QDebug>
423
5#include "document.h"24#include "document.h"
6#include "printer.h"
725
8PopplerImageProvider::PopplerImageProvider()26PopplerImageProvider::PopplerImageProvider()
9 : QQuickImageProvider(QQuickImageProvider::Image, QQuickImageProvider::ForceAsynchronousImageLoading)27 : QQuickImageProvider(QQuickImageProvider::Image, QQuickImageProvider::ForceAsynchronousImageLoading)
@@ -14,35 +32,57 @@
1432
15QImage PopplerImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)33QImage PopplerImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
16{34{
17 qDebug() << "ID" << id << requestedSize.height() << requestedSize.width();35 // Load id ( image://poppler/{pageNumber}/{color}/{filePath} )
18
19 // Load id ( image://poppler/{pageNumber}/{colorMode}/{filePath} )
20 QStringList parts = id.split("/");36 QStringList parts = id.split("/");
2137
22 bool colorOk, numberOk;38 bool colorOk, numberOk;
23 int pageNumber = parts.takeFirst().toInt(&numberOk, 10);39 int pageNumber = parts.takeFirst().toInt(&numberOk, 10);
24 int colorModeInt = parts.takeFirst().toInt(&colorOk, 10);40 QString colorMode = QString::fromStdString(parts.takeFirst().toStdString());
2541
26 Printer::ColorMode colorMode = static_cast<Printer::ColorMode>(colorModeInt);42 bool color;
43
44 if (colorMode == "true") {
45 color = true;
46 colorOk = true;
47 } else if (colorMode == "false") {
48 color = false;
49 colorOk = true;
50 } else {
51 colorOk = false;
52 }
2753
28 QString url = parts.join("/");54 QString url = parts.join("/");
2955
56 // Check request size is valid
57 if (requestedSize.height() <= 0 || requestedSize.width() <= 0) {
58 qWarning() << "Invalid requestedSize given" << requestedSize;
59
60 // Requested size is invalid, return a 1x1 image to prevent QML errors
61 // when resizing the window really small
62 if (size) {
63 *size = QSize(1, 1);
64 }
65
66 return QImage(QSize(1, 1), QImage::Format_ARGB32_Premultiplied);
67 } else if (size) {
68 // Set the size of the 'orignal' image to the requestedSize
69 // as we generate an image dynamically
70 *size = requestedSize;
71 }
72
73 // Check all parts given were OK
30 if (url.isEmpty() || !numberOk || !colorOk) {74 if (url.isEmpty() || !numberOk || !colorOk) {
75 qWarning() << "Invalid id given to poppler image provider:" << id;
31 return QImage();76 return QImage();
32 }77 }
3378
34 // Fallback size if none is given for QImage79 // Build a Document and generate an image to fit the given requestedSize
35 int width = 100;
36 int height = 50;
37
38 if (size)
39 *size = QSize(width, height);
40
41 qDebug() << "Url:" << url;
42 qDebug() << "Page:" << pageNumber;
43
44 Document *doc = new Document();80 Document *doc = new Document();
45 doc->setUrl(url);81 doc->setUrl(url);
4682
47 return doc->makeImageToFit(requestedSize, pageNumber, colorMode == Printer::Color);83 QImage image = doc->makeImageToFit(requestedSize, pageNumber, color);
84
85 doc->deleteLater();
86
87 return image;
48}88}
4989
=== modified file 'backend/UbuntuPrintingApp/popplerimageprovider.h'
--- backend/Ubuntu_Printing_App/popplerimageprovider.h 2016-12-09 17:14:23 +0000
+++ backend/UbuntuPrintingApp/popplerimageprovider.h 2017-02-08 21:32:20 +0000
@@ -1,3 +1,22 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
1#ifndef POPPLERIMAGEPROVIDER_H20#ifndef POPPLERIMAGEPROVIDER_H
2#define POPPLERIMAGEPROVIDER_H21#define POPPLERIMAGEPROVIDER_H
322
423
=== modified file 'backend/UbuntuPrintingApp/qmldir'
--- backend/Ubuntu_Printing_App/qmldir 2016-12-13 12:37:45 +0000
+++ backend/UbuntuPrintingApp/qmldir 2017-02-08 21:32:20 +0000
@@ -1,2 +1,2 @@
1module Ubuntu_Printing_App1module UbuntuPrintingApp
2plugin Ubuntu_Printing_Appbackend2plugin UbuntuPrintingAppbackend
33
=== removed file 'backend/Ubuntu_Printing_App/printer.cpp'
--- backend/Ubuntu_Printing_App/printer.cpp 2016-12-13 12:08:15 +0000
+++ backend/Ubuntu_Printing_App/printer.cpp 1970-01-01 00:00:00 +0000
@@ -1,355 +0,0 @@
1#include "printer.h"
2
3#include <QtCore/QDateTime>
4#include <QtCore/QDir>
5#include <QtCore/QFileInfo>
6#include <QtCore/QStandardPaths>
7#include <QtCore/QStringList>
8#include <QtCore/QVector>
9
10#include <QtCore/QDebug>
11
12#include <cups/cups.h>
13#include <cups/ppd.h>
14
15#define __CUPS_ADD_OPTION(dest, name, value) dest->num_options = \
16 cupsAddOption(name, value, dest->num_options, &dest->options);
17
18Printer::Printer(QObject *parent)
19 : QObject(parent)
20 , m_color_mode(Color)
21 , m_copies(1)
22 , m_cups_dest(0)
23 , m_cups_instance(QStringLiteral(""))
24 , m_cups_name(QStringLiteral(""))
25 , m_duplex(false)
26 , m_duplex_modes({})
27 , m_duplex_supported(false)
28 , m_job_id(0)
29 , m_name("")
30 , m_ppd(0)
31 , m_pdf_mode(false)
32 , m_quality(Normal)
33{
34
35}
36
37Printer::~Printer()
38{
39 if (m_ppd) {
40 ppdClose(m_ppd);
41 m_ppd = 0;
42 }
43
44 if (m_cups_dest) {
45 cupsFreeDests(1, m_cups_dest);
46
47 m_cups_dest = 0;
48 }
49}
50
51Printer::ColorMode Printer::colorMode() const
52{
53 return m_color_mode;
54}
55
56int Printer::copies() const
57{
58 return m_copies;
59}
60
61bool Printer::duplex() const
62{
63 return m_duplex;
64}
65
66bool Printer::duplexSupported() const
67{
68 return m_duplex_supported;
69}
70
71void Printer::loadDuplexModes(const QString name)
72{
73 if (m_ppd) {
74 ppdClose(m_ppd);
75 m_ppd = 0;
76 }
77
78 const char *ppdFile = cupsGetPPD(name.toLocal8Bit().data());
79
80 if (ppdFile) {
81 m_ppd = ppdOpenFile(ppdFile);
82 unlink(ppdFile);
83
84 if (m_ppd) {
85 ppdMarkDefaults(m_ppd);
86 } else {
87 m_ppd = 0;
88 return;
89 }
90 }
91
92 ppd_option_t *duplexModes = ppdFindOption(m_ppd, "Duplex");
93 ppd_option_t *defaultDuplexModes = ppdFindOption(m_ppd, "DefaultDuplex");
94
95 // Build list of supported duplex modes
96 bool duplexSupported = false;
97 m_duplex_modes.clear();
98
99 for (int i=0; i < duplexModes->num_choices; i++) {
100 m_duplex_modes.append(QString::fromLocal8Bit(duplexModes->choices[i].choice));
101
102 if (QString::fromLocal8Bit(duplexModes->choices[i].choice) != "None") {
103 duplexSupported = true;
104 }
105 }
106
107 setDuplexSupported(duplexSupported);
108
109 // Load default duplex mode
110 // TODO: do we need as option gets disable?
111 if (defaultDuplexModes) {
112 if (QString::fromLocal8Bit(defaultDuplexModes->choices[0].choice) == "None") {
113 setDuplex(false);
114 } else {
115 setDuplex(true);
116 }
117 }
118}
119
120bool Printer::loadOptions(cups_dest_t *cups_dest, Document *doc)
121{
122 // Load options
123 // Copies
124 if (m_copies > 1) {
125 __CUPS_ADD_OPTION(cups_dest, "copies", QString::number(m_copies).toLocal8Bit());
126 }
127
128 // Colour mode
129 if (m_color_mode == GrayScale) {
130 __CUPS_ADD_OPTION(cups_dest, "ColorModel", "CMYGray");
131 }
132
133 // Duplex
134 if (m_duplex_supported && m_duplex) {
135 if (doc->orientation() == Document::Portrait && m_duplex_modes.contains("DuplexNoTumble")) {
136 __CUPS_ADD_OPTION(cups_dest, "Duplex", "DuplexNoTumble");
137// __CUPS_ADD_OPTION(m_cups_dest, "sides", "two-sided-long-edge")
138 } else if (doc->orientation() == Document::Portrait && m_duplex_modes.contains("DuplexTumble")) {
139 __CUPS_ADD_OPTION(cups_dest, "Duplex", "DuplexTumble");
140// __CUPS_ADD_OPTION(m_cups_dest, "sides", "two-sided-long-edge")
141 } else {
142 // Fallback to pick first found duplex mode
143 for (QString mode : m_duplex_modes) {
144 if (mode != "None") {
145 __CUPS_ADD_OPTION(cups_dest, "Duplex", mode.toLocal8Bit().data());
146 break;
147 }
148 }
149 }
150 } else {
151 __CUPS_ADD_OPTION(cups_dest, "Duplex", "None");
152 }
153
154 // Orientation
155 if (doc->orientation() == Document::Landscape) {
156 __CUPS_ADD_OPTION(cups_dest, "landscape", "");
157 }
158
159 // Page range
160// __CUPS_ADD_OPTION(cups_dest, "number-up", "4"); // 1, 2, 4, 6, 9
161// __CUPS_ADD_OPTION(cups_dest, "number-up-layout", "lrtb"); // "lrtb", "lrbt", "rlbt", "rltb", "btlr", "btrl", "tblr", "tbrl"
162// __CUPS_ADD_OPTION(cups_dest, "page-ranges", "1-2"); // 3-5,7,10-20
163
164 // Print quality
165 QString printQuality = "";
166 switch (m_quality) {
167 case Draft:
168 printQuality = "FastDraft";
169 break;
170 case Best:
171 printQuality = "Best";
172 break;
173 case Photo:
174 printQuality = "Photo";
175 break;
176 case Normal:
177 default:
178 printQuality = "Normal";
179 break;
180 }
181 __CUPS_ADD_OPTION(cups_dest, "OutputMode", printQuality.toLocal8Bit());
182
183 return true;
184}
185
186QString Printer::makeOutputFilepath() const
187{
188 QDir dir(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
189
190 if (!dir.exists()) {
191 dir.mkpath(".");
192 }
193
194 QFileInfo fileInfo(dir.path(), QDateTime::currentDateTime().toString(Qt::ISODate));
195 return fileInfo.absoluteFilePath();
196}
197
198QString Printer::name() const
199{
200 return m_name;
201}
202
203bool Printer::pdfMode() const
204{
205 return m_pdf_mode;
206}
207
208bool Printer::print(Document *doc)
209{
210 // TODO: PDF mode!
211 if (m_pdf_mode) {
212 Q_EMIT exportRequest(doc->url().toLocalFile());
213
214// cupsTempFd();
215 return true;
216 }
217
218 // Get all the dests
219 int num_dests; Q_UNUSED(num_dests)
220 cups_dest_t *dests;
221
222 num_dests = cupsGetDests(&dests); // FIXME: appear to need to run this first?
223
224 for (int i=0; i < num_dests; i++) {
225 qDebug() << "Dest" << dests[i].name;
226 }
227
228 cupsFreeDests(num_dests, dests);
229
230 // Ensure the destination is free
231 if (m_cups_dest) {
232 cupsFreeDests(1, m_cups_dest);
233
234 m_cups_dest = 0;
235 }
236
237 // Get the destination
238 // TODO: IPP, cupsGetDestWithURI()
239 m_cups_dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, m_cups_name.toLocal8Bit().data(), m_cups_instance.toLocal8Bit().data());
240
241 if (!m_cups_dest) {
242 qWarning() << "Could not find printer:" << m_name;
243 return false;
244 }
245
246 // Load the printer options
247 loadOptions(m_cups_dest, doc);
248
249 // Load title
250 QString title = doc->title();
251
252 if (title.isEmpty()) {
253 title = doc->url().fileName();
254 }
255
256 // Send to the printer
257 m_job_id = cupsPrintFile(m_cups_dest->name,
258 doc->url().toLocalFile().toLocal8Bit().data(),
259 title.toLocal8Bit().data(),
260 m_cups_dest->num_options, m_cups_dest->options);
261
262 if (m_job_id == 0) {
263 qWarning() << "Creating Job Failed:" << cupsLastErrorString();
264 return false;
265 } else {
266 qDebug() << "JobID" << m_job_id;
267 return true;
268 }
269}
270
271void Printer::setColorMode(Printer::ColorMode colorMode)
272{
273 if (m_color_mode != colorMode) {
274 m_color_mode = colorMode;
275
276 Q_EMIT colorModeChanged();
277 }
278}
279
280void Printer::setCopies(int copies)
281{
282 if (m_copies != copies) {
283 m_copies = copies;
284
285 Q_EMIT copiesChanged();
286 }
287}
288
289void Printer::setDuplex(bool duplex)
290{
291 if (m_duplex != duplex) {
292 m_duplex = duplex;
293
294 Q_EMIT duplexChanged();
295 }
296}
297
298void Printer::setDuplexSupported(bool duplexSupported)
299{
300 if (m_duplex_supported != duplexSupported) {
301 m_duplex_supported = duplexSupported;
302
303 Q_EMIT duplexSupportedChanged();
304 }
305}
306
307void Printer::setName(QString name)
308{
309 if (m_name != name) {
310 m_name = name;
311
312 if (m_pdf_mode) {
313 setDuplexSupported(false);
314 } else {
315 // Extract the cups name and instance from the m_name
316 QStringList split = m_name.split("/");
317
318 m_cups_name = split.takeFirst();
319 m_cups_instance = split.isEmpty() ? "" : split.takeFirst();
320
321 if (split.length() > 0) {
322 qWarning() << "Unknown printer name pattern:" << m_name;
323 return;
324 }
325
326 loadDuplexModes(m_cups_name);
327 }
328
329 Q_EMIT nameChanged();
330 Q_EMIT settingsChanged();
331 }
332}
333
334void Printer::setPdfMode(bool pdfMode)
335{
336 if (m_pdf_mode != pdfMode) {
337 m_pdf_mode = pdfMode;
338
339 Q_EMIT pdfModeChanged();
340 }
341}
342
343void Printer::setQuality(Quality quality)
344{
345 if (m_quality != quality) {
346 m_quality = quality;
347
348 Q_EMIT qualityChanged();
349 }
350}
351
352Printer::Quality Printer::quality() const
353{
354 return m_quality;
355}
3560
=== removed file 'backend/Ubuntu_Printing_App/printer.h'
--- backend/Ubuntu_Printing_App/printer.h 2016-12-13 12:08:15 +0000
+++ backend/Ubuntu_Printing_App/printer.h 1970-01-01 00:00:00 +0000
@@ -1,94 +0,0 @@
1#ifndef PRINTER_H
2#define PRINTER_H
3
4#include <QtCore/QObject>
5
6#include <cups/cups.h>
7#include <cups/ppd.h>
8
9#include "document.h"
10
11class Printer : public QObject
12{
13 Q_OBJECT
14
15 Q_PROPERTY(ColorMode colorMode READ colorMode WRITE setColorMode NOTIFY colorModeChanged)
16 Q_PROPERTY(int copies READ copies WRITE setCopies NOTIFY copiesChanged)
17 Q_PROPERTY(bool duplex READ duplex WRITE setDuplex NOTIFY duplexChanged)
18 Q_PROPERTY(bool duplexSupported READ duplexSupported NOTIFY duplexSupportedChanged)
19 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
20 Q_PROPERTY(bool pdfMode READ pdfMode WRITE setPdfMode NOTIFY pdfModeChanged)
21 Q_PROPERTY(Quality quality READ quality WRITE setQuality NOTIFY qualityChanged)
22public:
23 enum ColorMode
24 {
25 Color,
26 GrayScale,
27 };
28 Q_ENUMS(ColorMode)
29
30 enum Quality
31 {
32 Draft,
33 Normal,
34 Best,
35 Photo,
36 };
37 Q_ENUMS(Quality)
38
39 explicit Printer(QObject *parent = 0);
40 ~Printer();
41 ColorMode colorMode() const;
42 int copies() const;
43 bool duplex() const;
44 bool duplexSupported() const;
45 QString name() const;
46 bool pdfMode() const;
47 Quality quality() const;
48
49 Q_INVOKABLE bool print(Document *doc);
50signals:
51 void colorModeChanged();
52 void copiesChanged();
53 void duplexChanged();
54 void duplexSupportedChanged();
55 void nameChanged();
56 void settingsChanged();
57 void pdfModeChanged();
58 void qualityChanged();
59
60 void exportRequest(const QString &filepath);
61public slots:
62 void setColorMode(ColorMode colorMode);
63 void setCopies(int copies);
64 void setDuplex(bool duplex);
65 void setDuplexSupported(bool duplexSupported);
66 void setName(QString name);
67 void setPdfMode(bool pdfMode);
68 void setQuality(Quality quality);
69private:
70 void loadDuplexModes(const QString name);
71 bool loadOptions(cups_dest_t *cups_dest, Document *doc);
72 QString makeOutputFilepath() const;
73
74 ColorMode m_color_mode;
75 int m_copies;
76
77 cups_dest_t *m_cups_dest;
78 QString m_cups_instance;
79 QString m_cups_name;
80
81 bool m_duplex;
82 QList<QString> m_duplex_modes;
83 bool m_duplex_supported;
84 int m_job_id;
85 QString m_name;
86
87 ppd_file_t *m_ppd;
88
89 bool m_pdf_mode;
90 Quality m_quality;
91
92};
93
94#endif // PRINTER_H
950
=== removed file 'backend/Ubuntu_Printing_App/printerinfo.cpp'
--- backend/Ubuntu_Printing_App/printerinfo.cpp 2016-12-12 17:09:39 +0000
+++ backend/Ubuntu_Printing_App/printerinfo.cpp 1970-01-01 00:00:00 +0000
@@ -1,39 +0,0 @@
1#include "printerinfo.h"
2
3#include <QtPrintSupport/QPrinterInfo>
4
5PrinterInfo::PrinterInfo(QObject *parent) : QObject(parent)
6{
7 m_available_printer_names = QStringList() << QPrinterInfo::availablePrinterNames() << "Create PDF";
8 m_default_printer_name = QPrinterInfo::defaultPrinterName();
9
10 // Watch printers for updates
11 m_timer_printers = new QTimer(this);
12 connect(m_timer_printers, SIGNAL(timeout()), this, SLOT(updatePrinters()));
13 m_timer_printers->start(5000);
14}
15
16QStringList PrinterInfo::availablePrinterNames() const
17{
18 return m_available_printer_names;
19}
20
21QString PrinterInfo::defaultPrinterName() const
22{
23 return m_default_printer_name;
24}
25
26void PrinterInfo::updatePrinters()
27{
28 if (m_available_printer_names != QStringList() << QPrinterInfo::availablePrinterNames() << "Create PDF") {
29 m_available_printer_names = QStringList() << QPrinterInfo::availablePrinterNames() << "Create PDF";
30
31 Q_EMIT availablePrinterNamesChanged();
32 }
33
34 if (m_default_printer_name != QPrinterInfo::defaultPrinterName()) {
35 m_default_printer_name = QPrinterInfo::defaultPrinterName();
36
37 Q_EMIT defaultPrinterNameChanged();
38 }
39}
400
=== removed file 'backend/Ubuntu_Printing_App/printerinfo.h'
--- backend/Ubuntu_Printing_App/printerinfo.h 2016-11-25 16:47:10 +0000
+++ backend/Ubuntu_Printing_App/printerinfo.h 1970-01-01 00:00:00 +0000
@@ -1,30 +0,0 @@
1#ifndef PRINTERINFO_H
2#define PRINTERINFO_H
3
4#include <QtCore/QObject>
5#include <QtCore/QString>
6#include <QtCore/QStringList>
7#include <QtCore/QTimer>
8
9class PrinterInfo : public QObject
10{
11 Q_OBJECT
12
13 Q_PROPERTY(QStringList availablePrinterNames READ availablePrinterNames NOTIFY availablePrinterNamesChanged)
14 Q_PROPERTY(QString defaultPrinterName READ defaultPrinterName NOTIFY defaultPrinterNameChanged)
15public:
16 explicit PrinterInfo(QObject *parent = 0);
17 QStringList availablePrinterNames() const;
18 QString defaultPrinterName() const;
19signals:
20 void availablePrinterNamesChanged();
21 void defaultPrinterNameChanged();
22private slots:
23 void updatePrinters();
24private:
25 QStringList m_available_printer_names;
26 QString m_default_printer_name;
27 QTimer *m_timer_printers;
28};
29
30#endif // PRINTERINFO_H
310
=== removed directory 'backend/tests'
=== removed directory 'backend/tests/unit'
=== removed file 'backend/tests/unit/tst_mytype.qml'
--- backend/tests/unit/tst_mytype.qml 2016-12-13 12:37:45 +0000
+++ backend/tests/unit/tst_mytype.qml 1970-01-01 00:00:00 +0000
@@ -1,49 +0,0 @@
1import QtQuick 2.4
2import QtTest 1.0
3import Ubuntu.Components 1.3
4import Ubuntu_Printing_App 1.0
5
6// See more details @ http://qt-project.org/doc/qt-5.0/qtquick/qml-testcase.html
7
8// Execute tests with:
9// qmltestrunner
10
11Item {
12 // The objects
13 MyType {
14 id: objectUnderTest
15 }
16
17 TestCase {
18 name: "MyType"
19
20 function init() {
21 console.debug(">> init");
22 compare("",objectUnderTest.helloWorld,"text was not empty on init");
23 console.debug("<< init");
24 }
25
26 function cleanup() {
27 console.debug(">> cleanup");
28 console.debug("<< cleanup");
29 }
30
31 function initTestCase() {
32 console.debug(">> initTestCase");
33 console.debug("<< initTestCase");
34 }
35
36 function cleanupTestCase() {
37 console.debug(">> cleanupTestCase");
38 console.debug("<< cleanupTestCase");
39 }
40
41 function test_canReadAndWriteText() {
42 var expected = "Hello World 2";
43
44 objectUnderTest.helloWorld = expected;
45
46 compare(expected,objectUnderTest.helloWorld,"expected did not equal result");
47 }
48 }
49}
500
=== modified file 'debian/changelog'
--- debian/changelog 2016-12-09 22:02:22 +0000
+++ debian/changelog 2017-02-08 21:32:20 +0000
@@ -2,4 +2,4 @@
22
3 * Initial release3 * Initial release
44
5 -- Andrew Hayzen <ahayzen@gmail.com> Fri, 09 Dec 2016 21:54:12 +00005 -- Andrew Hayzen <andrew.hayzen@canonical.com> Fri, 09 Dec 2016 21:54:12 +0000
66
=== modified file 'debian/control'
--- debian/control 2016-12-14 01:01:39 +0000
+++ debian/control 2017-02-08 21:32:20 +0000
@@ -1,27 +1,36 @@
1Source: ubuntu-printing-app1Source: ubuntu-printing-app
2Section: unknown2Section: misc
3Priority: optional3Priority: optional
4Maintainer: Andrew Hayzen <ahayzen@gmail.com>4Maintainer: Andrew Hayzen <andrew.hayzen@canonical.com>
5Build-Depends: cmake (>= 2.8.9),5Build-Depends: cmake (>= 2.8.9),
6 debhelper (>=9),6 debhelper (>=9),
7 dh-apparmor,7 dh-apparmor,
8 dh-translations,8 dh-translations,
9 libcups2-dev,
10 libpoppler-qt5-dev,9 libpoppler-qt5-dev,
11 qmlscene,10 qmlscene,
11 qml-module-qtquick2,
12 qml-module-qtquick-layouts,
13 qml-module-qttest,
14 qml-module-ubuntu-settings-components,
15 qml-module-ubuntu-test,
16 qtdeclarative5-ubuntu-content1,
17 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 1.3) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 1.3),
12 qt5-default,18 qt5-default,
13 qt5-qmake,19 qt5-qmake,
14 qtdeclarative5-dev,20 qtdeclarative5-dev,
15 ubuntu-sdk-qmake-extras21 qtdeclarative5-dev-tools,
22 ubuntu-sdk-qmake-extras,
23 xvfb
16Standards-Version: 3.9.624Standards-Version: 3.9.6
17Homepage: <insert the upstream URL, if relevant>25Homepage: http://launchpad.net/ubuntu-printing-app
26Vcs-Bzr: https://code.launchpad.net/~phablet-team/ubuntu-printing-app/trunk
1827
19Package: ubuntu-printing-app28Package: ubuntu-printing-app
20Architecture: any29Architecture: any
21Depends: ${shlibs:Depends}, ${misc:Depends},30Depends: ${shlibs:Depends}, ${misc:Depends},
22 libcups2,
23 qml-module-qtquick2,31 qml-module-qtquick2,
24 qml-module-qtquick-layouts,32 qml-module-qtquick-layouts,
33 qml-module-ubuntu-settings-components,
25 qtdeclarative5-ubuntu-content1,34 qtdeclarative5-ubuntu-content1,
26 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 1.3) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 1.3),35 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 1.3) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 1.3),
27Description: Printing app which consumes a PDF from content-hub36Description: Printing app which consumes a PDF from content-hub
2837
=== modified file 'debian/copyright'
--- debian/copyright 2016-12-09 22:02:22 +0000
+++ debian/copyright 2017-02-08 21:32:20 +0000
@@ -1,6 +1,6 @@
1Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/1Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2Upstream-Name: ubuntu-printing-app2Upstream-Name: ubuntu-printing-app
3Source: <url://example.com>3Source: https://code.launchpad.net/ubuntu-printing-app
44
5Files: *5Files: *
6Copyright: 2016 Canonical Ltd.6Copyright: 2016 Canonical Ltd.
77
=== removed file 'manifest.json.in'
--- manifest.json.in 2016-12-13 23:08:52 +0000
+++ manifest.json.in 1970-01-01 00:00:00 +0000
@@ -1,16 +0,0 @@
1{
2 "name": "ubuntu-printing-app.ahayzen",
3 "description": "A basic printing app for Ubuntu",
4 "architecture": "@CLICK_ARCH@",
5 "title": "ubuntu-printing-app",
6 "hooks": {
7 "ubuntu-printing-app": {
8 "apparmor": "ubuntu-printing-app/ubuntu-printing-app.apparmor",
9 "content-hub": "ubuntu-printing-app/ubuntu-printing-app-content-hub.json",
10 "desktop": "ubuntu-printing-app/ubuntu-printing-app.desktop"
11 }
12 },
13 "version": "0.1",
14 "maintainer": "Andrew Hayzen <ahayzen@gmail.com>",
15 "framework": "ubuntu-sdk-15.04.6"
16}
170
=== added directory 'po'
=== added file 'po/CMakeLists.txt'
--- po/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ po/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -0,0 +1,44 @@
1project(ubuntu-printing-app-translations)
2
3include(FindGettext)
4find_program(GETTEXT_XGETTEXT_EXECUTABLE xgettext)
5
6file(RELATIVE_PATH DESKTOP_FILE_IN_IN ${CMAKE_SOURCE_DIR}
7 ${CMAKE_SOURCE_DIR}/ubuntu-printing-app/${DESKTOP_FILE}.in.in)
8file(RELATIVE_PATH DESKTOP_FILE_IN_IN_H ${CMAKE_SOURCE_DIR}
9 ${CMAKE_CURRENT_SOURCE_DIR}/${DESKTOP_FILE_IN_IN}.h)
10
11file(GLOB_RECURSE I18N_SRC_FILES
12 RELATIVE ${CMAKE_SOURCE_DIR}
13 ${CMAKE_SOURCE_DIR}/ubuntu-printing-app/**.qml)
14list(SORT I18N_SRC_FILES)
15
16set(DOMAIN ${GETTEXT_PACKAGE})
17set(POT_FILE ${DOMAIN}.pot)
18file(GLOB PO_FILES *.po)
19
20add_custom_target(${POT_FILE} ALL
21 COMMENT "Generating translation template"
22 COMMAND touch ${POT_FILE}
23 COMMAND ${INTLTOOL_EXTRACT} --update --type=gettext/ini
24 --srcdir=${CMAKE_SOURCE_DIR} ${DESKTOP_FILE_IN_IN}
25 COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} -o ${POT_FILE}
26 -D ${CMAKE_SOURCE_DIR}
27 --from-code=UTF-8
28 --c++ --qt --add-comments=TRANSLATORS
29 --keyword=tr --keyword=tr:1,2 --keyword=N_
30 -j
31 --package-name=ubuntu-printing-app
32 --copyright-holder='Canonical Ltd.'
33 -D ${CMAKE_SOURCE_DIR} ${I18N_SRC_FILES}
34 -D ${CMAKE_BINARY_DIR} ${DESKTOP_FILE_IN_IN_H}
35 COMMAND ${CMAKE_COMMAND} -E copy ${POT_FILE} ${CMAKE_CURRENT_SOURCE_DIR})
36
37foreach(PO_FILE ${PO_FILES})
38 get_filename_component(LANG ${PO_FILE} NAME_WE)
39 gettext_process_po_files(${LANG} ALL PO_FILES ${PO_FILE})
40 set(INSTALL_DIR ${CMAKE_INSTALL_LOCALEDIR}/${LANG}/LC_MESSAGES)
41 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LANG}.gmo
42 DESTINATION ${INSTALL_DIR}
43 RENAME ${DOMAIN}.mo)
44endforeach(PO_FILE)
045
=== added file 'po/ubuntu-printing-app.pot'
--- po/ubuntu-printing-app.pot 1970-01-01 00:00:00 +0000
+++ po/ubuntu-printing-app.pot 2017-02-08 21:32:20 +0000
@@ -0,0 +1,122 @@
1# SOME DESCRIPTIVE TITLE.
2# Copyright (C) YEAR Canonical Ltd.
3# This file is distributed under the same license as the ubuntu-printing-app package.
4# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5#
6#, fuzzy
7msgid ""
8msgstr ""
9"Project-Id-Version: ubuntu-printing-app\n"
10"Report-Msgid-Bugs-To: \n"
11"POT-Creation-Date: 2017-02-08 21:19+0100\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"
15"Language: \n"
16"MIME-Version: 1.0\n"
17"Content-Type: text/plain; charset=CHARSET\n"
18"Content-Transfer-Encoding: 8bit\n"
19
20#: ubuntu-printing-app/Main.qml:55
21msgid "Document is invalid"
22msgstr ""
23
24#: ubuntu-printing-app/Main.qml:58
25msgid "Document not found"
26msgstr ""
27
28#: ubuntu-printing-app/Main.qml:61
29msgid "Not a PDF document"
30msgstr ""
31
32#: ubuntu-printing-app/Main.qml:64
33msgid "An unknown error occurred"
34msgstr ""
35
36#: ubuntu-printing-app/Main.qml:76
37msgid "Error"
38msgstr ""
39
40#: ubuntu-printing-app/Main.qml:96
41msgid "URL of PDF to print"
42msgstr ""
43
44#: ubuntu-printing-app/components/AlertDialog.qml:28
45msgid "OK"
46msgstr ""
47
48#: ubuntu-printing-app/components/PrintRow.qml:56
49msgid "Cancel"
50msgstr ""
51
52#: ubuntu-printing-app/components/PrintRow.qml:69
53msgid "Create PDF"
54msgstr ""
55
56#: ubuntu-printing-app/components/PrintRow.qml:69
57msgid "Print"
58msgstr ""
59
60#: ubuntu-printing-app/components/PrintRow.qml:69
61msgid "Sheets"
62msgstr ""
63
64#: ubuntu-printing-app/pages/ContentPeerPickerPage.qml:43
65msgid "Open With..."
66msgstr ""
67
68#: ubuntu-printing-app/pages/PrintPage.qml:47
69msgid "Page Setup"
70msgstr ""
71
72#: ubuntu-printing-app/pages/PrintPage.qml:47
73msgid "Printer Options"
74msgstr ""
75
76#: ubuntu-printing-app/pages/PrintPage.qml:85
77msgid "Printer"
78msgstr ""
79
80#: ubuntu-printing-app/pages/PrintPage.qml:97
81msgid "Copies"
82msgstr ""
83
84#: ubuntu-printing-app/pages/PrintPage.qml:120
85msgid "Collate"
86msgstr ""
87
88#: ubuntu-printing-app/pages/PrintPage.qml:140
89msgid "Reverse"
90msgstr ""
91
92#: ubuntu-printing-app/pages/PrintPage.qml:163
93msgid "Two-sided"
94msgstr ""
95
96#: ubuntu-printing-app/pages/PrintPage.qml:182
97msgid "All"
98msgstr ""
99
100#: ubuntu-printing-app/pages/PrintPage.qml:182
101msgid "Range"
102msgstr ""
103
104#: ubuntu-printing-app/pages/PrintPage.qml:186
105msgid "Pages"
106msgstr ""
107
108#: ubuntu-printing-app/pages/PrintPage.qml:228
109msgid "eg 1-3,8"
110msgstr ""
111
112#: ubuntu-printing-app/pages/PrintPage.qml:237
113msgid "Color"
114msgstr ""
115
116#: ubuntu-printing-app/pages/PrintPage.qml:258
117msgid "Quality"
118msgstr ""
119
120#: po/ubuntu-printing-app/ubuntu-printing-app.desktop.in.in.h:1
121msgid "ubuntu-printing-app"
122msgstr ""
0123
=== modified file 'runner/CMakeLists.txt'
--- runner/CMakeLists.txt 2016-12-13 23:08:52 +0000
+++ runner/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -1,6 +1,9 @@
11
2# Install runner2# Install runner
3install(FILES "ubuntu-printing-app" DESTINATION ${CMAKE_INSTALL_BINDIR})3configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ubuntu-printing-app.in ${CMAKE_CURRENT_BINARY_DIR}/${RUNNER})
4
5install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${RUNNER} DESTINATION ${CMAKE_INSTALL_BINDIR})
6
47
5# Show in QtC8# Show in QtC
6add_custom_target(ubuntu_printing_app_runner_files ALL SOURCES ubuntu-printing-app)9add_custom_target(ubuntu_printing_app_runner_files ALL SOURCES ubuntu-printing-app.in)
710
=== removed file 'runner/ubuntu-printing-app'
--- runner/ubuntu-printing-app 2016-12-13 14:23:08 +0000
+++ runner/ubuntu-printing-app 1970-01-01 00:00:00 +0000
@@ -1,3 +0,0 @@
1#!/bin/sh
2
3qmlscene -qt5 /usr/share/ubuntu-printing-app/Main.qml
40
=== added file 'runner/ubuntu-printing-app.in'
--- runner/ubuntu-printing-app.in 1970-01-01 00:00:00 +0000
+++ runner/ubuntu-printing-app.in 2017-02-08 21:32:20 +0000
@@ -0,0 +1,3 @@
1#!/bin/sh
2
3@EXEC@
04
=== added directory 'setup'
=== added directory 'setup/gui'
=== added file 'setup/gui/ubuntu-printing-app.desktop'
--- setup/gui/ubuntu-printing-app.desktop 1970-01-01 00:00:00 +0000
+++ setup/gui/ubuntu-printing-app.desktop 2017-02-08 21:32:20 +0000
@@ -0,0 +1,8 @@
1[Desktop Entry]
2Name=ubuntu-printing-app
3Exec=ubuntu-printing-app
4Icon=${SNAP}/meta/gui/ubuntu-printing-app.png
5Terminal=false
6Type=Application
7X-Ubuntu-Touch=true
8X-Ubuntu-Touch-Single-Instance=false
09
=== added file 'setup/gui/ubuntu-printing-app.png'
1Binary files setup/gui/ubuntu-printing-app.png 1970-01-01 00:00:00 +0000 and setup/gui/ubuntu-printing-app.png 2017-02-08 21:32:20 +0000 differ10Binary files setup/gui/ubuntu-printing-app.png 1970-01-01 00:00:00 +0000 and setup/gui/ubuntu-printing-app.png 2017-02-08 21:32:20 +0000 differ
=== added directory 'snap'
=== added directory 'snap/ubuntu-app-platform'
=== added file 'snapcraft.yaml'
--- snapcraft.yaml 1970-01-01 00:00:00 +0000
+++ snapcraft.yaml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,75 @@
1name: ubuntu-printing-app
2version: "0.1"
3summary: "Printing app which consumes a PDF from content-hub"
4description: Printing app which consumes a PDF document from
5 content-hub, allows for basic configuration and
6 then sends to a CUPS printer.
7confinement: strict
8
9apps:
10 ubuntu-printing-app:
11 command: desktop-launch $SNAP/usr/bin/ubuntu-printing-app --desktop_file_hint=unity8
12 plugs:
13 - cups-control
14 - home
15 - network
16 - opengl
17 - platform
18 - unity7
19 - unity8
20
21plugs:
22 platform:
23 interface: content
24 content: ubuntu-app-platform1
25 target: ubuntu-app-platform
26 default-provider: ubuntu-app-platform
27
28parts:
29 ubuntu-printing-app:
30 build-packages:
31 - intltool
32 - libpoppler-qt5-dev
33 - qml-module-qttest
34 - qml-module-ubuntu-test
35 - qt5-default
36 - qt5-qmake
37 - qtdeclarative5-dev
38 - ubuntu-sdk-qmake-extras
39 - xvfb
40 configflags: [-DCMAKE_INSTALL_PREFIX=/usr, -DSNAP_MODE=on]
41 plugin: cmake
42 source: .
43 after: [printer-components, desktop-ubuntu-app-platform]
44
45 printer-components:
46 plugin: cmake
47 configflags: [-DCMAKE_INSTALL_PREFIX=/usr]
48 source: https://code.launchpad.net/~phablet-team/ubuntu-settings-components/printer-components
49 source-type: bzr
50 build-packages:
51 - cmake-extras
52 - libcups2-dev
53 - libqt5printsupport5
54 - debhelper
55 - gettext
56 - pkg-config
57 - python3
58 - qml-module-qt-labs-folderlistmodel
59 - qml-module-qtquick-layouts
60 - qml-module-qtquick2
61 - qml-module-qttest
62 - qml-module-ubuntu-components
63 - qml-module-ubuntu-thumbnailer0.1
64 - qtbase5-dev
65 - qtbase5-private-dev
66 - qtdeclarative5-dev
67 - qtdeclarative5-dev-tools
68 - suru-icon-theme
69 stage-packages:
70 - libcups2
71 - libqt5printsupport5
72
73 environment:
74 source: snap/
75 plugin: dump
076
=== added directory 'tests'
=== added file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -0,0 +1,3 @@
1add_subdirectory(resources)
2add_subdirectory(qmltests)
3add_subdirectory(unittests)
04
=== added directory 'tests/qmltests'
=== added file 'tests/qmltests/CMakeLists.txt'
--- tests/qmltests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/qmltests/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -0,0 +1,46 @@
1find_package(Qt5Core REQUIRED)
2find_package(Qt5Gui REQUIRED)
3find_package(Qt5Qml REQUIRED)
4find_package(Qt5Quick REQUIRED)
5find_package(Qt5QuickTest REQUIRED)
6
7find_program(XVFBRUN xvfb-run)
8if(NOT XVFBRUN)
9 message(FATAL_ERROR "Could not find xvfb-run, please install the xvfb package")
10endif()
11set(XVFB_COMMAND ${XVFBRUN} -s "-screen 0 640x480x24" -a)
12
13find_program(QMLTESTRUNNER qmltestrunner)
14if(NOT QMLTESTRUNNER)
15 message(FATAL_ERROR "Could not find qmltestrunner, please install the package qtdeclarative5-dev-tools")
16endif()
17
18set(TEST tst_QmlTests)
19add_test(${TEST} ${XVFB_COMMAND} ${QMLTESTRUNNER}
20 -input ${CMAKE_CURRENT_SOURCE_DIR}
21 -import ${CMAKE_BINARY_DIR}/backend)
22
23
24# Add the qml test files to build dir
25set(QMLTEST_FILES
26 tst_CheckBoxRow.qml
27 tst_LabelRow.qml
28 tst_PreviewRow.qml
29 tst_PrintRow.qml
30 tst_PrintPage.qml
31 tst_SelectorRow.qml
32 tst_TextFieldRow.qml
33)
34
35add_custom_target(qmltest_copyFiles ALL
36 COMMENT "Copying files: ${QMLTEST_FILES}")
37
38foreach(FILENAME ${QMLTEST_FILES})
39 add_custom_command(
40 TARGET qmltest_copyFiles
41 COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}"
42 )
43endforeach(FILENAME)
44
45# Show in QtC
46add_custom_target(qmltest_files ALL SOURCES ${QMLTEST_FILES})
047
=== added file 'tests/qmltests/tst_CheckBoxRow.qml'
--- tests/qmltests/tst_CheckBoxRow.qml 1970-01-01 00:00:00 +0000
+++ tests/qmltests/tst_CheckBoxRow.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,87 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import QtTest 1.1
22import Ubuntu.Test 1.0
23import "../../ubuntu-printing-app/components"
24
25Item {
26 width: units.gu(100)
27 height: units.gu(75)
28
29 CheckBoxRow {
30 id: checkBoxRow
31 }
32
33 UbuntuTestCase {
34 name: "CheckBoxRowTestCase"
35 when: windowShown
36
37 readonly property bool dataChecked: false
38 readonly property string dataCheckboxText: "checkboxText"
39 readonly property bool dataEnabled: true
40 readonly property string dataText: "text"
41
42 function init() {
43 checkBoxRow.checked = dataChecked;
44 checkBoxRow.checkboxText = dataCheckboxText;
45 checkBoxRow.enabled = dataEnabled;
46 checkBoxRow.text = dataText;
47
48 waitForRendering(checkBoxRow);
49 }
50
51 function test_checked() {
52 // Check checkbox checked state is starting value
53 var checkbox = findChild(checkBoxRow, "checkbox");
54 compare(checkBoxRow.checked, dataChecked);
55
56 // Click on the checkbox
57 mouseClick(checkbox);
58
59 // Check that the checked state flips
60 tryCompare(checkBoxRow, "checked", !dataChecked);
61 }
62
63 function test_checkboxText() {
64 // Check that the checkbox label is correct
65 var label = findChild(checkBoxRow, "checkboxLabel");
66 compare(label.text, dataCheckboxText);
67 }
68
69 function test_enabled() {
70 // Check checkbox enabled state is starting value
71 var checkbox = findChild(checkBoxRow, "checkbox");
72 compare(checkBoxRow.enabled, dataEnabled);
73
74 // Flip the enabled state
75 checkBoxRow.enabled = !dataEnabled;
76
77 // Check that the enabled state changes
78 tryCompare(checkbox, "enabled", !dataEnabled);
79 }
80
81 function test_text() {
82 // Check that the text is correct
83 var label = findChild(checkBoxRow, "label");
84 compare(label.text, dataText);
85 }
86 }
87}
088
=== added file 'tests/qmltests/tst_LabelRow.qml'
--- tests/qmltests/tst_LabelRow.qml 1970-01-01 00:00:00 +0000
+++ tests/qmltests/tst_LabelRow.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,73 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import QtTest 1.1
22import Ubuntu.Test 1.0
23import "../../ubuntu-printing-app/components"
24
25Item {
26 width: units.gu(100)
27 height: units.gu(75)
28
29 LabelRow {
30 id: labelRow
31 }
32
33 UbuntuTestCase {
34 name: "LabelRowTestCase"
35 when: windowShown
36
37 readonly property bool dataEnabled: true
38 readonly property string dataPrimaryText: "Primary"
39 readonly property string dataSecondaryText: "Secondary"
40
41 function init() {
42 labelRow.enabled = dataEnabled;
43 labelRow.primaryText = dataPrimaryText;
44 labelRow.secondaryText = dataSecondaryText;
45
46 waitForRendering(labelRow);
47 }
48
49 function test_enabled() {
50 // Check that label enabled state is at the starting state
51 var secondary = findChild(labelRow, "secondary");
52 compare(labelRow.enabled, dataEnabled);
53
54 // Flip the enabled state
55 labelRow.enabled = !dataEnabled;
56
57 // Check that the label enabled state changes
58 tryCompare(secondary, "enabled", !dataEnabled);
59 }
60
61 function test_primaryText() {
62 // Check primary text is correct
63 var primary = findChild(labelRow, "primary");
64 compare(primary.text, dataPrimaryText);
65 }
66
67 function test_secondaryText() {
68 // Check secondary text is correct
69 var secondary = findChild(labelRow, "secondary");
70 compare(secondary.text, dataSecondaryText);
71 }
72 }
73}
074
=== added file 'tests/qmltests/tst_PreviewRow.qml'
--- tests/qmltests/tst_PreviewRow.qml 1970-01-01 00:00:00 +0000
+++ tests/qmltests/tst_PreviewRow.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,316 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import QtTest 1.1
22import Ubuntu.Test 1.0
23import "../../ubuntu-printing-app/components"
24
25import UbuntuPrintingApp 1.0
26import Ubuntu.Settings.Printers 0.1
27
28Item {
29 id: root
30 width: units.gu(100)
31 height: units.gu(75)
32
33 Document {
34 id: testDocument
35 url: Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf")
36 }
37
38 QtObject {
39 id: mockPrinterJob
40
41 property int colorModelType: PrinterEnum.ColorType
42 }
43
44 Item {
45 id: mockView
46 height: units.gu(100)
47 width: units.gu(100)
48 }
49
50 PreviewRow {
51 id: previewRow
52 document: testDocument
53 printerJob: mockPrinterJob
54 view: mockView
55 }
56
57 SignalSpy {
58 id: documentCountSpy
59 signalName: "onCountChanged"
60 target: testDocument
61 }
62
63 SignalSpy {
64 id: activityIndicatorSpy
65 signalName: "onRunningChanged"
66 // Target is set at runtime
67 }
68
69 UbuntuTestCase {
70 name: "PreviewRowTestCase"
71 when: windowShown
72
73 function init() {
74 testDocument.url = Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf");
75
76 mockPrinterJob.colorModelType = PrinterEnum.ColorType;
77
78 activityIndicatorSpy.target = null;
79 activityIndicatorSpy.clear();
80 documentCountSpy.clear();
81
82 waitForRendering(previewRow);
83 }
84
85 function test_activityIndicator() {
86 var image = findChild(previewRow, "previewImage");
87 var activityIndicator = findChild(previewRow, "activityIndicator");
88 activityIndicatorSpy.target = activityIndicator;
89
90 // Change the document and wait for image to finish loading
91 testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
92 tryCompare(image, "status", Image.Ready);
93
94 // Check that the running state changed twice false=>true=>falase
95 compare(activityIndicatorSpy.count, 2);
96 }
97
98 function test_document_image() {
99 var image = findChild(previewRow, "previewImage");
100
101 // Change the document
102 testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
103
104 // Ensure that the image has a valid state
105 tryCompare(image, "status", Image.Ready);
106 }
107
108 function test_document_image_invalid() {
109 var image = findChild(previewRow, "previewImage");
110
111 // Change the document to an invalid doc
112 testDocument.url = Qt.resolvedUrl("../resources/pdf/text.txt");
113
114 // Ensure that the image has a valid state
115 // This is because the poppler renderer always generates a valid image
116 tryCompare(image, "status", Image.Ready);
117 }
118
119 function test_document_change_page_reset() {
120 var next = findChild(previewRow, "nextButton");
121 var pageHelper = previewRow.pageHelper;
122
123 // Load a multi page document and change to 2nd page
124 testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
125
126 documentCountSpy.wait();
127 compare(documentCountSpy.count, 1);
128 compare(testDocument.count, 3);
129
130 mouseClick(next);
131 tryCompare(pageHelper, "page", 1);
132
133 // Load a single page document, check we go back to page 0
134 testDocument.url = Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf");
135
136 documentCountSpy.wait();
137 compare(documentCountSpy.count, 2);
138 compare(testDocument.count, 1);
139 compare(pageHelper.page, 0);
140 }
141
142 function test_overlay() {
143 var label = findChild(previewRow, "overlayLabel");
144 var pageHelper = previewRow.pageHelper;
145 var textParts = label.text.split("/");
146
147 // Check text starts with 1/1
148 compare(textParts.length, 2);
149 compare(textParts[0], "1");
150 compare(textParts[1], "1");
151
152 testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
153
154 waitForRendering(previewRow);
155 textParts = label.text.split("/");
156
157 // Check it has changed to 1/3
158 compare(textParts.length, 2);
159 compare(textParts[0], "1");
160 compare(textParts[1], "3");
161
162 pageHelper.page++;
163
164 waitForRendering(previewRow);
165 textParts = label.text.split("/");
166
167 // Check it has changed to 2/3
168 compare(textParts.length, 2);
169 compare(textParts[0], "2");
170 compare(textParts[1], "3");
171 }
172
173 function test_page_single() {
174 var next = findChild(previewRow, "nextButton");
175 var previous = findChild(previewRow, "previousButton");
176
177 // Check with a single page doc navigation controls are disabled
178 compare(next.enabled, false);
179 compare(previous.enabled, false);
180 }
181
182 function test_page_next() {
183 var image = findChild(previewRow, "previewImage");
184 var next = findChild(previewRow, "nextButton");
185 var pageHelper = previewRow.pageHelper;
186
187 testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
188
189 documentCountSpy.wait();
190 compare(documentCountSpy.count, 1);
191
192 // Check with multi page doc, next button becomes enabled
193 compare(testDocument.count, 3);
194 compare(next.enabled, true);
195 compare(pageHelper.page, 0);
196
197 // Check the requested image page is 0
198 // image://poppler/0/true/file:///path/to/file.pdf
199 compare(image.source.toString().slice(0, 17), "image://poppler/0");
200
201 // Click to the next page, check still enabled
202 mouseClick(next);
203 tryCompare(pageHelper, "page", 1);
204 compare(next.enabled, true);
205
206 // Check the requested image page is 1
207 // image://poppler/1/true/file:///path/to/file.pdf
208 compare(image.source.toString().slice(0, 17), "image://poppler/1");
209
210 // Click to the last page, check next becomes diabled
211 mouseClick(next);
212
213 // Change the document
214 testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
215
216 // Ensure that the image has a valid state
217 tryCompare(image, "status", Image.Ready);
218 tryCompare(pageHelper, "page", 2);
219 compare(next.enabled, false);
220
221 // Check the requested image page is 2
222 // image://poppler/2/true/file:///path/to/file.pdf
223 compare(image.source.toString().slice(0, 17), "image://poppler/2");
224 }
225
226 function test_page_previous() {
227 var image = findChild(previewRow, "previewImage");
228 var previous = findChild(previewRow, "previousButton");
229 var pageHelper = previewRow.pageHelper;
230
231 testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
232
233 documentCountSpy.wait();
234 compare(documentCountSpy.count, 1);
235
236 // Check with mulit page doc, previous is still disabled when on 1st
237 compare(testDocument.count, 3);
238 compare(previous.enabled, false);
239 compare(pageHelper.page, 0)
240
241 // Check the requested image page is 0
242 // image://poppler/0/true/file:///path/to/file.pdf
243 compare(image.source.toString().slice(0, 17), "image://poppler/0");
244
245 // Check when changing to the last page, previous is enabled
246 pageHelper.page = 2;
247 tryCompare(pageHelper, "page", 2);
248 compare(previous.enabled, true);
249
250 // Check the requested image page is 2
251 // image://poppler/2/true/file:///path/to/file.pdf
252 compare(image.source.toString().slice(0, 17), "image://poppler/2");
253
254 // Click to the previous page, check still enabled
255 mouseClick(previous);
256 tryCompare(pageHelper, "page", 1);
257 compare(previous.enabled, true);
258
259 // Check the requested image page is 1
260 // image://poppler/1/true/file:///path/to/file.pdf
261 compare(image.source.toString().slice(0, 17), "image://poppler/1");
262
263 // Click to the first page, check previous becomes disabled
264 mouseClick(previous);
265 tryCompare(pageHelper, "page", 0);
266 compare(previous.enabled, false);
267
268 // Check the requested image page is 0
269 // image://poppler/0/true/file:///path/to/file.pdf
270 compare(image.source.toString().slice(0, 17), "image://poppler/0");
271 }
272
273 function test_printerJob_color() {
274 var image = findChild(previewRow, "previewImage");
275 mockPrinterJob.colorModelType = PrinterEnum.ColorType;
276
277 waitForRendering(image);
278
279 // Check the image requested is color
280 // image://poppler/0/true/file:///path/to/file.pdf
281 compare(image.source.toString().slice(0, 22), "image://poppler/0/true");
282 }
283
284 function test_printerJob_grayscale() {
285 var image = findChild(previewRow, "previewImage");
286 mockPrinterJob.colorModelType = PrinterEnum.GrayType;
287
288 waitForRendering(image);
289
290 // Check the image requested is grayscale
291 // image://poppler/0/false/file:///path/to/file.pdf
292 compare(image.source.toString().slice(0, 23), "image://poppler/0/false");
293 }
294
295 function test_view() {
296 // test that the implicitHeight is set from the view height
297 var pageHelper = previewRow.pageHelper;
298
299 // min((WIDTH - 10) / ASPECT, HEIGHT / 1.5)
300
301 // height/width of 100GU, aspect is 0.71
302 // min((100 - 10) / 0.71, 100 / 1.5)
303 // min(126.76, 66.66)
304 fuzzyCompare(previewRow.implicitHeight, units.gu(66.66), units.gu(1));
305
306 // Change the view to have a short width
307 mockView.width = units.gu(50);
308 waitForRendering(previewRow);
309
310 // width 50GU, height 100GU, aspect is 0.71
311 // min((50 - 10) / 0.71, 100 / 1.5)
312 // min(56.33, 66.66)
313 fuzzyCompare(previewRow.implicitHeight, units.gu(56.33), units.gu(1));
314 }
315 }
316}
0317
=== added file 'tests/qmltests/tst_PrintPage.qml'
--- tests/qmltests/tst_PrintPage.qml 1970-01-01 00:00:00 +0000
+++ tests/qmltests/tst_PrintPage.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,437 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import QtTest 1.1
22import Ubuntu.Test 1.0
23import "../../ubuntu-printing-app/pages"
24
25import UbuntuPrintingApp 1.0
26import Ubuntu.Settings.Printers 0.1
27
28Item {
29 width: units.gu(100)
30 height: units.gu(75)
31
32 // Mock the PrintingHelper
33 QtObject {
34 id: mockPrinting
35
36 property ListModel model: ListModel {
37
38 }
39 property bool pdfMode: false
40 property var printer: QtObject {
41 property string name: "PrinterA"
42 property var supportedColorModels: []
43 property var supportedDuplexModes: []
44 property var supportedPrintQualities: []
45 }
46 property var printerJob: QtObject {
47 property bool collate: true
48 property int colorModel: 0
49 property int copies: 1
50 property int duplexMode: 0
51 property bool isTwoSided: false
52 property string printRange: ""
53 property var printRangeMode: 0 // var as it needs to be enum
54 property int quality: 0
55 property bool reverse: false
56 }
57 property int printerSelectedIndex: 0
58 }
59
60 Document {
61 id: document
62 url: Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf")
63 }
64
65 PrintPage {
66 id: printPage
67 anchors {
68 fill: parent
69 }
70 currentDocument: document
71 printing: mockPrinting
72 }
73
74 SignalSpy {
75 id: cancelSpy
76 signalName: "cancel"
77 target: printPage
78 }
79
80 SignalSpy {
81 id: confirmSpy
82 signalName: "confirm"
83 target: printPage
84 }
85
86 UbuntuTestCase {
87 name: "PrintPageTestCase"
88
89 when: windowShown
90
91 property var dataColorModels: ["A", "B", "C"]
92 property var dataDuplexModes: ["A", "B", "C"]
93 property var dataPrinters: [
94 {name: "PrinterA"},
95 {name: "PrinterB"},
96 ]
97 property var dataPrintQualities: ["A", "B", "C"]
98 readonly property int timeout: 1000
99
100 function init() {
101 document.url = Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf");
102
103 mockPrinting.model.clear();
104 for (var i=0; i < dataPrinters.length; i++) {
105 mockPrinting.model.append(dataPrinters[i]);
106 }
107
108 mockPrinting.pdfMode = false;
109
110 mockPrinting.printer.supportedColorModels = dataColorModels;
111 mockPrinting.printer.supportedDuplexModes = dataDuplexModes;
112 mockPrinting.printer.supportedPrintQualities = dataPrintQualities;
113
114 mockPrinting.printerJob.collate = true;
115 mockPrinting.printerJob.copies = 1;
116 mockPrinting.printerJob.printRangeMode = PrinterEnum.AllPages;
117 mockPrinting.printerJob.reverse = false;
118
119 mockPrinting.printerSelectedIndex = 0;
120
121 cancelSpy.clear();
122 confirmSpy.clear();
123
124 waitForRendering(printPage, timeout);
125 }
126
127 function test_cancelButton() {
128 var cancel = findChild(printPage, "cancel");
129
130 // Click the cancel button
131 mouseClick(cancel);
132
133 // Check that cancel signal was emitted
134 cancelSpy.wait();
135 compare(cancelSpy.count, 1);
136 }
137
138 function test_cancelHeader() {
139 // Note SDK adds _button to objectNames in ActionBar
140 var cancel = findChild(printPage, "headerBack_button");
141
142 // Click cancel in the header
143 mouseClick(cancel);
144
145 // Check that cancel signal was emitted
146 cancelSpy.wait();
147 compare(cancelSpy.count, 1);
148 }
149
150 function test_collate() {
151 // Set copies to 2, so collate is enabled
152 mockPrinting.printerJob.copies = 2;
153 tryCompare(mockPrinting.printerJob, "copies", 2);
154
155 // Check starting value of collate is correct
156 var collate = findChild(printPage, "collateCheckBox");
157 compare(collate.enabled, true);
158 compare(collate.checked, true);
159
160 // Click on the checkbox
161 mouseClick(collate);
162
163 // Check that the value of collate has flipped
164 tryCompare(collate, "checked", false, timeout);
165 compare(mockPrinting.printerJob.collate, false);
166 }
167
168 function test_collate_disabled() {
169 // Check collate is disabled when copies is 1
170 var collate = findChild(printPage, "collateCheckBox");
171 compare(mockPrinting.printerJob.copies, 1);
172 compare(collate.enabled, false);
173
174 // Check that is becomes enabled when there are two copies
175 mockPrinting.printerJob.copies = 2;
176 tryCompare(collate, "enabled", true);
177 }
178
179 function test_colorModel() {
180 var colorModel = findChild(printPage, "colorModelSelector");
181
182 // Check color model length is correct
183 compare(colorModel.model.length, dataColorModels.length);
184
185 // Check each of the options has the correct text
186 for (var i=0; i < dataColorModels.length; i++) {
187 var option = findChild(colorModel, "option" + i);
188 compare(option.text, dataColorModels[i]);
189 }
190 }
191
192 function test_colorModelEmptyModels() {
193 // Set the colorModel to empty
194 var colorModel = findChild(printPage, "colorModelSelector");
195 mockPrinting.printer.supportedColorModels = [];
196
197 waitForRendering(colorModel, timeout)
198
199 // Check that the selector becomes disabled
200 compare(colorModel.enabled, false);
201 }
202
203 function test_colorModelSingleModel() {
204 // Set the colorModel to a single entry
205 var colorModel = findChild(printPage, "colorModelSelector");
206 mockPrinting.printer.supportedColorModels = ["A"];
207
208 waitForRendering(colorModel, timeout)
209
210 // Check that the selector becomes disabled
211 compare(colorModel.enabled, false);
212 }
213
214 function test_confirm() {
215 var confirm = findChild(printPage, "confirm");
216
217 // Click the confirm button
218 mouseClick(confirm);
219
220 // Check that the confirm signal was emitted
221 confirmSpy.wait();
222 compare(confirmSpy.count, 1);
223 compare(confirmSpy.signalArguments.length, 1);
224
225 // Check the arg in the signal was the document url
226 var arg = confirmSpy.signalArguments.pop();
227 compare(arg.length, 1);
228 compare(arg[0], document.url);
229 }
230
231 function test_copies() {
232 // Check copies starting value is correct
233 var copies = findChild(printPage, "copiesTextField");
234 compare(copies.value, "1");
235
236 // Change the copies value and check the textField changes
237 mockPrinting.printerJob.copies = 5;
238 tryCompare(copies, "value", "5", timeout, "Copies value did not change");
239 }
240
241 function test_copiesKeyClick() {
242 // Check copies starting value is correct
243 var copies = findChild(printPage, "copiesTextField");
244 compare(copies.value, "1");
245
246 // Click on the textField
247 mouseClick(copies);
248
249 // Clear the current text and enter "2"
250 keyClick(Qt.Key_Backspace);
251 keyClick(Qt.Key_2);
252
253 // Check that "2" is set to the backend
254 tryCompare(copies, "value", "2", timeout, "Copies value did not change");
255 compare(mockPrinting.printerJob.copies, 2);
256 }
257
258 function test_duplex() {
259 var duplex = findChild(printPage, "duplexSelector");
260
261 // Check the duplex model length is correct
262 compare(duplex.model.length, dataDuplexModes.length);
263
264 // Check each of the options has the correct text
265 for (var i=0; i < dataDuplexModes.length; i++) {
266 var option = findChild(duplex, "option" + i);
267 compare(option.text, dataDuplexModes[i]);
268 }
269 }
270
271 function test_duplexEmptyModes() {
272 // Set the duplexModes to empty and with a multipage doc
273 var duplex = findChild(printPage, "duplexSelector");
274 document.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
275 mockPrinting.printer.supportedDuplexModes = [];
276
277 // Check the selector becomes disabled
278 waitForRendering(duplex, timeout)
279 compare(duplex.enabled, false);
280 }
281 function test_duplexEnabledMultiPage() {
282 var duplex = findChild(printPage, "duplexSelector");
283
284 // Check that with single page doc duplex is disabled
285 document.url = Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf");
286 compare(duplex.enabled, false);
287
288 // Check with multi page doc, duplex becomes enabled
289 document.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
290 tryCompare(duplex, "enabled", true, timeout,
291 "Duplex selected didn't become enabled when document changed");
292 }
293 function test_duplexSingleMode() {
294 // Set the duplexModes to a single entry and with a multipage doc
295 var duplex = findChild(printPage, "duplexSelector");
296 document.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
297 mockPrinting.printer.supportedDuplexModes = ["A"];
298
299 // Check the selector becomes disabled
300 waitForRendering(duplex, timeout)
301 compare(duplex.enabled, false);
302 }
303
304 function testPdfMode() {
305 var objects = ["collateCheckBox", "copiesTextField",
306 "duplexSelector", "pageRangeSelector",
307 "pageRangeTextField", "pageRangeLabel",
308 "colorModelSelector", "qualitySelector",
309 "reverseCheckBox"];
310 var pageTitle = printPage.title;
311
312 // Enable pdf mode
313 mockPrinting.pdfMode = true;
314 waitForRendering(printPage, timeout);
315
316 // Check that all the selectors become disabled
317 for (var obj in objects) {
318 compare(findChild(printPage, obj).enabled, false);
319 }
320
321 // Check that the page title changes
322 verify(pageTitle !== printPage.title, "Page title did not change");
323 }
324
325 function test_printers() {
326 var printers = findChild(printPage, "printerSelector");
327
328 // Check that the printers model length is correct
329 compare(printers.model.count, dataPrinters.length);
330
331 // Check each of the options has the correct text
332 for (var i=0; i < dataPrinters.length; i++) {
333 var option = findChild(printers, "option" + i);
334 compare(option.text, dataPrinters[i]["name"]);
335 }
336 }
337
338 function test_printRangeMode() {
339 var printRangeMode = findChild(printPage, "pageRangeSelector");
340 var printRange = findChild(printPage, "pageRangeTextField");
341
342 // Check that with AllPages, printRange is not visible
343 compare(mockPrinting.printerJob.printRangeMode, PrinterEnum.AllPages);
344 compare(printRange.visible, false);
345
346 // Change to PageRange mode
347 mockPrinting.printerJob.printRangeMode = PrinterEnum.PageRange;
348
349 // Check that printRange becomes visible
350 compare(mockPrinting.printerJob.printRangeMode, PrinterEnum.PageRange);
351 tryCompare(printRange, "visible", true, timeout);
352 }
353
354 function test_quality() {
355 var quality = findChild(printPage, "qualitySelector");
356
357 // Check that the qualities model length is correct
358 compare(quality.model.length, dataPrintQualities.length);
359
360 // Check each of the options has the correct text
361 for (var i=0; i < dataPrintQualities.length; i++) {
362 var option = findChild(quality, "option" + i);
363 compare(option.text, dataPrintQualities[i]);
364 }
365 }
366
367 function test_qualityEmptyModels() {
368 // Set the qualities model to empty
369 var quality = findChild(printPage, "qualitySelector");
370 mockPrinting.printer.supportedPrintQualities = [];
371
372 // Check that the selector becomes disabled
373 waitForRendering(quality, timeout)
374 compare(quality.enabled, false);
375 }
376
377 function test_qualitySingleModel() {
378 // Set the colorModel to a single entry
379 var quality = findChild(printPage, "qualitySelector");
380 mockPrinting.printer.supportedPrintQualities = ["A"];
381
382 // Check that the selector becomes disabled
383 waitForRendering(quality, timeout)
384 compare(quality.enabled, false);
385 }
386
387 function test_reverse() {
388 // Check starting value of reverse is correct
389 var reverse = findChild(printPage, "reverseCheckBox");
390 compare(reverse.checked, false);
391
392 // Click on the checkbox
393 mouseClick(reverse);
394
395 // Check that the value of reverse has flipped
396 tryCompare(reverse, "checked", true);
397 compare(mockPrinting.printerJob.reverse, true);
398 }
399
400 function test_sheets() {
401 var printRow = findChild(printPage, "printRow");
402 compare(document.count, 1);
403 compare(mockPrinting.printerJob.copies, 1);
404 compare(mockPrinting.printerJob.isTwoSided, false);
405 compare(printRow.sheets, 1);
406
407 // Enable twoSided, we should get 0.5 rounded to 1 sheet
408 mockPrinting.printerJob.isTwoSided = true;
409
410 compare(mockPrinting.printerJob.isTwoSided, true);
411 compare(printRow.sheets, 1);
412
413 // Enable two copies, we should get 2 copies with duplex, so 1 sheet
414 mockPrinting.printerJob.copies = 2;
415
416 compare(mockPrinting.printerJob.copies, 2);
417 compare(printRow.sheets, 1);
418
419 // Disable two sided, so 2 copies and 2 sheets
420 mockPrinting.printerJob.isTwoSided = false;
421
422 compare(mockPrinting.printerJob.isTwoSided, false);
423 compare(printRow.sheets, 2);
424
425 // Change to a multi page document (3 pages, 2 copies so 6 sheets)
426 document.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf");
427
428 compare(printRow.sheets, 6);
429
430 // Enable two sided, and 1 copy, check we have 3 pages, duplex so 2 sheets
431 mockPrinting.printerJob.copies = 1;
432 mockPrinting.printerJob.isTwoSided = true;
433
434 compare(printRow.sheets, 2);
435 }
436 }
437}
0438
=== added file 'tests/qmltests/tst_PrintRow.qml'
--- tests/qmltests/tst_PrintRow.qml 1970-01-01 00:00:00 +0000
+++ tests/qmltests/tst_PrintRow.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,110 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import QtTest 1.1
22import Ubuntu.Test 1.0
23import "../../ubuntu-printing-app/components"
24
25Item {
26 width: units.gu(100)
27 height: units.gu(75)
28
29 PrintRow {
30 id: printRow
31 anchors {
32 fill: parent
33 }
34 }
35
36 SignalSpy {
37 id: cancelSignal
38 signalName: "cancel"
39 target: printRow
40 }
41
42 SignalSpy {
43 id: confirmSignal
44 signalName: "confirm"
45 target: printRow
46 }
47
48 UbuntuTestCase {
49 name: "PrintRowTestCase"
50
51 when: windowShown
52
53
54 function init() {
55 printRow.pdfMode = false;
56 printRow.sheets = 0;
57
58 cancelSignal.clear();
59 confirmSignal.clear();
60 }
61
62 function test_clickCancel() {
63 var button = findChild(printRow, "cancel");
64 var buttonCenter = centerOf(button);
65 compare(cancelSignal.count, 0)
66
67 // Click on the cancel button
68 mouseClick(button);
69
70 // Check that the cancel signal is emitted
71 cancelSignal.wait();
72 compare(cancelSignal.count, 1)
73 }
74
75 function test_clickConfirm() {
76 var button = findChild(printRow, "confirm");
77 var buttonCenter = centerOf(button);
78 compare(confirmSignal.count, 0)
79
80 // Click on the confirm button
81 mouseClick(button);
82
83 // Check that the confirm signal is emitted
84 confirmSignal.wait();
85 compare(confirmSignal.count, 1)
86 }
87
88 function test_pdfMode() {
89 var button = findChild(printRow, "confirm");
90 var originalText = button.text;
91
92 // Change to Pdf mode
93 printRow.pdfMode = true;
94
95 // Check that the confirm button text changes
96 verify(button.text !== originalText, 1000, "Text did not change when entering PDF Mode");
97 }
98
99 function test_sheets() {
100 var button = findChild(printRow, "confirm");
101 var originalText = button.text;
102
103 // Change the number of sheets
104 printRow.sheets = 10;
105
106 // Check that the confirm button text changes
107 verify(button.text !== originalText, 1000, "Text did not change when changing sheets");
108 }
109 }
110}
0111
=== added file 'tests/qmltests/tst_SelectorRow.qml'
--- tests/qmltests/tst_SelectorRow.qml 1970-01-01 00:00:00 +0000
+++ tests/qmltests/tst_SelectorRow.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,136 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import QtTest 1.1
22import Ubuntu.Test 1.0
23import "../../ubuntu-printing-app/components"
24
25Item {
26 width: units.gu(100)
27 height: units.gu(75)
28
29 SelectorRow {
30 id: selectorRow
31 model: []
32 }
33
34 SignalSpy {
35 id: expansionCompletedSpy
36 signalName: "expansionCompleted"
37 target: selectorRow
38 }
39
40 SignalSpy {
41 id: selectedIndexSpy
42 signalName: "onSelectedIndexChanged"
43 target: selectorRow
44 }
45
46 SignalSpy {
47 id: selectedValueSpy
48 signalName: "onSelectedValueChanged"
49 target: selectorRow
50 }
51
52 UbuntuTestCase {
53 name: "SelectorRowTestCase"
54 when: windowShown
55
56 readonly property string dataLabelText: "Text"
57 readonly property var dataModel: ["A", "B", "C"]
58 readonly property int dataSelectedIndex: 0
59 readonly property int dataSecondarySelectedIndex: 1
60
61 function init() {
62 selectorRow.model = dataModel;
63 selectorRow.selectedIndex = dataSelectedIndex;
64 selectorRow.text = dataLabelText;
65
66 expansionCompletedSpy.clear();
67 selectedIndexSpy.clear();
68 selectedValueSpy.clear();
69
70 waitForRendering(selectorRow);
71 }
72
73 function test_changeOption() {
74 // Check selectedIndex is the starting index
75 compare(selectorRow.selectedIndex, dataSelectedIndex);
76
77 // Expand the selector
78 mouseClick(selectorRow);
79 expansionCompletedSpy.wait();
80 compare(expansionCompletedSpy.count, 1);
81
82 // Click on the secondary index
83 var option1 = findChild(selectorRow, "option" + dataSecondarySelectedIndex);
84 mouseClick(option1);
85
86 // Check that the selectedIndex is the secondaryIndex
87 selectedIndexSpy.wait();
88 compare(selectedIndexSpy.count, 1);
89 compare(selectorRow.selectedIndex, dataSecondarySelectedIndex);
90 }
91
92 function test_label() {
93 // Check that the label is correct
94 var label = findChild(selectorRow, "label");
95 compare(label.text, dataLabelText);
96 }
97
98 function test_model() {
99 // Check the model length is the starting value
100 compare(selectorRow.model.length, dataModel.length);
101
102 // Remove the last entry from the model
103 var tmpModel = dataModel;
104 tmpModel.pop();
105 selectorRow.model = tmpModel;
106
107 // Check the model length changed
108 compare(selectorRow.model.length, tmpModel.length);
109 }
110
111 function test_selectedIndex() {
112 // Check selectedIndex is the starting index
113 compare(selectorRow.selectedIndex, dataSelectedIndex);
114
115 // Change the index to the secondaryIndex
116 selectorRow.selectedIndex = dataSecondarySelectedIndex;
117
118 // Check the index changed
119 selectedIndexSpy.wait();
120 compare(selectedIndexSpy.count, 1);
121 compare(selectorRow.selectedIndex, dataSecondarySelectedIndex);
122 }
123
124 function test_selectedValue() {
125 // Check that selectedValue is the starting value
126 compare(selectorRow.selectedValue, dataModel[dataSelectedIndex]);
127
128 // Change to the secondaryIndex
129 selectorRow.selectedIndex = dataSecondarySelectedIndex;
130
131 // Check that the selectedValue changes
132 selectedValueSpy.wait();
133 compare(selectorRow.selectedValue, dataModel[dataSecondarySelectedIndex]);
134 }
135 }
136}
0137
=== added file 'tests/qmltests/tst_TextFieldRow.qml'
--- tests/qmltests/tst_TextFieldRow.qml 1970-01-01 00:00:00 +0000
+++ tests/qmltests/tst_TextFieldRow.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,174 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import QtTest 1.1
22import Ubuntu.Test 1.0
23import "../../ubuntu-printing-app/components"
24
25Item {
26 width: units.gu(100)
27 height: units.gu(75)
28
29 TextFieldRow {
30 id: textFieldRow
31 }
32
33 IntValidator {
34 id: intValidator
35 bottom: 1
36 top: 9
37 }
38
39 SignalSpy {
40 id: acceptableInputSpy
41 signalName: "onAcceptableInputChanged"
42 target: textFieldRow
43 }
44
45 SignalSpy {
46 id: valueSpy
47 signalName: "onValueChanged"
48 target: textFieldRow
49 }
50
51 UbuntuTestCase {
52 name: "TextFieldRowTestCase"
53 when: windowShown
54
55 readonly property bool dataEnabled: true
56 readonly property string dataPlaceholderText: "placeholder"
57
58 function init() {
59 textFieldRow.enabled = dataEnabled;
60 textFieldRow.inputMethodHints = Qt.ImhNone;
61 textFieldRow.placeholderText = dataPlaceholderText;
62 textFieldRow.text = "test";
63 textFieldRow.validator = null;
64 textFieldRow.value = "";
65
66 acceptableInputSpy.clear();
67 valueSpy.clear();
68
69 waitForRendering(textFieldRow);
70 }
71
72 function test_acceptableInput() {
73 var textField = findChild(textFieldRow, "textField");
74
75 // Set the validator to int (1-9)
76 textFieldRow.validator = intValidator;
77
78 // Set the value to an invalid value
79 textFieldRow.value = "99";
80
81 valueSpy.wait();
82 acceptableInputSpy.wait();
83
84 compare(valueSpy.count, 1);
85 compare(acceptableInputSpy.count, 1);
86
87 // Check the value was not acceptable
88 compare(textFieldRow.acceptableInput, false);
89 compare(textField.acceptableInput, false);
90
91 // Set the value to a valid value
92 textFieldRow.value = "2";
93
94 valueSpy.wait();
95 acceptableInputSpy.wait();
96
97 compare(valueSpy.count, 2);
98 compare(acceptableInputSpy.count, 2);
99
100 // Check the value was acceptable
101 compare(textFieldRow.acceptableInput, true);
102 compare(textField.acceptableInput, true);
103 }
104
105 function test_enabled() {
106 // Check textField enabled state is starting value
107 var textField = findChild(textFieldRow, "textField");
108 compare(textFieldRow.enabled, dataEnabled);
109
110 // Flip the enabled state
111 textFieldRow.enabled = !dataEnabled;
112
113 // Check that the enabled state changes
114 tryCompare(textField, "enabled", !dataEnabled);
115 }
116
117 function test_inputMethodHints() {
118 // Check that inputMethodHints is starting value
119 var textField = findChild(textFieldRow, "textField");
120 compare(textFieldRow.inputMethodHints, Qt.ImhNone);
121 compare(textField.inputMethodHints, Qt.ImhNone);
122
123 // Change the inputMethodHints mode
124 textFieldRow.inputMethodHints = Qt.ImhDigitsOnly;
125
126 // Check it changes in the textField
127 compare(textField.inputMethodHints, Qt.ImhDigitsOnly);
128 }
129
130 function test_placeholderText() {
131 // Check the placeholder text is correct
132 var textField = findChild(textFieldRow, "textField");
133 compare(textField.placeholderText, dataPlaceholderText);
134 compare(textFieldRow.placeholderText, dataPlaceholderText);
135
136 // Check that the value is not the placeholder
137 verify(textField.text !== dataPlaceholderText);
138 verify(textFieldRow.value !== dataPlaceholderText);
139 }
140
141 function test_text() {
142 // Check that the text is the correct value
143 var label = findChild(textFieldRow, "label");
144 compare(label.text, textFieldRow.text);
145 }
146
147 function test_validator() {
148 // Check that a validator can be set
149 var textField = findChild(textFieldRow, "textField");
150 textFieldRow.validator = intValidator;
151
152 compare(textField.validator, intValidator);
153 }
154
155 function test_value() {
156 // Check that the value is the starting value
157 var textField = findChild(textFieldRow, "textField");
158 compare(textFieldRow.value, "");
159 compare(textField.text, "");
160
161 // Click on the text field
162 mouseClick(textField);
163
164 // Enter "a"
165 keyPress(Qt.Key_A);
166
167 // Check that "a" is set to the value
168 valueSpy.wait();
169 compare(valueSpy.count, 1);
170 compare(textField.text, "a");
171 compare(textFieldRow.value, "a");
172 }
173 }
174}
0175
=== added directory 'tests/resources'
=== added file 'tests/resources/CMakeLists.txt'
--- tests/resources/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/resources/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -0,0 +1,6 @@
1add_subdirectory(pdf)
2
3# Copy the test pdf files to the build dir
4add_custom_target(test_pdf_copyFiles ALL
5 COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/pdf ${CMAKE_CURRENT_BINARY_DIR}/pdf
6 DEPENDS ${PDF_TEST_FILES})
07
=== added directory 'tests/resources/pdf'
=== added file 'tests/resources/pdf/CMakeLists.txt'
--- tests/resources/pdf/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/resources/pdf/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -0,0 +1,3 @@
1# Show files in QtC
2file(GLOB PDF_TEST_FILES *.pdf *.txt)
3add_custom_target(test_pdf_files ALL SOURCES ${PDF_TEST_FILES})
04
=== added file 'tests/resources/pdf/a4_portrait.pdf'
1Binary files tests/resources/pdf/a4_portrait.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/a4_portrait.pdf 2017-02-08 21:32:20 +0000 differ5Binary files tests/resources/pdf/a4_portrait.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/a4_portrait.pdf 2017-02-08 21:32:20 +0000 differ
=== added file 'tests/resources/pdf/a5_landscape.pdf'
2Binary files tests/resources/pdf/a5_landscape.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/a5_landscape.pdf 2017-02-08 21:32:20 +0000 differ6Binary files tests/resources/pdf/a5_landscape.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/a5_landscape.pdf 2017-02-08 21:32:20 +0000 differ
=== added file 'tests/resources/pdf/color.pdf'
3Binary files tests/resources/pdf/color.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/color.pdf 2017-02-08 21:32:20 +0000 differ7Binary files tests/resources/pdf/color.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/color.pdf 2017-02-08 21:32:20 +0000 differ
=== added file 'tests/resources/pdf/corrupt.pdf'
--- tests/resources/pdf/corrupt.pdf 1970-01-01 00:00:00 +0000
+++ tests/resources/pdf/corrupt.pdf 2017-02-08 21:32:20 +0000
@@ -0,0 +1,3 @@
1%PDF-1.4
2%äüöß
3%%EOF
04
=== added file 'tests/resources/pdf/mixed_landscape.pdf'
1Binary files tests/resources/pdf/mixed_landscape.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/mixed_landscape.pdf 2017-02-08 21:32:20 +0000 differ5Binary files tests/resources/pdf/mixed_landscape.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/mixed_landscape.pdf 2017-02-08 21:32:20 +0000 differ
=== added file 'tests/resources/pdf/mixed_portrait.pdf'
2Binary files tests/resources/pdf/mixed_portrait.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/mixed_portrait.pdf 2017-02-08 21:32:20 +0000 differ6Binary files tests/resources/pdf/mixed_portrait.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/mixed_portrait.pdf 2017-02-08 21:32:20 +0000 differ
=== added file 'tests/resources/pdf/test_title.pdf'
3Binary files tests/resources/pdf/test_title.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/test_title.pdf 2017-02-08 21:32:20 +0000 differ7Binary files tests/resources/pdf/test_title.pdf 1970-01-01 00:00:00 +0000 and tests/resources/pdf/test_title.pdf 2017-02-08 21:32:20 +0000 differ
=== added file 'tests/resources/pdf/text.txt'
=== added directory 'tests/unittests'
=== added file 'tests/unittests/CMakeLists.txt'
--- tests/unittests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/unittests/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -0,0 +1,1 @@
1add_subdirectory(backend)
02
=== added directory 'tests/unittests/backend'
=== added file 'tests/unittests/backend/CMakeLists.txt'
--- tests/unittests/backend/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/unittests/backend/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -0,0 +1,19 @@
1include_directories(
2 ${CMAKE_CURRENT_SOURCE_DIR}
3 ${CMAKE_CURRENT_BINARY_DIR}
4 ${CMAKE_SOURCE_DIR}/backend/
5)
6
7find_package(Qt5Test REQUIRED)
8
9add_executable(testDocument tst_document.cpp ${PDF_TEST_FILES})
10target_link_libraries(testDocument UbuntuPrintingAppbackend Qt5::Test Qt5::Gui)
11add_test(tst_document testDocument)
12
13add_executable(testPageHelper tst_pagehelper.cpp ${PDF_TEST_FILES})
14target_link_libraries(testPageHelper UbuntuPrintingAppbackend Qt5::Test Qt5::Gui)
15add_test(tst_pagehelper testPageHelper)
16
17add_executable(testPopplerImageProvider tst_popplerimageprovider.cpp ${PDF_TEST_FILES})
18target_link_libraries(testPopplerImageProvider UbuntuPrintingAppbackend Qt5::Test Qt5::Gui)
19add_test(tst_popplerimageprovider testPopplerImageProvider)
020
=== added file 'tests/unittests/backend/tst_document.cpp'
--- tests/unittests/backend/tst_document.cpp 1970-01-01 00:00:00 +0000
+++ tests/unittests/backend/tst_document.cpp 2017-02-08 21:32:20 +0000
@@ -0,0 +1,301 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20
21#include <QDebug>
22#include <QObject>
23#include <QSignalSpy>
24#include <QTest>
25
26#include "UbuntuPrintingApp/document.h"
27
28#define A4_PORTRAIT_SIZE QSize(595, 842)
29#define A4_LANDSCAPE_SIZE QSize(842, 595)
30#define A5_LANDSCAPE_SIZE QSize(595, 420)
31
32#define INVALID_IMAGE_SIZE QSize(0, 0)
33#define VALID_IMAGE_SIZE QSize(100, 100)
34
35Q_DECLARE_METATYPE(Document::Errors)
36
37class TestDocument : public QObject
38{
39 Q_OBJECT
40private Q_SLOTS:
41 void init()
42 {
43 qRegisterMetaType<Document::Errors>("Errors");
44
45 m_document = new Document();
46 }
47 void cleanup()
48 {
49 QSignalSpy destroyedSpy(m_document, SIGNAL(destroyed(QObject*)));
50 m_document->deleteLater();
51 QTRY_COMPARE(destroyedSpy.count(), 1);
52 }
53 QUrl getResourceUrl(const QString &resource) const
54 {
55 return QUrl("file://" + QDir::currentPath() + "/../../resources/pdf/" + resource);
56 }
57
58 void testInit()
59 {
60 QCOMPARE(m_document->count(), 0);
61 QCOMPARE(m_document->getPageSize(0), QSizeF());
62 QCOMPARE(m_document->getPageSize(0).isValid(), false);
63 QCOMPARE(m_document->orientation(), Document::Portrait);
64 QCOMPARE(m_document->title(), QStringLiteral(""));
65 QCOMPARE(m_document->url(), QUrl(QStringLiteral("")));
66 }
67
68 void testCountSinglePage()
69 {
70 QSignalSpy countSpy(m_document, SIGNAL(countChanged()));
71 m_document->setUrl(getResourceUrl("a4_portrait.pdf"));
72 QTRY_COMPARE(countSpy.count(), 1);
73 QCOMPARE(m_document->count(), 1);
74 }
75 void testCountMultiPage()
76 {
77 QSignalSpy countSpy(m_document, SIGNAL(countChanged()));
78 m_document->setUrl(getResourceUrl("mixed_portrait.pdf"));
79 QTRY_COMPARE(countSpy.count(), 1);
80 QCOMPARE(m_document->count(), 3);
81 }
82
83 void testGetPageSizeA4()
84 {
85 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
86 m_document->setUrl(getResourceUrl("a4_portrait.pdf"));
87 QTRY_COMPARE(urlSpy.count(), 1);
88 // Use QSize to compare otherwise double's will be slightly different
89 QCOMPARE(m_document->getPageSize(0).toSize(), A4_PORTRAIT_SIZE);
90 }
91 void testGetPageSizeMixed()
92 {
93 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
94 m_document->setUrl(getResourceUrl("mixed_portrait.pdf"));
95 QTRY_COMPARE(urlSpy.count(), 1);
96 // Use QSize to compare otherwise double's will be slightly different
97 QCOMPARE(m_document->getPageSize(0).toSize(), A4_PORTRAIT_SIZE);
98
99 // Check that second page size is landscape as this is a mixed document
100 QCOMPARE(m_document->getPageSize(1).toSize(), A4_LANDSCAPE_SIZE);
101 }
102 void testGetPageSizeA5Landscape()
103 {
104 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
105 m_document->setUrl(getResourceUrl("a5_landscape.pdf"));
106 QTRY_COMPARE(urlSpy.count(), 1);
107 // Use QSize to compare otherwise double's will be slightly different
108 QCOMPARE(m_document->getPageSize(0).toSize(), A5_LANDSCAPE_SIZE);
109 }
110
111 void testMakeImage()
112 {
113 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
114 m_document->setUrl(getResourceUrl("a4_portrait.pdf"));
115 QTRY_COMPARE(urlSpy.count(), 1);
116
117 QImage image = m_document->makeImage(VALID_IMAGE_SIZE, 0);
118 QCOMPARE(image.isNull(), false);
119 QCOMPARE(image.size(), VALID_IMAGE_SIZE);
120 }
121 void testMakeImageInvalidDocument()
122 {
123 QImage image = m_document->makeImage(VALID_IMAGE_SIZE, 0);
124 QCOMPARE(image.isNull(), true);
125 }
126 void testMakeImageInvalidPage()
127 {
128 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
129 m_document->setUrl(getResourceUrl("a4_portrait.pdf"));
130 QTRY_COMPARE(urlSpy.count(), 1);
131
132 QImage image = m_document->makeImage(VALID_IMAGE_SIZE, 1000);
133 QCOMPARE(image.isNull(), true);
134 }
135 void testMakeImageInvalidSize()
136 {
137 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
138 m_document->setUrl(getResourceUrl("a4_portrait.pdf"));
139 QTRY_COMPARE(urlSpy.count(), 1);
140
141 QImage image = m_document->makeImage(INVALID_IMAGE_SIZE, 0);
142 QCOMPARE(image.isNull(), true);
143 }
144 void testMakeImageNegativePage()
145 {
146 QImage image = m_document->makeImage(VALID_IMAGE_SIZE, -1);
147 QCOMPARE(image.isNull(), true);
148 }
149 void testMakeImageInvalidRenderToImage()
150 {
151 QSKIP("TODO: need to have a test to hit the case where renderToImage returns a null image");
152 }
153
154
155 void testMakeImageToFit()
156 {
157 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
158 m_document->setUrl(getResourceUrl("a4_portrait.pdf"));
159 QTRY_COMPARE(urlSpy.count(), 1);
160
161 QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, 0, true);
162 QCOMPARE(image.isNull(), false);
163 QCOMPARE(image.size(), VALID_IMAGE_SIZE);
164 }
165 void testMakeImageToFitColor()
166 {
167 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
168 m_document->setUrl(getResourceUrl("color.pdf"));
169 QTRY_COMPARE(urlSpy.count(), 1);
170
171 QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, 0, true);
172 QCOMPARE(image.isNull(), false);
173 QCOMPARE(image.size(), VALID_IMAGE_SIZE);
174 QCOMPARE(image.isGrayscale(), false);
175 }
176 void testMakeImageToFitGrayscale()
177 {
178 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
179 m_document->setUrl(getResourceUrl("color.pdf"));
180 QTRY_COMPARE(urlSpy.count(), 1);
181
182 QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, 0, false);
183 QCOMPARE(image.isNull(), false);
184 QCOMPARE(image.size(), VALID_IMAGE_SIZE);
185 QCOMPARE(image.isGrayscale(), true);
186 }
187 void testMakeImageToFitInvalidDocument()
188 {
189 QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, 0, true);
190 QCOMPARE(image.isNull(), true);
191 }
192 void testMakeImageToFitInvalidPage()
193 {
194 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
195 m_document->setUrl(getResourceUrl("a4_portrait.pdf"));
196 QTRY_COMPARE(urlSpy.count(), 1);
197
198 QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, 1000, true);
199 QCOMPARE(image.isNull(), true);
200 }
201 void testMakeImageToFitInvalidSize()
202 {
203 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
204 m_document->setUrl(getResourceUrl("a4_portrait.pdf"));
205 QTRY_COMPARE(urlSpy.count(), 1);
206
207 QImage image = m_document->makeImageToFit(INVALID_IMAGE_SIZE, 0, true);
208 QCOMPARE(image.isNull(), true);
209 }
210 void testMakeImageToFitNegativePage()
211 {
212 QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, -1, true);
213 QCOMPARE(image.isNull(), true);
214 }
215
216
217 void testOrientationPortrait()
218 {
219 QSignalSpy orientationSpy(m_document, SIGNAL(orientationChanged()));
220 m_document->setUrl(getResourceUrl("a4_portrait.pdf"));
221 QTRY_COMPARE(orientationSpy.count(), 1);
222 QCOMPARE(m_document->orientation(), Document::Orientation::Portrait);
223 }
224 void testOrientationLandscape()
225 {
226 QSignalSpy orientationSpy(m_document, SIGNAL(orientationChanged()));
227 m_document->setUrl(getResourceUrl("a5_landscape.pdf"));
228 QTRY_COMPARE(orientationSpy.count(), 1);
229 QCOMPARE(m_document->orientation(), Document::Orientation::Landscape);
230 }
231 void testOrientationMixedPortrait()
232 {
233 QSignalSpy orientationSpy(m_document, SIGNAL(orientationChanged()));
234 m_document->setUrl(getResourceUrl("mixed_portrait.pdf"));
235 QTRY_COMPARE(orientationSpy.count(), 1);
236 QCOMPARE(m_document->orientation(), Document::Orientation::Portrait);
237 }
238 void testOrientationMixedLandscape()
239 {
240 QSignalSpy orientationSpy(m_document, SIGNAL(orientationChanged()));
241 m_document->setUrl(getResourceUrl("mixed_landscape.pdf"));
242 QTRY_COMPARE(orientationSpy.count(), 1);
243 QCOMPARE(m_document->orientation(), Document::Orientation::Landscape);
244 }
245
246 void testTitle()
247 {
248 QSignalSpy titleSpy(m_document, SIGNAL(titleChanged()));
249 m_document->setUrl(getResourceUrl("test_title.pdf"));
250 QTRY_COMPARE(titleSpy.count(), 1);
251 QCOMPARE(m_document->title(), QStringLiteral("Test Title Document"));
252 }
253
254 void testUrl()
255 {
256 QSignalSpy errorSpy(m_document, SIGNAL(error(Document::Errors)));
257 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
258
259 QUrl resource = getResourceUrl("a4_portrait.pdf");
260
261 m_document->setUrl(resource);
262 QTRY_COMPARE(urlSpy.count(), 1);
263 QCOMPARE(errorSpy.count(), 0);
264 QCOMPARE(m_document->url(), resource);
265 }
266 void testUrlNotFound()
267 {
268 QSignalSpy errorSpy(m_document, SIGNAL(error(Document::Errors)));
269 m_document->setUrl(getResourceUrl("notfound.pdf"));
270 QTRY_COMPARE(errorSpy.count(), 1);
271 QCOMPARE(m_document->url(), QUrl(QStringLiteral("")));
272
273 QList<QVariant> args = errorSpy.takeFirst();
274 QCOMPARE(args.at(0).toInt(), (int) Document::Errors::ErrorNotFound);
275 }
276 void testUrlNotPdf()
277 {
278 QSignalSpy errorSpy(m_document, SIGNAL(error(Document::Errors)));
279 m_document->setUrl(getResourceUrl("text.txt"));
280 QTRY_COMPARE(errorSpy.count(), 1);
281 QCOMPARE(m_document->url(), QUrl(QStringLiteral("")));
282
283 QList<QVariant> args = errorSpy.takeFirst();
284 QCOMPARE(args.at(0).toInt(), (int) Document::Errors::ErrorNotPdf);
285 }
286 void testUrlInvalidDocument()
287 {
288 QSignalSpy errorSpy(m_document, SIGNAL(error(Document::Errors)));
289 m_document->setUrl(getResourceUrl("corrupt.pdf"));
290 QTRY_COMPARE(errorSpy.count(), 1);
291 QCOMPARE(m_document->url(), QUrl(QStringLiteral("")));
292
293 QList<QVariant> args = errorSpy.takeFirst();
294 QCOMPARE(args.at(0).toInt(), (int) Document::Errors::ErrorDocumentInvalid);
295 }
296private:
297 Document *m_document;
298};
299
300QTEST_GUILESS_MAIN(TestDocument)
301#include "tst_document.moc"
0302
=== added file 'tests/unittests/backend/tst_pagehelper.cpp'
--- tests/unittests/backend/tst_pagehelper.cpp 1970-01-01 00:00:00 +0000
+++ tests/unittests/backend/tst_pagehelper.cpp 2017-02-08 21:32:20 +0000
@@ -0,0 +1,171 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20
21#include <QDebug>
22#include <QObject>
23#include <QSignalSpy>
24#include <QTest>
25
26#include "UbuntuPrintingApp/document.h"
27#include "UbuntuPrintingApp/pagehelper.h"
28
29#define A4_PORTRAIT_ASPECT_RATIO 595.0 / 842.0
30#define A4_LANDSCAPE_ASPECT_RATIO 842.0 / 595.0
31#define A5_LANDSCAPE_ASPECT_RATIO 595.0 / 420.0
32
33class TestPageHelper : public QObject
34{
35 Q_OBJECT
36private Q_SLOTS:
37 void init()
38 {
39 m_document = new Document();
40 m_page_helper = new PageHelper();
41 m_page_helper->setDocument(m_document);
42 }
43 void cleanup()
44 {
45 QSignalSpy destroyedPageHelperSpy(m_page_helper, SIGNAL(destroyed(QObject*)));
46 m_page_helper->deleteLater();
47 QTRY_COMPARE(destroyedPageHelperSpy.count(), 1);
48
49 QSignalSpy destroyedDocumentSpy(m_document, SIGNAL(destroyed(QObject*)));
50 m_document->deleteLater();
51 QTRY_COMPARE(destroyedDocumentSpy.count(), 1);
52 }
53 QUrl getResourceUrl(const QString &resource) const
54 {
55 return QUrl("file://" + QDir::currentPath() + "/../../resources/pdf/" + resource);
56 }
57
58 void testInit()
59 {
60 QCOMPARE(m_page_helper->aspect(), A4_PORTRAIT_ASPECT_RATIO);
61 QCOMPARE(m_page_helper->document(), m_document);
62 QCOMPARE(m_page_helper->page(), 0);
63 }
64
65 void testAspect()
66 {
67 QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged()));
68 m_document->setUrl(getResourceUrl("a5_landscape.pdf"));
69 QTRY_COMPARE(aspectSpy.count(), 1);
70 QCOMPARE(m_page_helper->aspect(), A5_LANDSCAPE_ASPECT_RATIO);
71 }
72 void testAspectA4Document()
73 {
74 QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged()));
75 m_document->setUrl(getResourceUrl("a5_landscape.pdf"));
76 QTRY_COMPARE(aspectSpy.count(), 1);
77 QCOMPARE(m_page_helper->aspect(), A5_LANDSCAPE_ASPECT_RATIO);
78
79 m_document->setUrl(getResourceUrl("a4_portrait.pdf"));
80 QTRY_COMPARE(aspectSpy.count(), 2);
81 QCOMPARE(m_page_helper->aspect(), A4_PORTRAIT_ASPECT_RATIO);
82 }
83 void testAspectFallsBack()
84 {
85 QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged()));
86 m_document->setUrl(getResourceUrl("a5_landscape.pdf"));
87 QTRY_COMPARE(aspectSpy.count(), 1);
88 QCOMPARE(m_page_helper->aspect(), A5_LANDSCAPE_ASPECT_RATIO);
89
90 // Test when set to a new document that it goes back to A4
91 Document *newDoc = new Document();
92 m_page_helper->setDocument(newDoc);
93 QTRY_COMPARE(aspectSpy.count(), 2);
94 QCOMPARE(m_page_helper->aspect(), A4_PORTRAIT_ASPECT_RATIO);
95
96 newDoc->deleteLater();
97 }
98
99 void testDocument()
100 {
101 QSignalSpy documentSpy(m_page_helper, SIGNAL(documentChanged()));
102 Document *newDoc = new Document();
103 m_page_helper->setDocument(newDoc);
104 QTRY_COMPARE(documentSpy.count(), 1);
105 QCOMPARE(m_page_helper->document(), newDoc);
106 }
107 void testDocumentDisconnect()
108 {
109 QSignalSpy documentSpy(m_page_helper, SIGNAL(documentChanged()));
110 Document *newDoc = new Document();
111 m_page_helper->setDocument(newDoc);
112 QTRY_COMPARE(documentSpy.count(), 1);
113 QCOMPARE(m_page_helper->document(), newDoc);
114
115 // Check that changing the old document doesn't cause signals that were
116 // linked to be fired - eg loading of aspect
117 QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged()));
118 QSignalSpy urlSpy(m_document, SIGNAL(urlChanged()));
119 m_document->setUrl(getResourceUrl("a5_landscape.pdf"));
120 QTRY_COMPARE(urlSpy.count(), 1);
121 QCOMPARE(aspectSpy.count(), 0);
122
123 newDoc->deleteLater();
124 }
125
126 void testDocumentUrlChange()
127 {
128 QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged()));
129 m_document->setUrl(getResourceUrl("a5_landscape.pdf"));
130 QTRY_COMPARE(aspectSpy.count(), 1);
131
132 QCOMPARE(m_page_helper->aspect(), A5_LANDSCAPE_ASPECT_RATIO);
133 }
134
135 void testPageMixedLandscape()
136 {
137 QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged()));
138 QSignalSpy pageSpy(m_page_helper, SIGNAL(pageChanged()));
139 m_document->setUrl(getResourceUrl("mixed_landscape.pdf"));
140 QTRY_COMPARE(aspectSpy.count(), 1);
141 QCOMPARE(m_page_helper->page(), 0);
142 QCOMPARE(m_page_helper->aspect(), A4_LANDSCAPE_ASPECT_RATIO);
143
144 m_page_helper->setPage(1);
145 QTRY_COMPARE(pageSpy.count(), 1);
146 QCOMPARE(m_page_helper->page(), 1);
147 QTRY_COMPARE(aspectSpy.count(), 2);
148 QCOMPARE(m_page_helper->aspect(), A4_PORTRAIT_ASPECT_RATIO);
149 }
150 void testPageMixedPortrait()
151 {
152 QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged()));
153 QSignalSpy pageSpy(m_page_helper, SIGNAL(pageChanged()));
154 m_document->setUrl(getResourceUrl("mixed_portrait.pdf"));
155 QCOMPARE(aspectSpy.count(), 0);
156 QCOMPARE(m_page_helper->aspect(), A4_PORTRAIT_ASPECT_RATIO);
157
158 m_page_helper->setPage(1);
159 QTRY_COMPARE(pageSpy.count(), 1);
160 QCOMPARE(m_page_helper->page(), 1);
161 QTRY_COMPARE(aspectSpy.count(), 1);
162 QCOMPARE(m_page_helper->aspect(), A4_LANDSCAPE_ASPECT_RATIO);
163 }
164
165private:
166 Document *m_document;
167 PageHelper *m_page_helper;
168};
169
170QTEST_GUILESS_MAIN(TestPageHelper)
171#include "tst_pagehelper.moc"
0172
=== added file 'tests/unittests/backend/tst_popplerimageprovider.cpp'
--- tests/unittests/backend/tst_popplerimageprovider.cpp 1970-01-01 00:00:00 +0000
+++ tests/unittests/backend/tst_popplerimageprovider.cpp 2017-02-08 21:32:20 +0000
@@ -0,0 +1,127 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20
21#include <QDebug>
22#include <QObject>
23#include <QSignalSpy>
24#include <QTest>
25
26#include "UbuntuPrintingApp/popplerimageprovider.h"
27
28class TestPopplerImageProvider : public QObject
29{
30 Q_OBJECT
31private Q_SLOTS:
32 void init()
33 {
34 m_provider = new PopplerImageProvider();
35 }
36 void cleanup()
37 {
38 delete m_provider;
39 }
40 QUrl getResourceUrl(const QString &resource) const
41 {
42 return QUrl("file://" + QDir::currentPath() + "/../../resources/pdf/" + resource);
43 }
44
45 void testRequestImage()
46 {
47 QString id = "0/true/" + getResourceUrl("color.pdf").toString();
48 QSize *size = new QSize();
49 QSize requestedSize(250, 250);
50
51 QImage result = m_provider->requestImage(id, size, requestedSize);
52
53 QCOMPARE(result.isNull(), false);
54 QCOMPARE(result.size(), requestedSize);
55 QCOMPARE(*size, requestedSize);
56 QCOMPARE(result.isGrayscale(), false);
57 }
58 void testRequestImageGrayscale()
59 {
60 QString id = "0/false/" + getResourceUrl("color.pdf").toString();
61 QSize *size = new QSize();
62 QSize requestedSize(250, 250);
63
64 QImage result = m_provider->requestImage(id, size, requestedSize);
65
66 QCOMPARE(result.isNull(), false);
67 QCOMPARE(result.size(), requestedSize);
68 QCOMPARE(*size, requestedSize);
69 QCOMPARE(result.isGrayscale(), true);
70 }
71 void testRequestImageMultiPage()
72 {
73 // TODO: is there a way we can confirm that the image is showing the 2nd page?
74 QString id = "1/true/" + getResourceUrl("mixed_portrait.pdf").toString();
75 QSize *size = new QSize();
76 QSize requestedSize(250, 250);
77
78 QImage result = m_provider->requestImage(id, size, requestedSize);
79
80 QCOMPARE(result.isNull(), false);
81 QCOMPARE(result.size(), requestedSize);
82 QCOMPARE(*size, requestedSize);
83 QCOMPARE(result.isGrayscale(), true);
84 }
85
86 void testRequestImageInvalidColor()
87 {
88 QString id = "0/abc/" + getResourceUrl("a4_portrait.pdf").toString();
89 QSize *size = new QSize();
90 QSize requestedSize(250, 250);
91
92 QImage result = m_provider->requestImage(id, size, requestedSize);
93
94 QCOMPARE(result.isNull(), true);
95 QCOMPARE((*size), requestedSize);
96 }
97 void testRequestImageInvalidPage()
98 {
99 QString id = "1000/true/" + getResourceUrl("a4_portrait.pdf").toString();
100 QSize *size = new QSize();
101 QSize requestedSize(250, 250);
102
103 QImage result = m_provider->requestImage(id, size, requestedSize);
104
105 QCOMPARE(result.isNull(), true);
106 QCOMPARE((*size), requestedSize);
107 }
108 void testRequestImageInvalidRequestedSize()
109 {
110 QString id = "0/true/" + getResourceUrl("a4_portrait.pdf").toString();
111 QSize *size = new QSize();
112 QSize requestedSize(-100, -50);
113
114 QImage result = m_provider->requestImage(id, size, requestedSize);
115
116 // An invalid request size returns a size of 1,1 otherwise QML errors occur
117 QCOMPARE(result.isNull(), false);
118 QCOMPARE(result.size(), QSize(1, 1));
119 QCOMPARE((*size), QSize(1, 1));
120 }
121
122private:
123 PopplerImageProvider *m_provider;
124};
125
126QTEST_GUILESS_MAIN(TestPopplerImageProvider)
127#include "tst_popplerimageprovider.moc"
0128
=== modified file 'ubuntu-printing-app/CMakeLists.txt'
--- ubuntu-printing-app/CMakeLists.txt 2016-12-13 23:08:52 +0000
+++ ubuntu-printing-app/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -1,4 +1,5 @@
1add_subdirectory(components)1add_subdirectory(components)
2add_subdirectory(pages)
23
3# Install Main.qml and icon4# Install Main.qml and icon
4install(FILES ${MAIN_QML} DESTINATION ${UBUNTU_PRINTING_APP_DATA_DIR})5install(FILES ${MAIN_QML} DESTINATION ${UBUNTU_PRINTING_APP_DATA_DIR})
@@ -23,6 +24,6 @@
2324
24# Show in QtCreator25# Show in QtCreator
25if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")26if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
26 file(GLOB MAIN_QML_JS_FILES *.qml *.js)27 file(GLOB MAIN_QML_JS_FILES *.apparmor *.js *.json *.qml)
27 add_custom_target(ubuntu_printing_app_main_qml_js_files ALL SOURCES ${MAIN_QML_JS_FILES})28 add_custom_target(ubuntu_printing_app_main_qml_js_files ALL SOURCES ${MAIN_QML_JS_FILES})
28endif(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")29endif(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
2930
=== modified file 'ubuntu-printing-app/Main.qml'
--- ubuntu-printing-app/Main.qml 2016-12-13 12:37:45 +0000
+++ ubuntu-printing-app/Main.qml 2017-02-08 21:32:20 +0000
@@ -1,10 +1,31 @@
1/*
2 * Copyright 2016, 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
1import QtQuick 2.420import QtQuick 2.4
2import QtQuick.Layouts 1.121import QtQuick.Layouts 1.1
322
4import Ubuntu.Components 1.323import Ubuntu.Components 1.3
5import Ubuntu.Components.ListItems 1.3 as ListItems24import Ubuntu.Components.ListItems 1.3 as ListItems
6import Ubuntu.Content 0.125import Ubuntu.Components.Popups 1.3
7import Ubuntu_Printing_App 1.026import Ubuntu.Content 1.1
27import UbuntuPrintingApp 1.0
28import Ubuntu.Settings.Printers 0.1
829
9import "components"30import "components"
1031
@@ -18,295 +39,106 @@
18 objectName: "mainView"39 objectName: "mainView"
1940
20 // Note! applicationName needs to match the "name" field of the click manifest41 // Note! applicationName needs to match the "name" field of the click manifest
21 applicationName: "ubuntu-printing-app.ahayzen"42 applicationName: "ubuntu-printing-app"
2243
23 width: units.gu(40)44 width: units.gu(45)
24 height: units.gu(60)45 height: units.gu(70)
25
26 Connections {
27 target: ContentHub
28
29 onImportRequested: {
30 console.debug("State:", transfer.state)
31 console.debug("Transfer:", transfer)
32 console.debug("Items:", transfer.items)
33
34 for (var i=0; i < transfer.items.length; i++) {
35 var item = transfer.items[i];
36
37 document.url = item.url;
38 console.debug("Item URL:", item.url);
39 }
40 }
41 }
42
43 Printer {
44 id: printer
45 name: PrinterInfo.defaultPrinterName
46
47 // TODO: status ?
48
49 onExportRequest: console.debug("Export requested!", filepath)
50 }
5146
52 Document {47 Document {
53 id: document48 id: document
54 }49
5550 onError: {
56 /*51 var errorString;
57 PrinterInfo.availablePrinterNames52
5853 switch (errorType) {
59 PrinterInfo.defaultName54 case Document.ErrorDocumentInvalid:
6055 errorString = i18n.tr("Document is invalid");
61 Printer {56 break;
62 error: false57 case Document.ErrorNotFound:
63 errorString: ""58 errorString = i18n.tr("Document not found");
64 name: PrinterInfo.defaultName59 break;
6560 case Document.ErrorNotPdf:
66 colorMode: ColorModes.greyscale61 errorString = i18n.tr("Not a PDF document");
67 copies: 262 break;
6863 default:
69 print(Document document) // async64 errorString = i18n.tr("An unknown error occurred");
7065 break;
71 status: {Null,Rendering,SentToPrinter,Error}66 }
72 progress: 0.6 // progress of print67
73 }68 // Empty the Url so user cannot print
7469 url = "";
75 Document {70
76 error: false71 PopupUtils.open(
77 errorString: ""72 Qt.resolvedUrl("components/AlertDialog.qml"),
78 url: "/tmp/my.pdf"73 pageStack.currentPage,
79 }74 {
8075 "text": errorString,
81 */76 "title": i18n.tr("Error"),
8277 }
83 Page {78 )
84 id: page79 }
80 }
81
82 property PrintingHelper printing: PrintingHelper {}
83 property Page printPage: null
84
85 PageStack {
86 id: pageStack
85 anchors {87 anchors {
86 fill: parent88 fill: parent
87 }89 }
88 width: mainView.width90 }
8991
90 header: PageHeader {92 Arguments {
91 id: pageHeader93 id: args
92 leadingActionBar {94 Argument {
93 actions: [95 name: "url"
94 Action {96 help: i18n.tr("URL of PDF to print")
95 iconName: "back"97 required: false
9698 valueNames: ["url"]
97 onTriggered: Qt.quit()99 }
98 }100 }
99 ]101
100 }102 Connections {
101103 target: ContentHub
102 title: printer.pdfMode ? i18n.tr("Page Setup") : i18n.tr("Printer Options")104
103 }105 onImportRequested: {
104106 // FIXME: Only uses the first item given over content-hub
105 ScrollView {107 // do we need to support multiple items in the future?
106 anchors {108 if (transfer.items.length > 0) {
107 bottom: printRow.top109 document.url = transfer.items[0].url;
108 left: parent.left110 }
109 right: parent.right111 }
110 top: page.header.bottom112 }
111 }113
112114 Connections {
113 Item {115 target: printPage
114 height: columnLayout.height + units.gu(2)116
115 width: mainView.width - units.gu(2)117 onCancel: Qt.quit()
116 x: units.gu(1)118 onConfirm: {
117 y: x119 if (printing.pdfMode) {
118120 pageStack.push(Qt.resolvedUrl("pages/ContentPeerPickerPage.qml"), {"url": url});
119 ColumnLayout {121 } else {
120 id: columnLayout122 printing.printerJob.printFile(url);
121 spacing: units.gu(1)123 Qt.quit();
122 width: parent.width124 }
123
124 Rectangle {
125 anchors {
126 left: parent.left
127 right: parent.right
128 }
129 color: "#EEE"
130 implicitHeight: units.gu(25)
131
132 RowLayout {
133 anchors.fill: parent
134
135 Button {
136 enabled: previewImage.pageNumber > 0
137 Layout.preferredWidth: units.gu(4)
138 color: "#000"
139 text: "<"
140
141 onClicked: previewImage.pageNumber--
142 }
143
144 Item {
145 Layout.fillWidth: true
146 Layout.preferredHeight: units.gu(25)
147
148 Image {
149 id: previewImage
150 anchors {
151 fill: parent
152 }
153
154 asynchronous: true
155 source: document.url.toString() !== "" ? "image://poppler/" + pageNumber + "/" + printer.colorMode + "/" + document.url : ""
156 sourceSize {
157 height: units.gu(25)
158 width: previewImage.width
159 }
160
161 property int pageNumber: 0
162 }
163
164 ActivityIndicator {
165 anchors {
166 centerIn: parent
167 }
168 running: previewImage.status == Image.Loading
169 }
170 }
171
172 Button {
173 color: "#000"
174 enabled: previewImage.pageNumber < document.count - 1
175 Layout.preferredWidth: units.gu(4)
176 text: ">"
177
178 onClicked: previewImage.pageNumber++
179 }
180 }
181 }
182
183
184 SelectorRow {
185 model: PrinterInfo.availablePrinterNames
186 selectedIndex: model.indexOf(printer.name)
187 text: i18n.tr("Printer")
188
189 onSelectedIndexChanged: {
190 printer.pdfMode = selectedIndex === model.length - 1
191 printer.name = model[selectedIndex]
192 }
193 }
194
195 RowLayout {
196 Label {
197 Layout.preferredWidth: units.gu(10)
198 text: i18n.tr("Copies")
199 }
200
201 TextField {
202 enabled: !printer.pdfMode
203 inputMethodHints: Qt.ImhDigitsOnly
204 Layout.fillWidth: true
205 Layout.preferredWidth: units.gu(5)
206 text: printer.copies
207 validator: IntValidator {
208 bottom: 1
209 top: 999
210 }
211
212 // TODO: acceptableInput is False show hint
213
214 onTextChanged: {
215 if (acceptableInput) {
216 printer.copies = Number(text);
217 }
218 }
219 }
220 }
221
222 RowLayout {
223 Item {
224 Layout.preferredWidth: units.gu(10)
225 }
226
227 MouseArea {
228 enabled: checkbox.enabled
229 Layout.fillWidth: true
230 Layout.preferredHeight: units.gu(3)
231 Layout.preferredWidth: units.gu(10)
232
233 onClicked: checkbox.checked = !checkbox.checked
234
235 Row {
236 anchors {
237 fill: parent
238 }
239 spacing: units.gu(1)
240
241 CheckBox {
242 id: checkbox
243 anchors {
244 verticalCenter: parent.verticalCenter
245 }
246 checked: printer.duplex
247 enabled: document.count > 1 && printer.duplexSupported
248
249 onCheckedChanged: printer.duplex = checked
250 }
251
252 Label {
253 enabled: document.count > 1
254 height: parent.height
255 text: i18n.tr("Two-Sided")
256 verticalAlignment: Text.AlignVCenter
257 }
258 }
259
260 }
261 }
262
263 SelectorRow {
264 enabled: !printer.pdfMode
265 model: [i18n.tr("Black & White"), i18n.tr("Color")]
266 selectedIndex: modelValue.indexOf(printer.colorMode)
267 text: i18n.tr("Color")
268
269 property var modelValue: [Printer.GrayScale, Printer.Color]
270
271 onSelectedIndexChanged: printer.colorMode = modelValue[selectedIndex]
272 }
273
274 SelectorRow {
275 enabled: !printer.pdfMode
276 model: [i18n.tr("Draft"), i18n.tr("Normal"), i18n.tr("Best"), i18n.tr("Photo")]
277 selectedIndex: modelValue.indexOf(printer.quality)
278 text: i18n.tr("Quality")
279
280 property var modelValue: [Printer.Draft, Printer.Normal, Printer.Best, Printer.Photo]
281
282 onSelectedIndexChanged: printer.quality = modelValue[selectedIndex]
283 }
284 }
285 }
286 }
287
288 PrintRow {
289 id: printRow
290 anchors {
291 bottom: parent.bottom
292 left: parent.left
293 leftMargin: units.gu(1)
294 right: parent.right
295 rightMargin: units.gu(1)
296 }
297 pdfMode: printer.pdfMode
298 sheets: document.count
299
300 onCancel: Qt.quit()
301 onConfirm: printer.print(document); // TODO: check document is valid raise error if not?
302 }125 }
303 }126 }
304127
305 Component.onCompleted: {128 Component.onCompleted: {
306// document.url = Qt.resolvedUrl("/home/andy/Workspace/Work/Canonical/dump/2016-11-17T12:00:08");129 printing.printerJob.landscape = document.orientation === Document.Landscape;
307 document.url = Qt.resolvedUrl("/home/andrew/Downloads/UbuntuPhone.pdf");130 printing.printerJob.title = document.title || document.url.toString().split("/").pop();
308// document.url = Qt.resolvedUrl("/home/andrew/Documents/test.pdf");131 printPage = pageStack.push(
309 console.debug("Printers:", PrinterInfo.availablePrinterNames);132 Qt.resolvedUrl("pages/PrintPage.qml"),
133 {
134 "currentDocument": document,
135 "printing": printing,
136 }
137 );
138
139 if (args.values.url) {
140 document.url = Qt.resolvedUrl(args.values.url);
141 }
310 }142 }
311}143}
312144
313145
=== added file 'ubuntu-printing-app/components/AlertDialog.qml'
--- ubuntu-printing-app/components/AlertDialog.qml 1970-01-01 00:00:00 +0000
+++ ubuntu-printing-app/components/AlertDialog.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,32 @@
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import Ubuntu.Components 1.3
22import Ubuntu.Components.Popups 1.3
23
24Dialog {
25 id: dialog
26
27 Button {
28 text: i18n.tr("OK")
29
30 onClicked: PopupUtils.close(dialog)
31 }
32}
033
=== modified file 'ubuntu-printing-app/components/CMakeLists.txt'
--- ubuntu-printing-app/components/CMakeLists.txt 2016-12-13 23:08:52 +0000
+++ ubuntu-printing-app/components/CMakeLists.txt 2017-02-08 21:32:20 +0000
@@ -1,7 +1,12 @@
1set(COMPONENT_QML_JS_FILES1set(COMPONENT_QML_JS_FILES
2 ExpandableListItem.qml2 AlertDialog.qml
3 CheckBoxRow.qml
4 LabelRow.qml
5 PreviewRow.qml
3 PrintRow.qml6 PrintRow.qml
7 PrintingHelper.qml
4 SelectorRow.qml8 SelectorRow.qml
9 TextFieldRow.qml
5)10)
611
7install(FILES ${COMPONENT_QML_JS_FILES} DESTINATION ${UBUNTU_PRINTING_APP_DATA_DIR}/components)12install(FILES ${COMPONENT_QML_JS_FILES} DESTINATION ${UBUNTU_PRINTING_APP_DATA_DIR}/components)
813
=== added file 'ubuntu-printing-app/components/CheckBoxRow.qml'
--- ubuntu-printing-app/components/CheckBoxRow.qml 1970-01-01 00:00:00 +0000
+++ ubuntu-printing-app/components/CheckBoxRow.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,76 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import QtQuick.Layouts 1.1
22
23import Ubuntu.Components 1.3
24
25RowLayout {
26 anchors {
27 left: parent.left
28 leftMargin: units.gu(2)
29 right: parent.right
30 rightMargin: units.gu(2)
31 }
32 Layout.maximumWidth: width
33
34 property alias checked: checkbox.checked
35 property alias checkboxText: checkboxLabel.text
36 property alias enabled: checkbox.enabled
37 property alias text: label.text
38
39 Label {
40 id: label
41 Layout.preferredWidth: units.gu(10)
42 objectName: "label"
43 }
44
45 MouseArea {
46 enabled: checkbox.enabled
47 Layout.fillWidth: true
48 Layout.preferredHeight: units.gu(3)
49 Layout.preferredWidth: units.gu(10)
50
51 onClicked: checkbox.checked = !checkbox.checked
52
53 Row {
54 anchors {
55 fill: parent
56 }
57 spacing: units.gu(1)
58
59 CheckBox {
60 id: checkbox
61 anchors {
62 verticalCenter: parent.verticalCenter
63 }
64 objectName: "checkbox"
65 }
66
67 Label {
68 id: checkboxLabel
69 enabled: checkbox.enabled
70 height: parent.height
71 objectName: "checkboxLabel"
72 verticalAlignment: Text.AlignVCenter
73 }
74 }
75 }
76}
077
=== removed file 'ubuntu-printing-app/components/ExpandableListItem.qml'
--- ubuntu-printing-app/components/ExpandableListItem.qml 2016-11-25 16:47:10 +0000
+++ ubuntu-printing-app/components/ExpandableListItem.qml 1970-01-01 00:00:00 +0000
@@ -1,82 +0,0 @@
1/*
2 * Copyright (C) 2015-2016 Canonical Ltd
3 *
4 * This file is part of Ubuntu Weather App
5 *
6 * Ubuntu Weather App is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * Ubuntu Weather App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.4
20import Ubuntu.Components 1.3
21
22/*
23 Component which extends the SDK Expandable list item and provides a easy
24 to use component where the title, subtitle and a listview can be displayed. It
25 matches the design specification provided for clock.
26*/
27
28ListItem {
29 id: expandableListItem
30
31 // Public APIs
32 property ListModel model
33 property Component delegate
34 property alias title: expandableHeader.title
35 property alias subText: expandableHeader.subtitle
36 property alias listViewHeight: expandableList.height
37
38 highlightColor: "Transparent"
39 height: expandableHeader.height + divider.height
40 expansion.height: contentColumn.height
41 onClicked: expansion.expanded = !expansion.expanded
42
43 Column {
44 id: contentColumn
45
46 anchors {
47 left: parent.left
48 right: parent.right
49 }
50
51 ListItem {
52 height: expandableHeader.height + divider.height
53 ListItemLayout {
54 id: expandableHeader
55
56 Icon {
57 id: arrow
58
59 width: units.gu(2)
60 height: width
61 SlotsLayout.position: SlotsLayout.Trailing
62 SlotsLayout.overrideVerticalPositioning: true
63 anchors.verticalCenter: parent.verticalCenter
64 name: "go-down"
65 rotation: expandableListItem.expansion.expanded ? 180 : 0
66
67 Behavior on rotation {
68 UbuntuNumberAnimation {}
69 }
70 }
71 }
72 }
73
74 ListView {
75 id: expandableList
76 width: parent.width
77 interactive: false
78 model: expandableListItem.model
79 delegate: expandableListItem.delegate
80 }
81 }
82}
830
=== added file 'ubuntu-printing-app/components/LabelRow.qml'
--- ubuntu-printing-app/components/LabelRow.qml 1970-01-01 00:00:00 +0000
+++ ubuntu-printing-app/components/LabelRow.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,52 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import QtQuick.Layouts 1.1
22
23import Ubuntu.Components 1.3
24
25RowLayout {
26 anchors {
27 left: parent.left
28 leftMargin: units.gu(2)
29 right: parent.right
30 rightMargin: units.gu(2)
31 }
32 Layout.maximumWidth: width
33
34 property alias enabled: secondaryLabel.enabled
35 property alias primaryText: primaryLabel.text
36 property alias secondaryText: secondaryLabel.text
37
38 Label {
39 id: primaryLabel
40 Layout.preferredWidth: units.gu(10)
41 objectName: "primary"
42 }
43
44 Label {
45 id: secondaryLabel
46 Layout.fillWidth: true
47 Layout.preferredHeight: units.gu(3)
48 Layout.preferredWidth: units.gu(10)
49 objectName: "secondary"
50 verticalAlignment: Text.AlignVCenter
51 }
52}
053
=== added file 'ubuntu-printing-app/components/PreviewRow.qml'
--- ubuntu-printing-app/components/PreviewRow.qml 1970-01-01 00:00:00 +0000
+++ ubuntu-printing-app/components/PreviewRow.qml 2017-02-08 21:32:20 +0000
@@ -0,0 +1,142 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of ubuntu-printing-app.
5 *
6 * ubuntu-printing-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-printing-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20import QtQuick 2.4
21import Ubuntu.Components 1.3
22
23import UbuntuPrintingApp 1.0
24import Ubuntu.Settings.Printers 0.1
25
26Rectangle {
27 id: previewRow
28 anchors {
29 left: parent.left
30 right: parent.right
31 }
32 // Use foreground as this element is ontop of the background
33 color: theme.palette.normal.foreground
34 // Height is smallest of
35 // - calc'd height using aspect and width of image
36 // - 2/3 height of the view
37 implicitHeight: Math.min((view.width - units.gu(10)) / pageHelper.aspect, view.height / 1.5)
38
39 property Document document
40 property var printerJob
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: