Merge lp:~ahayzen/ubuntu-settings-components/jobmodel-use-notifications into lp:~phablet-team/ubuntu-settings-components/printer-components

Proposed by Andrew Hayzen
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 227
Merged at revision: 227
Proposed branch: lp:~ahayzen/ubuntu-settings-components/jobmodel-use-notifications
Merge into: lp:~phablet-team/ubuntu-settings-components/printer-components
Diff against target: 259 lines (+117/-28)
7 files modified
plugins/Ubuntu/Settings/Printers/backend/backend.h (+39/-0)
plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp (+24/-0)
plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp (+28/-9)
plugins/Ubuntu/Settings/Printers/models/jobmodel.h (+9/-4)
plugins/Ubuntu/Settings/Printers/models/printermodel.cpp (+1/-1)
plugins/Ubuntu/Settings/Printers/printer/printer.cpp (+3/-2)
plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp (+13/-12)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-settings-components/jobmodel-use-notifications
Reviewer Review Type Date Requested Status
Jonas G. Drange (community) Approve
Review via email: mp+316350@code.launchpad.net

Commit message

* Link notifications to JobModel - removing polling
* Fix compiler errors that appeared from the previous branch
* Fix logic change in last branch that was wrong way around

Description of the change

* Link notifications to JobModel - removing polling
* Fix compiler errors that appeared from the previous branch
* Fix logic change in last branch that was wrong way around

To post a comment you must log in.
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/Ubuntu/Settings/Printers/backend/backend.h'
2--- plugins/Ubuntu/Settings/Printers/backend/backend.h 2017-02-03 12:04:46 +0000
3+++ plugins/Ubuntu/Settings/Printers/backend/backend.h 2017-02-03 16:45:28 +0000
4@@ -152,6 +152,45 @@
5 void printerDriversLoaded(const QList<PrinterDriver> &drivers);
6 void printerDriversFailedToLoad(const QString &errorMessage);
7
8+ void jobCompleted(
9+ const QString &text,
10+ const QString &printerUri,
11+ const QString &printerName,
12+ uint printerState,
13+ const QString &printerStateReason,
14+ bool acceptingJobs,
15+ uint jobId,
16+ uint jobState,
17+ const QString &jobStateReason,
18+ const QString &job_name,
19+ uint jobImpressionsCompleted
20+ );
21+ void jobCreated(
22+ const QString &text,
23+ const QString &printerUri,
24+ const QString &printerName,
25+ uint printerState,
26+ const QString &printerStateReason,
27+ bool acceptingJobs,
28+ uint jobId,
29+ uint jobState,
30+ const QString &jobStateReason,
31+ const QString &job_name,
32+ uint jobImpressionsCompleted
33+ );
34+ void jobState(
35+ const QString &text,
36+ const QString &printerUri,
37+ const QString &printerName,
38+ uint printerState,
39+ const QString &printerStateReason,
40+ bool acceptingJobs,
41+ uint jobId,
42+ uint jobState,
43+ const QString &jobStateReason,
44+ const QString &job_name,
45+ uint jobImpressionsCompleted
46+ );
47 void printerAdded(
48 const QString &text,
49 const QString &printerUri,
50
51=== modified file 'plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp'
52--- plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp 2017-02-03 13:58:25 +0000
53+++ plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp 2017-02-03 16:45:28 +0000
54@@ -46,6 +46,30 @@
55 connect(m_cups, SIGNAL(printerDriversFailedToLoad(const QString&)),
56 this, SIGNAL(printerDriversFailedToLoad(const QString&)));
57
58+ connect(m_notifier, SIGNAL(JobCompleted(const QString&, const QString&,
59+ const QString&, uint,
60+ const QString&, bool, uint, uint,
61+ const QString&, const QString&, uint)),
62+ this, SIGNAL(jobCompleted(const QString&, const QString&,
63+ const QString&, uint, const QString&,
64+ bool, uint, uint, const QString&,
65+ const QString&, uint)));
66+ connect(m_notifier, SIGNAL(JobCreated(const QString&, const QString&,
67+ const QString&, uint, const QString&,
68+ bool, uint, uint, const QString&,
69+ const QString&, uint)),
70+ this, SIGNAL(jobCreated(const QString&, const QString&,
71+ const QString&, uint, const QString&, bool,
72+ uint, uint, const QString&, const QString&,
73+ uint)));
74+ connect(m_notifier, SIGNAL(JobState(const QString&, const QString&,
75+ const QString&, uint, const QString&,
76+ bool, uint, uint, const QString&,
77+ const QString&, uint)),
78+ this, SIGNAL(jobState(const QString&, const QString&,
79+ const QString&, uint, const QString&, bool,
80+ uint, uint, const QString&, const QString&,
81+ uint)));
82 connect(m_notifier, SIGNAL(PrinterAdded(const QString&, const QString&,
83 const QString&, uint,
84 const QString&, bool)),
85
86=== modified file 'plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp'
87--- plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp 2017-02-03 14:43:41 +0000
88+++ plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp 2017-02-03 16:45:28 +0000
89@@ -23,32 +23,51 @@
90
91 #include <QDebug>
92
93-JobModel::JobModel(const int updateIntervalMSecs, QObject *parent)
94- : JobModel(QStringLiteral(""), new PrinterCupsBackend, updateIntervalMSecs, parent)
95+JobModel::JobModel(QObject *parent)
96+ : JobModel(QStringLiteral(""), new PrinterCupsBackend, parent)
97 {
98 }
99
100 JobModel::JobModel(const QString &printerName, PrinterBackend *backend,
101- const int updateIntervalMSecs,
102 QObject *parent)
103 : QAbstractListModel(parent)
104 , m_backend(backend)
105 , m_printer_name(printerName)
106 {
107 update();
108- startUpdateTimer(updateIntervalMSecs);
109+
110+ QObject::connect(m_backend, &PrinterBackend::jobCreated,
111+ this, &JobModel::jobSignalCatchAll);
112+ QObject::connect(m_backend, &PrinterBackend::jobState,
113+ this, &JobModel::jobSignalCatchAll);
114+ QObject::connect(m_backend, &PrinterBackend::jobCompleted,
115+ this, &JobModel::jobSignalCatchAll);
116 }
117
118 JobModel::~JobModel()
119 {
120 }
121
122-void JobModel::startUpdateTimer(const int &msecs)
123+void JobModel::jobSignalCatchAll(
124+ const QString &text, const QString &printer_uri,
125+ const QString &printer_name, uint printer_state,
126+ const QString &printer_state_reasons, bool printer_is_accepting_jobs,
127+ uint job_id, uint job_state, const QString &job_state_reasons,
128+ const QString &job_name, uint job_impressions_completed)
129 {
130- // Start a timer to poll for changes in the printers
131- m_update_timer.setParent(this);
132- connect(&m_update_timer, SIGNAL(timeout()), this, SLOT(update()));
133- m_update_timer.start(msecs);
134+ Q_UNUSED(text);
135+ Q_UNUSED(printer_uri);
136+ Q_UNUSED(printer_name);
137+ Q_UNUSED(printer_state);
138+ Q_UNUSED(printer_state_reasons);
139+ Q_UNUSED(printer_is_accepting_jobs);
140+ Q_UNUSED(job_id);
141+ Q_UNUSED(job_state);
142+ Q_UNUSED(job_state_reasons);
143+ Q_UNUSED(job_name);
144+ Q_UNUSED(job_impressions_completed);
145+
146+ update();
147 }
148
149 void JobModel::update()
150
151=== modified file 'plugins/Ubuntu/Settings/Printers/models/jobmodel.h'
152--- plugins/Ubuntu/Settings/Printers/models/jobmodel.h 2017-02-02 17:22:55 +0000
153+++ plugins/Ubuntu/Settings/Printers/models/jobmodel.h 2017-02-03 16:45:28 +0000
154@@ -35,8 +35,8 @@
155
156 Q_PROPERTY(int count READ count NOTIFY countChanged)
157 public:
158- explicit JobModel(const int updateIntervalMSecs=5000, QObject *parent = Q_NULLPTR);
159- explicit JobModel(const QString &printerName, PrinterBackend *backend, const int updateIntervalMSecs=5000,
160+ explicit JobModel(QObject *parent = Q_NULLPTR);
161+ explicit JobModel(const QString &printerName, PrinterBackend *backend,
162 QObject *parent = Q_NULLPTR);
163 ~JobModel();
164
165@@ -59,14 +59,19 @@
166
167 Q_INVOKABLE QVariantMap get(const int row) const;
168 private:
169- QTimer m_update_timer;
170 PrinterBackend *m_backend;
171 QString m_printer_name;
172
173 QList<QSharedPointer<PrinterJob>> m_jobs;
174 private Q_SLOTS:
175- void startUpdateTimer(const int &msecs);
176 void update();
177+ void jobSignalCatchAll(const QString &text, const QString &printer_uri,
178+ const QString &printer_name, uint printer_state,
179+ const QString &printer_state_reasons,
180+ bool printer_is_accepting_jobs, uint job_id,
181+ uint job_state, const QString &job_state_reasons,
182+ const QString &job_name,
183+ uint job_impressions_completed);
184
185 Q_SIGNALS:
186 void countChanged();
187
188=== modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.cpp'
189--- plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-02-03 14:43:41 +0000
190+++ plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-02-03 16:45:28 +0000
191@@ -139,7 +139,7 @@
192
193 m_printers.insert(i, newPrinters.at(i));
194
195- JobModel *model = new JobModel(newPrinters.at(i)->name(), m_backend, 5000, this);
196+ JobModel *model = new JobModel(newPrinters.at(i)->name(), m_backend, this);
197 QQmlEngine::setObjectOwnership(model, QQmlEngine::CppOwnership);
198 m_job_models.insert(newPrinters.at(i)->name(), model);
199
200
201=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printer.cpp'
202--- plugins/Ubuntu/Settings/Printers/printer/printer.cpp 2017-02-03 14:43:41 +0000
203+++ plugins/Ubuntu/Settings/Printers/printer/printer.cpp 2017-02-03 16:45:28 +0000
204@@ -280,7 +280,7 @@
205
206 }
207
208-void Printer::deepCompare(Printer *other) const
209+bool Printer::deepCompare(Printer *other) const
210 {
211 bool changed = false;
212
213@@ -295,7 +295,8 @@
214 // TODO: enabled
215 // TODO: errorPolicy
216
217- return changed;
218+ // Return true if they are the same, so no change
219+ return changed == false;
220 }
221
222 void Printer::updateFrom(Printer* newPrinter)
223
224=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp'
225--- plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-02-03 14:43:41 +0000
226+++ plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-02-03 16:45:28 +0000
227@@ -356,19 +356,20 @@
228
229 bool changed = false;
230
231- changed |= collate() != newPrinterJob->collate();
232- changed |= colorModel() != newPrinterJob->colorModel();
233- changed |= copies() != newPrinterJob->copies();
234- changed |= duplexMode() != newPrinterJob->duplexMode();
235- changed |= landscape() != newPrinterJob->landscape();
236- changed |= printRange() != newPrinterJob->printRange();
237- changed |= printRangeMode() != newPrinterJob->printRangeMode();
238- changed |= quality() != newPrinterJob->quality();
239- changed |= reverse() != newPrinterJob->reverse();
240- changed |= state() != newPrinterJob->state();
241- changed |= title() != newPrinterJob->title();
242+ changed |= collate() != other->collate();
243+ changed |= colorModel() != other->colorModel();
244+ changed |= copies() != other->copies();
245+ changed |= duplexMode() != other->duplexMode();
246+ changed |= landscape() != other->landscape();
247+ changed |= printRange() != other->printRange();
248+ changed |= printRangeMode() != other->printRangeMode();
249+ changed |= quality() != other->quality();
250+ changed |= reverse() != other->reverse();
251+ changed |= state() != other->state();
252+ changed |= title() != other->title();
253
254- return changed;
255+ // Return true if they are the same, so no change
256+ return changed == false;
257 }
258
259 void PrinterJob::updateFrom(QSharedPointer<PrinterJob> newPrinterJob)

Subscribers

People subscribed via source and target branches