mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-26 23:36:59 -05:00
Link the original image
This commit is contained in:
parent
d49443caf3
commit
349f0e0c31
@ -21,6 +21,7 @@
|
|||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
#include <QStringList>
|
||||||
#include "PostedCreatePostDialog.h"
|
#include "PostedCreatePostDialog.h"
|
||||||
#include "ui_PostedCreatePostDialog.h"
|
#include "ui_PostedCreatePostDialog.h"
|
||||||
|
|
||||||
@ -37,6 +38,8 @@
|
|||||||
|
|
||||||
#include <util/imageutil.h>
|
#include <util/imageutil.h>
|
||||||
|
|
||||||
|
#include <gui/RetroShareLink.h>
|
||||||
|
|
||||||
PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent):
|
PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent):
|
||||||
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint),
|
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint),
|
||||||
mTokenQueue(tokenQ), mPosted(posted), mGrpId(grpId),
|
mTokenQueue(tokenQ), mPosted(posted), mGrpId(grpId),
|
||||||
@ -55,6 +58,10 @@ PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *pos
|
|||||||
setAttribute ( Qt::WA_DeleteOnClose, true );
|
setAttribute ( Qt::WA_DeleteOnClose, true );
|
||||||
|
|
||||||
ui->RichTextEditWidget->setPlaceHolderTextPosted();
|
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 */
|
/* fill in the available OwnIds for signing */
|
||||||
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, RsGxsId());
|
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, RsGxsId());
|
||||||
@ -88,9 +95,11 @@ void PostedCreatePostDialog::createPost()
|
|||||||
post.mMeta.mGroupId = mGrpId;
|
post.mMeta.mGroupId = mGrpId;
|
||||||
post.mLink = std::string(ui->linkEdit->text().toUtf8());
|
post.mLink = std::string(ui->linkEdit->text().toUtf8());
|
||||||
|
|
||||||
QString text;
|
if(!ui->RichTextEditWidget->toPlainText().trimmed().isEmpty()) {
|
||||||
text = ui->RichTextEditWidget->toHtml();
|
QString text;
|
||||||
post.mNotes = std::string(text.toUtf8());
|
text = ui->RichTextEditWidget->toHtml();
|
||||||
|
post.mNotes = std::string(text.toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
post.mMeta.mAuthorId = authorId;
|
post.mMeta.mAuthorId = authorId;
|
||||||
post.mMeta.mMsgName = std::string(ui->titleEdit->text().toUtf8());
|
post.mMeta.mMsgName = std::string(ui->titleEdit->text().toUtf8());
|
||||||
@ -114,18 +123,33 @@ void PostedCreatePostDialog::createPost()
|
|||||||
accept();
|
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 = "";
|
imagefilename = "";
|
||||||
imagebytes.clear();
|
imagebytes.clear();
|
||||||
|
QPixmap empty;
|
||||||
|
ui->imageLabel->setPixmap(empty);
|
||||||
|
|
||||||
// select a picture file
|
// select a picture file
|
||||||
if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg *.jpeg *.gif *.webp )", imagefilename)) {
|
if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg *.jpeg *.gif *.webp )", imagefilename)) {
|
||||||
QString encodedImage;
|
QString encodedImage;
|
||||||
int maxMessageSize = 34000; //34 kB
|
int maxMessageSize = 34000; //34 kB
|
||||||
QImage image;
|
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());
|
fprintf (stderr, "RsHtml::makeEmbeddedImage() - image \"%s\" can't be load\n", imagefilename.toLatin1().constData());
|
||||||
|
imagefilename = "";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,8 +159,27 @@ void PostedCreatePostDialog::addPicture()
|
|||||||
} else {
|
} else {
|
||||||
imagefilename = "";
|
imagefilename = "";
|
||||||
imagebytes.clear();
|
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()
|
void PostedCreatePostDialog::on_postButton_clicked()
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#define POSTEDCREATEPOSTDIALOG_H
|
#define POSTEDCREATEPOSTDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <gui/common/HashBox.h>
|
||||||
#include "retroshare/rsposted.h"
|
#include "retroshare/rsposted.h"
|
||||||
#include "util/RichTextEdit.h"
|
#include "util/RichTextEdit.h"
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ private slots:
|
|||||||
void on_postButton_clicked();
|
void on_postButton_clicked();
|
||||||
void on_imageButton_clicked();
|
void on_imageButton_clicked();
|
||||||
void on_linkButton_clicked();
|
void on_linkButton_clicked();
|
||||||
|
void fileHashingFinished(QList<HashedFile> hashedFiles);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString mLink;
|
QString mLink;
|
||||||
|
@ -293,20 +293,7 @@
|
|||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="2">
|
<item row="2" column="0" colspan="4">
|
||||||
<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">
|
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Preview</string>
|
<string>Preview</string>
|
||||||
@ -363,6 +350,26 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<item row="0" column="0">
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="pushButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -370,10 +377,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="1" column="0" colspan="4">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="HashBox" name="hashBox">
|
||||||
<property name="text">
|
<property name="sizePolicy">
|
||||||
<string>Picture size is limited to 34 KB</string>
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="widgetResizable">
|
||||||
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -457,6 +470,12 @@
|
|||||||
<extends>QLabel</extends>
|
<extends>QLabel</extends>
|
||||||
<header>gui/common/StyledLabel.h</header>
|
<header>gui/common/StyledLabel.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>HashBox</class>
|
||||||
|
<extends>QScrollArea</extends>
|
||||||
|
<header location="global">gui/common/HashBox.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>HeaderFrame</class>
|
<class>HeaderFrame</class>
|
||||||
<extends>QFrame</extends>
|
<extends>QFrame</extends>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user