taskbarprogress.cpp
1 //------------------------------------------------------------------------------
2 // taskbarprogress.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2015 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "taskbarprogress.h"
24 
25 #include <cassert>
26 #include <QSysInfo>
27 
28 // [Zalewa] I suppose the #ifdef checks could be a bit more abstract
29 // just in case if we ever have another platform that supports similar
30 // functionality, but let's worry about that when it comes to that.
31 
32 #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) && defined(Q_OS_WIN32)
33 #define WIN_TASKBAR
34 #endif
35 
36 #ifdef WIN_TASKBAR
37 #include <QWinTaskbarProgress>
38 #endif
39 
40 DClass<TaskbarProgress>
41 {
42 public:
43 #ifdef WIN_TASKBAR
44  QWinTaskbarProgress *progress;
45 #endif
46 
47  bool isAllowedOsVersion() const
48  {
49 #ifdef WIN_TASKBAR
50  return QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7;
51 #else
52  return false;
53 #endif
54  }
55 };
56 DPointered(TaskbarProgress)
57 
58 TaskbarProgress::TaskbarProgress(QWinTaskbarProgress *progress, QObject *parent)
59 : QObject(parent)
60 {
61 #ifdef WIN_TASKBAR
62  d->progress = NULL;
63  assert(d->isAllowedOsVersion());
64  if (d->isAllowedOsVersion())
65  {
66  d->progress = progress;
67  }
68 #endif
69  construct();
70 }
71 
72 TaskbarProgress::TaskbarProgress(QObject *parent)
73 : QObject(parent)
74 {
75 #ifdef WIN_TASKBAR
76  d->progress = NULL;
77  if (d->isAllowedOsVersion())
78  {
79  d->progress = new QWinTaskbarProgress(this);
80  }
81 #endif
82  construct();
83 }
84 
85 void TaskbarProgress::construct()
86 {
87 #ifdef WIN_TASKBAR
88  if (d->progress != NULL)
89  {
90  this->connect(d->progress, SIGNAL(maximumChanged(int)), SIGNAL(maximumChanged(int)));
91  this->connect(d->progress, SIGNAL(minimumChanged(int)), SIGNAL(minimumChanged(int)));
92  this->connect(d->progress, SIGNAL(valueChanged(int)), SIGNAL(valueChanged(int)));
93  this->connect(d->progress, SIGNAL(visibilityChanged(bool)), SIGNAL(visibilityChanged(bool)));
94  }
95 #endif
96 }
97 
98 bool TaskbarProgress::isPaused() const
99 {
100 #ifdef WIN_TASKBAR
101  if (d->progress != NULL)
102  {
103  return d->progress->isPaused();
104  }
105 #endif
106  return false;
107 }
108 
109 bool TaskbarProgress::isStopped() const
110 {
111 #ifdef WIN_TASKBAR
112  if (d->progress != NULL)
113  {
114  return d->progress->isStopped();
115  }
116 #endif
117  return false;
118 }
119 
120 bool TaskbarProgress::isVisible() const
121 {
122 #ifdef WIN_TASKBAR
123  if (d->progress != NULL)
124  {
125  return d->progress->isVisible();
126  }
127 #endif
128  return false;
129 }
130 
131 int TaskbarProgress::maximum() const
132 {
133 #ifdef WIN_TASKBAR
134  if (d->progress != NULL)
135  {
136  return d->progress->maximum();
137  }
138 #endif
139  return 0;
140 }
141 
142 int TaskbarProgress::minimum() const
143 {
144 #ifdef WIN_TASKBAR
145  if (d->progress != NULL)
146  {
147  return d->progress->minimum();
148  }
149 #endif
150  return 0;
151 }
152 
153 int TaskbarProgress::value() const
154 {
155 #ifdef WIN_TASKBAR
156  if (d->progress != NULL)
157  {
158  return d->progress->value();
159  }
160 #endif
161  return 0;
162 }
163 
164 void TaskbarProgress::hide()
165 {
166 #ifdef WIN_TASKBAR
167  if (d->progress != NULL)
168  {
169  d->progress->hide();
170  }
171 #endif
172 }
173 
174 void TaskbarProgress::pause()
175 {
176 #ifdef WIN_TASKBAR
177  if (d->progress != NULL)
178  {
179  d->progress->pause();
180  }
181 #endif
182 }
183 
184 void TaskbarProgress::reset()
185 {
186 #ifdef WIN_TASKBAR
187  if (d->progress != NULL)
188  {
189  d->progress->reset();
190  }
191 #endif
192 }
193 
194 void TaskbarProgress::resume()
195 {
196 #ifdef WIN_TASKBAR
197  if (d->progress != NULL)
198  {
199  d->progress->resume();
200  }
201 #endif
202 }
203 
204 void TaskbarProgress::setMaximum(int maximum)
205 {
206 #ifdef WIN_TASKBAR
207  if (d->progress != NULL)
208  {
209  d->progress->setMaximum(maximum);
210  }
211 #endif
212 }
213 
214 void TaskbarProgress::setMinimum(int minimum)
215 {
216 #ifdef WIN_TASKBAR
217  if (d->progress != NULL)
218  {
219  d->progress->setMinimum(minimum);
220  }
221 #endif
222 }
223 
224 void TaskbarProgress::setPaused(bool paused)
225 {
226 #ifdef WIN_TASKBAR
227  if (d->progress != NULL)
228  {
229  d->progress->setPaused(paused);
230  }
231 #endif
232 }
233 
234 void TaskbarProgress::setRange(int minimum, int maximum)
235 {
236 #ifdef WIN_TASKBAR
237  if (d->progress != NULL)
238  {
239  d->progress->setRange(minimum, maximum);
240  }
241 #endif
242 }
243 
244 void TaskbarProgress::setValue(int value)
245 {
246 #ifdef WIN_TASKBAR
247  if (d->progress != NULL)
248  {
249  d->progress->setValue(value);
250  }
251 #endif
252 }
253 
254 void TaskbarProgress::setVisible(bool visible)
255 {
256 #ifdef WIN_TASKBAR
257  if (d->progress != NULL)
258  {
259  d->progress->setVisible(visible);
260  }
261 #endif
262 }
263 
264 void TaskbarProgress::show()
265 {
266 #ifdef WIN_TASKBAR
267  if (d->progress != NULL)
268  {
269  d->progress->show();
270  }
271 #endif
272 }
273 
274 void TaskbarProgress::stop()
275 {
276 #ifdef WIN_TASKBAR
277  if (d->progress != NULL)
278  {
279  d->progress->stop();
280  }
281 #endif
282 }
Platform-agnostic wrapper for QWinTaskbarProgress.