Create the instance of MessengerWindow only when needed and delete it on close.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3301 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-07-18 11:43:39 +00:00
parent 8f5fe8bae2
commit d53a6c9d29
7 changed files with 87 additions and 56 deletions

View File

@ -154,8 +154,6 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
/* Create all the dialogs of which we only want one instance */ /* Create all the dialogs of which we only want one instance */
_bandwidthGraph = new BandwidthGraph(); _bandwidthGraph = new BandwidthGraph();
/*messengerWindow instance is created statically so that RsAutoUpdatePage can access it*/
messengerWindow = MessengerWindow::getInstance();
#ifdef UNFINISHED #ifdef UNFINISHED
applicationWindow = new ApplicationWindow(); applicationWindow = new ApplicationWindow();
applicationWindow->hide(); applicationWindow->hide();
@ -304,7 +302,6 @@ MainWindow::~MainWindow()
delete natstatus; delete natstatus;
delete ratesstatus; delete ratesstatus;
MessengerWindow::releaseInstance(); MessengerWindow::releaseInstance();
messengerWindow = NULL;
#ifdef UNFINISHED #ifdef UNFINISHED
delete applicationWindow; delete applicationWindow;
#endif #endif
@ -624,7 +621,7 @@ void MainWindow::showSettings()
/** Shows Messenger window */ /** Shows Messenger window */
void MainWindow::showMessengerWindow() void MainWindow::showMessengerWindow()
{ {
messengerWindow->show(); MessengerWindow::showYourself();
} }
@ -640,13 +637,11 @@ void MainWindow::showApplWindow()
* tray menu configuration. */ * tray menu configuration. */
void MainWindow::createActions() void MainWindow::createActions()
{ {
_settingsAct = new QAction(QIcon(IMAGE_PREFERENCES), tr("Options"), this); _settingsAct = new QAction(QIcon(IMAGE_PREFERENCES), tr("Options"), this);
connect(_settingsAct, SIGNAL(triggered()), this, SLOT(showSettings())); connect(_settingsAct, SIGNAL(triggered()), this, SLOT(showSettings()));
_bandwidthAct = new QAction(QIcon(IMAGE_BWGRAPH), tr("Bandwidth Graph"), this); _bandwidthAct = new QAction(QIcon(IMAGE_BWGRAPH), tr("Bandwidth Graph"), this);
connect(_bandwidthAct, SIGNAL(triggered()), connect(_bandwidthAct, SIGNAL(triggered()), _bandwidthGraph, SLOT(showWindow()));
_bandwidthGraph, SLOT(showWindow()));
_messengerwindowAct = new QAction(QIcon(IMAGE_RSM16), tr("Open Messenger"), this); _messengerwindowAct = new QAction(QIcon(IMAGE_RSM16), tr("Open Messenger"), this);
connect(_messengerwindowAct, SIGNAL(triggered()),this, SLOT(showMessengerWindow())); connect(_messengerwindowAct, SIGNAL(triggered()),this, SLOT(showMessengerWindow()));
@ -659,8 +654,6 @@ void MainWindow::createActions()
#endif #endif
_helpAct = new QAction(QIcon(IMG_HELP), tr("Help"), this); _helpAct = new QAction(QIcon(IMG_HELP), tr("Help"), this);
connect(_helpAct, SIGNAL(triggered()), this, SLOT(showHelpDialog())); connect(_helpAct, SIGNAL(triggered()), this, SLOT(showHelpDialog()));
} }
/** If the user attempts to quit the app, a check-warning is issued. This warning can be /** If the user attempts to quit the app, a check-warning is issued. This warning can be

View File

@ -111,7 +111,6 @@ public:
ChatDialog *chatDialog; ChatDialog *chatDialog;
MessagesDialog *messagesDialog; MessagesDialog *messagesDialog;
SharedFilesDialog *sharedfilesDialog; SharedFilesDialog *sharedfilesDialog;
MessengerWindow *messengerWindow;
ForumsDialog *forumsDialog; ForumsDialog *forumsDialog;
ChannelFeed *channelFeed; ChannelFeed *channelFeed;
Idle *idle; Idle *idle;

View File

@ -46,6 +46,7 @@
#include "RetroShareLink.h" #include "RetroShareLink.h"
#include "PeersDialog.h" #include "PeersDialog.h"
#include "ShareManager.h" #include "ShareManager.h"
#include "gui/notifyqt.h"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -81,7 +82,9 @@
/****** /******
* #define MSG_DEBUG 1 * #define MSG_DEBUG 1
*****/ *****/
MessengerWindow* MessengerWindow::mv = 0;
MessengerWindow* MessengerWindow::_instance = NULL;
static std::set<std::string> *expandedPeers = NULL;
// quick and dirty for sorting, better use QTreeView and QSortFilterProxyModel // quick and dirty for sorting, better use QTreeView and QSortFilterProxyModel
class MyMessengerTreeWidgetItem : public QTreeWidgetItem class MyMessengerTreeWidgetItem : public QTreeWidgetItem
@ -113,21 +116,31 @@ private:
QTreeWidget *m_pWidget; // the member "view" is private QTreeWidget *m_pWidget; // the member "view" is private
}; };
/*static*/ void MessengerWindow::showYourself ()
{
if (_instance == NULL) {
_instance = new MessengerWindow();
}
_instance->show();
_instance->activateWindow();
}
MessengerWindow* MessengerWindow::getInstance() MessengerWindow* MessengerWindow::getInstance()
{ {
if(mv == 0) return _instance;
{
mv = new MessengerWindow();
}
return mv;
} }
void MessengerWindow::releaseInstance() void MessengerWindow::releaseInstance()
{ {
if(mv != 0) if (_instance) {
{ delete _instance;
delete mv; }
} if (expandedPeers) {
/* delete saved expanded peers */
delete(expandedPeers);
expandedPeers = NULL;
}
} }
/** Constructor */ /** Constructor */
@ -137,6 +150,8 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); ui.setupUi(this);
setAttribute ( Qt::WA_DeleteOnClose, true );
connect( ui.messengertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messengertreeWidgetCostumPopupMenu( QPoint ) ) ); connect( ui.messengertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messengertreeWidgetCostumPopupMenu( QPoint ) ) );
connect( ui.messengertreeWidget, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend(QTreeWidgetItem *))); connect( ui.messengertreeWidget, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend(QTreeWidgetItem *)));
@ -151,11 +166,14 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
connect(ui.statuscomboBox, SIGNAL(activated(int)), this, SLOT(statusChanged(int))); connect(ui.statuscomboBox, SIGNAL(activated(int)), this, SLOT(statusChanged(int)));
connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged())); connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged()));
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateMessengerDisplay()));
connect(NotifyQt::getInstance(), SIGNAL(ownAvatarChanged()), this, SLOT(updateAvatar()));
connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage()));
QTimer *timer = new QTimer(this); QTimer *timer = new QTimer(this);
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateMessengerDisplay())); timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateMessengerDisplay()));
timer->start(1000); /* one second */ timer->start(1000); /* one second */
/* to hide the header */ /* to hide the header */
ui.messengertreeWidget->header()->hide(); ui.messengertreeWidget->header()->hide();
@ -169,7 +187,6 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
_header->setResizeMode (COLUMN_STATE, QHeaderView::Custom); _header->setResizeMode (COLUMN_STATE, QHeaderView::Custom);
_header->setStretchLastSection(false); _header->setStretchLastSection(false);
_header->resizeSection ( COLUMN_NAME, 200 ); _header->resizeSection ( COLUMN_NAME, 200 );
_header->resizeSection ( COLUMN_STATE, 42 ); _header->resizeSection ( COLUMN_STATE, 42 );
@ -215,6 +232,8 @@ MessengerWindow::~MessengerWindow ()
if (pMainWindow) { if (pMainWindow) {
pMainWindow->removeStatusObject(ui.statuscomboBox); pMainWindow->removeStatusObject(ui.statuscomboBox);
} }
_instance = NULL;
} }
void MessengerWindow::processSettings(bool bLoad) void MessengerWindow::processSettings(bool bLoad)
@ -260,11 +279,11 @@ void MessengerWindow::processSettings(bool bLoad)
void MessengerWindow::messengertreeWidgetCostumPopupMenu( QPoint point ) void MessengerWindow::messengertreeWidgetCostumPopupMenu( QPoint point )
{ {
QTreeWidgetItem *c = getCurrentPeer(); QTreeWidgetItem *c = getCurrentPeer();
if (!c) if (!c)
{ {
//no peer selected //no peer selected
return; return;
} }
QMenu contextMnu( this ); QMenu contextMnu( this );
@ -692,11 +711,22 @@ void MessengerWindow::insertPeers()
/* add gpg item to the list. If item is already in the list, it won't be duplicated thanks to Qt */ /* add gpg item to the list. If item is already in the list, it won't be duplicated thanks to Qt */
peertreeWidget->addTopLevelItem(gpg_item); peertreeWidget->addTopLevelItem(gpg_item);
if (expandedPeers && expandedPeers->find(detail.gpg_id) != expandedPeers->end()) {
/* we have information about expanded peers and the peer was expanded */
gpg_item->setExpanded(true);
}
} }
if (ui.filterPatternLineEdit->text().isEmpty() == false) { if (ui.filterPatternLineEdit->text().isEmpty() == false) {
FilterItems(); FilterItems();
} }
if (expandedPeers) {
/* we don't need the informations anymore */
delete(expandedPeers);
expandedPeers = NULL;
}
} }
/* Utility Fns */ /* Utility Fns */
@ -882,32 +912,28 @@ void MessengerWindow::updatePeersAvatar(const QString& peer_id)
//============================================================================ //============================================================================
/** Overloads the default show */
void MessengerWindow::show()
{
if (!this->isVisible()) {
QWidget::show();
} else {
QWidget::activateWindow();
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
QWidget::raise();
}
}
void MessengerWindow::closeEvent (QCloseEvent * event) void MessengerWindow::closeEvent (QCloseEvent * event)
{ {
//Settings->saveWidgetInformation(this); /* save the expanded peers */
if (expandedPeers == NULL) {
expandedPeers = new std::set<std::string>;
} else {
expandedPeers->clear();
}
for (int nIndex = 0; nIndex < ui.messengertreeWidget->topLevelItemCount(); nIndex++) {
QTreeWidgetItem *item = ui.messengertreeWidget->topLevelItem(nIndex);
if (item->isExpanded()) {
expandedPeers->insert(expandedPeers->end(), item->data(COLUMN_DATA, ROLE_ID).toString().toStdString());
}
}
hide();
event->ignore();
} }
/** Shows Share Manager */ /** Shows Share Manager */
void MessengerWindow::openShareManager() void MessengerWindow::openShareManager()
{ {
ShareManager::showYourself(); ShareManager::showYourself();
} }
void MessengerWindow::sendMessage() void MessengerWindow::sendMessage()
@ -927,7 +953,6 @@ LogoBar & MessengerWindow::getLogoBar() const {
void MessengerWindow::changeAvatarClicked() void MessengerWindow::changeAvatarClicked()
{ {
updateAvatar(); updateAvatar();
} }

View File

@ -37,12 +37,11 @@ class MessengerWindow : public RWindow
public: public:
QPixmap picture; QPixmap picture;
static void showYourself ();
static MessengerWindow* getInstance(); static MessengerWindow* getInstance();
static void releaseInstance(); static void releaseInstance();
public slots: public slots:
/** Called when this dialog is to be displayed */
void show();
void updateMessengerDisplay() ; void updateMessengerDisplay() ;
void updatePeersAvatar(const QString& peer_id); void updatePeersAvatar(const QString& peer_id);
void updateAvatar(); void updateAvatar();
@ -105,7 +104,7 @@ signals:
void friendsUpdated() ; void friendsUpdated() ;
private: private:
static MessengerWindow *mv; static MessengerWindow *_instance;
void processSettings(bool bLoad); void processSettings(bool bLoad);

View File

@ -24,6 +24,22 @@
* #define NOTIFY_DEBUG * #define NOTIFY_DEBUG
****/ ****/
/*static*/ NotifyQt *NotifyQt::_instance = NULL;
/*static*/ NotifyQt *NotifyQt::Create ()
{
if (_instance == NULL) {
_instance = new NotifyQt ();
}
return _instance;
}
/*static*/ NotifyQt *NotifyQt::getInstance ()
{
return _instance;
}
void NotifyQt::notifyErrorMsg(int list, int type, std::string msg) void NotifyQt::notifyErrorMsg(int list, int type, std::string msg)
{ {
emit errorOccurred(list,type,QString::fromStdString(msg)) ; emit errorOccurred(list,type,QString::fromStdString(msg)) ;

View File

@ -22,9 +22,8 @@ class NotifyQt: public QObject, public NotifyBase
{ {
Q_OBJECT Q_OBJECT
public: public:
NotifyQt() static NotifyQt *Create ();
: cDialog(NULL) static NotifyQt *getInstance ();
{ return; }
virtual ~NotifyQt() { return; } virtual ~NotifyQt() { return; }
@ -72,6 +71,9 @@ class NotifyQt: public QObject, public NotifyBase
void UpdateGUI(); /* called by timer */ void UpdateGUI(); /* called by timer */
private: private:
NotifyQt() : cDialog(NULL) { return; }
static NotifyQt *_instance;
// void displayNeighbours(); // void displayNeighbours();
// void displayFriends(); // void displayFriends();

View File

@ -53,7 +53,7 @@ int main(int argc, char *argv[])
rsiface = NULL; rsiface = NULL;
NotifyQt *notify = new NotifyQt(); NotifyQt *notify = NotifyQt::Create();
createRsIface(*notify); createRsIface(*notify);
createRsControl(*rsiface, *notify); createRsControl(*rsiface, *notify);
@ -173,7 +173,6 @@ int main(int argc, char *argv[])
QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w->sharedfilesDialog ,SLOT(postModDirectories(bool) )) ; QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w->sharedfilesDialog ,SLOT(postModDirectories(bool) )) ;
QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool) )) ; QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool) )) ;
QObject::connect(notify,SIGNAL(transfersChanged()) ,w->transfersDialog ,SLOT(insertTransfers() )) ; QObject::connect(notify,SIGNAL(transfersChanged()) ,w->transfersDialog ,SLOT(insertTransfers() )) ;
QObject::connect(notify,SIGNAL(friendsChanged()) ,w->messengerWindow ,SLOT(updateMessengerDisplay() )) ;
QObject::connect(notify,SIGNAL(friendsChanged()) ,w->peersDialog ,SLOT(insertPeers() )) ; QObject::connect(notify,SIGNAL(friendsChanged()) ,w->peersDialog ,SLOT(insertPeers() )) ;
QObject::connect(notify,SIGNAL(neighborsChanged()) ,w->networkDialog ,SLOT(insertConnect() )) ; QObject::connect(notify,SIGNAL(neighborsChanged()) ,w->networkDialog ,SLOT(insertConnect() )) ;
QObject::connect(notify,SIGNAL(messagesChanged()) ,w->messagesDialog ,SLOT(insertMessages() )) ; QObject::connect(notify,SIGNAL(messagesChanged()) ,w->messagesDialog ,SLOT(insertMessages() )) ;
@ -182,9 +181,7 @@ int main(int argc, char *argv[])
QObject::connect(notify,SIGNAL(peerHasNewCustomStateString(const QString&)),w->peersDialog,SLOT(updatePeersCustomStateString(const QString&))); QObject::connect(notify,SIGNAL(peerHasNewCustomStateString(const QString&)),w->peersDialog,SLOT(updatePeersCustomStateString(const QString&)));
QObject::connect(notify,SIGNAL(peerHasNewAvatar(const QString&)),w->peersDialog,SLOT(updatePeersAvatar(const QString&))); QObject::connect(notify,SIGNAL(peerHasNewAvatar(const QString&)),w->peersDialog,SLOT(updatePeersAvatar(const QString&)));
QObject::connect(notify,SIGNAL(ownAvatarChanged()),w->peersDialog,SLOT(updateAvatar())); QObject::connect(notify,SIGNAL(ownAvatarChanged()),w->peersDialog,SLOT(updateAvatar()));
QObject::connect(notify,SIGNAL(ownAvatarChanged()),w->messengerWindow,SLOT(updateAvatar()));
QObject::connect(notify,SIGNAL(ownStatusMessageChanged()),w->peersDialog,SLOT(loadmypersonalstatus())); QObject::connect(notify,SIGNAL(ownStatusMessageChanged()),w->peersDialog,SLOT(loadmypersonalstatus()));
QObject::connect(notify,SIGNAL(ownStatusMessageChanged()),w->messengerWindow,SLOT(loadmystatusmessage()));
QObject::connect(notify,SIGNAL(logInfoChanged(const QString&)),w->networkDialog,SLOT(setLogInfo(QString))) ; QObject::connect(notify,SIGNAL(logInfoChanged(const QString&)),w->networkDialog,SLOT(setLogInfo(QString))) ;
QObject::connect(notify,SIGNAL(errorOccurred(int,int,const QString&)),w,SLOT(displayErrorMessage(int,int,const QString&))) ; QObject::connect(notify,SIGNAL(errorOccurred(int,int,const QString&)),w,SLOT(displayErrorMessage(int,int,const QString&))) ;