2018-11-15 21:49:12 +01:00
/*******************************************************************************
* retroshare - gui / src / gui / gxschannels / GxsChannelGroupDialog . cpp *
* *
* Copyright 2013 by Robert Fernie < retroshare . project @ gmail . com > *
* *
* This program is free software : you can redistribute it and / or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation , either version 3 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 Affero General Public License for more details . *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program . If not , see < https : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2013-03-11 20:53:15 +00:00
2014-07-26 22:29:53 +00:00
# include <QBuffer>
2019-06-03 23:52:29 +02:00
# include "gui/gxs/GxsIdDetails.h"
2013-03-11 20:53:15 +00:00
# include "GxsChannelGroupDialog.h"
# include <retroshare/rsgxschannels.h>
# include <iostream>
// To start with we only have open forums - with distribution controls.
2013-07-19 09:48:51 +00:00
2014-01-28 07:57:58 +00:00
const uint32_t ChannelCreateEnabledFlags = (
GXS_GROUP_FLAGS_NAME |
GXS_GROUP_FLAGS_ICON |
2013-03-11 20:53:15 +00:00
GXS_GROUP_FLAGS_DESCRIPTION |
GXS_GROUP_FLAGS_DISTRIBUTION |
// GXS_GROUP_FLAGS_PUBLISHSIGN |
2018-08-09 21:18:37 +02:00
// GXS_GROUP_FLAGS_SHAREKEYS | // disabled because the UI doesn't handle it, so no need to show the disabled button. The user can do it in a second step from the channel menu.
2013-03-11 20:53:15 +00:00
// GXS_GROUP_FLAGS_PERSONALSIGN |
GXS_GROUP_FLAGS_COMMENTS |
0 ) ;
const uint32_t ChannelCreateDefaultsFlags = ( GXS_GROUP_DEFAULTS_DISTRIB_PUBLIC |
//GXS_GROUP_DEFAULTS_DISTRIB_GROUP |
//GXS_GROUP_DEFAULTS_DISTRIB_LOCAL |
2013-07-19 09:48:51 +00:00
2013-03-11 20:53:15 +00:00
GXS_GROUP_DEFAULTS_PUBLISH_OPEN |
//GXS_GROUP_DEFAULTS_PUBLISH_THREADS |
//GXS_GROUP_DEFAULTS_PUBLISH_REQUIRED |
//GXS_GROUP_DEFAULTS_PUBLISH_ENCRYPTED |
2013-07-19 09:48:51 +00:00
2013-03-11 20:53:15 +00:00
//GXS_GROUP_DEFAULTS_PERSONAL_GPG |
GXS_GROUP_DEFAULTS_PERSONAL_REQUIRED |
//GXS_GROUP_DEFAULTS_PERSONAL_IFNOPUB |
2013-07-19 09:48:51 +00:00
2013-03-11 20:53:15 +00:00
GXS_GROUP_DEFAULTS_COMMENTS_YES |
//GXS_GROUP_DEFAULTS_COMMENTS_NO |
0 ) ;
2014-01-28 07:57:58 +00:00
const uint32_t ChannelEditEnabledFlags = ChannelCreateEnabledFlags ;
const uint32_t ChannelEditDefaultsFlags = ChannelCreateDefaultsFlags ;
2020-03-22 21:47:14 +01:00
GxsChannelGroupDialog : : GxsChannelGroupDialog ( QWidget * parent )
: GxsGroupDialog ( ChannelCreateEnabledFlags , ChannelCreateDefaultsFlags , parent )
2013-03-11 20:53:15 +00:00
{
2019-03-30 22:53:14 +01:00
ui . commentGroupBox - > setEnabled ( false ) ; // These are here because comments_allowed are actually not used yet, so the group will not be changed by the setting and when
ui . comments_allowed - > setChecked ( true ) ; // the group info is displayed it will therefore be set to "disabled" in all cases although it is enabled.
2013-03-11 20:53:15 +00:00
}
2020-03-22 21:47:14 +01:00
GxsChannelGroupDialog : : GxsChannelGroupDialog ( Mode mode , RsGxsGroupId groupId , QWidget * parent )
: GxsGroupDialog ( mode , groupId , ChannelEditEnabledFlags , ChannelEditDefaultsFlags , parent )
2013-03-11 20:53:15 +00:00
{
2019-03-30 22:53:14 +01:00
ui . commentGroupBox - > setEnabled ( false ) ; // These are here because comments_allowed are actually not used yet, so the group will not be changed by the setting and when
ui . comments_allowed - > setChecked ( true ) ; // the group info is displayed it will therefore be set to "disabled" in all cases although it is enabled.
2013-03-11 20:53:15 +00:00
}
void GxsChannelGroupDialog : : initUi ( )
{
switch ( mode ( ) )
{
case MODE_CREATE :
setUiText ( UITYPE_SERVICE_HEADER , tr ( " Create New Channel " ) ) ;
2018-08-09 21:18:37 +02:00
setUiText ( UITYPE_BUTTONBOX_OK , tr ( " Create " ) ) ;
2013-03-11 20:53:15 +00:00
break ;
case MODE_SHOW :
setUiText ( UITYPE_SERVICE_HEADER , tr ( " Channel " ) ) ;
break ;
case MODE_EDIT :
setUiText ( UITYPE_SERVICE_HEADER , tr ( " Edit Channel " ) ) ;
2018-08-09 21:18:37 +02:00
setUiText ( UITYPE_BUTTONBOX_OK , tr ( " Update Channel " ) ) ;
2013-03-11 20:53:15 +00:00
break ;
}
2013-08-30 16:30:23 +00:00
setUiText ( UITYPE_KEY_SHARE_CHECKBOX , tr ( " Add Channel Admins " ) ) ;
2018-08-09 21:18:37 +02:00
setUiText ( UITYPE_CONTACTS_DOCK , tr ( " Select Channel Admins " ) ) ;
2013-03-11 20:53:15 +00:00
}
QPixmap GxsChannelGroupDialog : : serviceImage ( )
{
2014-05-06 17:41:38 +00:00
switch ( mode ( ) )
{
case MODE_CREATE :
2019-10-09 18:06:30 +02:00
return QPixmap ( " :/icons/png/channel.png " ) ;
2014-07-26 22:29:53 +00:00
case MODE_SHOW :
2019-10-09 18:06:30 +02:00
return QPixmap ( " :/icons/png/channel.png " ) ;
2014-05-06 17:41:38 +00:00
case MODE_EDIT :
2019-10-09 18:06:30 +02:00
return QPixmap ( " :/icons/png/channel.png " ) ;
2014-05-06 17:41:38 +00:00
}
2014-07-24 23:26:04 +00:00
return QPixmap ( ) ;
2013-03-11 20:53:15 +00:00
}
2014-07-26 22:29:53 +00:00
void GxsChannelGroupDialog : : prepareChannelGroup ( RsGxsChannelGroup & group , const RsGroupMetaData & meta )
{
group . mMeta = meta ;
group . mDescription = getDescription ( ) . toUtf8 ( ) . constData ( ) ;
QPixmap pixmap = getLogo ( ) ;
if ( ! pixmap . isNull ( ) ) {
QByteArray ba ;
QBuffer buffer ( & ba ) ;
buffer . open ( QIODevice : : WriteOnly ) ;
pixmap . save ( & buffer , " PNG " ) ; // writes image into ba in PNG format
group . mImage . copy ( ( uint8_t * ) ba . data ( ) , ba . size ( ) ) ;
} else {
group . mImage . clear ( ) ;
}
}
2020-03-22 21:47:14 +01:00
bool GxsChannelGroupDialog : : service_createGroup ( RsGroupMetaData & meta )
2013-03-11 20:53:15 +00:00
{
// Specific Function.
RsGxsChannelGroup grp ;
2014-07-26 22:29:53 +00:00
prepareChannelGroup ( grp , meta ) ;
2013-03-11 20:53:15 +00:00
2020-03-22 21:47:14 +01:00
rsGxsChannels - > createChannel ( grp ) ;
meta = grp . mMeta ;
2013-03-11 20:53:15 +00:00
return true ;
}
2014-01-28 07:57:58 +00:00
2020-03-22 21:47:14 +01:00
bool GxsChannelGroupDialog : : service_updateGroup ( const RsGroupMetaData & editedMeta )
2014-01-28 07:57:58 +00:00
{
2014-02-09 10:43:59 +00:00
RsGxsChannelGroup grp ;
2014-07-26 22:29:53 +00:00
prepareChannelGroup ( grp , editedMeta ) ;
2014-02-09 10:43:59 +00:00
std : : cerr < < " GxsChannelGroupDialog::service_EditGroup() submitting changes " ;
2014-01-28 07:57:58 +00:00
std : : cerr < < std : : endl ;
2020-03-22 21:47:14 +01:00
return rsGxsChannels - > editChannel ( grp ) ;
2014-02-09 10:43:59 +00:00
}
2020-03-22 21:47:14 +01:00
bool GxsChannelGroupDialog : : service_loadGroup ( const RsGxsGenericGroupData * data , Mode /*mode*/ , QString & description )
2014-02-09 10:43:59 +00:00
{
2020-03-22 21:47:14 +01:00
const RsGxsChannelGroup * pgroup = dynamic_cast < const RsGxsChannelGroup * > ( data ) ;
2014-04-14 22:36:10 +00:00
2020-03-22 21:47:14 +01:00
if ( ! pgroup )
2014-04-14 22:36:10 +00:00
{
2020-03-22 21:47:14 +01:00
std : : cerr < < " GxsChannelGroupDialog::service_loadGroup() Error supplied generic group data is not a RsGxsChannelGroup " < < std : : endl ;
2014-04-14 22:36:10 +00:00
return false ;
}
2020-03-22 21:47:14 +01:00
const RsGxsChannelGroup & group = * pgroup ;
2014-07-26 22:29:53 +00:00
description = QString : : fromUtf8 ( group . mDescription . c_str ( ) ) ;
if ( group . mImage . mData ) {
QPixmap pixmap ;
2019-06-03 23:52:29 +02:00
2020-03-22 21:47:14 +01:00
if ( GxsIdDetails : : loadPixmapFromData ( group . mImage . mData , group . mImage . mSize , pixmap , GxsIdDetails : : ORIGINAL ) )
2014-07-26 22:29:53 +00:00
setLogo ( pixmap ) ;
}
2014-04-14 22:36:10 +00:00
2014-02-09 10:43:59 +00:00
return true ;
2014-01-28 07:57:58 +00:00
}
2020-03-22 21:47:14 +01:00
bool GxsChannelGroupDialog : : service_getGroupData ( const RsGxsGroupId & grpId , RsGxsGenericGroupData * & data )
{
std : : vector < RsGxsChannelGroup > forumsInfo ;
if ( rsGxsChannels - > getChannelsInfo ( std : : list < RsGxsGroupId > ( { grpId } ) , forumsInfo ) & & forumsInfo . size ( ) = = 1 )
{
data = new RsGxsChannelGroup ( forumsInfo [ 0 ] ) ;
return true ;
}
else
return false ;
}