2008-05-08 20:27:28 -04:00
/*
* libretroshare / src / services : p3Qblog . cc
*
* RetroShare C + + Interface .
*
* Copyright 2007 - 2008 by Chris Evi - Parker
*
* 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 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 "services/p3Qblog.h"
# include <utility>
# include <ctime>
2008-05-10 17:33:07 -04:00
RsQblog * rsQblog = NULL ;
p3Qblog : : p3Qblog ( )
: FilterSwitch ( false )
{
loadDummy ( ) ; // load dummy data
return ;
}
p3Qblog : : ~ p3Qblog ( )
{
return ;
}
2008-05-08 20:27:28 -04:00
2008-05-24 11:09:51 -04:00
bool p3Qblog : : setStatus ( const std : : string & status )
2008-05-08 20:27:28 -04:00
{
2008-05-24 11:09:51 -04:00
FriendStatusSet [ usr ] = status ;
2008-05-08 20:27:28 -04:00
return true ;
}
2008-05-10 17:33:07 -04:00
bool p3Qblog : : getFilterSwitch ( void )
2008-05-08 20:27:28 -04:00
{
return FilterSwitch ;
}
bool p3Qblog : : setFilterSwitch ( bool & filterSwitch )
{
FilterSwitch = filterSwitch ;
return true ;
}
bool p3Qblog : : getFriendList ( std : : list < std : : string > & friendList )
{
2008-05-18 16:25:14 -04:00
if ( FriendList . empty ( ) )
{
std : : cerr < < " FriendList empty! " < < std : : endl ;
return false ;
}
2008-05-08 20:27:28 -04:00
friendList = FriendList ;
return true ;
}
2008-05-24 11:09:51 -04:00
bool p3Qblog : : getStatus ( std : : map < std : : string , std : : string > & usrStatus )
2008-05-08 20:27:28 -04:00
{
2008-05-24 11:09:51 -04:00
usrStatus = FriendStatusSet ;
2008-05-08 20:27:28 -04:00
return true ;
}
bool p3Qblog : : removeFiltFriend ( std : : string & usrId )
{
std : : list < std : : string > : : iterator it ;
/* search through list to remove friend */
for ( it = FriendList . begin ( ) ; it ! = FriendList . end ( ) ; it + + )
{
if ( it - > compare ( usrId ) )
{
FriendList . erase ( it ) ; // remove friend from list
return true ;
}
}
std : : cerr < < " usr could not be found! " < < std : : endl ;
return false ; // could not find friend
}
bool p3Qblog : : addToFilter ( std : : string & usrId )
{
std : : list < std : : string > : : iterator it ;
/* search through list to remove friend */
for ( it = FriendList . begin ( ) ; it ! = FriendList . end ( ) ; it + + )
{
if ( it - > compare ( usrId ) )
{
std : : cerr < < " usr already in list! " < < std : : endl ;
return false ; // user already in list, not added
}
}
FilterList . push_back ( usrId ) ;
return true ;
}
bool p3Qblog : : getBlogs ( std : : map < std : : string , std : : multimap < long int , std : : string > > & blogs )
{
if ( UsrBlogSet . empty ( ) ) // return error blogs are empty
{
std : : cerr < < " usr blog set empty! " < < std : : endl ;
return false ;
}
blogs = UsrBlogSet ;
return true ;
}
2008-05-24 11:09:51 -04:00
bool p3Qblog : : sendBlog ( const std : : string & msg )
2008-05-08 20:27:28 -04:00
{
time_t msgCreatedTime ;
2008-05-13 12:56:27 -04:00
UsrBlogSet [ " Usr1 " ] . insert ( std : : make_pair ( msgCreatedTime , msg ) ) ;
2008-05-08 20:27:28 -04:00
return true ;
}
2008-05-24 11:09:51 -04:00
bool p3Qblog : : getProfile ( std : : map < std : : string , std : : string > & profile )
2008-05-08 20:27:28 -04:00
{
/* return error is set empty */
if ( FriendSongset . empty ( ) )
{
std : : cerr < < " friend song set empty! " < < std : : endl ;
return false ;
}
2008-05-24 11:09:51 -04:00
profile = FriendSongset ;
2008-05-08 20:27:28 -04:00
return true ;
}
2008-05-24 11:09:51 -04:00
bool p3Qblog : : setProfile ( const std : : string & favSong )
2008-05-08 20:27:28 -04:00
{
2008-05-24 11:09:51 -04:00
FriendSongset [ usr ] = favSong ;
2008-05-08 20:27:28 -04:00
return true ;
}
2008-05-08 21:01:13 -04:00
2008-05-08 20:27:28 -04:00
void p3Qblog : : loadDummy ( void )
{
/* load usr list */
FriendList . push_back ( " Usr1 " ) ; // home usr/server
2008-05-18 16:25:14 -04:00
FriendList . push_back ( " Mike2 " ) ;
FriendList . push_back ( " Mike3 " ) ;
FriendList . push_back ( " Mike4 " ) ;
FriendList . push_back ( " Mike5 " ) ;
2008-05-08 20:27:28 -04:00
/* set usr status: need to create usr/status set or just add to profile object */
2008-05-24 11:09:51 -04:00
//TODO
2008-05-08 20:27:28 -04:00
/* set favsong: will be made part of profile */
FavSong = " DeathOfAthousandSuns " ;
/* load friend song set */
FriendSongset . insert ( std : : make_pair ( " Usr1 " , FavSong ) ) ; // home usr/server
FriendSongset . insert ( std : : make_pair ( " Mike2 " , " yowsers " ) ) ;
FriendSongset . insert ( std : : make_pair ( " Mike3 " , " destroyers " ) ) ;
FriendSongset . insert ( std : : make_pair ( " Mike4 " , " revolvers " ) ) ;
FriendSongset . insert ( std : : make_pair ( " Mike5 " , " pepolvers " ) ) ;
2008-05-18 16:25:14 -04:00
/* load usr blogs */
2008-05-08 20:27:28 -04:00
2008-05-18 16:25:14 -04:00
/* the usr dummy usr blogs */
2008-05-08 20:27:28 -04:00
std : : string usrBlog = " I think we should eat more cheese " ;
2008-05-08 21:01:13 -04:00
std : : string Blog2 = " today was so cool, i got attacked by fifty ninja while buying a loaf so i used my paper bag to suffocate each of them to death at hyper speed " ;
2008-05-18 16:25:14 -04:00
std : : string Blog3 = " Nuthins up " ;
std : : string Blog4 = " stop bothering me " ;
2008-05-08 20:27:28 -04:00
std : : string Blog5 = " I'm really a boring person and having nothin interesting to say " ;
2008-05-18 16:25:14 -04:00
2008-05-08 20:27:28 -04:00
2008-05-18 16:25:14 -04:00
time_t time1 , time2 , time3 , time4 , time5 ; // times of blogs
2008-05-08 21:01:13 -04:00
2008-05-18 16:25:14 -04:00
/*** populate time/blog multimaps and usrBlog map ****/
std : : multimap < long int , std : : string > timeBlog1 , timeBlog2 , timeBlog3 , timeBlog4 , timeBlog5 ;
2008-05-08 21:01:13 -04:00
timeBlog1 . insert ( std : : make_pair ( time1 , usrBlog ) ) ;
timeBlog2 . insert ( std : : make_pair ( time2 , Blog2 ) ) ;
2008-05-18 16:25:14 -04:00
timeBlog3 . insert ( std : : make_pair ( time3 , Blog3 ) ) ;
timeBlog4 . insert ( std : : make_pair ( time4 , Blog4 ) ) ;
2008-05-08 21:01:13 -04:00
timeBlog5 . insert ( std : : make_pair ( time5 , Blog5 ) ) ;
UsrBlogSet . insert ( std : : make_pair ( " Usr1 " , timeBlog1 ) ) ;
UsrBlogSet . insert ( std : : make_pair ( " Mike2 " , timeBlog2 ) ) ;
2008-05-18 16:25:14 -04:00
UsrBlogSet . insert ( std : : make_pair ( " Mike3 " , timeBlog2 ) ) ;
UsrBlogSet . insert ( std : : make_pair ( " Mike4 " , timeBlog2 ) ) ;
2008-05-08 21:01:13 -04:00
UsrBlogSet . insert ( std : : make_pair ( " Mike5 " , timeBlog5 ) ) ;
2008-05-08 20:27:28 -04:00
}