2018-11-13 16:02:26 -05:00
/*******************************************************************************
* gui / connect / ConnectFriendWizard . cpp *
* *
* Copyright ( C ) 2009 retroshare team < retroshare . project @ gmail . com > *
* Copyright ( C ) 2009 Oleksiy Bilyanskyy *
* *
* This program is free software : you can redistribute it and / or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation , either version 3 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 Affero General Public License for more details . *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program . If not , see < https : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2014-02-01 09:16:15 -05:00
2017-07-03 12:36:47 -04:00
# include <QCheckBox>
2014-02-01 09:16:15 -05:00
# include <QClipboard>
2017-07-03 12:36:47 -04:00
# include <QDesktopServices>
2014-02-01 09:16:15 -05:00
# include <QFileDialog>
2017-07-03 12:36:47 -04:00
# include <QLayout>
# include <QMessageBox>
2014-02-01 09:16:15 -05:00
# include <QTextCodec>
2017-07-03 12:36:47 -04:00
# include <QTextStream>
# include <QUrl>
2014-02-01 09:16:15 -05:00
# if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
# include <QUrlQuery>
# endif
2020-08-15 16:17:52 -04:00
# include "gui/common/FilesDefs.h"
2016-07-31 16:14:23 -04:00
# include "gui/settings/rsharesettings.h"
# include "util/misc.h"
2014-02-01 09:16:15 -05:00
# include "ConnectFriendWizard.h"
# include "ui_ConnectFriendWizard.h"
# include "gui/common/PeerDefs.h"
# include "gui/notifyqt.h"
# include "gui/common/GroupDefs.h"
# include "gui/msgs/MessageComposer.h"
# include <retroshare/rsiface.h>
2015-06-02 04:00:30 -04:00
# include <retroshare/rsbanlist.h>
2017-01-22 16:34:02 -05:00
# include <retroshare/rsconfig.h>
2014-02-01 09:16:15 -05:00
# include "ConnectProgressDialog.h"
2016-08-29 14:51:44 -04:00
# include "gui/GetStartedDialog.h"
2014-02-01 09:16:15 -05:00
//#define FRIEND_WIZARD_DEBUG
ConnectFriendPage : : ConnectFriendPage ( QWidget * parent ) : QWizardPage ( parent )
{
useComplete = false ;
complete = true ;
}
void ConnectFriendPage : : setComplete ( bool isComplete )
{
useComplete = true ;
complete = isComplete ;
emit completeChanged ( ) ;
}
bool ConnectFriendPage : : isComplete ( ) const
{
if ( useComplete ) {
return complete ;
}
return QWizardPage : : isComplete ( ) ;
}
ConnectFriendWizard : : ConnectFriendWizard ( QWidget * parent ) :
QWizard ( parent ) , ui ( new Ui : : ConnectFriendWizard )
{
ui - > setupUi ( this ) ;
2015-06-06 08:25:17 -04:00
mTitleFontSize = 0 ; // Standard
mTitleFontWeight = 0 ; // Standard
2017-03-03 16:12:36 -05:00
2019-06-09 18:36:40 -04:00
// ui->userFileFrame->hide(); // in homepage dropmenu now
2017-02-28 16:20:52 -05:00
2014-02-01 09:16:15 -05:00
// this define comes from Qt example. I don't have mac, so it wasn't tested
2015-08-29 15:31:01 -04:00
# ifndef Q_OS_MAC
2014-02-01 09:16:15 -05:00
setWizardStyle ( ModernStyle ) ;
# endif
2019-06-09 18:38:11 -04:00
setStartId ( Page_Text ) ;
2014-02-01 09:16:15 -05:00
// at this moment I don't know, what information should be in help
// setOption(HaveHelpButton, true);
// connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp()));
2020-08-19 10:19:42 -04:00
setPixmap ( QWizard : : LogoPixmap , FilesDefs : : getPixmapFromQtResourcePath ( " :/icons/invite64.png " ) ) ;
2014-02-01 09:16:15 -05:00
// we have no good pictures for watermarks
2020-08-19 10:19:42 -04:00
// setPixmap(QWizard::WatermarkPixmap, FilesDefs::getPixmapFromQtResourcePath(":/images/connectFriendWatermark.png"));
2014-02-01 09:16:15 -05:00
/* register global fields */
ui - > ErrorMessagePage - > registerField ( " errorMessage " , ui - > messageLabel , " text " ) ;
/* disable not used pages */
2019-06-09 18:12:20 -04:00
//ui->foffRadioButton->hide();
//ui->rsidRadioButton->hide();
2015-06-03 11:04:24 -04:00
2017-07-03 12:36:47 -04:00
ui - > cp_Label - > hide ( ) ;
2015-06-03 11:04:24 -04:00
ui - > requestinfolabel - > hide ( ) ;
2017-01-23 10:31:00 -05:00
2015-06-02 04:00:30 -04:00
connect ( ui - > acceptNoSignGPGCheckBox , SIGNAL ( toggled ( bool ) ) , ui - > _options_GB , SLOT ( setEnabled ( bool ) ) ) ;
2015-10-24 11:05:12 -04:00
connect ( ui - > addKeyToKeyring_CB , SIGNAL ( toggled ( bool ) ) , ui - > acceptNoSignGPGCheckBox , SLOT ( setChecked ( bool ) ) ) ;
2015-10-24 18:54:22 -04:00
connect ( ui - > gmailButton , SIGNAL ( clicked ( ) ) , this , SLOT ( inviteGmail ( ) ) ) ;
2015-10-24 11:05:12 -04:00
connect ( ui - > yahooButton , SIGNAL ( clicked ( ) ) , this , SLOT ( inviteYahoo ( ) ) ) ;
connect ( ui - > outlookButton , SIGNAL ( clicked ( ) ) , this , SLOT ( inviteOutlook ( ) ) ) ;
connect ( ui - > aolButton , SIGNAL ( clicked ( ) ) , this , SLOT ( inviteAol ( ) ) ) ;
connect ( ui - > yandexButton , SIGNAL ( clicked ( ) ) , this , SLOT ( inviteYandex ( ) ) ) ;
2015-10-24 18:54:22 -04:00
connect ( ui - > emailButton , SIGNAL ( clicked ( ) ) , this , SLOT ( runEmailClient2 ( ) ) ) ;
2017-01-23 07:09:40 -05:00
connect ( ui - > toggleadvancedButton , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleAdvanced ( ) ) ) ;
2015-10-24 11:05:12 -04:00
subject = tr ( " RetroShare Invitation " ) ;
body = GetStartedDialog : : GetInviteText ( ) ;
body + = " \n " + GetStartedDialog : : GetCutBelowText ( ) ;
2018-10-05 20:46:09 -04:00
body + = " \n \n " + QString : : fromUtf8 ( rsPeers - > GetRetroshareInvite ( ) . c_str ( ) ) ;
2017-01-22 16:34:02 -05:00
2019-06-10 09:15:15 -04:00
mIsShortInvite = false ;
2017-01-22 16:34:02 -05:00
std : : string advsetting ;
if ( rsConfig - > getConfigurationOption ( RS_CONFIG_ADVANCED , advsetting ) & & ( advsetting = = " YES " ) )
2017-01-23 07:09:40 -05:00
{
ui - > toggleadvancedButton - > setVisible ( false ) ;
}
2017-01-22 16:34:02 -05:00
else
2017-01-23 07:09:40 -05:00
{
2017-07-03 12:36:47 -04:00
ui - > cp_Frame - > hide ( ) ; // Advanced options - key sign, whitelist, direct source ...
2017-01-23 07:09:40 -05:00
AdvancedVisible = false ;
2017-01-23 10:31:00 -05:00
ui - > trustLabel - > hide ( ) ;
ui - > trustEdit - > hide ( ) ;
2017-01-23 07:09:40 -05:00
}
2017-01-22 16:34:02 -05:00
2017-07-03 12:36:47 -04:00
//Add warning to direct source checkbox depends general setting.
switch ( rsFiles - > filePermDirectDL ( ) )
{
case RS_FILE_PERM_DIRECT_DL_YES :
2020-08-15 16:17:52 -04:00
ui - > _direct_transfer_CB_2 - > setIcon ( FilesDefs : : getIconFromQtResourcePath ( " :/icons/warning_yellow_128.png " ) ) ;
2017-07-03 12:36:47 -04:00
ui - > _direct_transfer_CB_2 - > setToolTip ( ui - > _direct_transfer_CB_2 - > toolTip ( ) . append ( tr ( " \n Warning: In your File-Transfer option, you select allow direct download to Yes. " ) ) ) ;
break ;
case RS_FILE_PERM_DIRECT_DL_NO :
2020-08-15 16:17:52 -04:00
ui - > _direct_transfer_CB_2 - > setIcon ( FilesDefs : : getIconFromQtResourcePath ( " :/icons/warning_yellow_128.png " ) ) ;
2017-07-03 12:36:47 -04:00
ui - > _direct_transfer_CB_2 - > setToolTip ( ui - > _direct_transfer_CB_2 - > toolTip ( ) . append ( tr ( " \n Warning: In your File-Transfer option, you select allow direct download to No. " ) ) ) ;
break ;
default : break ;
}
2015-06-06 08:25:17 -04:00
updateStylesheet ( ) ;
}
void ConnectFriendWizard : : setBannerPixmap ( const QString & pixmap )
{
mBannerPixmap = pixmap ;
setPixmap ( QWizard : : BannerPixmap , mBannerPixmap ) ;
}
QString ConnectFriendWizard : : bannerPixmap ( )
{
return mBannerPixmap ;
}
void ConnectFriendWizard : : setTitleFontSize ( int size )
{
mTitleFontSize = size ;
updateStylesheet ( ) ;
}
int ConnectFriendWizard : : titleFontSize ( )
{
return mTitleFontSize ;
}
void ConnectFriendWizard : : setTitleFontWeight ( int weight )
{
mTitleFontWeight = weight ;
updateStylesheet ( ) ;
}
int ConnectFriendWizard : : titleFontWeight ( )
{
return mTitleFontWeight ;
}
void ConnectFriendWizard : : setTitleColor ( const QString & color )
{
mTitleColor = color ;
updateStylesheet ( ) ;
}
QString ConnectFriendWizard : : titleColor ( )
{
return mTitleColor ;
}
void ConnectFriendWizard : : setTitleText ( QWizardPage * page , const QString & title )
{
if ( ! page ) {
return ;
}
page - > setTitle ( title ) ;
mTitleString . remove ( page ) ;
updateStylesheet ( ) ;
}
void ConnectFriendWizard : : updateStylesheet ( )
{
/* add stylesheet to title */
QList < int > ids = pageIds ( ) ;
for ( QList < int > : : iterator pageIt = ids . begin ( ) ; pageIt ! = ids . end ( ) ; + + pageIt ) {
QWizardPage * p = page ( * pageIt ) ;
QString title ;
QMap < QWizardPage * , QString > : : iterator it = mTitleString . find ( p ) ;
if ( it = = mTitleString . end ( ) ) {
/* Save title string */
title = p - > title ( ) ;
mTitleString [ p ] = title ;
} else {
title = it . value ( ) ;
}
QString stylesheet = " <span style= \" " ;
if ( mTitleFontSize ) {
stylesheet + = QString ( " font-size:%1pt; " ) . arg ( mTitleFontSize ) ;
}
if ( mTitleFontWeight ) {
stylesheet + = QString ( " font-weight:%1; " ) . arg ( mTitleFontWeight ) ;
}
if ( ! mTitleColor . isEmpty ( ) ) {
stylesheet + = QString ( " color:%1; " ) . arg ( mTitleColor ) ;
}
stylesheet + = QString ( " \" >%1</span> " ) . arg ( title ) ;
p - > setTitle ( stylesheet ) ;
}
2014-02-01 09:16:15 -05:00
}
QString ConnectFriendWizard : : getErrorString ( uint32_t error_code )
{
switch ( error_code )
{
case CERTIFICATE_PARSING_ERROR_SIZE_ERROR : return tr ( " Abnormal size read is bigger than memory block. " ) ;
2014-12-30 06:11:08 -05:00
case CERTIFICATE_PARSING_ERROR_INVALID_LOCATION_ID : return tr ( " Invalid node id. " ) ;
2014-02-01 09:16:15 -05:00
case CERTIFICATE_PARSING_ERROR_INVALID_EXTERNAL_IP : return tr ( " Invalid external IP. " ) ;
case CERTIFICATE_PARSING_ERROR_INVALID_LOCAL_IP : return tr ( " Invalid local IP. " ) ;
case CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION : return tr ( " Invalid checksum section. " ) ;
case CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR : return tr ( " Checksum mismatch. Certificate is corrupted. " ) ;
case CERTIFICATE_PARSING_ERROR_WRONG_VERSION : return tr ( " Certificate has wrong version number. Remember that v0.6 and v0.5 networks are incompatible. " ) ;
case CERTIFICATE_PARSING_ERROR_UNKNOWN_SECTION_PTAG : return tr ( " Unknown section type found (Certificate might be corrupted). " ) ;
case CERTIFICATE_PARSING_ERROR_MISSING_CHECKSUM : return tr ( " Missing checksum. " ) ;
default :
return tr ( " Unknown certificate error " ) ;
}
}
void ConnectFriendWizard : : setCertificate ( const QString & certificate , bool friendRequest )
{
if ( certificate . isEmpty ( ) ) {
return ;
}
uint32_t cert_load_error_code ;
if ( rsPeers - > loadDetailsFromStringCert ( certificate . toUtf8 ( ) . constData ( ) , peerDetails , cert_load_error_code ) )
{
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " ConnectFriendWizard got id : " < < peerDetails . id < < " ; gpg_id : " < < peerDetails . gpg_id < < std : : endl ;
# endif
2018-02-14 15:48:56 -05:00
if ( peerDetails . id = = rsPeers - > getOwnId ( ) )
{
setField ( " errorMessage " , tr ( " This is your own certificate! You would not want to make friend with yourself. Wouldn't you? " ) ) ;
error = false ;
setStartId ( Page_ErrorMessage ) ;
}
else
{
mCertificate = certificate . toUtf8 ( ) . constData ( ) ;
setStartId ( Page_Conclusion ) ;
if ( friendRequest ) {
ui - > cp_Label - > show ( ) ;
ui - > requestinfolabel - > show ( ) ;
setTitleText ( ui - > ConclusionPage , tr ( " Friend request " ) ) ;
ui - > ConclusionPage - > setSubTitle ( tr ( " Details about the request " ) ) ;
2019-10-16 14:04:23 -04:00
setButtonText ( QWizard : : FinishButton , tr ( " Accept " ) ) ;
2018-02-14 15:48:56 -05:00
}
}
2019-06-09 09:03:48 -04:00
}
2019-06-21 17:30:06 -04:00
else if ( rsPeers - > parseShortInvite ( certificate . toUtf8 ( ) . constData ( ) , peerDetails , cert_load_error_code ) )
2019-06-09 09:03:48 -04:00
{
2019-06-10 09:15:15 -04:00
mIsShortInvite = true ;
2019-06-09 09:03:48 -04:00
if ( peerDetails . id = = rsPeers - > getOwnId ( ) )
{
setField ( " errorMessage " , tr ( " This is your own certificate! You would not want to make friend with yourself. Wouldn't you? " ) ) ;
error = false ;
setStartId ( Page_ErrorMessage ) ;
}
else
{
mCertificate = certificate . toUtf8 ( ) . constData ( ) ;
setStartId ( Page_Conclusion ) ;
if ( friendRequest ) {
ui - > cp_Label - > show ( ) ;
ui - > requestinfolabel - > show ( ) ;
setTitleText ( ui - > ConclusionPage , tr ( " Friend request " ) ) ;
ui - > ConclusionPage - > setSubTitle ( tr ( " Details about the request " ) ) ;
2019-10-16 14:04:23 -04:00
setButtonText ( QWizard : : FinishButton , tr ( " Accept " ) ) ;
2019-06-09 09:03:48 -04:00
}
}
}
else
{
2014-02-01 09:16:15 -05:00
// error message
setField ( " errorMessage " , tr ( " Certificate Load Failed " ) + " : \n \n " + getErrorString ( cert_load_error_code ) ) ;
setStartId ( Page_ErrorMessage ) ;
}
}
2014-03-17 16:56:06 -04:00
void ConnectFriendWizard : : setGpgId ( const RsPgpId & gpgId , const RsPeerId & sslId , bool friendRequest )
2014-02-01 09:16:15 -05:00
{
2019-12-14 12:24:46 -05:00
if ( sslId = = rsPeers - > getOwnId ( ) )
{
setField ( " errorMessage " , tr ( " This is your own certificate! You would not want to make friend with yourself. Wouldn't you? " ) ) ;
2014-02-01 09:16:15 -05:00
setStartId ( Page_ErrorMessage ) ;
2019-12-14 12:24:46 -05:00
error = false ;
2014-02-01 09:16:15 -05:00
}
2019-12-14 12:24:46 -05:00
if ( ! rsPeers - > getGPGDetails ( gpgId , peerDetails ) )
{
mIsShortInvite = true ;
peerDetails . id = sslId ;
peerDetails . gpg_id = gpgId ;
peerDetails . skip_pgp_signature_validation = true ;
mCertificate . clear ( ) ;
setStartId ( Page_Conclusion ) ;
if ( friendRequest ) {
ui - > cp_Label - > show ( ) ;
ui - > requestinfolabel - > show ( ) ;
setTitleText ( ui - > ConclusionPage , tr ( " Friend request " ) ) ;
ui - > ConclusionPage - > setSubTitle ( tr ( " Details about the request " ) ) ;
setButtonText ( QWizard : : FinishButton , tr ( " Accept " ) ) ;
}
}
else
{
/* Set ssl id when available */
peerDetails . id = sslId ;
mIsShortInvite = false ;
//setStartId(friendRequest ? Page_FriendRequest : Page_Conclusion);
setStartId ( Page_Conclusion ) ;
if ( friendRequest ) {
ui - > cp_Label - > show ( ) ;
ui - > requestinfolabel - > show ( ) ;
setTitleText ( ui - > ConclusionPage , tr ( " Friend request " ) ) ;
ui - > ConclusionPage - > setSubTitle ( tr ( " Details about the request " ) ) ;
setButtonText ( QWizard : : FinishButton , tr ( " Accept " ) ) ;
}
}
2014-02-01 09:16:15 -05:00
}
ConnectFriendWizard : : ~ ConnectFriendWizard ( )
{
delete ui ;
}
static void fillGroups ( ConnectFriendWizard * wizard , QComboBox * comboBox , const QString & groupId )
{
std : : list < RsGroupInfo > groupInfoList ;
rsPeers - > getGroupInfoList ( groupInfoList ) ;
GroupDefs : : sortByName ( groupInfoList ) ;
comboBox - > addItem ( " " , " " ) ; // empty value
for ( std : : list < RsGroupInfo > : : iterator groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; + + groupIt ) {
2016-07-05 23:49:43 -04:00
comboBox - > addItem ( GroupDefs : : name ( * groupIt ) , QString : : fromStdString ( groupIt - > id . toStdString ( ) ) ) ;
2014-02-01 09:16:15 -05:00
}
if ( groupId . isEmpty ( ) = = false ) {
comboBox - > setCurrentIndex ( comboBox - > findData ( groupId ) ) ;
}
QObject : : connect ( comboBox , SIGNAL ( currentIndexChanged ( int ) ) , wizard , SLOT ( groupCurrentIndexChanged ( int ) ) ) ;
}
void ConnectFriendWizard : : initializePage ( int id )
{
switch ( ( Page ) id ) {
case Page_Text :
2019-10-16 14:04:23 -04:00
2015-06-07 14:28:17 -04:00
connect ( ui - > userCertPasteButton , SIGNAL ( clicked ( ) ) , this , SLOT ( pasteCert ( ) ) ) ;
2017-05-08 11:26:12 -04:00
connect ( ui - > userCertOpenButton , SIGNAL ( clicked ( ) ) , this , SLOT ( openCert ( ) ) ) ;
2014-02-01 09:16:15 -05:00
connect ( ui - > friendCertEdit , SIGNAL ( textChanged ( ) ) , this , SLOT ( friendCertChanged ( ) ) ) ;
cleanfriendCertTimer = new QTimer ( this ) ;
cleanfriendCertTimer - > setSingleShot ( true ) ;
cleanfriendCertTimer - > setInterval ( 1000 ) ; // 1 second
connect ( cleanfriendCertTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( cleanFriendCert ( ) ) ) ;
cleanFriendCert ( ) ;
break ;
2015-10-24 11:05:12 -04:00
case Page_WebMail :
2014-02-01 09:16:15 -05:00
case Page_ErrorMessage :
break ;
case Page_Conclusion :
{
2018-01-15 16:00:08 -05:00
bool peerIsHiddenNode = peerDetails . isHiddenNode ;
bool amIHiddenNode = rsPeers - > isHiddenNode ( rsPeers - > getOwnId ( ) ) ;
2014-02-01 09:16:15 -05:00
std : : cerr < < " Conclusion page id : " < < peerDetails . id < < " ; gpg_id : " < < peerDetails . gpg_id < < std : : endl ;
2017-02-28 16:20:52 -05:00
ui - > _direct_transfer_CB_2 - > setChecked ( false ) ; //peerDetails.service_perm_flags & RS_NODE_PERM_DIRECT_DL) ;
2015-02-18 14:07:58 -05:00
ui - > _allow_push_CB_2 - > setChecked ( peerDetails . service_perm_flags & RS_NODE_PERM_ALLOW_PUSH ) ;
2018-01-15 16:00:08 -05:00
if ( ! peerIsHiddenNode & & ! amIHiddenNode )
ui - > _require_WL_CB_2 - > setChecked ( peerDetails . service_perm_flags & RS_NODE_PERM_REQUIRE_WL ) ;
else
{
ui - > _require_WL_CB_2 - > setChecked ( false ) ;
ui - > _require_WL_CB_2 - > hide ( ) ;
ui - > _addIPToWhiteList_CB_2 - > hide ( ) ;
ui - > _addIPToWhiteList_ComboBox_2 - > hide ( ) ;
}
2014-02-01 09:16:15 -05:00
2015-06-02 04:00:30 -04:00
sockaddr_storage addr ;
2018-01-15 16:00:08 -05:00
std : : cerr < < " Cert IP = " < < peerDetails . extAddr < < std : : endl ;
2015-06-02 04:00:30 -04:00
if ( sockaddr_storage_ipv4_aton ( addr , peerDetails . extAddr . c_str ( ) ) & & sockaddr_storage_isValidNet ( addr ) )
{
QString ipstring0 = QString : : fromStdString ( sockaddr_storage_iptostring ( addr ) ) ;
2017-02-28 16:20:52 -05:00
ui - > _addIPToWhiteList_CB_2 - > setChecked ( ui - > _require_WL_CB_2 - > isChecked ( ) ) ;
2015-06-02 04:00:30 -04:00
ui - > _addIPToWhiteList_ComboBox_2 - > addItem ( ipstring0 ) ;
ui - > _addIPToWhiteList_ComboBox_2 - > addItem ( ipstring0 + " /24 " ) ;
ui - > _addIPToWhiteList_ComboBox_2 - > addItem ( ipstring0 + " /16 " ) ;
ui - > _addIPToWhiteList_ComboBox_2 - > setEnabled ( true ) ;
ui - > _addIPToWhiteList_CB_2 - > setEnabled ( true ) ;
}
else if ( ui - > _require_WL_CB_2 - > isChecked ( ) )
{
ui - > _addIPToWhiteList_ComboBox_2 - > addItem ( tr ( " No IP in this certificate! " ) ) ;
ui - > _addIPToWhiteList_ComboBox_2 - > setToolTip ( tr ( " <p>This certificate has no IP. You will rely on discovery and DHT to find it. Because you require whitelist clearance, the peer will raise a security warning in the NewsFeed tab. From there, you can whitelist his IP.</p> " ) ) ;
ui - > _addIPToWhiteList_ComboBox_2 - > setEnabled ( false ) ;
ui - > _addIPToWhiteList_CB_2 - > setChecked ( false ) ;
ui - > _addIPToWhiteList_CB_2 - > setEnabled ( false ) ;
}
2014-02-01 09:16:15 -05:00
RsPeerDetails tmp_det ;
2014-03-17 16:56:06 -04:00
bool already_in_keyring = rsPeers - > getGPGDetails ( peerDetails . gpg_id , tmp_det ) ;
2014-02-01 09:16:15 -05:00
ui - > addKeyToKeyring_CB - > setChecked ( true ) ;
ui - > addKeyToKeyring_CB - > setEnabled ( ! already_in_keyring ) ;
if ( already_in_keyring )
ui - > addKeyToKeyring_CB - > setToolTip ( tr ( " This key is already in your keyring " ) ) ;
else
ui - > addKeyToKeyring_CB - > setToolTip ( tr ( " Check this to add the key to your keyring \n This might be useful for sending \n distant messages to this peer \n even if you don't make friends. " ) ) ;
2017-10-23 13:01:35 -04:00
if ( tmp_det . accept_connection ) {
2014-02-01 09:16:15 -05:00
ui - > acceptNoSignGPGCheckBox - > setChecked ( true ) ;
2017-10-23 13:01:35 -04:00
ui - > acceptNoSignGPGCheckBox - > setEnabled ( false ) ;
ui - > acceptNoSignGPGCheckBox - > setToolTip ( tr ( " This key is already on your trusted list " ) ) ;
2014-02-01 09:16:15 -05:00
}
2017-10-23 13:01:35 -04:00
else
2014-02-01 09:16:15 -05:00
ui - > alreadyRegisteredLabel - > hide ( ) ;
2017-10-23 13:01:35 -04:00
if ( tmp_det . ownsign ) {
2018-02-14 15:56:12 -05:00
ui - > signGPGCheckBox - > setChecked ( false ) ; // if already signed, we dont allow to sign it again, and dont show the box.
ui - > signGPGCheckBox - > setVisible ( false ) ;
2017-10-23 13:01:35 -04:00
ui - > signGPGCheckBox - > setToolTip ( tr ( " You have already signed this key " ) ) ;
2014-02-01 09:16:15 -05:00
}
QString trustString ;
switch ( peerDetails . validLvl ) {
case RS_TRUST_LVL_ULTIMATE :
trustString = tr ( " Ultimate " ) ;
break ;
case RS_TRUST_LVL_FULL :
trustString = tr ( " Full " ) ;
break ;
case RS_TRUST_LVL_MARGINAL :
trustString = tr ( " Marginal " ) ;
break ;
case RS_TRUST_LVL_NEVER :
trustString = tr ( " None " ) ;
break ;
default :
trustString = tr ( " No Trust " ) ;
break ;
}
QString ts ;
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > : : iterator it ;
2014-02-01 09:16:15 -05:00
for ( it = peerDetails . gpgSigners . begin ( ) ; it ! = peerDetails . gpgSigners . end ( ) ; + + it ) {
{
2014-03-17 16:56:06 -04:00
std : : string peer_name = rsPeers - > getGPGName ( * it ) ;
2014-02-01 09:16:15 -05:00
// This is baaaad code. We should handle this kind of errors with proper exceptions.
// This happens because signers from a unknown key cannt be found in the keyring, including
// self-signatures.
//
if ( peer_name = = " [Unknown PGP Cert name] " & & * it = = peerDetails . gpg_id )
peer_name = peerDetails . name ;
2014-03-17 16:56:06 -04:00
ts + = QString ( " %1<%2> \n " ) . arg ( QString : : fromUtf8 ( peer_name . c_str ( ) ) , QString : : fromStdString ( ( * it ) . toStdString ( ) ) ) ;
2014-02-01 09:16:15 -05:00
}
}
2017-07-03 12:36:47 -04:00
ui - > cp_Label - > setText ( tr ( " You have a friend request from " ) + " " + QString : : fromUtf8 ( peerDetails . name . c_str ( ) ) ) ;
2014-02-01 09:16:15 -05:00
ui - > nameEdit - > setText ( QString : : fromUtf8 ( peerDetails . name . c_str ( ) ) ) ;
ui - > trustEdit - > setText ( trustString ) ;
2019-12-14 12:24:46 -05:00
ui - > profileIdEdit - > setText ( QString : : fromStdString ( peerDetails . gpg_id . toStdString ( ) ) ) ;
2014-02-01 09:16:15 -05:00
QString loc = QString : : fromUtf8 ( peerDetails . location . c_str ( ) ) ;
if ( ! loc . isEmpty ( ) )
{
loc + = " ( " ;
2014-03-17 16:56:06 -04:00
loc + = QString : : fromStdString ( peerDetails . id . toStdString ( ) ) ;
2014-02-01 09:16:15 -05:00
loc + = " ) " ;
}
else
{
2014-03-17 16:56:06 -04:00
if ( ! peerDetails . id . isNull ( ) )
2014-02-01 09:16:15 -05:00
{
2014-03-17 16:56:06 -04:00
loc + = QString : : fromStdString ( peerDetails . id . toStdString ( ) ) ;
2014-02-01 09:16:15 -05:00
}
}
2014-12-30 06:11:08 -05:00
ui - > nodeEdit - > setText ( loc ) ;
2020-11-10 16:02:49 -05:00
std : : string s ;
if ( peerDetails . isHiddenNode )
s + = peerDetails . hiddenNodeAddress ;
else
{
if ( peerDetails . localAddr ! = " 0.0.0.0 " ) // This is not so nice, but because we deal we string there's no way
s + = peerDetails . localAddr ; // to ask about if the ip is null. We really need a proper IP class.
if ( peerDetails . extAddr ! = " 0.0.0.0 " )
{
if ( ! s . empty ( ) ) s + = " / " ;
s + = peerDetails . extAddr ;
}
if ( ! peerDetails . dyndns . empty ( ) )
s + = " ( " + peerDetails . dyndns + " ) " ;
}
ui - > ipEdit - > setText ( QString : : fromStdString ( s ) ) ;
2014-02-01 09:16:15 -05:00
ui - > signersEdit - > setPlainText ( ts ) ;
fillGroups ( this , ui - > groupComboBox , groupId ) ;
2017-01-24 14:56:55 -05:00
if ( peerDetails . isHiddenNode )
{
ui - > _addIPToWhiteList_CB_2 - > setEnabled ( false ) ;
ui - > _require_WL_CB_2 - > setEnabled ( false ) ;
ui - > _addIPToWhiteList_ComboBox_2 - > setEnabled ( false ) ;
ui - > _addIPToWhiteList_ComboBox_2 - > addItem ( " (Hidden node) " ) ;
int S = QFontMetricsF ( ui - > ipEdit - > font ( ) ) . height ( ) ;
ui - > ipEdit - > setToolTip ( " This is a Hidden node - you need tor/i2p proxy to connect " ) ;
2020-08-19 10:19:42 -04:00
ui - > ipLabel - > setPixmap ( FilesDefs : : getPixmapFromQtResourcePath ( " :/images/anonymous_128_blue.png " ) . scaledToHeight ( S * 2 , Qt : : SmoothTransformation ) ) ;
2017-01-24 14:56:55 -05:00
ui - > ipLabel - > setToolTip ( " This is a Hidden node - you need tor/i2p proxy to connect " ) ;
}
2019-12-14 12:24:46 -05:00
if ( mIsShortInvite )
2017-03-01 14:36:36 -05:00
{
2019-12-14 12:24:46 -05:00
ui - > nameEdit - > setText ( tr ( " [Unknown] " ) ) ;
ui - > addKeyToKeyring_CB - > setChecked ( false ) ;
ui - > addKeyToKeyring_CB - > setEnabled ( false ) ;
ui - > signersEdit - > hide ( ) ;
ui - > signersLabel - > hide ( ) ;
ui - > signGPGCheckBox - > setChecked ( false ) ;
ui - > signGPGCheckBox - > setEnabled ( false ) ;
ui - > acceptNoSignGPGCheckBox - > setChecked ( true ) ;
ui - > acceptNoSignGPGCheckBox - > setEnabled ( false ) ;
2017-03-01 14:36:36 -05:00
}
2019-12-14 12:24:46 -05:00
2017-03-01 14:36:36 -05:00
ui - > ipEdit - > setTextInteractionFlags ( Qt : : TextSelectableByMouse ) ;
2014-02-01 09:16:15 -05:00
}
break ;
}
}
static void sendMail ( QString sAddress , QString sSubject , QString sBody )
{
2015-08-29 15:31:01 -04:00
# ifdef Q_OS_WIN
2014-02-01 09:16:15 -05:00
/* search and replace the end of lines with: "%0D%0A" */
sBody . replace ( " \n " , " %0D%0A " ) ;
# endif
QUrl url = QUrl ( " mailto: " + sAddress ) ;
# if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
QUrlQuery urlQuery ;
# else
QUrl & urlQuery ( url ) ;
# endif
urlQuery . addQueryItem ( " subject " , sSubject ) ;
urlQuery . addQueryItem ( " body " , sBody ) ;
# if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
url . setQuery ( urlQuery ) ;
# endif
std : : cerr < < " MAIL STRING: " < < ( std : : string ) url . toEncoded ( ) . constData ( ) < < std : : endl ;
/* pass the url directly to QDesktopServices::openUrl */
QDesktopServices : : openUrl ( url ) ;
}
bool ConnectFriendWizard : : validateCurrentPage ( )
{
2019-09-28 11:29:24 -04:00
error = false ;
2014-02-01 09:16:15 -05:00
switch ( ( Page ) currentId ( ) ) {
2016-10-22 17:48:19 -04:00
case Page_WebMail :
2014-02-01 09:16:15 -05:00
break ;
case Page_Text :
{
std : : string certstr = ui - > friendCertEdit - > toPlainText ( ) . toUtf8 ( ) . constData ( ) ;
uint32_t cert_load_error_code ;
2019-06-21 17:30:06 -04:00
if ( rsPeers - > loadDetailsFromStringCert ( certstr , peerDetails , cert_load_error_code ) | | rsPeers - > parseShortInvite ( certstr , peerDetails , cert_load_error_code ) )
2019-06-09 09:03:48 -04:00
{
2014-02-01 09:16:15 -05:00
mCertificate = certstr ;
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " ConnectFriendWizard got id : " < < peerDetails . id < < " ; gpg_id : " < < peerDetails . gpg_id < < std : : endl ;
# endif
2018-02-14 15:48:56 -05:00
if ( peerDetails . id = = rsPeers - > getOwnId ( ) )
{
setField ( " errorMessage " , tr ( " This is your own certificate! You would not want to make friend with yourself. Wouldn't you? " ) ) ;
2019-09-28 11:29:24 -04:00
error = true ;
2018-02-14 15:48:56 -05:00
}
2014-02-01 09:16:15 -05:00
break ;
}
// error message
setField ( " errorMessage " , tr ( " Certificate Load Failed " ) + " : \n \n " + getErrorString ( cert_load_error_code ) ) ;
2019-09-28 11:29:24 -04:00
error = true ;
2014-02-01 09:16:15 -05:00
break ;
}
case Page_ErrorMessage :
break ;
case Page_Conclusion :
break ;
}
return true ;
}
int ConnectFriendWizard : : nextId ( ) const
{
switch ( ( Page ) currentId ( ) ) {
2019-09-28 11:29:24 -04:00
case Page_Text : return error ? Page_ErrorMessage : Page_Conclusion ;
2015-10-24 11:05:12 -04:00
case Page_WebMail :
2014-02-01 09:16:15 -05:00
case Page_ErrorMessage :
case Page_Conclusion :
return - 1 ;
}
return - 1 ;
}
ServicePermissionFlags ConnectFriendWizard : : serviceFlags ( ) const
{
2015-02-02 17:32:30 -05:00
ServicePermissionFlags flags ( 0 ) ;
2019-06-09 18:29:22 -04:00
if ( hasVisitedPage ( Page_Conclusion ) ) {
2015-02-18 14:07:58 -05:00
if ( ui - > _direct_transfer_CB_2 - > isChecked ( ) ) flags | = RS_NODE_PERM_DIRECT_DL ;
if ( ui - > _allow_push_CB_2 - > isChecked ( ) ) flags | = RS_NODE_PERM_ALLOW_PUSH ;
2015-06-01 15:44:36 -04:00
if ( ui - > _require_WL_CB_2 - > isChecked ( ) ) flags | = RS_NODE_PERM_REQUIRE_WL ;
2015-02-02 17:32:30 -05:00
}
return flags ;
2014-02-01 09:16:15 -05:00
}
void ConnectFriendWizard : : accept ( )
{
bool sign = false ;
bool accept_connection = false ;
bool add_key_to_keyring = false ;
if ( hasVisitedPage ( Page_Conclusion ) ) {
std : : cerr < < " ConnectFriendWizard::accept() called with page conclusion visited " < < std : : endl ;
sign = ui - > signGPGCheckBox - > isChecked ( ) ;
accept_connection = ui - > acceptNoSignGPGCheckBox - > isChecked ( ) ;
add_key_to_keyring = ui - > addKeyToKeyring_CB - > isChecked ( ) ;
2019-06-09 18:29:22 -04:00
} else {
2014-02-01 09:16:15 -05:00
QDialog : : accept ( ) ;
return ;
}
2019-06-10 09:15:15 -04:00
// add the profile pgp key to keyring
if ( ! mIsShortInvite & & ! mCertificate . empty ( ) & & add_key_to_keyring )
2014-02-01 09:16:15 -05:00
{
2014-03-17 16:56:06 -04:00
RsPgpId pgp_id ;
RsPeerId ssl_id ;
std : : string error_string ;
2014-02-01 09:16:15 -05:00
if ( ! rsPeers - > loadCertificateFromString ( mCertificate , ssl_id , pgp_id , error_string ) )
{
std : : cerr < < " ConnectFriendWizard::accept(): cannot load that certificate. " < < std : : endl ;
return ;
}
}
bool runProgressDialog = false ;
2019-06-10 09:15:15 -04:00
// add the peer as friend, either with or without pgp signature validation, depending on whether we have the key or not
// Note: that is different than having a short invite or not.
// first, set data related to profile key.
2014-03-17 16:56:06 -04:00
if ( accept_connection & & ! peerDetails . gpg_id . isNull ( ) )
2014-02-01 09:16:15 -05:00
{
std : : cerr < < " ConclusionPage::validatePage() accepting GPG key for connection. " < < std : : endl ;
2019-09-19 15:14:57 -04:00
if ( peerDetails . skip_pgp_signature_validation )
2019-06-09 17:49:31 -04:00
rsPeers - > addSslOnlyFriend ( peerDetails . id , peerDetails . gpg_id , peerDetails ) ;
else
rsPeers - > addFriend ( peerDetails . id , peerDetails . gpg_id , serviceFlags ( ) ) ;
rsPeers - > setServicePermissionFlags ( peerDetails . gpg_id , serviceFlags ( ) ) ;
if ( ui - > _addIPToWhiteList_CB_2 - > isChecked ( ) )
{
sockaddr_storage addr ;
if ( sockaddr_storage_ipv4_aton ( addr , peerDetails . extAddr . c_str ( ) ) & & sockaddr_storage_isValidNet ( addr ) )
{
std : : cerr < < " ConclusionPage::adding IP " < < sockaddr_storage_tostring ( addr ) < < " to whitelist. " < < std : : endl ;
rsBanList - > addIpRange ( addr , ui - > _addIPToWhiteList_ComboBox_2 - > currentIndex ( ) , RSBANLIST_TYPE_WHITELIST , std : : string ( tr ( " Added with certificate from %1 " ) . arg ( ui - > nameEdit - > text ( ) ) . toUtf8 ( ) . constData ( ) ) ) ;
}
}
2015-06-02 04:00:30 -04:00
2014-02-01 09:16:15 -05:00
if ( sign )
{
std : : cerr < < " ConclusionPage::validatePage() signing GPG key. " < < std : : endl ;
rsPeers - > signGPGCertificate ( peerDetails . gpg_id ) ; //bye default sign set accept_connection to true;
rsPeers - > setServicePermissionFlags ( peerDetails . gpg_id , serviceFlags ( ) ) ;
2019-06-09 17:49:31 -04:00
}
2014-02-01 09:16:15 -05:00
2019-06-09 17:49:31 -04:00
if ( ! groupId . isEmpty ( ) )
rsPeers - > assignPeerToGroup ( RsNodeGroupId ( groupId . toStdString ( ) ) , peerDetails . gpg_id , true ) ;
2014-02-01 09:16:15 -05:00
}
2019-06-10 09:15:15 -04:00
// Then set data related to node location
2014-03-17 16:56:06 -04:00
if ( ( accept_connection ) & & ( ! peerDetails . id . isNull ( ) ) )
2014-02-01 09:16:15 -05:00
{
runProgressDialog = true ;
if ( ! peerDetails . location . empty ( ) ) {
2014-12-30 06:11:08 -05:00
std : : cerr < < " ConnectFriendWizard::accept() : setting peer node. " < < std : : endl ;
2014-02-01 09:16:15 -05:00
rsPeers - > setLocation ( peerDetails . id , peerDetails . location ) ;
}
if ( peerDetails . isHiddenNode )
{
std : : cerr < < " ConnectFriendWizard::accept() : setting hidden node. " < < std : : endl ;
rsPeers - > setHiddenNode ( peerDetails . id , peerDetails . hiddenNodeAddress , peerDetails . hiddenNodePort ) ;
}
else
{
//let's check if there is ip adresses in the wizard.
if ( ! peerDetails . extAddr . empty ( ) & & peerDetails . extPort ) {
std : : cerr < < " ConnectFriendWizard::accept() : setting ip ext address. " < < std : : endl ;
rsPeers - > setExtAddress ( peerDetails . id , peerDetails . extAddr , peerDetails . extPort ) ;
}
if ( ! peerDetails . localAddr . empty ( ) & & peerDetails . localPort ) {
std : : cerr < < " ConnectFriendWizard::accept() : setting ip local address. " < < std : : endl ;
rsPeers - > setLocalAddress ( peerDetails . id , peerDetails . localAddr , peerDetails . localPort ) ;
}
if ( ! peerDetails . dyndns . empty ( ) ) {
std : : cerr < < " ConnectFriendWizard::accept() : setting DynDNS. " < < std : : endl ;
rsPeers - > setDynDNS ( peerDetails . id , peerDetails . dyndns ) ;
}
2018-03-02 18:08:56 -05:00
for ( auto & & ipr : peerDetails . ipAddressList )
2019-06-10 09:15:15 -04:00
rsPeers - > addPeerLocator ( peerDetails . id , RsUrl ( ipr . substr ( 0 , ipr . find ( ' ' ) ) ) ) ;
2014-02-01 09:16:15 -05:00
}
}
if ( runProgressDialog )
{
2014-03-17 16:56:06 -04:00
RsPeerId ssl_id = peerDetails . id ;
2014-02-01 09:16:15 -05:00
// its okay if ssl_id is invalid - dialog will show error.
ConnectProgressDialog : : showProgress ( ssl_id ) ;
}
NotifyQt : : getInstance ( ) - > notifyListChange ( NOTIFY_LIST_NEIGHBOURS , 1 ) ;
QDialog : : accept ( ) ;
}
//============================= TextPage =====================================
void ConnectFriendWizard : : friendCertChanged ( )
{
ui - > TextPage - > setComplete ( false ) ;
cleanfriendCertTimer - > start ( ) ;
}
void ConnectFriendWizard : : cleanFriendCert ( )
{
bool certValid = false ;
2017-01-22 15:44:26 -05:00
QString errorMsg ;
2014-02-01 09:16:15 -05:00
std : : string cert = ui - > friendCertEdit - > toPlainText ( ) . toUtf8 ( ) . constData ( ) ;
if ( cert . empty ( ) ) {
2020-08-19 10:19:42 -04:00
ui - > friendCertCleanLabel - > setPixmap ( FilesDefs : : getPixmapFromQtResourcePath ( " :/images/delete.png " ) ) ;
2014-02-01 09:16:15 -05:00
ui - > friendCertCleanLabel - > setToolTip ( " " ) ;
2016-12-21 13:07:57 -05:00
ui - > friendCertCleanLabel - > setStyleSheet ( " " ) ;
2017-01-22 15:44:26 -05:00
errorMsg = tr ( " " ) ;
2016-12-21 13:07:57 -05:00
2014-02-01 09:16:15 -05:00
} else {
std : : string cleanCert ;
2019-06-21 17:30:06 -04:00
uint32_t error_code ;
2014-02-01 09:16:15 -05:00
2019-06-10 09:15:15 -04:00
if ( rsPeers - > cleanCertificate ( cert , cleanCert , mIsShortInvite , error_code ) )
2019-06-09 09:03:48 -04:00
{
2014-02-01 09:16:15 -05:00
certValid = true ;
2019-06-09 09:03:48 -04:00
if ( cert ! = cleanCert )
{
2014-02-01 09:16:15 -05:00
QTextCursor textCursor = ui - > friendCertEdit - > textCursor ( ) ;
2019-06-09 09:03:48 -04:00
whileBlocking ( ui - > friendCertEdit ) - > setPlainText ( QString : : fromUtf8 ( cleanCert . c_str ( ) ) ) ;
whileBlocking ( ui - > friendCertEdit ) - > setTextCursor ( textCursor ) ;
2016-12-21 13:07:57 -05:00
ui - > friendCertCleanLabel - > setStyleSheet ( " " ) ;
2014-02-01 09:16:15 -05:00
}
2019-06-10 09:15:15 -04:00
errorMsg = tr ( " Valid certificate " ) + ( mIsShortInvite ? " (Short format) " : " (plain format with profile key) " ) ;
2019-06-09 09:03:48 -04:00
2020-08-19 10:19:42 -04:00
ui - > friendCertCleanLabel - > setPixmap ( FilesDefs : : getPixmapFromQtResourcePath ( " :/images/accepted16.png " ) ) ;
2014-02-01 09:16:15 -05:00
} else {
if ( error_code > 0 ) {
switch ( error_code ) {
2017-01-22 15:44:26 -05:00
case CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR :
case CERTIFICATE_PARSING_ERROR_WRONG_VERSION :
case CERTIFICATE_PARSING_ERROR_SIZE_ERROR :
case CERTIFICATE_PARSING_ERROR_INVALID_LOCATION_ID :
case CERTIFICATE_PARSING_ERROR_INVALID_EXTERNAL_IP :
case CERTIFICATE_PARSING_ERROR_INVALID_LOCAL_IP :
case CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION :
case CERTIFICATE_PARSING_ERROR_UNKNOWN_SECTION_PTAG :
case CERTIFICATE_PARSING_ERROR_MISSING_CHECKSUM :
2014-02-01 09:16:15 -05:00
default :
2017-01-22 15:44:26 -05:00
errorMsg = tr ( " Not a valid Retroshare certificate! " ) ;
2016-12-21 13:07:57 -05:00
ui - > friendCertCleanLabel - > setStyleSheet ( " QLabel#friendCertCleanLabel {border: 2px solid red; border-radius: 6px;} " ) ;
2014-02-01 09:16:15 -05:00
}
}
2020-08-19 10:19:42 -04:00
ui - > friendCertCleanLabel - > setPixmap ( FilesDefs : : getPixmapFromQtResourcePath ( " :/images/delete.png " ) ) ;
2014-02-01 09:16:15 -05:00
}
}
2020-08-19 10:19:42 -04:00
ui - > friendCertCleanLabel - > setPixmap ( certValid ? FilesDefs : : getPixmapFromQtResourcePath ( " :/images/accepted16.png " ) : FilesDefs : : getPixmapFromQtResourcePath ( " :/images/delete.png " ) ) ;
2014-02-01 09:16:15 -05:00
ui - > friendCertCleanLabel - > setToolTip ( errorMsg ) ;
2016-12-21 13:07:57 -05:00
ui - > friendCertCleanLabel - > setText ( errorMsg ) ;
2014-02-01 09:16:15 -05:00
ui - > TextPage - > setComplete ( certValid ) ;
}
2015-06-07 14:28:17 -04:00
void ConnectFriendWizard : : pasteCert ( )
{
QClipboard * clipboard = QApplication : : clipboard ( ) ;
ui - > friendCertEdit - > setPlainText ( clipboard - > text ( ) ) ;
}
2017-05-08 11:26:12 -04:00
void ConnectFriendWizard : : openCert ( )
{
QString fileName ;
if ( ! misc : : getOpenFileName ( this , RshareSettings : : LASTDIR_CERT , tr ( " Select Certificate " ) , tr ( " RetroShare Certificate (*.rsc );;All Files (*) " ) , fileName ) )
return ;
if ( ! fileName . isNull ( ) ) {
QFile fileCert ( fileName ) ;
if ( fileCert . open ( QIODevice : : ReadOnly ) ) {
QByteArray arrayCert ( fileCert . readAll ( ) ) ;
ui - > friendCertEdit - > setPlainText ( QString : : fromUtf8 ( arrayCert ) ) ;
fileCert . close ( ) ;
}
}
}
2019-06-09 18:36:40 -04:00
# ifdef TO_BE_REMOVED
2014-02-01 09:16:15 -05:00
//========================== CertificatePage =================================
void ConnectFriendWizard : : loadFriendCert ( )
{
2016-07-31 16:14:23 -04:00
QString fileName ;
if ( ! misc : : getOpenFileName ( this , RshareSettings : : LASTDIR_CERT , tr ( " Select Certificate " ) , tr ( " RetroShare Certificate (*.rsc );;All Files (*) " ) , fileName ) )
return ;
2014-02-01 09:16:15 -05:00
if ( ! fileName . isNull ( ) ) {
ui - > friendFileNameEdit - > setText ( fileName ) ;
}
}
void ConnectFriendWizard : : generateCertificateCalled ( )
{
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " generateCertificateCalled " < < std : : endl ;
# endif
2018-10-05 20:46:09 -04:00
std : : string cert = rsPeers - > GetRetroshareInvite ( ) ;
2014-02-01 09:16:15 -05:00
if ( cert . empty ( ) ) {
QMessageBox : : information ( this , " RetroShare " , tr ( " Sorry, create certificate failed " ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
return ;
}
QString qdir = QFileDialog : : getSaveFileName ( this , tr ( " Please choose a filename " ) , QDir : : homePath ( ) , tr ( " RetroShare Certificate (*.rsc );;All Files (*) " ) ) ;
//Todo: move save to file to p3Peers::SaveCertificateToFile
if ( qdir . isEmpty ( ) = = false ) {
QFile CertFile ( qdir ) ;
if ( CertFile . open ( QIODevice : : WriteOnly /* | QIODevice::Text*/ ) ) {
if ( CertFile . write ( QByteArray ( cert . c_str ( ) ) ) > 0 ) {
QMessageBox : : information ( this , " RetroShare " , tr ( " Certificate file successfully created " ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
} else {
QMessageBox : : information ( this , " RetroShare " , tr ( " Sorry, certificate file creation failed " ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
}
CertFile . close ( ) ;
} else {
QMessageBox : : information ( this , " RetroShare " , tr ( " Sorry, certificate file creation failed " ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
}
}
}
//============================= FofPage ======================================
void ConnectFriendWizard : : updatePeersList ( int index )
{
ui - > selectedPeersTW - > clearContents ( ) ;
ui - > selectedPeersTW - > setRowCount ( 0 ) ;
2014-03-17 16:56:06 -04:00
RsPgpId ownId = rsPeers - > getGPGOwnId ( ) ;
2014-02-01 09:16:15 -05:00
int row = 0 ;
_id_boxes . clear ( ) ;
// We have to use this trick because signers are given by their names instead of their ids. That's a cause
// for some confusion when two peers have the same name.
//
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > gpg_ids ;
2014-02-01 09:16:15 -05:00
rsPeers - > getGPGAllList ( gpg_ids ) ;
2014-03-17 16:56:06 -04:00
for ( std : : list < RsPgpId > : : const_iterator it ( gpg_ids . begin ( ) ) ; it ! = gpg_ids . end ( ) ; + + it ) {
2014-02-01 09:16:15 -05:00
if ( * it = = ownId ) {
// its me
continue ;
}
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " examining peer " < < * it < < " (name= " < < rsPeers - > getPeerName ( * it ) ;
# endif
RsPeerDetails details ;
2014-03-17 16:56:06 -04:00
if ( ! rsPeers - > getGPGDetails ( * it , details ) ) {
2014-02-01 09:16:15 -05:00
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " no details. " < < std : : endl ;
# endif
continue ;
}
// determine common friends
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > common_friends ;
2014-02-01 09:16:15 -05:00
2014-03-17 16:56:06 -04:00
for ( std : : list < RsPgpId > : : const_iterator it2 ( details . gpgSigners . begin ( ) ) ; it2 ! = details . gpgSigners . end ( ) ; + + it2 ) {
2014-02-01 09:16:15 -05:00
if ( rsPeers - > isGPGAccepted ( * it2 ) ) {
common_friends . push_back ( * it2 ) ;
}
}
bool show = false ;
switch ( index ) {
case 0 : // "All unsigned friends of my friends"
show = ! details . ownsign ;
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " case 0: ownsign= " < < details . ownsign < < " , show= " < < show < < std : : endl ;
# endif
break ;
case 1 : // "Unsigned peers who already signed my certificate"
show = details . hasSignedMe & & ! ( details . state & RS_PEER_STATE_FRIEND ) ;
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " case 1, ownsign= " < < details . ownsign < < " , is_authed_me= " < < details . hasSignedMe < < " , show= " < < show < < std : : endl ;
# endif
break ;
case 2 : // "Peers shown as denied"
show = details . ownsign & & ! ( details . state & RS_PEER_STATE_FRIEND ) ;
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " case 2, ownsign= " < < details . ownsign < < " , state_friend= " < < ( details . state & RS_PEER_STATE_FRIEND ) < < " , show= " < < show < < std : : endl ;
# endif
break ;
}
if ( show ) {
ui - > selectedPeersTW - > insertRow ( row ) ;
QCheckBox * cb = new QCheckBox ;
cb - > setChecked ( true ) ;
_id_boxes [ cb ] = details . id ;
_gpg_id_boxes [ cb ] = details . gpg_id ;
ui - > selectedPeersTW - > setCellWidget ( row , 0 , cb ) ;
ui - > selectedPeersTW - > setItem ( row , 1 , new QTableWidgetItem ( QString : : fromUtf8 ( details . name . c_str ( ) ) ) ) ;
QComboBox * qcb = new QComboBox ;
if ( common_friends . empty ( ) ) {
qcb - > addItem ( tr ( " *** None *** " ) ) ;
} else {
2014-03-17 16:56:06 -04:00
for ( std : : list < RsPgpId > : : const_iterator it2 ( common_friends . begin ( ) ) ; it2 ! = common_friends . end ( ) ; + + it2 ) {
qcb - > addItem ( QString : : fromStdString ( ( * it2 ) . toStdString ( ) ) ) ;
2014-02-01 09:16:15 -05:00
}
}
ui - > selectedPeersTW - > setCellWidget ( row , 2 , qcb ) ;
2014-03-17 16:56:06 -04:00
ui - > selectedPeersTW - > setItem ( row , 3 , new QTableWidgetItem ( QString : : fromStdString ( details . id . toStdString ( ) ) ) ) ;
2014-02-01 09:16:15 -05:00
+ + row ;
}
}
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " FofPage::updatePeersList() finished iterating over peers " < < std : : endl ;
# endif
if ( row > 0 ) {
ui - > selectedPeersTW - > resizeColumnsToContents ( ) ;
ui - > makeFriendButton - > setEnabled ( true ) ;
} else {
ui - > makeFriendButton - > setEnabled ( false ) ;
}
}
void ConnectFriendWizard : : signAllSelectedUsers ( )
{
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " making lots of friends !! " < < std : : endl ;
# endif
2014-03-17 16:56:06 -04:00
for ( std : : map < QCheckBox * , RsPeerId > : : const_iterator it ( _id_boxes . begin ( ) ) ; it ! = _id_boxes . end ( ) ; + + it ) {
2014-02-01 09:16:15 -05:00
if ( it - > first - > isChecked ( ) ) {
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " Making friend with " < < it - > second < < std : : endl ;
# endif
//rsPeers->AuthCertificate(it->second, "");
rsPeers - > addFriend ( it - > second , _gpg_id_boxes [ it - > first ] ) ;
}
}
ui - > FofPage - > setComplete ( true ) ;
ui - > userSelectionCB - > setEnabled ( false ) ;
ui - > selectedPeersTW - > setEnabled ( false ) ;
ui - > makeFriendButton - > setEnabled ( false ) ;
NotifyQt : : getInstance ( ) - > notifyListChange ( NOTIFY_LIST_NEIGHBOURS , 0 ) ;
NotifyQt : : getInstance ( ) - > notifyListChange ( NOTIFY_LIST_FRIENDS , 0 ) ;
}
//============================= RsidPage =====================================
2019-06-09 18:20:01 -04:00
2014-02-01 09:16:15 -05:00
//============================ Emailpage =====================================
2019-06-09 18:22:57 -04:00
# endif
2014-02-01 09:16:15 -05:00
//========================= ErrorMessagePage =================================
//========================== ConclusionPage ==================================
void ConnectFriendWizard : : setGroup ( const std : : string & id )
{
groupId = QString : : fromStdString ( id ) ;
}
void ConnectFriendWizard : : groupCurrentIndexChanged ( int index )
{
QComboBox * comboBox = dynamic_cast < QComboBox * > ( sender ( ) ) ;
if ( comboBox ) {
groupId = comboBox - > itemData ( index , Qt : : UserRole ) . toString ( ) ;
}
}
2015-10-24 11:05:12 -04:00
//========================== WebMailPage ==================================
void ConnectFriendWizard : : inviteGmail ( )
{
QDesktopServices : : openUrl ( QUrl ( " https://mail.google.com/mail/?view=cm&fs=1&su= " + subject + " &body= " + body , QUrl : : TolerantMode ) ) ;
}
void ConnectFriendWizard : : inviteYahoo ( )
{
QDesktopServices : : openUrl ( QUrl ( " http://compose.mail.yahoo.com/?&subject= " + subject + " &body= " + body , QUrl : : TolerantMode ) ) ;
}
2014-02-01 09:16:15 -05:00
2015-10-24 11:05:12 -04:00
void ConnectFriendWizard : : inviteOutlook ( )
{
QDesktopServices : : openUrl ( QUrl ( " http://mail.live.com/mail/EditMessageLight.aspx?n=&subject= " + subject + " &body= " + body , QUrl : : TolerantMode ) ) ;
}
void ConnectFriendWizard : : inviteAol ( )
{
QDesktopServices : : openUrl ( QUrl ( " http://webmail.aol.com/Mail/ComposeMessage.aspx?&subject= " + subject + " &body= " + body , QUrl : : TolerantMode ) ) ;
}
void ConnectFriendWizard : : inviteYandex ( )
{
QDesktopServices : : openUrl ( QUrl ( " https://mail.yandex.com/neo2/#compose/subject= " + subject + " &body= " + body , QUrl : : TolerantMode ) ) ;
}
2015-10-24 18:54:22 -04:00
void ConnectFriendWizard : : runEmailClient2 ( )
{
sendMail ( " " , subject , body ) ;
}
2017-01-23 07:09:40 -05:00
void ConnectFriendWizard : : toggleAdvanced ( )
{
if ( AdvancedVisible )
{
2017-07-03 12:36:47 -04:00
ui - > cp_Frame - > hide ( ) ;
2017-01-23 07:09:40 -05:00
ui - > toggleadvancedButton - > setText ( " Show advanced options " ) ;
AdvancedVisible = false ;
}
else
{
2017-07-03 12:36:47 -04:00
ui - > cp_Frame - > show ( ) ;
2017-01-23 07:09:40 -05:00
ui - > toggleadvancedButton - > setText ( " Hide advanced options " ) ;
AdvancedVisible = true ;
}
}