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
|
/*
* Copyright (C) 2008-2012 The QXmpp developers
*
* Author:
* Manjeet Dahiya
*
* Source:
* http://code.google.com/p/qxmpp
*
* This file is a part of QXmpp library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
*/
#include "statusWidget.h"
#include <QMenu>
#include <QFileDialog>
#include <QMessageBox>
statusWidget::statusWidget(QWidget* parent)
{
setupUi(this);
QMenu* menu = new QMenu(this);
menu->addAction(actionAvailable);
menu->addAction(actionBusy);
menu->addAction(actionAway);
// menu->addAction(actionInvisible);
menu->addSeparator();
menu->addAction(actionSign_out);
toolButton_userName->setMenu(menu);
bool check = connect(statusTextWidgetObject, SIGNAL(statusTextChanged(QString)), SIGNAL(statusTextChanged(QString)));
Q_ASSERT(check);
check = connect(actionAvailable, SIGNAL(triggered()), SLOT(presenceMenuTriggered()));
Q_ASSERT(check);
check = connect(actionBusy, SIGNAL(triggered()), SLOT(presenceMenuTriggered()));
Q_ASSERT(check);
check = connect(actionAway, SIGNAL(triggered()), SLOT(presenceMenuTriggered()));
Q_ASSERT(check);
// check = connect(actionInvisible, SIGNAL(triggered()), SLOT(presenceMenuTriggered()));
// Q_ASSERT(check);
check = connect(actionSign_out, SIGNAL(triggered()), SLOT(presenceMenuTriggered()));
Q_ASSERT(check);
check = connect(pushButton_avatar, SIGNAL(clicked()), SLOT(avatarSelection()));
Q_ASSERT(check);
}
void statusWidget::setStatusText(const QString& statusText)
{
statusTextWidgetObject->setStatusText(statusText);
}
void statusWidget::presenceMenuTriggered()
{
QString icon = "green";
QAction* action = qobject_cast<QAction*>(sender());
if(action == actionAvailable)
{
emit presenceTypeChanged(QXmppPresence::Available);
icon = "green";
}
else if(action == actionBusy)
{
emit presenceStatusTypeChanged(QXmppPresence::Status::DND);
icon = "red";
}
else if(action == actionAway)
{
emit presenceStatusTypeChanged(QXmppPresence::Status::Away);
icon = "orange";
}
#if 0
else if(action == actionInvisible)
{
emit presenceStatusTypeChanged(QXmppPresence::Status::Invisible);
icon = "gray";
}
#endif
else if(action == actionSign_out)
{
emit presenceTypeChanged(QXmppPresence::Unavailable);
icon = "gray";
}
label->setPixmap(QPixmap(":/icons/resource/"+icon+".png"));
}
void statusWidget::setPresenceAndStatusType(QXmppPresence::Type presenceType,
QXmppPresence::Status::Type statusType)
{
if(presenceType == QXmppPresence::Available)
{
QString icon = "green";
switch(statusType)
{
case QXmppPresence::Status::Online:
case QXmppPresence::Status::Chat:
icon = "green";
break;
case QXmppPresence::Status::Away:
case QXmppPresence::Status::XA:
icon = "orange";
break;
case QXmppPresence::Status::DND:
icon = "red";
break;
//case QXmppPresence::Status::Invisible:
case QXmppPresence::Status::Offline:
icon = "gray";
break;
}
label->setPixmap(QPixmap(":/icons/resource/"+icon+".png"));
}
else if(presenceType == QXmppPresence::Unavailable)
{
label->setPixmap(QPixmap(":/icons/resource/gray.png"));
}
}
void statusWidget::avatarSelection()
{
QString fileFilters = QString("Images (*.png *.jpeg *.jpg *.gif *.bmp);;All Files (*.*)");
QString file = QFileDialog::getOpenFileName(this, "Select your avatar",
QString(), fileFilters);
if(file.isEmpty())
return;
QImage image;
if(image.load(file))
{
QImage scaled = image.scaled(QSize(96, 96), Qt::KeepAspectRatio,
Qt::SmoothTransformation);
emit avatarChanged(scaled);
}
else
QMessageBox::information(this, "Avatar selection", "Invalid image file");
}
void statusWidget::setDisplayName(const QString& name)
{
toolButton_userName->setText(name);
}
void statusWidget::setAvatar(const QImage& image)
{
pushButton_avatar->setIcon(QIcon(QPixmap::fromImage(image)));
}
|