| 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 | // written by Graham Roff <graham@licq.org> |
|---|
| 22 | // Contributions by Dirk A. Mueller <dirk@licq.org> |
|---|
| 23 | |
|---|
| 24 | #include "forwarddlg.h" |
|---|
| 25 | |
|---|
| 26 | #include "config.h" |
|---|
| 27 | |
|---|
| 28 | #include <QGridLayout> |
|---|
| 29 | #include <QDragEnterEvent> |
|---|
| 30 | #include <QDropEvent> |
|---|
| 31 | #include <QLabel> |
|---|
| 32 | #include <QPushButton> |
|---|
| 33 | |
|---|
| 34 | #include <licq_icqd.h> |
|---|
| 35 | #include <licq_user.h> |
|---|
| 36 | |
|---|
| 37 | #include "core/gui-defines.h" |
|---|
| 38 | #include "core/messagebox.h" |
|---|
| 39 | |
|---|
| 40 | #include "helpers/support.h" |
|---|
| 41 | |
|---|
| 42 | #include "userevents/usersendmsgevent.h" |
|---|
| 43 | #include "userevents/usersendurlevent.h" |
|---|
| 44 | |
|---|
| 45 | #include "widgets/infofield.h" |
|---|
| 46 | |
|---|
| 47 | using namespace LicqQtGui; |
|---|
| 48 | /* TRANSLATOR LicqQtGui::ForwardDlg */ |
|---|
| 49 | |
|---|
| 50 | ForwardDlg::ForwardDlg(CUserEvent* e, QWidget* p) |
|---|
| 51 | : QDialog(p, Qt::Window) |
|---|
| 52 | { |
|---|
| 53 | Support::setWidgetProps(this, "UserForwardDialog"); |
|---|
| 54 | setAttribute(Qt::WA_DeleteOnClose, true); |
|---|
| 55 | |
|---|
| 56 | m_nEventType = e->SubCommand(); |
|---|
| 57 | m_nPPID = 0; |
|---|
| 58 | |
|---|
| 59 | QString t; |
|---|
| 60 | switch (e->SubCommand()) |
|---|
| 61 | { |
|---|
| 62 | case ICQ_CMDxSUB_MSG: |
|---|
| 63 | t = tr("Message"); |
|---|
| 64 | s1 = QString::fromLocal8Bit(dynamic_cast<CEventMsg*>(e)->Message()); |
|---|
| 65 | break; |
|---|
| 66 | case ICQ_CMDxSUB_URL: |
|---|
| 67 | t = tr("URL"); |
|---|
| 68 | s1 = QString::fromLocal8Bit(dynamic_cast<CEventUrl*>(e)->Url()); |
|---|
| 69 | s2 = QString::fromLocal8Bit(dynamic_cast<CEventUrl*>(e)->Description()); |
|---|
| 70 | break; |
|---|
| 71 | default: |
|---|
| 72 | WarnUser(this, tr("Unable to forward this message type (%d).") |
|---|
| 73 | .arg(e->SubCommand())); |
|---|
| 74 | return; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | setWindowTitle(tr("Forward %1 To User").arg(t)); |
|---|
| 78 | setAcceptDrops(true); |
|---|
| 79 | |
|---|
| 80 | QGridLayout* lay = new QGridLayout(this); |
|---|
| 81 | QLabel* lbl = new QLabel(tr("Drag the user to forward to here:")); |
|---|
| 82 | lay->addWidget(lbl, 0, 0, 1, 5); |
|---|
| 83 | edtUser = new InfoField(true); |
|---|
| 84 | edtUser->setAcceptDrops(false); |
|---|
| 85 | lay->addWidget(edtUser, 1, 0, 1, 5); |
|---|
| 86 | |
|---|
| 87 | lay->setColumnStretch(0, 2); |
|---|
| 88 | btnOk = new QPushButton(tr("&Forward")); |
|---|
| 89 | lay->addWidget(btnOk, 2, 1); |
|---|
| 90 | |
|---|
| 91 | lay->setColumnMinimumWidth(2, 10); |
|---|
| 92 | btnCancel = new QPushButton(tr("&Cancel")); |
|---|
| 93 | lay->addWidget(btnCancel, 2, 3); |
|---|
| 94 | lay->setColumnStretch(4, 2); |
|---|
| 95 | |
|---|
| 96 | connect(btnOk, SIGNAL(clicked()), SLOT(slot_ok())); |
|---|
| 97 | connect(btnCancel, SIGNAL(clicked()), SLOT(close())); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | ForwardDlg::~ForwardDlg() |
|---|
| 102 | { |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | void ForwardDlg::slot_ok() |
|---|
| 107 | { |
|---|
| 108 | if (myId.isEmpty()) |
|---|
| 109 | return; |
|---|
| 110 | |
|---|
| 111 | switch(m_nEventType) |
|---|
| 112 | { |
|---|
| 113 | case ICQ_CMDxSUB_MSG: |
|---|
| 114 | { |
|---|
| 115 | s1.prepend(tr("Forwarded message:\n")); |
|---|
| 116 | UserSendMsgEvent* e = new UserSendMsgEvent(myId, m_nPPID); |
|---|
| 117 | e->setText(s1); |
|---|
| 118 | e->show(); |
|---|
| 119 | break; |
|---|
| 120 | } |
|---|
| 121 | case ICQ_CMDxSUB_URL: |
|---|
| 122 | { |
|---|
| 123 | s1.prepend(tr("Forwarded URL:\n")); |
|---|
| 124 | UserSendUrlEvent* e = new UserSendUrlEvent(myId, m_nPPID); |
|---|
| 125 | e->setUrl(s2, s1); |
|---|
| 126 | e->show(); |
|---|
| 127 | break; |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | close(); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | void ForwardDlg::dragEnterEvent(QDragEnterEvent* dee) |
|---|
| 137 | { |
|---|
| 138 | if (dee->mimeData()->hasText()) |
|---|
| 139 | dee->accept(); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | void ForwardDlg::dropEvent(QDropEvent* de) |
|---|
| 144 | { |
|---|
| 145 | QString text = de->mimeData()->text(); |
|---|
| 146 | if (text.isEmpty()) |
|---|
| 147 | return; |
|---|
| 148 | |
|---|
| 149 | unsigned long nPPID = 0; |
|---|
| 150 | FOR_EACH_PROTO_PLUGIN_START(gLicqDaemon) |
|---|
| 151 | { |
|---|
| 152 | if (text.startsWith(PPIDSTRING((*_ppit)->PPID()))) |
|---|
| 153 | { |
|---|
| 154 | nPPID = (*_ppit)->PPID(); |
|---|
| 155 | break; |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | FOR_EACH_PROTO_PLUGIN_END; |
|---|
| 159 | |
|---|
| 160 | if (nPPID == 0 || text.length() <= 4) |
|---|
| 161 | return; |
|---|
| 162 | |
|---|
| 163 | myId = text.mid(4); |
|---|
| 164 | m_nPPID = nPPID; |
|---|
| 165 | |
|---|
| 166 | const ICQUser* u = gUserManager.FetchUser(myId.toLatin1(), m_nPPID, LOCK_R); |
|---|
| 167 | if (u == NULL) |
|---|
| 168 | return; |
|---|
| 169 | |
|---|
| 170 | edtUser->setText(QString::fromUtf8(u->GetAlias()) + " (" + myId + ")"); |
|---|
| 171 | gUserManager.DropUser(u); |
|---|
| 172 | } |
|---|