Added new common widget FriendSelectionWidget for selecting friends and use it in CreateLobbyDialog, ShareKey (forums and channels) and MessageComposer.

Fixed german language.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4850 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-01-27 00:32:17 +00:00
parent a3a0690cb4
commit e6816c9d6f
22 changed files with 6804 additions and 3137 deletions

View file

@ -35,210 +35,104 @@
CreateChannel::CreateChannel(QWidget *parent)
: QDialog(parent)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
picture = NULL;
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
// connect up the buttons.
connect( ui.cancelButton, SIGNAL( clicked ( bool ) ), this, SLOT( cancelChannel( ) ) );
connect( ui.createButton, SIGNAL( clicked ( bool ) ), this, SLOT( createChannel( ) ) );
connect( ui.LogoButton, SIGNAL(clicked() ), this , SLOT(addChannelLogo()));
connect( ui.ChannelLogoButton, SIGNAL(clicked() ), this , SLOT(addChannelLogo()));
picture = NULL;
// connect up the buttons.
connect( ui.cancelButton, SIGNAL( clicked ( bool ) ), this, SLOT( cancelChannel( ) ) );
connect( ui.createButton, SIGNAL( clicked ( bool ) ), this, SLOT( createChannel( ) ) );
connect( ui.LogoButton, SIGNAL(clicked() ), this , SLOT(addChannelLogo()));
connect( ui.ChannelLogoButton, SIGNAL(clicked() ), this , SLOT(addChannelLogo()));
connect( ui.pubKeyShare_cb, SIGNAL( clicked() ), this, SLOT( setShareList( ) ));
connect( ui.keyShareList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ),
this, SLOT(togglePersonItem( QTreeWidgetItem *, int ) ));
if(!ui.pubKeyShare_cb->isChecked()){
if (!ui.pubKeyShare_cb->isChecked()) {
ui.contactsdockWidget->hide();
this->resize(this->size().width() - ui.contactsdockWidget->size().width(),
this->size().height());
this->resize(this->size().width() - ui.contactsdockWidget->size().width(), this->size().height());
}
newChannel();
/* initialize key share list */
ui.keyShareList->setHeaderText(tr("Contacts:"));
ui.keyShareList->setModus(FriendSelectionWidget::MODUS_CHECK);
ui.keyShareList->start();
}
void CreateChannel::show()
{
//loadSettings();
if(!this->isVisible()) {
QWidget::show();
}
newChannel();
}
void CreateChannel::setShareList(){
if(ui.pubKeyShare_cb->isChecked()){
this->resize(this->size().width() + ui.contactsdockWidget->size().width(),
this->size().height());
if (ui.pubKeyShare_cb->isChecked()){
this->resize(this->size().width() + ui.contactsdockWidget->size().width(), this->size().height());
ui.contactsdockWidget->show();
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, PeerDefs::nameWithLocation(detail));
if (detail.state & RS_PEER_STATE_CONNECTED) {
item -> setTextColor(0,(Qt::darkBlue));
}
item -> setSizeHint(0, QSize( 17,17 ) );
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 */
}else{
} else {
ui.contactsdockWidget->hide();
this->resize(this->size().width() - ui.contactsdockWidget->size().width(),
this->size().height());
mShareList.clear();
this->resize(this->size().width() - ui.contactsdockWidget->size().width(), this->size().height());
}
}
void CreateChannel::newChannel()
void CreateChannel::newChannel()
{
/* enforce Private for the moment */
ui.typePrivate->setChecked(true);
ui.typeEncrypted->setEnabled(true);
ui.typeEncrypted->setEnabled(true);
ui.msgAnon->setChecked(true);
ui.msgAuth->setEnabled(false);
ui.msgGroupBox->hide();
}
void CreateChannel::createChannel()
void CreateChannel::createChannel()
{
QString name = misc::removeNewLine(ui.channelName->text());
QString desc = ui.channelDesc->toPlainText();
uint32_t flags = 0;
if(name.isEmpty())
{ /* error message */
QMessageBox::warning(this, tr("RetroShare"),tr("Please add a Name"),
QMessageBox::Ok, QMessageBox::Ok);
if (name.isEmpty()) {
/* error message */
QMessageBox::warning(this, "RetroShare", tr("Please add a Name"), QMessageBox::Ok, QMessageBox::Ok);
return; //Don't add a empty name!!
}
else
if (ui.typePrivate->isChecked())
{
if (ui.typePrivate->isChecked()) {
flags |= RS_DISTRIB_PRIVATE;
}
else if (ui.typeEncrypted->isChecked())
{
} else if (ui.typeEncrypted->isChecked()) {
flags |= RS_DISTRIB_ENCRYPTED;
}
if (ui.msgAuth->isChecked())
{
if (ui.msgAuth->isChecked()) {
flags |= RS_DISTRIB_AUTHEN_REQ;
}
else if (ui.msgAnon->isChecked())
{
} else if (ui.msgAnon->isChecked()) {
flags |= RS_DISTRIB_AUTHEN_ANON;
}
QByteArray ba;
QBuffer buffer(&ba);
if(!picture.isNull()){
if (!picture.isNull()) {
// send chan image
buffer.open(QIODevice::WriteOnly);
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
}
if (rsChannels)
{
if (rsChannels) {
std::string chId = rsChannels->createChannel(name.toStdWString(), desc.toStdWString(), flags, (unsigned char*)ba.data(), ba.size());
if(ui.pubKeyShare_cb->isChecked())
rsChannels->channelShareKeys(chId, mShareList);
if (ui.pubKeyShare_cb->isChecked()) {
std::list<std::string> shareList;
ui.keyShareList->selectedSslIds(shareList, false);
rsChannels->channelShareKeys(chId, shareList);
}
}
close();
return;
}
void CreateChannel::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;
}
void CreateChannel::cancelChannel()
void CreateChannel::cancelChannel()
{
close();
return;
}
void CreateChannel::addChannelLogo() // the same function as in EditChanDetails

View file

@ -19,7 +19,6 @@
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _CREATE_CHANNEL_DIALOG_H
#define _CREATE_CHANNEL_DIALOG_H
@ -27,36 +26,26 @@
class CreateChannel : public QDialog
{
Q_OBJECT
Q_OBJECT
public:
CreateChannel(QWidget *parent = 0);
CreateChannel(QWidget *parent = 0);
void newChannel(); /* cleanup */
/** Qt Designer generated object */
Ui::CreateChannel ui;
QPixmap picture;
public slots:
/** Overloaded QWidget.show */
void show();
void newChannel(); /* cleanup */
private slots:
/* actions to take.... */
void createChannel();
void cancelChannel();
void createChannel();
void cancelChannel();
void addChannelLogo();
void setShareList();
void togglePersonItem(QTreeWidgetItem* item, int col);
void addChannelLogo();
void setShareList();
private:
QPixmap picture;
std::list<std::string> mShareList;
/** Qt Designer generated object */
Ui::CreateChannel ui;
};
#endif

View file

@ -159,7 +159,7 @@
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTreeWidget" name="keyShareList">
<widget class="FriendSelectionWidget" name="keyShareList" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -190,14 +190,6 @@
<height>0</height>
</size>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Contacts:</string>
</property>
</column>
</widget>
</item>
</layout>
@ -475,6 +467,14 @@ border-radius: 10px;
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>FriendSelectionWidget</class>
<extends>QWidget</extends>
<header>gui/common/FriendSelectionWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>
</resources>

View file

@ -106,7 +106,7 @@ p, li { white-space: pre-wrap; }
<bool>false</bool>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -426,10 +426,6 @@ background: white;}</string>
</widget>
<resources>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
<include location="../../../../../../../../.designer/images.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -30,183 +30,74 @@
#include "gui/common/PeerDefs.h"
ShareKey::ShareKey(QWidget *parent, Qt::WFlags flags, std::string grpId,
int grpType) :
QDialog(parent, flags), mGrpId(grpId), mGrpType(grpType)
ShareKey::ShareKey(QWidget *parent, Qt::WFlags flags, std::string grpId, int grpType) :
QDialog(parent, flags), mGrpId(grpId), mGrpType(grpType)
{
ui = new Ui::ShareKey();
ui->setupUi(this);
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->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();
/* initialize key share list */
ui->keyShareList->setHeaderText(tr("Contacts:"));
ui->keyShareList->setModus(FriendSelectionWidget::MODUS_CHECK);
ui->keyShareList->start();
}
ShareKey::~ShareKey()
{
delete ui;
}
void ShareKey::closeEvent (QCloseEvent * event)
{
QWidget::closeEvent(event);
delete ui;
}
void ShareKey::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void ShareKey::shareKey()
{
std::list<std::string> shareList;
ui->keyShareList->selectedSslIds(shareList, false);
if (shareList.empty()) {
QMessageBox::warning(this, "RetroShare", tr("Please select at least one peer"), QMessageBox::Ok, QMessageBox::Ok);
return;
}
if(mShareList.empty())
{
QMessageBox::warning(this, tr("RetroShare"),tr("Please select at least one peer"),
QMessageBox::Ok, QMessageBox::Ok);
return;
}
if(mGrpType & CHANNEL_KEY_SHARE)
{
if(!rsChannels)
if (mGrpType & CHANNEL_KEY_SHARE) {
if (!rsChannels)
return;
if(!rsChannels->channelShareKeys(mGrpId, mShareList)){
std::cerr << "Failed to share keys!" << std::endl;
return;
}
}else if(mGrpType & FORUM_KEY_SHARE)
{
if (!rsChannels->channelShareKeys(mGrpId, shareList)) {
std::cerr << "Failed to share keys!" << std::endl;
return;
}
} else if(mGrpType & FORUM_KEY_SHARE) {
if(!rsForums)
return;
if(!rsForums->forumShareKeys(mGrpId, mShareList)){
std::cerr << "Failed to share keys!" << std::endl;
return;
}
}else{
if (!rsForums->forumShareKeys(mGrpId, shareList)) {
std::cerr << "Failed to share keys!" << std::endl;
return;
}
} else {
// incorrect type
return;
}
close();
return;
close();
}
void ShareKey::cancel()
{
close();
return;
close();
}
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, PeerDefs::nameWithLocation(detail));
if (detail.state & RS_PEER_STATE_CONNECTED) {
item -> setTextColor(0,(Qt::darkBlue));
}
item -> setSizeHint(0, QSize( 17,17 ) );
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

@ -8,39 +8,29 @@
#define CHANNEL_KEY_SHARE 0x00000001
#define FORUM_KEY_SHARE 0x00000002
class ShareKey : public QDialog {
Q_OBJECT
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 grpId = "", int grpType = 0);
~ShareKey();
/*
*@param chanId The channel id to send request for
*/
ShareKey(QWidget *parent = 0, Qt::WFlags flags = 0, std::string grpId = "", int grpType = 0);
~ShareKey();
protected:
void changeEvent(QEvent *e);
void closeEvent (QCloseEvent * event);
private:
void setShareList();
Ui::ShareKey *ui;
std::string mGrpId;
std::list<std::string> mShareList;
int mGrpType;
void changeEvent(QEvent *e);
private slots:
void shareKey();
void cancel();
void shareKey();
void cancel();
void togglePersonItem(QTreeWidgetItem* item, int col);
private:
std::string mGrpId;
int mGrpType;
Ui::ShareKey *ui;
};
#endif // SHAREKEY_H

View file

@ -138,7 +138,7 @@ p, li { white-space: pre-wrap; }
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTreeWidget" name="keyShareList">
<widget class="FriendSelectionWidget" name="keyShareList" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -169,20 +169,6 @@ p, li { white-space: pre-wrap; }
<height>0</height>
</size>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Contacts:</string>
</property>
</column>
</widget>
</item>
</layout>
@ -242,10 +228,16 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>FriendSelectionWidget</class>
<extends>QWidget</extends>
<header>gui/common/FriendSelectionWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>