mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-19 06:20:44 -04:00
Added attaching files support via drag and drop for Create Forum Message.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3193 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
fc6a0dff50
commit
cca5db6332
3 changed files with 154 additions and 57 deletions
|
@ -29,6 +29,8 @@
|
||||||
#include "rsiface/rsforums.h"
|
#include "rsiface/rsforums.h"
|
||||||
#include "rsiface/rsfiles.h"
|
#include "rsiface/rsfiles.h"
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "gui/feeds/AttachFileItem.h"
|
#include "gui/feeds/AttachFileItem.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -382,6 +384,83 @@ void CreateForumMsg::fileHashingFinished(AttachFileItem* file) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreateForumMsg::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
if (!(Qt::CopyAction & event->possibleActions()))
|
||||||
|
{
|
||||||
|
std::cerr << "CreateForumMsg::dropEvent() Rejecting uncopyable DropAction" << std::endl;
|
||||||
|
|
||||||
|
/* can't do it */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "CreateForumMsg::dropEvent() Formats" << std::endl;
|
||||||
|
QStringList formats = event->mimeData()->formats();
|
||||||
|
QStringList::iterator it;
|
||||||
|
for(it = formats.begin(); it != formats.end(); it++)
|
||||||
|
{
|
||||||
|
std::cerr << "Format: " << (*it).toStdString() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->mimeData()->hasUrls())
|
||||||
|
{
|
||||||
|
std::cerr << "CreateForumMsg::dropEvent() Urls:" << std::endl;
|
||||||
|
|
||||||
|
QList<QUrl> urls = event->mimeData()->urls();
|
||||||
|
QList<QUrl>::iterator uit;
|
||||||
|
for(uit = urls.begin(); uit != urls.end(); uit++)
|
||||||
|
{
|
||||||
|
std::string localpath = uit->toLocalFile().toStdString();
|
||||||
|
std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl;
|
||||||
|
std::cerr << "or As Local File: " << localpath << std::endl;
|
||||||
|
|
||||||
|
if (localpath.size() > 0)
|
||||||
|
{
|
||||||
|
struct stat buf;
|
||||||
|
//Check that the file does exist and is not a directory
|
||||||
|
if ((-1 == stat(localpath.c_str(), &buf))) {
|
||||||
|
std::cerr << "CreateForumMsg::dropEvent() file does not exists."<< std::endl;
|
||||||
|
QMessageBox mb(tr("Drop file error."), tr("File not found or file name not accepted."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||||
|
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||||
|
mb.exec();
|
||||||
|
} else if (S_ISDIR(buf.st_mode)) {
|
||||||
|
std::cerr << "CreateForumMsg::dropEvent() directory not accepted."<< std::endl;
|
||||||
|
QMessageBox mb(tr("Drop file error."), tr("Directory can't be dropped, only files are accepted."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||||
|
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||||
|
mb.exec();
|
||||||
|
} else {
|
||||||
|
CreateForumMsg::addAttachment(localpath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event->setDropAction(Qt::CopyAction);
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateForumMsg::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
/* print out mimeType */
|
||||||
|
std::cerr << "CreateForumMsg::dragEnterEvent() Formats" << std::endl;
|
||||||
|
QStringList formats = event->mimeData()->formats();
|
||||||
|
QStringList::iterator it;
|
||||||
|
for(it = formats.begin(); it != formats.end(); it++)
|
||||||
|
{
|
||||||
|
std::cerr << "Format: " << (*it).toStdString() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->mimeData()->hasUrls())
|
||||||
|
{
|
||||||
|
std::cerr << "CreateForumMsg::dragEnterEvent() Accepting Urls" << std::endl;
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "CreateForumMsg::dragEnterEvent() No Urls" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CreateForumMsg::pasteLink()
|
void CreateForumMsg::pasteLink()
|
||||||
{
|
{
|
||||||
ui.forumMessage->insertHtml(RSLinkClipboard::toHtml()) ;
|
ui.forumMessage->insertHtml(RSLinkClipboard::toHtml()) ;
|
||||||
|
|
|
@ -60,6 +60,9 @@ private slots:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent (QCloseEvent * event);
|
void closeEvent (QCloseEvent * event);
|
||||||
|
virtual void dragEnterEvent(QDragEnterEvent *event);
|
||||||
|
virtual void dropEvent(QDropEvent *event);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Define the popup menus for the Context menu */
|
/** Define the popup menus for the Context menu */
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>482</width>
|
<width>482</width>
|
||||||
<height>406</height>
|
<height>448</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -110,6 +110,9 @@ border: 1px solid #CCCCCC;}</string>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="attachFileButton">
|
<widget class="QToolButton" name="attachFileButton">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Attach File</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
|
@ -233,7 +236,16 @@ border: 1px solid #CCCCCC;}</string>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
|
<widget class="QGroupBox" name="groupBox_2">
|
||||||
|
<property name="title">
|
||||||
|
<string>Attach files via drag and drop</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_7">
|
||||||
|
<item row="0" column="0">
|
||||||
<widget class="QScrollArea" name="scrollArea">
|
<widget class="QScrollArea" name="scrollArea">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>You can attach files via drag and drop here in this window</string>
|
||||||
|
</property>
|
||||||
<property name="widgetResizable">
|
<property name="widgetResizable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@ -242,7 +254,7 @@ border: 1px solid #CCCCCC;}</string>
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>460</width>
|
<width>440</width>
|
||||||
<height>60</height>
|
<height>60</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -274,6 +286,9 @@ border: 1px solid #CCCCCC;}</string>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue