From 8ce338c49c600291a3583f275a1eee3e6066c9ab Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sun, 2 May 2010 13:12:46 +0000 Subject: [PATCH] Source code maintenance Memory leaks: - NetworkDialog::loadcert -> new QFileDialog - NetworkDialog::insertConnect -> takeTopLevelItem - NetworkDialog::on_actionAddFriend_activated -> new QFileDialog - main -> new StartDialog, new GenCertDialog to be continued Info: Pointer from takeTopLevelItem must be deleted Can someone convert the StartDialog from QMainWindow to QDialog ? git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2833 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/GenCertDialog.cpp | 14 ++--- retroshare-gui/src/gui/NetworkDialog.cpp | 67 ++++++++---------------- retroshare-gui/src/gui/NetworkDialog.h | 5 -- retroshare-gui/src/gui/PeersDialog.cpp | 1 - retroshare-gui/src/gui/StartDialog.cpp | 18 +++---- retroshare-gui/src/main.cpp | 16 ++---- 6 files changed, 40 insertions(+), 81 deletions(-) diff --git a/retroshare-gui/src/gui/GenCertDialog.cpp b/retroshare-gui/src/gui/GenCertDialog.cpp index 18c50b2ef..5086328d2 100644 --- a/retroshare-gui/src/gui/GenCertDialog.cpp +++ b/retroshare-gui/src/gui/GenCertDialog.cpp @@ -148,7 +148,7 @@ void GenCertDialog::genPerson() if (!genNewGPGKey) { if (ui.location_input->text().length() < 3) { /* Message Dialog */ - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, + QMessageBox::warning ( NULL, tr("Generate GPG key Failure"), tr("Location field is required with a minimum of 3 characters"), QMessageBox::Ok); @@ -158,7 +158,7 @@ void GenCertDialog::genPerson() if (pgpidx < 0) { /* Message Dialog */ - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, + QMessageBox::warning ( NULL, "Generate ID Failure", "Missing PGP Certificate", QMessageBox::Ok); @@ -170,7 +170,7 @@ void GenCertDialog::genPerson() if (ui.password_input->text().length() < 3 || ui.name_input->text().length() < 3 || ui.email_input->text().length() < 3 || ui.location_label->text().length() < 3) { /* Message Dialog */ - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, + QMessageBox::warning ( NULL, tr("Generate GPG key Failure"), tr("All fields are required with a minimum of 3 characters"), QMessageBox::Ok); @@ -245,7 +245,7 @@ void GenCertDialog::genPerson() else { /* Message Dialog */ - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, + QMessageBox::warning ( NULL, "Generate ID Failure", "Failed to Generate your new Certificate, maybe PGP password is wrong !", QMessageBox::Ok); @@ -312,7 +312,7 @@ void GenCertDialog::loadCertificates() else { /* some error msg */ - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, + QMessageBox::warning ( NULL, "Generate ID Failure", "Failed to Load your new Certificate!", QMessageBox::Ok); @@ -321,6 +321,6 @@ void GenCertDialog::loadCertificates() void GenCertDialog::infodlg() { - static InfoDialog *infodialog = new InfoDialog(); - infodialog->show(); + InfoDialog infodialog (this); + infodialog.exec (); } diff --git a/retroshare-gui/src/gui/NetworkDialog.cpp b/retroshare-gui/src/gui/NetworkDialog.cpp index 7d6fa1712..5a5024c03 100644 --- a/retroshare-gui/src/gui/NetworkDialog.cpp +++ b/retroshare-gui/src/gui/NetworkDialog.cpp @@ -75,8 +75,7 @@ RsCertId getNeighRsCertId(QTreeWidgetItem *i); /** Constructor */ NetworkDialog::NetworkDialog(QWidget *parent) -: RsAutoUpdatePage(10000,parent), // updates every 10 sec. - connectdialog(NULL) +: RsAutoUpdatePage(10000,parent) // updates every 10 sec. { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); @@ -89,9 +88,6 @@ NetworkDialog::NetworkDialog(QWidget *parent) connect( ui.unvalidGPGkeyWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( connecttreeWidgetCostumPopupMenu( QPoint ) ) ); connect( ui.unvalidGPGkeyWidget, SIGNAL( itemSelectionChanged()), ui.connecttreeWidget, SLOT( clearSelection() ) ); - /* create a single connect dialog */ - connectdialog = new ConnectDialog(); - connect(ui.infoLog, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayInfoLogMenu(const QPoint&))); connect(ui.showUnvalidKeys, SIGNAL(clicked()), this, SLOT(insertConnect())); @@ -210,8 +206,6 @@ void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point ) if (!wi) return; -// return ; - QMenu contextMnu( this ); QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier ); contextMnu.clear(); @@ -298,34 +292,21 @@ void NetworkDialog::peerdetails() ConfCertDialog::show(getCurrentNeighbour()->text(4).toStdString()); } -/** Shows Peer Information/Auth Dialog */ -void NetworkDialog::showpeerdetails(std::string id) -{ -#ifdef NET_DEBUG - std::cerr << "NetworkDialog::showpeerdetails()" << std::endl; -#endif - if ((connectdialog) && (connectdialog -> loadPeer(id))) - { - connectdialog->show(); - } -} - - /** Open a QFileDialog to browse for a pem/pqi file. */ void NetworkDialog::loadcert() { /* Create a new input dialog, which allows users to create files, too */ - QFileDialog *dialog = new QFileDialog(this, tr("Select a pem/pqi File")); - //dialog->setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); - //dialog->selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); - dialog->setFileMode(QFileDialog::AnyFile); - dialog->setReadOnly(false); + QFileDialog dialog (this, tr("Select a pem/pqi File")); + //dialog.setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); + //dialog.selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setReadOnly(false); /* Prompt the user to select a file or create a new one */ - if (!dialog->exec() || dialog->selectedFiles().isEmpty()) { + if (!dialog.exec() || dialog.selectedFiles().isEmpty()) { return; } - QString filename = QDir::convertSeparators(dialog->selectedFiles().at(0)); + QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0)); /* Check if the file exists */ QFile torrcFile(filename); @@ -383,8 +364,8 @@ void NetworkDialog::insertConnect() while (index < connectWidget->topLevelItemCount()) { std::string gpg_widget_id = (connectWidget->topLevelItem(index))->text(4).toStdString(); RsPeerDetails detail; - if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || detail.validLvl < 3) { - connectWidget->takeTopLevelItem(index); + if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || (detail.validLvl < 3 && !detail.accept_connection)) { + delete connectWidget->takeTopLevelItem(index); } else { index++; } @@ -393,8 +374,8 @@ void NetworkDialog::insertConnect() while (index < ui.unvalidGPGkeyWidget->topLevelItemCount()) { std::string gpg_widget_id = (ui.unvalidGPGkeyWidget->topLevelItem(index))->text(4).toStdString(); RsPeerDetails detail; - if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || detail.validLvl >= 3) { - ui.unvalidGPGkeyWidget->takeTopLevelItem(index); + if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || detail.validLvl >= 3 || detail.accept_connection) { + delete ui.unvalidGPGkeyWidget->takeTopLevelItem(index); } else { index++; } @@ -586,7 +567,7 @@ std::string NetworkDialog::loadneighbour() void NetworkDialog::addneighbour() { - QTreeWidgetItem *c = getCurrentNeighbour(); +// QTreeWidgetItem *c = getCurrentNeighbour(); #ifdef NET_DEBUG std::cerr << "NetworkDialog::addneighbour()" << std::endl; #endif @@ -597,7 +578,7 @@ void NetworkDialog::addneighbour() void NetworkDialog::authneighbour() { - QTreeWidgetItem *c = getCurrentNeighbour(); +// QTreeWidgetItem *c = getCurrentNeighbour(); #ifdef NET_DEBUG std::cerr << "NetworkDialog::authneighbour()" << std::endl; #endif @@ -611,17 +592,17 @@ void NetworkDialog::authneighbour() void NetworkDialog::on_actionAddFriend_activated() { /* Create a new input dialog, which allows users to create files, too */ - QFileDialog *dialog = new QFileDialog(this, tr("Select a pem/pqi File")); - //dialog->setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); - //dialog->selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); - dialog->setFileMode(QFileDialog::AnyFile); - dialog->setReadOnly(false); + QFileDialog dialog (this, tr("Select a pem/pqi File")); + //dialog.setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); + //dialog.selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setReadOnly(false); /* Prompt the user to select a file or create a new one */ - if (!dialog->exec() || dialog->selectedFiles().isEmpty()) { + if (!dialog.exec() || dialog.selectedFiles().isEmpty()) { return; } - QString filename = QDir::convertSeparators(dialog->selectedFiles().at(0)); + QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0)); /* Check if the file exists */ QFile torrcFile(filename); @@ -692,10 +673,8 @@ void NetworkDialog::on_actionClearLog_triggered() { void NetworkDialog::on_actionCreate_New_Profile_activated() { - static GenCertDialog *gencertdialog = new GenCertDialog(); - gencertdialog->show(); - - +// GenCertDialog gencertdialog (this); +// gencertdialog.exec (); } void NetworkDialog::displayInfoLogMenu(const QPoint& pos) { diff --git a/retroshare-gui/src/gui/NetworkDialog.h b/retroshare-gui/src/gui/NetworkDialog.h index b6aa33900..655890787 100644 --- a/retroshare-gui/src/gui/NetworkDialog.h +++ b/retroshare-gui/src/gui/NetworkDialog.h @@ -44,8 +44,6 @@ public: NetworkDialog(QWidget *parent = 0); /** Default Destructor */ - void showpeerdetails(std::string id); - //void load(); virtual void updateDisplay() ; // overloaded from RsAutoUpdatePage @@ -113,9 +111,6 @@ private: QAction* loadcertAct; QAction* exportcertAct; - /* connection dialog */ - ConnectDialog *connectdialog; - QTreeWidget *connecttreeWidget; class NetworkView *networkview; diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 834a9f5ce..d21064161 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -40,7 +40,6 @@ #include "profile/ProfileWidget.h" #include "profile/StatusMessage.h" -#include "GenCertDialog.h" #include "gui/connect/ConnectFriendWizard.h" #include "gui/forums/CreateForum.h" #include "gui/channels/CreateChannel.h" diff --git a/retroshare-gui/src/gui/StartDialog.cpp b/retroshare-gui/src/gui/StartDialog.cpp index 3a953a110..458106f9e 100644 --- a/retroshare-gui/src/gui/StartDialog.cpp +++ b/retroshare-gui/src/gui/StartDialog.cpp @@ -22,7 +22,6 @@ #include #include #include "StartDialog.h" -#include "GenCertDialog.h" #include "InfoDialog.h" #include "LogoBar.h" #include @@ -132,7 +131,7 @@ void StartDialog::loadPerson() if (pgpidx < 0) { /* Message Dialog */ - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, + QMessageBox::warning ( NULL, "Load Person Failure", "Missing PGP Certificate", QMessageBox::Ok); @@ -164,7 +163,7 @@ void StartDialog::loadCertificates() else { /* some error msg */ - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, + QMessageBox::warning ( NULL, tr("Login Failure"), tr("Maybe password is wrong"), QMessageBox::Ok); @@ -175,15 +174,12 @@ void StartDialog::loadCertificates() void StartDialog::on_labelProfile_linkActivated(QString link) { - //static GenCertDialog *gencertdialog = new GenCertDialog(); - //gencertdialog->show(); - QMessageBox::StandardButton sb = QMessageBox::question ( NULL, tr("Create a New Profile"), tr("This will generate a new Profile\n Are you sure you want to continue"), - (QMessageBox::Ok | QMessageBox::No)); + (QMessageBox::Yes | QMessageBox::No)); - if (sb == QMessageBox::Ok) + if (sb == QMessageBox::Yes) { reqNewCert = true; close(); @@ -192,8 +188,8 @@ void StartDialog::on_labelProfile_linkActivated(QString link) void StartDialog::on_labelInfo_linkActivated(QString link) { - static InfoDialog *infodialog = new InfoDialog(); - infodialog->show(); + InfoDialog infodialog (this); + infodialog.exec (); } bool StartDialog::requestedNewCert() @@ -209,7 +205,7 @@ void StartDialog::notSecureWarning() { /* some error msg */ if(ui.autologin_checkbox->isChecked()){ - QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, + QMessageBox::warning ( NULL, tr("Insecure"), tr("Auto Login is not so much secure:\n - Your SSL certificate will be stored unprotected. \n - Your PGP key will however not be stored.\nThis choice be reverted in settings."), QMessageBox::Ok); diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 37ea3120d..c60a5baed 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -91,6 +91,7 @@ int main(int argc, char *argv[]) /* if we're logged in */ genCert = sd->requestedNewCert(); + delete (sd); } else { @@ -99,19 +100,8 @@ int main(int argc, char *argv[]) if (genCert) { - GenCertDialog *gd = new GenCertDialog(); - - gd->show(); - - while(gd -> isVisible()) - { - rshare.processEvents(); -#ifdef WIN32 - Sleep(10); -#else // __LINUX__ - usleep(10000); -#endif - } + GenCertDialog gd; + gd.exec (); } } else