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

0001 /*
0002  * This file is part of ktp-accounts-kcm
0003  *
0004  * Copyright (C) 2011 David Edmundson. <kde@davidedmundson.co.uk>
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 "account-identity-dialog.h"
0022 #include "ui_account-identity-dialog.h"
0023 
0024 #include <TelepathyQt/Account>
0025 #include <TelepathyQt/AvatarData>
0026 #include <TelepathyQt/PendingOperation>
0027 
0028 //FIXME possibly need to monitor account connection status and disable if appropriate?
0029 
0030 AccountIdentityDialog::AccountIdentityDialog(const Tp::AccountPtr &account, QWidget *parent) :
0031     KDialog(parent),
0032     m_account(account),
0033     ui(new Ui::AccountIdentityDialog)
0034 {
0035     QWidget *widget = new QWidget(this);
0036     ui->setupUi(widget);
0037 
0038     Q_ASSERT(! m_account.isNull());
0039 
0040     setMainWidget(widget);
0041 
0042     setWindowTitle(i18n("Edit Account Identity"));
0043     setButtons(KDialog::Ok | KDialog::Cancel);
0044 
0045     connect(m_account.data(), SIGNAL(nicknameChanged(QString)), SLOT(onNicknameChanged(QString)));
0046     connect(m_account.data(), SIGNAL(avatarChanged(Tp::Avatar)), SLOT(onAvatarChanged(Tp::Avatar)));
0047     onNicknameChanged(account->nickname());
0048     onAvatarChanged(account->avatar());
0049 
0050     ui->accountId->setText(m_account->displayName());
0051     ui->accountAvatar->setAccount(m_account);
0052 
0053     connect(this, SIGNAL(okClicked()), SLOT(apply()));
0054 }
0055 
0056 AccountIdentityDialog::~AccountIdentityDialog()
0057 {
0058     delete ui;
0059 }
0060 
0061 void AccountIdentityDialog::onNicknameChanged(const QString &nickname)
0062 {
0063     ui->accountNickname->setText(nickname);
0064 }
0065 
0066 void AccountIdentityDialog::onAvatarChanged(const Tp::Avatar &avatar)
0067 {
0068     ui->accountAvatar->setAvatar(avatar);
0069 }
0070 
0071 void AccountIdentityDialog::apply()
0072 {
0073     if (!m_account.isNull()) {
0074         //not much point watching these, they just return that everything was OK even when it isn't.
0075         m_account->setAvatar(ui->accountAvatar->avatar());
0076         m_account->setNickname(ui->accountNickname->text());
0077     }
0078 
0079     close();
0080 }
0081 
0082 #include "account-identity-dialog.moc"