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-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
2009-08-21 13:58:55 -04:00
# include "rshare.h"
2007-11-14 22:18:48 -05:00
# include "MainWindow.h"
# include "MessengerWindow.h"
2010-06-08 17:38:36 -04:00
# include "NetworkDialog.h"
# include "SearchDialog.h"
# include "TransfersDialog.h"
# include "MessagesDialog.h"
# include "SharedFilesDialog.h"
# include "PluginsPage.h"
# include "ShareManager.h"
# include "NetworkView.h"
# include "LinksDialog.h"
# include "ForumsDialog.h"
# include "NewsFeed.h"
# include "PeersDialog.h"
2007-11-14 22:18:48 -05:00
# include "HelpDialog.h"
2009-12-30 21:23:02 -05:00
# include "AboutDialog.h"
2010-01-08 08:00:00 -05:00
# include "QuickStartWizard.h"
2007-11-14 22:18:48 -05:00
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-07-17 19:19:43 -04:00
# include "rsiface/rsstatus.h"
2009-05-01 08:45:27 -04:00
2007-11-14 22:18:48 -05:00
# include "rsiface/rsiface.h"
2008-01-25 03:49:40 -05:00
# include "rsiface/rspeers.h"
2008-07-02 12:59:56 -04:00
# include "rsiface/rsfiles.h"
2007-11-14 22:18:48 -05:00
2009-03-26 12:58:06 -04:00
# include "gui/connect/ConnectFriendWizard.h"
2009-08-13 11:11:08 -04:00
# include "util/rsversion.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"
2007-11-14 22:18:48 -05:00
2008-06-09 20:48:18 -04:00
# include <sstream>
# include <iomanip>
2008-12-07 13:34:54 -05:00
# include <unistd.h>
2007-11-14 22:18:48 -05:00
2010-03-04 13:08:24 -05:00
# define FONT QFont("Arial", 9)
2007-11-14 22:18:48 -05:00
/* Images for toolbar icons */
2009-08-21 13:58:55 -04:00
# define IMAGE_NETWORK2 ": / images / rs1.png"
2010-01-01 08:28:56 -05:00
# define IMAGE_PEERS ": / images / groupchat.png"
# define IMAGE_SEARCH ": / images / filefind.png"
# define IMAGE_TRANSFERS ": / images / ktorrent32.png"
2009-10-04 12:54:37 -04:00
# define IMAGE_LINKS ": / images / irkick.png"
2008-08-03 17:26:25 -04:00
# define IMAGE_FILES ": / images / fileshare24.png"
2010-01-01 08:28:56 -05:00
# 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"
2010-01-01 08:28:56 -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"
2010-01-01 08:28:56 -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"
2008-08-05 14:36:07 -04:00
# define IMG_HELP ": / images / help.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"
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 )
2010-07-17 19:19:43 -04:00
: RWindow ( " MainWindow " , parent , flags ) , maxTimeBeforeIdle ( 30 )
2007-11-14 22:18:48 -05:00
{
/* Invoke the Qt Designer generated QObject setup routine */
ui . setupUi ( this ) ;
2010-07-17 19:19:43 -04:00
_instance = this ;
m_bStatusLoadDone = false ;
isIdle = false ;
2010-05-20 17:53:27 -04:00
if ( Settings - > value ( QString : : fromUtf8 ( " FirstRun " ) , true ) . toBool ( ) )
2010-01-08 11:32:10 -05:00
{
2010-05-20 17:53:27 -04:00
Settings - > setValue ( QString : : fromUtf8 ( " FirstRun " ) , false ) ;
2010-01-08 11:32:10 -05:00
QuickStartWizard * qstartWizard = new QuickStartWizard ( this ) ;
qstartWizard - > exec ( ) ;
}
2009-08-09 10:39:47 -04:00
2010-03-09 08:22:58 -05:00
setWindowTitle ( tr ( " RetroShare %1 a secure decentralised communication platform " ) . arg ( retroshareVersion ( ) ) ) ;
2009-08-09 10:39:47 -04: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
/*messengerWindow instance is created statically so that RsAutoUpdatePage can access it*/
messengerWindow = MessengerWindow : : getInstance ( ) ;
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**/
2008-03-31 02:31:57 -04:00
connect ( ui . actionAdd_Friend , SIGNAL ( triggered ( ) ) , this , SLOT ( addFriend ( ) ) ) ;
2008-12-10 20:19:34 -05:00
connect ( ui . actionAdd_Share , SIGNAL ( triggered ( ) ) , this , SLOT ( openShareManager ( ) ) ) ;
2009-08-21 13:58:55 -04:00
connect ( ui . actionOptions , SIGNAL ( triggered ( ) ) , this , SLOT ( showSettings ( ) ) ) ;
2008-03-31 09:00:00 -04:00
connect ( ui . actionMessenger , SIGNAL ( triggered ( ) ) , this , SLOT ( showMessengerWindow ( ) ) ) ;
2010-04-18 15:54:19 -04:00
ui . actionMessenger - > setVisible ( true ) ;
2008-03-31 09:00:00 -04:00
connect ( ui . actionAbout , SIGNAL ( triggered ( ) ) , this , SLOT ( showabout ( ) ) ) ;
2009-09-12 12:39:50 -04:00
//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 */
2009-05-01 12:17:24 -04:00
connect ( ui . actionQuit , SIGNAL ( triggered ( ) ) , this , SLOT ( doQuit ( ) ) ) ;
2008-03-31 02:31:57 -04:00
2008-01-18 18:18:21 -05:00
/* load the StyleSheet*/
2009-08-09 10:39:47 -04:00
loadStyleSheet ( Rshare : : stylesheet ( ) ) ;
2007-11-14 22:18:48 -05:00
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 ) ;
2008-03-30 19:28:57 -04:00
2007-11-14 22:18:48 -05:00
2009-04-03 16:39:04 -04:00
ui . stackPages - > add ( networkDialog = new NetworkDialog ( ui . stackPages ) ,
2009-04-29 11:48:01 -04:00
createPageAction ( QIcon ( IMAGE_NETWORK2 ) , tr ( " Network " ) , grp ) ) ;
2008-11-29 15:17:58 -05:00
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
ui . stackPages - > add ( peersDialog = new PeersDialog ( ui . stackPages ) ,
createPageAction ( QIcon ( IMAGE_PEERS ) , tr ( " Friends " ) , grp ) ) ;
2008-11-29 15:17:58 -05:00
2009-08-10 19:44:46 -04:00
2007-11-14 22:18:48 -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
2009-08-10 19:44:46 -04:00
2007-11-14 22:18:48 -05:00
ui . stackPages - > add ( transfersDialog = new TransfersDialog ( ui . stackPages ) ,
2008-11-29 15:17:58 -05:00
createPageAction ( QIcon ( IMAGE_TRANSFERS ) , tr ( " Transfers " ) , grp ) ) ;
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
ui . stackPages - > add ( sharedfilesDialog = new SharedFilesDialog ( ui . stackPages ) ,
2009-08-09 10:39:47 -04:00
createPageAction ( QIcon ( IMAGE_FILES ) , tr ( " Files " ) , grp ) ) ;
2007-11-14 22:18:48 -05:00
2008-11-29 15:17:58 -05:00
2007-11-14 22:18:48 -05:00
ui . stackPages - > add ( messagesDialog = new MessagesDialog ( ui . stackPages ) ,
2010-03-28 16:46:45 -04:00
messageAction = createPageAction ( QIcon ( IMAGE_MESSAGES ) , tr ( " Messages " ) , grp ) ) ;
2008-03-30 17:05:14 -04:00
2009-02-02 08:01:53 -05:00
ui . stackPages - > add ( channelFeed = new ChannelFeed ( ui . stackPages ) ,
createPageAction ( QIcon ( IMAGE_CHANNELS ) , tr ( " Channels " ) , grp ) ) ;
2010-02-19 18:23:19 -05:00
2010-02-25 08:12:18 -05:00
# ifdef BLOGS
2010-02-19 18:23:19 -05:00
ui . stackPages - > add ( blogsFeed = new BlogsDialog ( ui . stackPages ) ,
createPageAction ( QIcon ( IMAGE_BLOGS ) , tr ( " Blogs " ) , grp ) ) ;
2010-02-24 07:58:24 -05:00
# endif
2010-02-04 16:47:34 -05:00
2008-11-15 18:47:17 -05:00
ui . stackPages - > add ( forumsDialog = new ForumsDialog ( ui . stackPages ) ,
2010-02-04 16:47:34 -05:00
createPageAction ( QIcon ( IMAGE_FORUMS ) , tr ( " Forums " ) , grp ) ) ;
2010-02-06 15:49:24 -05:00
# ifndef RS_RELEASE_VERSION
2010-02-04 16:47:34 -05:00
ui . stackPages - > add ( linksDialog = new LinksDialog ( ui . stackPages ) ,
createPageAction ( QIcon ( IMAGE_LINKS ) , tr ( " Links Cloud " ) , grp ) ) ;
2010-02-06 15:49:24 -05:00
# endif
2009-08-09 10:39:47 -04:00
2010-02-06 15:49:24 -05:00
# ifndef RS_RELEASE_VERSION
2009-04-05 09:04:18 -04:00
ui . stackPages - > add ( newsFeed = new NewsFeed ( ui . stackPages ) ,
createPageAction ( QIcon ( IMAGE_NEWSFEED ) , tr ( " News Feed " ) , grp ) ) ;
2010-02-06 15:49:24 -05:00
# endif
2007-11-14 22:18:48 -05:00
2010-02-27 12:47:52 -05:00
# ifndef RS_RELEASE_VERSION
2010-02-06 15:49:24 -05:00
# ifdef PLUGINMGR
2009-02-11 17:50:12 -05:00
ui . stackPages - > add ( pluginsPage = new PluginsPage ( ui . stackPages ) ,
createPageAction ( QIcon ( IMAGE_PLUGINS ) , tr ( " Plugins " ) , grp ) ) ;
2010-02-06 15:49:24 -05:00
# endif
2010-02-27 12:47:52 -05:00
# endif
2009-07-23 13:11:51 -04:00
2007-11-14 22:18:48 -05:00
/* Create the toolbar */
ui . toolBar - > addActions ( grp - > actions ( ) ) ;
2010-03-03 16:55:07 -05:00
2007-11-14 22:18:48 -05:00
connect ( grp , SIGNAL ( triggered ( QAction * ) ) , ui . stackPages , SLOT ( showPage ( QAction * ) ) ) ;
2009-05-01 20:12:29 -04:00
2010-03-03 16:55:07 -05:00
# ifdef UNFINISHED
ui . toolBar - > addSeparator ( ) ;
2009-08-09 10:39:47 -04:00
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
2008-04-24 08:58:27 -04:00
/* Select the first action */
grp - > actions ( ) [ 0 ] - > setChecked ( true ) ;
2009-08-09 10:39:47 -04:00
2009-08-10 19:44:46 -04:00
/** StatusBar section ********/
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 ) ;
2008-06-09 20:48:18 -04:00
2009-04-30 22:39:57 -04:00
QWidget * widget = new QWidget ( ) ;
2009-01-25 07:18:16 -05:00
QSizePolicy sizePolicy ( QSizePolicy : : Maximum , QSizePolicy : : Preferred ) ;
sizePolicy . setHorizontalStretch ( 0 ) ;
sizePolicy . setVerticalStretch ( 0 ) ;
sizePolicy . setHeightForWidth ( widget - > sizePolicy ( ) . hasHeightForWidth ( ) ) ;
widget - > setSizePolicy ( sizePolicy ) ;
QHBoxLayout * horizontalLayout = new QHBoxLayout ( widget ) ;
2009-04-30 22:39:57 -04:00
horizontalLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2009-01-25 07:18:16 -05:00
horizontalLayout - > setObjectName ( QString : : fromUtf8 ( " horizontalLayout " ) ) ;
2009-04-30 22:39:57 -04:00
_hashing_info_label = new QLabel ( widget ) ;
2009-01-25 07:18:16 -05:00
_hashing_info_label - > setObjectName ( QString : : fromUtf8 ( " label " ) ) ;
horizontalLayout - > addWidget ( _hashing_info_label ) ;
QSpacerItem * horizontalSpacer = new QSpacerItem ( 1000 , 0 , QSizePolicy : : Expanding , QSizePolicy : : Minimum ) ;
horizontalLayout - > addItem ( horizontalSpacer ) ;
statusBar ( ) - > addPermanentWidget ( widget ) ;
2009-04-30 22:39:57 -04:00
_hashing_info_label - > hide ( ) ;
2009-01-04 15:29:55 -05:00
2009-05-02 18:14:20 -04:00
ratesstatus = new RatesStatus ( ) ;
statusBar ( ) - > addPermanentWidget ( ratesstatus ) ;
2009-08-10 19:44:46 -04:00
/** Status Bar end ******/
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
/* Create the actions that will go in the tray menu */
createActions ( ) ;
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
2010-07-17 19:19:43 -04:00
loadOwnStatus ( ) ; // hack; placed in constructor to preempt sendstatus, so status loaded from file
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 ( )
{
delete _bandwidthGraph ;
delete _messengerwindowAct ;
delete peerstatus ;
delete natstatus ;
delete ratesstatus ;
2010-05-11 16:02:52 -04:00
MessengerWindow : : releaseInstance ( ) ;
messengerWindow = NULL ;
# ifdef UNFINISHED
2009-11-24 15:17:13 -05:00
delete applicationWindow ;
2009-12-05 08:42:24 -05:00
# endif
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-01-01 08:45:35 -05:00
trayMenu = new QMenu ( this ) ;
QObject : : connect ( trayMenu , SIGNAL ( aboutToShow ( ) ) , this , SLOT ( updateMenu ( ) ) ) ;
2009-08-09 10:39:47 -04:00
toggleVisibilityAction =
2010-01-01 08:45:35 -05:00
trayMenu - > addAction ( QIcon ( IMAGE_RETROSHARE ) , tr ( " Show/Hide " ) , this , SLOT ( toggleVisibilitycontextmenu ( ) ) ) ;
2010-07-17 19:19:43 -04:00
QMenu * pStatusMenu = trayMenu - > addMenu ( tr ( " Status " ) ) ;
initializeStatusObject ( pStatusMenu ) ;
connect ( pStatusMenu , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( statusChanged ( QAction * ) ) ) ;
2010-01-01 08:45:35 -05:00
trayMenu - > addSeparator ( ) ;
trayMenu - > addAction ( _messengerwindowAct ) ;
trayMenu - > addAction ( _messagesAct ) ;
trayMenu - > addAction ( _bandwidthAct ) ;
2007-11-18 18:35:53 -05:00
2009-12-05 08:42:24 -05:00
# ifdef UNFINISHED
2010-01-01 08:45:35 -05:00
trayMenu - > addAction ( _appAct ) ;
2007-11-14 22:18:48 -05:00
# endif
2010-01-01 08:45:35 -05:00
trayMenu - > addAction ( _settingsAct ) ;
trayMenu - > addAction ( _helpAct ) ;
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
connect ( trayIcon , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) , this ,
2007-11-14 22:18:48 -05:00
SLOT ( toggleVisibility ( QSystemTrayIcon : : ActivationReason ) ) ) ;
trayIcon - > show ( ) ;
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 ( ) ) {
QObject : : connect ( _instance - > peersDialog , SIGNAL ( notifyGroupChat ( const QString & , const QString & ) ) , _instance , SLOT ( displaySystrayMsg ( const QString & , const QString & ) ) , Qt : : QueuedConnection ) ;
} else {
QObject : : disconnect ( _instance - > peersDialog , SIGNAL ( notifyGroupChat ( const QString & , const QString & ) ) , _instance , SLOT ( displaySystrayMsg ( const QString & , const QString & ) ) ) ;
}
}
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
}
2008-06-09 20:48:18 -04:00
void MainWindow : : updateStatus ( )
{
2010-04-19 17:50:03 -04:00
// 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-07-06 17:17:41 -04:00
unsigned int nFriendCount = 0 ;
unsigned int nOnlineCount = 0 ;
rsPeers - > getPeerCount ( & nFriendCount , & nOnlineCount ) ;
2010-03-28 16:46:45 -04:00
if ( ratesstatus )
ratesstatus - > getRatesStatus ( ) ;
2009-08-09 10:39:47 -04:00
2010-03-28 16:46:45 -04:00
if ( peerstatus )
2010-07-06 17:17:41 -04:00
peerstatus - > getPeerStatus ( nFriendCount , nOnlineCount ) ;
2009-08-09 10:39:47 -04:00
2010-03-28 16:46:45 -04:00
if ( natstatus )
natstatus - > getNATStatus ( ) ;
2009-08-09 10:39:47 -04:00
2010-05-13 15:20:40 -04:00
unsigned int newInboxCount = 0 ;
2010-05-28 10:42:54 -04:00
rsMsgs - > getMessageCount ( NULL , & newInboxCount , NULL , NULL , NULL , NULL ) ;
2010-02-27 12:47:52 -05:00
2010-05-09 04:01:52 -04:00
if ( newInboxCount )
messageAction - > setIcon ( QIcon ( QPixmap ( " :/images/messages_new.png " ) ) ) ;
else
messageAction - > setIcon ( QIcon ( QPixmap ( " :/images/evolution.png " ) ) ) ;
2010-02-27 12:47:52 -05:00
2010-05-09 04:01:52 -04:00
if ( newInboxCount )
2010-03-28 16:46:45 -04:00
{
trayIcon - > setIcon ( QIcon ( " :/images/newmsg.png " ) ) ;
2010-05-09 04:01:52 -04:00
if ( newInboxCount > 1 ) {
trayIcon - > setToolTip ( tr ( " RetroShare " ) + " \n " + tr ( " You have %1 new messages " ) . arg ( newInboxCount ) ) ;
} else {
trayIcon - > setToolTip ( tr ( " RetroShare " ) + " \n " + tr ( " You have %1 new message " ) . arg ( newInboxCount ) ) ;
}
}
2010-07-06 17:17:41 -04:00
else if ( nOnlineCount = = 0 )
2010-03-28 16:46:45 -04:00
{
trayIcon - > setIcon ( QIcon ( IMAGE_NOONLINE ) ) ;
trayIcon - > setToolTip ( tr ( " RetroShare " ) ) ;
}
2010-07-06 17:17:41 -04:00
else if ( nOnlineCount < 2 )
2010-03-28 16:46:45 -04:00
{
trayIcon - > setIcon ( QIcon ( IMAGE_ONEONLINE ) ) ;
trayIcon - > setToolTip ( tr ( " RetroShare " ) ) ;
}
2010-07-06 17:17:41 -04:00
else if ( nOnlineCount < 3 )
2010-03-28 16:46:45 -04:00
{
trayIcon - > setIcon ( QIcon ( IMAGE_TWOONLINE ) ) ;
trayIcon - > setToolTip ( tr ( " RetroShare " ) ) ;
}
else
{
trayIcon - > setIcon ( QIcon ( IMAGE_RETROSHARE ) ) ;
trayIcon - > setToolTip ( tr ( " RetroShare " ) ) ;
}
2008-06-15 11:34:56 -04:00
}
2009-01-22 16:06:54 -05:00
void MainWindow : : updateHashingInfo ( const QString & s )
{
if ( s = = " " )
_hashing_info_label - > hide ( ) ;
else
{
2010-04-10 10:56:34 -04:00
_hashing_info_label - > setText ( s ) ;
2009-01-22 16:06:54 -05:00
_hashing_info_label - > show ( ) ;
}
}
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. */
QAction * MainWindow : : createPageAction ( QIcon img , QString text , QActionGroup * group )
{
QAction * action = new QAction ( img , text , group ) ;
action - > setCheckable ( true ) ;
action - > setFont ( FONT ) ;
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 )
{
action - > setFont ( FONT ) ;
ui . toolBar - > addAction ( action ) ;
connect ( action , SIGNAL ( triggered ( ) ) , this , slot ) ;
}
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. */
2010-05-23 17:32:58 -04:00
_instance - > show ( ) ;
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
}
2010-05-02 20:09:55 -04:00
/** Set focus to the given page. */
/*static*/ void MainWindow : : activatePage ( Page page )
{
if ( _instance = = NULL ) {
return ;
}
MainPage * Page = NULL ;
switch ( page ) {
case Network :
Page = _instance - > networkDialog ;
break ;
case Friends :
Page = _instance - > peersDialog ;
break ;
case Search :
Page = _instance - > searchDialog ;
break ;
case Transfers :
Page = _instance - > transfersDialog ;
break ;
case SharedDirectories :
Page = _instance - > sharedfilesDialog ;
break ;
case Messages :
Page = _instance - > messagesDialog ;
break ;
# ifndef RS_RELEASE_VERSION
case Links :
Page = _instance - > linksDialog ;
break ;
case Channels :
Page = _instance - > channelFeed ;
break ;
# endif
case Forums :
Page = _instance - > forumsDialog ;
break ;
# ifdef BLOGS
case Blogs :
Page = _instance - > blogsFeed ;
break ;
# endif
}
if ( Page ) {
/* Set the focus to the specified page. */
_instance - > ui . stackPages - > setCurrentPage ( Page ) ;
}
}
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 ;
}
switch ( page ) {
case Network :
return _instance - > networkDialog ;
case Friends :
return _instance - > peersDialog ;
case Search :
return _instance - > searchDialog ;
case Transfers :
return _instance - > transfersDialog ;
case SharedDirectories :
return _instance - > sharedfilesDialog ;
case Messages :
return _instance - > messagesDialog ;
# ifndef RS_RELEASE_VERSION
case Links :
return _instance - > linksDialog ;
case Channels :
return _instance - > channelFeed ;
# endif
case Forums :
return _instance - > forumsDialog ;
# ifdef BLOGS
case Blogs :
return _instance - > blogsFeed ;
# endif
}
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 ( )
{
messengerWindow - > show ( ) ;
}
/** 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
/** Create and bind actions to events. Setup for initial
* tray menu configuration . */
void MainWindow : : createActions ( )
{
2009-08-21 13:58:55 -04:00
_settingsAct = new QAction ( QIcon ( IMAGE_PREFERENCES ) , tr ( " Options " ) , this ) ;
connect ( _settingsAct , SIGNAL ( triggered ( ) ) , this , SLOT ( showSettings ( ) ) ) ;
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
_bandwidthAct = new QAction ( QIcon ( IMAGE_BWGRAPH ) , tr ( " Bandwidth Graph " ) , this ) ;
2009-08-09 10:39:47 -04:00
connect ( _bandwidthAct , SIGNAL ( triggered ( ) ) ,
2007-11-14 22:18:48 -05:00
_bandwidthGraph , SLOT ( showWindow ( ) ) ) ;
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
_messengerwindowAct = new QAction ( QIcon ( IMAGE_RSM16 ) , tr ( " Open Messenger " ) , this ) ;
connect ( _messengerwindowAct , SIGNAL ( triggered ( ) ) , this , SLOT ( showMessengerWindow ( ) ) ) ;
2009-01-07 16:12:31 -05:00
_messagesAct = new QAction ( QIcon ( IMAGE_MESSAGES ) , tr ( " Open Messages " ) , this ) ;
connect ( _messagesAct , SIGNAL ( triggered ( ) ) , this , SLOT ( showMess ( ) ) ) ;
2009-12-05 09:49:15 -05:00
# ifdef UNFINISHED
2008-08-16 18:24:53 -04:00
_appAct = new QAction ( QIcon ( IMAGE_UNFINISHED ) , tr ( " Applications " ) , this ) ;
connect ( _appAct , SIGNAL ( triggered ( ) ) , this , SLOT ( showApplWindow ( ) ) ) ;
2009-12-05 09:49:15 -05:00
# endif
2008-08-05 14:36:07 -04:00
_helpAct = new QAction ( QIcon ( IMG_HELP ) , tr ( " Help " ) , this ) ;
connect ( _helpAct , SIGNAL ( triggered ( ) ) , this , SLOT ( showHelpDialog ( ) ) ) ;
2009-08-09 10:39:47 -04:00
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-05-20 17:53:27 -04:00
if ( ! Settings - > value ( QString : : fromUtf8 ( " 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
}
2010-02-07 13:10:12 -05:00
void MainWindow : : displayErrorMessage ( int a , int b , const QString & error_msg )
{
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-05-20 17:53:27 -04:00
if ( ! Settings - > value ( QString : : fromUtf8 ( " ClosetoTray " ) , false ) . toBool ( ) )
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 ( )
{
toggleVisibilityAction - > setText ( isVisible ( ) ? tr ( " Hide " ) : tr ( " Show " ) ) ;
}
void MainWindow : : toggleVisibility ( QSystemTrayIcon : : ActivationReason e )
{
if ( e = = QSystemTrayIcon : : Trigger | | e = = QSystemTrayIcon : : DoubleClick ) {
if ( isHidden ( ) ) {
show ( ) ;
if ( isMinimized ( ) ) {
if ( isMaximized ( ) ) {
showMaximized ( ) ;
} else {
showNormal ( ) ;
}
}
raise ( ) ;
activateWindow ( ) ;
} else {
hide ( ) ;
}
}
}
void MainWindow : : toggleVisibilitycontextmenu ( )
{
if ( isVisible ( ) )
hide ( ) ;
else
show ( ) ;
}
void MainWindow : : loadStyleSheet ( const QString & sheetName )
{
2008-01-19 12:13:50 -05:00
/** internal Stylesheets **/
//QFile file(":/qss/" + sheetName.toLower() + ".qss");
2009-08-09 10:39:47 -04:00
2008-01-19 12:13:50 -05:00
/** extern Stylesheets **/
QFile file ( QApplication : : applicationDirPath ( ) + " /qss/ " + sheetName . toLower ( ) + " .qss " ) ;
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
file . open ( QFile : : ReadOnly ) ;
QString styleSheet = QLatin1String ( file . readAll ( ) ) ;
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
qApp - > setStyleSheet ( styleSheet ) ;
2009-08-09 10:39:47 -04:00
2007-11-14 22:18:48 -05:00
}
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 )
{
static HelpBrowser * helpBrowser = 0 ;
if ( ! helpBrowser )
helpBrowser = new HelpBrowser ( this ) ;
helpBrowser - > showWindow ( topic ) ;
}
2010-01-08 08:00:00 -05:00
void MainWindow : : on_actionQuick_Start_Wizard_activated ( )
{
2010-04-24 18:09:47 -04:00
QuickStartWizard qstartwizard ( this ) ;
qstartwizard . exec ( ) ;
2010-01-08 08:00:00 -05:00
}
2009-12-30 21:23:02 -05:00
/** Called when the user changes the UI translation. */
void
MainWindow : : retranslateUi ( )
{
ui . retranslateUi ( this ) ;
foreach ( MainPage * page , ui . stackPages - > pages ( ) ) {
page - > retranslateUi ( ) ;
}
foreach ( QAction * action , ui . toolBar - > actions ( ) ) {
action - > setText ( tr ( qPrintable ( action - > data ( ) . toString ( ) ) , " MainWindow " ) ) ;
}
}
2008-11-27 18:59:08 -05:00
void MainWindow : : setStyle ( )
{
QString standardSheet = " {background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 <color1>, stop:1 <color2>);} " ;
QColor stop1 = QColorDialog : : getColor ( Qt : : white ) ;
QColor stop2 = QColorDialog : : getColor ( Qt : : black ) ;
//QString widgetSheet = ".QWidget" + standardSheet.replace("<color1>", stop1.name()).replace("<color2>", stop2.name());
QString toolSheet = " QToolBar " + standardSheet . replace ( " <color1> " , stop1 . name ( ) ) . replace ( " <color2> " , stop2 . name ( ) ) ;
QString menuSheet = " QMenuBar " + standardSheet . replace ( " <color1> " , stop1 . name ( ) ) . replace ( " <color2> " , stop2 . name ( ) ) ;
qApp - > setStyleSheet ( /*widgetSheet + */ toolSheet + menuSheet ) ;
2009-08-09 10:39:47 -04:00
2008-03-27 19:40:37 -04:00
}
2010-02-25 08:12:18 -05:00
2010-07-17 19:19:43 -04:00
/* get own status */
static int getOwnStatus ( )
{
std : : string ownId = rsPeers - > getOwnId ( ) ;
StatusInfo si ;
std : : list < StatusInfo > statusList ;
std : : list < StatusInfo > : : iterator it ;
if ( ! rsStatus - > getStatus ( statusList ) ) {
return - 1 ;
}
for ( it = statusList . begin ( ) ; it ! = statusList . end ( ) ; it + + ) {
if ( it - > id = = ownId )
return it - > status ;
}
return - 1 ;
}
/* 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 ;
int nStatus = getOwnStatus ( ) ;
for ( std : : set < QObject * > : : iterator it = m_apStatusObjects . begin ( ) ; it ! = m_apStatusObjects . end ( ) ; it + + ) {
setStatusObject ( * it , nStatus ) ;
}
}
void MainWindow : : checkAndSetIdle ( int idleTime )
{
if ( ( idleTime > = ( int ) maxTimeBeforeIdle ) & & ! isIdle ) {
setIdle ( true ) ;
} else
if ( ( idleTime < ( int ) maxTimeBeforeIdle ) & & isIdle ) {
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 ;
setStatus ( NULL , getOwnStatus ( ) ) ;
}
/* add and initialize status object */
void MainWindow : : initializeStatusObject ( QObject * pObject )
{
if ( m_apStatusObjects . find ( pObject ) ! = m_apStatusObjects . end ( ) ) {
return ;
}
m_apStatusObjects . insert ( m_apStatusObjects . end ( ) , pObject ) ;
QMenu * pMenu = dynamic_cast < QMenu * > ( pObject ) ;
if ( pMenu ) {
/* initialize menu */
QActionGroup * pGroup = new QActionGroup ( pMenu ) ;
QAction * pAction = new QAction ( QIcon ( " :/images/im-user.png " ) , tr ( " Online " ) , pMenu ) ;
pAction - > setData ( RS_STATUS_ONLINE ) ;
pAction - > setCheckable ( true ) ;
pMenu - > addAction ( pAction ) ;
pGroup - > addAction ( pAction ) ;
pAction = new QAction ( QIcon ( " :/images/im-user-busy.png " ) , tr ( " Busy " ) , pMenu ) ;
pAction - > setData ( RS_STATUS_BUSY ) ;
pAction - > setCheckable ( true ) ;
pMenu - > addAction ( pAction ) ;
pGroup - > addAction ( pAction ) ;
pAction = new QAction ( QIcon ( " :/images/im-user-away.png " ) , tr ( " Away " ) , pMenu ) ;
pAction - > setData ( RS_STATUS_AWAY ) ;
pAction - > setCheckable ( true ) ;
pMenu - > addAction ( pAction ) ;
pGroup - > addAction ( pAction ) ;
} else {
/* initialize combobox */
QComboBox * pComboBox = dynamic_cast < QComboBox * > ( pObject ) ;
if ( pComboBox ) {
pComboBox - > addItem ( QIcon ( " :/images/im-user.png " ) , tr ( " Online " ) , RS_STATUS_ONLINE ) ;
pComboBox - > addItem ( QIcon ( " :/images/im-user-busy.png " ) , tr ( " Busy " ) , RS_STATUS_BUSY ) ;
pComboBox - > addItem ( QIcon ( " :/images/im-user-away.png " ) , tr ( " Away " ) , RS_STATUS_AWAY ) ;
}
/* add more objects here */
}
if ( m_bStatusLoadDone ) {
/* loadOwnStatus done, set own status directly */
int nStatus = getOwnStatus ( ) ;
if ( nStatus ! = - 1 ) {
setStatusObject ( pObject , nStatus ) ;
}
}
}
/* remove status object */
void MainWindow : : removeStatusObject ( QObject * pObject )
{
m_apStatusObjects . erase ( pObject ) ;
}
/** Save own status Online,Away,Busy **/
void MainWindow : : setStatus ( QObject * pObject , int nStatus )
{
RsPeerDetails detail ;
std : : string ownId = rsPeers - > getOwnId ( ) ;
if ( ! rsPeers - > getPeerDetails ( ownId , detail ) ) {
return ;
}
StatusInfo si ;
if ( isIdle & & nStatus = = ( int ) RS_STATUS_ONLINE ) {
/* set idle state only when I am in online state */
nStatus = RS_STATUS_INACTIVE ;
}
si . id = ownId ;
si . status = nStatus ;
rsStatus - > sendStatus ( si ) ;
/* 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 */
void MainWindow : : statusChanged ( QAction * pAction )
{
if ( pAction = = NULL ) {
return ;
}
setStatus ( pAction - > parent ( ) , pAction - > data ( ) . toInt ( ) ) ;
}