| 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 "usersendsmsevent.h" |
|---|
| 22 | |
|---|
| 23 | #include <QAction> |
|---|
| 24 | #include <QVBoxLayout> |
|---|
| 25 | #include <QHBoxLayout> |
|---|
| 26 | #include <QSplitter> |
|---|
| 27 | #include <QLabel> |
|---|
| 28 | #include <QPushButton> |
|---|
| 29 | #include <QTextCodec> |
|---|
| 30 | #include <QTimer> |
|---|
| 31 | |
|---|
| 32 | #include <licq_icqd.h> |
|---|
| 33 | |
|---|
| 34 | #include "core/gui-defines.h" |
|---|
| 35 | #include "core/licqgui.h" |
|---|
| 36 | #include "core/messagebox.h" |
|---|
| 37 | |
|---|
| 38 | #include "widgets/infofield.h" |
|---|
| 39 | #include "widgets/mledit.h" |
|---|
| 40 | |
|---|
| 41 | #include "usereventtabdlg.h" |
|---|
| 42 | |
|---|
| 43 | using namespace LicqQtGui; |
|---|
| 44 | /* TRANSLATOR LicqQtGui::UserSendSmsEvent */ |
|---|
| 45 | |
|---|
| 46 | UserSendSmsEvent::UserSendSmsEvent(QString id, unsigned long ppid, QWidget* parent) |
|---|
| 47 | : UserSendCommon(SmsEvent, id, ppid, parent, "UserSendSmsEvent") |
|---|
| 48 | { |
|---|
| 49 | mySendServerCheck->setChecked(true); |
|---|
| 50 | mySendServerCheck->setEnabled(false); |
|---|
| 51 | myUrgentCheck->setChecked(false); |
|---|
| 52 | myUrgentCheck->setEnabled(false); |
|---|
| 53 | myMassMessageCheck->setChecked(false); |
|---|
| 54 | myMassMessageCheck->setEnabled(false); |
|---|
| 55 | myForeColor->setEnabled(false); |
|---|
| 56 | myBackColor->setEnabled(false); |
|---|
| 57 | myEncoding->setEnabled(false); // SMSs are always UTF-8 |
|---|
| 58 | |
|---|
| 59 | myMainWidget->addWidget(myViewSplitter); |
|---|
| 60 | myMessageEdit->setFocus(); |
|---|
| 61 | |
|---|
| 62 | QHBoxLayout* h_lay = new QHBoxLayout(); |
|---|
| 63 | myMainWidget->addLayout(h_lay); |
|---|
| 64 | myNumberLabel = new QLabel(tr("Phone : ")); |
|---|
| 65 | h_lay->addWidget(myNumberLabel); |
|---|
| 66 | myNumberField = new InfoField(false); |
|---|
| 67 | h_lay->addWidget(myNumberField); |
|---|
| 68 | myNumberField->setFixedWidth(qMax(140, myNumberField->sizeHint().width())); |
|---|
| 69 | h_lay->addStretch(1); |
|---|
| 70 | myCountLabel = new QLabel(tr("Chars left : ")); |
|---|
| 71 | h_lay->addWidget(myCountLabel); |
|---|
| 72 | myCountField = new InfoField(false); |
|---|
| 73 | h_lay->addWidget(myCountField); |
|---|
| 74 | myCountField->setFixedWidth(40); |
|---|
| 75 | myCountField->setAlignment(Qt::AlignCenter); |
|---|
| 76 | count(); |
|---|
| 77 | connect(myMessageEdit, SIGNAL(textChanged()), SLOT(count())); |
|---|
| 78 | |
|---|
| 79 | ICQUser* u = gUserManager.FetchUser(myUsers.front().c_str(), myPpid, LOCK_W); |
|---|
| 80 | if (u != NULL) |
|---|
| 81 | { |
|---|
| 82 | myNumberField->setText(myCodec->toUnicode(u->GetCellularNumber())); |
|---|
| 83 | gUserManager.DropUser(u); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | myBaseTitle += tr(" - SMS"); |
|---|
| 87 | |
|---|
| 88 | UserEventTabDlg* tabDlg = LicqGui::instance()->userEventTabDlg(); |
|---|
| 89 | if (tabDlg != NULL && tabDlg->tabIsSelected(this)) |
|---|
| 90 | tabDlg->setWindowTitle(myBaseTitle); |
|---|
| 91 | |
|---|
| 92 | setWindowTitle(myBaseTitle); |
|---|
| 93 | myEventTypeGroup->actions().at(SmsEvent)->setChecked(true); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | UserSendSmsEvent::~UserSendSmsEvent() |
|---|
| 97 | { |
|---|
| 98 | // Empty |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | bool UserSendSmsEvent::sendDone(ICQEvent* /* e */) |
|---|
| 102 | { |
|---|
| 103 | return true; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | void UserSendSmsEvent::resetSettings() |
|---|
| 107 | { |
|---|
| 108 | myMessageEdit->clear(); |
|---|
| 109 | myMessageEdit->setFocus(); |
|---|
| 110 | massMessageToggled(false); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | void UserSendSmsEvent::send() |
|---|
| 114 | { |
|---|
| 115 | // Take care of typing notification now |
|---|
| 116 | mySendTypingTimer->stop(); |
|---|
| 117 | connect(myMessageEdit, SIGNAL(textChanged()), SLOT(messageTextChanged())); |
|---|
| 118 | gLicqDaemon->ProtoTypingNotification(myUsers.front().c_str(), myPpid, false, myConvoId); |
|---|
| 119 | |
|---|
| 120 | unsigned long icqEventTag = 0; |
|---|
| 121 | if (myEventTag.size()) |
|---|
| 122 | icqEventTag = myEventTag.front(); |
|---|
| 123 | |
|---|
| 124 | // do nothing if a command is already being processed |
|---|
| 125 | if (icqEventTag != 0) |
|---|
| 126 | return; |
|---|
| 127 | |
|---|
| 128 | if (!myMessageEdit->document()->isModified() && |
|---|
| 129 | !QueryYesNo(this, tr("You didn't edit the SMS.\nDo you really want to send it?"))) |
|---|
| 130 | return; |
|---|
| 131 | |
|---|
| 132 | // don't let the user send empty messages |
|---|
| 133 | if (myMessageEdit->toPlainText().trimmed().isEmpty()) |
|---|
| 134 | return; |
|---|
| 135 | |
|---|
| 136 | //TODO in daemon |
|---|
| 137 | icqEventTag = gLicqDaemon->icqSendSms(myUsers.front().c_str(), LICQ_PPID, |
|---|
| 138 | myNumberField->text().toLatin1(), |
|---|
| 139 | myMessageEdit->toPlainText().toUtf8().data()); |
|---|
| 140 | myEventTag.push_back(icqEventTag); |
|---|
| 141 | |
|---|
| 142 | UserSendCommon::send(); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | void UserSendSmsEvent::count() |
|---|
| 146 | { |
|---|
| 147 | int len = 160 - strlen(myMessageEdit->toPlainText().toUtf8().data()); |
|---|
| 148 | myCountField->setText((len >= 0) ? len : 0); |
|---|
| 149 | } |
|---|