2008-04-24 09:14:58 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Robert Fernie
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
#include <QtGui>
|
|
|
|
|
|
|
|
#include "BlogDialog.h"
|
2008-05-12 14:27:15 -04:00
|
|
|
|
2008-06-24 00:36:45 -04:00
|
|
|
#include "GeneralMsgDialog.h"
|
|
|
|
|
2008-05-10 08:16:34 -04:00
|
|
|
#include "rsiface/rsQblog.h"
|
2008-05-18 16:22:08 -04:00
|
|
|
#include "rsiface/rspeers.h" //to retrieve peer/usrId info
|
2008-04-24 09:14:58 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
#include "gui/feeds/BlogMsgItem.h"
|
|
|
|
|
2008-06-08 14:34:27 -04:00
|
|
|
|
2008-04-24 09:14:58 -04:00
|
|
|
/** Constructor */
|
|
|
|
BlogDialog::BlogDialog(QWidget *parent)
|
|
|
|
: MainPage (parent)
|
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
2008-06-20 08:43:23 -04:00
|
|
|
setupUi(this);
|
2008-04-24 09:14:58 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
connect(postButton, SIGNAL(clicked()), this, SLOT(postBlog()));
|
2008-06-08 14:34:27 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
/* mLayout -> to add widgets to */
|
|
|
|
mLayout = new QVBoxLayout;
|
2008-06-08 14:34:27 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
QWidget *middleWidget = new QWidget();
|
|
|
|
middleWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
|
|
|
|
middleWidget->setLayout(mLayout);
|
2008-06-08 14:34:27 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
QScrollArea *scrollArea = new QScrollArea;
|
|
|
|
scrollArea->setBackgroundRole(QPalette::Dark);
|
|
|
|
scrollArea->setWidget(middleWidget);
|
|
|
|
scrollArea->setWidgetResizable(true);
|
|
|
|
scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
2008-06-08 14:34:27 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
QVBoxLayout *layout2 = new QVBoxLayout;
|
|
|
|
layout2->addWidget(scrollArea);
|
|
|
|
|
|
|
|
frame->setLayout(layout2);
|
|
|
|
|
|
|
|
addDummyData();
|
2008-06-08 14:34:27 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
updateBlogsStatic();
|
2008-06-08 14:34:27 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
QTimer *timer = new QTimer(this);
|
|
|
|
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateBlogs()));
|
|
|
|
timer->start(15631);
|
2008-06-08 14:34:27 -04:00
|
|
|
|
2008-04-29 15:19:07 -04:00
|
|
|
}
|
|
|
|
|
2008-05-04 12:40:39 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
void BlogDialog::updateBlogs(void)
|
2008-05-04 12:40:39 -04:00
|
|
|
{
|
2008-06-04 06:48:30 -04:00
|
|
|
|
2008-05-04 12:40:39 -04:00
|
|
|
}
|
2008-05-18 16:22:08 -04:00
|
|
|
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
void BlogDialog::updateBlogsStatic(void)
|
2008-06-09 09:23:53 -04:00
|
|
|
{
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
#if 0
|
2008-06-04 06:48:30 -04:00
|
|
|
rsQblog->getFilterSwitch();
|
|
|
|
|
|
|
|
std::map<std::string, std::string> UsrStatus;
|
|
|
|
|
|
|
|
if(!rsQblog->getStatus(UsrStatus))
|
|
|
|
std::cerr << "failed to get usr status" << std::endl;
|
|
|
|
|
2008-05-18 16:22:08 -04:00
|
|
|
clear(); //create a clear screen
|
|
|
|
|
|
|
|
/* retrieve usr names and populate usr list bar */
|
2008-05-04 12:40:39 -04:00
|
|
|
|
2008-05-18 16:22:08 -04:00
|
|
|
std::list<std::string> usrList;
|
|
|
|
QString TempVar; // to convert numerics to string note: tbd find way to avoid temporary
|
|
|
|
|
2008-06-04 06:48:30 -04:00
|
|
|
if (!rsPeers)
|
|
|
|
{
|
|
|
|
/* not ready yet! */
|
|
|
|
return;
|
|
|
|
}
|
2008-05-18 16:22:08 -04:00
|
|
|
|
2008-06-04 06:48:30 -04:00
|
|
|
if(!rsPeers->getFriendList(usrList))
|
2008-05-18 16:22:08 -04:00
|
|
|
std::cerr << "failed to get friend list";
|
|
|
|
|
|
|
|
|
2008-06-04 06:48:30 -04:00
|
|
|
usrList.push_back(rsPeers->getOwnId()); // add your id
|
|
|
|
|
2008-05-18 16:22:08 -04:00
|
|
|
/* populate the blog msgs screen */
|
|
|
|
|
|
|
|
std::map< std::string, std::multimap<long int, std::string> > blogs; // to store blogs
|
|
|
|
|
|
|
|
if(!rsQblog->getBlogs(blogs))
|
2008-06-04 06:48:30 -04:00
|
|
|
std::cerr << "failed to get blogs" << std::endl;
|
2008-05-18 16:22:08 -04:00
|
|
|
|
|
|
|
/* print usr name and their blogs to screen */
|
|
|
|
for(std::list<std::string>::iterator it = usrList.begin(); it !=usrList.end(); it++)
|
|
|
|
{
|
2008-06-09 09:23:53 -04:00
|
|
|
|
|
|
|
|
2008-06-04 06:48:30 -04:00
|
|
|
TempVar = rsPeers->getPeerName(*it).c_str(); // store usr name in temporary
|
2008-05-18 16:22:08 -04:00
|
|
|
blogText->setTextColor(QColor(255, 0, 0, 255));
|
|
|
|
blogText->setCurrentFont(mUsrFont); // make bold for username
|
|
|
|
blogText->append("\n" + TempVar); // write usr name to screen
|
2008-06-04 06:48:30 -04:00
|
|
|
std::cerr << "creating usr tree" << std::endl;
|
2008-05-18 16:22:08 -04:00
|
|
|
|
|
|
|
/*print blog time-posted/msgs to screen*/
|
|
|
|
|
|
|
|
std::multimap<long int, std::string>::reverse_iterator blogIt = blogs[*it].rbegin();
|
|
|
|
|
2008-05-24 19:11:37 -04:00
|
|
|
if(blogs[*it].empty())
|
2008-06-04 06:48:30 -04:00
|
|
|
{
|
|
|
|
std::cerr << "usr blog empty!" << std::endl;
|
2008-05-18 16:22:08 -04:00
|
|
|
continue;
|
2008-06-04 06:48:30 -04:00
|
|
|
}
|
2008-05-18 16:22:08 -04:00
|
|
|
|
|
|
|
for( ; blogIt != blogs[*it].rend(); blogIt++)
|
|
|
|
{
|
2008-06-04 06:48:30 -04:00
|
|
|
std::cerr << "now printing blogs" << std::endl;
|
2008-05-18 16:22:08 -04:00
|
|
|
time_t postedTime = blogIt->first;
|
|
|
|
time(&postedTime); //convert to human readable time
|
|
|
|
blogText->setTextColor(QColor(255, 0, 0, 255)); //
|
|
|
|
blogText->setCurrentFont(mUsrFont); // make bold for posted date
|
|
|
|
blogText->append("\nPosted: " + QString (ctime(&postedTime))); // print time of blog to screen
|
|
|
|
blogText->setCurrentFont(mCurrentFont); // reset the font for blog messages
|
|
|
|
blogText->setTextColor(QColor(0, 0, 0, 255)); // set back color to black
|
|
|
|
blogText->append(blogIt->second.c_str()); // print blog msg to screen
|
2008-06-04 06:48:30 -04:00
|
|
|
}
|
|
|
|
|
2008-05-18 16:22:08 -04:00
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-05-18 16:22:08 -04:00
|
|
|
}
|
2008-04-29 15:19:07 -04:00
|
|
|
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
void BlogDialog::addDummyData()
|
2008-06-09 09:23:53 -04:00
|
|
|
{
|
2008-06-20 08:43:23 -04:00
|
|
|
BlogMsgItem *bm1 = new BlogMsgItem(this, 0, "peerId", "msgId", true);
|
|
|
|
BlogMsgItem *bm2 = new BlogMsgItem(this, 0, "peerId", "msgId", true);
|
|
|
|
BlogMsgItem *bm3 = new BlogMsgItem(this, 0, "peerId", "msgId", true);
|
|
|
|
BlogMsgItem *bm4 = new BlogMsgItem(this, 0, "peerId", "msgId", true);
|
|
|
|
BlogMsgItem *bm5 = new BlogMsgItem(this, 0, "peerId", "msgId", true);
|
|
|
|
|
|
|
|
mLayout->addWidget(bm1);
|
|
|
|
mLayout->addWidget(bm2);
|
|
|
|
mLayout->addWidget(bm3);
|
|
|
|
mLayout->addWidget(bm4);
|
|
|
|
mLayout->addWidget(bm5);
|
|
|
|
}
|
2008-06-09 09:23:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
/* FeedHolder Functions (for FeedItem functionality) */
|
|
|
|
void BlogDialog::deleteFeedItem(QWidget *item, uint32_t type)
|
|
|
|
{
|
|
|
|
std::cerr << "BlogDialog::deleteFeedItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
2008-06-09 09:23:53 -04:00
|
|
|
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
void BlogDialog::openChat(std::string peerId)
|
|
|
|
{
|
|
|
|
std::cerr << "BlogDialog::openChat()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
2008-06-09 09:23:53 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
void BlogDialog::postBlog()
|
|
|
|
{
|
|
|
|
openMsg(FEEDHOLDER_MSG_BLOG, "", "");
|
2008-06-09 09:23:53 -04:00
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
void BlogDialog::openMsg(uint32_t type, std::string grpId, std::string inReplyTo)
|
|
|
|
{
|
2008-06-24 00:36:45 -04:00
|
|
|
std::cerr << "BlogDialog::openMsg()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
GeneralMsgDialog *msgDialog = new GeneralMsgDialog(NULL);
|
|
|
|
|
|
|
|
|
|
|
|
msgDialog->addDestination(type, grpId, inReplyTo);
|
|
|
|
|
|
|
|
msgDialog->show();
|
|
|
|
return;
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
2008-04-29 15:19:07 -04:00
|
|
|
|
|
|
|
|