2018-12-25 21:10:15 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/TheWire/PulseAddDialog.cpp *
|
|
|
|
* *
|
2020-02-29 11:47:00 +11:00
|
|
|
* Copyright (c) 2012-2020 Robert Fernie <retroshare.project@gmail.com> *
|
2018-12-25 21:10:15 +01:00
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
#include <iostream>
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
#include "PulseDetails.h"
|
|
|
|
|
|
|
|
#include "PulseAddDialog.h"
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-04-11 12:55:04 +10:00
|
|
|
const uint32_t PULSE_MAX_SIZE = 1000; // 1k char.
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
PulseAddDialog::PulseAddDialog(QWidget *parent)
|
2020-05-16 22:35:32 +10:00
|
|
|
: QWidget(parent), mIsReply(false)
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
connect(ui.pushButton_Post, SIGNAL( clicked( void ) ), this, SLOT( postPulse( void ) ) );
|
|
|
|
connect(ui.pushButton_AddURL, SIGNAL( clicked( void ) ), this, SLOT( addURL( void ) ) );
|
2020-04-11 12:55:04 +10:00
|
|
|
connect(ui.pushButton_ClearDisplayAs, SIGNAL( clicked( void ) ), this, SLOT( clearDisplayAs( void ) ) );
|
2012-02-13 18:43:15 +00:00
|
|
|
connect(ui.pushButton_Cancel, SIGNAL( clicked( void ) ), this, SLOT( cancelPulse( void ) ) );
|
2020-04-11 12:55:04 +10:00
|
|
|
connect(ui.textEdit_Pulse, SIGNAL( textChanged( void ) ), this, SLOT( pulseTextChanged( void ) ) );
|
2020-02-29 11:47:00 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void PulseAddDialog::setGroup(RsWireGroup &group)
|
|
|
|
{
|
|
|
|
ui.label_groupName->setText(QString::fromStdString(group.mMeta.mGroupName));
|
|
|
|
ui.label_idName->setText(QString::fromStdString(group.mMeta.mAuthorId.toStdString()));
|
|
|
|
mGroup = group;
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-05-16 22:35:32 +10:00
|
|
|
// set ReplyWith Group.
|
|
|
|
void PulseAddDialog::setGroup(const RsGxsGroupId &grpId)
|
|
|
|
{
|
|
|
|
/* fetch in the background */
|
|
|
|
RsWireGroupSPtr pGroup;
|
|
|
|
rsWire->getWireGroup(grpId, pGroup);
|
|
|
|
|
|
|
|
setGroup(*pGroup);
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-04-11 12:55:04 +10:00
|
|
|
void PulseAddDialog::cleanup()
|
2020-02-29 11:47:00 +11:00
|
|
|
{
|
2020-04-10 21:36:31 +10:00
|
|
|
if (mIsReply)
|
|
|
|
{
|
2020-05-16 22:35:32 +10:00
|
|
|
std::cerr << "PulseAddDialog::cleanup() cleaning up old replyto";
|
2020-04-10 21:36:31 +10:00
|
|
|
std::cerr << std::endl;
|
|
|
|
QLayout *layout = ui.widget_replyto->layout();
|
|
|
|
// completely delete layout and sublayouts
|
|
|
|
QLayoutItem * item;
|
|
|
|
QWidget * widget;
|
|
|
|
while ((item = layout->takeAt(0)))
|
|
|
|
{
|
|
|
|
if ((widget = item->widget()) != 0)
|
|
|
|
{
|
2020-05-16 22:35:32 +10:00
|
|
|
std::cerr << "PulseAddDialog::cleanup() removing widget";
|
2020-04-10 21:36:31 +10:00
|
|
|
std::cerr << std::endl;
|
|
|
|
widget->hide();
|
|
|
|
delete widget;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-16 22:35:32 +10:00
|
|
|
std::cerr << "PulseAddDialog::cleanup() removing item";
|
2020-04-10 21:36:31 +10:00
|
|
|
std::cerr << std::endl;
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// then finally
|
|
|
|
delete layout;
|
2020-04-11 12:55:04 +10:00
|
|
|
mIsReply = false;
|
2020-04-10 21:36:31 +10:00
|
|
|
}
|
2020-04-11 12:55:04 +10:00
|
|
|
ui.frame_reply->setVisible(false);
|
|
|
|
ui.comboBox_sentiment->setCurrentIndex(0);
|
|
|
|
ui.lineEdit_URL->setText("");
|
|
|
|
ui.lineEdit_DisplayAs->setText("");
|
|
|
|
ui.textEdit_Pulse->setPlainText("");
|
|
|
|
// disable URL until functionality finished.
|
|
|
|
ui.frame_URL->setEnabled(false);
|
2020-05-17 12:10:46 +10:00
|
|
|
|
|
|
|
ui.pushButton_Post->setEnabled(false);
|
|
|
|
ui.pushButton_Post->setText("Post Pulse to Wire");
|
|
|
|
ui.frame_input->setVisible(true);
|
|
|
|
ui.widget_sentiment->setVisible(true);
|
2020-04-11 12:55:04 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
void PulseAddDialog::pulseTextChanged()
|
|
|
|
{
|
|
|
|
std::string pulseText = ui.textEdit_Pulse->toPlainText().toStdString();
|
|
|
|
bool enable = (pulseText.size() > 0) && (pulseText.size() < PULSE_MAX_SIZE);
|
|
|
|
ui.pushButton_Post->setEnabled(enable);
|
|
|
|
}
|
2020-04-10 21:36:31 +10:00
|
|
|
|
2020-05-16 22:35:32 +10:00
|
|
|
// Old Interface, deprecate / make internal.
|
2020-05-17 12:10:46 +10:00
|
|
|
void PulseAddDialog::setReplyTo(RsWirePulse &pulse, std::string &groupName, uint32_t replyType)
|
2020-04-11 12:55:04 +10:00
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
mIsReply = true;
|
|
|
|
mReplyToPulse = pulse;
|
2020-05-17 12:10:46 +10:00
|
|
|
mReplyType = replyType;
|
2020-04-11 12:55:04 +10:00
|
|
|
ui.frame_reply->setVisible(true);
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
{
|
2020-03-13 16:44:15 +11:00
|
|
|
std::map<rstime_t, RsWirePulse *> replies;
|
|
|
|
PulseDetails *details = new PulseDetails(NULL, &pulse, groupName, replies);
|
2020-02-29 11:47:00 +11:00
|
|
|
// add extra widget into layout.
|
|
|
|
QVBoxLayout *vbox = new QVBoxLayout();
|
|
|
|
vbox->addWidget(details);
|
|
|
|
vbox->setSpacing(1);
|
|
|
|
vbox->setContentsMargins(0,0,0,0);
|
|
|
|
ui.widget_replyto->setLayout(vbox);
|
|
|
|
ui.widget_replyto->setVisible(true);
|
|
|
|
}
|
2020-05-17 12:10:46 +10:00
|
|
|
|
|
|
|
if (mReplyType & WIRE_PULSE_TYPE_REPLY)
|
|
|
|
{
|
|
|
|
ui.pushButton_Post->setText("Reply to Pulse");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// cannot add msg for like / republish.
|
|
|
|
ui.pushButton_Post->setEnabled(true);
|
|
|
|
ui.frame_input->setVisible(false);
|
|
|
|
ui.widget_sentiment->setVisible(false);
|
|
|
|
if (mReplyType & WIRE_PULSE_TYPE_REPUBLISH) {
|
|
|
|
ui.pushButton_Post->setText("Republish Pulse");
|
|
|
|
}
|
|
|
|
else if (mReplyType & WIRE_PULSE_TYPE_LIKE) {
|
|
|
|
ui.pushButton_Post->setText("Like Pulse");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-13 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 12:10:46 +10:00
|
|
|
void PulseAddDialog::setReplyTo(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId, uint32_t replyType)
|
2020-05-16 22:35:32 +10:00
|
|
|
{
|
|
|
|
/* fetch in the background */
|
|
|
|
RsWireGroupSPtr pGroup;
|
|
|
|
if (!rsWire->getWireGroup(grpId, pGroup))
|
|
|
|
{
|
|
|
|
std::cerr << "PulseAddDialog::setRplyTo() failed to fetch group";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsWirePulseSPtr pPulse;
|
|
|
|
if (!rsWire->getWirePulse(grpId, msgId, pPulse))
|
|
|
|
{
|
|
|
|
std::cerr << "PulseAddDialog::setRplyTo() failed to fetch pulse";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-17 12:10:46 +10:00
|
|
|
setReplyTo(*pPulse, pGroup->mMeta.mGroupName, replyType);
|
2020-05-16 22:35:32 +10:00
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
void PulseAddDialog::addURL()
|
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::addURL()";
|
|
|
|
std::cerr << std::endl;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-11 12:55:04 +10:00
|
|
|
void PulseAddDialog::clearDisplayAs()
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
2020-04-11 12:55:04 +10:00
|
|
|
std::cerr << "PulseAddDialog::clearDisplayAs()";
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << std::endl;
|
2012-02-13 18:43:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PulseAddDialog::cancelPulse()
|
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::cancelPulse()";
|
|
|
|
std::cerr << std::endl;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
clearDialog();
|
|
|
|
hide();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::postPulse()
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::postPulse()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
if (mIsReply)
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
postReplyPulse();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
postOriginalPulse();
|
2012-02-13 18:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::postOriginalPulse()
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::postOriginalPulse()";
|
|
|
|
std::cerr << std::endl;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-05-16 22:35:32 +10:00
|
|
|
RsWirePulseSPtr pPulse(new RsWirePulse());
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-05-16 22:35:32 +10:00
|
|
|
pPulse->mSentiment = WIRE_PULSE_SENTIMENT_NO_SENTIMENT;
|
|
|
|
pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
|
|
|
|
// set images here too.
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-05-16 22:35:32 +10:00
|
|
|
// this should be in async thread, so doesn't block UI thread.
|
|
|
|
if (!rsWire->createOriginalPulse(mGroup.mMeta.mGroupId, pPulse))
|
|
|
|
{
|
|
|
|
std::cerr << "PulseAddDialog::postOriginalPulse() FAILED";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2020-02-29 11:47:00 +11:00
|
|
|
|
|
|
|
clearDialog();
|
|
|
|
hide();
|
2012-02-13 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 12:55:04 +10:00
|
|
|
uint32_t PulseAddDialog::toPulseSentiment(int index)
|
|
|
|
{
|
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
return WIRE_PULSE_SENTIMENT_POSITIVE;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return WIRE_PULSE_SENTIMENT_NEUTRAL;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
return WIRE_PULSE_SENTIMENT_NEGATIVE;
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
return WIRE_PULSE_SENTIMENT_NO_SENTIMENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::postReplyPulse()
|
|
|
|
{
|
|
|
|
std::cerr << "PulseAddDialog::postReplyPulse()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2020-05-16 22:35:32 +10:00
|
|
|
RsWirePulseSPtr pPulse(new RsWirePulse());
|
2020-02-29 11:47:00 +11:00
|
|
|
|
2020-05-16 22:35:32 +10:00
|
|
|
pPulse->mSentiment = toPulseSentiment(ui.comboBox_sentiment->currentIndex());
|
|
|
|
pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
|
|
|
|
// set images too.
|
2020-02-29 11:47:00 +11:00
|
|
|
|
2020-05-16 22:35:32 +10:00
|
|
|
// this should be in async thread, so doesn't block UI thread.
|
|
|
|
if (!rsWire->createReplyPulse(mReplyToPulse.mMeta.mGroupId,
|
|
|
|
mReplyToPulse.mMeta.mOrigMsgId,
|
|
|
|
mGroup.mMeta.mGroupId,
|
2020-05-17 12:10:46 +10:00
|
|
|
mReplyType,
|
2020-05-16 22:35:32 +10:00
|
|
|
pPulse))
|
|
|
|
{
|
|
|
|
std::cerr << "PulseAddDialog::postReplyPulse() FAILED";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
clearDialog();
|
|
|
|
hide();
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::clearDialog()
|
|
|
|
{
|
|
|
|
ui.textEdit_Pulse->setPlainText("");
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|