File indexing completed on 2023-11-26 04:55:35

0001 /*
0002  * This file is part of telepathy-accounts-kcm
0003  *
0004  * Copyright (C) 2012 Daniele E. Domenichelli <daniele.domenichelli@gmail.com>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this library; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0019  */
0020 
0021 #include "change-icon-button.h"
0022 
0023 #include <KDE/KDebug>
0024 
0025 #include <TelepathyQt/Account>
0026 #include <TelepathyQt/PendingOperation>
0027 
0028 ChangeIconButton::ChangeIconButton(QWidget* parent) :
0029     KIconButton(parent)
0030 {
0031     setIconType(KIconLoader::NoGroup, KIconLoader::Action);
0032     setIconSize(KIconLoader::SizeLarge);
0033     setButtonIconSize(KIconLoader::SizeMedium);
0034     setFixedSize(KIconLoader::SizeMedium + 10, KIconLoader::SizeMedium + 10);
0035 
0036     connect(this, SIGNAL(iconChanged(QString)), SLOT(onIconChanged(QString)));
0037 }
0038 
0039 ChangeIconButton::~ChangeIconButton()
0040 {
0041 }
0042 
0043 void ChangeIconButton::setAccount(const Tp::AccountPtr &account)
0044 {
0045     m_account = account;
0046 }
0047 
0048 Tp::AccountPtr ChangeIconButton::account() const
0049 {
0050     return m_account;
0051 }
0052 
0053 void ChangeIconButton::onIconChanged(const QString& icon)
0054 {
0055     kDebug();
0056     if (!m_account.isNull() && m_account->isValid()) {
0057         kDebug() << "Setting icon" << icon << "for account" << account()->uniqueIdentifier();
0058         Tp::PendingOperation *op = m_account->setIconName(icon);
0059         connect(op, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onFinished(Tp::PendingOperation*)));
0060     }
0061 }
0062 
0063 void ChangeIconButton::onFinished(Tp::PendingOperation* op)
0064 {
0065     if (op->isError()) {
0066         kWarning() << "Cannot set icon" << op->errorName() << op->errorMessage();
0067     }
0068 }