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"
# include "gxs/GxsForumGroupDialog.h"
2012-11-27 18:21:20 -05:00
# include "gxsforums/GxsForumThreadWidget.h"
2012-11-12 15:47:55 -05:00
# include "settings/rsharesettings.h"
# include "RetroShareLink.h"
# include "channels/ShareKey.h"
# include "notifyqt.h"
// These should be in retroshare/ folder.
# include "gxs/rsgxsflags.h"
//#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"
/*
* 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 .
* - > Missing Messages are not handled yet .
* - > 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 )
: RsAutoUpdatePage ( 1000 , parent )
{
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
2012-11-27 18:21:20 -05:00
/* Setup Queue */
2012-11-21 13:55:52 -05:00
mForumQueue = new TokenQueue ( rsGxsForums - > getTokenService ( ) , this ) ;
2012-11-12 15:47:55 -05:00
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-11-27 18:21:20 -05:00
connect ( ui . forumTreeWidget , SIGNAL ( treeItemClicked ( QString ) ) , this , SLOT ( changedForum ( QString ) ) ) ;
connect ( ui . threadTabWidget , SIGNAL ( tabCloseRequested ( int ) ) , this , SLOT ( threadTabCloseRequested ( int ) ) ) ;
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( forumMsgReadSatusChanged ( QString , QString , int ) ) , this , SLOT ( forumMsgReadSatusChanged ( QString , QString , int ) ) ) ;
2012-11-15 18:51:57 -05:00
2012-11-21 13:55:52 -05:00
// HACK - TEMPORARY HIJACKING THIS BUTTON FOR REFRESH.
2012-11-27 18:21:20 -05:00
connect ( ui . refreshButton , SIGNAL ( clicked ( ) ) , this , SLOT ( forceUpdateDisplay ( ) ) ) ;
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
2012-11-21 13:55:52 -05:00
/* Hide platform specific features */
2012-11-12 15:47:55 -05:00
# ifdef Q_WS_WIN
# endif
}
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);
//}
2012-11-12 15:47:55 -05:00
void GxsForumsDialog : : processSettings ( bool bLoad )
{
2012-11-21 13:55:52 -05:00
Settings - > beginGroup ( QString ( " GxsForumsDialog " ) ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
if ( bLoad ) {
// 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
2012-11-21 13:55:52 -05:00
ui . forumTreeWidget - > processSettings ( Settings , bLoad ) ;
2012-11-12 15:47:55 -05:00
2012-11-21 13:55:52 -05:00
Settings - > endGroup ( ) ;
}
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
2012-11-21 13:55:52 -05:00
QAction * action = contextMnu . addAction ( QIcon ( IMAGE_SUBSCRIBE ) , tr ( " Subscribe to Forum " ) , this , SLOT ( subscribeToForum ( ) ) ) ;
2012-11-28 07:31:14 -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 ( ) ) ) ;
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-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
}
void GxsForumsDialog : : updateDisplay ( )
{
2012-11-21 13:55:52 -05:00
std : : list < std : : string > forumIds ;
std : : list < std : : string > : : iterator it ;
if ( ! rsGxsForums )
return ;
2012-11-12 15:47:55 -05:00
#if 0
// TODO groupsChanged... HACK XXX.
2012-11-21 13:55:52 -05:00
if ( ( rsGxsForums - > groupsChanged ( forumIds ) ) | | ( rsGxsForums - > updated ( ) ) )
{
/* update Forums List */
insertForums ( ) ;
it = std : : find ( forumIds . begin ( ) , forumIds . end ( ) , mCurrForumId ) ;
if ( it ! = forumIds . end ( ) )
{
/* update threads as well */
insertThreads ( ) ;
}
}
2012-11-12 15:47:55 -05:00
# endif
2012-11-21 13:55:52 -05:00
/* The proper version (above) can be done with a data request -> TODO */
if ( rsGxsForums - > updated ( ) )
{
/* update Forums List */
insertForums ( ) ;
}
2012-11-12 15:47:55 -05:00
}
2012-11-15 18:51:57 -05:00
// HACK until update works.
void GxsForumsDialog : : forceUpdateDisplay ( )
{
std : : cerr < < " GxsForumsDialog::forceUpdateDisplay() " ;
std : : cerr < < std : : endl ;
2012-11-21 13:55:52 -05:00
/* 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
2012-11-21 13:55:52 -05:00
if ( IS_GROUP_ADMIN ( flags ) ) {
adminList . push_back ( groupItemInfo ) ;
} else if ( IS_GROUP_SUBSCRIBED ( flags ) ) {
2012-11-12 15:47:55 -05:00
/* subscribed forum */
2012-11-21 13:55:52 -05:00
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-08 21:32:47 -05:00
GxsForumThreadWidget * GxsForumsDialog : : forumThreadWidget ( const std : : string & id )
{
int tabCount = ui . threadTabWidget - > count ( ) ;
for ( int index = 0 ; index < tabCount ; + + index ) {
GxsForumThreadWidget * childWidget = dynamic_cast < GxsForumThreadWidget * > ( ui . threadTabWidget - > widget ( index ) ) ;
if ( childWidget & & childWidget - > forumId ( ) = = id ) {
return childWidget ;
break ;
}
}
return NULL ;
}
2012-11-12 15:47:55 -05:00
void GxsForumsDialog : : changedForum ( const QString & id )
{
2012-11-27 18:21:20 -05:00
mForumId = id . toStdString ( ) ;
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-08 21:32:47 -05:00
GxsForumThreadWidget * threadWidget = forumThreadWidget ( id . toStdString ( ) ) ;
2012-11-27 18:21:20 -05:00
if ( ! threadWidget ) {
/* create a thread widget */
threadWidget = new GxsForumThreadWidget ( id . toStdString ( ) ) ;
2012-12-08 21:32:47 -05:00
int index = ui . threadTabWidget - > addTab ( threadWidget , threadWidget - > forumName ( true ) ) ;
2012-12-04 11:06:21 -05:00
ui . threadTabWidget - > setTabIcon ( index , threadWidget - > forumIcon ( ) ) ;
2012-11-27 18:21:20 -05:00
connect ( threadWidget , SIGNAL ( forumChanged ( QWidget * ) ) , this , SLOT ( threadTabChanged ( QWidget * ) ) ) ;
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 ) ) ;
if ( threadWidget ) {
delete ( threadWidget ) ;
2012-11-21 13:55:52 -05:00
}
2012-11-27 18:21:20 -05:00
}
2012-11-12 15:47:55 -05:00
2012-11-27 18:21:20 -05:00
void GxsForumsDialog : : threadTabChanged ( QWidget * widget )
{
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 ) ;
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-12-08 21:32:47 -05:00
# define TOKEN_TYPE_LISTING 1
//#define TOKEN_TYPE_CURRENTFORUM 2
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 ( )
{
std : : cerr < < " GxsForumsDialog::requestGroupSummary() " ;
2012-11-21 13:55:52 -05:00
std : : cerr < < std : : endl ;
2012-12-08 21:32:47 -05:00
std : : list < uint32_t > tokens ;
mForumQueue - > activeRequestTokens ( TOKEN_TYPE_LISTING , tokens ) ;
if ( ! tokens . empty ( ) ) {
std : : list < uint32_t > : : iterator tokenIt ;
for ( tokenIt = tokens . begin ( ) ; tokenIt ! = tokens . end ( ) ; + + tokenIt ) {
std : : cerr < < " GxsForumsDialog::requestGroupSummary() Canceling Request: " < < * tokenIt ;
std : : cerr < < std : : endl ;
2012-12-04 11:06:21 -05:00
2012-12-08 21:32:47 -05:00
mForumQueue - > cancelRequest ( * tokenIt ) ;
}
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
{
2012-11-27 18:21:20 -05:00
std : : cerr < < " GxsForumsDialog::loadGroupSummary() " ;
2012-11-21 13:55:52 -05:00
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 ) ;
if ( groupInfo . size ( ) > 0 )
2012-11-12 15:47:55 -05:00
{
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 ;
}
2012-11-12 15:47:55 -05:00
}
/*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/
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 )
{
std : : cerr < < " GxsForumsDialog::loadRequest() UserType: " < < req . mUserType ;
std : : cerr < < std : : endl ;
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
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 ;
break ;
2012-11-12 15:47:55 -05:00
}
}
}