2013-03-11 16:53:15 -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.
|
|
|
|
****************************************************************/
|
|
|
|
|
2015-07-06 20:52:52 -04:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
|
|
#include <retroshare/rsfiles.h>
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
#include "GxsChannelDialog.h"
|
2014-05-04 18:59:06 -04:00
|
|
|
#include "GxsChannelGroupDialog.h"
|
|
|
|
#include "GxsChannelPostsWidget.h"
|
2017-10-21 17:48:27 -04:00
|
|
|
#include "CreateGxsChannelMsg.h"
|
2014-07-06 06:32:13 -04:00
|
|
|
#include "GxsChannelUserNotify.h"
|
2014-10-13 14:31:47 -04:00
|
|
|
#include "gui/gxs/GxsGroupShareKey.h"
|
2014-05-07 20:00:21 -04:00
|
|
|
#include "gui/feeds/GxsChannelPostItem.h"
|
2014-05-08 13:17:48 -04:00
|
|
|
#include "gui/settings/rsharesettings.h"
|
|
|
|
#include "gui/notifyqt.h"
|
2014-09-11 18:07:06 -04:00
|
|
|
#include "gui/common/GroupTreeWidget.h"
|
|
|
|
|
|
|
|
class GxsChannelGroupInfoData : public RsUserdata
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GxsChannelGroupInfoData() : RsUserdata() {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
QMap<RsGxsGroupId, QIcon> mIcon;
|
2014-12-27 17:13:29 -05:00
|
|
|
QMap<RsGxsGroupId, QString> mDescription;
|
2014-09-11 18:07:06 -04:00
|
|
|
};
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
GxsChannelDialog::GxsChannelDialog(QWidget *parent)
|
2014-05-07 20:00:21 -04:00
|
|
|
: GxsGroupFrameDialog(rsGxsChannels, parent)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GxsChannelDialog::~GxsChannelDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-10 17:38:43 -04:00
|
|
|
QString GxsChannelDialog::getHelpString() const
|
|
|
|
{
|
2015-06-30 12:44:58 -04:00
|
|
|
QString hlp_str = tr("<h1><img width=\"32\" src=\":/icons/help_64.png\"> Channels</h1> \
|
2014-09-10 17:38:43 -04:00
|
|
|
<p>Channels allow you to post data (e.g. movies, music) that will spread in the network</p> \
|
|
|
|
<p>You can see the channels your friends are subscribed to, and you automatically forward subscribed channels to \
|
|
|
|
your friends. This promotes good channels in the network.</p>\
|
|
|
|
<p>Only the channel's creator can post on that channel. Other peers \
|
|
|
|
in the network can only read from it, unless the channel is private. You can however share \
|
|
|
|
the posting rights or the reading rights with friend Retroshare nodes.</p>\
|
|
|
|
<p>Channels can be made anonymous, or attached to a Retroshare identity so that readers can contact you if needed.\
|
|
|
|
Enable \"Allow Comments\" if you want to let users comment on your posts.</p>\
|
2016-12-05 16:14:48 -05:00
|
|
|
<p>Channel posts are kept for %1 days, and sync-ed over the last %2 days, unless you change this.</p>\
|
|
|
|
").arg(QString::number(rsGxsChannels->getDefaultStoragePeriod()/86400)).arg(QString::number(rsGxsChannels->getDefaultSyncPeriod()/86400));
|
2015-05-02 14:48:10 -04:00
|
|
|
|
2014-09-10 17:38:43 -04:00
|
|
|
return hlp_str ;
|
|
|
|
}
|
|
|
|
|
2014-07-06 06:32:13 -04:00
|
|
|
UserNotify *GxsChannelDialog::getUserNotify(QObject *parent)
|
|
|
|
{
|
|
|
|
return new GxsChannelUserNotify(rsGxsChannels, parent);
|
|
|
|
}
|
2014-05-08 13:17:48 -04:00
|
|
|
|
2017-10-21 17:48:27 -04:00
|
|
|
void GxsChannelDialog::shareOnChannel(const RsGxsGroupId& channel_id,const QList<RetroShareLink>& file_links)
|
2017-10-21 15:23:40 -04:00
|
|
|
{
|
|
|
|
std::cerr << "Sharing file link on channel " << channel_id << ": Not yet implemented!" << std::endl;
|
2017-10-21 17:48:27 -04:00
|
|
|
|
|
|
|
CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(channel_id) ;
|
|
|
|
|
|
|
|
QString txt ;
|
|
|
|
for(QList<RetroShareLink>::const_iterator it(file_links.begin());it!=file_links.end();++it)
|
|
|
|
txt += (*it).toHtml() + "\n" ;
|
|
|
|
|
|
|
|
msgDialog->addHtmlText(txt);
|
|
|
|
msgDialog->show();
|
2017-10-21 15:23:40 -04:00
|
|
|
}
|
|
|
|
|
2014-05-04 18:59:06 -04:00
|
|
|
QString GxsChannelDialog::text(TextType type)
|
2013-03-24 12:29:08 -04:00
|
|
|
{
|
2014-05-04 18:59:06 -04:00
|
|
|
switch (type) {
|
|
|
|
case TEXT_NAME:
|
|
|
|
return tr("Channels");
|
|
|
|
case TEXT_NEW:
|
|
|
|
return tr("Create Channel");
|
|
|
|
case TEXT_TODO:
|
|
|
|
return "<b>Open points:</b><ul>"
|
|
|
|
"<li>Restore channel keys"
|
|
|
|
"</ul>";
|
2013-03-24 12:29:08 -04:00
|
|
|
|
2014-05-04 18:59:06 -04:00
|
|
|
case TEXT_YOUR_GROUP:
|
|
|
|
return tr("My Channels");
|
|
|
|
case TEXT_SUBSCRIBED_GROUP:
|
|
|
|
return tr("Subscribed Channels");
|
|
|
|
case TEXT_POPULAR_GROUP:
|
|
|
|
return tr("Popular Channels");
|
|
|
|
case TEXT_OTHER_GROUP:
|
|
|
|
return tr("Other Channels");
|
2013-07-19 05:48:51 -04:00
|
|
|
}
|
2013-03-24 12:29:08 -04:00
|
|
|
|
2014-05-04 18:59:06 -04:00
|
|
|
return "";
|
2013-03-24 12:29:08 -04:00
|
|
|
}
|
|
|
|
|
2014-05-04 18:59:06 -04:00
|
|
|
QString GxsChannelDialog::icon(IconType type)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-05-04 18:59:06 -04:00
|
|
|
switch (type) {
|
|
|
|
case ICON_NAME:
|
2016-08-16 16:02:30 -04:00
|
|
|
return ":/icons/png/channels.png";
|
2014-05-04 18:59:06 -04:00
|
|
|
case ICON_NEW:
|
2016-08-23 21:28:57 -04:00
|
|
|
return ":/icons/png/add.png";
|
2014-05-04 18:59:06 -04:00
|
|
|
case ICON_YOUR_GROUP:
|
2014-09-15 19:53:08 -04:00
|
|
|
return ":/images/folder16.png";
|
2014-05-04 18:59:06 -04:00
|
|
|
case ICON_SUBSCRIBED_GROUP:
|
2014-09-15 19:53:08 -04:00
|
|
|
return ":/images/folder_red.png";
|
2014-05-04 18:59:06 -04:00
|
|
|
case ICON_POPULAR_GROUP:
|
2014-09-15 19:53:08 -04:00
|
|
|
return ":/images/folder_green.png";
|
2014-05-04 18:59:06 -04:00
|
|
|
case ICON_OTHER_GROUP:
|
2014-09-15 19:53:08 -04:00
|
|
|
return ":/images/folder_yellow.png";
|
2014-05-04 18:59:06 -04:00
|
|
|
case ICON_DEFAULT:
|
|
|
|
return ":/images/channels.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-05-04 18:59:06 -04:00
|
|
|
GxsGroupDialog *GxsChannelDialog::createNewGroupDialog(TokenQueue *tokenQueue)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-05-04 18:59:06 -04:00
|
|
|
return new GxsChannelGroupDialog(tokenQueue, this);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-05-04 18:59:06 -04:00
|
|
|
GxsGroupDialog *GxsChannelDialog::createGroupDialog(TokenQueue *tokenQueue, RsTokenService *tokenService, GxsGroupDialog::Mode mode, RsGxsGroupId groupId)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-05-04 18:59:06 -04:00
|
|
|
return new GxsChannelGroupDialog(tokenQueue, tokenService, mode, groupId, this);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-05-04 18:59:06 -04:00
|
|
|
int GxsChannelDialog::shareKeyType()
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-05-04 18:59:06 -04:00
|
|
|
return CHANNEL_KEY_SHARE;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-05-04 18:59:06 -04:00
|
|
|
GxsMessageFrameWidget *GxsChannelDialog::createMessageFrameWidget(const RsGxsGroupId &groupId)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-05-07 20:00:21 -04:00
|
|
|
return new GxsChannelPostsWidget(groupId);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2015-07-06 20:52:52 -04:00
|
|
|
void GxsChannelDialog::setDefaultDirectory()
|
|
|
|
{
|
|
|
|
RsGxsGroupId grpId = groupId() ;
|
|
|
|
if (grpId.isNull())
|
|
|
|
return ;
|
|
|
|
|
|
|
|
rsGxsChannels->setChannelDownloadDirectory(grpId,"") ;
|
|
|
|
}
|
|
|
|
void GxsChannelDialog::specifyDownloadDirectory()
|
|
|
|
{
|
|
|
|
RsGxsGroupId grpId = groupId() ;
|
|
|
|
if (grpId.isNull())
|
|
|
|
return ;
|
|
|
|
|
|
|
|
QString dir = QFileDialog::getExistingDirectory(NULL,tr("Select channel download directory")) ;
|
|
|
|
|
|
|
|
if(dir.isNull())
|
|
|
|
return ;
|
|
|
|
|
|
|
|
rsGxsChannels->setChannelDownloadDirectory(grpId,std::string(dir.toUtf8())) ;
|
|
|
|
}
|
|
|
|
void GxsChannelDialog::setDownloadDirectory()
|
|
|
|
{
|
|
|
|
RsGxsGroupId grpId = groupId() ;
|
|
|
|
if (grpId.isNull())
|
|
|
|
return ;
|
|
|
|
|
|
|
|
QAction *action = qobject_cast<QAction*>(sender()) ;
|
|
|
|
|
|
|
|
if(!action)
|
|
|
|
return ;
|
|
|
|
|
|
|
|
QString directory = action->data().toString() ;
|
|
|
|
|
|
|
|
rsGxsChannels->setChannelDownloadDirectory(grpId,std::string(directory.toUtf8())) ;
|
|
|
|
}
|
2014-05-04 18:59:06 -04:00
|
|
|
void GxsChannelDialog::groupTreeCustomActions(RsGxsGroupId grpId, int subscribeFlags, QList<QAction*> &actions)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2015-07-06 20:52:52 -04:00
|
|
|
bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags);
|
|
|
|
bool autoDownload ;
|
|
|
|
rsGxsChannels->getChannelAutoDownload(grpId,autoDownload);
|
2013-07-19 05:48:51 -04:00
|
|
|
|
2015-07-06 20:52:52 -04:00
|
|
|
if (isSubscribed)
|
|
|
|
{
|
|
|
|
QAction *action = autoDownload ? (new QAction(QIcon(":/images/redled.png"), tr("Disable Auto-Download"), this))
|
|
|
|
: (new QAction(QIcon(":/images/start.png"),tr("Enable Auto-Download"), this));
|
2013-07-19 05:48:51 -04:00
|
|
|
|
2015-07-06 20:52:52 -04:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(toggleAutoDownload()));
|
|
|
|
actions.append(action);
|
|
|
|
|
|
|
|
std::string dl_directory;
|
|
|
|
rsGxsChannels->getChannelDownloadDirectory(grpId,dl_directory) ;
|
|
|
|
|
|
|
|
QMenu *mnu = new QMenu(tr("Set download directory")) ;
|
|
|
|
|
|
|
|
if(dl_directory.empty())
|
|
|
|
mnu->addAction(QIcon(":/images/start.png"),tr("[Default directory]"), this, SLOT(setDefaultDirectory())) ;
|
|
|
|
else
|
|
|
|
mnu->addAction(tr("[Default directory]"), this, SLOT(setDefaultDirectory())) ;
|
|
|
|
|
|
|
|
std::list<SharedDirInfo> lst ;
|
|
|
|
rsFiles->getSharedDirectories(lst) ;
|
|
|
|
bool found = false ;
|
|
|
|
|
|
|
|
for(std::list<SharedDirInfo>::const_iterator it(lst.begin());it!=lst.end();++it)
|
|
|
|
{
|
|
|
|
QAction *action = NULL;
|
|
|
|
|
|
|
|
if(dl_directory == it->filename)
|
|
|
|
{
|
|
|
|
action = new QAction(QIcon(":/images/start.png"),QString::fromUtf8(it->filename.c_str()),NULL) ;
|
|
|
|
found = true ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
action = new QAction(QString::fromUtf8(it->filename.c_str()),NULL) ;
|
|
|
|
|
|
|
|
connect(action,SIGNAL(triggered()),this,SLOT(setDownloadDirectory())) ;
|
|
|
|
action->setData(QString::fromUtf8(it->filename.c_str())) ;
|
|
|
|
|
|
|
|
mnu->addAction(action) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!found && !dl_directory.empty())
|
|
|
|
{
|
|
|
|
QAction *action = new QAction(QIcon(":/images/start.png"),QString::fromUtf8(dl_directory.c_str()),NULL) ;
|
|
|
|
connect(action,SIGNAL(triggered()),this,SLOT(setDownloadDirectory())) ;
|
|
|
|
action->setData(QString::fromUtf8(dl_directory.c_str())) ;
|
|
|
|
|
|
|
|
mnu->addAction(action) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
mnu->addAction(tr("Specify..."), this, SLOT(specifyDownloadDirectory())) ;
|
|
|
|
|
|
|
|
actions.push_back( mnu->menuAction()) ;
|
|
|
|
}
|
2013-07-19 05:48:51 -04:00
|
|
|
}
|
|
|
|
|
2014-05-07 20:00:21 -04:00
|
|
|
RsGxsCommentService *GxsChannelDialog::getCommentService()
|
|
|
|
{
|
|
|
|
return rsGxsChannels;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *GxsChannelDialog::createCommentHeaderWidget(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId)
|
|
|
|
{
|
|
|
|
return new GxsChannelPostItem(NULL, 0, grpId, msgId, true, true);
|
|
|
|
}
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
void GxsChannelDialog::toggleAutoDownload()
|
|
|
|
{
|
2014-05-04 18:59:06 -04:00
|
|
|
RsGxsGroupId grpId = groupId();
|
|
|
|
if (grpId.isNull()) {
|
2013-07-19 05:48:51 -04:00
|
|
|
return;
|
|
|
|
}
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2015-07-06 20:52:52 -04:00
|
|
|
bool autoDownload ;
|
|
|
|
|
|
|
|
if(!rsGxsChannels->getChannelAutoDownload(grpId,autoDownload) || !rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload))
|
2013-07-19 05:48:51 -04:00
|
|
|
{
|
2014-05-04 18:59:06 -04:00
|
|
|
std::cerr << "GxsChannelDialog::toggleAutoDownload() Auto Download failed to set";
|
2013-07-19 05:48:51 -04:00
|
|
|
std::cerr << std::endl;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
}
|
2014-09-11 18:07:06 -04:00
|
|
|
|
|
|
|
void GxsChannelDialog::loadGroupSummaryToken(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo, RsUserdata *&userdata)
|
|
|
|
{
|
|
|
|
std::vector<RsGxsChannelGroup> groups;
|
|
|
|
rsGxsChannels->getGroupData(token, groups);
|
|
|
|
|
2014-12-27 17:13:29 -05:00
|
|
|
/* Save groups to fill icons and description */
|
2014-09-11 18:07:06 -04:00
|
|
|
GxsChannelGroupInfoData *channelData = new GxsChannelGroupInfoData;
|
|
|
|
userdata = channelData;
|
|
|
|
|
|
|
|
std::vector<RsGxsChannelGroup>::iterator groupIt;
|
|
|
|
for (groupIt = groups.begin(); groupIt != groups.end(); ++groupIt) {
|
|
|
|
RsGxsChannelGroup &group = *groupIt;
|
|
|
|
groupInfo.push_back(group.mMeta);
|
|
|
|
|
|
|
|
if (group.mImage.mData != NULL) {
|
|
|
|
QPixmap image;
|
|
|
|
image.loadFromData(group.mImage.mData, group.mImage.mSize, "PNG");
|
|
|
|
channelData->mIcon[group.mMeta.mGroupId] = image;
|
|
|
|
}
|
2014-12-27 17:13:29 -05:00
|
|
|
|
|
|
|
if (!group.mDescription.empty()) {
|
|
|
|
channelData->mDescription[group.mMeta.mGroupId] = QString::fromUtf8(group.mDescription.c_str());
|
|
|
|
}
|
2014-09-11 18:07:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata)
|
|
|
|
{
|
|
|
|
GxsGroupFrameDialog::groupInfoToGroupItemInfo(groupInfo, groupItemInfo, userdata);
|
|
|
|
|
|
|
|
const GxsChannelGroupInfoData *channelData = dynamic_cast<const GxsChannelGroupInfoData*>(userdata);
|
|
|
|
if (!channelData) {
|
|
|
|
std::cerr << "GxsChannelDialog::groupInfoToGroupItemInfo() Failed to cast data to GxsChannelGroupInfoData";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-27 17:13:29 -05:00
|
|
|
QMap<RsGxsGroupId, QString>::const_iterator descriptionIt = channelData->mDescription.find(groupInfo.mGroupId);
|
|
|
|
if (descriptionIt != channelData->mDescription.end()) {
|
|
|
|
groupItemInfo.description = descriptionIt.value();
|
|
|
|
}
|
|
|
|
|
2014-09-11 18:07:06 -04:00
|
|
|
QMap<RsGxsGroupId, QIcon>::const_iterator iconIt = channelData->mIcon.find(groupInfo.mGroupId);
|
|
|
|
if (iconIt != channelData->mIcon.end()) {
|
|
|
|
groupItemInfo.icon = iconIt.value();
|
|
|
|
}
|
|
|
|
}
|