2012-11-12 15:47:55 -05:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2008 Robert Fernie
*
* 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
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <QMenu>
# include <QMessageBox>
# include "GxsForumsDialog.h"
2013-07-15 10:22:33 -04:00
# include "GxsForumGroupDialog.h"
# include "GxsForumThreadWidget.h"
# include "gui/settings/rsharesettings.h"
# include "gui/RetroShareLink.h"
# include "gui/channels/ShareKey.h"
# include "gui/common/RSTreeWidget.h"
# include "gui/notifyqt.h"
2013-07-12 13:24:11 -04:00
//#include "gui/common/UIStateHelper.h"
2012-11-12 15:47:55 -05:00
// These should be in retroshare/ folder.
2013-02-28 16:58:38 -05:00
# include "retroshare/rsgxsflags.h"
2012-11-12 15:47:55 -05:00
//#define DEBUG_FORUMS
/* Images for TreeWidget */
# define IMAGE_FOLDER ": / images / folder16.png"
# define IMAGE_FOLDERGREEN ": / images / folder_green.png"
# define IMAGE_FOLDERRED ": / images / folder_red.png"
# define IMAGE_FOLDERYELLOW ": / images / folder_yellow.png"
# define IMAGE_FORUM ": / images / konversation.png"
# define IMAGE_SUBSCRIBE ": / images / edit_add24.png"
# define IMAGE_UNSUBSCRIBE ": / images / cancel.png"
# define IMAGE_INFO ": / images / info16.png"
# define IMAGE_NEWFORUM ": / images / new_forum16.png"
# define IMAGE_FORUMAUTHD ": / images / konv_message2.png"
# define IMAGE_COPYLINK ": / images / copyrslink.png"
2013-07-15 10:22:33 -04:00
# define TOKEN_TYPE_LISTING 1
# define TOKEN_TYPE_SUBSCRIBE_CHANGE 2
//#define TOKEN_TYPE_CURRENTFORUM 3
2013-07-12 13:24:11 -04:00
2012-11-12 15:47:55 -05:00
/*
* Transformation Notes :
* there are still a couple of things that the new forums differ from Old version .
* these will need to be addressed in the future .
* - > Child TS ( for sorting ) is not handled by GXS , this will probably have to be done in the GUI .
* - > Need to handle IDs properly .
* - > Popularity not handled in GXS yet .
* - > Much more to do .
*/
/** Constructor */
GxsForumsDialog : : GxsForumsDialog ( QWidget * parent )
2013-07-14 14:48:40 -04:00
: RsGxsUpdateBroadcastPage ( rsGxsForums , parent )
2012-11-12 15:47:55 -05:00
{
2012-11-21 13:55:52 -05:00
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2012-11-12 15:47:55 -05:00
2013-07-12 13:24:11 -04:00
/* Setup Queue */
2012-11-21 13:55:52 -05:00
mForumQueue = new TokenQueue ( rsGxsForums - > getTokenService ( ) , this ) ;
2013-01-05 21:30:10 -05:00
mThreadWidget = NULL ;
2012-11-12 15:47:55 -05:00
2013-07-12 13:24:11 -04:00
/* Setup UI helper */
// mStateHelper = new UIStateHelper(this);
// no widget to add yet
2012-11-27 18:21:20 -05:00
connect ( ui . forumTreeWidget , SIGNAL ( treeCustomContextMenuRequested ( QPoint ) ) , this , SLOT ( forumListCustomPopupMenu ( QPoint ) ) ) ;
2012-11-12 15:47:55 -05:00
connect ( ui . newForumButton , SIGNAL ( clicked ( ) ) , this , SLOT ( newforum ( ) ) ) ;
2012-12-29 21:41:53 -05:00
connect ( ui . forumTreeWidget , SIGNAL ( treeItemActivated ( QString ) ) , this , SLOT ( changedForum ( QString ) ) ) ;
2013-01-05 21:30:10 -05:00
connect ( ui . forumTreeWidget - > treeWidget ( ) , SIGNAL ( signalMouseMiddleButtonClicked ( QTreeWidgetItem * ) ) , this , SLOT ( forumTreeMiddleButtonClicked ( QTreeWidgetItem * ) ) ) ;
2012-11-27 18:21:20 -05:00
connect ( ui . threadTabWidget , SIGNAL ( tabCloseRequested ( int ) ) , this , SLOT ( threadTabCloseRequested ( int ) ) ) ;
2012-12-29 21:41:53 -05:00
connect ( ui . threadTabWidget , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( threadTabChanged ( int ) ) ) ;
2012-11-27 18:21:20 -05:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( forumMsgReadSatusChanged ( QString , QString , int ) ) , this , SLOT ( forumMsgReadSatusChanged ( QString , QString , int ) ) ) ;
2013-01-05 21:30:10 -05:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( settingsChanged ( ) ) , this , SLOT ( settingsChanged ( ) ) ) ;
2012-11-15 18:51:57 -05:00
2013-07-12 13:24:11 -04:00
connect ( ui . todoPushButton , SIGNAL ( clicked ( ) ) , this , SLOT ( todo ( ) ) ) ;
2012-11-12 15:47:55 -05:00
2012-12-27 10:56:57 -05:00
/* Initialize group tree */
ui . forumTreeWidget - > initDisplayMenu ( ui . displayButton ) ;
2012-11-21 13:55:52 -05:00
/* Set initial size the splitter */
QList < int > sizes ;
sizes < < 300 < < width ( ) ; // Qt calculates the right sizes
2012-11-27 18:21:20 -05:00
ui . splitter - > setSizes ( sizes ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
/* create forum tree */
2012-12-20 07:16:53 -05:00
yourForums = ui . forumTreeWidget - > addCategoryItem ( tr ( " My Forums " ) , QIcon ( IMAGE_FOLDER ) , true ) ;
2012-11-21 13:55:52 -05:00
subscribedForums = ui . forumTreeWidget - > addCategoryItem ( tr ( " Subscribed Forums " ) , QIcon ( IMAGE_FOLDERRED ) , true ) ;
popularForums = ui . forumTreeWidget - > addCategoryItem ( tr ( " Popular Forums " ) , QIcon ( IMAGE_FOLDERGREEN ) , false ) ;
otherForums = ui . forumTreeWidget - > addCategoryItem ( tr ( " Other Forums " ) , QIcon ( IMAGE_FOLDERYELLOW ) , false ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
// load settings
processSettings ( true ) ;
2012-11-12 15:47:55 -05:00
2013-01-05 21:30:10 -05:00
settingsChanged ( ) ;
2012-11-12 15:47:55 -05:00
}
GxsForumsDialog : : ~ GxsForumsDialog ( )
{
2012-11-21 13:55:52 -05:00
// save settings
processSettings ( false ) ;
2012-11-27 18:21:20 -05:00
delete ( mForumQueue ) ;
2012-11-12 15:47:55 -05:00
}
2012-12-27 10:56:57 -05:00
//UserNotify *GxsForumsDialog::getUserNotify(QObject *parent)
2012-11-21 13:55:52 -05:00
//{
// return new GxsForumUserNotify(parent);
//}
2013-07-12 13:24:11 -04:00
void GxsForumsDialog : : todo ( )
{
QMessageBox : : information ( this , " Todo " ,
" <b>Open points:</b><ul> "
" <li>Restore forum keys "
" <li>Display AUTHD "
" <li>Copy/navigate forum link "
" <li>Display count of unread messages "
" <li>Show/Edit forum details "
" <li>Don't show own posts as unread "
" <li>Remove messages "
" </ul> " ) ;
}
2013-01-05 21:30:10 -05:00
void GxsForumsDialog : : processSettings ( bool load )
2012-11-12 15:47:55 -05:00
{
2012-11-21 13:55:52 -05:00
Settings - > beginGroup ( QString ( " GxsForumsDialog " ) ) ;
2012-11-12 15:47:55 -05:00
2013-01-05 21:30:10 -05:00
if ( load ) {
2012-11-21 13:55:52 -05:00
// load settings
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
// state of splitter
ui . splitter - > restoreState ( Settings - > value ( " Splitter " ) . toByteArray ( ) ) ;
} else {
// save settings
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
// state of splitter
Settings - > setValue ( " Splitter " , ui . splitter - > saveState ( ) ) ;
}
2012-11-12 15:47:55 -05:00
2013-01-05 21:30:10 -05:00
ui . forumTreeWidget - > processSettings ( Settings , load ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
Settings - > endGroup ( ) ;
}
2013-01-05 21:30:10 -05:00
void GxsForumsDialog : : settingsChanged ( )
{
if ( Settings - > getForumOpenAllInNewTab ( ) ) {
if ( mThreadWidget ) {
delete ( mThreadWidget ) ;
mThreadWidget = NULL ;
}
} else {
if ( ! mThreadWidget ) {
mThreadWidget = createThreadWidget ( " " ) ;
// remove close button of the the first tab
ui . threadTabWidget - > hideCloseButton ( ui . threadTabWidget - > indexOf ( mThreadWidget ) ) ;
}
}
}
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : forumListCustomPopupMenu ( QPoint /*point*/ )
2012-11-12 15:47:55 -05:00
{
2012-11-28 07:31:14 -05:00
int subscribeFlags = ui . forumTreeWidget - > subscribeFlags ( QString : : fromStdString ( mForumId ) ) ;
2012-11-27 18:21:20 -05:00
QMenu contextMnu ( this ) ;
2012-11-12 15:47:55 -05:00
2013-02-10 19:19:35 -05:00
# ifdef DEBUG_FORUMS
std : : cerr < < " GxsForumsDialog::forumListCustomPopupMenu() " ;
2013-02-10 13:59:57 -05:00
std : : cerr < < std : : endl ;
2013-02-10 19:19:35 -05:00
std : : cerr < < " mForumId: " < < mForumId ;
2013-02-10 13:59:57 -05:00
std : : cerr < < std : : endl ;
2013-02-10 19:19:35 -05:00
std : : cerr < < " subscribeFlags: " < < subscribeFlags ;
2013-02-10 13:59:57 -05:00
std : : cerr < < std : : endl ;
2013-02-10 19:19:35 -05:00
std : : cerr < < " IS_GROUP_SUBSCRIBED(): " < < IS_GROUP_SUBSCRIBED ( subscribeFlags ) ;
2013-02-10 13:59:57 -05:00
std : : cerr < < std : : endl ;
2013-02-10 19:19:35 -05:00
std : : cerr < < " IS_GROUP_ADMIN(): " < < IS_GROUP_ADMIN ( subscribeFlags ) ;
2013-02-10 13:59:57 -05:00
std : : cerr < < std : : endl ;
std : : cerr < < std : : endl ;
2013-02-10 19:19:35 -05:00
# endif
2013-02-10 13:59:57 -05:00
2012-11-21 13:55:52 -05:00
QAction * action = contextMnu . addAction ( QIcon ( IMAGE_SUBSCRIBE ) , tr ( " Subscribe to Forum " ) , this , SLOT ( subscribeToForum ( ) ) ) ;
2013-02-10 19:19:35 -05:00
action - > setDisabled ( mForumId . empty ( ) | | IS_GROUP_SUBSCRIBED ( subscribeFlags ) ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
action = contextMnu . addAction ( QIcon ( IMAGE_UNSUBSCRIBE ) , tr ( " Unsubscribe to Forum " ) , this , SLOT ( unsubscribeToForum ( ) ) ) ;
2013-02-10 19:19:35 -05:00
action - > setEnabled ( ! mForumId . empty ( ) & & IS_GROUP_SUBSCRIBED ( subscribeFlags ) ) ;
2012-11-12 15:47:55 -05:00
2013-01-05 21:30:10 -05:00
if ( ! Settings - > getForumOpenAllInNewTab ( ) ) {
action = contextMnu . addAction ( QIcon ( " " ) , tr ( " Open in new tab " ) , this , SLOT ( openInNewTab ( ) ) ) ;
if ( mForumId . empty ( ) | | forumThreadWidget ( mForumId ) ) {
action - > setEnabled ( false ) ;
}
2012-12-29 21:41:53 -05:00
}
2012-11-21 13:55:52 -05:00
contextMnu . addSeparator ( ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
contextMnu . addAction ( QIcon ( IMAGE_NEWFORUM ) , tr ( " New Forum " ) , this , SLOT ( newforum ( ) ) ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
action = contextMnu . addAction ( QIcon ( IMAGE_INFO ) , tr ( " Show Forum Details " ) , this , SLOT ( showForumDetails ( ) ) ) ;
2012-11-27 18:21:20 -05:00
action - > setEnabled ( ! mForumId . empty ( ) ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
action = contextMnu . addAction ( QIcon ( " :/images/settings16.png " ) , tr ( " Edit Forum Details " ) , this , SLOT ( editForumDetails ( ) ) ) ;
2012-11-28 07:31:14 -05:00
action - > setEnabled ( ! mForumId . empty ( ) & & IS_GROUP_ADMIN ( subscribeFlags ) ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
QAction * shareKeyAct = new QAction ( QIcon ( " :/images/gpgp_key_generate.png " ) , tr ( " Share Forum " ) , & contextMnu ) ;
connect ( shareKeyAct , SIGNAL ( triggered ( ) ) , this , SLOT ( shareKey ( ) ) ) ;
2012-11-28 07:31:14 -05:00
shareKeyAct - > setEnabled ( ! mForumId . empty ( ) & & IS_GROUP_ADMIN ( subscribeFlags ) ) ;
2012-11-21 13:55:52 -05:00
contextMnu . addAction ( shareKeyAct ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
QAction * restoreKeysAct = new QAction ( QIcon ( " :/images/settings16.png " ) , tr ( " Restore Publish Rights for Forum " ) , & contextMnu ) ;
connect ( restoreKeysAct , SIGNAL ( triggered ( ) ) , this , SLOT ( restoreForumKeys ( ) ) ) ;
2012-11-28 07:31:14 -05:00
restoreKeysAct - > setEnabled ( ! mForumId . empty ( ) & & ! IS_GROUP_ADMIN ( subscribeFlags ) ) ;
2012-11-21 13:55:52 -05:00
contextMnu . addAction ( restoreKeysAct ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
action = contextMnu . addAction ( QIcon ( IMAGE_COPYLINK ) , tr ( " Copy RetroShare Link " ) , this , SLOT ( copyForumLink ( ) ) ) ;
2012-11-27 18:21:20 -05:00
action - > setEnabled ( ! mForumId . empty ( ) ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
contextMnu . addSeparator ( ) ;
2012-11-12 15:47:55 -05:00
2012-12-08 21:32:47 -05:00
action = contextMnu . addAction ( QIcon ( " :/images/message-mail-read.png " ) , tr ( " Mark all as read " ) , this , SLOT ( markMsgAsRead ( ) ) ) ;
2012-11-28 07:31:14 -05:00
action - > setEnabled ( ! mForumId . empty ( ) & & IS_GROUP_SUBSCRIBED ( subscribeFlags ) ) ;
2012-11-12 15:47:55 -05:00
2012-12-08 21:32:47 -05:00
action = contextMnu . addAction ( QIcon ( " :/images/message-mail.png " ) , tr ( " Mark all as unread " ) , this , SLOT ( markMsgAsUnread ( ) ) ) ;
2012-11-28 07:31:14 -05:00
action - > setEnabled ( ! mForumId . empty ( ) & & IS_GROUP_SUBSCRIBED ( subscribeFlags ) ) ;
2012-11-12 15:47:55 -05:00
# ifdef DEBUG_FORUMS
2012-11-21 13:55:52 -05:00
contextMnu . addSeparator ( ) ;
action = contextMnu . addAction ( " Generate mass data " , this , SLOT ( generateMassData ( ) ) ) ;
2012-11-27 18:21:20 -05:00
action - > setEnabled ( ! mCurrForumId . empty ( ) & & IS_GROUP_SUBSCRIBED ( mSubscribeFlags ) ) ;
2012-11-12 15:47:55 -05:00
# endif
2012-11-21 13:55:52 -05:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2012-11-12 15:47:55 -05:00
}
void GxsForumsDialog : : restoreForumKeys ( void )
{
2012-11-27 18:21:20 -05:00
QMessageBox : : warning ( this , " RetroShare " , " ToDo " ) ;
2012-11-12 15:47:55 -05:00
# ifdef TOGXS
rsGxsForums - > groupRestoreKeys ( mCurrForumId ) ;
# endif
}
2013-07-19 05:48:51 -04:00
void GxsForumsDialog : : updateDisplay ( bool complete )
2012-11-12 15:47:55 -05:00
{
2013-07-19 05:48:51 -04:00
if ( complete | | ! getGrpIds ( ) . empty ( ) ) {
/* Update forums list */
insertForums ( ) ;
}
2012-11-12 15:47:55 -05:00
}
void GxsForumsDialog : : forumInfoToGroupItemInfo ( const RsGroupMetaData & forumInfo , GroupItemInfo & groupItemInfo )
{
2012-11-21 13:55:52 -05:00
groupItemInfo . id = QString : : fromStdString ( forumInfo . mGroupId ) ;
groupItemInfo . name = QString : : fromUtf8 ( forumInfo . mGroupName . c_str ( ) ) ;
//groupItemInfo.description = QString::fromUtf8(forumInfo.forumDesc);
groupItemInfo . popularity = forumInfo . mPop ;
groupItemInfo . lastpost = QDateTime : : fromTime_t ( forumInfo . mLastPost ) ;
2012-11-28 07:31:14 -05:00
groupItemInfo . subscribeFlags = forumInfo . mSubscribeFlags ;
2012-11-12 15:47:55 -05:00
# if TOGXS
2012-11-21 13:55:52 -05:00
if ( forumInfo . mGroupFlags & RS_DISTRIB_AUTHEN_REQ ) {
groupItemInfo . name + = " ( " + tr ( " AUTHD " ) + " ) " ;
groupItemInfo . icon = QIcon ( IMAGE_FORUMAUTHD ) ;
}
else
2012-11-12 15:47:55 -05:00
# endif
2012-11-21 13:55:52 -05:00
{
groupItemInfo . icon = QIcon ( IMAGE_FORUM ) ;
}
2012-11-12 15:47:55 -05:00
}
/***** INSERT FORUM LISTS *****/
void GxsForumsDialog : : insertForumsData ( const std : : list < RsGroupMetaData > & forumList )
{
std : : list < RsGroupMetaData > : : const_iterator it ;
2012-11-21 13:55:52 -05:00
QList < GroupItemInfo > adminList ;
QList < GroupItemInfo > subList ;
QList < GroupItemInfo > popList ;
QList < GroupItemInfo > otherList ;
std : : multimap < uint32_t , GroupItemInfo > popMap ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
for ( it = forumList . begin ( ) ; it ! = forumList . end ( ) ; it + + ) {
2012-11-12 15:47:55 -05:00
/* sort it into Publish (Own), Subscribed, Popular and Other */
uint32_t flags = it - > mSubscribeFlags ;
2012-11-21 13:55:52 -05:00
GroupItemInfo groupItemInfo ;
forumInfoToGroupItemInfo ( * it , groupItemInfo ) ;
2012-11-12 15:47:55 -05:00
2013-03-24 12:29:08 -04:00
if ( IS_GROUP_SUBSCRIBED ( flags ) )
{
if ( IS_GROUP_ADMIN ( flags ) )
{
adminList . push_back ( groupItemInfo ) ;
}
else
{
/* subscribed forum */
subList . push_back ( groupItemInfo ) ;
}
}
else
{
2012-11-12 15:47:55 -05:00
/* rate the others by popularity */
2012-11-21 13:55:52 -05:00
popMap . insert ( std : : make_pair ( it - > mPop , groupItemInfo ) ) ;
2012-11-12 15:47:55 -05:00
}
}
/* iterate backwards through popMap - take the top 5 or 10% of list */
uint32_t popCount = 5 ;
if ( popCount < popMap . size ( ) / 10 )
{
popCount = popMap . size ( ) / 10 ;
}
uint32_t i = 0 ;
uint32_t popLimit = 0 ;
2012-11-21 13:55:52 -05:00
std : : multimap < uint32_t , GroupItemInfo > : : reverse_iterator rit ;
2012-11-12 15:47:55 -05:00
for ( rit = popMap . rbegin ( ) ; ( ( rit ! = popMap . rend ( ) ) & & ( i < popCount ) ) ; rit + + , i + + ) ;
2012-11-21 13:55:52 -05:00
if ( rit ! = popMap . rend ( ) ) {
popLimit = rit - > first ;
}
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
for ( rit = popMap . rbegin ( ) ; rit ! = popMap . rend ( ) ; rit + + ) {
2012-11-12 15:47:55 -05:00
if ( rit - > second . popularity < ( int ) popLimit ) {
2012-11-21 13:55:52 -05:00
otherList . append ( rit - > second ) ;
} else {
popList . append ( rit - > second ) ;
}
2012-11-12 15:47:55 -05:00
}
/* now we can add them in as a tree! */
2012-11-21 13:55:52 -05:00
ui . forumTreeWidget - > fillGroupItems ( yourForums , adminList ) ;
ui . forumTreeWidget - > fillGroupItems ( subscribedForums , subList ) ;
ui . forumTreeWidget - > fillGroupItems ( popularForums , popList ) ;
ui . forumTreeWidget - > fillGroupItems ( otherForums , otherList ) ;
2012-11-12 15:47:55 -05:00
updateMessageSummaryList ( " " ) ;
}
2012-12-29 21:41:53 -05:00
GxsForumThreadWidget * GxsForumsDialog : : forumThreadWidget ( const std : : string & forumId )
2012-12-08 21:32:47 -05:00
{
int tabCount = ui . threadTabWidget - > count ( ) ;
for ( int index = 0 ; index < tabCount ; + + index ) {
GxsForumThreadWidget * childWidget = dynamic_cast < GxsForumThreadWidget * > ( ui . threadTabWidget - > widget ( index ) ) ;
2013-01-05 21:30:10 -05:00
if ( mThreadWidget & & childWidget = = mThreadWidget ) {
2012-12-29 21:41:53 -05:00
continue ;
}
if ( childWidget & & childWidget - > forumId ( ) = = forumId ) {
2012-12-08 21:32:47 -05:00
return childWidget ;
break ;
}
}
return NULL ;
}
2012-12-29 21:41:53 -05:00
GxsForumThreadWidget * GxsForumsDialog : : createThreadWidget ( const std : : string & forumId )
{
GxsForumThreadWidget * threadWidget = new GxsForumThreadWidget ( forumId ) ;
int index = ui . threadTabWidget - > addTab ( threadWidget , threadWidget - > forumName ( true ) ) ;
ui . threadTabWidget - > setTabIcon ( index , threadWidget - > forumIcon ( ) ) ;
connect ( threadWidget , SIGNAL ( forumChanged ( QWidget * ) ) , this , SLOT ( threadTabInfoChanged ( QWidget * ) ) ) ;
return threadWidget ;
}
void GxsForumsDialog : : changedForum ( const QString & forumId )
2012-11-12 15:47:55 -05:00
{
2012-12-29 21:41:53 -05:00
mForumId = forumId . toStdString ( ) ;
2012-11-27 18:21:20 -05:00
if ( mForumId . empty ( ) ) {
2012-11-21 13:55:52 -05:00
return ;
}
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
// requestGroupSummary_CurrentForum(mForumId);
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
/* search exisiting tab */
2012-12-29 21:41:53 -05:00
GxsForumThreadWidget * threadWidget = forumThreadWidget ( mForumId ) ;
2012-11-27 18:21:20 -05:00
if ( ! threadWidget ) {
2013-01-05 21:30:10 -05:00
if ( mThreadWidget ) {
/* not found, use standard tab */
threadWidget = mThreadWidget ;
threadWidget - > setForumId ( mForumId ) ;
} else {
/* create new tab */
threadWidget = createThreadWidget ( mForumId ) ;
}
2012-12-29 21:41:53 -05:00
}
ui . threadTabWidget - > setCurrentWidget ( threadWidget ) ;
}
2013-01-05 21:30:10 -05:00
void GxsForumsDialog : : forumTreeMiddleButtonClicked ( QTreeWidgetItem * item )
{
openForumInNewTab ( ui . forumTreeWidget - > itemId ( item ) . toStdString ( ) ) ;
}
2012-12-29 21:41:53 -05:00
void GxsForumsDialog : : openInNewTab ( )
{
2013-01-05 21:30:10 -05:00
openForumInNewTab ( mForumId ) ;
}
void GxsForumsDialog : : openForumInNewTab ( const std : : string & forumId )
{
if ( forumId . empty ( ) ) {
2012-12-29 21:41:53 -05:00
return ;
}
/* search exisiting tab */
2013-01-05 21:30:10 -05:00
GxsForumThreadWidget * threadWidget = forumThreadWidget ( forumId ) ;
2012-12-29 21:41:53 -05:00
if ( ! threadWidget ) {
/* not found, create new tab */
2013-01-05 21:30:10 -05:00
threadWidget = createThreadWidget ( forumId ) ;
2012-11-21 13:55:52 -05:00
}
2012-11-27 18:21:20 -05:00
ui . threadTabWidget - > setCurrentWidget ( threadWidget ) ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : threadTabCloseRequested ( int index )
2012-11-12 15:47:55 -05:00
{
2012-11-27 18:21:20 -05:00
GxsForumThreadWidget * threadWidget = dynamic_cast < GxsForumThreadWidget * > ( ui . threadTabWidget - > widget ( index ) ) ;
2012-12-29 21:41:53 -05:00
if ( ! threadWidget ) {
return ;
2012-11-21 13:55:52 -05:00
}
2012-12-29 21:41:53 -05:00
if ( threadWidget = = mThreadWidget ) {
return ;
}
delete ( threadWidget ) ;
}
void GxsForumsDialog : : threadTabChanged ( int index )
{
GxsForumThreadWidget * threadWidget = dynamic_cast < GxsForumThreadWidget * > ( ui . threadTabWidget - > widget ( index ) ) ;
if ( ! threadWidget ) {
return ;
}
ui . forumTreeWidget - > activateId ( QString : : fromStdString ( threadWidget - > forumId ( ) ) , false ) ;
2012-11-27 18:21:20 -05:00
}
2012-11-12 15:47:55 -05:00
2012-12-29 21:41:53 -05:00
void GxsForumsDialog : : threadTabInfoChanged ( QWidget * widget )
2012-11-27 18:21:20 -05:00
{
int index = ui . threadTabWidget - > indexOf ( widget ) ;
if ( index < 0 ) {
2012-11-21 13:55:52 -05:00
return ;
}
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
GxsForumThreadWidget * threadWidget = dynamic_cast < GxsForumThreadWidget * > ( ui . threadTabWidget - > widget ( index ) ) ;
if ( ! threadWidget ) {
2012-11-21 13:55:52 -05:00
return ;
}
2012-11-27 18:21:20 -05:00
2012-12-08 21:32:47 -05:00
ui . threadTabWidget - > setTabText ( index , threadWidget - > forumName ( true ) ) ;
2012-12-04 11:06:21 -05:00
ui . threadTabWidget - > setTabIcon ( index , threadWidget - > forumIcon ( ) ) ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : copyForumLink ( )
{
if ( mForumId . empty ( ) ) {
return ;
2012-11-21 13:55:52 -05:00
}
2012-11-27 18:21:20 -05:00
// THIS CODE CALLS getForumInfo() to verify that the Ids are valid.
// As we are switching to Request/Response this is now harder to do...
// So not bothering any more - shouldn't be necessary.
// IF we get errors - fix them, rather than patching here.
#if 0
ForumInfo fi ;
if ( rsGxsForums - > getForumInfo ( mCurrForumId , fi ) ) {
RetroShareLink link ;
if ( link . createForum ( fi . forumId , " " ) ) {
QList < RetroShareLink > urls ;
urls . push_back ( link ) ;
RSLinkClipboard : : copyLinks ( urls ) ;
2012-11-21 13:55:52 -05:00
}
}
2012-11-27 18:21:20 -05:00
# endif
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
QMessageBox : : warning ( this , " RetroShare " , " ToDo " ) ;
}
2012-12-08 21:32:47 -05:00
void GxsForumsDialog : : markMsgAsRead ( )
{
GxsForumThreadWidget * threadWidget = forumThreadWidget ( mForumId ) ;
if ( threadWidget ) {
threadWidget - > setAllMsgReadStatus ( true ) ;
}
}
void GxsForumsDialog : : markMsgAsUnread ( )
{
GxsForumThreadWidget * threadWidget = forumThreadWidget ( mForumId ) ;
if ( threadWidget ) {
threadWidget - > setAllMsgReadStatus ( false ) ;
}
}
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : newforum ( )
{
GxsForumGroupDialog cf ( mForumQueue , this ) ;
cf . exec ( ) ;
}
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : subscribeToForum ( )
{
forumSubscribe ( true ) ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : unsubscribeToForum ( )
2012-11-12 15:47:55 -05:00
{
2012-11-27 18:21:20 -05:00
forumSubscribe ( false ) ;
}
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : forumSubscribe ( bool subscribe )
{
if ( mForumId . empty ( ) ) {
2012-11-21 13:55:52 -05:00
return ;
}
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
uint32_t token ;
rsGxsForums - > subscribeToGroup ( token , mForumId , subscribe ) ;
2013-07-15 10:22:33 -04:00
mForumQueue - > queueRequest ( token , 0 , RS_TOKREQ_ANSTYPE_ACK , TOKEN_TYPE_SUBSCRIBE_CHANGE ) ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : showForumDetails ( )
2012-11-12 15:47:55 -05:00
{
2012-11-27 18:21:20 -05:00
if ( mForumId . empty ( ) ) {
return ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
RsGxsForumGroup grp ;
grp . mMeta . mGroupId = mForumId ;
2012-11-21 13:55:52 -05:00
2012-11-28 17:27:19 -05:00
GxsForumGroupDialog cf ( grp , GxsGroupDialog : : MODE_SHOW , this ) ;
2012-11-27 18:21:20 -05:00
cf . exec ( ) ;
}
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : editForumDetails ( )
{
if ( mForumId . empty ( ) ) {
return ;
2012-11-12 15:47:55 -05:00
}
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
RsGxsForumGroup grp ;
grp . mMeta . mGroupId = mForumId ;
2012-11-21 13:55:52 -05:00
2012-11-28 17:27:19 -05:00
GxsForumGroupDialog cf ( grp , GxsGroupDialog : : MODE_EDIT , this ) ;
2012-11-27 18:21:20 -05:00
cf . exec ( ) ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : shareKey ( )
2012-11-12 15:47:55 -05:00
{
2012-12-16 14:17:11 -05:00
ShareKey shareUi ( this , mForumId , FORUM_KEY_SHARE ) ;
2012-11-27 18:21:20 -05:00
shareUi . exec ( ) ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : updateMessageSummaryList ( std : : string forumId )
2012-11-12 15:47:55 -05:00
{
2012-11-27 18:21:20 -05:00
QTreeWidgetItem * items [ 2 ] = { yourForums , subscribedForums } ;
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
for ( int item = 0 ; item < 2 ; item + + ) {
int child ;
int childCount = items [ item ] - > childCount ( ) ;
for ( child = 0 ; child < childCount ; child + + ) {
QTreeWidgetItem * childItem = items [ item ] - > child ( child ) ;
std : : string childId = ui . forumTreeWidget - > itemId ( childItem ) . toStdString ( ) ;
if ( childId . empty ( ) ) {
continue ;
}
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
if ( forumId . empty ( ) | | childId = = forumId ) {
/* calculate unread messages */
unsigned int newMessageCount = 0 ;
unsigned int unreadMessageCount = 0 ;
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
//#TODO rsGxsForums->getMessageCount(childId, newMessageCount, unreadMessageCount);
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
std : : cerr < < " IMPLEMENT rsGxsForums->getMessageCount() " ;
std : : cerr < < std : : endl ;
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
ui . forumTreeWidget - > setUnreadCount ( childItem , unreadMessageCount ) ;
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
if ( forumId . empty ( ) = = false ) {
/* Calculate only this forum */
break ;
}
}
}
2012-11-12 15:47:55 -05:00
}
}
2012-11-27 18:21:20 -05:00
bool GxsForumsDialog : : navigate ( const std : : string & forumId , const std : : string & msgId )
2012-11-12 15:47:55 -05:00
{
2012-11-27 18:21:20 -05:00
if ( forumId . empty ( ) ) {
return false ;
}
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
if ( ui . forumTreeWidget - > activateId ( QString : : fromStdString ( forumId ) , msgId . empty ( ) ) = = NULL ) {
return false ;
2012-11-21 13:55:52 -05:00
}
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
/* Threads are filled in changedForum */
if ( mForumId ! = forumId ) {
return false ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
if ( msgId . empty ( ) ) {
return true ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
//#TODO
// if (mThreadLoading) {
// mThreadLoad.FocusMsgId = msgId;
// return true;
// }
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
/* Search exisiting item */
// QTreeWidgetItemIterator itemIterator(ui.threadTreeWidget);
// QTreeWidgetItem *item = NULL;
// while ((item = *itemIterator) != NULL) {
// itemIterator++;
// if (item->data(COLUMN_THREAD_DATA, ROLE_THREAD_MSGID).toString().toStdString() == msgId) {
// ui.threadTreeWidget->setCurrentItem(item);
// ui.threadTreeWidget->setFocus();
// return true;
// }
// }
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
return false ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : generateMassData ( )
2012-11-12 15:47:55 -05:00
{
2012-11-27 18:21:20 -05:00
# ifdef DEBUG_FORUMS
if ( mCurrForumId . empty ( ) ) {
return ;
2012-11-21 13:55:52 -05:00
}
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
if ( QMessageBox : : question ( this , " Generate mass data " , " Do you really want to generate mass data ? " , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) = = QMessageBox : : No ) {
2012-11-12 15:47:55 -05:00
return ;
}
2012-11-27 18:21:20 -05:00
for ( int thread = 1 ; thread < 1000 ; thread + + ) {
ForumMsgInfo threadInfo ;
threadInfo . forumId = mCurrForumId ;
threadInfo . title = QString ( " Test %1 " ) . arg ( thread , 3 , 10 , QChar ( ' 0 ' ) ) . toStdWString ( ) ;
threadInfo . msg = QString ( " That is only a test " ) . toStdWString ( ) ;
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
if ( rsGxsForums - > ForumMessageSend ( threadInfo ) = = false ) {
return ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
for ( int msg = 1 ; msg < 3 ; msg + + ) {
ForumMsgInfo msgInfo ;
msgInfo . forumId = mCurrForumId ;
msgInfo . threadId = threadInfo . msgId ;
msgInfo . parentId = threadInfo . msgId ;
msgInfo . title = threadInfo . title ;
msgInfo . msg = threadInfo . msg ;
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
if ( rsGxsForums - > ForumMessageSend ( msgInfo ) = = false ) {
return ;
2012-11-12 15:47:55 -05:00
}
}
}
2012-11-27 18:21:20 -05:00
# endif
2012-11-12 15:47:55 -05:00
}
/*********************** **** **** **** ***********************/
2012-11-27 18:21:20 -05:00
/** Request / Response of Data ********************************/
2012-11-12 15:47:55 -05:00
/*********************** **** **** **** ***********************/
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : insertForums ( )
2012-11-12 15:47:55 -05:00
{
2012-11-27 18:21:20 -05:00
requestGroupSummary ( ) ;
}
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : requestGroupSummary ( )
{
2013-07-12 13:24:11 -04:00
// mStateHelper->setLoading(TOKEN_TYPE_LISTING, true);
2013-07-15 10:22:33 -04:00
# ifdef DEBUG_FORUMS
2012-11-27 18:21:20 -05:00
std : : cerr < < " GxsForumsDialog::requestGroupSummary() " ;
2012-11-21 13:55:52 -05:00
std : : cerr < < std : : endl ;
2013-07-15 10:22:33 -04:00
# endif
2012-11-21 13:55:52 -05:00
2013-07-15 10:22:33 -04:00
mForumQueue - > cancelActiveRequestTokens ( TOKEN_TYPE_LISTING ) ;
2012-12-04 11:06:21 -05:00
2012-11-15 18:51:57 -05:00
RsTokReqOptions opts ;
2012-11-27 18:21:20 -05:00
opts . mReqType = GXS_REQUEST_TYPE_GROUP_META ;
2012-11-15 18:51:57 -05:00
2012-12-08 21:32:47 -05:00
uint32_t token ;
mForumQueue - > requestGroupInfo ( token , RS_TOKREQ_ANSTYPE_SUMMARY , opts , TOKEN_TYPE_LISTING ) ;
2012-11-12 15:47:55 -05:00
}
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : loadGroupSummary ( const uint32_t & token )
2012-11-12 15:47:55 -05:00
{
2013-07-15 10:22:33 -04:00
# ifdef DEBUG_FORUMS
2012-11-27 18:21:20 -05:00
std : : cerr < < " GxsForumsDialog::loadGroupSummary() " ;
2012-11-21 13:55:52 -05:00
std : : cerr < < std : : endl ;
2013-07-15 10:22:33 -04:00
# endif
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
std : : list < RsGroupMetaData > groupInfo ;
rsGxsForums - > getGroupSummary ( token , groupInfo ) ;
if ( groupInfo . size ( ) > 0 )
2012-11-12 15:47:55 -05:00
{
2013-07-12 13:24:11 -04:00
// mStateHelper->setActive(TOKEN_TYPE_LISTING, true);
2012-11-27 18:21:20 -05:00
insertForumsData ( groupInfo ) ;
2012-11-12 15:47:55 -05:00
}
2012-11-21 13:55:52 -05:00
else
{
2012-11-27 18:21:20 -05:00
std : : cerr < < " GxsForumsDialog::loadGroupSummary() ERROR No Groups... " ;
2012-11-21 13:55:52 -05:00
std : : cerr < < std : : endl ;
2013-07-12 13:24:11 -04:00
// mStateHelper->setActive(TOKEN_TYPE_LISTING, false);
2012-11-21 13:55:52 -05:00
}
2013-07-12 13:24:11 -04:00
// mStateHelper->setLoading(TOKEN_TYPE_LISTING, false);
2012-11-12 15:47:55 -05:00
}
/*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/
2013-07-15 10:22:33 -04:00
void GxsForumsDialog : : acknowledgeSubscribeChange ( const uint32_t & token )
{
# ifdef DEBUG_FORUMS
std : : cerr < < " GxsForumsDialog::acknowledgeSubscribeChange() " ;
std : : cerr < < std : : endl ;
# endif
RsGxsGroupId groupId ;
rsGxsForums - > acknowledgeGrp ( token , groupId ) ;
insertForums ( ) ;
}
/*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/
2012-11-27 18:21:20 -05:00
//void GxsForumsDialog::requestGroupSummary_CurrentForum(const std::string &forumId)
//{
// RsTokReqOptions opts;
// opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
2012-11-15 18:51:57 -05:00
2012-11-27 18:21:20 -05:00
// std::list<std::string> grpIds;
// grpIds.push_back(forumId);
2012-11-21 13:55:52 -05:00
2012-11-27 18:21:20 -05:00
// std::cerr << "GxsForumsDialog::requestGroupSummary_CurrentForum(" << forumId << ")";
// std::cerr << std::endl;
2012-11-15 18:51:57 -05:00
2012-11-27 18:21:20 -05:00
// uint32_t token;
2012-12-08 21:32:47 -05:00
// mForumQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_CURRENTFORUM);
2012-11-27 18:21:20 -05:00
//}
2012-11-15 18:51:57 -05:00
2012-11-27 18:21:20 -05:00
//void GxsForumsDialog::loadGroupSummary_CurrentForum(const uint32_t &token)
//{
// std::cerr << "GxsForumsDialog::loadGroupSummary_CurrentForum()";
// std::cerr << std::endl;
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
// std::list<RsGroupMetaData> groupInfo;
// rsGxsForums->getGroupSummary(token, groupInfo);
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
// if (groupInfo.size() == 1)
// {
// RsGroupMetaData fi = groupInfo.front();
// mSubscribeFlags = fi.mSubscribeFlags;
// }
// else
// {
// resetData();
// std::cerr << "GxsForumsDialog::loadGroupSummary_CurrentForum() ERROR Invalid Number of Groups...";
// std::cerr << std::endl;
// }
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
// setValid(true);
//}
2012-11-12 15:47:55 -05:00
/*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/
2012-11-21 13:55:52 -05:00
2012-11-12 15:47:55 -05:00
void GxsForumsDialog : : loadRequest ( const TokenQueue * queue , const TokenRequest & req )
{
2013-07-15 10:22:33 -04:00
# ifdef DEBUG_FORUMS
2012-11-12 15:47:55 -05:00
std : : cerr < < " GxsForumsDialog::loadRequest() UserType: " < < req . mUserType ;
std : : cerr < < std : : endl ;
2013-07-15 10:22:33 -04:00
# endif
2012-11-21 13:55:52 -05:00
2012-11-12 15:47:55 -05:00
if ( queue = = mForumQueue )
{
/* now switch on req */
switch ( req . mUserType )
{
2012-12-08 21:32:47 -05:00
case TOKEN_TYPE_LISTING :
2012-11-21 13:55:52 -05:00
loadGroupSummary ( req . mToken ) ;
break ;
2012-11-12 15:47:55 -05:00
2013-07-15 10:22:33 -04:00
case TOKEN_TYPE_SUBSCRIBE_CHANGE :
acknowledgeSubscribeChange ( req . mToken ) ;
break ;
2012-12-08 21:32:47 -05:00
// case TOKEN_TYPE_CURRENTFORUM:
2012-11-27 18:21:20 -05:00
// loadGroupSummary_CurrentForum(req.mToken);
// break;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
default :
std : : cerr < < " GxsForumsDialog::loadRequest() ERROR: INVALID TYPE " ;
std : : cerr < < std : : endl ;
2012-11-12 15:47:55 -05:00
}
}
}