From bbcbc9282e74f308312ad935506e7e37a091d6ff Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Tue, 8 Feb 2011 22:34:54 +0000 Subject: [PATCH] added key restore to forums and fixed restore bug git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4023 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsforums.h | 2 +- libretroshare/src/services/p3distrib.cc | 21 ++++++++------------- libretroshare/src/services/p3distrib.h | 2 +- libretroshare/src/services/p3forums.cc | 5 +++++ libretroshare/src/services/p3forums.h | 1 + retroshare-gui/src/gui/ForumsDialog.cpp | 16 ++++++++++++++++ retroshare-gui/src/gui/ForumsDialog.h | 2 +- 7 files changed, 33 insertions(+), 16 deletions(-) diff --git a/libretroshare/src/retroshare/rsforums.h b/libretroshare/src/retroshare/rsforums.h index a34c564d6..634dcc267 100644 --- a/libretroshare/src/retroshare/rsforums.h +++ b/libretroshare/src/retroshare/rsforums.h @@ -145,7 +145,7 @@ virtual bool getForumMessage(const std::string &fId, const std::string &mId, For virtual bool setMessageStatus(const std::string& fId,const std::string& mId, const uint32_t status, const uint32_t statusMask) = 0; virtual bool getMessageStatus(const std::string& fId, const std::string& mId, uint32_t& status) = 0; virtual bool ForumMessageSend(ForumMsgInfo &info) = 0; - +virtual bool forumRestoreKeys(const std::string& fId) = 0; virtual bool forumSubscribe(const std::string &fId, bool subscribe) = 0; virtual bool getMessageCount(const std::string &fId, unsigned int &newCount, unsigned int &unreadCount) = 0; diff --git a/libretroshare/src/services/p3distrib.cc b/libretroshare/src/services/p3distrib.cc index 40095c57c..6d613fc96 100644 --- a/libretroshare/src/services/p3distrib.cc +++ b/libretroshare/src/services/p3distrib.cc @@ -2041,7 +2041,7 @@ bool p3GroupDistrib::backUpKeys(const std::list& keysToBackUp } - delete store; + delete store; if(!RsDirUtil::renameFile(filenametmp,filename)) { @@ -2058,7 +2058,7 @@ bool p3GroupDistrib::backUpKeys(const std::list& keysToBackUp return ok; } -bool p3GroupDistrib::restoreGrpKeys(std::string grpId){ +bool p3GroupDistrib::restoreGrpKeys(const std::string& grpId){ #ifdef DISTRIB_DEBUG @@ -2077,6 +2077,7 @@ bool p3GroupDistrib::restoreGrpKeys(std::string grpId){ RsItem* item; bool ok = true; bool itemAttempted = false; + RsDistribGrpKey* key = NULL; RsStackMutex stack(distribMtx); @@ -2086,7 +2087,7 @@ bool p3GroupDistrib::restoreGrpKeys(std::string grpId){ while(NULL != (item = store->GetItem())){ itemAttempted = true; - RsDistribGrpKey* key = dynamic_cast(item); + key = dynamic_cast(item); if(key == NULL){ #ifdef DISTRIB_DEBUG @@ -2097,20 +2098,14 @@ bool p3GroupDistrib::restoreGrpKeys(std::string grpId){ return false; } - if(key->key.keyFlags & RSTLV_KEY_DISTRIB_ADMIN){ - + if(key->key.keyFlags & RSTLV_KEY_DISTRIB_ADMIN) ok &= locked_updateGroupAdminKey(*gi, key); - - }else - if((key->key.keyFlags & RSTLV_KEY_DISTRIB_PRIVATE)){ - + else if((key->key.keyFlags & RSTLV_KEY_DISTRIB_PRIVATE) || + (key->key.keyFlags & RSTLV_KEY_DISTRIB_PUBLIC)) ok &= locked_updateGroupPublishKey(*gi, key); - - }else{ - + else ok &= false; - } } diff --git a/libretroshare/src/services/p3distrib.h b/libretroshare/src/services/p3distrib.h index a52d9fc68..5dd237dd2 100644 --- a/libretroshare/src/services/p3distrib.h +++ b/libretroshare/src/services/p3distrib.h @@ -552,7 +552,7 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu * @param grpId the grpId id for which backup keys should be restored * @return false if failed and vice versa */ - virtual bool restoreGrpKeys(std::string grpId); /// restores a group keys from backup + virtual bool restoreGrpKeys(const std::string& grpId); /// restores a group keys from backup /** * Allows user to send keys to a list of peers diff --git a/libretroshare/src/services/p3forums.cc b/libretroshare/src/services/p3forums.cc index fb0d3fd6e..d9d366d85 100644 --- a/libretroshare/src/services/p3forums.cc +++ b/libretroshare/src/services/p3forums.cc @@ -431,6 +431,11 @@ bool p3Forums::getMessageStatus(const std::string& fId, const std::string& mId, return false; } +bool p3Forums::forumRestoreKeys(const std::string& fIds) +{ + return p3GroupDistrib::restoreGrpKeys(fIds); +} + std::string p3Forums::createForum(const std::wstring &forumName, const std::wstring &forumDesc, uint32_t forumFlags) { diff --git a/libretroshare/src/services/p3forums.h b/libretroshare/src/services/p3forums.h index 2dc21e28f..e7c957a8d 100644 --- a/libretroshare/src/services/p3forums.h +++ b/libretroshare/src/services/p3forums.h @@ -58,6 +58,7 @@ virtual bool getForumMessage(const std::string &fId, const std::string &mId, For virtual bool ForumMessageSend(ForumMsgInfo &info); virtual bool setMessageStatus(const std::string& fId, const std::string& mId, const uint32_t status, const uint32_t statusMask); virtual bool getMessageStatus(const std::string& fId, const std::string& mId, uint32_t& status); +virtual bool forumRestoreKeys(const std::string& fId); virtual bool forumSubscribe(const std::string &fId, bool subscribe); diff --git a/retroshare-gui/src/gui/ForumsDialog.cpp b/retroshare-gui/src/gui/ForumsDialog.cpp index 5a3c1bd1a..4635c2925 100644 --- a/retroshare-gui/src/gui/ForumsDialog.cpp +++ b/retroshare-gui/src/gui/ForumsDialog.cpp @@ -273,6 +273,8 @@ void ForumsDialog::forumListCustomPopupMenu( QPoint point ) action = contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Unsubscribe to Forum"), this, SLOT(unsubscribeToForum())); action->setEnabled (!mCurrForumId.empty() && m_bIsForumSubscribed); + + contextMnu.addSeparator(); contextMnu.addAction(QIcon(IMAGE_NEWFORUM), tr("New Forum"), this, SLOT(newforum())); @@ -283,6 +285,13 @@ void ForumsDialog::forumListCustomPopupMenu( QPoint point ) action = contextMnu.addAction(QIcon(":/images/settings16.png"), tr("Edit Forum Details"), this, SLOT(editForumDetails())); action->setEnabled (!mCurrForumId.empty () && m_bIsForumAdmin); + + QAction *restoreKeysAct = new QAction(QIcon(":/images/settings16.png"), tr("Restore Publish Rights for Forum" ), &contextMnu); + connect( restoreKeysAct , SIGNAL( triggered() ), this, SLOT( restoreForumKeys() ) ); + + restoreKeysAct->setEnabled(!mCurrForumId.empty() && !m_bIsForumAdmin); + contextMnu.addAction( restoreKeysAct); + contextMnu.addSeparator(); action = contextMnu.addAction(QIcon(":/images/message-mail-read.png"), tr("Mark all as read"), this, SLOT(markMsgAsReadAll())); @@ -326,6 +335,8 @@ void ForumsDialog::threadListCustomPopupMenu( QPoint point ) QAction *markMsgAsUnreadChildren = new QAction(QIcon(":/images/message-mail.png"), tr("Mark as unread") + " (" + tr ("with children") + ")", &contextMnu); connect(markMsgAsUnreadChildren , SIGNAL(triggered()), this, SLOT(markMsgAsUnreadChildren())); + + if (m_bIsForumSubscribed) { QList Rows; QList RowsRead; @@ -385,6 +396,11 @@ void ForumsDialog::threadListCustomPopupMenu( QPoint point ) contextMnu.exec(QCursor::pos()); } +void ForumsDialog::restoreForumKeys(void) +{ + rsForums->forumRestoreKeys(mCurrForumId); +} + void ForumsDialog::togglethreadview() { // save state of button diff --git a/retroshare-gui/src/gui/ForumsDialog.h b/retroshare-gui/src/gui/ForumsDialog.h index ef5584fd9..88654b6cf 100644 --- a/retroshare-gui/src/gui/ForumsDialog.h +++ b/retroshare-gui/src/gui/ForumsDialog.h @@ -43,7 +43,7 @@ private slots: /** Create the context popup menu and it's submenus */ void forumListCustomPopupMenu( QPoint point ); void threadListCustomPopupMenu( QPoint point ); - + void restoreForumKeys(); void newforum(); void changedForum(const QString &id);