2011-09-06 16:44:22 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 , crypton
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <QTreeWidget>
# include <QDebug>
# include <QTimer>
# include <QTime>
# include <QMenu>
# include <retroshare/rsiface.h>
# include <retroshare/rspeers.h>
# include <retroshare/rsdisc.h>
2013-04-10 17:21:52 -04:00
# include <retroshare/rsmsgs.h>
2011-09-06 16:44:22 -04:00
# include "common/vmessagebox.h"
# include "common/RSTreeWidgetItem.h"
2013-05-29 17:32:02 -04:00
# include <gui/common/FriendSelectionDialog.h>
2013-08-28 11:37:11 -04:00
# include "gui/msgs/MessageComposer.h"
2014-09-25 16:14:21 -04:00
# include "gui/profile/ProfileManager.h"
2011-09-06 16:44:22 -04:00
# include "NetworkDialog.h"
2012-07-17 16:40:51 -04:00
//#include "TrustView.h"
2011-09-06 16:44:22 -04:00
# include "NetworkView.h"
# include "GenCertDialog.h"
# include "connect/ConfCertDialog.h"
# include "settings/rsharesettings.h"
# include "RetroShareLink.h"
2013-10-19 09:25:06 -04:00
# include "util/QtVersion.h"
2011-09-06 16:44:22 -04:00
# include <time.h>
/* Images for context menu icons */
# define IMAGE_LOADCERT ": / images / loadcert16.png"
2013-08-28 11:37:11 -04:00
# define IMAGE_PEERDETAILS ": / images / info16.png"
2011-09-06 16:44:22 -04:00
# define IMAGE_AUTH ": / images / encrypted16.png"
2013-05-29 17:32:02 -04:00
# define IMAGE_CLEAN_UNUSED ": / images / deletemail24.png"
2011-09-06 16:44:22 -04:00
# define IMAGE_MAKEFRIEND ": / images / user / add_user16.png"
# define IMAGE_EXPORT ": / images / exportpeers_16x16.png"
# define IMAGE_COPYLINK ": / images / copyrslink.png"
2013-08-28 11:37:11 -04:00
# define IMAGE_MESSAGE ": / images / mail_new.png"
2011-09-06 16:44:22 -04:00
/* Images for Status icons */
# define IMAGE_AUTHED ": / images / accepted16.png"
# define IMAGE_DENIED ": / images / denied16.png"
# define IMAGE_TRUSTED ": / images / rs-2.png"
2013-09-07 10:06:08 -04:00
// Defines for key list columns
# define COLUMN_CHECK 0
2011-09-06 16:44:22 -04:00
# define COLUMN_PEERNAME 1
2013-09-07 10:06:08 -04:00
# define COLUMN_I_AUTH_PEER 2
# define COLUMN_PEER_AUTH_ME 3
2013-05-27 06:43:34 -04:00
# define COLUMN_PEERID 4
# define COLUMN_LAST_USED 5
2013-09-07 10:06:08 -04:00
# define COLUMN_COUNT 6
2011-09-06 16:44:22 -04:00
2014-03-17 16:56:06 -04:00
RsPeerId getNeighRsCertId ( QTreeWidgetItem * i ) ;
2011-09-06 16:44:22 -04:00
/******
* # define NET_DEBUG 1
* * * * */
/** Constructor */
NetworkDialog : : NetworkDialog ( QWidget * parent )
: RsAutoUpdatePage ( 10000 , parent ) // updates every 10 sec.
{
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2013-07-04 16:09:46 -04:00
connect ( ui . connectTreeWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( connectTreeWidgetCostumPopupMenu ( QPoint ) ) ) ;
connect ( ui . connectTreeWidget , SIGNAL ( itemDoubleClicked ( QTreeWidgetItem * , int ) ) , this , SLOT ( peerdetails ( ) ) ) ;
2011-09-06 16:44:22 -04:00
2012-04-05 17:03:03 -04:00
connect ( ui . filterLineEdit , SIGNAL ( textChanged ( const QString & ) ) , this , SLOT ( filterItems ( QString ) ) ) ;
2012-10-29 06:59:26 -04:00
connect ( ui . filterLineEdit , SIGNAL ( filterChanged ( int ) ) , this , SLOT ( filterColumnChanged ( int ) ) ) ;
2011-09-06 16:44:22 -04:00
2013-07-16 17:08:09 -04:00
connect ( ui . onlyTrustedKeys , SIGNAL ( clicked ( ) ) , this , SLOT ( securedUpdateDisplay ( ) ) ) ;
2011-09-06 16:44:22 -04:00
/* hide the Tree +/- */
2013-07-04 16:09:46 -04:00
ui . connectTreeWidget - > setRootIsDecorated ( false ) ;
ui . connectTreeWidget - > setColumnCount ( 6 ) ;
2011-09-06 16:44:22 -04:00
/* Set header resize modes and initial section sizes */
2013-07-04 16:09:46 -04:00
QHeaderView * _header = ui . connectTreeWidget - > header ( ) ;
2013-10-19 09:25:06 -04:00
QHeaderView_setSectionResizeMode ( _header , COLUMN_CHECK , QHeaderView : : Custom ) ;
QHeaderView_setSectionResizeMode ( _header , COLUMN_PEERNAME , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeMode ( _header , COLUMN_I_AUTH_PEER , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeMode ( _header , COLUMN_PEER_AUTH_ME , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeMode ( _header , COLUMN_PEERID , QHeaderView : : Interactive ) ;
QHeaderView_setSectionResizeMode ( _header , COLUMN_LAST_USED , QHeaderView : : Interactive ) ;
2013-09-07 10:06:08 -04:00
_header - > model ( ) - > setHeaderData ( COLUMN_CHECK , Qt : : Horizontal , tr ( " " ) ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_PEERNAME , Qt : : Horizontal , tr ( " Name " ) ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_I_AUTH_PEER , Qt : : Horizontal , tr ( " Did I authenticated peer " ) ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_PEER_AUTH_ME , Qt : : Horizontal , tr ( " Did peer authenticated me " ) ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_PEERID , Qt : : Horizontal , tr ( " Cert Id " ) ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_LAST_USED , Qt : : Horizontal , tr ( " Last used " ) ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_CHECK , Qt : : Horizontal , tr ( " If I accept connection from peer " ) , Qt : : ToolTipRole ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_PEERNAME , Qt : : Horizontal , tr ( " Name of peer " ) , Qt : : ToolTipRole ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_I_AUTH_PEER , Qt : : Horizontal , tr ( " Did I sign his PGP key " ) , Qt : : ToolTipRole ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_PEER_AUTH_ME , Qt : : Horizontal , tr ( " Did peer sign mine PGP key " ) , Qt : : ToolTipRole ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_PEERID , Qt : : Horizontal , tr ( " Peer's Certificat ID " ) , Qt : : ToolTipRole ) ;
_header - > model ( ) - > setHeaderData ( COLUMN_LAST_USED , Qt : : Horizontal , tr ( " Since when I use this Certificat " ) , Qt : : ToolTipRole ) ;
_header - > resizeSection ( COLUMN_CHECK , 25 ) ;
_header - > resizeSection ( COLUMN_PEERNAME , 200 ) ;
_header - > resizeSection ( COLUMN_I_AUTH_PEER , 200 ) ;
_header - > resizeSection ( COLUMN_PEER_AUTH_ME , 200 ) ;
_header - > resizeSection ( COLUMN_LAST_USED , 75 ) ;
2011-09-06 16:44:22 -04:00
// set header text aligment
2013-07-04 16:09:46 -04:00
QTreeWidgetItem * headerItem = ui . connectTreeWidget - > headerItem ( ) ;
2013-09-07 10:06:08 -04:00
headerItem - > setTextAlignment ( COLUMN_CHECK , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( COLUMN_PEERNAME , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( COLUMN_I_AUTH_PEER , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( COLUMN_PEER_AUTH_ME , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( COLUMN_PEERID , Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( COLUMN_LAST_USED , Qt : : AlignVCenter ) ;
2011-09-06 16:44:22 -04:00
2013-09-06 15:10:51 -04:00
headerItem - > setText ( 0 , QString ( ) ) ;
2011-09-06 16:44:22 -04:00
2013-09-07 10:06:08 -04:00
ui . connectTreeWidget - > sortItems ( COLUMN_PEERNAME , Qt : : AscendingOrder ) ;
2011-09-06 16:44:22 -04:00
2012-07-17 16:40:51 -04:00
// ui.networkTab->addTab(new TrustView(),QString(tr("Authentication matrix")));
2013-02-22 16:42:27 -05:00
// ui.networkTab->addTab(networkview = new NetworkView(),QString(tr("Network View")));
2011-09-06 16:44:22 -04:00
2013-07-16 17:08:09 -04:00
ui . onlyTrustedKeys - > setMinimumWidth ( 20 ) ;
2011-09-06 16:44:22 -04:00
QString version = " - " ;
2013-09-29 03:10:19 -04:00
std : : string rsversion ;
if ( rsDisc - > getPeerVersion ( rsPeers - > getOwnId ( ) , rsversion ) )
{
version = QString : : fromStdString ( rsversion ) ;
2011-09-06 16:44:22 -04:00
}
QMenu * menu = new QMenu ( ) ;
//menu->addAction(ui.actionAddFriend);
//menu->addAction(ui.actionCopyKey);
//menu->addAction(ui.actionExportKey);
//menu->addAction(ui.actionCreate_New_Profile);
//menu->addSeparator();
menu - > addAction ( ui . actionTabsright ) ;
menu - > addAction ( ui . actionTabswest ) ;
menu - > addAction ( ui . actionTabssouth ) ;
menu - > addAction ( ui . actionTabsnorth ) ;
menu - > addSeparator ( ) ;
menu - > addAction ( ui . actionTabsTriangular ) ;
menu - > addAction ( ui . actionTabsRounded ) ;
2013-02-22 16:42:27 -05:00
//ui.viewButton->setMenu(menu);
2011-09-06 16:44:22 -04:00
QTimer * timer2 = new QTimer ( this ) ;
connect ( timer2 , SIGNAL ( timeout ( ) ) , this , SLOT ( updateNetworkStatus ( ) ) ) ;
timer2 - > start ( 1000 ) ;
2012-10-29 06:59:26 -04:00
/* add filter actions */
2012-11-05 19:28:11 -05:00
ui . filterLineEdit - > addFilter ( QIcon ( ) , tr ( " Name " ) , COLUMN_PEERNAME , tr ( " Search Name " ) ) ;
ui . filterLineEdit - > addFilter ( QIcon ( ) , tr ( " Peer ID " ) , COLUMN_PEERID , tr ( " Search Peer ID " ) ) ;
2012-10-29 06:59:26 -04:00
ui . filterLineEdit - > setCurrentFilter ( COLUMN_PEERNAME ) ;
2013-02-22 16:42:27 -05:00
//updateNetworkStatus();
//loadtabsettings();
2011-09-06 16:44:22 -04:00
/* Hide platform specific features */
# ifdef Q_WS_WIN
# endif
}
2012-11-19 11:01:21 -05:00
void NetworkDialog : : changeEvent ( QEvent * e )
{
QWidget : : changeEvent ( e ) ;
switch ( e - > type ( ) ) {
case QEvent : : StyleChange :
2013-05-21 08:55:03 -04:00
securedUpdateDisplay ( ) ;
2012-11-19 11:01:21 -05:00
break ;
default :
// remove compiler warnings
break ;
}
}
2013-07-04 16:09:46 -04:00
void NetworkDialog : : connectTreeWidgetCostumPopupMenu ( QPoint /*point*/ )
2011-09-06 16:44:22 -04:00
{
2013-07-04 16:09:46 -04:00
//std::cerr << "NetworkDialog::connectTreeWidgetCostumPopupMenu( QPoint point ) called" << std::endl;
2012-08-15 16:08:18 -04:00
QTreeWidgetItem * wi = getCurrentNeighbour ( ) ;
if ( ! wi )
return ;
2011-09-06 16:44:22 -04:00
2012-08-15 16:08:18 -04:00
QMenu * contextMnu = new QMenu ;
2011-09-06 16:44:22 -04:00
2014-03-17 16:56:06 -04:00
RsPgpId peer_id ( wi - > text ( COLUMN_PEERID ) . toStdString ( ) ) ;
2011-09-06 16:44:22 -04:00
2012-08-15 16:08:18 -04:00
// That's what context menus are made for
RsPeerDetails detail ;
if ( ! rsPeers - > getGPGDetails ( peer_id , detail ) ) // that is not suppose to fail.
return ;
2011-09-06 16:44:22 -04:00
2012-08-15 16:08:18 -04:00
if ( peer_id ! = rsPeers - > getGPGOwnId ( ) )
{
if ( detail . accept_connection )
2013-05-29 17:32:02 -04:00
contextMnu - > addAction ( QIcon ( IMAGE_DENIED ) , tr ( " Deny friend " ) , this , SLOT ( denyFriend ( ) ) ) ;
2012-08-15 16:08:18 -04:00
else // not a friend
2013-05-29 17:32:02 -04:00
contextMnu - > addAction ( QIcon ( IMAGE_MAKEFRIEND ) , tr ( " Make friend " ) , this , SLOT ( makeFriend ( ) ) ) ;
2012-08-15 16:08:18 -04:00
}
if ( peer_id = = rsPeers - > getGPGOwnId ( ) )
2014-09-25 16:14:21 -04:00
contextMnu - > addAction ( QIcon ( IMAGE_EXPORT ) , tr ( " Export/create a new location " ) , this , SLOT ( on_actionExportKey_activated ( ) ) ) ;
2013-05-29 17:32:02 -04:00
contextMnu - > addAction ( QIcon ( IMAGE_PEERDETAILS ) , tr ( " Peer details... " ) , this , SLOT ( peerdetails ( ) ) ) ;
2014-09-25 16:14:21 -04:00
//contextMnu->addAction(QIcon(IMAGE_MESSAGE), tr("Send Message"), this, SLOT(sendDistantMessage()));
//contextMnu->addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink()));
2013-05-29 17:32:02 -04:00
contextMnu - > addSeparator ( ) ;
contextMnu - > addAction ( QIcon ( IMAGE_CLEAN_UNUSED ) , tr ( " Remove unused keys... " ) , this , SLOT ( removeUnusedKeys ( ) ) ) ;
contextMnu - > exec ( QCursor : : pos ( ) ) ;
}
void NetworkDialog : : removeUnusedKeys ( )
{
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > pre_selected ;
std : : list < RsPgpId > ids ;
2013-05-29 17:32:02 -04:00
rsPeers - > getGPGAllList ( ids ) ;
RsPeerDetails details ;
time_t now = time ( NULL ) ;
2013-09-07 10:06:08 -04:00
time_t THREE_MONTHS = 3 * 31 * 24 * 60 * 60 ; //3*DayPerMonth*HoursPerDay*MinPerHour*SecPerMin
2013-05-29 17:32:02 -04:00
2014-03-17 16:56:06 -04:00
for ( std : : list < RsPgpId > : : const_iterator it ( ids . begin ( ) ) ; it ! = ids . end ( ) ; + + it )
2012-08-15 16:08:18 -04:00
{
2014-03-17 16:56:06 -04:00
rsPeers - > getGPGDetails ( * it , details ) ;
2013-05-29 17:32:02 -04:00
2013-05-31 15:16:04 -04:00
if ( rsPeers - > haveSecretKey ( * it ) )
{
std : : cerr < < " Skipping public/secret key pair " < < * it < < std : : endl ;
continue ;
}
2013-06-10 09:27:24 -04:00
if ( now > ( time_t ) ( THREE_MONTHS + details . lastUsed ) )
2013-05-29 17:32:02 -04:00
{
std : : cerr < < " Adding " < < * it < < " to pre-selection. " < < std : : endl ;
pre_selected . push_back ( * it ) ;
}
2012-08-15 16:08:18 -04:00
}
2011-09-06 16:44:22 -04:00
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > selected = FriendSelectionDialog : : selectFriends_PGP ( NULL ,
2013-05-29 17:32:02 -04:00
tr ( " Clean keyring " ) ,
tr ( " The selected keys below haven't been used in the last 3 months. \n Do you want to delete them permanently ? \n \n Notes: Your old keyring will be backed up. \n The removal may fail when running multiple Retroshare instances on the same machine. " ) , FriendSelectionWidget : : MODUS_CHECK , FriendSelectionWidget : : SHOW_GPG | FriendSelectionWidget : : SHOW_NON_FRIEND_GPG ,
2014-03-17 16:56:06 -04:00
pre_selected ) ;
2013-05-29 17:32:02 -04:00
std : : cerr < < " Removing these keys from the keyring: " < < std : : endl ;
2014-03-17 16:56:06 -04:00
for ( std : : list < RsPgpId > : : const_iterator it ( selected . begin ( ) ) ; it ! = selected . end ( ) ; + + it )
2013-05-29 17:32:02 -04:00
std : : cerr < < " " < < * it < < std : : endl ;
std : : string backup_file ;
uint32_t error_code ;
2013-05-31 15:16:04 -04:00
if ( selected . empty ( ) )
return ;
2013-05-29 17:32:02 -04:00
if ( rsPeers - > removeKeysFromPGPKeyring ( selected , backup_file , error_code ) )
QMessageBox : : information ( NULL , tr ( " Keyring info " ) , tr ( " %1 keys have been deleted from your keyring. \n For security, your keyring was previously backed-up to file \n \n " ) . arg ( selected . size ( ) ) + QString : : fromStdString ( backup_file ) ) ;
else
{
QString error_string ;
2011-09-06 16:44:22 -04:00
2013-05-29 17:32:02 -04:00
switch ( error_code )
{
default :
case PGP_KEYRING_REMOVAL_ERROR_NO_ERROR : error_string = tr ( " Unknown error " ) ;
break ;
case PGP_KEYRING_REMOVAL_ERROR_CANT_REMOVE_SECRET_KEYS : error_string = tr ( " Cannot delete secret keys " ) ;
break ;
case PGP_KEYRING_REMOVAL_ERROR_CANNOT_WRITE_BACKUP :
case PGP_KEYRING_REMOVAL_ERROR_CANNOT_CREATE_BACKUP : error_string = tr ( " Cannot create backup file. Check for permissions in pgp directory, disk space, etc. " ) ;
break ;
2013-06-10 13:18:51 -04:00
case PGP_KEYRING_REMOVAL_ERROR_DATA_INCONSISTENCY : error_string = tr ( " Data inconsistency in the keyring. This is most probably a bug. Please contact the developers. " ) ;
2013-05-31 15:16:04 -04:00
break ;
2011-09-06 16:44:22 -04:00
2013-05-29 17:32:02 -04:00
}
QMessageBox : : warning ( NULL , tr ( " Keyring info " ) , tr ( " Key removal has failed. Your keyring remains intact. \n \n Reported error: " ) + error_string ) ;
}
2013-05-31 15:16:04 -04:00
insertConnect ( ) ;
2011-09-06 16:44:22 -04:00
}
void NetworkDialog : : denyFriend ( )
{
QTreeWidgetItem * wi = getCurrentNeighbour ( ) ;
2014-03-17 16:56:06 -04:00
RsPgpId peer_id ( wi - > text ( COLUMN_PEERID ) . toStdString ( ) ) ;
2011-09-06 16:44:22 -04:00
rsPeers - > removeFriend ( peer_id ) ;
2013-05-21 08:55:03 -04:00
securedUpdateDisplay ( ) ;
2011-09-06 16:44:22 -04:00
}
2013-09-07 10:06:08 -04:00
/*void NetworkDialog::deleteCert()
2011-09-06 16:44:22 -04:00
{
# ifdef TODO
// do whatever is needed to remove the certificate completely, hopping this
// will eventually remove the signature we've stamped on it.
std : : cout < < " Deleting friend ! " < < std : : endl ;
QTreeWidgetItem * wi = getCurrentNeighbour ( ) ;
std : : string peer_id = wi - > text ( 9 ) . toStdString ( ) ;
rsPeers - > deleteCertificate ( peer_id ) ;
2013-05-21 08:55:03 -04:00
securedUpdateDisplay ( ) ;
2011-09-06 16:44:22 -04:00
# endif
2013-09-07 10:06:08 -04:00
} */
2011-09-06 16:44:22 -04:00
void NetworkDialog : : makeFriend ( )
{
2014-03-17 16:56:06 -04:00
ConfCertDialog : : showIt ( RsPgpId ( getCurrentNeighbour ( ) - > text ( COLUMN_PEERID ) . toStdString ( ) ) , ConfCertDialog : : PageTrust ) ;
2011-09-06 16:44:22 -04:00
}
/** Shows Peer Information/Auth Dialog */
void NetworkDialog : : peerdetails ( )
{
QTreeWidgetItem * item = getCurrentNeighbour ( ) ;
if ( item = = NULL ) {
return ;
}
2014-03-17 16:56:06 -04:00
ConfCertDialog : : showIt ( RsPgpId ( item - > text ( COLUMN_PEERID ) . toStdString ( ) ) , ConfCertDialog : : PageDetails ) ;
2011-09-06 16:44:22 -04:00
}
void NetworkDialog : : copyLink ( )
{
QTreeWidgetItem * wi = getCurrentNeighbour ( ) ;
if ( wi = = NULL ) {
return ;
}
2014-03-17 16:56:06 -04:00
RsPgpId peer_id ( wi - > text ( COLUMN_PEERID ) . toStdString ( ) ) ;
2011-09-06 16:44:22 -04:00
2011-09-11 18:07:24 -04:00
QList < RetroShareLink > urls ;
2011-09-06 16:44:22 -04:00
RetroShareLink link ;
if ( link . createPerson ( peer_id ) ) {
urls . push_back ( link ) ;
}
RSLinkClipboard : : copyLinks ( urls ) ;
}
2014-03-29 10:18:05 -04:00
//void NetworkDialog::sendDistantMessage()
//{
// QTreeWidgetItem *wi = getCurrentNeighbour();
// if (wi == NULL) {
// return;
// }
//
// MessageComposer *nMsgDialog = MessageComposer::newMsg();
// if (nMsgDialog == NULL) {
// return;
// }
//
// DistantMsgPeerId pid ;
// RsPgpId mGpgId(wi->text(COLUMN_PEERID).toStdString()) ;
//
// if(rsMsgs->getDistantMessagePeerId(mGpgId,pid))
// {
// nMsgDialog->addRecipient(MessageComposer::TO, pid, mGpgId);
// nMsgDialog->show();
// nMsgDialog->activateWindow();
// }
//
// /* window will destroy itself! */
//}
2013-08-28 11:37:11 -04:00
2011-09-06 16:44:22 -04:00
void NetworkDialog : : updateDisplay ( )
{
insertConnect ( ) ;
}
/* get the list of Neighbours from the RsIface. */
void NetworkDialog : : insertConnect ( )
{
2013-05-31 15:16:04 -04:00
// static time_t last_time = 0 ;
2011-09-06 16:44:22 -04:00
if ( ! rsPeers )
return ;
2013-05-31 15:16:04 -04:00
// // Because this is called from a qt signal, there's no limitation between calls.
2011-09-06 16:44:22 -04:00
time_t now = time ( NULL ) ;
2013-05-31 15:16:04 -04:00
// if(last_time + 5 > now) // never update more often then every 5 seconds.
// return ;
//
// last_time = now ;
2011-09-06 16:44:22 -04:00
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > neighs ; //these are GPG ids
std : : list < RsPgpId > : : iterator it ;
2011-09-06 16:44:22 -04:00
rsPeers - > getGPGAllList ( neighs ) ;
/* get a link to the table */
2013-07-04 16:09:46 -04:00
QTreeWidget * connectWidget = ui . connectTreeWidget ;
2011-09-06 16:44:22 -04:00
//remove items
int index = 0 ;
2013-07-16 17:08:09 -04:00
while ( index < connectWidget - > topLevelItemCount ( ) )
{
2014-03-17 16:56:06 -04:00
RsPgpId gpg_widget_id ( ( connectWidget - > topLevelItem ( index ) ) - > text ( COLUMN_PEERID ) . toStdString ( ) ) ;
2011-09-06 16:44:22 -04:00
RsPeerDetails detail ;
2013-07-16 17:08:09 -04:00
if ( ( ! rsPeers - > getGPGDetails ( gpg_widget_id , detail ) ) | | ( ui . onlyTrustedKeys - > isChecked ( ) & & ( detail . validLvl < RS_TRUST_LVL_MARGINAL & & ! detail . accept_connection ) ) )
2011-09-06 16:44:22 -04:00
delete ( connectWidget - > takeTopLevelItem ( index ) ) ;
2013-07-16 17:08:09 -04:00
else
2011-09-06 16:44:22 -04:00
index + + ;
}
2013-09-07 10:06:08 -04:00
//QList<QTreeWidgetItem *> validItems;
//QList<QTreeWidgetItem *> unvalidItems;
2013-05-27 06:43:34 -04:00
2011-09-06 16:44:22 -04:00
for ( it = neighs . begin ( ) ; it ! = neighs . end ( ) ; it + + )
{
# ifdef NET_DEBUG
std : : cerr < < " NetworkDialog::insertConnect() inserting gpg key : " < < * it < < std : : endl ;
# endif
if ( * it = = rsPeers - > getGPGOwnId ( ) ) {
continue ;
}
RsPeerDetails detail ;
if ( ! rsPeers - > getGPGDetails ( * it , detail ) )
{
continue ; /* BAD */
}
/* make a widget per friend */
QTreeWidgetItem * item ;
2014-03-17 16:56:06 -04:00
QList < QTreeWidgetItem * > list = connectWidget - > findItems ( QString : : fromStdString ( ( * it ) . toStdString ( ) ) , Qt : : MatchExactly , COLUMN_PEERID ) ;
2011-09-06 16:44:22 -04:00
if ( list . size ( ) = = 1 ) {
item = list . front ( ) ;
} else {
//create new item
# ifdef NET_DEBUG
std : : cerr < < " NetworkDialog::insertConnect() creating new tree widget item : " < < * it < < std : : endl ;
# endif
item = new RSTreeWidgetItem ( NULL , 0 ) ;
item - > setChildIndicatorPolicy ( QTreeWidgetItem : : DontShowIndicatorWhenChildless ) ;
2013-09-07 10:06:08 -04:00
item - > setSizeHint ( COLUMN_CHECK , QSize ( 18 , 18 ) ) ;
2011-09-06 16:44:22 -04:00
/* (1) Person */
item - > setText ( COLUMN_PEERNAME , QString : : fromUtf8 ( detail . name . c_str ( ) ) ) ;
/* (4) key id */
2014-03-17 16:56:06 -04:00
item - > setText ( COLUMN_PEERID , QString : : fromStdString ( detail . gpg_id . toStdString ( ) ) ) ;
2011-09-06 16:44:22 -04:00
}
2013-09-07 10:06:08 -04:00
//QString TrustLevelString ;
2011-09-06 16:44:22 -04:00
/* (2) Key validity */
if ( detail . ownsign )
{
2013-09-07 10:06:08 -04:00
item - > setText ( COLUMN_I_AUTH_PEER , tr ( " Personal signature " ) ) ;
item - > setToolTip ( COLUMN_I_AUTH_PEER , tr ( " PGP key signed by you " ) ) ;
2011-09-06 16:44:22 -04:00
}
else
switch ( detail . trustLvl )
{
2013-09-07 10:06:08 -04:00
case RS_TRUST_LVL_MARGINAL : item - > setText ( COLUMN_I_AUTH_PEER , tr ( " Marginally trusted peer " ) ) ; break ;
2012-07-07 12:26:54 -04:00
case RS_TRUST_LVL_FULL :
2013-09-07 10:06:08 -04:00
case RS_TRUST_LVL_ULTIMATE : item - > setText ( COLUMN_I_AUTH_PEER , tr ( " Fully trusted peer " ) ) ; break ;
2012-07-07 12:26:54 -04:00
case RS_TRUST_LVL_UNKNOWN :
case RS_TRUST_LVL_UNDEFINED :
case RS_TRUST_LVL_NEVER :
2011-09-06 16:44:22 -04:00
default : item - > setText ( 2 , tr ( " Untrusted peer " ) ) ; break ;
}
/* (3) has me auth */
2013-05-27 06:43:34 -04:00
QString PeerAuthenticationString ;
2011-09-06 16:44:22 -04:00
if ( detail . hasSignedMe )
PeerAuthenticationString = tr ( " Has authenticated me " ) ;
2013-05-27 06:43:34 -04:00
else
PeerAuthenticationString = tr ( " Unknown " ) ;
2011-09-06 16:44:22 -04:00
2013-09-07 10:06:08 -04:00
item - > setText ( COLUMN_PEER_AUTH_ME , PeerAuthenticationString ) ;
2011-09-06 16:44:22 -04:00
2013-05-27 06:43:34 -04:00
uint64_t last_time_used = now - detail . lastUsed ;
QString lst_used_str ;
if ( last_time_used < 3600 )
lst_used_str = tr ( " Last hour " ) ;
else if ( last_time_used < 86400 )
lst_used_str = tr ( " Today " ) ;
else if ( last_time_used > 86400 * 15000 )
lst_used_str = tr ( " Never " ) ;
else
2013-05-30 16:26:16 -04:00
lst_used_str = tr ( " %1 days ago " ) . arg ( ( int ) ( last_time_used / 86400 ) ) ;
2013-05-27 06:43:34 -04:00
item - > setText ( COLUMN_LAST_USED , lst_used_str ) ;
2011-09-06 16:44:22 -04:00
/**
* Determinated the Background Color
*/
QColor backgrndcolor ;
if ( detail . accept_connection )
{
2013-09-07 10:06:08 -04:00
item - > setText ( COLUMN_CHECK , " 0 " ) ;
item - > setIcon ( COLUMN_CHECK , ( QIcon ( IMAGE_AUTHED ) ) ) ;
2011-09-06 16:44:22 -04:00
if ( detail . ownsign )
{
2012-11-19 11:01:21 -05:00
backgrndcolor = backgroundColorOwnSign ( ) ;
2011-09-06 16:44:22 -04:00
}
else
{
2012-11-19 11:01:21 -05:00
backgrndcolor = backgroundColorAcceptConnection ( ) ;
2011-09-06 16:44:22 -04:00
}
}
else
{
2013-09-07 10:06:08 -04:00
item - > setText ( COLUMN_CHECK , " 1 " ) ;
2011-09-06 16:44:22 -04:00
if ( detail . hasSignedMe )
{
2012-11-19 11:01:21 -05:00
backgrndcolor = backgroundColorHasSignedMe ( ) ;
2013-09-07 10:06:08 -04:00
item - > setIcon ( COLUMN_CHECK , ( QIcon ( IMAGE_DENIED ) ) ) ;
for ( int k = 0 ; k < COLUMN_COUNT ; + + k )
2011-09-06 16:44:22 -04:00
item - > setToolTip ( k , QString : : fromUtf8 ( detail . name . c_str ( ) ) + tr ( " has authenticated you. \n Right-click and select 'make friend' to be able to connect. " ) ) ;
}
else
{
2012-11-19 11:01:21 -05:00
backgrndcolor = backgroundColorDenied ( ) ;
2013-09-07 10:06:08 -04:00
item - > setIcon ( COLUMN_CHECK , ( QIcon ( IMAGE_DENIED ) ) ) ;
2011-09-06 16:44:22 -04:00
}
}
// Color each Background column in the Network Tab except the first one => 1-9
// whith the determinated color
2013-09-07 10:06:08 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; i + + )
2011-09-06 16:44:22 -04:00
item - > setBackground ( i , QBrush ( backgrndcolor ) ) ;
2013-07-16 17:08:09 -04:00
if ( ( detail . accept_connection | | detail . validLvl > = RS_TRUST_LVL_MARGINAL ) | | ! ui . onlyTrustedKeys - > isChecked ( ) )
2011-09-06 16:44:22 -04:00
connectWidget - > addTopLevelItem ( item ) ;
}
// add self to network.
RsPeerDetails ownGPGDetails ;
rsPeers - > getGPGDetails ( rsPeers - > getGPGOwnId ( ) , ownGPGDetails ) ;
/* make a widget per friend */
QTreeWidgetItem * self_item ;
2014-03-17 16:56:06 -04:00
QList < QTreeWidgetItem * > list = connectWidget - > findItems ( QString : : fromStdString ( ownGPGDetails . gpg_id . toStdString ( ) ) , Qt : : MatchExactly , COLUMN_PEERID ) ;
2011-09-06 16:44:22 -04:00
if ( list . size ( ) = = 1 ) {
self_item = list . front ( ) ;
} else {
self_item = new RSTreeWidgetItem ( NULL , 0 ) ;
self_item - > setChildIndicatorPolicy ( QTreeWidgetItem : : DontShowIndicatorWhenChildless ) ;
}
2013-09-07 10:06:08 -04:00
self_item - > setText ( COLUMN_CHECK , " 0 " ) ;
self_item - > setIcon ( COLUMN_CHECK , ( QIcon ( IMAGE_AUTHED ) ) ) ;
2011-09-06 16:44:22 -04:00
self_item - > setText ( COLUMN_PEERNAME , QString : : fromUtf8 ( ownGPGDetails . name . c_str ( ) ) + " ( " + tr ( " yourself " ) + " ) " ) ;
2013-09-07 10:06:08 -04:00
self_item - > setText ( COLUMN_I_AUTH_PEER , " N/A " ) ;
2014-03-17 16:56:06 -04:00
self_item - > setText ( COLUMN_PEERID , QString : : fromStdString ( ownGPGDetails . gpg_id . toStdString ( ) ) ) ;
2011-09-06 16:44:22 -04:00
// Color each Background column in the Network Tab except the first one => 1-9
2013-09-07 10:06:08 -04:00
for ( int i = 0 ; i < COLUMN_COUNT ; + + i )
2011-09-06 16:44:22 -04:00
{
2012-11-19 11:01:21 -05:00
self_item - > setBackground ( i , backgroundColorSelf ( ) ) ;
2011-09-06 16:44:22 -04:00
}
connectWidget - > addTopLevelItem ( self_item ) ;
connectWidget - > update ( ) ; /* update display */
2012-04-05 17:03:03 -04:00
if ( ui . filterLineEdit - > text ( ) . isEmpty ( ) = = false ) {
filterItems ( ui . filterLineEdit - > text ( ) ) ;
2011-09-06 16:44:22 -04:00
}
}
QTreeWidgetItem * NetworkDialog : : getCurrentNeighbour ( )
{
2013-07-16 17:08:09 -04:00
if ( ui . connectTreeWidget - > selectedItems ( ) . size ( ) ! = 0 )
{
2013-07-04 16:09:46 -04:00
return ui . connectTreeWidget - > currentItem ( ) ;
2013-07-16 17:08:09 -04:00
}
2011-09-06 16:44:22 -04:00
return NULL ;
}
/* Utility Fns */
2014-03-17 16:56:06 -04:00
RsPeerId getNeighRsCertId ( QTreeWidgetItem * i )
2011-09-06 16:44:22 -04:00
{
2014-03-17 16:56:06 -04:00
RsPeerId id ( ( i - > text ( COLUMN_PEERID ) ) . toStdString ( ) ) ;
2011-09-06 16:44:22 -04:00
return id ;
}
/* So from the Neighbours Dialog we can call the following control Functions:
* ( 1 ) Load Certificate NeighLoadCertificate ( std : : string file )
* ( 2 ) Neigh Auth NeighAuthFriend ( id , code )
* ( 4 ) Neigh Add NeighAddFriend ( id )
*
* All of these rely on the finding of the current Id .
*/
//std::string NetworkDialog::loadneighbour()
//{
//#ifdef NET_DEBUG
// std::cerr << "NetworkDialog::loadneighbour()" << std::endl;
//#endif
// use misc::getOpenFileName
// QString fileName = QFileDialog::getOpenFileName(this, tr("Select Certificate"), "",
// tr("Certificates (*.pqi *.pem)"));
//
// std::string file = fileName.toStdString();
// std::string id;
// std::string gpg_id;
// if (file != "")
// {
// rsPeers->loadCertificateFromFile(file, id, gpg_id);
// }
// return id;
//}
//void NetworkDialog::addneighbour()
//{
//// QTreeWidgetItem *c = getCurrentNeighbour();
//#ifdef NET_DEBUG
// std::cerr << "NetworkDialog::addneighbour()" << std::endl;
//#endif
// /*
// rsServer->NeighAddFriend(getNeighRsCertId(c));
// */
//}
//void NetworkDialog::authneighbour()
//{
//// QTreeWidgetItem *c = getCurrentNeighbour();
//#ifdef NET_DEBUG
// std::cerr << "NetworkDialog::authneighbour()" << std::endl;
//#endif
// /*
// RsAuthId code;
// rsServer->NeighAuthFriend(getNeighRsCertId(c), code);
// */
//}
/** Open a QFileDialog to browse for a pem/pqi file. */
void NetworkDialog : : on_actionAddFriend_activated ( )
{
// /* Create a new input dialog, which allows users to create files, too */
// use misc::getOpenFileName
// QFileDialog dialog (this, tr("Select a pem/pqi File"));
// //dialog.setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir());
// //dialog.selectFile(QFileInfo(ui.lineTorConfig->text()).fileName());
// dialog.setFileMode(QFileDialog::AnyFile);
// dialog.setReadOnly(false);
//
// /* Prompt the user to select a file or create a new one */
// if (!dialog.exec() || dialog.selectedFiles().isEmpty()) {
// return;
// }
// QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0));
//
// /* Check if the file exists */
// QFile torrcFile(filename);
// if (!QFileInfo(filename).exists()) {
// /* The given file does not exist. Should we create it? */
// int response = VMessageBox::question(this,
// tr("File Not Found"),
// tr("%1 does not exist. Would you like to create it?")
// .arg(filename),
// VMessageBox::Yes, VMessageBox::No);
//
// if (response == VMessageBox::No) {
// /* Don't create it. Just bail. */
// return;
// }
// /* Attempt to create the specified file */
// if (!torrcFile.open(QIODevice::WriteOnly)) {
// VMessageBox::warning(this,
// tr("Failed to Create File"),
// tr("Unable to create %1 [%2]").arg(filename)
// .arg(torrcFile.errorString()),
// VMessageBox::Ok);
// return;
// }
// }
// //ui.lineTorConfig->setText(filename);
}
void NetworkDialog : : on_actionExportKey_activated ( )
{
2014-09-25 16:14:21 -04:00
ProfileManager prof ;
prof . exec ( ) ;
2011-09-06 16:44:22 -04:00
}
void NetworkDialog : : on_actionCreate_New_Profile_activated ( )
{
// GenCertDialog gencertdialog (this);
// gencertdialog.exec ();
}
2013-02-22 16:42:27 -05:00
// void NetworkDialog::on_actionTabsnorth_activated()
// {
// ui.networkTab->setTabPosition(QTabWidget::North);
//
// Settings->setValueToGroup("NetworkDialog", "TabWidget_Position",ui.networkTab->tabPosition());
// }
//
// void NetworkDialog::on_actionTabssouth_activated()
// {
// ui.networkTab->setTabPosition(QTabWidget::South);
//
// Settings->setValueToGroup("NetworkDialog", "TabWidget_Position",ui.networkTab->tabPosition());
//
// }
//
// void NetworkDialog::on_actionTabswest_activated()
// {
// ui.networkTab->setTabPosition(QTabWidget::West);
//
// Settings->setValueToGroup("NetworkDialog", "TabWidget_Position",ui.networkTab->tabPosition());
// }
//
// void NetworkDialog::on_actionTabsright_activated()
// {
// ui.networkTab->setTabPosition(QTabWidget::East);
//
// Settings->setValueToGroup("NetworkDialog", "TabWidget_Position",ui.networkTab->tabPosition());
// }
//
// void NetworkDialog::on_actionTabsTriangular_activated()
// {
// ui.networkTab->setTabShape(QTabWidget::Triangular);
// ui.tabBottom->setTabShape(QTabWidget::Triangular);
// }
//
// void NetworkDialog::on_actionTabsRounded_activated()
// {
// ui.networkTab->setTabShape(QTabWidget::Rounded);
// ui.tabBottom->setTabShape(QTabWidget::Rounded);
// }
//
// void NetworkDialog::loadtabsettings()
// {
// Settings->beginGroup("NetworkDialog");
//
// if(Settings->value("TabWidget_Position","0").toInt() == 0)
// {
// qDebug() << "Tab North";
// ui.networkTab->setTabPosition(QTabWidget::North);
// }
// else if (Settings->value("TabWidget_Position","1").toInt() == 1)
// {
// qDebug() << "Tab South";
// ui.networkTab->setTabPosition(QTabWidget::South);
// }
// else if (Settings->value("TabWidget_Position","2").toInt() ==2)
// {
// qDebug() << "Tab West";
// ui.networkTab->setTabPosition(QTabWidget::West);
// }
// else if(Settings->value("TabWidget_Position","3").toInt() ==3)
// {
// qDebug() << "Tab East";
// ui.networkTab->setTabPosition(QTabWidget::East);
// }
//
// Settings->endGroup();
// }
2011-09-06 16:44:22 -04:00
2012-10-29 06:59:26 -04:00
void NetworkDialog : : filterColumnChanged ( int )
2011-09-06 16:44:22 -04:00
{
2012-04-05 17:03:03 -04:00
filterItems ( ui . filterLineEdit - > text ( ) ) ;
2011-09-06 16:44:22 -04:00
}
2012-04-05 17:03:03 -04:00
void NetworkDialog : : filterItems ( const QString & text )
2011-09-06 16:44:22 -04:00
{
2012-10-29 06:59:26 -04:00
int filterColumn = ui . filterLineEdit - > currentFilter ( ) ;
2011-09-06 16:44:22 -04:00
2013-07-04 16:09:46 -04:00
int count = ui . connectTreeWidget - > topLevelItemCount ( ) ;
2012-04-05 17:03:03 -04:00
for ( int index = 0 ; index < count ; index + + ) {
2013-07-04 16:09:46 -04:00
filterItem ( ui . connectTreeWidget - > topLevelItem ( index ) , text , filterColumn ) ;
2011-09-06 16:44:22 -04:00
}
}
2012-04-05 17:03:03 -04:00
bool NetworkDialog : : filterItem ( QTreeWidgetItem * item , const QString & text , int filterColumn )
2011-09-06 16:44:22 -04:00
{
2012-04-05 17:03:03 -04:00
bool visible = true ;
2011-09-06 16:44:22 -04:00
2012-04-05 17:03:03 -04:00
if ( text . isEmpty ( ) = = false ) {
if ( item - > text ( filterColumn ) . contains ( text , Qt : : CaseInsensitive ) = = false ) {
visible = false ;
2011-09-06 16:44:22 -04:00
}
}
2012-04-05 17:03:03 -04:00
int visibleChildCount = 0 ;
int count = item - > childCount ( ) ;
for ( int index = 0 ; index < count ; index + + ) {
if ( filterItem ( item - > child ( index ) , text , filterColumn ) ) {
visibleChildCount + + ;
2011-09-06 16:44:22 -04:00
}
}
2012-04-05 17:03:03 -04:00
if ( visible | | visibleChildCount ) {
item - > setHidden ( false ) ;
2011-09-06 16:44:22 -04:00
} else {
2012-04-05 17:03:03 -04:00
item - > setHidden ( true ) ;
2011-09-06 16:44:22 -04:00
}
2012-04-05 17:03:03 -04:00
return ( visible | | visibleChildCount ) ;
2011-09-06 16:44:22 -04:00
}