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

@ -30,8 +30,8 @@
#include "gui/common/PeerDefs.h"
#include "ChatDialog.h"
CreateLobbyDialog::CreateLobbyDialog(const std::list<std::string>& peer_list,QWidget *parent, Qt::WFlags flags, std::string grpId, int grpType) :
QDialog(parent, flags), mGrpId(grpId), mGrpType(grpType)
CreateLobbyDialog::CreateLobbyDialog(const std::list<std::string>& peer_list,QWidget *parent, Qt::WFlags flags) :
QDialog(parent, flags)
{
ui = new Ui::CreateLobbyDialog() ;
ui->setupUi(this);
@ -50,10 +50,13 @@ CreateLobbyDialog::CreateLobbyDialog(const std::list<std::string>& peer_list,QWi
connect( ui->lobbyName_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) );
connect( ui->nickName_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) );
connect(ui->keyShareList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ), this, SLOT(togglePersonItem( QTreeWidgetItem *, int ) ));
/* initialize key share list */
ui->keyShareList->setHeaderText(tr("Contacts:"));
ui->keyShareList->setModus(FriendSelectionWidget::MODUS_CHECK);
ui->keyShareList->start();
ui->keyShareList->setSelectedSslIds(peer_list, false);
setShareList(peer_list);
checkTextFields() ;
checkTextFields();
}
CreateLobbyDialog::~CreateLobbyDialog()
@ -83,8 +86,10 @@ void CreateLobbyDialog::checkTextFields()
void CreateLobbyDialog::createLobby()
{
if(mShareList.empty())
{
std::list<std::string> shareList;
ui->keyShareList->selectedSslIds(shareList, false);
if (shareList.empty()) {
QMessageBox::warning(this, "RetroShare", tr("Please select at least one friend"), QMessageBox::Ok, QMessageBox::Ok);
return;
}
@ -96,7 +101,7 @@ void CreateLobbyDialog::createLobby()
int lobby_privacy_type = (ui->security_CB->currentIndex() == 0)?RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC:RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE ;
ChatLobbyId id = rsMsgs->createChatLobby(lobby_name, mShareList, lobby_privacy_type);
ChatLobbyId id = rsMsgs->createChatLobby(lobby_name, shareList, lobby_privacy_type);
std::cerr << "gui: Created chat lobby " << std::hex << id << std::endl ;
@ -117,84 +122,3 @@ void CreateLobbyDialog::cancel()
{
close();
}
void CreateLobbyDialog::setShareList(const std::list<std::string>& friend_list)
{
if (!rsPeers)
{
/* not ready yet! */
return;
}
std::list<std::string> peers;
std::list<std::string>::iterator it;
mShareList.clear() ;
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);
for(std::list<std::string>::const_iterator it2(friend_list.begin());it2!=friend_list.end();++it2)
if(*it == *it2)
{
item -> setCheckState(0, Qt::Checked);
mShareList.push_back(*it) ;
break ;
}
/* 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 CreateLobbyDialog::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()))
mShareList.push_back(id); // make sure ids not added already
else if(lit != mShareList.end())
mShareList.erase(lit);
return;
}

View file

@ -11,26 +11,19 @@ public:
/*
*@param chanId The channel id to send request for
*/
CreateLobbyDialog(const std::list<std::string>& friends_list,QWidget *parent = 0, Qt::WFlags flags = 0, std::string grpId = "", int grpType = 0);
CreateLobbyDialog(const std::list<std::string>& friends_list,QWidget *parent = 0, Qt::WFlags flags = 0);
~CreateLobbyDialog();
protected:
void changeEvent(QEvent *e);
private:
void setShareList(const std::list<std::string>&);
Ui::CreateLobbyDialog *ui;
std::string mGrpId;
std::list<std::string> mShareList;
int mGrpType;
private slots:
void createLobby();
void checkTextFields();
void cancel();
void togglePersonItem(QTreeWidgetItem* item, int col);
};
#endif // CREATELOBBYDIALOG_H

View file

@ -225,7 +225,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>
@ -256,20 +256,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>
@ -342,6 +328,14 @@ 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"/>
</resources>