source: qutecom-coip/gui/src/account/accountmonitoritem.cpp @ 286:dc0e36586866

Last change on this file since 286:dc0e36586866 was 286:dc0e36586866, checked in by laurent <laurent@…>, 23 months ago

registering indicator process

File size: 8.0 KB
RevLine 
[283]1#include <account/accountmonitoritem.h>
2#include <ui_accountmonitoritem.h>
3#include <util/pix.h>
4
5AccountMonitorItem::AccountMonitorItem(std::string accountdId, QWidget *parent) 
6:QWidget(parent),ui(new Ui::AccountMonitorItem),_accountId(accountdId)
7{       
[286]8    _hideTimer = 0;
9    _animationTimer = 0;
10   
[283]11    QPalette pal = palette();
12    pal.setBrush(backgroundRole(), pal.dark());
13    setPalette(pal);
14   
15    ui->setupUi(this);
16    ui->labelIdentity->setPalette(pal);
17    ui->labelPresence->setPalette(pal);
18       
19        QMenu * _menu = new QMenu;
20        connect(_menu->addAction(QIcon(":/presence/online.png"),tr("Online")),SIGNAL(triggered()),this,SLOT(onlineClicked()));
21        connect(_menu->addAction(QIcon(":/presence/away.png"),tr("Away")),SIGNAL(triggered()),this,SLOT(awayClicked()));
22        connect(_menu->addAction(QIcon(":/presence/donotdisturb.png"),tr("Do not disturb")),SIGNAL(triggered()),this,SLOT(doNotDisturbClicked()));
23        connect(_menu->addAction(QIcon(":/presence/invisible.png"),tr("Invisible")),SIGNAL(triggered()),this,SLOT(invisibleClicked()));
24        connect(_menu->addAction(QIcon(":/presence/offline.png"),tr("Offline")),SIGNAL(triggered()),this,SLOT(offlineClicked()));
25       
26        ui->labelPresence->setText("");
27        ui->pushButtonPresence->setText("disconnected");
28        ui->pushButtonPresence->setMenu(_menu);
29       
30        AccountList accountList = Coip::self()->getTUserProfileManager().getCopyOfUserProfile().getAccountList();
31        Account * account = AccountListHelper::getCopyOfAccount(accountList, _accountId);
32        if(account)
33                ui->labelIdentity->setText(QString::fromStdString(account->getLogin()));
34       
35        connect(&Coip::self()->getTConnectManager(),
36                        SIGNAL(accountConnectionStateSignal(std::string, EnumConnectionState::ConnectionState)),this,
37                        SLOT(accountConnectionStateSlot(std::string, EnumConnectionState::ConnectionState)));
38        connect(&Coip::self()->getTConnectManager(),
39                        SIGNAL(accountConnectionErrorSignal(std::string, EnumConnectionError::ConnectionError)),this,
40                        SLOT(accountConnectionErrorSlot(std::string, EnumConnectionError::ConnectionError)));
41        connect(&Coip::self()->getTConnectManager(),
42                        SIGNAL(accountConnectionProgressSignal(std::string, unsigned, unsigned, std::string)),this,
43                        SLOT(accountConnectionProgressSlot(std::string, unsigned, unsigned, std::string)));
44       
45        connect(&Coip::self()->getTUserProfileManager().getTAccountManager(), 
46                        SIGNAL(accountAddedSignal(std::string)),this,
47                        SLOT(accountAddedSlot(std::string)));
48       
49        connect(&Coip::self()->getTUserProfileManager().getTAccountManager(), 
50                        SIGNAL(accountRemovedSignal(std::string)),this,
51                        SLOT(accountRemovedSlot(std::string)));
52       
53        connect(&Coip::self()->getTUserProfileManager().getTAccountManager(), 
54                        SIGNAL(accountUpdatedSignal(std::string,EnumUpdateSection::UpdateSection)),this,
55                        SLOT(accountUpdatedSlot(std::string,EnumUpdateSection::UpdateSection)));
56}
57
58AccountMonitorItem::~AccountMonitorItem()
59{
60        delete ui;
61}
62
63void AccountMonitorItem::accountConnectionStateSlot(std::string accountId, EnumConnectionState::ConnectionState state)
64{
65        if( _accountId == accountId )
66        {
67                AccountList accountList = Coip::self()->getTUserProfileManager().getCopyOfUserProfile().getAccountList();
68                Account * account = AccountListHelper::getCopyOfAccount(accountList, accountId);
69                if(account)
70                {
71                        if( state == EnumConnectionState::ConnectionStateDisconnected)
72                        {
[286]73                stopAnimationTimer();
[283]74                                ui->pushButtonPresence->setText("disconnected");
[286]75                QPixmap pix = Pix::getPresencePix(EnumPresenceState::PresenceStateOffline);
76                ui->labelPresence->setPixmap(pix);
[283]77                                show();
78                        }
79                        else if( state == EnumConnectionState::ConnectionStateConnected)
80                        {
[286]81                stopAnimationTimer();
[283]82                                ui->pushButtonPresence->setText("connected");
[286]83                QPixmap pix = Pix::getPresencePix(account->getPresenceState());
84                ui->labelPresence->setPixmap(pix);
85                                startHideTimer();
[283]86                        }
87                }
88        }
89}
90
91void AccountMonitorItem::accountConnectionErrorSlot(std::string accountId, EnumConnectionError::ConnectionError errorCode)
92{
93        if( _accountId == accountId )
94        {
95                AccountList accountList = Coip::self()->getTUserProfileManager().getCopyOfUserProfile().getAccountList();
96                Account * account = AccountListHelper::getCopyOfAccount(accountList, accountId);
97                if(account)
98                {
[286]99            stopAnimationTimer();
[283]100                        ui->pushButtonPresence->setText("Error");
[286]101            QPixmap pix = Pix::getPresencePix(EnumPresenceState::PresenceStateOffline);
102                        ui->labelPresence->setPixmap(pix);
[283]103                        show();
104                }
105        }
106}
107
108void AccountMonitorItem::accountConnectionProgressSlot(std::string accountId, unsigned currentStep, unsigned totalSteps, std::string infoMessage)
109{
110        if( _accountId == accountId )
111        {
112                AccountList accountList = Coip::self()->getTUserProfileManager().getCopyOfUserProfile().getAccountList();
113                Account * account = AccountListHelper::getCopyOfAccount(accountList, accountId);
114                if(account)
115                {
[286]116            startAnimationTimer();
[283]117                        ui->pushButtonPresence->setText("registering");
118                        show();
119                }
120        }
121}
122
123void AccountMonitorItem::accountAddedSlot(std::string accountId)
124{
125       
126}
127
128void AccountMonitorItem::accountRemovedSlot(std::string accountId)
129{
130       
131}
132
133void AccountMonitorItem::accountUpdatedSlot(std::string accountId, EnumUpdateSection::UpdateSection section)
134{
135        if( _accountId == accountId )
136        {
137                AccountList accountList = Coip::self()->getTUserProfileManager().getCopyOfUserProfile().getAccountList();
138                Account * account = AccountListHelper::getCopyOfAccount(accountList, accountId);
[286]139                if(account && _animationTimer == 0)
[283]140                {
141                        QPixmap pix = Pix::getPresencePix(account->getPresenceState());
142                        ui->labelPresence->setPixmap(pix);
143                }
144        }
145}
146
147void AccountMonitorItem::updatePresenceState(EnumPresenceState::PresenceState presenceState)
148{               
149        AccountList accountList = Coip::self()->getTUserProfileManager().getCopyOfUserProfile().getAccountList();
150        Account * account = AccountListHelper::getCopyOfAccount(accountList, _accountId);
151        if(account)
152        {
153                account->setPresenceState(presenceState);
154                Coip::self()->getTUserProfileManager().getTAccountManager().update(*account,EnumUpdateSection::UpdateSectionPresenceState);
155               
156                if(presenceState == EnumPresenceState::PresenceStateOffline)
157                {
158                        Coip::self()->getTConnectManager().disconnect(account->getUUID());
159                }
160                else
161                {
162                        if(account->getConnectionState() != EnumConnectionState::ConnectionStateConnected)
163                        {
164                                Coip::self()->getTConnectManager().connect(account->getUUID());
165                        }
166                }
167        }
168}
169
170void AccountMonitorItem::onlineClicked()
171{
172        updatePresenceState(EnumPresenceState::PresenceStateOnline);
173}
174
175void AccountMonitorItem::awayClicked()
176{
177        updatePresenceState(EnumPresenceState::PresenceStateAway);
178}
179
180void AccountMonitorItem::doNotDisturbClicked()
181{
182        updatePresenceState(EnumPresenceState::PresenceStateDoNotDisturb);
183}
184
185void AccountMonitorItem::invisibleClicked()
186{
187        updatePresenceState(EnumPresenceState::PresenceStateInvisible);
188}
189
190void AccountMonitorItem::offlineClicked()
191{
192        updatePresenceState(EnumPresenceState::PresenceStateOffline);
193}
194
195void AccountMonitorItem::changeEvent(QEvent *e)
196{
197    QWidget::changeEvent(e);
198    switch (e->type()) {
199    case QEvent::LanguageChange:       
200        break;
201    default:
202        break;
203    }
204}
205
[286]206void AccountMonitorItem::startAnimationTimer()
207{
208    if(_animationTimer == 0)
209        _animationTimer = startTimer(50);
210}
211
212void AccountMonitorItem::stopAnimationTimer()
213{
214    if (_animationTimer > 0)
215    {
216        killTimer(_animationTimer);
217        _animationTimer = 0;
218    }
219}
220
221void AccountMonitorItem::startHideTimer()
222{
223    if(_hideTimer == 0)
224        _hideTimer = startTimer(1500);
225}
226void AccountMonitorItem::stopHideTimer()
227{
228    if (_hideTimer > 0)
229    {
230        killTimer(_hideTimer);
231        _hideTimer = 0;
232    }
233}
234
[283]235void AccountMonitorItem::timerEvent(QTimerEvent *e)
236{
237        if(e->timerId() == _hideTimer)
238        {
[286]239                stopHideTimer();
[283]240                hide();
241        }
[286]242    else if(e->timerId() == _animationTimer)
243    {
244        QTransform transform;
245        transform.rotate(_angle);
246        QPixmap pix = QPixmap(":/account/loading.png").transformed(transform,Qt::SmoothTransformation).scaled(9,9);
247        ui->labelPresence->setPixmap(pix);
248        _angle += 10;
249    }
[283]250}
Note: See TracBrowser for help on using the repository browser.