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

File diff suppressed because it is too large Load Diff

View File

@ -21,139 +21,128 @@
#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
Q_OBJECT
public:
public:
QPixmap picture;
PopupChatDialog *getPrivateChat(std::string id, std::string name, uint chatflags);
QPixmap picture;
static MessengerWindow* getInstance();
static void releaseInstance();
static MessengerWindow* getInstance();
static void releaseInstance();
public slots:
/** Called when this dialog is to be displayed */
void show();
void updateMessengerDisplay() ;
void updatePeersAvatar(const QString& peer_id);
void updateAvatar();
void loadmystatusmessage();
void loadOwnStatus();
void checkAndSetIdle(int idleTime);
/** Called when this dialog is to be displayed */
void show();
void updateMessengerDisplay() ;
void updatePeersAvatar(const QString& peer_id);
void updateAvatar();
void loadmystatusmessage();
void loadOwnStatus();
void checkAndSetIdle(int idleTime);
LogoBar & getLogoBar() const;
LogoBar & getLogoBar() const;
protected:
void closeEvent (QCloseEvent * event);
/** Default Constructor */
MessengerWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
/** 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 );
/** Create the context popup menu and it's submenus */
void messengertreeWidgetCostumPopupMenu( QPoint point );
/** Add a new friend */
void addFriend();
/** Export friend */
void exportfriend();
/** Remove friend */
void removefriend();
/** start a chat with a friend **/
void chatfriend();
/** start Messages Composer **/
void sendMessage();
/** start to connect to a friend **/
void connectfriend();
/** show peers details for each friend **/
void configurefriend();
/** Add a new friend */
void addFriend();
/** Export friend */
void exportfriend();
/** Remove friend */
void removefriend();
/** start a chat with a friend **/
void chatfriend(QTreeWidgetItem *pPeer);
void chatfriendproxy();
/** start Messages Composer **/
void sendMessage();
/** start to connect to a friend **/
void connectfriend();
/** show peers details for each friend **/
void configurefriend();
/** Open Shared Manager **/
void openShareManager();
/** get own last stored Avatar**/
void getAvatar();
void changeAvatarClicked();
void savestatusmessage();
/** Open Shared Manager **/
void openShareManager();
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();
void filterRegExpChanged();
void clearFilter();
/** get own last stored Avatar**/
void getAvatar();
void changeAvatarClicked();
void savestatusmessage();
void on_actionSort_Peers_Descending_Order_activated();
void on_actionSort_Peers_Ascending_Order_activated();
void on_actionRoot_is_decorated_activated();
void displayMenu();
void filterRegExpChanged();
void clearFilter();
signals:
void friendsUpdated() ;
void startChat(QTreeWidgetItem* );
void friendsUpdated() ;
private:
static MessengerWindow *mv;
static MessengerWindow *mv;
/* Worker Functions */
/* (1) Update Display */
void processSettings(bool bLoad);
/* (2) Utility Fns */
QTreeWidgetItem *getCurrentPeer();
void savestatus();
void insertPeers();
// idle function
void setIdle(bool Idle);
bool isIdle;
const unsigned long maxTimeBeforeIdle;
void FilterItems();
bool FilterItem(QTreeWidgetItem *pItem, QString &sPattern);
/* Worker Functions */
/* (1) Update Display */
std::map<std::string, PopupChatDialog *> chatDialogs;
/* (2) Utility Fns */
QTreeWidgetItem *getCurrentPeer();
void savestatus();
void insertPeers();
// idle function
void setIdle(bool Idle);
bool isIdle;
const unsigned long maxTimeBeforeIdle;
class QLabel *iconLabel, *textLabel;
class QWidget *widget;
class QWidgetAction *widgetAction;
class QSpacerItem *spacerItem;
void FilterItems();
bool FilterItem(QTreeWidgetItem *pItem, QString &sPattern);
/** Defines the actions for the context menu */
QAction* chatAct;
QAction* sendMessageAct;
QAction* connectfriendAct;
QAction* configurefriendAct;
QAction* exportfriendAct;
QAction* removefriendAct;
class QLabel *iconLabel, *textLabel;
class QWidget *widget;
class QWidgetAction *widgetAction;
class QSpacerItem *spacerItem;
QTreeView *messengertreeWidget;
/** Defines the actions for the context menu */
QAction* chatAct;
QAction* sendMessageAct;
QAction* connectfriendAct;
QAction* configurefriendAct;
QAction* exportfriendAct;
QAction* removefriendAct;
LogoBar * _rsLogoBarmessenger;
QFont itemFont;
/** Qt Designer generated object */
Ui::MessengerWindow ui;
QTreeView *messengertreeWidget;
LogoBar * _rsLogoBarmessenger;
QFont itemFont;
/** Qt Designer generated object */
Ui::MessengerWindow ui;
};
#endif

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;
}
//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)
{
msgfriend();
}
}
chatfriend(getCurrentPeer());
}
void PeersDialog::chatfriend(QTreeWidgetItem *pPeer)
{
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 (!peer)
return;
if (!i)
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);
}
/* 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);
}
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();