| 1 | /* |
|---|
| 2 | * QuteCom, a voice over Internet phone |
|---|
| 3 | * Copyright (C) 2010 Mbdsys |
|---|
| 4 | * |
|---|
| 5 | * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | * it under the terms of the GNU General Public License as published by |
|---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | * (at your option) any later version. |
|---|
| 9 | * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | * GNU General Public License for more details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License |
|---|
| 16 | * along with this program; if not, write to the Free Software |
|---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #include "QtContactWidget.h" |
|---|
| 21 | |
|---|
| 22 | #include "ui_ContactWidget.h" |
|---|
| 23 | |
|---|
| 24 | #include "QtContact.h" |
|---|
| 25 | #include "QtContactListManager.h" |
|---|
| 26 | #include "QtContactManager.h" |
|---|
| 27 | |
|---|
| 28 | #include <presentation/qt/contactlist/QtContactListManager.h> |
|---|
| 29 | #include <presentation/qt/profile/QtProfileDetails.h> |
|---|
| 30 | |
|---|
| 31 | #include <control/CQuteCom.h> |
|---|
| 32 | #include <control/contactlist/CContactList.h> |
|---|
| 33 | #include <control/profile/CUserProfile.h> |
|---|
| 34 | #include <control/profile/CUserProfileHandler.h> |
|---|
| 35 | |
|---|
| 36 | #include <model/config/ConfigManager.h> |
|---|
| 37 | #include <model/config/Config.h> |
|---|
| 38 | #include <model/contactlist/ContactProfile.h> |
|---|
| 39 | |
|---|
| 40 | #include <util/OWPicture.h> |
|---|
| 41 | #include <util/Logger.h> |
|---|
| 42 | |
|---|
| 43 | #include <qtutil/PixmapMerging.h> |
|---|
| 44 | #include <qtutil/SafeConnect.h> |
|---|
| 45 | #include <qtutil/languagechangeeventfilter.h> |
|---|
| 46 | |
|---|
| 47 | #include <QtGui/QtGui> |
|---|
| 48 | |
|---|
| 49 | static const std::string AVATAR_BACKGROUND = ":/pics/avatar_background.png"; |
|---|
| 50 | |
|---|
| 51 | QtContactWidget::QtContactWidget(const std::string & contactId, CQuteCom & cQuteCom, |
|---|
| 52 | QtContactManager * qtContactManager, QWidget * parent) |
|---|
| 53 | : QWidget(parent), |
|---|
| 54 | _cQuteCom(cQuteCom) { |
|---|
| 55 | _contactId = contactId; |
|---|
| 56 | |
|---|
| 57 | _ui = new Ui::ContactWidget(); |
|---|
| 58 | _ui->setupUi(this); |
|---|
| 59 | |
|---|
| 60 | QColor bgColor = palette().highlight().color(); |
|---|
| 61 | QColor fgColor = palette().highlightedText().color(); |
|---|
| 62 | |
|---|
| 63 | QPalette pal(bgColor); |
|---|
| 64 | pal.setColor(QPalette::Text, fgColor); |
|---|
| 65 | pal.setColor(QPalette::ButtonText, fgColor); |
|---|
| 66 | |
|---|
| 67 | setPalette(pal); |
|---|
| 68 | Q_FOREACH(QToolButton* button, findChildren<QToolButton*>()) { |
|---|
| 69 | button->setPalette(pal); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | Config & config = ConfigManager::getInstance().getCurrentConfig(); |
|---|
| 73 | if (!config.getSmsFeatureEnabled()) { |
|---|
| 74 | _ui->smsButton->hide(); |
|---|
| 75 | } |
|---|
| 76 | updateButtons(); |
|---|
| 77 | |
|---|
| 78 | SAFE_CONNECT(_ui->callButton, SIGNAL(clicked()), SLOT(callButtonClicked())); |
|---|
| 79 | SAFE_CONNECT(_ui->chatButton, SIGNAL(clicked()), SLOT(chatButtonClicked())); |
|---|
| 80 | SAFE_CONNECT(_ui->smsButton, SIGNAL(clicked()), SLOT(smsButtonClicked())); |
|---|
| 81 | SAFE_CONNECT(_ui->landlineButton, SIGNAL(clicked()), SLOT(landlineButtonClicked())); |
|---|
| 82 | SAFE_CONNECT(_ui->mobileButton, SIGNAL(clicked()), SLOT(mobileButtonClicked())); |
|---|
| 83 | SAFE_CONNECT(_ui->avatarButton, SIGNAL(clicked()), SLOT(avatarButtonClicked())); |
|---|
| 84 | SAFE_CONNECT(_ui->sendFileButton, SIGNAL(clicked()), SLOT(sendFileButtonClicked())); |
|---|
| 85 | SAFE_CONNECT_RECEIVER_TYPE(this, SIGNAL(editContact(QString)), |
|---|
| 86 | qtContactManager, SLOT(editContact(QString)), Qt::QueuedConnection); |
|---|
| 87 | |
|---|
| 88 | #ifdef DISABLE_SMS |
|---|
| 89 | _ui->smsButton->hide(); |
|---|
| 90 | #endif |
|---|
| 91 | |
|---|
| 92 | #ifdef DISABLE_FILETRANSFER |
|---|
| 93 | _ui->sendFileButton->hide(); |
|---|
| 94 | #endif |
|---|
| 95 | |
|---|
| 96 | LANGUAGE_CHANGE(this); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | QtContactWidget::~QtContactWidget() { |
|---|
| 100 | delete _ui; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | void QtContactWidget::resizeEvent(QResizeEvent* event) { |
|---|
| 104 | QWidget::resizeEvent(event); |
|---|
| 105 | QPalette pal = palette(); |
|---|
| 106 | |
|---|
| 107 | QRect r = rect(); |
|---|
| 108 | QLinearGradient lg(QPointF(1, r.top()), QPointF(1, r.bottom())); |
|---|
| 109 | QColor color = pal.highlight().color(); |
|---|
| 110 | lg.setColorAt(0, color); |
|---|
| 111 | lg.setColorAt(1, color.dark(150)); |
|---|
| 112 | |
|---|
| 113 | pal.setBrush(backgroundRole(), QBrush(lg)); |
|---|
| 114 | setPalette(pal); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | void QtContactWidget::updateButtons() { |
|---|
| 118 | ContactProfile contactProfile = _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCContactList().getContactProfile(_contactId); |
|---|
| 119 | std::string foregroundPixmapData = contactProfile.getIcon().getData(); |
|---|
| 120 | _ui->avatarButton->setIcon(PixmapMerging::merge(foregroundPixmapData, AVATAR_BACKGROUND)); |
|---|
| 121 | |
|---|
| 122 | QString str = QString::fromUtf8(contactProfile.getHomePhone().c_str()); |
|---|
| 123 | if (str.isEmpty()) { |
|---|
| 124 | _ui->landlineButton->setText(tr("No landline phone number set")); |
|---|
| 125 | } else { |
|---|
| 126 | _ui->landlineButton->setText(str); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | str = QString::fromUtf8(contactProfile.getMobilePhone().c_str()); |
|---|
| 130 | if (str.isEmpty()) { |
|---|
| 131 | _ui->mobileButton->setText(tr("No mobile phone number set")); |
|---|
| 132 | _ui->smsButton->setEnabled(false); |
|---|
| 133 | } else { |
|---|
| 134 | _ui->mobileButton->setText(str); |
|---|
| 135 | _ui->smsButton->setEnabled(true); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | _ui->callButton->setEnabled(contactProfile.hasFreeCall() || contactProfile.hasVoiceMail()); |
|---|
| 139 | |
|---|
| 140 | _ui->chatButton->setEnabled(contactProfile.hasIM()); |
|---|
| 141 | |
|---|
| 142 | _ui->sendFileButton->setEnabled(contactProfile.hasFileTransfer()); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | void QtContactWidget::callButtonClicked() { |
|---|
| 146 | QtContactListManager * ul = QtContactListManager::getInstance(); |
|---|
| 147 | ul->startFreeCall(QString::fromUtf8(_contactId.c_str())); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | void QtContactWidget::smsButtonClicked() { |
|---|
| 151 | QtContactListManager * ul = QtContactListManager::getInstance(); |
|---|
| 152 | ul->startSMS(QString::fromUtf8(_contactId.c_str())); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | void QtContactWidget::chatButtonClicked() { |
|---|
| 156 | QtContactListManager * ul = QtContactListManager::getInstance(); |
|---|
| 157 | ul->startChat(QString::fromUtf8(_contactId.c_str())); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | void QtContactWidget::sendFileButtonClicked() { |
|---|
| 161 | QtContactListManager * ul = QtContactListManager::getInstance(); |
|---|
| 162 | ul->sendFile(QString::fromUtf8(_contactId.c_str())); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | void QtContactWidget::updateToolTips() { |
|---|
| 166 | |
|---|
| 167 | QtContactListManager * ul = QtContactListManager::getInstance(); |
|---|
| 168 | |
|---|
| 169 | if (!ul->getMobilePhone(QString::fromUtf8(_contactId.c_str())).isEmpty()) { |
|---|
| 170 | _ui->mobileButton->setToolTip(tr("Click here to call")); |
|---|
| 171 | } else { |
|---|
| 172 | _ui->mobileButton->setToolTip(tr("Click here to set a phone number")); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | if (!ul->getHomePhone(QString::fromUtf8(_contactId.c_str())).isEmpty()) { |
|---|
| 176 | _ui->landlineButton->setToolTip(tr("Click here to call")); |
|---|
| 177 | } else { |
|---|
| 178 | _ui->landlineButton->setToolTip(tr("Click here to set a phone number")); |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | _ui->avatarButton->setToolTip(tr("Click here to edit the contact")); |
|---|
| 182 | |
|---|
| 183 | if (_ui->smsButton->isEnabled()) { |
|---|
| 184 | _ui->smsButton->setToolTip(tr("Click here to send a SMS")); |
|---|
| 185 | } else { |
|---|
| 186 | _ui->smsButton->setToolTip(QString::null); |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | if (_ui->chatButton->isEnabled()) { |
|---|
| 190 | _ui->chatButton->setToolTip(tr("Click here to start a chat")); |
|---|
| 191 | } else { |
|---|
| 192 | _ui->chatButton->setToolTip(QString::null); |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | if (_ui->callButton->isEnabled()) { |
|---|
| 196 | _ui->callButton->setToolTip(tr("Click here to start a free call")); |
|---|
| 197 | } else { |
|---|
| 198 | _ui->callButton->setToolTip(QString::null); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | if (_ui->sendFileButton->isEnabled()) { |
|---|
| 202 | _ui->sendFileButton->setToolTip(tr("Click here to send a file")); |
|---|
| 203 | } else { |
|---|
| 204 | _ui->sendFileButton->setToolTip(QString::null); |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | void QtContactWidget::mobileButtonClicked() { |
|---|
| 209 | QtContactListManager * ul = QtContactListManager::getInstance(); |
|---|
| 210 | if (!ul->getMobilePhone(QString::fromUtf8(_contactId.c_str())).isEmpty()) { |
|---|
| 211 | ul->startCall(QString::fromUtf8(_contactId.c_str()), _ui->mobileButton->text()); |
|---|
| 212 | } else { |
|---|
| 213 | editContact(_text); |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | void QtContactWidget::landlineButtonClicked() { |
|---|
| 218 | QtContactListManager * ul = QtContactListManager::getInstance(); |
|---|
| 219 | if (!ul->getHomePhone(QString::fromUtf8(_contactId.c_str())).isEmpty()) { |
|---|
| 220 | ul->startCall(QString::fromUtf8(_contactId.c_str()), _ui->landlineButton->text()); |
|---|
| 221 | } else { |
|---|
| 222 | editContact(_text); |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | void QtContactWidget::avatarButtonClicked() { |
|---|
| 227 | editContact(_text); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | void QtContactWidget::paintEvent(QPaintEvent *) { |
|---|
| 231 | QPainter painter(this); |
|---|
| 232 | paintContact(&painter, rect()); |
|---|
| 233 | painter.end(); |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | void QtContactWidget::paintContact(QPainter * painter, const QRect & rect) { |
|---|
| 237 | QtContactListManager * ul = QtContactListManager::getInstance(); |
|---|
| 238 | |
|---|
| 239 | QtContact * qtContact = ul->getContact(QString::fromUtf8(_contactId.c_str())); |
|---|
| 240 | if (!qtContact) { |
|---|
| 241 | return; |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | QStyleOptionViewItem option; |
|---|
| 245 | option.initFrom(ul->getTreeWidget()); |
|---|
| 246 | option.state = QStyle::State_Selected; |
|---|
| 247 | qtContact->paintForeground(painter, option); |
|---|
| 248 | updateToolTips(); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | void QtContactWidget::languageChanged() |
|---|
| 252 | { |
|---|
| 253 | _ui->retranslateUi(this); |
|---|
| 254 | } |
|---|