-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtaskbar.cpp
More file actions
226 lines (175 loc) · 5 KB
/
taskbar.cpp
File metadata and controls
226 lines (175 loc) · 5 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/**
* -----------------------------------------------------
* File taskbar.cpp
* Authors David Ordnung, Impact
* License GPLv3
* Web http://dordnung.de, http://gugyclan.eu
* -----------------------------------------------------
*
* Copyright (C) 2013-2017 David Ordnung, Impact
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
// Includes Project
#include "taskbar.h"
#include "main.h"
#include "log.h"
#include "config.h"
#include "calladmin-client.h"
// Wx
#include <wx/stdpaths.h>
// Global icon
TaskBarIcon *m_taskBarIcon = NULL;
// unused warning -> disable
#pragma warning(disable: 4100)
// Taskbar ID's
enum
{
PU_RESTORE = wxID_HIGHEST+600,
PU_UPDATE,
#if defined(__WXMSW__)
PU_AUTOSTART,
#endif
PU_EXIT,
};
// Taskbar Events
BEGIN_EVENT_TABLE(TaskBarIcon, wxTaskBarIcon)
EVT_MENU(PU_RESTORE, TaskBarIcon::OnMenuRestore)
EVT_MENU(PU_UPDATE, TaskBarIcon::OnMenuUpdate)
#if defined(__WXMSW__)
EVT_MENU(PU_AUTOSTART, TaskBarIcon::OnMenuAutoStart)
#endif
EVT_MENU(PU_EXIT, TaskBarIcon::OnMenuExit)
EVT_TASKBAR_LEFT_DCLICK (TaskBarIcon::OnLeftButtonDClick)
END_EVENT_TABLE()
// Set Icon of Taskbar
TaskBarIcon::TaskBarIcon()
{
#if defined(__WXMSW__)
SetIcon(wxIcon("calladmin_icon", wxBITMAP_TYPE_ICO_RESOURCE), "Call Admin Client");
#else
wxLogNull nolog;
SetIcon(wxIcon(getAppPath("resources/calladmin_icon.ico"), wxBITMAP_TYPE_ICON), "Call Admin Client");
#endif
}
// Restore main dialog
void TaskBarIcon::OnMenuRestore(wxCommandEvent&)
{
if (main_dialog != NULL)
{
main_dialog->Show(true);
}
}
// On exit -> Exit hole programm
void TaskBarIcon::OnMenuExit(wxCommandEvent&)
{
exitProgramm();
}
#if defined(__WXMSW__)
// Append/Remove to Autostart
void TaskBarIcon::OnMenuAutoStart(wxCommandEvent& event)
{
// Registry Key
HKEY hkRegistry;
// Open Key
if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\", 0, KEY_WRITE, &hkRegistry) == ERROR_SUCCESS)
{
// He checked it
if (event.IsChecked())
{
// Get App Path
wxString appPath = wxStandardPaths::Get().GetExecutablePath();
// Close to Taskbar on Autostart
appPath = "\"" + appPath + "\"" + " -taskbar";
// Write in
RegSetValueExW(hkRegistry, L"CallAdmin-Client", 0, REG_SZ, (BYTE*)appPath.wc_str(), (wcslen(appPath.wc_str()) + 1) * sizeof(wchar_t));
LogAction("Added Call Admin to the auto start list");
}
else
{
// Remove it
RegDeleteValueA(hkRegistry, "CallAdmin-Client");
LogAction("Removed Call Admin from the auto start list");
}
// Close Key
RegCloseKey(hkRegistry);
}
}
#endif
// Check for update
void TaskBarIcon::OnMenuUpdate(wxCommandEvent&)
{
checkUpdate();
}
// Shows a Message
void TaskBarIcon::ShowMessage(wxString title, wxString message, wxWindow* parent)
{
#if defined(__WXMSW__) && wxUSE_TASKBARICON_BALLOONS
m_taskBarIcon->ShowBalloon(title, message, 15000, wxICON_INFORMATION);
#else
// Not the taskbar message
if (message != "Call Admin is now in the taskbar!")
{
wxMessageBox(message, title, wxICON_INFORMATION|wxOK, parent);
}
#endif
}
// Create the Taskbar Menu
wxMenu *TaskBarIcon::CreatePopupMenu()
{
wxMenu *menu = new wxMenu();
menu->Append(PU_RESTORE, "Restore Windows");
menu->AppendSeparator();
#if defined(__WXMSW__)
// Check Auto run Key
HKEY hkRegistry;
bool autoRun = false;
// Open it
if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\", 0, KEY_QUERY_VALUE, &hkRegistry) == ERROR_SUCCESS)
{
// Path in the registry
wchar_t wszPath[4096];
memset(wszPath, 0, sizeof(wszPath));
DWORD dwType, dwSize = sizeof(wszPath) - 1;
// Look for calladmin
if (RegQueryValueExW(hkRegistry, L"CallAdmin-Client", 0, &dwType, (unsigned char *)wszPath, &dwSize) == ERROR_SUCCESS)
{
// Is Path the same?
if (wxString(wszPath).Contains(wxStandardPaths::Get().GetExecutablePath()))
{
// So it's on
autoRun = true;
}
}
// Close the Key
RegCloseKey(hkRegistry);
}
#endif
menu->Append(PU_UPDATE, "Check For Update");
#if defined(__WXMSW__)
menu->Append(PU_AUTOSTART, "Start With Windows", wxEmptyString, wxITEM_CHECK)->Check(autoRun);
#endif
menu->AppendSeparator();
menu->Append(PU_EXIT, "Exit");
return menu;
}
// On doppel left click -> open Menu
void TaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent&)
{
if (main_dialog != NULL)
{
main_dialog->Show(true);
main_dialog->Restore();
}
}