added share key dialog for channels

enabled private group in channels

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3164 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2010-06-19 15:28:26 +00:00
parent ba45933138
commit 7b26785262
4 changed files with 441 additions and 15 deletions

View File

@ -142,7 +142,7 @@ void CreateChannel::newChannel()
/* enforce Private for the moment */
ui.typePrivate->setChecked(true);
ui.typeEncrypted->setEnabled(false);
ui.typeEncrypted->setEnabled(true);
ui.msgAnon->setChecked(true);
ui.msgAuth->setEnabled(false);
@ -243,20 +243,9 @@ void CreateChannel::addChannelLogo()
QString fileName = QFileDialog::getOpenFileName(this, "Load File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg)");
if(!fileName.isEmpty())
{
picture = QPixmap(fileName).scaled(64,64, Qt::IgnoreAspectRatio);
// to show the selected
ui.ChannelLogoButton->setIcon(picture);
std::cerr << "Sending avatar image down the pipe" << std::endl ;
// send avatar down the pipe for other peers to get it.
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
std::cerr << "Image size = " << ba.size() << std::endl ;
picture = QPixmap(fileName).scaled(64,64, Qt::IgnoreAspectRatio);
// to show the selected
ui.ChannelLogoButton->setIcon(picture);
}
}

View File

@ -0,0 +1,183 @@
/****************************************************************
* 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 "ShareKey.h"
#include <QMessageBox>
#include <algorithm>
#include "rsiface/rschannels.h"
#include "rsiface/rspeers.h"
ShareKey::ShareKey(QWidget *parent, Qt::WFlags flags, std::string chanId) :
QDialog(parent, flags), mChannelId(chanId)
{
ui = new Ui::ShareKey();
ui->setupUi(this);
connect( ui->shareButton, SIGNAL( clicked ( bool ) ), this, SLOT( shareKey( ) ) );
connect( ui->cancelButton, SIGNAL( clicked ( bool ) ), this, SLOT( cancel( ) ) );
connect(ui->keyShareList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ),
this, SLOT(togglePersonItem( QTreeWidgetItem *, int ) ));
setShareList();
}
ShareKey::~ShareKey()
{
delete ui;
}
void ShareKey::closeEvent (QCloseEvent * event)
{
QWidget::closeEvent(event);
}
void ShareKey::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void ShareKey::shareKey()
{
if(!rsChannels)
return;
if(mShareList.empty())
{
QMessageBox::warning(this, tr("RetroShare"),tr("Please select at least one peer"),
QMessageBox::Ok, QMessageBox::Ok);
return;
}
if(!rsChannels->channelShareKeys(mChannelId, mShareList)){
std::cerr << "Failed to share keys!" << std::endl;
return;
}
close();
return;
}
void ShareKey::cancel()
{
close();
return;
}
void ShareKey::setShareList(){
if (!rsPeers)
{
/* not ready yet! */
return;
}
std::list<std::string> peers;
std::list<std::string>::iterator it;
rsPeers->getFriendList(peers);
/* get a link to the table */
QTreeWidget *shareWidget = ui->keyShareList;
QList<QTreeWidgetItem *> items;
for(it = peers.begin(); it != peers.end(); it++)
{
RsPeerDetails detail;
if (!rsPeers->getPeerDetails(*it, detail))
{
continue; /* BAD */
}
/* make a widget per friend */
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
item -> setText(0, QString::fromStdString(detail.name) + " - " + QString::fromStdString(detail.location));
if (detail.state & RS_PEER_STATE_CONNECTED) {
item -> setTextColor(0,(Qt::darkBlue));
}
item -> setText(1, QString::fromStdString(detail.id));
item -> setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item -> setCheckState(0, Qt::Unchecked);
/* add to the list */
items.append(item);
}
/* remove old items */
shareWidget->clear();
shareWidget->setColumnCount(1);
/* add the items in! */
shareWidget->insertTopLevelItems(0, items);
shareWidget->update(); /* update display */
}
void ShareKey::togglePersonItem( QTreeWidgetItem *item, int col )
{
/* extract id */
std::string id = (item -> text(1)).toStdString();
/* get state */
bool checked = (Qt::Checked == item -> checkState(0)); /* alway column 0 */
/* call control fns */
std::list<std::string>::iterator lit = std::find(mShareList.begin(), mShareList.end(), id);
if(checked && (lit == mShareList.end())){
// make sure ids not added already
mShareList.push_back(id);
}else
if(lit != mShareList.end()){
mShareList.erase(lit);
}
return;
}

View File

@ -0,0 +1,43 @@
#ifndef SHAREKEY_H
#define SHAREKEY_H
#include <QDialog>
#include "ui_ShareKey.h"
class ShareKey : public QDialog {
Q_OBJECT
public:
/*
*@param chanId The channel id to send request for
*/
ShareKey(QWidget *parent = 0, Qt::WFlags flags = 0, std::string chanId = "");
~ShareKey();
protected:
void changeEvent(QEvent *e);
void closeEvent (QCloseEvent * event);
private:
void setShareList();
Ui::ShareKey *ui;
std::string mChannelId;
std::list<std::string> mShareList;
private slots:
void shareKey();
void cancel();
void togglePersonItem(QTreeWidgetItem* item, int col);
};
#endif // SHAREKEY_H

View File

@ -0,0 +1,211 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ShareKey</class>
<widget class="QDialog" name="ShareKey">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>241</width>
<height>327</height>
</rect>
</property>
<property name="windowTitle">
<string>Share Key</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<property name="verticalSpacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame">
<property name="minimumSize">
<size>
<width>239</width>
<height>49</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);
background-image: url(:/images/connect/connectFriendBanner.png);</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="tlShareKey">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Arial'; font-size:18pt; font-weight:600; color:#ffffff;&quot;&gt;Share Key&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QDockWidget" name="contactsdockWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>524287</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>220</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>check peers you would like to share private publish key with</string>
</property>
<property name="floating">
<bool>false</bool>
</property>
<property name="features">
<set>QDockWidget::NoDockWidgetFeatures</set>
</property>
<property name="windowTitle">
<string>Share Key With</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="_2">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTreeWidget" name="keyShareList">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>4</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>220</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Contacts:</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="shareButton">
<property name="text">
<string>Share</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>