MessengerWindow

- cleaned include files
- changed menu for set the tree is decorated
- new check for sort rows by state
- saved the state of sort order, hide offline, sort by state and decorated state

PopupChatWindow:
- when setting "Grab Focus when chat arrives" not checked, the new chat window is opened minimized and flashed in taskbar

reworked start private chat and message to friend from PeersDialog and MessengerWindow:
- moved method for starting a private chat from PeersDialog and MessengerWindow to PopupChatDialog
- moved method for sending a message to a friend from PeersDialog to MessageComposer
- removed signal startChat

fixed bug in MessengerWindow:
- when peer is not online and private chat is not available, the message was send to the wrong peer (the current peer in PeersDialog)


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3154 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-06-17 17:39:32 +00:00
parent 95c5c4b1a1
commit e282a55164
11 changed files with 764 additions and 770 deletions

View File

@ -31,6 +31,7 @@
#include "rshare.h"
#include "MessengerWindow.h"
#include "RsAutoUpdatePage.h"
#include "chat/PopupChatDialog.h"
#include "msgs/MessageComposer.h"
@ -41,7 +42,7 @@
#include "settings/rsharesettings.h"
#include "gui/connect/ConnectFriendWizard.h"
#include "PeersDialog.h"
#include "ShareManager.h"
#include <iostream>
@ -64,11 +65,47 @@
#define IMAGE_BUSY ":/images/im-user-busy.png"
#define IMAGE_INACTIVE ":/images/im-user-inactive.png"
#define COLUMN_COUNT 4
#define COLUMN_NAME 0
#define COLUMN_STATE 1
#define COLUMN_INFO 2
#define COLUMN_ID 3
/******
* #define MSG_DEBUG 1
*****/
MessengerWindow* MessengerWindow::mv = 0;
// quick and dirty for sorting, better use QTreeView and QSortFilterProxyModel
class MyMessengerTreeWidgetItem : public QTreeWidgetItem
{
public:
MyMessengerTreeWidgetItem(QTreeWidget *pWidget, int type) : QTreeWidgetItem(type)
{
m_pWidget = pWidget; // can't access the member "view"
}
bool operator<(const QTreeWidgetItem &other) const
{
int column = m_pWidget ? m_pWidget->sortColumn() : 0;
switch (column) {
case COLUMN_NAME:
{
const QVariant v1 = data(column, Qt::UserRole);
const QVariant v2 = other.data(column, Qt::UserRole);
return (v1.toString().compare (v2.toString(), Qt::CaseInsensitive) < 0);
}
}
// let the standard do the sort
return QTreeWidgetItem::operator<(other);
}
private:
QTreeWidget *m_pWidget; // the member "view" is private
};
MessengerWindow* MessengerWindow::getInstance()
{
if(mv == 0)
@ -94,12 +131,13 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
ui.setupUi(this);
connect( ui.messengertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messengertreeWidgetCostumPopupMenu( QPoint ) ) );
connect( ui.messengertreeWidget, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend()));
connect( ui.messengertreeWidget, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend(QTreeWidgetItem *)));
connect( ui.avatarButton, SIGNAL(clicked()), SLOT(getAvatar()));
connect( ui.shareButton, SIGNAL(clicked()), SLOT(openShareManager()));
connect( ui.addIMAccountButton, SIGNAL(clicked( bool ) ), this , SLOT( addFriend() ) );
connect( ui.actionHide_Offline_Friends, SIGNAL(triggered()), this, SLOT(insertPeers()));
connect( ui.actionSort_by_State, SIGNAL(triggered()), this, SLOT(insertPeers()));
connect(ui.clearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
connect(ui.messagelineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(savestatusmessage()));
@ -114,19 +152,19 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
ui.messengertreeWidget->header()->hide();
/* Set header resize modes and initial section sizes */
ui.messengertreeWidget->setColumnCount(4);
ui.messengertreeWidget->setColumnHidden ( 3, true);
ui.messengertreeWidget->setColumnHidden ( 2, true);
//ui.messengertreeWidget->sortItems( 0, Qt::AscendingOrder );
ui.messengertreeWidget->setColumnCount(COLUMN_COUNT);
ui.messengertreeWidget->setColumnHidden ( COLUMN_ID, true);
ui.messengertreeWidget->setColumnHidden ( COLUMN_INFO, true);
ui.messengertreeWidget->sortItems( COLUMN_NAME, Qt::AscendingOrder );
QHeaderView * _header = ui.messengertreeWidget->header () ;
_header->setResizeMode (0, QHeaderView::Stretch);
_header->setResizeMode (1, QHeaderView::Custom);
_header->setResizeMode (COLUMN_NAME, QHeaderView::Stretch);
_header->setResizeMode (COLUMN_STATE, QHeaderView::Custom);
_header->setStretchLastSection(false);
_header->resizeSection ( 0, 200 );
_header->resizeSection ( 1, 42 );
_header->resizeSection ( COLUMN_NAME, 200 );
_header->resizeSection ( COLUMN_STATE, 42 );
//LogoBar
_rsLogoBarmessenger = NULL;
@ -139,6 +177,11 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
itemFont = QFont("ARIAL", 10);
itemFont.setBold(true);
displayMenu();
// load settings
processSettings(true);
isIdle = false;
loadOwnStatus(); // hack; placed in constructor to preempt sendstatus, so status loaded from file
insertPeers();
@ -147,7 +190,6 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
ui.clearButton->hide();
displayMenu();
updateMessengerDisplay();
/* Hide platform specific features */
@ -155,6 +197,51 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
#endif
}
MessengerWindow::~MessengerWindow ()
{
// save settings
processSettings(false);
}
void MessengerWindow::processSettings(bool bLoad)
{
QHeaderView *header = ui.messengertreeWidget->header ();
Settings->beginGroup(_name);
if (bLoad) {
// load settings
// state of messenger tree
header->restoreState(Settings->value("MessengerTree").toByteArray());
// state of actionHide_Offline_Friends
ui.actionHide_Offline_Friends->setChecked(Settings->value("hideOfflineFriends", false).toBool());
// state of actionSort_by_State
ui.actionSort_by_State->setChecked(Settings->value("sortByState", false).toBool());
// state of actionRoot_is_decorated
ui.actionRoot_is_decorated->setChecked(Settings->value("rootIsDecorated", true).toBool());
on_actionRoot_is_decorated_activated();
} else {
// save settings
// state of messenger tree
Settings->setValue("MessengerTree", header->saveState());
// state of actionSort_by_State
Settings->setValue("sortByState", ui.actionSort_by_State->isChecked());
// state of actionHide_Offline_Friends
Settings->setValue("hideOfflineFriends", ui.actionHide_Offline_Friends->isChecked());
// state of actionRoot_is_decorated
Settings->setValue("rootIsDecorated", ui.actionRoot_is_decorated->isChecked());
}
Settings->endGroup();
}
void MessengerWindow::messengertreeWidgetCostumPopupMenu( QPoint point )
{
@ -174,7 +261,7 @@ void MessengerWindow::messengertreeWidgetCostumPopupMenu( QPoint point )
connect( collapseAll , SIGNAL( triggered() ), ui.messengertreeWidget, SLOT(collapseAll()) );
chatAct = new QAction(QIcon(IMAGE_CHAT), tr( "Chat" ), this );
connect( chatAct , SIGNAL( triggered() ), this, SLOT( chatfriend() ) );
connect( chatAct , SIGNAL( triggered() ), this, SLOT( chatfriendproxy() ) );
sendMessageAct = new QAction(QIcon(IMAGE_MSG), tr( "Message Friend" ), this );
connect( sendMessageAct , SIGNAL( triggered() ), this, SLOT( sendMessage() ) );
@ -268,7 +355,6 @@ void MessengerWindow::insertPeers()
{
std::list<std::string> gpgFriends;
std::list<std::string>::iterator it;
std::list<StatusInfo> statusInfo;
rsStatus->getStatus(statusInfo);
@ -294,10 +380,12 @@ void MessengerWindow::insertPeers()
/* get a link to the table */
QTreeWidget *peertreeWidget = ui.messengertreeWidget;
bool bSortState = ui.actionSort_by_State->isChecked();
//remove items that are not fiends anymore
int index = 0;
while (index < peertreeWidget->topLevelItemCount()) {
std::string gpg_widget_id = (peertreeWidget->topLevelItem(index))->text(3).toStdString();
std::string gpg_widget_id = (peertreeWidget->topLevelItem(index))->text(COLUMN_ID).toStdString();
std::list<std::string>::iterator gpgfriendIt;
bool found = false;
for (gpgfriendIt = gpgFriends.begin(); gpgfriendIt != gpgFriends.end(); gpgfriendIt++) {
@ -313,7 +401,6 @@ void MessengerWindow::insertPeers()
}
}
//add the gpg friends
for(it = gpgFriends.begin(); it != gpgFriends.end(); it++) {
// if (*it == rsPeers->getGPGOwnId()) {
@ -321,13 +408,10 @@ void MessengerWindow::insertPeers()
// }
/* make a widget per friend */
QTreeWidgetItem *gpg_item;
QList<QTreeWidgetItem *> list = peertreeWidget->findItems(QString::fromStdString(*it), Qt::MatchExactly, 3);
QTreeWidgetItem *gpg_item = NULL;
QList<QTreeWidgetItem *> list = peertreeWidget->findItems(QString::fromStdString(*it), Qt::MatchExactly, COLUMN_ID);
if (list.size() == 1) {
gpg_item = list.front();
} else {
gpg_item = new QTreeWidgetItem(0); //set type to 0 for custom popup menu
gpg_item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
}
RsPeerDetails detail;
@ -338,20 +422,22 @@ void MessengerWindow::insertPeers()
continue;
}
//use to mark item as updated
gpg_item->setData(0, Qt::UserRole, true);
if (gpg_item == NULL) {
gpg_item = new MyMessengerTreeWidgetItem(peertreeWidget, 0); //set type to 0 for custom popup menu
gpg_item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
}
gpg_item -> setTextAlignment(0, Qt::AlignLeft | Qt::AlignVCenter );
gpg_item -> setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter );
gpg_item -> setSizeHint(0, QSize( 27,27 ) );
gpg_item -> setSizeHint(COLUMN_NAME, QSize( 27,27 ) );
/* not displayed, used to find back the item */
gpg_item -> setText(3, QString::fromStdString(detail.id));
gpg_item -> setText(COLUMN_ID, QString::fromStdString(detail.id));
//remove items that are not friends anymore
int childIndex = 0;
while (childIndex < gpg_item->childCount()) {
std::string ssl_id = (gpg_item->child(childIndex))->text(3).toStdString();
std::string ssl_id = (gpg_item->child(childIndex))->text(COLUMN_ID).toStdString();
if (!rsPeers->isFriend(ssl_id)) {
delete (gpg_item->takeChild(childIndex));
} else {
@ -370,7 +456,7 @@ void MessengerWindow::insertPeers()
//find the corresponding sslItem child item of the gpg item
bool newChild = true;
for (int childIndex = 0; childIndex < gpg_item->childCount(); childIndex++) {
if (gpg_item->child(childIndex)->text(3).toStdString() == *sslIt) {
if (gpg_item->child(childIndex)->text(COLUMN_ID).toStdString() == *sslIt) {
sslItem = gpg_item->child(childIndex);
newChild = false;
break;
@ -388,24 +474,23 @@ void MessengerWindow::insertPeers()
}
if (sslItem == NULL) {
sslItem = new QTreeWidgetItem(1); //set type to 1 for custom popup menu
sslItem = new MyMessengerTreeWidgetItem(peertreeWidget, 1); //set type to 1 for custom popup menu
}
/* not displayed, used to find back the item */
sslItem -> setText(3, QString::fromStdString(sslDetail.id));
if (rsMsgs->getCustomStateString(sslDetail.id) != "") {
sslItem -> setText( 0, tr("location : ") + QString::fromStdString(sslDetail.location) + " " + QString::fromStdString(sslDetail.autoconnect) );
sslItem -> setToolTip( 0, tr("location : ") + QString::fromStdString(sslDetail.location) + tr(" - ") + QString::fromStdString(rsMsgs->getCustomStateString(sslDetail.id)));
gpg_item -> setText(0, QString::fromStdString(detail.name) + tr("\n") + QString::fromStdString(rsMsgs->getCustomStateString(sslDetail.id)));
sslItem -> setText(COLUMN_ID, QString::fromStdString(sslDetail.id));
QString sCustomString = QString::fromStdString(rsMsgs->getCustomStateString(sslDetail.id));
if (sCustomString != "") {
sslItem -> setText( COLUMN_NAME, tr("location : ") + QString::fromStdString(sslDetail.location) + " " + QString::fromStdString(sslDetail.autoconnect) );
sslItem -> setToolTip( COLUMN_NAME, tr("location : ") + QString::fromStdString(sslDetail.location) + tr(" - ") + sCustomString);
gpg_item -> setText(COLUMN_NAME, QString::fromStdString(detail.name) + tr("\n") + sCustomString);
} else {
sslItem -> setText( 0, tr("location : ") + QString::fromStdString(sslDetail.location) + " " + QString::fromStdString(sslDetail.autoconnect));
sslItem -> setToolTip( 0, tr("location : ") + QString::fromStdString(sslDetail.location));
gpg_item -> setText(0, QString::fromStdString(detail.name) + tr("\n") + QString::fromStdString(sslDetail.location));
sslItem -> setText( COLUMN_NAME, tr("location : ") + QString::fromStdString(sslDetail.location) + " " + QString::fromStdString(sslDetail.autoconnect));
sslItem -> setToolTip( COLUMN_NAME, tr("location : ") + QString::fromStdString(sslDetail.location));
gpg_item -> setText(COLUMN_NAME, QString::fromStdString(detail.name) + tr("\n") + QString::fromStdString(sslDetail.location));
}
/* not displayed, used to find back the item */
//sslItem -> setText(1, QString::fromStdString(sslDetail.autoconnect));
@ -415,10 +500,10 @@ void MessengerWindow::insertPeers()
gpg_connected = true;
/* change color and icon */
sslItem -> setIcon(0,(QIcon(":/images/connect_established.png")));
sslItem -> setIcon(COLUMN_NAME,(QIcon(":/images/connect_established.png")));
QFont font;
font.setBold(true);
for(i = 0; i < 3; i++) {
for(i = 0; i < COLUMN_COUNT; i++) {
sslItem -> setTextColor(i,(Qt::darkBlue));
sslItem -> setFont(i,font);
}
@ -428,21 +513,21 @@ void MessengerWindow::insertPeers()
QFont font;
font.setBold(true);
for(i = 0; i < 3; i++) {
for(i = 0; i < COLUMN_COUNT; i++) {
sslItem -> setTextColor(i,(Qt::black));
sslItem -> setFont(i,font);
}
} else {
sslItem->setHidden(ui.actionHide_Offline_Friends->isChecked());
if (sslDetail.autoconnect !="Offline") {
sslItem -> setIcon(0, (QIcon(":/images/connect_creating.png")));
sslItem -> setIcon(COLUMN_NAME, (QIcon(":/images/connect_creating.png")));
} else {
sslItem -> setIcon(0, (QIcon(":/images/connect_no.png")));
sslItem -> setIcon(COLUMN_NAME, (QIcon(":/images/connect_no.png")));
}
QFont font;
font.setBold(false);
for(i = 0; i < 3; i++) {
for(i = 0; i < COLUMN_COUNT; i++) {
sslItem -> setTextColor(i,(Qt::black));
sslItem -> setFont(i,font);
}
@ -458,11 +543,10 @@ void MessengerWindow::insertPeers()
}
}
int i = 0;
if (gpg_connected) {
gpg_item->setHidden(false);
//gpg_item -> setText(1, tr("Online")); // set to online regardless on update
//gpg_item -> setText(COLUMN_STATE, tr("Online")); // set to online regardless on update
std::list<StatusInfo>::iterator it = statusInfo.begin();
@ -479,7 +563,7 @@ void MessengerWindow::insertPeers()
std::string status;
rsStatus->getStatusString(it->status, status);
gpg_item -> setText(1, QString::fromStdString(status));
gpg_item -> setText(COLUMN_STATE, QString::fromStdString(status));
QFont font;
font.setBold(true);
@ -489,7 +573,6 @@ void MessengerWindow::insertPeers()
rsMsgs->getAvatarData(it->id ,data,size);
if(size != 0){
QPixmap avatar ;
avatar.loadFromData(data,size,"PNG") ;
QIcon avatar_icon(avatar);
@ -497,49 +580,49 @@ void MessengerWindow::insertPeers()
gpg_item-> setIcon(1, avatar_icon);
delete[] data;
}else
{
gpg_item -> setIcon(1,(QIcon(":/images/no_avatar_70.png")));
} else {
gpg_item -> setIcon(COLUMN_STATE,(QIcon(":/images/no_avatar_70.png")));
}
if(it->status == RS_STATUS_INACTIVE)
{
gpg_item -> setIcon(0,(QIcon(IMAGE_INACTIVE)));
gpg_item -> setToolTip(0, tr("Peer Idle"));
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_INACTIVE)));
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Idle"));
gpg_item->setData(COLUMN_NAME, Qt::UserRole, BuildStateSortString(bSortState, gpg_item->text(COLUMN_NAME), PEER_STATE_INACTIVE));
for(i = 0; i < 3; i++) {
for(i = 0; i < COLUMN_COUNT; i++) {
gpg_item -> setTextColor(i,(Qt::gray));
gpg_item -> setFont(i,font);
}
}
else
if(it->status == RS_STATUS_ONLINE)
else if(it->status == RS_STATUS_ONLINE)
{
gpg_item -> setIcon(0,(QIcon(IMAGE_ONLINE)));
gpg_item -> setToolTip(0, tr("Peer Online"));
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_ONLINE)));
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Online"));
gpg_item->setData(COLUMN_NAME, Qt::UserRole, BuildStateSortString(bSortState, gpg_item->text(COLUMN_NAME), PEER_STATE_ONLINE));
for(i = 0; i < 3; i++) {
for(i = 0; i < COLUMN_COUNT; i++) {
gpg_item -> setTextColor(i,(Qt::darkBlue));
gpg_item -> setFont(i,font);
}
}
else
if(it->status == RS_STATUS_AWAY)
else if(it->status == RS_STATUS_AWAY)
{
gpg_item -> setIcon(0,(QIcon(IMAGE_AWAY)));
gpg_item -> setToolTip(0, tr("Peer Away"));
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_AWAY)));
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Away"));
gpg_item->setData(COLUMN_NAME, Qt::UserRole, BuildStateSortString(bSortState, gpg_item->text(COLUMN_NAME), PEER_STATE_AWAY));
for(i = 0; i < 3; i++) {
for(i = 0; i < COLUMN_COUNT; i++) {
gpg_item -> setTextColor(i,(Qt::gray));
gpg_item -> setFont(i,font);
}
}
else
if(it->status == RS_STATUS_BUSY)
else if(it->status == RS_STATUS_BUSY)
{
gpg_item -> setIcon(0,(QIcon(IMAGE_BUSY)));
gpg_item -> setToolTip(0, tr("Peer Busy"));
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_BUSY)));
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Busy"));
gpg_item->setData(COLUMN_NAME, Qt::UserRole, BuildStateSortString(bSortState, gpg_item->text(COLUMN_NAME), PEER_STATE_BUSY));
for(i = 0; i < 3; i++) {
for(i = 0; i < COLUMN_COUNT; i++) {
gpg_item -> setTextColor(i,(Qt::gray));
gpg_item -> setFont(i,font);
}
@ -548,25 +631,25 @@ void MessengerWindow::insertPeers()
}
}
}
} else if (gpg_online) {
gpg_item->setHidden(ui.actionHide_Offline_Friends->isChecked());
gpg_item -> setIcon(0,(QIcon(IMAGE_AVAIBLE)));
//gpg_item -> setText(1, tr("Available"));
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_AVAIBLE)));
gpg_item->setData(COLUMN_NAME, Qt::UserRole, BuildStateSortString(bSortState, gpg_item->text(COLUMN_NAME), PEER_STATE_ONLINE));
//gpg_item -> setText(COLUMN_STATE, tr("Available"));
QFont font;
font.setBold(true);
for(i = 0; i < 3; i++) {
for(i = 0; i < COLUMN_COUNT; i++) {
gpg_item -> setTextColor(i,(Qt::black));
gpg_item -> setFont(i,font);
}
} else {
gpg_item->setHidden(ui.actionHide_Offline_Friends->isChecked());
gpg_item -> setIcon(0,(QIcon(IMAGE_OFFLINE)));
//gpg_item -> setText(1, tr("Offline"));
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_OFFLINE)));
gpg_item->setData(COLUMN_NAME, Qt::UserRole, BuildStateSortString(bSortState, gpg_item->text(COLUMN_NAME), PEER_STATE_OFFLINE));
//gpg_item -> setText(COLUMN_STATE, tr("Offline"));
QFont font;
font.setBold(false);
for(i = 0; i < 3; i++) {
for(i = 0; i < COLUMN_COUNT; i++) {
gpg_item -> setTextColor(i,(Qt::black));
gpg_item -> setFont(i,font);
}
@ -584,7 +667,7 @@ void MessengerWindow::insertPeers()
/* Utility Fns */
std::string getPeersRsCertId(QTreeWidgetItem *i)
{
std::string id = (i -> text(3)).toStdString();
std::string id = (i -> text(COLUMN_ID)).toStdString();
return id;
}
@ -631,17 +714,20 @@ void MessengerWindow::exportfriend()
}
void MessengerWindow::chatfriend()
void MessengerWindow::chatfriendproxy()
{
QTreeWidgetItem *i = getCurrentPeer();
if (!i)
return;
emit startChat(i);
chatfriend(getCurrentPeer());
}
void MessengerWindow::chatfriend(QTreeWidgetItem *pPeer)
{
if (pPeer == NULL) {
return;
}
std::string id = (pPeer->text(COLUMN_ID)).toStdString();
PopupChatDialog::chatFriend(id);
}
QTreeWidgetItem *MessengerWindow::getCurrentPeer()
{
@ -723,7 +809,7 @@ void MessengerWindow::connectfriend()
if (rsPeers)
{
rsPeers->connectAttempt(getPeersRsCertId(c));
c -> setIcon(0,(QIcon(IMAGE_CONNECT2)));
c -> setIcon(COLUMN_NAME,(QIcon(IMAGE_CONNECT2)));
}
}
@ -737,84 +823,12 @@ void MessengerWindow::updatePeersAvatar(const QString& peer_id)
{
std::cerr << "PeersDialog: Got notified of new avatar for peer " << peer_id.toStdString() << std::endl ;
PopupChatDialog *pcd = getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0);
PopupChatDialog *pcd = PopupChatDialog::getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0);
pcd->updatePeerAvatar(peer_id.toStdString());
}
//============================================================================
PopupChatDialog *
MessengerWindow::getPrivateChat(std::string id, std::string name, uint chatflags)
{
/* see if it exists already */
PopupChatDialog *popupchatdialog = NULL;
bool show = false;
if (chatflags & RS_CHAT_REOPEN)
{
show = true;
std::cerr << "reopen flag so: enable SHOW popupchatdialog()";
std::cerr << std::endl;
}
std::map<std::string, PopupChatDialog *>::iterator it;
if (chatDialogs.end() != (it = chatDialogs.find(id)))
{
/* exists already */
popupchatdialog = it->second;
}
else
{
popupchatdialog = new PopupChatDialog(id, name);
chatDialogs[id] = popupchatdialog;
if (chatflags & RS_CHAT_OPEN_NEW)
{
std::cerr << "new chat so: enable SHOW popupchatdialog()";
std::cerr << std::endl;
show = true;
}
}
if (show)
{
std::cerr << "SHOWING popupchatdialog()";
std::cerr << std::endl;
popupchatdialog->show();
}
/* now only do these if the window is visible */
if (popupchatdialog->isVisible())
{
if (chatflags & RS_CHAT_FOCUS)
{
std::cerr << "focus chat flag so: GETFOCUS popupchatdialog()";
std::cerr << std::endl;
popupchatdialog->getfocus();
}
else
{
std::cerr << "no focus chat flag so: FLASH popupchatdialog()";
std::cerr << std::endl;
popupchatdialog->flash();
}
}
else
{
std::cerr << "not visible ... so leave popupchatdialog()";
std::cerr << std::endl;
}
return popupchatdialog;
}
//============================================================================
/** Overloads the default show */
void MessengerWindow::show()
@ -846,35 +860,13 @@ void MessengerWindow::openShareManager()
void MessengerWindow::sendMessage()
{
#ifdef MESSENGERWINDOW_DEBUG
std::cerr << "SharedFilesDialog::sendMessage()" << std::endl;
#endif
QTreeWidgetItem *peer = getCurrentPeer();
QTreeWidgetItem *i = getCurrentPeer();
if (!i)
if (!peer)
return;
std::string status = (i -> text(1)).toStdString();
std::string name = (i -> text(2)).toStdString();
std::string id = (i -> text(3)).toStdString();
rsicontrol -> ClearInMsg();
rsicontrol -> SetInMsg(id, true);
std::list<std::string> sslIds;
rsPeers->getSSLChildListOfGPGId(id, sslIds);
for (std::list<std::string>::iterator it = sslIds.begin(); it != sslIds.end(); it++) {
//put all sslChilds in message list
rsicontrol -> SetInMsg(*it, true);
}
/* create a message */
MessageComposer *nMsgDialog = new MessageComposer();
nMsgDialog->newMsg();
nMsgDialog->show();
/* window will destroy itself! */
std::string id = (peer->text(COLUMN_ID)).toStdString();
MessageComposer::msgFriend(id);
}
LogoBar & MessengerWindow::getLogoBar() const {
@ -946,22 +938,17 @@ void MessengerWindow::savestatusmessage()
void MessengerWindow::on_actionSort_Peers_Descending_Order_activated()
{
ui.messengertreeWidget->sortItems ( 0, Qt::DescendingOrder );
ui.messengertreeWidget->sortItems ( COLUMN_NAME, Qt::DescendingOrder );
}
void MessengerWindow::on_actionSort_Peers_Ascending_Order_activated()
{
ui.messengertreeWidget->sortItems ( 0, Qt::AscendingOrder );
ui.messengertreeWidget->sortItems ( COLUMN_NAME, Qt::AscendingOrder );
}
void MessengerWindow::on_actionRoot_is_decorated_activated()
{
ui.messengertreeWidget->setRootIsDecorated(true);
}
void MessengerWindow::on_actionRoot_isnot_decorated_activated()
{
ui.messengertreeWidget->setRootIsDecorated(false);
ui.messengertreeWidget->setRootIsDecorated(ui.actionRoot_is_decorated->isChecked());
}
void MessengerWindow::displayMenu()
@ -969,15 +956,11 @@ void MessengerWindow::displayMenu()
QMenu *lookmenu = new QMenu();
lookmenu->addAction(ui.actionSort_Peers_Descending_Order);
lookmenu->addAction(ui.actionSort_Peers_Ascending_Order);
lookmenu->addAction(ui.actionSort_by_State);
lookmenu->addAction(ui.actionHide_Offline_Friends);
QMenu *viewMenu = new QMenu( tr("View"), this );
viewMenu->addAction(ui.actionRoot_is_decorated);
viewMenu->addAction(ui.actionRoot_isnot_decorated);
lookmenu->addMenu( viewMenu);
lookmenu->addAction(ui.actionRoot_is_decorated);
ui.displaypushButton->setMenu(lookmenu);
}
/** Load own status Online,Away,Busy **/

View File

@ -21,35 +21,26 @@
#ifndef _MESSENGERWINDOW_H
#define _MESSENGERWINDOW_H
#include <QFileDialog>
#include "mainpage.h"
#include "ui_MessengerWindow.h"
#include <gui/common/rwindow.h>
#include "chat/PopupChatDialog.h"
#include "RsAutoUpdatePage.h"
class LogoBar;
class PeersDialog;
class PopupChatDialog;
class MessengerWindow : public RWindow
{
Q_OBJECT
public:
PopupChatDialog *getPrivateChat(std::string id, std::string name, uint chatflags);
QPixmap picture;
static MessengerWindow* getInstance();
static void releaseInstance();
public slots:
/** Called when this dialog is to be displayed */
void show();
void updateMessengerDisplay() ;
@ -62,13 +53,14 @@ public slots:
LogoBar & getLogoBar() const;
protected:
void closeEvent (QCloseEvent * event);
/** Default Constructor */
MessengerWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default Destructor */
~MessengerWindow();
void closeEvent (QCloseEvent * event);
private slots:
/** Create the context popup menu and it's submenus */
void messengertreeWidgetCostumPopupMenu( QPoint point );
@ -79,7 +71,8 @@ private slots:
/** Remove friend */
void removefriend();
/** start a chat with a friend **/
void chatfriend();
void chatfriend(QTreeWidgetItem *pPeer);
void chatfriendproxy();
/** start Messages Composer **/
void sendMessage();
/** start to connect to a friend **/
@ -97,12 +90,9 @@ private slots:
void savestatusmessage();
void on_actionSort_Peers_Descending_Order_activated();
void on_actionSort_Peers_Ascending_Order_activated();
void on_actionRoot_is_decorated_activated();
void on_actionRoot_isnot_decorated_activated();
void displayMenu();
@ -111,11 +101,12 @@ private slots:
signals:
void friendsUpdated() ;
void startChat(QTreeWidgetItem* );
private:
static MessengerWindow *mv;
void processSettings(bool bLoad);
/* Worker Functions */
/* (1) Update Display */
@ -131,8 +122,6 @@ private:
void FilterItems();
bool FilterItem(QTreeWidgetItem *pItem, QString &sPattern);
std::map<std::string, PopupChatDialog *> chatDialogs;
class QLabel *iconLabel, *textLabel;
class QWidget *widget;
class QWidgetAction *widgetAction;

View File

@ -441,6 +441,9 @@ border: 1px solid #CCCCCC;
<property name="indentation">
<number>22</number>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="columnCount">
<number>0</number>
</property>
@ -489,6 +492,9 @@ border: 1px solid #CCCCCC;
</property>
</action>
<action name="actionRoot_is_decorated">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Set root is Decorated</string>
</property>
@ -496,11 +502,6 @@ border: 1px solid #CCCCCC;
<string>Set Root Decorated</string>
</property>
</action>
<action name="actionRoot_isnot_decorated">
<property name="text">
<string>Set Root is not Decorated</string>
</property>
</action>
<action name="actionHide_Offline_Friends">
<property name="checkable">
<bool>true</bool>
@ -509,6 +510,14 @@ border: 1px solid #CCCCCC;
<string>Hide Offline Friends</string>
</property>
</action>
<action name="actionSort_by_State">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Sort by State</string>
</property>
</action>
</widget>
<resources>
<include location="images.qrc"/>

View File

@ -77,24 +77,15 @@
#define COLUMN_INFO 2
#define COLUMN_ID 3
// states for sorting (equal values are possible)
// used in BuildSortString - state + name
#define PEER_STATE_ONLINE 1
#define PEER_STATE_AWAY 2
#define PEER_STATE_BUSY 3
#define PEER_STATE_AVAILABLE 4
#define PEER_STATE_INACTIVE 5
#define PEER_STATE_OFFLINE 6
/******
* #define PEERS_DEBUG 1
*****/
// quick and dirty for sorting, better use QTreeView and QSortFilterProxyModel
class MyTreeWidgetItem : public QTreeWidgetItem
class MyPeerTreeWidgetItem : public QTreeWidgetItem
{
public:
MyTreeWidgetItem(QTreeWidget *pWidget, int type) : QTreeWidgetItem(type)
MyPeerTreeWidgetItem(QTreeWidget *pWidget, int type) : QTreeWidgetItem(type)
{
m_pWidget = pWidget; // can't access the member "view"
}
@ -142,7 +133,6 @@ PeersDialog::PeersDialog(QWidget *parent)
connect( ui.peertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( peertreeWidgetCostumPopupMenu( QPoint ) ) );
connect( ui.peertreeWidget, SIGNAL( itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend(QTreeWidgetItem *)));
connect( this , SIGNAL( startChat( QTreeWidgetItem *) ), this, SLOT(chatfriend(QTreeWidgetItem *)));
connect( ui.avatartoolButton, SIGNAL(clicked()), SLOT(getAvatar()));
connect( ui.mypersonalstatuslabel, SIGNAL(clicked()), SLOT(statusmessage()));
@ -263,12 +253,6 @@ PeersDialog::~PeersDialog ()
// save settings
processSettings(false);
std::map<std::string, PopupChatDialog *>::iterator it;
for (it = chatDialogs.begin(); it != chatDialogs.end(); it++) {
if (it->second) {
delete (it->second);
}
}
delete smWidget;
}
@ -437,11 +421,6 @@ void PeersDialog::updateDisplay()
insertPeers() ;
}
static QString BuildSortString(QTreeWidgetItem *pItem, int nState)
{
return QString ("%1").arg(nState) + " " + pItem->text(COLUMN_NAME);
}
/* get the list of peers from the RsIface. */
void PeersDialog::insertPeers()
{
@ -520,7 +499,7 @@ void PeersDialog::insertPeers()
bool bNew = false;
if (gpg_item == NULL) {
gpg_item = new MyTreeWidgetItem(peertreeWidget, 0); //set type to 0 for custom popup menu
gpg_item = new MyPeerTreeWidgetItem(peertreeWidget, 0); //set type to 0 for custom popup menu
gpg_item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
bNew = true;
}
@ -577,7 +556,7 @@ void PeersDialog::insertPeers()
}
if (newChild) {
sslItem = new MyTreeWidgetItem(peertreeWidget, 1); //set type to 1 for custom popup menu
sslItem = new MyPeerTreeWidgetItem(peertreeWidget, 1); //set type to 1 for custom popup menu
}
/* not displayed, used to find back the item */
@ -652,7 +631,7 @@ void PeersDialog::insertPeers()
gpg_item->setHidden(false);
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_ONLINE)));
gpg_item -> setText(COLUMN_STATE, tr("Online"));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildSortString(gpg_item, PEER_STATE_ONLINE));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildStateSortString(true, gpg_item->text(COLUMN_NAME), PEER_STATE_ONLINE));
std::list<StatusInfo>::iterator it;
for(it = statusInfo.begin(); it != statusInfo.end() ; it++) {
@ -676,7 +655,7 @@ void PeersDialog::insertPeers()
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_INACTIVE)));
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Idle"));
gpg_item -> setText(COLUMN_STATE, tr("Idle"));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildSortString(gpg_item, PEER_STATE_INACTIVE));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildStateSortString(true, gpg_item->text(COLUMN_NAME), PEER_STATE_INACTIVE));
for(i = 0; i < COLUMN_COUNT; i++) {
gpg_item -> setTextColor(i,(Qt::gray));
gpg_item -> setFont(i,font);
@ -687,7 +666,7 @@ void PeersDialog::insertPeers()
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_ONLINE)));
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Online"));
gpg_item -> setText(COLUMN_STATE, tr("Online"));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildSortString(gpg_item, PEER_STATE_ONLINE));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildStateSortString(true, gpg_item->text(COLUMN_NAME), PEER_STATE_ONLINE));
for(i = 0; i < COLUMN_COUNT; i++) {
gpg_item -> setTextColor(i,(Qt::darkBlue));
gpg_item -> setFont(i,font);
@ -698,7 +677,7 @@ void PeersDialog::insertPeers()
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_AWAY)));
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Away"));
gpg_item -> setText(COLUMN_STATE, tr("Away"));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildSortString(gpg_item, PEER_STATE_AWAY));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildStateSortString(true, gpg_item->text(COLUMN_NAME), PEER_STATE_AWAY));
for(i = 0; i < COLUMN_COUNT; i++) {
gpg_item -> setTextColor(i,(Qt::gray));
gpg_item -> setFont(i,font);
@ -709,7 +688,7 @@ void PeersDialog::insertPeers()
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_BUSY)));
gpg_item -> setToolTip(COLUMN_NAME, tr("Peer Busy"));
gpg_item -> setText(COLUMN_STATE, tr("Busy"));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildSortString(gpg_item, PEER_STATE_BUSY));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildStateSortString(true, gpg_item->text(COLUMN_NAME), PEER_STATE_BUSY));
for(i = 0; i < COLUMN_COUNT; i++) {
gpg_item -> setTextColor(i,(Qt::gray));
gpg_item -> setFont(i,font);
@ -722,7 +701,7 @@ void PeersDialog::insertPeers()
gpg_item->setHidden(bHideUnconnected);
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_AVAIBLE)));
gpg_item -> setText(COLUMN_STATE, tr("Available"));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildSortString(gpg_item, PEER_STATE_AVAILABLE));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildStateSortString(true, gpg_item->text(COLUMN_NAME), PEER_STATE_AVAILABLE));
QFont font;
font.setBold(true);
for(i = 0; i < COLUMN_COUNT; i++) {
@ -733,7 +712,7 @@ void PeersDialog::insertPeers()
gpg_item->setHidden(bHideUnconnected);
gpg_item -> setIcon(COLUMN_NAME,(QIcon(IMAGE_OFFLINE)));
gpg_item -> setText(COLUMN_STATE, tr("Offline"));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildSortString(gpg_item, PEER_STATE_OFFLINE));
gpg_item -> setData(COLUMN_STATE, Qt::UserRole, BuildStateSortString(true, gpg_item->text(COLUMN_NAME), PEER_STATE_OFFLINE));
QFont font;
font.setBold(false);
for(i = 0; i < COLUMN_COUNT; i++) {
@ -790,96 +769,32 @@ void PeersDialog::exportfriend()
}
void PeersDialog::chatfriendproxy(){
QTreeWidgetItem* i = getCurrentPeer();
if(!i)
return;
emit startChat(i);
}
void PeersDialog::chatfriend(QTreeWidgetItem* currPeer)
void PeersDialog::chatfriendproxy()
{
// QTreeWidgetItem *currPeer = getCurrentPeer();
if (!currPeer){
return;
chatfriend(getCurrentPeer());
}
//std::string name = (i -> text(2)).toStdString();
std::string id = (currPeer -> text(COLUMN_ID)).toStdString();
bool oneLocationConnected = false;
RsPeerDetails detail;
if (!rsPeers->getPeerDetails(id, detail)) {
return;
}
if (detail.isOnlyGPGdetail) {
//let's get the ssl child details, and open all the chat boxes
std::list<std::string> sslIds;
rsPeers->getSSLChildListOfGPGId(detail.gpg_id, sslIds);
for (std::list<std::string>::iterator it = sslIds.begin(); it != sslIds.end(); it++) {
RsPeerDetails sslDetails;
if (rsPeers->getPeerDetails(*it, sslDetails)) {
if (sslDetails.state & RS_PEER_STATE_CONNECTED) {
oneLocationConnected = true;
getPrivateChat(*it, sslDetails.name + " - " + sslDetails.location, RS_CHAT_REOPEN);
}
}
}
} else {
if (detail.state & RS_PEER_STATE_CONNECTED) {
oneLocationConnected = true;
getPrivateChat(id, detail.name + " - " + detail.location, RS_CHAT_REOPEN);
}
}
if (!oneLocationConnected) {
/* info dialog */
if ((QMessageBox::question(this, tr("Friend Not Online"),tr("Your Friend is offline \nDo you want to send them a Message instead"),QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes))== QMessageBox::Yes)
void PeersDialog::chatfriend(QTreeWidgetItem *pPeer)
{
msgfriend();
}
}
if (pPeer == NULL) {
return;
}
std::string id = (pPeer->text(COLUMN_ID)).toStdString();
PopupChatDialog::chatFriend(id);
}
void PeersDialog::msgfriend()
{
#ifdef PEERS_DEBUG
std::cerr << "SharedFilesDialog::msgfriend()" << std::endl;
#endif
QTreeWidgetItem *peer = getCurrentPeer();
QTreeWidgetItem *i = getCurrentPeer();
if (!i)
if (!peer)
return;
std::string id = (i -> text(COLUMN_ID)).toStdString();
rsicontrol -> ClearInMsg();
rsicontrol -> SetInMsg(id, true);
std::list<std::string> sslIds;
rsPeers->getSSLChildListOfGPGId(id, sslIds);
for (std::list<std::string>::iterator it = sslIds.begin(); it != sslIds.end(); it++) {
//put all sslChilds in message list
rsicontrol -> SetInMsg(*it, true);
std::string id = (peer->text(COLUMN_ID)).toStdString();
MessageComposer::msgFriend(id);
}
/* create a message */
MessageComposer *nMsgDialog = new MessageComposer();
nMsgDialog->newMsg();
nMsgDialog->show();
/* window will destroy itself! */
}
QTreeWidgetItem *PeersDialog::getCurrentPeer()
{
/* get the current, and extract the Id */
@ -1027,7 +942,7 @@ void PeersDialog::updatePeersAvatar(const QString& peer_id)
std::cerr << "PeersDialog: Got notified of new avatar for peer " << peer_id.toStdString() << std::endl ;
#endif
PopupChatDialog *pcd = getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0);
PopupChatDialog *pcd = PopupChatDialog::getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0);
pcd->updatePeerAvatar(peer_id.toStdString());
}
@ -1035,7 +950,7 @@ void PeersDialog::updatePeerStatusString(const QString& peer_id,const QString& s
{
if(is_private_chat)
{
PopupChatDialog *pcd = getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0);
PopupChatDialog *pcd = PopupChatDialog::getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0);
pcd->updateStatusString(status_string);
}
else
@ -1085,7 +1000,7 @@ void PeersDialog::insertChat()
/* are they private? */
if (it->chatflags & RS_CHAT_PRIVATE)
{
PopupChatDialog *pcd = getPrivateChat(it->rsid, it->name, chatflags);
PopupChatDialog *pcd = PopupChatDialog::getPrivateChat(it->rsid, it->name, chatflags);
pcd->addChatMsg(&(*it));
playsound();
QApplication::alert(pcd);
@ -1289,90 +1204,6 @@ void PeersDialog::toggleSendItem( QTreeWidgetItem *item, int col )
//============================================================================
PopupChatDialog *
PeersDialog::getPrivateChat(std::string id, std::string name, uint chatflags)
{
/* see if it exists already */
PopupChatDialog *popupchatdialog = NULL;
bool show = false;
if (chatflags & RS_CHAT_REOPEN)
{
show = true;
#ifdef PEERS_DEBUG
std::cerr << "reopen flag so: enable SHOW popupchatdialog()" << std::endl;
#endif
}
std::map<std::string, PopupChatDialog *>::iterator it;
if (chatDialogs.end() != (it = chatDialogs.find(id)))
{
/* exists already */
popupchatdialog = it->second;
}
else
{
popupchatdialog = new PopupChatDialog(id, name);
chatDialogs[id] = popupchatdialog;
if (chatflags & RS_CHAT_OPEN_NEW)
{
#ifdef PEERS_DEBUG
std::cerr << "new chat so: enable SHOW popupchatdialog()" << std::endl;
#endif
show = true;
}
}
if (show)
{
#ifdef PEERS_DEBUG
std::cerr << "SHOWING popupchatdialog()" << std::endl;
#endif
popupchatdialog->show();
}
/* now only do these if the window is visible */
if (popupchatdialog->isVisible())
{
if (chatflags & RS_CHAT_FOCUS)
{
#ifdef PEERS_DEBUG
std::cerr << "focus chat flag so: GETFOCUS popupchatdialog()" << std::endl;
#endif
popupchatdialog->getfocus();
}
else
{
#ifdef PEERS_DEBUG
std::cerr << "no focus chat flag so: FLASH popupchatdialog()" << std::endl;
#endif
popupchatdialog->flash();
}
}
else
{
#ifdef PEERS_DEBUG
std::cerr << "not visible ... so leave popupchatdialog()" << std::endl;
#endif
}
return popupchatdialog;
}
//============================================================================
void PeersDialog::clearOldChats()
{
/* nothing yet */
}
void PeersDialog::setColor()
{
@ -1623,8 +1454,7 @@ void PeersDialog::updateAvatar()
pix.loadFromData(data,size,"PNG") ;
ui.avatartoolButton->setIcon(pix); // writes image into ba in PNG format
for(std::map<std::string, PopupChatDialog *>::const_iterator it(chatDialogs.begin());it!=chatDialogs.end();++it)
it->second->updateAvatar() ;
PopupChatDialog::updateAllAvatars();
delete[] data ;
}

View File

@ -33,6 +33,17 @@
#include "im_history/IMHistoryKeeper.h"
// states for sorting (equal values are possible)
// used in BuildSortString - state + name
#define PEER_STATE_ONLINE 1
#define PEER_STATE_AWAY 2
#define PEER_STATE_BUSY 3
#define PEER_STATE_AVAILABLE 4
#define PEER_STATE_INACTIVE 5
#define PEER_STATE_OFFLINE 6
#define BuildStateSortString(bEnabled,sName,nState) bEnabled ? (QString ("%1").arg(nState) + " " + sName) : sName
class QFont;
class QAction;
class QTextEdit;
@ -49,9 +60,6 @@ public:
/** Default Destructor */
~PeersDialog ();
PopupChatDialog *getPrivateChat(std::string id, std::string name, uint chatflags);
void clearOldChats();
void loadEmoticonsgroupchat();
// void setChatDialog(ChatDialog *cd);
@ -146,7 +154,6 @@ private slots:
signals:
void friendsUpdated() ;
void notifyGroupChat(const QString&,const QString&) ;
void startChat(QTreeWidgetItem* );
private:
void processSettings(bool bLoad);
@ -192,8 +199,6 @@ private:
QHash<QString, QString> smileys;
QWidget *smWidget;
std::map<std::string, PopupChatDialog *> chatDialogs;
QFont mCurrentFont; /* how the text will come out */
/** Qt Designer generated object */

View File

@ -29,10 +29,12 @@
#include "rsiface/rspeers.h"
#include "rsiface/rsmsgs.h"
#include "rsiface/rsfiles.h"
#include "rsiface/rsnotify.h"
#include "gui/settings/rsharesettings.h"
#include "gui/feeds/AttachFileItem.h"
#include "gui/msgs/MessageComposer.h"
#include <time.h>
#define appDir QApplication::applicationDirPath()
@ -46,6 +48,8 @@
* #define CHAT_DEBUG 1
*****/
static std::map<std::string, PopupChatDialog *> chatDialogs;
/** Default constructor */
PopupChatDialog::PopupChatDialog(std::string id, std::string name,
QWidget *parent, Qt::WFlags flags)
@ -140,6 +144,145 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
updatePeerAvatar(id) ;
}
/*static*/ PopupChatDialog *PopupChatDialog::getPrivateChat(std::string id, std::string name, uint chatflags)
{
/* see if it exists already */
PopupChatDialog *popupchatdialog = NULL;
bool show = false;
if (chatflags & RS_CHAT_REOPEN)
{
show = true;
#ifdef PEERS_DEBUG
std::cerr << "reopen flag so: enable SHOW popupchatdialog()" << std::endl;
#endif
}
std::map<std::string, PopupChatDialog *>::iterator it;
if (chatDialogs.end() != (it = chatDialogs.find(id)))
{
/* exists already */
popupchatdialog = it->second;
}
else
{
popupchatdialog = new PopupChatDialog(id, name);
chatDialogs[id] = popupchatdialog;
if (chatflags & RS_CHAT_OPEN_NEW)
{
#ifdef PEERS_DEBUG
std::cerr << "new chat so: enable SHOW popupchatdialog()" << std::endl;
#endif
show = true;
}
}
if (show)
{
#ifdef PEERS_DEBUG
std::cerr << "SHOWING popupchatdialog()" << std::endl;
#endif
if (popupchatdialog->isVisible() == false) {
if (chatflags & RS_CHAT_FOCUS) {
popupchatdialog->show();
} else {
popupchatdialog->showMinimized();
}
}
}
/* now only do these if the window is visible */
if (popupchatdialog->isVisible())
{
if (chatflags & RS_CHAT_FOCUS)
{
#ifdef PEERS_DEBUG
std::cerr << "focus chat flag so: GETFOCUS popupchatdialog()" << std::endl;
#endif
popupchatdialog->getfocus();
}
else
{
#ifdef PEERS_DEBUG
std::cerr << "no focus chat flag so: FLASH popupchatdialog()" << std::endl;
#endif
popupchatdialog->flash();
}
}
else
{
#ifdef PEERS_DEBUG
std::cerr << "not visible ... so leave popupchatdialog()" << std::endl;
#endif
}
return popupchatdialog;
}
/*static*/ void PopupChatDialog::cleanupChat()
{
std::map<std::string, PopupChatDialog *>::iterator it;
for (it = chatDialogs.begin(); it != chatDialogs.end(); it++) {
if (it->second) {
delete (it->second);
}
}
chatDialogs.clear();
}
void PopupChatDialog::chatFriend(std::string id)
{
if (id.empty()){
return;
}
bool oneLocationConnected = false;
RsPeerDetails detail;
if (!rsPeers->getPeerDetails(id, detail)) {
return;
}
if (detail.isOnlyGPGdetail) {
//let's get the ssl child details, and open all the chat boxes
std::list<std::string> sslIds;
rsPeers->getSSLChildListOfGPGId(detail.gpg_id, sslIds);
for (std::list<std::string>::iterator it = sslIds.begin(); it != sslIds.end(); it++) {
RsPeerDetails sslDetails;
if (rsPeers->getPeerDetails(*it, sslDetails)) {
if (sslDetails.state & RS_PEER_STATE_CONNECTED) {
oneLocationConnected = true;
getPrivateChat(*it, sslDetails.name + " - " + sslDetails.location, RS_CHAT_REOPEN | RS_CHAT_FOCUS);
}
}
}
} else {
if (detail.state & RS_PEER_STATE_CONNECTED) {
oneLocationConnected = true;
getPrivateChat(id, detail.name + " - " + detail.location, RS_CHAT_REOPEN | RS_CHAT_FOCUS);
}
}
if (!oneLocationConnected) {
/* info dialog */
if ((QMessageBox::question(NULL, tr("Friend Not Online"),tr("Your Friend is offline \nDo you want to send them a Message instead"),QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes))== QMessageBox::Yes) {
MessageComposer::msgFriend(id);
}
}
}
/*static*/ void PopupChatDialog::updateAllAvatars()
{
for(std::map<std::string, PopupChatDialog *>::const_iterator it(chatDialogs.begin());it!=chatDialogs.end();++it)
it->second->updateAvatar() ;
}
void PopupChatDialog::pasteLink()
{
std::cerr << "In paste link" << std::endl ;

View File

@ -44,11 +44,10 @@ class PopupChatDialog : public QMainWindow
Q_OBJECT
public:
/** Default constructor */
PopupChatDialog(std::string id, std::string name,
QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default destructor */
~PopupChatDialog();
static PopupChatDialog *getPrivateChat(std::string id, std::string name, uint chatflags);
static void cleanupChat();
static void chatFriend(std::string id);
static void updateAllAvatars();
void updateChat();
void updatePeerAvatar(const std::string&);
@ -85,6 +84,12 @@ public slots:
protected:
/** Default constructor */
PopupChatDialog(std::string id, std::string name,
QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default destructor */
~PopupChatDialog();
void closeEvent (QCloseEvent * event);
virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dropEvent(QDropEvent *event);

View File

@ -66,8 +66,10 @@ signals:
* <b>topic</b>. */
void helpRequested(const QString &topic);
private:
protected:
QString _name; /**< Name associated with this window. */
private:
bool m_bSaveStateOnClose; // is set to true in restoreWindowState
};

View File

@ -197,6 +197,30 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
#endif
}
/*static*/ void MessageComposer::msgFriend(std::string id)
{
#ifdef PEERS_DEBUG
std::cerr << "MessageComposer::msgfriend()" << std::endl;
#endif
rsicontrol -> ClearInMsg();
rsicontrol -> SetInMsg(id, true);
std::list<std::string> sslIds;
rsPeers->getSSLChildListOfGPGId(id, sslIds);
for (std::list<std::string>::iterator it = sslIds.begin(); it != sslIds.end(); it++) {
//put all sslChilds in message list
rsicontrol -> SetInMsg(*it, true);
}
/* create a message */
MessageComposer *pMsgDialog = new MessageComposer();
pMsgDialog->newMsg();
pMsgDialog->show();
/* window will destroy itself! */
}
void MessageComposer::closeEvent (QCloseEvent * event)
{
bool bClose = true;

View File

@ -46,6 +46,8 @@ public:
MessageComposer(QWidget *parent = 0, Qt::WFlags flags = 0);
static void msgFriend(std::string id);
void newMsg(std::string msgId = "");
/* worker fns */

View File

@ -175,7 +175,6 @@ int main(int argc, char *argv[])
w->installGroupChatNotifier();
QObject::connect(w->messengerWindow,SIGNAL(startChat(QTreeWidgetItem* )),w->peersDialog,SLOT(chatfriend(QTreeWidgetItem* ))) ;
QObject::connect(w->idle, SIGNAL(secondsIdle(int)), w->messengerWindow, SLOT(checkAndSetIdle(int)));
/* only show window, if not startMinimized */
@ -194,6 +193,9 @@ int main(int argc, char *argv[])
int ti = rshare.exec();
delete w ;
/* cleanup */
PopupChatDialog::cleanupChat();
rsicontrol->rsGlobalShutDown();
Settings->sync();