From fb58beef4f26164ec6444e5939c565bc87f0301c Mon Sep 17 00:00:00 2001 From: thunder2 Date: Mon, 3 May 2010 00:09:55 +0000 Subject: [PATCH] Source code maintenance Memory leaks: - PeersDialog::insertPeers -> takeTopLevelItem, takeChild - activate correct page on creating a new forum or channel from PeersDialog (problems with RS_RELEASE_VERSION) new static method to activate a page MainWindow::activatePage git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2842 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/ForumsDialog.cpp | 2 + retroshare-gui/src/gui/MainWindow.cpp | 82 +++++++++++++++---- retroshare-gui/src/gui/MainWindow.h | 43 ++++++++-- retroshare-gui/src/gui/MessagesDialog.cpp | 6 ++ .../src/gui/MessagesPopupDialog.cpp | 1 - retroshare-gui/src/gui/MessengerWindow.cpp | 17 ++-- retroshare-gui/src/gui/PeersDialog.cpp | 46 ++++++----- retroshare-gui/src/gui/SearchDialog.cpp | 2 + retroshare-gui/src/gui/SharedFilesDialog.cpp | 10 +++ retroshare-gui/src/gui/notifyqt.cpp | 7 +- retroshare-gui/src/main.cpp | 2 +- 11 files changed, 159 insertions(+), 59 deletions(-) diff --git a/retroshare-gui/src/gui/ForumsDialog.cpp b/retroshare-gui/src/gui/ForumsDialog.cpp index 682fdbbd7..f1117b96f 100644 --- a/retroshare-gui/src/gui/ForumsDialog.cpp +++ b/retroshare-gui/src/gui/ForumsDialog.cpp @@ -1289,6 +1289,8 @@ void ForumsDialog::replytomessage() nMsgDialog->addRecipient( msgInfo.srcId ) ; nMsgDialog->show(); nMsgDialog->activateWindow(); + + /* window will destroy itself! */ } else { diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 039b7b3bd..1d22ba41f 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -27,7 +27,6 @@ #include #include -#include "ChannelFeed.h" #include "ShareManager.h" #include "NetworkView.h" #include "LinksDialog.h" @@ -103,6 +102,17 @@ #define IMAGE_TWOONLINE ":/images/rstray2.png" #define IMAGE_BLOGS ":/images/kblogger.png" +/*static*/ MainWindow *MainWindow::_instance = NULL; + +/** create main window */ +/*static*/ MainWindow *MainWindow::Create () +{ + if (_instance == NULL) { + _instance = new MainWindow (); + } + + return _instance; +} /** Constructor */ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) @@ -184,29 +194,24 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) messageAction = createPageAction(QIcon(IMAGE_MESSAGES), tr("Messages"), grp)); #ifndef RS_RELEASE_VERSION - ChannelFeed *channelFeed = NULL; ui.stackPages->add(channelFeed = new ChannelFeed(ui.stackPages), createPageAction(QIcon(IMAGE_CHANNELS), tr("Channels"), grp)); #endif #ifdef BLOGS - BlogsDialog *blogsFeed = NULL; ui.stackPages->add(blogsFeed = new BlogsDialog(ui.stackPages), createPageAction(QIcon(IMAGE_BLOGS), tr("Blogs"), grp)); #endif - ForumsDialog *forumsDialog = NULL; ui.stackPages->add(forumsDialog = new ForumsDialog(ui.stackPages), createPageAction(QIcon(IMAGE_FORUMS), tr("Forums"), grp)); #ifndef RS_RELEASE_VERSION - LinksDialog *linksDialog = NULL; ui.stackPages->add(linksDialog = new LinksDialog(ui.stackPages), createPageAction(QIcon(IMAGE_LINKS), tr("Links Cloud"), grp)); #endif #ifndef RS_RELEASE_VERSION - NewsFeed *newsFeed = NULL; ui.stackPages->add(newsFeed = new NewsFeed(ui.stackPages), createPageAction(QIcon(IMAGE_NEWSFEED), tr("News Feed"), grp)); #endif @@ -440,9 +445,60 @@ void MainWindow::showWindow(Page page) /* Show the dialog. */ RWindow::showWindow(); /* Set the focus to the specified page. */ - ui.stackPages->setCurrentIndex((int)page); + activatePage (page); } +/** Set focus to the given page. */ +/*static*/ void MainWindow::activatePage(Page page) +{ + if (_instance == NULL) { + return; + } + + MainPage *Page = NULL; + + switch (page) { + case Network: + Page = _instance->networkDialog; + break; + case Friends: + Page = _instance->peersDialog; + break; + case Search: + Page = _instance->searchDialog; + break; + case Transfers: + Page = _instance->transfersDialog; + break; + case SharedDirectories: + Page = _instance->sharedfilesDialog; + break; + case Messages: + Page = _instance->messagesDialog; + break; +#ifndef RS_RELEASE_VERSION + case Links: + Page = _instance->linksDialog; + break; + case Channels: + Page = _instance->channelFeed; + break; +#endif + case Forums: + Page = _instance->forumsDialog; + break; +#ifdef BLOGS + case Blogs: + Page = _instance->blogsFeed; + break; +#endif + } + + if (Page) { + /* Set the focus to the specified page. */ + _instance->ui.stackPages->setCurrentPage(Page); + } +} /***** TOOL BAR FUNCTIONS *****/ @@ -450,13 +506,9 @@ void MainWindow::showWindow(Page page) /** Add a Friend ShortCut */ void MainWindow::addFriend() { - ConnectFriendWizard* connwiz = new ConnectFriendWizard(this); + ConnectFriendWizard connwiz (this); - // set widget to be deleted after close - connwiz->setAttribute( Qt::WA_DeleteOnClose, true); - - - connwiz->show(); + connwiz.exec (); } /** Shows Share Manager */ @@ -468,9 +520,9 @@ void MainWindow::openShareManager() /** Shows Messages Dialog */ void -MainWindow::showMess(MainWindow::Page page) +MainWindow::showMess() { - showWindow(page); + showWindow(MainWindow::Messages); } diff --git a/retroshare-gui/src/gui/MainWindow.h b/retroshare-gui/src/gui/MainWindow.h index b73fab2bc..3e9917a63 100644 --- a/retroshare-gui/src/gui/MainWindow.h +++ b/retroshare-gui/src/gui/MainWindow.h @@ -39,6 +39,11 @@ #include "SharedFilesDialog.h" #include "MessengerWindow.h" #include "PluginsPage.h" +#include "ForumsDialog.h" + +#ifndef RS_RELEASE_VERSION +#include "ChannelFeed.h" +#endif #include "bwgraph/bwgraph.h" #include "help/browser/helpbrowser.h" @@ -50,6 +55,16 @@ class PeerStatus; class NATStatus; class RatesStatus; +class ForumsDialog; + +#ifndef RS_RELEASE_VERSION +class LinksDialog; +class NewsFeed; +#endif + +#ifdef BLOGS +class BlogsDialog; +#endif class MainWindow : public RWindow { @@ -72,8 +87,8 @@ public: }; - /** Default Constructor */ - MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0); + /** Create main window */ + static MainWindow *Create (); /** Destructor. */ ~MainWindow(); @@ -91,9 +106,20 @@ public: MessagesDialog *messagesDialog; SharedFilesDialog *sharedfilesDialog; MessengerWindow *messengerWindow; - Idle *idle; + ForumsDialog *forumsDialog; + Idle *idle; -#ifdef UNFINISHED +#ifndef RS_RELEASE_VERSION + ChannelFeed *channelFeed; + LinksDialog *linksDialog; + NewsFeed *newsFeed; +#endif + +#ifdef BLOGS + BlogsDialog *blogsFeed; +#endif + +#ifdef UNFINISHED ApplicationWindow *applicationWindow; #endif PluginsPage* pluginsPage ; @@ -104,12 +130,17 @@ public slots: //void show(); /** Shows the config dialog with focus set to the given page. */ void showWindow(Page page); + /** Set focus to the given page. */ + static void activatePage (Page page); void updateHashingInfo(const QString&) ; void displayErrorMessage(int,int,const QString&) ; void postModDirectories(bool update_local); protected: + /** Default Constructor */ + MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0); + void closeEvent(QCloseEvent *); /** Called when the user changes the UI translation. */ @@ -141,7 +172,7 @@ private slots: /** Called when a child window requests the given help topic. */ void showHelpDialog(const QString &topic); - void showMess(MainWindow::Page page = MainWindow::Messages); + void showMess(); void showSettings(); void setStyle(); @@ -158,6 +189,8 @@ private: void createTrayIcon(); + static MainWindow *_instance; + /** Defines the actions for the tray menu */ QAction* _settingsAct; QAction* _bandwidthAct; diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index 1507f4cb6..7fdbb6fc6 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -346,6 +346,8 @@ void MessagesDialog::replytomessage() nMsgDialog->addRecipient( msgInfo.srcId ) ; nMsgDialog->show(); nMsgDialog->activateWindow(); + + /* window will destroy itself! */ } void MessagesDialog::replyallmessage() @@ -401,6 +403,8 @@ void MessagesDialog::replyallmessage() nMsgDialog->show(); nMsgDialog->activateWindow(); + + /* window will destroy itself! */ } void MessagesDialog::forwardmessage() @@ -458,6 +462,8 @@ void MessagesDialog::forwardmessage() //nMsgDialog->addRecipient( msgInfo.srcId ) ; nMsgDialog->show(); nMsgDialog->activateWindow(); + + /* window will destroy itself! */ } void MessagesDialog::togglefileview() diff --git a/retroshare-gui/src/gui/MessagesPopupDialog.cpp b/retroshare-gui/src/gui/MessagesPopupDialog.cpp index 61ed0ea08..2878411ee 100644 --- a/retroshare-gui/src/gui/MessagesPopupDialog.cpp +++ b/retroshare-gui/src/gui/MessagesPopupDialog.cpp @@ -23,7 +23,6 @@ #include "MessagesPopupDialog.h" #include "MessagesDialog.h" -#include "msgs/ChanMsgDialog.h" #include "util/printpreview.h" #include "rsiface/rsiface.h" diff --git a/retroshare-gui/src/gui/MessengerWindow.cpp b/retroshare-gui/src/gui/MessengerWindow.cpp index 70ceacef1..3f193a0e9 100644 --- a/retroshare-gui/src/gui/MessengerWindow.cpp +++ b/retroshare-gui/src/gui/MessengerWindow.cpp @@ -97,7 +97,7 @@ void MessengerWindow::releaseInstance() /** Constructor */ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags) - : maxTimeBeforeIdle(30), RWindow("MessengerWindow", parent, flags) + : RWindow("MessengerWindow", parent, flags), maxTimeBeforeIdle(30) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); @@ -572,12 +572,9 @@ std::string getPeersRsCertId(QTreeWidgetItem *i) /** Add a Friend ShortCut */ void MessengerWindow::addFriend() { - ConnectFriendWizard* connwiz = new ConnectFriendWizard(this); - // set widget to be deleted after close - connwiz->setAttribute( Qt::WA_DeleteOnClose, true); - - connwiz->show(); + ConnectFriendWizard connwiz (this); + connwiz.exec (); } /** Open a QFileDialog to browse for export a file. */ @@ -808,7 +805,7 @@ void MessengerWindow::show() QWidget::show(); } else { QWidget::activateWindow(); - setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive); + setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); QWidget::raise(); } } @@ -858,6 +855,8 @@ void MessengerWindow::sendMessage() nMsgDialog->newMsg(); nMsgDialog->show(); + + /* window will destroy itself! */ } LogoBar & MessengerWindow::getLogoBar() const { @@ -1058,10 +1057,10 @@ void MessengerWindow::savestatus() void MessengerWindow::checkAndSetIdle(int idleTime){ - if((idleTime >= maxTimeBeforeIdle) && !isIdle){ + if((idleTime >= (int) maxTimeBeforeIdle) && !isIdle){ setIdle(true); }else - if((idleTime < maxTimeBeforeIdle) && isIdle){ + if((idleTime < (int) maxTimeBeforeIdle) && isIdle){ setIdle(false); } diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index d21064161..68f498538 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -44,6 +44,8 @@ #include "gui/forums/CreateForum.h" #include "gui/channels/CreateChannel.h" +#include "MainWindow.h" + #include #include #include @@ -391,7 +393,7 @@ void PeersDialog::insertPeers() } } if (!found) { - peertreeWidget->takeTopLevelItem(index); + delete (peertreeWidget->takeTopLevelItem(index)); } else { index++; } @@ -418,7 +420,7 @@ void PeersDialog::insertPeers() if ((!rsPeers->getPeerDetails(*it, detail) || !detail.accept_connection) && detail.gpg_id != rsPeers->getGPGOwnId()) { //don't accept anymore connection, remove from the view - peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item)); + delete (peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item))); continue; } @@ -438,7 +440,7 @@ void PeersDialog::insertPeers() while (childIndex < gpg_item->childCount()) { std::string ssl_id = (gpg_item->child(childIndex))->text(3).toStdString(); if (!rsPeers->isFriend(ssl_id)) { - gpg_item->takeChild(childIndex); + delete (gpg_item->takeChild(childIndex)); } else { childIndex++; } @@ -706,6 +708,8 @@ void PeersDialog::msgfriend() nMsgDialog->newMsg(); nMsgDialog->show(); + + /* window will destroy itself! */ } @@ -1531,38 +1535,36 @@ void PeersDialog::changeAvatarClicked() void PeersDialog::on_actionAdd_Friend_activated() { - ConnectFriendWizard* connectwiz = new ConnectFriendWizard(this); + ConnectFriendWizard connectwiz (this); - // set widget to be deleted after close - connectwiz->setAttribute( Qt::WA_DeleteOnClose, true); - - - connectwiz->show(); + connectwiz.exec (); } void PeersDialog::on_actionCreate_New_Forum_activated() { - ((MainPageStack*)this->parent())->setCurrentIndex(8); // swtich to forum view - static CreateForum *cf = new CreateForum(this); - cf->show(); + MainWindow::activatePage (MainWindow::Forums); + + CreateForum cf (this); + cf.exec(); } void PeersDialog::on_actionCreate_New_Channel_activated() { +#ifndef RS_RELEASE_VERSION + MainWindow::activatePage (MainWindow::Channels); - CreateChannel *cf = new CreateChannel(NULL); - ((MainPageStack*)this->parent())->setCurrentIndex(6); // swtich to forum view - - cf->setWindowTitle(tr("Create a new Channel")); - cf->ui.labelicon->setPixmap(QPixmap(":/images/add_channel64.png")); + CreateChannel cf (this); + cf.setWindowTitle(tr("Create a new Channel")); + cf.ui.labelicon->setPixmap(QPixmap(":/images/add_channel64.png")); QString titleStr("%1"); - cf->ui.textlabelcreatforums->setText( titleStr.arg( tr("New Channel") ) ) ; - cf->show(); - + cf.ui.textlabelcreatforums->setText( titleStr.arg( tr("New Channel") ) ) ; + cf.exec(); +#endif } + /** Loads own personal status */ void PeersDialog::loadmypersonalstatus() { @@ -1572,8 +1574,8 @@ void PeersDialog::loadmypersonalstatus() void PeersDialog::statusmessage() { - static StatusMessage *statusmsgdialog = new StatusMessage(); - statusmsgdialog->show(); + StatusMessage statusmsgdialog (this); + statusmsgdialog.exec(); } void PeersDialog::addExtraFile() diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index a8789fca3..423da9228 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -1218,6 +1218,8 @@ void SearchDialog::sendLinkTo( ) nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()) ; nMsgDialog->show(); + + /* window will destroy itself! */ } void SearchDialog::togglereset() diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index d5edbb7bf..f4bf9f0d4 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -349,6 +349,8 @@ void SharedFilesDialog::sendremoteLinkTo() nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()); nMsgDialog->show(); + + /* window will destroy itself! */ } void SharedFilesDialog::sendLinkTo() @@ -370,6 +372,8 @@ void SharedFilesDialog::sendLinkTo() nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()); nMsgDialog->show(); + + /* window will destroy itself! */ } void SharedFilesDialog::sendHtmlLinkTo( ) @@ -390,6 +394,8 @@ void SharedFilesDialog::sendHtmlLinkTo( ) nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()); nMsgDialog->show(); + + /* window will destroy itself! */ } //void SharedFilesDialog::sendLinktoChat() @@ -525,6 +531,8 @@ void SharedFilesDialog::recommendFilesTo( std::string rsid ) nMsgDialog->sendMessage(); nMsgDialog->close(); + + /* window will destroy itself! */ } void SharedFilesDialog::recommendFilesToMsg( std::string rsid ) @@ -548,6 +556,8 @@ void SharedFilesDialog::recommendFilesToMsg( std::string rsid ) std::cout << "recommending to " << rsid << std::endl ; nMsgDialog->addRecipient(rsid) ; + + /* window will destroy itself! */ } //#endif diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index f3a2a012d..6845e5d88 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -7,12 +7,7 @@ #include #endif -#include "gui/NetworkDialog.h" -#include "gui/PeersDialog.h" -#include "gui/SharedFilesDialog.h" -#include "gui/TransfersDialog.h" -#include "gui/MessagesDialog.h" -#include "gui/MessengerWindow.h" +#include "gui/RsAutoUpdatePage.h" #include "gui/toaster/OnlineToaster.h" #include "gui/toaster/MessageToaster.h" diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index c60a5baed..f47ec0a65 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) rsicontrol->StartupRetroShare(); - MainWindow *w = new MainWindow; + MainWindow *w = MainWindow::Create (); // I'm using a signal to transfer the hashing info to the mainwindow, because Qt schedules signals properly to // avoid clashes between infos from threads.