2014-07-07 00:19:45 +08:00
/*
2015-06-06 09:40:08 +08:00
Copyright © 2014 - 2015 by The qTox Project
2014-07-07 00:19:45 +08:00
This file is part of qTox , a Qt - based graphical interface for Tox .
2015-06-06 09:40:08 +08:00
qTox is libre software : you can redistribute it and / or modify
2014-07-07 00:19:45 +08:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
2015-06-06 09:40:08 +08:00
qTox is distributed in the hope that it will be useful ,
2014-07-07 00:19:45 +08:00
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2015-06-06 09:40:08 +08:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2014-07-07 00:19:45 +08:00
2015-06-06 09:40:08 +08:00
You should have received a copy of the GNU General Public License
along with qTox . If not , see < http : //www.gnu.org/licenses/>.
2014-07-07 00:19:45 +08:00
*/
2014-06-25 04:11:11 +08:00
# include "widget.h"
2015-06-17 02:25:19 +08:00
# include "contentlayout.h"
2014-08-11 16:00:08 +08:00
# include "ui_mainwindow.h"
2015-04-24 08:32:09 +08:00
# include "src/core/core.h"
2015-06-26 19:00:16 +08:00
# include "src/core/coreav.h"
2015-06-06 07:44:47 +08:00
# include "src/persistence/settings.h"
2015-06-19 22:58:48 +08:00
# include "contentdialog.h"
2014-10-08 12:26:25 +08:00
# include "src/friend.h"
# include "src/friendlist.h"
# include "tool/friendrequestdialog.h"
# include "friendwidget.h"
# include "src/grouplist.h"
# include "src/group.h"
# include "groupwidget.h"
# include "form/groupchatform.h"
2015-05-31 03:10:43 +08:00
# include "circlewidget.h"
2015-06-06 07:44:47 +08:00
# include "src/widget/style.h"
2014-10-08 12:26:25 +08:00
# include "friendlistwidget.h"
# include "form/chatform.h"
# include "maskablepixmapwidget.h"
2015-06-06 07:44:47 +08:00
# include "src/net/autoupdate.h"
# include "src/audio/audio.h"
2014-11-27 21:13:35 +08:00
# include "src/platform/timer.h"
2015-01-29 21:56:53 +08:00
# include "systemtrayicon.h"
2015-02-06 19:28:49 +08:00
# include "src/nexus.h"
2015-12-06 02:08:28 +08:00
# include "src/persistence/profile.h"
2015-02-16 07:24:42 +08:00
# include "src/widget/gui.h"
2015-06-06 07:44:47 +08:00
# include "src/persistence/offlinemsgengine.h"
# include "src/widget/translator.h"
2015-06-08 02:24:55 +08:00
# include "src/widget/form/addfriendform.h"
2016-02-21 05:32:57 +08:00
# include "src/widget/form/groupinviteform.h"
2015-06-08 02:24:55 +08:00
# include "src/widget/form/filesform.h"
# include "src/widget/form/profileform.h"
# include "src/widget/form/settingswidget.h"
2015-08-22 17:05:16 +08:00
# include "tool/removefrienddialog.h"
2015-07-30 07:46:19 +08:00
# include "src/widget/tool/activatedialog.h"
2015-02-07 02:51:03 +08:00
# include <cassert>
2014-06-25 04:11:11 +08:00
# include <QMessageBox>
# include <QDebug>
2014-07-01 10:12:17 +08:00
# include <QFile>
# include <QString>
2014-09-24 22:51:16 +08:00
# include <QBuffer>
2014-07-01 10:12:17 +08:00
# include <QPainter>
# include <QMouseEvent>
2014-07-02 05:50:07 +08:00
# include <QClipboard>
2014-09-11 21:44:34 +08:00
# include <QThread>
2015-02-05 06:11:21 +08:00
# include <QDialogButtonBox>
2015-03-27 07:10:32 +08:00
# include <QShortcut>
2014-10-16 17:47:58 +08:00
# include <QTimer>
2014-10-09 06:31:20 +08:00
# include <QStyleFactory>
2015-02-13 22:23:21 +08:00
# include <QString>
# include <QByteArray>
# include <QImageReader>
# include <QList>
2015-02-22 20:21:42 +08:00
# include <QDesktopServices>
# include <QProcess>
2015-08-29 20:10:17 +08:00
# include <QSvgRenderer>
2015-06-17 02:25:19 +08:00
# include <QWindow>
2014-10-18 07:06:30 +08:00
# include <tox/tox.h>
2014-06-25 04:11:11 +08:00
2015-07-02 01:12:50 +08:00
# ifdef Q_OS_MAC
# include <QMenuBar>
# include <QWindow>
2015-07-30 07:46:19 +08:00
# include <QSignalMapper>
2015-07-02 01:12:50 +08:00
# endif
2015-02-07 02:51:03 +08:00
# ifdef Q_OS_ANDROID
# define IS_ON_DESKTOP_GUI 0
# else
# define IS_ON_DESKTOP_GUI 1
# endif
2015-02-20 20:26:41 +08:00
bool toxActivateEventHandler ( const QByteArray & )
2014-11-26 01:11:05 +08:00
{
2015-12-16 02:31:26 +08:00
Widget * widget = Nexus : : getDesktopGUI ( ) ;
if ( ! widget )
return true ;
if ( ! widget - > isActiveWindow ( ) )
widget - > forceShow ( ) ;
2015-04-24 19:01:50 +08:00
2015-02-20 20:26:41 +08:00
return true ;
2014-11-26 01:11:05 +08:00
}
2014-06-25 04:11:11 +08:00
Widget * Widget : : instance { nullptr } ;
2014-08-11 16:00:08 +08:00
Widget : : Widget ( QWidget * parent )
: QMainWindow ( parent ) ,
2015-02-06 08:27:07 +08:00
icon { nullptr } ,
2015-06-06 09:45:44 +08:00
trayMenu { nullptr } ,
2014-08-11 16:00:08 +08:00
ui ( new Ui : : MainWindow ) ,
2014-12-12 00:49:11 +08:00
activeChatroomWidget { nullptr } ,
eventFlag ( false ) ,
2015-02-06 08:27:07 +08:00
eventIcon ( false )
2015-03-28 04:15:51 +08:00
{
2015-03-20 03:24:06 +08:00
installEventFilter ( this ) ;
2015-06-05 18:26:04 +08:00
Translator : : translate ( ) ;
2014-10-15 23:35:58 +08:00
}
void Widget : : init ( )
2014-06-25 04:11:11 +08:00
{
ui - > setupUi ( this ) ;
2014-11-28 17:16:37 +08:00
2015-12-14 22:06:21 +08:00
QIcon themeIcon = QIcon : : fromTheme ( " qtox " ) ;
if ( ! themeIcon . isNull ( ) )
setWindowIcon ( themeIcon ) ;
2014-12-12 00:49:11 +08:00
timer = new QTimer ( ) ;
timer - > start ( 1000 ) ;
2015-02-08 00:18:25 +08:00
offlineMsgTimer = new QTimer ( ) ;
offlineMsgTimer - > start ( 15000 ) ;
2014-12-02 04:02:44 +08:00
2015-08-30 00:06:22 +08:00
icon_size = 15 ;
2015-06-06 03:37:01 +08:00
statusOnline = new QAction ( this ) ;
2015-11-07 04:53:26 +08:00
statusOnline - > setIcon ( prepareIcon ( getStatusIconPath ( Status : : Online ) , icon_size , icon_size ) ) ;
2015-08-29 20:10:17 +08:00
connect ( statusOnline , & QAction : : triggered , this , & Widget : : setStatusOnline ) ;
2015-06-06 03:37:01 +08:00
statusAway = new QAction ( this ) ;
2015-11-07 04:53:26 +08:00
statusAway - > setIcon ( prepareIcon ( getStatusIconPath ( Status : : Away ) , icon_size , icon_size ) ) ;
2015-08-29 20:10:17 +08:00
connect ( statusAway , & QAction : : triggered , this , & Widget : : setStatusAway ) ;
2015-06-06 03:37:01 +08:00
statusBusy = new QAction ( this ) ;
2015-11-07 04:53:26 +08:00
statusBusy - > setIcon ( prepareIcon ( getStatusIconPath ( Status : : Busy ) , icon_size , icon_size ) ) ;
2015-08-29 20:10:17 +08:00
connect ( statusBusy , & QAction : : triggered , this , & Widget : : setStatusBusy ) ;
2015-02-07 02:16:01 +08:00
2015-11-08 23:11:19 +08:00
actionLogout = new QAction ( this ) ;
2015-11-10 02:42:53 +08:00
actionLogout - > setIcon ( prepareIcon ( " :/img/others/logout-icon.svg " , icon_size , icon_size ) ) ;
2015-11-08 23:11:19 +08:00
actionQuit = new QAction ( this ) ;
2015-12-24 00:43:06 +08:00
# ifndef Q_OS_OSX
2015-11-08 23:11:19 +08:00
actionQuit - > setMenuRole ( QAction : : QuitRole ) ;
2015-12-24 00:43:06 +08:00
# endif
2015-11-10 02:42:53 +08:00
actionQuit - > setIcon ( prepareIcon ( " :/ui/rejectCall/rejectCall.svg " , icon_size , icon_size ) ) ;
2015-11-08 23:11:19 +08:00
connect ( actionQuit , & QAction : : triggered , qApp , & QApplication : : quit ) ;
2014-10-04 16:54:50 +08:00
layout ( ) - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2015-11-10 02:42:53 +08:00
ui - > friendList - > setStyleSheet ( Style : : resolve ( Style : : getStylesheet ( " :/ui/friendList/friendList.css " ) ) ) ;
2014-07-01 10:12:17 +08:00
2015-11-10 02:42:53 +08:00
profilePicture = new MaskablePixmapWidget ( this , QSize ( 40 , 40 ) , " :/img/avatar_mask.svg " ) ;
profilePicture - > setPixmap ( QPixmap ( " :/img/contact_dark.svg " ) ) ;
2014-09-28 01:13:46 +08:00
profilePicture - > setClickable ( true ) ;
2014-11-03 07:26:23 +08:00
ui - > myProfile - > insertWidget ( 0 , profilePicture ) ;
ui - > myProfile - > insertSpacing ( 1 , 7 ) ;
2014-09-26 22:39:29 +08:00
2015-06-13 00:09:01 +08:00
filterMenu = new QMenu ( this ) ;
filterGroup = new QActionGroup ( this ) ;
filterDisplayGroup = new QActionGroup ( this ) ;
filterDisplayName = new QAction ( this ) ;
filterDisplayName - > setCheckable ( true ) ;
filterDisplayName - > setChecked ( true ) ;
filterDisplayGroup - > addAction ( filterDisplayName ) ;
filterMenu - > addAction ( filterDisplayName ) ;
filterDisplayActivity = new QAction ( this ) ;
filterDisplayActivity - > setCheckable ( true ) ;
filterDisplayGroup - > addAction ( filterDisplayActivity ) ;
filterMenu - > addAction ( filterDisplayActivity ) ;
filterMenu - > addSeparator ( ) ;
filterAllAction = new QAction ( this ) ;
filterAllAction - > setCheckable ( true ) ;
filterAllAction - > setChecked ( true ) ;
filterGroup - > addAction ( filterAllAction ) ;
filterMenu - > addAction ( filterAllAction ) ;
filterOnlineAction = new QAction ( this ) ;
filterOnlineAction - > setCheckable ( true ) ;
filterGroup - > addAction ( filterOnlineAction ) ;
filterMenu - > addAction ( filterOnlineAction ) ;
filterOfflineAction = new QAction ( this ) ;
filterOfflineAction - > setCheckable ( true ) ;
filterGroup - > addAction ( filterOfflineAction ) ;
filterMenu - > addAction ( filterOfflineAction ) ;
filterFriendsAction = new QAction ( this ) ;
filterFriendsAction - > setCheckable ( true ) ;
filterGroup - > addAction ( filterFriendsAction ) ;
filterMenu - > addAction ( filterFriendsAction ) ;
filterGroupsAction = new QAction ( this ) ;
filterGroupsAction - > setCheckable ( true ) ;
filterGroup - > addAction ( filterGroupsAction ) ;
filterMenu - > addAction ( filterGroupsAction ) ;
ui - > searchContactFilterBox - > setMenu ( filterMenu ) ;
2015-05-11 05:40:08 +08:00
# ifndef Q_OS_MAC
2014-11-03 07:26:23 +08:00
ui - > statusHead - > setStyleSheet ( Style : : getStylesheet ( " :/ui/window/statusPanel.css " ) ) ;
2015-05-11 05:40:08 +08:00
# endif
2014-08-11 16:00:08 +08:00
2015-06-07 11:20:06 +08:00
contactListWidget = new FriendListWidget ( this , Settings : : getInstance ( ) . getGroupchatPosition ( ) ) ;
2014-08-22 23:19:16 +08:00
ui - > friendList - > setWidget ( contactListWidget ) ;
2014-08-12 01:46:14 +08:00
ui - > friendList - > setLayoutDirection ( Qt : : RightToLeft ) ;
2015-05-28 01:17:12 +08:00
ui - > friendList - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2014-06-25 04:11:11 +08:00
2014-09-01 17:08:02 +08:00
ui - > statusLabel - > setEditable ( true ) ;
2014-10-04 16:24:20 +08:00
ui - > statusPanel - > setStyleSheet ( Style : : getStylesheet ( " :/ui/window/statusPanel.css " ) ) ;
2014-07-06 03:30:00 +08:00
2014-07-06 04:54:27 +08:00
QMenu * statusButtonMenu = new QMenu ( ui - > statusButton ) ;
2015-02-07 02:16:01 +08:00
statusButtonMenu - > addAction ( statusOnline ) ;
statusButtonMenu - > addAction ( statusAway ) ;
statusButtonMenu - > addAction ( statusBusy ) ;
2014-07-06 04:54:27 +08:00
ui - > statusButton - > setMenu ( statusButtonMenu ) ;
2014-08-11 19:56:52 +08:00
// disable proportional scaling
2014-08-11 20:07:27 +08:00
ui - > mainSplitter - > setStretchFactor ( 0 , 0 ) ;
ui - > mainSplitter - > setStretchFactor ( 1 , 1 ) ;
2014-06-25 04:11:11 +08:00
2015-02-12 20:18:04 +08:00
onStatusSet ( Status : : Offline ) ;
2014-07-06 21:51:24 +08:00
2014-09-03 06:01:04 +08:00
// Disable some widgets until we're connected to the DHT
ui - > statusButton - > setEnabled ( false ) ;
2014-11-16 04:30:20 +08:00
Style : : setThemeColor ( Settings : : getInstance ( ) . getThemeColor ( ) ) ;
2015-02-07 02:01:31 +08:00
reloadTheme ( ) ;
2015-03-12 02:04:29 +08:00
updateIcons ( ) ;
2015-04-24 19:01:50 +08:00
2014-10-18 22:54:52 +08:00
filesForm = new FilesForm ( ) ;
addFriendForm = new AddFriendForm ;
2016-02-21 05:32:57 +08:00
groupInviteForm = new GroupInviteForm ;
2015-03-04 04:29:01 +08:00
profileForm = new ProfileForm ( ) ;
2014-10-18 22:54:52 +08:00
settingsWidget = new SettingsWidget ( ) ;
2014-06-25 04:11:11 +08:00
2015-11-10 02:48:00 +08:00
//connect logout tray menu action
connect ( actionLogout , & QAction : : triggered , profileForm , & ProfileForm : : onLogoutClicked ) ;
2015-02-06 19:28:49 +08:00
Core * core = Nexus : : getCore ( ) ;
2015-05-12 02:14:09 +08:00
connect ( core , & Core : : fileDownloadFinished , filesForm , & FilesForm : : onFileDownloadComplete ) ;
connect ( core , & Core : : fileUploadFinished , filesForm , & FilesForm : : onFileUploadComplete ) ;
2015-02-06 19:28:49 +08:00
connect ( settingsWidget , & SettingsWidget : : setShowSystemTray , this , & Widget : : onSetShowSystemTray ) ;
2015-05-12 02:14:09 +08:00
connect ( core , & Core : : selfAvatarChanged , profileForm , & ProfileForm : : onSelfAvatarLoaded ) ;
connect ( ui - > addButton , & QPushButton : : clicked , this , & Widget : : onAddClicked ) ;
connect ( ui - > groupButton , & QPushButton : : clicked , this , & Widget : : onGroupClicked ) ;
connect ( ui - > transferButton , & QPushButton : : clicked , this , & Widget : : onTransferClicked ) ;
connect ( ui - > settingsButton , & QPushButton : : clicked , this , & Widget : : onSettingsClicked ) ;
2015-03-11 10:01:13 +08:00
connect ( profilePicture , & MaskablePixmapWidget : : clicked , this , & Widget : : showProfile ) ;
connect ( ui - > nameLabel , & CroppingLabel : : clicked , this , & Widget : : showProfile ) ;
2015-06-08 02:25:05 +08:00
connect ( ui - > statusLabel , & CroppingLabel : : editFinished , this , & Widget : : onStatusMessageChanged ) ;
2014-11-28 17:16:37 +08:00
connect ( ui - > mainSplitter , & QSplitter : : splitterMoved , this , & Widget : : onSplitterMoved ) ;
2015-05-12 02:14:09 +08:00
connect ( addFriendForm , & AddFriendForm : : friendRequested , this , & Widget : : friendRequested ) ;
2016-02-21 05:32:57 +08:00
connect ( groupInviteForm , & GroupInviteForm : : groupCreate , Core : : getInstance ( ) , & Core : : createGroup ) ;
2014-12-12 00:49:11 +08:00
connect ( timer , & QTimer : : timeout , this , & Widget : : onUserAwayCheck ) ;
connect ( timer , & QTimer : : timeout , this , & Widget : : onEventIconTick ) ;
2015-02-20 18:56:20 +08:00
connect ( timer , & QTimer : : timeout , this , & Widget : : onTryCreateTrayIcon ) ;
2015-02-13 13:27:49 +08:00
connect ( offlineMsgTimer , & QTimer : : timeout , this , & Widget : : processOfflineMsgs ) ;
2015-04-09 00:18:07 +08:00
connect ( ui - > searchContactText , & QLineEdit : : textChanged , this , & Widget : : searchContacts ) ;
2015-06-13 00:09:01 +08:00
connect ( filterGroup , & QActionGroup : : triggered , this , & Widget : : searchContacts ) ;
connect ( filterDisplayGroup , & QActionGroup : : triggered , this , & Widget : : changeDisplayMode ) ;
2015-05-28 01:17:12 +08:00
connect ( ui - > friendList , & QWidget : : customContextMenuRequested , this , & Widget : : friendListContextMenu ) ;
2014-06-25 04:11:11 +08:00
2015-03-27 07:10:32 +08:00
// keyboard shortcuts
new QShortcut ( Qt : : CTRL + Qt : : Key_Q , this , SLOT ( close ( ) ) ) ;
2015-03-22 16:16:32 +08:00
new QShortcut ( Qt : : CTRL + Qt : : SHIFT + Qt : : Key_Tab , this , SLOT ( previousContact ( ) ) ) ;
new QShortcut ( Qt : : CTRL + Qt : : Key_Tab , this , SLOT ( nextContact ( ) ) ) ;
new QShortcut ( Qt : : CTRL + Qt : : Key_PageUp , this , SLOT ( previousContact ( ) ) ) ;
new QShortcut ( Qt : : CTRL + Qt : : Key_PageDown , this , SLOT ( nextContact ( ) ) ) ;
2015-03-27 07:10:32 +08:00
2015-07-02 01:12:50 +08:00
# ifdef Q_OS_MAC
2015-07-30 07:46:19 +08:00
QMenuBar * globalMenu = Nexus : : getInstance ( ) . globalMenuBar ;
2015-07-09 20:43:19 +08:00
QAction * windowMenu = Nexus : : getInstance ( ) . windowMenu - > menuAction ( ) ;
2015-07-30 07:46:19 +08:00
QAction * viewMenu = Nexus : : getInstance ( ) . viewMenu - > menuAction ( ) ;
QAction * frontAction = Nexus : : getInstance ( ) . frontAction ;
2015-07-02 01:12:50 +08:00
2015-07-30 07:46:19 +08:00
fileMenu = globalMenu - > insertMenu ( viewMenu , new QMenu ( this ) ) ;
editProfileAction = fileMenu - > menu ( ) - > addAction ( QString ( ) ) ;
2015-07-02 01:12:50 +08:00
connect ( editProfileAction , & QAction : : triggered , this , & Widget : : showProfile ) ;
2015-07-30 07:46:19 +08:00
changeStatusMenu = fileMenu - > menu ( ) - > addMenu ( QString ( ) ) ;
2015-07-09 20:43:19 +08:00
fileMenu - > menu ( ) - > addAction ( changeStatusMenu - > menuAction ( ) ) ;
2015-07-02 01:12:50 +08:00
changeStatusMenu - > addAction ( statusOnline ) ;
changeStatusMenu - > addSeparator ( ) ;
changeStatusMenu - > addAction ( statusAway ) ;
changeStatusMenu - > addAction ( statusBusy ) ;
2015-07-09 20:43:19 +08:00
fileMenu - > menu ( ) - > addSeparator ( ) ;
2015-07-30 07:46:19 +08:00
logoutAction = fileMenu - > menu ( ) - > addAction ( QString ( ) ) ;
2015-07-02 01:12:50 +08:00
connect ( logoutAction , & QAction : : triggered , [ this ] ( )
{
Nexus : : getInstance ( ) . showLogin ( ) ;
} ) ;
2015-07-30 07:46:19 +08:00
editMenu = globalMenu - > insertMenu ( viewMenu , new QMenu ( this ) ) ;
2015-07-09 20:43:19 +08:00
editMenu - > menu ( ) - > addSeparator ( ) ;
2015-07-02 01:12:50 +08:00
2015-07-30 07:46:19 +08:00
viewMenu - > menu ( ) - > insertMenu ( Nexus : : getInstance ( ) . fullscreenAction , filterMenu ) ;
2015-07-02 01:12:50 +08:00
2015-07-30 07:46:19 +08:00
viewMenu - > menu ( ) - > insertSeparator ( Nexus : : getInstance ( ) . fullscreenAction ) ;
2015-07-02 01:12:50 +08:00
2015-07-30 07:46:19 +08:00
contactMenu = globalMenu - > insertMenu ( windowMenu , new QMenu ( this ) ) ;
2015-07-02 01:12:50 +08:00
2015-07-30 07:46:19 +08:00
addContactAction = contactMenu - > menu ( ) - > addAction ( QString ( ) ) ;
2015-07-02 01:12:50 +08:00
connect ( addContactAction , & QAction : : triggered , this , & Widget : : onAddClicked ) ;
2015-07-30 07:46:19 +08:00
nextConversationAction = new QAction ( this ) ;
Nexus : : getInstance ( ) . windowMenu - > insertAction ( frontAction , nextConversationAction ) ;
2015-07-02 01:12:50 +08:00
nextConversationAction - > setShortcut ( QKeySequence : : SelectNextPage ) ;
2015-07-30 07:46:19 +08:00
connect ( nextConversationAction , & QAction : : triggered , [ this ] ( )
{
if ( ContentDialog : : current ( ) = = QApplication : : activeWindow ( ) )
ContentDialog : : current ( ) - > cycleContacts ( true ) ;
else if ( QApplication : : activeWindow ( ) = = this )
cycleContacts ( true ) ;
} ) ;
2015-07-02 01:12:50 +08:00
2015-07-30 07:46:19 +08:00
previousConversationAction = new QAction ( this ) ;
Nexus : : getInstance ( ) . windowMenu - > insertAction ( frontAction , previousConversationAction ) ;
2015-07-02 01:12:50 +08:00
previousConversationAction - > setShortcut ( QKeySequence : : SelectPreviousPage ) ;
2015-07-30 07:46:19 +08:00
connect ( previousConversationAction , & QAction : : triggered , [ this ]
{
if ( ContentDialog : : current ( ) = = QApplication : : activeWindow ( ) )
ContentDialog : : current ( ) - > cycleContacts ( false ) ;
else if ( QApplication : : activeWindow ( ) = = this )
cycleContacts ( false ) ;
} ) ;
2015-07-02 01:12:50 +08:00
2015-07-30 07:46:19 +08:00
windowMenu - > menu ( ) - > insertSeparator ( frontAction ) ;
2015-07-02 01:12:50 +08:00
2015-07-09 20:43:19 +08:00
QAction * preferencesAction = viewMenu - > menu ( ) - > addAction ( QString ( ) ) ;
2015-07-02 01:12:50 +08:00
preferencesAction - > setMenuRole ( QAction : : PreferencesRole ) ;
connect ( preferencesAction , & QAction : : triggered , this , & Widget : : onSettingsClicked ) ;
2015-07-09 20:43:19 +08:00
QAction * aboutAction = viewMenu - > menu ( ) - > addAction ( QString ( ) ) ;
2015-07-02 01:12:50 +08:00
aboutAction - > setMenuRole ( QAction : : AboutRole ) ;
connect ( aboutAction , & QAction : : triggered , [ this ] ( )
{
onSettingsClicked ( ) ;
settingsWidget - > showAbout ( ) ;
} ) ;
2015-07-30 07:46:19 +08:00
QMenu * dockChangeStatusMenu = new QMenu ( tr ( " Status " ) , this ) ;
dockChangeStatusMenu - > addAction ( statusOnline ) ;
statusOnline - > setIconVisibleInMenu ( true ) ;
dockChangeStatusMenu - > addSeparator ( ) ;
dockChangeStatusMenu - > addAction ( statusAway ) ;
dockChangeStatusMenu - > addAction ( statusBusy ) ;
Nexus : : getInstance ( ) . dockMenu - > addAction ( dockChangeStatusMenu - > menuAction ( ) ) ;
connect ( this , & Widget : : windowStateChanged , & Nexus : : getInstance ( ) , & Nexus : : onWindowStateChanged ) ;
2015-07-02 01:12:50 +08:00
# endif
2015-06-17 02:25:19 +08:00
contentLayout = nullptr ;
onSeparateWindowChanged ( Settings : : getInstance ( ) . getSeparateWindow ( ) , false ) ;
2015-05-10 11:40:49 +08:00
ui - > addButton - > setCheckable ( true ) ;
2016-02-21 05:32:57 +08:00
ui - > groupButton - > setCheckable ( true ) ;
2015-05-10 11:40:49 +08:00
ui - > transferButton - > setCheckable ( true ) ;
ui - > settingsButton - > setCheckable ( true ) ;
2015-06-23 02:01:50 +08:00
if ( contentLayout ! = nullptr )
onAddClicked ( ) ;
2014-11-10 07:31:29 +08:00
2015-06-17 02:25:19 +08:00
//restore window state
restoreGeometry ( Settings : : getInstance ( ) . getWindowGeometry ( ) ) ;
restoreState ( Settings : : getInstance ( ) . getWindowState ( ) ) ;
2015-10-07 21:19:21 +08:00
if ( ! ui - > mainSplitter - > restoreState ( Settings : : getInstance ( ) . getSplitterState ( ) ) )
{
// Set the status panel (friendlist) to a reasonnable width by default/on first start
constexpr int spWidthPc = 33 ;
ui - > mainSplitter - > resize ( size ( ) ) ;
QList < int > sizes = ui - > mainSplitter - > sizes ( ) ;
sizes [ 0 ] = ui - > mainSplitter - > width ( ) * spWidthPc / 100 ;
sizes [ 1 ] = ui - > mainSplitter - > width ( ) - sizes [ 0 ] ;
ui - > mainSplitter - > setSizes ( sizes ) ;
}
2015-06-17 02:25:19 +08:00
2015-06-02 04:17:39 +08:00
connect ( settingsWidget , & SettingsWidget : : compactToggled , contactListWidget , & FriendListWidget : : onCompactChanged ) ;
2015-03-12 08:41:18 +08:00
connect ( settingsWidget , & SettingsWidget : : groupchatPositionToggled , contactListWidget , & FriendListWidget : : onGroupchatPositionChanged ) ;
2015-06-17 02:25:19 +08:00
connect ( settingsWidget , & SettingsWidget : : separateWindowToggled , this , & Widget : : onSeparateWindowClicked ) ;
2014-11-10 07:31:29 +08:00
# if (AUTOUPDATE_ENABLED)
if ( Settings : : getInstance ( ) . getCheckUpdates ( ) )
AutoUpdater : : checkUpdatesAsyncInteractive ( ) ;
# endif
2015-06-06 03:37:01 +08:00
2016-02-21 05:32:57 +08:00
friendRequestsButton = nullptr ;
groupInvitesButton = nullptr ;
unreadGroupInvites = 0 ;
connect ( addFriendForm , & AddFriendForm : : friendRequestsSeen , this , & Widget : : friendRequestsUpdate ) ;
connect ( addFriendForm , & AddFriendForm : : friendRequestAccepted , this , & Widget : : friendRequestAccepted ) ;
connect ( groupInviteForm , & GroupInviteForm : : groupInvitesSeen , this , & Widget : : groupInvitesClear ) ;
connect ( groupInviteForm , & GroupInviteForm : : groupInviteAccepted , this , & Widget : : onGroupInviteAccepted ) ;
2015-06-06 03:37:01 +08:00
retranslateUi ( ) ;
Translator : : registerHandler ( std : : bind ( & Widget : : retranslateUi , this ) , this ) ;
2015-02-20 18:56:20 +08:00
if ( ! Settings : : getInstance ( ) . getShowSystemTray ( ) )
show ( ) ;
2015-07-30 07:46:19 +08:00
2015-07-30 19:53:36 +08:00
# ifdef Q_OS_MAC
2015-07-30 07:46:19 +08:00
Nexus : : getInstance ( ) . updateWindows ( ) ;
2015-07-30 19:53:36 +08:00
# endif
2014-10-18 22:54:52 +08:00
}
2015-03-20 03:24:06 +08:00
bool Widget : : eventFilter ( QObject * obj , QEvent * event )
{
2015-03-26 00:27:33 +08:00
if ( event - > type ( ) = = QEvent : : WindowStateChange & & obj ! = NULL )
2015-03-20 03:24:06 +08:00
{
QWindowStateChangeEvent * ce = static_cast < QWindowStateChangeEvent * > ( event ) ;
if ( windowState ( ) & Qt : : WindowMinimized )
{
if ( ce - > oldState ( ) & Qt : : WindowMaximized )
wasMaximized = true ;
else
wasMaximized = false ;
}
2015-07-30 07:46:19 +08:00
2015-07-30 19:53:36 +08:00
# ifdef Q_OS_MAC
2015-07-30 07:46:19 +08:00
emit windowStateChanged ( windowState ( ) ) ;
2015-07-30 19:53:36 +08:00
# endif
2015-03-20 03:24:06 +08:00
}
return false ;
}
2015-03-12 02:04:29 +08:00
void Widget : : updateIcons ( )
2014-11-27 01:58:30 +08:00
{
2015-02-12 20:18:04 +08:00
if ( ! icon )
return ;
2014-12-12 00:49:11 +08:00
QString status ;
if ( eventIcon )
2015-04-24 19:01:50 +08:00
{
2015-11-11 03:20:07 +08:00
status = QStringLiteral ( " event " ) ;
2015-04-24 19:01:50 +08:00
}
2014-11-27 01:58:30 +08:00
else
2014-12-12 00:49:11 +08:00
{
status = ui - > statusButton - > property ( " status " ) . toString ( ) ;
if ( ! status . length ( ) )
2015-11-11 03:20:07 +08:00
status = QStringLiteral ( " offline " ) ;
2014-12-12 00:49:11 +08:00
}
2015-03-11 19:01:10 +08:00
2016-04-04 23:39:56 +08:00
QIcon ico ;
if ( QIcon : : hasThemeIcon ( " qtox- " + status ) )
{
ico = QIcon : : fromTheme ( " qtox- " + status ) ;
}
else
2015-03-11 19:01:10 +08:00
{
QString color = Settings : : getInstance ( ) . getLightTrayIcon ( ) ? " light " : " dark " ;
2015-11-10 02:42:53 +08:00
QString path = " :/img/taskbar/ " + color + " /taskbar_ " + status + " .svg " ;
2015-08-29 20:10:17 +08:00
QSvgRenderer renderer ( path ) ;
// Prepare a QImage with desired characteritisc
2015-08-29 21:40:55 +08:00
QImage image = QImage ( 250 , 250 , QImage : : Format_ARGB32 ) ;
image . fill ( Qt : : transparent ) ;
2015-08-29 20:10:17 +08:00
QPainter painter ( & image ) ;
renderer . render ( & painter ) ;
ico = QIcon ( QPixmap : : fromImage ( image ) ) ;
2015-03-11 19:01:10 +08:00
}
2015-03-12 02:04:29 +08:00
setWindowIcon ( ico ) ;
if ( icon )
icon - > setIcon ( ico ) ;
2014-11-27 01:58:30 +08:00
}
2014-06-25 04:11:11 +08:00
Widget : : ~ Widget ( )
{
2015-07-03 01:16:11 +08:00
QWidgetList windowList = QApplication : : topLevelWidgets ( ) ;
for ( QWidget * window : windowList )
{
if ( window ! = this )
window - > close ( ) ;
}
2015-06-06 03:37:01 +08:00
Translator : : unregister ( this ) ;
2015-01-05 16:54:03 +08:00
AutoUpdater : : abortUpdates ( ) ;
2015-02-20 18:56:20 +08:00
if ( icon )
icon - > hide ( ) ;
2015-04-24 19:01:50 +08:00
2015-03-04 04:29:01 +08:00
delete profileForm ;
2014-09-30 17:44:27 +08:00
delete settingsWidget ;
2014-10-18 22:54:52 +08:00
delete addFriendForm ;
2016-02-21 05:32:57 +08:00
delete groupInviteForm ;
2014-10-18 22:54:52 +08:00
delete filesForm ;
2014-12-12 00:49:11 +08:00
delete timer ;
2015-02-08 00:18:25 +08:00
delete offlineMsgTimer ;
2015-06-17 02:25:19 +08:00
delete contentLayout ;
2014-06-25 04:11:11 +08:00
2014-11-07 22:55:32 +08:00
FriendList : : clear ( ) ;
2014-11-20 17:13:13 +08:00
GroupList : : clear ( ) ;
2014-10-21 02:03:44 +08:00
delete trayMenu ;
2014-06-25 04:11:11 +08:00
delete ui ;
2014-09-30 17:44:27 +08:00
instance = nullptr ;
2014-06-25 04:11:11 +08:00
}
Widget * Widget : : getInstance ( )
{
2015-02-07 02:51:03 +08:00
assert ( IS_ON_DESKTOP_GUI ) ; // Widget must only be used on Desktop platforms
2014-06-25 04:11:11 +08:00
if ( ! instance )
instance = new Widget ( ) ;
2015-04-24 19:01:50 +08:00
2014-06-25 04:11:11 +08:00
return instance ;
}
2015-12-11 01:46:07 +08:00
void Widget : : showUpdateDownloadProgress ( )
{
settingsWidget - > showAbout ( ) ;
onSettingsClicked ( ) ;
}
2015-10-06 21:13:47 +08:00
void Widget : : moveEvent ( QMoveEvent * event )
{
if ( event - > type ( ) = = QEvent : : Move )
{
saveWindowGeometry ( ) ;
saveSplitterGeometry ( ) ;
}
QWidget : : moveEvent ( event ) ;
}
2014-08-11 16:00:08 +08:00
void Widget : : closeEvent ( QCloseEvent * event )
2014-07-03 14:43:23 +08:00
{
2014-12-12 02:05:52 +08:00
if ( Settings : : getInstance ( ) . getShowSystemTray ( ) & & Settings : : getInstance ( ) . getCloseToTray ( ) = = true )
2014-10-20 03:47:06 +08:00
{
event - > ignore ( ) ;
this - > hide ( ) ;
}
else
{
2015-11-11 03:20:07 +08:00
if ( autoAwayActive )
{
emit statusSet ( Status : : Online ) ;
autoAwayActive = false ;
}
2014-11-28 17:16:37 +08:00
saveWindowGeometry ( ) ;
saveSplitterGeometry ( ) ;
2015-02-01 07:03:42 +08:00
qApp - > exit ( 0 ) ;
2014-10-20 03:47:06 +08:00
QWidget : : closeEvent ( event ) ;
}
2014-07-03 14:43:23 +08:00
}
2014-07-01 10:12:17 +08:00
2014-10-20 19:50:12 +08:00
void Widget : : changeEvent ( QEvent * event )
{
if ( event - > type ( ) = = QEvent : : WindowStateChange )
{
2015-05-12 02:14:09 +08:00
if ( isMinimized ( ) & &
Settings : : getInstance ( ) . getShowSystemTray ( ) & &
Settings : : getInstance ( ) . getMinimizeToTray ( ) )
2014-10-20 19:50:12 +08:00
this - > hide ( ) ;
}
2014-07-03 14:43:23 +08:00
}
2014-07-01 10:12:17 +08:00
2014-11-28 17:16:37 +08:00
void Widget : : resizeEvent ( QResizeEvent * event )
{
Q_UNUSED ( event ) ;
saveWindowGeometry ( ) ;
2015-01-26 01:43:30 +08:00
emit resized ( ) ;
2014-11-28 17:16:37 +08:00
}
2014-06-25 04:11:11 +08:00
QString Widget : : getUsername ( )
{
2015-02-06 19:28:49 +08:00
return Nexus : : getCore ( ) - > getUsername ( ) ;
2014-06-25 04:11:11 +08:00
}
2014-09-24 22:51:16 +08:00
void Widget : : onSelfAvatarLoaded ( const QPixmap & pic )
{
2014-09-26 22:39:29 +08:00
profilePicture - > setPixmap ( pic ) ;
2014-09-24 22:51:16 +08:00
}
2014-06-25 04:11:11 +08:00
void Widget : : onConnected ( )
{
2014-09-03 06:01:04 +08:00
ui - > statusButton - > setEnabled ( true ) ;
2015-09-26 02:56:11 +08:00
emit statusSet ( Nexus : : getCore ( ) - > getStatus ( ) ) ;
2014-06-25 04:11:11 +08:00
}
void Widget : : onDisconnected ( )
{
2014-09-03 06:01:04 +08:00
ui - > statusButton - > setEnabled ( false ) ;
2014-06-25 04:11:11 +08:00
emit statusSet ( Status : : Offline ) ;
}
void Widget : : onFailedToStartCore ( )
{
QMessageBox critical ( this ) ;
2015-09-08 04:43:22 +08:00
critical . setText ( tr ( " toxcore failed to start, the application will terminate after you close this message. " ) ) ;
2014-06-25 04:11:11 +08:00
critical . setIcon ( QMessageBox : : Critical ) ;
critical . exec ( ) ;
qApp - > quit ( ) ;
}
2014-10-06 04:49:44 +08:00
void Widget : : onBadProxyCore ( )
{
2015-05-26 04:37:19 +08:00
Settings : : getInstance ( ) . setProxyType ( 0 ) ;
2014-10-06 04:49:44 +08:00
QMessageBox critical ( this ) ;
critical . setText ( tr ( " toxcore failed to start with your proxy settings. qTox cannot run; please modify your "
" settings and restart. " , " popup text " ) ) ;
critical . setIcon ( QMessageBox : : Critical ) ;
critical . exec ( ) ;
onSettingsClicked ( ) ;
}
2014-06-25 04:11:11 +08:00
void Widget : : onStatusSet ( Status status )
{
2015-02-12 20:18:04 +08:00
ui - > statusButton - > setProperty ( " status " , getStatusTitle ( status ) ) ;
2015-11-07 04:53:26 +08:00
ui - > statusButton - > setIcon ( prepareIcon ( getStatusIconPath ( status ) , icon_size , icon_size ) ) ;
2015-03-12 02:04:29 +08:00
updateIcons ( ) ;
2014-06-25 04:11:11 +08:00
}
2015-06-17 02:25:19 +08:00
void Widget : : onSeparateWindowClicked ( bool separate )
{
onSeparateWindowChanged ( separate , true ) ;
}
void Widget : : onSeparateWindowChanged ( bool separate , bool clicked )
{
if ( ! separate )
{
QWindowList windowList = QGuiApplication : : topLevelWindows ( ) ;
2015-06-19 22:58:48 +08:00
2015-06-17 02:25:19 +08:00
for ( QWindow * window : windowList )
{
if ( window - > objectName ( ) = = " detachedWindow " )
window - > close ( ) ;
}
QWidget * contentWidget = new QWidget ( this ) ;
contentLayout = new ContentLayout ( contentWidget ) ;
ui - > mainSplitter - > addWidget ( contentWidget ) ;
setMinimumWidth ( 775 ) ;
2015-07-03 01:16:11 +08:00
2016-04-10 16:36:14 +08:00
onAddClicked ( ) ;
2015-06-17 02:25:19 +08:00
}
else
{
2015-07-01 00:29:09 +08:00
int width = ui - > friendList - > size ( ) . width ( ) ;
2015-07-03 01:16:11 +08:00
QSize size ;
QPoint pos ;
if ( contentLayout )
{
pos = mapToGlobal ( ui - > mainSplitter - > widget ( 1 ) - > pos ( ) ) ;
size = ui - > mainSplitter - > widget ( 1 ) - > size ( ) ;
}
2015-07-01 00:29:09 +08:00
2015-06-17 02:25:19 +08:00
if ( contentLayout ! = nullptr )
{
2015-06-19 22:58:48 +08:00
contentLayout - > clear ( ) ;
contentLayout - > parentWidget ( ) - > setParent ( 0 ) ; // Remove from splitter.
2015-06-17 02:25:19 +08:00
contentLayout - > parentWidget ( ) - > hide ( ) ;
contentLayout - > parentWidget ( ) - > deleteLater ( ) ;
contentLayout - > deleteLater ( ) ;
contentLayout = nullptr ;
}
setMinimumWidth ( ui - > tooliconsZone - > sizeHint ( ) . width ( ) ) ;
if ( clicked )
2015-07-01 19:49:36 +08:00
{
showNormal ( ) ;
2015-07-01 00:29:09 +08:00
resize ( width , height ( ) ) ;
2015-07-01 19:49:36 +08:00
}
2015-06-19 22:58:48 +08:00
setWindowTitle ( QString ( ) ) ;
2015-06-23 02:01:50 +08:00
setActiveToolMenuButton ( None ) ;
2015-06-17 02:25:19 +08:00
2015-07-03 01:16:11 +08:00
if ( clicked )
{
2015-07-03 02:38:18 +08:00
ContentLayout * contentLayout = createContentDialog ( ( SettingDialog ) ) ;
2015-07-03 01:16:11 +08:00
contentLayout - > parentWidget ( ) - > resize ( size ) ;
contentLayout - > parentWidget ( ) - > move ( pos ) ;
settingsWidget - > show ( contentLayout ) ;
setActiveToolMenuButton ( Widget : : None ) ;
}
}
2015-06-17 02:25:19 +08:00
}
2014-11-15 08:28:44 +08:00
void Widget : : setWindowTitle ( const QString & title )
{
2015-06-19 22:58:48 +08:00
if ( title . isEmpty ( ) )
{
QMainWindow : : setWindowTitle ( QApplication : : applicationName ( ) ) ;
}
else
{
QString tmp = title ;
/// <[^>]*> Regexp to remove HTML tags, in case someone used them in title
QMainWindow : : setWindowTitle ( QApplication : : applicationName ( ) + QStringLiteral ( " - " ) + tmp . remove ( QRegExp ( " <[^>]*> " ) ) ) ;
}
2014-11-15 08:28:44 +08:00
}
2015-01-26 18:43:34 +08:00
void Widget : : forceShow ( )
{
2016-01-03 21:06:24 +08:00
hide ( ) ; // Workaround to force minimized window to be restored
2015-01-26 18:43:34 +08:00
show ( ) ;
activateWindow ( ) ;
}
2014-06-25 04:11:11 +08:00
void Widget : : onAddClicked ( )
{
2015-06-17 02:25:19 +08:00
if ( Settings : : getInstance ( ) . getSeparateWindow ( ) )
{
if ( ! addFriendForm - > isShown ( ) )
2015-07-03 02:38:18 +08:00
addFriendForm - > show ( createContentDialog ( AddDialog ) ) ;
2015-07-20 22:03:01 +08:00
setActiveToolMenuButton ( Widget : : None ) ;
2015-06-17 02:25:19 +08:00
}
else
{
hideMainForms ( nullptr ) ;
addFriendForm - > show ( contentLayout ) ;
2015-07-03 02:38:18 +08:00
setWindowTitle ( fromDialogType ( AddDialog ) ) ;
2015-06-17 02:25:19 +08:00
setActiveToolMenuButton ( Widget : : AddButton ) ;
}
2014-06-25 04:11:11 +08:00
}
void Widget : : onGroupClicked ( )
{
2016-02-22 07:29:12 +08:00
if ( Settings : : getInstance ( ) . getSeparateWindow ( ) )
{
if ( ! groupInviteForm - > isShown ( ) )
groupInviteForm - > show ( createContentDialog ( GroupDialog ) ) ;
setActiveToolMenuButton ( Widget : : None ) ;
}
else
{
hideMainForms ( nullptr ) ;
groupInviteForm - > show ( contentLayout ) ;
setWindowTitle ( fromDialogType ( GroupDialog ) ) ;
setActiveToolMenuButton ( Widget : : GroupButton ) ;
}
2014-06-25 04:11:11 +08:00
}
void Widget : : onTransferClicked ( )
{
2015-06-17 02:25:19 +08:00
if ( Settings : : getInstance ( ) . getSeparateWindow ( ) )
{
if ( ! filesForm - > isShown ( ) )
2015-07-03 02:38:18 +08:00
filesForm - > show ( createContentDialog ( TransferDialog ) ) ;
2015-07-20 22:03:01 +08:00
setActiveToolMenuButton ( Widget : : None ) ;
2015-06-17 02:25:19 +08:00
}
else
{
hideMainForms ( nullptr ) ;
filesForm - > show ( contentLayout ) ;
2015-07-03 02:38:18 +08:00
setWindowTitle ( fromDialogType ( TransferDialog ) ) ;
2015-06-17 02:25:19 +08:00
setActiveToolMenuButton ( Widget : : TransferButton ) ;
}
2014-06-25 04:11:11 +08:00
}
2015-10-14 04:21:20 +08:00
void Widget : : confirmExecutableOpen ( const QFileInfo & file )
2015-02-20 03:14:19 +08:00
{
2015-02-22 20:21:42 +08:00
static const QStringList dangerousExtensions = { " app " , " bat " , " com " , " cpl " , " dmg " , " exe " , " hta " , " jar " , " js " , " jse " , " lnk " , " msc " , " msh " , " msh1 " , " msh1xml " , " msh2 " , " msh2xml " , " mshxml " , " msi " , " msp " , " pif " , " ps1 " , " ps1xml " , " ps2 " , " ps2xml " , " psc1 " , " psc2 " , " py " , " reg " , " scf " , " sh " , " src " , " vb " , " vbe " , " vbs " , " ws " , " wsc " , " wsf " , " wsh " } ;
if ( dangerousExtensions . contains ( file . suffix ( ) ) )
2015-02-20 03:14:19 +08:00
{
2015-03-26 00:27:33 +08:00
if ( ! GUI : : askQuestion ( tr ( " Executable file " , " popup title " ) , tr ( " You have asked qTox to open an executable file. Executable files can potentially damage your computer. Are you sure want to open this file? " , " popup text " ) , false , true ) )
2015-02-22 20:21:42 +08:00
return ;
2015-04-24 19:01:50 +08:00
2015-02-22 20:21:42 +08:00
// The user wants to run this file, so make it executable and run it
QFile ( file . filePath ( ) ) . setPermissions ( file . permissions ( ) | QFile : : ExeOwner | QFile : : ExeUser | QFile : : ExeGroup | QFile : : ExeOther ) ;
QProcess : : startDetached ( file . filePath ( ) ) ;
}
else
{
2015-03-01 17:43:43 +08:00
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( file . filePath ( ) ) ) ;
2015-02-20 03:14:19 +08:00
}
}
2014-10-21 02:03:44 +08:00
void Widget : : onIconClick ( QSystemTrayIcon : : ActivationReason reason )
2014-10-08 22:17:05 +08:00
{
2015-11-26 01:11:31 +08:00
if ( reason = = QSystemTrayIcon : : Trigger )
2015-01-26 18:43:34 +08:00
{
2015-11-26 01:11:31 +08:00
if ( isHidden ( ) | | isMinimized ( ) )
2014-11-26 01:11:05 +08:00
{
2015-11-26 01:11:31 +08:00
if ( wasMaximized )
showMaximized ( ) ;
2015-01-26 18:43:34 +08:00
else
2015-11-26 01:11:31 +08:00
showNormal ( ) ;
2015-01-26 18:43:34 +08:00
2015-11-26 01:11:31 +08:00
activateWindow ( ) ;
}
else if ( ! isActiveWindow ( ) )
{
activateWindow ( ) ;
2014-11-26 01:11:05 +08:00
}
2015-11-26 01:11:31 +08:00
else
{
2015-03-20 03:24:06 +08:00
wasMaximized = isMaximized ( ) ;
2015-11-26 01:11:31 +08:00
hide ( ) ;
}
}
else if ( reason = = QSystemTrayIcon : : Unknown )
{
2016-01-03 06:01:41 +08:00
if ( isHidden ( ) )
2015-11-26 06:35:17 +08:00
forceShow ( ) ;
2014-10-21 02:03:44 +08:00
}
2014-10-08 22:17:05 +08:00
}
2014-06-25 04:11:11 +08:00
void Widget : : onSettingsClicked ( )
{
2015-06-17 02:25:19 +08:00
if ( Settings : : getInstance ( ) . getSeparateWindow ( ) )
{
if ( ! settingsWidget - > isShown ( ) )
2015-07-03 02:38:18 +08:00
settingsWidget - > show ( createContentDialog ( SettingDialog ) ) ;
2015-07-20 22:03:01 +08:00
setActiveToolMenuButton ( Widget : : None ) ;
2016-01-16 22:31:34 +08:00
settingsWidget - > setWindowIcon ( QIcon ( " :/img/icons/qtox.svg " ) ) ;
2015-06-17 02:25:19 +08:00
}
else
{
hideMainForms ( nullptr ) ;
settingsWidget - > show ( contentLayout ) ;
2015-07-03 02:38:18 +08:00
setWindowTitle ( fromDialogType ( SettingDialog ) ) ;
2015-06-17 02:25:19 +08:00
setActiveToolMenuButton ( Widget : : SettingButton ) ;
}
2014-06-25 04:11:11 +08:00
}
2015-03-11 10:01:13 +08:00
void Widget : : showProfile ( ) // onAvatarClicked, onUsernameClicked
{
2015-07-01 00:29:09 +08:00
if ( Settings : : getInstance ( ) . getSeparateWindow ( ) )
{
if ( ! profileForm - > isShown ( ) )
2015-07-03 02:38:18 +08:00
profileForm - > show ( createContentDialog ( ProfileDialog ) ) ;
2015-07-20 22:03:01 +08:00
setActiveToolMenuButton ( Widget : : None ) ;
2016-01-03 21:06:24 +08:00
settingsWidget - > setWindowIcon ( QIcon ( " :/img/icons/qtox.svg " ) ) ;
2015-07-01 00:29:09 +08:00
}
else
{
hideMainForms ( nullptr ) ;
profileForm - > show ( contentLayout ) ;
2015-07-03 02:38:18 +08:00
setWindowTitle ( fromDialogType ( ProfileDialog ) ) ;
2015-07-01 00:29:09 +08:00
setActiveToolMenuButton ( Widget : : None ) ;
}
2015-03-11 10:01:13 +08:00
}
2015-06-17 02:25:19 +08:00
void Widget : : hideMainForms ( GenericChatroomWidget * chatroomWidget )
2014-06-25 04:11:11 +08:00
{
2015-05-08 01:47:18 +08:00
setActiveToolMenuButton ( Widget : : None ) ;
2015-07-01 00:29:09 +08:00
if ( contentLayout ! = nullptr )
contentLayout - > clear ( ) ;
2014-10-04 16:54:50 +08:00
2014-09-02 00:20:28 +08:00
if ( activeChatroomWidget ! = nullptr )
activeChatroomWidget - > setAsInactiveChatroom ( ) ;
2015-06-17 02:25:19 +08:00
activeChatroomWidget = chatroomWidget ;
2014-06-25 04:11:11 +08:00
}
void Widget : : setUsername ( const QString & username )
{
2015-09-28 02:54:44 +08:00
if ( username . isEmpty ( ) )
{
ui - > nameLabel - > setText ( tr ( " Your name " ) ) ;
ui - > nameLabel - > setToolTip ( tr ( " Your name " ) ) ;
}
else
{
ui - > nameLabel - > setText ( username ) ;
2016-02-28 19:53:15 +08:00
ui - > nameLabel - > setToolTip ( Qt : : convertFromPlainText ( username , Qt : : WhiteSpaceNormal ) ) ; // for overlength names
2015-09-28 02:54:44 +08:00
}
2015-01-23 01:43:44 +08:00
QString sanename = username ;
sanename . remove ( QRegExp ( " [ \\ t \\ n \\ v \\ f \\ r \\ x0000] " ) ) ;
nameMention = QRegExp ( " \\ b " + QRegExp : : escape ( username ) + " \\ b " , Qt : : CaseInsensitive ) ;
sanitizedNameMention = QRegExp ( " \\ b " + QRegExp : : escape ( sanename ) + " \\ b " , Qt : : CaseInsensitive ) ;
2014-06-25 04:11:11 +08:00
}
2015-06-08 02:25:05 +08:00
void Widget : : onStatusMessageChanged ( const QString & newStatusMessage )
2014-06-25 04:11:11 +08:00
{
2015-06-08 02:25:05 +08:00
// Keep old status message until Core tells us to set it.
2015-02-06 19:28:49 +08:00
Nexus : : getCore ( ) - > setStatusMessage ( newStatusMessage ) ;
2014-06-25 04:11:11 +08:00
}
void Widget : : setStatusMessage ( const QString & statusMessage )
{
2015-09-28 02:54:44 +08:00
if ( statusMessage . isEmpty ( ) )
{
ui - > statusLabel - > setText ( tr ( " Your status " ) ) ;
ui - > statusLabel - > setToolTip ( tr ( " Your status " ) ) ;
}
else
{
ui - > statusLabel - > setText ( statusMessage ) ;
2016-02-28 19:53:15 +08:00
ui - > statusLabel - > setToolTip ( Qt : : convertFromPlainText ( statusMessage , Qt : : WhiteSpaceNormal ) ) ; // for overlength messsages
2015-09-28 02:54:44 +08:00
}
2014-06-25 04:11:11 +08:00
}
2015-02-03 07:56:51 +08:00
void Widget : : reloadHistory ( )
{
for ( auto f : FriendList : : getAllFriends ( ) )
2015-09-04 00:58:23 +08:00
f - > getChatForm ( ) - > loadHistory ( QDateTime : : currentDateTime ( ) . addDays ( - 7 ) , true ) ;
2015-02-03 07:56:51 +08:00
}
2014-06-25 04:11:11 +08:00
void Widget : : addFriend ( int friendId , const QString & userId )
{
2015-05-18 04:55:50 +08:00
ToxId userToxId = ToxId ( userId ) ;
2014-11-16 22:48:18 +08:00
Friend * newfriend = FriendList : : addFriend ( friendId , userToxId ) ;
2015-06-24 02:58:30 +08:00
QDate activityDate = Settings : : getInstance ( ) . getFriendActivity ( newfriend - > getToxId ( ) ) ;
QDate chatDate = newfriend - > getChatForm ( ) - > getLatestDate ( ) ;
if ( chatDate > activityDate & & chatDate . isValid ( ) )
Settings : : getInstance ( ) . setFriendActivity ( newfriend - > getToxId ( ) , chatDate ) ;
2015-11-11 03:20:07 +08:00
contactListWidget - > addFriendWidget ( newfriend - > getFriendWidget ( ) , Status : : Offline , Settings : : getInstance ( ) . getFriendCircleID ( newfriend - > getToxId ( ) ) ) ;
2014-11-07 22:55:32 +08:00
2015-02-06 19:28:49 +08:00
Core * core = Nexus : : getCore ( ) ;
2015-09-28 01:59:26 +08:00
CoreAV * coreav = core - > getAv ( ) ;
2015-06-08 02:25:05 +08:00
connect ( newfriend , & Friend : : displayedNameChanged , this , & Widget : : onFriendDisplayChanged ) ;
2015-06-11 00:11:50 +08:00
connect ( settingsWidget , & SettingsWidget : : compactToggled , newfriend - > getFriendWidget ( ) , & GenericChatroomWidget : : compactChange ) ;
2015-11-11 03:20:07 +08:00
connect ( newfriend - > getFriendWidget ( ) , SIGNAL ( chatroomWidgetClicked ( GenericChatroomWidget * , bool ) ) , this , SLOT ( onChatroomWidgetClicked ( GenericChatroomWidget * , bool ) ) ) ;
2014-11-06 23:26:22 +08:00
connect ( newfriend - > getFriendWidget ( ) , SIGNAL ( removeFriend ( int ) ) , this , SLOT ( removeFriend ( int ) ) ) ;
connect ( newfriend - > getFriendWidget ( ) , SIGNAL ( copyFriendIdToClipboard ( int ) ) , this , SLOT ( copyFriendIdToClipboard ( int ) ) ) ;
connect ( newfriend - > getFriendWidget ( ) , SIGNAL ( chatroomWidgetClicked ( GenericChatroomWidget * ) ) , newfriend - > getChatForm ( ) , SLOT ( focusInput ( ) ) ) ;
2015-04-20 05:12:44 +08:00
connect ( newfriend - > getChatForm ( ) , & GenericChatForm : : sendMessage , core , & Core : : sendMessage ) ;
2014-11-06 23:26:22 +08:00
connect ( newfriend - > getChatForm ( ) , & GenericChatForm : : sendAction , core , & Core : : sendAction ) ;
2015-04-20 05:12:44 +08:00
connect ( newfriend - > getChatForm ( ) , & ChatForm : : sendFile , core , & Core : : sendFile ) ;
2014-11-18 10:15:44 +08:00
connect ( newfriend - > getChatForm ( ) , & ChatForm : : aliasChanged , newfriend - > getFriendWidget ( ) , & FriendWidget : : setAlias ) ;
2014-11-06 23:26:22 +08:00
connect ( core , & Core : : fileReceiveRequested , newfriend - > getChatForm ( ) , & ChatForm : : onFileRecvRequest ) ;
2015-10-08 06:52:05 +08:00
connect ( coreav , & CoreAV : : avInvite , newfriend - > getChatForm ( ) , & ChatForm : : onAvInvite , Qt : : BlockingQueuedConnection ) ;
connect ( coreav , & CoreAV : : avStart , newfriend - > getChatForm ( ) , & ChatForm : : onAvStart , Qt : : BlockingQueuedConnection ) ;
connect ( coreav , & CoreAV : : avEnd , newfriend - > getChatForm ( ) , & ChatForm : : onAvEnd , Qt : : BlockingQueuedConnection ) ;
2014-11-06 23:26:22 +08:00
connect ( core , & Core : : friendAvatarChanged , newfriend - > getChatForm ( ) , & ChatForm : : onAvatarChange ) ;
connect ( core , & Core : : friendAvatarChanged , newfriend - > getFriendWidget ( ) , & FriendWidget : : onAvatarChange ) ;
connect ( core , & Core : : friendAvatarRemoved , newfriend - > getChatForm ( ) , & ChatForm : : onAvatarRemoved ) ;
connect ( core , & Core : : friendAvatarRemoved , newfriend - > getFriendWidget ( ) , & FriendWidget : : onAvatarRemoved ) ;
2014-09-24 23:55:54 +08:00
// Try to get the avatar from the cache
2015-12-06 02:08:28 +08:00
QPixmap avatar = Nexus : : getProfile ( ) - > loadAvatar ( userId ) ;
2014-09-24 23:55:54 +08:00
if ( ! avatar . isNull ( ) )
{
2014-11-06 23:26:22 +08:00
newfriend - > getChatForm ( ) - > onAvatarChange ( friendId , avatar ) ;
newfriend - > getFriendWidget ( ) - > onAvatarChange ( friendId , avatar ) ;
2014-09-24 23:55:54 +08:00
}
2015-04-09 00:18:07 +08:00
2015-06-13 00:09:01 +08:00
int filter = getFilterCriteria ( ) ;
2015-06-07 11:20:06 +08:00
newfriend - > getFriendWidget ( ) - > search ( ui - > searchContactText - > text ( ) , filterOffline ( filter ) ) ;
2015-06-24 02:58:30 +08:00
2014-06-27 01:45:47 +08:00
}
2014-11-10 03:23:43 +08:00
void Widget : : addFriendFailed ( const QString & , const QString & errorInfo )
2014-06-27 01:45:47 +08:00
{
2014-11-10 08:04:35 +08:00
QString info = QString ( tr ( " Couldn't request friendship " ) ) ;
2014-12-12 02:05:52 +08:00
if ( ! errorInfo . isEmpty ( ) ) {
2014-11-10 03:23:43 +08:00
info = info + ( QString ( " : " ) + errorInfo ) ;
}
QMessageBox : : critical ( 0 , " Error " , info ) ;
2014-06-25 04:11:11 +08:00
}
2015-06-15 21:48:34 +08:00
void Widget : : onFriendshipChanged ( int friendId )
{
Friend * who = FriendList : : findFriend ( friendId ) ;
updateFriendActivity ( who ) ;
}
2014-06-25 04:11:11 +08:00
void Widget : : onFriendStatusChanged ( int friendId , Status status )
{
Friend * f = FriendList : : findFriend ( friendId ) ;
if ( ! f )
return ;
2015-03-26 00:27:33 +08:00
2014-11-09 09:01:02 +08:00
bool isActualChange = f - > getStatus ( ) ! = status ;
2015-03-26 00:27:33 +08:00
if ( isActualChange )
2015-03-23 17:38:24 +08:00
{
2015-03-26 00:27:33 +08:00
if ( f - > getStatus ( ) = = Status : : Offline )
2015-04-20 05:12:44 +08:00
contactListWidget - > moveWidget ( f - > getFriendWidget ( ) , Status : : Online ) ;
2015-03-26 00:27:33 +08:00
else if ( status = = Status : : Offline )
2015-04-20 05:12:44 +08:00
contactListWidget - > moveWidget ( f - > getFriendWidget ( ) , Status : : Offline ) ;
2015-03-12 08:30:01 +08:00
}
2014-11-06 23:26:22 +08:00
f - > setStatus ( status ) ;
f - > getFriendWidget ( ) - > updateStatusLight ( ) ;
2015-03-26 03:08:46 +08:00
if ( f - > getFriendWidget ( ) - > isActive ( ) )
2015-07-03 01:16:11 +08:00
setWindowTitle ( f - > getFriendWidget ( ) - > getTitle ( ) ) ;
2015-04-24 19:01:50 +08:00
2015-06-23 02:01:50 +08:00
ContentDialog : : updateFriendStatus ( friendId ) ;
2014-10-18 07:06:30 +08:00
//won't print the message if there were no messages before
2014-12-12 02:05:52 +08:00
if ( ! f - > getChatForm ( ) - > isEmpty ( )
2014-11-10 16:09:20 +08:00
& & Settings : : getInstance ( ) . getStatusChangeNotificationEnabled ( ) )
2014-10-18 07:06:30 +08:00
{
QString fStatus = " " ;
2015-03-21 16:59:28 +08:00
switch ( f - > getStatus ( ) )
2015-04-24 19:01:50 +08:00
{
2014-10-18 07:06:30 +08:00
case Status : : Away :
fStatus = tr ( " away " , " contact status " ) ; break ;
case Status : : Busy :
fStatus = tr ( " busy " , " contact status " ) ; break ;
case Status : : Offline :
2015-02-18 21:02:10 +08:00
fStatus = tr ( " offline " , " contact status " ) ;
f - > getChatForm ( ) - > setFriendTyping ( false ) ; // Hide the "is typing" message when a friend goes offline
break ;
2014-10-18 07:06:30 +08:00
default :
fStatus = tr ( " online " , " contact status " ) ; break ;
}
2014-11-09 09:01:02 +08:00
if ( isActualChange )
f - > getChatForm ( ) - > addSystemInfoMessage ( tr ( " %1 is now %2 " , " e.g. \" Dubslow is now online \" " ) . arg ( f - > getDisplayedName ( ) ) . arg ( fStatus ) ,
2015-01-05 01:21:35 +08:00
ChatMessage : : INFO , QDateTime : : currentDateTime ( ) ) ;
2014-10-18 07:06:30 +08:00
}
2014-11-10 19:30:56 +08:00
if ( isActualChange & & status ! = Status : : Offline )
{ // wait a little
2015-02-08 00:18:25 +08:00
QTimer : : singleShot ( 250 , f - > getChatForm ( ) - > getOfflineMsgEngine ( ) , SLOT ( deliverOfflineMsgs ( ) ) ) ;
2014-11-10 19:30:56 +08:00
}
2014-06-25 04:11:11 +08:00
}
void Widget : : onFriendStatusMessageChanged ( int friendId , const QString & message )
{
Friend * f = FriendList : : findFriend ( friendId ) ;
if ( ! f )
return ;
2014-09-29 02:09:10 +08:00
QString str = message ; str . replace ( ' \n ' , ' ' ) ;
str . remove ( ' \r ' ) ; str . remove ( QChar ( ( char ) 0 ) ) ; // null terminator...
f - > setStatusMessage ( str ) ;
2015-06-23 02:01:50 +08:00
ContentDialog : : updateFriendStatusMessage ( friendId , message ) ;
2014-06-25 04:11:11 +08:00
}
void Widget : : onFriendUsernameChanged ( int friendId , const QString & username )
{
Friend * f = FriendList : : findFriend ( friendId ) ;
if ( ! f )
return ;
2014-09-29 02:09:10 +08:00
QString str = username ; str . replace ( ' \n ' , ' ' ) ;
str . remove ( ' \r ' ) ; str . remove ( QChar ( ( char ) 0 ) ) ; // null terminator...
f - > setName ( str ) ;
2015-06-08 02:25:05 +08:00
}
void Widget : : onFriendDisplayChanged ( FriendWidget * friendWidget , Status s )
{
contactListWidget - > moveWidget ( friendWidget , s ) ;
2015-06-13 00:09:01 +08:00
int filter = getFilterCriteria ( ) ;
2015-06-08 02:25:05 +08:00
switch ( s )
{
case Status : : Offline :
friendWidget - > searchName ( ui - > searchContactText - > text ( ) , filterOffline ( filter ) ) ;
default :
friendWidget - > searchName ( ui - > searchContactText - > text ( ) , filterOnline ( filter ) ) ;
}
2015-06-07 11:20:06 +08:00
2014-06-25 04:11:11 +08:00
}
2015-06-23 02:01:50 +08:00
void Widget : : onChatroomWidgetClicked ( GenericChatroomWidget * widget , bool group )
2014-06-25 04:11:11 +08:00
{
2015-06-23 02:01:50 +08:00
widget - > resetEventFlags ( ) ;
widget - > updateStatusLight ( ) ;
2015-06-27 02:43:08 +08:00
if ( widget - > chatFormIsSet ( true ) & & ! group )
2015-06-23 02:01:50 +08:00
return ;
if ( Settings : : getInstance ( ) . getSeparateWindow ( ) | | group )
2015-06-17 02:25:19 +08:00
{
2015-06-23 02:01:50 +08:00
ContentDialog * dialog = nullptr ;
2015-06-19 22:58:48 +08:00
2015-06-23 02:01:50 +08:00
if ( ! Settings : : getInstance ( ) . getDontGroupWindows ( ) & & ! group )
dialog = ContentDialog : : current ( ) ;
2015-06-19 22:58:48 +08:00
2015-06-23 02:01:50 +08:00
if ( dialog = = nullptr )
2015-07-01 00:29:09 +08:00
dialog = createContentDialog ( ) ;
2015-06-19 22:58:48 +08:00
2015-06-23 02:01:50 +08:00
dialog - > show ( ) ;
Friend * frnd = widget - > getFriend ( ) ;
if ( frnd ! = nullptr )
{
addFriendDialog ( frnd , dialog ) ;
}
else
{
Group * group = widget - > getGroup ( ) ;
addGroupDialog ( group , dialog ) ;
2015-06-19 22:58:48 +08:00
}
2015-06-23 02:01:50 +08:00
dialog - > raise ( ) ;
dialog - > activateWindow ( ) ;
2015-06-17 02:25:19 +08:00
}
else
{
2015-06-19 22:58:48 +08:00
hideMainForms ( widget ) ;
2015-06-17 02:25:19 +08:00
widget - > setChatForm ( contentLayout ) ;
widget - > setAsActiveChatroom ( ) ;
2015-06-23 02:01:50 +08:00
setWindowTitle ( widget - > getTitle ( ) ) ;
2015-06-17 02:25:19 +08:00
}
2014-06-25 04:11:11 +08:00
}
2014-10-02 14:01:23 +08:00
void Widget : : onFriendMessageReceived ( int friendId , const QString & message , bool isAction )
2014-06-25 04:11:11 +08:00
{
Friend * f = FriendList : : findFriend ( friendId ) ;
if ( ! f )
return ;
2014-10-14 13:49:27 +08:00
QDateTime timestamp = QDateTime : : currentDateTime ( ) ;
2015-05-24 02:58:41 +08:00
f - > getChatForm ( ) - > addMessage ( f - > getToxId ( ) , message , isAction , timestamp , true ) ;
2014-10-14 22:36:17 +08:00
2015-12-31 21:36:12 +08:00
Profile * profile = Nexus : : getProfile ( ) ;
if ( profile - > isHistoryEnabled ( ) )
profile - > getHistory ( ) - > addNewMessage ( f - > getToxId ( ) . publicKey , isAction ? " /me " + f - > getDisplayedName ( ) + " " + message : message ,
2015-08-28 05:07:24 +08:00
f - > getToxId ( ) . publicKey , timestamp , true , f - > getDisplayedName ( ) ) ;
2014-06-28 00:12:43 +08:00
2015-06-23 02:01:50 +08:00
newFriendMessageAlert ( friendId ) ;
2014-06-25 04:11:11 +08:00
}
2014-11-01 22:19:11 +08:00
void Widget : : onReceiptRecieved ( int friendId , int receipt )
{
Friend * f = FriendList : : findFriend ( friendId ) ;
if ( ! f )
return ;
2015-02-08 00:18:25 +08:00
f - > getChatForm ( ) - > getOfflineMsgEngine ( ) - > dischargeReceipt ( receipt ) ;
2014-11-01 22:19:11 +08:00
}
2015-06-23 02:01:50 +08:00
void Widget : : addFriendDialog ( Friend * frnd , ContentDialog * dialog )
{
2015-06-27 02:43:08 +08:00
if ( ! ContentDialog : : getFriendDialog ( frnd - > getFriendID ( ) ) & & ! Settings : : getInstance ( ) . getSeparateWindow ( ) & & activeChatroomWidget = = frnd - > getFriendWidget ( ) )
onAddClicked ( ) ;
2015-06-23 02:01:50 +08:00
FriendWidget * friendWidget = dialog - > addFriend ( frnd - > getFriendID ( ) , frnd - > getDisplayedName ( ) ) ;
friendWidget - > setStatusMsg ( frnd - > getFriendWidget ( ) - > getStatusMsg ( ) ) ;
connect ( friendWidget , SIGNAL ( removeFriend ( int ) ) , this , SLOT ( removeFriend ( int ) ) ) ;
connect ( friendWidget , SIGNAL ( copyFriendIdToClipboard ( int ) ) , this , SLOT ( copyFriendIdToClipboard ( int ) ) ) ;
connect ( Core : : getInstance ( ) , & Core : : friendAvatarChanged , friendWidget , & FriendWidget : : onAvatarChange ) ;
connect ( Core : : getInstance ( ) , & Core : : friendAvatarRemoved , friendWidget , & FriendWidget : : onAvatarRemoved ) ;
2015-12-06 02:08:28 +08:00
QPixmap avatar = Nexus : : getProfile ( ) - > loadAvatar ( frnd - > getToxId ( ) . toString ( ) ) ;
2015-06-23 02:01:50 +08:00
if ( ! avatar . isNull ( ) )
friendWidget - > onAvatarChange ( frnd - > getFriendID ( ) , avatar ) ;
}
void Widget : : addGroupDialog ( Group * group , ContentDialog * dialog )
{
2015-07-20 22:33:07 +08:00
if ( ! ContentDialog : : getGroupDialog ( group - > getGroupId ( ) ) & & ! Settings : : getInstance ( ) . getSeparateWindow ( ) & & activeChatroomWidget = = group - > getGroupWidget ( ) )
onAddClicked ( ) ;
2015-06-23 02:01:50 +08:00
GroupWidget * groupWidget = dialog - > addGroup ( group - > getGroupId ( ) , group - > getName ( ) ) ;
connect ( groupWidget , SIGNAL ( removeGroup ( int ) ) , this , SLOT ( removeGroup ( int ) ) ) ;
connect ( groupWidget , SIGNAL ( chatroomWidgetClicked ( GenericChatroomWidget * ) ) , group - > getChatForm ( ) , SLOT ( focusInput ( ) ) ) ;
}
2015-10-24 08:26:32 +08:00
bool Widget : : newFriendMessageAlert ( int friendId , bool sound )
2015-06-23 02:01:50 +08:00
{
bool hasActive ;
QWidget * currentWindow ;
ContentDialog * contentDialog = ContentDialog : : getFriendDialog ( friendId ) ;
2015-06-24 00:54:00 +08:00
Friend * f = FriendList : : findFriend ( friendId ) ;
2015-06-23 02:01:50 +08:00
if ( contentDialog ! = nullptr )
{
currentWindow = contentDialog - > window ( ) ;
hasActive = ContentDialog : : isFriendWidgetActive ( friendId ) ;
}
else
{
currentWindow = window ( ) ;
2015-06-24 00:54:00 +08:00
hasActive = f - > getFriendWidget ( ) = = activeChatroomWidget ;
2015-06-23 02:01:50 +08:00
}
2015-10-24 08:26:32 +08:00
if ( newMessageAlert ( currentWindow , hasActive , sound ) )
2015-06-24 00:54:00 +08:00
{
f - > setEventFlag ( true ) ;
f - > getFriendWidget ( ) - > updateStatusLight ( ) ;
if ( contentDialog = = nullptr )
{
if ( hasActive )
setWindowTitle ( f - > getFriendWidget ( ) - > getTitle ( ) ) ;
}
else
{
ContentDialog : : updateFriendStatus ( friendId ) ;
}
return true ;
}
return false ;
2015-06-23 02:01:50 +08:00
}
2015-07-30 21:37:52 +08:00
bool Widget : : newGroupMessageAlert ( int groupId , bool notify )
2015-06-23 02:01:50 +08:00
{
bool hasActive ;
QWidget * currentWindow ;
ContentDialog * contentDialog = ContentDialog : : getGroupDialog ( groupId ) ;
2015-07-20 22:03:01 +08:00
Group * g = GroupList : : findGroup ( groupId ) ;
2015-06-23 02:01:50 +08:00
if ( contentDialog ! = nullptr )
{
currentWindow = contentDialog - > window ( ) ;
hasActive = ContentDialog : : isGroupWidgetActive ( groupId ) ;
}
else
{
currentWindow = window ( ) ;
2015-07-20 22:03:01 +08:00
hasActive = g - > getGroupWidget ( ) = = activeChatroomWidget ;
2015-06-23 02:01:50 +08:00
}
2015-10-24 08:26:32 +08:00
if ( newMessageAlert ( currentWindow , hasActive , true , notify ) )
2015-07-20 22:03:01 +08:00
{
g - > setEventFlag ( true ) ;
g - > getGroupWidget ( ) - > updateStatusLight ( ) ;
if ( contentDialog = = nullptr )
{
if ( hasActive )
setWindowTitle ( g - > getGroupWidget ( ) - > getTitle ( ) ) ;
}
else
{
ContentDialog : : updateGroupStatus ( groupId ) ;
}
return true ;
}
return false ;
2015-06-23 02:01:50 +08:00
}
2015-07-03 02:38:18 +08:00
QString Widget : : fromDialogType ( DialogType type )
{
switch ( type )
{
case AddDialog :
return tr ( " Add friend " ) ;
2016-02-22 07:29:12 +08:00
case GroupDialog :
return tr ( " Group invites " ) ;
2015-07-03 02:38:18 +08:00
case TransferDialog :
return tr ( " File transfers " ) ;
case SettingDialog :
return tr ( " Settings " ) ;
case ProfileDialog :
return tr ( " Profile " ) ;
default :
return QString ( ) ;
}
}
2015-10-24 08:26:32 +08:00
bool Widget : : newMessageAlert ( QWidget * currentWindow , bool isActive , bool sound , bool notify )
2014-06-28 05:36:44 +08:00
{
2015-07-01 21:22:05 +08:00
bool inactiveWindow = isMinimized ( ) | | ! currentWindow - > isActiveWindow ( ) ;
2015-06-23 02:01:50 +08:00
if ( ! inactiveWindow & & isActive )
2015-06-24 00:54:00 +08:00
return false ;
2015-04-24 19:01:50 +08:00
2015-07-30 21:37:52 +08:00
if ( notify )
2014-08-30 21:15:23 +08:00
{
2015-12-16 01:03:05 +08:00
if ( inactiveWindow )
{
QApplication : : alert ( currentWindow ) ;
eventFlag = true ;
}
2015-03-22 08:57:28 +08:00
2015-07-30 21:37:52 +08:00
if ( Settings : : getInstance ( ) . getShowWindow ( ) )
2015-03-22 08:57:28 +08:00
{
2015-07-30 21:37:52 +08:00
currentWindow - > show ( ) ;
if ( inactiveWindow & & Settings : : getInstance ( ) . getShowInFront ( ) )
currentWindow - > activateWindow ( ) ;
2015-03-22 08:57:28 +08:00
}
2014-08-30 21:15:23 +08:00
2015-10-24 08:26:32 +08:00
if ( Settings : : getInstance ( ) . getNotifySound ( ) & & sound )
2015-11-15 09:38:16 +08:00
Audio : : getInstance ( ) . playMono16Sound ( QStringLiteral ( " :/audio/notification.pcm " ) ) ;
2015-03-22 08:57:28 +08:00
}
2015-06-24 00:54:00 +08:00
return true ;
2014-06-28 05:36:44 +08:00
}
2014-06-25 04:11:11 +08:00
void Widget : : onFriendRequestReceived ( const QString & userId , const QString & message )
{
2016-02-25 23:46:40 +08:00
if ( addFriendForm - > addFriendRequest ( userId , message ) )
{
friendRequestsUpdate ( ) ;
newMessageAlert ( window ( ) , isActiveWindow ( ) , true , true ) ;
}
2014-06-25 04:11:11 +08:00
}
2015-06-12 21:53:44 +08:00
void Widget : : updateFriendActivity ( Friend * frnd )
{
QDate date = Settings : : getInstance ( ) . getFriendActivity ( frnd - > getToxId ( ) ) ;
if ( date ! = QDate : : currentDate ( ) )
{
2015-07-01 21:10:55 +08:00
// Update old activity before after new one. Store old date first.
QDate oldDate = Settings : : getInstance ( ) . getFriendActivity ( frnd - > getToxId ( ) ) ;
2015-06-12 21:53:44 +08:00
Settings : : getInstance ( ) . setFriendActivity ( frnd - > getToxId ( ) , QDate : : currentDate ( ) ) ;
contactListWidget - > moveWidget ( frnd - > getFriendWidget ( ) , frnd - > getStatus ( ) ) ;
2015-07-01 21:10:55 +08:00
contactListWidget - > updateActivityDate ( oldDate ) ;
2015-06-12 21:53:44 +08:00
}
}
2014-11-12 07:00:24 +08:00
void Widget : : removeFriend ( Friend * f , bool fake )
2015-05-12 04:48:32 +08:00
{
if ( ! fake )
{
2015-08-22 17:05:16 +08:00
RemoveFriendDialog ask ( this , f ) ;
ask . exec ( ) ;
if ( ! ask . accepted ( ) )
2015-05-12 04:48:32 +08:00
return ;
2015-08-22 17:05:16 +08:00
else if ( ask . removeHistory ( ) )
2015-12-17 18:24:01 +08:00
Nexus : : getProfile ( ) - > getHistory ( ) - > removeFriendHistory ( f - > getToxId ( ) . publicKey ) ;
2015-05-12 04:48:32 +08:00
}
2015-06-06 09:40:08 +08:00
2014-11-06 23:26:22 +08:00
f - > getFriendWidget ( ) - > setAsInactiveChatroom ( ) ;
2015-07-03 01:16:11 +08:00
if ( f - > getFriendWidget ( ) = = activeChatroomWidget )
2014-11-12 06:27:30 +08:00
{
2014-09-02 00:20:28 +08:00
activeChatroomWidget = nullptr ;
2014-11-12 06:27:30 +08:00
onAddClicked ( ) ;
}
2015-06-06 09:40:08 +08:00
2015-06-15 21:48:34 +08:00
contactListWidget - > removeFriendWidget ( f - > getFriendWidget ( ) ) ;
2015-07-01 22:19:15 +08:00
ContentDialog * lastDialog = ContentDialog : : getFriendDialog ( f - > getFriendID ( ) ) ;
if ( lastDialog ! = nullptr )
lastDialog - > removeFriend ( f - > getFriendID ( ) ) ;
2014-11-12 07:00:24 +08:00
FriendList : : removeFriend ( f - > getFriendID ( ) , fake ) ;
2015-02-06 19:28:49 +08:00
Nexus : : getCore ( ) - > removeFriend ( f - > getFriendID ( ) , fake ) ;
2015-06-06 09:40:08 +08:00
2014-06-25 04:11:11 +08:00
delete f ;
2015-07-01 22:19:15 +08:00
if ( contentLayout ! = nullptr & & contentLayout - > mainHead - > layout ( ) - > isEmpty ( ) )
2014-06-25 04:11:11 +08:00
onAddClicked ( ) ;
2014-11-02 16:45:44 +08:00
2015-06-03 18:26:48 +08:00
contactListWidget - > reDraw ( ) ;
2014-06-25 04:11:11 +08:00
}
2014-07-23 17:22:09 +08:00
void Widget : : removeFriend ( int friendId )
{
2014-11-12 07:00:24 +08:00
removeFriend ( FriendList : : findFriend ( friendId ) , false ) ;
2014-07-23 17:22:09 +08:00
}
2014-10-09 16:07:26 +08:00
void Widget : : clearContactsList ( )
{
2015-06-04 22:36:08 +08:00
assert ( QThread : : currentThread ( ) = = qApp - > thread ( ) ) ;
2014-11-07 22:55:32 +08:00
QList < Friend * > friends = FriendList : : getAllFriends ( ) ;
for ( Friend * f : friends )
2014-11-12 07:00:24 +08:00
removeFriend ( f , true ) ;
2014-11-20 17:13:13 +08:00
QList < Group * > groups = GroupList : : getAllGroups ( ) ;
for ( Group * g : groups )
2014-11-12 07:00:24 +08:00
removeGroup ( g , true ) ;
2014-10-09 16:07:26 +08:00
}
2015-07-01 00:29:09 +08:00
ContentDialog * Widget : : createContentDialog ( ) const
{
2015-07-30 07:46:19 +08:00
ContentDialog * contentDialog = new ContentDialog ( settingsWidget ) ;
contentDialog - > show ( ) ;
# ifdef Q_OS_MAC
connect ( contentDialog , & ContentDialog : : destroyed , & Nexus : : getInstance ( ) , & Nexus : : updateWindowsClosed ) ;
connect ( contentDialog , & ContentDialog : : windowStateChanged , & Nexus : : getInstance ( ) , & Nexus : : onWindowStateChanged ) ;
connect ( contentDialog - > windowHandle ( ) , & QWindow : : windowTitleChanged , & Nexus : : getInstance ( ) , & Nexus : : updateWindows ) ;
Nexus : : getInstance ( ) . updateWindows ( ) ;
# endif
return contentDialog ;
2015-07-01 00:29:09 +08:00
}
2015-07-30 07:46:19 +08:00
ContentLayout * Widget : : createContentDialog ( DialogType type )
2015-06-17 02:25:19 +08:00
{
2015-07-30 07:46:19 +08:00
class Dialog : public ActivateDialog
2015-07-03 01:16:11 +08:00
{
public :
2015-07-03 02:38:18 +08:00
Dialog ( DialogType type )
2015-07-30 07:46:19 +08:00
: ActivateDialog ( )
2015-07-03 02:38:18 +08:00
, type ( type )
2015-07-03 01:16:11 +08:00
{
restoreGeometry ( Settings : : getInstance ( ) . getDialogSettingsGeometry ( ) ) ;
2015-07-03 02:38:18 +08:00
Translator : : registerHandler ( std : : bind ( & Dialog : : retranslateUi , this ) , this ) ;
retranslateUi ( ) ;
connect ( Core : : getInstance ( ) , & Core : : usernameSet , this , & Dialog : : retranslateUi ) ;
}
~ Dialog ( )
{
Translator : : unregister ( this ) ;
}
public slots :
void retranslateUi ( )
{
setWindowTitle ( Core : : getInstance ( ) - > getUsername ( ) + QStringLiteral ( " - " ) + Widget : : fromDialogType ( type ) ) ;
2016-01-16 22:31:34 +08:00
setWindowIcon ( QIcon ( " :/img/icons/qtox.svg " ) ) ;
2015-07-03 01:16:11 +08:00
}
protected :
void resizeEvent ( QResizeEvent * event ) override
{
Settings : : getInstance ( ) . setDialogSettingsGeometry ( saveGeometry ( ) ) ;
QDialog : : resizeEvent ( event ) ;
}
void moveEvent ( QMoveEvent * event ) override
{
Settings : : getInstance ( ) . setDialogSettingsGeometry ( saveGeometry ( ) ) ;
QDialog : : moveEvent ( event ) ;
}
2015-07-03 02:38:18 +08:00
private :
DialogType type ;
2015-07-03 01:16:11 +08:00
} ;
2015-07-30 07:46:19 +08:00
Dialog * dialog = new Dialog ( type ) ;
2015-07-03 01:16:11 +08:00
dialog - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
ContentLayout * contentLayoutDialog = new ContentLayout ( dialog ) ;
2015-06-17 02:25:19 +08:00
dialog - > setObjectName ( " detached " ) ;
2015-07-03 01:16:11 +08:00
dialog - > setLayout ( contentLayoutDialog ) ;
2015-06-17 02:25:19 +08:00
dialog - > layout ( ) - > setMargin ( 0 ) ;
dialog - > layout ( ) - > setSpacing ( 0 ) ;
2015-07-01 21:22:05 +08:00
dialog - > setMinimumSize ( 720 , 400 ) ;
2015-06-17 02:25:19 +08:00
dialog - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
dialog - > show ( ) ;
2015-07-30 07:46:19 +08:00
# ifdef Q_OS_MAC
connect ( dialog , & Dialog : : destroyed , & Nexus : : getInstance ( ) , & Nexus : : updateWindowsClosed ) ;
connect ( dialog , & ActivateDialog : : windowStateChanged , & Nexus : : getInstance ( ) , & Nexus : : updateWindowsStates ) ;
connect ( dialog - > windowHandle ( ) , & QWindow : : windowTitleChanged , & Nexus : : getInstance ( ) , & Nexus : : updateWindows ) ;
Nexus : : getInstance ( ) . updateWindows ( ) ;
# endif
2015-07-03 01:16:11 +08:00
return contentLayoutDialog ;
2015-06-17 02:25:19 +08:00
}
2014-07-02 05:50:07 +08:00
void Widget : : copyFriendIdToClipboard ( int friendId )
{
Friend * f = FriendList : : findFriend ( friendId ) ;
if ( f ! = nullptr )
{
QClipboard * clipboard = QApplication : : clipboard ( ) ;
2015-02-06 19:28:49 +08:00
clipboard - > setText ( Nexus : : getCore ( ) - > getFriendAddress ( f - > getFriendID ( ) ) , QClipboard : : Clipboard ) ;
2014-07-02 05:50:07 +08:00
}
}
2014-11-13 07:13:11 +08:00
void Widget : : onGroupInviteReceived ( int32_t friendId , uint8_t type , QByteArray invite )
2014-06-25 04:11:11 +08:00
{
2016-03-22 04:56:52 +08:00
updateFriendActivity ( FriendList : : findFriend ( friendId ) ) ;
2014-11-11 23:05:01 +08:00
if ( type = = TOX_GROUPCHAT_TYPE_TEXT | | type = = TOX_GROUPCHAT_TYPE_AV )
2014-06-25 04:11:11 +08:00
{
2016-02-21 05:32:57 +08:00
+ + unreadGroupInvites ;
groupInvitesUpdate ( ) ;
2016-02-25 21:16:26 +08:00
newMessageAlert ( window ( ) , isActiveWindow ( ) , true , true ) ;
2016-02-21 05:32:57 +08:00
groupInviteForm - > addGroupInvite ( friendId , type , invite ) ;
2014-11-11 23:05:01 +08:00
}
else
{
2015-05-11 20:54:03 +08:00
qWarning ( ) < < " onGroupInviteReceived: Unknown groupchat type: " < < type ;
2014-06-25 04:11:11 +08:00
return ;
}
}
2016-02-21 05:32:57 +08:00
void Widget : : onGroupInviteAccepted ( int32_t friendId , uint8_t type , QByteArray invite )
{
int groupId = Nexus : : getCore ( ) - > joinGroupchat ( friendId , type , ( uint8_t * ) invite . data ( ) , invite . length ( ) ) ;
if ( groupId < 0 )
{
qWarning ( ) < < " onGroupInviteAccepted: Unable to accept group invite " ;
return ;
}
}
2014-11-23 23:55:49 +08:00
void Widget : : onGroupMessageReceived ( int groupnumber , int peernumber , const QString & message , bool isAction )
2014-06-25 04:11:11 +08:00
{
Group * g = GroupList : : findGroup ( groupnumber ) ;
if ( ! g )
return ;
2015-05-24 02:58:41 +08:00
ToxId author = Core : : getInstance ( ) - > getGroupPeerToxId ( groupnumber , peernumber ) ;
2016-03-22 04:56:52 +08:00
2015-12-17 18:24:01 +08:00
bool targeted = ! author . isSelf ( ) & & ( message . contains ( nameMention ) | | message . contains ( sanitizedNameMention ) ) ;
2014-12-04 01:47:07 +08:00
if ( targeted & & ! isAction )
2014-11-23 23:22:29 +08:00
g - > getChatForm ( ) - > addAlertMessage ( author , message , QDateTime : : currentDateTime ( ) ) ;
2014-10-20 19:05:45 +08:00
else
2014-11-23 23:55:49 +08:00
g - > getChatForm ( ) - > addMessage ( author , message , isAction , QDateTime : : currentDateTime ( ) , true ) ;
2014-06-28 07:10:02 +08:00
2015-07-30 21:37:52 +08:00
newGroupMessageAlert ( g - > getGroupId ( ) , targeted | | Settings : : getInstance ( ) . getGroupAlwaysNotify ( ) ) ;
2014-06-25 04:11:11 +08:00
}
void Widget : : onGroupNamelistChanged ( int groupnumber , int peernumber , uint8_t Change )
{
Group * g = GroupList : : findGroup ( groupnumber ) ;
if ( ! g )
{
2015-05-11 20:54:03 +08:00
qDebug ( ) < < " onGroupNamelistChanged: Group " < < groupnumber < < " not found, creating it " ;
2014-06-25 04:11:11 +08:00
g = createGroup ( groupnumber ) ;
}
TOX_CHAT_CHANGE change = static_cast < TOX_CHAT_CHANGE > ( Change ) ;
if ( change = = TOX_CHAT_CHANGE_PEER_ADD )
2014-09-12 00:05:02 +08:00
{
2014-11-23 23:22:29 +08:00
// g->addPeer(peernumber,name);
g - > regeneratePeerList ( ) ;
2015-01-03 03:29:39 +08:00
// g->getChatForm()->addSystemInfoMessage(tr("%1 has joined the chat").arg(name), "white", QDateTime::currentDateTime());
2014-10-20 19:34:17 +08:00
// we can't display these messages until irungentoo fixes peernumbers
// https://github.com/irungentoo/toxcore/issues/1128
2014-09-12 00:05:02 +08:00
}
2014-06-25 04:11:11 +08:00
else if ( change = = TOX_CHAT_CHANGE_PEER_DEL )
2014-10-20 19:34:17 +08:00
{
2014-11-23 23:22:29 +08:00
// g->removePeer(peernumber);
g - > regeneratePeerList ( ) ;
2015-01-03 03:29:39 +08:00
// g->getChatForm()->addSystemInfoMessage(tr("%1 has left the chat").arg(name), "white", QDateTime::currentDateTime());
2014-10-20 19:34:17 +08:00
}
else if ( change = = TOX_CHAT_CHANGE_PEER_NAME ) // core overwrites old name before telling us it changed...
2015-04-24 19:01:50 +08:00
{
2016-01-22 21:06:25 +08:00
QString name = Nexus : : getCore ( ) - > getGroupPeerName ( groupnumber , peernumber ) ;
2016-01-23 11:29:43 +08:00
if ( name . isEmpty ( ) )
name = tr ( " <Empty> " , " Placeholder when someone's name in a group chat is empty " ) ;
2015-08-19 01:40:11 +08:00
g - > updatePeer ( peernumber , name ) ;
2015-04-24 19:01:50 +08:00
}
2014-06-25 04:11:11 +08:00
}
2014-11-06 08:22:50 +08:00
void Widget : : onGroupTitleChanged ( int groupnumber , const QString & author , const QString & title )
{
Group * g = GroupList : : findGroup ( groupnumber ) ;
if ( ! g )
return ;
if ( ! author . isEmpty ( ) )
2015-01-05 01:21:35 +08:00
g - > getChatForm ( ) - > addSystemInfoMessage ( tr ( " %1 has set the title to %2 " ) . arg ( author , title ) , ChatMessage : : INFO , QDateTime : : currentDateTime ( ) ) ;
2015-06-07 11:20:06 +08:00
2015-06-08 02:25:05 +08:00
contactListWidget - > renameGroupWidget ( g - > getGroupWidget ( ) , title ) ;
2015-06-24 02:58:30 +08:00
g - > setName ( title ) ;
2015-06-13 00:09:01 +08:00
int filter = getFilterCriteria ( ) ;
2015-06-07 11:20:06 +08:00
g - > getGroupWidget ( ) - > searchName ( ui - > searchContactText - > text ( ) , filterGroups ( filter ) ) ;
2014-11-06 08:22:50 +08:00
}
2015-03-13 14:00:12 +08:00
void Widget : : onGroupPeerAudioPlaying ( int groupnumber , int peernumber )
{
Group * g = GroupList : : findGroup ( groupnumber ) ;
if ( ! g )
return ;
g - > getChatForm ( ) - > peerAudioPlaying ( peernumber ) ;
}
2014-11-12 07:00:24 +08:00
void Widget : : removeGroup ( Group * g , bool fake )
2014-06-25 04:11:11 +08:00
{
2014-11-23 23:22:29 +08:00
g - > getGroupWidget ( ) - > setAsInactiveChatroom ( ) ;
if ( static_cast < GenericChatroomWidget * > ( g - > getGroupWidget ( ) ) = = activeChatroomWidget )
2014-10-30 17:44:26 +08:00
{
2014-09-02 00:20:28 +08:00
activeChatroomWidget = nullptr ;
2014-10-30 17:44:26 +08:00
onAddClicked ( ) ;
}
2014-11-23 23:22:29 +08:00
GroupList : : removeGroup ( g - > getGroupId ( ) , fake ) ;
2015-07-01 22:19:15 +08:00
ContentDialog * contentDialog = ContentDialog : : getGroupDialog ( g - > getGroupId ( ) ) ;
if ( contentDialog ! = nullptr )
contentDialog - > removeGroup ( g - > getGroupId ( ) ) ;
2015-02-06 19:28:49 +08:00
Nexus : : getCore ( ) - > removeGroup ( g - > getGroupId ( ) , fake ) ;
2014-06-25 04:11:11 +08:00
delete g ;
2015-07-01 19:49:36 +08:00
if ( contentLayout ! = nullptr & & contentLayout - > mainHead - > layout ( ) - > isEmpty ( ) )
2014-06-25 04:11:11 +08:00
onAddClicked ( ) ;
2014-11-02 16:45:44 +08:00
2015-06-03 18:26:48 +08:00
contactListWidget - > reDraw ( ) ;
2014-06-25 04:11:11 +08:00
}
2014-10-09 16:07:26 +08:00
void Widget : : removeGroup ( int groupId )
{
removeGroup ( GroupList : : findGroup ( groupId ) ) ;
}
2014-06-25 04:11:11 +08:00
Group * Widget : : createGroup ( int groupId )
{
Group * g = GroupList : : findGroup ( groupId ) ;
if ( g )
{
2015-05-11 20:54:03 +08:00
qWarning ( ) < < " createGroup: Group already exists " ;
2014-06-25 04:11:11 +08:00
return g ;
}
2015-04-25 07:50:35 +08:00
Core * core = Nexus : : getCore ( ) ;
2014-06-25 04:11:11 +08:00
QString groupName = QString ( " Groupchat #%1 " ) . arg ( groupId ) ;
2015-09-28 01:59:26 +08:00
Group * newgroup = GroupList : : addGroup ( groupId , groupName , core - > getAv ( ) - > isGroupAvEnabled ( groupId ) ) ;
2015-06-07 11:20:06 +08:00
2015-05-28 01:17:12 +08:00
contactListWidget - > addGroupWidget ( newgroup - > getGroupWidget ( ) ) ;
2014-11-23 23:22:29 +08:00
newgroup - > getGroupWidget ( ) - > updateStatusLight ( ) ;
2016-04-12 20:52:08 +08:00
contactListWidget - > activateWindow ( ) ;
2014-11-23 23:22:29 +08:00
2015-06-11 00:11:50 +08:00
connect ( settingsWidget , & SettingsWidget : : compactToggled , newgroup - > getGroupWidget ( ) , & GenericChatroomWidget : : compactChange ) ;
2015-06-23 02:01:50 +08:00
connect ( newgroup - > getGroupWidget ( ) , SIGNAL ( chatroomWidgetClicked ( GenericChatroomWidget * , bool ) ) , this , SLOT ( onChatroomWidgetClicked ( GenericChatroomWidget * , bool ) ) ) ;
2014-11-23 23:22:29 +08:00
connect ( newgroup - > getGroupWidget ( ) , SIGNAL ( removeGroup ( int ) ) , this , SLOT ( removeGroup ( int ) ) ) ;
connect ( newgroup - > getGroupWidget ( ) , SIGNAL ( chatroomWidgetClicked ( GenericChatroomWidget * ) ) , newgroup - > getChatForm ( ) , SLOT ( focusInput ( ) ) ) ;
2015-04-20 05:12:44 +08:00
connect ( newgroup - > getChatForm ( ) , & GroupChatForm : : sendMessage , core , & Core : : sendGroupMessage ) ;
connect ( newgroup - > getChatForm ( ) , & GroupChatForm : : sendAction , core , & Core : : sendGroupAction ) ;
2014-11-23 23:22:29 +08:00
connect ( newgroup - > getChatForm ( ) , & GroupChatForm : : groupTitleChanged , core , & Core : : changeGroupTitle ) ;
2015-06-07 11:20:06 +08:00
2015-06-13 00:09:01 +08:00
int filter = getFilterCriteria ( ) ;
2015-06-07 11:20:06 +08:00
newgroup - > getGroupWidget ( ) - > searchName ( ui - > searchContactText - > text ( ) , filterGroups ( filter ) ) ;
2014-06-25 04:11:11 +08:00
return newgroup ;
}
2014-06-30 05:38:48 +08:00
void Widget : : onEmptyGroupCreated ( int groupId )
{
2015-06-18 23:27:50 +08:00
Group * group = createGroup ( groupId ) ;
// Only rename group if groups are visible.
if ( Widget : : getInstance ( ) - > groupsVisible ( ) )
group - > getGroupWidget ( ) - > editName ( ) ;
2014-06-30 05:38:48 +08:00
}
2014-07-01 03:14:51 +08:00
2014-07-03 06:27:30 +08:00
bool Widget : : event ( QEvent * e )
2014-07-01 10:12:17 +08:00
{
2015-03-21 16:59:28 +08:00
switch ( e - > type ( ) )
2014-12-12 00:49:11 +08:00
{
2015-12-16 01:31:45 +08:00
case QEvent : : MouseButtonPress :
case QEvent : : MouseButtonDblClick :
focusChatInput ( ) ;
break ;
2014-10-16 17:47:58 +08:00
case QEvent : : WindowActivate :
if ( activeChatroomWidget ! = nullptr )
{
activeChatroomWidget - > resetEventFlags ( ) ;
activeChatroomWidget - > updateStatusLight ( ) ;
2015-07-03 01:16:11 +08:00
setWindowTitle ( activeChatroomWidget - > getTitle ( ) ) ;
2014-10-16 17:47:58 +08:00
}
2015-12-16 01:31:45 +08:00
2014-12-12 00:49:11 +08:00
if ( eventFlag )
{
eventFlag = false ;
eventIcon = false ;
2015-03-12 02:04:29 +08:00
updateIcons ( ) ;
2014-12-12 00:49:11 +08:00
}
2015-07-30 07:46:19 +08:00
2015-12-16 01:31:45 +08:00
focusChatInput ( ) ;
2015-07-30 07:46:19 +08:00
# ifdef Q_OS_MAC
emit windowStateChanged ( windowState ( ) ) ;
case QEvent : : WindowStateChange :
Nexus : : getInstance ( ) . updateWindowsStates ( ) ;
# endif
2015-12-16 01:31:45 +08:00
break ;
2014-10-16 17:47:58 +08:00
default :
break ;
2014-07-03 06:27:30 +08:00
}
2014-07-01 10:12:17 +08:00
return QWidget : : event ( e ) ;
}
2014-11-26 20:34:08 +08:00
void Widget : : onUserAwayCheck ( )
2014-11-15 07:43:38 +08:00
{
2014-12-02 08:14:06 +08:00
# ifdef QTOX_PLATFORM_EXT
2014-11-27 02:27:20 +08:00
uint32_t autoAwayTime = Settings : : getInstance ( ) . getAutoAwayTime ( ) * 60 * 1000 ;
2014-11-15 07:43:38 +08:00
2014-12-02 05:28:53 +08:00
if ( ui - > statusButton - > property ( " status " ) . toString ( ) = = " online " )
2014-10-16 17:47:58 +08:00
{
2014-12-02 05:28:53 +08:00
if ( autoAwayTime & & Platform : : getIdleTime ( ) > = autoAwayTime )
2014-11-26 20:34:08 +08:00
{
2015-05-11 20:54:03 +08:00
qDebug ( ) < < " auto away activated at " < < QTime : : currentTime ( ) . toString ( ) ;
2014-12-02 05:28:53 +08:00
emit statusSet ( Status : : Away ) ;
autoAwayActive = true ;
2014-11-26 20:34:08 +08:00
}
}
2014-12-02 05:28:53 +08:00
else if ( ui - > statusButton - > property ( " status " ) . toString ( ) = = " away " )
2014-10-16 17:47:58 +08:00
{
2014-12-02 05:28:53 +08:00
if ( autoAwayActive & & ( ! autoAwayTime | | Platform : : getIdleTime ( ) < autoAwayTime ) )
2014-11-26 20:34:08 +08:00
{
2015-05-11 20:54:03 +08:00
qDebug ( ) < < " auto away deactivated at " < < QTime : : currentTime ( ) . toString ( ) ;
2014-12-02 05:28:53 +08:00
emit statusSet ( Status : : Online ) ;
autoAwayActive = false ;
2014-11-26 20:34:08 +08:00
}
2014-10-16 17:47:58 +08:00
}
2014-12-02 05:28:53 +08:00
else if ( autoAwayActive )
2015-04-24 19:01:50 +08:00
{
2014-11-26 20:34:08 +08:00
autoAwayActive = false ;
2015-04-24 19:01:50 +08:00
}
2014-12-02 08:14:06 +08:00
# endif
2014-10-16 17:47:58 +08:00
}
2014-12-12 00:49:11 +08:00
void Widget : : onEventIconTick ( )
{
if ( eventFlag )
{
eventIcon ^ = true ;
2015-03-12 02:04:29 +08:00
updateIcons ( ) ;
2014-12-12 00:49:11 +08:00
}
}
2015-02-20 18:56:20 +08:00
void Widget : : onTryCreateTrayIcon ( )
{
static int32_t tries = 15 ;
if ( ! icon & & tries - - )
{
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) )
{
2015-08-30 00:06:22 +08:00
icon = new SystemTrayIcon ( ) ;
2015-03-12 02:04:29 +08:00
updateIcons ( ) ;
2015-08-29 20:10:17 +08:00
trayMenu = new QMenu ( this ) ;
2015-08-30 19:25:46 +08:00
2015-02-20 18:56:20 +08:00
trayMenu - > addAction ( statusOnline ) ;
trayMenu - > addAction ( statusAway ) ;
trayMenu - > addAction ( statusBusy ) ;
trayMenu - > addSeparator ( ) ;
2015-08-30 19:25:46 +08:00
trayMenu - > addAction ( actionLogout ) ;
2015-02-20 18:56:20 +08:00
trayMenu - > addAction ( actionQuit ) ;
icon - > setContextMenu ( trayMenu ) ;
2015-08-29 20:10:17 +08:00
connect ( icon , & SystemTrayIcon : : activated , this , & Widget : : onIconClick ) ;
2015-02-20 18:56:20 +08:00
if ( Settings : : getInstance ( ) . getShowSystemTray ( ) )
{
icon - > show ( ) ;
setHidden ( Settings : : getInstance ( ) . getAutostartInTray ( ) ) ;
}
else
2015-04-24 19:01:50 +08:00
{
2015-02-20 18:56:20 +08:00
show ( ) ;
2015-04-24 19:01:50 +08:00
}
2015-07-09 20:43:19 +08:00
# ifdef Q_OS_MAC
2015-07-30 07:46:19 +08:00
qt_mac_set_dock_menu ( Nexus : : getInstance ( ) . dockMenu ) ;
2015-07-09 20:43:19 +08:00
# endif
2015-02-20 18:56:20 +08:00
}
else if ( ! isVisible ( ) )
2015-04-24 19:01:50 +08:00
{
2015-02-20 18:56:20 +08:00
show ( ) ;
2015-04-24 19:01:50 +08:00
}
2015-02-20 18:56:20 +08:00
}
else
{
disconnect ( timer , & QTimer : : timeout , this , & Widget : : onTryCreateTrayIcon ) ;
if ( ! icon )
{
2015-05-11 20:54:03 +08:00
qWarning ( ) < < " No system tray detected! " ;
2015-02-20 18:56:20 +08:00
show ( ) ;
}
}
}
2014-07-06 04:54:27 +08:00
void Widget : : setStatusOnline ( )
{
2015-05-12 05:01:25 +08:00
if ( ! ui - > statusButton - > isEnabled ( ) )
return ;
2015-02-06 19:28:49 +08:00
Nexus : : getCore ( ) - > setStatus ( Status : : Online ) ;
2014-07-06 04:54:27 +08:00
}
void Widget : : setStatusAway ( )
{
2015-05-12 05:01:25 +08:00
if ( ! ui - > statusButton - > isEnabled ( ) )
return ;
2015-02-06 19:28:49 +08:00
Nexus : : getCore ( ) - > setStatus ( Status : : Away ) ;
2014-07-06 04:54:27 +08:00
}
void Widget : : setStatusBusy ( )
2014-07-04 01:33:08 +08:00
{
2015-05-12 05:01:25 +08:00
if ( ! ui - > statusButton - > isEnabled ( ) )
return ;
2015-02-06 19:28:49 +08:00
Nexus : : getCore ( ) - > setStatus ( Status : : Busy ) ;
2014-07-04 01:33:08 +08:00
}
2014-07-21 02:17:06 +08:00
2015-04-20 05:12:44 +08:00
void Widget : : onMessageSendResult ( uint32_t friendId , const QString & message , int messageId )
2014-09-24 00:35:06 +08:00
{
Q_UNUSED ( message )
2014-11-10 19:30:56 +08:00
Q_UNUSED ( messageId )
2014-09-24 00:35:06 +08:00
Friend * f = FriendList : : findFriend ( friendId ) ;
if ( ! f )
return ;
}
void Widget : : onGroupSendResult ( int groupId , const QString & message , int result )
{
Q_UNUSED ( message )
Group * g = GroupList : : findGroup ( groupId ) ;
if ( ! g )
return ;
if ( result = = - 1 )
2015-01-05 01:21:35 +08:00
g - > getChatForm ( ) - > addSystemInfoMessage ( tr ( " Message failed to send " ) , ChatMessage : : INFO , QDateTime : : currentDateTime ( ) ) ;
2014-09-24 00:35:06 +08:00
}
2014-10-16 00:18:32 +08:00
2015-01-04 19:20:36 +08:00
void Widget : : onFriendTypingChanged ( int friendId , bool isTyping )
{
Friend * f = FriendList : : findFriend ( friendId ) ;
if ( ! f )
return ;
2015-04-24 19:01:50 +08:00
2015-01-04 19:20:36 +08:00
f - > getChatForm ( ) - > setFriendTyping ( isTyping ) ;
}
2015-02-20 18:56:20 +08:00
void Widget : : onSetShowSystemTray ( bool newValue )
{
if ( icon )
icon - > setVisible ( newValue ) ;
2014-11-14 04:33:11 +08:00
}
2014-11-28 06:35:56 +08:00
void Widget : : saveWindowGeometry ( )
{
Settings : : getInstance ( ) . setWindowGeometry ( saveGeometry ( ) ) ;
Settings : : getInstance ( ) . setWindowState ( saveState ( ) ) ;
}
void Widget : : saveSplitterGeometry ( )
{
Settings : : getInstance ( ) . setSplitterState ( ui - > mainSplitter - > saveState ( ) ) ;
}
2014-11-28 17:16:37 +08:00
void Widget : : onSplitterMoved ( int pos , int index )
{
Q_UNUSED ( pos ) ;
Q_UNUSED ( index ) ;
saveSplitterGeometry ( ) ;
}
2014-11-14 04:33:11 +08:00
2015-06-07 11:20:06 +08:00
void Widget : : cycleContacts ( bool forward )
2015-03-22 15:59:42 +08:00
{
2015-06-07 11:20:06 +08:00
contactListWidget - > cycleContacts ( activeChatroomWidget , forward ) ;
}
2015-03-22 15:59:42 +08:00
2015-06-07 11:20:06 +08:00
bool Widget : : filterGroups ( int index )
{
switch ( index )
{
case FilterCriteria : : Offline :
case FilterCriteria : : Friends :
return true ;
default :
return false ;
}
}
2015-03-22 15:59:42 +08:00
2015-06-07 11:20:06 +08:00
bool Widget : : filterOffline ( int index )
{
switch ( index )
{
case FilterCriteria : : Online :
case FilterCriteria : : Groups :
return true ;
default :
return false ;
}
}
2015-03-22 15:59:42 +08:00
2015-06-07 11:20:06 +08:00
bool Widget : : filterOnline ( int index )
{
switch ( index )
{
case FilterCriteria : : Offline :
case FilterCriteria : : Groups :
return true ;
default :
return false ;
}
2015-03-22 15:59:42 +08:00
}
2015-02-13 13:27:49 +08:00
void Widget : : processOfflineMsgs ( )
{
if ( OfflineMsgEngine : : globalMutex . tryLock ( ) )
{
QList < Friend * > frnds = FriendList : : getAllFriends ( ) ;
for ( Friend * f : frnds )
f - > getChatForm ( ) - > getOfflineMsgEngine ( ) - > deliverOfflineMsgs ( ) ;
OfflineMsgEngine : : globalMutex . unlock ( ) ;
}
}
2014-11-10 21:06:35 +08:00
void Widget : : clearAllReceipts ( )
{
QList < Friend * > frnds = FriendList : : getAllFriends ( ) ;
for ( Friend * f : frnds )
2016-01-18 21:50:11 +08:00
f - > getChatForm ( ) - > getOfflineMsgEngine ( ) - > removeAllReceipts ( ) ;
2014-11-15 03:12:23 +08:00
}
2014-11-16 04:30:20 +08:00
void Widget : : reloadTheme ( )
{
2015-02-07 19:46:55 +08:00
QString statusPanelStyle = Style : : getStylesheet ( " :/ui/window/statusPanel.css " ) ;
2015-04-01 16:01:25 +08:00
ui - > tooliconsZone - > setStyleSheet ( Style : : resolve ( " QPushButton{background-color:@themeDark;border:none;}QPushButton:hover{background-color:@themeMediumDark;border:none;}QPushButton:checked{background-color:@themeMedium;border:none;}QPushButton:pressed{background-color:@themeMediumLight;border:none;} " ) ) ;
2015-02-07 19:46:55 +08:00
ui - > statusPanel - > setStyleSheet ( statusPanelStyle ) ;
ui - > statusHead - > setStyleSheet ( statusPanelStyle ) ;
2015-11-10 02:42:53 +08:00
ui - > friendList - > setStyleSheet ( Style : : getStylesheet ( " :/ui/friendList/friendList.css " ) ) ;
ui - > statusButton - > setStyleSheet ( Style : : getStylesheet ( " :/ui/statusButton/statusButton.css " ) ) ;
2015-06-25 23:55:06 +08:00
contactListWidget - > reDraw ( ) ;
2014-11-16 04:30:20 +08:00
for ( Friend * f : FriendList : : getAllFriends ( ) )
f - > getFriendWidget ( ) - > reloadTheme ( ) ;
2014-11-20 17:13:13 +08:00
for ( Group * g : GroupList : : getAllGroups ( ) )
2014-11-23 23:22:29 +08:00
g - > getGroupWidget ( ) - > reloadTheme ( ) ;
2014-11-16 04:30:20 +08:00
}
2015-02-28 01:56:47 +08:00
void Widget : : nextContact ( )
{
2015-06-18 03:45:03 +08:00
cycleContacts ( true ) ;
2015-02-28 01:56:47 +08:00
}
void Widget : : previousContact ( )
{
2015-06-18 03:45:03 +08:00
cycleContacts ( false ) ;
2015-02-28 01:56:47 +08:00
}
2015-02-12 20:18:04 +08:00
QString Widget : : getStatusIconPath ( Status status )
{
switch ( status )
{
case Status : : Online :
2015-11-10 02:42:53 +08:00
return " :/img/status/dot_online.svg " ;
2015-02-12 20:18:04 +08:00
case Status : : Away :
2015-11-10 02:42:53 +08:00
return " :/img/status/dot_away.svg " ;
2015-02-12 20:18:04 +08:00
case Status : : Busy :
2015-11-10 02:42:53 +08:00
return " :/img/status/dot_busy.svg " ;
2015-02-12 20:18:04 +08:00
case Status : : Offline :
default :
2015-11-10 02:42:53 +08:00
return " :/img/status/dot_offline.svg " ;
2015-02-12 20:18:04 +08:00
}
}
2015-11-07 04:53:26 +08:00
inline QIcon Widget : : prepareIcon ( QString path , uint32_t w , uint32_t h )
2015-02-12 20:18:04 +08:00
{
2015-08-30 01:25:28 +08:00
# ifdef Q_OS_LINUX
2015-08-29 21:40:55 +08:00
QString desktop = getenv ( " XDG_CURRENT_DESKTOP " ) ;
if ( desktop . isEmpty ( ) )
2015-08-30 01:25:28 +08:00
{
2015-08-29 21:40:55 +08:00
desktop = getenv ( " DESKTOP_SESSION " ) ;
2015-08-30 01:25:28 +08:00
}
2015-08-29 21:40:55 +08:00
desktop = desktop . toLower ( ) ;
2015-08-30 01:25:28 +08:00
2015-11-29 20:04:46 +08:00
if ( desktop = = " xfce " | | desktop . contains ( " gnome " ) | | desktop = = " mate " | | desktop = = " x-cinnamon " )
2015-08-30 01:25:28 +08:00
{
if ( w > 0 & & h > 0 )
{
2015-11-08 23:11:19 +08:00
QSvgRenderer renderer ( path ) ;
QPixmap pm ( w , h ) ;
pm . fill ( Qt : : transparent ) ;
QPainter painter ( & pm ) ;
renderer . render ( & painter , pm . rect ( ) ) ;
return QIcon ( pm ) ;
2015-08-29 21:40:55 +08:00
}
}
# endif
2015-11-07 04:53:26 +08:00
return QIcon ( path ) ;
2015-02-12 20:18:04 +08:00
}
2015-11-07 04:53:26 +08:00
QPixmap Widget : : getStatusIconPixmap ( QString path , uint32_t w , uint32_t h )
2015-02-12 20:18:04 +08:00
{
QPixmap pix ( w , h ) ;
2015-11-07 04:53:26 +08:00
pix . load ( path ) ;
2015-02-12 20:18:04 +08:00
return pix ;
}
QString Widget : : getStatusTitle ( Status status )
{
switch ( status )
{
case Status : : Online :
2015-11-11 03:20:07 +08:00
return QStringLiteral ( " online " ) ;
2015-02-12 20:18:04 +08:00
case Status : : Away :
2015-11-11 03:20:07 +08:00
return QStringLiteral ( " away " ) ;
2015-02-12 20:18:04 +08:00
case Status : : Busy :
2015-11-11 03:20:07 +08:00
return QStringLiteral ( " busy " ) ;
2015-02-12 20:18:04 +08:00
case Status : : Offline :
default :
2015-11-11 03:20:07 +08:00
return QStringLiteral ( " offline " ) ;
2015-02-12 20:18:04 +08:00
}
}
Status Widget : : getStatusFromString ( QString status )
{
2015-11-11 03:20:07 +08:00
if ( status = = QStringLiteral ( " online " ) )
2015-02-12 20:18:04 +08:00
return Status : : Online ;
2015-11-11 03:20:07 +08:00
else if ( status = = QStringLiteral ( " away " ) )
2015-02-12 20:18:04 +08:00
return Status : : Away ;
2015-11-11 03:20:07 +08:00
else if ( status = = QStringLiteral ( " busy " ) )
return Status : : Busy ;
2015-02-12 20:18:04 +08:00
else
return Status : : Offline ;
}
2015-04-01 16:01:25 +08:00
2015-04-09 00:18:07 +08:00
void Widget : : searchContacts ( )
{
QString searchString = ui - > searchContactText - > text ( ) ;
2015-06-13 00:09:01 +08:00
int filter = getFilterCriteria ( ) ;
2015-04-09 00:18:07 +08:00
2015-06-07 11:20:06 +08:00
contactListWidget - > searchChatrooms ( searchString , filterOnline ( filter ) , filterOffline ( filter ) , filterGroups ( filter ) ) ;
2015-06-13 00:09:01 +08:00
updateFilterText ( ) ;
2015-06-07 11:20:06 +08:00
contactListWidget - > reDraw ( ) ;
}
2015-06-13 00:09:01 +08:00
void Widget : : changeDisplayMode ( )
{
2015-06-19 02:55:46 +08:00
filterDisplayGroup - > setEnabled ( false ) ;
2015-06-13 00:09:01 +08:00
if ( filterDisplayGroup - > checkedAction ( ) = = filterDisplayActivity )
contactListWidget - > setMode ( FriendListWidget : : Activity ) ;
else if ( filterDisplayGroup - > checkedAction ( ) = = filterDisplayName )
contactListWidget - > setMode ( FriendListWidget : : Name ) ;
2015-06-18 23:27:50 +08:00
searchContacts ( ) ;
2015-06-19 02:55:46 +08:00
filterDisplayGroup - > setEnabled ( true ) ;
updateFilterText ( ) ;
2015-06-13 00:09:01 +08:00
}
void Widget : : updateFilterText ( )
{
ui - > searchContactFilterBox - > setText ( filterDisplayGroup - > checkedAction ( ) - > text ( ) + QStringLiteral ( " | " ) + filterGroup - > checkedAction ( ) - > text ( ) ) ;
}
int Widget : : getFilterCriteria ( ) const
{
QAction * checked = filterGroup - > checkedAction ( ) ;
if ( checked = = filterOnlineAction )
return Online ;
else if ( checked = = filterOfflineAction )
return Offline ;
else if ( checked = = filterFriendsAction )
return Friends ;
else if ( checked = = filterGroupsAction )
return Groups ;
return All ;
}
2015-06-07 11:20:06 +08:00
void Widget : : searchCircle ( CircleWidget * circleWidget )
{
2015-06-13 00:09:01 +08:00
int filter = getFilterCriteria ( ) ;
2015-06-07 11:20:06 +08:00
circleWidget - > search ( ui - > searchContactText - > text ( ) , true , filterOnline ( filter ) , filterOffline ( filter ) ) ;
}
void Widget : : searchItem ( GenericChatItemWidget * chatItem , GenericChatItemWidget : : ItemType type )
{
bool hide ;
2015-06-13 00:09:01 +08:00
int filter = getFilterCriteria ( ) ;
2015-06-07 11:20:06 +08:00
switch ( type )
2015-04-09 00:18:07 +08:00
{
2015-06-07 11:20:06 +08:00
case GenericChatItemWidget : : GroupItem :
hide = filterGroups ( filter ) ;
2015-04-09 00:18:07 +08:00
break ;
default :
2015-06-07 11:20:06 +08:00
hide = true ;
2015-04-09 00:18:07 +08:00
}
2015-06-07 11:20:06 +08:00
chatItem - > searchName ( ui - > searchContactText - > text ( ) , hide ) ;
}
bool Widget : : groupsVisible ( ) const
{
2015-06-13 00:09:01 +08:00
int filter = getFilterCriteria ( ) ;
2015-06-07 11:20:06 +08:00
return ! filterGroups ( filter ) ;
2015-04-09 00:18:07 +08:00
}
2015-05-28 01:17:12 +08:00
void Widget : : friendListContextMenu ( const QPoint & pos )
2015-04-09 00:18:07 +08:00
{
2015-05-28 01:17:12 +08:00
QMenu menu ( this ) ;
2016-02-21 05:32:57 +08:00
QAction * createGroupAction = menu . addAction ( tr ( " Create new group... " ) ) ;
2015-05-28 01:17:12 +08:00
QAction * addCircleAction = menu . addAction ( tr ( " Add new circle... " ) ) ;
QAction * chosenAction = menu . exec ( ui - > friendList - > mapToGlobal ( pos ) ) ;
2015-04-09 00:18:07 +08:00
2015-05-28 01:17:12 +08:00
if ( chosenAction = = addCircleAction )
2015-06-02 04:17:39 +08:00
contactListWidget - > addCircleWidget ( ) ;
2016-02-21 05:32:57 +08:00
else if ( chosenAction = = createGroupAction )
Nexus : : getCore ( ) - > createGroup ( ) ;
}
void Widget : : friendRequestsUpdate ( )
{
unsigned int unreadFriendRequests = Settings : : getInstance ( ) . getUnreadFriendRequests ( ) ;
if ( unreadFriendRequests = = 0 )
{
delete friendRequestsButton ;
friendRequestsButton = nullptr ;
}
else if ( ! friendRequestsButton )
{
friendRequestsButton = new QPushButton ( this ) ;
friendRequestsButton - > setObjectName ( " green " ) ;
ui - > statusLayout - > insertWidget ( 2 , friendRequestsButton ) ;
connect ( friendRequestsButton , & QPushButton : : released , [ this ] ( )
{
2016-02-22 07:42:48 +08:00
onAddClicked ( ) ;
addFriendForm - > setMode ( AddFriendForm : : Mode : : FriendRequest ) ;
2016-02-21 05:32:57 +08:00
} ) ;
}
if ( friendRequestsButton )
friendRequestsButton - > setText ( tr ( " %n New Friend Request(s) " , " " , unreadFriendRequests ) ) ;
}
void Widget : : groupInvitesUpdate ( )
{
if ( unreadGroupInvites = = 0 )
{
delete groupInvitesButton ;
groupInvitesButton = nullptr ;
}
else if ( ! groupInvitesButton )
{
groupInvitesButton = new QPushButton ( this ) ;
groupInvitesButton - > setObjectName ( " green " ) ;
ui - > statusLayout - > insertWidget ( 2 , groupInvitesButton ) ;
connect ( groupInvitesButton , & QPushButton : : released , this , & Widget : : onGroupClicked ) ;
}
if ( groupInvitesButton )
groupInvitesButton - > setText ( tr ( " %n New Group Invite(s) " , " " , unreadGroupInvites ) ) ;
}
void Widget : : groupInvitesClear ( )
{
unreadGroupInvites = 0 ;
groupInvitesUpdate ( ) ;
2015-04-09 00:18:07 +08:00
}
2015-04-01 16:01:25 +08:00
void Widget : : setActiveToolMenuButton ( ActiveToolMenuButton newActiveButton )
{
ui - > addButton - > setChecked ( newActiveButton = = Widget : : AddButton ) ;
ui - > addButton - > setDisabled ( newActiveButton = = Widget : : AddButton ) ;
ui - > groupButton - > setChecked ( newActiveButton = = Widget : : GroupButton ) ;
ui - > groupButton - > setDisabled ( newActiveButton = = Widget : : GroupButton ) ;
ui - > transferButton - > setChecked ( newActiveButton = = Widget : : TransferButton ) ;
ui - > transferButton - > setDisabled ( newActiveButton = = Widget : : TransferButton ) ;
ui - > settingsButton - > setChecked ( newActiveButton = = Widget : : SettingButton ) ;
ui - > settingsButton - > setDisabled ( newActiveButton = = Widget : : SettingButton ) ;
}
2015-06-06 03:37:01 +08:00
void Widget : : retranslateUi ( )
{
2015-09-28 02:54:44 +08:00
Core * core = Nexus : : getCore ( ) ;
2015-06-06 03:37:01 +08:00
ui - > retranslateUi ( this ) ;
2015-09-28 05:52:10 +08:00
setUsername ( core - > getUsername ( ) ) ;
setStatusMessage ( core - > getStatusMessage ( ) ) ;
2015-06-13 00:09:01 +08:00
filterDisplayName - > setText ( tr ( " By Name " ) ) ;
filterDisplayActivity - > setText ( tr ( " By Activity " ) ) ;
filterAllAction - > setText ( tr ( " All " ) ) ;
filterOnlineAction - > setText ( tr ( " Online " ) ) ;
filterOfflineAction - > setText ( tr ( " Offline " ) ) ;
filterFriendsAction - > setText ( tr ( " Friends " ) ) ;
filterGroupsAction - > setText ( tr ( " Groups " ) ) ;
ui - > searchContactText - > setPlaceholderText ( tr ( " Search Contacts " ) ) ;
updateFilterText ( ) ;
2015-06-06 03:37:01 +08:00
ui - > searchContactText - > setPlaceholderText ( tr ( " Search Contacts " ) ) ;
statusOnline - > setText ( tr ( " Online " , " Button to set your status to 'Online' " ) ) ;
statusAway - > setText ( tr ( " Away " , " Button to set your status to 'Away' " ) ) ;
statusBusy - > setText ( tr ( " Busy " , " Button to set your status to 'Busy' " ) ) ;
2015-11-08 23:11:19 +08:00
actionLogout - > setText ( tr ( " Logout " , " Tray action menu to logout user " ) ) ;
actionQuit - > setText ( tr ( " Exit " , " Tray action menu to exit tox " ) ) ;
2015-07-03 02:38:18 +08:00
if ( ! Settings : : getInstance ( ) . getSeparateWindow ( ) )
2016-04-10 16:36:14 +08:00
setWindowTitle ( fromDialogType ( AddDialog ) ) ;
2015-07-02 01:12:50 +08:00
2016-02-21 05:32:57 +08:00
friendRequestsUpdate ( ) ;
groupInvitesUpdate ( ) ;
2015-07-02 01:12:50 +08:00
# ifdef Q_OS_MAC
2015-07-30 07:46:19 +08:00
Nexus : : getInstance ( ) . retranslateUi ( ) ;
filterMenu - > menuAction ( ) - > setText ( tr ( " Filter... " ) ) ;
fileMenu - > setText ( tr ( " File " ) ) ;
editMenu - > setText ( tr ( " Edit " ) ) ;
contactMenu - > setText ( tr ( " Contacts " ) ) ;
changeStatusMenu - > menuAction ( ) - > setText ( tr ( " Change Status " ) ) ;
editProfileAction - > setText ( tr ( " Edit Profile " ) ) ;
logoutAction - > setText ( tr ( " Log out " ) ) ;
addContactAction - > setText ( tr ( " Add Contact... " ) ) ;
nextConversationAction - > setText ( tr ( " Next Conversation " ) ) ;
previousConversationAction - > setText ( tr ( " Previous Conversation " ) ) ;
2015-07-02 01:12:50 +08:00
# endif
2015-07-30 07:46:19 +08:00
}
2015-12-16 01:31:45 +08:00
void Widget : : focusChatInput ( )
{
if ( activeChatroomWidget )
{
if ( Friend * f = activeChatroomWidget - > getFriend ( ) )
f - > getChatForm ( ) - > focusInput ( ) ;
else if ( Group * g = activeChatroomWidget - > getGroup ( ) )
g - > getChatForm ( ) - > focusInput ( ) ;
}
}