| 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 "authuserdlg.h" |
|---|
| 22 | |
|---|
| 23 | #include <QDialogButtonBox> |
|---|
| 24 | #include <QGroupBox> |
|---|
| 25 | #include <QHBoxLayout> |
|---|
| 26 | #include <QLabel> |
|---|
| 27 | #include <QLineEdit> |
|---|
| 28 | #include <QTextCodec> |
|---|
| 29 | #include <QVBoxLayout> |
|---|
| 30 | |
|---|
| 31 | #include <licq_icqd.h> |
|---|
| 32 | #include <licq_user.h> |
|---|
| 33 | |
|---|
| 34 | #include "helpers/support.h" |
|---|
| 35 | #include "helpers/usercodec.h" |
|---|
| 36 | |
|---|
| 37 | #include "widgets/mledit.h" |
|---|
| 38 | |
|---|
| 39 | using namespace LicqQtGui; |
|---|
| 40 | /* TRANSLATOR LicqQtGui::AuthUserDlg */ |
|---|
| 41 | |
|---|
| 42 | AuthUserDlg::AuthUserDlg(QString id, unsigned long ppid, bool grant, QWidget* parent) |
|---|
| 43 | : QDialog(parent), |
|---|
| 44 | myId(id), |
|---|
| 45 | myPpid(ppid), |
|---|
| 46 | myGrant(grant) |
|---|
| 47 | { |
|---|
| 48 | Support::setWidgetProps(this, "AuthUserDialog"); |
|---|
| 49 | setAttribute(Qt::WA_DeleteOnClose, true); |
|---|
| 50 | setWindowTitle(tr("Licq - %1 Authorization") |
|---|
| 51 | .arg(myGrant ? tr("Grant") : tr("Refuse"))); |
|---|
| 52 | |
|---|
| 53 | QVBoxLayout* toplay = new QVBoxLayout(this); |
|---|
| 54 | |
|---|
| 55 | QLabel* lblUin = new QLabel(); |
|---|
| 56 | lblUin->setAlignment(Qt::AlignCenter); |
|---|
| 57 | if (myId.isEmpty()) |
|---|
| 58 | { |
|---|
| 59 | lblUin->setText(tr("User Id:")); |
|---|
| 60 | myUin = new QLineEdit(); |
|---|
| 61 | connect(myUin, SIGNAL(returnPressed()), SLOT(ok())); |
|---|
| 62 | QHBoxLayout* lay = new QHBoxLayout(); |
|---|
| 63 | lay->addWidget(lblUin); |
|---|
| 64 | lay->addWidget(myUin); |
|---|
| 65 | toplay->addLayout(lay); |
|---|
| 66 | } |
|---|
| 67 | else |
|---|
| 68 | { |
|---|
| 69 | myUin = NULL; |
|---|
| 70 | toplay->addWidget(lblUin); |
|---|
| 71 | QString userName = myId; |
|---|
| 72 | const ICQUser* u = gUserManager.FetchUser(myId.toLatin1(), myPpid, LOCK_R); |
|---|
| 73 | if (u != NULL) |
|---|
| 74 | { |
|---|
| 75 | userName = QString("%1 (%2)").arg(QString::fromUtf8(u->GetAlias())).arg(myId); |
|---|
| 76 | gUserManager.DropUser(u); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | lblUin->setText(tr("%1 authorization to %2") |
|---|
| 80 | .arg(myGrant ? tr("Grant") : tr("Refuse")) |
|---|
| 81 | .arg(userName)); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | QGroupBox* grpResponse = new QGroupBox(tr("Response")); |
|---|
| 85 | toplay->addWidget(grpResponse); |
|---|
| 86 | toplay->setStretchFactor(grpResponse, 2); |
|---|
| 87 | |
|---|
| 88 | QVBoxLayout* layResponse = new QVBoxLayout(grpResponse); |
|---|
| 89 | myResponse = new MLEdit(true); |
|---|
| 90 | myResponse->setSizeHintLines(5); |
|---|
| 91 | connect(myResponse, SIGNAL(ctrlEnterPressed()), SLOT(ok())); |
|---|
| 92 | layResponse->addWidget(myResponse); |
|---|
| 93 | |
|---|
| 94 | QDialogButtonBox* buttons = new QDialogButtonBox( |
|---|
| 95 | QDialogButtonBox::Ok | |
|---|
| 96 | QDialogButtonBox::Cancel); |
|---|
| 97 | connect(buttons, SIGNAL(accepted()), SLOT(ok())); |
|---|
| 98 | connect(buttons, SIGNAL(rejected()), SLOT(close())); |
|---|
| 99 | |
|---|
| 100 | toplay->addWidget(buttons); |
|---|
| 101 | |
|---|
| 102 | if (myId.isEmpty()) |
|---|
| 103 | myUin->setFocus(); |
|---|
| 104 | else |
|---|
| 105 | myResponse->setFocus(); |
|---|
| 106 | |
|---|
| 107 | show(); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | void AuthUserDlg::ok() |
|---|
| 111 | { |
|---|
| 112 | if (myUin != NULL && myUin->text().trimmed().isEmpty()) |
|---|
| 113 | return; |
|---|
| 114 | |
|---|
| 115 | if (myId.isEmpty()) |
|---|
| 116 | myId = myUin->text().trimmed(); |
|---|
| 117 | |
|---|
| 118 | if (!myId.isEmpty()) |
|---|
| 119 | { |
|---|
| 120 | QTextCodec* codec = UserCodec::codecForProtoUser(myId, myPpid); |
|---|
| 121 | if (myGrant) |
|---|
| 122 | gLicqDaemon->ProtoAuthorizeGrant( |
|---|
| 123 | myId.toLatin1(), myPpid, codec->fromUnicode(myResponse->toPlainText())); |
|---|
| 124 | else |
|---|
| 125 | gLicqDaemon->ProtoAuthorizeRefuse( |
|---|
| 126 | myId.toLatin1(), myPpid, codec->fromUnicode(myResponse->toPlainText())); |
|---|
| 127 | close(); |
|---|
| 128 | } |
|---|
| 129 | } |
|---|