| 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 "protocombobox.h" |
|---|
| 22 | |
|---|
| 23 | #include <licq_icqd.h> |
|---|
| 24 | |
|---|
| 25 | #include "config/iconmanager.h" |
|---|
| 26 | |
|---|
| 27 | using namespace LicqQtGui; |
|---|
| 28 | /* TRANSLATOR LicqQtGui::ProtoComboBox */ |
|---|
| 29 | |
|---|
| 30 | ProtoComboBox::ProtoComboBox(QWidget* parent) |
|---|
| 31 | : QComboBox(parent) |
|---|
| 32 | { |
|---|
| 33 | fillComboBox(); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | ProtoComboBox::ProtoComboBox(bool skipExisting, QWidget* parent) |
|---|
| 37 | : QComboBox(parent) |
|---|
| 38 | { |
|---|
| 39 | fillComboBox(skipExisting); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | void ProtoComboBox::fillComboBox(bool skipExisting) |
|---|
| 43 | { |
|---|
| 44 | QString id; |
|---|
| 45 | unsigned long ppid; |
|---|
| 46 | |
|---|
| 47 | FOR_EACH_PROTO_PLUGIN_START(gLicqDaemon) |
|---|
| 48 | { |
|---|
| 49 | ppid = (*_ppit)->PPID(); |
|---|
| 50 | const ICQOwner* o = gUserManager.FetchOwner(ppid, LOCK_R); |
|---|
| 51 | if (o == NULL) |
|---|
| 52 | id = "0"; |
|---|
| 53 | else |
|---|
| 54 | { |
|---|
| 55 | if (skipExisting) |
|---|
| 56 | { |
|---|
| 57 | gUserManager.DropOwner(o); |
|---|
| 58 | continue; |
|---|
| 59 | } |
|---|
| 60 | else |
|---|
| 61 | { |
|---|
| 62 | id = o->IdString(); |
|---|
| 63 | gUserManager.DropOwner(o); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | addItem( |
|---|
| 68 | IconManager::instance()->iconForStatus(ICQ_STATUS_ONLINE, id, ppid), // icon |
|---|
| 69 | (*_ppit)->Name(), // protocol name |
|---|
| 70 | QString::number(ppid) // user data |
|---|
| 71 | ); |
|---|
| 72 | } |
|---|
| 73 | FOR_EACH_PROTO_PLUGIN_END |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | unsigned long ProtoComboBox::currentPpid() const |
|---|
| 77 | { |
|---|
| 78 | return itemData(currentIndex()).toString().toULong(); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | bool ProtoComboBox::setCurrentPpid(unsigned long ppid) |
|---|
| 82 | { |
|---|
| 83 | int index = findData(QString::number(ppid)); |
|---|
| 84 | |
|---|
| 85 | if (index == -1) |
|---|
| 86 | return false; |
|---|
| 87 | |
|---|
| 88 | setCurrentIndex(index); |
|---|
| 89 | |
|---|
| 90 | return true; |
|---|
| 91 | } |
|---|