mirror of
				https://github.com/RetroShare/RetroShare.git
				synced 2025-10-30 14:19:14 -04:00 
			
		
		
		
	Converted PhotoDialog to request/response system
- Added Generic TokenQueue to simplify the Interfacing. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5203 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
		
							parent
							
								
									d85aff3d0e
								
							
						
					
					
						commit
						b94e6d9888
					
				
					 8 changed files with 585 additions and 144 deletions
				
			
		|  | @ -914,12 +914,14 @@ identities { | |||
| 
 | ||||
| 	HEADERS += gui/Identity/IdDialog.h \ | ||||
| 		gui/Identity/IdEditDialog.h \ | ||||
|                   util/TokenQueue.h \ | ||||
| 
 | ||||
| 	FORMS += gui/Identity/IdDialog.ui \ | ||||
| 		gui/Identity/IdEditDialog.ui \ | ||||
| 
 | ||||
| 	SOURCES += gui/Identity/IdDialog.cpp \ | ||||
| 		gui/Identity/IdEditDialog.cpp \ | ||||
|                   util/TokenQueue.cpp \ | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -100,7 +100,6 @@ void PhotoAddDialog::publishAlbum() | |||
| 
 | ||||
| 
 | ||||
| 	RsPhotoAlbum album; | ||||
| 	RsPhotoThumbnail albumThumb; | ||||
| 
 | ||||
| 	album.mShareOptions.mShareType = 0; | ||||
| 	album.mShareOptions.mShareGroupId = "unknown"; | ||||
|  | @ -114,7 +113,7 @@ void PhotoAddDialog::publishAlbum() | |||
| 	album.mWhere = ui.lineEdit_Where->text().toStdString(); | ||||
| 	album.mWhen = ui.lineEdit_When->text().toStdString(); | ||||
| 
 | ||||
| 	if (rsPhoto->submitAlbumDetails(album, albumThumb)) | ||||
| 	if (rsPhoto->submitAlbumDetails(album)) | ||||
| 	{ | ||||
| 		/* now have path and album id */ | ||||
| 		int photoCount = ui.scrollAreaWidgetContents->getPhotoCount(); | ||||
|  | @ -122,10 +121,9 @@ void PhotoAddDialog::publishAlbum() | |||
| 		for(int i = 0; i < photoCount; i++) | ||||
| 		{ | ||||
| 			RsPhotoPhoto photo; | ||||
| 			RsPhotoThumbnail thumbnail; | ||||
| 			PhotoItem *item = ui.scrollAreaWidgetContents->getPhotoIdx(i); | ||||
| 			photo = item->mDetails; | ||||
| 			item->getPhotoThumbnail(thumbnail); | ||||
| 			item->getPhotoThumbnail(photo.mThumbnail); | ||||
| 	 | ||||
| 			photo.mAlbumId = album.mAlbumId; | ||||
| 			photo.mOrder = i; | ||||
|  | @ -139,7 +137,7 @@ void PhotoAddDialog::publishAlbum() | |||
| 			/* save image to album path */ | ||||
| 			photo.path = "unknown"; | ||||
| 
 | ||||
| 			rsPhoto->submitPhoto(photo, thumbnail); | ||||
| 			rsPhoto->submitPhoto(photo); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -74,6 +74,9 @@ PhotoDialog::PhotoDialog(QWidget *parent) | |||
| 	timer->start(1000); | ||||
| 
 | ||||
| 
 | ||||
| 	/* setup TokenQueue */ | ||||
| 	mPhotoQueue = new TokenQueue(rsPhoto, this); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -137,7 +140,8 @@ void PhotoDialog::checkUpdate() | |||
| 
 | ||||
| 	if (rsPhoto->updated()) | ||||
| 	{ | ||||
| 		insertAlbums(); | ||||
| 		//insertAlbums();
 | ||||
| 		requestAlbumList(); | ||||
| 	} | ||||
| 
 | ||||
| 	return; | ||||
|  | @ -183,93 +187,6 @@ double PhotoDialog::PhotoScore(const RsPhotoPhoto &photo) | |||
| 	return 1; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| bool PhotoDialog::FilterNSortAlbums(const std::list<std::string> &albumIds, std::list<std::string> &filteredAlbumIds, int count) | ||||
| { | ||||
| 	std::multimap<double, std::string> sortedAlbums; | ||||
| 	std::multimap<double, std::string>::iterator sit; | ||||
| 	std::list<std::string>::const_iterator it; | ||||
| 	 | ||||
| 	for(it = albumIds.begin(); it != albumIds.end(); it++) | ||||
| 	{ | ||||
| 		RsPhotoAlbum album; | ||||
| 		rsPhoto->getAlbum(*it, album); | ||||
| 
 | ||||
| 		if (matchesAlbumFilter(album)) | ||||
| 		{ | ||||
| 			double score = AlbumScore(album); | ||||
| 
 | ||||
| 			sortedAlbums.insert(std::make_pair(score, *it)); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	int i; | ||||
| 	for (sit = sortedAlbums.begin(), i = 0; (sit != sortedAlbums.end()) && (i < count); sit++, i++) | ||||
| 	{ | ||||
| 		filteredAlbumIds.push_back(sit->second); | ||||
| 	} | ||||
| 
 | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| bool PhotoDialog::FilterNSortPhotos(const std::list<std::string> &photoIds, std::list<std::string> &filteredPhotoIds, int count) | ||||
| { | ||||
| 	std::multimap<double, std::string> sortedPhotos; | ||||
| 	std::multimap<double, std::string>::iterator sit; | ||||
| 	std::list<std::string>::const_iterator it; | ||||
| 
 | ||||
| 	int i = 0; | ||||
| 	for(it = photoIds.begin(); it != photoIds.end(); it++, i++) | ||||
| 	{ | ||||
| 		RsPhotoPhoto photo; | ||||
| 		rsPhoto->getPhoto(*it, photo); | ||||
| 
 | ||||
| 		if (matchesPhotoFilter(photo)) | ||||
| 		{ | ||||
| 			double score = i; //PhotoScore(album);
 | ||||
| 			sortedPhotos.insert(std::make_pair(score, *it)); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	for (sit = sortedPhotos.begin(), i = 0; (sit != sortedPhotos.end()) && (i < count); sit++, i++) | ||||
| 	{ | ||||
| 		filteredPhotoIds.push_back(sit->second); | ||||
| 	} | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| void PhotoDialog::insertAlbums() | ||||
| { | ||||
| 	/* clear it all */ | ||||
| 	clearAlbums(); | ||||
| 	//ui.albumLayout->clear();
 | ||||
| 
 | ||||
| 	/* create a list of albums */ | ||||
| 
 | ||||
| 
 | ||||
| 	std::list<std::string> albumIds; | ||||
| 	std::list<std::string> filteredAlbumIds; | ||||
| 	std::list<std::string>::iterator it; | ||||
| 
 | ||||
| 	rsPhoto->getAlbumList(albumIds); | ||||
| 
 | ||||
| 	/* Filter Albums */ /* Sort Albums */ | ||||
| #define MAX_ALBUMS 50 | ||||
| 
 | ||||
| 	int count = MAX_ALBUMS; | ||||
| 	FilterNSortAlbums(albumIds, filteredAlbumIds, count); | ||||
| 
 | ||||
| 	for(it = filteredAlbumIds.begin(); it != filteredAlbumIds.end(); it++) | ||||
| 	{ | ||||
| 		addAlbum(*it); | ||||
| 	} | ||||
| 
 | ||||
| 	insertPhotosForAlbum(filteredAlbumIds); | ||||
| } | ||||
| 
 | ||||
| void PhotoDialog::insertPhotosForSelectedAlbum() | ||||
| { | ||||
| 	std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum()"; | ||||
|  | @ -277,36 +194,20 @@ void PhotoDialog::insertPhotosForSelectedAlbum() | |||
| 
 | ||||
| 	clearPhotos(); | ||||
| 
 | ||||
| 	std::list<std::string> albumIds; | ||||
| 	//std::list<std::string> albumIds;
 | ||||
| 	if (mAlbumSelected) | ||||
| 	{ | ||||
| 		albumIds.push_back(mAlbumSelected->mDetails.mAlbumId); | ||||
| 		std::string albumId = mAlbumSelected->mDetails.mAlbumId; | ||||
| 		//albumIds.push_back(albumId);
 | ||||
| 
 | ||||
| 		std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum() AlbumId: " << mAlbumSelected->mDetails.mAlbumId; | ||||
| 		std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum() AlbumId: " << albumId; | ||||
| 		std::cerr << std::endl; | ||||
| 		requestPhotoList(albumId); | ||||
| 	} | ||||
| 
 | ||||
| 	insertPhotosForAlbum(albumIds); | ||||
| 	//requestPhotoList(albumIds);
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void PhotoDialog::addAlbum(const std::string &id) | ||||
| { | ||||
| 
 | ||||
| 	RsPhotoAlbum album; | ||||
| 	rsPhoto->getAlbum(id, album); | ||||
| 
 | ||||
| 
 | ||||
| 	RsPhotoThumbnail thumbnail; | ||||
| 	rsPhoto->getAlbumThumbnail(id, thumbnail); | ||||
| 
 | ||||
| 	std::cerr << " PhotoDialog::addAlbum() AlbumId: " << album.mAlbumId << std::endl; | ||||
| 
 | ||||
| 	PhotoItem *item = new PhotoItem(this, album, thumbnail); | ||||
| 	QLayout *alayout = ui.scrollAreaWidgetContents->layout(); | ||||
| 	alayout->addWidget(item); | ||||
| } | ||||
| 
 | ||||
| void PhotoDialog::clearAlbums() | ||||
| { | ||||
| 	std::cerr << "PhotoDialog::clearAlbums()" << std::endl; | ||||
|  | @ -397,6 +298,230 @@ void PhotoDialog::clearPhotos() | |||
| 	 | ||||
| } | ||||
| 
 | ||||
| void PhotoDialog::addAlbum(const RsPhotoAlbum &album) | ||||
| { | ||||
| 	std::cerr << " PhotoDialog::addAlbum() AlbumId: " << album.mAlbumId << 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.mAlbumId; | ||||
| 	std::cerr << " PhotoId: " << photo.mId; | ||||
| 	std::cerr << std::endl; | ||||
| 
 | ||||
| 	PhotoItem *item = new PhotoItem(this, photo); | ||||
| 	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<std::string> ids; | ||||
| 	mPhotoQueue->genericRequest(TOKENREQ_GROUPLIST, ids, 0); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void PhotoDialog::loadAlbumList(const uint32_t &token) | ||||
| { | ||||
| 	std::cerr << "PhotoDialog::loadAlbumList()"; | ||||
| 	std::cerr << std::endl; | ||||
| 
 | ||||
| 	std::list<std::string> albumIds; | ||||
| 	rsPhoto->getAlbumList(token, albumIds); | ||||
| 
 | ||||
| 	requestAlbumData(albumIds); | ||||
| 
 | ||||
| 	clearPhotos(); | ||||
| 
 | ||||
| 	std::list<std::string>::iterator it; | ||||
| 	for(it = albumIds.begin(); it != albumIds.end(); it++) | ||||
| 	{ | ||||
| 		requestPhotoList(*it); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void PhotoDialog::requestAlbumData(const std::list<std::string> &ids) | ||||
| { | ||||
| 	mPhotoQueue->genericRequest(TOKENREQ_GROUPDATA, 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.mAlbumId << 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<std::string> ids; | ||||
| 	ids.push_back(albumId); | ||||
| 	mPhotoQueue->genericRequest(TOKENREQ_MSGLIST, ids, 0); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| void PhotoDialog::loadPhotoList(const uint32_t &token) | ||||
| { | ||||
| 	std::cerr << "PhotoDialog::loadPhotoList()"; | ||||
| 	std::cerr << std::endl; | ||||
| 
 | ||||
| 
 | ||||
| 	std::list<std::string> photoIds; | ||||
| 
 | ||||
| 	rsPhoto->getPhotoList(token, photoIds); | ||||
| 	requestPhotoData(photoIds); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void PhotoDialog::requestPhotoData(const std::list<std::string> &photoIds) | ||||
| { | ||||
| 	mPhotoQueue->genericRequest(TOKENREQ_MSGDATA, 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::addPhoto() AlbumId: " << photo.mAlbumId; | ||||
| 			std::cerr << " PhotoId: " << photo.mId; | ||||
| 			std::cerr << std::endl; | ||||
| 
 | ||||
| 			PhotoItem *item = new PhotoItem(this, photo); | ||||
| 			QLayout *alayout = ui.scrollAreaWidgetContents_2->layout(); | ||||
| 			alayout->addWidget(item); | ||||
| 		} | ||||
| 		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_GROUPLIST: | ||||
| 				loadAlbumList(req.mToken); | ||||
| 				break; | ||||
| 			case TOKENREQ_GROUPDATA: | ||||
| 				loadAlbumData(req.mToken); | ||||
| 				break; | ||||
| 			case TOKENREQ_MSGLIST: | ||||
| 				loadPhotoList(req.mToken); | ||||
| 				break; | ||||
| 			case TOKENREQ_MSGDATA: | ||||
| 				loadPhotoData(req.mToken); | ||||
| 				break; | ||||
| 			default: | ||||
| 				std::cerr << "PhotoDialog::loadRequest() ERROR: INVALID TYPE"; | ||||
| 				std::cerr << std::endl; | ||||
| 				break; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /**************************** Request / Response Filling of Data ************************/ | ||||
| 
 | ||||
| 
 | ||||
| // OLD STUFF THAT CANNOT BE USED WITH NEW REQ/RESP
 | ||||
| #if 0 | ||||
| 
 | ||||
| 
 | ||||
| void PhotoDialog::insertAlbums() | ||||
| { | ||||
| 	/* clear it all */ | ||||
| 	clearAlbums(); | ||||
| 	//ui.albumLayout->clear();
 | ||||
| 
 | ||||
| 	/* create a list of albums */ | ||||
| 
 | ||||
| 
 | ||||
| 	std::list<std::string> albumIds; | ||||
| 	std::list<std::string> filteredAlbumIds; | ||||
| 	std::list<std::string>::iterator it; | ||||
| 
 | ||||
| 	rsPhoto->getAlbumList(albumIds); | ||||
| 
 | ||||
| 	/* Filter Albums */ /* Sort Albums */ | ||||
| #define MAX_ALBUMS 50 | ||||
| 
 | ||||
| 	int count = MAX_ALBUMS; | ||||
| 	FilterNSortAlbums(albumIds, filteredAlbumIds, count); | ||||
| 
 | ||||
| 	for(it = filteredAlbumIds.begin(); it != filteredAlbumIds.end(); it++) | ||||
| 	{ | ||||
| 		addAlbum(*it); | ||||
| 	} | ||||
| 
 | ||||
| 	insertPhotosForAlbum(filteredAlbumIds); | ||||
| } | ||||
| 
 | ||||
| void PhotoDialog::insertPhotosForAlbum(const std::list<std::string> &albumIds) | ||||
| { | ||||
|  | @ -430,32 +555,79 @@ void PhotoDialog::insertPhotosForAlbum(const std::list<std::string> &albumIds) | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| void PhotoDialog::addPhoto(const std::string &id) | ||||
| void PhotoDialog::insertPhotosForSelectedAlbum() | ||||
| { | ||||
| 
 | ||||
| 	RsPhotoPhoto photo; | ||||
| 	rsPhoto->getPhoto(id,photo); | ||||
| 
 | ||||
| 	RsPhotoThumbnail thumbnail; | ||||
| 	rsPhoto->getPhotoThumbnail(id, thumbnail); | ||||
| 
 | ||||
| 	std::cerr << "PhotoDialog::addPhoto() AlbumId: " << photo.mAlbumId; | ||||
| 	std::cerr << " PhotoId: " << photo.mId; | ||||
| 	std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum()"; | ||||
| 	std::cerr << std::endl; | ||||
| 
 | ||||
| 	PhotoItem *item = new PhotoItem(this, photo, thumbnail); | ||||
| 	QLayout *alayout = ui.scrollAreaWidgetContents_2->layout(); | ||||
| 	alayout->addWidget(item); | ||||
| 	clearPhotos(); | ||||
| 
 | ||||
| 	std::list<std::string> albumIds; | ||||
| 	if (mAlbumSelected) | ||||
| 	{ | ||||
| 		albumIds.push_back(mAlbumSelected->mDetails.mAlbumId); | ||||
| 
 | ||||
| 		std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum() AlbumId: " << mAlbumSelected->mDetails.mAlbumId; | ||||
| 		std::cerr << std::endl; | ||||
| 	} | ||||
| 
 | ||||
| 	insertPhotosForAlbum(albumIds); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void PhotoDialog::deletePhotoItem(PhotoItem *item, uint32_t type) | ||||
| bool PhotoDialog::FilterNSortAlbums(const std::list<std::string> &albumIds, std::list<std::string> &filteredAlbumIds, int count) | ||||
| { | ||||
| 	std::multimap<double, std::string> sortedAlbums; | ||||
| 	std::multimap<double, std::string>::iterator sit; | ||||
| 	std::list<std::string>::const_iterator it; | ||||
| 	 | ||||
| 	for(it = albumIds.begin(); it != albumIds.end(); it++) | ||||
| 	{ | ||||
| 		RsPhotoAlbum album; | ||||
| 		rsPhoto->getAlbum(*it, album); | ||||
| 
 | ||||
| 		if (matchesAlbumFilter(album)) | ||||
| 		{ | ||||
| 			double score = AlbumScore(album); | ||||
| 
 | ||||
| 	return; | ||||
| 			sortedAlbums.insert(std::make_pair(score, *it)); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	int i; | ||||
| 	for (sit = sortedAlbums.begin(), i = 0; (sit != sortedAlbums.end()) && (i < count); sit++, i++) | ||||
| 	{ | ||||
| 		filteredAlbumIds.push_back(sit->second); | ||||
| 	} | ||||
| 
 | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| bool PhotoDialog::FilterNSortPhotos(const std::list<std::string> &photoIds, std::list<std::string> &filteredPhotoIds, int count) | ||||
| { | ||||
| 	std::multimap<double, std::string> sortedPhotos; | ||||
| 	std::multimap<double, std::string>::iterator sit; | ||||
| 	std::list<std::string>::const_iterator it; | ||||
| 
 | ||||
| 	int i = 0; | ||||
| 	for(it = photoIds.begin(); it != photoIds.end(); it++, i++) | ||||
| 	{ | ||||
| 		RsPhotoPhoto photo; | ||||
| 		rsPhoto->getPhoto(*it, photo); | ||||
| 
 | ||||
| 		if (matchesPhotoFilter(photo)) | ||||
| 		{ | ||||
| 			double score = i; //PhotoScore(album);
 | ||||
| 			sortedPhotos.insert(std::make_pair(score, *it)); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	for (sit = sortedPhotos.begin(), i = 0; (sit != sortedPhotos.end()) && (i < count); sit++, i++) | ||||
| 	{ | ||||
| 		filteredPhotoIds.push_back(sit->second); | ||||
| 	} | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
| 
 | ||||
|  |  | |||
|  | @ -33,8 +33,9 @@ | |||
| 
 | ||||
| #include "gui/PhotoShare/PhotoItem.h" | ||||
| #include "gui/PhotoShare/PhotoAddDialog.h" | ||||
| #include "util/TokenQueue.h" | ||||
| 
 | ||||
| class PhotoDialog : public MainPage, public PhotoHolder  | ||||
| class PhotoDialog : public MainPage, public PhotoHolder, public TokenResponse  | ||||
| { | ||||
|   Q_OBJECT | ||||
| 
 | ||||
|  | @ -54,6 +55,18 @@ private slots: | |||
| 
 | ||||
| private: | ||||
| 
 | ||||
| 	/* Request Response Functions for loading data */ | ||||
| 	void requestAlbumList(); | ||||
| 	void requestAlbumData(const std::list<std::string> &ids); | ||||
| 	void requestPhotoList(const std::string &albumId); | ||||
| 	void requestPhotoData(const std::list<std::string> &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 
 | ||||
|  | @ -67,14 +80,15 @@ private: | |||
| 
 | ||||
| 	/* Grunt work of setting up the GUI */ | ||||
| 
 | ||||
| 	bool FilterNSortAlbums(const std::list<std::string> &albumIds, std::list<std::string> &filteredAlbumIds, int count); | ||||
| 	bool FilterNSortPhotos(const std::list<std::string> &photoIds, std::list<std::string> &filteredPhotoIds, int count); | ||||
| 	void insertAlbums(); | ||||
| 	void insertPhotosForAlbum(const std::list<std::string> &albumIds); | ||||
| 	//bool FilterNSortAlbums(const std::list<std::string> &albumIds, std::list<std::string> &filteredAlbumIds, int count);
 | ||||
| 	//bool FilterNSortPhotos(const std::list<std::string> &photoIds, std::list<std::string> &filteredPhotoIds, int count);
 | ||||
| 	//void insertAlbums();
 | ||||
| 	//void insertPhotosForAlbum(const std::list<std::string> &albumIds);
 | ||||
| 
 | ||||
| 	void insertPhotosForSelectedAlbum(); | ||||
| 
 | ||||
| 	void addAlbum(const std::string &id); | ||||
| 	void addPhoto(const std::string &id); | ||||
| 	void addAlbum(const RsPhotoAlbum &album); | ||||
| 	void addPhoto(const RsPhotoPhoto &photo); | ||||
| 
 | ||||
| 	void clearAlbums(); | ||||
| 	void clearPhotos(); | ||||
|  | @ -84,6 +98,8 @@ private: | |||
| 	PhotoItem *mAlbumSelected; | ||||
| 	PhotoItem *mPhotoSelected; | ||||
| 
 | ||||
| 	TokenQueue *mPhotoQueue; | ||||
| 
 | ||||
| 	/* UI - from Designer */ | ||||
| 	Ui::PhotoDialog ui; | ||||
| 
 | ||||
|  |  | |||
|  | @ -39,7 +39,7 @@ | |||
|  ****/ | ||||
| 
 | ||||
| /** Constructor */ | ||||
| PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail) | ||||
| PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoAlbum &album) | ||||
| :QWidget(NULL), mParent(parent), mType(PHOTO_ITEM_TYPE_ALBUM)  | ||||
| { | ||||
| 	setupUi(this); | ||||
|  | @ -48,13 +48,13 @@ PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoAlbum &album, const RsPho | |||
| 
 | ||||
| 	mDetails = *( (RsPhotoPhoto *) &(album)); | ||||
| 	updateAlbumText(album); | ||||
| 	updateImage(thumbnail); | ||||
| 	updateImage(album.mThumbnail); | ||||
| 
 | ||||
| 	setSelected(false); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoPhoto &photo, const RsPhotoThumbnail &thumbnail) | ||||
| PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoPhoto &photo) | ||||
| :QWidget(NULL), mParent(parent), mType(PHOTO_ITEM_TYPE_PHOTO)  | ||||
| { | ||||
| 	setupUi(this); | ||||
|  | @ -64,7 +64,7 @@ PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoPhoto &photo, const RsPho | |||
| 	mDetails = *( (RsPhotoPhoto *) &(photo)); | ||||
| 
 | ||||
| 	updatePhotoText(photo); | ||||
| 	updateImage(thumbnail); | ||||
| 	updateImage(photo.mThumbnail); | ||||
| 
 | ||||
| 	setSelected(false); | ||||
| } | ||||
|  |  | |||
|  | @ -47,8 +47,8 @@ class PhotoItem : public QWidget, private Ui::PhotoItem | |||
|   Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
| 	PhotoItem(PhotoHolder *parent, const RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail); | ||||
| 	PhotoItem(PhotoHolder *parent, const RsPhotoPhoto &photo, const RsPhotoThumbnail &thumbnail); | ||||
| 	PhotoItem(PhotoHolder *parent, const RsPhotoAlbum &album); | ||||
| 	PhotoItem(PhotoHolder *parent, const RsPhotoPhoto &photo); | ||||
| 	PhotoItem(PhotoHolder *parent, std::string url); // for new photos.
 | ||||
| 
 | ||||
| 	bool getPhotoThumbnail(RsPhotoThumbnail &nail); | ||||
|  |  | |||
							
								
								
									
										157
									
								
								retroshare-gui/src/util/TokenQueue.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										157
									
								
								retroshare-gui/src/util/TokenQueue.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,157 @@ | |||
| /*
 | ||||
|  * Token Queue. | ||||
|  * | ||||
|  * 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 "util/TokenQueue.h" | ||||
| #include <iostream> | ||||
| 
 | ||||
| #include <QTimer> | ||||
| 
 | ||||
| /******
 | ||||
|  * #define ID_DEBUG 1 | ||||
|  *****/ | ||||
| 
 | ||||
| /** Constructor */ | ||||
| TokenQueue::TokenQueue(RsTokenService *service, TokenResponse *resp) | ||||
| :QWidget(NULL), mService(service), mResponder(resp) | ||||
| { | ||||
| 	//mTrigger = new QTimer(this);
 | ||||
| 	//mTrigger->connect(mTrigger, SIGNAL(timeout()), this, SLOT(pollRequests()));
 | ||||
| 	return; | ||||
| } | ||||
| 
 | ||||
| bool TokenQueue::genericRequest(uint32_t basictype, std::list<std::string> ids, uint32_t usertype) | ||||
| { | ||||
| 	uint32_t token; | ||||
| 	switch(basictype) | ||||
| 	{ | ||||
| 		case TOKENREQ_GROUPLIST: | ||||
| 			mService->requestGroupList(token); | ||||
| 			break; | ||||
| 
 | ||||
| 		case TOKENREQ_GROUPDATA: | ||||
| 			mService->requestGroupData(token, ids); | ||||
| 			break; | ||||
| 
 | ||||
| 		case TOKENREQ_MSGLIST: | ||||
| 			mService->requestMsgList(token, ids); | ||||
| 			break; | ||||
| 
 | ||||
| 		case TOKENREQ_MSGDATA: | ||||
| 			mService->requestMsgData(token, ids); | ||||
| 			break; | ||||
| 
 | ||||
| 		default: | ||||
| 			return false; | ||||
| 	} | ||||
| 
 | ||||
| 	queueRequest(token, basictype, usertype); | ||||
| 
 | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void TokenQueue::queueRequest(uint32_t token, uint32_t basictype, uint32_t usertype) | ||||
| { | ||||
| 	std::cerr << "TokenQueue::queueRequest() Token: " << token << " Type: " << basictype << " UserType: " << usertype; | ||||
| 	std::cerr << std::endl; | ||||
| 
 | ||||
| 	TokenRequest req; | ||||
| 	req.mToken = token; | ||||
| 	req.mType = basictype; | ||||
| 	req.mUserType = usertype; | ||||
| 
 | ||||
| 	gettimeofday(&req.mRequestTs, NULL); | ||||
| 	req.mPollTs = req.mRequestTs; | ||||
| 
 | ||||
| 	mRequests.push_back(req); | ||||
| 
 | ||||
| 	if (mRequests.size() == 1) | ||||
| 	{ | ||||
| 		/* start the timer */ | ||||
| 		doPoll(0.1); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void TokenQueue::doPoll(float dt) | ||||
| { | ||||
| 	/* single shot poll */ | ||||
| 	//mTrigger->singlesshot(dt * 1000);
 | ||||
| 	QTimer::singleShot((int) (dt * 1000.0), this, SLOT(pollRequests())); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void TokenQueue::pollRequests() | ||||
| { | ||||
| 	std::list<TokenRequest>::iterator it; | ||||
| 
 | ||||
| 	double pollPeriod = 1.0; // max poll period.
 | ||||
| 	for(it = mRequests.begin(); it != mRequests.end(); it++) | ||||
| 	{ | ||||
| 		if (checkForRequest(it->mToken)) | ||||
| 		{ | ||||
| 			/* clean it up and handle */ | ||||
| 			loadRequest(*it);		 | ||||
| 			it = mRequests.erase(it);	 | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			/* calculate desired poll period */ | ||||
| 
 | ||||
| 			/* if less then current poll period, adjust */	 | ||||
| 			 | ||||
| 			it++; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if (mRequests.size() > 0) | ||||
| 	{ | ||||
| 		doPoll(pollPeriod); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| bool TokenQueue::checkForRequest(uint32_t token) | ||||
| { | ||||
| 	/* check token */ | ||||
| 	return (COMPLETED_REQUEST == mService->requestStatus(token)); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void TokenQueue::loadRequest(const TokenRequest &req) | ||||
| { | ||||
| 	std::cerr << "TokenQueue::loadRequest() Dummy Function - please Implement"; | ||||
| 	std::cerr << std::endl; | ||||
| 	std::cerr << "Token: " << req.mToken << " Type: " << req.mType << " UserType: " << req.mUserType; | ||||
| 	std::cerr << std::endl; | ||||
| 
 | ||||
| 	mResponder->loadRequest(this, req); | ||||
| 
 | ||||
| 	return; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
							
								
								
									
										96
									
								
								retroshare-gui/src/util/TokenQueue.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								retroshare-gui/src/util/TokenQueue.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,96 @@ | |||
| /*
 | ||||
|  * Token Queue. | ||||
|  * | ||||
|  * 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_TOKEN_QUEUE_H | ||||
| #define MRK_TOKEN_QUEUE_H | ||||
| 
 | ||||
| #include <QWidget> | ||||
| #include <QTimer> | ||||
| #include <list> | ||||
| #include <string> | ||||
| #include <sys/time.h> | ||||
| 
 | ||||
| #include <retroshare/rsidentity.h> | ||||
| 
 | ||||
| 
 | ||||
| #define COMPLETED_REQUEST	4 | ||||
| 
 | ||||
| 
 | ||||
| #define TOKENREQ_GROUPLIST	1 | ||||
| #define TOKENREQ_GROUPDATA	2 | ||||
| #define TOKENREQ_MSGLIST	3 | ||||
| #define TOKENREQ_MSGDATA	4 | ||||
| 
 | ||||
| 
 | ||||
| class TokenQueue; | ||||
| 
 | ||||
| class TokenRequest | ||||
| { | ||||
| 	public: | ||||
| 	uint32_t mToken; | ||||
| 	uint32_t mType; | ||||
| 	uint32_t mUserType; | ||||
| 	struct timeval mRequestTs; | ||||
| 	struct timeval mPollTs; | ||||
| }; | ||||
| 
 | ||||
| class TokenResponse | ||||
| { | ||||
| 	public: | ||||
| 	//virtual ~TokenResponse() { return; }
 | ||||
| 	// These Functions are overloaded to get results out.
 | ||||
| 	virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req) = 0; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class TokenQueue: public QWidget | ||||
| { | ||||
|   Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
| 	TokenQueue(RsTokenService *service, TokenResponse *resp); | ||||
| 
 | ||||
| 	/* generic handling of token / response update behaviour */ | ||||
| 	bool genericRequest(uint32_t basictype, std::list<std::string> ids, uint32_t usertype); | ||||
| 	void queueRequest(uint32_t token, uint32_t basictype, uint32_t usertype); | ||||
| 	bool checkForRequest(uint32_t token); | ||||
| 	void loadRequest(const TokenRequest &req); | ||||
| 
 | ||||
| protected: | ||||
| 	void doPoll(float dt); | ||||
| 
 | ||||
| private slots: | ||||
| 	void pollRequests(); | ||||
| 
 | ||||
| private: | ||||
| 	/* Info for Data Requests */ | ||||
| 	std::list<TokenRequest> mRequests; | ||||
| 
 | ||||
| 	RsTokenService *mService; | ||||
| 	TokenResponse *mResponder; | ||||
| 
 | ||||
| 	QTimer *mTrigger; | ||||
| }; | ||||
| 
 | ||||
| #endif | ||||
| 
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue