mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-26 07:16:11 -05:00
Link the original image
This commit is contained in:
parent
d49443caf3
commit
349f0e0c31
@ -21,6 +21,7 @@
|
||||
#include <QBuffer>
|
||||
#include <QMessageBox>
|
||||
#include <QByteArray>
|
||||
#include <QStringList>
|
||||
#include "PostedCreatePostDialog.h"
|
||||
#include "ui_PostedCreatePostDialog.h"
|
||||
|
||||
@ -37,6 +38,8 @@
|
||||
|
||||
#include <util/imageutil.h>
|
||||
|
||||
#include <gui/RetroShareLink.h>
|
||||
|
||||
PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent):
|
||||
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint),
|
||||
mTokenQueue(tokenQ), mPosted(posted), mGrpId(grpId),
|
||||
@ -55,6 +58,10 @@ PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *pos
|
||||
setAttribute ( Qt::WA_DeleteOnClose, true );
|
||||
|
||||
ui->RichTextEditWidget->setPlaceHolderTextPosted();
|
||||
|
||||
ui->hashBox->setAutoHide(true);
|
||||
ui->hashBox->setDefaultTransferRequestFlags(RS_FILE_REQ_ANONYMOUS_ROUTING);
|
||||
connect(ui->hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
|
||||
|
||||
/* fill in the available OwnIds for signing */
|
||||
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, RsGxsId());
|
||||
@ -88,9 +95,11 @@ void PostedCreatePostDialog::createPost()
|
||||
post.mMeta.mGroupId = mGrpId;
|
||||
post.mLink = std::string(ui->linkEdit->text().toUtf8());
|
||||
|
||||
QString text;
|
||||
text = ui->RichTextEditWidget->toHtml();
|
||||
post.mNotes = std::string(text.toUtf8());
|
||||
if(!ui->RichTextEditWidget->toPlainText().trimmed().isEmpty()) {
|
||||
QString text;
|
||||
text = ui->RichTextEditWidget->toHtml();
|
||||
post.mNotes = std::string(text.toUtf8());
|
||||
}
|
||||
|
||||
post.mMeta.mAuthorId = authorId;
|
||||
post.mMeta.mMsgName = std::string(ui->titleEdit->text().toUtf8());
|
||||
@ -114,18 +123,33 @@ void PostedCreatePostDialog::createPost()
|
||||
accept();
|
||||
}
|
||||
|
||||
void PostedCreatePostDialog::addPicture()
|
||||
void PostedCreatePostDialog::fileHashingFinished(QList<HashedFile> hashedFiles)
|
||||
{
|
||||
if(hashedFiles.length() > 0) { //It seems like it returns 0 if hashing cancelled
|
||||
HashedFile hashedFile = hashedFiles[0]; //Should be exactly one file
|
||||
RetroShareLink link;
|
||||
link = RetroShareLink::createFile(hashedFile.filename, hashedFile.size, QString::fromStdString(hashedFile.hash.toStdString()));
|
||||
ui->linkEdit->setText(link.toString());
|
||||
}
|
||||
ui->submitButton->setEnabled(true);
|
||||
ui->pushButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void PostedCreatePostDialog::addPicture()
|
||||
{
|
||||
imagefilename = "";
|
||||
imagebytes.clear();
|
||||
QPixmap empty;
|
||||
ui->imageLabel->setPixmap(empty);
|
||||
|
||||
// select a picture file
|
||||
if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg *.jpeg *.gif *.webp )", imagefilename)) {
|
||||
QString encodedImage;
|
||||
int maxMessageSize = 34000; //34 kB
|
||||
QImage image;
|
||||
if (image.load (imagefilename) == false) {
|
||||
if (image.load(imagefilename) == false) {
|
||||
fprintf (stderr, "RsHtml::makeEmbeddedImage() - image \"%s\" can't be load\n", imagefilename.toLatin1().constData());
|
||||
imagefilename = "";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -135,8 +159,27 @@ void PostedCreatePostDialog::addPicture()
|
||||
} else {
|
||||
imagefilename = "";
|
||||
imagebytes.clear();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Do we need to hash the image?
|
||||
QMessageBox::StandardButton answer;
|
||||
answer = QMessageBox::question(this, tr("Post image"), tr("Do you want to share and link the original image?"), QMessageBox::Yes|QMessageBox::No);
|
||||
if (answer == QMessageBox::Yes) {
|
||||
if(!ui->linkEdit->text().trimmed().isEmpty()) {
|
||||
answer = QMessageBox::question(this, tr("Post image"), tr("You already added a link.<br />Do you want to replace it?"), QMessageBox::Yes|QMessageBox::No);
|
||||
}
|
||||
}
|
||||
|
||||
//If still yes then link it
|
||||
if(answer == QMessageBox::Yes) {
|
||||
ui->submitButton->setEnabled(false);
|
||||
ui->pushButton->setEnabled(false);
|
||||
QStringList files;
|
||||
files.append(imagefilename);
|
||||
ui->hashBox->addAttachments(files,RS_FILE_REQ_ANONYMOUS_ROUTING);
|
||||
}
|
||||
}
|
||||
|
||||
void PostedCreatePostDialog::on_postButton_clicked()
|
||||
|
@ -22,6 +22,7 @@
|
||||
#define POSTEDCREATEPOSTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <gui/common/HashBox.h>
|
||||
#include "retroshare/rsposted.h"
|
||||
#include "util/RichTextEdit.h"
|
||||
|
||||
@ -53,6 +54,7 @@ private slots:
|
||||
void on_postButton_clicked();
|
||||
void on_imageButton_clicked();
|
||||
void on_linkButton_clicked();
|
||||
void fileHashingFinished(QList<HashedFile> hashedFiles);
|
||||
|
||||
private:
|
||||
QString mLink;
|
||||
|
@ -293,20 +293,7 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>447</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<item row="2" column="0" colspan="4">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Preview</string>
|
||||
@ -363,6 +350,26 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>447</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Picture size is limited to 34 KB</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
@ -370,10 +377,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Picture size is limited to 34 KB</string>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="HashBox" name="hashBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -457,6 +470,12 @@
|
||||
<extends>QLabel</extends>
|
||||
<header>gui/common/StyledLabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>HashBox</class>
|
||||
<extends>QScrollArea</extends>
|
||||
<header location="global">gui/common/HashBox.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>HeaderFrame</class>
|
||||
<extends>QFrame</extends>
|
||||
|
Loading…
x
Reference in New Issue
Block a user