278
288
void ChatWidget::setChatEnabled(bool enable)
290
d->ui.contactsView->setEnabled(enable);
280
291
d->ui.sendMessageBox->setEnabled(enable);
282
// show a message informing the user
283
AdiumThemeStatusInfo statusMessage;
286
statusMessage.setMessage(i18n("Connection closed"));
288
statusMessage.setMessage(i18nc("Connected to IM service", "Connected"));
290
statusMessage.setService(d->channel->connection()->protocolName());
291
statusMessage.setTime(QDateTime::currentDateTime());
292
d->ui.chatArea->addStatusMessage(statusMessage);
294
292
Q_EMIT iconChanged(icon());
297
295
void ChatWidget::setTextChannel(const Tp::TextChannelPtr &newTextChannelPtr)
297
if (!d->channel.isNull()) {
298
onChannelConnectionChanged(newTextChannelPtr->connection()->status());
299
300
d->channel = newTextChannelPtr; // set the new channel
300
301
d->contactModel->setTextChannel(newTextChannelPtr);
329
330
QWidget::keyPressEvent(e);
333
void ChatWidget::temporaryFileTransferStateChanged(Tp::FileTransferState state, Tp::FileTransferStateChangeReason reason)
337
if ((state == Tp::FileTransferStateCompleted) || (state == Tp::FileTransferStateCancelled)) {
338
Tp::OutgoingFileTransferChannel *channel = qobject_cast<Tp::OutgoingFileTransferChannel*>(sender());
341
QString localFile = QUrl(channel->uri()).toLocalFile();
342
if (QFile::exists(localFile)) {
343
QFile::remove(localFile);
344
kDebug() << "File" << localFile << "removed";
347
d->tmpFileTransfers.removeAll(Tp::OutgoingFileTransferChannelPtr(channel));
352
void ChatWidget::temporaryFileTransferChannelCreated(Tp::PendingOperation *operation)
354
Tp::PendingChannelRequest *request = qobject_cast<Tp::PendingChannelRequest*>(operation);
357
Tp::OutgoingFileTransferChannelPtr transferChannel;
358
transferChannel = Tp::OutgoingFileTransferChannelPtr::qObjectCast<Tp::Channel>(request->channelRequest()->channel());
359
Q_ASSERT(!transferChannel.isNull());
361
/* Make sure the pointer lives until the transfer is over
362
* so that the signal connection below lasts until the end */
363
d->tmpFileTransfers << transferChannel;
365
connect(transferChannel.data(), SIGNAL(stateChanged(Tp::FileTransferState,Tp::FileTransferStateChangeReason)),
366
this, SLOT(temporaryFileTransferStateChanged(Tp::FileTransferState,Tp::FileTransferStateChangeReason)));
370
void ChatWidget::dropEvent(QDropEvent *e)
372
const QMimeData *data = e->mimeData();
374
if (data->hasUrls()) {
375
Q_FOREACH(const QUrl &url, data->urls()) {
376
if (url.isLocalFile()) {
377
Tp::FileTransferChannelCreationProperties properties(
379
KMimeType::findByFileContent(url.toLocalFile())->name());
380
d->account->createFileTransfer(d->channel->targetContact(),
381
properties, QDateTime::currentDateTime(),
382
QLatin1String("org.freedesktop.Telepathy.Client.KTp.FileTransfer"));
384
d->ui.sendMessageBox->append(url.toString());
387
e->acceptProposedAction();
388
} else if (data->hasText()) {
389
d->ui.sendMessageBox->append(data->text());
390
e->acceptProposedAction();
391
} else if (data->hasHtml()) {
392
d->ui.sendMessageBox->insertHtml(data->html());
393
e->acceptProposedAction();
394
} else if (data->hasImage()) {
395
QImage image = qvariant_cast<QImage>(data->imageData());
397
KTemporaryFile tmpFile;
398
tmpFile.setPrefix(d->account->displayName() + QLatin1String("-"));
399
tmpFile.setSuffix(QLatin1String(".png"));
400
tmpFile.setAutoRemove(false);
401
if (!tmpFile.open()) {
406
if (!image.save(tmpFile.fileName(), "PNG")) {
410
Tp::FileTransferChannelCreationProperties properties(
412
KMimeType::findByFileContent(tmpFile.fileName())->name());
413
Tp::PendingChannelRequest *request;
414
request = d->account->createFileTransfer(d->channel->targetContact(),
415
properties, QDateTime::currentDateTime(),
416
QLatin1String("org.freedesktop.Telepathy.Client.KTp.FileTransfer"));
417
connect(request, SIGNAL(finished(Tp::PendingOperation*)),
418
this, SLOT(temporaryFileTransferChannelCreated(Tp::PendingOperation*)));
420
kDebug() << "Starting transfer of" << tmpFile.fileName();
421
e->acceptProposedAction();
424
QWidget::dropEvent(e);
427
void ChatWidget::dragEnterEvent(QDragEnterEvent *e)
429
if (e->mimeData()->hasHtml() || e->mimeData()->hasImage() ||
430
e->mimeData()->hasText() || e->mimeData()->hasUrls()) {
434
QWidget::dragEnterEvent(e);
332
437
QString ChatWidget::title() const
394
499
SLOT(onChatStatusChanged(Tp::ContactPtr,Tp::ChannelChatState)));
395
500
connect(d->channel.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)),
396
501
this, SLOT(onChannelInvalidated()));
502
connect(d->channel.data()->connection().data(), SIGNAL(statusChanged(Tp::ConnectionStatus)),
503
this, SLOT(onChannelConnectionChanged(Tp::ConnectionStatus)));
398
505
if (d->channel->hasChatStateInterface()) {
399
506
connect(d->ui.sendMessageBox, SIGNAL(textChanged()), SLOT(onInputBoxChanged()));
937
1044
d->channel->requestChatState(Tp::ChannelChatStatePaused);
1047
void ChatWidget::onChannelConnectionChanged(Tp::ConnectionStatus status)
1049
if (status == Tp::ConnectionStatusConnected) {
1050
onContactPresenceChange(d->channel->groupSelfContact(), KTp::Presence(d->channel->groupSelfContact()->presence()));
1051
} else if (status == Tp::ConnectionStatusDisconnected) {
1052
// show a message informing the user
1053
AdiumThemeStatusInfo statusMessage;
1054
statusMessage.setMessage(i18n("You are now offline"));
1055
statusMessage.setService(d->channel->connection()->protocolName());
1056
statusMessage.setTime(QDateTime::currentDateTime());
1057
d->ui.chatArea->addStatusMessage(statusMessage);
940
1061
#include "chat-widget.moc"