1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
// **************************************************************************
#include "taskbar.h"
#ifdef FFS_WIN
#include <zen/dll.h>
#include <zen/win_ver.h>
#include "Taskbar_Seven/taskbar.h"
#elif defined HAVE_UBUNTU_UNITY
#include <unity/unity/unity.h>
#elif defined FFS_MAC
#include <zen/basic_math.h>
#include <zen/string_tools.h>
#include "osx_dock.h"
#endif
using namespace zen;
#ifdef FFS_WIN
using namespace tbseven;
class Taskbar::Pimpl //throw TaskbarNotAvailable
{
public:
Pimpl(const wxTopLevelWindow& window) :
assocWindow(window.GetHWND()),
setStatus_ (getDllName(), funName_setStatus),
setProgress_(getDllName(), funName_setProgress)
{
if (!assocWindow || !setProgress_ || !setStatus_)
throw TaskbarNotAvailable();
if (!zen::win7OrLater())
throw TaskbarNotAvailable();
}
~Pimpl() { setStatus_(assocWindow, tbseven::STATUS_NOPROGRESS); }
void setStatus(Status status)
{
TaskBarStatus tbSevenStatus = tbseven::STATUS_NORMAL;
switch (status)
{
case Taskbar::STATUS_INDETERMINATE:
tbSevenStatus = tbseven::STATUS_INDETERMINATE;
break;
case Taskbar::STATUS_NORMAL:
tbSevenStatus = tbseven::STATUS_NORMAL;
break;
case Taskbar::STATUS_ERROR:
tbSevenStatus = tbseven::STATUS_ERROR;
break;
case Taskbar::STATUS_PAUSED:
tbSevenStatus = tbseven::STATUS_PAUSED;
break;
}
setStatus_(assocWindow, tbSevenStatus);
}
void setProgress(double fraction)
{
setProgress_(assocWindow, fraction * 100000, 100000);
}
private:
void* assocWindow; //HWND
const DllFun<FunType_setStatus> setStatus_;
const DllFun<FunType_setProgress> setProgress_;
};
#elif defined HAVE_UBUNTU_UNITY //Ubuntu unity
namespace
{
const char FFS_DESKTOP_FILE[] = "freefilesync.desktop";
}
class Taskbar::Pimpl //throw (TaskbarNotAvailable)
{
public:
Pimpl(const wxTopLevelWindow& window) :
tbEntry(unity_launcher_entry_get_for_desktop_id(FFS_DESKTOP_FILE))
//tbEntry(unity_launcher_entry_get_for_app_uri("application://freefilesync.desktop"))
{
if (!tbEntry)
throw TaskbarNotAvailable();
}
~Pimpl() { setStatus(STATUS_INDETERMINATE); } //it seems UnityLauncherEntry* does not need destruction
void setStatus(Status status)
{
switch (status)
{
case Taskbar::STATUS_ERROR:
unity_launcher_entry_set_urgent(tbEntry, true);
break;
case Taskbar::STATUS_INDETERMINATE:
unity_launcher_entry_set_urgent(tbEntry, false);
unity_launcher_entry_set_progress_visible(tbEntry, false);
break;
case Taskbar::STATUS_NORMAL:
unity_launcher_entry_set_urgent(tbEntry, false);
unity_launcher_entry_set_progress_visible(tbEntry, true);
break;
case Taskbar::STATUS_PAUSED:
unity_launcher_entry_set_urgent(tbEntry, false);
break;
}
}
void setProgress(double fraction)
{
unity_launcher_entry_set_progress(tbEntry, fraction);
}
private:
UnityLauncherEntry* tbEntry;
};
#elif defined FFS_MAC
class Taskbar::Pimpl
{
public:
Pimpl(const wxTopLevelWindow& window) {}
~Pimpl() { setDockText(""); }
void setStatus(Status status) {}
void setProgress(double fraction)
{
//no decimal places to make output less noisy
setDockText((numberTo<std::string>(numeric::round(fraction * 100.0)) + '%').c_str()); //no need to internationalize fraction!?
}
private:
void setDockText(const char* str)
{
try
{
osx::dockIconSetText(str); //throw OsxError
}
catch (const osx::OsxError& e) { assert(false); }
}
};
#else //no taskbar support
class Taskbar::Pimpl
{
public:
Pimpl(const wxTopLevelWindow& window) { throw TaskbarNotAvailable(); }
void setStatus(Status status) {}
void setProgress(double fraction) {}
};
#endif
//########################################################################################################
Taskbar::Taskbar(const wxTopLevelWindow& window) : pimpl_(new Pimpl(window)) {} //throw TaskbarNotAvailable
Taskbar::~Taskbar() {}
void Taskbar::setStatus(Status status) { pimpl_->setStatus(status); }
void Taskbar::setProgress(double fraction) { pimpl_->setProgress(fraction); }
|