1 /*
2 * This file is part of Licq, an instant messaging client for UNIX.
3 * Copyright (C) 2012-2013 Licq developers <licq-dev@googlegroups.com>
4 *
5 * Licq 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 * Licq 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 Licq; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "ownercombobox.h"
21
22 #include <boost/foreach.hpp>
23
24 #include <licq/contactlist/usermanager.h>
25 #include <licq/contactlist/owner.h>
26
27 #include "contactlist/contactlist.h"
28
29 #include "config/iconmanager.h"
30
31 using namespace LicqQtGui;
32 /* TRANSLATOR LicqQtGui::OwnerComboBox */
33
OwnerComboBox(const QString & extra,QWidget * parent)34 OwnerComboBox::OwnerComboBox(const QString& extra, QWidget* parent)
35 : QComboBox(parent)
36 {
37 if (!extra.isNull())
38 addItem(extra, QVariant::fromValue(Licq::UserId()));
39
40 Licq::OwnerListGuard ownerList;
41 BOOST_FOREACH(const Licq::Owner* owner, **ownerList)
42 {
43 Licq::OwnerReadGuard o(owner);
44 addItem(IconManager::instance()->iconForStatus(Licq::User::OnlineStatus, o->id()),
45 o->accountId().c_str(), QVariant::fromValue(o->id()));
46 }
47 }
48
currentOwnerId() const49 Licq::UserId OwnerComboBox::currentOwnerId() const
50 {
51 return itemData(currentIndex()).value<Licq::UserId>();
52 }
53
setCurrentOwnerId(const Licq::UserId & ownerId)54 bool OwnerComboBox::setCurrentOwnerId(const Licq::UserId& ownerId)
55 {
56 for (int index = 0; index < count(); ++index)
57 {
58 if (itemData(index).value<Licq::UserId>() == ownerId)
59 {
60 setCurrentIndex(index);
61 return true;
62 }
63 }
64 return false;
65 }
66