From 1457a3b965be27fb91c44319b4726ea6fe38f0a7 Mon Sep 17 00:00:00 2001 From: defnax Date: Mon, 13 Aug 2012 15:37:21 +0000 Subject: [PATCH] Added a basic Profile Manager git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5407 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/gui/profile/ProfileManager.cpp | 201 +++++ .../src/gui/profile/ProfileManager.h | 67 ++ .../src/gui/profile/ProfileManager.ui | 846 ++++++++++++++++++ .../src/gui/profile/ProfileWidget.cpp | 8 + .../src/gui/profile/ProfileWidget.h | 2 + .../src/gui/profile/ProfileWidget.ui | 20 +- retroshare-gui/src/retroshare-gui.pro | 3 + 7 files changed, 1146 insertions(+), 1 deletion(-) create mode 100644 retroshare-gui/src/gui/profile/ProfileManager.cpp create mode 100644 retroshare-gui/src/gui/profile/ProfileManager.h create mode 100644 retroshare-gui/src/gui/profile/ProfileManager.ui diff --git a/retroshare-gui/src/gui/profile/ProfileManager.cpp b/retroshare-gui/src/gui/profile/ProfileManager.cpp new file mode 100644 index 000000000..9f36370a9 --- /dev/null +++ b/retroshare-gui/src/gui/profile/ProfileManager.cpp @@ -0,0 +1,201 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2012, RetroShare Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include +#include +#include +#include +#include "ProfileManager.h" +#include "gui/GenCertDialog.h" + +#include +#include +#include +#include +#include +#include + + +/* Define the format used for displaying the date and time */ +#define DATETIME_FMT "MMM dd hh:mm:ss" + + +/** Default constructor */ +ProfileManager::ProfileManager(QWidget *parent, Qt::WFlags flags) + : QDialog(parent, flags) +{ + /* Invoke Qt Designer generated QObject setup routine */ + ui.setupUi(this); + + 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())); + + + init() ; +} + +void ProfileManager::init() +{ + std::cerr << "Finding PGPUsers" << std::endl; + + QString titleString("%1"); + + std::list pgpIds; + std::list::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); + ui.listWidget->addItem(QString::fromUtf8(name.c_str()) + " <" + QString::fromUtf8(email.c_str()) + "> (" + gid + ")"); + + foundGPGKeys = true; + } + } + +} + + + +void ProfileManager::exportIdentity() +{ + 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()); + + std::string gpg_id = data.toString().toStdString() ; + + 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")) ; + else + QMessageBox::information(this,tr("Identity not saved"),tr("Your identity was not saved. An error occured.")) ; +} +void ProfileManager::importIdentity() +{ + QString fname = QFileDialog::getOpenFileName(this,tr("Export Identity"), "",tr("RetroShare Identity files (*.asc)")) ; + + if(fname.isNull()) + return ; + + std::string gpg_id ; + std::string err_string ; + + if(!RsInit::importIdentity(fname.toStdString(),gpg_id,err_string)) + { + QMessageBox::information(this,tr("Identity not loaded"),tr("Your identity was not loaded properly:")+" \n "+QString::fromStdString(err_string)) ; + return ; + } + else + { + std::string name,email ; + + RsInit::GetPGPLoginDetails(gpg_id, name, email); + std::cerr << "Adding PGPUser: " << name << " id: " << gpg_id << std::endl; + + 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() ; + +} + +void ProfileManager::selectFriend() +{ +#if 0 + /* still need to find home (first) */ + + QString fileName = QFileDialog::getOpenFileName(this, tr("Select Trusted Friend"), "", + tr("Certificates (*.pqi *.pem)")); + + std::string fname, userName; + fname = fileName.toStdString(); + if (RsInit::ValidateTrustedUser(fname, userName)) + { + ui.genFriend -> setText(QString::fromStdString(userName)); + } + else + { + ui.genFriend -> setText(""); + } +#endif +} + +void ProfileManager::checkChanged(int /*i*/) +{ +#if 0 + if (i) + { + selectFriend(); + } + else + { + /* invalidate selection */ + std::string fname = ""; + std::string userName = ""; + RsInit::ValidateTrustedUser(fname, userName); + ui.genFriend -> setText(""); + } +#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.exec (); +} + diff --git a/retroshare-gui/src/gui/profile/ProfileManager.h b/retroshare-gui/src/gui/profile/ProfileManager.h new file mode 100644 index 000000000..f0de98338 --- /dev/null +++ b/retroshare-gui/src/gui/profile/ProfileManager.h @@ -0,0 +1,67 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2012, RetroShare Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + + +#ifndef _PROFILEMANAGER_H +#define _PROFILEMANAGER_H + +#include + +#include "ui_ProfileManager.h" + + + +class ProfileManager : public QDialog +{ + Q_OBJECT + +public: + /** Default constructor */ + ProfileManager(QWidget *parent = 0, Qt::WFlags flags = 0); + /** Default destructor */ + +private slots: + + void selectFriend(); + void importIdentity(); + void exportIdentity(); + void checkChanged(int i); + void newIdentity(); + +private: + + void init() ; + + /** Loads the saved connectidialog settings */ + // void loadSettings(); + void loadCertificates(); + + + QMovie *movie; + + /** Qt Designer generated object */ + Ui::ProfileManager ui; + + bool genNewGPGKey; +}; + +#endif + diff --git a/retroshare-gui/src/gui/profile/ProfileManager.ui b/retroshare-gui/src/gui/profile/ProfileManager.ui new file mode 100644 index 000000000..945d5e8fe --- /dev/null +++ b/retroshare-gui/src/gui/profile/ProfileManager.ui @@ -0,0 +1,846 @@ + + + ProfileManager + + + + 0 + 0 + 625 + 356 + + + + + 0 + 0 + + + + + 167777 + 167777 + + + + + + + + + 0 + 0 + 0 + + + + + + + 208 + 208 + 208 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 104 + 104 + 104 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 255 + + + + + + + 255 + 0 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + + + 0 + 0 + 0 + + + + + + + 208 + 208 + 208 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 104 + 104 + 104 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 255 + + + + + + + 255 + 0 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + + + 0 + 0 + 0 + + + + + + + 208 + 208 + 208 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 104 + 104 + 104 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 255 + + + + + + + 255 + 0 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + + + Arial + 8 + 50 + false + false + false + false + + + + Qt::NoContextMenu + + + Profile Manager + + + + :/images/rstray3.png:/images/rstray3.png + + + QToolButton, QPushButton, QComboBox { +border-image: url(:/images/btn_26.png) 4; +border-width: 4; +padding: 0px 6px; +font-size: 12px; +} + +*{ +color: black; +} + +QComboBox QAbstractItemView { +background-color:white; +} + +QComboBox::down-arrow { +image: url(:/images/combobox_arrow.png); +} + +QComboBox:drop-down +{ +subcontrol-origin: padding; +subcontrol-position: top right; +border-left-style: none; +border-top-right-radius: 1px; +border-bottom-right-radius: 1px; +} + +QToolButton:hover, QPushButton:hover, QComboBox:hover { +border-image: url(:/images/btn_26_hover.png) 4; +} + +QToolButton:disabled, QPushButton:disabled, QComboBox::disabled { +color:gray; +} + +QToolButton:pressed, QPushButton:pressed{ +border-image: url(:/images/btn_26_pressed.png) 4; +} + + + + 0 + + + 0 + + + + + + 0 + 30 + + + + QFrame#frame{ +background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, +stop:0 #FEFEFE, stop:1 #E8E8E8); + +border: 1px solid #CCCCCC;} + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 0 + + + + + 0 + 20 + + + + + + + + + + 6 + + + 0 + + + 0 + + + + + + 16777215 + 26 + + + + + + + Generate New Identity + + + + :/images/contact_new.png:/images/contact_new.png + + + + + + + + 0 + 26 + + + + Import new identity + + + + + + + + 0 + 26 + + + + Export selected identity + + + + + + + + + + 16777215 + 32 + + + + + + + + + + + Select Identity + + + + + + + + 0 + 0 + + + + Select Profile to export + + + + + + + Identities + + + + + + + + + + + + Qt::Vertical + + + + 1 + 1 + + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + You can manage here your profiles, import, export your profiles or generate one . + + + + + + + + + + + 16777215 + 140 + + + + QFrame#frame_2{background-image: url(:/images/genbackground.png);} + + + + QFrame::NoFrame + + + QFrame::Plain + + + + 3 + + + 3 + + + + + + 64 + 64 + + + + + + + :/images/contact_new128.png + + + true + + + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:24pt; color:#ffffff;">Profile Manager</span></p></body></html> + + + + + + + + + + + + genPGPuser + + + + + + + + + buttonBox + accepted() + ProfileManager + close() + + + 320 + 334 + + + 320 + 177 + + + + + buttonBox + rejected() + ProfileManager + close() + + + 320 + 334 + + + 320 + 177 + + + + + diff --git a/retroshare-gui/src/gui/profile/ProfileWidget.cpp b/retroshare-gui/src/gui/profile/ProfileWidget.cpp index 093ecc038..694e1e684 100644 --- a/retroshare-gui/src/gui/profile/ProfileWidget.cpp +++ b/retroshare-gui/src/gui/profile/ProfileWidget.cpp @@ -25,6 +25,8 @@ #include #include "StatusMessage.h" +#include "gui/ProfileManager.h" +#include "ProfileEdit.h" #include #include @@ -46,6 +48,7 @@ ProfileWidget::ProfileWidget(QWidget *parent, Qt::WFlags flags) connect(ui.editstatuspushButton,SIGNAL(clicked()), this, SLOT(statusmessagedlg())); connect(ui.CopyCertButton,SIGNAL(clicked()), this, SLOT(copyCert())); + connect(ui.profile_Button,SIGNAL(clicked()), this, SLOT(profilemanager())); ui.onlinesince->setText(QDateTime::currentDateTime().toString(DATETIME_FMT)); @@ -136,3 +139,8 @@ void ProfileWidget::copyCert() } +void ProfileWidget::profilemanager() +{ + static ProfileManager *profilemanager = new ProfileManager(); + profilemanager->show(); +} diff --git a/retroshare-gui/src/gui/profile/ProfileWidget.h b/retroshare-gui/src/gui/profile/ProfileWidget.h index 50f677f35..7ce152ced 100644 --- a/retroshare-gui/src/gui/profile/ProfileWidget.h +++ b/retroshare-gui/src/gui/profile/ProfileWidget.h @@ -46,6 +46,8 @@ private slots: void showEvent ( QShowEvent * event ); void statusmessagedlg(); void copyCert(); + void profilemanager(); + private: diff --git a/retroshare-gui/src/gui/profile/ProfileWidget.ui b/retroshare-gui/src/gui/profile/ProfileWidget.ui index 9eedc9a35..3b54a88fa 100644 --- a/retroshare-gui/src/gui/profile/ProfileWidget.ui +++ b/retroshare-gui/src/gui/profile/ProfileWidget.ui @@ -70,7 +70,7 @@ border: 1px solid #CCCCCC; - + Qt::Horizontal @@ -102,6 +102,21 @@ border: 1px solid #CCCCCC; + + + + QPushButton:hover { +border: 1px solid #CCCCCC; +} + + + Profile Manager + + + true + + + @@ -715,6 +730,9 @@ p, li { white-space: pre-wrap; } + + + diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 774dd1d86..38c9c4c46 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -293,6 +293,7 @@ HEADERS += rshare.h \ util/ObjectPainter.h \ gui/bwgraph/bwgraph.h \ gui/profile/ProfileWidget.h \ + gui/profile/ProfileManager.h \ gui/profile/StatusMessage.h \ gui/chat/PopupChatWindow.h \ gui/chat/PopupChatDialog.h \ @@ -448,6 +449,7 @@ FORMS += gui/StartDialog.ui \ gui/bwgraph/bwgraph.ui \ gui/profile/ProfileWidget.ui \ gui/profile/StatusMessage.ui \ + gui/profile/ProfileManager.ui \ gui/channels/CreateChannel.ui \ gui/channels/CreateChannelMsg.ui \ gui/channels/ChannelDetails.ui \ @@ -588,6 +590,7 @@ SOURCES += main.cpp \ gui/bwgraph/bwgraph.cpp \ gui/profile/ProfileWidget.cpp \ gui/profile/StatusMessage.cpp \ + gui/profile/ProfileManager.cpp \ gui/channels/CreateChannel.cpp \ gui/channels/CreateChannelMsg.cpp \ gui/channels/ChannelDetails.cpp \