| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 2000-2006 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 "joinchatdlg.h" |
|---|
| 22 | |
|---|
| 23 | #include "config.h" |
|---|
| 24 | |
|---|
| 25 | #include <QGridLayout> |
|---|
| 26 | #include <QLabel> |
|---|
| 27 | #include <QListWidget> |
|---|
| 28 | #include <QPushButton> |
|---|
| 29 | |
|---|
| 30 | #include "helpers/support.h" |
|---|
| 31 | |
|---|
| 32 | using namespace LicqQtGui; |
|---|
| 33 | /* TRANSLATOR LicqQtGui::JoinChatDlg */ |
|---|
| 34 | |
|---|
| 35 | JoinChatDlg::JoinChatDlg(bool bRequesting, QWidget* p) |
|---|
| 36 | : QDialog(p) |
|---|
| 37 | { |
|---|
| 38 | Support::setWidgetProps(this, "ChatJoinDialog"); |
|---|
| 39 | setModal(true); |
|---|
| 40 | |
|---|
| 41 | QGridLayout* lay = new QGridLayout(this); |
|---|
| 42 | |
|---|
| 43 | QLabel* l = new QLabel(); |
|---|
| 44 | lay->addWidget(l, 0, 0, 1, 5); |
|---|
| 45 | |
|---|
| 46 | lstChats = new QListWidget(); |
|---|
| 47 | lay->addWidget(lstChats, 1, 0, 1, 5); |
|---|
| 48 | |
|---|
| 49 | lay->setColumnStretch(0, 2); |
|---|
| 50 | btnOk = new QPushButton(); |
|---|
| 51 | lay->addWidget(btnOk, 2, 1); |
|---|
| 52 | |
|---|
| 53 | lay->setColumnMinimumWidth(2, 10); |
|---|
| 54 | btnCancel = new QPushButton(); |
|---|
| 55 | lay->addWidget(btnCancel, 2, 3); |
|---|
| 56 | lay->setColumnStretch(4, 2); |
|---|
| 57 | |
|---|
| 58 | if (bRequesting) |
|---|
| 59 | { |
|---|
| 60 | l->setText(tr("Select chat to invite:")); |
|---|
| 61 | setWindowTitle(tr("Invite to Join Chat")); |
|---|
| 62 | btnOk->setText(tr("&Invite")); |
|---|
| 63 | btnCancel->setText(tr("&Cancel")); |
|---|
| 64 | } |
|---|
| 65 | else |
|---|
| 66 | { |
|---|
| 67 | l->setText(tr("Select chat to join:")); |
|---|
| 68 | setWindowTitle(tr("Join Multiparty Chat")); |
|---|
| 69 | btnOk->setText(tr("&Join")); |
|---|
| 70 | btnCancel->setText(tr("&Cancel")); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | connect(btnOk, SIGNAL(clicked()), SLOT(slot_ok())); |
|---|
| 74 | connect(btnCancel, SIGNAL(clicked()), SLOT(reject())); |
|---|
| 75 | |
|---|
| 76 | // Fill in the combo box |
|---|
| 77 | ChatDlgList::iterator iter; |
|---|
| 78 | for (iter = ChatDlg::chatDlgs.begin(); |
|---|
| 79 | iter != ChatDlg::chatDlgs.end(); iter++) |
|---|
| 80 | { |
|---|
| 81 | /* |
|---|
| 82 | QString n; |
|---|
| 83 | if ((*iter)->chatUser == NULL) // check if the first user closed already |
|---|
| 84 | { |
|---|
| 85 | n.setNum((*iter)->m_nUin); |
|---|
| 86 | } |
|---|
| 87 | else |
|---|
| 88 | { |
|---|
| 89 | // This is bad as the user is not locked at this point...but |
|---|
| 90 | // should work as the name is never changed |
|---|
| 91 | n = (*iter)->chatUser->Name(); |
|---|
| 92 | if (n.isEmpty()) n.setNum((*iter)->chatUser->Uin()); |
|---|
| 93 | } |
|---|
| 94 | QString c = (*iter)->ChatClients(); |
|---|
| 95 | if (!c.isEmpty()) |
|---|
| 96 | { |
|---|
| 97 | n += " (" + c + ")"; |
|---|
| 98 | }*/ |
|---|
| 99 | QString n = (*iter)->ChatClients(); |
|---|
| 100 | lstChats->addItem(n); |
|---|
| 101 | |
|---|
| 102 | originalChats.push_back(*iter); |
|---|
| 103 | } |
|---|
| 104 | lstChats->setCurrentItem(0); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | void JoinChatDlg::slot_ok() |
|---|
| 109 | { |
|---|
| 110 | if (lstChats->currentItem() == NULL) |
|---|
| 111 | return; |
|---|
| 112 | accept(); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | ChatDlg* JoinChatDlg::JoinedChat() |
|---|
| 117 | { |
|---|
| 118 | if (lstChats->currentItem() == NULL) |
|---|
| 119 | return NULL; |
|---|
| 120 | |
|---|
| 121 | unsigned short n = 0; |
|---|
| 122 | ChatDlgList::iterator iter; |
|---|
| 123 | for (iter = originalChats.begin(); |
|---|
| 124 | iter != originalChats.end() && n < lstChats->currentRow(); |
|---|
| 125 | iter++, n++) |
|---|
| 126 | { |
|---|
| 127 | // Empty |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | ChatDlg* cd = *iter; |
|---|
| 131 | |
|---|
| 132 | for (iter = ChatDlg::chatDlgs.begin(); |
|---|
| 133 | iter != ChatDlg::chatDlgs.end() && *iter != cd; |
|---|
| 134 | iter++) |
|---|
| 135 | { |
|---|
| 136 | // Empty |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | // Check that this chat still exists |
|---|
| 140 | if (iter == ChatDlg::chatDlgs.end()) |
|---|
| 141 | return NULL; |
|---|
| 142 | |
|---|
| 143 | return cd; |
|---|
| 144 | } |
|---|