2010-06-04 18:52:54 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Christopher Evi-Parker
|
|
|
|
*
|
|
|
|
* 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 "EditChanDetails.h"
|
|
|
|
|
2010-09-14 09:00:32 -04:00
|
|
|
#include <QFileDialog>
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rschannels.h>
|
2010-06-04 18:52:54 -04:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2010-09-14 09:00:32 -04:00
|
|
|
#define CHAN_DEFAULT_IMAGE ":/images/channels.png"
|
|
|
|
|
2010-06-04 18:52:54 -04:00
|
|
|
|
|
|
|
/** Default constructor */
|
|
|
|
EditChanDetails::EditChanDetails(QWidget *parent, Qt::WFlags flags, std::string cId)
|
|
|
|
: QDialog(parent, flags), mChannelId(cId)
|
|
|
|
{
|
2010-09-14 09:00:32 -04:00
|
|
|
/* Invoke Qt Designer generated QObject setup routine */
|
|
|
|
ui.setupUi(this);
|
2010-06-04 18:52:54 -04:00
|
|
|
|
2010-09-14 09:00:32 -04:00
|
|
|
connect(ui.applyButton, SIGNAL(clicked()), this, SLOT(applyDialog()));
|
|
|
|
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(closeinfodlg()));
|
|
|
|
|
|
|
|
connect( ui.LogoButton, SIGNAL(clicked() ), this , SLOT(addChannelLogo()));
|
|
|
|
connect( ui.ChannelLogoButton, SIGNAL(clicked() ), this , SLOT(addChannelLogo()));
|
|
|
|
|
|
|
|
ui.ChannelLogoButton->setDisabled(true);
|
|
|
|
ui.LogoButton->setDisabled(true);
|
2010-06-04 18:52:54 -04:00
|
|
|
|
2010-09-14 09:00:32 -04:00
|
|
|
loadChannel();
|
2010-06-04 18:52:54 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Overloads the default show() slot so we can set opacity*/
|
|
|
|
|
|
|
|
void EditChanDetails::show()
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!this->isVisible()) {
|
|
|
|
QDialog::show();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditChanDetails::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
2010-09-14 09:00:32 -04:00
|
|
|
QWidget::closeEvent(event);
|
2010-06-04 18:52:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditChanDetails::closeinfodlg()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EditChanDetails::loadChannel()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!rsChannels)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChannelInfo ci;
|
|
|
|
rsChannels->getChannelInfo(mChannelId, ci);
|
|
|
|
|
|
|
|
// Set Channel Name
|
|
|
|
ui.nameline->setText(QString::fromStdWString(ci.channelName));
|
|
|
|
|
|
|
|
|
|
|
|
// Set Channel Description
|
|
|
|
ui.DescriptiontextEdit->setText(QString::fromStdWString(ci.channelDesc));
|
2010-09-14 09:00:32 -04:00
|
|
|
|
|
|
|
// Set Channel Logo
|
|
|
|
if(ci.pngImageLen != 0)
|
|
|
|
{
|
|
|
|
QPixmap chanImage;
|
|
|
|
chanImage.loadFromData(ci.pngChanImage, ci.pngImageLen, "PNG");
|
|
|
|
ui.ChannelLogoButton->setIcon(QIcon(chanImage));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QPixmap defaulImage(CHAN_DEFAULT_IMAGE);
|
|
|
|
ui.ChannelLogoButton->setIcon(QIcon(defaulImage));
|
|
|
|
}
|
2010-06-04 18:52:54 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditChanDetails::applyDialog()
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!rsChannels)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if text boxes have not been edited leave alone
|
|
|
|
if(!ui.nameline->isModified() && !ui.DescriptiontextEdit->document()->isModified())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ChannelInfo ci;
|
|
|
|
|
|
|
|
ci.channelName = ui.nameline->text().toStdWString();
|
|
|
|
ci.channelDesc = ui.DescriptiontextEdit->document()->toPlainText().toStdWString();
|
|
|
|
|
|
|
|
|
|
|
|
/* reload now */
|
|
|
|
rsChannels->channelEditInfo(mChannelId, ci);
|
|
|
|
|
|
|
|
/* close the Dialog after the Changes applied */
|
|
|
|
closeinfodlg();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-14 09:00:32 -04:00
|
|
|
void EditChanDetails::addChannelLogo()
|
|
|
|
{
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"), QDir::homePath(), tr("Pictures (*.png *.xpm *.jpg)"));
|
|
|
|
if(!fileName.isEmpty())
|
|
|
|
{
|
|
|
|
picture = QPixmap(fileName).scaled(64,64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
|
|
|
|
|
|
// to show the selected
|
|
|
|
ui.ChannelLogoButton->setIcon(picture);
|
|
|
|
}
|
|
|
|
}
|
2010-06-04 18:52:54 -04:00
|
|
|
|