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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * 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. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
@ -37,98 +37,109 @@
#define IMAGE_EXPORT ":/images/exportpeers_16x16.png" #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_NAME 0
#define COLUMN_EMAIL 1 #define COLUMN_EMAIL 1
#define COLUMN_GID 2 #define COLUMN_GID 2
QTreeWidgetItem *item; /** Default constructor */
ProfileManager::ProfileManager(QWidget *parent, Qt::WFlags flags)
std::list<std::string> pgpIds; : QDialog(parent, flags)
std::list<std::string>::iterator it; {
bool foundGPGKeys = false; /* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this);
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);
foundGPGKeys = true; // setAttribute ( Qt::WA_DeleteOnClose, true );
}
}
identityTreeWidget->update(); /* update display */
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() 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()) std::string gpgId = item->text(COLUMN_GID).toStdString();
return ; if (gpgId.empty())
return;
QVariant data = ui.genPGPuser->itemData(ui.genPGPuser->currentIndex()); QString fname = QFileDialog::getSaveFileName(this, tr("Export Identity"), "", tr("RetroShare Identity files (*.asc)"));
std::string gpg_id = data.toString().toStdString() ;
if(RsInit::exportIdentity(fname.toStdString(),gpg_id)) if (fname.isNull())
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")) ; 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 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() void ProfileManager::importIdentity()
@ -141,7 +152,7 @@ void ProfileManager::importIdentity()
std::string gpg_id ; std::string gpg_id ;
std::string err_string ; 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)) ; QMessageBox::information(this,tr("Identity not loaded"),tr("Your identity was not loaded properly:")+" \n "+QString::fromStdString(err_string)) ;
return ; 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.")) ; 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() void ProfileManager::selectFriend()
@ -166,7 +176,7 @@ void ProfileManager::selectFriend()
/* still need to find home (first) */ /* still need to find home (first) */
QString fileName = QFileDialog::getOpenFileName(this, tr("Select Trusted Friend"), "", QString fileName = QFileDialog::getOpenFileName(this, tr("Select Trusted Friend"), "",
tr("Certificates (*.pqi *.pem)")); tr("Certificates (*.pqi *.pem)"));
std::string fname, userName; std::string fname, userName;
fname = fileName.toStdString(); fname = fileName.toStdString();
@ -199,45 +209,19 @@ void ProfileManager::checkChanged(int /*i*/)
#endif #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() void ProfileManager::newIdentity()
{ {
GenCertDialog gd; GenCertDialog gd;
gd.hideButtons() ; gd.hideButtons();
gd.exec (); gd.exec();
fillIdentities();
} }
QTreeWidgetItem *ProfileManager::getCurrentIdentity() QTreeWidgetItem *ProfileManager::getCurrentIdentity()
{ {
if (ui.identityTreeWidget->selectedItems().size() != 0) { if (ui.identityTreeWidget->selectedItems().size() != 0) {
return ui.identityTreeWidget -> currentItem(); return ui.identityTreeWidget->currentItem();
} }
return NULL; return NULL;
} }

View File

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

View File

@ -56,9 +56,6 @@
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
<property name="title">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,0"> <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,0">
@ -116,40 +113,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="2" column="0"> <item row="3" column="0" colspan="2">
<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">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
<string>Identities</string> <string>Identities</string>
@ -160,6 +124,9 @@
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum> <enum>Qt::CustomContextMenu</enum>
</property> </property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<column> <column>
<property name="text"> <property name="text">
<string>Name</string> <string>Name</string>
@ -180,31 +147,18 @@
</layout> </layout>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Ok</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>You can manage here your profiles, import, export your profiles or generate one .</string> <string>You can manage here your profiles, import, export your profiles or generate one .</string>
</property> </property>
@ -226,9 +180,6 @@
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops>
<tabstop>genPGPuser</tabstop>
</tabstops>
<resources> <resources>
<include location="../images.qrc"/> <include location="../images.qrc"/>
</resources> </resources>

View File

@ -50,18 +50,6 @@ ProfileWidget::ProfileWidget(QWidget *parent, Qt::WFlags flags)
connect(ui.profile_Button,SIGNAL(clicked()), this, SLOT(profilemanager())); connect(ui.profile_Button,SIGNAL(clicked()), this, SLOT(profilemanager()));
ui.onlinesince->setText(QDateTime::currentDateTime().toString(DATETIME_FMT)); ui.onlinesince->setText(QDateTime::currentDateTime().toString(DATETIME_FMT));
}
/** Destructor. */
ProfileWidget::~ProfileWidget()
{
}
void ProfileWidget::closeEvent (QCloseEvent * event)
{
QWidget::closeEvent(event);
} }
void ProfileWidget::showEvent ( QShowEvent * /*event*/ ) void ProfileWidget::showEvent ( QShowEvent * /*event*/ )
@ -69,7 +57,6 @@ void ProfileWidget::showEvent ( QShowEvent * /*event*/ )
RsPeerDetails detail; RsPeerDetails detail;
if (rsPeers->getPeerDetails(rsPeers->getOwnId(),detail)) if (rsPeers->getPeerDetails(rsPeers->getOwnId(),detail))
{ {
ui.name->setText(QString::fromUtf8(detail.name.c_str())); ui.name->setText(QString::fromUtf8(detail.name.c_str()));
ui.country->setText(QString::fromUtf8(detail.location.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) for(std::list<std::string>::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it)
ui.ipAddressList->addItem(QString::fromStdString(*it)); ui.ipAddressList->addItem(QString::fromStdString(*it));
/* set local address */ /* set local address */
ui.localAddress->setText(QString::fromStdString(detail.localAddr)); ui.localAddress->setText(QString::fromStdString(detail.localAddr));
ui.localPort -> setText(QString::number(detail.localPort)); ui.localPort -> setText(QString::number(detail.localPort));
@ -114,8 +100,8 @@ void ProfileWidget::showEvent ( QShowEvent * /*event*/ )
void ProfileWidget::statusmessagedlg() void ProfileWidget::statusmessagedlg()
{ {
static StatusMessage *statusmsgdialog = new StatusMessage(); StatusMessage statusMsgDialog;
statusmsgdialog->show(); statusMsgDialog.exec();
} }
void ProfileWidget::copyCert() void ProfileWidget::copyCert()
@ -140,6 +126,6 @@ void ProfileWidget::copyCert()
void ProfileWidget::profilemanager() void ProfileWidget::profilemanager()
{ {
static ProfileManager *profilemanager = new ProfileManager(); ProfileManager profilemanager;
profilemanager->show(); profilemanager.exec();
} }

View File

@ -29,32 +29,21 @@
class ProfileWidget : public QWidget class ProfileWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
/** Default constructor */ /** Default constructor */
ProfileWidget(QWidget *parent = 0, Qt::WFlags flags = 0); ProfileWidget(QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default destructor */
~ProfileWidget();
protected:
void closeEvent (QCloseEvent * event);
private slots: private slots:
void showEvent ( QShowEvent * event ); void showEvent ( QShowEvent * event );
void statusmessagedlg(); void statusmessagedlg();
void copyCert(); void copyCert();
void profilemanager(); void profilemanager();
private: private:
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::ProfileWidget ui; Ui::ProfileWidget ui;
}; };
#endif #endif