From f05d2f9b0968dd678206089bd34de6226ff083ab Mon Sep 17 00:00:00 2001 From: drbob Date: Sun, 1 Jul 2012 23:05:03 +0000 Subject: [PATCH] Improvements for New Services. * Forums now loads example data... * new Posted Service, only the basics for now. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5269 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/RetroShare.pro | 21 + retroshare-gui/src/gui/ForumsV2Dialog.cpp | 37 +- .../src/gui/Posted/PostedComments.cpp | 627 ++++++++++++++++ .../src/gui/Posted/PostedComments.h | 118 +++ .../src/gui/Posted/PostedComments.ui | 169 +++++ .../src/gui/Posted/PostedDialog.cpp | 670 ++++++++++++++++++ retroshare-gui/src/gui/Posted/PostedDialog.h | 68 ++ retroshare-gui/src/gui/Posted/PostedDialog.ui | 33 + retroshare-gui/src/gui/Posted/PostedItem.cpp | 299 ++++++++ retroshare-gui/src/gui/Posted/PostedItem.h | 65 ++ retroshare-gui/src/gui/Posted/PostedItem.ui | 285 ++++++++ .../src/gui/Posted/PostedListDialog.cpp | 511 +++++++++++++ .../src/gui/Posted/PostedListDialog.h | 100 +++ .../src/gui/Posted/PostedListDialog.ui | 228 ++++++ .../src/gui/unfinished/ApplicationWindow.cpp | 6 + 15 files changed, 3236 insertions(+), 1 deletion(-) create mode 100644 retroshare-gui/src/gui/Posted/PostedComments.cpp create mode 100644 retroshare-gui/src/gui/Posted/PostedComments.h create mode 100644 retroshare-gui/src/gui/Posted/PostedComments.ui create mode 100644 retroshare-gui/src/gui/Posted/PostedDialog.cpp create mode 100644 retroshare-gui/src/gui/Posted/PostedDialog.h create mode 100644 retroshare-gui/src/gui/Posted/PostedDialog.ui create mode 100644 retroshare-gui/src/gui/Posted/PostedItem.cpp create mode 100644 retroshare-gui/src/gui/Posted/PostedItem.h create mode 100644 retroshare-gui/src/gui/Posted/PostedItem.ui create mode 100644 retroshare-gui/src/gui/Posted/PostedListDialog.cpp create mode 100644 retroshare-gui/src/gui/Posted/PostedListDialog.h create mode 100644 retroshare-gui/src/gui/Posted/PostedListDialog.ui diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index e23df4862..75b2f39c1 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -4,6 +4,7 @@ CONFIG += wikipoos CONFIG += thewire CONFIG += identities CONFIG += forumsv2 +CONFIG += posted CONFIG += unfinished QT += network xml script @@ -956,3 +957,23 @@ forumsv2 { gui/forumsv2/CreateForumV2Msg.cpp \ } + + +posted { + + HEADERS += gui/Posted/PostedDialog.h \ + gui/Posted/PostedListDialog.h \ + gui/Posted/PostedItem.h \ + gui/Posted/PostedComments.h \ + + FORMS += gui/Posted/PostedDialog.ui \ + gui/Posted/PostedListDialog.ui \ + gui/Posted/PostedItem.ui \ + gui/Posted/PostedComments.ui \ + + SOURCES += gui/Posted/PostedDialog.cpp \ + gui/Posted/PostedListDialog.cpp \ + gui/Posted/PostedItem.cpp \ + gui/Posted/PostedComments.cpp \ + +} diff --git a/retroshare-gui/src/gui/ForumsV2Dialog.cpp b/retroshare-gui/src/gui/ForumsV2Dialog.cpp index 54c20d20d..44cd660e2 100644 --- a/retroshare-gui/src/gui/ForumsV2Dialog.cpp +++ b/retroshare-gui/src/gui/ForumsV2Dialog.cpp @@ -141,6 +141,12 @@ ForumsV2Dialog::ForumsV2Dialog(QWidget *parent) m_bProcessSettings = false; subscribeFlags = 0; + + /* Setup Queue */ + mForumQueue = new TokenQueue(rsForumsV2, this); + + + connect( ui.forumTreeWidget, SIGNAL( treeCustomContextMenuRequested( QPoint ) ), this, SLOT( forumListCustomPopupMenu( QPoint ) ) ); connect( ui.threadTreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( threadListCustomPopupMenu( QPoint ) ) ); @@ -478,7 +484,8 @@ void ForumsV2Dialog::updateDisplay() if (!rsForumsV2) return; - if (rsForumsV2->groupsChanged(forumIds)) + // TODO groupsChanged... HACK XXX. + if ((rsForumsV2->groupsChanged(forumIds)) || (rsForumsV2->updated())) { /* update Forums List */ insertForums(); @@ -1812,6 +1819,9 @@ void ForumsV2Dialog::requestGroupSummary_CurrentForum(const std::string &forumId std::list grpIds; grpIds.push_back(forumId); + std::cerr << "ForumsV2Dialog::requestGroupSummary_CurrentForum(" << forumId << ")"; + std::cerr << std::endl; + uint32_t token; mForumQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, FORUMSV2DIALOG_CURRENTFORUM); } @@ -1845,10 +1855,16 @@ void ForumsV2Dialog::loadGroupSummary_CurrentForum(const uint32_t &token) void ForumsV2Dialog::loadCurrentForumThreads(const std::string &forumId) { + + std::cerr << "ForumsV2Dialog::loadCurrentForumThreads(" << forumId << ")"; + std::cerr << std::endl; + /* if already active -> kill current loading */ if (mThreadLoading) { /* Cleanup */ + std::cerr << "ForumsV2Dialog::loadCurrentForumThreads() Cleanup old Threads"; + std::cerr << std::endl; /* Wipe Widget Tree */ mThreadLoad.Items.clear(); @@ -1857,6 +1873,9 @@ void ForumsV2Dialog::loadCurrentForumThreads(const std::string &forumId) std::map::iterator it; for(it = mThreadLoad.MsgTokens.begin(); it != mThreadLoad.MsgTokens.end(); it++) { + std::cerr << "ForumsV2Dialog::loadCurrentForumThreads() Canceling Request: " << it->first; + std::cerr << std::endl; + mForumQueue->cancelRequest(it->first); } @@ -1865,6 +1884,9 @@ void ForumsV2Dialog::loadCurrentForumThreads(const std::string &forumId) } /* initiate loading */ + std::cerr << "ForumsV2Dialog::loadCurrentForumThreads() Initiating Loading"; + std::cerr << std::endl; + mThreadLoading = true; mThreadLoad.ForumId = mCurrForumId; @@ -1913,6 +1935,9 @@ void ForumsV2Dialog::requestGroupThreadData_InsertThreads(const std::string &for std::list grpIds; grpIds.push_back(forumId); + std::cerr << "ForumsV2Dialog::requestGroupThreadData_InsertThreads(" << forumId << ")"; + std::cerr << std::endl; + uint32_t token; mForumQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grpIds, FORUMSV2DIALOG_INSERTTHREADS); } @@ -2045,6 +2070,9 @@ void ForumsV2Dialog::requestChildData_InsertThreads(uint32_t &token, const std:: std::list msgIds; msgIds.push_back(parentId); + std::cerr << "ForumsV2Dialog::requestChildData_InsertThreads(" << parentId << ")"; + std::cerr << std::endl; + mForumQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, FORUMSV2DIALOG_INSERTCHILD); } @@ -2157,6 +2185,10 @@ void ForumsV2Dialog::requestMsgData_InsertPost(const std::string &msgId) std::list msgIds; msgIds.push_back(msgId); + std::cerr << "ForumsV2Dialog::requestMsgData_InsertPost(" << msgId << ")"; + std::cerr << std::endl; + + uint32_t token; mForumQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, FORUMV2DIALOG_INSERT_POST); } @@ -2190,6 +2222,9 @@ void ForumsV2Dialog::requestMsgData_ReplyMessage(const std::string &msgId) std::list msgIds; msgIds.push_back(msgId); + std::cerr << "ForumsV2Dialog::requestMsgData_ReplyMessage(" << msgId << ")"; + std::cerr << std::endl; + uint32_t token; mForumQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, FORUMV2DIALOG_REPLY_MESSAGE); } diff --git a/retroshare-gui/src/gui/Posted/PostedComments.cpp b/retroshare-gui/src/gui/Posted/PostedComments.cpp new file mode 100644 index 000000000..4e1f73bab --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedComments.cpp @@ -0,0 +1,627 @@ +/* + * Retroshare Posted Comments + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "PostedComments.h" + +//#include +#include + +#include +#include + +#include +#include + +/****** + * #define PHOTO_DEBUG 1 + *****/ + + +/**************************************************************** + * New Photo Display Widget. + * + * This has two 'lists'. + * Top list shows Albums. + * Lower list is photos from the selected Album. + * + * Notes: + * Each Item will be an AlbumItem, which contains a thumbnail & random details. + * We will limit Items to < 100. With a 'Filter to see more message. + * + * Thumbnails will come from Service. + * Option to Share albums / pictures onward (if permissions allow). + * Option to Download the albums to a specified directory. (is this required if sharing an album?) + * + * Will introduce a FullScreen SlideShow later... first get basics happening. + */ + + + + +/** Constructor */ +PostedComments::PostedComments(QWidget *parent) +:QWidget(parent) +{ + ui.setupUi(this); + +#if 0 + mAddDialog = NULL; + mAlbumSelected = NULL; + mPhotoSelected = NULL; + mSlideShow = NULL; + + connect( ui.toolButton_NewAlbum, SIGNAL(clicked()), this, SLOT(OpenOrShowPhotoAddDialog())); + connect( ui.toolButton_EditAlbum, SIGNAL(clicked()), this, SLOT(OpenPhotoEditDialog())); + connect( ui.toolButton_SlideShow, SIGNAL(clicked()), this, SLOT(OpenSlideShow())); + + QTimer *timer = new QTimer(this); + timer->connect(timer, SIGNAL(timeout()), this, SLOT(checkUpdate())); + timer->start(1000); + +#endif + + /* setup TokenQueue */ + //mPhotoQueue = new TokenQueue(rsPhoto, this); + +} + +#if 0 + +void PhotoDialog::notifySelection(PhotoItem *item, int ptype) +{ + std::cerr << "PhotoDialog::notifySelection() from : " << ptype << " " << item; + std::cerr << std::endl; + + switch(ptype) + { + default: + case PHOTO_ITEM_TYPE_ALBUM: + notifyAlbumSelection(item); + break; + case PHOTO_ITEM_TYPE_PHOTO: + notifyPhotoSelection(item); + break; + } +} + +void PhotoDialog::notifyAlbumSelection(PhotoItem *item) +{ + std::cerr << "PhotoDialog::notifyAlbumSelection() from : " << item; + std::cerr << std::endl; + + if (mAlbumSelected) + { + std::cerr << "PhotoDialog::notifyAlbumSelection() unselecting old one : " << mAlbumSelected; + std::cerr << std::endl; + + mAlbumSelected->setSelected(false); + } + + mAlbumSelected = item; + insertPhotosForSelectedAlbum(); +} + + +void PhotoDialog::notifyPhotoSelection(PhotoItem *item) +{ + std::cerr << "PhotoDialog::notifyPhotoSelection() from : " << item; + std::cerr << std::endl; + + if (mPhotoSelected) + { + std::cerr << "PhotoDialog::notifyPhotoSelection() unselecting old one : " << mPhotoSelected; + std::cerr << std::endl; + + mPhotoSelected->setSelected(false); + } + + mPhotoSelected = item; +} + + +void PhotoDialog::checkUpdate() +{ + /* update */ + if (!rsPhoto) + return; + + if (rsPhoto->updated()) + { + //insertAlbums(); + requestAlbumList(); + } + + return; +} + + +/*************** New Photo Dialog ***************/ + +void PhotoDialog::OpenSlideShow() +{ + + // TODO. + if (!mAlbumSelected) + { + // ALERT. + int ret = QMessageBox::information(this, tr("PhotoShare"), + tr("Please select an album before\n" + "requesting to edit it!"), + QMessageBox::Ok); + return; + } + + if (mAlbumSelected->mIsPhoto) + { + std::cerr << "PhotoDialog::OpenPhotoEditDialog() MAJOR ERROR!"; + std::cerr << std::endl; + return; + } + + std::string albumId = mAlbumSelected->mAlbumDetails.mMeta.mGroupId; + + if (mSlideShow) + { + mSlideShow->show(); + } + else + { + mSlideShow = new PhotoSlideShow(NULL); + mSlideShow->show(); + } + mSlideShow->loadAlbum(albumId); + +} + + +/*************** New Photo Dialog ***************/ + +void PhotoDialog::OpenOrShowPhotoAddDialog() +{ + if (mAddDialog) + { + mAddDialog->show(); + } + else + { + mAddDialog = new PhotoAddDialog(NULL); + mAddDialog->show(); + } + mAddDialog->clearDialog(); +} + + +/*************** Edit Photo Dialog ***************/ + +void PhotoDialog::OpenPhotoEditDialog() +{ + /* check if we have an album selected */ + // THE TWO MessageBoxes - should be handled by disabling the Button!. + // TODO. + if (!mAlbumSelected) + { + // ALERT. + int ret = QMessageBox::information(this, tr("PhotoShare"), + tr("Please select an album before\n" + "requesting to edit it!"), + QMessageBox::Ok); + return; + } + + if (mAlbumSelected->mIsPhoto) + { + std::cerr << "PhotoDialog::OpenPhotoEditDialog() MAJOR ERROR!"; + std::cerr << std::endl; + } + + std::string albumId = mAlbumSelected->mAlbumDetails.mMeta.mGroupId; +#if 0 + uint32_t flags = mAlbumSelected->mAlbumDetails.mMeta.mGroupFlags; + + if (!(flags & OWN)) + { + // ALERT. + int ret = QMessageBox::information(this, tr("PhotoShare"), + tr("Cannot Edit Someone Else's Album"), + QMessageBox::Ok); + return; + } +#endif + + OpenOrShowPhotoAddDialog(); + mAddDialog->loadAlbum(albumId); + +} + + +bool PhotoDialog::matchesAlbumFilter(const RsPhotoAlbum &album) +{ + + return true; +} + +double PhotoDialog::AlbumScore(const RsPhotoAlbum &album) +{ + return 1; +} + + +bool PhotoDialog::matchesPhotoFilter(const RsPhotoPhoto &photo) +{ + + return true; +} + +double PhotoDialog::PhotoScore(const RsPhotoPhoto &photo) +{ + return 1; +} + +void PhotoDialog::insertPhotosForSelectedAlbum() +{ + std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum()"; + std::cerr << std::endl; + + clearPhotos(); + + //std::list albumIds; + if (mAlbumSelected) + { + if (mAlbumSelected->mIsPhoto) + { + std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum() MAJOR ERROR!"; + std::cerr << std::endl; + } + + std::string albumId = mAlbumSelected->mAlbumDetails.mMeta.mGroupId; + //albumIds.push_back(albumId); + + std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum() AlbumId: " << albumId; + std::cerr << std::endl; + requestPhotoList(albumId); + } + //requestPhotoList(albumIds); +} + + +void PhotoDialog::clearAlbums() +{ + std::cerr << "PhotoDialog::clearAlbums()" << std::endl; + + std::list photoItems; + std::list::iterator pit; + + QLayout *alayout = ui.scrollAreaWidgetContents->layout(); + int count = alayout->count(); + for(int i = 0; i < count; i++) + { + QLayoutItem *litem = alayout->itemAt(i); + if (!litem) + { + std::cerr << "PhotoDialog::clearAlbums() missing litem"; + std::cerr << std::endl; + continue; + } + + PhotoItem *item = dynamic_cast(litem->widget()); + if (item) + { + std::cerr << "PhotoDialog::clearAlbums() item: " << item; + std::cerr << std::endl; + + photoItems.push_back(item); + } + else + { + std::cerr << "PhotoDialog::clearAlbums() Found Child, which is not a PhotoItem???"; + std::cerr << std::endl; + } + } + + for(pit = photoItems.begin(); pit != photoItems.end(); pit++) + { + PhotoItem *item = *pit; + alayout->removeWidget(item); + delete item; + } + mAlbumSelected = NULL; + +} + +void PhotoDialog::clearPhotos() +{ + std::cerr << "PhotoDialog::clearPhotos()" << std::endl; + + std::list photoItems; + std::list::iterator pit; + + QLayout *alayout = ui.scrollAreaWidgetContents_2->layout(); + int count = alayout->count(); + for(int i = 0; i < count; i++) + { + QLayoutItem *litem = alayout->itemAt(i); + if (!litem) + { + std::cerr << "PhotoDialog::clearPhotos() missing litem"; + std::cerr << std::endl; + continue; + } + + PhotoItem *item = dynamic_cast(litem->widget()); + if (item) + { + std::cerr << "PhotoDialog::clearPhotos() item: " << item; + std::cerr << std::endl; + + photoItems.push_back(item); + } + else + { + std::cerr << "PhotoDialog::clearPhotos() Found Child, which is not a PhotoItem???"; + std::cerr << std::endl; + } + } + + for(pit = photoItems.begin(); pit != photoItems.end(); pit++) + { + PhotoItem *item = *pit; + alayout->removeWidget(item); + delete item; + } + + mPhotoSelected = NULL; + + +} + +void PhotoDialog::addAlbum(const RsPhotoAlbum &album) +{ + std::cerr << " PhotoDialog::addAlbum() AlbumId: " << album.mMeta.mGroupId << std::endl; + + PhotoItem *item = new PhotoItem(this, album); + QLayout *alayout = ui.scrollAreaWidgetContents->layout(); + alayout->addWidget(item); +} + + +void PhotoDialog::addPhoto(const RsPhotoPhoto &photo) +{ + std::cerr << "PhotoDialog::addPhoto() AlbumId: " << photo.mMeta.mGroupId; + std::cerr << " PhotoId: " << photo.mMeta.mMsgId; + std::cerr << std::endl; + + RsPhotoAlbum dummyAlbum; + dummyAlbum.mSetFlags = 0; + + PhotoItem *item = new PhotoItem(this, photo, dummyAlbum); + QLayout *alayout = ui.scrollAreaWidgetContents_2->layout(); + alayout->addWidget(item); + +} + +void PhotoDialog::deletePhotoItem(PhotoItem *item, uint32_t type) +{ + + + return; +} + + +/**************************** Request / Response Filling of Data ************************/ + + +void PhotoDialog::requestAlbumList() +{ + + std::list ids; + RsTokReqOptions opts; + uint32_t token; + mPhotoQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_LIST, opts, ids, 0); +} + + +void PhotoDialog::loadAlbumList(const uint32_t &token) +{ + std::cerr << "PhotoDialog::loadAlbumList()"; + std::cerr << std::endl; + + std::list albumIds; + rsPhoto->getGroupList(token, albumIds); + + requestAlbumData(albumIds); + + clearPhotos(); + + std::list::iterator it; + for(it = albumIds.begin(); it != albumIds.end(); it++) + { + requestPhotoList(*it); + } + +} + + +void PhotoDialog::requestAlbumData(const std::list &ids) +{ + RsTokReqOptions opts; + uint32_t token; + mPhotoQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids, 0); +} + + +bool PhotoDialog::loadAlbumData(const uint32_t &token) +{ + std::cerr << "PhotoDialog::loadAlbumData()"; + std::cerr << std::endl; + + clearAlbums(); + + bool moreData = true; + while(moreData) + { + RsPhotoAlbum album; + if (rsPhoto->getAlbum(token, album)) + { + std::cerr << " PhotoDialog::addAlbum() AlbumId: " << album.mMeta.mGroupId << std::endl; + + PhotoItem *item = new PhotoItem(this, album); + QLayout *alayout = ui.scrollAreaWidgetContents->layout(); + alayout->addWidget(item); + } + else + { + moreData = false; + } + } + + return true; +} + + +void PhotoDialog::requestPhotoList(const std::string &albumId) +{ + + std::list ids; + ids.push_back(albumId); + RsTokReqOptions opts; + opts.mOptions = RS_TOKREQOPT_MSG_LATEST; + uint32_t token; + mPhotoQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_LIST, opts, ids, 0); +} + + + + +void PhotoDialog::loadPhotoList(const uint32_t &token) +{ + std::cerr << "PhotoDialog::loadPhotoList()"; + std::cerr << std::endl; + + + std::list photoIds; + + rsPhoto->getMsgList(token, photoIds); + requestPhotoData(photoIds); +} + + +void PhotoDialog::requestPhotoData(const std::list &photoIds) +{ + RsTokReqOptions opts; + uint32_t token; + mPhotoQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, photoIds, 0); +} + + +void PhotoDialog::loadPhotoData(const uint32_t &token) +{ + std::cerr << "PhotoDialog::loadPhotoData()"; + std::cerr << std::endl; + + bool moreData = true; + while(moreData) + { + RsPhotoPhoto photo; + + if (rsPhoto->getPhoto(token, photo)) + { + + std::cerr << "PhotoDialog::loadPhotoData() AlbumId: " << photo.mMeta.mGroupId; + std::cerr << " PhotoId: " << photo.mMeta.mMsgId; + std::cerr << std::endl; + + addPhoto(photo); + } + else + { + moreData = false; + } + } +} + + +/********************************/ + +void PhotoDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) +{ + std::cerr << "PhotoDialog::loadRequest()"; + std::cerr << std::endl; + + if (queue == mPhotoQueue) + { + /* now switch on req */ + switch(req.mType) + { + case TOKENREQ_GROUPINFO: + switch(req.mAnsType) + { + case RS_TOKREQ_ANSTYPE_LIST: + loadAlbumList(req.mToken); + break; + case RS_TOKREQ_ANSTYPE_DATA: + loadAlbumData(req.mToken); + break; + default: + std::cerr << "PhotoDialog::loadRequest() ERROR: GROUP: INVALID ANS TYPE"; + std::cerr << std::endl; + break; + } + break; + case TOKENREQ_MSGINFO: + switch(req.mAnsType) + { + case RS_TOKREQ_ANSTYPE_LIST: + loadPhotoList(req.mToken); + break; + //case RS_TOKREQ_ANSTYPE_DATA: + // loadPhotoData(req.mToken); + // break; + default: + std::cerr << "PhotoDialog::loadRequest() ERROR: MSG: INVALID ANS TYPE"; + std::cerr << std::endl; + break; + } + break; + case TOKENREQ_MSGRELATEDINFO: + switch(req.mAnsType) + { + case RS_TOKREQ_ANSTYPE_DATA: + loadPhotoData(req.mToken); + break; + default: + std::cerr << "PhotoDialog::loadRequest() ERROR: MSG: INVALID ANS TYPE"; + std::cerr << std::endl; + break; + } + break; + default: + std::cerr << "PhotoDialog::loadRequest() ERROR: INVALID TYPE"; + std::cerr << std::endl; + break; + } + } +} + + +#endif + diff --git a/retroshare-gui/src/gui/Posted/PostedComments.h b/retroshare-gui/src/gui/Posted/PostedComments.h new file mode 100644 index 000000000..78d52354d --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedComments.h @@ -0,0 +1,118 @@ +/* + * Retroshare Posted Comments + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_POSTED_COMMENTS_H +#define MRK_POSTED_COMMENTS_H + +//#include "gui/mainpage.h" +#include "ui_PostedComments.h" + +#include + +#include + +//#include "gui/Posted/PostedItem.h" +//#include "gui/PhotoShare/PhotoAddDialog.h" +//#include "gui/PhotoShare/PhotoSlideShow.h" +#include "util/TokenQueue.h" + +class PostedComments: public QWidget, public TokenResponse +{ + Q_OBJECT + +public: + PostedComments(QWidget *parent = 0); + +private: + void loadRequest(const TokenQueue *queue, const TokenRequest &req) { return; } + +#if 0 +virtual void deletePhotoItem(PhotoItem *, uint32_t type); +virtual void notifySelection(PhotoItem *item, int ptype); + + void notifyAlbumSelection(PhotoItem *item); + void notifyPhotoSelection(PhotoItem *item); + +private slots: + + void checkUpdate(); + void OpenOrShowPhotoAddDialog(); + void OpenPhotoEditDialog(); + void OpenSlideShow(); +private: + + /* Request Response Functions for loading data */ + void requestAlbumList(); + void requestAlbumData(const std::list &ids); + void requestPhotoList(const std::string &albumId); + void requestPhotoData(const std::list &photoIds); + + void loadAlbumList(const uint32_t &token); + bool loadAlbumData(const uint32_t &token); + void loadPhotoList(const uint32_t &token); + void loadPhotoData(const uint32_t &token); + + void loadRequest(const TokenQueue *queue, const TokenRequest &req); + + + /* TODO: These functions must be filled in for proper filtering to work + * and tied to the GUI input + */ + + bool matchesAlbumFilter(const RsPhotoAlbum &album); + double AlbumScore(const RsPhotoAlbum &album); + bool matchesPhotoFilter(const RsPhotoPhoto &photo); + double PhotoScore(const RsPhotoPhoto &photo); + + /* Grunt work of setting up the GUI */ + + //bool FilterNSortAlbums(const std::list &albumIds, std::list &filteredAlbumIds, int count); + //bool FilterNSortPhotos(const std::list &photoIds, std::list &filteredPhotoIds, int count); + //void insertAlbums(); + //void insertPhotosForAlbum(const std::list &albumIds); + + void insertPhotosForSelectedAlbum(); + + void addAlbum(const RsPhotoAlbum &album); + void addPhoto(const RsPhotoPhoto &photo); + + void clearAlbums(); + void clearPhotos(); + + PhotoAddDialog *mAddDialog; + PhotoSlideShow *mSlideShow; + + PhotoItem *mAlbumSelected; + PhotoItem *mPhotoSelected; + +#endif + + TokenQueue *mPhotoQueue; + + /* UI - from Designer */ + Ui::PostedComments ui; + +}; + +#endif + diff --git a/retroshare-gui/src/gui/Posted/PostedComments.ui b/retroshare-gui/src/gui/Posted/PostedComments.ui new file mode 100644 index 000000000..0b974c14f --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedComments.ui @@ -0,0 +1,169 @@ + + + PostedComments + + + + 0 + 0 + 632 + 398 + + + + Form + + + + + + + + Hot + + + + + + + New + + + + + + + Top + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Today + + + + + Yesterday + + + + + This Week + + + + + This Month + + + + + This Year + + + + + + + + + + + + + + Refresh + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Showing 1-100 + + + + + + + Prev + + + + + + + Next + + + + + + + + + true + + + + + 0 + 0 + 382 + 302 + + + + + + + + + + 0 + 0 + + + + + 1 + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/Posted/PostedDialog.cpp b/retroshare-gui/src/gui/Posted/PostedDialog.cpp new file mode 100644 index 000000000..5558e28d4 --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedDialog.cpp @@ -0,0 +1,670 @@ +/* + * Retroshare Posted List + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "PostedDialog.h" + +#include "PostedListDialog.h" +#include "PostedComments.h" + +#include + +#include +#include + +#include +#include + +/****** + * #define PHOTO_DEBUG 1 + *****/ + + +/**************************************************************** + * New Photo Display Widget. + * + * This has two 'lists'. + * Top list shows Albums. + * Lower list is photos from the selected Album. + * + * Notes: + * Each Item will be an AlbumItem, which contains a thumbnail & random details. + * We will limit Items to < 100. With a 'Filter to see more message. + * + * Thumbnails will come from Service. + * Option to Share albums / pictures onward (if permissions allow). + * Option to Download the albums to a specified directory. (is this required if sharing an album?) + * + * Will introduce a FullScreen SlideShow later... first get basics happening. + */ + +PostedDialog::PostedDialog(QWidget *parent) +: MainPage(parent) +{ + ui.setupUi(this); + + mPostedList = new PostedListDialog(NULL); + mPostedComments = new PostedComments(NULL); + + ui.tabWidget->addTab(mPostedList, QString("List")); + ui.tabWidget->addTab(mPostedComments, QString("Comments")); + +} + + +#if 0 + + + + +/** Constructor */ +PhotoDialog::PhotoDialog(QWidget *parent) +: MainPage(parent) +{ + ui.setupUi(this); + + mAddDialog = NULL; + mAlbumSelected = NULL; + mPhotoSelected = NULL; + mSlideShow = NULL; + + connect( ui.toolButton_NewAlbum, SIGNAL(clicked()), this, SLOT(OpenOrShowPhotoAddDialog())); + connect( ui.toolButton_EditAlbum, SIGNAL(clicked()), this, SLOT(OpenPhotoEditDialog())); + connect( ui.toolButton_SlideShow, SIGNAL(clicked()), this, SLOT(OpenSlideShow())); + + QTimer *timer = new QTimer(this); + timer->connect(timer, SIGNAL(timeout()), this, SLOT(checkUpdate())); + timer->start(1000); + + + /* setup TokenQueue */ + mPhotoQueue = new TokenQueue(rsPhoto, this); + +} + + +void PhotoDialog::notifySelection(PhotoItem *item, int ptype) +{ + std::cerr << "PhotoDialog::notifySelection() from : " << ptype << " " << item; + std::cerr << std::endl; + + switch(ptype) + { + default: + case PHOTO_ITEM_TYPE_ALBUM: + notifyAlbumSelection(item); + break; + case PHOTO_ITEM_TYPE_PHOTO: + notifyPhotoSelection(item); + break; + } +} + +void PhotoDialog::notifyAlbumSelection(PhotoItem *item) +{ + std::cerr << "PhotoDialog::notifyAlbumSelection() from : " << item; + std::cerr << std::endl; + + if (mAlbumSelected) + { + std::cerr << "PhotoDialog::notifyAlbumSelection() unselecting old one : " << mAlbumSelected; + std::cerr << std::endl; + + mAlbumSelected->setSelected(false); + } + + mAlbumSelected = item; + insertPhotosForSelectedAlbum(); +} + + +void PhotoDialog::notifyPhotoSelection(PhotoItem *item) +{ + std::cerr << "PhotoDialog::notifyPhotoSelection() from : " << item; + std::cerr << std::endl; + + if (mPhotoSelected) + { + std::cerr << "PhotoDialog::notifyPhotoSelection() unselecting old one : " << mPhotoSelected; + std::cerr << std::endl; + + mPhotoSelected->setSelected(false); + } + + mPhotoSelected = item; +} + + +void PhotoDialog::checkUpdate() +{ + /* update */ + if (!rsPhoto) + return; + + if (rsPhoto->updated()) + { + //insertAlbums(); + requestAlbumList(); + } + + return; +} + + +/*************** New Photo Dialog ***************/ + +void PhotoDialog::OpenSlideShow() +{ + + // TODO. + if (!mAlbumSelected) + { + // ALERT. + int ret = QMessageBox::information(this, tr("PhotoShare"), + tr("Please select an album before\n" + "requesting to edit it!"), + QMessageBox::Ok); + return; + } + + if (mAlbumSelected->mIsPhoto) + { + std::cerr << "PhotoDialog::OpenPhotoEditDialog() MAJOR ERROR!"; + std::cerr << std::endl; + return; + } + + std::string albumId = mAlbumSelected->mAlbumDetails.mMeta.mGroupId; + + if (mSlideShow) + { + mSlideShow->show(); + } + else + { + mSlideShow = new PhotoSlideShow(NULL); + mSlideShow->show(); + } + mSlideShow->loadAlbum(albumId); + +} + + +/*************** New Photo Dialog ***************/ + +void PhotoDialog::OpenOrShowPhotoAddDialog() +{ + if (mAddDialog) + { + mAddDialog->show(); + } + else + { + mAddDialog = new PhotoAddDialog(NULL); + mAddDialog->show(); + } + mAddDialog->clearDialog(); +} + + +/*************** Edit Photo Dialog ***************/ + +void PhotoDialog::OpenPhotoEditDialog() +{ + /* check if we have an album selected */ + // THE TWO MessageBoxes - should be handled by disabling the Button!. + // TODO. + if (!mAlbumSelected) + { + // ALERT. + int ret = QMessageBox::information(this, tr("PhotoShare"), + tr("Please select an album before\n" + "requesting to edit it!"), + QMessageBox::Ok); + return; + } + + if (mAlbumSelected->mIsPhoto) + { + std::cerr << "PhotoDialog::OpenPhotoEditDialog() MAJOR ERROR!"; + std::cerr << std::endl; + } + + std::string albumId = mAlbumSelected->mAlbumDetails.mMeta.mGroupId; +#if 0 + uint32_t flags = mAlbumSelected->mAlbumDetails.mMeta.mGroupFlags; + + if (!(flags & OWN)) + { + // ALERT. + int ret = QMessageBox::information(this, tr("PhotoShare"), + tr("Cannot Edit Someone Else's Album"), + QMessageBox::Ok); + return; + } +#endif + + OpenOrShowPhotoAddDialog(); + mAddDialog->loadAlbum(albumId); + +} + + +bool PhotoDialog::matchesAlbumFilter(const RsPhotoAlbum &album) +{ + + return true; +} + +double PhotoDialog::AlbumScore(const RsPhotoAlbum &album) +{ + return 1; +} + + +bool PhotoDialog::matchesPhotoFilter(const RsPhotoPhoto &photo) +{ + + return true; +} + +double PhotoDialog::PhotoScore(const RsPhotoPhoto &photo) +{ + return 1; +} + +void PhotoDialog::insertPhotosForSelectedAlbum() +{ + std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum()"; + std::cerr << std::endl; + + clearPhotos(); + + //std::list albumIds; + if (mAlbumSelected) + { + if (mAlbumSelected->mIsPhoto) + { + std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum() MAJOR ERROR!"; + std::cerr << std::endl; + } + + std::string albumId = mAlbumSelected->mAlbumDetails.mMeta.mGroupId; + //albumIds.push_back(albumId); + + std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum() AlbumId: " << albumId; + std::cerr << std::endl; + requestPhotoList(albumId); + } + //requestPhotoList(albumIds); +} + + +void PhotoDialog::clearAlbums() +{ + std::cerr << "PhotoDialog::clearAlbums()" << std::endl; + + std::list photoItems; + std::list::iterator pit; + + QLayout *alayout = ui.scrollAreaWidgetContents->layout(); + int count = alayout->count(); + for(int i = 0; i < count; i++) + { + QLayoutItem *litem = alayout->itemAt(i); + if (!litem) + { + std::cerr << "PhotoDialog::clearAlbums() missing litem"; + std::cerr << std::endl; + continue; + } + + PhotoItem *item = dynamic_cast(litem->widget()); + if (item) + { + std::cerr << "PhotoDialog::clearAlbums() item: " << item; + std::cerr << std::endl; + + photoItems.push_back(item); + } + else + { + std::cerr << "PhotoDialog::clearAlbums() Found Child, which is not a PhotoItem???"; + std::cerr << std::endl; + } + } + + for(pit = photoItems.begin(); pit != photoItems.end(); pit++) + { + PhotoItem *item = *pit; + alayout->removeWidget(item); + delete item; + } + mAlbumSelected = NULL; + +} + +void PhotoDialog::clearPhotos() +{ + std::cerr << "PhotoDialog::clearPhotos()" << std::endl; + + std::list photoItems; + std::list::iterator pit; + + QLayout *alayout = ui.scrollAreaWidgetContents_2->layout(); + int count = alayout->count(); + for(int i = 0; i < count; i++) + { + QLayoutItem *litem = alayout->itemAt(i); + if (!litem) + { + std::cerr << "PhotoDialog::clearPhotos() missing litem"; + std::cerr << std::endl; + continue; + } + + PhotoItem *item = dynamic_cast(litem->widget()); + if (item) + { + std::cerr << "PhotoDialog::clearPhotos() item: " << item; + std::cerr << std::endl; + + photoItems.push_back(item); + } + else + { + std::cerr << "PhotoDialog::clearPhotos() Found Child, which is not a PhotoItem???"; + std::cerr << std::endl; + } + } + + for(pit = photoItems.begin(); pit != photoItems.end(); pit++) + { + PhotoItem *item = *pit; + alayout->removeWidget(item); + delete item; + } + + mPhotoSelected = NULL; + + +} + +void PhotoDialog::addAlbum(const RsPhotoAlbum &album) +{ + std::cerr << " PhotoDialog::addAlbum() AlbumId: " << album.mMeta.mGroupId << std::endl; + + PhotoItem *item = new PhotoItem(this, album); + QLayout *alayout = ui.scrollAreaWidgetContents->layout(); + alayout->addWidget(item); +} + + +void PhotoDialog::addPhoto(const RsPhotoPhoto &photo) +{ + std::cerr << "PhotoDialog::addPhoto() AlbumId: " << photo.mMeta.mGroupId; + std::cerr << " PhotoId: " << photo.mMeta.mMsgId; + std::cerr << std::endl; + + RsPhotoAlbum dummyAlbum; + dummyAlbum.mSetFlags = 0; + + PhotoItem *item = new PhotoItem(this, photo, dummyAlbum); + QLayout *alayout = ui.scrollAreaWidgetContents_2->layout(); + alayout->addWidget(item); + +} + +void PhotoDialog::deletePhotoItem(PhotoItem *item, uint32_t type) +{ + + + return; +} + + +/**************************** Request / Response Filling of Data ************************/ + + +void PhotoDialog::requestAlbumList() +{ + + std::list ids; + RsTokReqOptions opts; + uint32_t token; + mPhotoQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_LIST, opts, ids, 0); +} + + +void PhotoDialog::loadAlbumList(const uint32_t &token) +{ + std::cerr << "PhotoDialog::loadAlbumList()"; + std::cerr << std::endl; + + std::list albumIds; + rsPhoto->getGroupList(token, albumIds); + + requestAlbumData(albumIds); + + clearPhotos(); + + std::list::iterator it; + for(it = albumIds.begin(); it != albumIds.end(); it++) + { + requestPhotoList(*it); + } + +} + + +void PhotoDialog::requestAlbumData(const std::list &ids) +{ + RsTokReqOptions opts; + uint32_t token; + mPhotoQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids, 0); +} + + +bool PhotoDialog::loadAlbumData(const uint32_t &token) +{ + std::cerr << "PhotoDialog::loadAlbumData()"; + std::cerr << std::endl; + + clearAlbums(); + + bool moreData = true; + while(moreData) + { + RsPhotoAlbum album; + if (rsPhoto->getAlbum(token, album)) + { + std::cerr << " PhotoDialog::addAlbum() AlbumId: " << album.mMeta.mGroupId << std::endl; + + PhotoItem *item = new PhotoItem(this, album); + QLayout *alayout = ui.scrollAreaWidgetContents->layout(); + alayout->addWidget(item); + } + else + { + moreData = false; + } + } + + return true; +} + + +void PhotoDialog::requestPhotoList(const std::string &albumId) +{ + + std::list ids; + ids.push_back(albumId); + RsTokReqOptions opts; + opts.mOptions = RS_TOKREQOPT_MSG_LATEST; + uint32_t token; + mPhotoQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_LIST, opts, ids, 0); +} + + + + +void PhotoDialog::loadPhotoList(const uint32_t &token) +{ + std::cerr << "PhotoDialog::loadPhotoList()"; + std::cerr << std::endl; + + + std::list photoIds; + + rsPhoto->getMsgList(token, photoIds); + requestPhotoData(photoIds); +} + + +void PhotoDialog::requestPhotoData(const std::list &photoIds) +{ + RsTokReqOptions opts; + uint32_t token; + mPhotoQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, photoIds, 0); +} + + +void PhotoDialog::loadPhotoData(const uint32_t &token) +{ + std::cerr << "PhotoDialog::loadPhotoData()"; + std::cerr << std::endl; + + bool moreData = true; + while(moreData) + { + RsPhotoPhoto photo; + + if (rsPhoto->getPhoto(token, photo)) + { + + std::cerr << "PhotoDialog::loadPhotoData() AlbumId: " << photo.mMeta.mGroupId; + std::cerr << " PhotoId: " << photo.mMeta.mMsgId; + std::cerr << std::endl; + + addPhoto(photo); + } + else + { + moreData = false; + } + } +} + + +/********************************/ + +void PhotoDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) +{ + std::cerr << "PhotoDialog::loadRequest()"; + std::cerr << std::endl; + + if (queue == mPhotoQueue) + { + /* now switch on req */ + switch(req.mType) + { + case TOKENREQ_GROUPINFO: + switch(req.mAnsType) + { + case RS_TOKREQ_ANSTYPE_LIST: + loadAlbumList(req.mToken); + break; + case RS_TOKREQ_ANSTYPE_DATA: + loadAlbumData(req.mToken); + break; + default: + std::cerr << "PhotoDialog::loadRequest() ERROR: GROUP: INVALID ANS TYPE"; + std::cerr << std::endl; + break; + } + break; + case TOKENREQ_MSGINFO: + switch(req.mAnsType) + { + case RS_TOKREQ_ANSTYPE_LIST: + loadPhotoList(req.mToken); + break; + //case RS_TOKREQ_ANSTYPE_DATA: + // loadPhotoData(req.mToken); + // break; + default: + std::cerr << "PhotoDialog::loadRequest() ERROR: MSG: INVALID ANS TYPE"; + std::cerr << std::endl; + break; + } + break; + case TOKENREQ_MSGRELATEDINFO: + switch(req.mAnsType) + { + case RS_TOKREQ_ANSTYPE_DATA: + loadPhotoData(req.mToken); + break; + default: + std::cerr << "PhotoDialog::loadRequest() ERROR: MSG: INVALID ANS TYPE"; + std::cerr << std::endl; + break; + } + break; + default: + std::cerr << "PhotoDialog::loadRequest() ERROR: INVALID TYPE"; + std::cerr << std::endl; + break; + } + } +} + + +/**************************** Request / Response Filling of Data ************************/ + + +#endif + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/Posted/PostedDialog.h b/retroshare-gui/src/gui/Posted/PostedDialog.h new file mode 100644 index 000000000..acb0b7600 --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedDialog.h @@ -0,0 +1,68 @@ +/* + * Retroshare Posted Dialog + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_POSTED_DIALOG_H +#define MRK_POSTED_DIALOG_H + +#include "gui/mainpage.h" +#include "ui_PostedDialog.h" + +#include + +#include + +//#include "gui/Posted/PostedList.h" +//#include "gui/Posted/PostedComments.h" + +//#include "gui/PhotoShare/PhotoAddDialog.h" +//#include "gui/PhotoShare/PhotoSlideShow.h" +//#include "util/TokenQueue.h" + +class PostedListDialog; +class PostedComments; + +class PostedDialog : public MainPage +{ + Q_OBJECT + +public: + PostedDialog(QWidget *parent = 0); + +//virtual void addTab(std::string item); + +private slots: + + //void OpenSlideShow(); + +private: + + PostedListDialog *mPostedList; + PostedComments *mPostedComments; + + /* UI - from Designer */ + Ui::PostedDialog ui; + +}; + +#endif + diff --git a/retroshare-gui/src/gui/Posted/PostedDialog.ui b/retroshare-gui/src/gui/Posted/PostedDialog.ui new file mode 100644 index 000000000..bf21aa5f6 --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedDialog.ui @@ -0,0 +1,33 @@ + + + PostedDialog + + + + 0 + 0 + 726 + 557 + + + + + + + + + + -1 + + + true + + + + + + + + + + diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp new file mode 100644 index 000000000..640724953 --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -0,0 +1,299 @@ +/* + * Retroshare Posted Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + + +#include +#include +#include +#include + +#include "PostedItem.h" + +#include + +#include +#include + +/**** + * #define DEBUG_ITEM 1 + ****/ + +/** Constructor */ +PostedItem::PostedItem(PostedHolder *parent, const RsPostedPost &post) +:QWidget(NULL) +{ + setupUi(this); + setAttribute ( Qt::WA_DeleteOnClose, true ); + + titleLabel->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str())); + dateLabel->setText(QString("Whenever")); + fromLabel->setText(QString::fromUtf8(post.mMeta.mAuthorId.c_str())); + siteLabel->setText(QString::fromUtf8(post.mMeta.mAuthorId.c_str())); + scoreLabel->setText(QString("1140")); + + return; +} + + +#if 0 + +PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoAlbum &album) +:QWidget(NULL), mParent(parent), mType(PHOTO_ITEM_TYPE_ALBUM) +{ + setupUi(this); + setAttribute ( Qt::WA_DeleteOnClose, true ); + + mIsPhoto = false; + setDummyText(); + updateAlbumText(album); // saves: mAlbumDetails = album; + updateImage(album.mThumbnail); + + setSelected(false); +} + + +PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoPhoto &photo, const RsPhotoAlbum &album) +:QWidget(NULL), mParent(parent), mType(PHOTO_ITEM_TYPE_PHOTO) +{ + setupUi(this); + + setAttribute ( Qt::WA_DeleteOnClose, true ); + + mIsPhoto = true; + + setDummyText(); + updatePhotoText(photo); // saves: mPhotoDetails = photo; + updateAlbumText(album); // saves: mAlbumDetails = album; + + updateImage(photo.mThumbnail); + + setSelected(false); +} + + +PhotoItem::PhotoItem(PhotoHolder *parent, std::string path) // for new photos. +:QWidget(NULL), mParent(parent), mType(PHOTO_ITEM_TYPE_NEW) +{ + setupUi(this); + + setAttribute ( Qt::WA_DeleteOnClose, true ); + + setDummyText(); + mIsPhoto = true; + + int width = 120; + int height = 120; + + //QPixmap qtn = QPixmap(QString::fromStdString(path)).scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + QPixmap qtn = QPixmap(QString::fromStdString(path)).scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); + imgLabel->setPixmap(qtn); + setSelected(false); +} + +void PhotoItem::updateParent(PhotoHolder *parent) // for external construction. +{ + mParent = parent; +} + + +void PhotoItem::setDummyText() +{ + titleLabel->setText(QString("Unknown")); + fromBoldLabel->setText(QString("By:")); + fromLabel->setText(QString("Unknown")); + statusBoldLabel->setText(QString("Where:")); + statusLabel->setText(QString("Unknown")); + dateBoldLabel->setText(QString("When:")); + dateLabel->setText(QString("Unknown")); +} + + +void PhotoItem::updateAlbumText(const RsPhotoAlbum &album) +{ + mAlbumDetails = album; + mAlbumDetails.mThumbnail.data = 0; + updateText(); +} + +void PhotoItem::updatePhotoText(const RsPhotoPhoto &photo) +{ + // Save new Photo details. + mPhotoDetails = photo; + mPhotoDetails.mThumbnail.data = 0; + updateText(); +} + + + +void PhotoItem::updateText() +{ + // SET Album Values first -> then overwrite with Photo Values. + if (mAlbumDetails.mSetFlags & RSPHOTO_FLAGS_ATTRIB_TITLE) + { + titleLabel->setText(QString::fromUtf8(mAlbumDetails.mMeta.mGroupName.c_str())); + } + + // This needs to be fixed!! TODO + fromLabel->setText(QString::fromStdString(mAlbumDetails.mMeta.mGroupId)); + if (mAlbumDetails.mSetFlags & RSPHOTO_FLAGS_ATTRIB_AUTHOR) + { + // This needs to be fixed!! TODO + fromLabel->setText(QString::fromStdString(mAlbumDetails.mMeta.mGroupId)); + } + + if (mAlbumDetails.mSetFlags & RSPHOTO_FLAGS_ATTRIB_WHERE) + { + statusLabel->setText(QString::fromUtf8(mAlbumDetails.mWhere.c_str())); + } + + if (mAlbumDetails.mSetFlags & RSPHOTO_FLAGS_ATTRIB_WHEN) + { + dateLabel->setText(QString::fromUtf8(mAlbumDetails.mWhen.c_str())); + } + + // NOW Photo Bits. + if (mIsPhoto) + { + if (mPhotoDetails.mSetFlags & RSPHOTO_FLAGS_ATTRIB_TITLE) + { + titleLabel->setText(QString::fromUtf8(mPhotoDetails.mMeta.mMsgName.c_str())); + } + + if (mPhotoDetails.mSetFlags & RSPHOTO_FLAGS_ATTRIB_AUTHOR) + { + // This needs to be fixed!! TODO + fromLabel->setText(QString::fromStdString(mPhotoDetails.mMeta.mAuthorId)); + } + + if (mPhotoDetails.mSetFlags & RSPHOTO_FLAGS_ATTRIB_WHERE) + { + statusLabel->setText(QString::fromUtf8(mPhotoDetails.mWhere.c_str())); + } + + if (mPhotoDetails.mSetFlags & RSPHOTO_FLAGS_ATTRIB_WHEN) + { + dateLabel->setText(QString::fromUtf8(mPhotoDetails.mWhen.c_str())); + } + } + +} + +void PhotoItem::updateImage(const RsPhotoThumbnail &thumbnail) +{ + if (thumbnail.data != NULL) + { + QPixmap qtn; + qtn.loadFromData(thumbnail.data, thumbnail.size, thumbnail.type.c_str()); + imgLabel->setPixmap(qtn); + } +} + +bool PhotoItem::getPhotoThumbnail(RsPhotoThumbnail &nail) +{ + const QPixmap *tmppix = imgLabel->pixmap(); + + QByteArray ba; + QBuffer buffer(&ba); + + if(!tmppix->isNull()) + { + // send chan image + + buffer.open(QIODevice::WriteOnly); + tmppix->save(&buffer, "PNG"); // writes image into ba in PNG format + + RsPhotoThumbnail tmpnail; + tmpnail.data = (uint8_t *) ba.data(); + tmpnail.size = ba.size(); + + nail.copyFrom(tmpnail); + + return true; + } + + nail.data = NULL; + nail.size = 0; + return false; +} + + +void PhotoItem::removeItem() +{ +#ifdef DEBUG_ITEM + std::cerr << "PhotoItem::removeItem()"; + std::cerr << std::endl; +#endif + hide(); + if (mParent) + { + mParent->deletePhotoItem(this, mType); + } +} + + +void PhotoItem::setSelected(bool on) +{ + mSelected = on; + if (mSelected) + { + mParent->notifySelection(this, mType); + frame->setStyleSheet("QFrame#frame{border: 2px solid #55CC55;\nbackground: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #55EE55, stop: 1 #CCCCCC);\nborder-radius: 10px}"); + } + else + { + frame->setStyleSheet("QFrame#frame{border: 2px solid #CCCCCC;\nbackground: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #EEEEEE, stop: 1 #CCCCCC);\nborder-radius: 10px}"); + } + update(); +} + +bool PhotoItem::isSelected() +{ + return mSelected; +} + + +void PhotoItem::mousePressEvent(QMouseEvent *event) +{ + /* We can be very cunning here? + * grab out position. + * flag ourselves as selected. + * then pass the mousePressEvent up for handling by the parent + */ + + QPoint pos = event->pos(); + + std::cerr << "PhotoItem::mousePressEvent(" << pos.x() << ", " << pos.y() << ")"; + std::cerr << std::endl; + + setSelected(true); + + QWidget::mousePressEvent(event); +} + + +const QPixmap *PhotoItem::getPixmap() +{ + return imgLabel->pixmap(); +} + +#endif diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h new file mode 100644 index 000000000..c0d830811 --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -0,0 +1,65 @@ +/* + * Retroshare Posted Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_POSTED_POSTED_ITEM_H +#define MRK_POSTED_POSTED_ITEM_H + +#include "ui_PostedItem.h" + +#include + +class RsPostedPost; +class PostedItem; + +class PostedHolder +{ + public: +virtual void deletePostedItem(PostedItem *, uint32_t ptype) = 0; +virtual void notifySelection(PostedItem *item, int ptype) = 0; +}; + +class PostedItem : public QWidget, private Ui::PostedItem +{ + Q_OBJECT + +public: + PostedItem(PostedHolder *parent, const RsPostedPost &item); + + //void setDummyText(); + //void updateParent(PhotoHolder *parent); // for external construction. + //void removeItem(); + + //void setSelected(bool on); + //bool isSelected(); + +protected: + //void mousePressEvent(QMouseEvent *event); + +private: + uint32_t mType; + bool mSelected; +}; + + +#endif + diff --git a/retroshare-gui/src/gui/Posted/PostedItem.ui b/retroshare-gui/src/gui/Posted/PostedItem.ui new file mode 100644 index 000000000..ad1501e08 --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedItem.ui @@ -0,0 +1,285 @@ + + + PostedItem + + + + 0 + 0 + 638 + 177 + + + + + 9 + + + + + + + + 6 + + + + + + 0 + 0 + + + + QFrame#frame{border: 2px solid #CCCCCC; +background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, + stop: 0 #EEEEEE, stop: 1 #CCCCCC); +border-radius: 10px} + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 20 + + + + 1 + + + + + + + + + /\ + + + + + + + score + + + + + + + \/ + + + + + + + + + + 0 + 0 + + + + + 12 + 75 + true + + + + Title this is a very very very very loooooooooooooooonnnnnnnnnnnnnnnnng title dont you think? yes it is and should wrap around I hope + + + true + + + true + + + + + + + + + + + + + + 0 + 0 + + + + + 9 + 75 + true + + + + Date + + + + + + + + 0 + 0 + + + + + 9 + + + + You eyes only + + + true + + + + + + + + + + + + 0 + 0 + + + + + 9 + 75 + true + + + + From + + + + + + + + 0 + 0 + + + + + 9 + + + + Signed by + + + true + + + + + + + + + + + + 0 + 0 + + + + + 9 + 75 + true + + + + Site + + + + + + + + 0 + 0 + + + + + 9 + + + + Signed by + + + true + + + + + + + + + + + + + Qt::Horizontal + + + + 288 + 20 + + + + + + + + View Comments + + + + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/Posted/PostedListDialog.cpp b/retroshare-gui/src/gui/Posted/PostedListDialog.cpp new file mode 100644 index 000000000..698162640 --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedListDialog.cpp @@ -0,0 +1,511 @@ +/* + * Retroshare Posted List + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "PostedListDialog.h" + +//#include +#include + +#include +#include +#include + +#include +#include +#include + +/**************************************************************** + */ + +//#define DEBUG_FORUMS + +/* Images for context menu icons */ +#define IMAGE_MESSAGE ":/images/folder-draft.png" +#define IMAGE_MESSAGEREPLY ":/images/mail_reply.png" +#define IMAGE_MESSAGEREMOVE ":/images/mail_delete.png" +#define IMAGE_DOWNLOAD ":/images/start.png" +#define IMAGE_DOWNLOADALL ":/images/startall.png" + +/* 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/konversation16.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" + +/** Constructor */ +PostedListDialog::PostedListDialog(QWidget *parent) +: RsAutoUpdatePage(1000,parent) +{ + /* Invoke the Qt Designer generated object setup routine */ + ui.setupUi(this); + + /* Setup Queue */ + mPostedQueue = new TokenQueue(rsPosted, this); + + connect( ui.groupTreeWidget, SIGNAL( treeCustomContextMenuRequested( QPoint ) ), this, SLOT( groupListCustomPopupMenu( QPoint ) ) ); + + connect( ui.groupTreeWidget, SIGNAL( treeCurrentItemChanged(QString) ), this, SLOT( changedTopic(QString) ) ); + + /* Initialize group tree */ + //ui.groupTreeWidget->initDisplayMenu(ui.displayButton); + + /* create forum tree */ + yourTopics = ui.groupTreeWidget->addCategoryItem(tr("Your Topics"), QIcon(IMAGE_FOLDER), true); + subscribedTopics = ui.groupTreeWidget->addCategoryItem(tr("Subscribed Topics"), QIcon(IMAGE_FOLDERRED), true); + popularTopics = ui.groupTreeWidget->addCategoryItem(tr("Popular Topics"), QIcon(IMAGE_FOLDERGREEN), false); + otherTopics = ui.groupTreeWidget->addCategoryItem(tr("Other Topics"), QIcon(IMAGE_FOLDERYELLOW), false); + + /* Hide platform specific features */ +#ifdef Q_WS_WIN + +#endif +} + + +void PostedListDialog::groupListCustomPopupMenu( QPoint /*point*/ ) +{ + QMenu contextMnu( this ); + + QAction *action = contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Subscribe to Forum"), this, SLOT(subscribeToForum())); + //action->setDisabled (mCurrTopicId.empty() || IS_FORUM_SUBSCRIBED(subscribeFlags)); + + action = contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Unsubscribe to Forum"), this, SLOT(unsubscribeToForum())); + //action->setEnabled (!mCurrTopicId.empty() && IS_FORUM_SUBSCRIBED(subscribeFlags)); + + contextMnu.addSeparator(); + + contextMnu.addAction(QIcon(IMAGE_NEWFORUM), tr("New Forum"), this, SLOT(newforum())); + + action = contextMnu.addAction(QIcon(IMAGE_INFO), tr("Show Forum Details"), this, SLOT(showForumDetails())); + action->setEnabled (!mCurrTopicId.empty ()); + + action = contextMnu.addAction(QIcon(":/images/settings16.png"), tr("Edit Forum Details"), this, SLOT(editForumDetails())); + //action->setEnabled (!mCurrTopicId.empty () && IS_FORUM_ADMIN(subscribeFlags)); + + QAction *shareKeyAct = new QAction(QIcon(":/images/gpgp_key_generate.png"), tr("Share Forum"), &contextMnu); + connect( shareKeyAct, SIGNAL( triggered() ), this, SLOT( shareKey() ) ); + //shareKeyAct->setEnabled(!mCurrTopicId.empty() && IS_FORUM_ADMIN(subscribeFlags)); + contextMnu.addAction( shareKeyAct); + + QAction *restoreKeysAct = new QAction(QIcon(":/images/settings16.png"), tr("Restore Publish Rights for Forum" ), &contextMnu); + connect( restoreKeysAct , SIGNAL( triggered() ), this, SLOT( restoreForumKeys() ) ); + //restoreKeysAct->setEnabled(!mCurrTopicId.empty() && !IS_FORUM_ADMIN(subscribeFlags)); + contextMnu.addAction( restoreKeysAct); + + action = contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyForumLink())); + action->setEnabled(!mCurrTopicId.empty()); + + contextMnu.addSeparator(); + + action = contextMnu.addAction(QIcon(":/images/message-mail-read.png"), tr("Mark all as read"), this, SLOT(markMsgAsReadAll())); + //action->setEnabled (!mCurrTopicId.empty () && IS_FORUM_SUBSCRIBED(subscribeFlags)); + + action = contextMnu.addAction(QIcon(":/images/message-mail.png"), tr("Mark all as unread"), this, SLOT(markMsgAsUnreadAll())); + //action->setEnabled (!mCurrTopicId.empty () && IS_FORUM_SUBSCRIBED(subscribeFlags)); + +#ifdef DEBUG_FORUMS + contextMnu.addSeparator(); + action = contextMnu.addAction("Generate mass data", this, SLOT(generateMassData())); + action->setEnabled (!mCurrTopicId.empty() && IS_FORUM_SUBSCRIBED(subscribeFlags)); +#endif + + contextMnu.exec(QCursor::pos()); +} + +void PostedListDialog::updateDisplay() +{ + std::list groupIds; + std::list::iterator it; + if (!rsPosted) + return; + + // TODO groupsChanged... HACK XXX. + if ((rsPosted->groupsChanged(groupIds)) || (rsPosted->updated())) + { + /* update Forums List */ + insertGroups(); + + it = std::find(groupIds.begin(), groupIds.end(), mCurrTopicId); + if (it != groupIds.end()) + { + /* update threads as well */ + insertThreads(); + } + } +} + +void PostedListDialog::changedTopic(const QString &id) +{ + mCurrTopicId = id.toStdString(); + insertThreads(); +} + + +/*********************** **** **** **** ***********************/ +/** Request / Response of Data ********************************/ +/*********************** **** **** **** ***********************/ + +#define POSTEDDIALOG_LISTING 1 +#define POSTEDDIALOG_CURRENTFORUM 2 +#define POSTEDDIALOG_INSERTTHREADS 3 +#define POSTEDDIALOG_INSERTCHILD 4 +#define POSTEDDIALOG_INSERT_POST 5 +#define POSTEDDIALOG_REPLY_MESSAGE 6 + + +void PostedListDialog::insertGroups() +{ + requestGroupSummary(); +} + +void PostedListDialog::requestGroupSummary() +{ + std::cerr << "PostedListDialog::requestGroupSummary()"; + std::cerr << std::endl; + + std::list ids; + RsTokReqOptions opts; + uint32_t token; + mPostedQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, ids, POSTEDDIALOG_LISTING); +} + +void PostedListDialog::loadGroupSummary(const uint32_t &token) +{ + std::cerr << "PostedListDialog::loadGroupSummary()"; + std::cerr << std::endl; + + std::list groupInfo; + rsPosted->getGroupSummary(token, groupInfo); + + if (groupInfo.size() > 0) + { + insertGroupData(groupInfo); + } + else + { + std::cerr << "PostedListDialog::loadGroupSummary() ERROR No Groups..."; + std::cerr << std::endl; + } +} + +/*********************** **** **** **** ***********************/ +/*********************** **** **** **** ***********************/ + + + +void PostedListDialog::requestGroupSummary_CurrentForum(const std::string &forumId) +{ + RsTokReqOptions opts; + + std::list grpIds; + grpIds.push_back(forumId); + + std::cerr << "PostedListDialog::requestGroupSummary_CurrentForum(" << forumId << ")"; + std::cerr << std::endl; + + uint32_t token; + mPostedQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, POSTEDDIALOG_CURRENTFORUM); +} + +void PostedListDialog::loadGroupSummary_CurrentForum(const uint32_t &token) +{ + std::cerr << "PostedListDialog::loadGroupSummary_CurrentForum()"; + std::cerr << std::endl; + + std::list groupInfo; + rsPosted->getGroupSummary(token, groupInfo); + + if (groupInfo.size() == 1) + { + RsGroupMetaData fi = groupInfo.front(); + //insertForumThreads(fi); + } + else + { + std::cerr << "PostedListDialog::loadGroupSummary_CurrentForum() ERROR Invalid Number of Groups..."; + std::cerr << std::endl; + } +} + +/*********************** **** **** **** ***********************/ +/*********************** **** **** **** ***********************/ +/*********************** **** **** **** ***********************/ +/*********************** **** **** **** ***********************/ + + +void PostedListDialog::insertThreads() +{ + loadCurrentForumThreads(mCurrTopicId); +} + +void PostedListDialog::loadCurrentForumThreads(const std::string &forumId) +{ + + std::cerr << "PostedListDialog::loadCurrentForumThreads(" << forumId << ")"; + std::cerr << std::endl; + + /* if already active -> kill current loading */ + if (mThreadLoading) + { + /* Cleanup */ + } + + clearPosts(); + + /* initiate loading */ + std::cerr << "PostedListDialog::loadCurrentForumThreads() Initiating Loading"; + std::cerr << std::endl; + + mThreadLoading = true; + + requestGroupThreadData_InsertThreads(forumId); +} + + + +void PostedListDialog::requestGroupThreadData_InsertThreads(const std::string &forumId) +{ + RsTokReqOptions opts; + + opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST; + + std::list grpIds; + grpIds.push_back(forumId); + + std::cerr << "PostedListDialog::requestGroupThreadData_InsertThreads(" << forumId << ")"; + std::cerr << std::endl; + + uint32_t token; + mPostedQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grpIds, POSTEDDIALOG_INSERTTHREADS); +} + + +void PostedListDialog::loadGroupThreadData_InsertThreads(const uint32_t &token) +{ + std::cerr << "PostedListDialog::loadGroupThreadData_InsertThreads()"; + std::cerr << std::endl; + + bool moreData = true; + while(moreData) + { + RsPostedPost post; + if (rsPosted->getPost(token, post)) + { + std::cerr << "PostedListDialog::loadGroupThreadData_InsertThreads() MsgId: " << post.mMeta.mMsgId; + std::cerr << std::endl; + + loadPost(post); + } + else + { + moreData = false; + } + } + + mThreadLoading = false; + +} + +void PostedListDialog::loadPost(const RsPostedPost &post) +{ + PostedItem *item = new PostedItem(this, post); + QLayout *alayout = ui.scrollAreaWidgetContents->layout(); + alayout->addWidget(item); +} + + +void PostedListDialog::clearPosts() +{ + std::cerr << "PostedListDialog::clearPosts()" << std::endl; + + std::list postedItems; + std::list::iterator pit; + + QLayout *alayout = ui.scrollAreaWidgetContents->layout(); + int count = alayout->count(); + for(int i = 0; i < count; i++) + { + QLayoutItem *litem = alayout->itemAt(i); + if (!litem) + { + std::cerr << "PostedListDialog::clearPosts() missing litem"; + std::cerr << std::endl; + continue; + } + + PostedItem *item = dynamic_cast(litem->widget()); + if (item) + { + std::cerr << "PostedListDialog::clearPosts() item: " << item; + std::cerr << std::endl; + + postedItems.push_back(item); + } + else + { + std::cerr << "PostedListDialog::clearPosts() Found Child, which is not a PostedItem???"; + std::cerr << std::endl; + } + } + + for(pit = postedItems.begin(); pit != postedItems.end(); pit++) + { + PostedItem *item = *pit; + alayout->removeWidget(item); + delete item; + } +} + + + +/*********************** **** **** **** ***********************/ +/*********************** **** **** **** ***********************/ +/*********************** **** **** **** ***********************/ + +void PostedListDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) +{ + std::cerr << "PostedListDialog::loadRequest() UserType: " << req.mUserType; + std::cerr << std::endl; + + if (queue == mPostedQueue) + { + /* now switch on req */ + switch(req.mUserType) + { + case POSTEDDIALOG_LISTING: + loadGroupSummary(req.mToken); + break; + + case POSTEDDIALOG_CURRENTFORUM: + loadGroupSummary_CurrentForum(req.mToken); + break; + + case POSTEDDIALOG_INSERTTHREADS: + loadGroupThreadData_InsertThreads(req.mToken); + break; + + default: + std::cerr << "PostedListDialog::loadRequest() ERROR: INVALID TYPE"; + std::cerr << std::endl; + break; + } + } +} + + + +/**************************************************************************************/ +/**************************************************************************************/ +/**************************************************************************************/ +/**************************** Groups **********************/ + + +void PostedListDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo) +{ + + groupItemInfo.id = QString::fromStdString(groupInfo.mGroupId); + groupItemInfo.name = QString::fromUtf8(groupInfo.mGroupName.c_str()); + //groupItemInfo.description = QString::fromUtf8(groupInfo.forumDesc); + groupItemInfo.popularity = groupInfo.mPop; + groupItemInfo.lastpost = QDateTime::fromTime_t(groupInfo.mLastPost); + + if (groupInfo.mGroupFlags & RS_DISTRIB_AUTHEN_REQ) { + groupItemInfo.name += " (" + tr("AUTHD") + ")"; + groupItemInfo.icon = QIcon(IMAGE_FORUMAUTHD); + } else { + groupItemInfo.icon = QIcon(IMAGE_FORUM); + } +} + +void PostedListDialog::insertGroupData(const std::list &groupList) +{ + std::list::const_iterator it; + + QList adminList; + QList subList; + QList popList; + QList otherList; + std::multimap popMap; + + for (it = groupList.begin(); it != groupList.end(); it++) { + /* sort it into Publish (Own), Subscribed, Popular and Other */ + uint32_t flags = it->mSubscribeFlags; + + GroupItemInfo groupItemInfo; + groupInfoToGroupItemInfo(*it, groupItemInfo); + + if (flags & RS_DISTRIB_ADMIN) { + adminList.push_back(groupItemInfo); + } else if (flags & RS_DISTRIB_SUBSCRIBED) { + /* subscribed forum */ + subList.push_back(groupItemInfo); + } else { + /* rate the others by popularity */ + popMap.insert(std::make_pair(it->mPop, groupItemInfo)); + } + } + + /* 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; + std::multimap::reverse_iterator rit; + for(rit = popMap.rbegin(); ((rit != popMap.rend()) && (i < popCount)); rit++, i++) ; + if (rit != popMap.rend()) { + popLimit = rit->first; + } + + for (rit = popMap.rbegin(); rit != popMap.rend(); rit++) { + if (rit->second.popularity < (int) popLimit) { + otherList.append(rit->second); + } else { + popList.append(rit->second); + } + } + + /* now we can add them in as a tree! */ + ui.groupTreeWidget->fillGroupItems(yourTopics, adminList); + ui.groupTreeWidget->fillGroupItems(subscribedTopics, subList); + ui.groupTreeWidget->fillGroupItems(popularTopics, popList); + ui.groupTreeWidget->fillGroupItems(otherTopics, otherList); + + // updateMessageSummaryList(""); +} + +/**************************************************************************************/ +/**************************************************************************************/ +/**************************************************************************************/ + + diff --git a/retroshare-gui/src/gui/Posted/PostedListDialog.h b/retroshare-gui/src/gui/Posted/PostedListDialog.h new file mode 100644 index 000000000..f6a4d3667 --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedListDialog.h @@ -0,0 +1,100 @@ +/* + * Retroshare Posted List + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_POSTED_LIST_DIALOG_H +#define MRK_POSTED_LIST_DIALOG_H + +#include "gui/mainpage.h" +#include "ui_PostedListDialog.h" + +#include + +#include + +#include "gui/Posted/PostedItem.h" +#include "gui/common/GroupTreeWidget.h" + +#include "util/TokenQueue.h" + +#include "gui/RsAutoUpdatePage.h" + +class PostedListDialog : public RsAutoUpdatePage, public PostedHolder, public TokenResponse +{ + Q_OBJECT + +public: + PostedListDialog(QWidget *parent = 0); + +virtual void deletePostedItem(PostedItem *, uint32_t ptype) { return; } +virtual void notifySelection(PostedItem *item, int ptype) { return; } + + +private slots: + +void groupListCustomPopupMenu( QPoint /*point*/ ); +void changedTopic(const QString &id); + +private: + +void clearPosts(); + +void updateDisplay(); +void loadPost(const RsPostedPost &post); + +void insertGroups(); +void requestGroupSummary(); +void loadGroupSummary(const uint32_t &token); + +void requestGroupSummary_CurrentForum(const std::string &forumId); +void loadGroupSummary_CurrentForum(const uint32_t &token); + +void insertThreads(); +void loadCurrentForumThreads(const std::string &forumId); + +void requestGroupThreadData_InsertThreads(const std::string &forumId); +void loadGroupThreadData_InsertThreads(const uint32_t &token); + + +void insertGroupData(const std::list &groupList); +void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo); + + void loadRequest(const TokenQueue *queue, const TokenRequest &req); + + + QTreeWidgetItem *yourTopics; + QTreeWidgetItem *subscribedTopics; + QTreeWidgetItem *popularTopics; + QTreeWidgetItem *otherTopics; + + bool mThreadLoading; + std::string mCurrTopicId; + + TokenQueue *mPostedQueue; + + /* UI - from Designer */ + Ui::PostedListDialog ui; + +}; + +#endif + diff --git a/retroshare-gui/src/gui/Posted/PostedListDialog.ui b/retroshare-gui/src/gui/Posted/PostedListDialog.ui new file mode 100644 index 000000000..b0ccaa7ee --- /dev/null +++ b/retroshare-gui/src/gui/Posted/PostedListDialog.ui @@ -0,0 +1,228 @@ + + + PostedListDialog + + + + 0 + 0 + 792 + 426 + + + + Form + + + + + + + + Hot + + + + + + + New + + + + + + + Top + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Today + + + + + Yesterday + + + + + This Week + + + + + This Month + + + + + This Year + + + + + + + + + + Qt::Horizontal + + + + + + + New Link Group + + + + + + + Submit Post + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + + + + + + + + + + Refresh + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Showing 1-100 + + + + + + + Prev + + + + + + + Next + + + + + + + + + true + + + + + 0 + 0 + 461 + 330 + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 309 + + + + + + + + + + + + + + + + + GroupTreeWidget + QWidget +
gui/common/GroupTreeWidget.h
+ 1 +
+
+ + +
diff --git a/retroshare-gui/src/gui/unfinished/ApplicationWindow.cpp b/retroshare-gui/src/gui/unfinished/ApplicationWindow.cpp index 4bad1ffcd..3f37f9df8 100644 --- a/retroshare-gui/src/gui/unfinished/ApplicationWindow.cpp +++ b/retroshare-gui/src/gui/unfinished/ApplicationWindow.cpp @@ -37,6 +37,7 @@ #include "gui/TheWire/WireDialog.h" #include "gui/Identity/IdDialog.h" #include "gui/ForumsV2Dialog.h" +#include "gui/Posted/PostedDialog.h" //#include "GamesDialog.h" //#include "CalDialog.h" @@ -112,6 +113,11 @@ ApplicationWindow::ApplicationWindow(QWidget* parent, Qt::WFlags flags) ui.stackPages->add(forumsV2Dialog = new ForumsV2Dialog(ui.stackPages), createPageAction(QIcon(IMAGE_FORUMSV2), tr("ForumsV2"), grp)); + PostedDialog *postedDialog = NULL; + ui.stackPages->add(postedDialog = new PostedDialog(ui.stackPages), + createPageAction(QIcon(IMAGE_LIBRARY), tr("Posted Links"), grp)); + + /* Create the toolbar */ ui.toolBar->addActions(grp->actions()); ui.toolBar->addSeparator();