| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 2007 Licq developers |
|---|
| 5 | * |
|---|
| 6 | * Licq is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * Licq is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with Licq; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include "groupcombobox.h" |
|---|
| 22 | |
|---|
| 23 | #include <licq_user.h> |
|---|
| 24 | |
|---|
| 25 | #include "helpers/licqstrings.h" |
|---|
| 26 | |
|---|
| 27 | using namespace LicqQtGui; |
|---|
| 28 | /* TRANSLATOR LicqQtGui::GroupComboBox */ |
|---|
| 29 | |
|---|
| 30 | GroupComboBox::GroupComboBox(bool withAllUsers, QWidget* parent) |
|---|
| 31 | : QComboBox(parent) |
|---|
| 32 | { |
|---|
| 33 | // Assumes that GROUP_ALL_USERS always equals 0 |
|---|
| 34 | if (withAllUsers) |
|---|
| 35 | addItem(LicqStrings::getSystemGroupName(GROUP_ALL_USERS), |
|---|
| 36 | QString::number(GROUP_ALL_USERS)); |
|---|
| 37 | |
|---|
| 38 | FOR_EACH_GROUP_START_SORTED(LOCK_R) |
|---|
| 39 | { |
|---|
| 40 | addItem(pGroup->name().c_str(), QString::number(pGroup->id())); |
|---|
| 41 | } |
|---|
| 42 | FOR_EACH_GROUP_END |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | unsigned short GroupComboBox::currentGroupId() const |
|---|
| 46 | { |
|---|
| 47 | return itemData(currentIndex()).toString().toUShort(); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | bool GroupComboBox::setCurrentGroupId(unsigned short groupId) |
|---|
| 51 | { |
|---|
| 52 | int index = findData(QString::number(groupId)); |
|---|
| 53 | |
|---|
| 54 | if (index == -1) |
|---|
| 55 | return false; |
|---|
| 56 | |
|---|
| 57 | setCurrentIndex(index); |
|---|
| 58 | |
|---|
| 59 | return true; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | bool GroupComboBox::setCurrentGroupName(const QString& groupName) |
|---|
| 63 | { |
|---|
| 64 | int index = findText(groupName); |
|---|
| 65 | |
|---|
| 66 | if (index == -1) |
|---|
| 67 | return false; |
|---|
| 68 | |
|---|
| 69 | setCurrentIndex(index); |
|---|
| 70 | |
|---|
| 71 | return true; |
|---|
| 72 | } |
|---|