2009-01-30 14:52:47 -05:00
|
|
|
/****************************************************************
|
2010-08-06 08:30:06 -04:00
|
|
|
*
|
2009-01-30 14:52:47 -05:00
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, crypton
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "PopupChatDialog.h"
|
2010-11-15 15:49:24 -05:00
|
|
|
#include "PopupChatWindow.h"
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2010-05-11 16:02:52 -04:00
|
|
|
#include "gui/settings/rsharesettings.h"
|
2010-09-10 14:38:46 -04:00
|
|
|
#include "gui/settings/RsharePeerSettings.h"
|
2010-08-20 14:45:44 -04:00
|
|
|
#include "gui/notifyqt.h"
|
2010-09-28 16:33:34 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
#include <retroshare/rsiface.h>
|
|
|
|
|
2011-09-29 05:20:09 -04:00
|
|
|
#include <algorithm>
|
2009-01-30 14:52:47 -05:00
|
|
|
|
|
|
|
#define appDir QApplication::applicationDirPath()
|
|
|
|
|
2010-11-15 15:49:24 -05:00
|
|
|
#define WINDOW(This) dynamic_cast<PopupChatWindow*>(This->window())
|
2009-01-30 14:52:47 -05:00
|
|
|
|
|
|
|
/** Default constructor */
|
2012-01-17 15:36:36 -05:00
|
|
|
PopupChatDialog::PopupChatDialog(QWidget *parent, Qt::WFlags flags)
|
|
|
|
: ChatDialog(parent, flags)
|
2009-01-30 14:52:47 -05:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
/* Invoke Qt Designer generated QObject setup routine */
|
|
|
|
ui.setupUi(this);
|
2011-09-29 05:20:09 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
manualDelete = false;
|
2011-12-07 08:08:12 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
connect(ui.avatarFrameButton, SIGNAL(toggled(bool)), this, SLOT(showAvatarFrame(bool)));
|
|
|
|
connect(ui.actionClearOfflineMessages, SIGNAL(triggered()), this, SLOT(clearOfflineMessages()));
|
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(chatStatusChanged(const QString&, const QString&, bool)), this, SLOT(chatStatusChanged(const QString&, const QString&, bool)));
|
2012-01-11 19:13:25 -05:00
|
|
|
}
|
2011-09-29 05:20:09 -04:00
|
|
|
|
2012-01-17 19:32:15 -05:00
|
|
|
void PopupChatDialog::init(const std::string &peerId, const QString &title)
|
2012-01-11 19:13:25 -05:00
|
|
|
{
|
2012-03-10 19:22:25 -05:00
|
|
|
connect(ui.chatWidget, SIGNAL(statusChanged(int)), this, SLOT(statusChanged(int)));
|
|
|
|
|
2012-01-17 19:32:15 -05:00
|
|
|
ChatDialog::init(peerId, title);
|
2011-09-29 05:20:09 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
/* Hide or show the avatar frames */
|
|
|
|
showAvatarFrame(PeerSettings->getShowAvatarFrame(peerId));
|
2012-01-11 19:13:25 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
|
|
|
|
ui.avatarWidget->setId(peerId, false);
|
2012-01-11 19:13:25 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
ui.ownAvatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
|
|
|
|
ui.ownAvatarWidget->setOwnId();
|
2012-01-11 19:13:25 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
ui.chatWidget->addToolsAction(ui.actionClearOfflineMessages);
|
2012-01-11 19:13:25 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
// add offline chat messages
|
|
|
|
onChatChanged(NOTIFY_LIST_PRIVATE_OUTGOING_CHAT, NOTIFY_TYPE_ADD);
|
2012-01-11 19:13:25 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
// add to window
|
|
|
|
PopupChatWindow *window = PopupChatWindow::getWindow(false);
|
|
|
|
if (window) {
|
|
|
|
window->addDialog(this);
|
|
|
|
}
|
2011-09-29 05:20:09 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
// load settings
|
|
|
|
processSettings(true);
|
2010-08-06 10:58:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Destructor. */
|
|
|
|
PopupChatDialog::~PopupChatDialog()
|
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
// save settings
|
|
|
|
processSettings(false);
|
2010-08-06 10:58:53 -04:00
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
ChatWidget *PopupChatDialog::getChatWidget()
|
2010-08-06 10:58:53 -04:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
return ui.chatWidget;
|
2010-06-17 13:39:32 -04:00
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
void PopupChatDialog::processSettings(bool load)
|
2010-06-17 13:39:32 -04:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
Settings->beginGroup(QString("PopupChatDialog"));
|
2010-11-15 15:49:24 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
if (load) {
|
|
|
|
// load settings
|
|
|
|
} else {
|
|
|
|
// save settings
|
|
|
|
}
|
2010-06-17 13:39:32 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
Settings->endGroup();
|
2010-06-17 13:39:32 -04:00
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
void PopupChatDialog::showDialog(uint chatflags)
|
2010-09-01 13:56:15 -04:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
PopupChatWindow *window = WINDOW(this);
|
|
|
|
if (window) {
|
|
|
|
window->showDialog(this, chatflags);
|
|
|
|
}
|
2012-01-06 17:17:08 -05:00
|
|
|
}
|
2012-01-11 19:13:25 -05:00
|
|
|
|
2009-05-05 09:18:53 -04:00
|
|
|
// Called by libretroshare through notifyQt to display the peer's status
|
|
|
|
//
|
2012-01-17 15:36:36 -05:00
|
|
|
void PopupChatDialog::chatStatusChanged(const QString &peerId, const QString& statusString, bool isPrivateChat)
|
2010-09-01 13:56:15 -04:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
if (isPrivateChat && this->peerId == peerId.toStdString()) {
|
|
|
|
ui.chatWidget->updateStatusString(QString::fromUtf8(rsPeers->getPeerName(this->peerId).c_str()) + " %1", statusString);
|
|
|
|
}
|
2010-09-20 20:08:06 -04:00
|
|
|
}
|
|
|
|
|
2011-12-28 04:15:28 -05:00
|
|
|
void PopupChatDialog::addIncomingChatMsg(const ChatInfo& info)
|
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
ChatWidget *cw = getChatWidget();
|
|
|
|
if (cw) {
|
|
|
|
QDateTime sendTime = QDateTime::fromTime_t(info.sendTime);
|
|
|
|
QDateTime recvTime = QDateTime::fromTime_t(info.recvTime);
|
|
|
|
QString message = QString::fromStdWString(info.msg);
|
|
|
|
QString name = QString::fromUtf8(rsPeers->getPeerName(info.rsid).c_str()) ;
|
2009-05-11 10:21:11 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
cw->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL);
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
}
|
|
|
|
|
2012-02-25 07:17:36 -05:00
|
|
|
void PopupChatDialog::addButton(QPushButton *button)
|
|
|
|
{
|
|
|
|
getChatWidget()->addChatButton(button) ;
|
|
|
|
}
|
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
void PopupChatDialog::onChatChanged(int list, int type)
|
2010-09-04 10:23:30 -04:00
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
if (list == NOTIFY_LIST_PRIVATE_OUTGOING_CHAT) {
|
|
|
|
switch (type) {
|
|
|
|
case NOTIFY_TYPE_ADD:
|
|
|
|
{
|
|
|
|
std::list<ChatInfo> savedOfflineChatNew;
|
2010-09-04 10:23:30 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
QString name = QString::fromUtf8(rsPeers->getPeerName(rsPeers->getOwnId()).c_str());
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
std::list<ChatInfo> offlineChat;
|
|
|
|
if (rsMsgs->getPrivateChatQueueCount(false) && rsMsgs->getPrivateChatQueue(false, peerId, offlineChat)) {
|
|
|
|
ui.actionClearOfflineMessages->setEnabled(true);
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
std::list<ChatInfo>::iterator it;
|
|
|
|
for(it = offlineChat.begin(); it != offlineChat.end(); it++) {
|
|
|
|
/* are they public? */
|
|
|
|
if ((it->chatflags & RS_CHAT_PRIVATE) == 0) {
|
|
|
|
/* this should not happen */
|
|
|
|
continue;
|
|
|
|
}
|
2010-09-04 10:23:30 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
savedOfflineChatNew.push_back(*it);
|
2010-09-04 10:23:30 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
if (std::find(savedOfflineChat.begin(), savedOfflineChat.end(), *it) != savedOfflineChat.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-09-04 10:23:30 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
QDateTime sendTime = QDateTime::fromTime_t(it->sendTime);
|
|
|
|
QDateTime recvTime = QDateTime::fromTime_t(it->recvTime);
|
|
|
|
QString message = QString::fromStdWString(it->msg);
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
ui.chatWidget->addChatMsg(false, name, sendTime, recvTime, message, ChatWidget::TYPE_OFFLINE);
|
|
|
|
}
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
savedOfflineChat = savedOfflineChatNew;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NOTIFY_TYPE_DEL:
|
|
|
|
{
|
|
|
|
if (manualDelete == false) {
|
|
|
|
QString name = QString::fromUtf8(rsPeers->getPeerName(rsPeers->getOwnId()).c_str());
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
// now show saved offline chat messages as sent
|
|
|
|
std::list<ChatInfo>::iterator it;
|
|
|
|
for(it = savedOfflineChat.begin(); it != savedOfflineChat.end(); ++it) {
|
|
|
|
QDateTime sendTime = QDateTime::fromTime_t(it->sendTime);
|
|
|
|
QDateTime recvTime = QDateTime::fromTime_t(it->recvTime);
|
|
|
|
QString message = QString::fromStdWString(it->msg);
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
ui.chatWidget->addChatMsg(false, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL);
|
|
|
|
}
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
savedOfflineChat.clear();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
ui.actionClearOfflineMessages->setEnabled(!savedOfflineChat.empty());
|
|
|
|
}
|
2011-11-27 16:04:10 -05:00
|
|
|
}
|
|
|
|
|
2009-01-30 14:52:47 -05:00
|
|
|
/**
|
|
|
|
Toggles the ToolBox on and off, changes toggle button text
|
|
|
|
*/
|
|
|
|
void PopupChatDialog::showAvatarFrame(bool show)
|
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
ui.avatarframe->setVisible(show);
|
|
|
|
ui.avatarFrameButton->setChecked(show);
|
2010-04-27 18:08:38 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
if (show) {
|
|
|
|
ui.avatarFrameButton->setToolTip(tr("Hide Avatar"));
|
|
|
|
ui.avatarFrameButton->setIcon(QIcon(":images/hide_toolbox_frame.png"));
|
|
|
|
} else {
|
|
|
|
ui.avatarFrameButton->setToolTip(tr("Show Avatar"));
|
|
|
|
ui.avatarFrameButton->setIcon(QIcon(":images/show_toolbox_frame.png"));
|
|
|
|
}
|
2010-04-27 18:08:38 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
PeerSettings->setShowAvatarFrame(getPeerId(), show);
|
2010-04-27 18:08:38 -04:00
|
|
|
}
|
2010-08-18 08:02:36 -04:00
|
|
|
|
2010-09-20 20:08:06 -04:00
|
|
|
void PopupChatDialog::clearOfflineMessages()
|
|
|
|
{
|
2012-01-17 15:36:36 -05:00
|
|
|
manualDelete = true;
|
|
|
|
rsMsgs->clearPrivateChatQueue(false, peerId);
|
|
|
|
manualDelete = false;
|
2011-04-09 18:52:52 -04:00
|
|
|
}
|
2012-03-10 19:22:25 -05:00
|
|
|
|
|
|
|
void PopupChatDialog::statusChanged(int status)
|
|
|
|
{
|
|
|
|
updateStatus(status);
|
|
|
|
}
|