2016-08-30 20:01:07 +02:00
# include "./traywidget.h"
# include "./traymenu.h"
2016-08-25 00:45:32 +02:00
# include "./settingsdialog.h"
# include "./webviewdialog.h"
# include "../application/settings.h"
# include "resources/config.h"
# include "ui_traywidget.h"
# include <qtutilities/resources/qtconfigarguments.h>
# include <qtutilities/resources/resources.h>
# include <qtutilities/settingsdialog/qtsettings.h>
# include <qtutilities/aboutdialog/aboutdialog.h>
# include <qtutilities/misc/dialogutils.h>
# include <qtutilities/misc/desktoputils.h>
2016-08-29 20:51:30 +02:00
# include <c++utilities/conversion/stringconversion.h>
2016-08-30 20:01:07 +02:00
# include <QCoreApplication>
2016-08-25 00:45:32 +02:00
# include <QDesktopServices>
# include <QMessageBox>
# include <QClipboard>
# include <QDir>
# include <QTextBrowser>
# include <QStringBuilder>
2016-09-03 19:39:43 +02:00
# include <QFontDatabase>
2016-08-25 00:45:32 +02:00
# include <functional>
using namespace ApplicationUtilities ;
2016-08-29 20:51:30 +02:00
using namespace ConversionUtilities ;
2016-08-25 00:45:32 +02:00
using namespace Dialogs ;
using namespace Data ;
using namespace std ;
namespace QtGui {
/*!
* \ brief Instantiates a new tray widget .
*/
TrayWidget : : TrayWidget ( TrayMenu * parent ) :
QWidget ( parent ) ,
m_menu ( parent ) ,
m_ui ( new Ui : : TrayWidget ) ,
m_settingsDlg ( nullptr ) ,
m_aboutDlg ( nullptr ) ,
# ifndef SYNCTHINGTRAY_NO_WEBVIEW
m_webViewDlg ( nullptr ) ,
# endif
m_dirModel ( m_connection ) ,
2016-09-03 20:14:52 +02:00
m_devModel ( m_connection ) ,
m_selectedConnection ( nullptr )
2016-08-25 00:45:32 +02:00
{
m_ui - > setupUi ( this ) ;
// setup model and view
m_ui - > dirsTreeView - > setModel ( & m_dirModel ) ;
m_ui - > devsTreeView - > setModel ( & m_devModel ) ;
// setup sync-all button
2016-09-03 19:39:43 +02:00
m_cornerFrame = new QFrame ( this ) ;
auto * cornerFrameLayout = new QHBoxLayout ( m_cornerFrame ) ;
2016-08-25 00:45:32 +02:00
cornerFrameLayout - > setSpacing ( 0 ) , cornerFrameLayout - > setMargin ( 0 ) ;
2016-09-03 19:39:43 +02:00
//cornerFrameLayout->addStretch();
m_cornerFrame - > setLayout ( cornerFrameLayout ) ;
auto * viewIdButton = new QPushButton ( m_cornerFrame ) ;
2016-08-25 00:45:32 +02:00
viewIdButton - > setToolTip ( tr ( " View own device ID " ) ) ;
2016-08-29 20:51:30 +02:00
viewIdButton - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " view-barcode " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/actions/view-barcode.svg " ) ) ) ) ;
2016-08-25 00:45:32 +02:00
viewIdButton - > setFlat ( true ) ;
cornerFrameLayout - > addWidget ( viewIdButton ) ;
2016-09-03 19:39:43 +02:00
auto * restartButton = new QPushButton ( m_cornerFrame ) ;
restartButton - > setToolTip ( tr ( " Restart Syncthing " ) ) ;
restartButton - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " system-reboot " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/actions/view-refresh.svg " ) ) ) ) ;
restartButton - > setFlat ( true ) ;
connect ( restartButton , & QPushButton : : clicked , & m_connection , & SyncthingConnection : : restart ) ;
cornerFrameLayout - > addWidget ( restartButton ) ;
auto * showLogButton = new QPushButton ( m_cornerFrame ) ;
2016-08-25 00:45:32 +02:00
showLogButton - > setToolTip ( tr ( " Show Syncthing log " ) ) ;
2016-09-03 19:39:43 +02:00
showLogButton - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " text-x-generic " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/mimetypes/text-x-generic.svg " ) ) ) ) ;
2016-08-25 00:45:32 +02:00
showLogButton - > setFlat ( true ) ;
connect ( showLogButton , & QPushButton : : clicked , this , & TrayWidget : : showLog ) ;
cornerFrameLayout - > addWidget ( showLogButton ) ;
2016-09-03 19:39:43 +02:00
auto * scanAllButton = new QPushButton ( m_cornerFrame ) ;
2016-08-25 00:45:32 +02:00
scanAllButton - > setToolTip ( tr ( " Rescan all directories " ) ) ;
2016-08-29 20:51:30 +02:00
scanAllButton - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " folder-sync " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/actions/folder-sync.svg " ) ) ) ) ;
2016-08-25 00:45:32 +02:00
scanAllButton - > setFlat ( true ) ;
cornerFrameLayout - > addWidget ( scanAllButton ) ;
2016-09-03 19:39:43 +02:00
m_ui - > tabWidget - > setCornerWidget ( m_cornerFrame , Qt : : BottomRightCorner ) ;
2016-09-03 20:14:52 +02:00
// setup connection menu
m_connectionsActionGroup = new QActionGroup ( m_connectionsMenu = new QMenu ( tr ( " Connection " ) , this ) ) ;
m_connectionsMenu - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " network-connect " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/actions/network-connect.svg " ) ) ) ) ;
connect ( m_ui - > connectionsPushButton , & QPushButton : : clicked , this , & TrayWidget : : showConnectionsMenu ) ;
2016-09-03 19:39:43 +02:00
// apply settings, this also establishes the connection to Syncthing
applySettings ( ) ;
2016-08-25 00:45:32 +02:00
2016-08-29 20:51:30 +02:00
m_ui - > trafficIconLabel - > setPixmap ( QIcon : : fromTheme ( QStringLiteral ( " network-card " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/devices/network-card.svg " ) ) ) . pixmap ( 32 ) ) ;
2016-08-25 00:45:32 +02:00
// connect signals and slots
2016-08-29 20:51:30 +02:00
connect ( m_ui - > statusPushButton , & QPushButton : : clicked , this , & TrayWidget : : changeStatus ) ;
2016-08-30 20:01:07 +02:00
connect ( m_ui - > closePushButton , & QPushButton : : clicked , & QCoreApplication : : quit ) ;
2016-08-25 00:45:32 +02:00
connect ( m_ui - > aboutPushButton , & QPushButton : : clicked , this , & TrayWidget : : showAboutDialog ) ;
connect ( m_ui - > webUiPushButton , & QPushButton : : clicked , this , & TrayWidget : : showWebUi ) ;
connect ( m_ui - > settingsPushButton , & QPushButton : : clicked , this , & TrayWidget : : showSettingsDialog ) ;
2016-09-06 22:55:49 +02:00
connect ( & m_connection , & SyncthingConnection : : statusChanged , this , & TrayWidget : : handleStatusChanged ) ;
2016-08-29 20:51:30 +02:00
connect ( & m_connection , & SyncthingConnection : : trafficChanged , this , & TrayWidget : : updateTraffic ) ;
2016-09-01 16:34:30 +02:00
connect ( & m_connection , & SyncthingConnection : : newNotification , this , & TrayWidget : : handleNewNotification ) ;
2016-08-25 00:45:32 +02:00
connect ( m_ui - > dirsTreeView , & DirView : : openDir , this , & TrayWidget : : openDir ) ;
connect ( m_ui - > dirsTreeView , & DirView : : scanDir , this , & TrayWidget : : scanDir ) ;
2016-08-26 16:43:53 +02:00
connect ( m_ui - > devsTreeView , & DevView : : pauseResumeDev , this , & TrayWidget : : pauseResumeDev ) ;
connect ( scanAllButton , & QPushButton : : clicked , & m_connection , & SyncthingConnection : : rescanAllDirs ) ;
connect ( viewIdButton , & QPushButton : : clicked , this , & TrayWidget : : showOwnDeviceId ) ;
2016-09-03 20:14:52 +02:00
connect ( m_connectionsActionGroup , & QActionGroup : : triggered , this , & TrayWidget : : handleConnectionSelected ) ;
2016-08-25 00:45:32 +02:00
}
TrayWidget : : ~ TrayWidget ( )
{ }
void TrayWidget : : showSettingsDialog ( )
{
if ( ! m_settingsDlg ) {
m_settingsDlg = new SettingsDialog ( & m_connection , this ) ;
connect ( m_settingsDlg , & SettingsDialog : : applied , this , & TrayWidget : : applySettings ) ;
}
m_settingsDlg - > show ( ) ;
centerWidget ( m_settingsDlg ) ;
if ( m_menu ) {
m_menu - > close ( ) ;
}
m_settingsDlg - > activateWindow ( ) ;
}
void TrayWidget : : showAboutDialog ( )
{
if ( ! m_aboutDlg ) {
2016-09-01 16:34:30 +02:00
m_aboutDlg = new AboutDialog ( this , QString ( ) , QStringLiteral ( APP_AUTHOR " \n fallback icons from KDE/Breeze project \n Syncthing icons from Syncthing project " ) , QString ( ) , QString ( ) , QStringLiteral ( APP_DESCRIPTION ) , QImage ( QStringLiteral ( " :/icons/hicolor/scalable/app/syncthingtray.svg " ) ) ) ;
m_aboutDlg - > setWindowTitle ( tr ( " About " ) + QStringLiteral ( " - " APP_NAME ) ) ;
2016-08-25 00:45:32 +02:00
m_aboutDlg - > setWindowIcon ( QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/app/syncthingtray.svg " ) ) ) ;
}
m_aboutDlg - > show ( ) ;
centerWidget ( m_aboutDlg ) ;
if ( m_menu ) {
m_menu - > close ( ) ;
}
m_aboutDlg - > activateWindow ( ) ;
}
void TrayWidget : : showWebUi ( )
{
# ifndef SYNCTHINGTRAY_NO_WEBVIEW
if ( Settings : : webViewDisabled ( ) ) {
# endif
2016-09-03 20:14:52 +02:00
QDesktopServices : : openUrl ( m_connection . syncthingUrl ( ) ) ;
2016-08-25 00:45:32 +02:00
# ifndef SYNCTHINGTRAY_NO_WEBVIEW
} else {
if ( ! m_webViewDlg ) {
m_webViewDlg = new WebViewDialog ( this ) ;
2016-09-03 20:14:52 +02:00
if ( m_selectedConnection ) {
m_webViewDlg - > applySettings ( * m_selectedConnection ) ;
2016-08-25 00:45:32 +02:00
}
2016-09-03 20:14:52 +02:00
connect ( m_webViewDlg , & WebViewDialog : : destroyed , this , & TrayWidget : : handleWebViewDeleted ) ;
2016-08-25 00:45:32 +02:00
}
m_webViewDlg - > show ( ) ;
if ( m_menu ) {
m_menu - > close ( ) ;
}
m_webViewDlg - > activateWindow ( ) ;
}
# endif
}
void TrayWidget : : showOwnDeviceId ( )
{
2016-09-03 19:39:43 +02:00
auto * dlg = new QWidget ( this , Qt : : Window ) ;
2016-09-01 16:34:30 +02:00
dlg - > setWindowTitle ( tr ( " Own device ID " ) + QStringLiteral ( " - " APP_NAME ) ) ;
2016-08-25 00:45:32 +02:00
dlg - > setWindowIcon ( QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/app/syncthingtray.svg " ) ) ) ;
dlg - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
dlg - > setBackgroundRole ( QPalette : : Background ) ;
auto * layout = new QVBoxLayout ( dlg ) ;
layout - > setAlignment ( Qt : : AlignCenter ) ;
auto * pixmapLabel = new QLabel ( dlg ) ;
pixmapLabel - > setAlignment ( Qt : : AlignCenter ) ;
layout - > addWidget ( pixmapLabel ) ;
auto * textLabel = new QLabel ( dlg ) ;
textLabel - > setText ( m_connection . myId ( ) . isEmpty ( ) ? tr ( " device ID is unknown " ) : m_connection . myId ( ) ) ;
QFont defaultFont = textLabel - > font ( ) ;
defaultFont . setBold ( true ) ;
defaultFont . setPointSize ( defaultFont . pointSize ( ) + 2 ) ;
textLabel - > setFont ( defaultFont ) ;
textLabel - > setAlignment ( Qt : : AlignCenter ) ;
layout - > addWidget ( textLabel ) ;
auto * copyPushButton = new QPushButton ( dlg ) ;
copyPushButton - > setText ( tr ( " Copy to clipboard " ) ) ;
connect ( copyPushButton , & QPushButton : : clicked , bind ( & QClipboard : : setText , QGuiApplication : : clipboard ( ) , m_connection . myId ( ) , QClipboard : : Clipboard ) ) ;
layout - > addWidget ( copyPushButton ) ;
2016-09-03 19:39:43 +02:00
connect ( dlg , & QWidget : : destroyed ,
bind ( static_cast < bool ( * ) ( const QMetaObject : : Connection & ) > ( & QObject : : disconnect ) ,
m_connection . requestQrCode ( m_connection . myId ( ) , bind ( & QLabel : : setPixmap , pixmapLabel , placeholders : : _1 ) )
) ) ;
2016-08-25 00:45:32 +02:00
dlg - > setLayout ( layout ) ;
dlg - > show ( ) ;
centerWidget ( dlg ) ;
if ( m_menu ) {
m_menu - > close ( ) ;
}
dlg - > activateWindow ( ) ;
}
void TrayWidget : : showLog ( )
{
2016-09-03 19:39:43 +02:00
auto * dlg = new QWidget ( this , Qt : : Window ) ;
2016-09-01 16:34:30 +02:00
dlg - > setWindowTitle ( tr ( " Log " ) + QStringLiteral ( " - " APP_NAME ) ) ;
2016-08-25 00:45:32 +02:00
dlg - > setWindowIcon ( QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/app/syncthingtray.svg " ) ) ) ;
dlg - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
auto * layout = new QVBoxLayout ( dlg ) ;
layout - > setAlignment ( Qt : : AlignCenter ) ;
auto * browser = new QTextBrowser ( dlg ) ;
2016-09-03 19:39:43 +02:00
connect ( dlg , & QWidget : : destroyed ,
bind ( static_cast < bool ( * ) ( const QMetaObject : : Connection & ) > ( & QObject : : disconnect ) ,
m_connection . requestLog ( [ browser ] ( const std : : vector < SyncthingLogEntry > & entries ) {
for ( const SyncthingLogEntry & entry : entries ) {
browser - > append ( entry . when % QChar ( ' : ' ) % QChar ( ' ' ) % QChar ( ' \n ' ) % entry . message % QChar ( ' \n ' ) ) ;
}
} )
) ) ;
browser - > setReadOnly ( true ) ;
browser - > setFont ( QFontDatabase : : systemFont ( QFontDatabase : : FixedFont ) ) ;
2016-08-25 00:45:32 +02:00
layout - > addWidget ( browser ) ;
dlg - > setLayout ( layout ) ;
dlg - > show ( ) ;
dlg - > resize ( 600 , 500 ) ;
centerWidget ( dlg ) ;
if ( m_menu ) {
m_menu - > close ( ) ;
}
dlg - > activateWindow ( ) ;
}
2016-09-06 22:55:49 +02:00
void TrayWidget : : handleStatusChanged ( SyncthingStatus status )
2016-08-25 00:45:32 +02:00
{
switch ( status ) {
case SyncthingStatus : : Disconnected :
m_ui - > statusPushButton - > setText ( tr ( " Connect " ) ) ;
m_ui - > statusPushButton - > setToolTip ( tr ( " Not connected to Syncthing, click to connect " ) ) ;
2016-08-29 20:51:30 +02:00
m_ui - > statusPushButton - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " view-refresh " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/actions/view-refresh.svg " ) ) ) ) ;
2016-09-06 22:55:49 +02:00
m_ui - > statusPushButton - > setHidden ( false ) ;
updateTraffic ( ) ; // ensure previous traffic statistics are no longer shown
break ;
case SyncthingStatus : : Reconnecting :
m_ui - > statusPushButton - > setHidden ( true ) ;
2016-08-25 00:45:32 +02:00
break ;
2016-09-03 19:39:43 +02:00
case SyncthingStatus : : Idle :
case SyncthingStatus : : Scanning :
2016-08-25 00:45:32 +02:00
case SyncthingStatus : : NotificationsAvailable :
case SyncthingStatus : : Synchronizing :
m_ui - > statusPushButton - > setText ( tr ( " Pause " ) ) ;
2016-08-26 16:43:53 +02:00
m_ui - > statusPushButton - > setToolTip ( tr ( " Syncthing is running, click to pause all devices " ) ) ;
2016-08-29 20:51:30 +02:00
m_ui - > statusPushButton - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " media-playback-pause " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/actions/media-playback-pause.svg " ) ) ) ) ;
2016-09-06 22:55:49 +02:00
m_ui - > statusPushButton - > setHidden ( false ) ;
2016-08-25 00:45:32 +02:00
break ;
case SyncthingStatus : : Paused :
m_ui - > statusPushButton - > setText ( tr ( " Continue " ) ) ;
2016-08-26 16:43:53 +02:00
m_ui - > statusPushButton - > setToolTip ( tr ( " At least one device is paused, click to resume " ) ) ;
2016-08-29 20:51:30 +02:00
m_ui - > statusPushButton - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " media-playback-start " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/scalable/actions/media-playback-resume.svg " ) ) ) ) ;
2016-09-06 22:55:49 +02:00
m_ui - > statusPushButton - > setHidden ( false ) ;
2016-08-25 00:45:32 +02:00
break ;
}
}
void TrayWidget : : applySettings ( )
{
2016-09-03 20:14:52 +02:00
// update connections menu
int connectionIndex = 0 ;
const int connectionCount = static_cast < int > ( 1 + Settings : : secondaryConnectionSettings ( ) . size ( ) ) ;
const QList < QAction * > connectionActions = m_connectionsActionGroup - > actions ( ) ;
m_selectedConnection = nullptr ;
for ( ; connectionIndex < connectionCount ; + + connectionIndex ) {
Settings : : ConnectionSettings & connectionSettings = ( connectionIndex = = 0 ? Settings : : primaryConnectionSettings ( ) : Settings : : secondaryConnectionSettings ( ) [ static_cast < size_t > ( connectionIndex - 1 ) ] ) ;
if ( connectionIndex < connectionActions . size ( ) ) {
QAction * action = connectionActions . at ( connectionIndex ) ;
action - > setText ( connectionSettings . label ) ;
if ( action - > isChecked ( ) ) {
m_selectedConnection = & connectionSettings ;
}
} else {
QAction * action = m_connectionsMenu - > addAction ( connectionSettings . label ) ;
action - > setCheckable ( true ) ;
m_connectionsActionGroup - > addAction ( action ) ;
}
}
for ( ; connectionIndex < connectionActions . size ( ) ; + + connectionIndex ) {
m_connectionsActionGroup - > removeAction ( connectionActions . at ( connectionIndex ) ) ;
}
if ( ! m_selectedConnection ) {
m_selectedConnection = & Settings : : primaryConnectionSettings ( ) ;
m_connectionsMenu - > actions ( ) . at ( 0 ) - > setChecked ( true ) ;
}
m_connection . reconnect ( * m_selectedConnection ) ;
// web view
# ifndef SYNCTHINGTRAY_NO_WEBVIEW
if ( m_webViewDlg ) {
m_webViewDlg - > applySettings ( * m_selectedConnection ) ;
2016-08-25 00:45:32 +02:00
}
2016-09-03 20:14:52 +02:00
# endif
// update visual appearance
m_ui - > trafficFormWidget - > setVisible ( Settings : : showTraffic ( ) ) ;
2016-08-30 20:01:07 +02:00
if ( Settings : : showTraffic ( ) ) {
updateTraffic ( ) ;
}
2016-09-03 19:39:43 +02:00
m_ui - > trafficFrame - > setFrameStyle ( Settings : : frameStyle ( ) ) ;
m_ui - > buttonsFrame - > setFrameStyle ( Settings : : frameStyle ( ) ) ;
if ( QApplication : : style ( ) & & ! QApplication : : style ( ) - > objectName ( ) . compare ( QLatin1String ( " adwaita " ) , Qt : : CaseInsensitive ) ) {
m_cornerFrame - > setFrameStyle ( QFrame : : NoFrame ) ;
} else {
m_cornerFrame - > setFrameStyle ( Settings : : frameStyle ( ) ) ;
}
2016-08-25 00:45:32 +02:00
}
2016-08-26 16:43:53 +02:00
void TrayWidget : : openDir ( const QModelIndex & dirIndex )
2016-08-25 00:45:32 +02:00
{
2016-08-26 16:43:53 +02:00
if ( const SyncthingDir * dir = m_dirModel . dirInfo ( dirIndex ) ) {
2016-08-25 00:45:32 +02:00
if ( QDir ( dir - > path ) . exists ( ) ) {
DesktopUtils : : openLocalFileOrDir ( dir - > path ) ;
} else {
2016-09-01 16:34:30 +02:00
QMessageBox : : warning ( this , QCoreApplication : : applicationName ( ) , tr ( " The directory <i>%1</i> does not exist on the local machine. " ) . arg ( dir - > path ) ) ;
2016-08-25 00:45:32 +02:00
}
}
}
2016-08-26 16:43:53 +02:00
void TrayWidget : : scanDir ( const QModelIndex & dirIndex )
2016-08-25 00:45:32 +02:00
{
2016-08-26 16:43:53 +02:00
if ( const SyncthingDir * dir = m_dirModel . dirInfo ( dirIndex ) ) {
2016-08-25 00:45:32 +02:00
m_connection . rescan ( dir - > id ) ;
}
}
2016-08-26 16:43:53 +02:00
void TrayWidget : : pauseResumeDev ( const QModelIndex & devIndex )
{
if ( const SyncthingDev * dev = m_devModel . devInfo ( devIndex ) ) {
if ( dev - > paused ) {
m_connection . resume ( dev - > id ) ;
} else {
m_connection . pause ( dev - > id ) ;
}
}
}
2016-08-29 20:51:30 +02:00
void TrayWidget : : changeStatus ( )
2016-08-25 00:45:32 +02:00
{
switch ( m_connection . status ( ) ) {
case SyncthingStatus : : Disconnected :
m_connection . connect ( ) ;
break ;
2016-09-06 22:55:49 +02:00
case SyncthingStatus : : Reconnecting :
break ;
2016-09-03 19:39:43 +02:00
case SyncthingStatus : : Idle :
case SyncthingStatus : : Scanning :
2016-08-25 00:45:32 +02:00
case SyncthingStatus : : NotificationsAvailable :
case SyncthingStatus : : Synchronizing :
m_connection . pauseAllDevs ( ) ;
break ;
case SyncthingStatus : : Paused :
m_connection . resumeAllDevs ( ) ;
break ;
}
}
2016-08-30 20:01:07 +02:00
void TrayWidget : : updateTraffic ( )
2016-08-25 00:45:32 +02:00
{
2016-08-30 20:01:07 +02:00
if ( m_ui - > trafficFrame - > isHidden ( ) ) {
return ;
2016-08-25 00:45:32 +02:00
}
2016-09-06 22:55:49 +02:00
static const QString unknownStr ( tr ( " unknown " ) ) ;
if ( m_connection . isConnected ( ) ) {
if ( m_connection . totalIncomingRate ( ) ! = 0.0 ) {
m_ui - > inTrafficLabel - > setText ( m_connection . totalIncomingTraffic ( ) > = 0
? QStringLiteral ( " %1 (%2) " ) . arg ( QString : : fromUtf8 ( bitrateToString ( m_connection . totalIncomingRate ( ) , true ) . data ( ) ) , QString : : fromUtf8 ( dataSizeToString ( m_connection . totalIncomingTraffic ( ) ) . data ( ) ) )
: QString : : fromUtf8 ( bitrateToString ( m_connection . totalIncomingRate ( ) , true ) . data ( ) ) ) ;
} else {
m_ui - > inTrafficLabel - > setText ( m_connection . totalIncomingTraffic ( ) > = 0 ? QString : : fromUtf8 ( dataSizeToString ( m_connection . totalIncomingTraffic ( ) ) . data ( ) ) : unknownStr ) ;
}
if ( m_connection . totalOutgoingRate ( ) ! = 0.0 ) {
m_ui - > outTrafficLabel - > setText ( m_connection . totalIncomingTraffic ( ) > = 0
? QStringLiteral ( " %1 (%2) " ) . arg ( QString : : fromUtf8 ( bitrateToString ( m_connection . totalOutgoingRate ( ) , true ) . data ( ) ) , QString : : fromUtf8 ( dataSizeToString ( m_connection . totalOutgoingTraffic ( ) ) . data ( ) ) )
: QString : : fromUtf8 ( bitrateToString ( m_connection . totalOutgoingRate ( ) , true ) . data ( ) ) ) ;
} else {
m_ui - > outTrafficLabel - > setText ( m_connection . totalOutgoingTraffic ( ) > = 0 ? QString : : fromUtf8 ( dataSizeToString ( m_connection . totalOutgoingTraffic ( ) ) . data ( ) ) : unknownStr ) ;
}
2016-08-30 20:01:07 +02:00
} else {
2016-09-06 22:55:49 +02:00
m_ui - > inTrafficLabel - > setText ( unknownStr ) ;
m_ui - > outTrafficLabel - > setText ( unknownStr ) ;
2016-08-25 00:45:32 +02:00
}
}
2016-09-03 20:14:52 +02:00
# ifndef SYNCTHINGTRAY_NO_WEBVIEW
2016-08-30 20:01:07 +02:00
void TrayWidget : : handleWebViewDeleted ( )
2016-08-25 00:45:32 +02:00
{
2016-08-30 20:01:07 +02:00
m_webViewDlg = nullptr ;
2016-08-25 00:45:32 +02:00
}
2016-09-03 20:14:52 +02:00
# endif
2016-08-25 00:45:32 +02:00
2016-09-01 16:34:30 +02:00
void TrayWidget : : handleNewNotification ( const QString & msg )
{
// FIXME
}
2016-09-03 20:14:52 +02:00
void TrayWidget : : handleConnectionSelected ( QAction * connectionAction )
{
int index = m_connectionsMenu - > actions ( ) . indexOf ( connectionAction ) ;
if ( index > = 0 ) {
m_selectedConnection = ( index = = 0 )
? & Settings : : primaryConnectionSettings ( )
: & Settings : : secondaryConnectionSettings ( ) [ static_cast < size_t > ( index - 1 ) ] ;
m_connection . reconnect ( * m_selectedConnection ) ;
# ifndef SYNCTHINGTRAY_NO_WEBVIEW
if ( m_webViewDlg ) {
m_webViewDlg - > applySettings ( * m_selectedConnection ) ;
}
# endif
}
}
void TrayWidget : : showConnectionsMenu ( )
{
m_connectionsMenu - > exec ( QCursor : : pos ( ) ) ;
}
2016-08-25 00:45:32 +02:00
}