File indexing completed on 2023-12-03 08:28:37
0001 /* 0002 * Copyright (C) 2012 David Edmundson <kde@davidedmundson.co.uk> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public 0015 * License along with this library; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 0017 */ 0018 0019 0020 #include "accounts-combo-box.h" 0021 0022 #include <TelepathyQt/AccountSet> 0023 #include <TelepathyQt/Account> 0024 0025 #include <KTp/Models/accounts-list-model.h> 0026 0027 0028 class KTp::AccountsComboBox::Private 0029 { 0030 public: 0031 AccountsListModel *model; 0032 }; 0033 0034 KTp::AccountsComboBox::AccountsComboBox(QWidget *parent) : 0035 QComboBox(parent), 0036 d(new KTp::AccountsComboBox::Private()) 0037 { 0038 d->model = new AccountsListModel(this); 0039 setModel(d->model); 0040 } 0041 0042 KTp::AccountsComboBox::~AccountsComboBox() 0043 { 0044 delete d; 0045 } 0046 0047 void KTp::AccountsComboBox::setAccountSet(const Tp::AccountSetPtr &accountSet) 0048 { 0049 d->model->setAccountSet(accountSet); 0050 } 0051 0052 Tp::AccountPtr KTp::AccountsComboBox::currentAccount() 0053 { 0054 return itemData(currentIndex(), AccountsListModel::AccountRole).value<Tp::AccountPtr>(); 0055 } 0056 0057 void KTp::AccountsComboBox::setCurrentAccount(const QString &selectedAccountId) 0058 { 0059 for (int i=0;i<count();i++) { 0060 if (itemData(i, AccountsListModel::AccountRole).value<Tp::AccountPtr>()->uniqueIdentifier() == selectedAccountId) { 0061 setCurrentIndex(i); 0062 break; 0063 } 0064 } 0065 } 0066 0067 void KTp::AccountsComboBox::setCurrentAccount(const Tp::AccountPtr &selectedAccount) 0068 { 0069 setCurrentAccount(selectedAccount->uniqueIdentifier()); 0070 } 0071 0072 0073