added BlogDetails to Blogs, added context menu actions for subscribe/unsubscribe

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2463 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2010-02-28 21:26:46 +00:00
parent 0a25b291f3
commit 323b96cc04
6 changed files with 433 additions and 42 deletions

View File

@ -515,17 +515,20 @@ DEPENDPATH += gui/unfinished \
HEADERS += gui/unfinished/blogs/BlogsDialog.h \
gui/unfinished/blogs/CreateBlog.h \
gui/unfinished/blogs/CreateBlogMsg.h \
gui/unfinished/blogs/BlogsMsgItem.h
gui/unfinished/blogs/BlogsMsgItem.h \
gui/unfinished/blogs/BlogDetails.h
FORMS += gui/unfinished/blogs/BlogsDialog.ui \
gui/unfinished/blogs/CreateBlog.ui \
gui/unfinished/blogs/CreateBlogMsg.ui \
gui/unfinished/blogs/BlogsMsgItem.ui
gui/unfinished/blogs/BlogsMsgItem.ui \
gui/unfinished/blogs/BlogDetails.ui
SOURCES += gui/unfinished/blogs/BlogsDialog.cpp \
gui/unfinished/blogs/CreateBlog.cpp \
gui/unfinished/blogs/CreateBlogMsg.cpp \
gui/unfinished/blogs/BlogsMsgItem.cpp
gui/unfinished/blogs/BlogsMsgItem.cpp \
gui/unfinished/blogs/BlogDetails.cpp
DEFINES *= BLOGS
}

View File

@ -0,0 +1,146 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2009 RetroShare Team
*
* 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 "BlogDetails.h"
#include "rsiface/rsiface.h"
#include "rsiface/rspeers.h"
#include "rsiface/rsdisc.h"
#include "rsiface/rsblogs.h"
#include <QTime>
#include <QDateTime>
#include <sstream>
#include <list>
#include <iostream>
#include <string>
/** Default constructor */
BlogDetails::BlogDetails(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
/* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this);
connect(ui.applyButton, SIGNAL(clicked()), this, SLOT(applyDialog()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(closeinfodlg()));
ui.applyButton->setToolTip(tr("Close"));
ui.nameline ->setReadOnly(true);
ui.popline ->setReadOnly(true);
ui.postline ->setReadOnly(true);
ui.IDline ->setReadOnly(true);
ui.DescriptiontextEdit ->setReadOnly(true);
}
/** Overloads the default show() */
void
BlogDetails::show()
{
if(!this->isVisible()) {
QDialog::show();
}
}
void BlogDetails::closeEvent (QCloseEvent * event)
{
QWidget::closeEvent(event);
}
void BlogDetails::closeinfodlg()
{
close();
}
void BlogDetails::showDetails(std::string mBlogId)
{
bId = mBlogId;
loadBlog();
}
void BlogDetails::loadBlog()
{
if (!rsBlogs)
{
return;
}
std::list<BlogInfo> channelList;
std::list<BlogInfo>::iterator it;
BlogInfo bi;
rsBlogs->getBlogInfo(bId, bi);
rsBlogs->getBlogList(channelList);
for(it = channelList.begin(); it != channelList.end(); it++)
{
// Set Blog Name
ui.nameline->setText(QString::fromStdWString(bi.blogName));
// Set Blog Popularity
{
std::ostringstream out;
out << it->pop;
ui.popline -> setText(QString::fromStdString(out.str()));
}
// Set Last Blog Post Date
{
QDateTime qtime;
qtime.setTime_t(it->lastPost);
QString timestamp = qtime.toString("yyyy-MM-dd hh:mm:ss");
ui.postline -> setText(timestamp);
}
// Set Blog ID
ui.IDline->setText(QString::fromStdString(bi.blogId));
// Set Blog Description
ui.DescriptiontextEdit->setText(QString::fromStdWString(bi.blogDesc));
}
}
void BlogDetails::applyDialog()
{
/* reload now */
loadBlog();
/* close the Dialog after the Changes applied */
closeinfodlg();
}

View File

@ -0,0 +1,68 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2009 RetroShare Team
*
* 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.
****************************************************************/
#ifndef _BLOGDETAILS_H
#define _BLOGDETAILS_H
#include <QDialog>
#include "ui_BlogDetails.h"
class BlogDetails : public QDialog
{
Q_OBJECT
public:
/** Default constructor */
BlogDetails(QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default destructor */
void showDetails(std::string mChannelId);
signals:
void configChanged() ;
public slots:
/** Overloaded QWidget.show */
void show();
protected:
void closeEvent (QCloseEvent * event);
private slots:
void closeinfodlg();
void applyDialog();
private:
void loadBlog();
std::string bId;
/** Qt Designer generated object */
Ui::BlogDetails ui;
};
#endif

View File

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BlogDetails</class>
<widget class="QDialog" name="BlogDetails">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>436</width>
<height>355</height>
</rect>
</property>
<property name="windowTitle">
<string>Blog Details</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTabWidget" name="stabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="icon">
<iconset>
<normaloff>:/images/info16.png</normaloff>:/images/info16.png</iconset>
</attribute>
<attribute name="title">
<string>Blogl Details</string>
</attribute>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Blog Info</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Blog Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameline"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Popularity</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="popline">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Last Post</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="postline">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Blog ID</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="IDline"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Blog Description</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTextEdit" name="DescriptiontextEdit"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="_2">
<item row="0" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>311</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="applyButton">
<property name="text">
<string>OK</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -37,6 +37,7 @@
#include "BlogsMsgItem.h"
#include "CreateBlog.h"
#include "CreateBlogMsg.h"
#include "BlogDetails.h"
#include "gui/ChanGroupDelegate.h"
#include "gui/GeneralMsgDialog.h"
@ -54,7 +55,6 @@ BlogsDialog::BlogsDialog(QWidget *parent)
connect(subscribeButton, SIGNAL( clicked( void ) ), this, SLOT( subscribeBlog ( void ) ) );
connect(unsubscribeButton, SIGNAL( clicked( void ) ), this, SLOT( unsubscribeBlog ( void ) ) );
mBlogId = "";
mPeerId = rsPeers->getOwnId(); // add your id
@ -122,11 +122,39 @@ void BlogsDialog::blogListCustomPopupMenu( QPoint point )
QMenu contextMnu( this );
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
QAction *subscribeblogAct = new QAction(QIcon(":/images/edit_add24.png"), tr( "Subscribe to Blog" ), this );
connect( subscribeblogAct , SIGNAL( triggered() ), this, SLOT( subscribeBlog() ) );
QAction *unsubscribeblogAct = new QAction(QIcon(":/images/cancel.png"), tr( "Unsubscribe to Blog" ), this );
connect( unsubscribeblogAct , SIGNAL( triggered() ), this, SLOT( unsubscribeBlog() ) );
QAction *blogdetailsAct = new QAction(QIcon(":/images/info16.png"), tr( "Show Blog Details" ), this );
connect( blogdetailsAct , SIGNAL( triggered() ), this, SLOT( showBlogDetails() ) );
contextMnu.clear();
contextMnu.addAction( blogdetailsAct );
BlogInfo bi;
if (!rsBlogs->getBlogInfo(mBlogId, bi))
{
return;
}
if (bi.blogFlags & RS_DISTRIB_PUBLISH)
{
contextMnu.addAction( blogdetailsAct );
}
else if (bi.blogFlags & RS_DISTRIB_SUBSCRIBED)
{
contextMnu.addAction( unsubscribeblogAct );
contextMnu.addSeparator();
contextMnu.addAction( blogdetailsAct );;
}
else
{
contextMnu.addAction( subscribeblogAct );
contextMnu.addSeparator();
contextMnu.addAction( blogdetailsAct );
}
contextMnu.exec( mevent->globalPos() );
@ -181,7 +209,6 @@ void BlogsDialog::openMsg(uint32_t type, std::string grpId, std::string inReplyT
return;
}
void BlogsDialog::createMsg()
{
if (mBlogId == "")
@ -195,9 +222,9 @@ void BlogsDialog::createMsg()
return;
}
void BlogsDialog::selectBlog( std::string cId)
void BlogsDialog::selectBlog( std::string bId)
{
mBlogId = cId;
mBlogId = bId;
updateBlogMsgs();
}
@ -235,7 +262,6 @@ void BlogsDialog::checkUpdate()
}
}
void BlogsDialog::updateBlogList()
{
@ -341,12 +367,12 @@ void BlogsDialog::updateBlogListOwn(std::list<std::string> &ids)
QStandardItem *item1 = new QStandardItem();
QStandardItem *item2 = new QStandardItem();
BlogInfo ci;
if (rsBlogs && rsBlogs->getBlogInfo(*iit, ci)) {
item1->setData(QVariant(QString::fromStdWString(ci.blogName)), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(ci.blogId)), Qt::DisplayRole);
BlogInfo bi;
if (rsBlogs && rsBlogs->getBlogInfo(*iit, bi)) {
item1->setData(QVariant(QString::fromStdWString(bi.blogName)), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(bi.blogId)), Qt::DisplayRole);
item1->setToolTip(tr("Popularity: %1\nFetches: %2\nAvailable: %3"
).arg(QString::number(ci.pop)).arg(9999).arg(9999));
).arg(QString::number(bi.pop)).arg(9999).arg(9999));
} else {
item1->setData(QVariant(QString("Unknown Blog")), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(*iit)), Qt::DisplayRole);
@ -375,12 +401,12 @@ void BlogsDialog::updateBlogListSub(std::list<std::string> &ids)
QStandardItem *item1 = new QStandardItem();
QStandardItem *item2 = new QStandardItem();
BlogInfo ci;
if (rsBlogs && rsBlogs->getBlogInfo(*iit, ci)) {
item1->setData(QVariant(QString::fromStdWString(ci.blogName)), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(ci.blogId)), Qt::DisplayRole);
BlogInfo bi;
if (rsBlogs && rsBlogs->getBlogInfo(*iit, bi)) {
item1->setData(QVariant(QString::fromStdWString(bi.blogName)), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(bi.blogId)), Qt::DisplayRole);
item1->setToolTip(tr("Popularity: %1\nFetches: %2\nAvailable: %3"
).arg(QString::number(ci.pop)).arg(9999).arg(9999));
).arg(QString::number(bi.pop)).arg(9999).arg(9999));
} else {
item1->setData(QVariant(QString("Unknown Blog")), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(*iit)), Qt::DisplayRole);
@ -410,12 +436,12 @@ void BlogsDialog::updateBlogListPop(std::list<std::string> &ids)
QStandardItem *item1 = new QStandardItem();
QStandardItem *item2 = new QStandardItem();
BlogInfo ci;
if (rsBlogs && rsBlogs->getBlogInfo(*iit, ci)) {
item1->setData(QVariant(QString::fromStdWString(ci.blogName)), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(ci.blogId)), Qt::DisplayRole);
BlogInfo bi;
if (rsBlogs && rsBlogs->getBlogInfo(*iit, bi)) {
item1->setData(QVariant(QString::fromStdWString(bi.blogName)), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(bi.blogId)), Qt::DisplayRole);
item1->setToolTip(tr("Popularity: %1\nFetches: %2\nAvailable: %3"
).arg(QString::number(ci.pop)).arg(9999).arg(9999));
).arg(QString::number(bi.pop)).arg(9999).arg(9999));
} else {
item1->setData(QVariant(QString("Unknown Blog")), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(*iit)), Qt::DisplayRole);
@ -444,12 +470,12 @@ void BlogsDialog::updateBlogListOther(std::list<std::string> &ids)
QStandardItem *item1 = new QStandardItem();
QStandardItem *item2 = new QStandardItem();
BlogInfo ci;
if (rsBlogs && rsBlogs->getBlogInfo(*iit, ci)) {
item1->setData(QVariant(QString::fromStdWString(ci.blogName)), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(ci.blogId)), Qt::DisplayRole);
BlogInfo bi;
if (rsBlogs && rsBlogs->getBlogInfo(*iit, bi)) {
item1->setData(QVariant(QString::fromStdWString(bi.blogName)), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(bi.blogId)), Qt::DisplayRole);
item1->setToolTip(tr("Popularity: %1\nFetches: %2\nAvailable: %3"
).arg(QString::number(ci.pop)).arg(9999).arg(9999));
).arg(QString::number(bi.pop)).arg(9999).arg(9999));
} else {
item1->setData(QVariant(QString("Unknown Blog")), Qt::DisplayRole);
item2->setData(QVariant(QString::fromStdString(*iit)), Qt::DisplayRole);
@ -467,8 +493,8 @@ void BlogsDialog::updateBlogMsgs()
if (!rsBlogs)
return;
BlogInfo ci;
if (!rsBlogs->getBlogInfo(mBlogId, ci))
BlogInfo bi;
if (!rsBlogs->getBlogInfo(mBlogId, bi))
{
postButton->setEnabled(false);
subscribeButton->setEnabled(false);
@ -485,11 +511,11 @@ void BlogsDialog::updateBlogMsgs()
"color:white;\">%1</span>");
/* set Blog name */
QString bname = QString::fromStdWString(ci.blogName);
QString bname = QString::fromStdWString(bi.blogName);
nameLabel->setText(blogStr.arg(bname));
/* do buttons */
if (ci.blogFlags & RS_DISTRIB_SUBSCRIBED)
if (bi.blogFlags & RS_DISTRIB_SUBSCRIBED)
{
subscribeButton->setEnabled(false);
unsubscribeButton->setEnabled(true);
@ -500,7 +526,7 @@ void BlogsDialog::updateBlogMsgs()
unsubscribeButton->setEnabled(false);
}
if (ci.blogFlags & RS_DISTRIB_PUBLISH)
if (bi.blogFlags & RS_DISTRIB_PUBLISH)
{
postButton->setEnabled(true);
}
@ -531,7 +557,6 @@ void BlogsDialog::updateBlogMsgs()
}
}
void BlogsDialog::unsubscribeBlog()
{
#ifdef BLOG_DEBUG
@ -545,7 +570,6 @@ void BlogsDialog::unsubscribeBlog()
updateBlogMsgs();
}
void BlogsDialog::subscribeBlog()
{
#ifdef BLOG_DEBUG
@ -559,7 +583,6 @@ void BlogsDialog::subscribeBlog()
updateBlogMsgs();
}
void BlogsDialog::toggleSelection(const QModelIndex &index)
{
QItemSelectionModel *selectionModel = treeView->selectionModel();
@ -577,9 +600,9 @@ void BlogsDialog::showBlogDetails()
if (!rsBlogs)
return;
//static BlogDetails *blogui = new BlogDetails();
static BlogDetails *blogui = new BlogDetails();
//blogui->showDetails(mBlogId);
//blogui->show();
blogui->showDetails(mBlogId);
blogui->show();
}

View File

@ -87,7 +87,7 @@ private:
QStandardItemModel *model;
std::string mBlogId; /* current Channel */
std::string mBlogId; /* current Blog */
std::string mPeerId;
/* Layout Pointers */