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:
thunder2 2011-12-07 13:08:12 +00:00
parent c9fc77f2d1
commit 0ee35b55f4
35 changed files with 932 additions and 1031 deletions

View file

@ -42,7 +42,6 @@
#include "common/vmessagebox.h"
#include "connect/ConfCertDialog.h"
#include "connect/ConnectFriendWizard.h"
#include "feeds/AttachFileItem.h"
#include "forums/CreateForum.h"
#include "gui/common/AvatarDefs.h"
#include "gui/mainpagestack.h"
@ -109,6 +108,8 @@ FriendsDialog::FriendsDialog(QWidget *parent)
connect(ui.colorChatButton, SIGNAL(clicked()), this, SLOT(setColor()));
connect(ui.actionSave_History, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
connect(ui.hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
ui.fontsButton->setIcon(QIcon(QString(":/images/fonts.png")));
mCurrentColor = Qt::black;
@ -157,6 +158,8 @@ FriendsDialog::FriendsDialog(QWidget *parent)
setAcceptDrops(true);
ui.lineEdit->setAcceptDrops(false);
ui.hashBox->setDropWidget(this);
ui.hashBox->setAutoHide(true);
/* Set initial size the splitter */
QList<int> sizes;
@ -704,141 +707,44 @@ void FriendsDialog::statusmessage()
void FriendsDialog::addExtraFile()
{
QString file;
if (misc::getOpenFileName(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", file)) {
addAttachment(file.toUtf8().constData());
QStringList files;
if (misc::getOpenFileNames(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", files)) {
ui.hashBox->addAttachments(files);
}
}
void FriendsDialog::addAttachment(std::string filePath) {
/* add a AttachFileItem to the attachment section */
std::cerr << "PopupChatDialog::addExtraFile() hashing file." << std::endl;
/* add widget in for new destination */
AttachFileItem *file = new AttachFileItem(filePath);
//file->
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 *)), SLOT(fileHashingFinished(AttachFileItem *))) ;
}
}
void FriendsDialog::fileHashingFinished(AttachFileItem* file)
void FriendsDialog::fileHashingFinished(QList<HashedFile> hashedFiles)
{
std::cerr << "FriendsDialog::fileHashingFinished() started." << std::endl;
//check that the file is ok tos end
if (file->getState() == AFI_STATE_ERROR) {
#ifdef FRIENDS_DEBUG
std::cerr << "PopupChatDialog::fileHashingFinished error file is not hashed." << std::endl;
#endif
return;
QString mesgString;
QList<HashedFile>::iterator it;
for (it = hashedFiles.begin(); it != hashedFiles.end(); ++it) {
HashedFile& hashedFile = *it;
RetroShareLink link;
if (!link.createFile(hashedFile.filename, hashedFile.size, QString::fromStdString(hashedFile.hash))) {
continue;
}
mesgString += link.toHtmlSize();
if (it!= hashedFiles.end()) {
mesgString += "<BR>";
}
}
//convert fileSize from uint_64 to string for html link
// char fileSizeChar [100];
// sprintf(fileSizeChar, "%lld", file->FileSize());
// std::string fileSize = *(&fileSizeChar);
RetroShareLink link;
if (!link.createFile(QString::fromUtf8(file->FileName().c_str()), file->FileSize(), QString::fromStdString(file->FileHash()))) {
return;
}
QString mesgString = link.toHtmlSize();
// std::string mesgString = "<a href='retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "'>"
// + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "</a>";
#ifdef FRIENDS_DEBUG
std::cerr << "FriendsDialog::fileHashingFinished mesgString : " << mesgString.toStdString() << std::endl;
#endif
/* convert to real html document */
QTextBrowser textBrowser;
textBrowser.setHtml(mesgString);
std::wstring msg = textBrowser.toHtml().toStdWString();
if (!mesgString.isEmpty()) {
/* convert to real html document */
QTextBrowser textBrowser;
textBrowser.setHtml(mesgString);
std::wstring msg = textBrowser.toHtml().toStdWString();
rsMsgs->sendPublicChat(msg);
setFont();
}
void FriendsDialog::dropEvent(QDropEvent *event)
{
if (!(Qt::CopyAction & event->possibleActions()))
{
std::cerr << "FriendsDialog::dropEvent() Rejecting uncopyable DropAction" << std::endl;
/* can't do it */
return;
rsMsgs->sendPublicChat(msg);
setFont();
}
std::cerr << "FriendsDialog::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 << "FriendsDialog::dropEvent() Urls:" << 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 << "FriendsDialog::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)) {
FriendsDialog::addAttachment(localpath.toUtf8().constData());
} else {
std::cerr << "FriendsDialog::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 FriendsDialog::dragEnterEvent(QDragEnterEvent *event)
{
/* print out mimeType */
std::cerr << "FriendsDialog::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 << "FriendsDialog::dragEnterEvent() Accepting Urls" << std::endl;
event->acceptProposedAction();
}
else
{
std::cerr << "FriendsDialog::dragEnterEvent() No Urls" << std::endl;
}
}
bool FriendsDialog::fileSave()

View file

@ -36,7 +36,6 @@ class QAction;
class QTextEdit;
class QTextCharFormat;
class ChatDialog;
class AttachFileItem;
class FriendsDialog : public RsAutoUpdatePage
{
@ -59,7 +58,7 @@ public slots:
void setChatInfo(QString info, QColor color=QApplication::palette().color(QPalette::WindowText));
void resetStatusBar() ;
void fileHashingFinished(AttachFileItem* file);
void fileHashingFinished(QList<HashedFile> hashedFiles);
void smileyWidgetgroupchat();
void addSmileys();
@ -68,8 +67,6 @@ public slots:
void updatePeerStatusString(const QString& peer_id,const QString& status_string,bool is_private_chat) ;
protected:
virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dropEvent(QDropEvent *event);
bool eventFilter(QObject *obj, QEvent *ev);
void showEvent (QShowEvent *event);
@ -106,7 +103,6 @@ private slots:
void loadmypersonalstatus();
void addExtraFile();
void addAttachment(std::string);
bool fileSave();
bool fileSaveAs();

View file

@ -1204,17 +1204,8 @@ border: 1px solid #CCCCCC;}</string>
</layout>
</widget>
</item>
<item row="2" column="0">
<layout class="QVBoxLayout" name="verticalLayout"/>
</item>
<item row="0" column="0">
<widget class="QSplitter" name="splitter_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -1293,6 +1284,19 @@ background: white;}</string>
</widget>
</widget>
</item>
<item row="2" column="0">
<widget class="HashBox" name="hashBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
@ -1431,6 +1435,12 @@ background: white;}</string>
<header>gui/common/AvatarWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>HashBox</class>
<extends>QScrollArea</extends>
<header location="global">gui/common/HashBox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>RSTabWidget</class>
<extends>QTabWidget</extends>

View file

@ -29,6 +29,7 @@
#include <gui/RsAutoUpdatePage.h>
#include <gui/common/RsCollectionFile.h>
#include <gui/common/RsUrlHandler.h>
#include <gui/common/FilesDefs.h>
#include "RemoteDirModel.h"
#include <retroshare/rsfiles.h>
#include <retroshare/rstypes.h>
@ -277,36 +278,7 @@ QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln)
else if (details.type == DIR_TYPE_FILE) /* File */
{
// extensions predefined
QString ext = QFileInfo(QString::fromUtf8(details.name.c_str())).suffix();
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif"
|| ext == "bmp" || ext == "ico" || ext == "svg")
return QIcon(":/images/FileTypePicture.png");
else if (ext == "avi" || ext == "AVI" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "ogm"
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov"
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp")
return QIcon(":/images/FileTypeVideo.png");
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma" || ext == "xpm")
return QIcon(":/images/FileTypeAudio.png");
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z"
|| ext == "rar" || ext == "rpm" || ext == "deb")
return QIcon(":/images/FileTypeArchive.png");
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com"
|| ext == "bin" || ext == "exe" || ext == "js" || ext == "pif"
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
return QIcon(":/images/FileTypeProgram.png");
else if (ext == "iso" || ext == "nrg" || ext == "mdf" )
return QIcon(":/images/FileTypeCDImage.png");
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
return QIcon(":/images/FileTypeDocument.png");
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|| ext == "sxc" || ext == "odt" || ext == "ods")
return QIcon(":/images/FileTypeDocument.png");
else if (ext == "html" || ext == "htm" || ext == "php")
return QIcon(":/images/FileTypeDocument.png");
else if (ext == RsCollectionFile::ExtensionString)
return QIcon(":/images/mimetypes/rscollection-16.png");
else
return QIcon(":/images/FileTypeAny.png");
return FilesDefs::getIconFromFilename(QString::fromUtf8(details.name.c_str()));
}
else
return QVariant();

View file

@ -30,6 +30,7 @@
#include "gui/RSHumanReadableDelegate.h"
#include "gui/RsAutoUpdatePage.h"
#include "gui/common/RsCollectionFile.h"
#include "gui/common/FilesDefs.h"
#include "settings/rsharesettings.h"
#include "advsearch/advancedsearchdialog.h"
@ -772,7 +773,6 @@ void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId,
child->setText(SR_NAME_COL, QString::fromUtf8(dir.name.c_str()));
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
QString ext = QFileInfo(QString::fromStdString(dir.name)).suffix();
child->setText(SR_SIZE_COL, QString("%1").arg(dir.count,(int)15,(int)10)); // very important for sorting
child->setText(SR_AGE_COL, QString("%1").arg(dir.age,15,10));
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
@ -781,7 +781,7 @@ void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId,
child->setTextAlignment( SR_ID_COL, Qt::AlignRight );
child->setText(SR_SEARCH_ID_COL, sid_hexa);
setIconAndType(child, ext);
setIconAndType(child, QString::fromUtf8(dir.name.c_str()));
if (item == NULL) {
ui.searchResultWidget->addTopLevelItem(child);
@ -1072,8 +1072,7 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
item->setText(SR_NAME_COL, QString::fromUtf8(file.name.c_str()));
item->setText(SR_HASH_COL, QString::fromStdString(file.hash));
QString ext = QFileInfo(QString::fromStdString(file.name)).suffix();
setIconAndType(item, ext);
setIconAndType(item, QString::fromUtf8(file.name.c_str()));
/*
* to facilitate downlaods we need to save the file size too
@ -1224,84 +1223,10 @@ void SearchDialog::selectSearchResults(int index)
ui.filterPatternLineEdit->clear();
}
void SearchDialog::setIconAndType(QTreeWidgetItem *item, QString ext)
void SearchDialog::setIconAndType(QTreeWidgetItem *item, const QString& filename)
{
ext = ext.toLower();
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico"
|| ext == "svg" || ext == "tif" || ext == "tiff")
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypePicture.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Picture"));
}
else if (ext == "avi" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "mkv" || ext == "mp4"
|| ext == "flv" || ext == "mov" || ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp"
|| ext == "dvx" || ext == "divx")
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeVideo.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Video"));
}
else if (ext == "flac" || ext == "ogg" || ext == "mp3" || ext == "m4a" || ext == "mp1" || ext == "mp2" || ext == "wav" || ext == "wma")
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeAudio.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Audio"));
}
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "tgz" || ext == "gz" || ext == "rar"
|| ext == "rpm" || ext == "7z" || ext == "ace" || ext == "jar" || ext == "cab" || ext == "deb")
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeArchive.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Archive"));
}
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com" || ext == "bin" || ext == "exe" || ext == "js"
|| ext == "msi" ||ext == "pif" || ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeProgram.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Program"));
}
else if (ext == "iso" || ext == "nrg" || ext == "mdf" || ext == "img" || ext == "dmg" || ext == "bin" || ext == "uif" )
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeCDImage.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("CD-Image"));
}
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == "pdf" )
{
item->setIcon(SR_NAME_COL, QIcon(":/images/mimetypes/pdf.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls" || ext == "pps" || ext == "xml" || ext == "nfo"
|| ext == "reg" || ext == "sxc" || ext == "odt" || ext == "ods" || ext == "dot" || ext == "ppt" || ext == "css" || ext == "crt" )
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == "html" || ext == "htm" || ext == "php")
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == RsCollectionFile::ExtensionString)
{
item->setIcon(SR_NAME_COL, QIcon(":/images/library.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("RetroShare collection file"));
}
else if (ext == "sub" || ext == "srt")
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeAny.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Subtitles"));
}
else if (ext == "nds")
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeAny.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Nintendo DS Rom"));
}
else
{
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeAny.png"));
}
item->setIcon(SR_NAME_COL, FilesDefs::getIconFromFilename(filename));
item->setText(SR_TYPE_COL, FilesDefs::getNameFromFilename(filename));
}
void SearchDialog::copyResultLink()

View file

@ -101,7 +101,7 @@ private:
void insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file, int searchType = ANONYMOUS_SEARCH) ;
void insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item);
void insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir);
void setIconAndType(QTreeWidgetItem *item, QString ext);
void setIconAndType(QTreeWidgetItem *item, const QString& filename);
void downloadDirectory(const QTreeWidgetItem *item, const QString &base);
void getSourceFriendsForHash(const std::string& hash,std::list<std::string>& srcIds);

View file

@ -31,6 +31,7 @@
#include <QMessageBox>
#include <gui/common/RsUrlHandler.h>
#include <gui/common/RsCollectionFile.h>
#include <gui/common/FilesDefs.h>
#include <algorithm>
@ -624,46 +625,11 @@ int TransfersDialog::addItem(const QString&, const QString& name, const QString&
DLListModel->setData(DLListModel->index(row, DOWNLOADTIME), QVariant((qlonglong)downloadtime));
DLListModel->setData(DLListModel->index(row, ID), QVariant((QString)coreID));
QString ext = QFileInfo(name).suffix();
DLListModel->setData(DLListModel->index(row,NAME), getIconFromExtension(ext), Qt::DecorationRole);
DLListModel->setData(DLListModel->index(row,NAME), FilesDefs::getIconFromFilename(name), Qt::DecorationRole);
return row ;
}
QIcon TransfersDialog::getIconFromExtension(QString ext)
{
ext = ext.toLower();
if (ext == "jpg" || ext == "jpeg" || ext == "tif" || ext == "tiff" || ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico" || ext == "svg")
return QIcon(QString::fromUtf8(":/images/FileTypePicture.png")) ;
else if (ext == "avi" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "divx" || ext == "ts"
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov" || ext == "asf" || ext == "xvid"
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp" || ext == "ogm")
return QIcon(QString::fromUtf8(":/images/FileTypeVideo.png")) ;
else if (ext == "ogg" || ext == "mp3" || ext == "mp1" || ext == "mp2" || ext == "wav" || ext == "wma" || ext == "m4a" || ext == "flac")
return QIcon(QString::fromUtf8(":/images/FileTypeAudio.png")) ;
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z" || ext == "msi"
|| ext == "rar" || ext == "rpm" || ext == "ace" || ext == "jar" || ext == "tgz" || ext == "lha"
|| ext == "cab" || ext == "cbz"|| ext == "cbr" || ext == "alz" || ext == "sit" || ext == "arj" || ext == "deb")
return QIcon(QString::fromUtf8(":/images/FileTypeArchive.png")) ;
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com"
|| ext == "exe" || ext == "js" || ext == "pif"
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
return QIcon(QString::fromUtf8(":/images/FileTypeProgram.png")) ;
else if (ext == "iso" || ext == "nrg" || ext == "mdf" || ext == "img" || ext == "dmg" || ext == "bin" )
return QIcon(QString::fromUtf8(":/images/FileTypeCDImage.png")) ;
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ;
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls" || ext == "pps" || ext == "xml"
|| ext == "sxc" || ext == "odt" || ext == "ods" || ext == "dot" || ext == "ppt" || ext == "css" )
return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ;
else if (ext == "html" || ext == "htm" || ext == "php")
return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ;
else if (ext == RsCollectionFile::ExtensionString)
return QIcon(QString::fromUtf8(":/images/mimetypes/rscollection-16.png")) ;
else
return QIcon(QString::fromUtf8(":/images/FileTypeAny.png")) ;
}
int TransfersDialog::addPeerToItem(int row, const QString& name, const QString& coreID, double dlspeed, uint32_t status, const FileProgressInfo& peerInfo)
{
QStandardItem *dlItem = DLListModel->item(row);
@ -808,8 +774,7 @@ int TransfersDialog::addUploadItem( const QString&, const QString& name, const Q
ULListModel->setData(ULListModel->index(row, UHASH), QVariant((QString)coreID));
ULListModel->setData(ULListModel->index(row, UUSERID), QVariant((QString)peer_id));
QString ext = QFileInfo(name).suffix();
ULListModel->setData(ULListModel->index(row,UNAME), getIconFromExtension(ext), Qt::DecorationRole);
ULListModel->setData(ULListModel->index(row,UNAME), FilesDefs::getIconFromFilename(name), Qt::DecorationRole);
return row;
}

View file

@ -108,7 +108,6 @@ signals:
private:
QString getPeerName(const std::string& peer_id) const ;
static QIcon getIconFromExtension(QString) ;
QStandardItemModel *DLListModel;
QStandardItemModel *ULListModel;

View file

@ -27,7 +27,6 @@
#include <QColorDialog>
#include <QDateTime>
#include <QFontDialog>
#include <QDir>
#include <QBuffer>
#include <QTextCodec>
#include <QSound>
@ -40,13 +39,9 @@
#include "rshare.h"
#include <retroshare/rspeers.h>
#include <retroshare/rsmsgs.h>
#include <retroshare/rsfiles.h>
#include "retroshare/rsinit.h"
#include <retroshare/rsnotify.h>
#include <retroshare/rsstatus.h>
#include <retroshare/rshistory.h>
#include <retroshare/rsiface.h>
#include "gui/settings/rsharesettings.h"
#include "gui/settings/RsharePeerSettings.h"
#include "gui/notifyqt.h"
@ -54,11 +49,10 @@
#include "gui/common/StatusDefs.h"
#include "gui/common/AvatarDefs.h"
#include "gui/common/Emoticons.h"
#include "gui/im_history/ImHistoryBrowser.h"
#include "gui/feeds/AttachFileItem.h"
#include "gui/msgs/MessageComposer.h"
#include "gui/common/PeerDefs.h"
#include "gui/common/FilesDefs.h"
#include "gui/im_history/ImHistoryBrowser.h"
#include "gui/msgs/MessageComposer.h"
#include <time.h>
#include <algorithm>
@ -129,6 +123,8 @@ PopupChatDialog::PopupChatDialog(const std::string &id, const QString &name, QWi
connect(ui.actionSave_Chat_History, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
connect(ui.actionClearOfflineMessages, SIGNAL(triggered()), this, SLOT(clearOfflineMessages()));
connect(ui.hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&, int)), this, SLOT(updateStatus(const QString&, int)));
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewCustomStateString(const QString&, const QString&)), this, SLOT(updatePeersCustomStateString(const QString&, const QString&)));
@ -155,6 +151,8 @@ PopupChatDialog::PopupChatDialog(const std::string &id, const QString &name, QWi
setAcceptDrops(true);
ui.chattextEdit->setAcceptDrops(false);
ui.hashBox->setDropWidget(this);
ui.hashBox->setAutoHide(true);
QMenu * toolmenu = new QMenu();
toolmenu->addAction(ui.actionClear_Chat_History);
@ -806,9 +804,9 @@ void PopupChatDialog::on_actionDelete_Chat_History_triggered()
void PopupChatDialog::addExtraFile()
{
QString file;
if (misc::getOpenFileName(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", file)) {
addAttachment(file.toUtf8().constData(), 0);
QStringList files;
if (misc::getOpenFileNames(this, RshareSettings::LASTDIR_EXTRAFILE, tr("Add Extra File"), "", files)) {
ui.hashBox->addAttachments(files/*, 0*/);
}
}
@ -817,98 +815,38 @@ void PopupChatDialog::addExtraPicture()
// select a picture file
QString file;
if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg)", file)) {
addAttachment(file.toUtf8().constData(), 1);
ui.hashBox->addAttachments(QStringList(file), HashedFile::Picture);
}
}
void PopupChatDialog::addAttachment(std::string filePath,int flag)
void PopupChatDialog::fileHashingFinished(QList<HashedFile> hashedFiles)
{
/* add a AttachFileItem to the attachment section */
std::cerr << "PopupChatDialog::addExtraFile() hashing file.";
std::cerr << std::endl;
/* add widget in for new destination */
AttachFileItem *file = new AttachFileItem(filePath);
//file->
if(flag==1)
file->setPicFlag(1);
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() == AFI_STATE_LOCAL) {
fileHashingFinished(file);
} else {
QObject::connect(file,SIGNAL(fileFinished(AttachFileItem *)), SLOT(fileHashingFinished(AttachFileItem *))) ;
}
}
void PopupChatDialog::fileHashingFinished(AttachFileItem* file)
{
std::cerr << "PopupChatDialog::fileHashingFinished() started.";
std::cerr << std::endl;
//check that the file is ok tos end
if (file->getState() == AFI_STATE_ERROR) {
#ifdef CHAT_DEBUG
std::cerr << "PopupChatDialog::fileHashingFinished error file is not hashed.";
#endif
return;
}
std::string ownId;
{
rsiface->lockData(); /* Lock Interface */
const RsConfig &conf = rsiface->getConfig();
ownId = conf.ownId;
rsiface->unlockData(); /* Unlock Interface */
}
std::cerr << "PopupChatDialog::fileHashingFinished() started." << std::endl;
QString message;
QString ext = QFileInfo(QString::fromStdString(file->FileName())).suffix();
if(file->getPicFlag()==1){
message+="<img src=\"file:///";
message+=file->FilePath().c_str();
message+="\" width=\"100\" height=\"100\">";
message+="<br>";
}
else if (ext == "ogg" || ext == "mp3" || ext == "MP3" || ext == "mp1" || ext == "mp2" || ext == "wav" || ext == "wma")
{
message+="<img src=\":/images/audio-x-monkey.png";
message+="\" width=\"48\" height=\"48\">";
message+="<br>";
}
else if (ext == "avi" || ext == "AVI" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "ogm"
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov"
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp")
{
message+="<img src=\":/images/video-x-generic.png";
message+="\" width=\"48\" height=\"48\">";
message+="<br>";
}
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z"
|| ext == "rar" || ext == "rpm" || ext == "deb")
{
message+="<img src=\":/images/application-x-rar.png";
message+="\" width=\"48\" height=\"48\">";
message+="<br>";
}
else if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico"
|| ext == "svg" || ext == "tif" || ext == "tiff" || ext == "JPG")
{
message+="<img src=\":/images/application-draw.png";
message+="\" width=\"48\" height=\"48\">";
message+="<br>";
}
QList<HashedFile>::iterator it;
for (it = hashedFiles.begin(); it != hashedFiles.end(); ++it) {
HashedFile& hashedFile = *it;
QString ext = QFileInfo(hashedFile.filename).suffix();
RetroShareLink link;
link.createFile(QString::fromUtf8(file->FileName().c_str()),file->FileSize(),QString::fromStdString(file->FileHash()));
message += link.toHtmlSize();
RetroShareLink link;
link.createFile(hashedFile.filename, hashedFile.size, QString::fromStdString(hashedFile.hash));
if (hashedFile.flag & HashedFile::Picture) {
message += QString("<img src=\"file:///%1\" width=\"100\" height=\"100\">").arg(hashedFile.filepath);
message+="<br>";
} else {
QString image = FilesDefs::getImageFromFilename(hashedFile.filename, false);
if (!image.isEmpty()) {
message += QString("<img src=\"%1\">").arg(image);
}
}
message += link.toHtmlSize();
if (it != hashedFiles.end()) {
message += "<BR>";
}
}
#ifdef CHAT_DEBUG
std::cerr << "PopupChatDialog::fileHashingFinished message : " << message.toStdString() << std::endl;
@ -920,94 +858,12 @@ void PopupChatDialog::fileHashingFinished(AttachFileItem* file)
std::wstring msg = textBrowser.toHtml().toStdWString();
if (rsMsgs->sendPrivateChat(dialogId, msg)) {
std::string ownId = rsPeers->getOwnId();
QDateTime currentTime = QDateTime::currentDateTime();
addChatMsg(false, QString::fromUtf8(rsPeers->getPeerName(ownId).c_str()), currentTime, currentTime, QString::fromStdWString(msg), TYPE_NORMAL);
}
}
void PopupChatDialog::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)) {
PopupChatDialog::addAttachment(localpath.toUtf8().constData(), false);
} 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 PopupChatDialog::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;
}
}
bool PopupChatDialog::fileSave()
{
if (fileName.isEmpty())

View file

@ -28,7 +28,6 @@
class QAction;
class QTextEdit;
class QTextCharFormat;
class AttachFileItem;
class ChatInfo;
#include <retroshare/rsmsgs.h>
@ -70,8 +69,6 @@ protected:
~PopupChatDialog();
virtual void resizeEvent(QResizeEvent *event);
virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dropEvent(QDropEvent *event);
bool eventFilter(QObject *obj, QEvent *ev);
@ -82,7 +79,7 @@ private slots:
void pasteLink() ;
void contextMenu(QPoint) ;
void fileHashingFinished(AttachFileItem* file);
void fileHashingFinished(QList<HashedFile> hashedFiles);
void smileyWidget();
void addSmiley();
@ -116,7 +113,6 @@ private:
void colorChanged(const QColor &c);
void fontChanged(const QFont &font);
void addAttachment(std::string,int flag);
void processSettings(bool bLoad);
void onPrivateChatChanged(int list, int type);

View file

@ -25,19 +25,22 @@
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0" rowspan="6">
<item row="0" column="0" rowspan="7">
<widget class="QFrame" name="leftsideframe">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -108,7 +111,7 @@
</layout>
</widget>
</item>
<item row="0" column="1" rowspan="6">
<item row="0" column="1" rowspan="7">
<widget class="QFrame" name="avatarframe">
<property name="maximumSize">
<size>
@ -711,9 +714,6 @@ border: 1px solid #CCCCCC;
</layout>
</widget>
</item>
<item row="6" column="0" colspan="3">
<layout class="QVBoxLayout" name="vboxLayout"/>
</item>
<item row="4" column="2">
<widget class="QSplitter" name="chatsplitter">
<property name="lineWidth">
@ -725,6 +725,9 @@ border: 1px solid #CCCCCC;
<property name="handleWidth">
<number>2</number>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
@ -738,7 +741,7 @@ border: 1px solid #CCCCCC;
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
<height>30</height>
</size>
</property>
<property name="styleSheet">
@ -831,6 +834,13 @@ background: white;}</string>
</widget>
</widget>
</item>
<item row="6" column="2">
<widget class="HashBox" name="hashBox">
<property name="widgetResizable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -912,6 +922,12 @@ background: white;}</string>
<header>gui/common/AvatarWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>HashBox</class>
<extends>QScrollArea</extends>
<header location="global">gui/common/HashBox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>

View file

@ -162,7 +162,7 @@ void PopupChatWindow::addDialog(PopupChatDialog *dialog)
ui.tabWidget->addTab(dialog, dialog->getTitle());
} else {
ui.horizontalLayout->addWidget(dialog);
ui.horizontalLayout->setContentsMargins(0, 0, 5, 0);
ui.horizontalLayout->setContentsMargins(0, 0, 0, 0);
peerId = dialog->getPeerId();
chatDialog = dialog;
calculateStyle(dialog);

View file

@ -0,0 +1,85 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2011, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QApplication>
#include <QFileInfo>
#include "FilesDefs.h"
#include "RsCollectionFile.h"
static QString getInfoFromFilename(const QString& filename, bool anyForUnknown, bool image)
{
QString ext = QFileInfo(filename).suffix().toLower();
if (ext == "jpg" || ext == "jpeg" || ext == "tif" || ext == "tiff" || ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico" || ext == "svg") {
return image ? ":/images/FileTypePicture.png" : QApplication::translate("FilesDefs", "Picture");
} else if (ext == "avi" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "divx" || ext == "ts" ||
ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov" || ext == "asf" || ext == "xvid" ||
ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp" || ext == "ogm") {
return image ? ":/images/FileTypeVideo.png" : QApplication::translate("FilesDefs", "Video");
} else if (ext == "ogg" || ext == "mp3" || ext == "mp1" || ext == "mp2" || ext == "wav" || ext == "wma" || ext == "m4a" || ext == "flac" ||ext == "xpm") {
return image ? ":/images/FileTypeAudio.png" : QApplication::translate("FilesDefs", "Audio");
} else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z" || ext == "msi" ||
ext == "rar" || ext == "rpm" || ext == "ace" || ext == "jar" || ext == "tgz" || ext == "lha" ||
ext == "cab" || ext == "cbz"|| ext == "cbr" || ext == "alz" || ext == "sit" || ext == "arj" || ext == "deb") {
return image ? ":/images/FileTypeArchive.png" : QApplication::translate("FilesDefs", "Archive");
} else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com" ||
ext == "exe" || ext == "js" || ext == "pif" ||
ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws") {
return image ? ":/images/FileTypeProgram.png" : QApplication::translate("FilesDefs", "Program");
} else if (ext == "iso" || ext == "nrg" || ext == "mdf" || ext == "img" || ext == "dmg" || ext == "bin" || ext == "uif") {
return image ? ":/images/FileTypeCDImage.png" : QApplication::translate("FilesDefs", "CD/DVD-Image");
} else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h" || ext == "ui" ||
ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls" || ext == "pps" || ext == "xml" || ext == "nfo" ||
ext == "reg" || ext == "sxc" || ext == "odt" || ext == "ods" || ext == "dot" || ext == "ppt" || ext == "css" || ext == "crt" ||
ext == "html" || ext == "htm" || ext == "php") {
return image ? ":/images/FileTypeDocument.png" : QApplication::translate("FilesDefs", "Document");
} else if (ext == "pdf") {
return image ? ":/images/mimetypes/pdf.png" : QApplication::translate("FilesDefs", "Document");
} else if (ext == RsCollectionFile::ExtensionString) {
return image ? ":/images/mimetypes/rscollection-16.png" : QApplication::translate("FilesDefs", "RetroShare collection file");
} else if (ext == "sub" || ext == "srt") {
return image ? ":/images/FileTypeAny.png" : QApplication::translate("FilesDefs", "Subtitles");
} else if (ext == "nds") {
return image ? ":/images/FileTypeAny.png" : QApplication::translate("FilesDefs", "Nintendo DS Rom");
}
if (anyForUnknown) {
return image ? ":/images/FileTypeAny.png" : "";
}
return "";
}
QString FilesDefs::getImageFromFilename(const QString& filename, bool anyForUnknown)
{
return getInfoFromFilename(filename, anyForUnknown, true);
}
QIcon FilesDefs::getIconFromFilename(const QString& filename)
{
return QIcon(getInfoFromFilename(filename, true, true));
}
QString FilesDefs::getNameFromFilename(const QString &filename)
{
return getInfoFromFilename(filename, false, false);
}

View file

@ -0,0 +1,37 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2011, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _FILESDEFS_H
#define _FILESDEFS_H
#include <QString>
#include <QIcon>
class FilesDefs
{
public:
static QString getImageFromFilename(const QString& filename, bool anyForUnknown);
static QIcon getIconFromFilename(const QString& filename);
static QString getNameFromFilename(const QString& filename);
};
#endif

View file

@ -0,0 +1,259 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2011, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QMessageBox>
#include <QDir>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QUrl>
#include <QTimer>
#include <iostream>
#include "gui/feeds/AttachFileItem.h"
#include "HashBox.h"
#include "ui_HashBox.h"
HashedFile::HashedFile()
{
size = 0;
flag = NoFlag;
}
HashBox::HashBox(QWidget *parent) :
QScrollArea(parent),
ui(new Ui::HashBox)
{
ui->setupUi(this);
mAutoHide = false;
dropWidget = NULL;
}
HashBox::~HashBox()
{
delete ui;
}
void HashBox::setAutoHide(bool autoHide)
{
mAutoHide = autoHide;
setVisible(!mAutoHide);
}
void HashBox::setDropWidget(QWidget* widget)
{
if (dropWidget) {
dropWidget->removeEventFilter(this);
}
dropWidget = widget;
if (dropWidget) {
widget->installEventFilter(this);
}
}
static void showFormats(const std::string& event, const QStringList& formats)
{
std::cerr << event << "() Formats" << std::endl;
QStringList::const_iterator it;
for (it = formats.begin(); it != formats.end(); ++it) {
std::cerr << "Format: " << (*it).toStdString();
std::cerr << std::endl;
}
}
bool HashBox::eventFilter(QObject* object, QEvent* event)
{
if (object == dropWidget) {
if (event->type() == QEvent::DragEnter) {
QDragEnterEvent* dragEnterEvent = static_cast<QDragEnterEvent*>(event);
if (dragEnterEvent) {
/* print out mimeType */
showFormats("HashBox::dragEnterEvent", dragEnterEvent->mimeData()->formats());
if (dragEnterEvent->mimeData()->hasUrls()) {
std::cerr << "HashBox::dragEnterEvent() Accepting Urls" << std::endl;
dragEnterEvent->acceptProposedAction();
} else {
std::cerr << "HashBox::dragEnterEvent() No Urls" << std::endl;
}
}
} else if (event->type() == QEvent::Drop) {
QDropEvent* dropEvent = static_cast<QDropEvent*>(event);
if (dropEvent) {
if (Qt::CopyAction & dropEvent->possibleActions()) {
/* print out mimeType */
showFormats("HashBox::dropEvent", dropEvent->mimeData()->formats());
QStringList files;
if (dropEvent->mimeData()->hasUrls()) {
std::cerr << "HashBox::dropEvent() Urls:" << std::endl;
QList<QUrl> urls = dropEvent->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 << "HashBox::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)) {
files.push_back(localpath);
} else {
std::cerr << "HashBox::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();
}
}
}
}
addAttachments(files);
dropEvent->setDropAction(Qt::CopyAction);
dropEvent->accept();
} else {
std::cerr << "HashBox::dropEvent() Rejecting uncopyable DropAction" << std::endl;
}
}
}
}
// pass the event on to the parent class
return QScrollArea::eventFilter(object, event);
}
void HashBox::addAttachments(const QStringList& files, HashedFile::Flags flag)
{
/* add a AttachFileItem to the attachment section */
std::cerr << "PopupChatDialog::addExtraFile() hashing file." << std::endl;
if (files.isEmpty()) {
return;
}
if (mAutoHide) {
show();
}
QStringList::ConstIterator it;
for (it = files.constBegin(); it != files.constEnd(); ++it) {
/* add widget in for new destination */
AttachFileItem* file = new AttachFileItem(*it);
QObject::connect(file, SIGNAL(fileFinished(AttachFileItem*)), this, SLOT(fileFinished(AttachFileItem*)));
HashingInfo hashingInfo;
hashingInfo.item = file;
hashingInfo.flag = flag;
mHashingInfos.push_back(hashingInfo);
ui->verticalLayout->addWidget(file, 1, 0);
}
QApplication::processEvents();
// workaround for Qt bug, the size from the first call to QScrollArea::sizeHint() is stored in QWidgetItemV2 and
// QScrollArea::sizeHint() is never called again so that widgetResizable of QScrollArea doesn't work
// the next line clears the member QScrollArea::widgetSize for recalculation of the added children in QScrollArea::sizeHint()
setWidget(takeWidget());
// the next line set the cache to dirty
updateGeometry();
emit fileHashingStarted();
checkAttachmentReady();
}
void HashBox::fileFinished(AttachFileItem* file)
{
std::cerr << "HashBox::fileHashingFinished() started." << std::endl;
//check that the file is ok
if (file->getState() == AFI_STATE_ERROR) {
std::cerr << "HashBox::fileHashingFinished error file is not hashed.";
return;
}
checkAttachmentReady();
}
void HashBox::checkAttachmentReady()
{
if (mHashingInfos.isEmpty()) {
return;
}
QList<HashingInfo>::iterator it;
for (it = mHashingInfos.begin(); it != mHashingInfos.end(); ++it) {
if (it->item->isHidden()) {
continue;
}
if (!it->item->done()) {
break;
}
}
if (it != mHashingInfos.end()) {
/* repeat... */
QTimer::singleShot(500, this, SLOT(checkAttachmentReady()));
return;
}
if (mAutoHide) {
hide();
}
QList<HashedFile> hashedFiles;
for (it = mHashingInfos.begin(); it != mHashingInfos.end(); ++it) {
HashingInfo& hashingInfo = *it;
if (hashingInfo.item->done()) {
HashedFile hashedFile;
hashedFile.filename = hashingInfo.item->FileName();
hashedFile.filepath = hashingInfo.item->FilePath();
hashedFile.hash = hashingInfo.item->FileHash();
hashedFile.size = hashingInfo.item->FileSize();
hashedFile.flag = hashingInfo.flag;
hashedFiles.push_back(hashedFile);
ui->verticalLayout->removeWidget(hashingInfo.item);
hashingInfo.item->deleteLater();
}
}
mHashingInfos.clear();
QApplication::processEvents();
// workaround for Qt bug, the size from the first call to QScrollArea::sizeHint() is stored in QWidgetItemV2 and
// QScrollArea::sizeHint() is never called again so that widgetResizable of QScrollArea doesn't work
// the next line clears the member QScrollArea::widgetSize for recalculation of the removed children in QScrollArea::sizeHint()
setWidget(takeWidget());
// the next line set the cache to dirty
updateGeometry();
emit fileHashingFinished(hashedFiles);
}

View file

@ -0,0 +1,91 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2011, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef HASHBOX_H
#define HASHBOX_H
#include <QScrollArea>
namespace Ui {
class HashBox;
}
class AttachFileItem;
class QVBoxLayout;
class HashedFile
{
public:
enum Flags {
NoFlag = 0,
Picture = 1
};
public:
QString filename;
QString filepath;
uint64_t size;
std::string hash;
Flags flag;
public:
HashedFile();
};
class HashBox : public QScrollArea
{
Q_OBJECT
public:
explicit HashBox(QWidget *parent = 0);
~HashBox();
void setAutoHide(bool autoHide);
void addAttachments(const QStringList& files, HashedFile::Flags flag = HashedFile::NoFlag);
void setDropWidget(QWidget* widget);
protected:
bool eventFilter(QObject *object, QEvent *event);
private slots:
void fileFinished(AttachFileItem* file);
void checkAttachmentReady();
signals:
void fileHashingStarted();
void fileHashingFinished(QList<HashedFile> hashedFiles);
private:
class HashingInfo
{
public:
AttachFileItem* item;
HashedFile::Flags flag;
};
QList<HashingInfo> mHashingInfos;
bool mAutoHide;
QWidget* dropWidget;
Ui::HashBox *ui;
};
#endif // HASHBOX_H

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HashBox</class>
<widget class="QScrollArea" name="HashBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>35</height>
</size>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>0</number>
</property>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -61,8 +61,7 @@
const uint32_t AFI_DEFAULT_PERIOD = (30 * 3600 * 24); /* 30 Days */
/** Constructor */
AttachFileItem::AttachFileItem(std::string hash, std::string name, uint64_t size,
uint32_t flags, std::string srcId)
AttachFileItem::AttachFileItem(const std::string& hash, const QString& name, uint64_t size, uint32_t flags, const std::string& srcId)
:QWidget(NULL), mFileHash(hash), mFileName(name), mFileSize(size), mSrcId(srcId)
{
/* Invoke the Qt Designer generated object setup routine */
@ -72,7 +71,6 @@ AttachFileItem::AttachFileItem(std::string hash, std::string name, uint64_t size
mMode = flags & AFI_MASK_STATE;
mType = flags & AFI_MASK_TYPE;
mPicFlag=0;
if (mMode == AFI_STATE_EXTRA)
{
@ -92,7 +90,7 @@ AttachFileItem::AttachFileItem(std::string hash, std::string name, uint64_t size
}
/** Constructor */
AttachFileItem::AttachFileItem(std::string path)
AttachFileItem::AttachFileItem(const QString& path)
:QWidget(NULL), mPath(path), mFileSize(0)
{
/* Invoke the Qt Designer generated object setup routine */
@ -100,10 +98,9 @@ AttachFileItem::AttachFileItem(std::string path)
mMode = AFI_STATE_EXTRA;
mType = AFI_TYPE_ATTACH;
mPicFlag=0;
/* ask for Files to hash/prepare it for us */
if ((!rsFiles) || (!rsFiles->ExtraFileHash(path, AFI_DEFAULT_PERIOD, 0)))
if ((!rsFiles) || (!rsFiles->ExtraFileHash(path.toUtf8().constData(), AFI_DEFAULT_PERIOD, 0)))
{
mMode = AFI_STATE_ERROR;
}
@ -113,7 +110,6 @@ AttachFileItem::AttachFileItem(std::string path)
void AttachFileItem::Setup()
{
connect( cancelButton, SIGNAL( clicked( void ) ), this, SLOT( cancel ( void ) ) );
/* once off check - if remote, check if we have it
@ -127,8 +123,7 @@ void AttachFileItem::Setup()
if (mMode == AFI_STATE_REMOTE)
{
FileInfo fi;
uint32_t hintflags = RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
| RS_FILE_HINTS_SPEC_ONLY;
uint32_t hintflags = RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY;
/* look up path */
if (rsFiles->FileDetails(mFileHash, hintflags, fi))
@ -140,14 +135,12 @@ void AttachFileItem::Setup()
std::cerr << std::endl;
#endif
mMode = AFI_STATE_LOCAL;
mPath = fi.path;
mPath = QString::fromUtf8(fi.path.c_str());
}
}
updateItemStatic();
updateItem();
}
@ -169,7 +162,7 @@ void AttachFileItem::updateItemStatic()
std::cerr << std::endl;
#endif
QString filename = QString::fromUtf8(mFileName.c_str());
QString filename = mFileName;
mDivisor = 1;
if (mFileSize > 10000000) /* 10 Mb */
@ -219,7 +212,7 @@ void AttachFileItem::updateItemStatic()
std::cerr << "AttachFileItem::updateItemStatic() Updated Path";
std::cerr << std::endl;
#endif
mPath = fi.path;
mPath = QString::fromUtf8(fi.path.c_str());
}
}
}
@ -234,12 +227,12 @@ void AttachFileItem::updateItemStatic()
cancelButton->setEnabled(false);
progressBar->setValue(0);
filename = "[ERROR] " + filename;
filename = tr("[ERROR])") + " " + filename;
break;
case AFI_STATE_EXTRA:
filename = QString::fromUtf8(mPath.c_str());
filename = mPath;
progressBar->setRange(0, 100);
progressBar->setFormat("HASHING");
@ -303,10 +296,8 @@ void AttachFileItem::updateItemStatic()
break;
}
fileLabel->setText(filename);
fileLabel->setToolTip(filename);
}
void AttachFileItem::updateItem()
@ -339,7 +330,7 @@ void AttachFileItem::updateItem()
std::cerr << std::endl;
#endif
/* check for file status */
if (rsFiles->ExtraFileStatus(mPath, fi))
if (rsFiles->ExtraFileStatus(mPath.toUtf8().constData(), fi))
{
#ifdef DEBUG_ITEM
std::cerr << "AttachFileItem::updateItem() STATE=>Local";
@ -348,7 +339,7 @@ void AttachFileItem::updateItem()
mMode = AFI_STATE_LOCAL;
/* fill in file details */
mFileName = fi.fname;
mFileName = QString::fromUtf8(fi.fname.c_str());
mFileSize = fi.size;
mFileHash = fi.hash;
@ -422,7 +413,7 @@ void AttachFileItem::updateItem()
/* save path */
/* update progress */
mMode = AFI_STATE_LOCAL;
mPath = fi.path;
mPath = QString::fromUtf8(fi.path.c_str());
stateChanged = true;
}
progressBar->setValue(fi.avail / mDivisor);
@ -442,7 +433,6 @@ void AttachFileItem::updateItem()
/* update progress */
break;
}
}
/****** update based on new state ******/
@ -485,7 +475,6 @@ void AttachFileItem::updateItem()
msec_rate = 2000; /* should be download rate dependent */
break;
}
if (repeat)
{
@ -495,10 +484,8 @@ void AttachFileItem::updateItem()
#endif
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
}
}
void AttachFileItem::cancel()
{
#ifdef DEBUG_ITEM
@ -519,7 +506,7 @@ void AttachFileItem::cancel()
}
}
uint32_t AttachFileItem::getState() {
uint32_t AttachFileItem::getState()
{
return mMode;
}

View file

@ -41,49 +41,39 @@ const uint32_t AFI_TYPE_ATTACH = 0x0020;
class AttachFileItem : public QWidget, private Ui::AttachFileItem
{
Q_OBJECT
Q_OBJECT
public:
/** Default Constructor */
AttachFileItem(std::string localpath);
AttachFileItem(std::string hash, std::string name, uint64_t size,
uint32_t flags, std::string srcId);
/** Default Constructor */
AttachFileItem(const QString& localpath);
AttachFileItem(const std::string& hash, const QString& name, uint64_t size, uint32_t flags, const std::string& srcId);
/** Default Destructor */
/** Default Destructor */
std::string FileHash() { return mFileHash; }
std::string FileName() { return mFileName; }
uint64_t FileSize() { return mFileSize; }
std::string FilePath() { return mPath; }
int getPicFlag() { return mPicFlag;}
void setPicFlag(int flag) { mPicFlag=flag;}
const std::string& FileHash() { return mFileHash; }
const QString& FileName() { return mFileName; }
uint64_t FileSize() { return mFileSize; }
const QString& FilePath() { return mPath; }
void updateItemStatic();
bool done();
bool done();
bool ready();
uint32_t getState();
public slots:
private slots:
void cancel();
void cancel();
void updateItem();
private:
void Setup();
std::string mPath;
QString mPath;
std::string mFileHash;
std::string mFileName;
QString mFileName;
uint64_t mFileSize;
std::string mSrcId;
uint32_t mPicFlag;
uint32_t mMode;
uint32_t mType;
uint64_t mDivisor;
@ -92,11 +82,8 @@ private:
float amountDone;
signals:
void fileFinished(AttachFileItem * AttachFileItem);
void fileFinished(AttachFileItem * AttachFileItem);
};
#endif

View file

@ -10,11 +10,11 @@
<height>35</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>35</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
@ -130,7 +130,7 @@ background: white;}
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<iconset resource="../../../../plugins/qdiagram_plugin/qdiagram.qrc">
<normaloff>:/images/delete.png</normaloff>:/images/delete.png</iconset>
</property>
</widget>
@ -154,7 +154,7 @@ background: white;}
</layout>
</widget>
<resources>
<include location="../images.qrc"/>
<include location="../../../../plugins/qdiagram_plugin/qdiagram.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -26,13 +26,12 @@
#include <QFile>
#include <QDesktopWidget>
#include <QDropEvent>
#include <QPushButton>
#include <retroshare/rsforums.h>
#include <retroshare/rsfiles.h>
#include "gui/settings/rsharesettings.h"
#include "gui/RetroShareLink.h"
#include "gui/feeds/AttachFileItem.h"
#include "gui/common/Emoticons.h"
#include "util/misc.h"
@ -52,6 +51,8 @@ CreateForumMsg::CreateForumMsg(std::string fId, std::string pId)
connect( ui.forumMessage, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( forumMessageCostumPopupMenu( QPoint ) ) );
connect(ui.hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
// connect up the buttons.
connect( ui.postmessage_action, SIGNAL( triggered (bool) ), this, SLOT( createMsg( ) ) );
connect( ui.close_action, SIGNAL( triggered (bool) ), this, SLOT( cancelMsg( ) ) );
@ -60,6 +61,8 @@ CreateForumMsg::CreateForumMsg(std::string fId, std::string pId)
connect( ui.pastersButton, SIGNAL(clicked() ), this , SLOT(pasteLink()));
setAcceptDrops(true);
ui.hashBox->setDropWidget(this);
ui.hashBox->setAutoHide(false);
newMsg();
}
@ -203,130 +206,34 @@ void CreateForumMsg::addFile()
{
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 CreateForumMsg::addAttachment(std::string filePath) {
/* add a AttachFileItem to the attachment section */
std::cerr << "CreateForumMsg::addFile() hashing file.";
std::cerr << std::endl;
void CreateForumMsg::fileHashingFinished(QList<HashedFile> hashedFiles)
{
std::cerr << "CreateForumMsg::fileHashingFinished() started." << std::endl;
/* add widget in for new destination */
AttachFileItem *file = new AttachFileItem(filePath);
//file->
QString mesgString;
ui.verticalLayout->addWidget(file, 1, 0);
//when the file is local or is finished hashing, call the fileHashingFinished method to send a forum message
if (file->getState() == AFI_STATE_LOCAL) {
fileHashingFinished(file);
} else {
QObject::connect(file,SIGNAL(fileFinished(AttachFileItem *)),this, SLOT(fileHashingFinished(AttachFileItem *))) ;
}
}
void CreateForumMsg::fileHashingFinished(AttachFileItem* file) {
std::cerr << "CreateForumMsg::fileHashingFinished() started.";
std::cerr << std::endl;
//check that the file is ok tos end
if (file->getState() == AFI_STATE_ERROR) {
#ifdef CHAT_DEBUG
std::cerr << "CreateForumMsg::fileHashingFinished error file is not hashed.";
#endif
return;
}
RetroShareLink link;
if (link.createFile(QString::fromUtf8(file->FileName().c_str()), file->FileSize(), QString::fromStdString(file->FileHash()))) {
QString mesgString = link.toHtmlSize() + "<br>";
QList<HashedFile>::iterator it;
for (it = hashedFiles.begin(); it != hashedFiles.end(); ++it) {
HashedFile& hashedFile = *it;
RetroShareLink link;
if (link.createFile(hashedFile.filename, hashedFile.size, QString::fromStdString(hashedFile.hash))) {
mesgString += link.toHtmlSize() + "<br>";
}
}
#ifdef CHAT_DEBUG
std::cerr << "CreateForumMsg::anchorClicked mesgString : " << mesgString.toStdString() << std::endl;
std::cerr << "CreateForumMsg::anchorClicked mesgString : " << mesgString.toStdString() << std::endl;
#endif
ui.forumMessage->textCursor().insertHtml(mesgString);
if (!mesgString.isEmpty()) {
ui.forumMessage->textCursor().insertHtml(mesgString);
}
ui.forumMessage->setFocus( Qt::OtherFocusReason );
}
}
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++)
{
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 << "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,this);
mb.exec();
} else if (QFile::exists(localpath)) {
addAttachment(localpath.toUtf8().constData());
} else {
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,this);
mb.exec();
}
}
}
}
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;
}
ui.forumMessage->setFocus( Qt::OtherFocusReason );
}
void CreateForumMsg::pasteLink()
@ -338,4 +245,3 @@ void CreateForumMsg::pasteLinkFull()
{
ui.forumMessage->insertHtml(RSLinkClipboard::toHtmlFull()) ;
}

View file

@ -25,8 +25,6 @@
#include "ui_CreateForumMsg.h"
class AttachFileItem;
class CreateForumMsg : public QMainWindow
{
Q_OBJECT
@ -40,8 +38,8 @@ private slots:
/** Create the context popup menu and it's submenus */
void forumMessageCostumPopupMenu( QPoint point );
void fileHashingFinished(AttachFileItem* file);
/* actions to take.... */
void fileHashingFinished(QList<HashedFile> hashedFiles);
/* actions to take.... */
void createMsg();
void cancelMsg();
void pasteLink();
@ -50,13 +48,9 @@ private slots:
void smileyWidgetForums();
void addSmileys();
void addFile();
void addAttachment(std::string);
protected:
void closeEvent (QCloseEvent * event);
virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dropEvent(QDropEvent *event);
private:
std::string mForumId;

View file

@ -261,44 +261,19 @@ p, li { white-space: pre-wrap; }
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea">
<widget class="HashBox" name="hashBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>You can attach files via drag and drop here in this window</string>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>440</width>
<height>57</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<property name="margin">
<number>0</number>
</property>
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout"/>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
@ -343,6 +318,14 @@ p, li { white-space: pre-wrap; }
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>HashBox</class>
<extends>QScrollArea</extends>
<header location="global">gui/common/HashBox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>
</resources>

View file

@ -2,14 +2,10 @@
<qresource prefix="/" >
<file>images/splash.png</file>
<file>images/attach.png</file>
<file>images/audio-x-monkey.png</file>
<file>images/video-x-generic.png</file>
<file>images/application-x-rar.png</file>
<file>images/application-draw.png</file>
<file>images/pgp.png</file>
<file>images/rs_wizard.png</file>
<file>images/about.png</file>
<file>images/backblue.png</file>
<file>images/backblue.png</file>
<file>images/backchat.png</file>
<file>images/buttonframe.png</file>
<file>images/btn1.png</file>
@ -166,7 +162,7 @@
<file>images/filerating5.png</file>
<file>images/fileshare16.png</file>
<file>images/fileshare24.png</file>
<file>images/fileshare32.png</file>
<file>images/fileshare32.png</file>
<file>images/fileshare48.png</file>
<file>images/find.png</file>
<file>images/find-16.png</file>
@ -439,7 +435,7 @@
<file>images/user/friends24.png</file>
<file>images/user/identity16.png</file>
<file>images/user/identity24.png</file>
<file>images/user/identity32.png</file>
<file>images/user/identity32.png</file>
<file>images/user/identity48.png</file>
<file>images/user/identityoffline24.png</file>
<file>images/user/identity24away.png</file>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -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);

View file

@ -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;

View file

@ -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>