Merge pull request #2082 from csoler/v0.6-BugFixing_2

Attempt to improve consistency of HomePage
This commit is contained in:
csoler 2020-10-21 18:46:20 +02:00 committed by GitHub
commit ea020112a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 265 additions and 274 deletions

View File

@ -46,68 +46,74 @@
#include <QTextCodec>
HomePage::HomePage(QWidget *parent) :
MainPage(parent),
ui(new Ui::HomePage),
MainPage(parent),
ui(new Ui::HomePage),
mIncludeAllIPs(false),
mUseShortFormat(false)
mUseShortFormat(false),
mUseBackwardCompatibleCert(false)
{
ui->setupUi(this);
updateOwnCert();
updateOwnId();
connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addFriend()));
connect(ui->expandButton, SIGNAL(clicked()), this, SLOT(doExpand()));
updateCertificate();
connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addFriend()));
QAction *WebMailAction = new QAction(QIcon(),tr("Invite via WebMail"), this);
connect(WebMailAction, SIGNAL(triggered()), this, SLOT(webMail()));
QAction *RecAction = new QAction(QIcon(),tr("Recommend friends to each others"), this);
connect(RecAction, SIGNAL(triggered()), this, SLOT(recommendFriends()));
QAction *SendAction = new QAction(QIcon(),tr("Send via Email"), this);
connect(SendAction, SIGNAL(triggered()), this, SLOT(runEmailClient()));
QAction *CopyIdAction = new QAction(QIcon(),tr("Copy your Retroshare ID to Clipboard"), this);
QAction *CopyIdAction = new QAction(QIcon(),tr("Copy your Retroshare ID to Clipboard"), this);
connect(CopyIdAction, SIGNAL(triggered()), this, SLOT(copyId()));
QMenu *menu = new QMenu();
menu->addAction(CopyIdAction);
if(!RsAccounts::isHiddenNode())
{
QAction *includeIPsAct = new QAction(QIcon(), tr("Include all your known IPs"),this);
connect(includeIPsAct, SIGNAL(triggered()), this, SLOT(toggleIncludeAllIPs()));
includeIPsAct->setCheckable(true);
includeIPsAct->setChecked(mIncludeAllIPs);
QMenu *menu = new QMenu();
menu->addAction(CopyIdAction);
menu->addAction(includeIPsAct);
}
menu->addSeparator();
menu->addAction(SendAction);
menu->addAction(WebMailAction);
if(!RsAccounts::isHiddenNode())
{
QAction *includeIPsAct = new QAction(QIcon(), tr("Include all your known IPs"),this);
connect(includeIPsAct, SIGNAL(triggered()), this, SLOT(toggleIncludeAllIPs()));
includeIPsAct->setCheckable(true);
includeIPsAct->setChecked(mIncludeAllIPs);
menu->addAction(includeIPsAct);
}
QAction *useOldFormatAct = new QAction(QIcon(), tr("Use old certificate format"),this);
useOldFormatAct->setToolTip(tr("Displays the certificate format used up to version 0.6.5\nOld Retroshare nodes will not understand the\nnew short format"));
connect(useOldFormatAct, SIGNAL(triggered()), this, SLOT(toggleUseOldFormat()));
useOldFormatAct->setCheckable(true);
useOldFormatAct->setChecked(mUseBackwardCompatibleCert);
menu->addAction(useOldFormatAct);
menu->addSeparator();
menu->addAction(SendAction);
menu->addAction(WebMailAction);
menu->addAction(RecAction);
ui->shareButton->setMenu(menu);
QObject::connect(ui->userCertEdit,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(certContextMenu(QPoint)));
connect(ui->openwebhelp,SIGNAL(clicked()), this,SLOT(openWebHelp())) ;
connect(ui->openwebhelp,SIGNAL(clicked()), this,SLOT(openWebHelp())) ;
ui->userCertEdit->hide();
ui->userCertEdit->hide();
int S = QFontMetricsF(font()).height();
QString help_str = tr(
" <h1><img width=\"%1\" src=\":/icons/help_64.png\">&nbsp;&nbsp;Welcome to Retroshare!</h1>\
<p>You need to <b>make friends</b>! After you create a network of friends or join an existing network,\
you'll be able to exchange files, chat, talk in forums, etc. </p>\
<div align=center>\
<IMG align=\"center\" width=\"%2\" src=\":/images/network_map.png\"/> \
you'll be able to exchange files, chat, talk in forums, etc. </p>\
<div align=center>\
<IMG align=\"center\" width=\"%2\" src=\":/images/network_map.png\"/> \
</div>\
<p>To do so, copy your certificate on this page and send it to friends, and add your friends' certificate.</p> \
<p>Another option is to search the internet for \"Retroshare chat servers\" (independently administrated). These servers allow you to exchange \
certificates with a dedicated Retroshare node, through which\
you will be able to anonymously meet other people.</p> ").arg(QString::number(2*S)).arg(width()*0.5);
certificates with a dedicated Retroshare node, through which\
you will be able to anonymously meet other people.</p> ").arg(QString::number(2*S)).arg(width()*0.5);
registerHelpButton(ui->helpButton,help_str,"HomePage") ;
}
@ -115,7 +121,7 @@ void HomePage::certContextMenu(QPoint point)
{
QMenu menu(this) ;
QAction *CopyAction = new QAction(QIcon(),tr("Copy your Cert to Clipboard"), this);
QAction *CopyAction = new QAction(QIcon(),tr("Copy your Cert to Clipboard"), this);
connect(CopyAction, SIGNAL(triggered()), this, SLOT(copyCert()));
QAction *SaveAction = new QAction(QIcon(),tr("Save your Cert into a File"), this);
@ -124,22 +130,22 @@ void HomePage::certContextMenu(QPoint point)
menu.addAction(CopyAction);
menu.addAction(SaveAction);
QAction *shortFormatAct = new QAction(QIcon(), tr("Use new (short) certificate format"),this);
connect(shortFormatAct, SIGNAL(triggered()), this, SLOT(toggleUseShortFormat()));
shortFormatAct->setCheckable(true);
shortFormatAct->setChecked(mUseShortFormat);
QAction *shortFormatAct = new QAction(QIcon(), tr("Use new (short) certificate format"),this);
connect(shortFormatAct, SIGNAL(triggered()), this, SLOT(toggleUseShortFormat()));
shortFormatAct->setCheckable(true);
shortFormatAct->setChecked(mUseShortFormat);
menu.addAction(shortFormatAct);
menu.addAction(shortFormatAct);
if(!RsAccounts::isHiddenNode())
{
QAction *includeIPsAct = new QAction(QIcon(), tr("Include all your known IPs"),this);
connect(includeIPsAct, SIGNAL(triggered()), this, SLOT(toggleIncludeAllIPs()));
includeIPsAct->setCheckable(true);
includeIPsAct->setChecked(mIncludeAllIPs);
{
QAction *includeIPsAct = new QAction(QIcon(), tr("Include all your known IPs"),this);
connect(includeIPsAct, SIGNAL(triggered()), this, SLOT(toggleIncludeAllIPs()));
includeIPsAct->setCheckable(true);
includeIPsAct->setChecked(mIncludeAllIPs);
menu.addAction(includeIPsAct);
}
menu.addAction(includeIPsAct);
}
menu.exec(QCursor::pos());
}
@ -147,18 +153,25 @@ void HomePage::certContextMenu(QPoint point)
void HomePage::toggleUseShortFormat()
{
mUseShortFormat = !mUseShortFormat;
updateOwnCert();
updateCertificate();
}
void HomePage::toggleIncludeAllIPs()
{
mIncludeAllIPs = !mIncludeAllIPs;
updateOwnCert();
updateOwnId();
updateCertificate();
}
HomePage::~HomePage()
{
delete ui;
delete ui;
}
void HomePage::updateCertificate()
{
if(mUseBackwardCompatibleCert)
updateOwnCert();
else
updateOwnId();
}
void HomePage::updateOwnCert()
@ -173,18 +186,18 @@ void HomePage::updateOwnCert()
return ;
}
std::string invite ;
std::string invite ;
if(mUseShortFormat)
rsPeers->getShortInvite(invite,rsPeers->getOwnId(),true,!mIncludeAllIPs);
else
invite = rsPeers->GetRetroshareInvite(detail.id,false,include_extra_locators);
rsPeers->getShortInvite(invite,rsPeers->getOwnId(),true,!mIncludeAllIPs);
else
invite = rsPeers->GetRetroshareInvite(detail.id,false,include_extra_locators);
ui->userCertEdit->setPlainText(QString::fromUtf8(invite.c_str()));
ui->retroshareid->setText("\n"+QString::fromUtf8(invite.c_str())+"\n");
QString description = ConfCertDialog::getCertificateDescription(detail,false,mUseShortFormat,include_extra_locators);
ui->userCertEdit->setToolTip(description);
ui->retroshareid->setToolTip(description);
}
void HomePage::updateOwnId()
@ -202,13 +215,12 @@ void HomePage::updateOwnId()
rsPeers->getShortInvite(invite,rsPeers->getOwnId(),true,!include_extra_locators);
#ifdef TODO
QString S;
QString txt;
int i=0;
for(uint32_t i=0;i<invite.size();)
if(QFontMetricsF(font()).width(S) < ui->retroshareid->width())
if(S.length() < 100)
S += invite[i++];
else
{
@ -218,36 +230,36 @@ void HomePage::updateOwnId()
txt += S;
ui->retroshareid->setText(txt);
#endif
ui->retroshareid->setText(QString::fromUtf8(invite.c_str()));
ui->retroshareid->setText("\n"+txt+"\n"); // the "\n" is here to make some space
//#endif
// ui->retroshareid->setText(QString::fromUtf8(invite.c_str()));
}
static void sendMail(QString sAddress, QString sSubject, QString sBody)
{
#ifdef Q_OS_WIN
/* search and replace the end of lines with: "%0D%0A" */
sBody.replace("\n", "%0D%0A");
/* search and replace the end of lines with: "%0D%0A" */
sBody.replace("\n", "%0D%0A");
#endif
QUrl url = QUrl("mailto:" + sAddress);
QUrl url = QUrl("mailto:" + sAddress);
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
QUrlQuery urlQuery;
QUrlQuery urlQuery;
#else
QUrl &urlQuery(url);
QUrl &urlQuery(url);
#endif
urlQuery.addQueryItem("subject", sSubject);
urlQuery.addQueryItem("body", sBody);
urlQuery.addQueryItem("subject", sSubject);
urlQuery.addQueryItem("body", sBody);
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
url.setQuery(urlQuery);
url.setQuery(urlQuery);
#endif
std::cerr << "MAIL STRING:" << (std::string)url.toEncoded().constData() << std::endl;
std::cerr << "MAIL STRING:" << (std::string)url.toEncoded().constData() << std::endl;
/* pass the url directly to QDesktopServices::openUrl */
QDesktopServices::openUrl (url);
/* pass the url directly to QDesktopServices::openUrl */
QDesktopServices::openUrl (url);
}
void HomePage::recommendFriends()
@ -257,38 +269,38 @@ void HomePage::recommendFriends()
void HomePage::runEmailClient()
{
sendMail("", tr("RetroShare Invite"), ui->userCertEdit->toPlainText());
sendMail("", tr("RetroShare Invite"), ui->retroshareid->text());
}
void HomePage::copyCert()
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(ui->userCertEdit->toPlainText());
QMessageBox::information(this, "RetroShare", tr("Your Retroshare certificate is copied to Clipboard, paste and send it to your friend via email or some other way"));
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(ui->retroshareid->text());
QMessageBox::information(this, "RetroShare", tr("Your Retroshare certificate is copied to Clipboard, paste and send it to your friend via email or some other way"));
}
void HomePage::copyId()
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(ui->retroshareid->text());
QMessageBox::information(this, "RetroShare", tr("Your Retroshare ID is copied to Clipboard, paste and send it to your friend via email or some other way"));
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(ui->retroshareid->text());
QMessageBox::information(this, "RetroShare", tr("Your Retroshare ID is copied to Clipboard, paste and send it to your friend via email or some other way"));
}
void HomePage::saveCert()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."), "", tr("RetroShare Certificate (*.rsc );;All Files (*)"));
if (fileName.isEmpty())
return;
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."), "", tr("RetroShare Certificate (*.rsc );;All Files (*)"));
if (fileName.isEmpty())
return;
QFile file(fileName);
if (!file.open(QFile::WriteOnly))
return;
QFile file(fileName);
if (!file.open(QFile::WriteOnly))
return;
//Todo: move save to file to p3Peers::SaveCertificateToFile
//Todo: move save to file to p3Peers::SaveCertificateToFile
QTextStream ts(&file);
ts.setCodec(QTextCodec::codecForName("UTF-8"));
ts << ui->userCertEdit->document()->toPlainText();
QTextStream ts(&file);
ts.setCodec(QTextCodec::codecForName("UTF-8"));
ts << ui->retroshareid->text();
}
/** Add a Friends Text Certificate */
@ -321,18 +333,20 @@ void HomePage::openWebHelp()
QDesktopServices::openUrl(QUrl(QString("https://retroshare.readthedocs.io")));
}
void HomePage::doExpand()
void HomePage::toggleUseOldFormat()
{
mUseBackwardCompatibleCert = !mUseBackwardCompatibleCert;
updateCertificate();
if (ui->expandButton->isChecked())
{
ui->userCertEdit->show();
ui->expandButton->setToolTip(tr("Hide"));
}
else
{
ui->userCertEdit->hide();
ui->expandButton->setToolTip(tr("Show full certificate (old format)"));
}
if (mUseBackwardCompatibleCert)
{
//ui->userCertEdit->show();
//ui->expandButton->setToolTip(tr("Revert to normal Retroshare ID"));
}
else
{
//ui->userCertEdit->hide();
//ui->expandButton->setToolTip(tr("Show full certificate (old format for backward compatibility)"));
}
}

View File

@ -49,7 +49,8 @@ public:
private slots:
void certContextMenu(QPoint);
void updateOwnCert();
void updateOwnId();
void updateCertificate();
void updateOwnId();
void runEmailClient();
void copyCert();
void copyId();
@ -58,16 +59,17 @@ private slots:
void webMail();
//void loadCert();
void openWebHelp() ;
void recommendFriends();
void toggleUseOldFormat() ;
void recommendFriends();
void toggleIncludeAllIPs();
void toggleUseShortFormat();
void doExpand();
private:
Ui::HomePage *ui;
bool mIncludeAllIPs;
bool mUseShortFormat;
bool mUseBackwardCompatibleCert;
};

View File

@ -66,177 +66,6 @@ private and secure decentralized communication platform.
</property>
</spacer>
</item>
<item row="2" column="1">
<layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="4">
<widget class="QToolButton" name="helpButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/help_64.png</normaloff>:/icons/help_64.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="6">
<widget class="QPlainTextEdit" name="userCertEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Courier New</family>
</font>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="tabStopWidth">
<number>80</number>
</property>
<property name="centerOnScroll">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QToolButton" name="expandButton">
<property name="toolTip">
<string>Show full certificate (old format)</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/png/cert.png</normaloff>:/icons/png/cert.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QToolButton" name="shareButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Share your RetroShare ID&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/svg/share.svg</normaloff>:/icons/svg/share.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QLabel" name="retroshareid">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="userCertLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>This is your Retroshare ID. Copy and share with your friends!</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="2" rowspan="4">
<spacer name="horizontalSpacer_3">
<property name="orientation">
@ -388,6 +217,152 @@ private and secure decentralized communication platform.
</property>
</spacer>
</item>
<item row="2" column="1">
<layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="2" column="0" colspan="7">
<widget class="QPlainTextEdit" name="userCertEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Courier New</family>
</font>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="tabStopWidth">
<number>80</number>
</property>
<property name="centerOnScroll">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="userCertLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>This is your Retroshare ID. Copy and share with your friends!</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="retroshareid">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Courier New</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QToolButton" name="helpButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/help_64.png</normaloff>:/icons/help_64.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QToolButton" name="shareButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Share your RetroShare ID&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/svg/share.svg</normaloff>:/icons/svg/share.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>