@ -30,34 +30,30 @@
@@ -30,34 +30,30 @@
* Contact : hammered999 @ gmail . com
*/
# include <QVBoxLayout>
# include <QHBoxLayout>
# include "shutdownconfirmdlg.h"
# include "ui_shutdownconfirmdlg.h"
# include <QStyle>
# include <QIcon>
# include <QLabel>
# include <QDialogButtonBox>
# include <QCheckBox>
# include <QPushButton>
# include "base/preferences.h"
# include "base/types .h"
# include "base/utils/misc .h"
# include "shutdownconfirm.h"
# include "ui_confirmshutdowndlg.h"
ShutdownConfirmDlg : : ShutdownConfirmDlg ( const ShutdownAction & action )
ShutdownConfirmDlg : : ShutdownConfirmDlg ( const ShutdownDialogAction & action )
: ui ( new Ui : : confirmShutdownDlg )
, m_timeout ( 15 )
, m_action ( action )
{
ui - > setupUi ( this ) ;
initText ( ) ;
QIcon warningIcon ( style ( ) - > standardIcon ( QStyle : : SP_MessageBoxWarning ) ) ;
ui - > warningLabel - > setPixmap ( warningIcon . pixmap ( 32 ) ) ;
updateText ( ) ;
if ( m_action = = ShutdownAction : : None )
if ( m_action = = ShutdownDialogAction : : Exit )
ui - > neverShowAgainCheckbox - > setVisible ( true ) ;
else
ui - > neverShowAgainCheckbox - > setVisible ( false ) ;
@ -66,12 +62,13 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
@@ -66,12 +62,13 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
QPushButton * cancelButton = ui - > buttonBox - > button ( QDialogButtonBox : : Cancel ) ;
cancelButton - > setFocus ( ) ;
cancelButton - > setDefault ( true ) ;
// Always on top
setWindowFlags ( windowFlags ( ) | Qt : : WindowStaysOnTopHint ) ;
move ( Utils : : Misc : : screenCenter ( this ) ) ;
m_timer . setInterval ( 1000 ) ; // 1sec
connect ( & m_timer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateSeconds ( ) ) ) ;
// Move to center
move ( Utils : : Misc : : screenCenter ( this ) ) ;
}
ShutdownConfirmDlg : : ~ ShutdownConfirmDlg ( )
@ -85,11 +82,10 @@ void ShutdownConfirmDlg::showEvent(QShowEvent *event)
@@ -85,11 +82,10 @@ void ShutdownConfirmDlg::showEvent(QShowEvent *event)
m_timer . start ( ) ;
}
bool ShutdownConfirmDlg : : askForConfirmation ( const ShutdownAction & action )
bool ShutdownConfirmDlg : : askForConfirmation ( const ShutdownDialog Action & action )
{
ShutdownConfirmDlg dlg ( action ) ;
dlg . exec ( ) ;
return dlg . shutdown ( ) ;
return ( dlg . exec ( ) = = QDialog : : Accepted ) ;
}
void ShutdownConfirmDlg : : updateSeconds ( )
@ -108,43 +104,43 @@ void ShutdownConfirmDlg::accept()
@@ -108,43 +104,43 @@ void ShutdownConfirmDlg::accept()
QDialog : : accept ( ) ;
}
bool ShutdownConfirmDlg : : shutdown ( ) const
{
return ( result ( ) = = QDialog : : Accepted ) ;
}
void ShutdownConfirmDlg : : updateText ( )
void ShutdownConfirmDlg : : initText ( )
{
QString text ;
QPushButton * okButton = ui - > buttonBox - > button ( QDialogButtonBox : : Ok ) ;
switch ( m_action ) {
case ShutdownAction : : None :
text = tr ( " qBittorrent will now exit. " ) ;
case ShutdownDialogAction : : Exit :
m_msg = tr ( " qBittorrent will now exit. " ) ;
okButton - > setText ( tr ( " E&xit Now " ) ) ;
setWindowTitle ( tr ( " Exit confirmation " ) ) ;
break ;
case ShutdownAction : : Shutdown :
text = tr ( " The computer is going to shutdown. " ) ;
case ShutdownDialog Action : : Shutdown :
m_msg = tr ( " The computer is going to shutdown. " ) ;
okButton - > setText ( tr ( " &Shutdown Now " ) ) ;
setWindowTitle ( tr ( " Shutdown confirmation " ) ) ;
break ;
case ShutdownAction : : Suspend :
text = tr ( " The computer is going to enter suspend mode. " ) ;
case ShutdownDialog Action : : Suspend :
m_msg = tr ( " The computer is going to enter suspend mode. " ) ;
okButton - > setText ( tr ( " &Suspend Now " ) ) ;
setWindowTitle ( tr ( " Suspend confirmation " ) ) ;
break ;
case ShutdownAction : : Hibernate :
text = tr ( " The computer is going to enter hibernation mode. " ) ;
case ShutdownDialog Action : : Hibernate :
m_msg = tr ( " The computer is going to enter hibernation mode. " ) ;
okButton - > setText ( tr ( " &Hibernate Now " ) ) ;
setWindowTitle ( tr ( " Hibernate confirmation " ) ) ;
break ;
}
text + = " \n " + tr ( " You can cancel the action within %1 seconds. " ) . arg ( QString : : number ( m_timeout ) ) + " \n " ;
ui - > shutdownText - > setText ( text ) ;
m_msg + = " \n " ;
updateText ( ) ;
}
void ShutdownConfirmDlg : : updateText ( )
{
QString t = tr ( " You can cancel the action within %1 seconds. " ) . arg ( QString : : number ( m_timeout ) ) + " \n " ;
ui - > shutdownText - > setText ( m_msg + t ) ;
}