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
This commit is contained in:
thunder2 2010-05-02 13:12:46 +00:00
parent 8957fb919c
commit 8ce338c49c
6 changed files with 40 additions and 81 deletions

View file

@ -148,7 +148,7 @@ void GenCertDialog::genPerson()
if (!genNewGPGKey) { if (!genNewGPGKey) {
if (ui.location_input->text().length() < 3) { if (ui.location_input->text().length() < 3) {
/* Message Dialog */ /* Message Dialog */
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL,
tr("Generate GPG key Failure"), tr("Generate GPG key Failure"),
tr("Location field is required with a minimum of 3 characters"), tr("Location field is required with a minimum of 3 characters"),
QMessageBox::Ok); QMessageBox::Ok);
@ -158,7 +158,7 @@ void GenCertDialog::genPerson()
if (pgpidx < 0) if (pgpidx < 0)
{ {
/* Message Dialog */ /* Message Dialog */
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL,
"Generate ID Failure", "Generate ID Failure",
"Missing PGP Certificate", "Missing PGP Certificate",
QMessageBox::Ok); QMessageBox::Ok);
@ -170,7 +170,7 @@ void GenCertDialog::genPerson()
if (ui.password_input->text().length() < 3 || ui.name_input->text().length() < 3 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) { || ui.email_input->text().length() < 3 || ui.location_label->text().length() < 3) {
/* Message Dialog */ /* Message Dialog */
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL,
tr("Generate GPG key Failure"), tr("Generate GPG key Failure"),
tr("All fields are required with a minimum of 3 characters"), tr("All fields are required with a minimum of 3 characters"),
QMessageBox::Ok); QMessageBox::Ok);
@ -245,7 +245,7 @@ void GenCertDialog::genPerson()
else else
{ {
/* Message Dialog */ /* Message Dialog */
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL,
"Generate ID Failure", "Generate ID Failure",
"Failed to Generate your new Certificate, maybe PGP password is wrong !", "Failed to Generate your new Certificate, maybe PGP password is wrong !",
QMessageBox::Ok); QMessageBox::Ok);
@ -312,7 +312,7 @@ void GenCertDialog::loadCertificates()
else else
{ {
/* some error msg */ /* some error msg */
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL,
"Generate ID Failure", "Generate ID Failure",
"Failed to Load your new Certificate!", "Failed to Load your new Certificate!",
QMessageBox::Ok); QMessageBox::Ok);
@ -321,6 +321,6 @@ void GenCertDialog::loadCertificates()
void GenCertDialog::infodlg() void GenCertDialog::infodlg()
{ {
static InfoDialog *infodialog = new InfoDialog(); InfoDialog infodialog (this);
infodialog->show(); infodialog.exec ();
} }

View file

@ -75,8 +75,7 @@ RsCertId getNeighRsCertId(QTreeWidgetItem *i);
/** Constructor */ /** Constructor */
NetworkDialog::NetworkDialog(QWidget *parent) NetworkDialog::NetworkDialog(QWidget *parent)
: RsAutoUpdatePage(10000,parent), // updates every 10 sec. : RsAutoUpdatePage(10000,parent) // updates every 10 sec.
connectdialog(NULL)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); 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( customContextMenuRequested( QPoint ) ), this, SLOT( connecttreeWidgetCostumPopupMenu( QPoint ) ) );
connect( ui.unvalidGPGkeyWidget, SIGNAL( itemSelectionChanged()), ui.connecttreeWidget, SLOT( clearSelection() ) ); 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.infoLog, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayInfoLogMenu(const QPoint&)));
connect(ui.showUnvalidKeys, SIGNAL(clicked()), this, SLOT(insertConnect())); connect(ui.showUnvalidKeys, SIGNAL(clicked()), this, SLOT(insertConnect()));
@ -210,8 +206,6 @@ void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point )
if (!wi) if (!wi)
return; return;
// return ;
QMenu contextMnu( this ); QMenu contextMnu( this );
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier ); QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
contextMnu.clear(); contextMnu.clear();
@ -298,34 +292,21 @@ void NetworkDialog::peerdetails()
ConfCertDialog::show(getCurrentNeighbour()->text(4).toStdString()); 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. */ /** Open a QFileDialog to browse for a pem/pqi file. */
void NetworkDialog::loadcert() void NetworkDialog::loadcert()
{ {
/* Create a new input dialog, which allows users to create files, too */ /* Create a new input dialog, which allows users to create files, too */
QFileDialog *dialog = new QFileDialog(this, tr("Select a pem/pqi File")); QFileDialog dialog (this, tr("Select a pem/pqi File"));
//dialog->setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); //dialog.setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir());
//dialog->selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); //dialog.selectFile(QFileInfo(ui.lineTorConfig->text()).fileName());
dialog->setFileMode(QFileDialog::AnyFile); dialog.setFileMode(QFileDialog::AnyFile);
dialog->setReadOnly(false); dialog.setReadOnly(false);
/* Prompt the user to select a file or create a new one */ /* 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; return;
} }
QString filename = QDir::convertSeparators(dialog->selectedFiles().at(0)); QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0));
/* Check if the file exists */ /* Check if the file exists */
QFile torrcFile(filename); QFile torrcFile(filename);
@ -383,8 +364,8 @@ void NetworkDialog::insertConnect()
while (index < connectWidget->topLevelItemCount()) { while (index < connectWidget->topLevelItemCount()) {
std::string gpg_widget_id = (connectWidget->topLevelItem(index))->text(4).toStdString(); std::string gpg_widget_id = (connectWidget->topLevelItem(index))->text(4).toStdString();
RsPeerDetails detail; RsPeerDetails detail;
if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || detail.validLvl < 3) { if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || (detail.validLvl < 3 && !detail.accept_connection)) {
connectWidget->takeTopLevelItem(index); delete connectWidget->takeTopLevelItem(index);
} else { } else {
index++; index++;
} }
@ -393,8 +374,8 @@ void NetworkDialog::insertConnect()
while (index < ui.unvalidGPGkeyWidget->topLevelItemCount()) { while (index < ui.unvalidGPGkeyWidget->topLevelItemCount()) {
std::string gpg_widget_id = (ui.unvalidGPGkeyWidget->topLevelItem(index))->text(4).toStdString(); std::string gpg_widget_id = (ui.unvalidGPGkeyWidget->topLevelItem(index))->text(4).toStdString();
RsPeerDetails detail; RsPeerDetails detail;
if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || detail.validLvl >= 3) { if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || detail.validLvl >= 3 || detail.accept_connection) {
ui.unvalidGPGkeyWidget->takeTopLevelItem(index); delete ui.unvalidGPGkeyWidget->takeTopLevelItem(index);
} else { } else {
index++; index++;
} }
@ -586,7 +567,7 @@ std::string NetworkDialog::loadneighbour()
void NetworkDialog::addneighbour() void NetworkDialog::addneighbour()
{ {
QTreeWidgetItem *c = getCurrentNeighbour(); // QTreeWidgetItem *c = getCurrentNeighbour();
#ifdef NET_DEBUG #ifdef NET_DEBUG
std::cerr << "NetworkDialog::addneighbour()" << std::endl; std::cerr << "NetworkDialog::addneighbour()" << std::endl;
#endif #endif
@ -597,7 +578,7 @@ void NetworkDialog::addneighbour()
void NetworkDialog::authneighbour() void NetworkDialog::authneighbour()
{ {
QTreeWidgetItem *c = getCurrentNeighbour(); // QTreeWidgetItem *c = getCurrentNeighbour();
#ifdef NET_DEBUG #ifdef NET_DEBUG
std::cerr << "NetworkDialog::authneighbour()" << std::endl; std::cerr << "NetworkDialog::authneighbour()" << std::endl;
#endif #endif
@ -611,17 +592,17 @@ void NetworkDialog::authneighbour()
void NetworkDialog::on_actionAddFriend_activated() void NetworkDialog::on_actionAddFriend_activated()
{ {
/* Create a new input dialog, which allows users to create files, too */ /* Create a new input dialog, which allows users to create files, too */
QFileDialog *dialog = new QFileDialog(this, tr("Select a pem/pqi File")); QFileDialog dialog (this, tr("Select a pem/pqi File"));
//dialog->setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); //dialog.setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir());
//dialog->selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); //dialog.selectFile(QFileInfo(ui.lineTorConfig->text()).fileName());
dialog->setFileMode(QFileDialog::AnyFile); dialog.setFileMode(QFileDialog::AnyFile);
dialog->setReadOnly(false); dialog.setReadOnly(false);
/* Prompt the user to select a file or create a new one */ /* 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; return;
} }
QString filename = QDir::convertSeparators(dialog->selectedFiles().at(0)); QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0));
/* Check if the file exists */ /* Check if the file exists */
QFile torrcFile(filename); QFile torrcFile(filename);
@ -692,10 +673,8 @@ void NetworkDialog::on_actionClearLog_triggered() {
void NetworkDialog::on_actionCreate_New_Profile_activated() void NetworkDialog::on_actionCreate_New_Profile_activated()
{ {
static GenCertDialog *gencertdialog = new GenCertDialog(); // GenCertDialog gencertdialog (this);
gencertdialog->show(); // gencertdialog.exec ();
} }
void NetworkDialog::displayInfoLogMenu(const QPoint& pos) { void NetworkDialog::displayInfoLogMenu(const QPoint& pos) {

View file

@ -44,8 +44,6 @@ public:
NetworkDialog(QWidget *parent = 0); NetworkDialog(QWidget *parent = 0);
/** Default Destructor */ /** Default Destructor */
void showpeerdetails(std::string id);
//void load(); //void load();
virtual void updateDisplay() ; // overloaded from RsAutoUpdatePage virtual void updateDisplay() ; // overloaded from RsAutoUpdatePage
@ -113,9 +111,6 @@ private:
QAction* loadcertAct; QAction* loadcertAct;
QAction* exportcertAct; QAction* exportcertAct;
/* connection dialog */
ConnectDialog *connectdialog;
QTreeWidget *connecttreeWidget; QTreeWidget *connecttreeWidget;
class NetworkView *networkview; class NetworkView *networkview;

View file

@ -40,7 +40,6 @@
#include "profile/ProfileWidget.h" #include "profile/ProfileWidget.h"
#include "profile/StatusMessage.h" #include "profile/StatusMessage.h"
#include "GenCertDialog.h"
#include "gui/connect/ConnectFriendWizard.h" #include "gui/connect/ConnectFriendWizard.h"
#include "gui/forums/CreateForum.h" #include "gui/forums/CreateForum.h"
#include "gui/channels/CreateChannel.h" #include "gui/channels/CreateChannel.h"

View file

@ -22,7 +22,6 @@
#include <rshare.h> #include <rshare.h>
#include <rsiface/rsinit.h> #include <rsiface/rsinit.h>
#include "StartDialog.h" #include "StartDialog.h"
#include "GenCertDialog.h"
#include "InfoDialog.h" #include "InfoDialog.h"
#include "LogoBar.h" #include "LogoBar.h"
#include <QFileDialog> #include <QFileDialog>
@ -132,7 +131,7 @@ void StartDialog::loadPerson()
if (pgpidx < 0) if (pgpidx < 0)
{ {
/* Message Dialog */ /* Message Dialog */
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL,
"Load Person Failure", "Load Person Failure",
"Missing PGP Certificate", "Missing PGP Certificate",
QMessageBox::Ok); QMessageBox::Ok);
@ -164,7 +163,7 @@ void StartDialog::loadCertificates()
else else
{ {
/* some error msg */ /* some error msg */
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL,
tr("Login Failure"), tr("Login Failure"),
tr("Maybe password is wrong"), tr("Maybe password is wrong"),
QMessageBox::Ok); QMessageBox::Ok);
@ -175,15 +174,12 @@ void StartDialog::loadCertificates()
void StartDialog::on_labelProfile_linkActivated(QString link) void StartDialog::on_labelProfile_linkActivated(QString link)
{ {
//static GenCertDialog *gencertdialog = new GenCertDialog();
//gencertdialog->show();
QMessageBox::StandardButton sb = QMessageBox::question ( NULL, QMessageBox::StandardButton sb = QMessageBox::question ( NULL,
tr("Create a New Profile"), tr("Create a New Profile"),
tr("This will generate a new Profile\n Are you sure you want to continue"), 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; reqNewCert = true;
close(); close();
@ -192,8 +188,8 @@ void StartDialog::on_labelProfile_linkActivated(QString link)
void StartDialog::on_labelInfo_linkActivated(QString link) void StartDialog::on_labelInfo_linkActivated(QString link)
{ {
static InfoDialog *infodialog = new InfoDialog(); InfoDialog infodialog (this);
infodialog->show(); infodialog.exec ();
} }
bool StartDialog::requestedNewCert() bool StartDialog::requestedNewCert()
@ -209,7 +205,7 @@ void StartDialog::notSecureWarning() {
/* some error msg */ /* some error msg */
if(ui.autologin_checkbox->isChecked()){ if(ui.autologin_checkbox->isChecked()){
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL, QMessageBox::warning ( NULL,
tr("Insecure"), 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."), 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); QMessageBox::Ok);

View file

@ -91,6 +91,7 @@ int main(int argc, char *argv[])
/* if we're logged in */ /* if we're logged in */
genCert = sd->requestedNewCert(); genCert = sd->requestedNewCert();
delete (sd);
} }
else else
{ {
@ -99,19 +100,8 @@ int main(int argc, char *argv[])
if (genCert) if (genCert)
{ {
GenCertDialog *gd = new GenCertDialog(); GenCertDialog gd;
gd.exec ();
gd->show();
while(gd -> isVisible())
{
rshare.processEvents();
#ifdef WIN32
Sleep(10);
#else // __LINUX__
usleep(10000);
#endif
}
} }
} }
else else