2007-11-14 22:18:48 -05:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 , 2007 crypton
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
2009-08-09 10:39:47 -04:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
2007-11-14 22:18:48 -05:00
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <QMessageBox>
# include <QString>
# include <QtDebug>
# include <QIcon>
# include <QPixmap>
2010-07-23 14:52:58 -04:00
# include <QColorDialog>
2010-11-17 20:18:31 -05:00
# include <QDesktopServices>
# include <QUrl>
2007-11-14 22:18:48 -05:00
2010-02-25 08:12:18 -05:00
# ifdef BLOGS
2010-02-24 07:58:24 -05:00
# include "gui/unfinished/blogs/BlogsDialog.h"
# endif
2008-11-29 15:17:58 -05:00
2011-06-16 17:59:26 -04:00
# include <retroshare/rsplugin.h>
2011-07-30 13:13:08 -04:00
# include <retroshare/rsconfig.h>
2009-08-21 13:58:55 -04:00
# include "rshare.h"
2007-11-14 22:18:48 -05:00
# include "MainWindow.h"
2012-12-20 08:30:16 -05:00
# include "ui_MainWindow.h"
2007-11-14 22:18:48 -05:00
# include "MessengerWindow.h"
2010-06-08 17:38:36 -04:00
# include "NetworkDialog.h"
# include "SearchDialog.h"
2013-07-14 08:53:38 -04:00
# include "gui/FileTransfer/TransfersDialog.h"
2010-06-08 17:38:36 -04:00
# include "MessagesDialog.h"
2013-02-23 08:24:16 -05:00
# include "SharedFilesDialog.h"
2010-06-08 17:38:36 -04:00
# include "PluginsPage.h"
2013-02-22 16:42:27 -05:00
# include "NewsFeed.h"
2010-06-08 17:38:36 -04:00
# include "ShareManager.h"
# include "NetworkView.h"
2011-05-17 13:27:47 -04:00
# include "FriendsDialog.h"
2013-02-22 16:42:27 -05:00
# include "ChatLobbyWidget.h"
2007-11-14 22:18:48 -05:00
# include "HelpDialog.h"
2009-12-30 21:23:02 -05:00
# include "AboutDialog.h"
2015-07-09 23:24:39 -04:00
# include "gui/statistics/BandwidthGraphWindow.h"
2010-07-23 14:52:58 -04:00
# include "help/browser/helpbrowser.h"
2012-01-17 15:36:36 -05:00
# include "chat/ChatDialog.h"
2010-11-17 20:18:31 -05:00
# include "RetroShareLink.h"
2012-01-22 17:58:23 -05:00
# include "SoundManager.h"
2012-02-24 20:48:56 -05:00
# include "notifyqt.h"
2012-08-05 16:12:55 -04:00
# include "common/UserNotify.h"
2013-09-02 17:48:23 -04:00
# include "gui/ServicePermissionDialog.h"
2010-07-23 14:52:58 -04:00
# ifdef UNFINISHED
# include "unfinished/ApplicationWindow.h"
# endif
2007-11-14 22:18:48 -05:00
2011-07-11 14:53:14 -04:00
# define GETSTARTED_GUI 1
# ifdef GETSTARTED_GUI
# include "gui/GetStartedDialog.h"
# endif
2014-10-01 15:43:31 -04:00
# ifdef RS_USE_CIRCLES
2014-05-01 07:46:25 -04:00
# include "gui/People/PeopleDialog.h"
2014-10-01 15:43:31 -04:00
# endif
2010-07-17 19:19:43 -04:00
# include "idle/idle.h"
2009-03-15 18:45:40 -04:00
2008-06-15 11:34:56 -04:00
# include "statusbar/peerstatus.h"
2009-05-01 08:45:27 -04:00
# include "statusbar/natstatus.h"
2009-05-02 18:14:20 -04:00
# include "statusbar/ratesstatus.h"
2010-10-27 08:49:46 -04:00
# include "statusbar/dhtstatus.h"
2010-10-09 14:35:34 -04:00
# include "statusbar/hashingstatus.h"
2011-01-07 11:56:57 -05:00
# include "statusbar/discstatus.h"
2012-11-25 17:50:38 -05:00
# include "statusbar/OpModeStatus.h"
2012-01-22 17:58:23 -05:00
# include "statusbar/SoundStatus.h"
2014-05-10 14:32:48 -04:00
# include "statusbar/ToasterDisable.h"
2014-11-02 15:29:06 -05:00
# include "statusbar/SysTrayStatus.h"
2010-08-06 05:40:23 -04:00
# include <retroshare/rsstatus.h>
2009-05-01 08:45:27 -04:00
2010-08-06 05:40:23 -04:00
# include <retroshare/rsiface.h>
# include <retroshare/rspeers.h>
# include <retroshare/rsfiles.h>
2010-09-01 13:56:15 -04:00
# include <retroshare/rsnotify.h>
2007-11-14 22:18:48 -05:00
2014-05-07 20:00:21 -04:00
# include "gui/gxschannels/GxsChannelDialog.h"
2014-04-26 12:32:33 -04:00
# include "gui/gxsforums/GxsForumsDialog.h"
2014-04-27 10:23:27 -04:00
# include "gui/Identity/IdDialog.h"
2014-09-10 04:37:27 -04:00
# ifdef RS_USE_CIRCLES
2014-04-27 10:23:27 -04:00
# include "gui/Circles/CirclesDialog.h"
2014-09-10 04:37:27 -04:00
# endif
# ifdef RS_USE_WIKI
2014-05-09 22:38:47 -04:00
# include "gui/WikiPoos/WikiDialog.h"
2014-09-10 04:37:27 -04:00
# endif
2014-05-09 22:38:47 -04:00
# include "gui/Posted/PostedDialog.h"
2014-09-04 13:01:28 -04:00
# include "gui/statistics/StatisticsWindow.h"
2014-04-26 12:32:33 -04:00
2009-03-26 12:58:06 -04:00
# include "gui/connect/ConnectFriendWizard.h"
2014-05-29 10:49:45 -04:00
# include "gui/common/RsCollectionFile.h"
2009-08-21 13:58:55 -04:00
# include "settings/rsettingswin.h"
2010-05-11 16:02:52 -04:00
# include "settings/rsharesettings.h"
2015-04-28 10:55:13 -04:00
# include "settings/WebuiPage.h"
2010-09-12 10:10:28 -04:00
# include "common/StatusDefs.h"
2014-05-09 22:38:47 -04:00
# include "gui/notifyqt.h"
2007-11-14 22:18:48 -05:00
2008-06-09 20:48:18 -04:00
# include <iomanip>
2008-12-07 13:34:54 -05:00
# include <unistd.h>
2007-11-14 22:18:48 -05:00
2015-06-29 12:08:17 -04:00
# define IMAGE_QUIT ": / icons / quit_128.png"
# define IMAGE_PREFERENCES ": / icons / system_128.png"
# define IMAGE_ABOUT ": / icons / information_128.png"
# define IMAGE_ADDFRIEND ": / icons / add_user_256.png"
# define IMAGE_RETROSHARE ": / icons / logo_128.png"
2015-06-30 12:44:58 -04:00
# define IMAGE_NOONLINE ": / icons / logo_0_connected_128.png"
# define IMAGE_ONEONLINE ": / icons / logo_1_connected_128.png"
# define IMAGE_TWOONLINE ": / icons / logo_2_connected_128.png"
2015-07-06 05:10:57 -04:00
# define IMAGE_OVERLAY ": / icons / star_overlay_128.png"
2015-06-29 12:08:17 -04:00
2007-11-14 22:18:48 -05:00
/* Images for toolbar icons */
2013-02-22 16:42:27 -05:00
//#define IMAGE_NETWORK2 ":/images/rs1.png"
2014-05-09 22:38:47 -04:00
//#define IMAGE_PEERS ":/images/groupchat.png"
//#define IMAGE_TRANSFERS ":/images/ktorrent32.png"
2015-06-29 12:08:17 -04:00
//#define IMAGE_FILES ":/images/fileshare32.png"
//#define IMAGE_CHANNELS ":/images/channels.png"
//#define IMAGE_FORUMS ":/images/konversation.png"
//#define IMAGE_CHAT ":/images/groupchat.png"
//#define IMAGE_STATISTIC ":/images/utilities-system-monitor.png"
2014-05-09 22:38:47 -04:00
//#define IMAGE_MESSAGES ":/images/evolution.png"
2007-11-14 22:18:48 -05:00
# define IMAGE_BWGRAPH ": / images / ksysguard.png"
2015-07-09 17:36:32 -04:00
# define IMAGE_MESSENGER ": / images / rsmessenger48.png"
2007-11-14 22:18:48 -05:00
# define IMAGE_CLOSE ": / images / close_normal.png"
2011-03-04 05:22:00 -05:00
# define IMAGE_BLOCK ": / images / blockdevice.png"
# define IMAGE_COLOR ": / images / highlight.png"
2008-03-30 17:05:14 -04:00
# define IMAGE_GAMES ": / images / kgames.png"
# define IMAGE_PHOTO ": / images / lphoto.png"
2014-05-29 10:49:45 -04:00
# define IMAGE_NEWRSCOLLECTION ": / images / library.png"
2008-03-30 19:28:57 -04:00
# define IMAGE_ADDSHARE ": / images / directoryadd_24x24_shadow.png"
# define IMAGE_OPTIONS ": / images / settings.png"
2008-07-31 11:29:14 -04:00
# define IMAGE_UNFINISHED ": / images / underconstruction.png"
2008-08-02 16:26:29 -04:00
# define IMAGE_MINIMIZE ": / images / window_nofullscreen.png"
# define IMAGE_MAXIMIZE ": / images / window_fullscreen.png"
2014-05-09 22:38:47 -04:00
//#define IMG_HELP ":/images/help24.png"
//#define IMAGE_NEWSFEED ":/images/newsfeed/news-feed-32.png"
2009-02-01 20:30:15 -05:00
# define IMAGE_PLUGINS ": / images / extension_32.png"
2010-02-19 18:23:19 -05:00
# define IMAGE_BLOGS ": / images / kblogger.png"
2013-06-21 20:05:02 -04:00
# define IMAGE_DHT ": / images / dht16.png"
2014-05-09 22:38:47 -04:00
//#define IMAGE_CHATLOBBY ":/images/chat_32.png"
//#define IMAGE_GXSCHANNELS ":/images/channels.png"
//#define IMAGE_GXSFORUMS ":/images/konversation.png"
//#define IMAGE_IDENTITY ":/images/identity/identities_32.png"
//#define IMAGE_CIRCLES ":/images/circles/circles_32.png"
2014-04-27 10:23:27 -04:00
2009-02-01 20:30:15 -05:00
2010-05-02 20:09:55 -04:00
/*static*/ MainWindow * MainWindow : : _instance = NULL ;
/** create main window */
/*static*/ MainWindow * MainWindow : : Create ( )
{
if ( _instance = = NULL ) {
2010-07-17 19:19:43 -04:00
/* _instance is set in constructor */
new MainWindow ( ) ;
2010-05-02 20:09:55 -04:00
}
return _instance ;
}
2007-11-14 22:18:48 -05:00
2010-07-17 19:19:43 -04:00
/*static*/ MainWindow * MainWindow : : getInstance ( )
{
return _instance ;
}
2007-11-14 22:18:48 -05:00
/** Constructor */
2013-10-18 17:10:33 -04:00
MainWindow : : MainWindow ( QWidget * parent , Qt : : WindowFlags flags )
2014-04-27 10:23:27 -04:00
: RWindow ( " MainWindow " , parent , flags )
2007-11-14 22:18:48 -05:00
{
2014-05-29 12:15:26 -04:00
ui = new Ui : : MainWindow ;
trayIcon = NULL ;
2014-05-01 07:46:25 -04:00
2007-11-14 22:18:48 -05:00
/* Invoke the Qt Designer generated QObject setup routine */
2014-05-01 07:46:25 -04:00
ui - > setupUi ( this ) ;
2010-07-17 19:19:43 -04:00
_instance = this ;
m_bStatusLoadDone = false ;
isIdle = false ;
2012-02-24 20:48:56 -05:00
onlineCount = 0 ;
2010-07-17 19:19:43 -04:00
2011-07-13 15:24:33 -04:00
notifyMenu = NULL ;
2010-11-25 19:54:18 -05:00
2011-05-01 19:30:45 -04:00
/* Calculate only once */
RsPeerDetails pd ;
if ( rsPeers - > getPeerDetails ( rsPeers - > getOwnId ( ) , pd ) ) {
nameAndLocation = QString ( " %1 (%2) " ) . arg ( QString : : fromUtf8 ( pd . name . c_str ( ) ) ) . arg ( QString : : fromUtf8 ( pd . location . c_str ( ) ) ) ;
}
2015-08-18 20:21:45 -04:00
setWindowTitle ( tr ( " RetroShare %1 a secure decentralized communication platform " ) . arg ( Rshare : : retroshareVersion ( true ) ) + " - " + nameAndLocation ) ;
2011-07-30 13:13:08 -04:00
2010-11-17 20:18:31 -05:00
/* add url handler for RetroShare links */
2013-03-15 19:08:54 -04:00
QDesktopServices : : setUrlHandler ( RSLINK_SCHEME , this , " retroshareLinkActivated " ) ;
QDesktopServices : : setUrlHandler ( " http " , this , " externalLinkActivated " ) ;
QDesktopServices : : setUrlHandler ( " https " , this , " externalLinkActivated " ) ;
2010-11-17 20:18:31 -05:00
2007-11-14 22:18:48 -05:00
// Setting icons
2015-06-29 12:08:17 -04:00
this - > setWindowIcon ( QIcon ( QString : : fromUtf8 ( " :/icons/logo_128.png " ) ) ) ;
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
/* Create all the dialogs of which we only want one instance */
_bandwidthGraph = new BandwidthGraph ( ) ;
2009-11-30 11:12:13 -05:00
2010-02-24 07:58:24 -05:00
# ifdef UNFINISHED
2007-11-14 22:18:48 -05:00
applicationWindow = new ApplicationWindow ( ) ;
applicationWindow - > hide ( ) ;
2014-05-09 22:38:47 -04:00
# endif
2009-05-01 20:12:29 -04:00
2014-05-09 22:38:47 -04:00
initStackedPage ( ) ;
connect ( ui - > listWidget , SIGNAL ( currentRowChanged ( int ) ) , this , SLOT ( setNewPage ( int ) ) ) ;
connect ( ui - > stackPages , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( setNewPage ( int ) ) ) ;
2014-04-29 07:52:13 -04:00
2014-05-09 22:38:47 -04:00
//ui->stackPages->setCurrentIndex(Settings->getLastPageInMainWindow());
setNewPage ( Settings - > getLastPageInMainWindow ( ) ) ;
2014-12-12 14:44:45 -05:00
ui - > splitter - > setStretchFactor ( 0 , 0 ) ;
ui - > splitter - > setStretchFactor ( 1 , 1 ) ;
2014-05-10 14:05:18 -04:00
/* Load listWidget postion */
2014-11-02 15:21:01 -05:00
QByteArray state = Settings - > valueFromGroup ( " MainWindow " , " SplitterState " , QByteArray ( ) ) . toByteArray ( ) ;
if ( ! state . isEmpty ( ) ) ui - > splitter - > restoreState ( state ) ;
state = Settings - > valueFromGroup ( " MainWindow " , " State " , QByteArray ( ) ) . toByteArray ( ) ;
if ( ! state . isEmpty ( ) ) restoreState ( state ) ;
2009-08-09 10:39:47 -04:00
2009-08-10 19:44:46 -04:00
/** StatusBar section ********/
2010-07-18 17:28:56 -04:00
/* initialize combobox in status bar */
statusComboBox = new QComboBox ( statusBar ( ) ) ;
2011-11-25 18:46:41 -05:00
statusComboBox - > setFocusPolicy ( Qt : : ClickFocus ) ;
2010-07-20 15:45:07 -04:00
initializeStatusObject ( statusComboBox , true ) ;
2010-07-18 17:28:56 -04:00
QWidget * widget = new QWidget ( ) ;
QHBoxLayout * hbox = new QHBoxLayout ( ) ;
hbox - > setMargin ( 0 ) ;
hbox - > setSpacing ( 6 ) ;
hbox - > addWidget ( statusComboBox ) ;
widget - > setLayout ( hbox ) ;
statusBar ( ) - > addWidget ( widget ) ;
2008-06-16 16:28:16 -04:00
peerstatus = new PeerStatus ( ) ;
statusBar ( ) - > addWidget ( peerstatus ) ;
2009-08-09 10:39:47 -04:00
2009-05-01 08:45:27 -04:00
natstatus = new NATStatus ( ) ;
statusBar ( ) - > addWidget ( natstatus ) ;
2010-10-27 08:49:46 -04:00
dhtstatus = new DHTStatus ( ) ;
statusBar ( ) - > addWidget ( dhtstatus ) ;
2008-06-09 20:48:18 -04:00
2010-10-09 14:35:34 -04:00
hashingstatus = new HashingStatus ( ) ;
2015-01-07 06:47:10 -05:00
statusBar ( ) - > addPermanentWidget ( hashingstatus , 1 ) ;
2009-01-04 15:29:55 -05:00
2011-01-07 11:56:57 -05:00
discstatus = new DiscStatus ( ) ;
statusBar ( ) - > addPermanentWidget ( discstatus ) ;
2009-05-02 18:14:20 -04:00
ratesstatus = new RatesStatus ( ) ;
statusBar ( ) - > addPermanentWidget ( ratesstatus ) ;
2012-01-22 17:58:23 -05:00
2014-05-29 12:15:26 -04:00
opModeStatus = new OpModeStatus ( ) ;
statusBar ( ) - > addPermanentWidget ( opModeStatus ) ;
2012-11-25 17:50:38 -05:00
2014-05-29 12:15:26 -04:00
soundStatus = new SoundStatus ( ) ;
soundStatus - > setHidden ( Settings - > valueFromGroup ( " StatusBar " , " HideSound " , QVariant ( false ) ) . toBool ( ) ) ;
statusBar ( ) - > addPermanentWidget ( soundStatus ) ;
toasterDisable = new ToasterDisable ( ) ;
toasterDisable - > setHidden ( Settings - > valueFromGroup ( " StatusBar " , " HideToaster " , QVariant ( false ) ) . toBool ( ) ) ;
statusBar ( ) - > addPermanentWidget ( toasterDisable ) ;
2014-11-02 15:29:06 -05:00
sysTrayStatus = new SysTrayStatus ( ) ;
sysTrayStatus - > setVisible ( Settings - > valueFromGroup ( " StatusBar " , " ShowSysTrayOnStatusBar " , QVariant ( false ) ) . toBool ( ) ) ;
statusBar ( ) - > addPermanentWidget ( sysTrayStatus ) ;
2014-05-29 12:15:26 -04:00
setCompactStatusMode ( Settings - > valueFromGroup ( " StatusBar " , " CompactMode " , QVariant ( false ) ) . toBool ( ) ) ;
2014-05-10 14:32:48 -04:00
2009-08-10 19:44:46 -04:00
/** Status Bar end ******/
2009-08-09 10:39:47 -04:00
2009-11-24 15:17:13 -05:00
/* Creates a tray icon with a context menu and adds it to the system's * notification area. */
createTrayIcon ( ) ;
2009-08-09 10:39:47 -04:00
2012-08-05 16:12:55 -04:00
createNotifyIcons ( ) ;
2014-05-09 22:38:47 -04:00
/* calculate friend count */
2012-02-24 20:48:56 -05:00
updateFriends ( ) ;
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( peerStatusChanged ( QString , int ) ) , this , SLOT ( updateFriends ( ) ) ) ;
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( friendsChanged ( ) ) , this , SLOT ( updateFriends ( ) ) ) ;
2010-07-20 15:45:07 -04:00
loadOwnStatus ( ) ;
2010-07-17 19:19:43 -04:00
2010-07-18 17:28:56 -04:00
/* Set focus to the current page */
2014-05-01 07:46:25 -04:00
ui - > stackPages - > currentWidget ( ) - > setFocus ( ) ;
2010-07-18 17:28:56 -04:00
2010-04-27 08:18:44 -04:00
idle = new Idle ( ) ;
idle - > start ( ) ;
2010-07-17 19:19:43 -04:00
connect ( idle , SIGNAL ( secondsIdle ( int ) ) , this , SLOT ( checkAndSetIdle ( int ) ) ) ;
2010-04-27 08:18:44 -04:00
2009-11-24 15:17:13 -05:00
QTimer * timer = new QTimer ( this ) ;
timer - > connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateStatus ( ) ) ) ;
timer - > start ( 1000 ) ;
2014-05-09 22:38:47 -04:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( settingsChanged ( ) ) , this , SLOT ( settingsChanged ( ) ) ) ;
settingsChanged ( ) ;
2009-11-24 15:17:13 -05:00
}
/** Destructor. */
MainWindow : : ~ MainWindow ( )
{
2014-05-01 07:46:25 -04:00
Settings - > setLastPageInMainWindow ( ui - > stackPages - > currentIndex ( ) ) ;
2014-05-10 14:05:18 -04:00
/* Save listWidget position */
Settings - > setValueToGroup ( " MainWindow " , " SplitterState " , ui - > splitter - > saveState ( ) ) ;
2014-11-02 15:21:01 -05:00
Settings - > setValueToGroup ( " MainWindow " , " State " , saveState ( ) ) ;
2010-11-04 07:14:47 -04:00
2009-11-24 15:17:13 -05:00
delete peerstatus ;
delete natstatus ;
2010-10-27 08:49:46 -04:00
delete dhtstatus ;
2014-05-29 12:15:26 -04:00
delete hashingstatus ;
2011-01-07 11:56:57 -05:00
delete discstatus ;
2014-05-29 12:15:26 -04:00
delete ratesstatus ;
delete opModeStatus ;
delete soundStatus ;
delete toasterDisable ;
2014-11-02 15:29:06 -05:00
delete sysTrayStatus ;
2010-05-11 16:02:52 -04:00
MessengerWindow : : releaseInstance ( ) ;
# ifdef UNFINISHED
2009-11-24 15:17:13 -05:00
delete applicationWindow ;
2010-07-18 07:43:39 -04:00
# endif
2014-05-07 20:00:21 -04:00
delete ( ui ) ;
2009-11-24 15:17:13 -05:00
}
2007-11-14 22:18:48 -05:00
2014-05-09 22:38:47 -04:00
/** Initialyse Stacked Page*/
void MainWindow : : initStackedPage ( )
{
/* WORK OUT IF WE"RE IN ADVANCED MODE OR NOT */
bool advancedMode = false ;
std : : string advsetting ;
if ( rsConfig - > getConfigurationOption ( RS_CONFIG_ADVANCED , advsetting ) & & ( advsetting = = " YES " ) ) {
advancedMode = true ;
}
QList < QPair < MainPage * , QPair < QAction * , QListWidgetItem * > > > notify ;
/* Create the Main pages and actions */
QActionGroup * grp = new QActionGroup ( this ) ;
addPage ( newsFeed = new NewsFeed ( ui - > stackPages ) , grp , & notify ) ;
addPage ( friendsDialog = new FriendsDialog ( ui - > stackPages ) , grp , & notify ) ;
2014-09-09 15:19:18 -04:00
# ifdef RS_USE_CIRCLES
2014-09-10 04:37:27 -04:00
PeopleDialog * peopleDialog = NULL ;
2014-05-09 22:38:47 -04:00
addPage ( peopleDialog = new PeopleDialog ( ui - > stackPages ) , grp , & notify ) ;
2014-09-09 15:19:18 -04:00
# endif
2014-05-09 22:38:47 -04:00
IdDialog * idDialog = NULL ;
addPage ( idDialog = new IdDialog ( ui - > stackPages ) , grp , & notify ) ;
2014-09-09 15:19:18 -04:00
# ifdef RS_USE_CIRCLES
2014-09-10 04:37:27 -04:00
CirclesDialog * circlesDialog = NULL ;
2014-05-09 22:38:47 -04:00
addPage ( circlesDialog = new CirclesDialog ( ui - > stackPages ) , grp , & notify ) ;
2014-09-09 15:19:18 -04:00
# endif
2014-05-09 22:38:47 -04:00
addPage ( transfersDialog = new TransfersDialog ( ui - > stackPages ) , grp , & notify ) ;
addPage ( chatLobbyDialog = new ChatLobbyWidget ( ui - > stackPages ) , grp , & notify ) ;
addPage ( messagesDialog = new MessagesDialog ( ui - > stackPages ) , grp , & notify ) ;
addPage ( gxschannelDialog = new GxsChannelDialog ( ui - > stackPages ) , grp , & notify ) ;
addPage ( gxsforumDialog = new GxsForumsDialog ( ui - > stackPages ) , grp , & notify ) ;
2014-06-01 05:36:56 -04:00
addPage ( postedDialog = new PostedDialog ( ui - > stackPages ) , grp , & notify ) ;
2014-05-09 22:38:47 -04:00
2014-09-09 15:19:18 -04:00
# ifdef RS_USE_WIKI
2014-09-10 04:37:27 -04:00
WikiDialog * wikiDialog = NULL ;
2014-05-09 22:38:47 -04:00
addPage ( wikiDialog = new WikiDialog ( ui - > stackPages ) , grp , & notify ) ;
2014-09-09 15:19:18 -04:00
# endif
2014-05-09 22:38:47 -04:00
# ifdef BLOGS
addPage ( blogsFeed = new BlogsDialog ( ui - > stackPages ) , grp , NULL ) ;
# endif
std : : cerr < < " Looking for interfaces in existing plugins: " < < std : : endl ;
for ( int i = 0 ; i < rsPlugins - > nbPlugins ( ) ; + + i )
{
2015-08-05 17:41:04 -04:00
MainPage * pluginPage = NULL ;
QIcon icon , * pIcon = NULL ;
2014-05-09 22:38:47 -04:00
2015-08-05 17:41:04 -04:00
if ( rsPlugins - > plugin ( i ) ! = NULL & & ( pluginPage = rsPlugins - > plugin ( i ) - > qt_page ( ) ) ! = NULL )
2014-05-09 22:38:47 -04:00
{
2015-08-05 17:41:04 -04:00
if ( ( pIcon = rsPlugins - > plugin ( i ) - > qt_icon ( ) ) ! = NULL )
icon = * pIcon ;
2014-05-09 22:38:47 -04:00
else
icon = QIcon ( " :images/extension_48.png " ) ;
2015-12-02 09:18:17 -05:00
std : : cerr < < " Adding widget page for plugin " < < rsPlugins - > plugin ( i ) - > getPluginName ( ) < < std : : endl ;
2014-05-09 22:38:47 -04:00
pluginPage - > setIconPixmap ( icon ) ;
pluginPage - > setPageName ( QString : : fromUtf8 ( rsPlugins - > plugin ( i ) - > getPluginName ( ) . c_str ( ) ) ) ;
addPage ( pluginPage , grp , & notify ) ;
}
else if ( rsPlugins - > plugin ( i ) = = NULL )
std : : cerr < < " No plugin object ! " < < std : : endl ;
else
std : : cerr < < " No plugin page ! " < < std : : endl ;
}
# ifndef RS_RELEASE_VERSION
# ifdef PLUGINMGR
addPage ( pluginsPage = new PluginsPage ( ui - > stackPages ) , grp , NULL ) ;
# endif
# endif
# ifdef GETSTARTED_GUI
MainPage * getStartedPage = NULL ;
if ( ! advancedMode )
{
//ui->stackPages->add(getStartedPage = new GetStartedDialog(ui->stackPages),
// createPageAction(QIcon(IMG_HELP), tr("Getting Started"), grp));
addPage ( getStartedPage = new GetStartedDialog ( ui - > stackPages ) , grp , NULL ) ;
}
# endif
/* Create the toolbar */
ui - > toolBarPage - > addActions ( grp - > actions ( ) ) ;
connect ( grp , SIGNAL ( triggered ( QAction * ) ) , ui - > stackPages , SLOT ( showPage ( QAction * ) ) ) ;
# ifdef UNFINISHED
2014-05-10 14:05:18 -04:00
addAction ( new QAction ( QIcon ( IMAGE_UNFINISHED ) , tr ( " Unfinished " ) , ui - > toolBar ) , & MainWindow : : showApplWindow , SLOT ( showApplWindow ( ) ) ) ;
2014-05-09 22:38:47 -04:00
ui - > toolBarAction - > addSeparator ( ) ;
notify + = applicationWindow - > getNotify ( ) ;
# endif
2014-05-10 14:05:18 -04:00
/** Add icon on Action bar */
addAction ( new QAction ( QIcon ( IMAGE_ADDFRIEND ) , tr ( " Add " ) , ui - > toolBarAction ) , & MainWindow : : addFriend , SLOT ( addFriend ( ) ) ) ;
2014-05-29 12:15:26 -04:00
//addAction(new QAction(QIcon(IMAGE_NEWRSCOLLECTION), tr("New"), ui->toolBarAction), &MainWindow::newRsCollection, SLOT(newRsCollection()));
2014-05-10 14:05:18 -04:00
addAction ( new QAction ( QIcon ( IMAGE_PREFERENCES ) , tr ( " Options " ) , ui - > toolBarAction ) , & MainWindow : : showSettings , SLOT ( showSettings ( ) ) ) ;
addAction ( new QAction ( QIcon ( IMAGE_ABOUT ) , tr ( " About " ) , ui - > toolBarAction ) , & MainWindow : : showabout , SLOT ( showabout ( ) ) ) ;
addAction ( new QAction ( QIcon ( IMAGE_QUIT ) , tr ( " Quit " ) , ui - > toolBarAction ) , & MainWindow : : doQuit , SLOT ( doQuit ( ) ) ) ;
2014-05-09 22:38:47 -04:00
QList < QPair < MainPage * , QPair < QAction * , QListWidgetItem * > > > : : iterator notifyIt ;
for ( notifyIt = notify . begin ( ) ; notifyIt ! = notify . end ( ) ; + + notifyIt ) {
UserNotify * userNotify = notifyIt - > first - > getUserNotify ( this ) ;
if ( userNotify ) {
userNotify - > initialize ( ui - > toolBarPage , notifyIt - > second . first , notifyIt - > second . second ) ;
connect ( userNotify , SIGNAL ( countChanged ( ) ) , this , SLOT ( updateTrayCombine ( ) ) ) ;
userNotifyList . push_back ( userNotify ) ;
}
}
}
/** Creates a new action associated with a config page. */
QAction * MainWindow : : createPageAction ( const QIcon & icon , const QString & text , QActionGroup * group )
{
QAction * action = new QAction ( icon , text , group ) ;
action - > setCheckable ( true ) ;
return action ;
}
/** Adds the given action to the toolbar and hooks its triggered() signal to
2014-05-10 14:05:18 -04:00
* the specified slot ( if given ) .
* Have to pass function pointer and slot , because we can ' t make slot of function pointer */
void MainWindow : : addAction ( QAction * action , FunctionType actionFunction , const char * slot )
2014-05-09 22:38:47 -04:00
{
ui - > toolBarAction - > addAction ( action ) ;
2014-05-10 14:05:18 -04:00
if ( slot ) connect ( action , SIGNAL ( triggered ( ) ) , this , slot ) ;
2014-05-09 22:38:47 -04:00
QListWidgetItem * item = new QListWidgetItem ( action - > icon ( ) , action - > text ( ) ) ;
item - > setData ( Qt : : UserRole , QString ( slot ) ) ;
ui - > listWidget - > addItem ( item ) ;
2014-05-10 14:05:18 -04:00
if ( slot ) _functionList [ slot ] = actionFunction ;
2014-05-09 22:38:47 -04:00
}
/** Add the given page to the stackPage and list. */
void MainWindow : : addPage ( MainPage * page , QActionGroup * grp , QList < QPair < MainPage * , QPair < QAction * , QListWidgetItem * > > > * notify )
{
QAction * action ;
ui - > stackPages - > add ( page , action = createPageAction ( page - > iconPixmap ( ) , page - > pageName ( ) , grp ) ) ;
QListWidgetItem * item = new QListWidgetItem ( QIcon ( page - > iconPixmap ( ) ) , page - > pageName ( ) ) ;
ui - > listWidget - > addItem ( item ) ;
if ( notify )
{
QPair < QAction * , QListWidgetItem * > pair = QPair < QAction * , QListWidgetItem * > ( action , item ) ;
notify - > push_back ( QPair < MainPage * , QPair < QAction * , QListWidgetItem * > > ( page , pair ) ) ;
}
}
/** Selection page. */
void MainWindow : : setNewPage ( int page )
{
MainPage * pagew = dynamic_cast < MainPage * > ( ui - > stackPages - > widget ( page ) ) ;
if ( pagew )
{
ui - > stackPages - > setCurrentIndex ( page ) ;
ui - > listWidget - > setCurrentRow ( page ) ;
} else {
QString procName = ui - > listWidget - > item ( page ) - > data ( Qt : : UserRole ) . toString ( ) ;
2014-05-10 14:05:18 -04:00
FunctionType function = _functionList [ procName ] ;
if ( function ) ( this - > * function ) ( ) ;
2014-05-09 22:38:47 -04:00
ui - > listWidget - > setCurrentRow ( ui - > stackPages - > currentIndex ( ) ) ;
}
}
2010-05-21 16:49:48 -04:00
void MainWindow : : displayDiskSpaceWarning ( int loc , int size_limit_mb )
{
QString locString ;
switch ( loc )
{
case RS_PARTIALS_DIRECTORY : locString = " Partials " ;
break ;
case RS_CONFIG_DIRECTORY : locString = " Config " ;
break ;
case RS_DOWNLOAD_DIRECTORY : locString = " Download " ;
break ;
default :
std : : cerr < < " Error: " < < __PRETTY_FUNCTION__ < < " was called with an unknown parameter loc= " < < loc < < std : : endl ;
return ;
}
QMessageBox : : critical ( NULL , tr ( " Low disk space warning " ) ,
2015-06-12 04:27:26 -04:00
tr ( " The disk space in your " ) + " " + locString + " " + tr ( " directory is running low (current limit is " ) + " " + QString : : number ( size_limit_mb ) + tr ( " MB). \n \n RetroShare will now safely suspend any disk access to this directory. \n \n Please make some free space and click Ok. " ) ) ;
2010-05-21 16:49:48 -04:00
}
2009-11-24 15:17:13 -05:00
/** Creates a tray icon with a context menu and adds it to the system
* notification area . */
void MainWindow : : createTrayIcon ( )
{
2009-08-10 19:44:46 -04:00
/** Tray icon Menu **/
2010-11-25 19:54:18 -05:00
QMenu * trayMenu = new QMenu ( this ) ;
2014-11-02 15:29:06 -05:00
if ( sysTrayStatus ) sysTrayStatus - > trayMenu = trayMenu ;
2010-01-01 08:45:35 -05:00
QObject : : connect ( trayMenu , SIGNAL ( aboutToShow ( ) ) , this , SLOT ( updateMenu ( ) ) ) ;
2010-08-09 08:16:21 -04:00
toggleVisibilityAction = trayMenu - > addAction ( QIcon ( IMAGE_RETROSHARE ) , tr ( " Show/Hide " ) , this , SLOT ( toggleVisibilitycontextmenu ( ) ) ) ;
2014-11-02 15:29:06 -05:00
if ( sysTrayStatus ) sysTrayStatus - > toggleVisibilityAction = toggleVisibilityAction ;
2010-07-17 19:19:43 -04:00
2011-07-13 15:24:33 -04:00
/* Create status menu */
QMenu * statusMenu = trayMenu - > addMenu ( tr ( " Status " ) ) ;
initializeStatusObject ( statusMenu , true ) ;
/* Create notify menu */
notifyMenu = trayMenu - > addMenu ( tr ( " Notify " ) ) ;
notifyMenu - > menuAction ( ) - > setVisible ( false ) ;
2010-07-17 19:19:43 -04:00
2010-01-01 08:45:35 -05:00
trayMenu - > addSeparator ( ) ;
2015-07-09 17:36:32 -04:00
trayMenu - > addAction ( QIcon ( IMAGE_MESSENGER ) , tr ( " Open Messenger " ) , this , SLOT ( showMessengerWindow ( ) ) ) ;
2011-05-01 19:30:45 -04:00
trayMenu - > addAction ( QIcon ( IMAGE_MESSAGES ) , tr ( " Open Messages " ) , this , SLOT ( showMess ( ) ) ) ;
2015-04-28 10:55:13 -04:00
trayMenu - > addAction ( QIcon ( " :/images/emblem-web.png " ) , tr ( " Show web interface " ) , this , SLOT ( showWebinterface ( ) ) ) ;
2011-05-01 19:30:45 -04:00
trayMenu - > addAction ( QIcon ( IMAGE_BWGRAPH ) , tr ( " Bandwidth Graph " ) , _bandwidthGraph , SLOT ( showWindow ( ) ) ) ;
2014-09-04 13:01:28 -04:00
trayMenu - > addAction ( QIcon ( IMAGE_DHT ) , tr ( " Statistics " ) , this , SLOT ( showStatisticsWindow ( ) ) ) ;
2007-11-18 18:35:53 -05:00
2009-12-05 08:42:24 -05:00
# ifdef UNFINISHED
2011-05-01 19:30:45 -04:00
trayMenu - > addAction ( QIcon ( IMAGE_UNFINISHED ) , tr ( " Applications " ) , this , SLOT ( showApplWindow ( ) ) ) ;
2007-11-14 22:18:48 -05:00
# endif
2011-05-01 19:30:45 -04:00
trayMenu - > addAction ( QIcon ( IMAGE_PREFERENCES ) , tr ( " Options " ) , this , SLOT ( showSettings ( ) ) ) ;
trayMenu - > addAction ( QIcon ( IMG_HELP ) , tr ( " Help " ) , this , SLOT ( showHelpDialog ( ) ) ) ;
2010-01-01 08:45:35 -05:00
trayMenu - > addSeparator ( ) ;
trayMenu - > addAction ( QIcon ( IMAGE_MINIMIZE ) , tr ( " Minimize " ) , this , SLOT ( showMinimized ( ) ) ) ;
trayMenu - > addAction ( QIcon ( IMAGE_MAXIMIZE ) , tr ( " Maximize " ) , this , SLOT ( showMaximized ( ) ) ) ;
trayMenu - > addSeparator ( ) ;
trayMenu - > addAction ( QIcon ( IMAGE_CLOSE ) , tr ( " &Quit " ) , this , SLOT ( doQuit ( ) ) ) ;
2009-08-10 19:44:46 -04:00
/** End of Icon Menu **/
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
// Create the tray icon
trayIcon = new QSystemTrayIcon ( this ) ;
trayIcon - > setToolTip ( tr ( " RetroShare " ) ) ;
2010-01-01 08:45:35 -05:00
trayIcon - > setContextMenu ( trayMenu ) ;
2009-05-20 18:51:15 -04:00
trayIcon - > setIcon ( QIcon ( IMAGE_NOONLINE ) ) ;
2009-08-09 10:39:47 -04:00
2010-08-09 08:16:21 -04:00
connect ( trayIcon , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) , this , SLOT ( toggleVisibility ( QSystemTrayIcon : : ActivationReason ) ) ) ;
2007-11-14 22:18:48 -05:00
trayIcon - > show ( ) ;
2010-11-25 19:54:18 -05:00
}
void MainWindow : : createNotifyIcons ( )
{
2012-08-05 16:12:55 -04:00
/* create notify icons */
QList < UserNotify * > : : iterator it ;
for ( it = userNotifyList . begin ( ) ; it ! = userNotifyList . end ( ) ; + + it ) {
UserNotify * userNotify = * it ;
userNotify - > createIcons ( notifyMenu ) ;
userNotify - > updateIcon ( ) ;
2010-11-25 19:54:18 -05:00
}
2012-10-24 04:34:42 -04:00
updateTrayCombine ( ) ;
2012-08-05 16:12:55 -04:00
}
2010-11-25 19:54:18 -05:00
2012-08-05 16:12:55 -04:00
const QList < UserNotify * > & MainWindow : : getUserNotifyList ( )
{
return userNotifyList ;
2009-10-04 11:17:06 -04:00
}
2012-08-05 16:12:55 -04:00
2012-07-30 09:27:40 -04:00
/*static*/ void MainWindow : : displayLobbySystrayMsg ( const QString & title , const QString & msg )
{
if ( _instance = = NULL )
return ;
if ( Settings - > getDisplayTrayChatLobby ( ) )
_instance - > displaySystrayMsg ( title , msg ) ;
}
2009-10-04 11:17:06 -04:00
2010-06-15 12:51:48 -04:00
/*static*/ void MainWindow : : installGroupChatNotifier ( )
{
if ( _instance = = NULL ) {
// nothing to do
return ;
}
if ( Settings - > getDisplayTrayGroupChat ( ) ) {
2011-05-17 13:27:47 -04:00
QObject : : connect ( _instance - > friendsDialog , SIGNAL ( notifyGroupChat ( const QString & , const QString & ) ) , _instance , SLOT ( displaySystrayMsg ( const QString & , const QString & ) ) , Qt : : QueuedConnection ) ;
2010-06-15 12:51:48 -04:00
} else {
2011-05-17 13:27:47 -04:00
QObject : : disconnect ( _instance - > friendsDialog , SIGNAL ( notifyGroupChat ( const QString & , const QString & ) ) , _instance , SLOT ( displaySystrayMsg ( const QString & , const QString & ) ) ) ;
2010-06-15 12:51:48 -04:00
}
}
2010-11-25 19:54:18 -05:00
/*static*/ void MainWindow : : installNotifyIcons ( )
{
if ( _instance = = NULL ) {
// nothing to do
return ;
}
_instance - > createNotifyIcons ( ) ;
}
2009-07-13 10:01:49 -04:00
void MainWindow : : displaySystrayMsg ( const QString & title , const QString & msg )
{
2010-01-01 08:45:35 -05:00
trayIcon - > showMessage ( title , msg , QSystemTrayIcon : : Information , 3000 ) ;
2009-07-13 10:01:49 -04:00
}
2010-11-25 19:54:18 -05:00
void MainWindow : : updateTrayCombine ( )
{
2011-07-13 15:24:33 -04:00
notifyToolTip . clear ( ) ;
2010-11-25 19:54:18 -05:00
2011-07-13 15:24:33 -04:00
bool visible = false ;
2010-11-25 19:54:18 -05:00
2011-07-13 15:24:33 -04:00
if ( notifyMenu ) {
QList < QAction * > actions = notifyMenu - > actions ( ) ;
int count = 0 ;
2010-11-25 19:54:18 -05:00
QList < QAction * > : : iterator actionIt ;
2014-10-21 18:33:02 -04:00
for ( actionIt = actions . begin ( ) ; actionIt ! = actions . end ( ) ; + + actionIt ) {
2010-11-25 19:54:18 -05:00
if ( ( * actionIt ) - > isVisible ( ) ) {
visible = true ;
2011-07-13 15:24:33 -04:00
count + = ( * actionIt ) - > data ( ) . toInt ( ) ;
// ToolTip is too long to show all services
// if (notifyToolTip.isEmpty() == false) {
// notifyToolTip += "\r";
// }
// notifyToolTip += (*actionIt)->data().toString() + ":" + (*actionIt)->text();
}
if ( visible ) {
notifyToolTip = ( ( count = = 1 ) ? tr ( " %1 new message " ) : tr ( " %1 new messages " ) ) . arg ( count ) ;
2010-11-25 19:54:18 -05:00
}
2011-07-13 15:24:33 -04:00
}
2010-11-24 19:20:25 -05:00
}
2011-07-13 15:24:33 -04:00
notifyMenu - > menuAction ( ) - > setVisible ( visible ) ;
2012-02-29 18:03:09 -05:00
// update tray icon
updateFriends ( ) ;
2010-11-24 19:20:25 -05:00
}
2015-09-01 08:43:29 -04:00
void MainWindow : : toggleStatusToolTip ( bool toggle ) {
2015-09-01 20:09:39 -04:00
if ( ! toggle ) return ;
2015-09-01 08:43:29 -04:00
QString tray = " RetroShare \n " ;
tray + = " \n " + nameAndLocation ;
trayIcon - > setToolTip ( tray ) ;
}
2010-08-09 08:16:21 -04:00
void MainWindow : : updateStatus ( )
{
// This call is essential to remove locks due to QEventLoop re-entrance while asking gpg passwds. Dont' remove it!
if ( RsAutoUpdatePage : : eventsLocked ( ) )
return ;
2015-09-01 08:43:29 -04:00
if ( Settings - > valueFromGroup ( " StatusBar " , " DisableSysTrayToolTip " , QVariant ( false ) ) . toBool ( ) )
return ;
2010-10-27 17:29:48 -04:00
float downKb = 0 ;
float upKb = 0 ;
2012-11-25 15:26:32 -05:00
rsConfig - > GetCurrentDataRates ( downKb , upKb ) ;
2009-08-09 10:39:47 -04:00
2010-08-09 08:16:21 -04:00
if ( ratesstatus )
2010-10-28 06:41:19 -04:00
ratesstatus - > getRatesStatus ( downKb , upKb ) ;
2010-02-27 12:47:52 -05:00
2010-08-09 08:16:21 -04:00
if ( natstatus )
natstatus - > getNATStatus ( ) ;
2010-10-27 08:49:46 -04:00
if ( dhtstatus )
dhtstatus - > getDHTStatus ( ) ;
2010-08-09 08:16:21 -04:00
2011-01-07 11:56:57 -05:00
if ( discstatus ) {
discstatus - > update ( ) ;
}
2012-02-24 20:48:56 -05:00
QString tray = " RetroShare \n " + tr ( " Down: %1 (kB/s) " ) . arg ( downKb , 0 , ' f ' , 2 ) + " | " + tr ( " Up: %1 (kB/s) " ) . arg ( upKb , 0 , ' f ' , 2 ) + " \n " ;
if ( onlineCount = = 1 ) {
tray + = tr ( " %1 friend connected " ) . arg ( onlineCount ) ;
} else {
tray + = tr ( " %1 friends connected " ) . arg ( onlineCount ) ;
}
tray + = " \n " + nameAndLocation ;
if ( ! notifyToolTip . isEmpty ( ) ) {
tray + = " \n " ;
tray + = notifyToolTip ;
}
trayIcon - > setToolTip ( tray ) ;
}
void MainWindow : : updateFriends ( )
{
2013-10-16 16:42:34 -04:00
if ( RsAutoUpdatePage : : eventsLocked ( ) )
return ;
2012-02-24 20:48:56 -05:00
unsigned int friendCount = 0 ;
rsPeers - > getPeerCount ( & friendCount , & onlineCount , false ) ;
if ( peerstatus )
peerstatus - > getPeerStatus ( friendCount , onlineCount ) ;
2011-07-13 15:24:33 -04:00
QString trayIconResource ;
2012-02-24 20:48:56 -05:00
if ( onlineCount = = 0 ) {
2011-07-13 15:24:33 -04:00
trayIconResource = IMAGE_NOONLINE ;
2012-02-24 20:48:56 -05:00
} else if ( onlineCount < 2 ) {
2011-07-13 15:24:33 -04:00
trayIconResource = IMAGE_ONEONLINE ;
2012-02-24 20:48:56 -05:00
} else if ( onlineCount < 3 ) {
2011-07-13 15:24:33 -04:00
trayIconResource = IMAGE_TWOONLINE ;
2012-02-24 20:48:56 -05:00
} else {
2011-07-13 15:24:33 -04:00
trayIconResource = IMAGE_RETROSHARE ;
}
QIcon icon ;
if ( notifyMenu & & notifyMenu - > menuAction ( ) - > isVisible ( ) ) {
QPixmap trayImage ( trayIconResource ) ;
2015-07-06 05:10:57 -04:00
QPixmap overlayImage ( IMAGE_OVERLAY ) ;
2011-07-13 15:24:33 -04:00
QPainter painter ( & trayImage ) ;
painter . drawPixmap ( 0 , 0 , overlayImage ) ;
icon . addPixmap ( trayImage ) ;
} else {
icon = QIcon ( trayIconResource ) ;
2010-08-09 08:16:21 -04:00
}
2010-10-27 17:29:48 -04:00
2014-05-29 12:15:26 -04:00
if ( trayIcon ) trayIcon - > setIcon ( icon ) ;
2014-11-02 15:29:06 -05:00
if ( sysTrayStatus ) sysTrayStatus - > setIcon ( icon ) ;
2008-06-15 11:34:56 -04:00
}
2010-04-24 18:09:47 -04:00
void MainWindow : : postModDirectories ( bool update_local )
{
RSettingsWin : : postModDirectories ( update_local ) ;
ShareManager : : postModDirectories ( update_local ) ;
QCoreApplication : : flush ( ) ;
}
2012-03-30 19:02:52 -04:00
# ifdef WINDOWS_SYS
//void SetForegroundWindowInternal(HWND hWnd)
//{
// if (!::IsWindow(hWnd)) return;
// // relation time of SetForegroundWindow lock
// DWORD lockTimeOut = 0;
// HWND hCurrWnd = ::GetForegroundWindow();
// DWORD dwThisTID = ::GetCurrentThreadId(),
// dwCurrTID = ::GetWindowThreadProcessId(hCurrWnd,0);
// // we need to bypass some limitations from Microsoft :)
// if (dwThisTID != dwCurrTID) {
// ::AttachThreadInput(dwThisTID, dwCurrTID, TRUE);
// ::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,&lockTimeOut,0);
// ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,0,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
// ::AllowSetForegroundWindow(ASFW_ANY);
// }
// ::SetForegroundWindow(hWnd);
// if(dwThisTID != dwCurrTID) {
// ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,(PVOID)lockTimeOut,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
// ::AttachThreadInput(dwThisTID, dwCurrTID, FALSE);
// }
//}
void SetForegroundWindowInternal ( HWND hWnd )
{
if ( ! : : IsWindow ( hWnd ) ) return ;
BYTE keyState [ 256 ] = { 0 } ;
// to unlock SetForegroundWindow we need to imitate Alt pressing
if ( : : GetKeyboardState ( ( LPBYTE ) & keyState ) ) {
if ( ! ( keyState [ VK_MENU ] & 0x80 ) ) {
: : keybd_event ( VK_MENU , 0 , KEYEVENTF_EXTENDEDKEY | 0 , 0 ) ;
}
}
: : SetForegroundWindow ( hWnd ) ;
if ( : : GetKeyboardState ( ( LPBYTE ) & keyState ) ) {
if ( ! ( keyState [ VK_MENU ] & 0x80 ) ) {
: : keybd_event ( VK_MENU , 0 , KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP , 0 ) ;
}
}
}
# endif
/*static*/ void MainWindow : : raiseWindow ( )
{
if ( _instance = = NULL ) {
return ;
}
/* Show the dialog. */
_instance - > show ( ) ;
_instance - > raise ( ) ;
# ifdef WINDOWS_SYS
2013-10-19 19:41:23 -04:00
SetForegroundWindowInternal ( ( HWND ) _instance - > winId ( ) ) ;
2012-03-30 19:02:52 -04:00
# endif
}
2009-01-07 16:12:31 -05:00
/** Shows the MainWindow with focus set to the given page. */
2010-05-23 17:32:58 -04:00
/*static*/ void MainWindow : : showWindow ( Page page )
2007-11-14 22:18:48 -05:00
{
2010-05-23 17:32:58 -04:00
if ( _instance = = NULL ) {
return ;
}
2007-11-14 22:18:48 -05:00
2009-01-07 16:12:31 -05:00
/* Show the dialog. */
2012-03-30 19:02:52 -04:00
raiseWindow ( ) ;
2007-11-14 22:18:48 -05:00
/* Set the focus to the specified page. */
2010-05-02 20:09:55 -04:00
activatePage ( page ) ;
2007-11-14 22:18:48 -05:00
}
2012-12-20 08:30:16 -05:00
/** Shows the MainWindow with focus set to the given page. */
/*static*/ void MainWindow : : showWindow ( MainPage * page )
{
if ( _instance = = NULL ) {
return ;
}
/* Show the dialog. */
raiseWindow ( ) ;
/* Set the focus to the specified page. */
2014-05-01 07:46:25 -04:00
_instance - > ui - > stackPages - > setCurrentPage ( page ) ;
2012-12-20 08:30:16 -05:00
}
2010-05-02 20:09:55 -04:00
/** Set focus to the given page. */
2010-11-04 07:14:47 -04:00
/*static*/ bool MainWindow : : activatePage ( Page page )
2010-05-02 20:09:55 -04:00
{
if ( _instance = = NULL ) {
2010-11-04 07:14:47 -04:00
return false ;
2010-05-02 20:09:55 -04:00
}
2013-02-22 16:42:27 -05:00
switch ( page ) {
2013-02-23 09:29:36 -05:00
case Search :
2014-05-01 07:46:25 -04:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > transfersDialog ) ;
2013-02-23 09:29:36 -05:00
_instance - > transfersDialog - > activatePage ( TransfersDialog : : SearchTab ) ;
break ;
case Network :
2014-05-01 07:46:25 -04:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > friendsDialog ) ;
2013-02-23 09:29:36 -05:00
_instance - > friendsDialog - > activatePage ( FriendsDialog : : NetworkTab ) ;
break ;
2013-02-22 16:42:27 -05:00
case Friends :
2014-05-01 07:46:25 -04:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > friendsDialog ) ;
2013-02-22 16:42:27 -05:00
break ;
case ChatLobby :
2014-05-01 07:46:25 -04:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > chatLobbyDialog ) ;
2013-02-22 16:42:27 -05:00
break ;
case Transfers :
2014-05-01 07:46:25 -04:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > transfersDialog ) ;
2013-02-22 16:42:27 -05:00
break ;
2013-02-23 09:29:36 -05:00
case SharedDirectories :
2014-05-01 07:46:25 -04:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > transfersDialog ) ;
2013-02-23 09:29:36 -05:00
_instance - > transfersDialog - > activatePage ( TransfersDialog : : LocalSharedFilesTab ) ;
2013-02-22 16:42:27 -05:00
break ;
case Messages :
2014-05-01 07:46:25 -04:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > messagesDialog ) ;
2013-02-22 16:42:27 -05:00
break ;
case Channels :
2014-05-27 17:14:05 -04:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > gxschannelDialog ) ;
2013-02-23 09:29:36 -05:00
return true ;
2013-02-22 16:42:27 -05:00
case Forums :
2014-05-27 17:14:05 -04:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > gxsforumDialog ) ;
return true ;
2010-05-02 20:09:55 -04:00
# ifdef BLOGS
2013-02-22 16:42:27 -05:00
case Blogs :
Page = _instance - > blogsFeed ;
2013-02-23 09:29:36 -05:00
return true ;
2010-05-02 20:09:55 -04:00
# endif
2014-07-22 11:04:36 -04:00
case Posted :
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > postedDialog ) ;
return true ;
2013-02-22 16:42:27 -05:00
default :
2013-02-23 09:29:36 -05:00
std : : cerr < < " Show page called on value that is not handled yet. Please code it! (value = " < < page < < " ) " < < std : : endl ;
2013-02-22 16:42:27 -05:00
}
2010-05-02 20:09:55 -04:00
2013-02-23 09:29:36 -05:00
return false ;
2010-11-04 07:14:47 -04:00
}
/** Get the active page. */
/*static*/ MainWindow : : Page MainWindow : : getActivatePage ( )
{
if ( _instance = = NULL ) {
return Network ;
}
2014-05-01 07:46:25 -04:00
QWidget * page = _instance - > ui - > stackPages - > currentWidget ( ) ;
2010-11-04 07:14:47 -04:00
2013-02-22 16:42:27 -05:00
// if (page == _instance->networkDialog) {
// return Network;
// }
2011-05-17 13:27:47 -04:00
if ( page = = _instance - > friendsDialog ) {
2010-11-04 07:14:47 -04:00
return Friends ;
}
2013-02-22 16:42:27 -05:00
if ( page = = _instance - > chatLobbyDialog ) {
return ChatLobby ;
2010-11-04 07:14:47 -04:00
}
if ( page = = _instance - > transfersDialog ) {
return Transfers ;
}
2013-02-22 16:42:27 -05:00
// if (page == _instance->sharedfilesDialog) {
// return SharedDirectories;
// }
2010-11-04 07:14:47 -04:00
if ( page = = _instance - > messagesDialog ) {
return Messages ;
}
2010-11-20 15:58:35 -05:00
# ifdef RS_USE_LINKS
2010-11-04 07:14:47 -04:00
if ( page = = _instance - > linksDialog ) {
return Links ;
}
2010-12-26 19:09:14 -05:00
# endif
2013-09-07 00:21:48 -04:00
#if 0
2010-11-04 07:14:47 -04:00
if ( page = = _instance - > channelFeed ) {
return Channels ;
}
if ( page = = _instance - > forumsDialog ) {
return Forums ;
}
2013-09-07 00:21:48 -04:00
# endif
2010-11-04 07:14:47 -04:00
# ifdef BLOGS
if ( page = = _instance - > blogsFeed ) {
return Blogs ;
}
# endif
return Network ;
2010-05-02 20:09:55 -04:00
}
2007-11-14 22:18:48 -05:00
2010-05-27 15:48:52 -04:00
/** get page */
/*static*/ MainPage * MainWindow : : getPage ( Page page )
{
if ( _instance = = NULL ) {
return NULL ;
}
2013-02-23 08:24:16 -05:00
switch ( page )
{
case Network :
return _instance - > friendsDialog - > networkDialog ;
case Friends :
return _instance - > friendsDialog ;
case ChatLobby :
return _instance - > chatLobbyDialog ;
case Transfers :
return _instance - > transfersDialog ;
case SharedDirectories :
return _instance - > transfersDialog - > localSharedFiles ;
case Search :
return _instance - > transfersDialog - > searchDialog ;
case Messages :
return _instance - > messagesDialog ;
2010-11-20 15:58:35 -05:00
# ifdef RS_USE_LINKS
2013-02-23 08:24:16 -05:00
case Links :
return _instance - > linksDialog ;
2010-11-17 18:53:58 -05:00
# endif
2013-02-23 08:24:16 -05:00
case Channels :
2014-07-24 19:26:04 -04:00
return _instance - > gxschannelDialog ;
2013-02-23 08:24:16 -05:00
case Forums :
2014-07-24 19:26:04 -04:00
return _instance - > gxsforumDialog ;
case Posted :
return _instance - > postedDialog ;
2010-05-27 15:48:52 -04:00
# ifdef BLOGS
2013-02-23 08:24:16 -05:00
case Blogs :
return _instance - > blogsFeed ;
2010-05-27 15:48:52 -04:00
# endif
2013-02-23 08:24:16 -05:00
}
2010-05-27 15:48:52 -04:00
return NULL ;
}
2007-11-14 22:18:48 -05:00
/***** TOOL BAR FUNCTIONS *****/
/** Add a Friend ShortCut */
void MainWindow : : addFriend ( )
{
2010-05-02 20:09:55 -04:00
ConnectFriendWizard connwiz ( this ) ;
2007-11-14 22:18:48 -05:00
2010-05-02 20:09:55 -04:00
connwiz . exec ( ) ;
2007-11-14 22:18:48 -05:00
}
2014-05-29 10:49:45 -04:00
/** New RSCollection ShortCut */
void MainWindow : : newRsCollection ( )
{
std : : vector < DirDetails > dirVec ;
RsCollectionFile ( dirVec ) . openNewColl ( this ) ;
}
2009-01-07 16:12:31 -05:00
/** Shows Share Manager */
2008-12-10 20:19:34 -05:00
void MainWindow : : openShareManager ( )
{
2010-04-24 18:09:47 -04:00
ShareManager : : showYourself ( ) ;
2008-12-10 20:19:34 -05:00
}
2009-01-07 16:12:31 -05:00
/** Shows Messages Dialog */
void
2010-05-02 20:09:55 -04:00
MainWindow : : showMess ( )
2009-01-07 16:12:31 -05:00
{
2010-05-02 20:09:55 -04:00
showWindow ( MainWindow : : Messages ) ;
2009-01-07 16:12:31 -05:00
}
2007-11-14 22:18:48 -05:00
/** Shows Options */
2009-07-23 13:11:51 -04:00
void MainWindow : : showSettings ( )
{
2010-04-24 18:09:47 -04:00
RSettingsWin : : showYourself ( this ) ;
2009-07-23 13:11:51 -04:00
}
2007-11-14 22:18:48 -05:00
/** Shows Messenger window */
void MainWindow : : showMessengerWindow ( )
{
2010-07-18 07:43:39 -04:00
MessengerWindow : : showYourself ( ) ;
2007-11-14 22:18:48 -05:00
}
2014-09-04 13:01:28 -04:00
/** Shows Statistics window */
void MainWindow : : showStatisticsWindow ( )
2011-07-06 09:08:27 -04:00
{
2014-09-04 13:01:28 -04:00
StatisticsWindow : : showYourself ( ) ;
2015-04-28 10:55:13 -04:00
}
2014-09-04 13:01:28 -04:00
2015-04-28 10:55:13 -04:00
void MainWindow : : showWebinterface ( )
{
WebuiPage : : showWebui ( ) ;
2011-07-06 09:08:27 -04:00
}
2007-11-14 22:18:48 -05:00
/** Shows Application window */
2009-12-05 08:42:24 -05:00
# ifdef UNFINISHED
2007-11-14 22:18:48 -05:00
void MainWindow : : showApplWindow ( )
{
applicationWindow - > show ( ) ;
}
2009-12-05 08:42:24 -05:00
# endif
2007-11-14 22:18:48 -05:00
2009-08-09 10:39:47 -04:00
/** If the user attempts to quit the app, a check-warning is issued. This warning can be
turned off for future quit events .
2007-11-14 22:18:48 -05:00
*/
void MainWindow : : doQuit ( )
2009-08-09 10:39:47 -04:00
{
2010-12-13 15:34:07 -05:00
if ( ! Settings - > value ( " doQuit " , false ) . toBool ( ) )
2009-08-09 21:40:17 -04:00
{
QString queryWrn ;
2009-04-02 16:28:12 -04:00
queryWrn . clear ( ) ;
2009-05-08 21:05:40 -04:00
queryWrn . append ( tr ( " Do you really want to exit RetroShare ? " ) ) ;
2009-04-02 16:28:12 -04:00
2015-06-12 04:27:26 -04:00
if ( ( QMessageBox : : question ( this , tr ( " Really quit ? " ) , queryWrn , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ) = = QMessageBox : : Yes )
2009-04-02 16:28:12 -04:00
{
2009-08-09 10:39:47 -04:00
qApp - > quit ( ) ;
2009-04-02 16:28:12 -04:00
}
else
2010-05-29 11:14:25 -04:00
return ;
2009-08-09 21:40:17 -04:00
}
2010-05-29 11:14:25 -04:00
2009-12-30 21:23:02 -05:00
rApp - > quit ( ) ;
2007-11-14 22:18:48 -05:00
}
2011-08-12 10:06:29 -04:00
void MainWindow : : displayErrorMessage ( int /*a*/ , int /*b*/ , const QString & error_msg )
2010-02-07 13:10:12 -05:00
{
QMessageBox : : critical ( NULL , tr ( " Internal Error " ) , error_msg ) ;
}
2007-11-14 22:18:48 -05:00
void MainWindow : : closeEvent ( QCloseEvent * e )
{
2013-08-04 19:53:29 -04:00
e - > ignore ( ) ;
2007-11-14 22:18:48 -05:00
2013-08-04 19:53:29 -04:00
if ( Settings - > getCloseToTray ( ) )
{
if ( trayIcon - > isVisible ( ) ) {
2007-11-14 22:18:48 -05:00
/*****
2013-08-04 19:53:29 -04:00
static bool firstTime = true ;
if ( firstTime )
{
QMessageBox : : information ( this , tr ( " RetroShare System tray " ) , tr ( " Application will continue running. Quit using context menu in the system tray " ) ) ;
firstTime = false ;
}
2007-11-14 22:18:48 -05:00
* * * * */
2013-08-04 19:53:29 -04:00
hide ( ) ;
}
return ;
}
2007-11-14 22:18:48 -05:00
2013-08-04 19:53:29 -04:00
doQuit ( ) ;
2007-11-14 22:18:48 -05:00
}
void MainWindow : : updateMenu ( )
{
2011-11-25 06:07:54 -05:00
toggleVisibilityAction - > setText ( isVisible ( ) & & ! isMinimized ( ) ? tr ( " Hide " ) : tr ( " Show " ) ) ;
2007-11-14 22:18:48 -05:00
}
void MainWindow : : toggleVisibility ( QSystemTrayIcon : : ActivationReason e )
{
2011-11-25 06:07:54 -05:00
if ( e = = QSystemTrayIcon : : Trigger | | e = = QSystemTrayIcon : : DoubleClick ) {
if ( isHidden ( ) | | isMinimized ( ) ) {
2007-11-14 22:18:48 -05:00
show ( ) ;
2011-11-25 06:07:54 -05:00
if ( isMinimized ( ) ) {
if ( isMaximized ( ) ) {
2007-11-14 22:18:48 -05:00
showMaximized ( ) ;
} else {
showNormal ( ) ;
}
}
raise ( ) ;
activateWindow ( ) ;
2011-11-25 06:07:54 -05:00
} else {
2007-11-14 22:18:48 -05:00
hide ( ) ;
}
}
}
void MainWindow : : toggleVisibilitycontextmenu ( )
{
2011-11-25 06:07:54 -05:00
if ( isVisible ( ) & & ! isMinimized ( ) )
2007-11-14 22:18:48 -05:00
hide ( ) ;
else
show ( ) ;
}
2008-03-31 09:00:00 -04:00
void MainWindow : : showabout ( )
{
2010-04-24 18:09:47 -04:00
AboutDialog adlg ( this ) ;
adlg . exec ( ) ;
2008-03-31 09:00:00 -04:00
}
2008-08-05 14:36:07 -04:00
/** Displays the help browser and displays the most recently viewed help
* topic . */
void MainWindow : : showHelpDialog ( )
{
showHelpDialog ( QString ( ) ) ;
}
/**< Shows the help browser and displays the given help <b>topic</b>. */
void MainWindow : : showHelpDialog ( const QString & topic )
{
2012-07-15 18:24:03 -04:00
HelpBrowser : : showWindow ( topic ) ;
2008-08-05 14:36:07 -04:00
}
2009-12-30 21:23:02 -05:00
/** Called when the user changes the UI translation. */
void
MainWindow : : retranslateUi ( )
{
2014-04-27 10:23:27 -04:00
retranslateUi ( ) ;
2014-05-01 07:46:25 -04:00
foreach ( MainPage * page , ui - > stackPages - > pages ( ) ) {
2009-12-30 21:23:02 -05:00
page - > retranslateUi ( ) ;
}
2014-05-09 22:38:47 -04:00
foreach ( QAction * action , ui - > toolBarPage - > actions ( ) ) {
2009-12-30 21:23:02 -05:00
action - > setText ( tr ( qPrintable ( action - > data ( ) . toString ( ) ) , " MainWindow " ) ) ;
}
}
2010-07-17 19:19:43 -04:00
/* set status object to status value */
static void setStatusObject ( QObject * pObject , int nStatus )
{
QMenu * pMenu = dynamic_cast < QMenu * > ( pObject ) ;
if ( pMenu ) {
/* set action in menu */
foreach ( QObject * pObject , pMenu - > children ( ) ) {
QAction * pAction = qobject_cast < QAction * > ( pObject ) ;
if ( pAction = = NULL ) {
continue ;
}
if ( pAction - > data ( ) . toInt ( ) = = nStatus ) {
pAction - > setChecked ( true ) ;
break ;
}
}
return ;
}
QComboBox * pComboBox = dynamic_cast < QComboBox * > ( pObject ) ;
if ( pComboBox ) {
/* set index of combobox */
int nIndex = pComboBox - > findData ( nStatus , Qt : : UserRole ) ;
if ( nIndex ! = - 1 ) {
pComboBox - > setCurrentIndex ( nIndex ) ;
}
return ;
}
/* add more objects here */
}
/** Load own status Online,Away,Busy **/
void MainWindow : : loadOwnStatus ( )
{
m_bStatusLoadDone = true ;
2010-07-20 15:45:07 -04:00
StatusInfo statusInfo ;
if ( rsStatus - > getOwnStatus ( statusInfo ) ) {
/* send status to all added objects */
2014-10-21 18:33:02 -04:00
for ( std : : set < QObject * > : : iterator it = m_apStatusObjects . begin ( ) ; it ! = m_apStatusObjects . end ( ) ; + + it ) {
2010-07-20 15:45:07 -04:00
setStatusObject ( * it , statusInfo . status ) ;
}
2010-07-17 19:19:43 -04:00
}
}
void MainWindow : : checkAndSetIdle ( int idleTime )
{
2010-07-21 03:39:14 -04:00
int maxTimeBeforeIdle = Settings - > getMaxTimeBeforeIdle ( ) ;
if ( ( idleTime > = maxTimeBeforeIdle ) & & ! isIdle ) {
2010-07-17 19:19:43 -04:00
setIdle ( true ) ;
2010-07-21 03:39:14 -04:00
} else if ( ( idleTime < maxTimeBeforeIdle ) & & isIdle ) {
2010-07-17 19:19:43 -04:00
setIdle ( false ) ;
}
2010-02-25 08:12:18 -05:00
2010-07-17 19:19:43 -04:00
return ;
}
void MainWindow : : setIdle ( bool idle )
{
isIdle = idle ;
2010-07-20 15:45:07 -04:00
StatusInfo statusInfo ;
if ( rsStatus - > getOwnStatus ( statusInfo ) ) {
setStatus ( NULL , statusInfo . status ) ;
}
2010-07-17 19:19:43 -04:00
}
/* add and initialize status object */
2010-07-20 15:45:07 -04:00
void MainWindow : : initializeStatusObject ( QObject * pObject , bool bConnect )
2010-07-17 19:19:43 -04:00
{
if ( m_apStatusObjects . find ( pObject ) ! = m_apStatusObjects . end ( ) ) {
2010-07-20 15:45:07 -04:00
/* already added */
2010-07-17 19:19:43 -04:00
return ;
}
m_apStatusObjects . insert ( m_apStatusObjects . end ( ) , pObject ) ;
2014-05-29 12:15:26 -04:00
//std::string statusString;
2010-09-11 16:25:08 -04:00
2010-07-17 19:19:43 -04:00
QMenu * pMenu = dynamic_cast < QMenu * > ( pObject ) ;
if ( pMenu ) {
/* initialize menu */
QActionGroup * pGroup = new QActionGroup ( pMenu ) ;
2014-11-20 20:54:21 -05:00
QAction * pAction = new QAction ( QIcon ( StatusDefs : : imageStatus ( RS_STATUS_ONLINE ) ) , StatusDefs : : name ( RS_STATUS_ONLINE ) , pMenu ) ;
2010-07-17 19:19:43 -04:00
pAction - > setData ( RS_STATUS_ONLINE ) ;
pAction - > setCheckable ( true ) ;
pMenu - > addAction ( pAction ) ;
pGroup - > addAction ( pAction ) ;
2014-11-20 20:54:21 -05:00
pAction = new QAction ( QIcon ( StatusDefs : : imageStatus ( RS_STATUS_BUSY ) ) , StatusDefs : : name ( RS_STATUS_BUSY ) , pMenu ) ;
2010-07-17 19:19:43 -04:00
pAction - > setData ( RS_STATUS_BUSY ) ;
pAction - > setCheckable ( true ) ;
pMenu - > addAction ( pAction ) ;
pGroup - > addAction ( pAction ) ;
2014-11-20 20:54:21 -05:00
pAction = new QAction ( QIcon ( StatusDefs : : imageStatus ( RS_STATUS_AWAY ) ) , StatusDefs : : name ( RS_STATUS_AWAY ) , pMenu ) ;
2010-07-17 19:19:43 -04:00
pAction - > setData ( RS_STATUS_AWAY ) ;
pAction - > setCheckable ( true ) ;
pMenu - > addAction ( pAction ) ;
pGroup - > addAction ( pAction ) ;
2010-07-20 15:45:07 -04:00
if ( bConnect ) {
connect ( pMenu , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( statusChangedMenu ( QAction * ) ) ) ;
}
2010-07-17 19:19:43 -04:00
} else {
/* initialize combobox */
QComboBox * pComboBox = dynamic_cast < QComboBox * > ( pObject ) ;
if ( pComboBox ) {
2014-11-20 20:54:21 -05:00
pComboBox - > addItem ( QIcon ( StatusDefs : : imageStatus ( RS_STATUS_ONLINE ) ) , StatusDefs : : name ( RS_STATUS_ONLINE ) , RS_STATUS_ONLINE ) ;
pComboBox - > addItem ( QIcon ( StatusDefs : : imageStatus ( RS_STATUS_BUSY ) ) , StatusDefs : : name ( RS_STATUS_BUSY ) , RS_STATUS_BUSY ) ;
pComboBox - > addItem ( QIcon ( StatusDefs : : imageStatus ( RS_STATUS_AWAY ) ) , StatusDefs : : name ( RS_STATUS_AWAY ) , RS_STATUS_AWAY ) ;
2010-07-20 15:45:07 -04:00
if ( bConnect ) {
connect ( pComboBox , SIGNAL ( activated ( int ) ) , this , SLOT ( statusChangedComboBox ( int ) ) ) ;
}
2010-07-17 19:19:43 -04:00
}
/* add more objects here */
}
if ( m_bStatusLoadDone ) {
/* loadOwnStatus done, set own status directly */
2010-07-20 15:45:07 -04:00
StatusInfo statusInfo ;
if ( rsStatus - > getOwnStatus ( statusInfo ) ) {
setStatusObject ( pObject , statusInfo . status ) ;
2010-07-17 19:19:43 -04:00
}
}
}
/* remove status object */
void MainWindow : : removeStatusObject ( QObject * pObject )
{
m_apStatusObjects . erase ( pObject ) ;
2010-07-20 15:45:07 -04:00
/* disconnect all signals between the object and MainWindow */
disconnect ( pObject , NULL , this , NULL ) ;
2010-07-17 19:19:43 -04:00
}
/** Save own status Online,Away,Busy **/
void MainWindow : : setStatus ( QObject * pObject , int nStatus )
{
if ( isIdle & & nStatus = = ( int ) RS_STATUS_ONLINE ) {
2010-07-20 15:45:07 -04:00
/* set idle only when I am online */
2010-07-17 19:19:43 -04:00
nStatus = RS_STATUS_INACTIVE ;
}
2014-03-17 16:56:06 -04:00
rsStatus - > sendStatus ( RsPeerId ( ) , nStatus ) ;
2010-07-17 19:19:43 -04:00
/* set status in all status objects, but the calling one */
2014-10-21 18:33:02 -04:00
for ( std : : set < QObject * > : : iterator it = m_apStatusObjects . begin ( ) ; it ! = m_apStatusObjects . end ( ) ; + + it ) {
2010-07-17 19:19:43 -04:00
if ( * it ! = pObject ) {
setStatusObject ( * it , nStatus ) ;
}
}
}
/* new status from context menu */
2010-07-20 15:45:07 -04:00
void MainWindow : : statusChangedMenu ( QAction * pAction )
2010-07-17 19:19:43 -04:00
{
if ( pAction = = NULL ) {
return ;
}
setStatus ( pAction - > parent ( ) , pAction - > data ( ) . toInt ( ) ) ;
}
2010-07-18 17:28:56 -04:00
/* new status from combobox in statusbar */
void MainWindow : : statusChangedComboBox ( int index )
{
if ( index < 0 ) {
return ;
}
2010-07-20 15:45:07 -04:00
/* no object known */
setStatus ( NULL , statusComboBox - > itemData ( index , Qt : : UserRole ) . toInt ( ) ) ;
2010-07-18 17:28:56 -04:00
}
2014-05-09 22:38:47 -04:00
/*new setting*/
void MainWindow : : settingsChanged ( )
{
ui - > toolBarPage - > setVisible ( Settings - > getPageButtonLoc ( ) ) ;
ui - > toolBarAction - > setVisible ( Settings - > getActionButtonLoc ( ) ) ;
ui - > listWidget - > setVisible ( ! Settings - > getPageButtonLoc ( ) | | ! Settings - > getActionButtonLoc ( ) ) ;
2014-10-21 18:33:02 -04:00
for ( int i = 0 ; i < ui - > listWidget - > count ( ) ; + + i ) {
2014-05-09 22:38:47 -04:00
if ( ui - > listWidget - > item ( i ) - > data ( Qt : : UserRole ) . toString ( ) = = " " ) {
ui - > listWidget - > item ( i ) - > setHidden ( Settings - > getPageButtonLoc ( ) ) ;
} else {
ui - > listWidget - > item ( i ) - > setHidden ( Settings - > getActionButtonLoc ( ) ) ;
}
}
2014-05-10 14:05:18 -04:00
int toolSize = Settings - > getToolButtonSize ( ) ;
2014-05-09 22:38:47 -04:00
ui - > toolBarPage - > setToolButtonStyle ( Settings - > getToolButtonStyle ( ) ) ;
2014-05-10 14:05:18 -04:00
ui - > toolBarPage - > setIconSize ( QSize ( toolSize , toolSize ) ) ;
2014-05-09 22:38:47 -04:00
ui - > toolBarAction - > setToolButtonStyle ( Settings - > getToolButtonStyle ( ) ) ;
2014-05-10 14:05:18 -04:00
ui - > toolBarAction - > setIconSize ( QSize ( toolSize , toolSize ) ) ;
int itemSize = Settings - > getListItemIconSize ( ) ;
ui - > listWidget - > setIconSize ( QSize ( itemSize , itemSize ) ) ;
2014-05-09 22:38:47 -04:00
}
2013-03-15 19:08:54 -04:00
void MainWindow : : externalLinkActivated ( const QUrl & url )
{
static bool already_warned = false ;
if ( ! already_warned )
{
QMessageBox mb ( QObject : : tr ( " Confirmation " ) , QObject : : tr ( " Do you want this link to be handled by your system? " ) + " <br/><br/> " + url . toString ( ) + " <br/><br/> " + tr ( " Make sure this link has not been forged to drag you to a malicious website. " ) , QMessageBox : : Question , QMessageBox : : Yes , QMessageBox : : No , 0 ) ;
2013-03-21 08:00:29 -04:00
QCheckBox * checkbox = new QCheckBox ( tr ( " Don't ask me again " ) ) ;
2013-03-15 19:08:54 -04:00
mb . layout ( ) - > addWidget ( checkbox ) ;
2010-11-17 20:18:31 -05:00
2013-03-15 19:08:54 -04:00
int res = mb . exec ( ) ;
if ( res = = QMessageBox : : No )
return ;
else if ( checkbox - > isChecked ( ) )
already_warned = true ;
}
QDesktopServices : : openUrl ( url ) ;
}
void MainWindow : : retroshareLinkActivated ( const QUrl & url )
2010-11-17 20:18:31 -05:00
{
2010-11-18 11:31:44 -05:00
RetroShareLink link ( url ) ;
if ( link . valid ( ) = = false ) {
// QUrl can't handle the old RetroShare link format properly
if ( url . host ( ) . isEmpty ( ) ) {
QMessageBox mb ( " RetroShare " , tr ( " It seems to be an old RetroShare link. Please use copy instead. " ) , QMessageBox : : Critical , QMessageBox : : Ok , 0 , 0 ) ;
mb . exec ( ) ;
return ;
}
QMessageBox mb ( " RetroShare " , tr ( " The file link is malformed. " ) , QMessageBox : : Critical , QMessageBox : : Ok , 0 , 0 ) ;
mb . exec ( ) ;
return ;
}
2011-09-11 18:07:24 -04:00
QList < RetroShareLink > links ;
links . append ( link ) ;
RetroShareLink : : process ( links ) ;
2010-11-17 20:18:31 -05:00
}
2013-09-02 17:48:23 -04:00
2015-02-03 16:28:32 -05:00
//void MainWindow::servicePermission()
//{
// ServicePermissionDialog::showYourself();
//}
2014-05-29 12:15:26 -04:00
SoundStatus * MainWindow : : soundStatusInstance ( )
{
return soundStatus ;
}
ToasterDisable * MainWindow : : toasterDisableInstance ( )
{
return toasterDisable ;
}
2014-11-02 15:29:06 -05:00
SysTrayStatus * MainWindow : : sysTrayStatusInstance ( )
{
return sysTrayStatus ;
}
2014-05-29 12:15:26 -04:00
void MainWindow : : setCompactStatusMode ( bool compact )
{
//statusComboBox: TODO Show only icon
peerstatus - > setCompactMode ( compact ) ;
updateFriends ( ) ;
natstatus - > setCompactMode ( compact ) ;
natstatus - > getNATStatus ( ) ;
dhtstatus - > setCompactMode ( compact ) ;
dhtstatus - > getDHTStatus ( ) ;
hashingstatus - > setCompactMode ( compact ) ;
ratesstatus - > setCompactMode ( compact ) ;
//opModeStatus: TODO Show only ???
}