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"
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
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 ( ) ;
2010-01-13 16:08:46 -05:00
ui . loadButton - > setFocus ( ) ;
2010-04-08 07:55:10 -04:00
2007-11-14 22:18:48 -05:00
connect ( ui . loadButton , SIGNAL ( clicked ( ) ) , this , SLOT ( loadPerson ( ) ) ) ;
2010-04-08 07:55:10 -04:00
connect ( ui . autologin_checkbox , SIGNAL ( clicked ( ) ) , this , SLOT ( notSecureWarning ( ) ) ) ;
2007-11-14 22:18:48 -05:00
/* load the Certificate File name */
std : : string userName ;
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 ) ) ;
2010-01-18 17:44:09 -05:00
std : : string gpgid , name , email , location ;
RsInit : : getAccountDetails ( * it , gpgid , name , email , location ) ;
2010-02-20 08:36:30 -05:00
QString accountName = QString : : fromStdString ( name + " ( " ) + QString : : fromStdString ( gpgid ) . right ( 8 ) + " ) - " + QString : : fromStdString ( location ) ;
2009-07-30 17:48:54 -04:00
ui . loadName - > addItem ( accountName , userData ) ;
if ( preferedId = = * it )
{
pidx = i ;
}
}
}
if ( pidx > 0 )
{
ui . loadName - > setCurrentIndex ( pidx ) ;
}
2007-11-14 22:18:48 -05:00
}
/**
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 = " " ;
2009-05-23 11:13:01 -04:00
int pgpidx = ui . loadName - > currentIndex ( ) ;
if ( pgpidx < 0 )
{
/* Message Dialog */
2010-05-02 09:12:46 -04:00
QMessageBox : : warning ( NULL ,
2009-05-23 11:13:01 -04:00
" 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 ) ;
}
2010-01-13 16:08:46 -05:00
RsInit : : LoadPassword ( accountId , " " ) ;
2007-11-14 22:18:48 -05:00
loadCertificates ( ) ;
}
void StartDialog : : loadCertificates ( )
{
/* Final stage of loading */
2010-04-08 07:55:10 -04:00
if ( RsInit : : LoadCertificates ( ui . autologin_checkbox - > isChecked ( ) ) )
2007-11-14 22:18:48 -05:00
{
close ( ) ;
}
else
{
/* some error msg */
2010-05-02 09:12:46 -04:00
QMessageBox : : warning ( NULL ,
2010-02-09 14:10:42 -05:00
tr ( " Login Failure " ) ,
tr ( " Maybe password is wrong " ) ,
2007-11-14 22:18:48 -05:00
QMessageBox : : Ok ) ;
}
}
2010-04-08 07:55:10 -04:00
2009-12-23 11:17:36 -05:00
void StartDialog : : on_labelProfile_linkActivated ( QString link )
2007-11-14 22:18:48 -05:00
{
QMessageBox : : StandardButton sb = QMessageBox : : question ( NULL ,
2010-04-08 07:55:10 -04:00
tr ( " Create a New Profile " ) ,
2010-02-09 14:10:42 -05:00
tr ( " This will generate a new Profile \n Are you sure you want to continue " ) ,
2010-05-02 09:12:46 -04:00
( QMessageBox : : Yes | QMessageBox : : No ) ) ;
2007-11-14 22:18:48 -05:00
2010-05-02 09:12:46 -04:00
if ( sb = = QMessageBox : : Yes )
2007-11-14 22:18:48 -05:00
{
reqNewCert = true ;
close ( ) ;
}
}
2009-12-23 11:17:36 -05:00
void StartDialog : : on_labelInfo_linkActivated ( QString link )
2009-09-22 13:23:41 -04:00
{
2010-05-02 09:12:46 -04:00
InfoDialog infodialog ( this ) ;
infodialog . exec ( ) ;
2009-09-22 13:23:41 -04:00
}
2009-12-23 11:17:36 -05:00
bool StartDialog : : requestedNewCert ( )
2007-11-14 22:18:48 -05:00
{
return reqNewCert ;
}
LogoBar & StartDialog : : getLogoBar ( ) const {
return * _rsLogoBar ;
}
2010-04-08 07:55:10 -04:00
void StartDialog : : notSecureWarning ( ) {
/* some error msg */
if ( ui . autologin_checkbox - > isChecked ( ) ) {
2010-05-02 09:12:46 -04:00
QMessageBox : : warning ( NULL ,
2010-04-08 07:55:10 -04:00
tr ( " Insecure " ) ,
2010-04-19 17:50:03 -04:00
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. \n This choice be reverted in settings. " ) ,
2010-04-08 07:55:10 -04:00
QMessageBox : : Ok ) ;
}
return ;
}