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