-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathTaskBarBaloon.cpp
183 lines (154 loc) · 5.51 KB
/
TaskBarBaloon.cpp
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
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011-2015 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "TaskBarBaloon.h"
#include <wx/utils.h>
#include <wx/stdpaths.h>
#include "stringtools.h"
#include "main.h"
#include "Connector.h"
const int TIMER_BALOON=34;
extern MyTimer *timer;
BEGIN_EVENT_TABLE(TaskBarBaloon, wxFrame)
EVT_PAINT(TaskBarBaloon::OnPaint)
EVT_LEFT_DOWN(TaskBarBaloon::OnClick)
EVT_KEY_DOWN(TaskBarBaloon::OnEscape)
EVT_TIMER(TIMER_BALOON,TaskBarBaloon::OnTimerTick)
END_EVENT_TABLE()
TaskBarBaloon::TaskBarBaloon(wxString sTitle, wxString sMessage, std::string new_ident)
: wxFrame(NULL,-1,wxT("no title"),wxDefaultPosition,wxDefaultSize,wxNO_BORDER | wxSTAY_ON_TOP | wxFRAME_SHAPED | wxFRAME_NO_TASKBAR),
new_ident(new_ident)
{
wxColour bgColour(255,255,231); // yellow BG
this->SetBackgroundColour(bgColour);
wxBoxSizer * mainSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText * title = new wxStaticText(this, -1, sTitle);
wxFont titleFont = this->GetFont();
titleFont.SetWeight(wxFONTWEIGHT_BOLD);
title->SetFont(titleFont);
mainSizer->Add(title,0,wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5);
title->Connect(wxEVT_LEFT_DOWN,
wxMouseEventHandler(TaskBarBaloon::OnClick), NULL, this );
title->Connect(wxEVT_KEY_DOWN,
wxKeyEventHandler(TaskBarBaloon::OnEscape), NULL, this );
wxStaticText * text = new wxStaticText(this, -1, sMessage);
mainSizer->Add(text,1,wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 5);
text->Connect(wxEVT_LEFT_DOWN,
wxMouseEventHandler(TaskBarBaloon::OnClick), NULL, this );
text->Connect(wxEVT_KEY_DOWN,
wxKeyEventHandler(TaskBarBaloon::OnEscape), NULL, this );
this->SetSizer(mainSizer);
mainSizer->SetSizeHints( this );
this->timer = new wxTimer(this,TIMER_BALOON);
// here, we try to align the frame to the right bottom corner
this->Center();
int iX = 0, iY = 0;
this->GetPosition( &iX, &iY );
iX = (iX * 2) - 2;
iY = (iY * 2) - 2;
this->Move( iX, iY );
}
void TaskBarBaloon::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
int iWidth = 0, iHeight = 0;
this->GetClientSize( &iWidth, &iHeight );
wxPen pen(this->GetForegroundColour());
dc.SetPen(pen);
wxBrush brush(this->GetBackgroundColour());
dc.SetBrush(brush);
dc.Clear();
dc.DrawRectangle(0,0,iWidth,iHeight);
}
/** closing frame at end of timeout */
void TaskBarBaloon::OnTimerTick(wxTimerEvent & event)
{
this->Destroy();
}
/** showing frame and running timer */
void TaskBarBaloon::showBaloon(unsigned int iTimeout)
{
this->Show(false);
this->Show(true);
this->timer->Start(iTimeout,wxTIMER_ONE_SHOT);
}
#ifdef _WIN32
HANDLE ExecuteProcessO( const std::string & CommandLine, const std::string & WorkDir )
{
STARTUPINFOA sStartInfo;
ZeroMemory( &sStartInfo, sizeof(STARTUPINFO) );
sStartInfo.cb = sizeof(STARTUPINFO);
sStartInfo.wShowWindow = SW_SHOWDEFAULT;
sStartInfo.dwFlags = STARTF_USESHOWWINDOW;
PROCESS_INFORMATION sProcessInfo;
ZeroMemory( &sProcessInfo, sizeof(PROCESS_INFORMATION) );
BOOL ok = CreateProcessA( NULL, (char*)CommandLine.c_str(),
NULL, NULL, true,
NORMAL_PRIORITY_CLASS, NULL, WorkDir.c_str() , &sStartInfo, &sProcessInfo );
if ( !ok ) {
sProcessInfo.hProcess = 0;
return sProcessInfo.hProcess;
}
return sProcessInfo.hProcess;
}
HANDLE ExecuteProcess( const std::string & exe, const std::string &args, const std::string & WorkDir )
{
std::string cmd="\""+exe+"\"";
if( args!="" )
cmd+=" "+args;
HANDLE h=ExecuteProcessO(cmd, WorkDir);
if( h!=NULL )
return h;
SHELLEXECUTEINFOA TempInfo = {0};
TempInfo.cbSize = sizeof(SHELLEXECUTEINFOA);
TempInfo.fMask = 0; //SEE_MASK_NOCLOSEPROCESS
TempInfo.hwnd = NULL;
TempInfo.lpVerb = "runas";
TempInfo.lpFile = exe.c_str();
TempInfo.lpParameters = args.c_str();
TempInfo.lpDirectory = WorkDir.c_str();
TempInfo.nShow = SW_NORMAL;
BOOL b=ShellExecuteExA(&TempInfo);
if( b==TRUE )
{
return (HANDLE)1;
}
else
return NULL;
}
#endif
void update_urbackup(void)
{
#ifdef _WIN32
wxStandardPaths& sp = wxStandardPaths::Get();
std::string e_pstr=ExtractFilePath(sp.GetExecutablePath().ToUTF8().data());
ExecuteProcess(e_pstr+"\\UrBackupUpdate.exe","","");
timer->resetDisplayedUpdateInfo();
#endif
}
void TaskBarBaloon::OnClick(wxMouseEvent & event)
{
this->Show(false);
if(new_ident.empty())
{
update_urbackup();
}
else
{
Connector::addNewServer(new_ident);
}
}