root/trunk/qt4-gui/src/userevents/usersendchatevent.cpp

Revision 6463, 5.1 kB (checked in by flynd, 4 months ago)

Use a const pointer for user objects that are only fetched for read access. Fixed some places where we changed the user even though we just had a read lock.

Line 
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 "usersendchatevent.h"
22
23#include <QAction>
24#include <QHBoxLayout>
25#include <QSplitter>
26#include <QLabel>
27#include <QPushButton>
28#include <QTextCodec>
29
30#include <licq_icqd.h>
31
32#include "config/chat.h"
33
34#include "core/gui-defines.h"
35#include "core/licqgui.h"
36#include "core/messagebox.h"
37
38#include "dialogs/chatdlg.h"
39#include "dialogs/joinchatdlg.h"
40
41#include "widgets/infofield.h"
42#include "widgets/mledit.h"
43
44#include "usereventtabdlg.h"
45
46using namespace LicqQtGui;
47/* TRANSLATOR LicqQtGui::UserSendChatEvent */
48
49UserSendChatEvent::UserSendChatEvent(QString id, unsigned long ppid, QWidget* parent)
50  : UserSendCommon(ChatEvent, id, ppid, parent, "UserSendChatEvent")
51{
52  myChatPort = 0;
53  myMassMessageCheck->setChecked(false);
54  myMassMessageCheck->setEnabled(false);
55  myForeColor->setEnabled(false);
56  myBackColor->setEnabled(false);
57
58  myMainWidget->addWidget(myViewSplitter);
59
60  if (!Config::Chat::instance()->msgChatView())
61    myMessageEdit->setMinimumHeight(150);
62
63  QHBoxLayout* h_lay = new QHBoxLayout();
64  myMainWidget->addLayout(h_lay);
65  myItemLabel = new QLabel(tr("Multiparty: "));
66  h_lay->addWidget(myItemLabel);
67
68  myItemEdit = new InfoField(false);
69  h_lay->addWidget(myItemEdit);
70
71  myBrowseButton = new QPushButton(tr("Invite"));
72  connect(myBrowseButton, SIGNAL(clicked()), SLOT(inviteUser()));
73  h_lay->addWidget(myBrowseButton);
74
75  myBaseTitle += tr(" - Chat Request");
76
77  UserEventTabDlg* tabDlg = LicqGui::instance()->userEventTabDlg();
78  if (tabDlg != NULL && tabDlg->tabIsSelected(this))
79    tabDlg->setWindowTitle(myBaseTitle);
80
81  setWindowTitle(myBaseTitle);
82  myEventTypeGroup->actions().at(ChatEvent)->setChecked(true);
83}
84
85UserSendChatEvent::~UserSendChatEvent()
86{
87  // Empty
88}
89
90bool UserSendChatEvent::sendDone(ICQEvent* e)
91{
92  if (!e->ExtendedAck() || !e->ExtendedAck()->Accepted())
93  {
94    const ICQUser* u = gUserManager.FetchUser(myUsers.front().c_str(), myPpid, LOCK_R);
95    QString s = !e->ExtendedAck() ?
96      tr("No reason provided") :
97      myCodec->toUnicode(e->ExtendedAck()->Response());
98    QString result = tr("Chat with %1 refused:\n%2")
99      .arg(u == NULL ? QString(myUsers.front().c_str()) : QString::fromUtf8(u->GetAlias()))
100      .arg(s);
101    if (u != NULL)
102      gUserManager.DropUser(u);
103    InformUser(this, result);
104  }
105  else
106  {
107    const CEventChat* c = dynamic_cast<const CEventChat*>(e->UserEvent());
108    if (c->Port() == 0)  // If we requested a join, no need to do anything
109    {
110      ChatDlg* chatDlg = new ChatDlg(myUsers.front().c_str(), myPpid);
111      chatDlg->StartAsClient(e->ExtendedAck()->Port());
112    }
113  }
114
115  return true;
116}
117
118void UserSendChatEvent::resetSettings()
119{
120  myMessageEdit->clear();
121  myItemEdit->clear();
122  myMessageEdit->setFocus();
123  massMessageToggled(false);
124}
125
126void UserSendChatEvent::inviteUser()
127{
128  if (myChatPort == 0)
129  {
130    if (ChatDlg::chatDlgs.size() > 0)
131    {
132      ChatDlg* chatDlg = NULL;
133      JoinChatDlg* j = new JoinChatDlg(true, this);
134      if (j->exec() && (chatDlg = j->JoinedChat()) != NULL)
135      {
136        myItemEdit->setText(j->ChatClients());
137        myChatPort = chatDlg->LocalPort();
138        myChatClients = chatDlg->ChatName() + ", " + chatDlg->ChatClients();
139      }
140      delete j;
141      myBrowseButton->setText(tr("Clear"));
142    }
143  }
144  else
145  {
146    myChatPort = 0;
147    myChatClients = "";
148    myItemEdit->setText("");
149    myBrowseButton->setText(tr("Invite"));
150  }
151}
152
153void UserSendChatEvent::send()
154{
155  // Take care of typing notification now
156  mySendTypingTimer->stop();
157  connect(myMessageEdit, SIGNAL(textChanged()), SLOT(messageTextChanged()));
158  gLicqDaemon->ProtoTypingNotification(myUsers.front().c_str(), myPpid, false, myConvoId);
159
160  unsigned long icqEventTag;
161
162  if (myChatPort == 0)
163    //TODO in daemon
164    icqEventTag = gLicqDaemon->icqChatRequest(
165        myUsers.front().c_str(),
166        myCodec->fromUnicode(myMessageEdit->toPlainText()),
167        myUrgentCheck->isChecked() ? ICQ_TCPxMSG_URGENT : ICQ_TCPxMSG_NORMAL,
168        mySendServerCheck->isChecked());
169  else
170    icqEventTag = gLicqDaemon->icqMultiPartyChatRequest(
171        myUsers.front().c_str(),
172        myCodec->fromUnicode(myMessageEdit->toPlainText()),
173        myCodec->fromUnicode(myChatClients),
174        myChatPort,
175        myUrgentCheck->isChecked() ? ICQ_TCPxMSG_URGENT : ICQ_TCPxMSG_NORMAL,
176        mySendServerCheck->isChecked());
177
178  myEventTag.push_back(icqEventTag);
179
180  UserSendCommon::send();
181}
Note: See TracBrowser for help on using the browser.