mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-07 16:45:11 -04:00
Added new widget for hashing files.
Added new common class FilesDefs to handle informations of file types like icons and names. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4713 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
c9fc77f2d1
commit
0ee35b55f4
35 changed files with 932 additions and 1031 deletions
|
@ -49,7 +49,6 @@
|
|||
#include "gui/common/PeerDefs.h"
|
||||
#include "gui/RetroShareLink.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "gui/feeds/AttachFileItem.h"
|
||||
#include "gui/common/Emoticons.h"
|
||||
#include "textformat.h"
|
||||
#include "util/misc.h"
|
||||
|
@ -109,7 +108,7 @@ public:
|
|||
|
||||
/** Constructor */
|
||||
MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
|
||||
: QMainWindow(parent, flags), mCheckAttachment(true)
|
||||
: QMainWindow(parent, flags)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui.setupUi(this);
|
||||
|
@ -168,6 +167,9 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
|
|||
connect(ui.msgFileList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuFileList(QPoint)));
|
||||
connect(ui.msgSendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuMsgSendList(QPoint)));
|
||||
|
||||
connect(ui.hashBox, SIGNAL(fileHashingStarted()), this, SLOT(fileHashingStarted()));
|
||||
connect(ui.hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
|
||||
|
||||
setWindowModified(ui.msgText->document()->isModified());
|
||||
actionSave->setEnabled(ui.msgText->document()->isModified());
|
||||
actionUndo->setEnabled(ui.msgText->document()->isUndoAvailable());
|
||||
|
@ -304,6 +306,8 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
|
|||
ui.tagButton->setMenu(menu);
|
||||
|
||||
setAcceptDrops(true);
|
||||
ui.hashBox->setDropWidget(this);
|
||||
ui.hashBox->setAutoHide(true);
|
||||
|
||||
#ifdef RS_RELEASE_VERSION
|
||||
ui.imagebtn->setVisible(false);
|
||||
|
@ -2231,88 +2235,35 @@ void MessageComposer::attachFile()
|
|||
// select a file
|
||||
QStringList files;
|
||||
if (misc::getOpenFileNames(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", files)) {
|
||||
for (QStringList::iterator fileIt = files.begin(); fileIt != files.end(); fileIt++) {
|
||||
addAttachment((*fileIt).toUtf8().constData());
|
||||
}
|
||||
ui.hashBox->addAttachments(files);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageComposer::addAttachment(std::string filePath)
|
||||
void MessageComposer::fileHashingStarted()
|
||||
{
|
||||
/* add a AttachFileItem to the attachment section */
|
||||
std::cerr << "MessageComposer::addFile() hashing file.";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "MessageComposer::fileHashingStarted() started." << std::endl;
|
||||
|
||||
/* add widget in for new destination */
|
||||
AttachFileItem *file = new AttachFileItem(filePath);
|
||||
|
||||
ui.hashBox->show();
|
||||
ui.msgFileList->hide();
|
||||
ui.verticalLayout->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() == AFI_STATE_LOCAL) {
|
||||
fileHashingFinished(file);
|
||||
} else {
|
||||
QObject::connect(file,SIGNAL(fileFinished(AttachFileItem *)),this, SLOT(fileHashingFinished(AttachFileItem *))) ;
|
||||
}
|
||||
mAttachments.push_back(file);
|
||||
|
||||
if (mCheckAttachment)
|
||||
{
|
||||
checkAttachmentReady();
|
||||
}
|
||||
ui.hashBox->show();
|
||||
}
|
||||
|
||||
void MessageComposer::fileHashingFinished(AttachFileItem* file)
|
||||
void MessageComposer::fileHashingFinished(QList<HashedFile> hashedFiles)
|
||||
{
|
||||
std::cerr << "MessageComposer::fileHashingFinished() started.";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "MessageComposer::fileHashingFinished() started." << std::endl;
|
||||
|
||||
//check that the file is ok tos end
|
||||
if (file->getState() == AFI_STATE_ERROR) {
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "MessageComposer::fileHashingFinished error file is not hashed.";
|
||||
#endif
|
||||
return;
|
||||
QList<HashedFile>::iterator it;
|
||||
for (it = hashedFiles.begin(); it != hashedFiles.end(); ++it) {
|
||||
FileInfo info;
|
||||
info.fname = it->filename.toUtf8().constData();
|
||||
info.hash = it->hash;
|
||||
info.size = it->size;
|
||||
addFile(info);
|
||||
}
|
||||
|
||||
FileInfo fileInfo;
|
||||
fileInfo.fname = file->FileName();
|
||||
fileInfo.hash = file->FileHash();
|
||||
fileInfo.size = file->FileSize();
|
||||
|
||||
addFile(fileInfo);
|
||||
}
|
||||
|
||||
void MessageComposer::checkAttachmentReady()
|
||||
{
|
||||
std::list<AttachFileItem *>::iterator fit;
|
||||
|
||||
mCheckAttachment = false;
|
||||
|
||||
for(fit = mAttachments.begin(); fit != mAttachments.end(); fit++)
|
||||
{
|
||||
if (!(*fit)->isHidden())
|
||||
{
|
||||
if (!(*fit)->ready())
|
||||
{
|
||||
ui.actionSend->setEnabled(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fit == mAttachments.end())
|
||||
{
|
||||
ui.actionSend->setEnabled(true);
|
||||
ui.hashBox->hide();
|
||||
ui.msgFileList->show();
|
||||
}
|
||||
|
||||
/* repeat... */
|
||||
int msec_rate = 1000;
|
||||
QTimer::singleShot( msec_rate, this, SLOT(checkAttachmentReady(void)));
|
||||
ui.actionSend->setEnabled(true);
|
||||
ui.hashBox->hide();
|
||||
ui.msgFileList->show();
|
||||
}
|
||||
|
||||
/* clear Filter */
|
||||
|
@ -2470,82 +2421,6 @@ void MessageComposer::friendDetails()
|
|||
ConfCertDialog::showIt(id, ConfCertDialog::PageDetails);
|
||||
}
|
||||
|
||||
void MessageComposer::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
/* print out mimeType */
|
||||
std::cerr << "PopupChatDialog::dragEnterEvent() Formats";
|
||||
std::cerr << std::endl;
|
||||
|
||||
QStringList formats = event->mimeData()->formats();
|
||||
QStringList::iterator it;
|
||||
for(it = formats.begin(); it != formats.end(); it++) {
|
||||
std::cerr << "Format: " << (*it).toStdString();
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
std::cerr << "PopupChatDialog::dragEnterEvent() Accepting Urls";
|
||||
std::cerr << std::endl;
|
||||
event->acceptProposedAction();
|
||||
} else {
|
||||
std::cerr << "PopupChatDialog::dragEnterEvent() No Urls";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void MessageComposer::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (!(Qt::CopyAction & event->possibleActions())) {
|
||||
std::cerr << "PopupChatDialog::dropEvent() Rejecting uncopyable DropAction";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* can't do it */
|
||||
return;
|
||||
}
|
||||
|
||||
std::cerr << "PopupChatDialog::dropEvent() Formats";
|
||||
std::cerr << std::endl;
|
||||
|
||||
QStringList formats = event->mimeData()->formats();
|
||||
QStringList::iterator it;
|
||||
for(it = formats.begin(); it != formats.end(); it++) {
|
||||
std::cerr << "Format: " << (*it).toStdString();
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
std::cerr << "PopupChatDialog::dropEvent() Urls:";
|
||||
std::cerr << std::endl;
|
||||
|
||||
QList<QUrl> urls = event->mimeData()->urls();
|
||||
QList<QUrl>::iterator uit;
|
||||
for(uit = urls.begin(); uit != urls.end(); uit++) {
|
||||
QString localpath = uit->toLocalFile();
|
||||
std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl;
|
||||
std::cerr << "or As Local File: " << localpath.toStdString() << std::endl;
|
||||
|
||||
if (localpath.isEmpty() == false) {
|
||||
//Check that the file does exist and is not a directory
|
||||
QDir dir(localpath);
|
||||
if (dir.exists()) {
|
||||
std::cerr << "PopupChatDialog::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,this);
|
||||
mb.exec();
|
||||
} else if (QFile::exists(localpath)) {
|
||||
addAttachment(localpath.toUtf8().constData());
|
||||
} else {
|
||||
std::cerr << "PopupChatDialog::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,this);
|
||||
mb.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void MessageComposer::tagAboutToShow()
|
||||
{
|
||||
TagsMenu *menu = dynamic_cast<TagsMenu*>(ui.tagButton->menu());
|
||||
|
@ -2575,7 +2450,7 @@ void MessageComposer::tagSet(int tagId, bool set)
|
|||
m_tagIds.push_back(tagId);
|
||||
/* Keep the list sorted */
|
||||
m_tagIds.sort();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (set == false) {
|
||||
m_tagIds.remove(tagId);
|
||||
|
|
|
@ -31,7 +31,6 @@ class QComboBox;
|
|||
class QFontComboBox;
|
||||
class QTextEdit;
|
||||
class QTextCharFormat;
|
||||
class AttachFileItem;
|
||||
class RSTreeWidgetItemCompareRole;
|
||||
|
||||
class MessageComposer : public QMainWindow
|
||||
|
@ -80,9 +79,6 @@ protected:
|
|||
void closeEvent (QCloseEvent * event);
|
||||
bool eventFilter(QObject *obj, QEvent *ev);
|
||||
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event);
|
||||
virtual void dropEvent(QDropEvent *event);
|
||||
|
||||
private slots:
|
||||
/* toggle Contacts DockWidget */
|
||||
void contextMenu(QPoint);
|
||||
|
@ -119,11 +115,10 @@ private slots:
|
|||
|
||||
void clipboardDataChanged();
|
||||
|
||||
void fileHashingFinished(AttachFileItem* file);
|
||||
void fileHashingStarted();
|
||||
void fileHashingFinished(QList<HashedFile> hashedFiles);
|
||||
|
||||
void attachFile();
|
||||
void addAttachment(std::string);
|
||||
void checkAttachmentReady();
|
||||
|
||||
void fontSizeIncrease();
|
||||
void fontSizeDecrease();
|
||||
|
@ -216,11 +211,6 @@ private:
|
|||
std::list<uint32_t> m_tagIds;
|
||||
QList<QLabel*> tagLabels;
|
||||
|
||||
/* maps of files */
|
||||
std::list<AttachFileItem *> mAttachments;
|
||||
|
||||
bool mCheckAttachment;
|
||||
|
||||
RSTreeWidgetItemCompareRole *m_compareRole;
|
||||
QCompleter *m_completer;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>796</width>
|
||||
<height>588</height>
|
||||
<height>624</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
|
@ -17,7 +17,7 @@
|
|||
<string>Compose</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/folder-draft.png</normaloff>:/images/folder-draft.png</iconset>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
|
@ -397,7 +397,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/textedit/format_font_size_more.png</normaloff>:/images/textedit/format_font_size_more.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -429,7 +429,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/textedit/format_font_size_less.png</normaloff>:/images/textedit/format_font_size_less.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -467,7 +467,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/textedit/textbold.png</normaloff>:/images/textedit/textbold.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -508,7 +508,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/textedit/textitalic.png</normaloff>:/images/textedit/textitalic.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -614,7 +614,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/add_image24.png</normaloff>:/images/add_image24.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -640,7 +640,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/textedit/hi22-action-format-text-code.png</normaloff>:/images/textedit/hi22-action-format-text-code.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -673,7 +673,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/emoticons/kopete/kopete020.png</normaloff>:/images/emoticons/kopete/kopete020.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -711,7 +711,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/textedit/textunder.png</normaloff>:/images/textedit/textunder.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -784,15 +784,6 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>22</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>22</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" rowspan="2">
|
||||
|
@ -835,7 +826,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<string>Tags</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/tag24.png</normaloff>:/images/tag24.png</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
|
@ -923,41 +914,10 @@ border: 1px solid #CCCCCC;}</string>
|
|||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QScrollArea" name="hashBox">
|
||||
<widget class="HashBox" name="hashBox">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>560</width>
|
||||
<height>57</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>46</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -1006,7 +966,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
</widget>
|
||||
<action name="actionSend">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/send24.png</normaloff>:/images/send24.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -1018,7 +978,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
</action>
|
||||
<action name="actionReply">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/replymail24.png</normaloff>:/images/replymail24.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -1027,7 +987,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
</action>
|
||||
<action name="actionContactsView">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/contacts24.png</normaloff>:/images/contacts24.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -1039,7 +999,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
</action>
|
||||
<action name="actionSaveas">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/save24.png</normaloff>:/images/save24.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -1051,7 +1011,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
</action>
|
||||
<action name="actionAttach">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/attach.png</normaloff>:/images/attach.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -1066,7 +1026,7 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/quote_24.png</normaloff>:/images/quote_24.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -1077,6 +1037,14 @@ border: 1px solid #CCCCCC;}</string>
|
|||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>HashBox</class>
|
||||
<extends>QScrollArea</extends>
|
||||
<header location="global">gui/common/HashBox.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>recipientWidget</tabstop>
|
||||
<tabstop>titleEdit</tabstop>
|
||||
|
@ -1093,6 +1061,8 @@ border: 1px solid #CCCCCC;}</string>
|
|||
<tabstop>comboFont</tabstop>
|
||||
<tabstop>hashBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue