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

Revision 6463, 4.6 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 "usersendurlevent.h"
22
23#include <QAction>
24#include <QActionGroup>
25#include <QHBoxLayout>
26#include <QLabel>
27#include <QKeyEvent>
28#include <QPushButton>
29#include <QSplitter>
30#include <QTextCodec>
31#include <QTimer>
32#include <QVBoxLayout>
33
34#include <licq_icqd.h>
35
36#include "config/chat.h"
37
38#include "core/gui-defines.h"
39#include "core/licqgui.h"
40#include "core/messagebox.h"
41
42#include "dialogs/mmsenddlg.h"
43#include "dialogs/showawaymsgdlg.h"
44
45#include "widgets/infofield.h"
46#include "widgets/mledit.h"
47
48#include "usereventtabdlg.h"
49
50using namespace LicqQtGui;
51/* TRANSLATOR LicqQtGui::UserSendUrlEvent */
52
53UserSendUrlEvent::UserSendUrlEvent(QString id, unsigned long ppid, QWidget* parent)
54  : UserSendCommon(UrlEvent, id, ppid, parent, "UserSendUrlEvent")
55{
56  myMainWidget->addWidget(myViewSplitter);
57  myMessageEdit->setFocus();
58
59  QHBoxLayout* h_lay = new QHBoxLayout();
60  myMainWidget->addLayout(h_lay);
61  myUrlLabel = new QLabel(tr("URL : "));
62  h_lay->addWidget(myUrlLabel);
63  myUrlEdit = new InfoField(false);
64  h_lay->addWidget(myUrlEdit);
65  myUrlEdit->installEventFilter(this);
66
67  myBaseTitle += tr(" - URL");
68
69  UserEventTabDlg* tabDlg = LicqGui::instance()->userEventTabDlg();
70  if (tabDlg != NULL && tabDlg->tabIsSelected(this))
71    tabDlg->setWindowTitle(myBaseTitle);
72
73  setWindowTitle(myBaseTitle);
74  myEventTypeGroup->actions().at(UrlEvent)->setChecked(true);
75}
76
77UserSendUrlEvent::~UserSendUrlEvent()
78{
79  // Empty
80}
81
82bool UserSendUrlEvent::eventFilter(QObject* watched, QEvent* e)
83{
84  if (watched == myUrlEdit)
85  {
86    if (e->type() == QEvent::KeyPress)
87    {
88      QKeyEvent* key = dynamic_cast<QKeyEvent*>(e);
89      const bool isEnter = (key->key() == Qt::Key_Enter || key->key() == Qt::Key_Return);
90      if (isEnter && (Config::Chat::instance()->singleLineChatMode() || key->modifiers() & Qt::ControlModifier))
91      {
92        mySendButton->animateClick();
93        return true; // filter the event out
94      }
95    }
96    return false;
97  }
98  else
99    return UserSendCommon::eventFilter(watched, e);
100}
101
102void UserSendUrlEvent::setUrl(const QString& url, const QString& description)
103{
104  myUrlEdit->setText(url);
105  setText(description);
106}
107
108bool UserSendUrlEvent::sendDone(ICQEvent* e)
109{
110  if (e->Command() != ICQ_CMDxTCP_START)
111    return true;
112
113  bool showAwayDlg = false;
114  const ICQUser* u = gUserManager.FetchUser(myUsers.front().c_str(), myPpid, LOCK_R);
115  if (u != NULL)
116  {
117    showAwayDlg = u->Away() && u->ShowAwayMsg();
118    gUserManager.DropUser(u);
119  }
120
121  if (showAwayDlg && Config::Chat::instance()->popupAutoResponse())
122    new ShowAwayMsgDlg(myUsers.front().c_str(), myPpid);
123
124  return true;
125}
126
127void UserSendUrlEvent::resetSettings()
128{
129  myMessageEdit->clear();
130  myUrlEdit->clear();
131  myMessageEdit->setFocus();
132  massMessageToggled(false);
133}
134
135void UserSendUrlEvent::send()
136{
137  // Take care of typing notification now
138  mySendTypingTimer->stop();
139  connect(myMessageEdit, SIGNAL(textChanged()), SLOT(messageTextChanged()));
140  gLicqDaemon->ProtoTypingNotification(myUsers.front().c_str(), myPpid, false, myConvoId);
141
142  if (myUrlEdit->text().trimmed().isEmpty())
143  {
144    InformUser(this, tr("No URL specified"));
145    return;
146  }
147
148  if (!checkSecure())
149    return;
150
151  if (myMassMessageCheck->isChecked())
152  {
153    MMSendDlg* m = new MMSendDlg(myMassMessageList, this);
154    int r = m->go_url(myUrlEdit->text(), myMessageEdit->toPlainText());
155    delete m;
156    if (r != QDialog::Accepted)
157      return;
158  }
159
160  unsigned long icqEventTag;
161  icqEventTag = gLicqDaemon->ProtoSendUrl(
162      myUsers.front().c_str(),
163      myPpid,
164      myUrlEdit->text().toLatin1(),
165      myCodec->fromUnicode(myMessageEdit->toPlainText()),
166      mySendServerCheck->isChecked() ? false : true,
167      myUrgentCheck->isChecked() ? ICQ_TCPxMSG_URGENT : ICQ_TCPxMSG_NORMAL,
168      myMassMessageCheck->isChecked(),
169      &myIcqColor);
170
171  myEventTag.push_back(icqEventTag);
172
173  UserSendCommon::send();
174}
Note: See TracBrowser for help on using the browser.