-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstatusbar.cpp
114 lines (93 loc) · 2.83 KB
/
statusbar.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
#include "stdafx.h"
#include "statusbar.h"
#include "utilitymanager.h"
StatusBar *g_pStatusBar = NULL;
StatusBar::StatusBar(QFrame * parent)
: QFrame(parent)
{
setObjectName("statusBar");
//setMouseTracking(true);
InitControl();
g_pStatusBar = this;
m_pStatusTimer = new QTimer(this);
connect(m_pStatusTimer, SIGNAL(timeout()), this, SLOT(on_getStatus_timeout()));
m_pStatusTimer->start(ONE_SECOND);
m_pWordTimer = new QTimer(this);
connect(m_pWordTimer, SIGNAL(timeout()), this, SLOT(on_getWord_timeout()));
m_pWordTimer->start(FIVE_SECONDS);
}
StatusBar::~StatusBar()
{
m_pStatusTimer->stop();
m_pWordTimer->stop();
}
void StatusBar::InitControl()
{
m_pCopyrightLabel = new QLabel(this);
m_pCopyrightLabel->setObjectName("copyrightLabel");
m_pCopyrightLabel->setText(tr("Copyright 2013-2015"));
//m_pCopyrightLabel->setOpenExternalLinks(true);
connect(m_pCopyrightLabel, SIGNAL(linkActivated(const QString &)), this, SLOT(on_copyrightLabel_linkActivated(const QString &)));
m_pServerImageLabel = new QLabel(this);
m_pServerImageLabel->setObjectName("serverImageLabel");
m_pServerImageLabel->setProperty("Online", false);
m_pServerStatusLabel = new QLabel(this);
m_pServerStatusLabel->setObjectName("serverStatusLabel");
QHBoxLayout *m_pLayout = new QHBoxLayout(this);
m_pLayout->setSpacing(10);
m_pLayout->setContentsMargins(0, 0, 0, 0);
m_pLayout->addWidget(m_pCopyrightLabel);
m_pLayout->addStretch();
m_pLayout->addWidget(m_pServerImageLabel);
m_pLayout->addWidget(m_pServerStatusLabel);
setLayout(m_pLayout);
}
void StatusBar::SetHotWords(QStringList hotWords)
{
m_hotWords = hotWords;
}
void StatusBar::on_getStatus_timeout()
{
DWORD unknow = 0;
DWORD status = 0;
PDWORD pStatus = &status;
#ifdef LOCAL_KAD_LIB
status = g_kadLibrary.Connect() ? CONNECT_CONNECTED : CONNECT_CONNECTING;
#else
pGetEmuleStatus(&unknow, &status, &pStatus);
#endif
if(status == CONNECT_UNKNOW)
{
m_pServerStatusLabel->setText(tr("Status:Unknow"));
RefreshStyle(m_pServerImageLabel, "Online", false);
}
else if(status == CONNECT_CONNECTING)
{
m_pServerStatusLabel->setText(tr("Status:Connecting"));
RefreshStyle(m_pServerImageLabel, "Online", false);
}
else if(status == CONNECT_ERROR)
{
m_pServerStatusLabel->setText(tr("Status:Disconnected"));
RefreshStyle(m_pServerImageLabel, "Online", false);
}
else if(status == CONNECT_CONNECTED)
{
m_pServerStatusLabel->setText(tr("Status:Connected"));
RefreshStyle(m_pServerImageLabel, "Online", true);
g_isKadConnected = true;
}
}
void StatusBar::on_getWord_timeout()
{
if(m_hotWords.count() > 0)
{
int index = rand() % m_hotWords.count();
QString text = tr("Hot keywords:<a href=\"%1\" style=\"color:#00A2E8\">%1</a>").arg(m_hotWords[index]);
m_pCopyrightLabel->setText(text);
}
}
void StatusBar::on_copyrightLabel_linkActivated(const QString & link)
{
emit searchKey(link);
}