Merge lp:~jonas-drange/ubuntu-printing-app/soft-depend-on-printjob into lp:ubuntu-printing-app
- soft-depend-on-printjob
- Merge into trunk
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 |
Related bugs: |
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.
Description of the change
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
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2016-12-13 23:40:36 +0000 | |||
3 | +++ CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
4 | @@ -17,52 +17,41 @@ | |||
5 | 17 | set(APP_HARDCODE ubuntu-printing-app) | 17 | set(APP_HARDCODE ubuntu-printing-app) |
6 | 18 | set(CMAKE_AUTOMOC ON) | 18 | set(CMAKE_AUTOMOC ON) |
7 | 19 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") # -fno-permissive -pedantic -Wall -Wextra") | 19 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") # -fno-permissive -pedantic -Wall -Wextra") |
8 | 20 | set(UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Tell QtCreator the location and name o the manifest file") | ||
9 | 21 | set(DESKTOP_FILE "${APP_NAME}.desktop") | 20 | set(DESKTOP_FILE "${APP_NAME}.desktop") |
10 | 22 | set(ICON_FILE ubuntu-printing-app.png) | 21 | set(ICON_FILE ubuntu-printing-app.png) |
11 | 23 | set(MAIN_QML Main.qml) | 22 | set(MAIN_QML Main.qml) |
12 | 23 | set(RUNNER ${APP_HARDCODE}) | ||
13 | 24 | set(SNAP_DESKTOP_FILE setup/gui/${DESKTOP_FILE}) | ||
14 | 24 | 25 | ||
15 | 25 | # Set the options | 26 | # Set the options |
17 | 26 | option(CLICK_MODE "Build as a click package" off) | 27 | option(SNAP_MODE "Build as a snap package" off) |
18 | 27 | 28 | ||
19 | 28 | # Find packages | 29 | # Find packages |
24 | 29 | find_package(Qt5Core) | 30 | find_package(Qt5Core REQUIRED) |
25 | 30 | find_package(Qt5Qml) | 31 | find_package(Qt5Qml REQUIRED) |
26 | 31 | find_package(Qt5Quick) | 32 | find_package(Qt5Quick REQUIRED) |
27 | 32 | find_package(Qt5PrintSupport) | 33 | find_package(Qt5PrintSupport REQUIRED) |
28 | 33 | 34 | ||
29 | 34 | include(GNUInstallDirs) | 35 | include(GNUInstallDirs) |
30 | 35 | 36 | ||
31 | 36 | 37 | ||
32 | 37 | # Set the path for the QML files and the backend | 38 | # Set the path for the QML files and the backend |
42 | 38 | if(CLICK_MODE) | 39 | set(UBUNTU_PRINTING_APP_DATA_DIR "${CMAKE_INSTALL_DATADIR}/${APP_HARDCODE}") |
43 | 39 | message("CLICK_MODE is not supported at this time!") | 40 | execute_process( |
44 | 40 | else(CLICK_MODE) | 41 | COMMAND qmake -query QT_INSTALL_QML |
45 | 41 | set(UBUNTU_PRINTING_APP_DATA_DIR "${CMAKE_INSTALL_DATADIR}/${APP_HARDCODE}") | 42 | OUTPUT_VARIABLE QT_IMPORTS_DIR |
46 | 42 | execute_process( | 43 | OUTPUT_STRIP_TRAILING_WHITESPACE |
47 | 43 | COMMAND qmake -query QT_INSTALL_QML | 44 | ) |
48 | 44 | OUTPUT_VARIABLE QT_IMPORTS_DIR | 45 | set(MODULE_PATH ${QT_IMPORTS_DIR}/UbuntuPrintingApp) |
49 | 45 | OUTPUT_STRIP_TRAILING_WHITESPACE | 46 | |
50 | 46 | ) | 47 | # Set the exec path |
51 | 48 | if(SNAP_MODE) | ||
52 | 49 | set(EXEC "APP_ID=${APP_HARDCODE} qmlscene $@ -I $SNAP/${MODULE_PATH} $SNAP/${CMAKE_INSTALL_PREFIX}/${UBUNTU_PRINTING_APP_DATA_DIR}/${MAIN_QML}") | ||
53 | 50 | set(ICON "$SNAP/${CMAKE_INSTALL_PREFIX}/${UBUNTU_PRINTING_APP_DATA_DIR}/${ICON_FILE}") | ||
54 | 51 | else(SNAP_MODE) | ||
55 | 52 | set(EXEC "APP_ID=${APP_HARDCODE} qmlscene $@ -I ${MODULE_PATH} ${CMAKE_INSTALL_PREFIX}/${UBUNTU_PRINTING_APP_DATA_DIR}/${MAIN_QML}") | ||
56 | 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}) |
75 | 48 | set(MODULE_PATH ${QT_IMPORTS_DIR}/Ubuntu_Printing_App) | 54 | endif(SNAP_MODE) |
58 | 49 | endif(CLICK_MODE) | ||
59 | 50 | |||
60 | 51 | # Set the exec path | ||
61 | 52 | if (CLICK_MODE) | ||
62 | 53 | message("CLICK_MODE is not supported at this time!") | ||
63 | 54 | else(CLICK_MODE) | ||
64 | 55 | # FIXME should this point to the runner? | ||
65 | 56 | set(EXEC "qmlscene $@ -I ${MODULE_PATH} ${CMAKE_INSTALL_PREFIX}/${UBUNTU_PRINTING_APP_DATA_DIR}/${MAIN_QML}") | ||
66 | 57 | endif(CLICK_MODE) | ||
67 | 58 | |||
68 | 59 | |||
69 | 60 | # Find translatable files | ||
70 | 61 | file(GLOB_RECURSE I18N_SRC_FILES | ||
71 | 62 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/po | ||
72 | 63 | *.qml *.js *.cpp) | ||
73 | 64 | list(APPEND I18N_SRC_FILES ${DESKTOP_FILE}.in.in.h) | ||
74 | 65 | list(SORT I18N_SRC_FILES) | ||
76 | 66 | 55 | ||
77 | 67 | 56 | ||
78 | 68 | # Add subdirs | 57 | # Add subdirs |
79 | @@ -70,10 +59,21 @@ | |||
80 | 70 | add_subdirectory(runner) | 59 | add_subdirectory(runner) |
81 | 71 | add_subdirectory(ubuntu-printing-app) | 60 | add_subdirectory(ubuntu-printing-app) |
82 | 72 | 61 | ||
83 | 62 | # Setup gettext defs and include po directory | ||
84 | 63 | set(GETTEXT_PACKAGE "ubuntu-printing-app") | ||
85 | 64 | add_definitions(-DI18N_DOMAIN="${GETTEXT_PACKAGE}") | ||
86 | 65 | |||
87 | 66 | add_subdirectory(po) | ||
88 | 67 | |||
89 | 68 | # Add tests | ||
90 | 69 | find_package(Qt5Test REQUIRED) | ||
91 | 70 | enable_testing() | ||
92 | 71 | add_subdirectory(tests) | ||
93 | 72 | |||
94 | 73 | 73 | ||
95 | 74 | # Add run command for QtC | 74 | # Add run command for QtC |
96 | 75 | add_custom_target("run" /usr/bin/qmlscene -I ${CMAKE_BINARY_DIR}/backend ${CMAKE_SOURCE_DIR}/ubuntu-printing-app/Main.qml | 75 | add_custom_target("run" /usr/bin/qmlscene -I ${CMAKE_BINARY_DIR}/backend ${CMAKE_SOURCE_DIR}/ubuntu-printing-app/Main.qml |
98 | 76 | DEPENDS Ubuntu_Printing_App Ubuntu_Printing_App_qmldir | 76 | DEPENDS UbuntuPrintingApp UbuntuPrintingAppqmldir |
99 | 77 | WORKING_DIRECTORY ./ubuntu-printing-app) | 77 | WORKING_DIRECTORY ./ubuntu-printing-app) |
100 | 78 | 78 | ||
101 | 79 | # Show files in QtC | 79 | # Show files in QtC |
102 | 80 | 80 | ||
103 | === modified file 'backend/CMakeLists.txt' | |||
104 | --- backend/CMakeLists.txt 2016-12-13 23:40:36 +0000 | |||
105 | +++ backend/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
106 | @@ -1,43 +1,34 @@ | |||
107 | 1 | include_directories( | 1 | include_directories( |
108 | 2 | ${CMAKE_CURRENT_SOURCE_DIR} | 2 | ${CMAKE_CURRENT_SOURCE_DIR} |
109 | 3 | /usr/include/cups/ | ||
110 | 4 | /usr/include/poppler/qt5/ | 3 | /usr/include/poppler/qt5/ |
111 | 5 | ${Qt5PrintSupport_INCLUDE_DIRS} | ||
112 | 6 | ) | 4 | ) |
113 | 7 | 5 | ||
120 | 8 | #add_definitions( | 6 | set(LIBNAME UbuntuPrintingAppbackend) |
115 | 9 | # -DGETTEXT_PACKAGE=\"${PROJECT_NAME}\" | ||
116 | 10 | # -DGETTEXT_LOCALEDIR=\"${CMAKE_INSTALL_LOCALEDIR}\" | ||
117 | 11 | #) | ||
118 | 12 | |||
119 | 13 | set(LIBNAME Ubuntu_Printing_Appbackend) | ||
121 | 14 | 7 | ||
122 | 15 | set( | 8 | set( |
129 | 16 | Ubuntu_Printing_App_SRC | 9 | UbuntuPrintingAppSRC |
130 | 17 | Ubuntu_Printing_App/backend.cpp | 10 | UbuntuPrintingApp/backend.cpp |
131 | 18 | Ubuntu_Printing_App/document.cpp | 11 | UbuntuPrintingApp/document.cpp |
132 | 19 | Ubuntu_Printing_App/popplerimageprovider.cpp | 12 | UbuntuPrintingApp/popplerimageprovider.cpp |
133 | 20 | Ubuntu_Printing_App/printer.cpp | 13 | UbuntuPrintingApp/pagehelper.cpp |
128 | 21 | Ubuntu_Printing_App/printerinfo.cpp | ||
134 | 22 | ) | 14 | ) |
135 | 23 | 15 | ||
137 | 24 | add_library(${LIBNAME} SHARED ${Ubuntu_Printing_App_SRC}) | 16 | add_library(${LIBNAME} SHARED ${UbuntuPrintingAppSRC}) |
138 | 25 | 17 | ||
140 | 26 | qt5_use_modules(${LIBNAME} Core Gui Qml Quick PrintSupport) | 18 | qt5_use_modules(${LIBNAME} Core Gui Qml Quick) |
141 | 27 | target_link_libraries(${LIBNAME} | 19 | target_link_libraries(${LIBNAME} |
142 | 28 | cups | ||
143 | 29 | poppler-qt5 | 20 | poppler-qt5 |
144 | 30 | ) | 21 | ) |
145 | 31 | 22 | ||
146 | 32 | set_target_properties(${LIBNAME} PROPERTIES | 23 | set_target_properties(${LIBNAME} PROPERTIES |
148 | 33 | LIBRARY_OUTPUT_DIRECTORY Ubuntu_Printing_App | 24 | LIBRARY_OUTPUT_DIRECTORY UbuntuPrintingApp |
149 | 34 | ) | 25 | ) |
150 | 35 | 26 | ||
151 | 36 | # Copy the qmldir file to the build dir | 27 | # Copy the qmldir file to the build dir |
154 | 37 | add_custom_target(Ubuntu_Printing_App_qmldir ALL | 28 | add_custom_target(UbuntuPrintingApp_qmldir ALL |
155 | 38 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Ubuntu_Printing_App/qmldir ${CMAKE_CURRENT_BINARY_DIR}/Ubuntu_Printing_App | 29 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/UbuntuPrintingApp/qmldir ${CMAKE_CURRENT_BINARY_DIR}/UbuntuPrintingApp |
156 | 39 | DEPENDS ${QMLFILES}) | 30 | DEPENDS ${QMLFILES}) |
157 | 40 | 31 | ||
158 | 41 | # Install the plugin file | 32 | # Install the plugin file |
159 | 42 | install(TARGETS ${LIBNAME} DESTINATION ${MODULE_PATH}) | 33 | install(TARGETS ${LIBNAME} DESTINATION ${MODULE_PATH}) |
161 | 43 | install(FILES Ubuntu_Printing_App/qmldir DESTINATION ${MODULE_PATH}) | 34 | install(FILES UbuntuPrintingApp/qmldir DESTINATION ${MODULE_PATH}) |
162 | 44 | 35 | ||
163 | === renamed directory 'backend/Ubuntu_Printing_App' => 'backend/UbuntuPrintingApp' | |||
164 | === modified file 'backend/UbuntuPrintingApp/backend.cpp' | |||
165 | --- backend/Ubuntu_Printing_App/backend.cpp 2016-12-13 12:37:45 +0000 | |||
166 | +++ backend/UbuntuPrintingApp/backend.cpp 2017-02-08 21:32:20 +0000 | |||
167 | @@ -1,30 +1,36 @@ | |||
168 | 1 | /* | ||
169 | 2 | * Copyright 2016 Canonical Ltd. | ||
170 | 3 | * | ||
171 | 4 | * This file is part of ubuntu-printing-app. | ||
172 | 5 | * | ||
173 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
174 | 7 | * it under the terms of the GNU General Public License as published by | ||
175 | 8 | * the Free Software Foundation; version 3. | ||
176 | 9 | * | ||
177 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
178 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
179 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
180 | 13 | * GNU General Public License for more details. | ||
181 | 14 | * | ||
182 | 15 | * You should have received a copy of the GNU General Public License | ||
183 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
184 | 17 | * | ||
185 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
186 | 19 | */ | ||
187 | 1 | #include <QtQml> | 20 | #include <QtQml> |
188 | 2 | #include <QtQml/QQmlContext> | 21 | #include <QtQml/QQmlContext> |
189 | 3 | #include "backend.h" | 22 | #include "backend.h" |
190 | 4 | 23 | ||
191 | 5 | #include "document.h" | 24 | #include "document.h" |
192 | 25 | #include "pagehelper.h" | ||
193 | 6 | #include "popplerimageprovider.h" | 26 | #include "popplerimageprovider.h" |
194 | 7 | #include "printer.h" | ||
195 | 8 | #include "printerinfo.h" | ||
196 | 9 | |||
197 | 10 | |||
198 | 11 | #define MAKE_SINGLETON_FACTORY(type) \ | ||
199 | 12 | static QObject* type##_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine) { \ | ||
200 | 13 | Q_UNUSED(engine); \ | ||
201 | 14 | Q_UNUSED(scriptEngine); \ | ||
202 | 15 | return new type(); \ | ||
203 | 16 | } | ||
204 | 17 | |||
205 | 18 | MAKE_SINGLETON_FACTORY(PrinterInfo) | ||
206 | 19 | |||
207 | 20 | 27 | ||
208 | 21 | void BackendPlugin::registerTypes(const char *uri) | 28 | void BackendPlugin::registerTypes(const char *uri) |
209 | 22 | { | 29 | { |
211 | 23 | Q_ASSERT(uri == QLatin1String("Ubuntu_Printing_App")); | 30 | Q_ASSERT(uri == QLatin1String("UbuntuPrintingApp")); |
212 | 24 | 31 | ||
213 | 25 | qmlRegisterType<Document>(uri, 1, 0, "Document"); | 32 | qmlRegisterType<Document>(uri, 1, 0, "Document"); |
216 | 26 | qmlRegisterType<Printer>(uri, 1, 0, "Printer"); | 33 | qmlRegisterType<PageHelper>(uri, 1, 0, "PageHelper"); |
215 | 27 | qmlRegisterSingletonType<PrinterInfo>(uri, 1, 0, "PrinterInfo", PrinterInfo_singleton_factory); | ||
217 | 28 | } | 34 | } |
218 | 29 | 35 | ||
219 | 30 | void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri) | 36 | void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri) |
220 | 31 | 37 | ||
221 | === modified file 'backend/UbuntuPrintingApp/backend.h' | |||
222 | --- backend/Ubuntu_Printing_App/backend.h 2016-12-13 12:37:45 +0000 | |||
223 | +++ backend/UbuntuPrintingApp/backend.h 2017-02-08 21:32:20 +0000 | |||
224 | @@ -1,3 +1,22 @@ | |||
225 | 1 | /* | ||
226 | 2 | * Copyright 2016 Canonical Ltd. | ||
227 | 3 | * | ||
228 | 4 | * This file is part of ubuntu-printing-app. | ||
229 | 5 | * | ||
230 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
231 | 7 | * it under the terms of the GNU General Public License as published by | ||
232 | 8 | * the Free Software Foundation; version 3. | ||
233 | 9 | * | ||
234 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
235 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
236 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
237 | 13 | * GNU General Public License for more details. | ||
238 | 14 | * | ||
239 | 15 | * You should have received a copy of the GNU General Public License | ||
240 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
241 | 17 | * | ||
242 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
243 | 19 | */ | ||
244 | 1 | #ifndef BACKEND_PLUGIN_H | 20 | #ifndef BACKEND_PLUGIN_H |
245 | 2 | #define BACKEND_PLUGIN_H | 21 | #define BACKEND_PLUGIN_H |
246 | 3 | 22 | ||
247 | @@ -7,7 +26,7 @@ | |||
248 | 7 | /* | 26 | /* |
249 | 8 | ----8<----- | 27 | ----8<----- |
250 | 9 | 28 | ||
252 | 10 | import Ubuntu_Printing_App 1.0 | 29 | import UbuntuPrintingApp 1.0 |
253 | 11 | 30 | ||
254 | 12 | Rectangle { | 31 | Rectangle { |
255 | 13 | width: 200 | 32 | width: 200 |
256 | 14 | 33 | ||
257 | === modified file 'backend/UbuntuPrintingApp/document.cpp' | |||
258 | --- backend/Ubuntu_Printing_App/document.cpp 2016-12-13 12:08:15 +0000 | |||
259 | +++ backend/UbuntuPrintingApp/document.cpp 2017-02-08 21:32:20 +0000 | |||
260 | @@ -1,3 +1,22 @@ | |||
261 | 1 | /* | ||
262 | 2 | * Copyright 2016 Canonical Ltd. | ||
263 | 3 | * | ||
264 | 4 | * This file is part of ubuntu-printing-app. | ||
265 | 5 | * | ||
266 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
267 | 7 | * it under the terms of the GNU General Public License as published by | ||
268 | 8 | * the Free Software Foundation; version 3. | ||
269 | 9 | * | ||
270 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
271 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
272 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
273 | 13 | * GNU General Public License for more details. | ||
274 | 14 | * | ||
275 | 15 | * You should have received a copy of the GNU General Public License | ||
276 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
277 | 17 | * | ||
278 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
279 | 19 | */ | ||
280 | 1 | #include "document.h" | 20 | #include "document.h" |
281 | 2 | 21 | ||
282 | 3 | #include <QtCore/QDebug> | 22 | #include <QtCore/QDebug> |
283 | @@ -18,7 +37,7 @@ | |||
284 | 18 | : QObject(parent), | 37 | : QObject(parent), |
285 | 19 | m_count(0), | 38 | m_count(0), |
286 | 20 | m_document(Q_NULLPTR), | 39 | m_document(Q_NULLPTR), |
288 | 21 | m_url("") | 40 | m_url(QStringLiteral("")) |
289 | 22 | { | 41 | { |
290 | 23 | 42 | ||
291 | 24 | } | 43 | } |
292 | @@ -49,6 +68,21 @@ | |||
293 | 49 | return fmin(destDPI.width(), destDPI.height()); | 68 | return fmin(destDPI.width(), destDPI.height()); |
294 | 50 | } | 69 | } |
295 | 51 | 70 | ||
296 | 71 | QSizeF Document::getPageSize(int pageNumber) | ||
297 | 72 | { | ||
298 | 73 | QSizeF size; | ||
299 | 74 | |||
300 | 75 | if (m_document) { | ||
301 | 76 | Poppler::Page *page = m_document->page(pageNumber); | ||
302 | 77 | |||
303 | 78 | if (page) { | ||
304 | 79 | size = page->pageSizeF(); | ||
305 | 80 | } | ||
306 | 81 | } | ||
307 | 82 | |||
308 | 83 | return size; | ||
309 | 84 | } | ||
310 | 85 | |||
311 | 52 | QImage Document::makeImage(QSizeF size, int pageNumber) | 86 | QImage Document::makeImage(QSizeF size, int pageNumber) |
312 | 53 | { | 87 | { |
313 | 54 | if (pageNumber < 0) { | 88 | if (pageNumber < 0) { |
314 | @@ -61,8 +95,9 @@ | |||
315 | 61 | return QImage(); | 95 | return QImage(); |
316 | 62 | } | 96 | } |
317 | 63 | 97 | ||
320 | 64 | // Splash backend has much better rendering | 98 | if (size == QSize(0, 0)) { |
321 | 65 | m_document->setRenderBackend(Poppler::Document::SplashBackend); | 99 | return QImage(); |
322 | 100 | } | ||
323 | 66 | 101 | ||
324 | 67 | Poppler::Page *page = m_document->page(pageNumber); | 102 | Poppler::Page *page = m_document->page(pageNumber); |
325 | 68 | 103 | ||
326 | @@ -74,17 +109,16 @@ | |||
327 | 74 | // Calculate the DPI to render at | 109 | // Calculate the DPI to render at |
328 | 75 | float res = getDpi(page->pageSizeF(), size); | 110 | float res = getDpi(page->pageSizeF(), size); |
329 | 76 | 111 | ||
330 | 77 | qDebug() << "Making image with res of" << res; | ||
331 | 78 | |||
332 | 79 | // Make the image | 112 | // Make the image |
333 | 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()); |
334 | 81 | 114 | ||
335 | 115 | delete page; | ||
336 | 116 | |||
337 | 82 | if (image.isNull()) { | 117 | if (image.isNull()) { |
338 | 83 | qWarning() << "Image is null"; | 118 | qWarning() << "Image is null"; |
339 | 119 | return QImage(); | ||
340 | 84 | } | 120 | } |
341 | 85 | 121 | ||
342 | 86 | delete page; | ||
343 | 87 | |||
344 | 88 | return image; | 122 | return image; |
345 | 89 | } | 123 | } |
346 | 90 | 124 | ||
347 | @@ -100,13 +134,10 @@ | |||
348 | 100 | return QImage(); | 134 | return QImage(); |
349 | 101 | } | 135 | } |
350 | 102 | 136 | ||
351 | 103 | // Splash backend has much better rendering | ||
352 | 104 | m_document->setRenderBackend(Poppler::Document::SplashBackend); | ||
353 | 105 | |||
354 | 106 | Poppler::Page *page = m_document->page(pageNumber); | 137 | Poppler::Page *page = m_document->page(pageNumber); |
355 | 107 | 138 | ||
356 | 108 | if (!page) { | 139 | if (!page) { |
358 | 109 | qWarning() << "Invalid page"; | 140 | qWarning() << "Invalid page:" << pageNumber; |
359 | 110 | return QImage(); | 141 | return QImage(); |
360 | 111 | } | 142 | } |
361 | 112 | 143 | ||
362 | @@ -120,17 +151,13 @@ | |||
363 | 120 | 151 | ||
364 | 121 | // Make the image | 152 | // Make the image |
365 | 122 | QImage image = makeImage(scaledSize, pageNumber); | 153 | QImage image = makeImage(scaledSize, pageNumber); |
366 | 123 | // image.setDotsPerMeterX(6000); | ||
367 | 124 | // image.setDotsPerMeterY(6000); | ||
368 | 125 | 154 | ||
369 | 126 | if (!color) { | 155 | if (!color) { |
370 | 127 | image = image.convertToFormat(QImage::Format_Grayscale8); | 156 | image = image.convertToFormat(QImage::Format_Grayscale8); |
371 | 128 | } | 157 | } |
372 | 129 | 158 | ||
373 | 130 | qDebug() << "i" << image.width() << scaledSize.width() << image.dotsPerMeterX(); | ||
374 | 131 | |||
375 | 132 | // Make a container then put the content image inside | 159 | // Make a container then put the content image inside |
377 | 133 | QImage container(size.toSize(), QImage::Format_ARGB32_Premultiplied); //QImage::Format_Grayscale8); //QImage::Format_ARGB32); | 160 | QImage container(size.toSize(), QImage::Format_ARGB32_Premultiplied); |
378 | 134 | QPainter painter; | 161 | QPainter painter; |
379 | 135 | 162 | ||
380 | 136 | container.fill(QColor(0, 0, 0, 0)); | 163 | container.fill(QColor(0, 0, 0, 0)); |
381 | @@ -141,6 +168,7 @@ | |||
382 | 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); |
383 | 142 | } else { | 169 | } else { |
384 | 143 | qWarning() << "Image is null"; | 170 | qWarning() << "Image is null"; |
385 | 171 | return QImage(); | ||
386 | 144 | } | 172 | } |
387 | 145 | 173 | ||
388 | 146 | painter.end(); | 174 | painter.end(); |
389 | @@ -148,197 +176,12 @@ | |||
390 | 148 | return container; | 176 | return container; |
391 | 149 | } | 177 | } |
392 | 150 | 178 | ||
393 | 151 | QPixmap Document::makePixmap(QSize size, int pageNumber) | ||
394 | 152 | { | ||
395 | 153 | if (pageNumber < 0) { | ||
396 | 154 | qWarning() << "Invalid page number"; | ||
397 | 155 | } | ||
398 | 156 | |||
399 | 157 | if (!m_document) { | ||
400 | 158 | qWarning() << "No document loaded"; | ||
401 | 159 | } | ||
402 | 160 | |||
403 | 161 | // Splash backend has much better rendering | ||
404 | 162 | m_document->setRenderBackend(Poppler::Document::SplashBackend); | ||
405 | 163 | |||
406 | 164 | Poppler::Page *page = m_document->page(pageNumber); | ||
407 | 165 | |||
408 | 166 | if (!page) { | ||
409 | 167 | qWarning() << "Invalid page"; | ||
410 | 168 | } | ||
411 | 169 | |||
412 | 170 | float res = getDpi(page->pageSizeF(), size); | ||
413 | 171 | |||
414 | 172 | qDebug() << "Making image with res of" << res; | ||
415 | 173 | |||
416 | 174 | // Make QPixmap | ||
417 | 175 | QPixmap pixmap(size); | ||
418 | 176 | |||
419 | 177 | // If using ArthurBackend can do | ||
420 | 178 | // QPainter painter(&pixmap); | ||
421 | 179 | // if (!page->renderToPainter(painter, res, res)) { | ||
422 | 180 | // qWarning() << "Failed to render to painter"; | ||
423 | 181 | // } | ||
424 | 182 | |||
425 | 183 | QImage image = page->renderToImage(res, res); | ||
426 | 184 | |||
427 | 185 | if (image.isNull()) { | ||
428 | 186 | qWarning() << "Image is null"; | ||
429 | 187 | } | ||
430 | 188 | |||
431 | 189 | pixmap = QPixmap::fromImage(image); | ||
432 | 190 | |||
433 | 191 | delete page; | ||
434 | 192 | |||
435 | 193 | return pixmap; | ||
436 | 194 | } | ||
437 | 195 | |||
438 | 196 | QImage Document::renderImage(QSize size, int pageNumber) | ||
439 | 197 | { | ||
440 | 198 | if (pageNumber < 0) { | ||
441 | 199 | qWarning() << "Invalid page number"; | ||
442 | 200 | } | ||
443 | 201 | |||
444 | 202 | if (!m_document) { | ||
445 | 203 | qWarning() << "No document loaded"; | ||
446 | 204 | } | ||
447 | 205 | |||
448 | 206 | // m_document->setRenderBackend(Poppler::Document::SplashBackend); | ||
449 | 207 | |||
450 | 208 | Poppler::Page *page = m_document->page(pageNumber); | ||
451 | 209 | |||
452 | 210 | if (!page) { | ||
453 | 211 | qWarning() << "Invalid page"; | ||
454 | 212 | } | ||
455 | 213 | |||
456 | 214 | /* | ||
457 | 215 | * width / res width / res | ||
458 | 216 | */ | ||
459 | 217 | |||
460 | 218 | // int res = size.width() / (page->pageSize().width() / 72); | ||
461 | 219 | |||
462 | 220 | // qDebug() << "Res:" << res; | ||
463 | 221 | |||
464 | 222 | |||
465 | 223 | |||
466 | 224 | QSizeF sourceSizeInch(page->pageSizeF().width() / 72, page->pageSizeF().height() / 72); | ||
467 | 225 | |||
468 | 226 | QSizeF destDPI(size.width() / sourceSizeInch.width(), size.height()/ sourceSizeInch.height()); | ||
469 | 227 | |||
470 | 228 | float res; | ||
471 | 229 | |||
472 | 230 | if (destDPI.width() > destDPI.height()) { | ||
473 | 231 | res = destDPI.height(); | ||
474 | 232 | } else { | ||
475 | 233 | res = destDPI.width(); | ||
476 | 234 | } | ||
477 | 235 | |||
478 | 236 | qDebug() << "Making image with res of" << res; | ||
479 | 237 | |||
480 | 238 | QImage image = page->renderToImage(res, res); | ||
481 | 239 | |||
482 | 240 | if (image.isNull()) { | ||
483 | 241 | qWarning() << "Image is null"; | ||
484 | 242 | } | ||
485 | 243 | |||
486 | 244 | delete page; | ||
487 | 245 | |||
488 | 246 | return image; | ||
489 | 247 | } | ||
490 | 248 | |||
491 | 249 | bool Document::renderPage(QPainter *painter, int pageNumber) | ||
492 | 250 | { | ||
493 | 251 | if (!painter) { | ||
494 | 252 | qWarning() << "Invalid painter"; | ||
495 | 253 | return false; | ||
496 | 254 | } | ||
497 | 255 | |||
498 | 256 | if (pageNumber < 0) { | ||
499 | 257 | qWarning() << "Invalid page number"; | ||
500 | 258 | return false; | ||
501 | 259 | } | ||
502 | 260 | |||
503 | 261 | if (!m_document) { | ||
504 | 262 | qWarning() << "No document loaded"; | ||
505 | 263 | return false; | ||
506 | 264 | } | ||
507 | 265 | |||
508 | 266 | Poppler::Page *page = m_document->page(pageNumber); | ||
509 | 267 | |||
510 | 268 | m_document->setRenderBackend(Poppler::Document::ArthurBackend); | ||
511 | 269 | |||
512 | 270 | if (!page) { | ||
513 | 271 | qWarning() << "Invalid page"; | ||
514 | 272 | return false; | ||
515 | 273 | } | ||
516 | 274 | |||
517 | 275 | /* | ||
518 | 276 | A4 | ||
519 | 277 | DPI: 96 1200 | ||
520 | 278 | Device Size: 767 1097 | ||
521 | 279 | Doc Size: 595 842 | ||
522 | 280 | |||
523 | 281 | A5 | ||
524 | 282 | DPI: 96 1200 | ||
525 | 283 | Device Size: 534 767 | ||
526 | 284 | Doc Size: 595 842 | ||
527 | 285 | */ | ||
528 | 286 | |||
529 | 287 | QSizeF sourceSizeInch(page->pageSizeF().width() / 72, page->pageSizeF().height() / 72); | ||
530 | 288 | |||
531 | 289 | QSizeF destDPI(painter->device()->width() / sourceSizeInch.width(), painter->device()->height()/ sourceSizeInch.height()); | ||
532 | 290 | |||
533 | 291 | float res; | ||
534 | 292 | |||
535 | 293 | if (destDPI.width() > destDPI.height()) { | ||
536 | 294 | res = destDPI.height(); | ||
537 | 295 | } else { | ||
538 | 296 | res = destDPI.width(); | ||
539 | 297 | } | ||
540 | 298 | |||
541 | 299 | // Poppler::PSConverter *psConv = m_document->psConverter(); | ||
542 | 300 | |||
543 | 301 | // psConv->setLeftMargin(5); | ||
544 | 302 | // psConv->setRightMargin(1); | ||
545 | 303 | // psConv->setOutputFileName("/tmp/out.ps"); | ||
546 | 304 | // psConv->setPaperHeight(painter->device()->height()); | ||
547 | 305 | // psConv->setPaperWidth(painter->device()->width()); | ||
548 | 306 | |||
549 | 307 | // QList<int> pages = { 1 }; | ||
550 | 308 | |||
551 | 309 | // psConv->setPageList(pages); | ||
552 | 310 | |||
553 | 311 | // qDebug() << "PS" << psConv->convert(); | ||
554 | 312 | |||
555 | 313 | |||
556 | 314 | // float res = painter->device()->width() / (page->pageSize().width() / 72); //painter->device()->logicalDpiX()); | ||
557 | 315 | |||
558 | 316 | //res = 70; | ||
559 | 317 | |||
560 | 318 | qDebug() << "DPI:" << painter->device()->logicalDpiX() << painter->device()->physicalDpiX() << res; | ||
561 | 319 | |||
562 | 320 | qDebug() << "Device Size:" << painter->device()->width() << painter->device()->height(); | ||
563 | 321 | qDebug() << "Doc Size:" << page->pageSize().width() << page->pageSize().height(); | ||
564 | 322 | |||
565 | 323 | // Create Image same dimensions as PageSize | ||
566 | 324 | // Render to the image | ||
567 | 325 | // Render the image to the printer | ||
568 | 326 | // Image can also be used for preview? | ||
569 | 327 | |||
570 | 328 | if (!page->renderToPainter(painter, res, res)) { | ||
571 | 329 | // if (!page->renderToPainter(painter, painter->device()->logicalDpiX(), painter->device()->logicalDpiY(), | ||
572 | 330 | // 0, 0, page->pageSize().width(), page->pageSize().height())) { | ||
573 | 331 | qWarning() << "Rendering failed"; | ||
574 | 332 | return false; | ||
575 | 333 | } | ||
576 | 334 | |||
577 | 335 | delete page; | ||
578 | 336 | |||
579 | 337 | return true; | ||
580 | 338 | } | ||
581 | 339 | |||
582 | 340 | Document::Orientation Document::orientation() const | 179 | Document::Orientation Document::orientation() const |
583 | 341 | { | 180 | { |
584 | 181 | if (!m_document) { | ||
585 | 182 | return Portrait; | ||
586 | 183 | } | ||
587 | 184 | |||
588 | 342 | Poppler::Page *page = m_document->page(0); | 185 | Poppler::Page *page = m_document->page(0); |
589 | 343 | 186 | ||
590 | 344 | if (page) { | 187 | if (page) { |
591 | @@ -350,102 +193,64 @@ | |||
592 | 350 | return Portrait; | 193 | return Portrait; |
593 | 351 | } | 194 | } |
594 | 352 | 195 | ||
605 | 353 | qDebug() << "DOC" << page->orientation() << Portrait << Landscape; | 196 | // TODO: page orientation seems to be wrong? |
606 | 354 | 197 | // qDebug() << "DOC" << page->orientation() << Portrait << Landscape; | |
607 | 355 | if (page->orientation() == Poppler::Page::Landscape) { | 198 | // if (page->orientation() == Poppler::Page::Landscape) { |
608 | 356 | return Landscape; | 199 | // return Landscape; |
609 | 357 | } else if (page->orientation() == Poppler::Page::Portrait) { | 200 | // } else if (page->orientation() == Poppler::Page::Portrait) { |
610 | 358 | return Portrait; | 201 | // return Portrait; |
611 | 359 | } else { | 202 | // } else { |
612 | 360 | qWarning() << "Other orientation:" << page->orientation() << "using Portrait"; | 203 | // qWarning() << "Other orientation:" << page->orientation() << "using Portrait"; |
613 | 361 | return Portrait; | 204 | // return Portrait; |
614 | 362 | } | 205 | // } |
615 | 363 | } else { | 206 | } else { |
616 | 364 | return Portrait; | 207 | return Portrait; |
617 | 365 | } | 208 | } |
618 | 366 | } | 209 | } |
619 | 367 | 210 | ||
620 | 368 | bool Document::printFromImage(QPainter *painter, int pageNumber, QRect pageRect, double resolution) | ||
621 | 369 | { | ||
622 | 370 | // Ensure we are using the right render hints | ||
623 | 371 | m_document->setRenderBackend(Poppler::Document::SplashBackend); | ||
624 | 372 | |||
625 | 373 | m_document->setRenderHint(Poppler::Document::Antialiasing, true); | ||
626 | 374 | m_document->setRenderHint(Poppler::Document::TextAntialiasing, true); | ||
627 | 375 | m_document->setRenderHint(Poppler::Document::TextHinting, true); | ||
628 | 376 | |||
629 | 377 | Poppler::Page *page = m_document->page(pageNumber); | ||
630 | 378 | |||
631 | 379 | if (!page) { | ||
632 | 380 | qWarning() << "Invalid page!"; | ||
633 | 381 | return false; | ||
634 | 382 | } | ||
635 | 383 | |||
636 | 384 | // Render at given resolution | ||
637 | 385 | QImage image = page->renderToImage(resolution, resolution); | ||
638 | 386 | |||
639 | 387 | // Get the scalar for the image to fit within the pageRect | ||
640 | 388 | double ratioX = (double) image.width() / (double) pageRect.width(); | ||
641 | 389 | double ratioY = (double) image.height() / (double) pageRect.height(); | ||
642 | 390 | |||
643 | 391 | image.setDevicePixelRatio(fmax(ratioX, ratioY)); | ||
644 | 392 | |||
645 | 393 | // Check that image isn't null | ||
646 | 394 | if (image.isNull()) { | ||
647 | 395 | return false; | ||
648 | 396 | } | ||
649 | 397 | |||
650 | 398 | // Draw the image to the painter, should we scale? the image should be correct aspect | ||
651 | 399 | // Here we should check if the image aspect is different and position in the centre? | ||
652 | 400 | painter->drawImage(0, 0, image); | ||
653 | 401 | //painter->drawImage(QRect(QPoint(0, 0), QSize(pageRect.width(), pageRect.height())), image, image.rect()); | ||
654 | 402 | |||
655 | 403 | qDebug() << "Device Width:" << pageRect.width() << "LogicalDPI:" << painter->device()->logicalDpiX(); // << "RenderDPI:" << renderDPI.width(); | ||
656 | 404 | qDebug() << "RatioX" << ratioX << "RatioY" << ratioY; | ||
657 | 405 | |||
658 | 406 | qDebug() << "PageRect:" << pageRect.width() << pageRect.height(); | ||
659 | 407 | qDebug() << "Image:" << image.width() << image.height() << image.dotsPerMeterX(); | ||
660 | 408 | |||
661 | 409 | return true; | ||
662 | 410 | } | ||
663 | 411 | |||
664 | 412 | void Document::setUrl(QUrl url) | 211 | void Document::setUrl(QUrl url) |
665 | 413 | { | 212 | { |
666 | 414 | if (m_url != url) { | 213 | if (m_url != url) { |
667 | 415 | if (url.isLocalFile() && QFileInfo::exists(url.toLocalFile())) { | 214 | if (url.isLocalFile() && QFileInfo::exists(url.toLocalFile())) { |
668 | 416 | if (QMimeDatabase().mimeTypeForUrl(url).name() == "application/pdf") { | 215 | if (QMimeDatabase().mimeTypeForUrl(url).name() == "application/pdf") { |
682 | 417 | m_url = url; | 216 | // Attempt to Load document |
683 | 418 | 217 | m_document = Poppler::Document::load(url.toLocalFile()); | |
671 | 419 | // Load document | ||
672 | 420 | m_document = Poppler::Document::load(m_url.toLocalFile()); | ||
673 | 421 | m_document->setRenderBackend(Poppler::Document::ArthurBackend); | ||
674 | 422 | |||
675 | 423 | m_document->setRenderHint(Poppler::Document::Antialiasing, true); | ||
676 | 424 | m_document->setRenderHint(Poppler::Document::TextAntialiasing, true); | ||
677 | 425 | m_document->setRenderHint(Poppler::Document::TextHinting, true); | ||
678 | 426 | // m_document->setRenderHint(Poppler::Document::TextSlightHinting, true); | ||
679 | 427 | // m_document->setRenderHint(Poppler::Document::OverprintPreview, true); | ||
680 | 428 | // m_document->setRenderHint(Poppler::Document::ThinLineSolid, true); | ||
681 | 429 | // m_document->setRenderHint(Poppler::Document::ThinLineShape, true); | ||
684 | 430 | 218 | ||
685 | 431 | if (!m_document || m_document->isLocked()) { | 219 | if (!m_document || m_document->isLocked()) { |
686 | 432 | qWarning() << "Invalid Document"; | 220 | qWarning() << "Invalid Document"; |
687 | 433 | delete m_document; | 221 | delete m_document; |
688 | 434 | m_document = Q_NULLPTR; | 222 | m_document = Q_NULLPTR; |
689 | 223 | |||
690 | 224 | Q_EMIT error(Errors::ErrorDocumentInvalid); | ||
691 | 435 | } else { | 225 | } else { |
692 | 226 | m_url = url; | ||
693 | 227 | |||
694 | 228 | m_document->setRenderBackend(Poppler::Document::SplashBackend); | ||
695 | 229 | |||
696 | 230 | m_document->setRenderHint(Poppler::Document::Antialiasing, true); | ||
697 | 231 | m_document->setRenderHint(Poppler::Document::TextAntialiasing, true); | ||
698 | 232 | m_document->setRenderHint(Poppler::Document::TextHinting, true); | ||
699 | 233 | m_document->setRenderHint(Poppler::Document::TextSlightHinting, true); | ||
700 | 234 | |||
701 | 235 | Q_EMIT urlChanged(); | ||
702 | 236 | |||
703 | 436 | if (m_count != m_document->numPages()) { | 237 | if (m_count != m_document->numPages()) { |
704 | 437 | m_count = m_document->numPages(); | 238 | m_count = m_document->numPages(); |
705 | 438 | 239 | ||
706 | 439 | Q_EMIT countChanged(); | 240 | Q_EMIT countChanged(); |
707 | 440 | } | 241 | } |
708 | 242 | |||
709 | 243 | Q_EMIT orientationChanged(); | ||
710 | 244 | Q_EMIT titleChanged(); | ||
711 | 441 | } | 245 | } |
712 | 442 | |||
713 | 443 | Q_EMIT urlChanged(); | ||
714 | 444 | } else { | 246 | } else { |
715 | 445 | qWarning() << "File is not a PDF:" << url; | 247 | qWarning() << "File is not a PDF:" << url; |
716 | 248 | Q_EMIT error(Errors::ErrorNotPdf); | ||
717 | 446 | } | 249 | } |
718 | 447 | } else { | 250 | } else { |
719 | 448 | qWarning() << "Url is not a local file:" << url; | 251 | qWarning() << "Url is not a local file:" << url; |
720 | 252 | |||
721 | 253 | Q_EMIT error(Errors::ErrorNotFound); | ||
722 | 449 | } | 254 | } |
723 | 450 | } | 255 | } |
724 | 451 | } | 256 | } |
725 | @@ -455,7 +260,7 @@ | |||
726 | 455 | if (m_document) { | 260 | if (m_document) { |
727 | 456 | return m_document->info("Title"); | 261 | return m_document->info("Title"); |
728 | 457 | } else { | 262 | } else { |
730 | 458 | return ""; | 263 | return QStringLiteral(""); |
731 | 459 | } | 264 | } |
732 | 460 | } | 265 | } |
733 | 461 | 266 | ||
734 | 462 | 267 | ||
735 | === modified file 'backend/UbuntuPrintingApp/document.h' | |||
736 | --- backend/Ubuntu_Printing_App/document.h 2016-12-13 12:08:15 +0000 | |||
737 | +++ backend/UbuntuPrintingApp/document.h 2017-02-08 21:32:20 +0000 | |||
738 | @@ -1,7 +1,27 @@ | |||
739 | 1 | /* | ||
740 | 2 | * Copyright 2016 Canonical Ltd. | ||
741 | 3 | * | ||
742 | 4 | * This file is part of ubuntu-printing-app. | ||
743 | 5 | * | ||
744 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
745 | 7 | * it under the terms of the GNU General Public License as published by | ||
746 | 8 | * the Free Software Foundation; version 3. | ||
747 | 9 | * | ||
748 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
749 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
750 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
751 | 13 | * GNU General Public License for more details. | ||
752 | 14 | * | ||
753 | 15 | * You should have received a copy of the GNU General Public License | ||
754 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
755 | 17 | * | ||
756 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
757 | 19 | */ | ||
758 | 1 | #ifndef DOCUMENT_H | 20 | #ifndef DOCUMENT_H |
759 | 2 | #define DOCUMENT_H | 21 | #define DOCUMENT_H |
760 | 3 | 22 | ||
761 | 4 | #include <QtCore/QObject> | 23 | #include <QtCore/QObject> |
762 | 24 | #include <QtCore/QSizeF> | ||
763 | 5 | #include <QtCore/QUrl> | 25 | #include <QtCore/QUrl> |
764 | 6 | 26 | ||
765 | 7 | #include <QtGui/QPainter> | 27 | #include <QtGui/QPainter> |
766 | @@ -13,30 +33,39 @@ | |||
767 | 13 | Q_OBJECT | 33 | Q_OBJECT |
768 | 14 | 34 | ||
769 | 15 | Q_PROPERTY(int count READ count NOTIFY countChanged) | 35 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
770 | 36 | Q_PROPERTY(Orientation orientation READ orientation NOTIFY orientationChanged) | ||
771 | 37 | Q_PROPERTY(QString title READ title NOTIFY titleChanged) | ||
772 | 16 | Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) | 38 | Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) |
773 | 17 | public: | 39 | public: |
774 | 40 | enum class Errors { | ||
775 | 41 | ErrorDocumentInvalid, | ||
776 | 42 | ErrorNotFound, | ||
777 | 43 | ErrorNotPdf, | ||
778 | 44 | }; | ||
779 | 45 | |||
780 | 46 | Q_ENUM(Errors) | ||
781 | 47 | |||
782 | 18 | enum Orientation { | 48 | enum Orientation { |
783 | 19 | Portrait, | 49 | Portrait, |
784 | 20 | Landscape, | 50 | Landscape, |
785 | 21 | }; | 51 | }; |
786 | 52 | Q_ENUM(Orientation) | ||
787 | 22 | 53 | ||
788 | 23 | explicit Document(QObject *parent = 0); | 54 | explicit Document(QObject *parent = 0); |
789 | 24 | ~Document(); | 55 | ~Document(); |
790 | 25 | int count() const; | 56 | int count() const; |
791 | 57 | QSizeF getPageSize(int pageNumber); | ||
792 | 26 | Orientation orientation() const; | 58 | Orientation orientation() const; |
793 | 27 | QString title() const; | 59 | QString title() const; |
794 | 28 | QUrl url() const; | 60 | QUrl url() const; |
795 | 29 | 61 | ||
796 | 30 | QImage makeImage(QSizeF size, int pageNumber); | 62 | QImage makeImage(QSizeF size, int pageNumber); |
797 | 31 | QImage makeImageToFit(QSizeF size, int pageNumber, bool color); | 63 | QImage makeImageToFit(QSizeF size, int pageNumber, bool color); |
798 | 32 | QPixmap makePixmap(QSize size, int pageNumber); | ||
799 | 33 | |||
800 | 34 | Q_INVOKABLE QImage renderImage(QSize size, int pageNumber); | ||
801 | 35 | Q_INVOKABLE bool renderPage(QPainter *painter, int pageNumber); | ||
802 | 36 | |||
803 | 37 | bool printFromImage(QPainter *painter, int pageNumber, QRect pageRect, double resolution); | ||
804 | 38 | signals: | 64 | signals: |
805 | 39 | void countChanged(); | 65 | void countChanged(); |
806 | 66 | void error(Document::Errors errorType); | ||
807 | 67 | void orientationChanged(); | ||
808 | 68 | void titleChanged(); | ||
809 | 40 | void urlChanged(); | 69 | void urlChanged(); |
810 | 41 | public slots: | 70 | public slots: |
811 | 42 | void setUrl(QUrl url); | 71 | void setUrl(QUrl url); |
812 | 43 | 72 | ||
813 | === added file 'backend/UbuntuPrintingApp/pagehelper.cpp' | |||
814 | --- backend/UbuntuPrintingApp/pagehelper.cpp 1970-01-01 00:00:00 +0000 | |||
815 | +++ backend/UbuntuPrintingApp/pagehelper.cpp 2017-02-08 21:32:20 +0000 | |||
816 | @@ -0,0 +1,104 @@ | |||
817 | 1 | /* | ||
818 | 2 | * Copyright 2016 Canonical Ltd. | ||
819 | 3 | * | ||
820 | 4 | * This file is part of ubuntu-printing-app. | ||
821 | 5 | * | ||
822 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
823 | 7 | * it under the terms of the GNU General Public License as published by | ||
824 | 8 | * the Free Software Foundation; version 3. | ||
825 | 9 | * | ||
826 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
827 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
828 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
829 | 13 | * GNU General Public License for more details. | ||
830 | 14 | * | ||
831 | 15 | * You should have received a copy of the GNU General Public License | ||
832 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
833 | 17 | * | ||
834 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
835 | 19 | */ | ||
836 | 20 | #include <QtCore/QSizeF> | ||
837 | 21 | |||
838 | 22 | #include <poppler/qt5/poppler-qt5.h> | ||
839 | 23 | |||
840 | 24 | #include "pagehelper.h" | ||
841 | 25 | |||
842 | 26 | #define A4_ASPECT_RATIO 595.0 / 842.0 | ||
843 | 27 | |||
844 | 28 | PageHelper::PageHelper(QObject *parent) | ||
845 | 29 | : QObject(parent) | ||
846 | 30 | , m_aspect(A4_ASPECT_RATIO) | ||
847 | 31 | , m_document(Q_NULLPTR) | ||
848 | 32 | , m_page(0) | ||
849 | 33 | { | ||
850 | 34 | |||
851 | 35 | } | ||
852 | 36 | |||
853 | 37 | double PageHelper::aspect() const | ||
854 | 38 | { | ||
855 | 39 | return m_aspect; | ||
856 | 40 | } | ||
857 | 41 | |||
858 | 42 | Document *PageHelper::document() const | ||
859 | 43 | { | ||
860 | 44 | return m_document; | ||
861 | 45 | } | ||
862 | 46 | |||
863 | 47 | void PageHelper::loadAspect() | ||
864 | 48 | { | ||
865 | 49 | if (!m_document) { | ||
866 | 50 | setAspect(A4_ASPECT_RATIO); | ||
867 | 51 | } | ||
868 | 52 | |||
869 | 53 | QSizeF pageSize = m_document->getPageSize(m_page); | ||
870 | 54 | |||
871 | 55 | if (pageSize.isValid()) { | ||
872 | 56 | setAspect(pageSize.width() / pageSize.height()); | ||
873 | 57 | } else { | ||
874 | 58 | setAspect(A4_ASPECT_RATIO); | ||
875 | 59 | } | ||
876 | 60 | } | ||
877 | 61 | |||
878 | 62 | int PageHelper::page() const | ||
879 | 63 | { | ||
880 | 64 | return m_page; | ||
881 | 65 | } | ||
882 | 66 | |||
883 | 67 | void PageHelper::setAspect(double aspect) | ||
884 | 68 | { | ||
885 | 69 | if (m_aspect != aspect) { | ||
886 | 70 | m_aspect = aspect; | ||
887 | 71 | |||
888 | 72 | Q_EMIT aspectChanged(); | ||
889 | 73 | } | ||
890 | 74 | } | ||
891 | 75 | |||
892 | 76 | void PageHelper::setDocument(Document *document) | ||
893 | 77 | { | ||
894 | 78 | if (m_document != document) { | ||
895 | 79 | if (m_document) { // disconnect old signals | ||
896 | 80 | m_document->disconnect(); | ||
897 | 81 | } | ||
898 | 82 | |||
899 | 83 | m_document = document; | ||
900 | 84 | |||
901 | 85 | // If the document URL changes reload the aspect | ||
902 | 86 | PageHelper::connect(m_document, SIGNAL(urlChanged()), this, SLOT(loadAspect())); | ||
903 | 87 | |||
904 | 88 | Q_EMIT documentChanged(); | ||
905 | 89 | |||
906 | 90 | loadAspect(); | ||
907 | 91 | } | ||
908 | 92 | } | ||
909 | 93 | |||
910 | 94 | void PageHelper::setPage(int page) | ||
911 | 95 | { | ||
912 | 96 | if (m_page != page) { | ||
913 | 97 | m_page = page; | ||
914 | 98 | |||
915 | 99 | Q_EMIT pageChanged(); | ||
916 | 100 | |||
917 | 101 | loadAspect(); | ||
918 | 102 | } | ||
919 | 103 | } | ||
920 | 104 | |||
921 | 0 | 105 | ||
922 | === added file 'backend/UbuntuPrintingApp/pagehelper.h' | |||
923 | --- backend/UbuntuPrintingApp/pagehelper.h 1970-01-01 00:00:00 +0000 | |||
924 | +++ backend/UbuntuPrintingApp/pagehelper.h 2017-02-08 21:32:20 +0000 | |||
925 | @@ -0,0 +1,55 @@ | |||
926 | 1 | /* | ||
927 | 2 | * Copyright 2016 Canonical Ltd. | ||
928 | 3 | * | ||
929 | 4 | * This file is part of ubuntu-printing-app. | ||
930 | 5 | * | ||
931 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
932 | 7 | * it under the terms of the GNU General Public License as published by | ||
933 | 8 | * the Free Software Foundation; version 3. | ||
934 | 9 | * | ||
935 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
936 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
937 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
938 | 13 | * GNU General Public License for more details. | ||
939 | 14 | * | ||
940 | 15 | * You should have received a copy of the GNU General Public License | ||
941 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
942 | 17 | * | ||
943 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
944 | 19 | */ | ||
945 | 20 | #ifndef PAGEHELPER_H | ||
946 | 21 | #define PAGEHELPER_H | ||
947 | 22 | |||
948 | 23 | #include <QtCore/QObject> | ||
949 | 24 | |||
950 | 25 | #include "document.h" | ||
951 | 26 | |||
952 | 27 | class PageHelper : public QObject | ||
953 | 28 | { | ||
954 | 29 | Q_OBJECT | ||
955 | 30 | |||
956 | 31 | Q_PROPERTY(double aspect READ aspect NOTIFY aspectChanged) | ||
957 | 32 | Q_PROPERTY(Document *document READ document WRITE setDocument NOTIFY documentChanged) | ||
958 | 33 | Q_PROPERTY(int page READ page WRITE setPage NOTIFY pageChanged) | ||
959 | 34 | public: | ||
960 | 35 | explicit PageHelper(QObject *parent = 0); | ||
961 | 36 | double aspect() const; | ||
962 | 37 | Document *document() const; | ||
963 | 38 | int page() const; | ||
964 | 39 | signals: | ||
965 | 40 | void aspectChanged(); | ||
966 | 41 | void documentChanged(); | ||
967 | 42 | void pageChanged(); | ||
968 | 43 | public slots: | ||
969 | 44 | void setDocument(Document *document); | ||
970 | 45 | void setPage(int page); | ||
971 | 46 | private slots: | ||
972 | 47 | void setAspect(double aspect); | ||
973 | 48 | void loadAspect(); | ||
974 | 49 | private: | ||
975 | 50 | double m_aspect; | ||
976 | 51 | Document *m_document; | ||
977 | 52 | int m_page; | ||
978 | 53 | }; | ||
979 | 54 | |||
980 | 55 | #endif // PAGEGELPER_H | ||
981 | 0 | 56 | ||
982 | === modified file 'backend/UbuntuPrintingApp/popplerimageprovider.cpp' | |||
983 | --- backend/Ubuntu_Printing_App/popplerimageprovider.cpp 2016-12-12 17:09:39 +0000 | |||
984 | +++ backend/UbuntuPrintingApp/popplerimageprovider.cpp 2017-02-08 21:32:20 +0000 | |||
985 | @@ -1,9 +1,27 @@ | |||
986 | 1 | /* | ||
987 | 2 | * Copyright 2016 Canonical Ltd. | ||
988 | 3 | * | ||
989 | 4 | * This file is part of ubuntu-printing-app. | ||
990 | 5 | * | ||
991 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
992 | 7 | * it under the terms of the GNU General Public License as published by | ||
993 | 8 | * the Free Software Foundation; version 3. | ||
994 | 9 | * | ||
995 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
996 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
997 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
998 | 13 | * GNU General Public License for more details. | ||
999 | 14 | * | ||
1000 | 15 | * You should have received a copy of the GNU General Public License | ||
1001 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1002 | 17 | * | ||
1003 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
1004 | 19 | */ | ||
1005 | 1 | #include "popplerimageprovider.h" | 20 | #include "popplerimageprovider.h" |
1006 | 2 | 21 | ||
1007 | 3 | #include <QDebug> | 22 | #include <QDebug> |
1008 | 4 | 23 | ||
1009 | 5 | #include "document.h" | 24 | #include "document.h" |
1010 | 6 | #include "printer.h" | ||
1011 | 7 | 25 | ||
1012 | 8 | PopplerImageProvider::PopplerImageProvider() | 26 | PopplerImageProvider::PopplerImageProvider() |
1013 | 9 | : QQuickImageProvider(QQuickImageProvider::Image, QQuickImageProvider::ForceAsynchronousImageLoading) | 27 | : QQuickImageProvider(QQuickImageProvider::Image, QQuickImageProvider::ForceAsynchronousImageLoading) |
1014 | @@ -14,35 +32,57 @@ | |||
1015 | 14 | 32 | ||
1016 | 15 | QImage PopplerImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) | 33 | QImage PopplerImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) |
1017 | 16 | { | 34 | { |
1021 | 17 | qDebug() << "ID" << id << requestedSize.height() << requestedSize.width(); | 35 | // Load id ( image://poppler/{pageNumber}/{color}/{filePath} ) |
1019 | 18 | |||
1020 | 19 | // Load id ( image://poppler/{pageNumber}/{colorMode}/{filePath} ) | ||
1022 | 20 | QStringList parts = id.split("/"); | 36 | QStringList parts = id.split("/"); |
1023 | 21 | 37 | ||
1024 | 22 | bool colorOk, numberOk; | 38 | bool colorOk, numberOk; |
1025 | 23 | int pageNumber = parts.takeFirst().toInt(&numberOk, 10); | 39 | int pageNumber = parts.takeFirst().toInt(&numberOk, 10); |
1029 | 24 | int colorModeInt = parts.takeFirst().toInt(&colorOk, 10); | 40 | QString colorMode = QString::fromStdString(parts.takeFirst().toStdString()); |
1030 | 25 | 41 | ||
1031 | 26 | Printer::ColorMode colorMode = static_cast<Printer::ColorMode>(colorModeInt); | 42 | bool color; |
1032 | 43 | |||
1033 | 44 | if (colorMode == "true") { | ||
1034 | 45 | color = true; | ||
1035 | 46 | colorOk = true; | ||
1036 | 47 | } else if (colorMode == "false") { | ||
1037 | 48 | color = false; | ||
1038 | 49 | colorOk = true; | ||
1039 | 50 | } else { | ||
1040 | 51 | colorOk = false; | ||
1041 | 52 | } | ||
1042 | 27 | 53 | ||
1043 | 28 | QString url = parts.join("/"); | 54 | QString url = parts.join("/"); |
1044 | 29 | 55 | ||
1045 | 56 | // Check request size is valid | ||
1046 | 57 | if (requestedSize.height() <= 0 || requestedSize.width() <= 0) { | ||
1047 | 58 | qWarning() << "Invalid requestedSize given" << requestedSize; | ||
1048 | 59 | |||
1049 | 60 | // Requested size is invalid, return a 1x1 image to prevent QML errors | ||
1050 | 61 | // when resizing the window really small | ||
1051 | 62 | if (size) { | ||
1052 | 63 | *size = QSize(1, 1); | ||
1053 | 64 | } | ||
1054 | 65 | |||
1055 | 66 | return QImage(QSize(1, 1), QImage::Format_ARGB32_Premultiplied); | ||
1056 | 67 | } else if (size) { | ||
1057 | 68 | // Set the size of the 'orignal' image to the requestedSize | ||
1058 | 69 | // as we generate an image dynamically | ||
1059 | 70 | *size = requestedSize; | ||
1060 | 71 | } | ||
1061 | 72 | |||
1062 | 73 | // Check all parts given were OK | ||
1063 | 30 | if (url.isEmpty() || !numberOk || !colorOk) { | 74 | if (url.isEmpty() || !numberOk || !colorOk) { |
1064 | 75 | qWarning() << "Invalid id given to poppler image provider:" << id; | ||
1065 | 31 | return QImage(); | 76 | return QImage(); |
1066 | 32 | } | 77 | } |
1067 | 33 | 78 | ||
1078 | 34 | // Fallback size if none is given for QImage | 79 | // Build a Document and generate an image to fit the given requestedSize |
1069 | 35 | int width = 100; | ||
1070 | 36 | int height = 50; | ||
1071 | 37 | |||
1072 | 38 | if (size) | ||
1073 | 39 | *size = QSize(width, height); | ||
1074 | 40 | |||
1075 | 41 | qDebug() << "Url:" << url; | ||
1076 | 42 | qDebug() << "Page:" << pageNumber; | ||
1077 | 43 | |||
1079 | 44 | Document *doc = new Document(); | 80 | Document *doc = new Document(); |
1080 | 45 | doc->setUrl(url); | 81 | doc->setUrl(url); |
1081 | 46 | 82 | ||
1083 | 47 | return doc->makeImageToFit(requestedSize, pageNumber, colorMode == Printer::Color); | 83 | QImage image = doc->makeImageToFit(requestedSize, pageNumber, color); |
1084 | 84 | |||
1085 | 85 | doc->deleteLater(); | ||
1086 | 86 | |||
1087 | 87 | return image; | ||
1088 | 48 | } | 88 | } |
1089 | 49 | 89 | ||
1090 | === modified file 'backend/UbuntuPrintingApp/popplerimageprovider.h' | |||
1091 | --- backend/Ubuntu_Printing_App/popplerimageprovider.h 2016-12-09 17:14:23 +0000 | |||
1092 | +++ backend/UbuntuPrintingApp/popplerimageprovider.h 2017-02-08 21:32:20 +0000 | |||
1093 | @@ -1,3 +1,22 @@ | |||
1094 | 1 | /* | ||
1095 | 2 | * Copyright 2016 Canonical Ltd. | ||
1096 | 3 | * | ||
1097 | 4 | * This file is part of ubuntu-printing-app. | ||
1098 | 5 | * | ||
1099 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
1100 | 7 | * it under the terms of the GNU General Public License as published by | ||
1101 | 8 | * the Free Software Foundation; version 3. | ||
1102 | 9 | * | ||
1103 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
1104 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1105 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1106 | 13 | * GNU General Public License for more details. | ||
1107 | 14 | * | ||
1108 | 15 | * You should have received a copy of the GNU General Public License | ||
1109 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1110 | 17 | * | ||
1111 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
1112 | 19 | */ | ||
1113 | 1 | #ifndef POPPLERIMAGEPROVIDER_H | 20 | #ifndef POPPLERIMAGEPROVIDER_H |
1114 | 2 | #define POPPLERIMAGEPROVIDER_H | 21 | #define POPPLERIMAGEPROVIDER_H |
1115 | 3 | 22 | ||
1116 | 4 | 23 | ||
1117 | === modified file 'backend/UbuntuPrintingApp/qmldir' | |||
1118 | --- backend/Ubuntu_Printing_App/qmldir 2016-12-13 12:37:45 +0000 | |||
1119 | +++ backend/UbuntuPrintingApp/qmldir 2017-02-08 21:32:20 +0000 | |||
1120 | @@ -1,2 +1,2 @@ | |||
1123 | 1 | module Ubuntu_Printing_App | 1 | module UbuntuPrintingApp |
1124 | 2 | plugin Ubuntu_Printing_Appbackend | 2 | plugin UbuntuPrintingAppbackend |
1125 | 3 | 3 | ||
1126 | === removed file 'backend/Ubuntu_Printing_App/printer.cpp' | |||
1127 | --- backend/Ubuntu_Printing_App/printer.cpp 2016-12-13 12:08:15 +0000 | |||
1128 | +++ backend/Ubuntu_Printing_App/printer.cpp 1970-01-01 00:00:00 +0000 | |||
1129 | @@ -1,355 +0,0 @@ | |||
1130 | 1 | #include "printer.h" | ||
1131 | 2 | |||
1132 | 3 | #include <QtCore/QDateTime> | ||
1133 | 4 | #include <QtCore/QDir> | ||
1134 | 5 | #include <QtCore/QFileInfo> | ||
1135 | 6 | #include <QtCore/QStandardPaths> | ||
1136 | 7 | #include <QtCore/QStringList> | ||
1137 | 8 | #include <QtCore/QVector> | ||
1138 | 9 | |||
1139 | 10 | #include <QtCore/QDebug> | ||
1140 | 11 | |||
1141 | 12 | #include <cups/cups.h> | ||
1142 | 13 | #include <cups/ppd.h> | ||
1143 | 14 | |||
1144 | 15 | #define __CUPS_ADD_OPTION(dest, name, value) dest->num_options = \ | ||
1145 | 16 | cupsAddOption(name, value, dest->num_options, &dest->options); | ||
1146 | 17 | |||
1147 | 18 | Printer::Printer(QObject *parent) | ||
1148 | 19 | : QObject(parent) | ||
1149 | 20 | , m_color_mode(Color) | ||
1150 | 21 | , m_copies(1) | ||
1151 | 22 | , m_cups_dest(0) | ||
1152 | 23 | , m_cups_instance(QStringLiteral("")) | ||
1153 | 24 | , m_cups_name(QStringLiteral("")) | ||
1154 | 25 | , m_duplex(false) | ||
1155 | 26 | , m_duplex_modes({}) | ||
1156 | 27 | , m_duplex_supported(false) | ||
1157 | 28 | , m_job_id(0) | ||
1158 | 29 | , m_name("") | ||
1159 | 30 | , m_ppd(0) | ||
1160 | 31 | , m_pdf_mode(false) | ||
1161 | 32 | , m_quality(Normal) | ||
1162 | 33 | { | ||
1163 | 34 | |||
1164 | 35 | } | ||
1165 | 36 | |||
1166 | 37 | Printer::~Printer() | ||
1167 | 38 | { | ||
1168 | 39 | if (m_ppd) { | ||
1169 | 40 | ppdClose(m_ppd); | ||
1170 | 41 | m_ppd = 0; | ||
1171 | 42 | } | ||
1172 | 43 | |||
1173 | 44 | if (m_cups_dest) { | ||
1174 | 45 | cupsFreeDests(1, m_cups_dest); | ||
1175 | 46 | |||
1176 | 47 | m_cups_dest = 0; | ||
1177 | 48 | } | ||
1178 | 49 | } | ||
1179 | 50 | |||
1180 | 51 | Printer::ColorMode Printer::colorMode() const | ||
1181 | 52 | { | ||
1182 | 53 | return m_color_mode; | ||
1183 | 54 | } | ||
1184 | 55 | |||
1185 | 56 | int Printer::copies() const | ||
1186 | 57 | { | ||
1187 | 58 | return m_copies; | ||
1188 | 59 | } | ||
1189 | 60 | |||
1190 | 61 | bool Printer::duplex() const | ||
1191 | 62 | { | ||
1192 | 63 | return m_duplex; | ||
1193 | 64 | } | ||
1194 | 65 | |||
1195 | 66 | bool Printer::duplexSupported() const | ||
1196 | 67 | { | ||
1197 | 68 | return m_duplex_supported; | ||
1198 | 69 | } | ||
1199 | 70 | |||
1200 | 71 | void Printer::loadDuplexModes(const QString name) | ||
1201 | 72 | { | ||
1202 | 73 | if (m_ppd) { | ||
1203 | 74 | ppdClose(m_ppd); | ||
1204 | 75 | m_ppd = 0; | ||
1205 | 76 | } | ||
1206 | 77 | |||
1207 | 78 | const char *ppdFile = cupsGetPPD(name.toLocal8Bit().data()); | ||
1208 | 79 | |||
1209 | 80 | if (ppdFile) { | ||
1210 | 81 | m_ppd = ppdOpenFile(ppdFile); | ||
1211 | 82 | unlink(ppdFile); | ||
1212 | 83 | |||
1213 | 84 | if (m_ppd) { | ||
1214 | 85 | ppdMarkDefaults(m_ppd); | ||
1215 | 86 | } else { | ||
1216 | 87 | m_ppd = 0; | ||
1217 | 88 | return; | ||
1218 | 89 | } | ||
1219 | 90 | } | ||
1220 | 91 | |||
1221 | 92 | ppd_option_t *duplexModes = ppdFindOption(m_ppd, "Duplex"); | ||
1222 | 93 | ppd_option_t *defaultDuplexModes = ppdFindOption(m_ppd, "DefaultDuplex"); | ||
1223 | 94 | |||
1224 | 95 | // Build list of supported duplex modes | ||
1225 | 96 | bool duplexSupported = false; | ||
1226 | 97 | m_duplex_modes.clear(); | ||
1227 | 98 | |||
1228 | 99 | for (int i=0; i < duplexModes->num_choices; i++) { | ||
1229 | 100 | m_duplex_modes.append(QString::fromLocal8Bit(duplexModes->choices[i].choice)); | ||
1230 | 101 | |||
1231 | 102 | if (QString::fromLocal8Bit(duplexModes->choices[i].choice) != "None") { | ||
1232 | 103 | duplexSupported = true; | ||
1233 | 104 | } | ||
1234 | 105 | } | ||
1235 | 106 | |||
1236 | 107 | setDuplexSupported(duplexSupported); | ||
1237 | 108 | |||
1238 | 109 | // Load default duplex mode | ||
1239 | 110 | // TODO: do we need as option gets disable? | ||
1240 | 111 | if (defaultDuplexModes) { | ||
1241 | 112 | if (QString::fromLocal8Bit(defaultDuplexModes->choices[0].choice) == "None") { | ||
1242 | 113 | setDuplex(false); | ||
1243 | 114 | } else { | ||
1244 | 115 | setDuplex(true); | ||
1245 | 116 | } | ||
1246 | 117 | } | ||
1247 | 118 | } | ||
1248 | 119 | |||
1249 | 120 | bool Printer::loadOptions(cups_dest_t *cups_dest, Document *doc) | ||
1250 | 121 | { | ||
1251 | 122 | // Load options | ||
1252 | 123 | // Copies | ||
1253 | 124 | if (m_copies > 1) { | ||
1254 | 125 | __CUPS_ADD_OPTION(cups_dest, "copies", QString::number(m_copies).toLocal8Bit()); | ||
1255 | 126 | } | ||
1256 | 127 | |||
1257 | 128 | // Colour mode | ||
1258 | 129 | if (m_color_mode == GrayScale) { | ||
1259 | 130 | __CUPS_ADD_OPTION(cups_dest, "ColorModel", "CMYGray"); | ||
1260 | 131 | } | ||
1261 | 132 | |||
1262 | 133 | // Duplex | ||
1263 | 134 | if (m_duplex_supported && m_duplex) { | ||
1264 | 135 | if (doc->orientation() == Document::Portrait && m_duplex_modes.contains("DuplexNoTumble")) { | ||
1265 | 136 | __CUPS_ADD_OPTION(cups_dest, "Duplex", "DuplexNoTumble"); | ||
1266 | 137 | // __CUPS_ADD_OPTION(m_cups_dest, "sides", "two-sided-long-edge") | ||
1267 | 138 | } else if (doc->orientation() == Document::Portrait && m_duplex_modes.contains("DuplexTumble")) { | ||
1268 | 139 | __CUPS_ADD_OPTION(cups_dest, "Duplex", "DuplexTumble"); | ||
1269 | 140 | // __CUPS_ADD_OPTION(m_cups_dest, "sides", "two-sided-long-edge") | ||
1270 | 141 | } else { | ||
1271 | 142 | // Fallback to pick first found duplex mode | ||
1272 | 143 | for (QString mode : m_duplex_modes) { | ||
1273 | 144 | if (mode != "None") { | ||
1274 | 145 | __CUPS_ADD_OPTION(cups_dest, "Duplex", mode.toLocal8Bit().data()); | ||
1275 | 146 | break; | ||
1276 | 147 | } | ||
1277 | 148 | } | ||
1278 | 149 | } | ||
1279 | 150 | } else { | ||
1280 | 151 | __CUPS_ADD_OPTION(cups_dest, "Duplex", "None"); | ||
1281 | 152 | } | ||
1282 | 153 | |||
1283 | 154 | // Orientation | ||
1284 | 155 | if (doc->orientation() == Document::Landscape) { | ||
1285 | 156 | __CUPS_ADD_OPTION(cups_dest, "landscape", ""); | ||
1286 | 157 | } | ||
1287 | 158 | |||
1288 | 159 | // Page range | ||
1289 | 160 | // __CUPS_ADD_OPTION(cups_dest, "number-up", "4"); // 1, 2, 4, 6, 9 | ||
1290 | 161 | // __CUPS_ADD_OPTION(cups_dest, "number-up-layout", "lrtb"); // "lrtb", "lrbt", "rlbt", "rltb", "btlr", "btrl", "tblr", "tbrl" | ||
1291 | 162 | // __CUPS_ADD_OPTION(cups_dest, "page-ranges", "1-2"); // 3-5,7,10-20 | ||
1292 | 163 | |||
1293 | 164 | // Print quality | ||
1294 | 165 | QString printQuality = ""; | ||
1295 | 166 | switch (m_quality) { | ||
1296 | 167 | case Draft: | ||
1297 | 168 | printQuality = "FastDraft"; | ||
1298 | 169 | break; | ||
1299 | 170 | case Best: | ||
1300 | 171 | printQuality = "Best"; | ||
1301 | 172 | break; | ||
1302 | 173 | case Photo: | ||
1303 | 174 | printQuality = "Photo"; | ||
1304 | 175 | break; | ||
1305 | 176 | case Normal: | ||
1306 | 177 | default: | ||
1307 | 178 | printQuality = "Normal"; | ||
1308 | 179 | break; | ||
1309 | 180 | } | ||
1310 | 181 | __CUPS_ADD_OPTION(cups_dest, "OutputMode", printQuality.toLocal8Bit()); | ||
1311 | 182 | |||
1312 | 183 | return true; | ||
1313 | 184 | } | ||
1314 | 185 | |||
1315 | 186 | QString Printer::makeOutputFilepath() const | ||
1316 | 187 | { | ||
1317 | 188 | QDir dir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); | ||
1318 | 189 | |||
1319 | 190 | if (!dir.exists()) { | ||
1320 | 191 | dir.mkpath("."); | ||
1321 | 192 | } | ||
1322 | 193 | |||
1323 | 194 | QFileInfo fileInfo(dir.path(), QDateTime::currentDateTime().toString(Qt::ISODate)); | ||
1324 | 195 | return fileInfo.absoluteFilePath(); | ||
1325 | 196 | } | ||
1326 | 197 | |||
1327 | 198 | QString Printer::name() const | ||
1328 | 199 | { | ||
1329 | 200 | return m_name; | ||
1330 | 201 | } | ||
1331 | 202 | |||
1332 | 203 | bool Printer::pdfMode() const | ||
1333 | 204 | { | ||
1334 | 205 | return m_pdf_mode; | ||
1335 | 206 | } | ||
1336 | 207 | |||
1337 | 208 | bool Printer::print(Document *doc) | ||
1338 | 209 | { | ||
1339 | 210 | // TODO: PDF mode! | ||
1340 | 211 | if (m_pdf_mode) { | ||
1341 | 212 | Q_EMIT exportRequest(doc->url().toLocalFile()); | ||
1342 | 213 | |||
1343 | 214 | // cupsTempFd(); | ||
1344 | 215 | return true; | ||
1345 | 216 | } | ||
1346 | 217 | |||
1347 | 218 | // Get all the dests | ||
1348 | 219 | int num_dests; Q_UNUSED(num_dests) | ||
1349 | 220 | cups_dest_t *dests; | ||
1350 | 221 | |||
1351 | 222 | num_dests = cupsGetDests(&dests); // FIXME: appear to need to run this first? | ||
1352 | 223 | |||
1353 | 224 | for (int i=0; i < num_dests; i++) { | ||
1354 | 225 | qDebug() << "Dest" << dests[i].name; | ||
1355 | 226 | } | ||
1356 | 227 | |||
1357 | 228 | cupsFreeDests(num_dests, dests); | ||
1358 | 229 | |||
1359 | 230 | // Ensure the destination is free | ||
1360 | 231 | if (m_cups_dest) { | ||
1361 | 232 | cupsFreeDests(1, m_cups_dest); | ||
1362 | 233 | |||
1363 | 234 | m_cups_dest = 0; | ||
1364 | 235 | } | ||
1365 | 236 | |||
1366 | 237 | // Get the destination | ||
1367 | 238 | // TODO: IPP, cupsGetDestWithURI() | ||
1368 | 239 | m_cups_dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, m_cups_name.toLocal8Bit().data(), m_cups_instance.toLocal8Bit().data()); | ||
1369 | 240 | |||
1370 | 241 | if (!m_cups_dest) { | ||
1371 | 242 | qWarning() << "Could not find printer:" << m_name; | ||
1372 | 243 | return false; | ||
1373 | 244 | } | ||
1374 | 245 | |||
1375 | 246 | // Load the printer options | ||
1376 | 247 | loadOptions(m_cups_dest, doc); | ||
1377 | 248 | |||
1378 | 249 | // Load title | ||
1379 | 250 | QString title = doc->title(); | ||
1380 | 251 | |||
1381 | 252 | if (title.isEmpty()) { | ||
1382 | 253 | title = doc->url().fileName(); | ||
1383 | 254 | } | ||
1384 | 255 | |||
1385 | 256 | // Send to the printer | ||
1386 | 257 | m_job_id = cupsPrintFile(m_cups_dest->name, | ||
1387 | 258 | doc->url().toLocalFile().toLocal8Bit().data(), | ||
1388 | 259 | title.toLocal8Bit().data(), | ||
1389 | 260 | m_cups_dest->num_options, m_cups_dest->options); | ||
1390 | 261 | |||
1391 | 262 | if (m_job_id == 0) { | ||
1392 | 263 | qWarning() << "Creating Job Failed:" << cupsLastErrorString(); | ||
1393 | 264 | return false; | ||
1394 | 265 | } else { | ||
1395 | 266 | qDebug() << "JobID" << m_job_id; | ||
1396 | 267 | return true; | ||
1397 | 268 | } | ||
1398 | 269 | } | ||
1399 | 270 | |||
1400 | 271 | void Printer::setColorMode(Printer::ColorMode colorMode) | ||
1401 | 272 | { | ||
1402 | 273 | if (m_color_mode != colorMode) { | ||
1403 | 274 | m_color_mode = colorMode; | ||
1404 | 275 | |||
1405 | 276 | Q_EMIT colorModeChanged(); | ||
1406 | 277 | } | ||
1407 | 278 | } | ||
1408 | 279 | |||
1409 | 280 | void Printer::setCopies(int copies) | ||
1410 | 281 | { | ||
1411 | 282 | if (m_copies != copies) { | ||
1412 | 283 | m_copies = copies; | ||
1413 | 284 | |||
1414 | 285 | Q_EMIT copiesChanged(); | ||
1415 | 286 | } | ||
1416 | 287 | } | ||
1417 | 288 | |||
1418 | 289 | void Printer::setDuplex(bool duplex) | ||
1419 | 290 | { | ||
1420 | 291 | if (m_duplex != duplex) { | ||
1421 | 292 | m_duplex = duplex; | ||
1422 | 293 | |||
1423 | 294 | Q_EMIT duplexChanged(); | ||
1424 | 295 | } | ||
1425 | 296 | } | ||
1426 | 297 | |||
1427 | 298 | void Printer::setDuplexSupported(bool duplexSupported) | ||
1428 | 299 | { | ||
1429 | 300 | if (m_duplex_supported != duplexSupported) { | ||
1430 | 301 | m_duplex_supported = duplexSupported; | ||
1431 | 302 | |||
1432 | 303 | Q_EMIT duplexSupportedChanged(); | ||
1433 | 304 | } | ||
1434 | 305 | } | ||
1435 | 306 | |||
1436 | 307 | void Printer::setName(QString name) | ||
1437 | 308 | { | ||
1438 | 309 | if (m_name != name) { | ||
1439 | 310 | m_name = name; | ||
1440 | 311 | |||
1441 | 312 | if (m_pdf_mode) { | ||
1442 | 313 | setDuplexSupported(false); | ||
1443 | 314 | } else { | ||
1444 | 315 | // Extract the cups name and instance from the m_name | ||
1445 | 316 | QStringList split = m_name.split("/"); | ||
1446 | 317 | |||
1447 | 318 | m_cups_name = split.takeFirst(); | ||
1448 | 319 | m_cups_instance = split.isEmpty() ? "" : split.takeFirst(); | ||
1449 | 320 | |||
1450 | 321 | if (split.length() > 0) { | ||
1451 | 322 | qWarning() << "Unknown printer name pattern:" << m_name; | ||
1452 | 323 | return; | ||
1453 | 324 | } | ||
1454 | 325 | |||
1455 | 326 | loadDuplexModes(m_cups_name); | ||
1456 | 327 | } | ||
1457 | 328 | |||
1458 | 329 | Q_EMIT nameChanged(); | ||
1459 | 330 | Q_EMIT settingsChanged(); | ||
1460 | 331 | } | ||
1461 | 332 | } | ||
1462 | 333 | |||
1463 | 334 | void Printer::setPdfMode(bool pdfMode) | ||
1464 | 335 | { | ||
1465 | 336 | if (m_pdf_mode != pdfMode) { | ||
1466 | 337 | m_pdf_mode = pdfMode; | ||
1467 | 338 | |||
1468 | 339 | Q_EMIT pdfModeChanged(); | ||
1469 | 340 | } | ||
1470 | 341 | } | ||
1471 | 342 | |||
1472 | 343 | void Printer::setQuality(Quality quality) | ||
1473 | 344 | { | ||
1474 | 345 | if (m_quality != quality) { | ||
1475 | 346 | m_quality = quality; | ||
1476 | 347 | |||
1477 | 348 | Q_EMIT qualityChanged(); | ||
1478 | 349 | } | ||
1479 | 350 | } | ||
1480 | 351 | |||
1481 | 352 | Printer::Quality Printer::quality() const | ||
1482 | 353 | { | ||
1483 | 354 | return m_quality; | ||
1484 | 355 | } | ||
1485 | 356 | 0 | ||
1486 | === removed file 'backend/Ubuntu_Printing_App/printer.h' | |||
1487 | --- backend/Ubuntu_Printing_App/printer.h 2016-12-13 12:08:15 +0000 | |||
1488 | +++ backend/Ubuntu_Printing_App/printer.h 1970-01-01 00:00:00 +0000 | |||
1489 | @@ -1,94 +0,0 @@ | |||
1490 | 1 | #ifndef PRINTER_H | ||
1491 | 2 | #define PRINTER_H | ||
1492 | 3 | |||
1493 | 4 | #include <QtCore/QObject> | ||
1494 | 5 | |||
1495 | 6 | #include <cups/cups.h> | ||
1496 | 7 | #include <cups/ppd.h> | ||
1497 | 8 | |||
1498 | 9 | #include "document.h" | ||
1499 | 10 | |||
1500 | 11 | class Printer : public QObject | ||
1501 | 12 | { | ||
1502 | 13 | Q_OBJECT | ||
1503 | 14 | |||
1504 | 15 | Q_PROPERTY(ColorMode colorMode READ colorMode WRITE setColorMode NOTIFY colorModeChanged) | ||
1505 | 16 | Q_PROPERTY(int copies READ copies WRITE setCopies NOTIFY copiesChanged) | ||
1506 | 17 | Q_PROPERTY(bool duplex READ duplex WRITE setDuplex NOTIFY duplexChanged) | ||
1507 | 18 | Q_PROPERTY(bool duplexSupported READ duplexSupported NOTIFY duplexSupportedChanged) | ||
1508 | 19 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) | ||
1509 | 20 | Q_PROPERTY(bool pdfMode READ pdfMode WRITE setPdfMode NOTIFY pdfModeChanged) | ||
1510 | 21 | Q_PROPERTY(Quality quality READ quality WRITE setQuality NOTIFY qualityChanged) | ||
1511 | 22 | public: | ||
1512 | 23 | enum ColorMode | ||
1513 | 24 | { | ||
1514 | 25 | Color, | ||
1515 | 26 | GrayScale, | ||
1516 | 27 | }; | ||
1517 | 28 | Q_ENUMS(ColorMode) | ||
1518 | 29 | |||
1519 | 30 | enum Quality | ||
1520 | 31 | { | ||
1521 | 32 | Draft, | ||
1522 | 33 | Normal, | ||
1523 | 34 | Best, | ||
1524 | 35 | Photo, | ||
1525 | 36 | }; | ||
1526 | 37 | Q_ENUMS(Quality) | ||
1527 | 38 | |||
1528 | 39 | explicit Printer(QObject *parent = 0); | ||
1529 | 40 | ~Printer(); | ||
1530 | 41 | ColorMode colorMode() const; | ||
1531 | 42 | int copies() const; | ||
1532 | 43 | bool duplex() const; | ||
1533 | 44 | bool duplexSupported() const; | ||
1534 | 45 | QString name() const; | ||
1535 | 46 | bool pdfMode() const; | ||
1536 | 47 | Quality quality() const; | ||
1537 | 48 | |||
1538 | 49 | Q_INVOKABLE bool print(Document *doc); | ||
1539 | 50 | signals: | ||
1540 | 51 | void colorModeChanged(); | ||
1541 | 52 | void copiesChanged(); | ||
1542 | 53 | void duplexChanged(); | ||
1543 | 54 | void duplexSupportedChanged(); | ||
1544 | 55 | void nameChanged(); | ||
1545 | 56 | void settingsChanged(); | ||
1546 | 57 | void pdfModeChanged(); | ||
1547 | 58 | void qualityChanged(); | ||
1548 | 59 | |||
1549 | 60 | void exportRequest(const QString &filepath); | ||
1550 | 61 | public slots: | ||
1551 | 62 | void setColorMode(ColorMode colorMode); | ||
1552 | 63 | void setCopies(int copies); | ||
1553 | 64 | void setDuplex(bool duplex); | ||
1554 | 65 | void setDuplexSupported(bool duplexSupported); | ||
1555 | 66 | void setName(QString name); | ||
1556 | 67 | void setPdfMode(bool pdfMode); | ||
1557 | 68 | void setQuality(Quality quality); | ||
1558 | 69 | private: | ||
1559 | 70 | void loadDuplexModes(const QString name); | ||
1560 | 71 | bool loadOptions(cups_dest_t *cups_dest, Document *doc); | ||
1561 | 72 | QString makeOutputFilepath() const; | ||
1562 | 73 | |||
1563 | 74 | ColorMode m_color_mode; | ||
1564 | 75 | int m_copies; | ||
1565 | 76 | |||
1566 | 77 | cups_dest_t *m_cups_dest; | ||
1567 | 78 | QString m_cups_instance; | ||
1568 | 79 | QString m_cups_name; | ||
1569 | 80 | |||
1570 | 81 | bool m_duplex; | ||
1571 | 82 | QList<QString> m_duplex_modes; | ||
1572 | 83 | bool m_duplex_supported; | ||
1573 | 84 | int m_job_id; | ||
1574 | 85 | QString m_name; | ||
1575 | 86 | |||
1576 | 87 | ppd_file_t *m_ppd; | ||
1577 | 88 | |||
1578 | 89 | bool m_pdf_mode; | ||
1579 | 90 | Quality m_quality; | ||
1580 | 91 | |||
1581 | 92 | }; | ||
1582 | 93 | |||
1583 | 94 | #endif // PRINTER_H | ||
1584 | 95 | 0 | ||
1585 | === removed file 'backend/Ubuntu_Printing_App/printerinfo.cpp' | |||
1586 | --- backend/Ubuntu_Printing_App/printerinfo.cpp 2016-12-12 17:09:39 +0000 | |||
1587 | +++ backend/Ubuntu_Printing_App/printerinfo.cpp 1970-01-01 00:00:00 +0000 | |||
1588 | @@ -1,39 +0,0 @@ | |||
1589 | 1 | #include "printerinfo.h" | ||
1590 | 2 | |||
1591 | 3 | #include <QtPrintSupport/QPrinterInfo> | ||
1592 | 4 | |||
1593 | 5 | PrinterInfo::PrinterInfo(QObject *parent) : QObject(parent) | ||
1594 | 6 | { | ||
1595 | 7 | m_available_printer_names = QStringList() << QPrinterInfo::availablePrinterNames() << "Create PDF"; | ||
1596 | 8 | m_default_printer_name = QPrinterInfo::defaultPrinterName(); | ||
1597 | 9 | |||
1598 | 10 | // Watch printers for updates | ||
1599 | 11 | m_timer_printers = new QTimer(this); | ||
1600 | 12 | connect(m_timer_printers, SIGNAL(timeout()), this, SLOT(updatePrinters())); | ||
1601 | 13 | m_timer_printers->start(5000); | ||
1602 | 14 | } | ||
1603 | 15 | |||
1604 | 16 | QStringList PrinterInfo::availablePrinterNames() const | ||
1605 | 17 | { | ||
1606 | 18 | return m_available_printer_names; | ||
1607 | 19 | } | ||
1608 | 20 | |||
1609 | 21 | QString PrinterInfo::defaultPrinterName() const | ||
1610 | 22 | { | ||
1611 | 23 | return m_default_printer_name; | ||
1612 | 24 | } | ||
1613 | 25 | |||
1614 | 26 | void PrinterInfo::updatePrinters() | ||
1615 | 27 | { | ||
1616 | 28 | if (m_available_printer_names != QStringList() << QPrinterInfo::availablePrinterNames() << "Create PDF") { | ||
1617 | 29 | m_available_printer_names = QStringList() << QPrinterInfo::availablePrinterNames() << "Create PDF"; | ||
1618 | 30 | |||
1619 | 31 | Q_EMIT availablePrinterNamesChanged(); | ||
1620 | 32 | } | ||
1621 | 33 | |||
1622 | 34 | if (m_default_printer_name != QPrinterInfo::defaultPrinterName()) { | ||
1623 | 35 | m_default_printer_name = QPrinterInfo::defaultPrinterName(); | ||
1624 | 36 | |||
1625 | 37 | Q_EMIT defaultPrinterNameChanged(); | ||
1626 | 38 | } | ||
1627 | 39 | } | ||
1628 | 40 | 0 | ||
1629 | === removed file 'backend/Ubuntu_Printing_App/printerinfo.h' | |||
1630 | --- backend/Ubuntu_Printing_App/printerinfo.h 2016-11-25 16:47:10 +0000 | |||
1631 | +++ backend/Ubuntu_Printing_App/printerinfo.h 1970-01-01 00:00:00 +0000 | |||
1632 | @@ -1,30 +0,0 @@ | |||
1633 | 1 | #ifndef PRINTERINFO_H | ||
1634 | 2 | #define PRINTERINFO_H | ||
1635 | 3 | |||
1636 | 4 | #include <QtCore/QObject> | ||
1637 | 5 | #include <QtCore/QString> | ||
1638 | 6 | #include <QtCore/QStringList> | ||
1639 | 7 | #include <QtCore/QTimer> | ||
1640 | 8 | |||
1641 | 9 | class PrinterInfo : public QObject | ||
1642 | 10 | { | ||
1643 | 11 | Q_OBJECT | ||
1644 | 12 | |||
1645 | 13 | Q_PROPERTY(QStringList availablePrinterNames READ availablePrinterNames NOTIFY availablePrinterNamesChanged) | ||
1646 | 14 | Q_PROPERTY(QString defaultPrinterName READ defaultPrinterName NOTIFY defaultPrinterNameChanged) | ||
1647 | 15 | public: | ||
1648 | 16 | explicit PrinterInfo(QObject *parent = 0); | ||
1649 | 17 | QStringList availablePrinterNames() const; | ||
1650 | 18 | QString defaultPrinterName() const; | ||
1651 | 19 | signals: | ||
1652 | 20 | void availablePrinterNamesChanged(); | ||
1653 | 21 | void defaultPrinterNameChanged(); | ||
1654 | 22 | private slots: | ||
1655 | 23 | void updatePrinters(); | ||
1656 | 24 | private: | ||
1657 | 25 | QStringList m_available_printer_names; | ||
1658 | 26 | QString m_default_printer_name; | ||
1659 | 27 | QTimer *m_timer_printers; | ||
1660 | 28 | }; | ||
1661 | 29 | |||
1662 | 30 | #endif // PRINTERINFO_H | ||
1663 | 31 | 0 | ||
1664 | === removed directory 'backend/tests' | |||
1665 | === removed directory 'backend/tests/unit' | |||
1666 | === removed file 'backend/tests/unit/tst_mytype.qml' | |||
1667 | --- backend/tests/unit/tst_mytype.qml 2016-12-13 12:37:45 +0000 | |||
1668 | +++ backend/tests/unit/tst_mytype.qml 1970-01-01 00:00:00 +0000 | |||
1669 | @@ -1,49 +0,0 @@ | |||
1670 | 1 | import QtQuick 2.4 | ||
1671 | 2 | import QtTest 1.0 | ||
1672 | 3 | import Ubuntu.Components 1.3 | ||
1673 | 4 | import Ubuntu_Printing_App 1.0 | ||
1674 | 5 | |||
1675 | 6 | // See more details @ http://qt-project.org/doc/qt-5.0/qtquick/qml-testcase.html | ||
1676 | 7 | |||
1677 | 8 | // Execute tests with: | ||
1678 | 9 | // qmltestrunner | ||
1679 | 10 | |||
1680 | 11 | Item { | ||
1681 | 12 | // The objects | ||
1682 | 13 | MyType { | ||
1683 | 14 | id: objectUnderTest | ||
1684 | 15 | } | ||
1685 | 16 | |||
1686 | 17 | TestCase { | ||
1687 | 18 | name: "MyType" | ||
1688 | 19 | |||
1689 | 20 | function init() { | ||
1690 | 21 | console.debug(">> init"); | ||
1691 | 22 | compare("",objectUnderTest.helloWorld,"text was not empty on init"); | ||
1692 | 23 | console.debug("<< init"); | ||
1693 | 24 | } | ||
1694 | 25 | |||
1695 | 26 | function cleanup() { | ||
1696 | 27 | console.debug(">> cleanup"); | ||
1697 | 28 | console.debug("<< cleanup"); | ||
1698 | 29 | } | ||
1699 | 30 | |||
1700 | 31 | function initTestCase() { | ||
1701 | 32 | console.debug(">> initTestCase"); | ||
1702 | 33 | console.debug("<< initTestCase"); | ||
1703 | 34 | } | ||
1704 | 35 | |||
1705 | 36 | function cleanupTestCase() { | ||
1706 | 37 | console.debug(">> cleanupTestCase"); | ||
1707 | 38 | console.debug("<< cleanupTestCase"); | ||
1708 | 39 | } | ||
1709 | 40 | |||
1710 | 41 | function test_canReadAndWriteText() { | ||
1711 | 42 | var expected = "Hello World 2"; | ||
1712 | 43 | |||
1713 | 44 | objectUnderTest.helloWorld = expected; | ||
1714 | 45 | |||
1715 | 46 | compare(expected,objectUnderTest.helloWorld,"expected did not equal result"); | ||
1716 | 47 | } | ||
1717 | 48 | } | ||
1718 | 49 | } | ||
1719 | 50 | 0 | ||
1720 | === modified file 'debian/changelog' | |||
1721 | --- debian/changelog 2016-12-09 22:02:22 +0000 | |||
1722 | +++ debian/changelog 2017-02-08 21:32:20 +0000 | |||
1723 | @@ -2,4 +2,4 @@ | |||
1724 | 2 | 2 | ||
1725 | 3 | * Initial release | 3 | * Initial release |
1726 | 4 | 4 | ||
1728 | 5 | -- Andrew Hayzen <ahayzen@gmail.com> Fri, 09 Dec 2016 21:54:12 +0000 | 5 | -- Andrew Hayzen <andrew.hayzen@canonical.com> Fri, 09 Dec 2016 21:54:12 +0000 |
1729 | 6 | 6 | ||
1730 | === modified file 'debian/control' | |||
1731 | --- debian/control 2016-12-14 01:01:39 +0000 | |||
1732 | +++ debian/control 2017-02-08 21:32:20 +0000 | |||
1733 | @@ -1,27 +1,36 @@ | |||
1734 | 1 | Source: ubuntu-printing-app | 1 | Source: ubuntu-printing-app |
1736 | 2 | Section: unknown | 2 | Section: misc |
1737 | 3 | Priority: optional | 3 | Priority: optional |
1739 | 4 | Maintainer: Andrew Hayzen <ahayzen@gmail.com> | 4 | Maintainer: Andrew Hayzen <andrew.hayzen@canonical.com> |
1740 | 5 | Build-Depends: cmake (>= 2.8.9), | 5 | Build-Depends: cmake (>= 2.8.9), |
1741 | 6 | debhelper (>=9), | 6 | debhelper (>=9), |
1742 | 7 | dh-apparmor, | 7 | dh-apparmor, |
1743 | 8 | dh-translations, | 8 | dh-translations, |
1744 | 9 | libcups2-dev, | ||
1745 | 10 | libpoppler-qt5-dev, | 9 | libpoppler-qt5-dev, |
1746 | 11 | qmlscene, | 10 | qmlscene, |
1747 | 11 | qml-module-qtquick2, | ||
1748 | 12 | qml-module-qtquick-layouts, | ||
1749 | 13 | qml-module-qttest, | ||
1750 | 14 | qml-module-ubuntu-settings-components, | ||
1751 | 15 | qml-module-ubuntu-test, | ||
1752 | 16 | qtdeclarative5-ubuntu-content1, | ||
1753 | 17 | qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 1.3) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 1.3), | ||
1754 | 12 | qt5-default, | 18 | qt5-default, |
1755 | 13 | qt5-qmake, | 19 | qt5-qmake, |
1756 | 14 | qtdeclarative5-dev, | 20 | qtdeclarative5-dev, |
1758 | 15 | ubuntu-sdk-qmake-extras | 21 | qtdeclarative5-dev-tools, |
1759 | 22 | ubuntu-sdk-qmake-extras, | ||
1760 | 23 | xvfb | ||
1761 | 16 | Standards-Version: 3.9.6 | 24 | Standards-Version: 3.9.6 |
1763 | 17 | Homepage: <insert the upstream URL, if relevant> | 25 | Homepage: http://launchpad.net/ubuntu-printing-app |
1764 | 26 | Vcs-Bzr: https://code.launchpad.net/~phablet-team/ubuntu-printing-app/trunk | ||
1765 | 18 | 27 | ||
1766 | 19 | Package: ubuntu-printing-app | 28 | Package: ubuntu-printing-app |
1767 | 20 | Architecture: any | 29 | Architecture: any |
1768 | 21 | Depends: ${shlibs:Depends}, ${misc:Depends}, | 30 | Depends: ${shlibs:Depends}, ${misc:Depends}, |
1769 | 22 | libcups2, | ||
1770 | 23 | qml-module-qtquick2, | 31 | qml-module-qtquick2, |
1771 | 24 | qml-module-qtquick-layouts, | 32 | qml-module-qtquick-layouts, |
1772 | 33 | qml-module-ubuntu-settings-components, | ||
1773 | 25 | qtdeclarative5-ubuntu-content1, | 34 | qtdeclarative5-ubuntu-content1, |
1774 | 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), |
1775 | 27 | Description: Printing app which consumes a PDF from content-hub | 36 | Description: Printing app which consumes a PDF from content-hub |
1776 | 28 | 37 | ||
1777 | === modified file 'debian/copyright' | |||
1778 | --- debian/copyright 2016-12-09 22:02:22 +0000 | |||
1779 | +++ debian/copyright 2017-02-08 21:32:20 +0000 | |||
1780 | @@ -1,6 +1,6 @@ | |||
1781 | 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ | 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ |
1782 | 2 | Upstream-Name: ubuntu-printing-app | 2 | Upstream-Name: ubuntu-printing-app |
1784 | 3 | Source: <url://example.com> | 3 | Source: https://code.launchpad.net/ubuntu-printing-app |
1785 | 4 | 4 | ||
1786 | 5 | Files: * | 5 | Files: * |
1787 | 6 | Copyright: 2016 Canonical Ltd. | 6 | Copyright: 2016 Canonical Ltd. |
1788 | 7 | 7 | ||
1789 | === removed file 'manifest.json.in' | |||
1790 | --- manifest.json.in 2016-12-13 23:08:52 +0000 | |||
1791 | +++ manifest.json.in 1970-01-01 00:00:00 +0000 | |||
1792 | @@ -1,16 +0,0 @@ | |||
1793 | 1 | { | ||
1794 | 2 | "name": "ubuntu-printing-app.ahayzen", | ||
1795 | 3 | "description": "A basic printing app for Ubuntu", | ||
1796 | 4 | "architecture": "@CLICK_ARCH@", | ||
1797 | 5 | "title": "ubuntu-printing-app", | ||
1798 | 6 | "hooks": { | ||
1799 | 7 | "ubuntu-printing-app": { | ||
1800 | 8 | "apparmor": "ubuntu-printing-app/ubuntu-printing-app.apparmor", | ||
1801 | 9 | "content-hub": "ubuntu-printing-app/ubuntu-printing-app-content-hub.json", | ||
1802 | 10 | "desktop": "ubuntu-printing-app/ubuntu-printing-app.desktop" | ||
1803 | 11 | } | ||
1804 | 12 | }, | ||
1805 | 13 | "version": "0.1", | ||
1806 | 14 | "maintainer": "Andrew Hayzen <ahayzen@gmail.com>", | ||
1807 | 15 | "framework": "ubuntu-sdk-15.04.6" | ||
1808 | 16 | } | ||
1809 | 17 | 0 | ||
1810 | === added directory 'po' | |||
1811 | === added file 'po/CMakeLists.txt' | |||
1812 | --- po/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1813 | +++ po/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
1814 | @@ -0,0 +1,44 @@ | |||
1815 | 1 | project(ubuntu-printing-app-translations) | ||
1816 | 2 | |||
1817 | 3 | include(FindGettext) | ||
1818 | 4 | find_program(GETTEXT_XGETTEXT_EXECUTABLE xgettext) | ||
1819 | 5 | |||
1820 | 6 | file(RELATIVE_PATH DESKTOP_FILE_IN_IN ${CMAKE_SOURCE_DIR} | ||
1821 | 7 | ${CMAKE_SOURCE_DIR}/ubuntu-printing-app/${DESKTOP_FILE}.in.in) | ||
1822 | 8 | file(RELATIVE_PATH DESKTOP_FILE_IN_IN_H ${CMAKE_SOURCE_DIR} | ||
1823 | 9 | ${CMAKE_CURRENT_SOURCE_DIR}/${DESKTOP_FILE_IN_IN}.h) | ||
1824 | 10 | |||
1825 | 11 | file(GLOB_RECURSE I18N_SRC_FILES | ||
1826 | 12 | RELATIVE ${CMAKE_SOURCE_DIR} | ||
1827 | 13 | ${CMAKE_SOURCE_DIR}/ubuntu-printing-app/**.qml) | ||
1828 | 14 | list(SORT I18N_SRC_FILES) | ||
1829 | 15 | |||
1830 | 16 | set(DOMAIN ${GETTEXT_PACKAGE}) | ||
1831 | 17 | set(POT_FILE ${DOMAIN}.pot) | ||
1832 | 18 | file(GLOB PO_FILES *.po) | ||
1833 | 19 | |||
1834 | 20 | add_custom_target(${POT_FILE} ALL | ||
1835 | 21 | COMMENT "Generating translation template" | ||
1836 | 22 | COMMAND touch ${POT_FILE} | ||
1837 | 23 | COMMAND ${INTLTOOL_EXTRACT} --update --type=gettext/ini | ||
1838 | 24 | --srcdir=${CMAKE_SOURCE_DIR} ${DESKTOP_FILE_IN_IN} | ||
1839 | 25 | COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} -o ${POT_FILE} | ||
1840 | 26 | -D ${CMAKE_SOURCE_DIR} | ||
1841 | 27 | --from-code=UTF-8 | ||
1842 | 28 | --c++ --qt --add-comments=TRANSLATORS | ||
1843 | 29 | --keyword=tr --keyword=tr:1,2 --keyword=N_ | ||
1844 | 30 | -j | ||
1845 | 31 | --package-name=ubuntu-printing-app | ||
1846 | 32 | --copyright-holder='Canonical Ltd.' | ||
1847 | 33 | -D ${CMAKE_SOURCE_DIR} ${I18N_SRC_FILES} | ||
1848 | 34 | -D ${CMAKE_BINARY_DIR} ${DESKTOP_FILE_IN_IN_H} | ||
1849 | 35 | COMMAND ${CMAKE_COMMAND} -E copy ${POT_FILE} ${CMAKE_CURRENT_SOURCE_DIR}) | ||
1850 | 36 | |||
1851 | 37 | foreach(PO_FILE ${PO_FILES}) | ||
1852 | 38 | get_filename_component(LANG ${PO_FILE} NAME_WE) | ||
1853 | 39 | gettext_process_po_files(${LANG} ALL PO_FILES ${PO_FILE}) | ||
1854 | 40 | set(INSTALL_DIR ${CMAKE_INSTALL_LOCALEDIR}/${LANG}/LC_MESSAGES) | ||
1855 | 41 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LANG}.gmo | ||
1856 | 42 | DESTINATION ${INSTALL_DIR} | ||
1857 | 43 | RENAME ${DOMAIN}.mo) | ||
1858 | 44 | endforeach(PO_FILE) | ||
1859 | 0 | 45 | ||
1860 | === added file 'po/ubuntu-printing-app.pot' | |||
1861 | --- po/ubuntu-printing-app.pot 1970-01-01 00:00:00 +0000 | |||
1862 | +++ po/ubuntu-printing-app.pot 2017-02-08 21:32:20 +0000 | |||
1863 | @@ -0,0 +1,122 @@ | |||
1864 | 1 | # SOME DESCRIPTIVE TITLE. | ||
1865 | 2 | # Copyright (C) YEAR Canonical Ltd. | ||
1866 | 3 | # This file is distributed under the same license as the ubuntu-printing-app package. | ||
1867 | 4 | # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
1868 | 5 | # | ||
1869 | 6 | #, fuzzy | ||
1870 | 7 | msgid "" | ||
1871 | 8 | msgstr "" | ||
1872 | 9 | "Project-Id-Version: ubuntu-printing-app\n" | ||
1873 | 10 | "Report-Msgid-Bugs-To: \n" | ||
1874 | 11 | "POT-Creation-Date: 2017-02-08 21:19+0100\n" | ||
1875 | 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
1876 | 13 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
1877 | 14 | "Language-Team: LANGUAGE <LL@li.org>\n" | ||
1878 | 15 | "Language: \n" | ||
1879 | 16 | "MIME-Version: 1.0\n" | ||
1880 | 17 | "Content-Type: text/plain; charset=CHARSET\n" | ||
1881 | 18 | "Content-Transfer-Encoding: 8bit\n" | ||
1882 | 19 | |||
1883 | 20 | #: ubuntu-printing-app/Main.qml:55 | ||
1884 | 21 | msgid "Document is invalid" | ||
1885 | 22 | msgstr "" | ||
1886 | 23 | |||
1887 | 24 | #: ubuntu-printing-app/Main.qml:58 | ||
1888 | 25 | msgid "Document not found" | ||
1889 | 26 | msgstr "" | ||
1890 | 27 | |||
1891 | 28 | #: ubuntu-printing-app/Main.qml:61 | ||
1892 | 29 | msgid "Not a PDF document" | ||
1893 | 30 | msgstr "" | ||
1894 | 31 | |||
1895 | 32 | #: ubuntu-printing-app/Main.qml:64 | ||
1896 | 33 | msgid "An unknown error occurred" | ||
1897 | 34 | msgstr "" | ||
1898 | 35 | |||
1899 | 36 | #: ubuntu-printing-app/Main.qml:76 | ||
1900 | 37 | msgid "Error" | ||
1901 | 38 | msgstr "" | ||
1902 | 39 | |||
1903 | 40 | #: ubuntu-printing-app/Main.qml:96 | ||
1904 | 41 | msgid "URL of PDF to print" | ||
1905 | 42 | msgstr "" | ||
1906 | 43 | |||
1907 | 44 | #: ubuntu-printing-app/components/AlertDialog.qml:28 | ||
1908 | 45 | msgid "OK" | ||
1909 | 46 | msgstr "" | ||
1910 | 47 | |||
1911 | 48 | #: ubuntu-printing-app/components/PrintRow.qml:56 | ||
1912 | 49 | msgid "Cancel" | ||
1913 | 50 | msgstr "" | ||
1914 | 51 | |||
1915 | 52 | #: ubuntu-printing-app/components/PrintRow.qml:69 | ||
1916 | 53 | msgid "Create PDF" | ||
1917 | 54 | msgstr "" | ||
1918 | 55 | |||
1919 | 56 | #: ubuntu-printing-app/components/PrintRow.qml:69 | ||
1920 | 57 | msgid "Print" | ||
1921 | 58 | msgstr "" | ||
1922 | 59 | |||
1923 | 60 | #: ubuntu-printing-app/components/PrintRow.qml:69 | ||
1924 | 61 | msgid "Sheets" | ||
1925 | 62 | msgstr "" | ||
1926 | 63 | |||
1927 | 64 | #: ubuntu-printing-app/pages/ContentPeerPickerPage.qml:43 | ||
1928 | 65 | msgid "Open With..." | ||
1929 | 66 | msgstr "" | ||
1930 | 67 | |||
1931 | 68 | #: ubuntu-printing-app/pages/PrintPage.qml:47 | ||
1932 | 69 | msgid "Page Setup" | ||
1933 | 70 | msgstr "" | ||
1934 | 71 | |||
1935 | 72 | #: ubuntu-printing-app/pages/PrintPage.qml:47 | ||
1936 | 73 | msgid "Printer Options" | ||
1937 | 74 | msgstr "" | ||
1938 | 75 | |||
1939 | 76 | #: ubuntu-printing-app/pages/PrintPage.qml:85 | ||
1940 | 77 | msgid "Printer" | ||
1941 | 78 | msgstr "" | ||
1942 | 79 | |||
1943 | 80 | #: ubuntu-printing-app/pages/PrintPage.qml:97 | ||
1944 | 81 | msgid "Copies" | ||
1945 | 82 | msgstr "" | ||
1946 | 83 | |||
1947 | 84 | #: ubuntu-printing-app/pages/PrintPage.qml:120 | ||
1948 | 85 | msgid "Collate" | ||
1949 | 86 | msgstr "" | ||
1950 | 87 | |||
1951 | 88 | #: ubuntu-printing-app/pages/PrintPage.qml:140 | ||
1952 | 89 | msgid "Reverse" | ||
1953 | 90 | msgstr "" | ||
1954 | 91 | |||
1955 | 92 | #: ubuntu-printing-app/pages/PrintPage.qml:163 | ||
1956 | 93 | msgid "Two-sided" | ||
1957 | 94 | msgstr "" | ||
1958 | 95 | |||
1959 | 96 | #: ubuntu-printing-app/pages/PrintPage.qml:182 | ||
1960 | 97 | msgid "All" | ||
1961 | 98 | msgstr "" | ||
1962 | 99 | |||
1963 | 100 | #: ubuntu-printing-app/pages/PrintPage.qml:182 | ||
1964 | 101 | msgid "Range" | ||
1965 | 102 | msgstr "" | ||
1966 | 103 | |||
1967 | 104 | #: ubuntu-printing-app/pages/PrintPage.qml:186 | ||
1968 | 105 | msgid "Pages" | ||
1969 | 106 | msgstr "" | ||
1970 | 107 | |||
1971 | 108 | #: ubuntu-printing-app/pages/PrintPage.qml:228 | ||
1972 | 109 | msgid "eg 1-3,8" | ||
1973 | 110 | msgstr "" | ||
1974 | 111 | |||
1975 | 112 | #: ubuntu-printing-app/pages/PrintPage.qml:237 | ||
1976 | 113 | msgid "Color" | ||
1977 | 114 | msgstr "" | ||
1978 | 115 | |||
1979 | 116 | #: ubuntu-printing-app/pages/PrintPage.qml:258 | ||
1980 | 117 | msgid "Quality" | ||
1981 | 118 | msgstr "" | ||
1982 | 119 | |||
1983 | 120 | #: po/ubuntu-printing-app/ubuntu-printing-app.desktop.in.in.h:1 | ||
1984 | 121 | msgid "ubuntu-printing-app" | ||
1985 | 122 | msgstr "" | ||
1986 | 0 | 123 | ||
1987 | === modified file 'runner/CMakeLists.txt' | |||
1988 | --- runner/CMakeLists.txt 2016-12-13 23:08:52 +0000 | |||
1989 | +++ runner/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
1990 | @@ -1,6 +1,9 @@ | |||
1991 | 1 | 1 | ||
1992 | 2 | # Install runner | 2 | # Install runner |
1994 | 3 | install(FILES "ubuntu-printing-app" DESTINATION ${CMAKE_INSTALL_BINDIR}) | 3 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ubuntu-printing-app.in ${CMAKE_CURRENT_BINARY_DIR}/${RUNNER}) |
1995 | 4 | |||
1996 | 5 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${RUNNER} DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
1997 | 6 | |||
1998 | 4 | 7 | ||
1999 | 5 | # Show in QtC | 8 | # Show in QtC |
2001 | 6 | add_custom_target(ubuntu_printing_app_runner_files ALL SOURCES ubuntu-printing-app) | 9 | add_custom_target(ubuntu_printing_app_runner_files ALL SOURCES ubuntu-printing-app.in) |
2002 | 7 | 10 | ||
2003 | === removed file 'runner/ubuntu-printing-app' | |||
2004 | --- runner/ubuntu-printing-app 2016-12-13 14:23:08 +0000 | |||
2005 | +++ runner/ubuntu-printing-app 1970-01-01 00:00:00 +0000 | |||
2006 | @@ -1,3 +0,0 @@ | |||
2007 | 1 | #!/bin/sh | ||
2008 | 2 | |||
2009 | 3 | qmlscene -qt5 /usr/share/ubuntu-printing-app/Main.qml | ||
2010 | 4 | 0 | ||
2011 | === added file 'runner/ubuntu-printing-app.in' | |||
2012 | --- runner/ubuntu-printing-app.in 1970-01-01 00:00:00 +0000 | |||
2013 | +++ runner/ubuntu-printing-app.in 2017-02-08 21:32:20 +0000 | |||
2014 | @@ -0,0 +1,3 @@ | |||
2015 | 1 | #!/bin/sh | ||
2016 | 2 | |||
2017 | 3 | @EXEC@ | ||
2018 | 0 | 4 | ||
2019 | === added directory 'setup' | |||
2020 | === added directory 'setup/gui' | |||
2021 | === added file 'setup/gui/ubuntu-printing-app.desktop' | |||
2022 | --- setup/gui/ubuntu-printing-app.desktop 1970-01-01 00:00:00 +0000 | |||
2023 | +++ setup/gui/ubuntu-printing-app.desktop 2017-02-08 21:32:20 +0000 | |||
2024 | @@ -0,0 +1,8 @@ | |||
2025 | 1 | [Desktop Entry] | ||
2026 | 2 | Name=ubuntu-printing-app | ||
2027 | 3 | Exec=ubuntu-printing-app | ||
2028 | 4 | Icon=${SNAP}/meta/gui/ubuntu-printing-app.png | ||
2029 | 5 | Terminal=false | ||
2030 | 6 | Type=Application | ||
2031 | 7 | X-Ubuntu-Touch=true | ||
2032 | 8 | X-Ubuntu-Touch-Single-Instance=false | ||
2033 | 0 | 9 | ||
2034 | === added file 'setup/gui/ubuntu-printing-app.png' | |||
2035 | 1 | Binary 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 | 10 | Binary 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 |
2036 | === added directory 'snap' | |||
2037 | === added directory 'snap/ubuntu-app-platform' | |||
2038 | === added file 'snapcraft.yaml' | |||
2039 | --- snapcraft.yaml 1970-01-01 00:00:00 +0000 | |||
2040 | +++ snapcraft.yaml 2017-02-08 21:32:20 +0000 | |||
2041 | @@ -0,0 +1,75 @@ | |||
2042 | 1 | name: ubuntu-printing-app | ||
2043 | 2 | version: "0.1" | ||
2044 | 3 | summary: "Printing app which consumes a PDF from content-hub" | ||
2045 | 4 | description: Printing app which consumes a PDF document from | ||
2046 | 5 | content-hub, allows for basic configuration and | ||
2047 | 6 | then sends to a CUPS printer. | ||
2048 | 7 | confinement: strict | ||
2049 | 8 | |||
2050 | 9 | apps: | ||
2051 | 10 | ubuntu-printing-app: | ||
2052 | 11 | command: desktop-launch $SNAP/usr/bin/ubuntu-printing-app --desktop_file_hint=unity8 | ||
2053 | 12 | plugs: | ||
2054 | 13 | - cups-control | ||
2055 | 14 | - home | ||
2056 | 15 | - network | ||
2057 | 16 | - opengl | ||
2058 | 17 | - platform | ||
2059 | 18 | - unity7 | ||
2060 | 19 | - unity8 | ||
2061 | 20 | |||
2062 | 21 | plugs: | ||
2063 | 22 | platform: | ||
2064 | 23 | interface: content | ||
2065 | 24 | content: ubuntu-app-platform1 | ||
2066 | 25 | target: ubuntu-app-platform | ||
2067 | 26 | default-provider: ubuntu-app-platform | ||
2068 | 27 | |||
2069 | 28 | parts: | ||
2070 | 29 | ubuntu-printing-app: | ||
2071 | 30 | build-packages: | ||
2072 | 31 | - intltool | ||
2073 | 32 | - libpoppler-qt5-dev | ||
2074 | 33 | - qml-module-qttest | ||
2075 | 34 | - qml-module-ubuntu-test | ||
2076 | 35 | - qt5-default | ||
2077 | 36 | - qt5-qmake | ||
2078 | 37 | - qtdeclarative5-dev | ||
2079 | 38 | - ubuntu-sdk-qmake-extras | ||
2080 | 39 | - xvfb | ||
2081 | 40 | configflags: [-DCMAKE_INSTALL_PREFIX=/usr, -DSNAP_MODE=on] | ||
2082 | 41 | plugin: cmake | ||
2083 | 42 | source: . | ||
2084 | 43 | after: [printer-components, desktop-ubuntu-app-platform] | ||
2085 | 44 | |||
2086 | 45 | printer-components: | ||
2087 | 46 | plugin: cmake | ||
2088 | 47 | configflags: [-DCMAKE_INSTALL_PREFIX=/usr] | ||
2089 | 48 | source: https://code.launchpad.net/~phablet-team/ubuntu-settings-components/printer-components | ||
2090 | 49 | source-type: bzr | ||
2091 | 50 | build-packages: | ||
2092 | 51 | - cmake-extras | ||
2093 | 52 | - libcups2-dev | ||
2094 | 53 | - libqt5printsupport5 | ||
2095 | 54 | - debhelper | ||
2096 | 55 | - gettext | ||
2097 | 56 | - pkg-config | ||
2098 | 57 | - python3 | ||
2099 | 58 | - qml-module-qt-labs-folderlistmodel | ||
2100 | 59 | - qml-module-qtquick-layouts | ||
2101 | 60 | - qml-module-qtquick2 | ||
2102 | 61 | - qml-module-qttest | ||
2103 | 62 | - qml-module-ubuntu-components | ||
2104 | 63 | - qml-module-ubuntu-thumbnailer0.1 | ||
2105 | 64 | - qtbase5-dev | ||
2106 | 65 | - qtbase5-private-dev | ||
2107 | 66 | - qtdeclarative5-dev | ||
2108 | 67 | - qtdeclarative5-dev-tools | ||
2109 | 68 | - suru-icon-theme | ||
2110 | 69 | stage-packages: | ||
2111 | 70 | - libcups2 | ||
2112 | 71 | - libqt5printsupport5 | ||
2113 | 72 | |||
2114 | 73 | environment: | ||
2115 | 74 | source: snap/ | ||
2116 | 75 | plugin: dump | ||
2117 | 0 | 76 | ||
2118 | === added directory 'tests' | |||
2119 | === added file 'tests/CMakeLists.txt' | |||
2120 | --- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
2121 | +++ tests/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
2122 | @@ -0,0 +1,3 @@ | |||
2123 | 1 | add_subdirectory(resources) | ||
2124 | 2 | add_subdirectory(qmltests) | ||
2125 | 3 | add_subdirectory(unittests) | ||
2126 | 0 | 4 | ||
2127 | === added directory 'tests/qmltests' | |||
2128 | === added file 'tests/qmltests/CMakeLists.txt' | |||
2129 | --- tests/qmltests/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
2130 | +++ tests/qmltests/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
2131 | @@ -0,0 +1,46 @@ | |||
2132 | 1 | find_package(Qt5Core REQUIRED) | ||
2133 | 2 | find_package(Qt5Gui REQUIRED) | ||
2134 | 3 | find_package(Qt5Qml REQUIRED) | ||
2135 | 4 | find_package(Qt5Quick REQUIRED) | ||
2136 | 5 | find_package(Qt5QuickTest REQUIRED) | ||
2137 | 6 | |||
2138 | 7 | find_program(XVFBRUN xvfb-run) | ||
2139 | 8 | if(NOT XVFBRUN) | ||
2140 | 9 | message(FATAL_ERROR "Could not find xvfb-run, please install the xvfb package") | ||
2141 | 10 | endif() | ||
2142 | 11 | set(XVFB_COMMAND ${XVFBRUN} -s "-screen 0 640x480x24" -a) | ||
2143 | 12 | |||
2144 | 13 | find_program(QMLTESTRUNNER qmltestrunner) | ||
2145 | 14 | if(NOT QMLTESTRUNNER) | ||
2146 | 15 | message(FATAL_ERROR "Could not find qmltestrunner, please install the package qtdeclarative5-dev-tools") | ||
2147 | 16 | endif() | ||
2148 | 17 | |||
2149 | 18 | set(TEST tst_QmlTests) | ||
2150 | 19 | add_test(${TEST} ${XVFB_COMMAND} ${QMLTESTRUNNER} | ||
2151 | 20 | -input ${CMAKE_CURRENT_SOURCE_DIR} | ||
2152 | 21 | -import ${CMAKE_BINARY_DIR}/backend) | ||
2153 | 22 | |||
2154 | 23 | |||
2155 | 24 | # Add the qml test files to build dir | ||
2156 | 25 | set(QMLTEST_FILES | ||
2157 | 26 | tst_CheckBoxRow.qml | ||
2158 | 27 | tst_LabelRow.qml | ||
2159 | 28 | tst_PreviewRow.qml | ||
2160 | 29 | tst_PrintRow.qml | ||
2161 | 30 | tst_PrintPage.qml | ||
2162 | 31 | tst_SelectorRow.qml | ||
2163 | 32 | tst_TextFieldRow.qml | ||
2164 | 33 | ) | ||
2165 | 34 | |||
2166 | 35 | add_custom_target(qmltest_copyFiles ALL | ||
2167 | 36 | COMMENT "Copying files: ${QMLTEST_FILES}") | ||
2168 | 37 | |||
2169 | 38 | foreach(FILENAME ${QMLTEST_FILES}) | ||
2170 | 39 | add_custom_command( | ||
2171 | 40 | TARGET qmltest_copyFiles | ||
2172 | 41 | COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}" | ||
2173 | 42 | ) | ||
2174 | 43 | endforeach(FILENAME) | ||
2175 | 44 | |||
2176 | 45 | # Show in QtC | ||
2177 | 46 | add_custom_target(qmltest_files ALL SOURCES ${QMLTEST_FILES}) | ||
2178 | 0 | 47 | ||
2179 | === added file 'tests/qmltests/tst_CheckBoxRow.qml' | |||
2180 | --- tests/qmltests/tst_CheckBoxRow.qml 1970-01-01 00:00:00 +0000 | |||
2181 | +++ tests/qmltests/tst_CheckBoxRow.qml 2017-02-08 21:32:20 +0000 | |||
2182 | @@ -0,0 +1,87 @@ | |||
2183 | 1 | /* | ||
2184 | 2 | * Copyright 2017 Canonical Ltd. | ||
2185 | 3 | * | ||
2186 | 4 | * This file is part of ubuntu-printing-app. | ||
2187 | 5 | * | ||
2188 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
2189 | 7 | * it under the terms of the GNU General Public License as published by | ||
2190 | 8 | * the Free Software Foundation; version 3. | ||
2191 | 9 | * | ||
2192 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
2193 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2194 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2195 | 13 | * GNU General Public License for more details. | ||
2196 | 14 | * | ||
2197 | 15 | * You should have received a copy of the GNU General Public License | ||
2198 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2199 | 17 | * | ||
2200 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
2201 | 19 | */ | ||
2202 | 20 | import QtQuick 2.4 | ||
2203 | 21 | import QtTest 1.1 | ||
2204 | 22 | import Ubuntu.Test 1.0 | ||
2205 | 23 | import "../../ubuntu-printing-app/components" | ||
2206 | 24 | |||
2207 | 25 | Item { | ||
2208 | 26 | width: units.gu(100) | ||
2209 | 27 | height: units.gu(75) | ||
2210 | 28 | |||
2211 | 29 | CheckBoxRow { | ||
2212 | 30 | id: checkBoxRow | ||
2213 | 31 | } | ||
2214 | 32 | |||
2215 | 33 | UbuntuTestCase { | ||
2216 | 34 | name: "CheckBoxRowTestCase" | ||
2217 | 35 | when: windowShown | ||
2218 | 36 | |||
2219 | 37 | readonly property bool dataChecked: false | ||
2220 | 38 | readonly property string dataCheckboxText: "checkboxText" | ||
2221 | 39 | readonly property bool dataEnabled: true | ||
2222 | 40 | readonly property string dataText: "text" | ||
2223 | 41 | |||
2224 | 42 | function init() { | ||
2225 | 43 | checkBoxRow.checked = dataChecked; | ||
2226 | 44 | checkBoxRow.checkboxText = dataCheckboxText; | ||
2227 | 45 | checkBoxRow.enabled = dataEnabled; | ||
2228 | 46 | checkBoxRow.text = dataText; | ||
2229 | 47 | |||
2230 | 48 | waitForRendering(checkBoxRow); | ||
2231 | 49 | } | ||
2232 | 50 | |||
2233 | 51 | function test_checked() { | ||
2234 | 52 | // Check checkbox checked state is starting value | ||
2235 | 53 | var checkbox = findChild(checkBoxRow, "checkbox"); | ||
2236 | 54 | compare(checkBoxRow.checked, dataChecked); | ||
2237 | 55 | |||
2238 | 56 | // Click on the checkbox | ||
2239 | 57 | mouseClick(checkbox); | ||
2240 | 58 | |||
2241 | 59 | // Check that the checked state flips | ||
2242 | 60 | tryCompare(checkBoxRow, "checked", !dataChecked); | ||
2243 | 61 | } | ||
2244 | 62 | |||
2245 | 63 | function test_checkboxText() { | ||
2246 | 64 | // Check that the checkbox label is correct | ||
2247 | 65 | var label = findChild(checkBoxRow, "checkboxLabel"); | ||
2248 | 66 | compare(label.text, dataCheckboxText); | ||
2249 | 67 | } | ||
2250 | 68 | |||
2251 | 69 | function test_enabled() { | ||
2252 | 70 | // Check checkbox enabled state is starting value | ||
2253 | 71 | var checkbox = findChild(checkBoxRow, "checkbox"); | ||
2254 | 72 | compare(checkBoxRow.enabled, dataEnabled); | ||
2255 | 73 | |||
2256 | 74 | // Flip the enabled state | ||
2257 | 75 | checkBoxRow.enabled = !dataEnabled; | ||
2258 | 76 | |||
2259 | 77 | // Check that the enabled state changes | ||
2260 | 78 | tryCompare(checkbox, "enabled", !dataEnabled); | ||
2261 | 79 | } | ||
2262 | 80 | |||
2263 | 81 | function test_text() { | ||
2264 | 82 | // Check that the text is correct | ||
2265 | 83 | var label = findChild(checkBoxRow, "label"); | ||
2266 | 84 | compare(label.text, dataText); | ||
2267 | 85 | } | ||
2268 | 86 | } | ||
2269 | 87 | } | ||
2270 | 0 | 88 | ||
2271 | === added file 'tests/qmltests/tst_LabelRow.qml' | |||
2272 | --- tests/qmltests/tst_LabelRow.qml 1970-01-01 00:00:00 +0000 | |||
2273 | +++ tests/qmltests/tst_LabelRow.qml 2017-02-08 21:32:20 +0000 | |||
2274 | @@ -0,0 +1,73 @@ | |||
2275 | 1 | /* | ||
2276 | 2 | * Copyright 2017 Canonical Ltd. | ||
2277 | 3 | * | ||
2278 | 4 | * This file is part of ubuntu-printing-app. | ||
2279 | 5 | * | ||
2280 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
2281 | 7 | * it under the terms of the GNU General Public License as published by | ||
2282 | 8 | * the Free Software Foundation; version 3. | ||
2283 | 9 | * | ||
2284 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
2285 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2286 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2287 | 13 | * GNU General Public License for more details. | ||
2288 | 14 | * | ||
2289 | 15 | * You should have received a copy of the GNU General Public License | ||
2290 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2291 | 17 | * | ||
2292 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
2293 | 19 | */ | ||
2294 | 20 | import QtQuick 2.4 | ||
2295 | 21 | import QtTest 1.1 | ||
2296 | 22 | import Ubuntu.Test 1.0 | ||
2297 | 23 | import "../../ubuntu-printing-app/components" | ||
2298 | 24 | |||
2299 | 25 | Item { | ||
2300 | 26 | width: units.gu(100) | ||
2301 | 27 | height: units.gu(75) | ||
2302 | 28 | |||
2303 | 29 | LabelRow { | ||
2304 | 30 | id: labelRow | ||
2305 | 31 | } | ||
2306 | 32 | |||
2307 | 33 | UbuntuTestCase { | ||
2308 | 34 | name: "LabelRowTestCase" | ||
2309 | 35 | when: windowShown | ||
2310 | 36 | |||
2311 | 37 | readonly property bool dataEnabled: true | ||
2312 | 38 | readonly property string dataPrimaryText: "Primary" | ||
2313 | 39 | readonly property string dataSecondaryText: "Secondary" | ||
2314 | 40 | |||
2315 | 41 | function init() { | ||
2316 | 42 | labelRow.enabled = dataEnabled; | ||
2317 | 43 | labelRow.primaryText = dataPrimaryText; | ||
2318 | 44 | labelRow.secondaryText = dataSecondaryText; | ||
2319 | 45 | |||
2320 | 46 | waitForRendering(labelRow); | ||
2321 | 47 | } | ||
2322 | 48 | |||
2323 | 49 | function test_enabled() { | ||
2324 | 50 | // Check that label enabled state is at the starting state | ||
2325 | 51 | var secondary = findChild(labelRow, "secondary"); | ||
2326 | 52 | compare(labelRow.enabled, dataEnabled); | ||
2327 | 53 | |||
2328 | 54 | // Flip the enabled state | ||
2329 | 55 | labelRow.enabled = !dataEnabled; | ||
2330 | 56 | |||
2331 | 57 | // Check that the label enabled state changes | ||
2332 | 58 | tryCompare(secondary, "enabled", !dataEnabled); | ||
2333 | 59 | } | ||
2334 | 60 | |||
2335 | 61 | function test_primaryText() { | ||
2336 | 62 | // Check primary text is correct | ||
2337 | 63 | var primary = findChild(labelRow, "primary"); | ||
2338 | 64 | compare(primary.text, dataPrimaryText); | ||
2339 | 65 | } | ||
2340 | 66 | |||
2341 | 67 | function test_secondaryText() { | ||
2342 | 68 | // Check secondary text is correct | ||
2343 | 69 | var secondary = findChild(labelRow, "secondary"); | ||
2344 | 70 | compare(secondary.text, dataSecondaryText); | ||
2345 | 71 | } | ||
2346 | 72 | } | ||
2347 | 73 | } | ||
2348 | 0 | 74 | ||
2349 | === added file 'tests/qmltests/tst_PreviewRow.qml' | |||
2350 | --- tests/qmltests/tst_PreviewRow.qml 1970-01-01 00:00:00 +0000 | |||
2351 | +++ tests/qmltests/tst_PreviewRow.qml 2017-02-08 21:32:20 +0000 | |||
2352 | @@ -0,0 +1,316 @@ | |||
2353 | 1 | /* | ||
2354 | 2 | * Copyright 2017 Canonical Ltd. | ||
2355 | 3 | * | ||
2356 | 4 | * This file is part of ubuntu-printing-app. | ||
2357 | 5 | * | ||
2358 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
2359 | 7 | * it under the terms of the GNU General Public License as published by | ||
2360 | 8 | * the Free Software Foundation; version 3. | ||
2361 | 9 | * | ||
2362 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
2363 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2364 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2365 | 13 | * GNU General Public License for more details. | ||
2366 | 14 | * | ||
2367 | 15 | * You should have received a copy of the GNU General Public License | ||
2368 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2369 | 17 | * | ||
2370 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
2371 | 19 | */ | ||
2372 | 20 | import QtQuick 2.4 | ||
2373 | 21 | import QtTest 1.1 | ||
2374 | 22 | import Ubuntu.Test 1.0 | ||
2375 | 23 | import "../../ubuntu-printing-app/components" | ||
2376 | 24 | |||
2377 | 25 | import UbuntuPrintingApp 1.0 | ||
2378 | 26 | import Ubuntu.Settings.Printers 0.1 | ||
2379 | 27 | |||
2380 | 28 | Item { | ||
2381 | 29 | id: root | ||
2382 | 30 | width: units.gu(100) | ||
2383 | 31 | height: units.gu(75) | ||
2384 | 32 | |||
2385 | 33 | Document { | ||
2386 | 34 | id: testDocument | ||
2387 | 35 | url: Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf") | ||
2388 | 36 | } | ||
2389 | 37 | |||
2390 | 38 | QtObject { | ||
2391 | 39 | id: mockPrinterJob | ||
2392 | 40 | |||
2393 | 41 | property int colorModelType: PrinterEnum.ColorType | ||
2394 | 42 | } | ||
2395 | 43 | |||
2396 | 44 | Item { | ||
2397 | 45 | id: mockView | ||
2398 | 46 | height: units.gu(100) | ||
2399 | 47 | width: units.gu(100) | ||
2400 | 48 | } | ||
2401 | 49 | |||
2402 | 50 | PreviewRow { | ||
2403 | 51 | id: previewRow | ||
2404 | 52 | document: testDocument | ||
2405 | 53 | printerJob: mockPrinterJob | ||
2406 | 54 | view: mockView | ||
2407 | 55 | } | ||
2408 | 56 | |||
2409 | 57 | SignalSpy { | ||
2410 | 58 | id: documentCountSpy | ||
2411 | 59 | signalName: "onCountChanged" | ||
2412 | 60 | target: testDocument | ||
2413 | 61 | } | ||
2414 | 62 | |||
2415 | 63 | SignalSpy { | ||
2416 | 64 | id: activityIndicatorSpy | ||
2417 | 65 | signalName: "onRunningChanged" | ||
2418 | 66 | // Target is set at runtime | ||
2419 | 67 | } | ||
2420 | 68 | |||
2421 | 69 | UbuntuTestCase { | ||
2422 | 70 | name: "PreviewRowTestCase" | ||
2423 | 71 | when: windowShown | ||
2424 | 72 | |||
2425 | 73 | function init() { | ||
2426 | 74 | testDocument.url = Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf"); | ||
2427 | 75 | |||
2428 | 76 | mockPrinterJob.colorModelType = PrinterEnum.ColorType; | ||
2429 | 77 | |||
2430 | 78 | activityIndicatorSpy.target = null; | ||
2431 | 79 | activityIndicatorSpy.clear(); | ||
2432 | 80 | documentCountSpy.clear(); | ||
2433 | 81 | |||
2434 | 82 | waitForRendering(previewRow); | ||
2435 | 83 | } | ||
2436 | 84 | |||
2437 | 85 | function test_activityIndicator() { | ||
2438 | 86 | var image = findChild(previewRow, "previewImage"); | ||
2439 | 87 | var activityIndicator = findChild(previewRow, "activityIndicator"); | ||
2440 | 88 | activityIndicatorSpy.target = activityIndicator; | ||
2441 | 89 | |||
2442 | 90 | // Change the document and wait for image to finish loading | ||
2443 | 91 | testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
2444 | 92 | tryCompare(image, "status", Image.Ready); | ||
2445 | 93 | |||
2446 | 94 | // Check that the running state changed twice false=>true=>falase | ||
2447 | 95 | compare(activityIndicatorSpy.count, 2); | ||
2448 | 96 | } | ||
2449 | 97 | |||
2450 | 98 | function test_document_image() { | ||
2451 | 99 | var image = findChild(previewRow, "previewImage"); | ||
2452 | 100 | |||
2453 | 101 | // Change the document | ||
2454 | 102 | testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
2455 | 103 | |||
2456 | 104 | // Ensure that the image has a valid state | ||
2457 | 105 | tryCompare(image, "status", Image.Ready); | ||
2458 | 106 | } | ||
2459 | 107 | |||
2460 | 108 | function test_document_image_invalid() { | ||
2461 | 109 | var image = findChild(previewRow, "previewImage"); | ||
2462 | 110 | |||
2463 | 111 | // Change the document to an invalid doc | ||
2464 | 112 | testDocument.url = Qt.resolvedUrl("../resources/pdf/text.txt"); | ||
2465 | 113 | |||
2466 | 114 | // Ensure that the image has a valid state | ||
2467 | 115 | // This is because the poppler renderer always generates a valid image | ||
2468 | 116 | tryCompare(image, "status", Image.Ready); | ||
2469 | 117 | } | ||
2470 | 118 | |||
2471 | 119 | function test_document_change_page_reset() { | ||
2472 | 120 | var next = findChild(previewRow, "nextButton"); | ||
2473 | 121 | var pageHelper = previewRow.pageHelper; | ||
2474 | 122 | |||
2475 | 123 | // Load a multi page document and change to 2nd page | ||
2476 | 124 | testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
2477 | 125 | |||
2478 | 126 | documentCountSpy.wait(); | ||
2479 | 127 | compare(documentCountSpy.count, 1); | ||
2480 | 128 | compare(testDocument.count, 3); | ||
2481 | 129 | |||
2482 | 130 | mouseClick(next); | ||
2483 | 131 | tryCompare(pageHelper, "page", 1); | ||
2484 | 132 | |||
2485 | 133 | // Load a single page document, check we go back to page 0 | ||
2486 | 134 | testDocument.url = Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf"); | ||
2487 | 135 | |||
2488 | 136 | documentCountSpy.wait(); | ||
2489 | 137 | compare(documentCountSpy.count, 2); | ||
2490 | 138 | compare(testDocument.count, 1); | ||
2491 | 139 | compare(pageHelper.page, 0); | ||
2492 | 140 | } | ||
2493 | 141 | |||
2494 | 142 | function test_overlay() { | ||
2495 | 143 | var label = findChild(previewRow, "overlayLabel"); | ||
2496 | 144 | var pageHelper = previewRow.pageHelper; | ||
2497 | 145 | var textParts = label.text.split("/"); | ||
2498 | 146 | |||
2499 | 147 | // Check text starts with 1/1 | ||
2500 | 148 | compare(textParts.length, 2); | ||
2501 | 149 | compare(textParts[0], "1"); | ||
2502 | 150 | compare(textParts[1], "1"); | ||
2503 | 151 | |||
2504 | 152 | testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
2505 | 153 | |||
2506 | 154 | waitForRendering(previewRow); | ||
2507 | 155 | textParts = label.text.split("/"); | ||
2508 | 156 | |||
2509 | 157 | // Check it has changed to 1/3 | ||
2510 | 158 | compare(textParts.length, 2); | ||
2511 | 159 | compare(textParts[0], "1"); | ||
2512 | 160 | compare(textParts[1], "3"); | ||
2513 | 161 | |||
2514 | 162 | pageHelper.page++; | ||
2515 | 163 | |||
2516 | 164 | waitForRendering(previewRow); | ||
2517 | 165 | textParts = label.text.split("/"); | ||
2518 | 166 | |||
2519 | 167 | // Check it has changed to 2/3 | ||
2520 | 168 | compare(textParts.length, 2); | ||
2521 | 169 | compare(textParts[0], "2"); | ||
2522 | 170 | compare(textParts[1], "3"); | ||
2523 | 171 | } | ||
2524 | 172 | |||
2525 | 173 | function test_page_single() { | ||
2526 | 174 | var next = findChild(previewRow, "nextButton"); | ||
2527 | 175 | var previous = findChild(previewRow, "previousButton"); | ||
2528 | 176 | |||
2529 | 177 | // Check with a single page doc navigation controls are disabled | ||
2530 | 178 | compare(next.enabled, false); | ||
2531 | 179 | compare(previous.enabled, false); | ||
2532 | 180 | } | ||
2533 | 181 | |||
2534 | 182 | function test_page_next() { | ||
2535 | 183 | var image = findChild(previewRow, "previewImage"); | ||
2536 | 184 | var next = findChild(previewRow, "nextButton"); | ||
2537 | 185 | var pageHelper = previewRow.pageHelper; | ||
2538 | 186 | |||
2539 | 187 | testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
2540 | 188 | |||
2541 | 189 | documentCountSpy.wait(); | ||
2542 | 190 | compare(documentCountSpy.count, 1); | ||
2543 | 191 | |||
2544 | 192 | // Check with multi page doc, next button becomes enabled | ||
2545 | 193 | compare(testDocument.count, 3); | ||
2546 | 194 | compare(next.enabled, true); | ||
2547 | 195 | compare(pageHelper.page, 0); | ||
2548 | 196 | |||
2549 | 197 | // Check the requested image page is 0 | ||
2550 | 198 | // image://poppler/0/true/file:///path/to/file.pdf | ||
2551 | 199 | compare(image.source.toString().slice(0, 17), "image://poppler/0"); | ||
2552 | 200 | |||
2553 | 201 | // Click to the next page, check still enabled | ||
2554 | 202 | mouseClick(next); | ||
2555 | 203 | tryCompare(pageHelper, "page", 1); | ||
2556 | 204 | compare(next.enabled, true); | ||
2557 | 205 | |||
2558 | 206 | // Check the requested image page is 1 | ||
2559 | 207 | // image://poppler/1/true/file:///path/to/file.pdf | ||
2560 | 208 | compare(image.source.toString().slice(0, 17), "image://poppler/1"); | ||
2561 | 209 | |||
2562 | 210 | // Click to the last page, check next becomes diabled | ||
2563 | 211 | mouseClick(next); | ||
2564 | 212 | |||
2565 | 213 | // Change the document | ||
2566 | 214 | testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
2567 | 215 | |||
2568 | 216 | // Ensure that the image has a valid state | ||
2569 | 217 | tryCompare(image, "status", Image.Ready); | ||
2570 | 218 | tryCompare(pageHelper, "page", 2); | ||
2571 | 219 | compare(next.enabled, false); | ||
2572 | 220 | |||
2573 | 221 | // Check the requested image page is 2 | ||
2574 | 222 | // image://poppler/2/true/file:///path/to/file.pdf | ||
2575 | 223 | compare(image.source.toString().slice(0, 17), "image://poppler/2"); | ||
2576 | 224 | } | ||
2577 | 225 | |||
2578 | 226 | function test_page_previous() { | ||
2579 | 227 | var image = findChild(previewRow, "previewImage"); | ||
2580 | 228 | var previous = findChild(previewRow, "previousButton"); | ||
2581 | 229 | var pageHelper = previewRow.pageHelper; | ||
2582 | 230 | |||
2583 | 231 | testDocument.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
2584 | 232 | |||
2585 | 233 | documentCountSpy.wait(); | ||
2586 | 234 | compare(documentCountSpy.count, 1); | ||
2587 | 235 | |||
2588 | 236 | // Check with mulit page doc, previous is still disabled when on 1st | ||
2589 | 237 | compare(testDocument.count, 3); | ||
2590 | 238 | compare(previous.enabled, false); | ||
2591 | 239 | compare(pageHelper.page, 0) | ||
2592 | 240 | |||
2593 | 241 | // Check the requested image page is 0 | ||
2594 | 242 | // image://poppler/0/true/file:///path/to/file.pdf | ||
2595 | 243 | compare(image.source.toString().slice(0, 17), "image://poppler/0"); | ||
2596 | 244 | |||
2597 | 245 | // Check when changing to the last page, previous is enabled | ||
2598 | 246 | pageHelper.page = 2; | ||
2599 | 247 | tryCompare(pageHelper, "page", 2); | ||
2600 | 248 | compare(previous.enabled, true); | ||
2601 | 249 | |||
2602 | 250 | // Check the requested image page is 2 | ||
2603 | 251 | // image://poppler/2/true/file:///path/to/file.pdf | ||
2604 | 252 | compare(image.source.toString().slice(0, 17), "image://poppler/2"); | ||
2605 | 253 | |||
2606 | 254 | // Click to the previous page, check still enabled | ||
2607 | 255 | mouseClick(previous); | ||
2608 | 256 | tryCompare(pageHelper, "page", 1); | ||
2609 | 257 | compare(previous.enabled, true); | ||
2610 | 258 | |||
2611 | 259 | // Check the requested image page is 1 | ||
2612 | 260 | // image://poppler/1/true/file:///path/to/file.pdf | ||
2613 | 261 | compare(image.source.toString().slice(0, 17), "image://poppler/1"); | ||
2614 | 262 | |||
2615 | 263 | // Click to the first page, check previous becomes disabled | ||
2616 | 264 | mouseClick(previous); | ||
2617 | 265 | tryCompare(pageHelper, "page", 0); | ||
2618 | 266 | compare(previous.enabled, false); | ||
2619 | 267 | |||
2620 | 268 | // Check the requested image page is 0 | ||
2621 | 269 | // image://poppler/0/true/file:///path/to/file.pdf | ||
2622 | 270 | compare(image.source.toString().slice(0, 17), "image://poppler/0"); | ||
2623 | 271 | } | ||
2624 | 272 | |||
2625 | 273 | function test_printerJob_color() { | ||
2626 | 274 | var image = findChild(previewRow, "previewImage"); | ||
2627 | 275 | mockPrinterJob.colorModelType = PrinterEnum.ColorType; | ||
2628 | 276 | |||
2629 | 277 | waitForRendering(image); | ||
2630 | 278 | |||
2631 | 279 | // Check the image requested is color | ||
2632 | 280 | // image://poppler/0/true/file:///path/to/file.pdf | ||
2633 | 281 | compare(image.source.toString().slice(0, 22), "image://poppler/0/true"); | ||
2634 | 282 | } | ||
2635 | 283 | |||
2636 | 284 | function test_printerJob_grayscale() { | ||
2637 | 285 | var image = findChild(previewRow, "previewImage"); | ||
2638 | 286 | mockPrinterJob.colorModelType = PrinterEnum.GrayType; | ||
2639 | 287 | |||
2640 | 288 | waitForRendering(image); | ||
2641 | 289 | |||
2642 | 290 | // Check the image requested is grayscale | ||
2643 | 291 | // image://poppler/0/false/file:///path/to/file.pdf | ||
2644 | 292 | compare(image.source.toString().slice(0, 23), "image://poppler/0/false"); | ||
2645 | 293 | } | ||
2646 | 294 | |||
2647 | 295 | function test_view() { | ||
2648 | 296 | // test that the implicitHeight is set from the view height | ||
2649 | 297 | var pageHelper = previewRow.pageHelper; | ||
2650 | 298 | |||
2651 | 299 | // min((WIDTH - 10) / ASPECT, HEIGHT / 1.5) | ||
2652 | 300 | |||
2653 | 301 | // height/width of 100GU, aspect is 0.71 | ||
2654 | 302 | // min((100 - 10) / 0.71, 100 / 1.5) | ||
2655 | 303 | // min(126.76, 66.66) | ||
2656 | 304 | fuzzyCompare(previewRow.implicitHeight, units.gu(66.66), units.gu(1)); | ||
2657 | 305 | |||
2658 | 306 | // Change the view to have a short width | ||
2659 | 307 | mockView.width = units.gu(50); | ||
2660 | 308 | waitForRendering(previewRow); | ||
2661 | 309 | |||
2662 | 310 | // width 50GU, height 100GU, aspect is 0.71 | ||
2663 | 311 | // min((50 - 10) / 0.71, 100 / 1.5) | ||
2664 | 312 | // min(56.33, 66.66) | ||
2665 | 313 | fuzzyCompare(previewRow.implicitHeight, units.gu(56.33), units.gu(1)); | ||
2666 | 314 | } | ||
2667 | 315 | } | ||
2668 | 316 | } | ||
2669 | 0 | 317 | ||
2670 | === added file 'tests/qmltests/tst_PrintPage.qml' | |||
2671 | --- tests/qmltests/tst_PrintPage.qml 1970-01-01 00:00:00 +0000 | |||
2672 | +++ tests/qmltests/tst_PrintPage.qml 2017-02-08 21:32:20 +0000 | |||
2673 | @@ -0,0 +1,437 @@ | |||
2674 | 1 | /* | ||
2675 | 2 | * Copyright 2017 Canonical Ltd. | ||
2676 | 3 | * | ||
2677 | 4 | * This file is part of ubuntu-printing-app. | ||
2678 | 5 | * | ||
2679 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
2680 | 7 | * it under the terms of the GNU General Public License as published by | ||
2681 | 8 | * the Free Software Foundation; version 3. | ||
2682 | 9 | * | ||
2683 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
2684 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2685 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2686 | 13 | * GNU General Public License for more details. | ||
2687 | 14 | * | ||
2688 | 15 | * You should have received a copy of the GNU General Public License | ||
2689 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2690 | 17 | * | ||
2691 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
2692 | 19 | */ | ||
2693 | 20 | import QtQuick 2.4 | ||
2694 | 21 | import QtTest 1.1 | ||
2695 | 22 | import Ubuntu.Test 1.0 | ||
2696 | 23 | import "../../ubuntu-printing-app/pages" | ||
2697 | 24 | |||
2698 | 25 | import UbuntuPrintingApp 1.0 | ||
2699 | 26 | import Ubuntu.Settings.Printers 0.1 | ||
2700 | 27 | |||
2701 | 28 | Item { | ||
2702 | 29 | width: units.gu(100) | ||
2703 | 30 | height: units.gu(75) | ||
2704 | 31 | |||
2705 | 32 | // Mock the PrintingHelper | ||
2706 | 33 | QtObject { | ||
2707 | 34 | id: mockPrinting | ||
2708 | 35 | |||
2709 | 36 | property ListModel model: ListModel { | ||
2710 | 37 | |||
2711 | 38 | } | ||
2712 | 39 | property bool pdfMode: false | ||
2713 | 40 | property var printer: QtObject { | ||
2714 | 41 | property string name: "PrinterA" | ||
2715 | 42 | property var supportedColorModels: [] | ||
2716 | 43 | property var supportedDuplexModes: [] | ||
2717 | 44 | property var supportedPrintQualities: [] | ||
2718 | 45 | } | ||
2719 | 46 | property var printerJob: QtObject { | ||
2720 | 47 | property bool collate: true | ||
2721 | 48 | property int colorModel: 0 | ||
2722 | 49 | property int copies: 1 | ||
2723 | 50 | property int duplexMode: 0 | ||
2724 | 51 | property bool isTwoSided: false | ||
2725 | 52 | property string printRange: "" | ||
2726 | 53 | property var printRangeMode: 0 // var as it needs to be enum | ||
2727 | 54 | property int quality: 0 | ||
2728 | 55 | property bool reverse: false | ||
2729 | 56 | } | ||
2730 | 57 | property int printerSelectedIndex: 0 | ||
2731 | 58 | } | ||
2732 | 59 | |||
2733 | 60 | Document { | ||
2734 | 61 | id: document | ||
2735 | 62 | url: Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf") | ||
2736 | 63 | } | ||
2737 | 64 | |||
2738 | 65 | PrintPage { | ||
2739 | 66 | id: printPage | ||
2740 | 67 | anchors { | ||
2741 | 68 | fill: parent | ||
2742 | 69 | } | ||
2743 | 70 | currentDocument: document | ||
2744 | 71 | printing: mockPrinting | ||
2745 | 72 | } | ||
2746 | 73 | |||
2747 | 74 | SignalSpy { | ||
2748 | 75 | id: cancelSpy | ||
2749 | 76 | signalName: "cancel" | ||
2750 | 77 | target: printPage | ||
2751 | 78 | } | ||
2752 | 79 | |||
2753 | 80 | SignalSpy { | ||
2754 | 81 | id: confirmSpy | ||
2755 | 82 | signalName: "confirm" | ||
2756 | 83 | target: printPage | ||
2757 | 84 | } | ||
2758 | 85 | |||
2759 | 86 | UbuntuTestCase { | ||
2760 | 87 | name: "PrintPageTestCase" | ||
2761 | 88 | |||
2762 | 89 | when: windowShown | ||
2763 | 90 | |||
2764 | 91 | property var dataColorModels: ["A", "B", "C"] | ||
2765 | 92 | property var dataDuplexModes: ["A", "B", "C"] | ||
2766 | 93 | property var dataPrinters: [ | ||
2767 | 94 | {name: "PrinterA"}, | ||
2768 | 95 | {name: "PrinterB"}, | ||
2769 | 96 | ] | ||
2770 | 97 | property var dataPrintQualities: ["A", "B", "C"] | ||
2771 | 98 | readonly property int timeout: 1000 | ||
2772 | 99 | |||
2773 | 100 | function init() { | ||
2774 | 101 | document.url = Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf"); | ||
2775 | 102 | |||
2776 | 103 | mockPrinting.model.clear(); | ||
2777 | 104 | for (var i=0; i < dataPrinters.length; i++) { | ||
2778 | 105 | mockPrinting.model.append(dataPrinters[i]); | ||
2779 | 106 | } | ||
2780 | 107 | |||
2781 | 108 | mockPrinting.pdfMode = false; | ||
2782 | 109 | |||
2783 | 110 | mockPrinting.printer.supportedColorModels = dataColorModels; | ||
2784 | 111 | mockPrinting.printer.supportedDuplexModes = dataDuplexModes; | ||
2785 | 112 | mockPrinting.printer.supportedPrintQualities = dataPrintQualities; | ||
2786 | 113 | |||
2787 | 114 | mockPrinting.printerJob.collate = true; | ||
2788 | 115 | mockPrinting.printerJob.copies = 1; | ||
2789 | 116 | mockPrinting.printerJob.printRangeMode = PrinterEnum.AllPages; | ||
2790 | 117 | mockPrinting.printerJob.reverse = false; | ||
2791 | 118 | |||
2792 | 119 | mockPrinting.printerSelectedIndex = 0; | ||
2793 | 120 | |||
2794 | 121 | cancelSpy.clear(); | ||
2795 | 122 | confirmSpy.clear(); | ||
2796 | 123 | |||
2797 | 124 | waitForRendering(printPage, timeout); | ||
2798 | 125 | } | ||
2799 | 126 | |||
2800 | 127 | function test_cancelButton() { | ||
2801 | 128 | var cancel = findChild(printPage, "cancel"); | ||
2802 | 129 | |||
2803 | 130 | // Click the cancel button | ||
2804 | 131 | mouseClick(cancel); | ||
2805 | 132 | |||
2806 | 133 | // Check that cancel signal was emitted | ||
2807 | 134 | cancelSpy.wait(); | ||
2808 | 135 | compare(cancelSpy.count, 1); | ||
2809 | 136 | } | ||
2810 | 137 | |||
2811 | 138 | function test_cancelHeader() { | ||
2812 | 139 | // Note SDK adds _button to objectNames in ActionBar | ||
2813 | 140 | var cancel = findChild(printPage, "headerBack_button"); | ||
2814 | 141 | |||
2815 | 142 | // Click cancel in the header | ||
2816 | 143 | mouseClick(cancel); | ||
2817 | 144 | |||
2818 | 145 | // Check that cancel signal was emitted | ||
2819 | 146 | cancelSpy.wait(); | ||
2820 | 147 | compare(cancelSpy.count, 1); | ||
2821 | 148 | } | ||
2822 | 149 | |||
2823 | 150 | function test_collate() { | ||
2824 | 151 | // Set copies to 2, so collate is enabled | ||
2825 | 152 | mockPrinting.printerJob.copies = 2; | ||
2826 | 153 | tryCompare(mockPrinting.printerJob, "copies", 2); | ||
2827 | 154 | |||
2828 | 155 | // Check starting value of collate is correct | ||
2829 | 156 | var collate = findChild(printPage, "collateCheckBox"); | ||
2830 | 157 | compare(collate.enabled, true); | ||
2831 | 158 | compare(collate.checked, true); | ||
2832 | 159 | |||
2833 | 160 | // Click on the checkbox | ||
2834 | 161 | mouseClick(collate); | ||
2835 | 162 | |||
2836 | 163 | // Check that the value of collate has flipped | ||
2837 | 164 | tryCompare(collate, "checked", false, timeout); | ||
2838 | 165 | compare(mockPrinting.printerJob.collate, false); | ||
2839 | 166 | } | ||
2840 | 167 | |||
2841 | 168 | function test_collate_disabled() { | ||
2842 | 169 | // Check collate is disabled when copies is 1 | ||
2843 | 170 | var collate = findChild(printPage, "collateCheckBox"); | ||
2844 | 171 | compare(mockPrinting.printerJob.copies, 1); | ||
2845 | 172 | compare(collate.enabled, false); | ||
2846 | 173 | |||
2847 | 174 | // Check that is becomes enabled when there are two copies | ||
2848 | 175 | mockPrinting.printerJob.copies = 2; | ||
2849 | 176 | tryCompare(collate, "enabled", true); | ||
2850 | 177 | } | ||
2851 | 178 | |||
2852 | 179 | function test_colorModel() { | ||
2853 | 180 | var colorModel = findChild(printPage, "colorModelSelector"); | ||
2854 | 181 | |||
2855 | 182 | // Check color model length is correct | ||
2856 | 183 | compare(colorModel.model.length, dataColorModels.length); | ||
2857 | 184 | |||
2858 | 185 | // Check each of the options has the correct text | ||
2859 | 186 | for (var i=0; i < dataColorModels.length; i++) { | ||
2860 | 187 | var option = findChild(colorModel, "option" + i); | ||
2861 | 188 | compare(option.text, dataColorModels[i]); | ||
2862 | 189 | } | ||
2863 | 190 | } | ||
2864 | 191 | |||
2865 | 192 | function test_colorModelEmptyModels() { | ||
2866 | 193 | // Set the colorModel to empty | ||
2867 | 194 | var colorModel = findChild(printPage, "colorModelSelector"); | ||
2868 | 195 | mockPrinting.printer.supportedColorModels = []; | ||
2869 | 196 | |||
2870 | 197 | waitForRendering(colorModel, timeout) | ||
2871 | 198 | |||
2872 | 199 | // Check that the selector becomes disabled | ||
2873 | 200 | compare(colorModel.enabled, false); | ||
2874 | 201 | } | ||
2875 | 202 | |||
2876 | 203 | function test_colorModelSingleModel() { | ||
2877 | 204 | // Set the colorModel to a single entry | ||
2878 | 205 | var colorModel = findChild(printPage, "colorModelSelector"); | ||
2879 | 206 | mockPrinting.printer.supportedColorModels = ["A"]; | ||
2880 | 207 | |||
2881 | 208 | waitForRendering(colorModel, timeout) | ||
2882 | 209 | |||
2883 | 210 | // Check that the selector becomes disabled | ||
2884 | 211 | compare(colorModel.enabled, false); | ||
2885 | 212 | } | ||
2886 | 213 | |||
2887 | 214 | function test_confirm() { | ||
2888 | 215 | var confirm = findChild(printPage, "confirm"); | ||
2889 | 216 | |||
2890 | 217 | // Click the confirm button | ||
2891 | 218 | mouseClick(confirm); | ||
2892 | 219 | |||
2893 | 220 | // Check that the confirm signal was emitted | ||
2894 | 221 | confirmSpy.wait(); | ||
2895 | 222 | compare(confirmSpy.count, 1); | ||
2896 | 223 | compare(confirmSpy.signalArguments.length, 1); | ||
2897 | 224 | |||
2898 | 225 | // Check the arg in the signal was the document url | ||
2899 | 226 | var arg = confirmSpy.signalArguments.pop(); | ||
2900 | 227 | compare(arg.length, 1); | ||
2901 | 228 | compare(arg[0], document.url); | ||
2902 | 229 | } | ||
2903 | 230 | |||
2904 | 231 | function test_copies() { | ||
2905 | 232 | // Check copies starting value is correct | ||
2906 | 233 | var copies = findChild(printPage, "copiesTextField"); | ||
2907 | 234 | compare(copies.value, "1"); | ||
2908 | 235 | |||
2909 | 236 | // Change the copies value and check the textField changes | ||
2910 | 237 | mockPrinting.printerJob.copies = 5; | ||
2911 | 238 | tryCompare(copies, "value", "5", timeout, "Copies value did not change"); | ||
2912 | 239 | } | ||
2913 | 240 | |||
2914 | 241 | function test_copiesKeyClick() { | ||
2915 | 242 | // Check copies starting value is correct | ||
2916 | 243 | var copies = findChild(printPage, "copiesTextField"); | ||
2917 | 244 | compare(copies.value, "1"); | ||
2918 | 245 | |||
2919 | 246 | // Click on the textField | ||
2920 | 247 | mouseClick(copies); | ||
2921 | 248 | |||
2922 | 249 | // Clear the current text and enter "2" | ||
2923 | 250 | keyClick(Qt.Key_Backspace); | ||
2924 | 251 | keyClick(Qt.Key_2); | ||
2925 | 252 | |||
2926 | 253 | // Check that "2" is set to the backend | ||
2927 | 254 | tryCompare(copies, "value", "2", timeout, "Copies value did not change"); | ||
2928 | 255 | compare(mockPrinting.printerJob.copies, 2); | ||
2929 | 256 | } | ||
2930 | 257 | |||
2931 | 258 | function test_duplex() { | ||
2932 | 259 | var duplex = findChild(printPage, "duplexSelector"); | ||
2933 | 260 | |||
2934 | 261 | // Check the duplex model length is correct | ||
2935 | 262 | compare(duplex.model.length, dataDuplexModes.length); | ||
2936 | 263 | |||
2937 | 264 | // Check each of the options has the correct text | ||
2938 | 265 | for (var i=0; i < dataDuplexModes.length; i++) { | ||
2939 | 266 | var option = findChild(duplex, "option" + i); | ||
2940 | 267 | compare(option.text, dataDuplexModes[i]); | ||
2941 | 268 | } | ||
2942 | 269 | } | ||
2943 | 270 | |||
2944 | 271 | function test_duplexEmptyModes() { | ||
2945 | 272 | // Set the duplexModes to empty and with a multipage doc | ||
2946 | 273 | var duplex = findChild(printPage, "duplexSelector"); | ||
2947 | 274 | document.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
2948 | 275 | mockPrinting.printer.supportedDuplexModes = []; | ||
2949 | 276 | |||
2950 | 277 | // Check the selector becomes disabled | ||
2951 | 278 | waitForRendering(duplex, timeout) | ||
2952 | 279 | compare(duplex.enabled, false); | ||
2953 | 280 | } | ||
2954 | 281 | function test_duplexEnabledMultiPage() { | ||
2955 | 282 | var duplex = findChild(printPage, "duplexSelector"); | ||
2956 | 283 | |||
2957 | 284 | // Check that with single page doc duplex is disabled | ||
2958 | 285 | document.url = Qt.resolvedUrl("../resources/pdf/a4_portrait.pdf"); | ||
2959 | 286 | compare(duplex.enabled, false); | ||
2960 | 287 | |||
2961 | 288 | // Check with multi page doc, duplex becomes enabled | ||
2962 | 289 | document.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
2963 | 290 | tryCompare(duplex, "enabled", true, timeout, | ||
2964 | 291 | "Duplex selected didn't become enabled when document changed"); | ||
2965 | 292 | } | ||
2966 | 293 | function test_duplexSingleMode() { | ||
2967 | 294 | // Set the duplexModes to a single entry and with a multipage doc | ||
2968 | 295 | var duplex = findChild(printPage, "duplexSelector"); | ||
2969 | 296 | document.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
2970 | 297 | mockPrinting.printer.supportedDuplexModes = ["A"]; | ||
2971 | 298 | |||
2972 | 299 | // Check the selector becomes disabled | ||
2973 | 300 | waitForRendering(duplex, timeout) | ||
2974 | 301 | compare(duplex.enabled, false); | ||
2975 | 302 | } | ||
2976 | 303 | |||
2977 | 304 | function testPdfMode() { | ||
2978 | 305 | var objects = ["collateCheckBox", "copiesTextField", | ||
2979 | 306 | "duplexSelector", "pageRangeSelector", | ||
2980 | 307 | "pageRangeTextField", "pageRangeLabel", | ||
2981 | 308 | "colorModelSelector", "qualitySelector", | ||
2982 | 309 | "reverseCheckBox"]; | ||
2983 | 310 | var pageTitle = printPage.title; | ||
2984 | 311 | |||
2985 | 312 | // Enable pdf mode | ||
2986 | 313 | mockPrinting.pdfMode = true; | ||
2987 | 314 | waitForRendering(printPage, timeout); | ||
2988 | 315 | |||
2989 | 316 | // Check that all the selectors become disabled | ||
2990 | 317 | for (var obj in objects) { | ||
2991 | 318 | compare(findChild(printPage, obj).enabled, false); | ||
2992 | 319 | } | ||
2993 | 320 | |||
2994 | 321 | // Check that the page title changes | ||
2995 | 322 | verify(pageTitle !== printPage.title, "Page title did not change"); | ||
2996 | 323 | } | ||
2997 | 324 | |||
2998 | 325 | function test_printers() { | ||
2999 | 326 | var printers = findChild(printPage, "printerSelector"); | ||
3000 | 327 | |||
3001 | 328 | // Check that the printers model length is correct | ||
3002 | 329 | compare(printers.model.count, dataPrinters.length); | ||
3003 | 330 | |||
3004 | 331 | // Check each of the options has the correct text | ||
3005 | 332 | for (var i=0; i < dataPrinters.length; i++) { | ||
3006 | 333 | var option = findChild(printers, "option" + i); | ||
3007 | 334 | compare(option.text, dataPrinters[i]["name"]); | ||
3008 | 335 | } | ||
3009 | 336 | } | ||
3010 | 337 | |||
3011 | 338 | function test_printRangeMode() { | ||
3012 | 339 | var printRangeMode = findChild(printPage, "pageRangeSelector"); | ||
3013 | 340 | var printRange = findChild(printPage, "pageRangeTextField"); | ||
3014 | 341 | |||
3015 | 342 | // Check that with AllPages, printRange is not visible | ||
3016 | 343 | compare(mockPrinting.printerJob.printRangeMode, PrinterEnum.AllPages); | ||
3017 | 344 | compare(printRange.visible, false); | ||
3018 | 345 | |||
3019 | 346 | // Change to PageRange mode | ||
3020 | 347 | mockPrinting.printerJob.printRangeMode = PrinterEnum.PageRange; | ||
3021 | 348 | |||
3022 | 349 | // Check that printRange becomes visible | ||
3023 | 350 | compare(mockPrinting.printerJob.printRangeMode, PrinterEnum.PageRange); | ||
3024 | 351 | tryCompare(printRange, "visible", true, timeout); | ||
3025 | 352 | } | ||
3026 | 353 | |||
3027 | 354 | function test_quality() { | ||
3028 | 355 | var quality = findChild(printPage, "qualitySelector"); | ||
3029 | 356 | |||
3030 | 357 | // Check that the qualities model length is correct | ||
3031 | 358 | compare(quality.model.length, dataPrintQualities.length); | ||
3032 | 359 | |||
3033 | 360 | // Check each of the options has the correct text | ||
3034 | 361 | for (var i=0; i < dataPrintQualities.length; i++) { | ||
3035 | 362 | var option = findChild(quality, "option" + i); | ||
3036 | 363 | compare(option.text, dataPrintQualities[i]); | ||
3037 | 364 | } | ||
3038 | 365 | } | ||
3039 | 366 | |||
3040 | 367 | function test_qualityEmptyModels() { | ||
3041 | 368 | // Set the qualities model to empty | ||
3042 | 369 | var quality = findChild(printPage, "qualitySelector"); | ||
3043 | 370 | mockPrinting.printer.supportedPrintQualities = []; | ||
3044 | 371 | |||
3045 | 372 | // Check that the selector becomes disabled | ||
3046 | 373 | waitForRendering(quality, timeout) | ||
3047 | 374 | compare(quality.enabled, false); | ||
3048 | 375 | } | ||
3049 | 376 | |||
3050 | 377 | function test_qualitySingleModel() { | ||
3051 | 378 | // Set the colorModel to a single entry | ||
3052 | 379 | var quality = findChild(printPage, "qualitySelector"); | ||
3053 | 380 | mockPrinting.printer.supportedPrintQualities = ["A"]; | ||
3054 | 381 | |||
3055 | 382 | // Check that the selector becomes disabled | ||
3056 | 383 | waitForRendering(quality, timeout) | ||
3057 | 384 | compare(quality.enabled, false); | ||
3058 | 385 | } | ||
3059 | 386 | |||
3060 | 387 | function test_reverse() { | ||
3061 | 388 | // Check starting value of reverse is correct | ||
3062 | 389 | var reverse = findChild(printPage, "reverseCheckBox"); | ||
3063 | 390 | compare(reverse.checked, false); | ||
3064 | 391 | |||
3065 | 392 | // Click on the checkbox | ||
3066 | 393 | mouseClick(reverse); | ||
3067 | 394 | |||
3068 | 395 | // Check that the value of reverse has flipped | ||
3069 | 396 | tryCompare(reverse, "checked", true); | ||
3070 | 397 | compare(mockPrinting.printerJob.reverse, true); | ||
3071 | 398 | } | ||
3072 | 399 | |||
3073 | 400 | function test_sheets() { | ||
3074 | 401 | var printRow = findChild(printPage, "printRow"); | ||
3075 | 402 | compare(document.count, 1); | ||
3076 | 403 | compare(mockPrinting.printerJob.copies, 1); | ||
3077 | 404 | compare(mockPrinting.printerJob.isTwoSided, false); | ||
3078 | 405 | compare(printRow.sheets, 1); | ||
3079 | 406 | |||
3080 | 407 | // Enable twoSided, we should get 0.5 rounded to 1 sheet | ||
3081 | 408 | mockPrinting.printerJob.isTwoSided = true; | ||
3082 | 409 | |||
3083 | 410 | compare(mockPrinting.printerJob.isTwoSided, true); | ||
3084 | 411 | compare(printRow.sheets, 1); | ||
3085 | 412 | |||
3086 | 413 | // Enable two copies, we should get 2 copies with duplex, so 1 sheet | ||
3087 | 414 | mockPrinting.printerJob.copies = 2; | ||
3088 | 415 | |||
3089 | 416 | compare(mockPrinting.printerJob.copies, 2); | ||
3090 | 417 | compare(printRow.sheets, 1); | ||
3091 | 418 | |||
3092 | 419 | // Disable two sided, so 2 copies and 2 sheets | ||
3093 | 420 | mockPrinting.printerJob.isTwoSided = false; | ||
3094 | 421 | |||
3095 | 422 | compare(mockPrinting.printerJob.isTwoSided, false); | ||
3096 | 423 | compare(printRow.sheets, 2); | ||
3097 | 424 | |||
3098 | 425 | // Change to a multi page document (3 pages, 2 copies so 6 sheets) | ||
3099 | 426 | document.url = Qt.resolvedUrl("../resources/pdf/mixed_portrait.pdf"); | ||
3100 | 427 | |||
3101 | 428 | compare(printRow.sheets, 6); | ||
3102 | 429 | |||
3103 | 430 | // Enable two sided, and 1 copy, check we have 3 pages, duplex so 2 sheets | ||
3104 | 431 | mockPrinting.printerJob.copies = 1; | ||
3105 | 432 | mockPrinting.printerJob.isTwoSided = true; | ||
3106 | 433 | |||
3107 | 434 | compare(printRow.sheets, 2); | ||
3108 | 435 | } | ||
3109 | 436 | } | ||
3110 | 437 | } | ||
3111 | 0 | 438 | ||
3112 | === added file 'tests/qmltests/tst_PrintRow.qml' | |||
3113 | --- tests/qmltests/tst_PrintRow.qml 1970-01-01 00:00:00 +0000 | |||
3114 | +++ tests/qmltests/tst_PrintRow.qml 2017-02-08 21:32:20 +0000 | |||
3115 | @@ -0,0 +1,110 @@ | |||
3116 | 1 | /* | ||
3117 | 2 | * Copyright 2017 Canonical Ltd. | ||
3118 | 3 | * | ||
3119 | 4 | * This file is part of ubuntu-printing-app. | ||
3120 | 5 | * | ||
3121 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
3122 | 7 | * it under the terms of the GNU General Public License as published by | ||
3123 | 8 | * the Free Software Foundation; version 3. | ||
3124 | 9 | * | ||
3125 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
3126 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3127 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3128 | 13 | * GNU General Public License for more details. | ||
3129 | 14 | * | ||
3130 | 15 | * You should have received a copy of the GNU General Public License | ||
3131 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3132 | 17 | * | ||
3133 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
3134 | 19 | */ | ||
3135 | 20 | import QtQuick 2.4 | ||
3136 | 21 | import QtTest 1.1 | ||
3137 | 22 | import Ubuntu.Test 1.0 | ||
3138 | 23 | import "../../ubuntu-printing-app/components" | ||
3139 | 24 | |||
3140 | 25 | Item { | ||
3141 | 26 | width: units.gu(100) | ||
3142 | 27 | height: units.gu(75) | ||
3143 | 28 | |||
3144 | 29 | PrintRow { | ||
3145 | 30 | id: printRow | ||
3146 | 31 | anchors { | ||
3147 | 32 | fill: parent | ||
3148 | 33 | } | ||
3149 | 34 | } | ||
3150 | 35 | |||
3151 | 36 | SignalSpy { | ||
3152 | 37 | id: cancelSignal | ||
3153 | 38 | signalName: "cancel" | ||
3154 | 39 | target: printRow | ||
3155 | 40 | } | ||
3156 | 41 | |||
3157 | 42 | SignalSpy { | ||
3158 | 43 | id: confirmSignal | ||
3159 | 44 | signalName: "confirm" | ||
3160 | 45 | target: printRow | ||
3161 | 46 | } | ||
3162 | 47 | |||
3163 | 48 | UbuntuTestCase { | ||
3164 | 49 | name: "PrintRowTestCase" | ||
3165 | 50 | |||
3166 | 51 | when: windowShown | ||
3167 | 52 | |||
3168 | 53 | |||
3169 | 54 | function init() { | ||
3170 | 55 | printRow.pdfMode = false; | ||
3171 | 56 | printRow.sheets = 0; | ||
3172 | 57 | |||
3173 | 58 | cancelSignal.clear(); | ||
3174 | 59 | confirmSignal.clear(); | ||
3175 | 60 | } | ||
3176 | 61 | |||
3177 | 62 | function test_clickCancel() { | ||
3178 | 63 | var button = findChild(printRow, "cancel"); | ||
3179 | 64 | var buttonCenter = centerOf(button); | ||
3180 | 65 | compare(cancelSignal.count, 0) | ||
3181 | 66 | |||
3182 | 67 | // Click on the cancel button | ||
3183 | 68 | mouseClick(button); | ||
3184 | 69 | |||
3185 | 70 | // Check that the cancel signal is emitted | ||
3186 | 71 | cancelSignal.wait(); | ||
3187 | 72 | compare(cancelSignal.count, 1) | ||
3188 | 73 | } | ||
3189 | 74 | |||
3190 | 75 | function test_clickConfirm() { | ||
3191 | 76 | var button = findChild(printRow, "confirm"); | ||
3192 | 77 | var buttonCenter = centerOf(button); | ||
3193 | 78 | compare(confirmSignal.count, 0) | ||
3194 | 79 | |||
3195 | 80 | // Click on the confirm button | ||
3196 | 81 | mouseClick(button); | ||
3197 | 82 | |||
3198 | 83 | // Check that the confirm signal is emitted | ||
3199 | 84 | confirmSignal.wait(); | ||
3200 | 85 | compare(confirmSignal.count, 1) | ||
3201 | 86 | } | ||
3202 | 87 | |||
3203 | 88 | function test_pdfMode() { | ||
3204 | 89 | var button = findChild(printRow, "confirm"); | ||
3205 | 90 | var originalText = button.text; | ||
3206 | 91 | |||
3207 | 92 | // Change to Pdf mode | ||
3208 | 93 | printRow.pdfMode = true; | ||
3209 | 94 | |||
3210 | 95 | // Check that the confirm button text changes | ||
3211 | 96 | verify(button.text !== originalText, 1000, "Text did not change when entering PDF Mode"); | ||
3212 | 97 | } | ||
3213 | 98 | |||
3214 | 99 | function test_sheets() { | ||
3215 | 100 | var button = findChild(printRow, "confirm"); | ||
3216 | 101 | var originalText = button.text; | ||
3217 | 102 | |||
3218 | 103 | // Change the number of sheets | ||
3219 | 104 | printRow.sheets = 10; | ||
3220 | 105 | |||
3221 | 106 | // Check that the confirm button text changes | ||
3222 | 107 | verify(button.text !== originalText, 1000, "Text did not change when changing sheets"); | ||
3223 | 108 | } | ||
3224 | 109 | } | ||
3225 | 110 | } | ||
3226 | 0 | 111 | ||
3227 | === added file 'tests/qmltests/tst_SelectorRow.qml' | |||
3228 | --- tests/qmltests/tst_SelectorRow.qml 1970-01-01 00:00:00 +0000 | |||
3229 | +++ tests/qmltests/tst_SelectorRow.qml 2017-02-08 21:32:20 +0000 | |||
3230 | @@ -0,0 +1,136 @@ | |||
3231 | 1 | /* | ||
3232 | 2 | * Copyright 2017 Canonical Ltd. | ||
3233 | 3 | * | ||
3234 | 4 | * This file is part of ubuntu-printing-app. | ||
3235 | 5 | * | ||
3236 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
3237 | 7 | * it under the terms of the GNU General Public License as published by | ||
3238 | 8 | * the Free Software Foundation; version 3. | ||
3239 | 9 | * | ||
3240 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
3241 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3242 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3243 | 13 | * GNU General Public License for more details. | ||
3244 | 14 | * | ||
3245 | 15 | * You should have received a copy of the GNU General Public License | ||
3246 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3247 | 17 | * | ||
3248 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
3249 | 19 | */ | ||
3250 | 20 | import QtQuick 2.4 | ||
3251 | 21 | import QtTest 1.1 | ||
3252 | 22 | import Ubuntu.Test 1.0 | ||
3253 | 23 | import "../../ubuntu-printing-app/components" | ||
3254 | 24 | |||
3255 | 25 | Item { | ||
3256 | 26 | width: units.gu(100) | ||
3257 | 27 | height: units.gu(75) | ||
3258 | 28 | |||
3259 | 29 | SelectorRow { | ||
3260 | 30 | id: selectorRow | ||
3261 | 31 | model: [] | ||
3262 | 32 | } | ||
3263 | 33 | |||
3264 | 34 | SignalSpy { | ||
3265 | 35 | id: expansionCompletedSpy | ||
3266 | 36 | signalName: "expansionCompleted" | ||
3267 | 37 | target: selectorRow | ||
3268 | 38 | } | ||
3269 | 39 | |||
3270 | 40 | SignalSpy { | ||
3271 | 41 | id: selectedIndexSpy | ||
3272 | 42 | signalName: "onSelectedIndexChanged" | ||
3273 | 43 | target: selectorRow | ||
3274 | 44 | } | ||
3275 | 45 | |||
3276 | 46 | SignalSpy { | ||
3277 | 47 | id: selectedValueSpy | ||
3278 | 48 | signalName: "onSelectedValueChanged" | ||
3279 | 49 | target: selectorRow | ||
3280 | 50 | } | ||
3281 | 51 | |||
3282 | 52 | UbuntuTestCase { | ||
3283 | 53 | name: "SelectorRowTestCase" | ||
3284 | 54 | when: windowShown | ||
3285 | 55 | |||
3286 | 56 | readonly property string dataLabelText: "Text" | ||
3287 | 57 | readonly property var dataModel: ["A", "B", "C"] | ||
3288 | 58 | readonly property int dataSelectedIndex: 0 | ||
3289 | 59 | readonly property int dataSecondarySelectedIndex: 1 | ||
3290 | 60 | |||
3291 | 61 | function init() { | ||
3292 | 62 | selectorRow.model = dataModel; | ||
3293 | 63 | selectorRow.selectedIndex = dataSelectedIndex; | ||
3294 | 64 | selectorRow.text = dataLabelText; | ||
3295 | 65 | |||
3296 | 66 | expansionCompletedSpy.clear(); | ||
3297 | 67 | selectedIndexSpy.clear(); | ||
3298 | 68 | selectedValueSpy.clear(); | ||
3299 | 69 | |||
3300 | 70 | waitForRendering(selectorRow); | ||
3301 | 71 | } | ||
3302 | 72 | |||
3303 | 73 | function test_changeOption() { | ||
3304 | 74 | // Check selectedIndex is the starting index | ||
3305 | 75 | compare(selectorRow.selectedIndex, dataSelectedIndex); | ||
3306 | 76 | |||
3307 | 77 | // Expand the selector | ||
3308 | 78 | mouseClick(selectorRow); | ||
3309 | 79 | expansionCompletedSpy.wait(); | ||
3310 | 80 | compare(expansionCompletedSpy.count, 1); | ||
3311 | 81 | |||
3312 | 82 | // Click on the secondary index | ||
3313 | 83 | var option1 = findChild(selectorRow, "option" + dataSecondarySelectedIndex); | ||
3314 | 84 | mouseClick(option1); | ||
3315 | 85 | |||
3316 | 86 | // Check that the selectedIndex is the secondaryIndex | ||
3317 | 87 | selectedIndexSpy.wait(); | ||
3318 | 88 | compare(selectedIndexSpy.count, 1); | ||
3319 | 89 | compare(selectorRow.selectedIndex, dataSecondarySelectedIndex); | ||
3320 | 90 | } | ||
3321 | 91 | |||
3322 | 92 | function test_label() { | ||
3323 | 93 | // Check that the label is correct | ||
3324 | 94 | var label = findChild(selectorRow, "label"); | ||
3325 | 95 | compare(label.text, dataLabelText); | ||
3326 | 96 | } | ||
3327 | 97 | |||
3328 | 98 | function test_model() { | ||
3329 | 99 | // Check the model length is the starting value | ||
3330 | 100 | compare(selectorRow.model.length, dataModel.length); | ||
3331 | 101 | |||
3332 | 102 | // Remove the last entry from the model | ||
3333 | 103 | var tmpModel = dataModel; | ||
3334 | 104 | tmpModel.pop(); | ||
3335 | 105 | selectorRow.model = tmpModel; | ||
3336 | 106 | |||
3337 | 107 | // Check the model length changed | ||
3338 | 108 | compare(selectorRow.model.length, tmpModel.length); | ||
3339 | 109 | } | ||
3340 | 110 | |||
3341 | 111 | function test_selectedIndex() { | ||
3342 | 112 | // Check selectedIndex is the starting index | ||
3343 | 113 | compare(selectorRow.selectedIndex, dataSelectedIndex); | ||
3344 | 114 | |||
3345 | 115 | // Change the index to the secondaryIndex | ||
3346 | 116 | selectorRow.selectedIndex = dataSecondarySelectedIndex; | ||
3347 | 117 | |||
3348 | 118 | // Check the index changed | ||
3349 | 119 | selectedIndexSpy.wait(); | ||
3350 | 120 | compare(selectedIndexSpy.count, 1); | ||
3351 | 121 | compare(selectorRow.selectedIndex, dataSecondarySelectedIndex); | ||
3352 | 122 | } | ||
3353 | 123 | |||
3354 | 124 | function test_selectedValue() { | ||
3355 | 125 | // Check that selectedValue is the starting value | ||
3356 | 126 | compare(selectorRow.selectedValue, dataModel[dataSelectedIndex]); | ||
3357 | 127 | |||
3358 | 128 | // Change to the secondaryIndex | ||
3359 | 129 | selectorRow.selectedIndex = dataSecondarySelectedIndex; | ||
3360 | 130 | |||
3361 | 131 | // Check that the selectedValue changes | ||
3362 | 132 | selectedValueSpy.wait(); | ||
3363 | 133 | compare(selectorRow.selectedValue, dataModel[dataSecondarySelectedIndex]); | ||
3364 | 134 | } | ||
3365 | 135 | } | ||
3366 | 136 | } | ||
3367 | 0 | 137 | ||
3368 | === added file 'tests/qmltests/tst_TextFieldRow.qml' | |||
3369 | --- tests/qmltests/tst_TextFieldRow.qml 1970-01-01 00:00:00 +0000 | |||
3370 | +++ tests/qmltests/tst_TextFieldRow.qml 2017-02-08 21:32:20 +0000 | |||
3371 | @@ -0,0 +1,174 @@ | |||
3372 | 1 | /* | ||
3373 | 2 | * Copyright 2017 Canonical Ltd. | ||
3374 | 3 | * | ||
3375 | 4 | * This file is part of ubuntu-printing-app. | ||
3376 | 5 | * | ||
3377 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
3378 | 7 | * it under the terms of the GNU General Public License as published by | ||
3379 | 8 | * the Free Software Foundation; version 3. | ||
3380 | 9 | * | ||
3381 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
3382 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3383 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3384 | 13 | * GNU General Public License for more details. | ||
3385 | 14 | * | ||
3386 | 15 | * You should have received a copy of the GNU General Public License | ||
3387 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3388 | 17 | * | ||
3389 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
3390 | 19 | */ | ||
3391 | 20 | import QtQuick 2.4 | ||
3392 | 21 | import QtTest 1.1 | ||
3393 | 22 | import Ubuntu.Test 1.0 | ||
3394 | 23 | import "../../ubuntu-printing-app/components" | ||
3395 | 24 | |||
3396 | 25 | Item { | ||
3397 | 26 | width: units.gu(100) | ||
3398 | 27 | height: units.gu(75) | ||
3399 | 28 | |||
3400 | 29 | TextFieldRow { | ||
3401 | 30 | id: textFieldRow | ||
3402 | 31 | } | ||
3403 | 32 | |||
3404 | 33 | IntValidator { | ||
3405 | 34 | id: intValidator | ||
3406 | 35 | bottom: 1 | ||
3407 | 36 | top: 9 | ||
3408 | 37 | } | ||
3409 | 38 | |||
3410 | 39 | SignalSpy { | ||
3411 | 40 | id: acceptableInputSpy | ||
3412 | 41 | signalName: "onAcceptableInputChanged" | ||
3413 | 42 | target: textFieldRow | ||
3414 | 43 | } | ||
3415 | 44 | |||
3416 | 45 | SignalSpy { | ||
3417 | 46 | id: valueSpy | ||
3418 | 47 | signalName: "onValueChanged" | ||
3419 | 48 | target: textFieldRow | ||
3420 | 49 | } | ||
3421 | 50 | |||
3422 | 51 | UbuntuTestCase { | ||
3423 | 52 | name: "TextFieldRowTestCase" | ||
3424 | 53 | when: windowShown | ||
3425 | 54 | |||
3426 | 55 | readonly property bool dataEnabled: true | ||
3427 | 56 | readonly property string dataPlaceholderText: "placeholder" | ||
3428 | 57 | |||
3429 | 58 | function init() { | ||
3430 | 59 | textFieldRow.enabled = dataEnabled; | ||
3431 | 60 | textFieldRow.inputMethodHints = Qt.ImhNone; | ||
3432 | 61 | textFieldRow.placeholderText = dataPlaceholderText; | ||
3433 | 62 | textFieldRow.text = "test"; | ||
3434 | 63 | textFieldRow.validator = null; | ||
3435 | 64 | textFieldRow.value = ""; | ||
3436 | 65 | |||
3437 | 66 | acceptableInputSpy.clear(); | ||
3438 | 67 | valueSpy.clear(); | ||
3439 | 68 | |||
3440 | 69 | waitForRendering(textFieldRow); | ||
3441 | 70 | } | ||
3442 | 71 | |||
3443 | 72 | function test_acceptableInput() { | ||
3444 | 73 | var textField = findChild(textFieldRow, "textField"); | ||
3445 | 74 | |||
3446 | 75 | // Set the validator to int (1-9) | ||
3447 | 76 | textFieldRow.validator = intValidator; | ||
3448 | 77 | |||
3449 | 78 | // Set the value to an invalid value | ||
3450 | 79 | textFieldRow.value = "99"; | ||
3451 | 80 | |||
3452 | 81 | valueSpy.wait(); | ||
3453 | 82 | acceptableInputSpy.wait(); | ||
3454 | 83 | |||
3455 | 84 | compare(valueSpy.count, 1); | ||
3456 | 85 | compare(acceptableInputSpy.count, 1); | ||
3457 | 86 | |||
3458 | 87 | // Check the value was not acceptable | ||
3459 | 88 | compare(textFieldRow.acceptableInput, false); | ||
3460 | 89 | compare(textField.acceptableInput, false); | ||
3461 | 90 | |||
3462 | 91 | // Set the value to a valid value | ||
3463 | 92 | textFieldRow.value = "2"; | ||
3464 | 93 | |||
3465 | 94 | valueSpy.wait(); | ||
3466 | 95 | acceptableInputSpy.wait(); | ||
3467 | 96 | |||
3468 | 97 | compare(valueSpy.count, 2); | ||
3469 | 98 | compare(acceptableInputSpy.count, 2); | ||
3470 | 99 | |||
3471 | 100 | // Check the value was acceptable | ||
3472 | 101 | compare(textFieldRow.acceptableInput, true); | ||
3473 | 102 | compare(textField.acceptableInput, true); | ||
3474 | 103 | } | ||
3475 | 104 | |||
3476 | 105 | function test_enabled() { | ||
3477 | 106 | // Check textField enabled state is starting value | ||
3478 | 107 | var textField = findChild(textFieldRow, "textField"); | ||
3479 | 108 | compare(textFieldRow.enabled, dataEnabled); | ||
3480 | 109 | |||
3481 | 110 | // Flip the enabled state | ||
3482 | 111 | textFieldRow.enabled = !dataEnabled; | ||
3483 | 112 | |||
3484 | 113 | // Check that the enabled state changes | ||
3485 | 114 | tryCompare(textField, "enabled", !dataEnabled); | ||
3486 | 115 | } | ||
3487 | 116 | |||
3488 | 117 | function test_inputMethodHints() { | ||
3489 | 118 | // Check that inputMethodHints is starting value | ||
3490 | 119 | var textField = findChild(textFieldRow, "textField"); | ||
3491 | 120 | compare(textFieldRow.inputMethodHints, Qt.ImhNone); | ||
3492 | 121 | compare(textField.inputMethodHints, Qt.ImhNone); | ||
3493 | 122 | |||
3494 | 123 | // Change the inputMethodHints mode | ||
3495 | 124 | textFieldRow.inputMethodHints = Qt.ImhDigitsOnly; | ||
3496 | 125 | |||
3497 | 126 | // Check it changes in the textField | ||
3498 | 127 | compare(textField.inputMethodHints, Qt.ImhDigitsOnly); | ||
3499 | 128 | } | ||
3500 | 129 | |||
3501 | 130 | function test_placeholderText() { | ||
3502 | 131 | // Check the placeholder text is correct | ||
3503 | 132 | var textField = findChild(textFieldRow, "textField"); | ||
3504 | 133 | compare(textField.placeholderText, dataPlaceholderText); | ||
3505 | 134 | compare(textFieldRow.placeholderText, dataPlaceholderText); | ||
3506 | 135 | |||
3507 | 136 | // Check that the value is not the placeholder | ||
3508 | 137 | verify(textField.text !== dataPlaceholderText); | ||
3509 | 138 | verify(textFieldRow.value !== dataPlaceholderText); | ||
3510 | 139 | } | ||
3511 | 140 | |||
3512 | 141 | function test_text() { | ||
3513 | 142 | // Check that the text is the correct value | ||
3514 | 143 | var label = findChild(textFieldRow, "label"); | ||
3515 | 144 | compare(label.text, textFieldRow.text); | ||
3516 | 145 | } | ||
3517 | 146 | |||
3518 | 147 | function test_validator() { | ||
3519 | 148 | // Check that a validator can be set | ||
3520 | 149 | var textField = findChild(textFieldRow, "textField"); | ||
3521 | 150 | textFieldRow.validator = intValidator; | ||
3522 | 151 | |||
3523 | 152 | compare(textField.validator, intValidator); | ||
3524 | 153 | } | ||
3525 | 154 | |||
3526 | 155 | function test_value() { | ||
3527 | 156 | // Check that the value is the starting value | ||
3528 | 157 | var textField = findChild(textFieldRow, "textField"); | ||
3529 | 158 | compare(textFieldRow.value, ""); | ||
3530 | 159 | compare(textField.text, ""); | ||
3531 | 160 | |||
3532 | 161 | // Click on the text field | ||
3533 | 162 | mouseClick(textField); | ||
3534 | 163 | |||
3535 | 164 | // Enter "a" | ||
3536 | 165 | keyPress(Qt.Key_A); | ||
3537 | 166 | |||
3538 | 167 | // Check that "a" is set to the value | ||
3539 | 168 | valueSpy.wait(); | ||
3540 | 169 | compare(valueSpy.count, 1); | ||
3541 | 170 | compare(textField.text, "a"); | ||
3542 | 171 | compare(textFieldRow.value, "a"); | ||
3543 | 172 | } | ||
3544 | 173 | } | ||
3545 | 174 | } | ||
3546 | 0 | 175 | ||
3547 | === added directory 'tests/resources' | |||
3548 | === added file 'tests/resources/CMakeLists.txt' | |||
3549 | --- tests/resources/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
3550 | +++ tests/resources/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
3551 | @@ -0,0 +1,6 @@ | |||
3552 | 1 | add_subdirectory(pdf) | ||
3553 | 2 | |||
3554 | 3 | # Copy the test pdf files to the build dir | ||
3555 | 4 | add_custom_target(test_pdf_copyFiles ALL | ||
3556 | 5 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/pdf ${CMAKE_CURRENT_BINARY_DIR}/pdf | ||
3557 | 6 | DEPENDS ${PDF_TEST_FILES}) | ||
3558 | 0 | 7 | ||
3559 | === added directory 'tests/resources/pdf' | |||
3560 | === added file 'tests/resources/pdf/CMakeLists.txt' | |||
3561 | --- tests/resources/pdf/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
3562 | +++ tests/resources/pdf/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
3563 | @@ -0,0 +1,3 @@ | |||
3564 | 1 | # Show files in QtC | ||
3565 | 2 | file(GLOB PDF_TEST_FILES *.pdf *.txt) | ||
3566 | 3 | add_custom_target(test_pdf_files ALL SOURCES ${PDF_TEST_FILES}) | ||
3567 | 0 | 4 | ||
3568 | === added file 'tests/resources/pdf/a4_portrait.pdf' | |||
3569 | 1 | Binary 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 | 5 | Binary 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 |
3570 | === added file 'tests/resources/pdf/a5_landscape.pdf' | |||
3571 | 2 | Binary 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 | 6 | Binary 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 |
3572 | === added file 'tests/resources/pdf/color.pdf' | |||
3573 | 3 | Binary 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 | 7 | Binary 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 |
3574 | === added file 'tests/resources/pdf/corrupt.pdf' | |||
3575 | --- tests/resources/pdf/corrupt.pdf 1970-01-01 00:00:00 +0000 | |||
3576 | +++ tests/resources/pdf/corrupt.pdf 2017-02-08 21:32:20 +0000 | |||
3577 | @@ -0,0 +1,3 @@ | |||
3578 | 1 | %PDF-1.4 | ||
3579 | 2 | %äüöß | ||
3580 | 3 | %%EOF | ||
3581 | 0 | 4 | ||
3582 | === added file 'tests/resources/pdf/mixed_landscape.pdf' | |||
3583 | 1 | Binary 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 | 5 | Binary 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 |
3584 | === added file 'tests/resources/pdf/mixed_portrait.pdf' | |||
3585 | 2 | Binary 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 | 6 | Binary 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 |
3586 | === added file 'tests/resources/pdf/test_title.pdf' | |||
3587 | 3 | Binary 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 | 7 | Binary 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 |
3588 | === added file 'tests/resources/pdf/text.txt' | |||
3589 | === added directory 'tests/unittests' | |||
3590 | === added file 'tests/unittests/CMakeLists.txt' | |||
3591 | --- tests/unittests/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
3592 | +++ tests/unittests/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
3593 | @@ -0,0 +1,1 @@ | |||
3594 | 1 | add_subdirectory(backend) | ||
3595 | 0 | 2 | ||
3596 | === added directory 'tests/unittests/backend' | |||
3597 | === added file 'tests/unittests/backend/CMakeLists.txt' | |||
3598 | --- tests/unittests/backend/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
3599 | +++ tests/unittests/backend/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
3600 | @@ -0,0 +1,19 @@ | |||
3601 | 1 | include_directories( | ||
3602 | 2 | ${CMAKE_CURRENT_SOURCE_DIR} | ||
3603 | 3 | ${CMAKE_CURRENT_BINARY_DIR} | ||
3604 | 4 | ${CMAKE_SOURCE_DIR}/backend/ | ||
3605 | 5 | ) | ||
3606 | 6 | |||
3607 | 7 | find_package(Qt5Test REQUIRED) | ||
3608 | 8 | |||
3609 | 9 | add_executable(testDocument tst_document.cpp ${PDF_TEST_FILES}) | ||
3610 | 10 | target_link_libraries(testDocument UbuntuPrintingAppbackend Qt5::Test Qt5::Gui) | ||
3611 | 11 | add_test(tst_document testDocument) | ||
3612 | 12 | |||
3613 | 13 | add_executable(testPageHelper tst_pagehelper.cpp ${PDF_TEST_FILES}) | ||
3614 | 14 | target_link_libraries(testPageHelper UbuntuPrintingAppbackend Qt5::Test Qt5::Gui) | ||
3615 | 15 | add_test(tst_pagehelper testPageHelper) | ||
3616 | 16 | |||
3617 | 17 | add_executable(testPopplerImageProvider tst_popplerimageprovider.cpp ${PDF_TEST_FILES}) | ||
3618 | 18 | target_link_libraries(testPopplerImageProvider UbuntuPrintingAppbackend Qt5::Test Qt5::Gui) | ||
3619 | 19 | add_test(tst_popplerimageprovider testPopplerImageProvider) | ||
3620 | 0 | 20 | ||
3621 | === added file 'tests/unittests/backend/tst_document.cpp' | |||
3622 | --- tests/unittests/backend/tst_document.cpp 1970-01-01 00:00:00 +0000 | |||
3623 | +++ tests/unittests/backend/tst_document.cpp 2017-02-08 21:32:20 +0000 | |||
3624 | @@ -0,0 +1,301 @@ | |||
3625 | 1 | /* | ||
3626 | 2 | * Copyright 2017 Canonical Ltd. | ||
3627 | 3 | * | ||
3628 | 4 | * This file is part of ubuntu-printing-app. | ||
3629 | 5 | * | ||
3630 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
3631 | 7 | * it under the terms of the GNU General Public License as published by | ||
3632 | 8 | * the Free Software Foundation; version 3. | ||
3633 | 9 | * | ||
3634 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
3635 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3636 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3637 | 13 | * GNU General Public License for more details. | ||
3638 | 14 | * | ||
3639 | 15 | * You should have received a copy of the GNU General Public License | ||
3640 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3641 | 17 | * | ||
3642 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
3643 | 19 | */ | ||
3644 | 20 | |||
3645 | 21 | #include <QDebug> | ||
3646 | 22 | #include <QObject> | ||
3647 | 23 | #include <QSignalSpy> | ||
3648 | 24 | #include <QTest> | ||
3649 | 25 | |||
3650 | 26 | #include "UbuntuPrintingApp/document.h" | ||
3651 | 27 | |||
3652 | 28 | #define A4_PORTRAIT_SIZE QSize(595, 842) | ||
3653 | 29 | #define A4_LANDSCAPE_SIZE QSize(842, 595) | ||
3654 | 30 | #define A5_LANDSCAPE_SIZE QSize(595, 420) | ||
3655 | 31 | |||
3656 | 32 | #define INVALID_IMAGE_SIZE QSize(0, 0) | ||
3657 | 33 | #define VALID_IMAGE_SIZE QSize(100, 100) | ||
3658 | 34 | |||
3659 | 35 | Q_DECLARE_METATYPE(Document::Errors) | ||
3660 | 36 | |||
3661 | 37 | class TestDocument : public QObject | ||
3662 | 38 | { | ||
3663 | 39 | Q_OBJECT | ||
3664 | 40 | private Q_SLOTS: | ||
3665 | 41 | void init() | ||
3666 | 42 | { | ||
3667 | 43 | qRegisterMetaType<Document::Errors>("Errors"); | ||
3668 | 44 | |||
3669 | 45 | m_document = new Document(); | ||
3670 | 46 | } | ||
3671 | 47 | void cleanup() | ||
3672 | 48 | { | ||
3673 | 49 | QSignalSpy destroyedSpy(m_document, SIGNAL(destroyed(QObject*))); | ||
3674 | 50 | m_document->deleteLater(); | ||
3675 | 51 | QTRY_COMPARE(destroyedSpy.count(), 1); | ||
3676 | 52 | } | ||
3677 | 53 | QUrl getResourceUrl(const QString &resource) const | ||
3678 | 54 | { | ||
3679 | 55 | return QUrl("file://" + QDir::currentPath() + "/../../resources/pdf/" + resource); | ||
3680 | 56 | } | ||
3681 | 57 | |||
3682 | 58 | void testInit() | ||
3683 | 59 | { | ||
3684 | 60 | QCOMPARE(m_document->count(), 0); | ||
3685 | 61 | QCOMPARE(m_document->getPageSize(0), QSizeF()); | ||
3686 | 62 | QCOMPARE(m_document->getPageSize(0).isValid(), false); | ||
3687 | 63 | QCOMPARE(m_document->orientation(), Document::Portrait); | ||
3688 | 64 | QCOMPARE(m_document->title(), QStringLiteral("")); | ||
3689 | 65 | QCOMPARE(m_document->url(), QUrl(QStringLiteral(""))); | ||
3690 | 66 | } | ||
3691 | 67 | |||
3692 | 68 | void testCountSinglePage() | ||
3693 | 69 | { | ||
3694 | 70 | QSignalSpy countSpy(m_document, SIGNAL(countChanged())); | ||
3695 | 71 | m_document->setUrl(getResourceUrl("a4_portrait.pdf")); | ||
3696 | 72 | QTRY_COMPARE(countSpy.count(), 1); | ||
3697 | 73 | QCOMPARE(m_document->count(), 1); | ||
3698 | 74 | } | ||
3699 | 75 | void testCountMultiPage() | ||
3700 | 76 | { | ||
3701 | 77 | QSignalSpy countSpy(m_document, SIGNAL(countChanged())); | ||
3702 | 78 | m_document->setUrl(getResourceUrl("mixed_portrait.pdf")); | ||
3703 | 79 | QTRY_COMPARE(countSpy.count(), 1); | ||
3704 | 80 | QCOMPARE(m_document->count(), 3); | ||
3705 | 81 | } | ||
3706 | 82 | |||
3707 | 83 | void testGetPageSizeA4() | ||
3708 | 84 | { | ||
3709 | 85 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3710 | 86 | m_document->setUrl(getResourceUrl("a4_portrait.pdf")); | ||
3711 | 87 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3712 | 88 | // Use QSize to compare otherwise double's will be slightly different | ||
3713 | 89 | QCOMPARE(m_document->getPageSize(0).toSize(), A4_PORTRAIT_SIZE); | ||
3714 | 90 | } | ||
3715 | 91 | void testGetPageSizeMixed() | ||
3716 | 92 | { | ||
3717 | 93 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3718 | 94 | m_document->setUrl(getResourceUrl("mixed_portrait.pdf")); | ||
3719 | 95 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3720 | 96 | // Use QSize to compare otherwise double's will be slightly different | ||
3721 | 97 | QCOMPARE(m_document->getPageSize(0).toSize(), A4_PORTRAIT_SIZE); | ||
3722 | 98 | |||
3723 | 99 | // Check that second page size is landscape as this is a mixed document | ||
3724 | 100 | QCOMPARE(m_document->getPageSize(1).toSize(), A4_LANDSCAPE_SIZE); | ||
3725 | 101 | } | ||
3726 | 102 | void testGetPageSizeA5Landscape() | ||
3727 | 103 | { | ||
3728 | 104 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3729 | 105 | m_document->setUrl(getResourceUrl("a5_landscape.pdf")); | ||
3730 | 106 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3731 | 107 | // Use QSize to compare otherwise double's will be slightly different | ||
3732 | 108 | QCOMPARE(m_document->getPageSize(0).toSize(), A5_LANDSCAPE_SIZE); | ||
3733 | 109 | } | ||
3734 | 110 | |||
3735 | 111 | void testMakeImage() | ||
3736 | 112 | { | ||
3737 | 113 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3738 | 114 | m_document->setUrl(getResourceUrl("a4_portrait.pdf")); | ||
3739 | 115 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3740 | 116 | |||
3741 | 117 | QImage image = m_document->makeImage(VALID_IMAGE_SIZE, 0); | ||
3742 | 118 | QCOMPARE(image.isNull(), false); | ||
3743 | 119 | QCOMPARE(image.size(), VALID_IMAGE_SIZE); | ||
3744 | 120 | } | ||
3745 | 121 | void testMakeImageInvalidDocument() | ||
3746 | 122 | { | ||
3747 | 123 | QImage image = m_document->makeImage(VALID_IMAGE_SIZE, 0); | ||
3748 | 124 | QCOMPARE(image.isNull(), true); | ||
3749 | 125 | } | ||
3750 | 126 | void testMakeImageInvalidPage() | ||
3751 | 127 | { | ||
3752 | 128 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3753 | 129 | m_document->setUrl(getResourceUrl("a4_portrait.pdf")); | ||
3754 | 130 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3755 | 131 | |||
3756 | 132 | QImage image = m_document->makeImage(VALID_IMAGE_SIZE, 1000); | ||
3757 | 133 | QCOMPARE(image.isNull(), true); | ||
3758 | 134 | } | ||
3759 | 135 | void testMakeImageInvalidSize() | ||
3760 | 136 | { | ||
3761 | 137 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3762 | 138 | m_document->setUrl(getResourceUrl("a4_portrait.pdf")); | ||
3763 | 139 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3764 | 140 | |||
3765 | 141 | QImage image = m_document->makeImage(INVALID_IMAGE_SIZE, 0); | ||
3766 | 142 | QCOMPARE(image.isNull(), true); | ||
3767 | 143 | } | ||
3768 | 144 | void testMakeImageNegativePage() | ||
3769 | 145 | { | ||
3770 | 146 | QImage image = m_document->makeImage(VALID_IMAGE_SIZE, -1); | ||
3771 | 147 | QCOMPARE(image.isNull(), true); | ||
3772 | 148 | } | ||
3773 | 149 | void testMakeImageInvalidRenderToImage() | ||
3774 | 150 | { | ||
3775 | 151 | QSKIP("TODO: need to have a test to hit the case where renderToImage returns a null image"); | ||
3776 | 152 | } | ||
3777 | 153 | |||
3778 | 154 | |||
3779 | 155 | void testMakeImageToFit() | ||
3780 | 156 | { | ||
3781 | 157 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3782 | 158 | m_document->setUrl(getResourceUrl("a4_portrait.pdf")); | ||
3783 | 159 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3784 | 160 | |||
3785 | 161 | QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, 0, true); | ||
3786 | 162 | QCOMPARE(image.isNull(), false); | ||
3787 | 163 | QCOMPARE(image.size(), VALID_IMAGE_SIZE); | ||
3788 | 164 | } | ||
3789 | 165 | void testMakeImageToFitColor() | ||
3790 | 166 | { | ||
3791 | 167 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3792 | 168 | m_document->setUrl(getResourceUrl("color.pdf")); | ||
3793 | 169 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3794 | 170 | |||
3795 | 171 | QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, 0, true); | ||
3796 | 172 | QCOMPARE(image.isNull(), false); | ||
3797 | 173 | QCOMPARE(image.size(), VALID_IMAGE_SIZE); | ||
3798 | 174 | QCOMPARE(image.isGrayscale(), false); | ||
3799 | 175 | } | ||
3800 | 176 | void testMakeImageToFitGrayscale() | ||
3801 | 177 | { | ||
3802 | 178 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3803 | 179 | m_document->setUrl(getResourceUrl("color.pdf")); | ||
3804 | 180 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3805 | 181 | |||
3806 | 182 | QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, 0, false); | ||
3807 | 183 | QCOMPARE(image.isNull(), false); | ||
3808 | 184 | QCOMPARE(image.size(), VALID_IMAGE_SIZE); | ||
3809 | 185 | QCOMPARE(image.isGrayscale(), true); | ||
3810 | 186 | } | ||
3811 | 187 | void testMakeImageToFitInvalidDocument() | ||
3812 | 188 | { | ||
3813 | 189 | QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, 0, true); | ||
3814 | 190 | QCOMPARE(image.isNull(), true); | ||
3815 | 191 | } | ||
3816 | 192 | void testMakeImageToFitInvalidPage() | ||
3817 | 193 | { | ||
3818 | 194 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3819 | 195 | m_document->setUrl(getResourceUrl("a4_portrait.pdf")); | ||
3820 | 196 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3821 | 197 | |||
3822 | 198 | QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, 1000, true); | ||
3823 | 199 | QCOMPARE(image.isNull(), true); | ||
3824 | 200 | } | ||
3825 | 201 | void testMakeImageToFitInvalidSize() | ||
3826 | 202 | { | ||
3827 | 203 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3828 | 204 | m_document->setUrl(getResourceUrl("a4_portrait.pdf")); | ||
3829 | 205 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3830 | 206 | |||
3831 | 207 | QImage image = m_document->makeImageToFit(INVALID_IMAGE_SIZE, 0, true); | ||
3832 | 208 | QCOMPARE(image.isNull(), true); | ||
3833 | 209 | } | ||
3834 | 210 | void testMakeImageToFitNegativePage() | ||
3835 | 211 | { | ||
3836 | 212 | QImage image = m_document->makeImageToFit(VALID_IMAGE_SIZE, -1, true); | ||
3837 | 213 | QCOMPARE(image.isNull(), true); | ||
3838 | 214 | } | ||
3839 | 215 | |||
3840 | 216 | |||
3841 | 217 | void testOrientationPortrait() | ||
3842 | 218 | { | ||
3843 | 219 | QSignalSpy orientationSpy(m_document, SIGNAL(orientationChanged())); | ||
3844 | 220 | m_document->setUrl(getResourceUrl("a4_portrait.pdf")); | ||
3845 | 221 | QTRY_COMPARE(orientationSpy.count(), 1); | ||
3846 | 222 | QCOMPARE(m_document->orientation(), Document::Orientation::Portrait); | ||
3847 | 223 | } | ||
3848 | 224 | void testOrientationLandscape() | ||
3849 | 225 | { | ||
3850 | 226 | QSignalSpy orientationSpy(m_document, SIGNAL(orientationChanged())); | ||
3851 | 227 | m_document->setUrl(getResourceUrl("a5_landscape.pdf")); | ||
3852 | 228 | QTRY_COMPARE(orientationSpy.count(), 1); | ||
3853 | 229 | QCOMPARE(m_document->orientation(), Document::Orientation::Landscape); | ||
3854 | 230 | } | ||
3855 | 231 | void testOrientationMixedPortrait() | ||
3856 | 232 | { | ||
3857 | 233 | QSignalSpy orientationSpy(m_document, SIGNAL(orientationChanged())); | ||
3858 | 234 | m_document->setUrl(getResourceUrl("mixed_portrait.pdf")); | ||
3859 | 235 | QTRY_COMPARE(orientationSpy.count(), 1); | ||
3860 | 236 | QCOMPARE(m_document->orientation(), Document::Orientation::Portrait); | ||
3861 | 237 | } | ||
3862 | 238 | void testOrientationMixedLandscape() | ||
3863 | 239 | { | ||
3864 | 240 | QSignalSpy orientationSpy(m_document, SIGNAL(orientationChanged())); | ||
3865 | 241 | m_document->setUrl(getResourceUrl("mixed_landscape.pdf")); | ||
3866 | 242 | QTRY_COMPARE(orientationSpy.count(), 1); | ||
3867 | 243 | QCOMPARE(m_document->orientation(), Document::Orientation::Landscape); | ||
3868 | 244 | } | ||
3869 | 245 | |||
3870 | 246 | void testTitle() | ||
3871 | 247 | { | ||
3872 | 248 | QSignalSpy titleSpy(m_document, SIGNAL(titleChanged())); | ||
3873 | 249 | m_document->setUrl(getResourceUrl("test_title.pdf")); | ||
3874 | 250 | QTRY_COMPARE(titleSpy.count(), 1); | ||
3875 | 251 | QCOMPARE(m_document->title(), QStringLiteral("Test Title Document")); | ||
3876 | 252 | } | ||
3877 | 253 | |||
3878 | 254 | void testUrl() | ||
3879 | 255 | { | ||
3880 | 256 | QSignalSpy errorSpy(m_document, SIGNAL(error(Document::Errors))); | ||
3881 | 257 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
3882 | 258 | |||
3883 | 259 | QUrl resource = getResourceUrl("a4_portrait.pdf"); | ||
3884 | 260 | |||
3885 | 261 | m_document->setUrl(resource); | ||
3886 | 262 | QTRY_COMPARE(urlSpy.count(), 1); | ||
3887 | 263 | QCOMPARE(errorSpy.count(), 0); | ||
3888 | 264 | QCOMPARE(m_document->url(), resource); | ||
3889 | 265 | } | ||
3890 | 266 | void testUrlNotFound() | ||
3891 | 267 | { | ||
3892 | 268 | QSignalSpy errorSpy(m_document, SIGNAL(error(Document::Errors))); | ||
3893 | 269 | m_document->setUrl(getResourceUrl("notfound.pdf")); | ||
3894 | 270 | QTRY_COMPARE(errorSpy.count(), 1); | ||
3895 | 271 | QCOMPARE(m_document->url(), QUrl(QStringLiteral(""))); | ||
3896 | 272 | |||
3897 | 273 | QList<QVariant> args = errorSpy.takeFirst(); | ||
3898 | 274 | QCOMPARE(args.at(0).toInt(), (int) Document::Errors::ErrorNotFound); | ||
3899 | 275 | } | ||
3900 | 276 | void testUrlNotPdf() | ||
3901 | 277 | { | ||
3902 | 278 | QSignalSpy errorSpy(m_document, SIGNAL(error(Document::Errors))); | ||
3903 | 279 | m_document->setUrl(getResourceUrl("text.txt")); | ||
3904 | 280 | QTRY_COMPARE(errorSpy.count(), 1); | ||
3905 | 281 | QCOMPARE(m_document->url(), QUrl(QStringLiteral(""))); | ||
3906 | 282 | |||
3907 | 283 | QList<QVariant> args = errorSpy.takeFirst(); | ||
3908 | 284 | QCOMPARE(args.at(0).toInt(), (int) Document::Errors::ErrorNotPdf); | ||
3909 | 285 | } | ||
3910 | 286 | void testUrlInvalidDocument() | ||
3911 | 287 | { | ||
3912 | 288 | QSignalSpy errorSpy(m_document, SIGNAL(error(Document::Errors))); | ||
3913 | 289 | m_document->setUrl(getResourceUrl("corrupt.pdf")); | ||
3914 | 290 | QTRY_COMPARE(errorSpy.count(), 1); | ||
3915 | 291 | QCOMPARE(m_document->url(), QUrl(QStringLiteral(""))); | ||
3916 | 292 | |||
3917 | 293 | QList<QVariant> args = errorSpy.takeFirst(); | ||
3918 | 294 | QCOMPARE(args.at(0).toInt(), (int) Document::Errors::ErrorDocumentInvalid); | ||
3919 | 295 | } | ||
3920 | 296 | private: | ||
3921 | 297 | Document *m_document; | ||
3922 | 298 | }; | ||
3923 | 299 | |||
3924 | 300 | QTEST_GUILESS_MAIN(TestDocument) | ||
3925 | 301 | #include "tst_document.moc" | ||
3926 | 0 | 302 | ||
3927 | === added file 'tests/unittests/backend/tst_pagehelper.cpp' | |||
3928 | --- tests/unittests/backend/tst_pagehelper.cpp 1970-01-01 00:00:00 +0000 | |||
3929 | +++ tests/unittests/backend/tst_pagehelper.cpp 2017-02-08 21:32:20 +0000 | |||
3930 | @@ -0,0 +1,171 @@ | |||
3931 | 1 | /* | ||
3932 | 2 | * Copyright 2017 Canonical Ltd. | ||
3933 | 3 | * | ||
3934 | 4 | * This file is part of ubuntu-printing-app. | ||
3935 | 5 | * | ||
3936 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
3937 | 7 | * it under the terms of the GNU General Public License as published by | ||
3938 | 8 | * the Free Software Foundation; version 3. | ||
3939 | 9 | * | ||
3940 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
3941 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3942 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3943 | 13 | * GNU General Public License for more details. | ||
3944 | 14 | * | ||
3945 | 15 | * You should have received a copy of the GNU General Public License | ||
3946 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3947 | 17 | * | ||
3948 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
3949 | 19 | */ | ||
3950 | 20 | |||
3951 | 21 | #include <QDebug> | ||
3952 | 22 | #include <QObject> | ||
3953 | 23 | #include <QSignalSpy> | ||
3954 | 24 | #include <QTest> | ||
3955 | 25 | |||
3956 | 26 | #include "UbuntuPrintingApp/document.h" | ||
3957 | 27 | #include "UbuntuPrintingApp/pagehelper.h" | ||
3958 | 28 | |||
3959 | 29 | #define A4_PORTRAIT_ASPECT_RATIO 595.0 / 842.0 | ||
3960 | 30 | #define A4_LANDSCAPE_ASPECT_RATIO 842.0 / 595.0 | ||
3961 | 31 | #define A5_LANDSCAPE_ASPECT_RATIO 595.0 / 420.0 | ||
3962 | 32 | |||
3963 | 33 | class TestPageHelper : public QObject | ||
3964 | 34 | { | ||
3965 | 35 | Q_OBJECT | ||
3966 | 36 | private Q_SLOTS: | ||
3967 | 37 | void init() | ||
3968 | 38 | { | ||
3969 | 39 | m_document = new Document(); | ||
3970 | 40 | m_page_helper = new PageHelper(); | ||
3971 | 41 | m_page_helper->setDocument(m_document); | ||
3972 | 42 | } | ||
3973 | 43 | void cleanup() | ||
3974 | 44 | { | ||
3975 | 45 | QSignalSpy destroyedPageHelperSpy(m_page_helper, SIGNAL(destroyed(QObject*))); | ||
3976 | 46 | m_page_helper->deleteLater(); | ||
3977 | 47 | QTRY_COMPARE(destroyedPageHelperSpy.count(), 1); | ||
3978 | 48 | |||
3979 | 49 | QSignalSpy destroyedDocumentSpy(m_document, SIGNAL(destroyed(QObject*))); | ||
3980 | 50 | m_document->deleteLater(); | ||
3981 | 51 | QTRY_COMPARE(destroyedDocumentSpy.count(), 1); | ||
3982 | 52 | } | ||
3983 | 53 | QUrl getResourceUrl(const QString &resource) const | ||
3984 | 54 | { | ||
3985 | 55 | return QUrl("file://" + QDir::currentPath() + "/../../resources/pdf/" + resource); | ||
3986 | 56 | } | ||
3987 | 57 | |||
3988 | 58 | void testInit() | ||
3989 | 59 | { | ||
3990 | 60 | QCOMPARE(m_page_helper->aspect(), A4_PORTRAIT_ASPECT_RATIO); | ||
3991 | 61 | QCOMPARE(m_page_helper->document(), m_document); | ||
3992 | 62 | QCOMPARE(m_page_helper->page(), 0); | ||
3993 | 63 | } | ||
3994 | 64 | |||
3995 | 65 | void testAspect() | ||
3996 | 66 | { | ||
3997 | 67 | QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged())); | ||
3998 | 68 | m_document->setUrl(getResourceUrl("a5_landscape.pdf")); | ||
3999 | 69 | QTRY_COMPARE(aspectSpy.count(), 1); | ||
4000 | 70 | QCOMPARE(m_page_helper->aspect(), A5_LANDSCAPE_ASPECT_RATIO); | ||
4001 | 71 | } | ||
4002 | 72 | void testAspectA4Document() | ||
4003 | 73 | { | ||
4004 | 74 | QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged())); | ||
4005 | 75 | m_document->setUrl(getResourceUrl("a5_landscape.pdf")); | ||
4006 | 76 | QTRY_COMPARE(aspectSpy.count(), 1); | ||
4007 | 77 | QCOMPARE(m_page_helper->aspect(), A5_LANDSCAPE_ASPECT_RATIO); | ||
4008 | 78 | |||
4009 | 79 | m_document->setUrl(getResourceUrl("a4_portrait.pdf")); | ||
4010 | 80 | QTRY_COMPARE(aspectSpy.count(), 2); | ||
4011 | 81 | QCOMPARE(m_page_helper->aspect(), A4_PORTRAIT_ASPECT_RATIO); | ||
4012 | 82 | } | ||
4013 | 83 | void testAspectFallsBack() | ||
4014 | 84 | { | ||
4015 | 85 | QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged())); | ||
4016 | 86 | m_document->setUrl(getResourceUrl("a5_landscape.pdf")); | ||
4017 | 87 | QTRY_COMPARE(aspectSpy.count(), 1); | ||
4018 | 88 | QCOMPARE(m_page_helper->aspect(), A5_LANDSCAPE_ASPECT_RATIO); | ||
4019 | 89 | |||
4020 | 90 | // Test when set to a new document that it goes back to A4 | ||
4021 | 91 | Document *newDoc = new Document(); | ||
4022 | 92 | m_page_helper->setDocument(newDoc); | ||
4023 | 93 | QTRY_COMPARE(aspectSpy.count(), 2); | ||
4024 | 94 | QCOMPARE(m_page_helper->aspect(), A4_PORTRAIT_ASPECT_RATIO); | ||
4025 | 95 | |||
4026 | 96 | newDoc->deleteLater(); | ||
4027 | 97 | } | ||
4028 | 98 | |||
4029 | 99 | void testDocument() | ||
4030 | 100 | { | ||
4031 | 101 | QSignalSpy documentSpy(m_page_helper, SIGNAL(documentChanged())); | ||
4032 | 102 | Document *newDoc = new Document(); | ||
4033 | 103 | m_page_helper->setDocument(newDoc); | ||
4034 | 104 | QTRY_COMPARE(documentSpy.count(), 1); | ||
4035 | 105 | QCOMPARE(m_page_helper->document(), newDoc); | ||
4036 | 106 | } | ||
4037 | 107 | void testDocumentDisconnect() | ||
4038 | 108 | { | ||
4039 | 109 | QSignalSpy documentSpy(m_page_helper, SIGNAL(documentChanged())); | ||
4040 | 110 | Document *newDoc = new Document(); | ||
4041 | 111 | m_page_helper->setDocument(newDoc); | ||
4042 | 112 | QTRY_COMPARE(documentSpy.count(), 1); | ||
4043 | 113 | QCOMPARE(m_page_helper->document(), newDoc); | ||
4044 | 114 | |||
4045 | 115 | // Check that changing the old document doesn't cause signals that were | ||
4046 | 116 | // linked to be fired - eg loading of aspect | ||
4047 | 117 | QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged())); | ||
4048 | 118 | QSignalSpy urlSpy(m_document, SIGNAL(urlChanged())); | ||
4049 | 119 | m_document->setUrl(getResourceUrl("a5_landscape.pdf")); | ||
4050 | 120 | QTRY_COMPARE(urlSpy.count(), 1); | ||
4051 | 121 | QCOMPARE(aspectSpy.count(), 0); | ||
4052 | 122 | |||
4053 | 123 | newDoc->deleteLater(); | ||
4054 | 124 | } | ||
4055 | 125 | |||
4056 | 126 | void testDocumentUrlChange() | ||
4057 | 127 | { | ||
4058 | 128 | QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged())); | ||
4059 | 129 | m_document->setUrl(getResourceUrl("a5_landscape.pdf")); | ||
4060 | 130 | QTRY_COMPARE(aspectSpy.count(), 1); | ||
4061 | 131 | |||
4062 | 132 | QCOMPARE(m_page_helper->aspect(), A5_LANDSCAPE_ASPECT_RATIO); | ||
4063 | 133 | } | ||
4064 | 134 | |||
4065 | 135 | void testPageMixedLandscape() | ||
4066 | 136 | { | ||
4067 | 137 | QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged())); | ||
4068 | 138 | QSignalSpy pageSpy(m_page_helper, SIGNAL(pageChanged())); | ||
4069 | 139 | m_document->setUrl(getResourceUrl("mixed_landscape.pdf")); | ||
4070 | 140 | QTRY_COMPARE(aspectSpy.count(), 1); | ||
4071 | 141 | QCOMPARE(m_page_helper->page(), 0); | ||
4072 | 142 | QCOMPARE(m_page_helper->aspect(), A4_LANDSCAPE_ASPECT_RATIO); | ||
4073 | 143 | |||
4074 | 144 | m_page_helper->setPage(1); | ||
4075 | 145 | QTRY_COMPARE(pageSpy.count(), 1); | ||
4076 | 146 | QCOMPARE(m_page_helper->page(), 1); | ||
4077 | 147 | QTRY_COMPARE(aspectSpy.count(), 2); | ||
4078 | 148 | QCOMPARE(m_page_helper->aspect(), A4_PORTRAIT_ASPECT_RATIO); | ||
4079 | 149 | } | ||
4080 | 150 | void testPageMixedPortrait() | ||
4081 | 151 | { | ||
4082 | 152 | QSignalSpy aspectSpy(m_page_helper, SIGNAL(aspectChanged())); | ||
4083 | 153 | QSignalSpy pageSpy(m_page_helper, SIGNAL(pageChanged())); | ||
4084 | 154 | m_document->setUrl(getResourceUrl("mixed_portrait.pdf")); | ||
4085 | 155 | QCOMPARE(aspectSpy.count(), 0); | ||
4086 | 156 | QCOMPARE(m_page_helper->aspect(), A4_PORTRAIT_ASPECT_RATIO); | ||
4087 | 157 | |||
4088 | 158 | m_page_helper->setPage(1); | ||
4089 | 159 | QTRY_COMPARE(pageSpy.count(), 1); | ||
4090 | 160 | QCOMPARE(m_page_helper->page(), 1); | ||
4091 | 161 | QTRY_COMPARE(aspectSpy.count(), 1); | ||
4092 | 162 | QCOMPARE(m_page_helper->aspect(), A4_LANDSCAPE_ASPECT_RATIO); | ||
4093 | 163 | } | ||
4094 | 164 | |||
4095 | 165 | private: | ||
4096 | 166 | Document *m_document; | ||
4097 | 167 | PageHelper *m_page_helper; | ||
4098 | 168 | }; | ||
4099 | 169 | |||
4100 | 170 | QTEST_GUILESS_MAIN(TestPageHelper) | ||
4101 | 171 | #include "tst_pagehelper.moc" | ||
4102 | 0 | 172 | ||
4103 | === added file 'tests/unittests/backend/tst_popplerimageprovider.cpp' | |||
4104 | --- tests/unittests/backend/tst_popplerimageprovider.cpp 1970-01-01 00:00:00 +0000 | |||
4105 | +++ tests/unittests/backend/tst_popplerimageprovider.cpp 2017-02-08 21:32:20 +0000 | |||
4106 | @@ -0,0 +1,127 @@ | |||
4107 | 1 | /* | ||
4108 | 2 | * Copyright 2017 Canonical Ltd. | ||
4109 | 3 | * | ||
4110 | 4 | * This file is part of ubuntu-printing-app. | ||
4111 | 5 | * | ||
4112 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
4113 | 7 | * it under the terms of the GNU General Public License as published by | ||
4114 | 8 | * the Free Software Foundation; version 3. | ||
4115 | 9 | * | ||
4116 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
4117 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4118 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4119 | 13 | * GNU General Public License for more details. | ||
4120 | 14 | * | ||
4121 | 15 | * You should have received a copy of the GNU General Public License | ||
4122 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4123 | 17 | * | ||
4124 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
4125 | 19 | */ | ||
4126 | 20 | |||
4127 | 21 | #include <QDebug> | ||
4128 | 22 | #include <QObject> | ||
4129 | 23 | #include <QSignalSpy> | ||
4130 | 24 | #include <QTest> | ||
4131 | 25 | |||
4132 | 26 | #include "UbuntuPrintingApp/popplerimageprovider.h" | ||
4133 | 27 | |||
4134 | 28 | class TestPopplerImageProvider : public QObject | ||
4135 | 29 | { | ||
4136 | 30 | Q_OBJECT | ||
4137 | 31 | private Q_SLOTS: | ||
4138 | 32 | void init() | ||
4139 | 33 | { | ||
4140 | 34 | m_provider = new PopplerImageProvider(); | ||
4141 | 35 | } | ||
4142 | 36 | void cleanup() | ||
4143 | 37 | { | ||
4144 | 38 | delete m_provider; | ||
4145 | 39 | } | ||
4146 | 40 | QUrl getResourceUrl(const QString &resource) const | ||
4147 | 41 | { | ||
4148 | 42 | return QUrl("file://" + QDir::currentPath() + "/../../resources/pdf/" + resource); | ||
4149 | 43 | } | ||
4150 | 44 | |||
4151 | 45 | void testRequestImage() | ||
4152 | 46 | { | ||
4153 | 47 | QString id = "0/true/" + getResourceUrl("color.pdf").toString(); | ||
4154 | 48 | QSize *size = new QSize(); | ||
4155 | 49 | QSize requestedSize(250, 250); | ||
4156 | 50 | |||
4157 | 51 | QImage result = m_provider->requestImage(id, size, requestedSize); | ||
4158 | 52 | |||
4159 | 53 | QCOMPARE(result.isNull(), false); | ||
4160 | 54 | QCOMPARE(result.size(), requestedSize); | ||
4161 | 55 | QCOMPARE(*size, requestedSize); | ||
4162 | 56 | QCOMPARE(result.isGrayscale(), false); | ||
4163 | 57 | } | ||
4164 | 58 | void testRequestImageGrayscale() | ||
4165 | 59 | { | ||
4166 | 60 | QString id = "0/false/" + getResourceUrl("color.pdf").toString(); | ||
4167 | 61 | QSize *size = new QSize(); | ||
4168 | 62 | QSize requestedSize(250, 250); | ||
4169 | 63 | |||
4170 | 64 | QImage result = m_provider->requestImage(id, size, requestedSize); | ||
4171 | 65 | |||
4172 | 66 | QCOMPARE(result.isNull(), false); | ||
4173 | 67 | QCOMPARE(result.size(), requestedSize); | ||
4174 | 68 | QCOMPARE(*size, requestedSize); | ||
4175 | 69 | QCOMPARE(result.isGrayscale(), true); | ||
4176 | 70 | } | ||
4177 | 71 | void testRequestImageMultiPage() | ||
4178 | 72 | { | ||
4179 | 73 | // TODO: is there a way we can confirm that the image is showing the 2nd page? | ||
4180 | 74 | QString id = "1/true/" + getResourceUrl("mixed_portrait.pdf").toString(); | ||
4181 | 75 | QSize *size = new QSize(); | ||
4182 | 76 | QSize requestedSize(250, 250); | ||
4183 | 77 | |||
4184 | 78 | QImage result = m_provider->requestImage(id, size, requestedSize); | ||
4185 | 79 | |||
4186 | 80 | QCOMPARE(result.isNull(), false); | ||
4187 | 81 | QCOMPARE(result.size(), requestedSize); | ||
4188 | 82 | QCOMPARE(*size, requestedSize); | ||
4189 | 83 | QCOMPARE(result.isGrayscale(), true); | ||
4190 | 84 | } | ||
4191 | 85 | |||
4192 | 86 | void testRequestImageInvalidColor() | ||
4193 | 87 | { | ||
4194 | 88 | QString id = "0/abc/" + getResourceUrl("a4_portrait.pdf").toString(); | ||
4195 | 89 | QSize *size = new QSize(); | ||
4196 | 90 | QSize requestedSize(250, 250); | ||
4197 | 91 | |||
4198 | 92 | QImage result = m_provider->requestImage(id, size, requestedSize); | ||
4199 | 93 | |||
4200 | 94 | QCOMPARE(result.isNull(), true); | ||
4201 | 95 | QCOMPARE((*size), requestedSize); | ||
4202 | 96 | } | ||
4203 | 97 | void testRequestImageInvalidPage() | ||
4204 | 98 | { | ||
4205 | 99 | QString id = "1000/true/" + getResourceUrl("a4_portrait.pdf").toString(); | ||
4206 | 100 | QSize *size = new QSize(); | ||
4207 | 101 | QSize requestedSize(250, 250); | ||
4208 | 102 | |||
4209 | 103 | QImage result = m_provider->requestImage(id, size, requestedSize); | ||
4210 | 104 | |||
4211 | 105 | QCOMPARE(result.isNull(), true); | ||
4212 | 106 | QCOMPARE((*size), requestedSize); | ||
4213 | 107 | } | ||
4214 | 108 | void testRequestImageInvalidRequestedSize() | ||
4215 | 109 | { | ||
4216 | 110 | QString id = "0/true/" + getResourceUrl("a4_portrait.pdf").toString(); | ||
4217 | 111 | QSize *size = new QSize(); | ||
4218 | 112 | QSize requestedSize(-100, -50); | ||
4219 | 113 | |||
4220 | 114 | QImage result = m_provider->requestImage(id, size, requestedSize); | ||
4221 | 115 | |||
4222 | 116 | // An invalid request size returns a size of 1,1 otherwise QML errors occur | ||
4223 | 117 | QCOMPARE(result.isNull(), false); | ||
4224 | 118 | QCOMPARE(result.size(), QSize(1, 1)); | ||
4225 | 119 | QCOMPARE((*size), QSize(1, 1)); | ||
4226 | 120 | } | ||
4227 | 121 | |||
4228 | 122 | private: | ||
4229 | 123 | PopplerImageProvider *m_provider; | ||
4230 | 124 | }; | ||
4231 | 125 | |||
4232 | 126 | QTEST_GUILESS_MAIN(TestPopplerImageProvider) | ||
4233 | 127 | #include "tst_popplerimageprovider.moc" | ||
4234 | 0 | 128 | ||
4235 | === modified file 'ubuntu-printing-app/CMakeLists.txt' | |||
4236 | --- ubuntu-printing-app/CMakeLists.txt 2016-12-13 23:08:52 +0000 | |||
4237 | +++ ubuntu-printing-app/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
4238 | @@ -1,4 +1,5 @@ | |||
4239 | 1 | add_subdirectory(components) | 1 | add_subdirectory(components) |
4240 | 2 | add_subdirectory(pages) | ||
4241 | 2 | 3 | ||
4242 | 3 | # Install Main.qml and icon | 4 | # Install Main.qml and icon |
4243 | 4 | install(FILES ${MAIN_QML} DESTINATION ${UBUNTU_PRINTING_APP_DATA_DIR}) | 5 | install(FILES ${MAIN_QML} DESTINATION ${UBUNTU_PRINTING_APP_DATA_DIR}) |
4244 | @@ -23,6 +24,6 @@ | |||
4245 | 23 | 24 | ||
4246 | 24 | # Show in QtCreator | 25 | # Show in QtCreator |
4247 | 25 | if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") | 26 | if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") |
4249 | 26 | file(GLOB MAIN_QML_JS_FILES *.qml *.js) | 27 | file(GLOB MAIN_QML_JS_FILES *.apparmor *.js *.json *.qml) |
4250 | 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}) |
4251 | 28 | endif(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") | 29 | endif(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") |
4252 | 29 | 30 | ||
4253 | === modified file 'ubuntu-printing-app/Main.qml' | |||
4254 | --- ubuntu-printing-app/Main.qml 2016-12-13 12:37:45 +0000 | |||
4255 | +++ ubuntu-printing-app/Main.qml 2017-02-08 21:32:20 +0000 | |||
4256 | @@ -1,10 +1,31 @@ | |||
4257 | 1 | /* | ||
4258 | 2 | * Copyright 2016, 2017 Canonical Ltd. | ||
4259 | 3 | * | ||
4260 | 4 | * This file is part of ubuntu-printing-app. | ||
4261 | 5 | * | ||
4262 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
4263 | 7 | * it under the terms of the GNU General Public License as published by | ||
4264 | 8 | * the Free Software Foundation; version 3. | ||
4265 | 9 | * | ||
4266 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
4267 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4268 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4269 | 13 | * GNU General Public License for more details. | ||
4270 | 14 | * | ||
4271 | 15 | * You should have received a copy of the GNU General Public License | ||
4272 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4273 | 17 | * | ||
4274 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
4275 | 19 | */ | ||
4276 | 1 | import QtQuick 2.4 | 20 | import QtQuick 2.4 |
4277 | 2 | import QtQuick.Layouts 1.1 | 21 | import QtQuick.Layouts 1.1 |
4278 | 3 | 22 | ||
4279 | 4 | import Ubuntu.Components 1.3 | 23 | import Ubuntu.Components 1.3 |
4280 | 5 | import Ubuntu.Components.ListItems 1.3 as ListItems | 24 | import Ubuntu.Components.ListItems 1.3 as ListItems |
4283 | 6 | import Ubuntu.Content 0.1 | 25 | import Ubuntu.Components.Popups 1.3 |
4284 | 7 | import Ubuntu_Printing_App 1.0 | 26 | import Ubuntu.Content 1.1 |
4285 | 27 | import UbuntuPrintingApp 1.0 | ||
4286 | 28 | import Ubuntu.Settings.Printers 0.1 | ||
4287 | 8 | 29 | ||
4288 | 9 | import "components" | 30 | import "components" |
4289 | 10 | 31 | ||
4290 | @@ -18,295 +39,106 @@ | |||
4291 | 18 | objectName: "mainView" | 39 | objectName: "mainView" |
4292 | 19 | 40 | ||
4293 | 20 | // Note! applicationName needs to match the "name" field of the click manifest | 41 | // Note! applicationName needs to match the "name" field of the click manifest |
4324 | 21 | applicationName: "ubuntu-printing-app.ahayzen" | 42 | applicationName: "ubuntu-printing-app" |
4325 | 22 | 43 | ||
4326 | 23 | width: units.gu(40) | 44 | width: units.gu(45) |
4327 | 24 | height: units.gu(60) | 45 | height: units.gu(70) |
4298 | 25 | |||
4299 | 26 | Connections { | ||
4300 | 27 | target: ContentHub | ||
4301 | 28 | |||
4302 | 29 | onImportRequested: { | ||
4303 | 30 | console.debug("State:", transfer.state) | ||
4304 | 31 | console.debug("Transfer:", transfer) | ||
4305 | 32 | console.debug("Items:", transfer.items) | ||
4306 | 33 | |||
4307 | 34 | for (var i=0; i < transfer.items.length; i++) { | ||
4308 | 35 | var item = transfer.items[i]; | ||
4309 | 36 | |||
4310 | 37 | document.url = item.url; | ||
4311 | 38 | console.debug("Item URL:", item.url); | ||
4312 | 39 | } | ||
4313 | 40 | } | ||
4314 | 41 | } | ||
4315 | 42 | |||
4316 | 43 | Printer { | ||
4317 | 44 | id: printer | ||
4318 | 45 | name: PrinterInfo.defaultPrinterName | ||
4319 | 46 | |||
4320 | 47 | // TODO: status ? | ||
4321 | 48 | |||
4322 | 49 | onExportRequest: console.debug("Export requested!", filepath) | ||
4323 | 50 | } | ||
4328 | 51 | 46 | ||
4329 | 52 | Document { | 47 | Document { |
4330 | 53 | id: document | 48 | id: document |
4362 | 54 | } | 49 | |
4363 | 55 | 50 | onError: { | |
4364 | 56 | /* | 51 | var errorString; |
4365 | 57 | PrinterInfo.availablePrinterNames | 52 | |
4366 | 58 | 53 | switch (errorType) { | |
4367 | 59 | PrinterInfo.defaultName | 54 | case Document.ErrorDocumentInvalid: |
4368 | 60 | 55 | errorString = i18n.tr("Document is invalid"); | |
4369 | 61 | Printer { | 56 | break; |
4370 | 62 | error: false | 57 | case Document.ErrorNotFound: |
4371 | 63 | errorString: "" | 58 | errorString = i18n.tr("Document not found"); |
4372 | 64 | name: PrinterInfo.defaultName | 59 | break; |
4373 | 65 | 60 | case Document.ErrorNotPdf: | |
4374 | 66 | colorMode: ColorModes.greyscale | 61 | errorString = i18n.tr("Not a PDF document"); |
4375 | 67 | copies: 2 | 62 | break; |
4376 | 68 | 63 | default: | |
4377 | 69 | print(Document document) // async | 64 | errorString = i18n.tr("An unknown error occurred"); |
4378 | 70 | 65 | break; | |
4379 | 71 | status: {Null,Rendering,SentToPrinter,Error} | 66 | } |
4380 | 72 | progress: 0.6 // progress of print | 67 | |
4381 | 73 | } | 68 | // Empty the Url so user cannot print |
4382 | 74 | 69 | url = ""; | |
4383 | 75 | Document { | 70 | |
4384 | 76 | error: false | 71 | PopupUtils.open( |
4385 | 77 | errorString: "" | 72 | Qt.resolvedUrl("components/AlertDialog.qml"), |
4386 | 78 | url: "/tmp/my.pdf" | 73 | pageStack.currentPage, |
4387 | 79 | } | 74 | { |
4388 | 80 | 75 | "text": errorString, | |
4389 | 81 | */ | 76 | "title": i18n.tr("Error"), |
4390 | 82 | 77 | } | |
4391 | 83 | Page { | 78 | ) |
4392 | 84 | id: page | 79 | } |
4393 | 80 | } | ||
4394 | 81 | |||
4395 | 82 | property PrintingHelper printing: PrintingHelper {} | ||
4396 | 83 | property Page printPage: null | ||
4397 | 84 | |||
4398 | 85 | PageStack { | ||
4399 | 86 | id: pageStack | ||
4400 | 85 | anchors { | 87 | anchors { |
4401 | 86 | fill: parent | 88 | fill: parent |
4402 | 87 | } | 89 | } |
4617 | 88 | width: mainView.width | 90 | } |
4618 | 89 | 91 | ||
4619 | 90 | header: PageHeader { | 92 | Arguments { |
4620 | 91 | id: pageHeader | 93 | id: args |
4621 | 92 | leadingActionBar { | 94 | Argument { |
4622 | 93 | actions: [ | 95 | name: "url" |
4623 | 94 | Action { | 96 | help: i18n.tr("URL of PDF to print") |
4624 | 95 | iconName: "back" | 97 | required: false |
4625 | 96 | 98 | valueNames: ["url"] | |
4626 | 97 | onTriggered: Qt.quit() | 99 | } |
4627 | 98 | } | 100 | } |
4628 | 99 | ] | 101 | |
4629 | 100 | } | 102 | Connections { |
4630 | 101 | 103 | target: ContentHub | |
4631 | 102 | title: printer.pdfMode ? i18n.tr("Page Setup") : i18n.tr("Printer Options") | 104 | |
4632 | 103 | } | 105 | onImportRequested: { |
4633 | 104 | 106 | // FIXME: Only uses the first item given over content-hub | |
4634 | 105 | ScrollView { | 107 | // do we need to support multiple items in the future? |
4635 | 106 | anchors { | 108 | if (transfer.items.length > 0) { |
4636 | 107 | bottom: printRow.top | 109 | document.url = transfer.items[0].url; |
4637 | 108 | left: parent.left | 110 | } |
4638 | 109 | right: parent.right | 111 | } |
4639 | 110 | top: page.header.bottom | 112 | } |
4640 | 111 | } | 113 | |
4641 | 112 | 114 | Connections { | |
4642 | 113 | Item { | 115 | target: printPage |
4643 | 114 | height: columnLayout.height + units.gu(2) | 116 | |
4644 | 115 | width: mainView.width - units.gu(2) | 117 | onCancel: Qt.quit() |
4645 | 116 | x: units.gu(1) | 118 | onConfirm: { |
4646 | 117 | y: x | 119 | if (printing.pdfMode) { |
4647 | 118 | 120 | pageStack.push(Qt.resolvedUrl("pages/ContentPeerPickerPage.qml"), {"url": url}); | |
4648 | 119 | ColumnLayout { | 121 | } else { |
4649 | 120 | id: columnLayout | 122 | printing.printerJob.printFile(url); |
4650 | 121 | spacing: units.gu(1) | 123 | Qt.quit(); |
4651 | 122 | width: parent.width | 124 | } |
4438 | 123 | |||
4439 | 124 | Rectangle { | ||
4440 | 125 | anchors { | ||
4441 | 126 | left: parent.left | ||
4442 | 127 | right: parent.right | ||
4443 | 128 | } | ||
4444 | 129 | color: "#EEE" | ||
4445 | 130 | implicitHeight: units.gu(25) | ||
4446 | 131 | |||
4447 | 132 | RowLayout { | ||
4448 | 133 | anchors.fill: parent | ||
4449 | 134 | |||
4450 | 135 | Button { | ||
4451 | 136 | enabled: previewImage.pageNumber > 0 | ||
4452 | 137 | Layout.preferredWidth: units.gu(4) | ||
4453 | 138 | color: "#000" | ||
4454 | 139 | text: "<" | ||
4455 | 140 | |||
4456 | 141 | onClicked: previewImage.pageNumber-- | ||
4457 | 142 | } | ||
4458 | 143 | |||
4459 | 144 | Item { | ||
4460 | 145 | Layout.fillWidth: true | ||
4461 | 146 | Layout.preferredHeight: units.gu(25) | ||
4462 | 147 | |||
4463 | 148 | Image { | ||
4464 | 149 | id: previewImage | ||
4465 | 150 | anchors { | ||
4466 | 151 | fill: parent | ||
4467 | 152 | } | ||
4468 | 153 | |||
4469 | 154 | asynchronous: true | ||
4470 | 155 | source: document.url.toString() !== "" ? "image://poppler/" + pageNumber + "/" + printer.colorMode + "/" + document.url : "" | ||
4471 | 156 | sourceSize { | ||
4472 | 157 | height: units.gu(25) | ||
4473 | 158 | width: previewImage.width | ||
4474 | 159 | } | ||
4475 | 160 | |||
4476 | 161 | property int pageNumber: 0 | ||
4477 | 162 | } | ||
4478 | 163 | |||
4479 | 164 | ActivityIndicator { | ||
4480 | 165 | anchors { | ||
4481 | 166 | centerIn: parent | ||
4482 | 167 | } | ||
4483 | 168 | running: previewImage.status == Image.Loading | ||
4484 | 169 | } | ||
4485 | 170 | } | ||
4486 | 171 | |||
4487 | 172 | Button { | ||
4488 | 173 | color: "#000" | ||
4489 | 174 | enabled: previewImage.pageNumber < document.count - 1 | ||
4490 | 175 | Layout.preferredWidth: units.gu(4) | ||
4491 | 176 | text: ">" | ||
4492 | 177 | |||
4493 | 178 | onClicked: previewImage.pageNumber++ | ||
4494 | 179 | } | ||
4495 | 180 | } | ||
4496 | 181 | } | ||
4497 | 182 | |||
4498 | 183 | |||
4499 | 184 | SelectorRow { | ||
4500 | 185 | model: PrinterInfo.availablePrinterNames | ||
4501 | 186 | selectedIndex: model.indexOf(printer.name) | ||
4502 | 187 | text: i18n.tr("Printer") | ||
4503 | 188 | |||
4504 | 189 | onSelectedIndexChanged: { | ||
4505 | 190 | printer.pdfMode = selectedIndex === model.length - 1 | ||
4506 | 191 | printer.name = model[selectedIndex] | ||
4507 | 192 | } | ||
4508 | 193 | } | ||
4509 | 194 | |||
4510 | 195 | RowLayout { | ||
4511 | 196 | Label { | ||
4512 | 197 | Layout.preferredWidth: units.gu(10) | ||
4513 | 198 | text: i18n.tr("Copies") | ||
4514 | 199 | } | ||
4515 | 200 | |||
4516 | 201 | TextField { | ||
4517 | 202 | enabled: !printer.pdfMode | ||
4518 | 203 | inputMethodHints: Qt.ImhDigitsOnly | ||
4519 | 204 | Layout.fillWidth: true | ||
4520 | 205 | Layout.preferredWidth: units.gu(5) | ||
4521 | 206 | text: printer.copies | ||
4522 | 207 | validator: IntValidator { | ||
4523 | 208 | bottom: 1 | ||
4524 | 209 | top: 999 | ||
4525 | 210 | } | ||
4526 | 211 | |||
4527 | 212 | // TODO: acceptableInput is False show hint | ||
4528 | 213 | |||
4529 | 214 | onTextChanged: { | ||
4530 | 215 | if (acceptableInput) { | ||
4531 | 216 | printer.copies = Number(text); | ||
4532 | 217 | } | ||
4533 | 218 | } | ||
4534 | 219 | } | ||
4535 | 220 | } | ||
4536 | 221 | |||
4537 | 222 | RowLayout { | ||
4538 | 223 | Item { | ||
4539 | 224 | Layout.preferredWidth: units.gu(10) | ||
4540 | 225 | } | ||
4541 | 226 | |||
4542 | 227 | MouseArea { | ||
4543 | 228 | enabled: checkbox.enabled | ||
4544 | 229 | Layout.fillWidth: true | ||
4545 | 230 | Layout.preferredHeight: units.gu(3) | ||
4546 | 231 | Layout.preferredWidth: units.gu(10) | ||
4547 | 232 | |||
4548 | 233 | onClicked: checkbox.checked = !checkbox.checked | ||
4549 | 234 | |||
4550 | 235 | Row { | ||
4551 | 236 | anchors { | ||
4552 | 237 | fill: parent | ||
4553 | 238 | } | ||
4554 | 239 | spacing: units.gu(1) | ||
4555 | 240 | |||
4556 | 241 | CheckBox { | ||
4557 | 242 | id: checkbox | ||
4558 | 243 | anchors { | ||
4559 | 244 | verticalCenter: parent.verticalCenter | ||
4560 | 245 | } | ||
4561 | 246 | checked: printer.duplex | ||
4562 | 247 | enabled: document.count > 1 && printer.duplexSupported | ||
4563 | 248 | |||
4564 | 249 | onCheckedChanged: printer.duplex = checked | ||
4565 | 250 | } | ||
4566 | 251 | |||
4567 | 252 | Label { | ||
4568 | 253 | enabled: document.count > 1 | ||
4569 | 254 | height: parent.height | ||
4570 | 255 | text: i18n.tr("Two-Sided") | ||
4571 | 256 | verticalAlignment: Text.AlignVCenter | ||
4572 | 257 | } | ||
4573 | 258 | } | ||
4574 | 259 | |||
4575 | 260 | } | ||
4576 | 261 | } | ||
4577 | 262 | |||
4578 | 263 | SelectorRow { | ||
4579 | 264 | enabled: !printer.pdfMode | ||
4580 | 265 | model: [i18n.tr("Black & White"), i18n.tr("Color")] | ||
4581 | 266 | selectedIndex: modelValue.indexOf(printer.colorMode) | ||
4582 | 267 | text: i18n.tr("Color") | ||
4583 | 268 | |||
4584 | 269 | property var modelValue: [Printer.GrayScale, Printer.Color] | ||
4585 | 270 | |||
4586 | 271 | onSelectedIndexChanged: printer.colorMode = modelValue[selectedIndex] | ||
4587 | 272 | } | ||
4588 | 273 | |||
4589 | 274 | SelectorRow { | ||
4590 | 275 | enabled: !printer.pdfMode | ||
4591 | 276 | model: [i18n.tr("Draft"), i18n.tr("Normal"), i18n.tr("Best"), i18n.tr("Photo")] | ||
4592 | 277 | selectedIndex: modelValue.indexOf(printer.quality) | ||
4593 | 278 | text: i18n.tr("Quality") | ||
4594 | 279 | |||
4595 | 280 | property var modelValue: [Printer.Draft, Printer.Normal, Printer.Best, Printer.Photo] | ||
4596 | 281 | |||
4597 | 282 | onSelectedIndexChanged: printer.quality = modelValue[selectedIndex] | ||
4598 | 283 | } | ||
4599 | 284 | } | ||
4600 | 285 | } | ||
4601 | 286 | } | ||
4602 | 287 | |||
4603 | 288 | PrintRow { | ||
4604 | 289 | id: printRow | ||
4605 | 290 | anchors { | ||
4606 | 291 | bottom: parent.bottom | ||
4607 | 292 | left: parent.left | ||
4608 | 293 | leftMargin: units.gu(1) | ||
4609 | 294 | right: parent.right | ||
4610 | 295 | rightMargin: units.gu(1) | ||
4611 | 296 | } | ||
4612 | 297 | pdfMode: printer.pdfMode | ||
4613 | 298 | sheets: document.count | ||
4614 | 299 | |||
4615 | 300 | onCancel: Qt.quit() | ||
4616 | 301 | onConfirm: printer.print(document); // TODO: check document is valid raise error if not? | ||
4652 | 302 | } | 125 | } |
4653 | 303 | } | 126 | } |
4654 | 304 | 127 | ||
4655 | 305 | Component.onCompleted: { | 128 | Component.onCompleted: { |
4660 | 306 | // document.url = Qt.resolvedUrl("/home/andy/Workspace/Work/Canonical/dump/2016-11-17T12:00:08"); | 129 | printing.printerJob.landscape = document.orientation === Document.Landscape; |
4661 | 307 | document.url = Qt.resolvedUrl("/home/andrew/Downloads/UbuntuPhone.pdf"); | 130 | printing.printerJob.title = document.title || document.url.toString().split("/").pop(); |
4662 | 308 | // document.url = Qt.resolvedUrl("/home/andrew/Documents/test.pdf"); | 131 | printPage = pageStack.push( |
4663 | 309 | console.debug("Printers:", PrinterInfo.availablePrinterNames); | 132 | Qt.resolvedUrl("pages/PrintPage.qml"), |
4664 | 133 | { | ||
4665 | 134 | "currentDocument": document, | ||
4666 | 135 | "printing": printing, | ||
4667 | 136 | } | ||
4668 | 137 | ); | ||
4669 | 138 | |||
4670 | 139 | if (args.values.url) { | ||
4671 | 140 | document.url = Qt.resolvedUrl(args.values.url); | ||
4672 | 141 | } | ||
4673 | 310 | } | 142 | } |
4674 | 311 | } | 143 | } |
4675 | 312 | 144 | ||
4676 | 313 | 145 | ||
4677 | === added file 'ubuntu-printing-app/components/AlertDialog.qml' | |||
4678 | --- ubuntu-printing-app/components/AlertDialog.qml 1970-01-01 00:00:00 +0000 | |||
4679 | +++ ubuntu-printing-app/components/AlertDialog.qml 2017-02-08 21:32:20 +0000 | |||
4680 | @@ -0,0 +1,32 @@ | |||
4681 | 1 | /* | ||
4682 | 2 | * Copyright 2017 Canonical Ltd. | ||
4683 | 3 | * | ||
4684 | 4 | * This file is part of ubuntu-printing-app. | ||
4685 | 5 | * | ||
4686 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
4687 | 7 | * it under the terms of the GNU General Public License as published by | ||
4688 | 8 | * the Free Software Foundation; version 3. | ||
4689 | 9 | * | ||
4690 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
4691 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4692 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4693 | 13 | * GNU General Public License for more details. | ||
4694 | 14 | * | ||
4695 | 15 | * You should have received a copy of the GNU General Public License | ||
4696 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4697 | 17 | * | ||
4698 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
4699 | 19 | */ | ||
4700 | 20 | import QtQuick 2.4 | ||
4701 | 21 | import Ubuntu.Components 1.3 | ||
4702 | 22 | import Ubuntu.Components.Popups 1.3 | ||
4703 | 23 | |||
4704 | 24 | Dialog { | ||
4705 | 25 | id: dialog | ||
4706 | 26 | |||
4707 | 27 | Button { | ||
4708 | 28 | text: i18n.tr("OK") | ||
4709 | 29 | |||
4710 | 30 | onClicked: PopupUtils.close(dialog) | ||
4711 | 31 | } | ||
4712 | 32 | } | ||
4713 | 0 | 33 | ||
4714 | === modified file 'ubuntu-printing-app/components/CMakeLists.txt' | |||
4715 | --- ubuntu-printing-app/components/CMakeLists.txt 2016-12-13 23:08:52 +0000 | |||
4716 | +++ ubuntu-printing-app/components/CMakeLists.txt 2017-02-08 21:32:20 +0000 | |||
4717 | @@ -1,7 +1,12 @@ | |||
4718 | 1 | set(COMPONENT_QML_JS_FILES | 1 | set(COMPONENT_QML_JS_FILES |
4720 | 2 | ExpandableListItem.qml | 2 | AlertDialog.qml |
4721 | 3 | CheckBoxRow.qml | ||
4722 | 4 | LabelRow.qml | ||
4723 | 5 | PreviewRow.qml | ||
4724 | 3 | PrintRow.qml | 6 | PrintRow.qml |
4725 | 7 | PrintingHelper.qml | ||
4726 | 4 | SelectorRow.qml | 8 | SelectorRow.qml |
4727 | 9 | TextFieldRow.qml | ||
4728 | 5 | ) | 10 | ) |
4729 | 6 | 11 | ||
4730 | 7 | install(FILES ${COMPONENT_QML_JS_FILES} DESTINATION ${UBUNTU_PRINTING_APP_DATA_DIR}/components) | 12 | install(FILES ${COMPONENT_QML_JS_FILES} DESTINATION ${UBUNTU_PRINTING_APP_DATA_DIR}/components) |
4731 | 8 | 13 | ||
4732 | === added file 'ubuntu-printing-app/components/CheckBoxRow.qml' | |||
4733 | --- ubuntu-printing-app/components/CheckBoxRow.qml 1970-01-01 00:00:00 +0000 | |||
4734 | +++ ubuntu-printing-app/components/CheckBoxRow.qml 2017-02-08 21:32:20 +0000 | |||
4735 | @@ -0,0 +1,76 @@ | |||
4736 | 1 | /* | ||
4737 | 2 | * Copyright 2016 Canonical Ltd. | ||
4738 | 3 | * | ||
4739 | 4 | * This file is part of ubuntu-printing-app. | ||
4740 | 5 | * | ||
4741 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
4742 | 7 | * it under the terms of the GNU General Public License as published by | ||
4743 | 8 | * the Free Software Foundation; version 3. | ||
4744 | 9 | * | ||
4745 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
4746 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4747 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4748 | 13 | * GNU General Public License for more details. | ||
4749 | 14 | * | ||
4750 | 15 | * You should have received a copy of the GNU General Public License | ||
4751 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4752 | 17 | * | ||
4753 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
4754 | 19 | */ | ||
4755 | 20 | import QtQuick 2.4 | ||
4756 | 21 | import QtQuick.Layouts 1.1 | ||
4757 | 22 | |||
4758 | 23 | import Ubuntu.Components 1.3 | ||
4759 | 24 | |||
4760 | 25 | RowLayout { | ||
4761 | 26 | anchors { | ||
4762 | 27 | left: parent.left | ||
4763 | 28 | leftMargin: units.gu(2) | ||
4764 | 29 | right: parent.right | ||
4765 | 30 | rightMargin: units.gu(2) | ||
4766 | 31 | } | ||
4767 | 32 | Layout.maximumWidth: width | ||
4768 | 33 | |||
4769 | 34 | property alias checked: checkbox.checked | ||
4770 | 35 | property alias checkboxText: checkboxLabel.text | ||
4771 | 36 | property alias enabled: checkbox.enabled | ||
4772 | 37 | property alias text: label.text | ||
4773 | 38 | |||
4774 | 39 | Label { | ||
4775 | 40 | id: label | ||
4776 | 41 | Layout.preferredWidth: units.gu(10) | ||
4777 | 42 | objectName: "label" | ||
4778 | 43 | } | ||
4779 | 44 | |||
4780 | 45 | MouseArea { | ||
4781 | 46 | enabled: checkbox.enabled | ||
4782 | 47 | Layout.fillWidth: true | ||
4783 | 48 | Layout.preferredHeight: units.gu(3) | ||
4784 | 49 | Layout.preferredWidth: units.gu(10) | ||
4785 | 50 | |||
4786 | 51 | onClicked: checkbox.checked = !checkbox.checked | ||
4787 | 52 | |||
4788 | 53 | Row { | ||
4789 | 54 | anchors { | ||
4790 | 55 | fill: parent | ||
4791 | 56 | } | ||
4792 | 57 | spacing: units.gu(1) | ||
4793 | 58 | |||
4794 | 59 | CheckBox { | ||
4795 | 60 | id: checkbox | ||
4796 | 61 | anchors { | ||
4797 | 62 | verticalCenter: parent.verticalCenter | ||
4798 | 63 | } | ||
4799 | 64 | objectName: "checkbox" | ||
4800 | 65 | } | ||
4801 | 66 | |||
4802 | 67 | Label { | ||
4803 | 68 | id: checkboxLabel | ||
4804 | 69 | enabled: checkbox.enabled | ||
4805 | 70 | height: parent.height | ||
4806 | 71 | objectName: "checkboxLabel" | ||
4807 | 72 | verticalAlignment: Text.AlignVCenter | ||
4808 | 73 | } | ||
4809 | 74 | } | ||
4810 | 75 | } | ||
4811 | 76 | } | ||
4812 | 0 | 77 | ||
4813 | === removed file 'ubuntu-printing-app/components/ExpandableListItem.qml' | |||
4814 | --- ubuntu-printing-app/components/ExpandableListItem.qml 2016-11-25 16:47:10 +0000 | |||
4815 | +++ ubuntu-printing-app/components/ExpandableListItem.qml 1970-01-01 00:00:00 +0000 | |||
4816 | @@ -1,82 +0,0 @@ | |||
4817 | 1 | /* | ||
4818 | 2 | * Copyright (C) 2015-2016 Canonical Ltd | ||
4819 | 3 | * | ||
4820 | 4 | * This file is part of Ubuntu Weather App | ||
4821 | 5 | * | ||
4822 | 6 | * Ubuntu Weather App is free software: you can redistribute it and/or modify | ||
4823 | 7 | * it under the terms of the GNU General Public License version 3 as | ||
4824 | 8 | * published by the Free Software Foundation. | ||
4825 | 9 | * | ||
4826 | 10 | * Ubuntu Weather App is distributed in the hope that it will be useful, | ||
4827 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4828 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4829 | 13 | * GNU General Public License for more details. | ||
4830 | 14 | * | ||
4831 | 15 | * You should have received a copy of the GNU General Public License | ||
4832 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4833 | 17 | */ | ||
4834 | 18 | |||
4835 | 19 | import QtQuick 2.4 | ||
4836 | 20 | import Ubuntu.Components 1.3 | ||
4837 | 21 | |||
4838 | 22 | /* | ||
4839 | 23 | Component which extends the SDK Expandable list item and provides a easy | ||
4840 | 24 | to use component where the title, subtitle and a listview can be displayed. It | ||
4841 | 25 | matches the design specification provided for clock. | ||
4842 | 26 | */ | ||
4843 | 27 | |||
4844 | 28 | ListItem { | ||
4845 | 29 | id: expandableListItem | ||
4846 | 30 | |||
4847 | 31 | // Public APIs | ||
4848 | 32 | property ListModel model | ||
4849 | 33 | property Component delegate | ||
4850 | 34 | property alias title: expandableHeader.title | ||
4851 | 35 | property alias subText: expandableHeader.subtitle | ||
4852 | 36 | property alias listViewHeight: expandableList.height | ||
4853 | 37 | |||
4854 | 38 | highlightColor: "Transparent" | ||
4855 | 39 | height: expandableHeader.height + divider.height | ||
4856 | 40 | expansion.height: contentColumn.height | ||
4857 | 41 | onClicked: expansion.expanded = !expansion.expanded | ||
4858 | 42 | |||
4859 | 43 | Column { | ||
4860 | 44 | id: contentColumn | ||
4861 | 45 | |||
4862 | 46 | anchors { | ||
4863 | 47 | left: parent.left | ||
4864 | 48 | right: parent.right | ||
4865 | 49 | } | ||
4866 | 50 | |||
4867 | 51 | ListItem { | ||
4868 | 52 | height: expandableHeader.height + divider.height | ||
4869 | 53 | ListItemLayout { | ||
4870 | 54 | id: expandableHeader | ||
4871 | 55 | |||
4872 | 56 | Icon { | ||
4873 | 57 | id: arrow | ||
4874 | 58 | |||
4875 | 59 | width: units.gu(2) | ||
4876 | 60 | height: width | ||
4877 | 61 | SlotsLayout.position: SlotsLayout.Trailing | ||
4878 | 62 | SlotsLayout.overrideVerticalPositioning: true | ||
4879 | 63 | anchors.verticalCenter: parent.verticalCenter | ||
4880 | 64 | name: "go-down" | ||
4881 | 65 | rotation: expandableListItem.expansion.expanded ? 180 : 0 | ||
4882 | 66 | |||
4883 | 67 | Behavior on rotation { | ||
4884 | 68 | UbuntuNumberAnimation {} | ||
4885 | 69 | } | ||
4886 | 70 | } | ||
4887 | 71 | } | ||
4888 | 72 | } | ||
4889 | 73 | |||
4890 | 74 | ListView { | ||
4891 | 75 | id: expandableList | ||
4892 | 76 | width: parent.width | ||
4893 | 77 | interactive: false | ||
4894 | 78 | model: expandableListItem.model | ||
4895 | 79 | delegate: expandableListItem.delegate | ||
4896 | 80 | } | ||
4897 | 81 | } | ||
4898 | 82 | } | ||
4899 | 83 | 0 | ||
4900 | === added file 'ubuntu-printing-app/components/LabelRow.qml' | |||
4901 | --- ubuntu-printing-app/components/LabelRow.qml 1970-01-01 00:00:00 +0000 | |||
4902 | +++ ubuntu-printing-app/components/LabelRow.qml 2017-02-08 21:32:20 +0000 | |||
4903 | @@ -0,0 +1,52 @@ | |||
4904 | 1 | /* | ||
4905 | 2 | * Copyright 2016 Canonical Ltd. | ||
4906 | 3 | * | ||
4907 | 4 | * This file is part of ubuntu-printing-app. | ||
4908 | 5 | * | ||
4909 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
4910 | 7 | * it under the terms of the GNU General Public License as published by | ||
4911 | 8 | * the Free Software Foundation; version 3. | ||
4912 | 9 | * | ||
4913 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
4914 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4915 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4916 | 13 | * GNU General Public License for more details. | ||
4917 | 14 | * | ||
4918 | 15 | * You should have received a copy of the GNU General Public License | ||
4919 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4920 | 17 | * | ||
4921 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
4922 | 19 | */ | ||
4923 | 20 | import QtQuick 2.4 | ||
4924 | 21 | import QtQuick.Layouts 1.1 | ||
4925 | 22 | |||
4926 | 23 | import Ubuntu.Components 1.3 | ||
4927 | 24 | |||
4928 | 25 | RowLayout { | ||
4929 | 26 | anchors { | ||
4930 | 27 | left: parent.left | ||
4931 | 28 | leftMargin: units.gu(2) | ||
4932 | 29 | right: parent.right | ||
4933 | 30 | rightMargin: units.gu(2) | ||
4934 | 31 | } | ||
4935 | 32 | Layout.maximumWidth: width | ||
4936 | 33 | |||
4937 | 34 | property alias enabled: secondaryLabel.enabled | ||
4938 | 35 | property alias primaryText: primaryLabel.text | ||
4939 | 36 | property alias secondaryText: secondaryLabel.text | ||
4940 | 37 | |||
4941 | 38 | Label { | ||
4942 | 39 | id: primaryLabel | ||
4943 | 40 | Layout.preferredWidth: units.gu(10) | ||
4944 | 41 | objectName: "primary" | ||
4945 | 42 | } | ||
4946 | 43 | |||
4947 | 44 | Label { | ||
4948 | 45 | id: secondaryLabel | ||
4949 | 46 | Layout.fillWidth: true | ||
4950 | 47 | Layout.preferredHeight: units.gu(3) | ||
4951 | 48 | Layout.preferredWidth: units.gu(10) | ||
4952 | 49 | objectName: "secondary" | ||
4953 | 50 | verticalAlignment: Text.AlignVCenter | ||
4954 | 51 | } | ||
4955 | 52 | } | ||
4956 | 0 | 53 | ||
4957 | === added file 'ubuntu-printing-app/components/PreviewRow.qml' | |||
4958 | --- ubuntu-printing-app/components/PreviewRow.qml 1970-01-01 00:00:00 +0000 | |||
4959 | +++ ubuntu-printing-app/components/PreviewRow.qml 2017-02-08 21:32:20 +0000 | |||
4960 | @@ -0,0 +1,142 @@ | |||
4961 | 1 | /* | ||
4962 | 2 | * Copyright 2016 Canonical Ltd. | ||
4963 | 3 | * | ||
4964 | 4 | * This file is part of ubuntu-printing-app. | ||
4965 | 5 | * | ||
4966 | 6 | * ubuntu-printing-app is free software; you can redistribute it and/or modify | ||
4967 | 7 | * it under the terms of the GNU General Public License as published by | ||
4968 | 8 | * the Free Software Foundation; version 3. | ||
4969 | 9 | * | ||
4970 | 10 | * ubuntu-printing-app is distributed in the hope that it will be useful, | ||
4971 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4972 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4973 | 13 | * GNU General Public License for more details. | ||
4974 | 14 | * | ||
4975 | 15 | * You should have received a copy of the GNU General Public License | ||
4976 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4977 | 17 | * | ||
4978 | 18 | * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> | ||
4979 | 19 | */ | ||
4980 | 20 | import QtQuick 2.4 | ||
4981 | 21 | import Ubuntu.Components 1.3 | ||
4982 | 22 | |||
4983 | 23 | import UbuntuPrintingApp 1.0 | ||
4984 | 24 | import Ubuntu.Settings.Printers 0.1 | ||
4985 | 25 | |||
4986 | 26 | Rectangle { | ||
4987 | 27 | id: previewRow | ||
4988 | 28 | anchors { | ||
4989 | 29 | left: parent.left | ||
4990 | 30 | right: parent.right | ||
4991 | 31 | } | ||
4992 | 32 | // Use foreground as this element is ontop of the background | ||
4993 | 33 | color: theme.palette.normal.foreground | ||
4994 | 34 | // Height is smallest of | ||
4995 | 35 | // - calc'd height using aspect and width of image | ||
4996 | 36 | // - 2/3 height of the view | ||
4997 | 37 | implicitHeight: Math.min((view.width - units.gu(10)) / pageHelper.aspect, view.height / 1.5) | ||
4998 | 38 | |||
4999 | 39 | property Document document | ||
5000 | 40 | property var printerJob |
The diff has been truncated for viewing.