1 /*
2 * This file is part of Licq, an instant messaging client for UNIX.
3 * Copyright (C) 2007-2012 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 "protocombobox.h"
21
22 #include <boost/foreach.hpp>
23
24 #include <licq/plugin/pluginmanager.h>
25
26 #include "config/iconmanager.h"
27
28 using namespace LicqQtGui;
29 /* TRANSLATOR LicqQtGui::ProtoComboBox */
30
ProtoComboBox(const QString & extra,QWidget * parent)31 ProtoComboBox::ProtoComboBox(const QString& extra, QWidget* parent)
32 : QComboBox(parent)
33 {
34 if (!extra.isNull())
35 addItem(extra, 0);
36
37 Licq::ProtocolPluginsList protocols;
38 Licq::gPluginManager.getProtocolPluginsList(protocols);
39 BOOST_FOREACH(Licq::ProtocolPlugin::Ptr protocol, protocols)
40 {
41 unsigned long ppid = protocol->protocolId();
42
43 addItem(
44 IconManager::instance()->iconForProtocol(ppid, Licq::User::OnlineStatus), // icon
45 protocol->name().c_str(), // protocol name
46 QString::number(ppid) // user data
47 );
48 }
49 }
50
currentPpid() const51 unsigned long ProtoComboBox::currentPpid() const
52 {
53 return itemData(currentIndex()).toString().toULong();
54 }
55
setCurrentPpid(unsigned long ppid)56 bool ProtoComboBox::setCurrentPpid(unsigned long ppid)
57 {
58 int index = findData(QString::number(ppid));
59
60 if (index == -1)
61 return false;
62
63 setCurrentIndex(index);
64
65 return true;
66 }
67