-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwidget.cpp
317 lines (259 loc) · 7.87 KB
/
mainwidget.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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#include "mainwidget.h"
#include "ui_mainwidget.h"
extern QList<MsgNode*> g_msgList;
QString g_conf = "/.config/isoft/news.ini";
static QString gs_url = "https://10.238.208.133/ovd/client/news.php";
static QString gs_newsFile = "/tmp/news.xml";
mainWidget::mainWidget(QPoint pos, QWidget *parent) :
QWidget(parent),
ui(new Ui::mainWidget)
{
ui->setupUi(this);
setWindowTitle(tr ("消息推送"));
m_widgetPos = pos;
setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
this->initUI();
this->initConn();
this->getAllMsgList();
this->setCmdAll(true);
}
mainWidget::~mainWidget()
{
delete ui;
}
QPoint mainWidget::widgetPos()
{
return this->m_widgetPos;
}
void mainWidget::paintEvent(QPaintEvent*)
{
QPainter painter(this);
QPen pen;
pen.setColor(QColor("#E0E0E0"));
painter.setPen(pen);
painter.setFont(QFont("Arial", 50));
painter.drawRect(QRect(0, 0, this->width() - 1, this->height() - 1));
}
void mainWidget::mousePressEvent(QMouseEvent *event)
{
m_dPos = event->globalPos() - this->pos ();
}
void mainWidget::mouseMoveEvent(QMouseEvent *event)
{
move(event->globalPos() - m_dPos);
m_widgetPos = this->pos();
}
void mainWidget::initUI()
{
ui->searchLineEdit->setPlaceholderText(tr ("请输入关键词"));
ui->allBtn->setStyleSheet ("text-align: left;");
ui->meetBtn->setStyleSheet ("text-align: left;");
ui->policyBtn->setStyleSheet("text-align: left;");
ui->personBtn->setStyleSheet("text-align: left;");
/// 搜索按钮
m_searchAction = new QAction (QIcon(":/search"), tr ("搜索"), ui->searchLineEdit);
/// 把搜索按钮设置在右端
ui->searchLineEdit->addAction (m_searchAction, QLineEdit::TrailingPosition);
m_msgWidget = new MsgWidget;
ui->viewLayout->addWidget (m_msgWidget->getTableView());
ui->pageHLayout->addWidget (m_msgWidget->getPageWidget(), 0, Qt::AlignCenter);
ui->retLabel->setLabelText("返回消息中心列表");
ui->retLabel->setUnderLine(true);
ui->personBtn->setWindowFlags(Qt::FramelessWindowHint);
ui->closeBtn->getIconPath(":/close");
}
void mainWidget::initConn()
{
connect(ui->closeBtn, SIGNAL (clicked()), this, SLOT (hideWidget()));
connect(ui->readCheckBox, SIGNAL (stateChanged(int)), this, SLOT (setCmdNoRead(int)));
connect(ui->allBtn, SIGNAL (clicked(bool)), this, SLOT (setCmdAll(bool)));
connect(ui->meetBtn, SIGNAL (clicked(bool)), this, SLOT (setCmdA(bool)));
connect(ui->policyBtn, SIGNAL (clicked(bool)), this, SLOT (setCmdB(bool)));
connect(ui->personBtn, SIGNAL (clicked(bool)), this, SLOT (setCmdC(bool)));
connect(m_searchAction, SIGNAL (triggered(bool)), this, SLOT (setCmdSearch(bool)));
connect(ui->searchLineEdit, SIGNAL (returnPressed()), this, SLOT (setStartSearch()));
connect(ui->retLabel, SIGNAL (labelClicked(bool)),this, SLOT (setCmdAll(bool)));
}
void mainWidget::getAllMsgList()
{
// 获得网址和消息存储文件名
QString newsFile;
QString url;
QString confFile = QDir::homePath() + g_conf;
QFile fileConf (confFile);
if (!fileConf.exists())
{
newsFile = gs_newsFile;
url = gs_url;
}
else
{
ReadConf readConf (confFile);
url = readConf.getUrl();
newsFile= readConf.getNewsFile();
// qDebug() << "url: " << url << " newsFile: " << newsFile;
}
QProcess p(0);
QString cmd = QString("wget %1 --no-check-certificate -O %2").arg(url).arg(newsFile);
p.start(cmd);
p.waitForStarted(1000);
p.waitForFinished(10000);
qDebug() << "wget";
// https 获取网页消息
// httpMsg httpMsg;
// httpMsg.startRequest(url, newsFile);
QFile file (newsFile);
if (!file.exists())
{
qDebug() << newsFile << "no exist";
return ;
}
// 获取消息
GetMsg getMsg;
getMsg.openXml (newsFile);
getMsg.getMsg ();
}
/// 查看全部
void mainWidget::setCmdAll(bool)
{
/// 取消仅看未读
ui->readCheckBox->setCheckState(Qt::Unchecked);
/// 清空以前的表格
m_msgWidget->removeAllRow();
for (int i = 0; i < g_msgList.count(); ++i)
{
m_msgWidget->addMsg(*g_msgList.at(i), i);
}
ui->msgCntLabel->setText(tr ("共有消息%1个").arg(this->getMsgCnt()));
m_msgWidget->showStartTable();
ui->retLabel->hide();
ui->splitLabel->hide();
}
/// 会议通知 消息
void mainWidget::setCmdA(bool)
{
/// 取消仅看未读
ui->readCheckBox->setCheckState(Qt::Unchecked);
/// 清空以前的表格
m_msgWidget->removeAllRow();
int num = 0;
for (int i = 0; i < g_msgList.count(); ++i)
{
if ('A' == g_msgList.at(i)->type)
{
m_msgWidget->addMsg(*g_msgList.at(i), num);
num++;
}
}
qDebug() << "会议通知 消息: " << num;
ui->msgCntLabel->setText(tr ("共有消息%1个").arg(this->getMsgCnt()));
m_msgWidget->showStartTable();
ui->retLabel->hide();
ui->splitLabel->hide();
}
/// 政策纪律宣贯
void mainWidget::setCmdB(bool)
{
/// 取消仅看未读
ui->readCheckBox->setCheckState(Qt::Unchecked);
/// 清空以前的表格
m_msgWidget->removeAllRow();
int num = 0;
for (int i = 0; i < g_msgList.count(); ++i)
{
if ('B' == g_msgList.at(i)->type)
{
m_msgWidget->addMsg(*g_msgList.at(i), num);
num++;
}
}
ui->msgCntLabel->setText(tr ("共有消息%1个").arg(this->getMsgCnt()));
m_msgWidget->showStartTable();
ui->retLabel->hide();
ui->splitLabel->hide();
}
/// 人事任免通知
void mainWidget::setCmdC(bool)
{
/// 取消仅看未读
ui->readCheckBox->setCheckState(Qt::Unchecked);
/// 清空以前的表格
m_msgWidget->removeAllRow();
int num = 0;
for (int i = 0; i < g_msgList.count(); ++i)
{
if ('C' == g_msgList.at(i)->type)
{
m_msgWidget->addMsg(*g_msgList.at(i), num);
num++;
}
}
ui->msgCntLabel->setText(tr ("共有消息%1个").arg(this->getMsgCnt()));
m_msgWidget->showStartTable();
ui->retLabel->hide();
ui->splitLabel->hide();
}
void mainWidget::setCmdNoRead(int state)
{
qDebug() << "ReadState: " << state;
int num = 0;
if (state == Qt::Checked)
{
/// 清空以前的表格
m_msgWidget->removeAllRow();
for (int i = 0; i < g_msgList.count(); ++i)
{
if (!g_msgList.at(i)->read)
{
m_msgWidget->addMsg(*g_msgList.at(i), num);
num++;
}
}
ui->msgCntLabel->setText(tr ("共有消息%1个").arg(this->getMsgCnt()));
m_msgWidget->showStartTable();
}
else if (state == Qt::Unchecked)
{
this->setCmdAll(true);
}
ui->retLabel->hide();
ui->splitLabel->hide();
}
int mainWidget::getMsgCnt()
{
return m_msgWidget->getMsgCnt();
}
void mainWidget::setStartSearch()
{
this->setCmdSearch(true);
}
void mainWidget::hideWidget()
{
m_widgetPos = this->pos();
this->hide();
}
void mainWidget::setCmdSearch(bool)
{
if (ui->searchLineEdit->text().isEmpty())
{
return;
}
QString keyword (ui->searchLineEdit->text());
qDebug () << "keyword: " << keyword;
/// 取消仅看未读
ui->readCheckBox->setCheckState(Qt::Unchecked);
/// 清空以前的表格
m_msgWidget->removeAllRow();
int num = 0;
for (int i = 0; i < g_msgList.count(); ++i)
{
if (g_msgList.at(i)->title.contains(keyword) > 0)
{
m_msgWidget->addMsg(*g_msgList.at(i), num++);
}
}
ui->msgCntLabel->setText(tr ("查找到包含\"%1\"的结果%2个").arg(keyword).arg(this->getMsgCnt()));
m_msgWidget->showStartTable();
ui->retLabel->show();
ui->splitLabel->show();
}