2007-11-14 22:18:48 -05:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, 2007 crypton
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include <rshare.h>
|
2009-02-08 09:30:28 -05:00
|
|
|
#include <rsiface/rsinit.h>
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "StartDialog.h"
|
|
|
|
#include "GenCertDialog.h"
|
2009-09-22 13:23:41 -04:00
|
|
|
#include "InfoDialog.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "LogoBar.h"
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include "util/Widget.h"
|
|
|
|
|
|
|
|
/* Define the format used for displaying the date and time */
|
|
|
|
#define DATETIME_FMT "MMM dd hh:mm:ss"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Default constructor */
|
2009-02-08 09:30:28 -05:00
|
|
|
StartDialog::StartDialog(QWidget *parent, Qt::WFlags flags)
|
|
|
|
: QMainWindow(parent, flags), reqNewCert(false)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/* Invoke Qt Designer generated QObject setup routine */
|
|
|
|
ui.setupUi(this);
|
2008-11-07 17:11:33 -05:00
|
|
|
|
|
|
|
/**
|
2007-11-14 22:18:48 -05:00
|
|
|
#if (QT_VERSION >= 040300)
|
|
|
|
skinobject = new QSkinObject(this);
|
|
|
|
skinobject->startSkinning();
|
2008-11-07 17:11:33 -05:00
|
|
|
#endif**/
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
RshareSettings config;
|
|
|
|
config.loadWidgetInformation(this);
|
|
|
|
|
|
|
|
_rsLogoBar = NULL;
|
|
|
|
|
|
|
|
//LogoBar
|
|
|
|
_rsLogoBar = new LogoBar(ui.callBarFrame);
|
|
|
|
Widget::createLayout(ui.callBarFrame)->addWidget(_rsLogoBar);
|
|
|
|
|
|
|
|
/* Create Bandwidth Graph related QObjects */
|
|
|
|
_settings = new RshareSettings();
|
|
|
|
|
2009-08-13 08:16:35 -04:00
|
|
|
ui.loadPasswd->setFocus();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
//connect(ui.genButton, SIGNAL(clicked()), this, SLOT(genPerson()));
|
|
|
|
connect(ui.loadButton, SIGNAL(clicked()), this, SLOT(loadPerson()));
|
|
|
|
connect(ui.loadPasswd, SIGNAL(returnPressed()), this, SLOT(loadPerson()));
|
2009-08-02 10:11:54 -04:00
|
|
|
connect(ui.loadGPGPasswd, SIGNAL(returnPressed()), this, SLOT(loadPerson()));
|
2007-11-14 22:18:48 -05:00
|
|
|
//connect(ui.selectButton, SIGNAL(clicked()), this, SLOT(selectFriend()));
|
|
|
|
//connect(ui.friendBox, SIGNAL(stateChanged(int)), this, SLOT(checkChanged(int)));
|
|
|
|
connect(ui.createaccountButton, SIGNAL(clicked()), this, SLOT(createnewaccount()));
|
2009-09-22 13:23:41 -04:00
|
|
|
connect(ui.infoButton,SIGNAL(clicked()), this, SLOT(infodlg()));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* load the Certificate File name */
|
|
|
|
std::string userName;
|
|
|
|
|
2009-05-23 11:13:01 -04:00
|
|
|
#ifdef RS_USE_PGPSSL
|
2009-08-18 08:43:33 -04:00
|
|
|
|
2009-08-19 05:31:33 -04:00
|
|
|
#ifndef WINDOWS_SYS /* UNIX */
|
|
|
|
//hide autologin because it's not functionnal on other than windows system
|
|
|
|
ui.autoBox->hide();
|
2009-10-27 16:47:19 -04:00
|
|
|
|
|
|
|
//comment those to show the pgp and ssl password dialog
|
|
|
|
ui.loadPasswd->hide();
|
|
|
|
ui.label_4->hide();
|
|
|
|
|
2009-10-27 16:50:30 -04:00
|
|
|
std::string gpgEngineFileName;
|
|
|
|
if (RsInit::getPGPEngineFileName(gpgEngineFileName)) {
|
|
|
|
std::cerr << "RsInit::getPGPEngineFileName() : " << gpgEngineFileName << std::endl;
|
|
|
|
//if fileName contains gpg2 then the passphrase is set by pinentry and not by RS
|
|
|
|
QString *fileName = new QString(gpgEngineFileName.c_str());
|
|
|
|
if (fileName->contains("gpg2")) {
|
|
|
|
ui.loadGPGPasswd->hide();
|
|
|
|
ui.label_5->hide();
|
|
|
|
}
|
|
|
|
}
|
2009-08-19 05:31:33 -04:00
|
|
|
#endif
|
2009-08-18 08:43:33 -04:00
|
|
|
|
2009-05-23 11:13:01 -04:00
|
|
|
/* get all available pgp private certificates....
|
|
|
|
* mark last one as default.
|
|
|
|
*/
|
2009-07-30 17:48:54 -04:00
|
|
|
std::list<std::string> accountIds;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
std::string preferedId;
|
|
|
|
RsInit::getPreferedAccountId(preferedId);
|
|
|
|
int pidx = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (RsInit::getAccountIds(accountIds))
|
|
|
|
{
|
|
|
|
for(it = accountIds.begin(), i = 0; it != accountIds.end(); it++, i++)
|
|
|
|
{
|
|
|
|
const QVariant & userData = QVariant(QString::fromStdString(*it));
|
|
|
|
std::string gpgid, name, email, sslname;
|
|
|
|
RsInit::getAccountDetails(*it, gpgid, name, email, sslname);
|
|
|
|
QString accountName = QString::fromStdString(name);
|
|
|
|
accountName += "/";
|
|
|
|
accountName += QString::fromStdString(sslname);
|
|
|
|
ui.loadName->addItem(accountName, userData);
|
|
|
|
|
|
|
|
if (preferedId == *it)
|
|
|
|
{
|
|
|
|
pidx = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pidx > 0)
|
|
|
|
{
|
|
|
|
ui.loadName->setCurrentIndex(pidx);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2009-05-23 11:13:01 -04:00
|
|
|
std::list<std::string> pgpIds;
|
|
|
|
std::list<std::string>::iterator it;
|
2009-07-30 17:48:54 -04:00
|
|
|
if (RsInit::GetPGPLogins(pgpIds))
|
2009-05-23 11:13:01 -04:00
|
|
|
{
|
|
|
|
for(it = pgpIds.begin(); it != pgpIds.end(); it++)
|
|
|
|
{
|
|
|
|
const QVariant & userData = QVariant(QString::fromStdString(*it));
|
|
|
|
std::string name, email;
|
2009-07-30 17:48:54 -04:00
|
|
|
RsInit::GetPGPLoginDetails(*it, name, email);
|
2009-05-23 11:13:01 -04:00
|
|
|
ui.loadName->addItem(QString::fromStdString(name), userData);
|
|
|
|
}
|
|
|
|
}
|
2009-07-30 17:48:54 -04:00
|
|
|
#endif
|
|
|
|
|
2009-05-23 11:13:01 -04:00
|
|
|
#else
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
if (RsInit::ValidateCertificate(userName))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/* just need to enter password */
|
2009-05-23 11:13:01 -04:00
|
|
|
ui.loadName->addItem(QString::fromStdString(userName));
|
|
|
|
//ui.loadName->setText(QString::fromStdString(userName));
|
2007-11-14 22:18:48 -05:00
|
|
|
ui.loadPasswd->setFocus(Qt::OtherFocusReason);
|
|
|
|
ui.loadButton -> setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* need to generate new user */
|
2009-05-23 11:13:01 -04:00
|
|
|
ui.loadName->addItem("<No Existing User>");
|
|
|
|
//ui.loadName->setText("<No Existing User>");
|
2007-11-14 22:18:48 -05:00
|
|
|
ui.loadButton -> setEnabled(false);
|
|
|
|
//ui.genName->setFocus(Qt::OtherFocusReason);
|
|
|
|
}
|
2009-05-17 08:58:15 -04:00
|
|
|
#ifndef Q_WS_WIN
|
|
|
|
ui.autoBox->setChecked(false) ;
|
|
|
|
ui.autoBox->setEnabled(false) ;
|
|
|
|
#endif
|
2009-05-23 11:13:01 -04:00
|
|
|
#endif
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
//ui.genFriend -> setText("<None Selected>");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Overloads the default show() slot so we can set opacity*/
|
|
|
|
|
|
|
|
void StartDialog::show()
|
|
|
|
{
|
|
|
|
//loadSettings();
|
|
|
|
if(!this->isVisible()) {
|
|
|
|
QMainWindow::show();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartDialog::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
|
|
|
RshareSettings config;
|
|
|
|
config.saveWidgetInformation(this);
|
|
|
|
|
|
|
|
QWidget::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartDialog::closeinfodlg()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void StartDialog::loadPerson()
|
|
|
|
{
|
2009-07-30 17:48:54 -04:00
|
|
|
std::string accountId = "";
|
2007-11-14 22:18:48 -05:00
|
|
|
std::string passwd = ui.loadPasswd->text().toStdString();
|
2009-05-23 11:13:01 -04:00
|
|
|
#ifdef RS_USE_PGPSSL
|
|
|
|
|
|
|
|
std::string gpgPasswd = ui.loadGPGPasswd->text().toStdString();
|
|
|
|
int pgpidx = ui.loadName->currentIndex();
|
|
|
|
if (pgpidx < 0)
|
|
|
|
{
|
|
|
|
/* Message Dialog */
|
|
|
|
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL,
|
|
|
|
"Load Person Failure",
|
|
|
|
"Missing PGP Certificate",
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant data = ui.loadName->itemData(pgpidx);
|
2009-07-30 17:48:54 -04:00
|
|
|
accountId = (data.toString()).toStdString();
|
2009-05-23 11:13:01 -04:00
|
|
|
|
2009-07-30 17:48:54 -04:00
|
|
|
std::string gpgId, gpgName, gpgEmail, sslName;
|
|
|
|
if (RsInit::getAccountDetails(accountId,
|
|
|
|
gpgId, gpgName, gpgEmail, sslName))
|
|
|
|
{
|
|
|
|
RsInit::SelectGPGAccount(gpgId);
|
|
|
|
RsInit::LoadGPGPassword(gpgPasswd);
|
|
|
|
}
|
2009-05-23 11:13:01 -04:00
|
|
|
#else
|
|
|
|
#endif
|
2009-07-30 17:48:54 -04:00
|
|
|
RsInit::LoadPassword(accountId, passwd);
|
2007-11-14 22:18:48 -05:00
|
|
|
loadCertificates();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartDialog::loadCertificates()
|
|
|
|
{
|
|
|
|
bool autoSave = (Qt::Checked == ui.autoBox -> checkState());
|
|
|
|
/* Final stage of loading */
|
2009-02-08 09:30:28 -05:00
|
|
|
if (RsInit::LoadCertificates(autoSave))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* some error msg */
|
|
|
|
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL,
|
|
|
|
"Login Failure",
|
|
|
|
"*** Wrong Password ***",
|
|
|
|
QMessageBox::Ok);
|
|
|
|
ui.loadPasswd->setText("");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StartDialog::createnewaccount()
|
|
|
|
{
|
|
|
|
//static GenCertDialog *gencertdialog = new GenCertDialog();
|
|
|
|
//gencertdialog->show();
|
|
|
|
|
|
|
|
QMessageBox::StandardButton sb = QMessageBox::question ( NULL,
|
2009-08-04 19:37:01 -04:00
|
|
|
"Create a New Profil",
|
|
|
|
"This will generate a new Profile\n Are you sure you want to continue",
|
2007-11-14 22:18:48 -05:00
|
|
|
(QMessageBox::Ok | QMessageBox::No));
|
|
|
|
|
|
|
|
if (sb == QMessageBox::Ok)
|
|
|
|
{
|
|
|
|
reqNewCert = true;
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 13:23:41 -04:00
|
|
|
|
|
|
|
void StartDialog::infodlg()
|
|
|
|
{
|
|
|
|
static InfoDialog *infodialog = new InfoDialog();
|
|
|
|
infodialog->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
bool StartDialog::requestedNewCert()
|
|
|
|
{
|
|
|
|
return reqNewCert;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LogoBar & StartDialog::getLogoBar() const {
|
|
|
|
return *_rsLogoBar;
|
|
|
|
}
|
|
|
|
|