1 /*
2 * barrier -- mouse and keyboard sharing utility
3 * Copyright (C) 2012-2016 Symless Ltd.
4 * Copyright (C) 2003 Chris Schoeneman
5 *
6 * This package is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * found in the file LICENSE that should have accompanied this file.
9 *
10 * This package 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, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "barrier/ClientTaskBarReceiver.h"
20 #include "client/Client.h"
21 #include "mt/Lock.h"
22 #include "base/String.h"
23 #include "base/IEventQueue.h"
24 #include "arch/Arch.h"
25 #include "common/Version.h"
26
27 //
28 // ClientTaskBarReceiver
29 //
30
ClientTaskBarReceiver(IEventQueue * events)31 ClientTaskBarReceiver::ClientTaskBarReceiver(IEventQueue* events) :
32 m_state(kNotRunning),
33 m_events(events)
34 {
35 // do nothing
36 }
37
~ClientTaskBarReceiver()38 ClientTaskBarReceiver::~ClientTaskBarReceiver()
39 {
40 // do nothing
41 }
42
43 void
updateStatus(Client * client,const String & errorMsg)44 ClientTaskBarReceiver::updateStatus(Client* client, const String& errorMsg)
45 {
46 {
47 // update our status
48 m_errorMessage = errorMsg;
49 if (client == NULL) {
50 if (m_errorMessage.empty()) {
51 m_state = kNotRunning;
52 }
53 else {
54 m_state = kNotWorking;
55 }
56 }
57 else {
58 m_server = client->getServerAddress().getHostname();
59
60 if (client->isConnected()) {
61 m_state = kConnected;
62 }
63 else if (client->isConnecting()) {
64 m_state = kConnecting;
65 }
66 else {
67 m_state = kNotConnected;
68 }
69 }
70
71 // let subclasses have a go
72 onStatusChanged(client);
73 }
74
75 // tell task bar
76 ARCH->updateReceiver(this);
77 }
78
79 ClientTaskBarReceiver::EState
getStatus() const80 ClientTaskBarReceiver::getStatus() const
81 {
82 return m_state;
83 }
84
85 const String&
getErrorMessage() const86 ClientTaskBarReceiver::getErrorMessage() const
87 {
88 return m_errorMessage;
89 }
90
91 void
quit()92 ClientTaskBarReceiver::quit()
93 {
94 m_events->addEvent(Event(Event::kQuit));
95 }
96
97 void
onStatusChanged(Client *)98 ClientTaskBarReceiver::onStatusChanged(Client*)
99 {
100 // do nothing
101 }
102
103 void
lock() const104 ClientTaskBarReceiver::lock() const
105 {
106 // do nothing
107 }
108
109 void
unlock() const110 ClientTaskBarReceiver::unlock() const
111 {
112 // do nothing
113 }
114
115 std::string
getToolTip() const116 ClientTaskBarReceiver::getToolTip() const
117 {
118 switch (m_state) {
119 case kNotRunning:
120 return barrier::string::sprintf("%s: Not running", kAppVersion);
121
122 case kNotWorking:
123 return barrier::string::sprintf("%s: %s",
124 kAppVersion, m_errorMessage.c_str());
125
126 case kNotConnected:
127 return barrier::string::sprintf("%s: Not connected: %s",
128 kAppVersion, m_errorMessage.c_str());
129
130 case kConnecting:
131 return barrier::string::sprintf("%s: Connecting to %s...",
132 kAppVersion, m_server.c_str());
133
134 case kConnected:
135 return barrier::string::sprintf("%s: Connected to %s",
136 kAppVersion, m_server.c_str());
137
138 default:
139 return "";
140 }
141 }
142