| 1 | /*
|
|---|
| 2 | * synergy -- mouse and keyboard sharing utility
|
|---|
| 3 | * Copyright (C) 2003 Chris Schoeneman
|
|---|
| 4 | *
|
|---|
| 5 | * This package is free software; you can redistribute it and/or
|
|---|
| 6 | * modify it under the terms of the GNU General Public License
|
|---|
| 7 | * found in the file COPYING that should have accompanied this file.
|
|---|
| 8 | *
|
|---|
| 9 | * This package is distributed in the hope that it will be useful,
|
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | * GNU General Public License for more details.
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | #include "CClientTaskBarReceiver.h"
|
|---|
| 16 | #include "CClient.h"
|
|---|
| 17 | #include "CLock.h"
|
|---|
| 18 | #include "CStringUtil.h"
|
|---|
| 19 | #include "IEventQueue.h"
|
|---|
| 20 | #include "CArch.h"
|
|---|
| 21 | #include "Version.h"
|
|---|
| 22 |
|
|---|
| 23 | //
|
|---|
| 24 | // CClientTaskBarReceiver
|
|---|
| 25 | //
|
|---|
| 26 |
|
|---|
| 27 | CClientTaskBarReceiver::CClientTaskBarReceiver() :
|
|---|
| 28 | m_state(kNotRunning)
|
|---|
| 29 | {
|
|---|
| 30 | // do nothing
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | CClientTaskBarReceiver::~CClientTaskBarReceiver()
|
|---|
| 34 | {
|
|---|
| 35 | // do nothing
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | void
|
|---|
| 39 | CClientTaskBarReceiver::updateStatus(CClient* client, const CString& errorMsg)
|
|---|
| 40 | {
|
|---|
| 41 | {
|
|---|
| 42 | // update our status
|
|---|
| 43 | m_errorMessage = errorMsg;
|
|---|
| 44 | if (client == NULL) {
|
|---|
| 45 | if (m_errorMessage.empty()) {
|
|---|
| 46 | m_state = kNotRunning;
|
|---|
| 47 | }
|
|---|
| 48 | else {
|
|---|
| 49 | m_state = kNotWorking;
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 | else {
|
|---|
| 53 | m_server = client->getServerAddress().getHostname();
|
|---|
| 54 |
|
|---|
| 55 | if (client->isConnected()) {
|
|---|
| 56 | m_state = kConnected;
|
|---|
| 57 | }
|
|---|
| 58 | else if (client->isConnecting()) {
|
|---|
| 59 | m_state = kConnecting;
|
|---|
| 60 | }
|
|---|
| 61 | else {
|
|---|
| 62 | m_state = kNotConnected;
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | // let subclasses have a go
|
|---|
| 67 | onStatusChanged(client);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | // tell task bar
|
|---|
| 71 | ARCH->updateReceiver(this);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | CClientTaskBarReceiver::EState
|
|---|
| 75 | CClientTaskBarReceiver::getStatus() const
|
|---|
| 76 | {
|
|---|
| 77 | return m_state;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | const CString&
|
|---|
| 81 | CClientTaskBarReceiver::getErrorMessage() const
|
|---|
| 82 | {
|
|---|
| 83 | return m_errorMessage;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | void
|
|---|
| 87 | CClientTaskBarReceiver::quit()
|
|---|
| 88 | {
|
|---|
| 89 | EVENTQUEUE->addEvent(CEvent(CEvent::kQuit));
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | void
|
|---|
| 93 | CClientTaskBarReceiver::onStatusChanged(CClient*)
|
|---|
| 94 | {
|
|---|
| 95 | // do nothing
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | void
|
|---|
| 99 | CClientTaskBarReceiver::lock() const
|
|---|
| 100 | {
|
|---|
| 101 | // do nothing
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | void
|
|---|
| 105 | CClientTaskBarReceiver::unlock() const
|
|---|
| 106 | {
|
|---|
| 107 | // do nothing
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | std::string
|
|---|
| 111 | CClientTaskBarReceiver::getToolTip() const
|
|---|
| 112 | {
|
|---|
| 113 | switch (m_state) {
|
|---|
| 114 | case kNotRunning:
|
|---|
| 115 | return CStringUtil::print("%s: Not running", kAppVersion);
|
|---|
| 116 |
|
|---|
| 117 | case kNotWorking:
|
|---|
| 118 | return CStringUtil::print("%s: %s",
|
|---|
| 119 | kAppVersion, m_errorMessage.c_str());
|
|---|
| 120 |
|
|---|
| 121 | case kNotConnected:
|
|---|
| 122 | return CStringUtil::print("%s: Not connected: %s",
|
|---|
| 123 | kAppVersion, m_errorMessage.c_str());
|
|---|
| 124 |
|
|---|
| 125 | case kConnecting:
|
|---|
| 126 | return CStringUtil::print("%s: Connecting to %s...",
|
|---|
| 127 | kAppVersion, m_server.c_str());
|
|---|
| 128 |
|
|---|
| 129 | case kConnected:
|
|---|
| 130 | return CStringUtil::print("%s: Connected to %s",
|
|---|
| 131 | kAppVersion, m_server.c_str());
|
|---|
| 132 |
|
|---|
| 133 | default:
|
|---|
| 134 | return "";
|
|---|
| 135 | }
|
|---|
| 136 | }
|
|---|