@ -33,6 +33,7 @@
@@ -33,6 +33,7 @@
# include <QPlainTextEdit>
# include <QPushButton>
# include <QCoreApplication>
# include <QThread>
bool toxURIEventHandler ( const QByteArray & eventData )
{
@ -51,33 +52,70 @@ bool toxURIEventHandler(const QByteArray& eventData)
@@ -51,33 +52,70 @@ bool toxURIEventHandler(const QByteArray& eventData)
*/
bool handleToxURI ( const QString & toxURI )
{
Core * core = Core : : getInstance ( ) ;
Nexus & nexus = Nexus : : getInstance ( ) ;
Core * core = nexus . getCore ( ) ;
while ( ! core )
{
core = Core : : getInstance ( ) ;
if ( ! nexus . isRunning ( ) )
return false ;
core = nexus . getCore ( ) ;
qApp - > processEvents ( ) ;
QThread : : msleep ( 10 ) ;
}
while ( ! core - > isReady ( ) )
{
if ( ! nexus . isRunning ( ) )
return false ;
qApp - > processEvents ( ) ;
QThread : : msleep ( 10 ) ;
}
QString toxaddr = toxURI . mid ( 4 ) ;
ToxId toxId = Toxme : : lookup ( toxaddr ) ;
ToxId toxId ( toxaddr ) ;
if ( ! toxId . isValid ( ) )
{
QMessageBox : : warning ( 0 , " qTox " ,
ToxURIDialog : : tr ( " %1 is not a valid Toxme address. " )
. arg ( toxaddr ) ) ;
toxId = Toxme : : lookup ( toxaddr ) ;
if ( ! toxId . isValid ( ) )
{
QMessageBox * messageBox = new QMessageBox ( QMessageBox : : Warning ,
QMessageBox : : tr ( " Couldn't add friend " ) ,
QMessageBox : : tr ( " %1 is not a valid Toxme address. " )
. arg ( toxaddr ) , QMessageBox : : Ok , nullptr ) ;
messageBox - > setButtonText ( QMessageBox : : Ok , QMessageBox : : tr ( " Ok " ) ) ;
QObject : : connect ( messageBox , & QMessageBox : : finished , messageBox , & QMessageBox : : deleteLater ) ;
messageBox - > show ( ) ;
return false ;
}
}
if ( toxId = = core - > getSelfId ( ) )
{
QMessageBox * messageBox = new QMessageBox ( QMessageBox : : Warning ,
QMessageBox : : tr ( " Couldn't add friend " ) ,
QMessageBox : : tr ( " You can't add yourself as a friend! " ,
" When trying to add your own Tox ID as friend " ) ,
QMessageBox : : Ok , nullptr ) ;
messageBox - > setButtonText ( QMessageBox : : Ok , QMessageBox : : tr ( " Ok " ) ) ;
QObject : : connect ( messageBox , & QMessageBox : : finished , messageBox , & QMessageBox : : deleteLater ) ;
messageBox - > show ( ) ;
return false ;
}
ToxURIDialog dialog ( 0 , toxaddr , QObject : : tr ( " %1 here! Tox me maybe? " ,
ToxURIDialog * dialog = new ToxURID ialog ( 0 , toxaddr , QObject : : tr ( " %1 here! Tox me maybe? " ,
" Default message in Tox URI friend requests. Write something appropriate! " )
. arg ( Nexus : : getCore ( ) - > getUsername ( ) ) ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted )
Core : : getInstance ( ) - > requestFriendship ( toxId , dialog . getRequestMessage ( ) ) ;
QObject : : connect ( dialog , & ToxURIDialog : : finished , [ = ] ( int result ) {
if ( result = = QDialog : : Accepted )
Core : : getInstance ( ) - > requestFriendship ( toxId , dialog - > getRequestMessage ( ) ) ;
dialog - > deleteLater ( ) ;
} ) ;
dialog - > open ( ) ;
return true ;
}