| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 1999-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 "adduserdlg.h" |
|---|
| 22 | |
|---|
| 23 | #include <QCheckBox> |
|---|
| 24 | #include <QDialogButtonBox> |
|---|
| 25 | #include <QGridLayout> |
|---|
| 26 | #include <QLabel> |
|---|
| 27 | #include <QLineEdit> |
|---|
| 28 | |
|---|
| 29 | #include <licq_icqd.h> |
|---|
| 30 | |
|---|
| 31 | #include "helpers/support.h" |
|---|
| 32 | |
|---|
| 33 | #include "widgets/groupcombobox.h" |
|---|
| 34 | #include "widgets/protocombobox.h" |
|---|
| 35 | |
|---|
| 36 | using namespace LicqQtGui; |
|---|
| 37 | /* TRANSLATOR LicqQtGui::AddUserDlg */ |
|---|
| 38 | |
|---|
| 39 | AddUserDlg::AddUserDlg(QString id, unsigned long ppid, QWidget* parent) |
|---|
| 40 | : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint) |
|---|
| 41 | { |
|---|
| 42 | Support::setWidgetProps(this, "AddUserDialog"); |
|---|
| 43 | setWindowTitle(tr("Licq - Add user")); |
|---|
| 44 | setAttribute(Qt::WA_DeleteOnClose, true); |
|---|
| 45 | |
|---|
| 46 | QGridLayout* layDialog = new QGridLayout(this); |
|---|
| 47 | |
|---|
| 48 | QLabel* lblProtocol = new QLabel(tr("&Protocol:")); |
|---|
| 49 | myProtocol = new ProtoComboBox(); |
|---|
| 50 | myProtocol->setCurrentPpid(ppid); |
|---|
| 51 | lblProtocol->setBuddy(myProtocol); |
|---|
| 52 | |
|---|
| 53 | unsigned line = 0; |
|---|
| 54 | |
|---|
| 55 | layDialog->addWidget(lblProtocol, line, 0); |
|---|
| 56 | layDialog->addWidget(myProtocol, line++, 1); |
|---|
| 57 | |
|---|
| 58 | QLabel* lblGroup = new QLabel(tr("&Group:")); |
|---|
| 59 | myGroup = new GroupComboBox(); |
|---|
| 60 | lblGroup->setBuddy(myGroup); |
|---|
| 61 | |
|---|
| 62 | layDialog->addWidget(lblGroup, line, 0); |
|---|
| 63 | layDialog->addWidget(myGroup, line++, 1); |
|---|
| 64 | |
|---|
| 65 | QLabel* lblId = new QLabel(tr("New &User ID:")); |
|---|
| 66 | myId = new QLineEdit(); |
|---|
| 67 | if (!id.isEmpty()) |
|---|
| 68 | myId->setText(id); |
|---|
| 69 | connect(myId, SIGNAL(returnPressed()), SLOT(ok())); |
|---|
| 70 | lblId->setBuddy(myId); |
|---|
| 71 | |
|---|
| 72 | layDialog->addWidget(lblId, line, 0); |
|---|
| 73 | layDialog->addWidget(myId, line++, 1); |
|---|
| 74 | |
|---|
| 75 | myNotify = new QCheckBox(tr("&Notify User")); |
|---|
| 76 | myNotify->setChecked(true); |
|---|
| 77 | layDialog->addWidget(myNotify, line++, 0, 1, 2); |
|---|
| 78 | |
|---|
| 79 | QDialogButtonBox* buttons = new QDialogButtonBox( |
|---|
| 80 | QDialogButtonBox::Ok | |
|---|
| 81 | QDialogButtonBox::Cancel); |
|---|
| 82 | connect(buttons, SIGNAL(accepted()), SLOT(ok())); |
|---|
| 83 | connect(buttons, SIGNAL(rejected()), SLOT(close())); |
|---|
| 84 | |
|---|
| 85 | layDialog->addWidget(buttons, line++, 0, 1, 2); |
|---|
| 86 | |
|---|
| 87 | myId->setFocus(); |
|---|
| 88 | show(); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | void AddUserDlg::ok() |
|---|
| 92 | { |
|---|
| 93 | QByteArray id = myId->text().trimmed().toLatin1(); |
|---|
| 94 | unsigned long ppid = myProtocol->currentPpid(); |
|---|
| 95 | unsigned short group = myGroup->currentGroupId(); |
|---|
| 96 | bool notify = myNotify->isChecked(); |
|---|
| 97 | bool added = false; |
|---|
| 98 | |
|---|
| 99 | if (!id.isEmpty()) |
|---|
| 100 | { |
|---|
| 101 | const ICQUser* u = gUserManager.FetchUser(id, ppid, LOCK_R); |
|---|
| 102 | |
|---|
| 103 | if (u == NULL) |
|---|
| 104 | added = gLicqDaemon->AddUserToList(id, ppid, true, false, group); |
|---|
| 105 | else |
|---|
| 106 | { |
|---|
| 107 | bool notInList = u->NotInList(); |
|---|
| 108 | gUserManager.DropUser(u); |
|---|
| 109 | |
|---|
| 110 | if (notInList) |
|---|
| 111 | { |
|---|
| 112 | gUserManager.SetUserInGroup(id, ppid, GROUPS_USER, group, true, true); |
|---|
| 113 | ICQUser* user = gUserManager.FetchUser(id, ppid, LOCK_W); |
|---|
| 114 | user->SetPermanent(); |
|---|
| 115 | gUserManager.DropUser(user); |
|---|
| 116 | added = true; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | if (added && notify) |
|---|
| 122 | gLicqDaemon->icqAlertUser(id, ppid); |
|---|
| 123 | |
|---|
| 124 | close(); |
|---|
| 125 | } |
|---|