- Added copy link to GxsFeedItem (GxsChannelPostItem)

- Fixed copy link of GxsGroupFrameDialog
  - utf8 issue
  - removed unread message count from group name

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7476 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-07-26 23:52:45 +00:00
parent 8427c92486
commit 3458cdc8fc
12 changed files with 112 additions and 182 deletions

View File

@ -175,6 +175,11 @@ RsPostedPost &PostedItem::post()
return mPost;
}
QString PostedItem::messageName()
{
return QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
}
void PostedItem::makeDownVote()
{
RsGxsGrpMsgIdPair msgId;

View File

@ -53,6 +53,8 @@ signals:
protected:
virtual void loadMessage(const uint32_t &token);
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_UNKNOWN; }
virtual QString messageName();
private:
void setup();

View File

@ -408,93 +408,37 @@ bool RetroShareLink::createUnknwonSslCertificate(const RsPeerId& sslId, const Rs
return false;
}
bool RetroShareLink::createForum(const std::string& id, const std::string& msgId)
bool RetroShareLink::createGxsGroupLink(const RetroShareLink::enumType &linkType, const RsGxsGroupId &groupId, const QString &groupName)
{
clear();
#if 0
if (!id.empty()) {
_hash = QString::fromStdString(id);
_msgId = QString::fromStdString(msgId);
_type = TYPE_FORUM;
if (msgId.empty()) {
ForumInfo fi;
if (rsForums->getForumInfo(id, fi)) {
_name = QString::fromStdWString(fi.forumName);
}
} else {
ForumMsgInfo mi;
if (rsForums->getForumMessage(id, msgId, mi)) {
_name = ForumsDialog::titleFromInfo(mi);
}
}
if (!groupId.isNull()) {
_hash = QString::fromStdString(groupId.toStdString());
_type = linkType;
_name = groupName;
}
#endif
check();
return valid();
}
bool RetroShareLink::createChannel(const std::string &id, const std::string &msgId)
bool RetroShareLink::createGxsMessageLink(const RetroShareLink::enumType &linkType, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &msgName)
{
clear();
#if 0
if (!id.empty()) {
_hash = QString::fromStdString(id);
_msgId = QString::fromStdString(msgId);
_type = TYPE_CHANNEL;
if (msgId.empty()) {
ChannelInfo ci;
if (rsChannels->getChannelInfo(id, ci)) {
_name = QString::fromStdWString(ci.channelName);
}
} else {
ChannelMsgInfo mi;
if (rsChannels->getChannelMessage(id, msgId, mi)) {
_name = QString::fromStdWString(mi.subject);
}
}
if (!groupId.isNull() && !msgId.isNull()) {
_hash = QString::fromStdString(groupId.toStdString());
_msgId = QString::fromStdString(msgId.toStdString());
_type = linkType;
_name = msgName;
}
#endif
check();
return valid();
}
bool RetroShareLink::createGxsLink(const RsGxsGroupId &id, const RsGxsMessageId &msgId,
const std::string& groupName, const std::string& msgSubject,
const RetroShareLink::enumType &linkType)
{
clear();
if (!id.isNull()) {
_hash = QString::fromStdString(id.toStdString());
if(!msgId.isNull())
_msgId = QString::fromStdString(msgId.toStdString());
_type = linkType;
if (msgId.isNull()) {
_name = QString::fromStdString(groupName);
} else {
_name = QString::fromStdString(msgSubject);
}
}
check();
return valid();
}
bool RetroShareLink::createSearch(const QString& keywords)
{
clear();

View File

@ -56,17 +56,18 @@
class RetroShareLink
{
public:
enum enumType { TYPE_UNKNOWN = 0x00,
TYPE_FILE = 0x01,
TYPE_PERSON = 0x02,
TYPE_FORUM = 0x03,
TYPE_CHANNEL = 0x04,
TYPE_SEARCH = 0x05,
TYPE_MESSAGE = 0x06,
TYPE_CERTIFICATE = 0x07,
TYPE_EXTRAFILE = 0x08,
TYPE_PRIVATE_CHAT = 0x09,
TYPE_PUBLIC_MSG = 0x0a
enum enumType {
TYPE_UNKNOWN = 0x00,
TYPE_FILE = 0x01,
TYPE_PERSON = 0x02,
TYPE_FORUM = 0x03,
TYPE_CHANNEL = 0x04,
TYPE_SEARCH = 0x05,
TYPE_MESSAGE = 0x06,
TYPE_CERTIFICATE = 0x07,
TYPE_EXTRAFILE = 0x08,
TYPE_PRIVATE_CHAT = 0x09,
TYPE_PUBLIC_MSG = 0x0a
};
public:
@ -76,18 +77,15 @@ class RetroShareLink
bool createFile(const QString& name, uint64_t size, const QString& hash);
bool createExtraFile(const QString& name, uint64_t size, const QString& hash, const QString& ssl_id);
bool createPerson(const RsPgpId &id);
bool createForum(const std::string& id, const std::string& msgId);
bool createChannel(const std::string& id, const std::string& msgId);
bool createGxsLink(const RsGxsGroupId &id, const RsGxsMessageId &msgId,
const std::string& groupName, const std::string& msgSubject,
const RetroShareLink::enumType &linkType);
bool createPerson(const RsPgpId &id);
bool createGxsGroupLink(const RetroShareLink::enumType &linkType, const RsGxsGroupId &groupId, const QString &groupName);
bool createGxsMessageLink(const RetroShareLink::enumType &linkType, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &msgName);
bool createSearch(const QString& keywords);
bool createMessage(const RsPeerId &peerId, const QString& subject);
bool createMessage(const RsGxsId &peerId, const QString& subject);
bool createCertificate(const RsPeerId &ssl_id) ;
bool createMessage(const RsPeerId &peerId, const QString& subject);
bool createMessage(const RsGxsId &peerId, const QString& subject);
bool createCertificate(const RsPeerId &ssl_id) ;
bool createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ;
bool createUnknwonSslCertificate(const RsPeerId &sslId, const RsPgpId &gpgId = RsPgpId()) ;
bool createUnknwonSslCertificate(const RsPeerId &sslId, const RsPgpId &gpgId = RsPgpId()) ;
enumType type() const {return _type; }
uint64_t size() const { return _size ; }

View File

@ -297,22 +297,22 @@ QString GroupTreeWidget::itemId(QTreeWidgetItem *item)
return "";
}
return item->data(COLUMN_DATA, ROLE_ID).toString();
}
QString GroupTreeWidget::itemIdAt(QPoint &point)
{
QTreeWidgetItem *item = ui->treeWidget->itemAt(point);
if (item == NULL) {
return "";
}
return item->data(COLUMN_DATA, ROLE_ID).toString();
}
void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<GroupItemInfo> &itemList)
{
if (categoryItem == NULL) {
return item->data(COLUMN_DATA, ROLE_ID).toString();
}
QString GroupTreeWidget::itemIdAt(QPoint &point)
{
QTreeWidgetItem *item = ui->treeWidget->itemAt(point);
if (item == NULL) {
return "";
}
return item->data(COLUMN_DATA, ROLE_ID).toString();
}
void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<GroupItemInfo> &itemList)
{
if (categoryItem == NULL) {
return;
}
@ -423,7 +423,6 @@ void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount)
item->setText(COLUMN_NAME, name);
item->setFont(COLUMN_NAME, font);
}
QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id)
@ -467,19 +466,16 @@ RSTreeWidget *GroupTreeWidget::treeWidget()
return ui->treeWidget;
}
bool GroupTreeWidget::getGroupName(QString id, QTreeWidgetItem* categoryItem, QString& name)
bool GroupTreeWidget::getGroupName(QString id, QString& name)
{
int childCount = categoryItem->childCount();
for (int child = 0; child < childCount; child++) {
QTreeWidgetItem *childItem = categoryItem->child(child);
if (childItem->data(COLUMN_DATA, ROLE_ID).toString() == id) {
/* Found child */
QTreeWidgetItem *item = getItemFromId(id);
if (item == NULL) {
return false;
}
name = childItem->text(COLUMN_NAME);
return true;
}
}
return false;
name = item->data(COLUMN_DATA, ROLE_NAME).toString();
return true;
}
int GroupTreeWidget::subscribeFlags(const QString &id)

View File

@ -80,13 +80,13 @@ public:
void processSettings(RshareSettings *settings, bool load);
// Add a new category item
QTreeWidgetItem *addCategoryItem(const QString &name, const QIcon &icon, bool expand);
// Get id of item
QString itemId(QTreeWidgetItem *item);
QString itemIdAt(QPoint &point);
// Fill items of a group
void fillGroupItems(QTreeWidgetItem *categoryItem, const QList<GroupItemInfo> &itemList);
// Set the unread count of an item
QTreeWidgetItem *addCategoryItem(const QString &name, const QIcon &icon, bool expand);
// Get id of item
QString itemId(QTreeWidgetItem *item);
QString itemIdAt(QPoint &point);
// Fill items of a group
void fillGroupItems(QTreeWidgetItem *categoryItem, const QList<GroupItemInfo> &itemList);
// Set the unread count of an item
void setUnreadCount(QTreeWidgetItem *item, int unreadCount);
QTreeWidgetItem *getItemFromId(const QString &id);
@ -99,7 +99,7 @@ public:
void setTextColorCategory(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_CATEGORY] = color; }
void setTextColorPrivateKey(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_PRIVATEKEY] = color; }
bool getGroupName(QString id, QTreeWidgetItem* item, QString& name);
bool getGroupName(QString id, QString& name);
int subscribeFlags(const QString &id);

View File

@ -189,11 +189,11 @@ void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post)
{
title = tr("Channel Feed") + ": ";
RetroShareLink link;
link.createChannel(post.mMeta.mGroupId.toStdString(), "");
link.createGxsGroupLink(RetroShareLink::TYPE_CHANNEL, post.mMeta.mGroupId, "");
title += link.toHtml();
ui->titleLabel->setText(title);
RetroShareLink msgLink;
msgLink.createChannel(post.mMeta.mGroupId.toStdString(), post.mMeta.mMsgId.toStdString());
msgLink.createGxsMessageLink(RetroShareLink::TYPE_CHANNEL, post.mMeta.mGroupId, post.mMeta.mMsgId, QString::fromUtf8(post.mMeta.mMsgName.c_str()));
ui->subjectLabel->setText(msgLink.toHtml());
if (IS_GROUP_SUBSCRIBED(mSubscribeFlags) || IS_GROUP_ADMIN(mSubscribeFlags))
@ -314,6 +314,11 @@ void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post)
mInUpdateItemStatic = false;
}
QString GxsChannelPostItem::messageName()
{
return QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
}
void GxsChannelPostItem::setReadStatus(bool isNew, bool isUnread)
{
if (isUnread)
@ -536,25 +541,6 @@ void GxsChannelPostItem::channelMsgReadSatusChanged(const QString& channelId, co
#endif
}
void GxsChannelPostItem::copyLink()
{
#if 0
if (mChanId.empty() || mMsgId.empty()) {
return;
}
ChannelMsgInfo cmi;
if (rsChannels->getChannelMessage(mChanId, mMsgId, cmi)) {
RetroShareLink link;
if (link.createChannel(cmi.channelId, cmi.msgId)) {
QList<RetroShareLink> urls;
urls.push_back(link);
RSLinkClipboard::copyLinks(urls);
}
}
#endif
}
void GxsChannelPostItem::makeDownVote()
{
RsGxsGrpMsgIdPair msgId;

View File

@ -55,6 +55,8 @@ public:
protected:
virtual void loadMessage(const uint32_t &token);
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_CHANNEL; }
virtual QString messageName();
private slots:
/* default stuff */
@ -62,7 +64,6 @@ private slots:
void readAndClearItem();
void download();
void play();
void copyLink();
void loadComments();
void readToggled(bool checked);

View File

@ -97,6 +97,24 @@ void GxsFeedItem::subscribe()
}
}
void GxsFeedItem::copyLink()
{
if (mGroupId.isNull() || mMessageId.isNull()) {
return;
}
if (getLinkType() == RetroShareLink::TYPE_UNKNOWN) {
return;
}
RetroShareLink link;
if (link.createGxsMessageLink(getLinkType(), mGroupId, mMessageId, messageName())) {
QList<RetroShareLink> urls;
urls.push_back(link);
RSLinkClipboard::copyLinks(urls);
}
}
void GxsFeedItem::updateItemStatic()
{
std::cerr << "GxsFeedItem::updateItemStatic()";

View File

@ -26,6 +26,8 @@
#include <retroshare/rsgxsifacehelper.h>
#include "util/TokenQueue.h"
#include "gui/RetroShareLink.h"
#include <stdint.h>
class FeedHolder;
@ -54,6 +56,9 @@ protected:
virtual void loadGroupMeta(const uint32_t &token);
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
virtual RetroShareLink::enumType getLinkType() = 0;
virtual QString messageName() = 0;
// general fns that can be implemented here.
protected slots:
@ -61,6 +66,7 @@ protected slots:
void subscribe();
void unsubscribe();
void removeItem();
void copyLink();
private slots:
/* RsGxsUpdateBroadcastBase */
@ -85,4 +91,3 @@ private:
};
#endif

View File

@ -386,48 +386,23 @@ void GxsGroupFrameDialog::copyGroupLink()
return;
}
RetroShareLink link;
RetroShareLink link;
QString name;
if(!getCurrentGroupName(name)) return;
QString name;
if(!getCurrentGroupName(name)) return;
if (link.createGxsLink(mGroupId, RsGxsMessageId(), name.toStdString(), "", getLinkType())) {
QList<RetroShareLink> urls;
urls.push_back(link);
RSLinkClipboard::copyLinks(urls);
}
if (link.createGxsGroupLink(getLinkType(), mGroupId, name)) {
QList<RetroShareLink> urls;
urls.push_back(link);
RSLinkClipboard::copyLinks(urls);
}
}
bool GxsGroupFrameDialog::getCurrentGroupName(QString& name)
{
GroupTreeWidget* gtw = ui->groupTreeWidget;
QString id = QString::fromStdString(mGroupId.toStdString());
if(gtw->getGroupName(id, mYourGroups, name))
{
return true;
}
else if(gtw->getGroupName(id, mSubscribedGroups, name))
{
return true;
}
else if(gtw->getGroupName(id, mYourGroups, name))
{
return true;
}
else if(gtw->getGroupName(id, mOtherGroups, name))
{
return true;
}
return false;
return ui->groupTreeWidget->getGroupName(QString::fromStdString(mGroupId.toStdString()), name);
}
void GxsGroupFrameDialog::markMsgAsRead()
{
GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId, false);

View File

@ -73,7 +73,7 @@ public:
GxsGroupFrameDialog(RsGxsIfaceHelper *ifaceImpl, QWidget *parent = 0);
~GxsGroupFrameDialog();
bool navigate(const RsGxsGroupId groupId, const RsGxsMessageId& msgId);
bool navigate(const RsGxsGroupId groupId, const RsGxsMessageId& msgId);
// Callback for all Loads.
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);