RetroShare/retroshare-gui/src/gui/PhotoShare/PhotoSlideShow.cpp
chrisparker126 a715947046 Added Rs photo v2 item serialisation test, fixed subsequent bugs
Reactivated Photodialog. almost completed integration, publishing and item storage working, 
but data retrieval algorithm needs to be changed (request flags need to be translated, based on update call rather than client assumption)
fixed bug in rsgenexchange notification. 
Added LGPL notices


git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5387 b45a01b8-16f6-495d-af2f-9b41ad6348cc
2012-08-06 21:00:38 +00:00

359 lines
7.9 KiB
C++

/*
* Retroshare Photo 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 "gui/PhotoShare/PhotoSlideShow.h"
#include "gui/PhotoShare/PhotoDrop.h"
#include <iostream>
/** Constructor */
PhotoSlideShow::PhotoSlideShow(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect(ui.pushButton_ShiftLeft, SIGNAL( clicked( void ) ), this, SLOT( moveLeft( void ) ) );
connect(ui.pushButton_ShiftRight, SIGNAL( clicked( void ) ), this, SLOT( moveRight( void ) ) );
connect(ui.pushButton_ShowDetails, SIGNAL( clicked( void ) ), this, SLOT( showPhotoDetails( void ) ) );
connect(ui.pushButton_StartStop, SIGNAL( clicked( void ) ), this, SLOT( StartStop( void ) ) );
connect(ui.pushButton_Close, SIGNAL( clicked( void ) ), this, SLOT( closeShow( void ) ) );
mPhotoQueue = new TokenQueueV2(rsPhotoV2->getTokenService(), this);
mRunning = true;
mShotActive = true;
mImageIdx = 0;
//loadImage();
//QTimer::singleShot(5000, this, SLOT(timerEvent()));
}
PhotoSlideShow::~PhotoSlideShow(){
}
void PhotoSlideShow::showPhotoDetails()
{
}
void PhotoSlideShow::moveLeft()
{
if (mRunning)
{
return;
}
mImageIdx--;
if (mImageIdx < 0)
{
mImageIdx = mPhotos.size() - 1;
}
loadImage();
}
void PhotoSlideShow::moveRight()
{
if (mRunning)
{
return;
}
mImageIdx++;
if (mImageIdx >= mPhotos.size())
{
mImageIdx = 0;
}
loadImage();
}
void PhotoSlideShow::StartStop()
{
if (mRunning)
{
mRunning = false;
}
else
{
mRunning = true;
if (!mShotActive) // make sure only one timer running
{
mShotActive = true;
QTimer::singleShot(5000, this, SLOT(timerEvent()));
}
}
}
void PhotoSlideShow::timerEvent()
{
if (!mRunning)
{
mShotActive = false;
return;
}
mImageIdx++;
if (mImageIdx >= mPhotos.size())
{
mImageIdx = 0;
}
loadImage();
QTimer::singleShot(5000, this, SLOT(timerEvent()));
}
void PhotoSlideShow::closeShow()
{
mRunning = false;
hide();
}
void PhotoSlideShow::loadImage()
{
/* get the image */
int i = 0;
bool found = false;
std::string msgId;
//std::map<std::string, RsPhotoPhoto *>::iterator it;
std::map<int, std::string>::iterator it;
for(it = mPhotoOrder.begin(); it != mPhotoOrder.end(); it++, i++)
{
if (i == mImageIdx)
{
msgId = it->second;
found = true;
break;
}
}
RsPhotoPhoto *ptr = NULL;
if (found)
{
ptr = mPhotos[msgId];
}
if (ptr)
{
/* load into the slot */
if (ptr->mThumbnail.data != NULL)
{
QPixmap qtn;
// copy the data for Qpixmap to use.
RsPhotoThumbnail tn;
tn.copyFrom(ptr->mThumbnail);
qtn.loadFromData(tn.data, tn.size, tn.type.c_str());
tn.data = 0;
//ui.imgLabel->setPixmap(qtn);
QPixmap sqtn = qtn.scaled(ui.albumLabel->width(), ui.imgLabel->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
ui.imgLabel->setPixmap(sqtn);
}
}
}
void PhotoSlideShow::updateMoveButtons(uint32_t status)
{
std::cerr << "PhotoSlideShow::updateMoveButtons(" << status << ")";
std::cerr << std::endl;
switch(status)
{
case PHOTO_SHIFT_NO_BUTTONS:
ui.pushButton_ShiftLeft->setEnabled(false);
ui.pushButton_ShiftRight->setEnabled(false);
break;
case PHOTO_SHIFT_LEFT_ONLY:
ui.pushButton_ShiftLeft->setEnabled(true);
ui.pushButton_ShiftRight->setEnabled(false);
break;
case PHOTO_SHIFT_RIGHT_ONLY:
ui.pushButton_ShiftLeft->setEnabled(false);
ui.pushButton_ShiftRight->setEnabled(true);
break;
case PHOTO_SHIFT_BOTH:
ui.pushButton_ShiftLeft->setEnabled(true);
ui.pushButton_ShiftRight->setEnabled(true);
break;
}
}
void PhotoSlideShow::clearDialog()
{
#if 0
ui.lineEdit_Title->setText(QString("title"));
ui.lineEdit_Caption->setText(QString("Caption"));
ui.lineEdit_Where->setText(QString("Where"));
ui.lineEdit_When->setText(QString("When"));
ui.scrollAreaWidgetContents->clearPhotos();
ui.AlbumDrop->clearPhotos();
/* clean up album image */
mAlbumData.mThumbnail.deleteImage();
RsPhotoAlbum emptyAlbum;
mAlbumData = emptyAlbum;
/* add empty image */
PhotoItem *item = new PhotoItem(NULL, mAlbumData);
ui.AlbumDrop->addPhotoItem(item);
mAlbumEdit = false;
#endif
}
void PhotoSlideShow::loadAlbum(const std::string &albumId)
{
/* much like main load fns */
clearDialog();
RsTokReqOptionsV2 opts;
uint32_t token;
std::list<std::string> albumIds;
albumIds.push_back(albumId);
// We need both Album and Photo Data.
mPhotoQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, albumIds, 0);
}
bool PhotoSlideShow::loadPhotoData(const uint32_t &token)
{
std::cerr << "PhotoSlideShow::loadPhotoData()";
std::cerr << std::endl;
PhotoResult res;
rsPhotoV2->getPhoto(token, res);
PhotoResult::iterator mit = res.begin();
for(; mit != res.end(); mit++)
{
std::vector<RsPhotoPhoto>& photoV = mit->second;
std::vector<RsPhotoPhoto>::iterator vit = photoV.begin();
for(; vit != photoV.end(); vit++)
{
RsPhotoPhoto& photo = *vit;
RsPhotoPhoto *ptr = new RsPhotoPhoto;
*ptr = photo;
ptr->mThumbnail.data = 0;
ptr->mThumbnail.copyFrom(photo.mThumbnail);
mPhotos[photo.mMeta.mMsgId] = ptr;
mPhotoOrder[ptr->mOrder] = photo.mMeta.mMsgId;
std::cerr << "PhotoSlideShow::addAddPhoto() AlbumId: " << photo.mMeta.mGroupId;
std::cerr << " PhotoId: " << photo.mMeta.mMsgId;
std::cerr << std::endl;
}
}
// Load and Start.
loadImage();
QTimer::singleShot(5000, this, SLOT(timerEvent()));
return true;
}
bool PhotoSlideShow::loadAlbumData(const uint32_t &token)
{
std::cerr << "PhotoSlideShow::loadAlbumData()";
std::cerr << std::endl;
std::vector<RsPhotoAlbum> albums;
rsPhotoV2->getAlbum(token, albums);
std::vector<RsPhotoAlbum>::iterator vit = albums.begin();
GxsMsgReq req;
for(; vit != albums.end(); vit++)
{
RsPhotoAlbum& album = *vit;
std::cerr << " PhotoSlideShow::loadAlbumData() AlbumId: " << album.mMeta.mGroupId << std::endl;
//updateAlbumDetails(album);
uint32_t token;
std::list<std::string> albumIds;
albumIds.push_back(album.mMeta.mGroupId);
req[album.mMeta.mGroupId] = std::vector<RsGxsMessageId>();
}
RsTokReqOptionsV2 opts;
opts.mOptions = RS_TOKREQOPT_MSG_LATEST;
uint32_t t;
mPhotoQueue->requestMsgInfo(t, RS_TOKREQ_ANSTYPE_DATA, opts, req, 0);
return true;
}
void PhotoSlideShow::loadRequest(const TokenQueueV2 *queue, const TokenRequestV2 &req)
{
std::cerr << "PhotoSlideShow::loadRequest()";
std::cerr << std::endl;
if (queue == mPhotoQueue)
{
/* now switch on req */
switch(req.mType)
{
case TOKENREQ_GROUPINFO:
loadAlbumData(req.mToken);
break;
case TOKENREQ_MSGINFO:
loadPhotoData(req.mToken);
break;
default:
std::cerr << "PhotoSlideShow::loadRequest() ERROR: GROUP: INVALID ANS TYPE";
std::cerr << std::endl;
break;
}
}
}