mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-02 03:16:18 -05:00
Added attaching files feature for Forums, not working properly yet.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2038 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e2cc7213a3
commit
9a8f693f3d
@ -93,6 +93,8 @@ ForumsDialog::ForumsDialog(QWidget *parent)
|
||||
|
||||
connect( ui.threadTreeWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( changedThread2() ) );
|
||||
connect( ui.viewBox, SIGNAL( currentIndexChanged ( int ) ), this, SLOT( insertThreads() ) );
|
||||
connect(ui.postText, SIGNAL( anchorClicked(const QUrl &)), SLOT(anchorClicked(const QUrl &)));
|
||||
|
||||
|
||||
connect(ui.expandButton, SIGNAL(clicked()), this, SLOT(togglefileview()));
|
||||
|
||||
@ -1065,3 +1067,49 @@ void ForumsDialog::replytomessage()
|
||||
}
|
||||
}
|
||||
|
||||
void ForumsDialog::anchorClicked (const QUrl& link )
|
||||
{
|
||||
#ifdef FORUM_DEBUG
|
||||
std::cerr << "ForumsDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl;
|
||||
#endif
|
||||
|
||||
if (link.scheme() == "file") {
|
||||
std::string fileName = link.queryItemValue(QString("fileName")).toStdString();
|
||||
std::string fileHash = link.queryItemValue(QString("fileHash")).toStdString();
|
||||
uint32_t fileSize = link.queryItemValue(QString("fileSize")).toInt();
|
||||
|
||||
#ifdef FORUM_DEBUG
|
||||
std::cerr << "ForumsDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize;
|
||||
std::cerr << ". source id : " << dialogId << std::endl;
|
||||
#endif
|
||||
|
||||
if (fileName != "" && fileHash != "") {
|
||||
|
||||
std::list<std::string> srcIds;
|
||||
//srcIds.push_front(dialogId);
|
||||
rsFiles->FileRequest(fileName, fileHash, fileSize, "", 0, srcIds);
|
||||
|
||||
QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.exec();
|
||||
}
|
||||
}
|
||||
else if (link.scheme() == "http")
|
||||
{
|
||||
QDesktopServices::openUrl(link);
|
||||
}
|
||||
else if (link.scheme() == "")
|
||||
{
|
||||
//it's probably a web adress, let's add http:// at the beginning of the link
|
||||
QString newAddress = link.toString();
|
||||
newAddress.prepend("http://");
|
||||
QDesktopServices::openUrl(QUrl(newAddress));
|
||||
}
|
||||
|
||||
}
|
@ -38,6 +38,8 @@ public:
|
||||
void loadForumEmoticons();
|
||||
|
||||
|
||||
void anchorClicked (const QUrl &);
|
||||
|
||||
private slots:
|
||||
|
||||
void insertThreads();
|
||||
|
@ -24,9 +24,27 @@
|
||||
#include <gui/settings/rsharesettings.h>
|
||||
|
||||
#include <QtGui>
|
||||
#include <QFileDialog>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QHashIterator>
|
||||
#include <QDesktopServices>
|
||||
#include <QTextCodec>
|
||||
#include <QTextEdit>
|
||||
#include <QTextCursor>
|
||||
#include <QTextList>
|
||||
#include <QString>
|
||||
#include <QtDebug>
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "rsiface/rsforums.h"
|
||||
#include "rsiface/rsfiles.h"
|
||||
|
||||
#include "gui/feeds/SubFileItem.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
/** Constructor */
|
||||
CreateForumMsg::CreateForumMsg(std::string fId, std::string pId)
|
||||
@ -42,6 +60,8 @@ CreateForumMsg::CreateForumMsg(std::string fId, std::string pId)
|
||||
connect( ui.postmessage_action, SIGNAL( triggered (bool) ), this, SLOT( createMsg( ) ) );
|
||||
connect( ui.close_action, SIGNAL( triggered (bool) ), this, SLOT( cancelMsg( ) ) );
|
||||
connect( ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums()));
|
||||
connect( ui.attachFileButton, SIGNAL(clicked() ), this , SLOT(addFile()));
|
||||
|
||||
|
||||
newMsg();
|
||||
|
||||
@ -281,3 +301,78 @@ void CreateForumMsg::addSmileys()
|
||||
{
|
||||
ui.forumMessage->setText(ui.forumMessage->toHtml() + qobject_cast<QPushButton*>(sender())->toolTip().split("|").first());
|
||||
}
|
||||
|
||||
void CreateForumMsg::addFile()
|
||||
{
|
||||
// select a file
|
||||
QString qfile = QFileDialog::getOpenFileName(this, tr("Add Extra File"), "", "", 0,
|
||||
QFileDialog::DontResolveSymlinks);
|
||||
std::string filePath = qfile.toStdString();
|
||||
if (filePath != "")
|
||||
{
|
||||
CreateForumMsg::addAttachment(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
void CreateForumMsg::addAttachment(std::string filePath) {
|
||||
/* add a SubFileItem to the attachment section */
|
||||
std::cerr << "CreateForumMsg::addFile() hashing file.";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* add widget in for new destination */
|
||||
SubFileItem *file = new SubFileItem(filePath);
|
||||
//file->
|
||||
|
||||
ui.vboxLayout->addWidget(file, 1, 0);
|
||||
|
||||
//when the file is local or is finished hashing, call the fileHashingFinished method to send a chat message
|
||||
if (file->getState() == SFI_STATE_LOCAL) {
|
||||
fileHashingFinished(file);
|
||||
} else {
|
||||
QObject::connect(file,SIGNAL(fileFinished(SubFileItem *)), SLOT(fileHashingFinished(SubFileItem *))) ;
|
||||
}
|
||||
}
|
||||
|
||||
void CreateForumMsg::fileHashingFinished(SubFileItem* file) {
|
||||
std::cerr << "CreateForumMsg::fileHashingFinished() started.";
|
||||
std::cerr << std::endl;
|
||||
|
||||
//check that the file is ok tos end
|
||||
if (file->getState() == SFI_STATE_ERROR) {
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "CreateForumMsg::fileHashingFinished error file is not hashed.";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
//convert fileSize from uint_64 to string for html link
|
||||
char fileSizeChar [100];
|
||||
sprintf(fileSizeChar, "%lld", file->FileSize());
|
||||
std::string fileSize = *(&fileSizeChar);
|
||||
|
||||
std::string mesgString = "<a href='file:?fileHash=" + (file->FileHash()) + "&fileName=" + (file->FileName()) + "&fileSize=" + fileSize + "'>"
|
||||
+ "file:?fileHash=" + (file->FileHash()) + "&fileName=" + (file->FileName()) + "&fileSize=" + fileSize + "</a>";
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "CreateForumMsg::anchorClicked mesgString : " << mesgString << std::endl;
|
||||
#endif
|
||||
|
||||
const char * messageString = mesgString.c_str ();
|
||||
|
||||
//convert char massageString to w_char
|
||||
wchar_t* message;
|
||||
int requiredSize = mbstowcs(NULL, messageString, 0); // C4996
|
||||
/* Add one to leave room for the NULL terminator */
|
||||
message = (wchar_t *)malloc( (requiredSize + 1) * sizeof( wchar_t ));
|
||||
if (! message) {
|
||||
std::cerr << ("Memory allocation failure.\n");
|
||||
}
|
||||
int size = mbstowcs( message, messageString, requiredSize + 1); // C4996
|
||||
if (size == (size_t) (-1)) {
|
||||
printf("Couldn't convert string--invalid multibyte character.\n");
|
||||
}
|
||||
|
||||
ui.forumMessage->setHtml(QString::fromStdWString(message));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <QWidget>
|
||||
#include <string>
|
||||
|
||||
#include "gui/feeds/SubFileItem.h"
|
||||
|
||||
#include "ui_CreateForumMsg.h"
|
||||
|
||||
class CreateForumMsg : public QMainWindow
|
||||
@ -39,6 +41,8 @@ public:
|
||||
|
||||
void loadEmoticonsForums();
|
||||
|
||||
void fileHashingFinished(SubFileItem* file);
|
||||
|
||||
private slots:
|
||||
|
||||
/* actions to take.... */
|
||||
@ -47,6 +51,9 @@ private slots:
|
||||
|
||||
void smileyWidgetForums();
|
||||
void addSmileys();
|
||||
void addFile();
|
||||
void addAttachment(std::string);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
@ -88,6 +88,23 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="attachFileButton">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/add-share24.png</normaloff>:/images/add-share24.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="emoticonButton">
|
||||
<property name="text">
|
||||
@ -112,6 +129,23 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout"/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="toolBar">
|
||||
|
Loading…
Reference in New Issue
Block a user