mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Improved ProfileManager
- removed combobox and added export to the list of identities - add extension to the filename when the user enters a name without extension - refill list after generating a new identity git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5537 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b4a9ccaa47
commit
bb784ce325
@ -37,7 +37,9 @@
|
||||
|
||||
#define IMAGE_EXPORT ":/images/exportpeers_16x16.png"
|
||||
|
||||
|
||||
#define COLUMN_NAME 0
|
||||
#define COLUMN_EMAIL 1
|
||||
#define COLUMN_GID 2
|
||||
|
||||
/** Default constructor */
|
||||
ProfileManager::ProfileManager(QWidget *parent, Qt::WFlags flags)
|
||||
@ -46,86 +48,95 @@ ProfileManager::ProfileManager(QWidget *parent, Qt::WFlags flags)
|
||||
/* Invoke Qt Designer generated QObject setup routine */
|
||||
ui.setupUi(this);
|
||||
|
||||
// setAttribute ( Qt::WA_DeleteOnClose, true );
|
||||
|
||||
ui.headerFrame->setHeaderImage(QPixmap(":/images/contact_new128.png"));
|
||||
ui.headerFrame->setHeaderText(tr("Profile Manager"));
|
||||
|
||||
connect(ui.identityTreeWidget, SIGNAL( customContextMenuRequested(QPoint)), this, SLOT( identityTreeWidgetCostumPopupMenu(QPoint)));
|
||||
connect(ui.identityTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(identityItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
|
||||
connect(ui.newIdentity_PB, SIGNAL(clicked()), this, SLOT(newIdentity()));
|
||||
connect(ui.importIdentity_PB, SIGNAL(clicked()), this, SLOT(importIdentity()));
|
||||
connect(ui.exportIdentity_PB, SIGNAL(clicked()), this, SLOT(exportIdentity()));
|
||||
|
||||
ui.identityTreeWidget -> setColumnCount(3);
|
||||
ui.exportIdentity_PB->setEnabled(false);
|
||||
|
||||
init() ;
|
||||
fillIdentities();
|
||||
}
|
||||
|
||||
void ProfileManager::identityTreeWidgetCostumPopupMenu(QPoint)
|
||||
{
|
||||
QTreeWidgetItem *wi = getCurrentIdentity();
|
||||
if (!wi)
|
||||
return;
|
||||
QTreeWidgetItem *item = getCurrentIdentity();
|
||||
|
||||
QMenu contextMnu(this);
|
||||
|
||||
//QAction* exportidentityAct = new QAction(QIcon(IMAGE_EXPORT), tr( "Export Identity" ), &contextMnu );
|
||||
//connect( exportidentityAct , SIGNAL( triggered() ), this, SLOT( exportIdentity() ) );
|
||||
//contextMnu.addAction( exportidentityAct);
|
||||
QAction *action = contextMnu.addAction(QIcon(IMAGE_EXPORT), tr("Export Identity"), this, SLOT(exportIdentity()));
|
||||
action->setEnabled(item != NULL);
|
||||
|
||||
contextMnu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ProfileManager::init()
|
||||
void ProfileManager::identityItemChanged(QTreeWidgetItem *current, QTreeWidgetItem */*previous*/)
|
||||
{
|
||||
ui.exportIdentity_PB->setEnabled(current != NULL);
|
||||
}
|
||||
|
||||
void ProfileManager::fillIdentities()
|
||||
{
|
||||
ui.identityTreeWidget->clear();
|
||||
|
||||
ui.identityTreeWidget->setColumnWidth(COLUMN_NAME, 200);
|
||||
ui.identityTreeWidget->setColumnWidth(COLUMN_EMAIL, 200);
|
||||
|
||||
std::cerr << "Finding PGPUsers" << std::endl;
|
||||
|
||||
QTreeWidget *identityTreeWidget = ui.identityTreeWidget;
|
||||
|
||||
#define COLUMN_NAME 0
|
||||
#define COLUMN_EMAIL 1
|
||||
#define COLUMN_GID 2
|
||||
|
||||
QTreeWidgetItem *item;
|
||||
|
||||
std::list<std::string> pgpIds;
|
||||
std::list<std::string>::iterator it;
|
||||
bool foundGPGKeys = false;
|
||||
|
||||
if (RsInit::GetPGPLogins(pgpIds)) {
|
||||
for(it = pgpIds.begin(); it != pgpIds.end(); it++)
|
||||
{
|
||||
QVariant userData(QString::fromStdString(*it));
|
||||
for (it = pgpIds.begin(); it != pgpIds.end(); it++) {
|
||||
std::string name, email;
|
||||
RsInit::GetPGPLoginDetails(*it, name, email);
|
||||
std::cerr << "Adding PGPUser: " << name << " id: " << *it << std::endl;
|
||||
QString gid = QString::fromStdString(*it).right(8) ;
|
||||
ui.genPGPuser->addItem(QString::fromUtf8(name.c_str()) + " <" + QString::fromUtf8(email.c_str()) + "> (" + gid + ")", userData);
|
||||
QString gid = QString::fromStdString(*it);
|
||||
|
||||
item = new RSTreeWidgetItem(NULL, 0);
|
||||
item -> setText(COLUMN_NAME, QString::fromUtf8(name.c_str()));
|
||||
item -> setText(COLUMN_EMAIL, QString::fromUtf8(email.c_str()));
|
||||
item -> setText(COLUMN_GID, gid);
|
||||
identityTreeWidget->addTopLevelItem(item);
|
||||
|
||||
foundGPGKeys = true;
|
||||
}
|
||||
}
|
||||
|
||||
identityTreeWidget->update(); /* update display */
|
||||
|
||||
// for (int i = 0; i < ui.identityTreeWidget->columnCount(); ++i) {
|
||||
// ui.identityTreeWidget->resizeColumnToContents(i);
|
||||
// }
|
||||
}
|
||||
|
||||
void ProfileManager::exportIdentity()
|
||||
{
|
||||
QTreeWidgetItem *item = getCurrentIdentity();
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
std::string gpgId = item->text(COLUMN_GID).toStdString();
|
||||
if (gpgId.empty())
|
||||
return;
|
||||
|
||||
QString fname = QFileDialog::getSaveFileName(this, tr("Export Identity"), "", tr("RetroShare Identity files (*.asc)"));
|
||||
|
||||
if (fname.isNull())
|
||||
return;
|
||||
|
||||
QVariant data = ui.genPGPuser->itemData(ui.genPGPuser->currentIndex());
|
||||
if (QFileInfo(fname).suffix().isEmpty()) {
|
||||
fname += ".asc";
|
||||
}
|
||||
|
||||
std::string gpg_id = data.toString().toStdString() ;
|
||||
|
||||
if(RsInit::exportIdentity(fname.toStdString(),gpg_id))
|
||||
if (RsInit::exportIdentity(fname.toUtf8().constData(), gpgId))
|
||||
QMessageBox::information(this, tr("Identity saved"), tr("Your identity was successfully saved\nIt is encrypted\n\nYou can now copy it to another computer\nand use the import button to load it"));
|
||||
else
|
||||
QMessageBox::information(this, tr("Identity not saved"), tr("Your identity was not saved. An error occured."));
|
||||
@ -141,7 +152,7 @@ void ProfileManager::importIdentity()
|
||||
std::string gpg_id ;
|
||||
std::string err_string ;
|
||||
|
||||
if(!RsInit::importIdentity(fname.toStdString(),gpg_id,err_string))
|
||||
if(!RsInit::importIdentity(fname.toUtf8().constData(),gpg_id,err_string))
|
||||
{
|
||||
QMessageBox::information(this,tr("Identity not loaded"),tr("Your identity was not loaded properly:")+" \n "+QString::fromStdString(err_string)) ;
|
||||
return ;
|
||||
@ -156,8 +167,7 @@ void ProfileManager::importIdentity()
|
||||
QMessageBox::information(this,tr("New identity imported"),tr("Your identity was imported successfuly:")+" \n"+"\nName :"+QString::fromStdString(name)+"\nemail: " + QString::fromStdString(email)+"\nKey ID: "+QString::fromStdString(gpg_id)+"\n\n"+tr("You can use it now to create a new location.")) ;
|
||||
}
|
||||
|
||||
init() ;
|
||||
|
||||
fillIdentities();
|
||||
}
|
||||
|
||||
void ProfileManager::selectFriend()
|
||||
@ -199,38 +209,12 @@ void ProfileManager::checkChanged(int /*i*/)
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProfileManager::loadCertificates()
|
||||
{
|
||||
std::string lockFile;
|
||||
int retVal = RsInit::LockAndLoadCertificates(false, lockFile);
|
||||
switch(retVal)
|
||||
{
|
||||
case 0: close();
|
||||
break;
|
||||
case 1: QMessageBox::warning( this,
|
||||
tr("Multiple instances"),
|
||||
tr("Another RetroShare using the same profile is "
|
||||
"already running on your system. Please close "
|
||||
"that instance first") );
|
||||
break;
|
||||
case 2: QMessageBox::warning( this,
|
||||
tr("Multiple instances"),
|
||||
tr("An unexpected error occurred when Retroshare"
|
||||
"tried to acquire the single instance lock") );
|
||||
break;
|
||||
case 3: QMessageBox::warning( this,
|
||||
tr("Generate ID Failure"),
|
||||
tr("Failed to Load your new Certificate!") );
|
||||
break;
|
||||
default: std::cerr << "StartDialog::loadCertificates() unexpected switch value " << retVal << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileManager::newIdentity()
|
||||
{
|
||||
GenCertDialog gd;
|
||||
gd.hideButtons();
|
||||
gd.exec();
|
||||
fillIdentities();
|
||||
}
|
||||
|
||||
QTreeWidgetItem *ProfileManager::getCurrentIdentity()
|
||||
|
@ -27,8 +27,6 @@
|
||||
|
||||
#include "ui_ProfileManager.h"
|
||||
|
||||
|
||||
|
||||
class ProfileManager : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -40,6 +38,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void identityTreeWidgetCostumPopupMenu( QPoint point );
|
||||
void identityItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
|
||||
void selectFriend();
|
||||
void importIdentity();
|
||||
@ -50,11 +49,7 @@ private slots:
|
||||
private:
|
||||
QTreeWidgetItem *getCurrentIdentity();
|
||||
|
||||
void init() ;
|
||||
|
||||
/** Loads the saved connectidialog settings */
|
||||
// void loadSettings();
|
||||
void loadCertificates();
|
||||
void fillIdentities();
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::ProfileManager ui;
|
||||
|
@ -56,9 +56,6 @@
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,0">
|
||||
@ -116,40 +113,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="progress_label">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="genPGPuserlabel">
|
||||
<property name="text">
|
||||
<string>Select Identity</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="genPGPuser">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Select Profile to export</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Identities</string>
|
||||
@ -160,6 +124,9 @@
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
@ -180,31 +147,18 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>1</width>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>You can manage here your profiles, import, export your profiles or generate one .</string>
|
||||
</property>
|
||||
@ -226,9 +180,6 @@
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>genPGPuser</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
|
@ -50,18 +50,6 @@ ProfileWidget::ProfileWidget(QWidget *parent, Qt::WFlags flags)
|
||||
connect(ui.profile_Button,SIGNAL(clicked()), this, SLOT(profilemanager()));
|
||||
|
||||
ui.onlinesince->setText(QDateTime::currentDateTime().toString(DATETIME_FMT));
|
||||
|
||||
}
|
||||
|
||||
/** Destructor. */
|
||||
ProfileWidget::~ProfileWidget()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ProfileWidget::closeEvent (QCloseEvent * event)
|
||||
{
|
||||
QWidget::closeEvent(event);
|
||||
}
|
||||
|
||||
void ProfileWidget::showEvent ( QShowEvent * /*event*/ )
|
||||
@ -69,7 +57,6 @@ void ProfileWidget::showEvent ( QShowEvent * /*event*/ )
|
||||
RsPeerDetails detail;
|
||||
if (rsPeers->getPeerDetails(rsPeers->getOwnId(),detail))
|
||||
{
|
||||
|
||||
ui.name->setText(QString::fromUtf8(detail.name.c_str()));
|
||||
ui.country->setText(QString::fromUtf8(detail.location.c_str()));
|
||||
|
||||
@ -92,7 +79,6 @@ void ProfileWidget::showEvent ( QShowEvent * /*event*/ )
|
||||
for(std::list<std::string>::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it)
|
||||
ui.ipAddressList->addItem(QString::fromStdString(*it));
|
||||
|
||||
|
||||
/* set local address */
|
||||
ui.localAddress->setText(QString::fromStdString(detail.localAddr));
|
||||
ui.localPort -> setText(QString::number(detail.localPort));
|
||||
@ -114,8 +100,8 @@ void ProfileWidget::showEvent ( QShowEvent * /*event*/ )
|
||||
|
||||
void ProfileWidget::statusmessagedlg()
|
||||
{
|
||||
static StatusMessage *statusmsgdialog = new StatusMessage();
|
||||
statusmsgdialog->show();
|
||||
StatusMessage statusMsgDialog;
|
||||
statusMsgDialog.exec();
|
||||
}
|
||||
|
||||
void ProfileWidget::copyCert()
|
||||
@ -140,6 +126,6 @@ void ProfileWidget::copyCert()
|
||||
|
||||
void ProfileWidget::profilemanager()
|
||||
{
|
||||
static ProfileManager *profilemanager = new ProfileManager();
|
||||
profilemanager->show();
|
||||
ProfileManager profilemanager;
|
||||
profilemanager.exec();
|
||||
}
|
||||
|
@ -34,27 +34,16 @@ class ProfileWidget : public QWidget
|
||||
public:
|
||||
/** Default constructor */
|
||||
ProfileWidget(QWidget *parent = 0, Qt::WFlags flags = 0);
|
||||
/** Default destructor */
|
||||
~ProfileWidget();
|
||||
|
||||
|
||||
protected:
|
||||
void closeEvent (QCloseEvent * event);
|
||||
|
||||
private slots:
|
||||
|
||||
void showEvent ( QShowEvent * event );
|
||||
void statusmessagedlg();
|
||||
void copyCert();
|
||||
void profilemanager();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::ProfileWidget ui;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user