2009-03-26 12:58:06 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2009 The RetroShare Team , Oleksiy Bilyanskyy
*
* 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 "ConnectFriendWizard.h"
# include "rsiface/rspeers.h" //for rsPeers variable
# include "rsiface/rsiface.h"
# include <QLineEdit>
# include <QTextEdit>
# include <QLabel>
# include <QPushButton>
# include <QRadioButton>
# include <QCheckBox>
# include <QGroupBox>
2009-05-18 15:51:40 -04:00
# include <QComboBox>
2009-07-14 09:29:49 -04:00
# include <QtGui>
# include <QClipboard>
2009-05-18 15:51:40 -04:00
# include <QTableWidget>
# include <QHeaderView>
2009-03-26 12:58:06 -04:00
# include <QFileDialog>
# include <QGridLayout>
# include <QVBoxLayout>
# include <QHBoxLayout>
# include <QMessageBox>
# include <QRegExpValidator>
# include <QRegExp>
2010-01-13 16:29:21 -05:00
# include <boost/lexical_cast.hpp>
2009-03-26 12:58:06 -04:00
# include <QDebug>
2009-05-05 15:19:36 -04:00
# include <sstream>
# include <iostream>
2009-05-18 15:51:40 -04:00
# include <set>
2009-03-26 12:58:06 -04:00
2010-01-13 16:22:52 -05:00
# define SSL_ID_FIELD_CONNECT_FRIEND_WIZARD "idField"
# define GPG_ID_FIELD_CONNECT_FRIEND_WIZARD "GPGidField"
# define LOCATION_FIELD_CONNECT_FRIEND_WIZARD "peerLocation"
# define CERT_STRING_FIELD_CONNECT_FRIEND_WIZARD "peerCertString"
# define SIGN_RADIO_BUTTON_FIELD_CONNECT_FRIEND_WIZARD "signRadioButton"
# define ACCEPT_RADIO_BUTTON_FIELD_CONNECT_FRIEND_WIZARD "acceptRadioButton"
2009-03-26 12:58:06 -04:00
//============================================================================
//!
ConnectFriendWizard : : ConnectFriendWizard ( QWidget * parent )
: QWizard ( parent )
{
setPage ( Page_Intro , new IntroPage ) ;
setPage ( Page_Text , new TextPage ) ;
setPage ( Page_Cert , new CertificatePage ) ;
2009-05-18 15:51:40 -04:00
setPage ( Page_Foff , new FofPage ) ;
2009-03-26 12:58:06 -04:00
setPage ( Page_ErrorMessage , new ErrorMessagePage ) ;
setPage ( Page_Conclusion , new ConclusionPage ) ;
setStartId ( Page_Intro ) ;
// this define comes from Qt example. I don't have mac, so it wasn't tested
# ifndef Q_WS_MAC
setWizardStyle ( ModernStyle ) ;
# endif
2009-03-28 06:41:49 -04:00
// at this moment I don't know, what information should be in help
// setOption(HaveHelpButton, true);
// connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp()));
2009-03-26 12:58:06 -04:00
setPixmap ( QWizard : : LogoPixmap ,
QPixmap ( " :/images/connect/connectFriendLogo.png " ) ) ;
2009-03-28 06:41:49 -04:00
// we have no good pictures for watermarks
2009-03-26 12:58:06 -04:00
// setPixmap(QWizard::WatermarkPixmap,
// QPixmap(":/images/connectFriendWatermark.png"));
setPixmap ( QWizard : : BannerPixmap ,
QPixmap ( " :/images/connect/connectFriendBanner.png " ) ) ;
setWindowTitle ( tr ( " Connect Friend Wizard " ) ) ;
}
//============================================================================
void
ConnectFriendWizard : : accept ( )
{
2010-01-13 16:22:52 -05:00
if ( hasVisitedPage ( Page_Conclusion ) ) {
std : : cerr < < " ConnectFriendWizard::accept() called with page conclusion visited " < < std : : endl ;
std : : string ssl_Id = field ( SSL_ID_FIELD_CONNECT_FRIEND_WIZARD ) . toString ( ) . toStdString ( ) ;
std : : string gpg_Id = field ( GPG_ID_FIELD_CONNECT_FRIEND_WIZARD ) . toString ( ) . toStdString ( ) ;
bool sign = field ( SIGN_RADIO_BUTTON_FIELD_CONNECT_FRIEND_WIZARD ) . toBool ( ) ;
bool accept_connection = field ( ACCEPT_RADIO_BUTTON_FIELD_CONNECT_FRIEND_WIZARD ) . toBool ( ) ;
if ( gpg_Id ! = " " ) {
if ( sign ) {
std : : cerr < < " ConclusionPage::validatePage() signing GPG key. " < < std : : endl ;
rsPeers - > signGPGCertificate ( gpg_Id ) ; //bye default sign set accept_connection to true;
} else if ( accept_connection ) {
std : : cerr < < " ConclusionPage::validatePage() accepting GPG key for connection. " < < std : : endl ;
rsPeers - > setAcceptToConnectGPGCertificate ( gpg_Id , true ) ;
}
}
2009-09-06 15:53:22 -04:00
2010-01-13 16:22:52 -05:00
if ( ssl_Id ! = " " ) {
rsPeers - > addFriend ( ssl_Id , gpg_Id ) ;
//let's check if there is ip adresses in the wizard.
if ( ! this - > field ( " ext_friend_ip " ) . isNull ( ) & & ! this - > field ( " ext_friend_port " ) . isNull ( ) ) {
std : : cerr < < " ConnectFriendWizard::accept() : setting ip ext address. " < < std : : endl ;
rsPeers - > setExtAddress ( ssl_Id , this - > field ( " ext_friend_ip " ) . toString ( ) . toStdString ( ) , this - > field ( " ext_friend_port " ) . toInt ( ) ) ;
}
if ( ! this - > field ( " local_friend_ip " ) . isNull ( ) & & ! this - > field ( " local_friend_port " ) . isNull ( ) ) {
std : : cerr < < " ConnectFriendWizard::accept() : setting ip local address. " < < std : : endl ;
rsPeers - > setLocalAddress ( ssl_Id , this - > field ( " local_friend_ip " ) . toString ( ) . toStdString ( ) , this - > field ( " local_friend_port " ) . toInt ( ) ) ;
}
2010-01-13 16:29:21 -05:00
if ( ! this - > field ( LOCATION_FIELD_CONNECT_FRIEND_WIZARD ) . isNull ( ) ) {
2010-01-13 16:22:52 -05:00
std : : cerr < < " ConnectFriendWizard::accept() : setting peerLocation. " < < std : : endl ;
2010-01-13 16:29:21 -05:00
rsPeers - > setLocation ( ssl_Id , this - > field ( LOCATION_FIELD_CONNECT_FRIEND_WIZARD ) . toString ( ) . toStdString ( ) ) ;
2010-01-13 16:22:52 -05:00
}
}
2009-09-06 15:53:22 -04:00
2009-03-26 12:58:06 -04:00
rsicontrol - > getNotify ( ) . notifyListChange ( NOTIFY_LIST_NEIGHBOURS , 1 ) ;
}
QDialog : : accept ( ) ;
}
//============================================================================
//============================================================================
//============================================================================
//
IntroPage : : IntroPage ( QWidget * parent )
: QWizardPage ( parent )
{
QString titleStr ( " <span style= \" font-size:14pt; font-weight:500; "
" color:#32cd32; \" >%1</span> " ) ;
setTitle ( titleStr . arg ( tr ( " Add a new Friend " ) ) ) ;
2009-05-18 15:51:40 -04:00
setSubTitle ( tr ( " This wizard will help you to connect to your friend(s) "
" to RetroShare network. There are three possible ways "
2009-03-26 12:58:06 -04:00
" to do this: " ) ) ;
textRadioButton = new QRadioButton ( tr ( " &Enter the certificate manually " ) ) ;
2009-05-18 15:51:40 -04:00
certRadioButton = new QRadioButton ( tr ( " &Use *.pqi files with certificates " ) ) ;
foffRadioButton = new QRadioButton ( tr ( " &Make friend with selected friends of my friends " ) ) ;
2009-03-26 12:58:06 -04:00
textRadioButton - > setChecked ( true ) ;
QVBoxLayout * layout = new QVBoxLayout ;
layout - > addWidget ( textRadioButton ) ;
layout - > addWidget ( certRadioButton ) ;
2009-05-18 15:51:40 -04:00
layout - > addWidget ( foffRadioButton ) ;
2009-03-26 12:58:06 -04:00
setLayout ( layout ) ;
}
//
//============================================================================
//
int IntroPage : : nextId ( ) const
{
2009-05-18 15:51:40 -04:00
if ( textRadioButton - > isChecked ( ) ) return ConnectFriendWizard : : Page_Text ;
if ( certRadioButton - > isChecked ( ) ) return ConnectFriendWizard : : Page_Cert ;
if ( foffRadioButton - > isChecked ( ) ) return ConnectFriendWizard : : Page_Foff ;
2009-03-26 12:58:06 -04:00
}
//
//============================================================================
//============================================================================
//============================================================================
//
TextPage : : TextPage ( QWidget * parent )
: QWizardPage ( parent )
{
QString titleStr ( " <span style= \" font-size:14pt; font-weight:500; "
" color:#32cd32; \" >%1</span> " ) ;
setTitle ( titleStr . arg ( tr ( " Text certificate " ) ) ) ;
2009-08-08 06:05:56 -04:00
setSubTitle ( tr ( " Use text representation of the PGP certificates. " ) ) ;
2009-03-26 12:58:06 -04:00
2009-08-08 06:05:56 -04:00
userCertLabel = new QLabel ( tr ( " The text below is your PGP certificate. "
2009-03-26 12:58:06 -04:00
" You have to provide it to your friend " ) ) ;
2009-05-23 11:13:01 -04:00
std : : cerr < < " TextPage() getting Invite " < < std : : endl ;
2009-03-26 12:58:06 -04:00
userCertEdit = new QTextEdit ;
std : : string invite = rsPeers - > GetRetroshareInvite ( ) ;
2009-05-05 15:19:36 -04:00
2009-03-26 12:58:06 -04:00
userCertEdit - > setText ( QString : : fromStdString ( invite ) ) ;
userCertEdit - > setReadOnly ( true ) ;
2009-05-05 15:19:36 -04:00
userCertEdit - > setMinimumHeight ( 200 ) ;
2009-03-26 12:58:06 -04:00
2009-05-23 11:13:01 -04:00
std : : cerr < < " TextPage() getting Invite: " < < invite < < std : : endl ;
2009-03-26 12:58:06 -04:00
userCertHelpButton = new QPushButton ;
userCertHelpButton - > setSizePolicy ( QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ;
userCertHelpButton - > setFixedSize ( 20 , 20 ) ;
userCertHelpButton - > setFlat ( true ) ;
userCertHelpButton - > setIcon ( QIcon ( " :images/connect/info16.png " ) ) ;
connect ( userCertHelpButton , SIGNAL ( clicked ( ) ) ,
this , SLOT ( showHelpUserCert ( ) ) ) ;
2009-07-14 09:29:49 -04:00
userCertCopyButton = new QPushButton ;
userCertCopyButton - > setSizePolicy ( QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ;
userCertCopyButton - > setFixedSize ( 20 , 20 ) ;
userCertCopyButton - > setFlat ( true ) ;
userCertCopyButton - > setIcon ( QIcon ( " :images/copyrslink.png " ) ) ;
userCertCopyButton - > setToolTip ( tr ( " Copy your Cert to Clipboard " ) ) ;
connect ( userCertCopyButton , SIGNAL ( clicked ( ) ) ,
this , SLOT ( copyCert ( ) ) ) ;
2009-03-26 12:58:06 -04:00
# if defined(Q_OS_WIN)
userCertMailButton = new QPushButton ;
userCertMailButton - > setSizePolicy ( QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ;
userCertMailButton - > setFixedSize ( 20 , 20 ) ;
userCertMailButton - > setFlat ( true ) ;
userCertMailButton - > setIcon ( QIcon ( " :images/connect/mail_send.png " ) ) ;
userCertMailButton - > setToolTip ( tr ( " Run Email program " ) ) ;
connect ( userCertMailButton , SIGNAL ( clicked ( ) ) ,
this , SLOT ( runEmailClient ( ) ) ) ;
# endif
userCertButtonsLayout = new QVBoxLayout ( ) ;
userCertButtonsLayout - > addWidget ( userCertHelpButton ) ;
2009-07-14 09:29:49 -04:00
userCertButtonsLayout - > addWidget ( userCertCopyButton ) ;
2009-03-26 12:58:06 -04:00
# if defined(Q_OS_WIN)
userCertButtonsLayout - > addWidget ( userCertMailButton ) ;
# endif
userCertLayout = new QHBoxLayout ( ) ;
userCertLayout - > addWidget ( userCertEdit ) ;
userCertLayout - > addLayout ( userCertButtonsLayout ) ;
2009-08-08 06:05:56 -04:00
friendCertLabel = new QLabel ( tr ( " Please, paste your friends PGP "
2009-03-26 12:58:06 -04:00
" certificate into the box below " ) ) ;
friendCertEdit = new QTextEdit ;
registerField ( " aaabbb " , friendCertEdit , " plainText " ) ; //, "textChanged");
//=== add all widgets to one layout
textPageLayout = new QVBoxLayout ( ) ;
textPageLayout - > addWidget ( userCertLabel ) ;
textPageLayout - > addLayout ( userCertLayout ) ;
textPageLayout - > addWidget ( friendCertLabel ) ;
textPageLayout - > addWidget ( friendCertEdit ) ;
//
setLayout ( textPageLayout ) ;
}
//
//============================================================================
//
# if defined(Q_OS_WIN)
# include <iostream>
# include <windows.h>
void
TextPage : : runEmailClient ( )
{
std : : string mailstr = " mailto: " ;
mailstr + = " ?subject=RetroShare Invite " ;
mailstr + = " &body= " ;
mailstr + = ( userCertEdit - > toPlainText ( ) ) . toStdString ( ) ;
/* search and replace the end of lines with: "%0D%0A" */
std : : cerr < < " MAIL STRING: " < < mailstr . c_str ( ) < < std : : endl ;
size_t loc ;
while ( ( loc = mailstr . find ( " \n " ) ) ! = mailstr . npos )
{
/* sdfkasdflkjh */
mailstr . replace ( loc , 1 , " %0D%0A " ) ;
}
HINSTANCE hInst = ShellExecuteA ( 0 , " open " , mailstr . c_str ( ) ,
NULL , NULL , SW_SHOW ) ;
if ( reinterpret_cast < int > ( hInst ) < = 32 )
{
/* error */
std : : cerr < < " ShellExecute Error: " < < reinterpret_cast < int > ( hInst ) ;
std : : cerr < < std : : endl ;
}
}
# endif
//
//============================================================================
//
void
TextPage : : showHelpUserCert ( )
{
QMessageBox : : information ( this ,
tr ( " Connect Friend Help " ) ,
tr ( " You can copy this text and send it to your "
2009-07-14 11:09:20 -04:00
" friend via email or some other way " ) ) ;
2009-07-14 09:29:49 -04:00
}
//
//============================================================================
//
void
TextPage : : copyCert ( )
{
QMessageBox : : information ( this ,
tr ( " RetroShare " ) ,
2009-07-25 10:23:41 -04:00
tr ( " Your Cert is copied to Clipboard, paste and send it to your "
2009-07-14 11:09:20 -04:00
" friend via email or some other way " ) ) ;
2009-07-14 09:29:49 -04:00
QClipboard * clipboard = QApplication : : clipboard ( ) ;
clipboard - > setText ( userCertEdit - > toPlainText ( ) ) ;
2009-03-26 12:58:06 -04:00
}
//
//============================================================================
//
2009-07-14 09:29:49 -04:00
2010-01-13 16:22:52 -05:00
int TextPage : : nextId ( ) const {
2009-03-26 12:58:06 -04:00
std : : string certstr ;
certstr = friendCertEdit - > toPlainText ( ) . toStdString ( ) ;
2010-01-13 16:22:52 -05:00
RsPeerDetails pd ;
if ( rsPeers - > loadDetailsFromStringCert ( certstr , pd ) ) {
# ifdef FRIEND_WIZARD_DEBUG
std : : cerr < < " ConnectFriendWizard got id : " < < pd . id < < " ; gpg_id : " < < pd . gpg_id < < std : : endl ;
# endif
wizard ( ) - > setField ( SSL_ID_FIELD_CONNECT_FRIEND_WIZARD , QString : : fromStdString ( pd . id ) ) ;
wizard ( ) - > setField ( GPG_ID_FIELD_CONNECT_FRIEND_WIZARD , QString : : fromStdString ( pd . gpg_id ) ) ;
wizard ( ) - > setField ( LOCATION_FIELD_CONNECT_FRIEND_WIZARD , QString : : fromStdString ( pd . location ) ) ;
wizard ( ) - > setField ( CERT_STRING_FIELD_CONNECT_FRIEND_WIZARD , QString : : fromStdString ( certstr ) ) ;
2009-03-26 12:58:06 -04:00
2010-01-13 16:29:21 -05:00
wizard ( ) - > setField ( " ext_friend_ip " , QString : : fromStdString ( pd . extAddr ) ) ;
wizard ( ) - > setField ( " ext_friend_port " , QString : : fromStdString ( boost : : lexical_cast < std : : string > ( pd . extPort ) ) ) ;
wizard ( ) - > setField ( " local_friend_ip " , QString : : fromStdString ( pd . localAddr ) ) ;
wizard ( ) - > setField ( " local_friend_port " , QString : : fromStdString ( boost : : lexical_cast < std : : string > ( pd . localPort ) ) ) ;
2009-05-05 15:19:36 -04:00
2009-03-26 12:58:06 -04:00
return ConnectFriendWizard : : Page_Conclusion ;
}
else
{
// error message
wizard ( ) - > setField ( " errorMessage " , tr ( " Certificate Load Failed " ) ) ;
return ConnectFriendWizard : : Page_ErrorMessage ;
}
return ConnectFriendWizard : : Page_ErrorMessage ;
}
//
//============================================================================
//============================================================================
2009-05-18 15:51:40 -04:00
//============================================================================
//
2010-01-13 16:22:52 -05:00
FofPage : : FofPage ( QWidget * parent ) : QWizardPage ( parent ) {
2009-05-18 15:51:40 -04:00
_friends_signed = false ;
QString titleStr ( " <span style= \" font-size:14pt; font-weight:500; " " color:#32cd32; \" >%1</span> " ) ;
setTitle ( titleStr . arg ( tr ( " Friends of friends " ) ) ) ;
setSubTitle ( tr ( " Select now who you want to make friends with. " ) ) ;
userFileLabel = new QLabel ( tr ( " Show me: " ) ) ;
userSelectionCB = new QComboBox ;
userSelectionCB - > addItem ( tr ( " Any peer I've not signed " ) ) ;
userSelectionCB - > addItem ( tr ( " Friends of my friends who already trust me " ) ) ;
userSelectionCB - > addItem ( tr ( " Signed peers showing as denied " ) ) ;
selectedPeersTW = new QTableWidget ( 0 , 4 , NULL ) ;
selectedPeersTW - > setHorizontalHeaderItem ( 0 , new QTableWidgetItem ( tr ( " " ) ) ) ;
selectedPeersTW - > setHorizontalHeaderItem ( 1 , new QTableWidgetItem ( tr ( " Peer name " ) ) ) ;
selectedPeersTW - > setHorizontalHeaderItem ( 2 , new QTableWidgetItem ( tr ( " Also signed by " ) ) ) ;
selectedPeersTW - > setHorizontalHeaderItem ( 3 , new QTableWidgetItem ( tr ( " Peer id " ) ) ) ;
makeFriendButton = new QPushButton ( tr ( " Make friend with these peers " ) ) ;
userFileLayout = new QVBoxLayout ;
userFileLayout - > addWidget ( userFileLabel ) ;
userFileLayout - > addWidget ( userSelectionCB ) ;
userFileLayout - > addWidget ( selectedPeersTW ) ;
userFileLayout - > addWidget ( makeFriendButton ) ;
2009-05-25 07:33:27 -04:00
// userFileFrame = new QGroupBox;
// userFileFrame->setFlat(true);
// userFileFrame->setTitle("toto");
// userFileFrame->setLayout(userFileLayout);
2009-05-18 15:51:40 -04:00
setLayout ( userFileLayout ) ;
connect ( makeFriendButton , SIGNAL ( clicked ( ) ) , this , SLOT ( signAllSelectedUsers ( ) ) ) ;
connect ( userSelectionCB , SIGNAL ( activated ( int ) ) , this , SLOT ( updatePeersList ( int ) ) ) ;
updatePeersList ( 0 ) ;
}
2010-01-13 16:22:52 -05:00
void FofPage : : updatePeersList ( int e ) {
2009-05-18 15:51:40 -04:00
rsiface - > unlockData ( ) ; /* UnLock Interface */
selectedPeersTW - > clearContents ( ) ;
2010-01-13 16:22:52 -05:00
selectedPeersTW - > setRowCount ( 0 ) ;
2009-05-18 15:51:40 -04:00
std : : list < std : : string > ids ;
2010-01-13 16:22:52 -05:00
rsPeers - > getGPGAllList ( ids ) ;
2009-05-18 15:51:40 -04:00
int row = 0 ;
_id_boxes . clear ( ) ;
2010-01-13 16:22:52 -05:00
std : : cerr < < " FofPage::updatePeersList() updating peers list with e= " < < e < < std : : endl ;
2009-05-18 15:51:40 -04:00
// 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.
//
2010-01-13 16:22:52 -05:00
std : : list < std : : string > gpg_ids ;
rsPeers - > getGPGAllList ( gpg_ids ) ;
for ( std : : list < std : : string > : : const_iterator it ( gpg_ids . begin ( ) ) ; it ! = gpg_ids . end ( ) ; + + it )
2009-05-18 15:51:40 -04:00
{
std : : cerr < < " examining peer " < < * it < < " (name= " < < rsPeers - > getPeerName ( * it ) ;
RsPeerDetails details ;
if ( ! rsPeers - > getPeerDetails ( * it , details ) )
{
std : : cerr < < " no details. " < < std : : endl ;
continue ;
}
// determine common friends
std : : set < std : : string > common_friends ;
2010-01-13 16:22:52 -05:00
for ( std : : list < std : : string > : : const_iterator it2 ( details . gpgSigners . begin ( ) ) ; it2 ! = details . gpgSigners . end ( ) ; + + it2 ) {
if ( rsPeers - > isGPGAccepted ( * it2 ) ) {
common_friends . insert ( * it2 ) ;
}
}
2009-05-18 15:51:40 -04:00
bool show = false ;
switch ( e )
{
case 2 : // "Peers shown as denied"
show = details . ownsign & & ! ( details . state & RS_PEER_STATE_FRIEND ) ;
std : : cerr < < " case 2, ownsign= " < < details . ownsign < < " , state_friend= " < < ( details . state & RS_PEER_STATE_FRIEND ) < < " , show= " < < show < < std : : endl ;
break ;
case 1 : // "Unsigned peers who already signed my certificate"
2010-01-13 16:14:49 -05:00
show = details . hasSignedMe & & ! ( details . state & RS_PEER_STATE_FRIEND ) ;
std : : cerr < < " case 1, ownsign= " < < details . ownsign < < " , is_authed_me= " < < details . hasSignedMe < < " , show= " < < show < < std : : endl ;
2009-05-18 15:51:40 -04:00
break ;
case 0 : // "All unsigned friends of my friends"
show = ! details . ownsign ;
std : : cerr < < " case 0: ownsign= " < < details . ownsign < < " , show= " < < show < < std : : endl ;
break ;
default : break ;
}
2010-01-13 16:22:52 -05:00
if ( show )
2009-05-18 15:51:40 -04:00
{
selectedPeersTW - > insertRow ( row ) ;
QCheckBox * cb = new QCheckBox ;
cb - > setChecked ( true ) ;
_id_boxes [ cb ] = details . id ;
2010-01-13 16:22:52 -05:00
_gpg_id_boxes [ cb ] = details . gpg_id ;
2009-05-18 15:51:40 -04:00
selectedPeersTW - > setCellWidget ( row , 0 , cb ) ;
selectedPeersTW - > setItem ( row , 1 , new QTableWidgetItem ( QString : : fromStdString ( details . name ) ) ) ;
QComboBox * qcb = new QComboBox ;
if ( common_friends . empty ( ) )
qcb - > addItem ( tr ( " *** None *** " ) ) ;
else
for ( std : : set < std : : string > : : const_iterator it2 ( common_friends . begin ( ) ) ; it2 ! = common_friends . end ( ) ; + + it2 )
qcb - > addItem ( QString : : fromStdString ( * it2 ) ) ;
selectedPeersTW - > setCellWidget ( row , 2 , qcb ) ;
selectedPeersTW - > setItem ( row , 3 , new QTableWidgetItem ( QString : : fromStdString ( details . id ) ) ) ;
+ + row ;
}
}
2010-01-13 16:22:52 -05:00
std : : cerr < < " FofPage::updatePeersList() finished iterating over peers " < < std : : endl ;
2009-05-18 15:51:40 -04:00
if ( row > 0 )
{
selectedPeersTW - > resizeColumnsToContents ( ) ;
makeFriendButton - > setEnabled ( true ) ;
}
else
makeFriendButton - > setEnabled ( false ) ;
selectedPeersTW - > verticalHeader ( ) - > hide ( ) ;
selectedPeersTW - > setSortingEnabled ( true ) ;
}
2010-01-13 16:22:52 -05:00
int FofPage : : nextId ( ) const {
2009-05-18 15:51:40 -04:00
return - 1 ;
}
2010-01-13 16:22:52 -05:00
bool FofPage : : isComplete ( ) const {
2009-05-18 15:51:40 -04:00
return _friends_signed ;
}
2010-01-13 16:22:52 -05:00
void FofPage : : signAllSelectedUsers ( ) {
2009-05-18 15:51:40 -04:00
std : : cerr < < " makign lots of friends !! " < < std : : endl ;
for ( std : : map < QCheckBox * , std : : string > : : const_iterator it ( _id_boxes . begin ( ) ) ; it ! = _id_boxes . end ( ) ; + + it )
if ( it - > first - > isChecked ( ) )
{
std : : cerr < < " Making friend with " < < it - > second < < std : : endl ;
2010-01-13 16:11:02 -05:00
//rsPeers->AuthCertificate(it->second, "");
2010-01-13 16:22:52 -05:00
rsPeers - > addFriend ( it - > second , _gpg_id_boxes [ it - > first ] ) ;
2009-05-18 15:51:40 -04:00
}
_friends_signed = true ;
userSelectionCB - > setEnabled ( false ) ;
selectedPeersTW - > setEnabled ( false ) ;
makeFriendButton - > setEnabled ( false ) ;
2009-05-18 16:01:17 -04:00
rsicontrol - > getNotify ( ) . notifyListChange ( NOTIFY_LIST_NEIGHBOURS , 0 ) ;
rsicontrol - > getNotify ( ) . notifyListChange ( NOTIFY_LIST_FRIENDS , 0 ) ;
2009-05-18 15:51:40 -04:00
emit completeChanged ( ) ;
}
//
//============================================================================
//============================================================================
2009-03-26 12:58:06 -04:00
//============================================================================
2010-01-13 16:22:52 -05:00
CertificatePage : : CertificatePage ( QWidget * parent ) : QWizardPage ( parent ) {
2009-03-26 12:58:06 -04:00
QString titleStr ( " <span style= \" font-size:14pt; font-weight:500; "
" color:#32cd32; \" >%1</span> " ) ;
setTitle ( titleStr . arg ( tr ( " Certificate files " ) ) ) ;
2009-08-08 06:05:56 -04:00
setSubTitle ( tr ( " Use PGP certificates saved in files. " ) ) ;
2009-03-26 12:58:06 -04:00
userFileLabel = new QLabel ( tr ( " You have to generate a file with your "
" certificate and give it to your friend. "
" Also, you can use a file generated "
" before. " ) ) ;
userFileLabel - > setWordWrap ( true ) ;
userFileCreateButton = new QPushButton ;
2009-07-24 14:29:19 -04:00
userFileCreateButton - > setText ( tr ( " Export my certificate... " ) ) ;
2009-03-26 12:58:06 -04:00
connect ( userFileCreateButton , SIGNAL ( clicked ( ) ) ,
this , SLOT ( generateCertificateCalled ( ) ) ) ;
userFileLayout = new QHBoxLayout ;
userFileLayout - > addWidget ( userFileLabel ) ;
userFileLayout - > addWidget ( userFileCreateButton ) ;
userFileFrame = new QGroupBox ;
userFileFrame - > setFlat ( true ) ;
2009-12-22 08:49:38 -05:00
userFileFrame - > setTitle ( tr ( " Export my certificate... " ) ) ;
2009-03-26 12:58:06 -04:00
userFileFrame - > setLayout ( userFileLayout ) ;
friendFileLabel = new QLabel ( tr ( " Specify path to your friend's "
" certificate in the box below " ) ) ;
friendFileNameEdit = new QLineEdit ;
registerField ( " friendCertificateFile* " , friendFileNameEdit ) ;
friendFileNameOpenButton = new QPushButton ;
2009-07-24 14:29:19 -04:00
friendFileNameOpenButton - > setText ( tr ( " Browse " ) ) ;
2009-03-26 12:58:06 -04:00
connect ( friendFileNameOpenButton , SIGNAL ( clicked ( ) ) ,
this , SLOT ( loadFriendCert ( ) ) ) ;
friendFileLayout = new QHBoxLayout ;
friendFileLayout - > addWidget ( friendFileNameEdit ) ;
friendFileLayout - > addWidget ( friendFileNameOpenButton ) ;
certPageLayout = new QVBoxLayout ;
certPageLayout - > addWidget ( userFileFrame ) ;
certPageLayout - > addWidget ( friendFileLabel ) ;
certPageLayout - > addLayout ( friendFileLayout ) ;
setLayout ( certPageLayout ) ;
}
//============================================================================
2010-01-13 16:22:52 -05:00
void CertificatePage : : loadFriendCert ( ) {
2009-03-26 12:58:06 -04:00
QString fileName =
QFileDialog : : getOpenFileName ( this , tr ( " Select Certificate " ) ,
" " , tr ( " Certificates (*.pqi *.pem) " ) ) ;
if ( ! fileName . isNull ( ) )
{
friendFileNameEdit - > setText ( fileName ) ;
emit completeChanged ( ) ;
}
}
//============================================================================
2010-01-13 16:22:52 -05:00
void CertificatePage : : generateCertificateCalled ( ) {
2009-03-26 12:58:06 -04:00
qDebug ( ) < < " generateCertificateCalled " ;
QString qdir = QFileDialog : : getSaveFileName ( this ,
2009-12-22 08:49:38 -05:00
tr ( " Please choose a filename " ) ,
2009-03-26 12:58:06 -04:00
QDir : : homePath ( ) ,
" RetroShare Certificate (*.pqi) " ) ;
2010-01-13 16:22:52 -05:00
if ( rsPeers - > saveCertificateToFile ( rsPeers - > getOwnId ( ) , qdir . toStdString ( ) ) )
2009-03-26 12:58:06 -04:00
{
QMessageBox : : information ( this , tr ( " RetroShare " ) ,
tr ( " Certificate file successfully created " ) ,
QMessageBox : : Ok , QMessageBox : : Ok ) ;
}
else
{
QMessageBox : : information ( this , tr ( " RetroShare " ) ,
tr ( " Sorry, certificate file creation failed " ) ,
QMessageBox : : Ok , QMessageBox : : Ok ) ;
}
}
//============================================================================
2010-01-13 16:22:52 -05:00
bool CertificatePage : : isComplete ( ) const {
2009-03-26 12:58:06 -04:00
return ! ( ( friendFileNameEdit - > text ( ) ) . isEmpty ( ) ) ;
}
//============================================================================
2010-01-13 16:22:52 -05:00
int CertificatePage : : nextId ( ) const {
2009-03-26 12:58:06 -04:00
std : : string id ;
QString fn = friendFileNameEdit - > text ( ) ;
if ( QFile : : exists ( fn ) )
{
std : : string fnstr = fn . toStdString ( ) ;
2010-01-13 16:22:52 -05:00
// if ( rsPeers->LoadCertificateFromFile(fnstr, id) )
if ( false )
2009-03-26 12:58:06 -04:00
{
2010-01-13 16:22:52 -05:00
wizard ( ) - > setField ( SSL_ID_FIELD_CONNECT_FRIEND_WIZARD , QString : : fromStdString ( id ) ) ;
2009-03-26 12:58:06 -04:00
return ConnectFriendWizard : : Page_Conclusion ;
}
else
{
wizard ( ) - > setField ( " errorMessage " ,
2010-01-13 16:22:52 -05:00
// QString(tr("Certificate Load Failed:something is wrong with %1 ")).arg(fn) );
QString ( tr ( " Not implemented " ) ) ) ;
2009-03-26 12:58:06 -04:00
return ConnectFriendWizard : : Page_ErrorMessage ;
}
}
else
{
QString mess =
QString ( tr ( " Certificate Load Failed:file %1 not found " ) )
. arg ( fn ) ;
wizard ( ) - > setField ( " errorMessage " , mess ) ;
return ConnectFriendWizard : : Page_ErrorMessage ;
}
}
//
//============================================================================
//============================================================================
//============================================================================
ErrorMessagePage : : ErrorMessagePage ( QWidget * parent )
: QWizardPage ( parent )
{
QString titleStr ( " <span style= \" font-size:14pt; font-weight:500; "
" color:#32cd32; \" >%1</span> " ) ;
setTitle ( titleStr . arg ( tr ( " Sorry, some error appeared " ) ) ) ;
setSubTitle ( tr ( " Here is the error message: " ) ) ;
messageLabel = new QLabel ( " zooloo " ) ;
registerField ( " errorMessage " , messageLabel , " text " ) ;
errMessLayout = new QVBoxLayout ;
errMessLayout - > addWidget ( messageLabel ) ;
setLayout ( errMessLayout ) ;
}
//============================================================================
//
int ErrorMessagePage : : nextId ( ) const
{
return - 1 ;
}
//
//============================================================================
//============================================================================
//============================================================================
2010-01-13 16:22:52 -05:00
ConclusionPage : : ConclusionPage ( QWidget * parent ) : QWizardPage ( parent ) {
2009-03-26 12:58:06 -04:00
QString titleStr ( " <span style= \" font-size:14pt; font-weight:500; "
" color:#32cd32; \" >%1</span> " ) ;
setTitle ( titleStr . arg ( tr ( " Make Friend " ) ) ) ;
2010-01-13 16:22:52 -05:00
setSubTitle ( tr ( " Details about your friend : " ) ) ;
2009-03-26 12:58:06 -04:00
peerDetailsFrame = new QGroupBox ;
peerDetailsFrame - > setTitle ( tr ( " Peer details " ) ) ;
peerDetailsLayout = new QGridLayout ( ) ;
2010-01-13 16:22:52 -05:00
trustLabel = new QLabel ( tr ( " Key validity: " ) ) ;
2009-03-26 12:58:06 -04:00
peerDetailsLayout - > addWidget ( trustLabel , 0 , 0 , 1 , 1 ) ;
2010-01-13 16:22:52 -05:00
trustEdit = new QLabel ( ) ;
2009-03-26 12:58:06 -04:00
peerDetailsLayout - > addWidget ( trustEdit , 0 , 1 , 1 , 1 ) ;
nameLabel = new QLabel ( tr ( " Name: " ) ) ;
peerDetailsLayout - > addWidget ( nameLabel , 1 , 0 , 1 , 1 ) ;
2010-01-13 16:22:52 -05:00
nameEdit = new QLabel ( ) ;
2009-03-26 12:58:06 -04:00
peerDetailsLayout - > addWidget ( nameEdit , 1 , 1 , 1 , 1 ) ;
2010-01-13 16:22:52 -05:00
emailLabel = new QLabel ( tr ( " Email: " ) ) ;
peerDetailsLayout - > addWidget ( emailLabel , 2 , 0 , 1 , 1 ) ;
emailEdit = new QLabel ( ) ;
peerDetailsLayout - > addWidget ( emailEdit , 2 , 1 , 1 , 1 ) ;
2009-03-26 12:58:06 -04:00
locLabel = new QLabel ( tr ( " Loc: " ) ) ;
peerDetailsLayout - > addWidget ( locLabel , 3 , 0 , 1 , 1 ) ;
2010-01-13 16:22:52 -05:00
locEdit = new QLabel ( ) ;
2009-03-26 12:58:06 -04:00
peerDetailsLayout - > addWidget ( locEdit , 3 , 1 , 1 , 1 ) ;
signersLabel = new QLabel ( tr ( " Signers " ) ) ;
2010-01-13 16:22:52 -05:00
peerDetailsLayout - > addWidget ( signersLabel , 4 , 0 , 1 , 1 ) ;
2009-03-26 12:58:06 -04:00
signersEdit = new QTextEdit ( ) ;
2010-01-13 16:22:52 -05:00
peerDetailsLayout - > addWidget ( signersEdit , 4 , 1 , 1 , 1 ) ;
2009-03-26 12:58:06 -04:00
peerDetailsFrame - > setLayout ( peerDetailsLayout ) ;
2010-01-13 16:22:52 -05:00
signGPGRadioButton = new QRadioButton ( ) ;
signGPGRadioButton - > setText ( tr ( " Add as friend and Sign GPG Key " ) ) ;
registerField ( SIGN_RADIO_BUTTON_FIELD_CONNECT_FRIEND_WIZARD , signGPGRadioButton ) ;
acceptNoSignGPGRadioButton = new QRadioButton ( ) ;
acceptNoSignGPGRadioButton - > setText ( tr ( " Add as friend but don't sign GPG Key " ) ) ;
registerField ( ACCEPT_RADIO_BUTTON_FIELD_CONNECT_FRIEND_WIZARD , acceptNoSignGPGRadioButton ) ;
peerDetailsLayout - > addWidget ( signGPGRadioButton , 5 , 0 , 1 , - 1 ) ; // QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = 0 )
peerDetailsLayout - > addWidget ( acceptNoSignGPGRadioButton , 6 , 0 , 1 , - 1 ) ; // QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = 0 )
2009-03-26 12:58:06 -04:00
conclusionPageLayout = new QVBoxLayout ( ) ;
conclusionPageLayout - > addWidget ( peerDetailsFrame ) ;
setLayout ( conclusionPageLayout ) ;
2010-01-13 16:22:52 -05:00
//registering fields for cross pages access. There maybe a cleaner solution
2009-03-26 12:58:06 -04:00
peerIdEdit = new QLineEdit ( this ) ;
peerIdEdit - > setVisible ( false ) ;
2010-01-13 16:22:52 -05:00
registerField ( SSL_ID_FIELD_CONNECT_FRIEND_WIZARD , peerIdEdit ) ;
peerGPGIdEdit = new QLineEdit ( this ) ;
peerGPGIdEdit - > setVisible ( false ) ;
registerField ( SSL_ID_FIELD_CONNECT_FRIEND_WIZARD , peerGPGIdEdit ) ;
peerLocation = new QLineEdit ( this ) ;
peerLocation - > setVisible ( false ) ;
registerField ( GPG_ID_FIELD_CONNECT_FRIEND_WIZARD , peerLocation ) ;
peerCertStringEdit = new QLineEdit ( this ) ;
peerCertStringEdit - > setVisible ( false ) ;
registerField ( CERT_STRING_FIELD_CONNECT_FRIEND_WIZARD , peerCertStringEdit ) ;
2009-09-06 15:53:22 -04:00
ext_friend_ip = new QLineEdit ( this ) ;
ext_friend_ip - > setVisible ( false ) ;
registerField ( " ext_friend_ip " , ext_friend_ip ) ;
ext_friend_port = new QLineEdit ( this ) ;
ext_friend_port - > setVisible ( false ) ;
registerField ( " ext_friend_port " , ext_friend_port ) ;
local_friend_ip = new QLineEdit ( this ) ;
local_friend_ip - > setVisible ( false ) ;
registerField ( " local_friend_ip " , local_friend_ip ) ;
local_friend_port = new QLineEdit ( this ) ;
local_friend_port - > setVisible ( false ) ;
registerField ( " local_friend_port " , local_friend_port ) ;
2009-03-26 12:58:06 -04:00
}
//============================================================================
//
2010-01-13 16:22:52 -05:00
int ConclusionPage : : nextId ( ) const {
2009-03-26 12:58:06 -04:00
return - 1 ;
}
2010-01-13 16:22:52 -05:00
2009-03-26 12:58:06 -04:00
//
//============================================================================
//
2010-01-13 16:22:52 -05:00
void ConclusionPage : : initializePage ( ) {
std : : string id = field ( SSL_ID_FIELD_CONNECT_FRIEND_WIZARD ) . toString ( ) . toStdString ( ) ;
std : : string gpg_id = field ( GPG_ID_FIELD_CONNECT_FRIEND_WIZARD ) . toString ( ) . toStdString ( ) ;
std : : string location = field ( LOCATION_FIELD_CONNECT_FRIEND_WIZARD ) . toString ( ) . toStdString ( ) ;
std : : string certString = field ( CERT_STRING_FIELD_CONNECT_FRIEND_WIZARD ) . toString ( ) . toStdString ( ) ;
std : : cerr < < " Conclusion page id : " < < id < < " ; gpg_id : " < < gpg_id < < std : : endl ;
2009-03-26 12:58:06 -04:00
RsPeerDetails detail ;
2010-01-13 16:22:52 -05:00
if ( ! rsPeers - > loadDetailsFromStringCert ( certString , detail ) ) {
if ( ! rsPeers - > getPeerDetails ( id , detail ) ) {
if ( ! rsPeers - > getPeerDetails ( gpg_id , detail ) ) {
rsiface - > unlockData ( ) ; /* UnLock Interface */
return ; //false;
}
}
2009-03-26 12:58:06 -04:00
}
2010-01-13 16:22:52 -05:00
//set the radio button to sign the GPG key
if ( detail . accept_connection & & ! detail . ownsign ) {
//gpg key connection is already accepted, don't propose to accept it again
signGPGRadioButton - > setText ( tr ( " Peer is already a GPG key is already a retroshare friend. Sign his GPG key. " ) ) ;
signGPGRadioButton - > setChecked ( true ) ;
acceptNoSignGPGRadioButton - > hide ( ) ;
acceptNoSignGPGRadioButton - > setChecked ( false ) ;
}
if ( ! detail . accept_connection & & detail . ownsign ) {
//gpg key is already signed, don't propose to sign it again
acceptNoSignGPGRadioButton - > setText ( tr ( " GPG key is already signed, make it a retroshare friend. " ) ) ;
acceptNoSignGPGRadioButton - > setChecked ( true ) ;
signGPGRadioButton - > hide ( ) ;
signGPGRadioButton - > setChecked ( false ) ;
}
if ( ! detail . accept_connection & & ! detail . ownsign ) {
signGPGRadioButton - > setText ( tr ( " Add as friend and Sign GPG Key " ) ) ;
signGPGRadioButton - > show ( ) ;
acceptNoSignGPGRadioButton - > setText ( tr ( " Add as friend but don't sign GPG Key " ) ) ;
acceptNoSignGPGRadioButton - > show ( ) ;
}
if ( detail . accept_connection & & detail . ownsign & & ! detail . isOnlyGPGdetail ) {
acceptNoSignGPGRadioButton - > setChecked ( false ) ;
acceptNoSignGPGRadioButton - > hide ( ) ;
signGPGRadioButton - > setChecked ( false ) ;
signGPGRadioButton - > hide ( ) ;
radioButtonsLabel = new QLabel ( tr ( " It seems your friend is already registered. Adding it might just set it's ip address. " ) ) ;
peerDetailsLayout - > addWidget ( radioButtonsLabel , 7 , 0 , 1 , - 1 ) ; // QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = 0 )
}
2009-03-26 12:58:06 -04:00
2010-01-13 16:22:52 -05:00
std : : string trustString ;
switch ( detail . validLvl )
2009-03-26 12:58:06 -04:00
{
2010-01-13 16:22:52 -05:00
case RS_TRUST_LVL_ULTIMATE :
trustString = " Ultimate " ;
break ;
case RS_TRUST_LVL_FULL :
trustString = " Full " ;
2009-03-26 12:58:06 -04:00
break ;
case RS_TRUST_LVL_MARGINAL :
trustString = " Marginal " ;
break ;
2010-01-13 16:22:52 -05:00
case RS_TRUST_LVL_NONE :
trustString = " None " ;
break ;
2009-03-26 12:58:06 -04:00
default :
trustString = " No Trust " ;
break ;
}
QString ts ;
std : : list < std : : string > : : iterator it ;
2010-01-13 16:22:52 -05:00
for ( it = detail . gpgSigners . begin ( ) ; it ! = detail . gpgSigners . end ( ) ; it + + ) {
2009-03-26 12:58:06 -04:00
ts . append ( QString : : fromStdString ( rsPeers - > getPeerName ( * it ) ) ) ;
ts . append ( " < " ) ;
ts . append ( QString : : fromStdString ( * it ) ) ;
ts . append ( " > " ) ;
ts . append ( " \n " ) ;
}
nameEdit - > setText ( QString : : fromStdString ( detail . name ) ) ;
trustEdit - > setText ( QString : : fromStdString ( trustString ) ) ;
2010-01-13 16:22:52 -05:00
emailEdit - > setText ( QString : : fromStdString ( detail . email ) ) ;
2010-01-13 16:27:49 -05:00
locEdit - > setText ( QString : : fromStdString ( detail . location ) ) ;
2009-03-26 12:58:06 -04:00
signersEdit - > setPlainText ( ts ) ;
}
2010-01-13 16:22:52 -05:00
2009-03-26 12:58:06 -04:00
//============================================================================
//