2010-12-07 19:14:12 -05:00
/****************************************************************
* This file is distributed under the following license :
*
* Copyright ( c ) 2010 RetroShare Team
*
* 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 .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2015-03-20 06:39:17 -04:00
# include <retroshare/rsgxsifacehelper.h>
2010-12-07 19:14:12 -05:00
2010-07-23 14:52:58 -04:00
# include <QInputDialog>
# include <QMessageBox>
2010-12-07 19:14:12 -05:00
# include <QTimer>
//#include <QMutexLocker>
# include <QDesktopWidget>
2009-12-28 17:40:45 -05:00
# include "notifyqt.h"
2010-08-06 05:40:23 -04:00
# include <retroshare/rsnotify.h>
2012-09-04 16:04:49 -04:00
# include <retroshare/rspeers.h>
2013-03-01 18:00:43 -05:00
# include <util/rsdir.h>
2009-12-28 17:40:45 -05:00
2010-12-07 19:14:12 -05:00
# include "RsAutoUpdatePage.h"
2009-12-28 17:40:45 -05:00
2011-02-22 09:51:03 -05:00
# include "MainWindow.h"
2010-12-07 19:14:12 -05:00
# include "toaster/OnlineToaster.h"
# include "toaster/MessageToaster.h"
# include "toaster/DownloadToaster.h"
2012-03-30 19:02:52 -04:00
# include "toaster/ChatToaster.h"
# include "toaster/GroupChatToaster.h"
# include "toaster/ChatLobbyToaster.h"
2012-04-25 15:19:16 -04:00
# include "toaster/FriendRequestToaster.h"
2015-05-26 11:19:57 -04:00
# include "toaster/ToasterItem.h"
# include "common/ToasterNotify.h"
2009-12-28 17:40:45 -05:00
2012-03-30 19:02:52 -04:00
# include "chat/ChatDialog.h"
2013-01-03 11:20:14 -05:00
# include "chat/ChatLobbyDialog.h"
2012-03-30 19:02:52 -04:00
# include "chat/ChatWidget.h"
# include "FriendsDialog.h"
2009-12-28 17:40:45 -05:00
# include "gui/settings/rsharesettings.h"
2012-01-22 17:58:23 -05:00
# include "SoundManager.h"
2009-12-28 17:40:45 -05:00
2015-05-26 11:19:57 -04:00
# include "retroshare/rsplugin.h"
2009-12-28 17:40:45 -05:00
/*****
* # define NOTIFY_DEBUG
* * * */
2010-07-18 07:43:39 -04:00
/*static*/ NotifyQt * NotifyQt : : _instance = NULL ;
2014-05-10 14:32:48 -04:00
/*static*/ bool NotifyQt : : _disableAllToaster = false ;
2010-07-18 07:43:39 -04:00
/*static*/ NotifyQt * NotifyQt : : Create ( )
{
if ( _instance = = NULL ) {
_instance = new NotifyQt ( ) ;
}
return _instance ;
}
/*static*/ NotifyQt * NotifyQt : : getInstance ( )
{
return _instance ;
}
2014-05-10 14:32:48 -04:00
/*static*/ bool NotifyQt : : isAllDisable ( )
{
return _disableAllToaster ;
}
void NotifyQt : : SetDisableAll ( bool bValue )
{
if ( bValue ! = _disableAllToaster )
{
_disableAllToaster = bValue ;
emit disableAllChanged ( bValue ) ;
}
}
2010-12-07 19:14:12 -05:00
NotifyQt : : NotifyQt ( ) : cDialog ( NULL )
{
runningToasterTimer = new QTimer ( this ) ;
connect ( runningToasterTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( runningTick ( ) ) ) ;
runningToasterTimer - > setInterval ( 10 ) ; // tick 100 times a second
runningToasterTimer - > setSingleShot ( true ) ;
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
_enabled = false ;
}
2014-06-12 18:06:43 -04:00
2014-12-29 16:41:05 -05:00
// register to allow sending over Qt::QueuedConnection
qRegisterMetaType < ChatId > ( " ChatId " ) ;
qRegisterMetaType < ChatMessage > ( " ChatMessage " ) ;
2015-03-20 06:39:17 -04:00
qRegisterMetaType < RsGxsChanges > ( " RsGxsChanges " ) ;
2010-12-07 19:14:12 -05:00
}
2009-12-28 17:40:45 -05:00
void NotifyQt : : notifyErrorMsg ( int list , int type , std : : string msg )
{
2012-05-15 16:32:36 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2012-05-06 07:48:02 -04:00
emit errorOccurred ( list , type , QString : : fromUtf8 ( msg . c_str ( ) ) ) ;
2009-12-28 17:40:45 -05:00
}
2014-12-29 16:41:05 -05:00
void NotifyQt : : notifyChatMessage ( const ChatMessage & msg )
{
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
# ifdef NOTIFY_DEBUG
std : : cerr < < " notifyQt: Received chat message " < < std : : endl ;
# endif
emit chatMessageReceived ( msg ) ;
}
2009-12-28 17:40:45 -05:00
void NotifyQt : : notifyOwnAvatarChanged ( )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2014-05-10 14:32:48 -04:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " Notifyqt:: notified that own avatar changed " < < std : : endl ;
2014-05-10 14:32:48 -04:00
# endif
2009-12-28 17:40:45 -05:00
emit ownAvatarChanged ( ) ;
}
2013-03-01 18:00:43 -05:00
class SignatureEventData
{
public :
SignatureEventData ( const void * _data , int32_t _len , unsigned int _signlen )
{
// We need a new memory chnk because there's no guarranty _sign nor _signlen are not in the stack
sign = ( unsigned char * ) malloc ( _signlen ) ;
signlen = new unsigned int ;
* signlen = _signlen ;
2015-06-12 17:04:11 -04:00
signature_result = SELF_SIGNATURE_RESULT_PENDING ;
2013-03-22 17:59:27 -04:00
data = malloc ( _len ) ;
len = _len ;
memcpy ( data , _data , len ) ;
2013-03-01 18:00:43 -05:00
}
~ SignatureEventData ( )
{
free ( sign ) ;
delete signlen ;
2013-03-22 17:59:27 -04:00
free ( data ) ;
2013-03-01 18:00:43 -05:00
}
2013-06-10 09:27:24 -04:00
void performSignature ( )
2015-06-12 17:04:11 -04:00
{
if ( rsPeers - > gpgSignData ( data , len , sign , signlen ) )
signature_result = SELF_SIGNATURE_RESULT_SUCCESS ;
else
signature_result = SELF_SIGNATURE_RESULT_FAILED ;
}
2013-03-01 18:00:43 -05:00
2013-03-22 17:59:27 -04:00
void * data ;
2013-03-01 18:00:43 -05:00
uint32_t len ;
unsigned char * sign ;
unsigned int * signlen ;
2015-06-12 17:04:11 -04:00
int signature_result ; // 0=pending, 1=done, 2=failed/cancelled.
2013-03-01 18:00:43 -05:00
} ;
bool NotifyQt : : askForDeferredSelfSignature ( const void * data , const uint32_t len , unsigned char * sign , unsigned int * signlen , int & signature_result )
{
{
QMutexLocker m ( & _mutex ) ;
std : : cerr < < " NotifyQt:: deferred signature event requeted. " < < std : : endl ;
// Look into the queue
Sha1CheckSum chksum = RsDirUtil : : sha1sum ( ( uint8_t * ) data , len ) ;
2015-06-12 17:04:11 -04:00
std : : map < std : : string , SignatureEventData * > : : iterator it = _deferred_signature_queue . find ( chksum . toStdString ( ) ) ;
signature_result = SELF_SIGNATURE_RESULT_PENDING ;
2013-03-01 18:00:43 -05:00
if ( it ! = _deferred_signature_queue . end ( ) )
2015-06-12 17:04:11 -04:00
{
signature_result = it - > second - > signature_result ;
if ( it - > second - > signature_result ! = SELF_SIGNATURE_RESULT_PENDING ) // found it. Copy the result, and remove from the queue.
{
// We should check for the exact data match, for the sake of being totally secure.
//
std : : cerr < < " Found into queue: returning it " < < std : : endl ;
memcpy ( sign , it - > second - > sign , * it - > second - > signlen ) ;
* signlen = * ( it - > second - > signlen ) ;
delete it - > second ;
_deferred_signature_queue . erase ( it ) ;
}
return true ; // already registered, but not done yet.
}
2013-03-01 18:00:43 -05:00
// Not found. Store in the queue and emit a signal.
//
std : : cerr < < " NotifyQt:: deferred signature event requeted. Pushing into queue " < < std : : endl ;
SignatureEventData * edta = new SignatureEventData ( data , len , * signlen ) ;
_deferred_signature_queue [ chksum . toStdString ( ) ] = edta ;
}
emit deferredSignatureHandlingRequested ( ) ;
2015-06-12 17:04:11 -04:00
return true ;
2013-03-01 18:00:43 -05:00
}
void NotifyQt : : handleSignatureEvent ( )
{
std : : cerr < < " NotifyQt:: performing a deferred signature in the main GUI thread. " < < std : : endl ;
2013-03-11 12:04:25 -04:00
static bool working = false ;
if ( ! working )
{
working = true ;
2013-03-01 18:00:43 -05:00
for ( std : : map < std : : string , SignatureEventData * > : : const_iterator it ( _deferred_signature_queue . begin ( ) ) ; it ! = _deferred_signature_queue . end ( ) ; + + it )
it - > second - > performSignature ( ) ;
2013-03-11 12:04:25 -04:00
working = false ;
}
2013-03-01 18:00:43 -05:00
}
2013-03-11 12:04:25 -04:00
2015-06-11 16:31:52 -04:00
bool NotifyQt : : askForPassword ( const std : : string & key_details , bool prev_is_bad , std : : string & password , bool & cancelled )
2009-12-28 17:40:45 -05:00
{
2010-04-19 17:50:03 -04:00
RsAutoUpdatePage : : lockAllEvents ( ) ;
2011-02-27 16:47:49 -05:00
QInputDialog dialog ;
2012-11-28 14:58:14 -05:00
dialog . setWindowTitle ( tr ( " PGP key passphrase " ) ) ;
2014-07-07 15:37:04 -04:00
dialog . setLabelText ( ( prev_is_bad ? QString ( " %1 \n \n " ) . arg ( tr ( " Wrong password ! " ) ) : QString ( ) ) + QString ( " %1: \n %2 " ) . arg ( tr ( " Please enter your PGP password for key " ) , QString : : fromUtf8 ( key_details . c_str ( ) ) ) ) ;
2011-02-27 16:47:49 -05:00
dialog . setTextEchoMode ( QLineEdit : : Password ) ;
2013-04-18 14:41:51 -04:00
dialog . setModal ( true ) ;
2011-02-27 16:47:49 -05:00
int ret = dialog . exec ( ) ;
2010-04-19 17:50:03 -04:00
2015-06-11 16:31:52 -04:00
cancelled = false ;
2010-04-19 17:50:03 -04:00
RsAutoUpdatePage : : unlockAllEvents ( ) ;
2015-06-11 16:31:52 -04:00
if ( ret = = QDialog : : Rejected ) {
password . clear ( ) ;
cancelled = true ;
return true ;
}
if ( ret = = QDialog : : Accepted ) {
2011-08-27 18:54:05 -04:00
password = dialog . textValue ( ) . toUtf8 ( ) . constData ( ) ;
2011-08-05 16:45:09 -04:00
return true ;
2015-06-11 16:31:52 -04:00
}
2011-02-27 16:47:49 -05:00
2011-08-05 16:45:09 -04:00
return false ;
2009-12-28 17:40:45 -05:00
}
2012-09-09 09:59:21 -04:00
bool NotifyQt : : askForPluginConfirmation ( const std : : string & plugin_file_name , const std : : string & plugin_file_hash )
{
RsAutoUpdatePage : : lockAllEvents ( ) ;
QMessageBox dialog ;
dialog . setWindowTitle ( tr ( " Unregistered plugin/executable " ) ) ;
QString text ;
text + = tr ( " RetroShare has detected an unregistered plugin. This happens in two cases:<UL><LI>Your RetroShare executable has changed.</LI><LI>The plugin has changed</LI></UL>Click on Yes to authorize this plugin, or No to deny it. You can change your mind later in Options -> Plugins, then restart. " ) ;
text + = " <UL> " ;
text + = " <LI>Hash: \t " + QString : : fromStdString ( plugin_file_hash ) + " </LI> " ;
text + = " <LI>File: \t " + QString : : fromStdString ( plugin_file_name ) + " </LI> " ;
text + = " </UL> " ;
dialog . setText ( text ) ;
2015-06-29 12:08:17 -04:00
dialog . setWindowIcon ( QIcon ( " :/icons/logo_128.png " ) ) ;
2012-09-09 09:59:21 -04:00
dialog . setStandardButtons ( QMessageBox : : Yes | QMessageBox : : No ) ;
int ret = dialog . exec ( ) ;
RsAutoUpdatePage : : unlockAllEvents ( ) ;
if ( ret = = QMessageBox : : Yes )
return true ;
else
return false ;
}
2009-12-28 17:40:45 -05:00
2010-11-05 18:46:40 -04:00
void NotifyQt : : notifyDiscInfoChanged ( )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2011-01-20 17:22:02 -05:00
# ifdef NOTIFY_DEBUG
2010-11-05 18:46:40 -04:00
std : : cerr < < " Notifyqt:: notified that discoveryInfo changed " < < std : : endl ;
2011-01-20 17:22:02 -05:00
# endif
2010-11-05 18:46:40 -04:00
emit discInfoChanged ( ) ;
}
2010-11-24 19:20:25 -05:00
void NotifyQt : : notifyDownloadComplete ( const std : : string & fileHash )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2011-01-20 17:22:02 -05:00
# ifdef NOTIFY_DEBUG
2010-11-24 19:20:25 -05:00
std : : cerr < < " Notifyqt::notifyDownloadComplete notified that a download is completed " < < std : : endl ;
2011-01-20 17:22:02 -05:00
# endif
2010-11-24 19:20:25 -05:00
emit downloadComplete ( QString : : fromStdString ( fileHash ) ) ;
}
void NotifyQt : : notifyDownloadCompleteCount ( uint32_t count )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2010-11-24 19:20:25 -05:00
std : : cerr < < " Notifyqt::notifyDownloadCompleteCount " < < count < < std : : endl ;
emit downloadCompleteCountChanged ( count ) ;
}
2010-05-21 16:49:48 -04:00
void NotifyQt : : notifyDiskFull ( uint32_t loc , uint32_t size_in_mb )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2010-05-21 16:49:48 -04:00
std : : cerr < < " Notifyqt:: notified that disk is full " < < std : : endl ;
emit diskFull ( loc , size_in_mb ) ;
}
2010-08-20 14:45:44 -04:00
/* peer has changed the state */
void NotifyQt : : notifyPeerStatusChanged ( const std : : string & peer_id , uint32_t state )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2012-02-24 20:48:56 -05:00
# ifdef NOTIFY_DEBUG
2010-08-20 14:45:44 -04:00
std : : cerr < < " Notifyqt:: notified that peer " < < peer_id < < " has changed the state to " < < state < < std : : endl ;
2012-02-24 20:48:56 -05:00
# endif
2010-08-20 14:45:44 -04:00
2012-02-24 20:48:56 -05:00
emit peerStatusChanged ( QString : : fromStdString ( peer_id ) , state ) ;
2010-08-20 14:45:44 -04:00
}
/* one or more peers has changed the states */
void NotifyQt : : notifyPeerStatusChangedSummary ( )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2011-10-11 19:29:38 -04:00
# ifdef NOTIFY_DEBUG
2010-08-20 14:45:44 -04:00
std : : cerr < < " Notifyqt:: notified that one peer has changed the state " < < std : : endl ;
2011-10-11 19:29:38 -04:00
# endif
2010-08-20 14:45:44 -04:00
emit peerStatusChangedSummary ( ) ;
}
2015-03-20 06:39:17 -04:00
void NotifyQt : : notifyGxsChange ( const RsGxsChanges & changes )
{
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
# ifdef NOTIFY_DEBUG
std : : cerr < < " Notifyqt:: notified that gxs has changes " < < std : : endl ;
# endif
emit gxsChange ( changes ) ;
}
2014-12-29 16:41:05 -05:00
# ifdef REMOVE
2012-02-11 19:58:47 -05:00
void NotifyQt : : notifyForumMsgReadSatusChanged ( const std : : string & forumId , const std : : string & msgId , uint32_t status )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2012-02-11 19:58:47 -05:00
emit forumMsgReadSatusChanged ( QString : : fromStdString ( forumId ) , QString : : fromStdString ( msgId ) , status ) ;
}
2010-10-06 20:17:42 -04:00
void NotifyQt : : notifyChannelMsgReadSatusChanged ( const std : : string & channelId , const std : : string & msgId , uint32_t status )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2012-02-11 19:58:47 -05:00
emit channelMsgReadSatusChanged ( QString : : fromStdString ( channelId ) , QString : : fromStdString ( msgId ) , status ) ;
2010-10-06 20:17:42 -04:00
}
2014-12-29 16:41:05 -05:00
# endif
2009-12-28 17:40:45 -05:00
void NotifyQt : : notifyOwnStatusMessageChanged ( )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2011-10-11 19:29:38 -04:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " Notifyqt:: notified that own avatar changed " < < std : : endl ;
2011-10-11 19:29:38 -04:00
# endif
2009-12-28 17:40:45 -05:00
emit ownStatusMessageChanged ( ) ;
}
void NotifyQt : : notifyPeerHasNewAvatar ( std : : string peer_id )
{
2012-05-15 16:32:36 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2011-10-11 19:29:38 -04:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " notifyQt: notification of new avatar. " < < std : : endl ;
2011-10-11 19:29:38 -04:00
# endif
2009-12-28 17:40:45 -05:00
emit peerHasNewAvatar ( QString : : fromStdString ( peer_id ) ) ;
}
2010-09-02 06:15:13 -04:00
void NotifyQt : : notifyCustomState ( const std : : string & peer_id , const std : : string & status_string )
2009-12-28 17:40:45 -05:00
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2011-10-11 19:29:38 -04:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " notifyQt: Received custom status string notification " < < std : : endl ;
2011-10-11 19:29:38 -04:00
# endif
emit peerHasNewCustomStateString ( QString : : fromStdString ( peer_id ) , QString : : fromUtf8 ( status_string . c_str ( ) ) ) ;
2009-12-28 17:40:45 -05:00
}
2013-03-18 19:19:37 -04:00
void NotifyQt : : notifyChatLobbyTimeShift ( int shift )
{
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
# ifdef NOTIFY_DEBUG
std : : cerr < < " notifyQt: Received chat lobby time shift message: shift = " < < shift < < std : : endl ;
# endif
emit chatLobbyTimeShift ( shift ) ;
}
2013-06-10 09:27:24 -04:00
void NotifyQt : : handleChatLobbyTimeShift ( int /*shift*/ )
2013-03-18 19:19:37 -04:00
{
2013-08-28 16:02:09 -04:00
return ; // we say nothing. The help dialog of lobbies explains this already.
2013-03-18 19:19:37 -04:00
static bool already = false ;
if ( ! already )
{
2013-03-19 15:37:26 -04:00
already = true ;
2015-06-12 04:27:26 -04:00
QString string = tr ( " For the chat lobbies to work properly, the time of your computer needs to be correct. Please check that this is the case (A possible time shift of several minutes was detected with your friends). " ) ;
2013-03-18 19:19:37 -04:00
QMessageBox : : warning ( NULL , tr ( " Please check your system clock. " ) , string ) ;
}
}
2012-01-06 17:17:08 -05:00
void NotifyQt : : notifyChatLobbyEvent ( uint64_t lobby_id , uint32_t event_type , const std : : string & nickname , const std : : string & str )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2012-01-06 17:17:08 -05:00
# ifdef NOTIFY_DEBUG
std : : cerr < < " notifyQt: Received chat lobby event message: lobby # " < < std : : hex < < lobby_id < < std : : dec < < " , event= " < < event_type < < " , str= \" " < < str < < " \" " < < std : : endl ;
# endif
emit chatLobbyEvent ( lobby_id , event_type , QString : : fromUtf8 ( nickname . c_str ( ) ) , QString : : fromUtf8 ( str . c_str ( ) ) ) ;
}
2014-12-29 16:41:05 -05:00
void NotifyQt : : notifyChatStatus ( const ChatId & chat_id , const std : : string & status_string )
2009-12-28 17:40:45 -05:00
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2011-10-11 19:29:38 -04:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " notifyQt: Received chat status string: " < < status_string < < std : : endl ;
2011-10-11 19:29:38 -04:00
# endif
2014-12-29 16:41:05 -05:00
emit chatStatusChanged ( chat_id , QString : : fromUtf8 ( status_string . c_str ( ) ) ) ;
2014-06-12 18:06:43 -04:00
}
2009-12-28 17:40:45 -05:00
void NotifyQt : : notifyTurtleSearchResult ( uint32_t search_id , const std : : list < TurtleFileInfo > & files )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2011-10-11 19:29:38 -04:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " in notify search result... " < < std : : endl ;
2011-10-11 19:29:38 -04:00
# endif
2009-12-28 17:40:45 -05:00
for ( std : : list < TurtleFileInfo > : : const_iterator it ( files . begin ( ) ) ; it ! = files . end ( ) ; + + it )
{
FileDetail det ;
det . rank = 0 ;
det . age = 0 ;
det . name = ( * it ) . name ;
det . hash = ( * it ) . hash ;
det . size = ( * it ) . size ;
2014-03-17 16:56:06 -04:00
det . id . clear ( ) ;
2009-12-28 17:40:45 -05:00
emit gotTurtleSearchResult ( search_id , det ) ;
}
}
2010-10-09 14:35:34 -04:00
void NotifyQt : : notifyHashingInfo ( uint32_t type , const std : : string & fileinfo )
{
QString info ;
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2010-10-09 14:35:34 -04:00
switch ( type ) {
case NOTIFY_HASHTYPE_EXAMINING_FILES :
info = tr ( " Examining shared files... " ) ;
break ;
case NOTIFY_HASHTYPE_FINISH :
break ;
case NOTIFY_HASHTYPE_HASH_FILE :
info = tr ( " Hashing file " ) + " " + QString : : fromUtf8 ( fileinfo . c_str ( ) ) ;
break ;
case NOTIFY_HASHTYPE_SAVE_FILE_INDEX :
info = tr ( " Saving file index... " ) ;
break ;
}
emit hashingInfoChanged ( info ) ;
2009-12-28 17:40:45 -05:00
}
2011-09-29 05:20:09 -04:00
void NotifyQt : : notifyHistoryChanged ( uint32_t msgId , int type )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2011-09-29 05:20:09 -04:00
emit historyChanged ( msgId , type ) ;
}
2009-12-28 17:40:45 -05:00
void NotifyQt : : notifyListChange ( int list , int type )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2009-12-28 17:40:45 -05:00
# ifdef NOTIFY_DEBUG
std : : cerr < < " NotifyQt::notifyListChange() " < < std : : endl ;
# endif
switch ( list )
{
case NOTIFY_LIST_NEIGHBOURS :
2010-02-08 11:42:26 -05:00
# ifdef NOTIFY_DEBUG
2011-08-21 18:28:19 -04:00
std : : cerr < < " received neighbours changed " < < std : : endl ;
2009-12-28 17:40:45 -05:00
# endif
2011-08-21 18:28:19 -04:00
emit neighboursChanged ( ) ;
2009-12-28 17:40:45 -05:00
break ;
case NOTIFY_LIST_FRIENDS :
2010-02-08 11:42:26 -05:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " received friends changed " < < std : : endl ;
# endif
emit friendsChanged ( ) ;
break ;
case NOTIFY_LIST_DIRLIST_LOCAL :
2010-02-08 11:42:26 -05:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " received files changed " < < std : : endl ;
# endif
emit filesPostModChanged ( true ) ; /* Local */
break ;
2011-11-28 17:36:13 -05:00
case NOTIFY_LIST_CHAT_LOBBY_INVITATION :
# ifdef NOTIFY_DEBUG
std : : cerr < < " received files changed " < < std : : endl ;
# endif
emit chatLobbyInviteReceived ( ) ; /* Local */
break ;
2009-12-28 17:40:45 -05:00
case NOTIFY_LIST_DIRLIST_FRIENDS :
2010-02-08 11:42:26 -05:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " received files changed " < < std : : endl ;
# endif
emit filesPostModChanged ( false ) ; /* Local */
break ;
case NOTIFY_LIST_SEARCHLIST :
break ;
case NOTIFY_LIST_MESSAGELIST :
2010-02-08 11:42:26 -05:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " received msg changed " < < std : : endl ;
# endif
emit messagesChanged ( ) ;
break ;
2010-08-22 18:12:26 -04:00
case NOTIFY_LIST_MESSAGE_TAGS :
# ifdef NOTIFY_DEBUG
std : : cerr < < " received msg tags changed " < < std : : endl ;
# endif
emit messagesTagsChanged ( ) ;
break ;
2009-12-28 17:40:45 -05:00
case NOTIFY_LIST_CHANNELLIST :
break ;
case NOTIFY_LIST_TRANSFERLIST :
2010-02-08 11:42:26 -05:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " received transfer changed " < < std : : endl ;
# endif
emit transfersChanged ( ) ;
break ;
case NOTIFY_LIST_CONFIG :
2010-02-08 11:42:26 -05:00
# ifdef NOTIFY_DEBUG
2009-12-28 17:40:45 -05:00
std : : cerr < < " received config changed " < < std : : endl ;
# endif
emit configChanged ( ) ;
break ;
2014-12-29 16:41:05 -05:00
# ifdef REMOVE
2010-08-09 17:20:34 -04:00
case NOTIFY_LIST_FORUMLIST_LOCKED :
# ifdef NOTIFY_DEBUG
std : : cerr < < " received forum msg changed " < < std : : endl ;
# endif
emit forumsChanged ( ) ; // use connect with Qt::QueuedConnection
break ;
2010-10-06 20:17:42 -04:00
case NOTIFY_LIST_CHANNELLIST_LOCKED :
# ifdef NOTIFY_DEBUG
std : : cerr < < " received channel msg changed " < < std : : endl ;
# endif
emit channelsChanged ( type ) ; // use connect with Qt::QueuedConnection
break ;
2010-09-01 13:56:15 -04:00
case NOTIFY_LIST_PUBLIC_CHAT :
2010-08-31 13:13:52 -04:00
# ifdef NOTIFY_DEBUG
2010-09-01 13:56:15 -04:00
std : : cerr < < " received public chat changed " < < std : : endl ;
2010-08-31 13:13:52 -04:00
# endif
2010-09-01 13:56:15 -04:00
emit publicChatChanged ( type ) ;
break ;
2010-09-20 20:08:06 -04:00
case NOTIFY_LIST_PRIVATE_INCOMING_CHAT :
case NOTIFY_LIST_PRIVATE_OUTGOING_CHAT :
2010-09-01 13:56:15 -04:00
# ifdef NOTIFY_DEBUG
std : : cerr < < " received private chat changed " < < std : : endl ;
# endif
2010-09-20 20:08:06 -04:00
emit privateChatChanged ( list , type ) ;
2010-08-31 13:13:52 -04:00
break ;
2014-12-29 16:41:05 -05:00
# endif
2012-01-11 19:13:25 -05:00
case NOTIFY_LIST_CHAT_LOBBY_LIST :
2012-01-28 08:20:01 -05:00
# ifdef NOTIFY_DEBUG
2012-01-11 19:13:25 -05:00
std : : cerr < < " received notify chat lobby list " < < std : : endl ;
2012-01-28 08:20:01 -05:00
# endif
2012-01-11 19:13:25 -05:00
emit lobbyListChanged ( ) ;
2013-06-21 08:25:27 -04:00
break ;
2012-01-07 08:33:30 -05:00
2010-09-22 18:37:57 -04:00
case NOTIFY_LIST_GROUPLIST :
# ifdef NOTIFY_DEBUG
std : : cerr < < " received groups changed " < < std : : endl ;
# endif
emit groupsChanged ( type ) ;
break ;
2009-12-28 17:40:45 -05:00
default :
break ;
}
return ;
}
2011-08-12 10:06:29 -04:00
void NotifyQt : : notifyListPreChange ( int list , int /*type*/ )
2009-12-28 17:40:45 -05:00
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2009-12-28 17:40:45 -05:00
# ifdef NOTIFY_DEBUG
std : : cerr < < " NotifyQt::notifyListPreChange() " < < std : : endl ;
# endif
switch ( list )
{
case NOTIFY_LIST_NEIGHBOURS :
break ;
case NOTIFY_LIST_FRIENDS :
emit friendsChanged ( ) ;
break ;
case NOTIFY_LIST_DIRLIST_FRIENDS :
emit filesPreModChanged ( false ) ; /* remote */
break ;
case NOTIFY_LIST_DIRLIST_LOCAL :
emit filesPreModChanged ( true ) ; /* local */
break ;
case NOTIFY_LIST_SEARCHLIST :
break ;
case NOTIFY_LIST_MESSAGELIST :
break ;
case NOTIFY_LIST_CHANNELLIST :
break ;
case NOTIFY_LIST_TRANSFERLIST :
break ;
default :
break ;
}
return ;
}
/* New Timer Based Update scheme ...
* means correct thread seperation
*
2014-05-10 14:32:48 -04:00
* uses Flags , to detect changes
2009-12-28 17:40:45 -05:00
*/
2012-05-15 16:25:53 -04:00
void NotifyQt : : enable ( )
{
QMutexLocker m ( & _mutex ) ;
std : : cerr < < " Enabling notification system " < < std : : endl ;
_enabled = true ;
}
2009-12-28 17:40:45 -05:00
void NotifyQt : : UpdateGUI ( )
{
2013-07-02 15:55:13 -04:00
if ( RsAutoUpdatePage : : eventsLocked ( ) )
return ;
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2009-12-28 17:40:45 -05:00
static bool already_updated = false ; // these only update once at start because they may already have been set before
// the gui is running, then they get updated by callbacks.
if ( ! already_updated )
{
emit messagesChanged ( ) ;
2011-08-21 18:28:19 -04:00
emit neighboursChanged ( ) ;
2009-12-28 17:40:45 -05:00
emit configChanged ( ) ;
already_updated = true ;
}
/* Finally Check for PopupMessages / System Error Messages */
if ( rsNotify )
{
uint32_t sysid ;
uint32_t type ;
2014-03-17 16:56:06 -04:00
std : : string title , id , msg ;
2010-11-24 19:20:25 -05:00
2015-05-26 11:19:57 -04:00
/* You can set timeToShow, timeToLive and timeToHide or can leave the standard */
ToasterItem * toaster = NULL ;
2010-06-13 17:02:29 -04:00
if ( rsNotify - > NotifyPopupMessage ( type , id , title , msg ) )
2009-12-28 17:40:45 -05:00
{
2010-05-20 17:53:27 -04:00
uint popupflags = Settings - > getNotifyFlags ( ) ;
2009-12-28 17:40:45 -05:00
switch ( type )
{
2013-08-31 09:12:26 -04:00
case RS_POPUP_ENCRYPTED_MSG :
2015-06-07 13:35:58 -04:00
SoundManager : : play ( SOUND_MESSAGE_ARRIVED ) ;
2013-08-31 09:12:26 -04:00
2014-05-10 14:32:48 -04:00
if ( ( popupflags & RS_POPUP_MSG ) & & ! _disableAllToaster )
2013-08-31 09:12:26 -04:00
{
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new MessageToaster ( " " , tr ( " Encrypted message " ) , QString ( " [%1] " ) . arg ( tr ( " Encrypted message " ) ) ) ) ;
2013-08-31 09:12:26 -04:00
}
break ;
2009-12-28 17:40:45 -05:00
case RS_POPUP_MSG :
2015-06-07 13:35:58 -04:00
SoundManager : : play ( SOUND_MESSAGE_ARRIVED ) ;
2012-10-23 16:54:07 -04:00
2014-05-10 14:32:48 -04:00
if ( ( popupflags & RS_POPUP_MSG ) & & ! _disableAllToaster )
2010-12-05 17:27:50 -05:00
{
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new MessageToaster ( id , QString : : fromUtf8 ( title . c_str ( ) ) , QString : : fromUtf8 ( msg . c_str ( ) ) ) ) ;
2010-12-05 17:27:50 -05:00
}
2010-12-07 19:14:12 -05:00
break ;
case RS_POPUP_CONNECT :
2015-06-07 13:35:58 -04:00
SoundManager : : play ( SOUND_USER_ONLINE ) ;
2012-01-22 17:58:23 -05:00
2014-05-10 14:32:48 -04:00
if ( ( popupflags & RS_POPUP_CONNECT ) & & ! _disableAllToaster )
2010-12-05 17:27:50 -05:00
{
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new OnlineToaster ( RsPeerId ( id ) ) ) ;
2010-12-05 17:27:50 -05:00
}
2009-12-28 17:40:45 -05:00
break ;
2010-11-24 19:20:25 -05:00
case RS_POPUP_DOWNLOAD :
2015-06-07 13:35:58 -04:00
SoundManager : : play ( SOUND_DOWNLOAD_COMPLETE ) ;
2012-10-23 16:54:07 -04:00
2014-05-10 14:32:48 -04:00
if ( ( popupflags & RS_POPUP_DOWNLOAD ) & & ! _disableAllToaster )
2010-11-24 19:20:25 -05:00
{
2012-03-30 19:02:52 -04:00
/* id = file hash */
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new DownloadToaster ( RsFileHash ( id ) , QString : : fromUtf8 ( title . c_str ( ) ) ) ) ;
2010-11-24 19:20:25 -05:00
}
break ;
2012-03-30 19:02:52 -04:00
case RS_POPUP_CHAT :
2014-05-10 14:32:48 -04:00
if ( ( popupflags & RS_POPUP_CHAT ) & & ! _disableAllToaster )
2012-03-30 19:02:52 -04:00
{
2014-12-29 16:41:05 -05:00
// TODO: fix for distant chat, look up if dstant chat uses RS_POPUP_CHAT
ChatDialog * chatDialog = ChatDialog : : getChat ( ChatId ( RsPeerId ( id ) ) ) ;
2012-03-30 19:02:52 -04:00
ChatWidget * chatWidget ;
if ( chatDialog & & ( chatWidget = chatDialog - > getChatWidget ( ) ) & & chatWidget - > isActive ( ) ) {
// do not show when active
break ;
}
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new ChatToaster ( RsPeerId ( id ) , QString : : fromUtf8 ( msg . c_str ( ) ) ) ) ;
2012-03-30 19:02:52 -04:00
}
break ;
case RS_POPUP_GROUPCHAT :
2014-05-10 14:32:48 -04:00
if ( ( popupflags & RS_POPUP_GROUPCHAT ) & & ! _disableAllToaster )
2012-03-30 19:02:52 -04:00
{
MainWindow * mainWindow = MainWindow : : getInstance ( ) ;
if ( mainWindow & & mainWindow - > isActiveWindow ( ) & & ! mainWindow - > isMinimized ( ) ) {
if ( MainWindow : : getActivatePage ( ) = = MainWindow : : Friends ) {
if ( FriendsDialog : : isGroupChatActive ( ) ) {
// do not show when active
break ;
}
}
}
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new GroupChatToaster ( RsPeerId ( id ) , QString : : fromUtf8 ( msg . c_str ( ) ) ) ) ;
2012-03-30 19:02:52 -04:00
}
break ;
case RS_POPUP_CHATLOBBY :
2014-05-10 14:32:48 -04:00
if ( ( popupflags & RS_POPUP_CHATLOBBY ) & & ! _disableAllToaster )
2012-03-30 19:02:52 -04:00
{
2014-12-29 16:41:05 -05:00
if ( RsPeerId : : SIZE_IN_BYTES < sizeof ( ChatLobbyId ) )
{
std : : cerr < < " NotifyQt::UpdateGUI() Error: ChatLobbyId does not fit into a RsPeerId, this should not happen! " < < std : : endl ;
break ;
}
RsPeerId vpid ( id ) ; // create virtual peer id
ChatLobbyId lobby_id ;
// copy first bytes of virtual peer id, to make a chat lobby id
memcpy ( & lobby_id , vpid . toByteArray ( ) , sizeof ( ChatLobbyId ) ) ;
ChatDialog * chatDialog = ChatDialog : : getChat ( ChatId ( lobby_id ) ) ;
ChatWidget * chatWidget ;
if ( chatDialog & & ( chatWidget = chatDialog - > getChatWidget ( ) ) & & chatWidget - > isActive ( ) ) {
// do not show when active
break ;
}
ChatLobbyDialog * chatLobbyDialog = dynamic_cast < ChatLobbyDialog * > ( chatDialog ) ;
2015-03-06 16:13:23 -05:00
if ( ! chatLobbyDialog | | chatLobbyDialog - > isParticipantMuted ( RsGxsId ( title ) ) )
break ; // participant is muted
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new ChatLobbyToaster ( lobby_id , QString : : fromUtf8 ( title . c_str ( ) ) , QString : : fromUtf8 ( msg . c_str ( ) ) ) ) ;
2012-03-30 19:02:52 -04:00
}
break ;
2012-09-04 16:04:49 -04:00
case RS_POPUP_CONNECT_ATTEMPT :
2014-05-10 14:32:48 -04:00
if ( ( popupflags & RS_POPUP_CONNECT_ATTEMPT ) & & ! _disableAllToaster )
2012-04-25 15:19:16 -04:00
{
// id = gpgid
// title = ssl name
// msg = peer id
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new FriendRequestToaster ( RsPgpId ( id ) , QString : : fromUtf8 ( title . c_str ( ) ) , RsPeerId ( msg ) ) ) ;
2012-04-25 15:19:16 -04:00
}
break ;
2009-12-28 17:40:45 -05:00
}
2015-05-26 11:19:57 -04:00
}
2010-12-05 17:27:50 -05:00
2015-05-26 11:19:57 -04:00
/*Now check Plugins*/
if ( ! toaster ) {
int pluginCount = rsPlugins - > nbPlugins ( ) ;
for ( int i = 0 ; i < pluginCount ; + + i ) {
RsPlugin * rsPlugin = rsPlugins - > plugin ( i ) ;
if ( rsPlugin ) {
ToasterNotify * toasterNotify = rsPlugin - > qt_toasterNotify ( ) ;
if ( toasterNotify ) {
toaster = toasterNotify - > toasterItem ( ) ;
continue ;
}
}
2010-12-07 19:14:12 -05:00
}
2009-12-28 17:40:45 -05:00
}
2015-05-26 11:19:57 -04:00
if ( toaster ) {
/* init attributes */
toaster - > widget - > setWindowFlags ( Qt : : ToolTip | Qt : : WindowStaysOnTopHint ) ;
/* add toaster to waiting list */
//QMutexLocker lock(&waitingToasterMutex);
waitingToasterList . push_back ( toaster ) ;
}
2009-12-28 17:40:45 -05:00
if ( rsNotify - > NotifySysMessage ( sysid , type , title , msg ) )
{
/* make a warning message */
switch ( type )
{
case RS_SYS_ERROR :
2010-12-21 16:13:08 -05:00
QMessageBox : : critical ( MainWindow : : getInstance ( ) ,
2012-05-06 07:48:02 -04:00
QString : : fromUtf8 ( title . c_str ( ) ) ,
QString : : fromUtf8 ( msg . c_str ( ) ) ) ;
2009-12-28 17:40:45 -05:00
break ;
case RS_SYS_WARNING :
2010-12-21 16:13:08 -05:00
QMessageBox : : warning ( MainWindow : : getInstance ( ) ,
2012-05-06 07:48:02 -04:00
QString : : fromUtf8 ( title . c_str ( ) ) ,
QString : : fromUtf8 ( msg . c_str ( ) ) ) ;
2009-12-28 17:40:45 -05:00
break ;
default :
case RS_SYS_INFO :
2010-12-21 16:13:08 -05:00
QMessageBox : : information ( MainWindow : : getInstance ( ) ,
2012-05-06 07:48:02 -04:00
QString : : fromUtf8 ( title . c_str ( ) ) ,
QString : : fromUtf8 ( msg . c_str ( ) ) ) ;
2009-12-28 17:40:45 -05:00
break ;
}
}
2010-12-07 19:14:12 -05:00
2009-12-28 17:40:45 -05:00
if ( rsNotify - > NotifyLogMessage ( sysid , type , title , msg ) )
{
/* make a log message */
std : : string logMesString = title + " " + msg ;
switch ( type )
{
case RS_SYS_ERROR :
case RS_SYS_WARNING :
2012-05-06 07:48:02 -04:00
case RS_SYS_INFO :
emit logInfoChanged ( QString : : fromUtf8 ( logMesString . c_str ( ) ) ) ;
2009-12-28 17:40:45 -05:00
}
}
}
2010-12-07 19:14:12 -05:00
/* Now start the waiting toasters */
startWaitingToasters ( ) ;
2009-12-28 17:40:45 -05:00
}
2012-09-04 16:04:49 -04:00
2015-05-26 11:19:57 -04:00
void NotifyQt : : testToasters ( uint notifyFlags , /*RshareSettings::enumToasterPosition*/ int position , QPoint margin )
2012-09-04 16:04:49 -04:00
{
QString title = tr ( " Test " ) ;
QString message = tr ( " This is a test. " ) ;
2014-03-17 16:56:06 -04:00
RsPeerId id = rsPeers - > getOwnId ( ) ;
RsPgpId pgpid = rsPeers - > getGPGOwnId ( ) ;
2012-09-04 16:04:49 -04:00
uint pos = 0 ;
while ( notifyFlags ) {
uint type = notifyFlags & ( 1 < < pos ) ;
notifyFlags & = ~ ( 1 < < pos ) ;
+ + pos ;
2015-05-26 11:19:57 -04:00
ToasterItem * toaster = NULL ;
2012-09-04 16:04:49 -04:00
switch ( type )
{
2013-08-31 09:12:26 -04:00
case RS_POPUP_ENCRYPTED_MSG :
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new MessageToaster ( std : : string ( ) , tr ( " Unknown title " ) , QString ( " [%1] " ) . arg ( tr ( " Encrypted message " ) ) ) ) ;
2013-08-31 09:12:26 -04:00
break ;
2012-09-04 16:04:49 -04:00
case RS_POPUP_MSG :
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new MessageToaster ( id . toStdString ( ) , title , message ) ) ;
2012-09-04 16:04:49 -04:00
break ;
case RS_POPUP_CONNECT :
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new OnlineToaster ( id ) ) ;
2012-09-04 16:04:49 -04:00
break ;
case RS_POPUP_DOWNLOAD :
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new DownloadToaster ( RsFileHash : : random ( ) , title ) ) ;
2012-09-04 16:04:49 -04:00
break ;
case RS_POPUP_CHAT :
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new ChatToaster ( id , message ) ) ;
2012-09-04 16:04:49 -04:00
break ;
case RS_POPUP_GROUPCHAT :
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new GroupChatToaster ( id , message ) ) ;
2012-09-04 16:04:49 -04:00
break ;
case RS_POPUP_CHATLOBBY :
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new ChatLobbyToaster ( 0 , title , message ) ) ;
2012-09-04 16:04:49 -04:00
break ;
case RS_POPUP_CONNECT_ATTEMPT :
2015-05-26 11:19:57 -04:00
toaster = new ToasterItem ( new FriendRequestToaster ( pgpid , title , id ) ) ;
2012-09-04 16:04:49 -04:00
break ;
}
if ( toaster ) {
/* init attributes */
toaster - > widget - > setWindowFlags ( Qt : : ToolTip | Qt : : WindowStaysOnTopHint ) ;
toaster - > position = ( RshareSettings : : enumToasterPosition ) position ;
toaster - > margin = margin ;
/* add toaster to waiting list */
2014-05-10 14:32:48 -04:00
//QMutexLocker lock(&waitingToasterMutex);
2012-09-04 16:04:49 -04:00
waitingToasterList . push_back ( toaster ) ;
}
}
}
2015-05-26 11:19:57 -04:00
void NotifyQt : : testToaster ( ToasterNotify * toasterNotify , /*RshareSettings::enumToasterPosition*/ int position , QPoint margin )
{
if ( ! toasterNotify ) {
return ;
}
ToasterItem * toaster = toasterNotify - > testToasterItem ( ) ;
if ( toaster ) {
/* init attributes */
toaster - > widget - > setWindowFlags ( Qt : : ToolTip | Qt : : WindowStaysOnTopHint ) ;
toaster - > position = ( RshareSettings : : enumToasterPosition ) position ;
toaster - > margin = margin ;
/* add toaster to waiting list */
//QMutexLocker lock(&waitingToasterMutex);
waitingToasterList . push_back ( toaster ) ;
}
}
void NotifyQt : : testToaster ( QString tag , ToasterNotify * toasterNotify , /*RshareSettings::enumToasterPosition*/ int position , QPoint margin )
{
if ( ! toasterNotify ) {
return ;
}
ToasterItem * toaster = toasterNotify - > testToasterItem ( tag ) ;
if ( toaster ) {
/* init attributes */
toaster - > widget - > setWindowFlags ( Qt : : ToolTip | Qt : : WindowStaysOnTopHint ) ;
toaster - > position = ( RshareSettings : : enumToasterPosition ) position ;
toaster - > margin = margin ;
/* add toaster to waiting list */
//QMutexLocker lock(&waitingToasterMutex);
waitingToasterList . push_back ( toaster ) ;
}
}
2015-01-08 14:12:47 -05:00
void NotifyQt : : notifyChatFontChanged ( )
{
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
emit chatFontChanged ( ) ;
}
2010-09-07 11:49:31 -04:00
void NotifyQt : : notifyChatStyleChanged ( int /*ChatStyle::enumStyleType*/ styleType )
{
2012-05-15 16:25:53 -04:00
{
QMutexLocker m ( & _mutex ) ;
if ( ! _enabled )
return ;
}
2010-09-07 11:49:31 -04:00
emit chatStyleChanged ( styleType ) ;
}
2010-12-07 19:14:12 -05:00
2013-01-05 21:30:10 -05:00
void NotifyQt : : notifySettingsChanged ( )
{
emit settingsChanged ( ) ;
}
2010-12-07 19:14:12 -05:00
void NotifyQt : : startWaitingToasters ( )
{
{
2014-05-10 14:32:48 -04:00
//QMutexLocker lock(&waitingToasterMutex);
2010-12-07 19:14:12 -05:00
if ( waitingToasterList . empty ( ) ) {
/* No toasters are waiting */
return ;
}
}
{
2014-05-10 14:32:48 -04:00
//QMutexLocker lock(&runningToasterMutex);
2010-12-07 19:14:12 -05:00
if ( runningToasterList . size ( ) > = 3 ) {
/* Don't show more than 3 toasters at once */
return ;
}
}
2015-05-26 11:19:57 -04:00
ToasterItem * toaster = NULL ;
2010-12-07 19:14:12 -05:00
{
2014-05-10 14:32:48 -04:00
//QMutexLocker lock(&waitingToasterMutex);
2010-12-07 19:14:12 -05:00
if ( waitingToasterList . size ( ) ) {
/* Take one toaster of the waiting list */
toaster = waitingToasterList . front ( ) ;
waitingToasterList . pop_front ( ) ;
}
}
if ( toaster ) {
2014-05-10 14:32:48 -04:00
//QMutexLocker lock(&runningToasterMutex);
2010-12-07 19:14:12 -05:00
/* Calculate positions */
QSize size = toaster - > widget - > size ( ) ;
QDesktopWidget * desktop = QApplication : : desktop ( ) ;
QRect desktopGeometry = desktop - > availableGeometry ( desktop - > primaryScreen ( ) ) ;
2012-09-04 16:04:49 -04:00
switch ( toaster - > position ) {
2010-12-10 16:49:38 -05:00
case RshareSettings : : TOASTERPOS_TOPLEFT :
2012-09-04 16:04:49 -04:00
toaster - > startPos = QPoint ( desktopGeometry . left ( ) + toaster - > margin . x ( ) , desktopGeometry . top ( ) - size . height ( ) ) ;
toaster - > endPos = QPoint ( toaster - > startPos . x ( ) , desktopGeometry . top ( ) + toaster - > margin . y ( ) ) ;
2010-12-10 16:49:38 -05:00
break ;
case RshareSettings : : TOASTERPOS_TOPRIGHT :
2012-09-04 16:04:49 -04:00
toaster - > startPos = QPoint ( desktopGeometry . right ( ) - size . width ( ) - toaster - > margin . x ( ) , desktopGeometry . top ( ) - size . height ( ) ) ;
toaster - > endPos = QPoint ( toaster - > startPos . x ( ) , desktopGeometry . top ( ) + toaster - > margin . y ( ) ) ;
2010-12-10 16:49:38 -05:00
break ;
case RshareSettings : : TOASTERPOS_BOTTOMLEFT :
2012-09-04 16:04:49 -04:00
toaster - > startPos = QPoint ( desktopGeometry . left ( ) + toaster - > margin . x ( ) , desktopGeometry . bottom ( ) ) ;
toaster - > endPos = QPoint ( toaster - > startPos . x ( ) , desktopGeometry . bottom ( ) - size . height ( ) - toaster - > margin . y ( ) ) ;
2010-12-10 16:49:38 -05:00
break ;
case RshareSettings : : TOASTERPOS_BOTTOMRIGHT : // default
default :
2012-09-04 16:04:49 -04:00
toaster - > startPos = QPoint ( desktopGeometry . right ( ) - size . width ( ) - toaster - > margin . x ( ) , desktopGeometry . bottom ( ) ) ;
toaster - > endPos = QPoint ( toaster - > startPos . x ( ) , desktopGeometry . bottom ( ) - size . height ( ) - toaster - > margin . y ( ) ) ;
2010-12-10 16:49:38 -05:00
break ;
}
2010-12-07 19:14:12 -05:00
/* Initialize widget */
toaster - > widget - > move ( toaster - > startPos ) ;
/* Initialize toaster */
toaster - > elapsedTimeToShow = 0 ;
toaster - > elapsedTimeToLive = 0 ;
toaster - > elapsedTimeToHide = 0 ;
/* Add toaster to the running list */
runningToasterList . push_front ( toaster ) ;
if ( runningToasterTimer - > isActive ( ) = = false ) {
/* Start the toaster timer */
runningToasterTimer - > start ( ) ;
}
}
}
void NotifyQt : : runningTick ( )
{
2014-05-10 14:32:48 -04:00
//QMutexLocker lock(&runningToasterMutex);
2010-12-07 19:14:12 -05:00
int interval = runningToasterTimer - > interval ( ) ;
QPoint diff ;
2015-05-26 11:19:57 -04:00
QList < ToasterItem * > : : iterator it = runningToasterList . begin ( ) ;
2010-12-07 19:14:12 -05:00
while ( it ! = runningToasterList . end ( ) ) {
2015-05-26 11:19:57 -04:00
ToasterItem * toaster = * it ;
2010-12-07 19:14:12 -05:00
2010-12-09 15:16:05 -05:00
bool visible = true ;
if ( toaster - > elapsedTimeToShow ) {
/* Toaster is started, check for visible */
visible = toaster - > widget - > isVisible ( ) ;
}
QPoint newPos ;
enum { NOTHING , SHOW , HIDE } operation = NOTHING ;
2010-12-07 19:14:12 -05:00
if ( visible & & toaster - > elapsedTimeToShow < = toaster - > timeToShow ) {
/* Toaster is showing */
2010-12-09 15:16:05 -05:00
if ( toaster - > elapsedTimeToShow = = 0 ) {
/* Toaster is not visible, show it now */
operation = SHOW ;
}
2010-12-07 19:14:12 -05:00
2010-12-09 15:16:05 -05:00
toaster - > elapsedTimeToShow + = interval ;
2010-12-07 19:14:12 -05:00
2010-12-09 15:16:05 -05:00
newPos = QPoint ( toaster - > startPos . x ( ) - ( toaster - > startPos . x ( ) - toaster - > endPos . x ( ) ) * toaster - > elapsedTimeToShow / toaster - > timeToShow ,
toaster - > startPos . y ( ) - ( toaster - > startPos . y ( ) - toaster - > endPos . y ( ) ) * toaster - > elapsedTimeToShow / toaster - > timeToShow ) ;
2010-12-07 19:14:12 -05:00
} else if ( visible & & toaster - > elapsedTimeToLive < = toaster - > timeToLive ) {
/* Toaster is living */
toaster - > elapsedTimeToLive + = interval ;
2010-12-09 15:16:05 -05:00
newPos = toaster - > endPos ;
2010-12-07 19:14:12 -05:00
} else if ( visible & & toaster - > elapsedTimeToHide < = toaster - > timeToHide ) {
/* Toaster is hiding */
toaster - > elapsedTimeToHide + = interval ;
2010-12-09 15:16:05 -05:00
if ( toaster - > elapsedTimeToHide = = toaster - > timeToHide ) {
/* Toaster is back at the start position, hide it */
operation = HIDE ;
}
2010-12-07 19:14:12 -05:00
2010-12-09 15:16:05 -05:00
newPos = QPoint ( toaster - > startPos . x ( ) - ( toaster - > startPos . x ( ) - toaster - > endPos . x ( ) ) * ( toaster - > timeToHide - toaster - > elapsedTimeToHide ) / toaster - > timeToHide ,
toaster - > startPos . y ( ) - ( toaster - > startPos . y ( ) - toaster - > endPos . y ( ) ) * ( toaster - > timeToHide - toaster - > elapsedTimeToHide ) / toaster - > timeToHide ) ;
2010-12-07 19:14:12 -05:00
} else {
/* Toaster is hidden, delete it */
it = runningToasterList . erase ( it ) ;
2015-05-26 11:19:57 -04:00
//delete(toaster->widget);
2010-12-07 19:14:12 -05:00
delete ( toaster ) ;
continue ;
}
2010-12-09 15:16:05 -05:00
toaster - > widget - > move ( newPos + diff ) ;
diff + = newPos - toaster - > startPos ;
2010-12-10 16:49:38 -05:00
QRect mask = QRect ( 0 , 0 , toaster - > widget - > width ( ) , qAbs ( toaster - > startPos . y ( ) - newPos . y ( ) ) ) ;
if ( newPos . y ( ) > toaster - > startPos . y ( ) ) {
/* Toaster is moving from top */
mask . moveTop ( toaster - > widget - > height ( ) - ( newPos . y ( ) - toaster - > startPos . y ( ) ) ) ;
}
toaster - > widget - > setMask ( QRegion ( mask ) ) ;
2010-12-09 15:16:05 -05:00
switch ( operation ) {
case NOTHING :
break ;
case SHOW :
toaster - > widget - > show ( ) ;
break ;
case HIDE :
toaster - > widget - > hide ( ) ;
break ;
}
2010-12-07 19:14:12 -05:00
+ + it ;
}
if ( runningToasterList . size ( ) ) {
/* There are more running toasters, start the timer again */
runningToasterTimer - > start ( ) ;
}
}