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:
thunder2 2012-09-12 11:17:00 +00:00
parent b4a9ccaa47
commit bb784ce325
5 changed files with 122 additions and 217 deletions

View File

@ -15,7 +15,7 @@
*
* 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,
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
@ -37,98 +37,109 @@
#define IMAGE_EXPORT ":/images/exportpeers_16x16.png"
/** Default constructor */
ProfileManager::ProfileManager(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
/* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this);
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.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);
init() ;
}
void ProfileManager::identityTreeWidgetCostumPopupMenu( QPoint )
{
QTreeWidgetItem *wi = getCurrentIdentity();
if (!wi)
return;
QMenu contextMnu( this );
//QAction* exportidentityAct = new QAction(QIcon(IMAGE_EXPORT), tr( "Export Identity" ), &contextMnu );
//connect( exportidentityAct , SIGNAL( triggered() ), this, SLOT( exportIdentity() ) );
//contextMnu.addAction( exportidentityAct);
contextMnu.exec(QCursor::pos());
}
void ProfileManager::init()
{
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));
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);
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);
/** Default constructor */
ProfileManager::ProfileManager(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
/* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this);
foundGPGKeys = true;
}
}
identityTreeWidget->update(); /* update display */
// 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.exportIdentity_PB->setEnabled(false);
fillIdentities();
}
void ProfileManager::identityTreeWidgetCostumPopupMenu(QPoint)
{
QTreeWidgetItem *item = getCurrentIdentity();
QMenu contextMnu(this);
QAction *action = contextMnu.addAction(QIcon(IMAGE_EXPORT), tr("Export Identity"), this, SLOT(exportIdentity()));
action->setEnabled(item != NULL);
contextMnu.exec(QCursor::pos());
}
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;
QTreeWidgetItem *item;
std::list<std::string> pgpIds;
std::list<std::string>::iterator it;
if (RsInit::GetPGPLogins(pgpIds)) {
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);
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);
}
}
// for (int i = 0; i < ui.identityTreeWidget->columnCount(); ++i) {
// ui.identityTreeWidget->resizeColumnToContents(i);
// }
}
void ProfileManager::exportIdentity()
{
QString fname = QFileDialog::getSaveFileName(this,tr("Export Identity"), "",tr("RetroShare Identity files (*.asc)")) ;
QTreeWidgetItem *item = getCurrentIdentity();
if (!item)
return;
if(fname.isNull())
return ;
std::string gpgId = item->text(COLUMN_GID).toStdString();
if (gpgId.empty())
return;
QVariant data = ui.genPGPuser->itemData(ui.genPGPuser->currentIndex());
std::string gpg_id = data.toString().toStdString() ;
QString fname = QFileDialog::getSaveFileName(this, tr("Export Identity"), "", tr("RetroShare Identity files (*.asc)"));
if(RsInit::exportIdentity(fname.toStdString(),gpg_id))
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")) ;
if (fname.isNull())
return;
if (QFileInfo(fname).suffix().isEmpty()) {
fname += ".asc";
}
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.")) ;
QMessageBox::information(this, tr("Identity not saved"), tr("Your identity was not saved. An error occured."));
}
void ProfileManager::importIdentity()
@ -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()
@ -166,7 +176,7 @@ void ProfileManager::selectFriend()
/* still need to find home (first) */
QString fileName = QFileDialog::getOpenFileName(this, tr("Select Trusted Friend"), "",
tr("Certificates (*.pqi *.pem)"));
tr("Certificates (*.pqi *.pem)"));
std::string fname, userName;
fname = fileName.toStdString();
@ -199,45 +209,19 @@ 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 ();
GenCertDialog gd;
gd.hideButtons();
gd.exec();
fillIdentities();
}
QTreeWidgetItem *ProfileManager::getCurrentIdentity()
{
if (ui.identityTreeWidget->selectedItems().size() != 0) {
return ui.identityTreeWidget -> currentItem();
}
if (ui.identityTreeWidget->selectedItems().size() != 0) {
return ui.identityTreeWidget->currentItem();
}
return NULL;
return NULL;
}

View File

@ -27,19 +27,18 @@
#include "ui_ProfileManager.h"
class ProfileManager : public QDialog
{
Q_OBJECT
Q_OBJECT
public:
/** Default constructor */
ProfileManager(QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default destructor */
/** Default constructor */
ProfileManager(QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default destructor */
private slots:
void identityTreeWidgetCostumPopupMenu( QPoint point );
void identityItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void selectFriend();
void importIdentity();
@ -50,16 +49,12 @@ private slots:
private:
QTreeWidgetItem *getCurrentIdentity();
void init() ;
void fillIdentities();
/** Loads the saved connectidialog settings */
// void loadSettings();
void loadCertificates();
/** Qt Designer generated object */
Ui::ProfileManager ui;
/** Qt Designer generated object */
Ui::ProfileManager ui;
bool genNewGPGKey;
bool genNewGPGKey;
};
#endif

View File

@ -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>

View File

@ -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();
}

View File

@ -29,32 +29,21 @@
class ProfileWidget : public QWidget
{
Q_OBJECT
Q_OBJECT
public:
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