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"
# include "TransfersDialog.h"
# 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"
# include "ForumsDialog.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"
2010-07-23 14:52:58 -04:00
# include "ChannelFeed.h"
# include "bwgraph/bwgraph.h"
# 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"
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
2009-08-16 16:10:53 -04:00
# include "gui/TurtleRouterDialog.h"
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"
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-08-09 17:20:34 -04:00
# include <retroshare/rsforums.h>
2010-10-06 20:17:42 -04:00
# include <retroshare/rschannels.h>
2010-09-01 13:56:15 -04:00
# include <retroshare/rsnotify.h>
2007-11-14 22:18:48 -05:00
2009-03-26 12:58:06 -04:00
# include "gui/connect/ConnectFriendWizard.h"
2012-09-12 09:11:04 -04:00
# include "util/rsguiversion.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"
2010-09-12 10:10:28 -04:00
# include "common/StatusDefs.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
2011-07-07 08:05:36 -04:00
/****
*
* # define USE_DHTWINDOW 1
2012-06-21 19:24:53 -04:00
* # define USE_BWCTRLWINDOW 1
2011-07-07 08:05:36 -04:00
*
* * * */
2011-07-10 14:20:30 -04:00
# define USE_DHTWINDOW 1
2012-06-21 19:24:53 -04:00
# define USE_BWCTRLWINDOW 1
2011-07-07 08:05:36 -04:00
2011-07-06 09:08:27 -04:00
# ifdef USE_DHTWINDOW
# include "dht/DhtWindow.h"
# endif
2012-06-21 19:24:53 -04:00
# ifdef USE_BWCTRLWINDOW
# include "bwctrl/BwCtrlWindow.h"
# endif
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"
2011-03-04 05:22:00 -05:00
# define IMAGE_PEERS ": / images / groupchat.png"
# define IMAGE_TRANSFERS ": / images / ktorrent32.png"
# define IMAGE_FILES ": / images / fileshare32.png"
# define IMAGE_CHANNELS ": / images / channels.png"
2008-11-15 18:47:17 -05:00
# define IMAGE_FORUMS ": / images / konversation.png"
2008-08-14 20:23:27 -04:00
# define IMAGE_PREFERENCES ": / images / kcmsystem24.png"
2011-03-04 05:22:00 -05:00
# define IMAGE_CHAT ": / images / groupchat.png"
2007-11-14 22:18:48 -05:00
# define IMAGE_RETROSHARE ": / images / rstray3.png"
# define IMAGE_ABOUT ": / images / informations_24x24.png"
# define IMAGE_STATISTIC ": / images / utilities-system-monitor.png"
# define IMAGE_MESSAGES ": / images / evolution.png"
# define IMAGE_BWGRAPH ": / images / ksysguard.png"
2008-03-31 08:06:56 -04:00
# define IMAGE_RSM32 ": / images / kdmconfig.png"
2007-11-14 22:18:48 -05:00
# define IMAGE_RSM16 ": / images / rsmessenger16.png"
# 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"
2008-03-30 19:28:57 -04:00
# define IMAGE_ADDFRIEND ": / images / add-friend24.png"
# define IMAGE_ADDSHARE ": / images / directoryadd_24x24_shadow.png"
# define IMAGE_OPTIONS ": / images / settings.png"
# define IMAGE_QUIT ": / images / exit_24x24.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"
2012-01-30 05:52:08 -05:00
# define IMG_HELP ": / images / help24.png"
2008-11-29 15:17:58 -05:00
# define IMAGE_NEWSFEED ": / images / konqsidebar_news24.png"
2009-02-01 20:30:15 -05:00
# define IMAGE_PLUGINS ": / images / extension_32.png"
2009-05-20 18:51:15 -04:00
# define IMAGE_NOONLINE ": / images / rstray0.png"
# define IMAGE_ONEONLINE ": / images / rstray1.png"
# define IMAGE_TWOONLINE ": / images / rstray2.png"
2010-02-19 18:23:19 -05:00
# define IMAGE_BLOGS ": / images / kblogger.png"
2011-08-04 17:41:53 -04:00
# define IMAGE_DHT ": / images / dht16.png"
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 */
MainWindow : : MainWindow ( QWidget * parent , Qt : : WFlags flags )
2012-12-20 08:30:16 -05:00
: RWindow ( " MainWindow " , parent , flags ) , ui ( new Ui : : MainWindow )
2007-11-14 22:18:48 -05:00
{
/* Invoke the Qt Designer generated QObject setup routine */
2012-12-20 08:30:16 -05: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 ( ) ) ) ;
}
2012-10-11 06:28:24 -04:00
setWindowTitle ( tr ( " RetroShare %1 a secure decentralized communication platform " ) . arg ( retroshareVersion ( ) ) + " - " + nameAndLocation ) ;
2009-08-09 10:39:47 -04:00
2011-07-30 13:13:08 -04:00
/* WORK OUT IF WE"RE IN ADVANCED MODE OR NOT */
bool advancedMode = false ;
std : : string advsetting ;
2012-01-22 17:58:23 -05:00
if ( rsConfig - > getConfigurationOption ( RS_CONFIG_ADVANCED , advsetting ) & & ( advsetting = = " YES " ) ) {
advancedMode = true ;
2011-07-30 13:13:08 -04:00
}
2010-11-17 20:18:31 -05:00
/* add url handler for RetroShare links */
2010-11-18 11:31:44 -05:00
QDesktopServices : : setUrlHandler ( RSLINK_SCHEME , this , " linkActivated " ) ;
2010-11-17 20:18:31 -05:00
2007-11-14 22:18:48 -05:00
// Setting icons
this - > setWindowIcon ( QIcon ( QString : : fromUtf8 ( " :/images/rstray3.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 ( ) ;
2010-02-24 07:58:24 -05:00
# endif
2009-08-09 10:39:47 -04:00
2009-05-01 12:17:24 -04:00
/** Left Side ToolBar**/
2012-12-20 08:30:16 -05:00
connect ( ui - > actionAdd_Friend , SIGNAL ( triggered ( ) ) , this , SLOT ( addFriend ( ) ) ) ;
connect ( ui - > actionAdd_Share , SIGNAL ( triggered ( ) ) , this , SLOT ( openShareManager ( ) ) ) ;
connect ( ui - > actionOptions , SIGNAL ( triggered ( ) ) , this , SLOT ( showSettings ( ) ) ) ;
connect ( ui - > actionMessenger , SIGNAL ( triggered ( ) ) , this , SLOT ( showMessengerWindow ( ) ) ) ;
2010-04-18 15:54:19 -04:00
2012-12-20 08:30:16 -05:00
ui - > actionMessenger - > setVisible ( true ) ;
2010-04-18 15:54:19 -04:00
2012-12-20 08:30:16 -05:00
connect ( ui - > actionAbout , SIGNAL ( triggered ( ) ) , this , SLOT ( showabout ( ) ) ) ;
//connect(ui->actionColor, SIGNAL(triggered()), this, SLOT( setStyle()) );
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
/** adjusted quit behaviour: trigger a warning that can be switched off in the saved
config file RetroShare . conf */
2012-12-20 08:30:16 -05:00
connect ( ui - > actionQuit , SIGNAL ( triggered ( ) ) , this , SLOT ( doQuit ( ) ) ) ;
2008-03-31 02:31:57 -04:00
2012-08-05 16:12:55 -04:00
QList < QPair < MainPage * , QAction * > > notify ;
2008-03-30 17:05:14 -04:00
/* Create the Main pages and actions */
2007-11-14 22:18:48 -05:00
QActionGroup * grp = new QActionGroup ( this ) ;
2012-08-05 16:12:55 -04:00
QAction * action ;
2008-03-30 19:28:57 -04:00
2013-02-22 16:42:27 -05:00
ui - > stackPages - > add ( newsFeed = new NewsFeed ( ui - > stackPages ) ,
createPageAction ( QIcon ( IMAGE_NEWSFEED ) , tr ( " News feed " ) , grp ) ) ;
// ui->stackPages->add(networkDialog = new NetworkDialog(ui->stackPages),
// createPageAction(QIcon(IMAGE_NETWORK2), tr("Network"), grp));
2008-11-29 15:17:58 -05:00
2012-12-20 08:30:16 -05:00
ui - > stackPages - > add ( friendsDialog = new FriendsDialog ( ui - > stackPages ) ,
2012-08-05 16:12:55 -04:00
action = createPageAction ( QIcon ( IMAGE_PEERS ) , tr ( " Friends " ) , grp ) ) ;
notify . push_back ( QPair < MainPage * , QAction * > ( friendsDialog , action ) ) ;
2008-11-29 15:17:58 -05:00
2013-02-22 16:42:27 -05:00
// ui->stackPages->add(searchDialog = new SearchDialog(ui->stackPages),
// createPageAction(QIcon(IMAGE_SEARCH), tr("Search"), grp));
2009-08-09 10:39:47 -04:00
2012-12-20 08:30:16 -05:00
ui - > stackPages - > add ( transfersDialog = new TransfersDialog ( ui - > stackPages ) ,
2012-08-05 16:12:55 -04:00
action = createPageAction ( QIcon ( IMAGE_TRANSFERS ) , tr ( " Transfers " ) , grp ) ) ;
notify . push_back ( QPair < MainPage * , QAction * > ( transfersDialog , action ) ) ;
2009-08-09 10:39:47 -04:00
2013-02-22 16:42:27 -05:00
ui - > stackPages - > add ( chatLobbyDialog = new ChatLobbyWidget ( ui - > stackPages ) ,
action = createPageAction ( QIcon ( IMAGE_CHAT ) , tr ( " Chat Lobbies " ) , grp ) ) ;
notify . push_back ( QPair < MainPage * , QAction * > ( chatLobbyDialog , action ) ) ;
2007-11-14 22:18:48 -05:00
2012-12-20 08:30:16 -05:00
ui - > stackPages - > add ( messagesDialog = new MessagesDialog ( ui - > stackPages ) ,
2012-08-05 16:12:55 -04:00
action = createPageAction ( QIcon ( IMAGE_MESSAGES ) , tr ( " Messages " ) , grp ) ) ;
notify . push_back ( QPair < MainPage * , QAction * > ( messagesDialog , action ) ) ;
2008-03-30 17:05:14 -04:00
2012-12-20 08:30:16 -05:00
ui - > stackPages - > add ( channelFeed = new ChannelFeed ( ui - > stackPages ) ,
2012-08-05 16:12:55 -04:00
action = createPageAction ( QIcon ( IMAGE_CHANNELS ) , tr ( " Channels " ) , grp ) ) ;
notify . push_back ( QPair < MainPage * , QAction * > ( channelFeed , action ) ) ;
2010-02-19 18:23:19 -05:00
2010-11-20 15:58:35 -05:00
# ifdef BLOGS
2012-12-20 08:30:16 -05:00
ui - > stackPages - > add ( blogsFeed = new BlogsDialog ( ui - > stackPages ) , createPageAction ( QIcon ( IMAGE_BLOGS ) , tr ( " Blogs " ) , grp ) ) ;
2010-11-20 15:58:35 -05:00
# endif
2010-02-04 16:47:34 -05:00
2012-12-20 08:30:16 -05:00
ui - > stackPages - > add ( forumsDialog = new ForumsDialog ( ui - > stackPages ) ,
2012-08-05 16:12:55 -04:00
action = createPageAction ( QIcon ( IMAGE_FORUMS ) , tr ( " Forums " ) , grp ) ) ;
notify . push_back ( QPair < MainPage * , QAction * > ( forumsDialog , action ) ) ;
2010-02-06 15:49:24 -05:00
2011-06-16 17:59:26 -04:00
std : : cerr < < " Looking for interfaces in existing plugins: " < < std : : endl ;
2011-07-13 15:24:33 -04:00
for ( int i = 0 ; i < rsPlugins - > nbPlugins ( ) ; + + i )
2011-06-16 17:59:26 -04:00
{
2011-07-05 16:29:07 -04:00
QIcon icon ;
if ( rsPlugins - > plugin ( i ) ! = NULL & & rsPlugins - > plugin ( i ) - > qt_page ( ) ! = NULL )
2011-06-16 17:59:26 -04:00
{
2011-07-05 16:29:07 -04:00
if ( rsPlugins - > plugin ( i ) - > qt_icon ( ) ! = NULL )
icon = * rsPlugins - > plugin ( i ) - > qt_icon ( ) ;
else
icon = QIcon ( " :images/extension_48.png " ) ;
2011-06-16 17:59:26 -04:00
std : : cerr < < " Addign widget page for plugin " < < rsPlugins - > plugin ( i ) - > getPluginName ( ) < < std : : endl ;
2012-08-05 16:12:55 -04:00
MainPage * pluginPage = rsPlugins - > plugin ( i ) - > qt_page ( ) ;
QAction * pluginAction = createPageAction ( icon , QString : : fromUtf8 ( rsPlugins - > plugin ( i ) - > getPluginName ( ) . c_str ( ) ) , grp ) ;
2012-12-20 08:30:16 -05:00
ui - > stackPages - > add ( pluginPage , pluginAction ) ;
2012-08-05 16:12:55 -04:00
notify . push_back ( QPair < MainPage * , QAction * > ( pluginPage , pluginAction ) ) ;
2011-06-16 17:59:26 -04:00
}
2011-07-05 16:29:07 -04:00
else if ( rsPlugins - > plugin ( i ) = = NULL )
std : : cerr < < " No plugin object ! " < < std : : endl ;
else
std : : cerr < < " No plugin page ! " < < std : : endl ;
2011-06-16 17:59:26 -04:00
}
2009-08-09 10:39:47 -04:00
2010-11-20 15:58:35 -05:00
# ifndef RS_RELEASE_VERSION
# ifdef PLUGINMGR
2012-12-20 08:30:16 -05:00
ui - > stackPages - > add ( pluginsPage = new PluginsPage ( ui - > stackPages ) ,
2009-02-11 17:50:12 -05:00
createPageAction ( QIcon ( IMAGE_PLUGINS ) , tr ( " Plugins " ) , grp ) ) ;
2010-11-20 15:58:35 -05:00
# endif
# endif
2009-07-23 13:11:51 -04:00
2011-07-11 14:53:14 -04:00
# ifdef GETSTARTED_GUI
MainPage * getStartedPage = NULL ;
2011-07-30 13:13:08 -04:00
if ( ! advancedMode )
{
2012-12-20 08:30:16 -05:00
ui - > stackPages - > add ( getStartedPage = new GetStartedDialog ( ui - > stackPages ) ,
2011-07-11 14:53:14 -04:00
createPageAction ( QIcon ( IMG_HELP ) , tr ( " Getting Started " ) , grp ) ) ;
2011-07-30 13:13:08 -04:00
}
2011-07-11 14:53:14 -04:00
# endif
2007-11-14 22:18:48 -05:00
/* Create the toolbar */
2012-12-20 08:30:16 -05:00
ui - > toolBar - > addActions ( grp - > actions ( ) ) ;
2010-03-03 16:55:07 -05:00
2012-12-20 08:30:16 -05:00
connect ( grp , SIGNAL ( triggered ( QAction * ) ) , ui - > stackPages , SLOT ( showPage ( QAction * ) ) ) ;
2009-05-01 20:12:29 -04:00
2010-07-18 17:28:56 -04:00
# ifdef UNFINISHED
2012-12-20 08:30:16 -05:00
ui - > toolBar - > addSeparator ( ) ;
addAction ( new QAction ( QIcon ( IMAGE_UNFINISHED ) , tr ( " Unfinished " ) , ui - > toolBar ) , SLOT ( showApplWindow ( ) ) ) ;
2009-05-01 20:12:29 -04:00
# endif
2009-07-23 13:11:51 -04:00
2012-12-20 08:30:16 -05:00
ui - > stackPages - > setCurrentIndex ( Settings - > getLastPageInMainWindow ( ) ) ;
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 ( ) ;
statusBar ( ) - > addPermanentWidget ( hashingstatus ) ;
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
2012-11-25 17:50:38 -05:00
statusBar ( ) - > addPermanentWidget ( new OpModeStatus ( ) ) ;
2012-01-22 17:58:23 -05:00
statusBar ( ) - > addPermanentWidget ( new SoundStatus ( ) ) ;
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
QList < QPair < MainPage * , QAction * > > : : iterator notifyIt ;
for ( notifyIt = notify . begin ( ) ; notifyIt ! = notify . end ( ) ; + + notifyIt ) {
UserNotify * userNotify = notifyIt - > first - > getUserNotify ( this ) ;
if ( userNotify ) {
2012-12-20 08:30:16 -05:00
userNotify - > initialize ( ui - > toolBar , notifyIt - > second ) ;
2012-08-05 16:12:55 -04:00
connect ( userNotify , SIGNAL ( countChanged ( ) ) , this , SLOT ( updateTrayCombine ( ) ) ) ;
userNotifyList . push_back ( userNotify ) ;
}
}
createNotifyIcons ( ) ;
2012-02-24 20:48:56 -05:00
/* caclulate friend count */
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 */
2012-12-20 08:30:16 -05: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 ) ;
}
/** Destructor. */
MainWindow : : ~ MainWindow ( )
{
2012-12-20 08:30:16 -05:00
Settings - > setLastPageInMainWindow ( ui - > stackPages - > currentIndex ( ) ) ;
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 ;
2009-11-24 15:17:13 -05:00
delete ratesstatus ;
2011-01-07 11:56:57 -05:00
delete discstatus ;
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
2012-12-20 08:30:16 -05:00
delete ( ui ) ;
2009-11-24 15:17:13 -05:00
}
2007-11-14 22:18:48 -05:00
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 " ) ,
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. " ) ) ;
}
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 ) ;
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 ( ) ) ) ;
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 ( ) ;
2011-05-01 19:30:45 -04:00
trayMenu - > addAction ( QIcon ( IMAGE_RSM16 ) , tr ( " Open Messenger " ) , this , SLOT ( showMessengerWindow ( ) ) ) ;
trayMenu - > addAction ( QIcon ( IMAGE_MESSAGES ) , tr ( " Open Messages " ) , this , SLOT ( showMess ( ) ) ) ;
trayMenu - > addAction ( QIcon ( IMAGE_BWGRAPH ) , tr ( " Bandwidth Graph " ) , _bandwidthGraph , SLOT ( showWindow ( ) ) ) ;
2011-07-06 09:08:27 -04:00
# ifdef USE_DHTWINDOW
2012-02-15 15:40:41 -05:00
trayMenu - > addAction ( QIcon ( IMAGE_DHT ) , tr ( " DHT Details " ) , this , SLOT ( showDhtWindow ( ) ) ) ;
2011-07-06 09:08:27 -04:00
# endif
2012-06-21 19:24:53 -04:00
# ifdef USE_BWCTRLWINDOW
trayMenu - > addAction ( QIcon ( IMAGE_DHT ) , tr ( " Bandwidth Details " ) , this , SLOT ( showBwCtrlWindow ( ) ) ) ;
# endif
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 ;
for ( actionIt = actions . begin ( ) ; actionIt ! = actions . end ( ) ; actionIt + + ) {
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
}
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 ;
2009-08-09 10:39:47 -04:00
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 ( )
{
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 ) ;
QPixmap overlayImage ( " :/images/rstray_star.png " ) ;
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
2011-07-13 15:24:33 -04:00
trayIcon - > 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 ( ) ;
}
2007-11-14 22:18:48 -05:00
/** Creates a new action associated with a config page. */
2012-08-08 06:48:29 -04:00
QAction * MainWindow : : createPageAction ( const QIcon & icon , const QString & text , QActionGroup * group )
2007-11-14 22:18:48 -05:00
{
2012-10-14 08:25:12 -04:00
QFont font ;
2012-08-08 06:48:29 -04:00
QAction * action = new QAction ( icon , text , group ) ;
2012-10-14 08:25:12 -04:00
font = action - > font ( ) ;
font . setPointSize ( 9 ) ;
2007-11-14 22:18:48 -05:00
action - > setCheckable ( true ) ;
2012-10-14 08:25:12 -04:00
action - > setFont ( font ) ;
2007-11-14 22:18:48 -05:00
return action ;
}
/** Adds the given action to the toolbar and hooks its triggered() signal to
* the specified slot ( if given ) . */
void MainWindow : : addAction ( QAction * action , const char * slot )
{
2012-10-14 08:25:12 -04:00
QFont font ;
font = action - > font ( ) ;
font . setPointSize ( 9 ) ;
action - > setFont ( font ) ;
2012-12-20 08:30:16 -05:00
ui - > toolBar - > addAction ( action ) ;
2007-11-14 22:18:48 -05:00
connect ( action , SIGNAL ( triggered ( ) ) , this , slot ) ;
}
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
SetForegroundWindowInternal ( _instance - > winId ( ) ) ;
# 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. */
_instance - > ui - > stackPages - > setCurrentPage ( page ) ;
}
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 :
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > transfersDialog ) ;
_instance - > transfersDialog - > activatePage ( TransfersDialog : : SearchTab ) ;
break ;
case Network :
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > friendsDialog ) ;
_instance - > friendsDialog - > activatePage ( FriendsDialog : : NetworkTab ) ;
break ;
2013-02-22 16:42:27 -05:00
case Friends :
2013-02-23 09:29:36 -05:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > friendsDialog ) ;
2013-02-22 16:42:27 -05:00
break ;
case ChatLobby :
2013-02-23 09:29:36 -05:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > chatLobbyDialog ) ;
2013-02-22 16:42:27 -05:00
break ;
case Transfers :
2013-02-23 09:29:36 -05: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 :
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > transfersDialog ) ;
_instance - > transfersDialog - > activatePage ( TransfersDialog : : LocalSharedFilesTab ) ;
2013-02-22 16:42:27 -05:00
break ;
case Messages :
2013-02-23 09:29:36 -05:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > messagesDialog ) ;
2013-02-22 16:42:27 -05:00
break ;
case Channels :
2013-02-23 09:29:36 -05:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > channelFeed ) ;
return true ;
2013-02-22 16:42:27 -05:00
case Forums :
2013-02-23 09:29:36 -05:00
_instance - > ui - > stackPages - > setCurrentPage ( _instance - > forumsDialog ) ;
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
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 ;
}
2012-12-20 08:30:16 -05: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
2010-11-04 07:14:47 -04:00
if ( page = = _instance - > channelFeed ) {
return Channels ;
}
if ( page = = _instance - > forumsDialog ) {
return Forums ;
}
# 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 :
return _instance - > channelFeed ;
case Forums :
return _instance - > forumsDialog ;
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
}
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
}
2011-07-06 09:08:27 -04:00
/** Shows Dht window */
void MainWindow : : showDhtWindow ( )
{
# ifdef USE_DHTWINDOW
DhtWindow : : showYourself ( ) ;
# endif
}
2007-11-14 22:18:48 -05:00
2012-06-21 19:24:53 -04:00
/** Shows Bandwitch Control window */
void MainWindow : : showBwCtrlWindow ( )
{
# ifdef USE_BWCTRLWINDOW
BwCtrlWindow : : showYourself ( ) ;
# endif
}
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
2009-07-23 13:11:51 -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 )
{
static bool firstTime = true ;
2010-12-13 15:34:07 -05:00
if ( ! Settings - > getCloseToTray ( ) )
2009-09-08 08:34:18 -04:00
{
if ( trayIcon - > isVisible ( ) ) {
if ( firstTime )
{
2007-11-14 22:18:48 -05:00
/*****
QMessageBox : : information ( this , tr ( " RetroShare System tray " ) ,
tr ( " Application will continue running. Quit using context menu in the system tray " ) ) ;
* * * * */
firstTime = false ;
2009-09-08 08:34:18 -04:00
}
hide ( ) ;
e - > ignore ( ) ;
}
}
else
{
rsicontrol - > rsGlobalShutDown ( ) ;
2009-12-30 21:23:02 -05:00
rApp - > quit ( ) ;
2009-09-08 08:34:18 -04:00
}
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 ( )
{
2012-12-20 08:30:16 -05:00
ui - > retranslateUi ( this ) ;
foreach ( MainPage * page , ui - > stackPages - > pages ( ) ) {
2009-12-30 21:23:02 -05:00
page - > retranslateUi ( ) ;
}
2012-12-20 08:30:16 -05:00
foreach ( QAction * action , ui - > toolBar - > 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 */
for ( std : : set < QObject * > : : iterator it = m_apStatusObjects . begin ( ) ; it ! = m_apStatusObjects . end ( ) ; it + + ) {
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 ) ;
2010-09-11 16:25:08 -04:00
std : : string statusString ;
2010-07-17 19:19:43 -04:00
QMenu * pMenu = dynamic_cast < QMenu * > ( pObject ) ;
if ( pMenu ) {
/* initialize menu */
QActionGroup * pGroup = new QActionGroup ( pMenu ) ;
2010-09-12 10:10:28 -04:00
QAction * pAction = new QAction ( QIcon ( StatusDefs : : imageIM ( 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 ) ;
2010-09-12 10:10:28 -04:00
pAction = new QAction ( QIcon ( StatusDefs : : imageIM ( 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 ) ;
2010-09-12 10:10:28 -04:00
pAction = new QAction ( QIcon ( StatusDefs : : imageIM ( 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 ) {
2010-09-12 10:10:28 -04:00
pComboBox - > addItem ( QIcon ( StatusDefs : : imageIM ( RS_STATUS_ONLINE ) ) , StatusDefs : : name ( RS_STATUS_ONLINE ) , RS_STATUS_ONLINE ) ;
pComboBox - > addItem ( QIcon ( StatusDefs : : imageIM ( RS_STATUS_BUSY ) ) , StatusDefs : : name ( RS_STATUS_BUSY ) , RS_STATUS_BUSY ) ;
pComboBox - > addItem ( QIcon ( StatusDefs : : imageIM ( 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 ;
}
2010-07-20 15:45:07 -04:00
rsStatus - > sendStatus ( " " , nStatus ) ;
2010-07-17 19:19:43 -04:00
/* set status in all status objects, but the calling one */
for ( std : : set < QObject * > : : iterator it = m_apStatusObjects . begin ( ) ; it ! = m_apStatusObjects . end ( ) ; it + + ) {
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
}
2010-11-17 20:18:31 -05:00
void MainWindow : : linkActivated ( const QUrl & url )
{
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 . setWindowIcon ( QIcon ( " :/images/rstray3.png " ) ) ;
mb . exec ( ) ;
return ;
}
QMessageBox mb ( " RetroShare " , tr ( " The file link is malformed. " ) , QMessageBox : : Critical , QMessageBox : : Ok , 0 , 0 ) ;
mb . setWindowIcon ( QIcon ( " :/images/rstray3.png " ) ) ;
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
}