2018-07-20 19:48:29 +02:00
/*******************************************************************************
* retroshare - gui / src / : main . cpp *
* *
* libretroshare : retroshare core library *
* *
* Copyright 2006 by Crypton < retroshare @ lunamutt . com > *
* *
* 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/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-15 03:18:48 +00:00
2018-11-05 00:19:45 +01:00
# include "util/stacktrace.h"
2019-08-29 23:15:46 +02:00
# include "util/argstream.h"
2023-11-04 23:41:49 +01:00
# include "retroshare/rswebui.h"
2018-11-05 00:19:45 +01:00
CrashStackTrace gCrashStackTrace ;
2007-11-15 03:18:48 +00:00
# include <QObject>
2010-07-23 18:52:58 +00:00
# include <QMessageBox>
2010-10-19 18:06:22 +00:00
# include <QSplashScreen>
2016-08-06 17:15:56 +02:00
2007-11-15 03:18:48 +00:00
# include <rshare.h>
2020-08-15 22:17:52 +02:00
# include "gui/common/FilesDefs.h"
2011-05-17 17:27:47 +00:00
# include "gui/FriendsDialog.h"
2016-08-06 17:15:56 +02:00
# include "gui/GenCertDialog.h"
# include "gui/MainWindow.h"
2010-08-31 20:00:49 +00:00
# include "gui/NetworkDialog.h"
2016-08-06 17:15:56 +02:00
# include "gui/NetworkView.h"
2011-02-22 14:51:03 +00:00
# include "gui/QuickStartWizard.h"
2016-08-06 17:15:56 +02:00
# include "gui/RetroShareLink.h"
# include "gui/SoundManager.h"
2010-06-08 21:38:36 +00:00
# include "gui/StartDialog.h"
2016-08-06 17:15:56 +02:00
# include "gui/chat/ChatDialog.h"
2010-06-08 21:38:36 +00:00
# include "gui/connect/ConfCertDialog.h"
2021-01-21 22:57:27 +01:00
# include "gui/common/AvatarDialog.h"
2010-09-14 17:47:11 +00:00
# include "gui/common/Emoticons.h"
2016-08-06 17:15:56 +02:00
# include "gui/FileTransfer/SearchDialog.h"
# include "gui/FileTransfer/TransfersDialog.h"
# include "gui/settings/RsharePeerSettings.h"
# include "gui/settings/rsharesettings.h"
# include "idle/idle.h"
2012-07-15 21:37:35 +00:00
# include "lang/languagesupport.h"
2013-07-14 18:48:40 +00:00
# include "util/RsGxsUpdateBroadcast.h"
2017-12-26 17:21:57 +01:00
# include "util/rsdir.h"
2018-01-27 20:22:31 +01:00
# include "util/rstime.h"
2019-08-29 23:15:46 +02:00
# include "retroshare/rsinit.h"
2016-08-06 17:15:56 +02:00
2019-08-21 15:23:25 +02:00
# ifdef MESSENGER_WINDOW
# include "gui/MessengerWindow.h"
# endif
2019-11-10 17:38:16 +01:00
# ifdef RS_WEBUI
2018-04-15 12:41:54 +02:00
# include "gui / settings / WebuiPage.h"
# endif
2018-09-21 01:58:38 +02:00
# ifdef RS_JSONAPI
# include "gui / settings / JsonApiPage.h"
# endif // RS_JSONAPI
2021-06-25 21:46:00 +02:00
# include "retroshare/rstor.h"
2018-07-25 11:37:40 +02:00
# include "TorControl/TorControlWindow.h"
2017-12-21 10:43:28 +01:00
2016-08-06 17:15:56 +02:00
# include "retroshare/rsidentity.h"
2017-12-27 18:59:50 +01:00
# include "retroshare/rspeers.h"
2007-11-15 03:18:48 +00:00
2016-06-11 14:38:31 +02:00
# ifdef SIGFPE_DEBUG
# include <fenv.h>
# endif
2013-10-19 23:41:23 +00:00
# if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
# ifdef WINDOWS_SYS
# include <QFileDialog>
# endif
# endif
2017-03-06 06:34:06 +01:00
# ifdef Q_OS_WIN
# if QT_VERSION >= QT_VERSION_CHECK (5, 7, 0)
// see INSTALL.W32 in openssl
// Needed as workaround for gcc 5.3.0 because the call to GetProcAddress in cryptlib.c finds an function pointer
// to the not existing function _OPENSSL_isservice in the executable running on Windows 7.
extern " C " {
__declspec ( dllexport ) __cdecl BOOL _OPENSSL_isservice ( void )
{
DWORD sess ;
if ( ProcessIdToSessionId ( GetCurrentProcessId ( ) , & sess ) )
return sess = = 0 ;
return FALSE ;
}
}
# endif
# endif
2008-08-15 19:03:50 +00:00
# include <util/stringutil.h>
2010-08-06 09:40:23 +00:00
# include <retroshare/rsinit.h>
# include <retroshare/rsiface.h>
2009-12-31 01:34:23 +00:00
# include "gui/notifyqt.h"
2012-04-12 23:29:39 +00:00
# include <unistd.h>
2007-11-15 03:18:48 +00:00
2012-07-20 19:00:10 +00:00
static void displayWarningAboutDSAKeys ( )
{
2014-01-18 02:35:06 +00:00
std : : map < std : : string , std : : vector < std : : string > > unsupported_keys ;
RsAccounts : : GetUnsupportedKeys ( unsupported_keys ) ;
if ( unsupported_keys . empty ( ) )
2012-07-20 19:00:10 +00:00
return ;
QMessageBox msgBox ;
2014-12-30 11:11:08 +00:00
QString txt = QObject : : tr ( " You appear to have nodes associated to DSA keys: " ) ;
2012-07-20 19:00:10 +00:00
txt + = " <UL> " ;
2014-01-18 02:35:06 +00:00
for ( std : : map < std : : string , std : : vector < std : : string > > : : const_iterator it ( unsupported_keys . begin ( ) ) ; it ! = unsupported_keys . end ( ) ; + + it )
2012-07-20 19:00:10 +00:00
{
txt + = " <LI> " + QString : : fromStdString ( it - > first ) ;
txt + = " <UL> " ;
for ( uint32_t i = 0 ; i < it - > second . size ( ) ; + + i )
txt + = " <li> " + QString : : fromStdString ( it - > second [ i ] ) + " </li> " ;
txt + = " </UL> " ;
txt + = " </li> " ;
}
txt + = " </UL> " ;
msgBox . setText ( txt ) ;
2014-12-30 11:11:08 +00:00
msgBox . setInformativeText ( QObject : : tr ( " DSA keys are not yet supported by this version of RetroShare. All these nodes will be unusable. We're very sorry for that. " ) ) ;
2012-07-20 19:00:10 +00:00
msgBox . setStandardButtons ( QMessageBox : : Ok ) ;
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
2020-08-15 22:17:52 +02:00
msgBox . setWindowIcon ( FilesDefs : : getIconFromQtResourcePath ( " :/icons/logo_128.png " ) ) ;
2012-07-20 19:00:10 +00:00
msgBox . exec ( ) ;
}
2013-10-19 23:41:23 +00:00
# ifdef WINDOWS_SYS
2014-06-22 20:40:01 +00:00
# if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) && QT_VERSION < QT_VERSION_CHECK (5, 3, 0)
2013-10-19 23:41:23 +00:00
QStringList filedialog_open_filenames_hook ( QWidget * parent , const QString & caption , const QString & dir , const QString & filter , QString * selectedFilter , QFileDialog : : Options options )
{
return QFileDialog : : getOpenFileNames ( parent , caption , dir , filter , selectedFilter , options | QFileDialog : : DontUseNativeDialog ) ;
}
QString filedialog_open_filename_hook ( QWidget * parent , const QString & caption , const QString & dir , const QString & filter , QString * selectedFilter , QFileDialog : : Options options )
{
return QFileDialog : : getOpenFileName ( parent , caption , dir , filter , selectedFilter , options | QFileDialog : : DontUseNativeDialog ) ;
}
QString filedialog_save_filename_hook ( QWidget * parent , const QString & caption , const QString & dir , const QString & filter , QString * selectedFilter , QFileDialog : : Options options )
{
return QFileDialog : : getSaveFileName ( parent , caption , dir , filter , selectedFilter , options | QFileDialog : : DontUseNativeDialog ) ;
}
QString filedialog_existing_directory_hook ( QWidget * parent , const QString & caption , const QString & dir , QFileDialog : : Options options )
{
return QFileDialog : : getExistingDirectory ( parent , caption , dir , options | QFileDialog : : DontUseNativeDialog ) ;
}
# endif
# endif
2007-11-15 03:18:48 +00:00
int main ( int argc , char * argv [ ] )
{
2010-11-04 22:54:18 +00:00
# ifdef WINDOWS_SYS
2012-08-31 13:53:54 +00:00
// The current directory of the application is changed when using the native dialog on Windows
// This is a quick fix until libretroshare is using a absolute path in the portable Version
2014-06-22 20:40:01 +00:00
# if QT_VERSION >= QT_VERSION_CHECK (5, 3, 0)
// Do we need a solution in v0.6?
# endif
# if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) && QT_VERSION < QT_VERSION_CHECK (5, 3, 0)
2013-10-19 23:41:23 +00:00
typedef QStringList ( * _qt_filedialog_open_filenames_hook ) ( QWidget * parent , const QString & caption , const QString & dir , const QString & filter , QString * selectedFilter , QFileDialog : : Options options ) ;
typedef QString ( * _qt_filedialog_open_filename_hook ) ( QWidget * parent , const QString & caption , const QString & dir , const QString & filter , QString * selectedFilter , QFileDialog : : Options options ) ;
typedef QString ( * _qt_filedialog_save_filename_hook ) ( QWidget * parent , const QString & caption , const QString & dir , const QString & filter , QString * selectedFilter , QFileDialog : : Options options ) ;
typedef QString ( * _qt_filedialog_existing_directory_hook ) ( QWidget * parent , const QString & caption , const QString & dir , QFileDialog : : Options options ) ;
extern Q_GUI_EXPORT _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook ;
extern Q_GUI_EXPORT _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook ;
extern Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook ;
extern Q_GUI_EXPORT _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook ;
qt_filedialog_open_filename_hook = filedialog_open_filename_hook ;
qt_filedialog_open_filenames_hook = filedialog_open_filenames_hook ;
qt_filedialog_save_filename_hook = filedialog_save_filename_hook ;
qt_filedialog_existing_directory_hook = filedialog_existing_directory_hook ;
2014-06-22 20:40:01 +00:00
# endif
# if QT_VERSION < QT_VERSION_CHECK (5, 0, 0)
2012-08-31 13:53:54 +00:00
extern bool Q_GUI_EXPORT qt_use_native_dialogs ;
qt_use_native_dialogs = false ;
2013-10-19 23:41:23 +00:00
# endif
2012-08-31 13:53:54 +00:00
2012-07-17 22:16:56 +00:00
{
/* Set the current directory to the application dir,
because the start dir with autostart from the registry run key is not the exe dir */
QApplication app ( argc , argv ) ;
QDir : : setCurrent ( QCoreApplication : : applicationDirPath ( ) ) ;
}
2016-06-11 14:38:31 +02:00
# endif
# ifdef SIGFPE_DEBUG
feenableexcept ( FE_INVALID | FE_DIVBYZERO ) ;
2010-11-04 22:54:18 +00:00
# endif
2007-11-15 03:18:48 +00:00
2012-01-22 22:58:23 +00:00
QStringList args = char_array_to_stringlist ( argv + 1 , argc - 1 ) ;
2015-06-27 11:47:37 +00:00
Q_INIT_RESOURCE ( images ) ;
Q_INIT_RESOURCE ( icons ) ;
2007-11-15 03:18:48 +00:00
2016-08-13 14:34:31 +02:00
// Loop through all command-line args/values to get help wanted before RsInit exit.
for ( int i = 0 ; i < args . size ( ) ; + + i ) {
QString arg ;
/* Get the argument name and set a blank value */
arg = args . at ( i ) ;
if ( ( arg . toLower ( ) = = " -h " ) | | ( arg . toLower ( ) = = " --help " ) ) {
QApplication dummyApp ( argc , argv ) ; // needed for QMessageBox
Rshare : : showUsageMessageBox ( ) ;
}
}
2014-01-07 22:51:22 +00:00
// This is needed to allocate rsNotify, so that it can be used to ask for PGP passphrase
//
RsControl : : earlyInitNotificationSystem ( ) ;
2010-07-18 11:43:39 +00:00
NotifyQt * notify = NotifyQt : : Create ( ) ;
2014-01-07 22:51:22 +00:00
rsNotify - > registerNotifyClient ( notify ) ;
2009-11-05 19:38:10 +00:00
2012-01-22 22:58:23 +00:00
/* RetroShare Core Objects */
2009-02-08 14:30:28 +00:00
RsInit : : InitRsConfig ( ) ;
2019-08-29 23:15:46 +02:00
RsConfigOptions conf ;
argstream as ( argc , argv ) ;
as > > option ( ' s ' , " stderr " , conf . outStderr , " output to stderr instead of log file. " )
> > option ( ' u ' , " udp " , conf . udpListenerOnly , " Only listen to UDP. " )
> > parameter ( ' c ' , " base-dir " , conf . optBaseDir , " directory " , " Set base directory. " , false )
> > parameter ( ' l ' , " log-file " , conf . logfname , " logfile " , " Set Log filename. " , false )
> > parameter ( ' d ' , " debug-level " , conf . debugLevel , " level " , " Set debug level. " , false )
> > parameter ( ' i ' , " ip-address " , conf . forcedInetAddress , " nnn.nnn.nnn.nnn " , " Force IP address to use (if cannot be detected). " , false )
> > parameter ( ' p ' , " port " , conf . forcedPort , " port " , " Set listenning port to use. " , false )
2022-11-07 21:10:55 +01:00
> > parameter ( ' o ' , " opmode " , conf . opModeStr , " opmode " , " Set Operating mode (Full, NoTurtle, Gaming, Minimal). " , false )
> > parameter ( ' t ' , " opmode " , conf . userSuppliedTorExecutable , " tor " , " supply full tor eecutable path. " , false ) ;
2019-08-29 23:15:46 +02:00
# ifdef RS_JSONAPI
as > > parameter ( ' J ' , " jsonApiPort " , conf . jsonApiPort , " jsonApiPort " , " Enable JSON API on the specified port " , false )
> > parameter ( ' P ' , " jsonApiBindAddress " , conf . jsonApiBindAddress , " jsonApiBindAddress " , " JSON API Bind Address. " , false ) ;
# endif // ifdef RS_JSONAPI
# ifdef LOCALNET_TESTING
as > > parameter ( ' R ' , " restrict-port " , portRestrictions , " port1-port2 " , " Apply port restriction " , false ) ;
# endif // ifdef LOCALNET_TESTING
# ifdef RS_AUTOLOGIN
as > > option ( ' a ' , " auto-login " , conf . autoLogin , " AutoLogin (Windows Only) + StartMinimised " ) ;
# endif // ifdef RS_AUTOLOGIN
conf . main_executable_path = argv [ 0 ] ;
int initResult = RsInit : : InitRetroShare ( conf ) ;
2010-11-03 22:54:34 +00:00
2012-06-09 21:01:22 +00:00
if ( initResult = = RS_INIT_NO_KEYRING ) // happens when we already have accounts, but no pgp key. This is when switching to the openpgp-sdk version.
{
2012-07-17 22:16:56 +00:00
QApplication dummyApp ( argc , argv ) ; // needed for QMessageBox
/* Translate into the desired language */
LanguageSupport : : translate ( LanguageSupport : : defaultLanguageCode ( ) ) ;
2012-06-09 21:01:22 +00:00
QMessageBox msgBox ;
2012-11-28 19:58:14 +00:00
msgBox . setText ( QObject : : tr ( " This version of RetroShare is using OpenPGP-SDK. As a side effect, it's not using the system shared PGP keyring, but has it's own keyring shared by all RetroShare instances. <br><br>You do not appear to have such a keyring, although PGP keys are mentioned by existing RetroShare accounts, probably because you just changed to this new version of the software. " ) ) ;
2012-07-13 12:20:44 +00:00
msgBox . setInformativeText ( QObject : : tr ( " Choose between:<br><ul><li><b>Ok</b> to copy the existing keyring from gnupg (safest bet), or </li><li><b>Close without saving</b> to start fresh with an empty keyring (you will be asked to create a new PGP key to work with RetroShare, or import a previously saved pgp keypair). </li><li><b>Cancel</b> to quit and forge a keyring by yourself (needs some PGP skills)</li></ul> " ) ) ;
2012-06-09 21:01:22 +00:00
msgBox . setStandardButtons ( QMessageBox : : Ok | QMessageBox : : Discard | QMessageBox : : Cancel ) ;
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
2020-08-15 22:17:52 +02:00
msgBox . setWindowIcon ( FilesDefs : : getIconFromQtResourcePath ( " :/icons/logo_128.png " ) ) ;
2012-06-09 21:01:22 +00:00
int ret = msgBox . exec ( ) ;
if ( ret = = QMessageBox : : Cancel )
return 0 ;
if ( ret = = QMessageBox : : Ok )
{
2014-01-18 02:35:06 +00:00
if ( ! RsAccounts : : CopyGnuPGKeyrings ( ) )
2012-06-09 21:01:22 +00:00
return 0 ;
2019-08-29 23:15:46 +02:00
initResult = RsInit : : InitRetroShare ( conf ) ;
2012-07-20 19:00:10 +00:00
displayWarningAboutDSAKeys ( ) ;
2012-06-09 21:01:22 +00:00
}
else
initResult = RS_INIT_OK ;
}
2010-11-03 22:54:34 +00:00
if ( initResult < 0 ) {
/* Error occured */
2012-07-17 22:16:56 +00:00
QApplication dummyApp ( argc , argv ) ; // needed for QMessageBox
/* Translate into the desired language */
LanguageSupport : : translate ( LanguageSupport : : defaultLanguageCode ( ) ) ;
2012-07-20 19:00:10 +00:00
displayWarningAboutDSAKeys ( ) ;
2010-11-03 22:54:34 +00:00
QMessageBox mb ( QMessageBox : : Critical , QObject : : tr ( " RetroShare " ) , " " , QMessageBox : : Ok ) ;
2020-08-15 22:17:52 +02:00
mb . setWindowIcon ( FilesDefs : : getIconFromQtResourcePath ( " :/icons/logo_128.png " ) ) ;
2010-11-03 22:54:34 +00:00
2012-06-09 21:01:22 +00:00
switch ( initResult )
{
case RS_INIT_AUTH_FAILED :
std : : cerr < < " RsInit::InitRetroShare AuthGPG::InitAuth failed " < < std : : endl ;
2012-11-28 19:58:14 +00:00
mb . setText ( QObject : : tr ( " Initialization failed. Wrong or missing installation of PGP. " ) ) ;
2012-06-09 21:01:22 +00:00
break ;
default :
/* Unexpected return code */
std : : cerr < < " RsInit::InitRetroShare unexpected return code " < < initResult < < std : : endl ;
2012-10-11 10:28:24 +00:00
mb . setText ( QObject : : tr ( " An unexpected error occurred. Please report 'RsInit::InitRetroShare unexpected return code %1'. " ) . arg ( initResult ) ) ;
2012-06-09 21:01:22 +00:00
break ;
2010-11-03 22:54:34 +00:00
}
mb . exec ( ) ;
return 1 ;
}
2010-05-20 21:53:27 +00:00
2010-06-14 13:32:13 +00:00
/* create global settings object
path maybe wrong , when no profile exist
in this case it can be use only for default values */
2010-05-20 21:53:27 +00:00
RshareSettings : : Create ( ) ;
2007-11-15 03:18:48 +00:00
/* Setup The GUI Stuff */
2017-12-21 10:43:28 +01:00
Rshare rshare ( args , argc , argv , QString : : fromUtf8 ( RsAccounts : : ConfigDirectory ( ) . c_str ( ) ) ) ;
2016-03-01 13:08:33 +01:00
/* Start RetroShare */
2016-08-06 17:15:56 +02:00
QString sDefaultGXSIdToCreate = " " ;
2010-11-03 22:54:34 +00:00
switch ( initResult ) {
case RS_INIT_OK :
2007-11-15 03:18:48 +00:00
{
2010-11-03 22:54:34 +00:00
/* Login Dialog */
/* check for existing Certificate */
bool genCert = false ;
2014-03-17 20:56:06 +00:00
std : : list < RsPeerId > accountIds ;
2014-01-18 02:35:06 +00:00
if ( RsAccounts : : GetAccountIds ( accountIds ) & & ( accountIds . size ( ) > 0 ) )
2009-02-08 14:30:28 +00:00
{
2012-11-01 01:07:36 +00:00
StartDialog sd ;
if ( sd . exec ( ) = = QDialog : : Rejected ) {
return 1 ;
2010-11-03 22:54:34 +00:00
}
/* if we're logged in */
2012-11-01 01:07:36 +00:00
genCert = sd . requestedNewCert ( ) ;
2010-11-03 22:54:34 +00:00
}
else
{
genCert = true ;
2009-02-08 14:30:28 +00:00
}
2007-11-15 03:18:48 +00:00
2010-11-03 22:54:34 +00:00
if ( genCert )
{
2012-10-29 11:02:03 +00:00
GenCertDialog gd ( false ) ;
2017-12-21 18:16:32 +01:00
if ( gd . exec ( ) = = QDialog : : Rejected )
2012-11-01 01:07:36 +00:00
return 1 ;
2017-12-21 18:16:32 +01:00
2016-08-06 17:15:56 +02:00
sDefaultGXSIdToCreate = gd . getGXSNickname ( ) ;
2010-11-03 22:54:34 +00:00
}
2007-11-15 03:18:48 +00:00
2017-12-26 20:42:25 +01:00
//splashScreen.show();
2007-11-15 03:18:48 +00:00
}
2010-11-03 22:54:34 +00:00
break ;
case RS_INIT_HAVE_ACCOUNT :
{
2017-12-26 20:42:25 +01:00
//splashScreen.show();
//splashScreen.showMessage(rshare.translate("SplashScreen", "Load profile"), Qt::AlignHCenter | Qt::AlignBottom);
2010-10-19 18:06:22 +00:00
2014-03-17 20:56:06 +00:00
RsPeerId preferredId ;
2014-01-18 02:35:06 +00:00
RsAccounts : : GetPreferredAccountId ( preferredId ) ;
2010-04-08 15:51:10 +00:00
2010-11-03 22:54:34 +00:00
// true: note auto-login is active
2012-11-01 01:07:36 +00:00
Rshare : : loadCertificate ( preferredId , true ) ;
2010-11-03 22:54:34 +00:00
}
break ;
default :
/* Unexpected return code */
std : : cerr < < " RsInit::InitRetroShare unexpected return code " < < initResult < < std : : endl ;
QMessageBox : : warning ( 0 , QObject : : tr ( " RetroShare " ) , QObject : : tr ( " An unexpected error occured. Please report 'RsInit::InitRetroShare unexpected return code %1'. " ) . arg ( initResult ) ) ;
return 1 ;
2007-11-15 03:18:48 +00:00
}
2023-11-04 23:41:49 +01:00
/* recreate global settings object, now with correct path, specific to the selected node */
2011-10-14 21:16:34 +00:00
RshareSettings : : Create ( true ) ;
Rshare : : resetLanguageAndStyle ( ) ;
2012-01-22 22:58:23 +00:00
SoundManager : : create ( ) ;
2018-07-24 23:47:32 +02:00
bool is_hidden_node = false ;
bool is_auto_tor = false ;
bool is_first_time = false ;
2017-12-21 18:16:32 +01:00
2018-07-24 23:47:32 +02:00
RsAccounts : : getCurrentAccountOptions ( is_hidden_node , is_auto_tor , is_first_time ) ;
2017-12-21 18:16:32 +01:00
2018-07-25 11:37:40 +02:00
if ( is_auto_tor )
2018-07-24 23:47:32 +02:00
{
2022-11-07 21:10:55 +01:00
if ( ! conf . userSuppliedTorExecutable . empty ( ) )
RsTor : : setTorExecutablePath ( conf . userSuppliedTorExecutable ) ;
2018-07-24 23:47:32 +02:00
// Now that we know the Tor service running, and we know the SSL id, we can make sure it provides a viable hidden service
2017-12-26 17:21:57 +01:00
2021-06-26 17:12:17 +02:00
std : : string tor_hidden_service_dir = RsAccounts : : AccountDirectory ( ) + " /hidden_service/ " ;
2017-12-26 17:21:57 +01:00
2021-06-26 17:12:17 +02:00
RsTor : : setTorDataDirectory ( Rshare : : dataDirectory ( ) . toStdString ( ) + " /tor/ " ) ;
RsTor : : setHiddenServiceDirectory ( tor_hidden_service_dir ) ; // re-set it, because now it's changed to the specific location that is run
2018-01-20 17:10:47 +01:00
2021-06-26 17:12:17 +02:00
RsDirUtil : : checkCreateDirectory ( std : : string ( tor_hidden_service_dir ) ) ;
2017-12-26 17:21:57 +01:00
2021-12-17 16:54:44 +01:00
//RsTor::setupHiddenService();
2018-07-24 23:47:32 +02:00
2021-06-26 17:12:17 +02:00
if ( ! RsTor : : start ( ) | | RsTor : : hasError ( ) )
2018-07-24 23:47:32 +02:00
{
2021-06-26 17:12:17 +02:00
QMessageBox : : critical ( NULL , QObject : : tr ( " Cannot start Tor Manager! " ) , QObject : : tr ( " Tor cannot be started on your system: \n \n " ) + QString : : fromStdString ( RsTor : : errorMessage ( ) ) ) ;
2018-07-24 23:47:32 +02:00
return 1 ;
}
2017-12-21 18:16:32 +01:00
2017-12-21 21:34:51 +01:00
{
2021-06-26 17:12:17 +02:00
TorControlDialog tcd ;
2018-07-24 23:47:32 +02:00
QString error_msg ;
tcd . show ( ) ;
2018-02-08 15:26:21 +01:00
2018-07-24 23:47:32 +02:00
while ( tcd . checkForTor ( error_msg ) ! = TorControlDialog : : TOR_STATUS_OK | | tcd . checkForHiddenService ( ) ! = TorControlDialog : : HIDDEN_SERVICE_STATUS_OK ) // runs until some status is reached: either tor works, or it fails.
2018-02-08 15:26:21 +01:00
{
2018-07-24 23:47:32 +02:00
QCoreApplication : : processEvents ( ) ;
rstime : : rs_usleep ( 0.2 * 1000 * 1000 ) ;
if ( ! error_msg . isNull ( ) )
{
QMessageBox : : critical ( NULL , QObject : : tr ( " Cannot start Tor " ) , QObject : : tr ( " Sorry but Tor cannot be started on your system! \n \n The error reported is: \" " ) + error_msg + " \" " ) ;
return 1 ;
}
2018-02-08 15:26:21 +01:00
}
2017-12-21 18:16:32 +01:00
2018-07-24 23:47:32 +02:00
tcd . hide ( ) ;
2017-12-21 18:16:32 +01:00
2018-07-24 23:47:32 +02:00
if ( tcd . checkForHiddenService ( ) ! = TorControlDialog : : HIDDEN_SERVICE_STATUS_OK )
{
QMessageBox : : critical ( NULL , QObject : : tr ( " Cannot start a hidden tor service! " ) , QObject : : tr ( " It was not possible to start a hidden service. " ) ) ;
return 1 ;
}
2017-12-21 21:34:51 +01:00
}
2017-12-21 18:16:32 +01:00
}
2020-08-19 16:19:42 +02:00
QSplashScreen splashScreen ( FilesDefs : : getPixmapFromQtResourcePath ( " :/images/logo/logo_splash.png " ) /* , Qt::WindowStaysOnTopHint*/ ) ;
2017-12-26 20:42:25 +01:00
splashScreen . show ( ) ;
2010-10-19 18:06:22 +00:00
splashScreen . showMessage ( rshare . translate ( " SplashScreen " , " Load configuration " ) , Qt : : AlignHCenter | Qt : : AlignBottom ) ;
2018-01-19 13:42:31 +01:00
QCoreApplication : : processEvents ( ) ;
2012-02-03 00:15:49 +00:00
/* stop Retroshare if startup fails */
2014-01-07 22:51:22 +00:00
if ( ! RsControl : : instance ( ) - > StartupRetroShare ( ) )
2012-02-03 00:15:49 +00:00
{
std : : cerr < < " libretroshare failed to startup! " < < std : : endl ;
return 1 ;
}
2018-07-25 11:37:40 +02:00
if ( is_auto_tor )
{
// Tor works with viable hidden service. Let's use it!
2017-12-27 18:59:50 +01:00
2021-06-26 17:12:17 +02:00
std : : string service_id ;
std : : string onion_address ;
2018-07-25 11:37:40 +02:00
uint16_t service_port ;
uint16_t service_target_port ;
uint16_t proxy_server_port ;
2021-06-26 17:12:17 +02:00
std : : string service_target_address ;
std : : string proxy_server_address ;
2017-12-27 18:59:50 +01:00
2021-06-26 17:12:17 +02:00
RsTor : : getHiddenServiceInfo ( service_id , onion_address , service_port , service_target_address , service_target_port ) ;
RsTor : : getProxyServerInfo ( proxy_server_address , proxy_server_port ) ;
2017-12-27 18:59:50 +01:00
2018-07-25 11:37:40 +02:00
std : : cerr < < " Got hidden service info: " < < std : : endl ;
2021-06-26 17:12:17 +02:00
std : : cerr < < " onion address : " < < onion_address < < std : : endl ;
std : : cerr < < " service_id : " < < service_id < < std : : endl ;
2018-07-25 11:37:40 +02:00
std : : cerr < < " service port : " < < service_port < < std : : endl ;
std : : cerr < < " target port : " < < service_target_port < < std : : endl ;
2021-06-26 17:12:17 +02:00
std : : cerr < < " target address : " < < service_target_address < < std : : endl ;
2017-12-27 18:59:50 +01:00
2021-06-26 17:12:17 +02:00
std : : cerr < < " Setting proxy server to " < < service_target_address < < " : " < < service_target_port < < std : : endl ;
2017-12-27 18:59:50 +01:00
2021-06-26 17:12:17 +02:00
rsPeers - > setLocalAddress ( rsPeers - > getOwnId ( ) , service_target_address , service_target_port ) ;
rsPeers - > setHiddenNode ( rsPeers - > getOwnId ( ) , onion_address , service_port ) ;
rsPeers - > setProxyServer ( RS_HIDDEN_TYPE_TOR , proxy_server_address , proxy_server_port ) ;
2018-07-25 11:37:40 +02:00
}
2012-02-03 00:15:49 +00:00
2011-11-17 21:17:24 +00:00
Rshare : : initPlugins ( ) ;
2007-11-15 03:18:48 +00:00
2010-10-19 18:06:22 +00:00
splashScreen . showMessage ( rshare . translate ( " SplashScreen " , " Create interface " ) , Qt : : AlignHCenter | Qt : : AlignBottom ) ;
2017-12-27 18:59:50 +01:00
QCoreApplication : : processEvents ( ) ; // forces splashscreen to show up
2010-10-19 18:06:22 +00:00
2010-09-10 18:38:46 +00:00
RsharePeerSettings : : Create ( ) ;
2010-06-14 13:32:13 +00:00
2010-09-14 17:47:11 +00:00
Emoticons : : load ( ) ;
2021-01-21 22:57:27 +01:00
AvatarDialog : : load ( ) ;
2010-09-14 17:47:11 +00:00
2010-10-19 18:06:22 +00:00
if ( Settings - > value ( QString : : fromUtf8 ( " FirstRun " ) , true ) . toBool ( ) ) {
splashScreen . hide ( ) ;
Settings - > setValue ( QString : : fromUtf8 ( " FirstRun " ) , false ) ;
2012-02-03 00:15:49 +00:00
2015-06-07 17:35:58 +00:00
SoundManager : : initDefault ( ) ;
2015-06-07 12:40:25 +00:00
2012-02-03 00:15:49 +00:00
# ifdef __APPLE__
/* For OSX, we set the default to "cleanlooks", as the AQUA style hides some input boxes
* only on the first run - as the user might want to change it ; )
*/
QString osx_style ( " cleanlooks " ) ;
Rshare : : setStyle ( osx_style ) ;
Settings - > setInterfaceStyle ( osx_style ) ;
# endif
2012-01-27 13:52:13 +00:00
// This is now disabled - as it doesn't add very much.
// Need to make sure that defaults are sensible!
# ifdef ENABLE_QUICKSTART_WIZARD
2010-10-19 18:06:22 +00:00
QuickStartWizard qstartWizard ;
qstartWizard . exec ( ) ;
2012-01-27 13:52:13 +00:00
# endif
2012-02-03 00:15:49 +00:00
2010-10-19 18:06:22 +00:00
}
2010-05-03 00:09:55 +00:00
MainWindow * w = MainWindow : : Create ( ) ;
2010-10-19 18:06:22 +00:00
splashScreen . finish ( w ) ;
2009-01-22 21:06:54 +00:00
2016-03-01 13:08:33 +01:00
w - > processLastArgs ( ) ;
2011-04-14 23:58:30 +00:00
2016-08-06 17:15:56 +02:00
if ( ! sDefaultGXSIdToCreate . isEmpty ( ) ) {
RsIdentityParameters params ;
params . nickname = sDefaultGXSIdToCreate . toUtf8 ( ) . constData ( ) ;
params . isPgpLinked = true ;
params . mImage . clear ( ) ;
uint32_t token = 0 ;
rsIdentity - > createIdentity ( token , params ) ;
}
2009-01-22 21:06:54 +00:00
// I'm using a signal to transfer the hashing info to the mainwindow, because Qt schedules signals properly to
// avoid clashes between infos from threads.
//
2009-08-16 20:10:53 +00:00
2014-06-12 22:06:43 +00:00
qRegisterMetaType < RsPeerId > ( " RsPeerId " ) ;
2023-11-10 22:42:32 +01:00
# ifdef DEBUG
2009-03-15 22:45:40 +00:00
std : : cerr < < " connecting signals and slots " < < std : : endl ;
2023-11-10 22:42:32 +01:00
# endif
2013-03-01 23:00:43 +00:00
QObject : : connect ( notify , SIGNAL ( deferredSignatureHandlingRequested ( ) ) , notify , SLOT ( handleSignatureEvent ( ) ) , Qt : : QueuedConnection ) ;
2013-03-18 23:19:37 +00:00
QObject : : connect ( notify , SIGNAL ( chatLobbyTimeShift ( int ) ) , notify , SLOT ( handleChatLobbyTimeShift ( int ) ) , Qt : : QueuedConnection ) ;
2010-05-21 20:49:48 +00:00
QObject : : connect ( notify , SIGNAL ( diskFull ( int , int ) ) , w , SLOT ( displayDiskSpaceWarning ( int , int ) ) ) ;
2016-08-19 18:49:42 +02:00
QObject : : connect ( notify , SIGNAL ( filesPostModChanged ( bool ) ) , w , SLOT ( postModDirectories ( bool ) ) , Qt : : QueuedConnection ) ;
2009-08-16 20:10:53 +00:00
QObject : : connect ( notify , SIGNAL ( transfersChanged ( ) ) , w - > transfersDialog , SLOT ( insertTransfers ( ) ) ) ;
2011-05-17 17:27:47 +00:00
QObject : : connect ( notify , SIGNAL ( publicChatChanged ( int ) ) , w - > friendsDialog , SLOT ( publicChatChanged ( int ) ) ) ;
2013-05-21 12:55:03 +00:00
QObject : : connect ( notify , SIGNAL ( neighboursChanged ( ) ) , w - > friendsDialog - > networkDialog , SLOT ( securedUpdateDisplay ( ) ) ) ;
2007-11-15 03:18:48 +00:00
2011-05-17 17:27:47 +00:00
QObject : : connect ( notify , SIGNAL ( chatStatusChanged ( const QString & , const QString & , bool ) ) , w - > friendsDialog , SLOT ( updatePeerStatusString ( const QString & , const QString & , bool ) ) ) ;
QObject : : connect ( notify , SIGNAL ( ownStatusMessageChanged ( ) ) , w - > friendsDialog , SLOT ( loadmypersonalstatus ( ) ) ) ;
2009-10-05 19:07:02 +00:00
2017-10-08 21:00:15 +02:00
// QObject::connect(notify,SIGNAL(logInfoChanged(const QString&)) ,w->friendsDialog->networkDialog,SLOT(setLogInfo(QString))) ;
2013-02-22 21:42:27 +00:00
QObject : : connect ( notify , SIGNAL ( discInfoChanged ( ) ) , w - > friendsDialog - > networkView , SLOT ( update ( ) ) , Qt : : QueuedConnection ) ;
2010-02-07 18:10:12 +00:00
QObject : : connect ( notify , SIGNAL ( errorOccurred ( int , int , const QString & ) ) , w , SLOT ( displayErrorMessage ( int , int , const QString & ) ) ) ;
2009-05-05 13:18:53 +00:00
2010-06-15 16:51:48 +00:00
w - > installGroupChatNotifier ( ) ;
2009-07-13 14:01:49 +00:00
2010-06-15 16:51:48 +00:00
/* only show window, if not startMinimized */
2011-04-14 21:59:51 +00:00
if ( RsInit : : getStartMinimised ( ) | | Settings - > getStartMinimized ( ) )
2007-11-15 03:18:48 +00:00
{
2010-10-19 18:06:22 +00:00
splashScreen . close ( ) ;
2010-11-21 22:18:56 +00:00
} else {
w - > show ( ) ;
2008-10-18 16:02:06 +00:00
}
2009-02-08 14:30:28 +00:00
2007-11-15 03:18:48 +00:00
/* Startup a Timer to keep the gui's updated */
QTimer * timer = new QTimer ( w ) ;
timer - > connect ( timer , SIGNAL ( timeout ( ) ) , notify , SLOT ( UpdateGUI ( ) ) ) ;
2009-02-08 14:30:28 +00:00
timer - > start ( 1000 ) ;
2010-08-31 20:00:49 +00:00
2012-05-15 20:35:05 +00:00
notify - > enable ( ) ; // enable notification system after GUI creation, to avoid data races in Qt.
2023-11-04 23:41:49 +01:00
// Read webui params in settings. We cannot save them to some webui.cfg because cfg needs the node id and
// jsonapi is started before node ID selection in retroshare-service.
2018-09-21 01:58:38 +02:00
2023-11-04 23:41:49 +01:00
# ifdef RS_JSONAPI
2019-11-16 18:19:07 +01:00
# ifdef RS_WEBUI
2023-11-04 23:41:49 +01:00
conf . enableWebUI = Settings - > getWebinterfaceEnabled ( ) ;
if ( ! Settings - > getWebinterfaceFilesDirectory ( ) . isNull ( ) )
rsWebUi - > setHtmlFilesDirectory ( Settings - > getWebinterfaceFilesDirectory ( ) . toStdString ( ) ) ;
# endif
2023-11-10 22:42:32 +01:00
RsInit : : startupWebServices ( conf , false ) ;
2019-11-16 18:19:07 +01:00
# endif
2009-02-08 14:30:28 +00:00
/* dive into the endless loop */
2010-05-20 21:53:27 +00:00
int ti = rshare . exec ( ) ;
delete w ;
2007-11-15 03:18:48 +00:00
2019-11-16 18:19:07 +01:00
# ifdef RS_JSONAPI
JsonApiPage : : checkShutdownJsonApi ( ) ;
# endif // RS_JSONAPI
2010-06-17 17:39:32 +00:00
/* cleanup */
2012-01-17 20:36:36 +00:00
ChatDialog : : cleanupChat ( ) ;
2013-07-14 18:48:40 +00:00
# ifdef RS_ENABLE_GXS
RsGxsUpdateBroadcast : : cleanup ( ) ;
# endif
2010-06-17 17:39:32 +00:00
2021-12-29 17:23:25 +01:00
if ( is_auto_tor ) {
RsTor : : stop ( ) ;
}
2014-01-07 22:51:22 +00:00
RsControl : : instance ( ) - > rsGlobalShutDown ( ) ;
2010-05-29 15:14:25 +00:00
2012-01-22 22:58:23 +00:00
delete ( soundManager ) ;
soundManager = NULL ;
2010-05-20 21:53:27 +00:00
Settings - > sync ( ) ;
2012-01-22 22:58:23 +00:00
delete ( Settings ) ;
2007-11-15 03:18:48 +00:00
2010-05-20 21:53:27 +00:00
return ti ;
}