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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2017-05-08 04:51:15 -04:00
# include <QMessageBox>
# include "rshare.h"
# include "retroshare/rsinit.h"
2007-11-14 22:18:48 -05:00
# include "StartDialog.h"
# include "LogoBar.h"
2017-05-08 04:51:15 -04:00
# include "retroshare/rsnotify.h"
2010-05-11 16:02:52 -04:00
# include "settings/rsharesettings.h"
2007-11-14 22:18:48 -05:00
2012-08-22 09:44:23 -04:00
# include <iostream>
2007-11-14 22:18:48 -05:00
/** Default constructor */
2012-10-31 21:07:36 -04:00
StartDialog : : StartDialog ( QWidget * parent )
2012-11-06 18:26:47 -05:00
: QDialog ( parent , Qt : : WindowSystemMenuHint | Qt : : WindowTitleHint | Qt : : WindowMinimizeButtonHint | Qt : : WindowCloseButtonHint ) , reqNewCert ( false )
2007-11-14 22:18:48 -05:00
{
2012-08-22 09:44:23 -04:00
/* Invoke Qt Designer generated QObject setup routine */
ui . setupUi ( this ) ;
2008-11-07 17:11:33 -05:00
2016-12-03 14:04:25 -05:00
# ifdef RS_AUTOLOGIN
connect ( ui . autologin_checkbox , SIGNAL ( clicked ( ) ) , this , SLOT ( notSecureWarning ( ) ) ) ;
# else
ui . autologin_checkbox - > setHidden ( true ) ;
# endif
2012-08-22 09:44:23 -04:00
Settings - > loadWidgetInformation ( this ) ;
2010-01-13 16:08:46 -05:00
2009-05-23 11:13:01 -04:00
/* get all available pgp private certificates....
2012-08-22 09:44:23 -04:00
* mark last one as default .
*/
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > accountIds ;
std : : list < RsPeerId > : : iterator it ;
RsPeerId preferedId ;
2014-01-17 21:35:06 -05:00
RsAccounts : : GetPreferredAccountId ( preferedId ) ;
2009-07-30 17:48:54 -04:00
int pidx = - 1 ;
int i ;
2014-01-17 21:35:06 -05:00
if ( RsAccounts : : GetAccountIds ( accountIds ) )
2009-07-30 17:48:54 -04:00
{
2014-10-21 18:33:02 -04:00
for ( it = accountIds . begin ( ) , i = 0 ; it ! = accountIds . end ( ) ; + + it , + + i )
2009-07-30 17:48:54 -04:00
{
2014-03-17 16:56:06 -04:00
const QVariant & userData = QVariant ( QString : : fromStdString ( ( * it ) . toStdString ( ) ) ) ;
RsPgpId gpgid ;
2014-12-30 06:11:08 -05:00
std : : string name , email , node ;
RsAccounts : : GetAccountDetails ( * it , gpgid , name , email , node ) ;
QString accountName = QString : : fromUtf8 ( name . c_str ( ) ) + " ( " + QString : : fromStdString ( gpgid . toStdString ( ) ) . right ( 8 ) + " ) - " + QString : : fromUtf8 ( node . c_str ( ) ) ;
2012-08-22 09:44:23 -04:00
ui . loadName - > addItem ( accountName , userData ) ;
2009-07-30 17:48:54 -04:00
if ( preferedId = = * it )
{
pidx = i ;
}
}
}
2017-05-10 13:06:03 -04:00
QObject : : connect ( ui . loadName , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( updateSelectedProfile ( int ) ) ) ;
QObject : : connect ( ui . password_input , SIGNAL ( returnPressed ( ) ) , this , SLOT ( loadPerson ( ) ) ) ;
QObject : : connect ( ui . loadButton , SIGNAL ( clicked ( ) ) , this , SLOT ( loadPerson ( ) ) ) ;
2017-05-08 04:51:15 -04:00
2009-07-30 17:48:54 -04:00
if ( pidx > 0 )
{
ui . loadName - > setCurrentIndex ( pidx ) ;
}
2017-05-10 13:06:03 -04:00
ui . password_input - > setFocus ( ) ;
2007-11-14 22:18:48 -05:00
}
2017-05-08 04:51:15 -04:00
void StartDialog : : updateSelectedProfile ( int )
{
ui . password_input - > clear ( ) ;
ui . password_input - > setFocus ( ) ;
}
2007-11-14 22:18:48 -05:00
void StartDialog : : closeEvent ( QCloseEvent * event )
{
2012-08-22 09:44:23 -04:00
Settings - > saveWidgetInformation ( this ) ;
2007-11-14 22:18:48 -05:00
2012-08-22 09:44:23 -04:00
QWidget : : closeEvent ( event ) ;
2007-11-14 22:18:48 -05:00
}
2012-08-22 09:44:23 -04:00
void StartDialog : : loadPerson ( )
2007-11-14 22:18:48 -05:00
{
2012-08-22 09:44:23 -04:00
int pgpidx = ui . loadName - > currentIndex ( ) ;
if ( pgpidx < 0 )
{
/* Message Dialog */
QMessageBox : : warning ( this , tr ( " Load Person Failure " ) , tr ( " Missing PGP Certificate " ) , QMessageBox : : Ok ) ;
return ;
}
2007-11-14 22:18:48 -05:00
2012-08-22 09:44:23 -04:00
QVariant data = ui . loadName - > itemData ( pgpidx ) ;
2014-03-17 16:56:06 -04:00
RsPeerId accountId = RsPeerId ( ( data . toString ( ) ) . toStdString ( ) ) ;
2009-05-23 11:13:01 -04:00
2017-05-08 04:51:15 -04:00
// Cache the passphrase, so that it is not asked again.
rsNotify - > cachePgpPassphrase ( ui . password_input - > text ( ) . toUtf8 ( ) . constData ( ) ) ;
bool res = Rshare : : loadCertificate ( accountId , ui . autologin_checkbox - > isChecked ( ) ) ;
if ( res )
2012-10-31 21:07:36 -04:00
accept ( ) ;
2007-11-14 22:18:48 -05:00
}
2011-08-12 10:06:29 -04:00
void StartDialog : : on_labelProfile_linkActivated ( QString /*link*/ )
2007-11-14 22:18:48 -05:00
{
2012-08-22 09:44:23 -04:00
reqNewCert = true ;
2012-10-31 21:07:36 -04:00
accept ( ) ;
2007-11-14 22:18:48 -05:00
}
2009-12-23 11:17:36 -05:00
bool StartDialog : : requestedNewCert ( )
2007-11-14 22:18:48 -05:00
{
return reqNewCert ;
}
2016-12-03 14:04:25 -05:00
# ifdef RS_AUTOLOGIN
2012-08-22 09:44:23 -04:00
void StartDialog : : notSecureWarning ( )
{
2010-04-08 07:55:10 -04:00
/* some error msg */
2012-08-22 09:44:23 -04:00
if ( ui . autologin_checkbox - > isChecked ( ) )
2015-04-19 11:34:14 -04:00
# ifdef WINDOWS_SYS
QMessageBox : : warning ( this , tr ( " Warning " ) , tr ( " The password to your SSL certificate (your node) will be stored encrypted in the keys/help.dta file. This is not secure. \n \n Your PGP password will not be stored. \n \n This choice can be reverted in settings. " ) , QMessageBox : : Ok ) ;
2012-08-22 09:44:23 -04:00
# else
# ifdef __APPLE__
2014-12-30 06:11:08 -05:00
QMessageBox : : warning ( this , tr ( " Warning " ) , tr ( " The password to your SSL certificate (your node) will be stored encrypted in your Keychain. \n \n Your PGP passwd will not be stored. \n \n This choice can be reverted in settings. " ) , QMessageBox : : Ok ) ;
2011-01-29 09:27:16 -05:00
# else
2015-04-19 11:34:14 -04:00
// this handles all linux systems at once.
QMessageBox : : warning ( this , tr ( " Warning " ) , tr ( " The password to your SSL certificate (your node) will be stored encrypted in your Gnome Keyring. \n \n Your PGP passwd will not be stored. \n \n This choice can be reverted in settings. " ) , QMessageBox : : Ok ) ;
2012-08-22 09:44:23 -04:00
# endif
2011-01-29 09:27:16 -05:00
# endif
2010-04-08 07:55:10 -04:00
}
2016-12-03 14:04:25 -05:00
# endif // RS_AUTOLOGIN