* Added Drag and Drop feature for CertificatePage, you can now drag and drop friends key file in a easy way.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3094 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2010-06-09 23:46:24 +00:00
parent 04aaceaf4d
commit e78ed75d36
2 changed files with 48 additions and 5 deletions

View File

@ -24,6 +24,7 @@
#include "rsiface/rspeers.h" //for rsPeers variable #include "rsiface/rspeers.h" //for rsPeers variable
#include "rsiface/rsiface.h" #include "rsiface/rsiface.h"
#include <QtGui>
#include <QLineEdit> #include <QLineEdit>
#include <QTextEdit> #include <QTextEdit>
#include <QLabel> #include <QLabel>
@ -168,7 +169,7 @@ IntroPage::IntroPage(QWidget *parent)
"to do this:")) ; "to do this:")) ;
textRadioButton = new QRadioButton(tr("&Enter the certificate manually")); textRadioButton = new QRadioButton(tr("&Enter the certificate manually"));
certRadioButton = new QRadioButton(tr("&Use *.rsc files with certificates" )); certRadioButton = new QRadioButton(tr("&You get a certificate file from your friend" ));
foffRadioButton = new QRadioButton(tr("&Make friend with selected friends of my friends" )); foffRadioButton = new QRadioButton(tr("&Make friend with selected friends of my friends" ));
textRadioButton->setChecked(true); textRadioButton->setChecked(true);
@ -610,6 +611,8 @@ CertificatePage::CertificatePage(QWidget *parent) : QWizardPage(parent) {
"before.")); "before."));
userFileLabel->setWordWrap(true); userFileLabel->setWordWrap(true);
setAcceptDrops(true);
userFileCreateButton = new QPushButton; userFileCreateButton = new QPushButton;
userFileCreateButton->setText(tr("Export my certificate...")); userFileCreateButton->setText(tr("Export my certificate..."));
connect(userFileCreateButton, SIGNAL( clicked() ), this, SLOT( generateCertificateCalled())); connect(userFileCreateButton, SIGNAL( clicked() ), this, SLOT( generateCertificateCalled()));
@ -620,11 +623,11 @@ CertificatePage::CertificatePage(QWidget *parent) : QWizardPage(parent) {
userFileFrame = new QGroupBox; userFileFrame = new QGroupBox;
userFileFrame->setFlat(true); userFileFrame->setFlat(true);
userFileFrame->setTitle(tr("Export my certificate...")); userFileFrame->setTitle(tr("Import friend's certificate..."));
userFileFrame->setLayout(userFileLayout); userFileFrame->setLayout(userFileLayout);
friendFileLabel = new QLabel(tr("Specify path to your friend's " friendFileLabel = new QLabel(tr("Drag and Drop your friends's certificate in this Window or specify path "
"certificate in the box below " ) ); "in the box below " ) );
friendFileNameEdit = new QLineEdit; friendFileNameEdit = new QLineEdit;
registerField("friendCertificateFile*", friendFileNameEdit); registerField("friendCertificateFile*", friendFileNameEdit);
@ -649,7 +652,7 @@ CertificatePage::CertificatePage(QWidget *parent) : QWizardPage(parent) {
void CertificatePage::loadFriendCert() { void CertificatePage::loadFriendCert() {
QString fileName = QString fileName =
QFileDialog::getOpenFileName(this, tr("Select Certificate"), QFileDialog::getOpenFileName(this, tr("Select Certificate"),
"", tr("RetroShare Certificates (*.rsc)")); "", tr("RetroShare Certificate (*.rsc );;All Files (*)"));
if (!fileName.isNull()) if (!fileName.isNull())
{ {
@ -700,6 +703,41 @@ void CertificatePage::generateCertificateCalled() {
//============================================================================ //============================================================================
void CertificatePage::dragEnterEvent(QDragEnterEvent *event)
{
// accept just text/uri-list mime format
if (event->mimeData()->hasFormat("text/uri-list"))
{
event->acceptProposedAction();
}
}
void CertificatePage::dropEvent(QDropEvent *event)
{
QList<QUrl> urlList;
QString fName;
QFileInfo info;
if (event->mimeData()->hasUrls())
{
urlList = event->mimeData()->urls(); // returns list of QUrls
// if just text was dropped, urlList is empty (size == 0)
if ( urlList.size() > 0) // if at least one QUrl is present in list
{
fName = urlList[0].toLocalFile(); // convert first QUrl to local path
info.setFile( fName ); // information about file
if ( info.isFile() )
friendFileNameEdit->setText( fName ); // if is file, setText
}
}
event->acceptProposedAction();
}
//============================================================================
bool CertificatePage::isComplete() const { bool CertificatePage::isComplete() const {
return !( (friendFileNameEdit->text()).isEmpty() ); return !( (friendFileNameEdit->text()).isEmpty() );
} }

View File

@ -118,6 +118,9 @@ public:
int nextId() const; int nextId() const;
bool isComplete() const ; bool isComplete() const ;
void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
private: private:
QGroupBox* userFileFrame; QGroupBox* userFileFrame;
QLabel *userFileLabel; QLabel *userFileLabel;
@ -134,6 +137,8 @@ private:
private slots: private slots:
void generateCertificateCalled(); void generateCertificateCalled();
void loadFriendCert(); void loadFriendCert();
}; };
//============================================================================ //============================================================================