| 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 "usersendcontactevent.h" |
|---|
| 22 | |
|---|
| 23 | #include <QAction> |
|---|
| 24 | #include <QLabel> |
|---|
| 25 | #include <QSplitter> |
|---|
| 26 | #include <QTimer> |
|---|
| 27 | #include <QVBoxLayout> |
|---|
| 28 | |
|---|
| 29 | #include <licq_icqd.h> |
|---|
| 30 | #include <licq_user.h> |
|---|
| 31 | |
|---|
| 32 | #include "config/chat.h" |
|---|
| 33 | |
|---|
| 34 | #include "core/gui-defines.h" |
|---|
| 35 | #include "core/licqgui.h" |
|---|
| 36 | |
|---|
| 37 | #include "dialogs/mmsenddlg.h" |
|---|
| 38 | #include "dialogs/showawaymsgdlg.h" |
|---|
| 39 | |
|---|
| 40 | #include "views/mmuserview.h" |
|---|
| 41 | |
|---|
| 42 | #include "widgets/mledit.h" |
|---|
| 43 | |
|---|
| 44 | #include "usereventtabdlg.h" |
|---|
| 45 | |
|---|
| 46 | using namespace LicqQtGui; |
|---|
| 47 | /* TRANSLATOR LicqQtGui::UserSendContactEvent */ |
|---|
| 48 | |
|---|
| 49 | UserSendContactEvent::UserSendContactEvent(QString id, unsigned long ppid, QWidget* parent) |
|---|
| 50 | : UserSendCommon(ContactEvent, id, ppid, parent, "UserSendContactEvent") |
|---|
| 51 | { |
|---|
| 52 | myMassMessageCheck->setChecked(false); |
|---|
| 53 | myMassMessageCheck->setEnabled(false); |
|---|
| 54 | myForeColor->setEnabled(false); |
|---|
| 55 | myBackColor->setEnabled(false); |
|---|
| 56 | myEmoticon->setEnabled(false); |
|---|
| 57 | |
|---|
| 58 | myMainWidget->addWidget(myViewSplitter); |
|---|
| 59 | |
|---|
| 60 | QSplitter* bottom = dynamic_cast<QSplitter*>(myMessageEdit->parentWidget()); |
|---|
| 61 | int ind = bottom->indexOf(myMessageEdit); |
|---|
| 62 | delete myMessageEdit; |
|---|
| 63 | myMessageEdit = NULL; |
|---|
| 64 | |
|---|
| 65 | QWidget* w = new QWidget(); |
|---|
| 66 | bottom->insertWidget(ind, w); |
|---|
| 67 | QVBoxLayout* lay = new QVBoxLayout(w); |
|---|
| 68 | lay->setContentsMargins(0, 0, 0, 0); |
|---|
| 69 | |
|---|
| 70 | w->setToolTip(tr("Drag Users Here - Right Click for Options")); |
|---|
| 71 | |
|---|
| 72 | myContactsList = new MMUserView(myUsers.front().c_str(), myPpid, |
|---|
| 73 | LicqGui::instance()->contactList()); |
|---|
| 74 | lay->addWidget(myContactsList); |
|---|
| 75 | |
|---|
| 76 | myBaseTitle += tr(" - Contact List"); |
|---|
| 77 | |
|---|
| 78 | UserEventTabDlg* tabDlg = LicqGui::instance()->userEventTabDlg(); |
|---|
| 79 | if (tabDlg != NULL && tabDlg->tabIsSelected(this)) |
|---|
| 80 | tabDlg->setWindowTitle(myBaseTitle); |
|---|
| 81 | |
|---|
| 82 | setWindowTitle(myBaseTitle); |
|---|
| 83 | myEventTypeGroup->actions().at(ContactEvent)->setChecked(true); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | UserSendContactEvent::~UserSendContactEvent() |
|---|
| 87 | { |
|---|
| 88 | // Empty |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | void UserSendContactEvent::setContact(QString id, unsigned long ppid) |
|---|
| 92 | { |
|---|
| 93 | const ICQUser* u = gUserManager.FetchUser(id.toLatin1(), ppid, LOCK_R); |
|---|
| 94 | |
|---|
| 95 | if (u != NULL) |
|---|
| 96 | { |
|---|
| 97 | myContactsList->add(id, ppid); |
|---|
| 98 | gUserManager.DropUser(u); |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | bool UserSendContactEvent::sendDone(ICQEvent* e) |
|---|
| 103 | { |
|---|
| 104 | if (e->Command() != ICQ_CMDxTCP_START) |
|---|
| 105 | return true; |
|---|
| 106 | |
|---|
| 107 | bool showAwayDlg = false; |
|---|
| 108 | const ICQUser* u = gUserManager.FetchUser(myUsers.front().c_str(), myPpid, LOCK_R); |
|---|
| 109 | if (u != NULL) |
|---|
| 110 | { |
|---|
| 111 | showAwayDlg = u->Away() && u->ShowAwayMsg(); |
|---|
| 112 | gUserManager.DropUser(u); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | if (showAwayDlg && Config::Chat::instance()->popupAutoResponse()) |
|---|
| 116 | new ShowAwayMsgDlg(myUsers.front().c_str(), myPpid); |
|---|
| 117 | |
|---|
| 118 | return true; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | void UserSendContactEvent::resetSettings() |
|---|
| 122 | { |
|---|
| 123 | myContactsList->clear(); |
|---|
| 124 | massMessageToggled(false); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | //TODO Fix this for new protocol plugin |
|---|
| 128 | void UserSendContactEvent::send() |
|---|
| 129 | { |
|---|
| 130 | // Take care of typing notification now |
|---|
| 131 | mySendTypingTimer->stop(); |
|---|
| 132 | gLicqDaemon->ProtoTypingNotification(myUsers.front().c_str(), myPpid, false, myConvoId); |
|---|
| 133 | |
|---|
| 134 | StringList users; |
|---|
| 135 | |
|---|
| 136 | QPair<QString, unsigned long> i; |
|---|
| 137 | foreach (i, myContactsList->contacts()) |
|---|
| 138 | { |
|---|
| 139 | users.push_back(i.first.toLatin1().data()); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | if (users.size() == 0) |
|---|
| 143 | return; |
|---|
| 144 | |
|---|
| 145 | if (!checkSecure()) |
|---|
| 146 | return; |
|---|
| 147 | |
|---|
| 148 | if (myMassMessageCheck->isChecked()) |
|---|
| 149 | { |
|---|
| 150 | MMSendDlg* m = new MMSendDlg(myMassMessageList, this); |
|---|
| 151 | int r = m->go_contact(users); |
|---|
| 152 | delete m; |
|---|
| 153 | if (r != QDialog::Accepted) return; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | unsigned long icqEventTag; |
|---|
| 157 | icqEventTag = gLicqDaemon->icqSendContactList( |
|---|
| 158 | myUsers.front().c_str(), |
|---|
| 159 | users, |
|---|
| 160 | mySendServerCheck->isChecked() ? false : true, |
|---|
| 161 | myUrgentCheck->isChecked() ? ICQ_TCPxMSG_URGENT : ICQ_TCPxMSG_NORMAL, |
|---|
| 162 | myMassMessageCheck->isChecked(), |
|---|
| 163 | &myIcqColor); |
|---|
| 164 | myEventTag.push_back(icqEventTag); |
|---|
| 165 | |
|---|
| 166 | UserSendCommon::send(); |
|---|
| 167 | } |
|---|