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 */
_bandwidthGraph = new BandwidthGraph();
/*messengerWindow instance is created statically so that RsAutoUpdatePage can access it*/
messengerWindow = MessengerWindow::getInstance();
#ifdef UNFINISHED
applicationWindow = new ApplicationWindow();
applicationWindow->hide();
@ -304,7 +302,6 @@ MainWindow::~MainWindow()
delete natstatus;
delete ratesstatus;
MessengerWindow::releaseInstance();
messengerWindow = NULL;
#ifdef UNFINISHED
delete applicationWindow;
#endif
@ -624,7 +621,7 @@ void MainWindow::showSettings()
/** Shows Messenger window */
void MainWindow::showMessengerWindow()
{
messengerWindow->show();
MessengerWindow::showYourself();
}
@ -640,13 +637,11 @@ void MainWindow::showApplWindow()
* tray menu configuration. */
void MainWindow::createActions()
{
_settingsAct = new QAction(QIcon(IMAGE_PREFERENCES), tr("Options"), this);
connect(_settingsAct, SIGNAL(triggered()), this, SLOT(showSettings()));
_bandwidthAct = new QAction(QIcon(IMAGE_BWGRAPH), tr("Bandwidth Graph"), this);
connect(_bandwidthAct, SIGNAL(triggered()),
_bandwidthGraph, SLOT(showWindow()));
connect(_bandwidthAct, SIGNAL(triggered()), _bandwidthGraph, SLOT(showWindow()));
_messengerwindowAct = new QAction(QIcon(IMAGE_RSM16), tr("Open Messenger"), this);
connect(_messengerwindowAct, SIGNAL(triggered()),this, SLOT(showMessengerWindow()));
@ -659,8 +654,6 @@ void MainWindow::createActions()
#endif
_helpAct = new QAction(QIcon(IMG_HELP), tr("Help"), this);
connect(_helpAct, SIGNAL(triggered()), this, SLOT(showHelpDialog()));
}
/** 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;
MessagesDialog *messagesDialog;
SharedFilesDialog *sharedfilesDialog;
MessengerWindow *messengerWindow;
ForumsDialog *forumsDialog;
ChannelFeed *channelFeed;
Idle *idle;

View File

@ -46,6 +46,7 @@
#include "RetroShareLink.h"
#include "PeersDialog.h"
#include "ShareManager.h"
#include "gui/notifyqt.h"
#include <iostream>
#include <sstream>
@ -81,7 +82,9 @@
/******
* #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
class MyMessengerTreeWidgetItem : public QTreeWidgetItem
@ -113,20 +116,30 @@ 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()
{
if(mv == 0)
{
mv = new MessengerWindow();
}
return mv;
return _instance;
}
void MessengerWindow::releaseInstance()
{
if(mv != 0)
{
delete mv;
if (_instance) {
delete _instance;
}
if (expandedPeers) {
/* delete saved expanded peers */
delete(expandedPeers);
expandedPeers = NULL;
}
}
@ -137,6 +150,8 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
setAttribute ( Qt::WA_DeleteOnClose, true );
connect( ui.messengertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messengertreeWidgetCostumPopupMenu( QPoint ) ) );
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.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);
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateMessengerDisplay()));
timer->start(1000); /* one second */
/* to hide the header */
ui.messengertreeWidget->header()->hide();
@ -169,7 +187,6 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
_header->setResizeMode (COLUMN_STATE, QHeaderView::Custom);
_header->setStretchLastSection(false);
_header->resizeSection ( COLUMN_NAME, 200 );
_header->resizeSection ( COLUMN_STATE, 42 );
@ -215,6 +232,8 @@ MessengerWindow::~MessengerWindow ()
if (pMainWindow) {
pMainWindow->removeStatusObject(ui.statuscomboBox);
}
_instance = NULL;
}
void MessengerWindow::processSettings(bool bLoad)
@ -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 */
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) {
FilterItems();
}
if (expandedPeers) {
/* we don't need the informations anymore */
delete(expandedPeers);
expandedPeers = NULL;
}
}
/* 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)
{
//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 */
void MessengerWindow::openShareManager()
{
ShareManager::showYourself();
}
void MessengerWindow::sendMessage()
@ -927,7 +953,6 @@ LogoBar & MessengerWindow::getLogoBar() const {
void MessengerWindow::changeAvatarClicked()
{
updateAvatar();
}

View File

@ -37,12 +37,11 @@ class MessengerWindow : public RWindow
public:
QPixmap picture;
static void showYourself ();
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();
@ -105,7 +104,7 @@ signals:
void friendsUpdated() ;
private:
static MessengerWindow *mv;
static MessengerWindow *_instance;
void processSettings(bool bLoad);

View File

@ -24,6 +24,22 @@
* #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)
{
emit errorOccurred(list,type,QString::fromStdString(msg)) ;

View File

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

View File

@ -53,7 +53,7 @@ int main(int argc, char *argv[])
rsiface = NULL;
NotifyQt *notify = new NotifyQt();
NotifyQt *notify = NotifyQt::Create();
createRsIface(*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 ,SLOT(postModDirectories(bool) )) ;
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(neighborsChanged()) ,w->networkDialog ,SLOT(insertConnect() )) ;
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(peerHasNewAvatar(const QString&)),w->peersDialog,SLOT(updatePeersAvatar(const QString&)));
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->messengerWindow,SLOT(loadmystatusmessage()));
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&))) ;