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
This commit is contained in:
thunder2 2010-05-03 00:09:55 +00:00
parent ed566d85b9
commit fb58beef4f
11 changed files with 159 additions and 59 deletions

View File

@ -1289,6 +1289,8 @@ void ForumsDialog::replytomessage()
nMsgDialog->addRecipient( msgInfo.srcId ) ; nMsgDialog->addRecipient( msgInfo.srcId ) ;
nMsgDialog->show(); nMsgDialog->show();
nMsgDialog->activateWindow(); nMsgDialog->activateWindow();
/* window will destroy itself! */
} }
else else
{ {

View File

@ -27,7 +27,6 @@
#include <QIcon> #include <QIcon>
#include <QPixmap> #include <QPixmap>
#include "ChannelFeed.h"
#include "ShareManager.h" #include "ShareManager.h"
#include "NetworkView.h" #include "NetworkView.h"
#include "LinksDialog.h" #include "LinksDialog.h"
@ -103,6 +102,17 @@
#define IMAGE_TWOONLINE ":/images/rstray2.png" #define IMAGE_TWOONLINE ":/images/rstray2.png"
#define IMAGE_BLOGS ":/images/kblogger.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 */ /** Constructor */
MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) 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)); messageAction = createPageAction(QIcon(IMAGE_MESSAGES), tr("Messages"), grp));
#ifndef RS_RELEASE_VERSION #ifndef RS_RELEASE_VERSION
ChannelFeed *channelFeed = NULL;
ui.stackPages->add(channelFeed = new ChannelFeed(ui.stackPages), ui.stackPages->add(channelFeed = new ChannelFeed(ui.stackPages),
createPageAction(QIcon(IMAGE_CHANNELS), tr("Channels"), grp)); createPageAction(QIcon(IMAGE_CHANNELS), tr("Channels"), grp));
#endif #endif
#ifdef BLOGS #ifdef BLOGS
BlogsDialog *blogsFeed = NULL;
ui.stackPages->add(blogsFeed = new BlogsDialog(ui.stackPages), ui.stackPages->add(blogsFeed = new BlogsDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_BLOGS), tr("Blogs"), grp)); createPageAction(QIcon(IMAGE_BLOGS), tr("Blogs"), grp));
#endif #endif
ForumsDialog *forumsDialog = NULL;
ui.stackPages->add(forumsDialog = new ForumsDialog(ui.stackPages), ui.stackPages->add(forumsDialog = new ForumsDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_FORUMS), tr("Forums"), grp)); createPageAction(QIcon(IMAGE_FORUMS), tr("Forums"), grp));
#ifndef RS_RELEASE_VERSION #ifndef RS_RELEASE_VERSION
LinksDialog *linksDialog = NULL;
ui.stackPages->add(linksDialog = new LinksDialog(ui.stackPages), ui.stackPages->add(linksDialog = new LinksDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_LINKS), tr("Links Cloud"), grp)); createPageAction(QIcon(IMAGE_LINKS), tr("Links Cloud"), grp));
#endif #endif
#ifndef RS_RELEASE_VERSION #ifndef RS_RELEASE_VERSION
NewsFeed *newsFeed = NULL;
ui.stackPages->add(newsFeed = new NewsFeed(ui.stackPages), ui.stackPages->add(newsFeed = new NewsFeed(ui.stackPages),
createPageAction(QIcon(IMAGE_NEWSFEED), tr("News Feed"), grp)); createPageAction(QIcon(IMAGE_NEWSFEED), tr("News Feed"), grp));
#endif #endif
@ -440,9 +445,60 @@ void MainWindow::showWindow(Page page)
/* Show the dialog. */ /* Show the dialog. */
RWindow::showWindow(); RWindow::showWindow();
/* Set the focus to the specified page. */ /* 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 *****/ /***** TOOL BAR FUNCTIONS *****/
@ -450,13 +506,9 @@ void MainWindow::showWindow(Page page)
/** Add a Friend ShortCut */ /** Add a Friend ShortCut */
void MainWindow::addFriend() void MainWindow::addFriend()
{ {
ConnectFriendWizard* connwiz = new ConnectFriendWizard(this); ConnectFriendWizard connwiz (this);
// set widget to be deleted after close connwiz.exec ();
connwiz->setAttribute( Qt::WA_DeleteOnClose, true);
connwiz->show();
} }
/** Shows Share Manager */ /** Shows Share Manager */
@ -468,9 +520,9 @@ void MainWindow::openShareManager()
/** Shows Messages Dialog */ /** Shows Messages Dialog */
void void
MainWindow::showMess(MainWindow::Page page) MainWindow::showMess()
{ {
showWindow(page); showWindow(MainWindow::Messages);
} }

View File

@ -39,6 +39,11 @@
#include "SharedFilesDialog.h" #include "SharedFilesDialog.h"
#include "MessengerWindow.h" #include "MessengerWindow.h"
#include "PluginsPage.h" #include "PluginsPage.h"
#include "ForumsDialog.h"
#ifndef RS_RELEASE_VERSION
#include "ChannelFeed.h"
#endif
#include "bwgraph/bwgraph.h" #include "bwgraph/bwgraph.h"
#include "help/browser/helpbrowser.h" #include "help/browser/helpbrowser.h"
@ -50,6 +55,16 @@
class PeerStatus; class PeerStatus;
class NATStatus; class NATStatus;
class RatesStatus; class RatesStatus;
class ForumsDialog;
#ifndef RS_RELEASE_VERSION
class LinksDialog;
class NewsFeed;
#endif
#ifdef BLOGS
class BlogsDialog;
#endif
class MainWindow : public RWindow class MainWindow : public RWindow
{ {
@ -72,8 +87,8 @@ public:
}; };
/** Default Constructor */ /** Create main window */
MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0); static MainWindow *Create ();
/** Destructor. */ /** Destructor. */
~MainWindow(); ~MainWindow();
@ -91,7 +106,18 @@ public:
MessagesDialog *messagesDialog; MessagesDialog *messagesDialog;
SharedFilesDialog *sharedfilesDialog; SharedFilesDialog *sharedfilesDialog;
MessengerWindow *messengerWindow; MessengerWindow *messengerWindow;
Idle *idle; ForumsDialog *forumsDialog;
Idle *idle;
#ifndef RS_RELEASE_VERSION
ChannelFeed *channelFeed;
LinksDialog *linksDialog;
NewsFeed *newsFeed;
#endif
#ifdef BLOGS
BlogsDialog *blogsFeed;
#endif
#ifdef UNFINISHED #ifdef UNFINISHED
ApplicationWindow *applicationWindow; ApplicationWindow *applicationWindow;
@ -104,12 +130,17 @@ public slots:
//void show(); //void show();
/** Shows the config dialog with focus set to the given page. */ /** Shows the config dialog with focus set to the given page. */
void showWindow(Page page); void showWindow(Page page);
/** Set focus to the given page. */
static void activatePage (Page page);
void updateHashingInfo(const QString&) ; void updateHashingInfo(const QString&) ;
void displayErrorMessage(int,int,const QString&) ; void displayErrorMessage(int,int,const QString&) ;
void postModDirectories(bool update_local); void postModDirectories(bool update_local);
protected: protected:
/** Default Constructor */
MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
void closeEvent(QCloseEvent *); void closeEvent(QCloseEvent *);
/** Called when the user changes the UI translation. */ /** Called when the user changes the UI translation. */
@ -141,7 +172,7 @@ private slots:
/** Called when a child window requests the given help <b>topic</b>. */ /** Called when a child window requests the given help <b>topic</b>. */
void showHelpDialog(const QString &topic); void showHelpDialog(const QString &topic);
void showMess(MainWindow::Page page = MainWindow::Messages); void showMess();
void showSettings(); void showSettings();
void setStyle(); void setStyle();
@ -158,6 +189,8 @@ private:
void createTrayIcon(); void createTrayIcon();
static MainWindow *_instance;
/** Defines the actions for the tray menu */ /** Defines the actions for the tray menu */
QAction* _settingsAct; QAction* _settingsAct;
QAction* _bandwidthAct; QAction* _bandwidthAct;

View File

@ -346,6 +346,8 @@ void MessagesDialog::replytomessage()
nMsgDialog->addRecipient( msgInfo.srcId ) ; nMsgDialog->addRecipient( msgInfo.srcId ) ;
nMsgDialog->show(); nMsgDialog->show();
nMsgDialog->activateWindow(); nMsgDialog->activateWindow();
/* window will destroy itself! */
} }
void MessagesDialog::replyallmessage() void MessagesDialog::replyallmessage()
@ -401,6 +403,8 @@ void MessagesDialog::replyallmessage()
nMsgDialog->show(); nMsgDialog->show();
nMsgDialog->activateWindow(); nMsgDialog->activateWindow();
/* window will destroy itself! */
} }
void MessagesDialog::forwardmessage() void MessagesDialog::forwardmessage()
@ -458,6 +462,8 @@ void MessagesDialog::forwardmessage()
//nMsgDialog->addRecipient( msgInfo.srcId ) ; //nMsgDialog->addRecipient( msgInfo.srcId ) ;
nMsgDialog->show(); nMsgDialog->show();
nMsgDialog->activateWindow(); nMsgDialog->activateWindow();
/* window will destroy itself! */
} }
void MessagesDialog::togglefileview() void MessagesDialog::togglefileview()

View File

@ -23,7 +23,6 @@
#include "MessagesPopupDialog.h" #include "MessagesPopupDialog.h"
#include "MessagesDialog.h" #include "MessagesDialog.h"
#include "msgs/ChanMsgDialog.h"
#include "util/printpreview.h" #include "util/printpreview.h"
#include "rsiface/rsiface.h" #include "rsiface/rsiface.h"

View File

@ -97,7 +97,7 @@ void MessengerWindow::releaseInstance()
/** Constructor */ /** Constructor */
MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags) 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 */ /* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); ui.setupUi(this);
@ -572,12 +572,9 @@ std::string getPeersRsCertId(QTreeWidgetItem *i)
/** Add a Friend ShortCut */ /** Add a Friend ShortCut */
void MessengerWindow::addFriend() void MessengerWindow::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 ();
} }
/** Open a QFileDialog to browse for export a file. */ /** Open a QFileDialog to browse for export a file. */
@ -808,7 +805,7 @@ void MessengerWindow::show()
QWidget::show(); QWidget::show();
} else { } else {
QWidget::activateWindow(); QWidget::activateWindow();
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive); setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
QWidget::raise(); QWidget::raise();
} }
} }
@ -858,6 +855,8 @@ void MessengerWindow::sendMessage()
nMsgDialog->newMsg(); nMsgDialog->newMsg();
nMsgDialog->show(); nMsgDialog->show();
/* window will destroy itself! */
} }
LogoBar & MessengerWindow::getLogoBar() const { LogoBar & MessengerWindow::getLogoBar() const {
@ -1058,10 +1057,10 @@ void MessengerWindow::savestatus()
void MessengerWindow::checkAndSetIdle(int idleTime){ void MessengerWindow::checkAndSetIdle(int idleTime){
if((idleTime >= maxTimeBeforeIdle) && !isIdle){ if((idleTime >= (int) maxTimeBeforeIdle) && !isIdle){
setIdle(true); setIdle(true);
}else }else
if((idleTime < maxTimeBeforeIdle) && isIdle){ if((idleTime < (int) maxTimeBeforeIdle) && isIdle){
setIdle(false); setIdle(false);
} }

View File

@ -44,6 +44,8 @@
#include "gui/forums/CreateForum.h" #include "gui/forums/CreateForum.h"
#include "gui/channels/CreateChannel.h" #include "gui/channels/CreateChannel.h"
#include "MainWindow.h"
#include <sstream> #include <sstream>
#include <time.h> #include <time.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -391,7 +393,7 @@ void PeersDialog::insertPeers()
} }
} }
if (!found) { if (!found) {
peertreeWidget->takeTopLevelItem(index); delete (peertreeWidget->takeTopLevelItem(index));
} else { } else {
index++; index++;
} }
@ -418,7 +420,7 @@ void PeersDialog::insertPeers()
if ((!rsPeers->getPeerDetails(*it, detail) || !detail.accept_connection) if ((!rsPeers->getPeerDetails(*it, detail) || !detail.accept_connection)
&& detail.gpg_id != rsPeers->getGPGOwnId()) { && detail.gpg_id != rsPeers->getGPGOwnId()) {
//don't accept anymore connection, remove from the view //don't accept anymore connection, remove from the view
peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item)); delete (peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item)));
continue; continue;
} }
@ -438,7 +440,7 @@ void PeersDialog::insertPeers()
while (childIndex < gpg_item->childCount()) { 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(3).toStdString();
if (!rsPeers->isFriend(ssl_id)) { if (!rsPeers->isFriend(ssl_id)) {
gpg_item->takeChild(childIndex); delete (gpg_item->takeChild(childIndex));
} else { } else {
childIndex++; childIndex++;
} }
@ -706,6 +708,8 @@ void PeersDialog::msgfriend()
nMsgDialog->newMsg(); nMsgDialog->newMsg();
nMsgDialog->show(); nMsgDialog->show();
/* window will destroy itself! */
} }
@ -1531,38 +1535,36 @@ void PeersDialog::changeAvatarClicked()
void PeersDialog::on_actionAdd_Friend_activated() void PeersDialog::on_actionAdd_Friend_activated()
{ {
ConnectFriendWizard* connectwiz = new ConnectFriendWizard(this); ConnectFriendWizard connectwiz (this);
// set widget to be deleted after close connectwiz.exec ();
connectwiz->setAttribute( Qt::WA_DeleteOnClose, true);
connectwiz->show();
} }
void PeersDialog::on_actionCreate_New_Forum_activated() void PeersDialog::on_actionCreate_New_Forum_activated()
{ {
((MainPageStack*)this->parent())->setCurrentIndex(8); // swtich to forum view MainWindow::activatePage (MainWindow::Forums);
static CreateForum *cf = new CreateForum(this);
cf->show(); CreateForum cf (this);
cf.exec();
} }
void PeersDialog::on_actionCreate_New_Channel_activated() void PeersDialog::on_actionCreate_New_Channel_activated()
{ {
#ifndef RS_RELEASE_VERSION
MainWindow::activatePage (MainWindow::Channels);
CreateChannel *cf = new CreateChannel(NULL); CreateChannel cf (this);
((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"));
cf->setWindowTitle(tr("Create a new Channel"));
cf->ui.labelicon->setPixmap(QPixmap(":/images/add_channel64.png"));
QString titleStr("<span style=\"font-size:24pt; font-weight:500;" QString titleStr("<span style=\"font-size:24pt; font-weight:500;"
"color:#32CD32;\">%1</span>"); "color:#32CD32;\">%1</span>");
cf->ui.textlabelcreatforums->setText( titleStr.arg( tr("New Channel") ) ) ; cf.ui.textlabelcreatforums->setText( titleStr.arg( tr("New Channel") ) ) ;
cf->show(); cf.exec();
#endif
} }
/** Loads own personal status */ /** Loads own personal status */
void PeersDialog::loadmypersonalstatus() void PeersDialog::loadmypersonalstatus()
{ {
@ -1572,8 +1574,8 @@ void PeersDialog::loadmypersonalstatus()
void PeersDialog::statusmessage() void PeersDialog::statusmessage()
{ {
static StatusMessage *statusmsgdialog = new StatusMessage(); StatusMessage statusmsgdialog (this);
statusmsgdialog->show(); statusmsgdialog.exec();
} }
void PeersDialog::addExtraFile() void PeersDialog::addExtraFile()

View File

@ -1218,6 +1218,8 @@ void SearchDialog::sendLinkTo( )
nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()) ; nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()) ;
nMsgDialog->show(); nMsgDialog->show();
/* window will destroy itself! */
} }
void SearchDialog::togglereset() void SearchDialog::togglereset()

View File

@ -349,6 +349,8 @@ void SharedFilesDialog::sendremoteLinkTo()
nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()); nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString());
nMsgDialog->show(); nMsgDialog->show();
/* window will destroy itself! */
} }
void SharedFilesDialog::sendLinkTo() void SharedFilesDialog::sendLinkTo()
@ -370,6 +372,8 @@ void SharedFilesDialog::sendLinkTo()
nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()); nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString());
nMsgDialog->show(); nMsgDialog->show();
/* window will destroy itself! */
} }
void SharedFilesDialog::sendHtmlLinkTo( ) void SharedFilesDialog::sendHtmlLinkTo( )
@ -390,6 +394,8 @@ void SharedFilesDialog::sendHtmlLinkTo( )
nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()); nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString());
nMsgDialog->show(); nMsgDialog->show();
/* window will destroy itself! */
} }
//void SharedFilesDialog::sendLinktoChat() //void SharedFilesDialog::sendLinktoChat()
@ -525,6 +531,8 @@ void SharedFilesDialog::recommendFilesTo( std::string rsid )
nMsgDialog->sendMessage(); nMsgDialog->sendMessage();
nMsgDialog->close(); nMsgDialog->close();
/* window will destroy itself! */
} }
void SharedFilesDialog::recommendFilesToMsg( std::string rsid ) void SharedFilesDialog::recommendFilesToMsg( std::string rsid )
@ -548,6 +556,8 @@ void SharedFilesDialog::recommendFilesToMsg( std::string rsid )
std::cout << "recommending to " << rsid << std::endl ; std::cout << "recommending to " << rsid << std::endl ;
nMsgDialog->addRecipient(rsid) ; nMsgDialog->addRecipient(rsid) ;
/* window will destroy itself! */
} }
//#endif //#endif

View File

@ -7,12 +7,7 @@
#include <rsiface/rsturtle.h> #include <rsiface/rsturtle.h>
#endif #endif
#include "gui/NetworkDialog.h" #include "gui/RsAutoUpdatePage.h"
#include "gui/PeersDialog.h"
#include "gui/SharedFilesDialog.h"
#include "gui/TransfersDialog.h"
#include "gui/MessagesDialog.h"
#include "gui/MessengerWindow.h"
#include "gui/toaster/OnlineToaster.h" #include "gui/toaster/OnlineToaster.h"
#include "gui/toaster/MessageToaster.h" #include "gui/toaster/MessageToaster.h"

View File

@ -122,7 +122,7 @@ int main(int argc, char *argv[])
rsicontrol->StartupRetroShare(); 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 // 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. // avoid clashes between infos from threads.