added back functionality to choose DL directory for each channel

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8581 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-07-07 00:52:52 +00:00
parent f91ca2b47e
commit 46a4273668
6 changed files with 283 additions and 68 deletions

View file

@ -19,6 +19,11 @@
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QMenu>
#include <QFileDialog>
#include <retroshare/rsfiles.h>
#include "GxsChannelDialog.h"
#include "GxsChannelGroupDialog.h"
#include "GxsChannelPostsWidget.h"
@ -138,19 +143,101 @@ GxsMessageFrameWidget *GxsChannelDialog::createMessageFrameWidget(const RsGxsGro
return new GxsChannelPostsWidget(groupId);
}
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())) ;
}
void GxsChannelDialog::groupTreeCustomActions(RsGxsGroupId grpId, int subscribeFlags, QList<QAction*> &actions)
{
bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags);
bool autoDownload = rsGxsChannels->getChannelAutoDownload(grpId);
bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags);
bool autoDownload ;
rsGxsChannels->getChannelAutoDownload(grpId,autoDownload);
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));
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));
connect(action, SIGNAL(triggered()), this, SLOT(toggleAutoDownload()));
actions.append(action);
}
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()) ;
}
}
RsGxsCommentService *GxsChannelDialog::getCommentService()
@ -170,8 +257,9 @@ void GxsChannelDialog::toggleAutoDownload()
return;
}
bool autoDownload = rsGxsChannels->getChannelAutoDownload(grpId);
if (!rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload))
bool autoDownload ;
if(!rsGxsChannels->getChannelAutoDownload(grpId,autoDownload) || !rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload))
{
std::cerr << "GxsChannelDialog::toggleAutoDownload() Auto Download failed to set";
std::cerr << std::endl;

View file

@ -51,6 +51,9 @@ protected:
private slots:
void toggleAutoDownload();
void setDefaultDirectory();
void setDownloadDirectory();
void specifyDownloadDirectory();
private:
/* GxsGroupFrameDialog */

View file

@ -249,7 +249,8 @@ void GxsChannelPostsWidget::insertChannelDetails(const RsGxsChannelGroup &group)
ui->subscribeToolButton->setSubscribed(IS_GROUP_SUBSCRIBED(group.mMeta.mSubscribeFlags));
bool autoDownload = rsGxsChannels->getChannelAutoDownload(group.mMeta.mGroupId);
bool autoDownload ;
rsGxsChannels->getChannelAutoDownload(group.mMeta.mGroupId,autoDownload);
setAutoDownload(autoDownload);
if (IS_GROUP_SUBSCRIBED(group.mMeta.mSubscribeFlags)) {
@ -464,8 +465,8 @@ void GxsChannelPostsWidget::toggleAutoDownload()
return;
}
bool autoDownload = rsGxsChannels->getChannelAutoDownload(grpId);
if (!rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload))
bool autoDownload ;
if(!rsGxsChannels->getChannelAutoDownload(grpId,autoDownload) || !rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload))
{
std::cerr << "GxsChannelDialog::toggleAutoDownload() Auto Download failed to set";
std::cerr << std::endl;