1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2007-2010, 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 "groupcombobox.h"
21 
22 #include <boost/foreach.hpp>
23 
24 #include <licq/contactlist/group.h>
25 #include <licq/contactlist/usermanager.h>
26 
27 using namespace LicqQtGui;
28 /* TRANSLATOR LicqQtGui::GroupComboBox */
29 
GroupComboBox(bool groupPos,QWidget * parent)30 GroupComboBox::GroupComboBox(bool groupPos, QWidget* parent)
31   : QComboBox(parent)
32 {
33   if (groupPos)
34     addItem(tr("First"), -1);
35 
36   Licq::GroupListGuard groupList(true);
37   BOOST_FOREACH(const Licq::Group* group, **groupList)
38   {
39     Licq::GroupReadGuard pGroup(group);
40     QString text = QString::fromLocal8Bit(pGroup->name().c_str());
41     if (groupPos)
42       text.prepend(tr("After "));
43     addItem(text, pGroup->id());
44   }
45 }
46 
currentGroupId() const47 int GroupComboBox::currentGroupId() const
48 {
49   return itemData(currentIndex()).toInt();
50 }
51 
setCurrentGroupId(int groupId)52 bool GroupComboBox::setCurrentGroupId(int groupId)
53 {
54   int index = findData(groupId);
55 
56   if (index == -1)
57     return false;
58 
59   setCurrentIndex(index);
60 
61   return true;
62 }
63 
setCurrentGroupName(const QString & groupName)64 bool GroupComboBox::setCurrentGroupName(const QString& groupName)
65 {
66   int index = findText(groupName);
67 
68   if (index == -1)
69     return false;
70 
71   setCurrentIndex(index);
72 
73   return true;
74 }
75