2010-06-19 11:28:26 -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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2014-10-13 14:31:47 -04:00
# include "GxsGroupShareKey.h"
2010-06-19 11:28:26 -04:00
# include <QMessageBox>
# include <algorithm>
2010-08-06 05:40:23 -04:00
# include <retroshare/rspeers.h>
2014-10-05 15:14:05 -04:00
# include <retroshare/rsgxschannels.h>
2014-10-13 14:31:47 -04:00
# include <retroshare/rsgxsforums.h>
# include <retroshare/rsposted.h>
2010-06-19 11:28:26 -04:00
2010-09-28 16:33:34 -04:00
# include "gui/common/PeerDefs.h"
2014-10-13 14:31:47 -04:00
GroupShareKey : : GroupShareKey ( QWidget * parent , const RsGxsGroupId & grpId , int grpType ) :
2012-11-06 18:26:47 -05:00
QDialog ( parent , Qt : : WindowSystemMenuHint | Qt : : WindowTitleHint | Qt : : WindowCloseButtonHint ) , mGrpId ( grpId ) , mGrpType ( grpType )
2010-06-19 11:28:26 -04:00
{
2012-01-26 19:32:17 -05:00
ui = new Ui : : ShareKey ( ) ;
ui - > setupUi ( this ) ;
2010-06-19 11:28:26 -04:00
2012-08-24 06:49:08 -04:00
ui - > headerFrame - > setHeaderImage ( QPixmap ( " :/images/user/agt_forum64.png " ) ) ;
2014-10-27 09:12:48 -04:00
ui - > headerFrame - > setHeaderText ( tr ( " Share " ) ) ;
2012-08-24 06:49:08 -04:00
2012-10-10 06:51:53 -04:00
connect ( ui - > buttonBox , SIGNAL ( accepted ( ) ) , this , SLOT ( shareKey ( ) ) ) ;
connect ( ui - > buttonBox , SIGNAL ( rejected ( ) ) , this , SLOT ( close ( ) ) ) ;
2010-06-19 11:28:26 -04:00
2012-01-26 19:32:17 -05:00
/* initialize key share list */
ui - > keyShareList - > setHeaderText ( tr ( " Contacts: " ) ) ;
ui - > keyShareList - > setModus ( FriendSelectionWidget : : MODUS_CHECK ) ;
2012-11-24 09:48:31 -05:00
ui - > keyShareList - > setShowType ( FriendSelectionWidget : : SHOW_GROUP | FriendSelectionWidget : : SHOW_SSL ) ;
2012-01-26 19:32:17 -05:00
ui - > keyShareList - > start ( ) ;
2014-10-27 09:12:48 -04:00
setTyp ( ) ;
2010-06-19 11:28:26 -04:00
}
2014-10-13 14:31:47 -04:00
GroupShareKey : : ~ GroupShareKey ( )
2010-06-19 11:28:26 -04:00
{
2012-01-26 19:32:17 -05:00
delete ui ;
2010-06-19 11:28:26 -04:00
}
2014-10-13 14:31:47 -04:00
void GroupShareKey : : changeEvent ( QEvent * e )
2010-06-19 11:28:26 -04:00
{
2012-01-26 19:32:17 -05:00
QDialog : : changeEvent ( e ) ;
switch ( e - > type ( ) ) {
case QEvent : : LanguageChange :
ui - > retranslateUi ( this ) ;
break ;
default :
break ;
}
2010-06-19 11:28:26 -04:00
}
2014-10-27 09:12:48 -04:00
void GroupShareKey : : setTyp ( )
{
if ( mGrpType = = CHANNEL_KEY_SHARE )
{
if ( ! rsGxsChannels )
return ;
ui - > headerFrame - > setHeaderImage ( QPixmap ( " :/images/channels.png " ) ) ;
2015-06-02 17:48:11 -04:00
ui - > headerFrame - > setHeaderText ( tr ( " Share channel admin permissions " ) ) ;
ui - > sharekeyinfo_label - > setText ( tr ( " You can allow your friends to publish in your channel and to modify the description. Or you can send the admin permissions to another Retroshare instance. Select the friends which you want to allowed to publish in this channel. Note: it is not possible to revoke channel admin permissions. " ) ) ;
2014-10-27 09:12:48 -04:00
}
else if ( mGrpType = = FORUM_KEY_SHARE )
{
ui - > headerFrame - > setHeaderImage ( QPixmap ( " :/images/konversation64.png " ) ) ;
2015-06-02 17:48:11 -04:00
ui - > headerFrame - > setHeaderText ( tr ( " Share forum admin permissions " ) ) ;
ui - > sharekeyinfo_label - > setText ( tr ( " You can let your friends know about your forum by sharing it with them. Select the friends with which you want to share your forum. " ) ) ;
2014-10-27 09:12:48 -04:00
}
else if ( mGrpType = = POSTED_KEY_SHARE )
{
if ( ! rsPosted )
return ;
ui - > headerFrame - > setHeaderImage ( QPixmap ( " :/images/posted_64.png " ) ) ;
2015-06-02 17:48:11 -04:00
ui - > headerFrame - > setHeaderText ( tr ( " Share topic admin permissions " ) ) ;
ui - > sharekeyinfo_label - > setText ( tr ( " You can allow your friends to edit the topic. Select them in the list below. Note: it is not possible to revoke Posted admin permissions. " ) ) ;
2014-10-27 09:12:48 -04:00
}
else
{
// incorrect type
return ;
}
}
2014-10-13 14:31:47 -04:00
void GroupShareKey : : shareKey ( )
2010-06-19 11:28:26 -04:00
{
2015-04-17 17:36:22 -04:00
std : : set < RsPeerId > shareList ;
2014-03-17 16:56:06 -04:00
ui - > keyShareList - > selectedIds < RsPeerId , FriendSelectionWidget : : IDTYPE_SSL > ( shareList , false ) ;
2010-06-19 11:28:26 -04:00
2012-01-26 19:32:17 -05:00
if ( shareList . empty ( ) ) {
QMessageBox : : warning ( this , " RetroShare " , tr ( " Please select at least one peer " ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
2011-08-29 17:20:48 -04:00
2012-01-26 19:32:17 -05:00
return ;
}
2010-06-19 11:28:26 -04:00
2014-10-13 14:31:47 -04:00
if ( mGrpType = = CHANNEL_KEY_SHARE )
{
2014-10-05 15:14:05 -04:00
if ( ! rsGxsChannels )
2014-10-13 14:31:47 -04:00
return ;
2011-08-29 17:20:48 -04:00
2014-10-05 15:14:05 -04:00
if ( ! rsGxsChannels - > groupShareKeys ( mGrpId , shareList ) ) {
2014-10-13 14:31:47 -04:00
std : : cerr < < " Failed to share keys! " < < std : : endl ;
return ;
}
}
else if ( mGrpType = = FORUM_KEY_SHARE )
{
2014-10-05 15:14:05 -04:00
QMessageBox : : warning ( NULL , " Not implemented. " , " Not implemented " ) ;
2014-10-13 14:31:47 -04:00
// if (!rsForums->forumShareKeys(mGrpId, shareList)) {
2014-10-05 15:14:05 -04:00
// std::cerr << "Failed to share keys!" << std::endl;
2014-10-13 14:31:47 -04:00
//return;
2014-10-05 15:14:05 -04:00
//}
2014-10-13 14:31:47 -04:00
}
else if ( mGrpType = = POSTED_KEY_SHARE )
{
if ( ! rsPosted )
return ;
if ( ! rsPosted - > groupShareKeys ( mGrpId , shareList ) ) {
std : : cerr < < " Failed to share keys! " < < std : : endl ;
return ;
}
}
else
{
2011-08-29 17:20:48 -04:00
// incorrect type
return ;
}
2010-06-19 11:28:26 -04:00
2012-01-26 19:32:17 -05:00
close ( ) ;
2010-06-19 11:28:26 -04:00
}