moved file hashing and download count to new notification system

This commit is contained in:
csoler 2020-01-30 23:02:23 +01:00
parent 10bee9f26b
commit 81c1eb227c
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
12 changed files with 163 additions and 24 deletions

View File

@ -136,7 +136,13 @@ void HashStorage::threadTick()
stopHashThread();
}
RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_FINISH, "") ;
if(rsEvents)
{
auto ev = std::make_shared<RsSharedDirectoriesEvent>();
ev->mEventCode = RsSharedDirectoriesEventCode::DIRECTORY_SWEEP_ENDED;
rsEvents->postEvent(ev);
}
//RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_FINISH, "") ;
}
else
{
@ -181,7 +187,14 @@ void HashStorage::threadTick()
else
rs_sprintf(tmpout, "%lu/%lu (%s - %d%%) : %s", (unsigned long int)mHashCounter+1, (unsigned long int)mTotalFilesToHash, friendlyUnit(mTotalHashedSize).c_str(), int(mTotalHashedSize/double(mTotalSizeToHash)*100.0), job.full_path.c_str()) ;
RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, tmpout) ;
//RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, tmpout) ;
if(rsEvents)
{
auto ev = std::make_shared<RsSharedDirectoriesEvent>();
ev->mEventCode = RsSharedDirectoriesEventCode::HASHING_FILE;
ev->mMessage = tmpout;
rsEvents->postEvent(ev);
}
double seconds_origin = rstime::RsScopeTimer::currentTime() ;

View File

@ -816,10 +816,13 @@ bool ftController::completeFile(const RsFileHash& hash)
}
/* Notify GUI */
RsServer::notify()->AddPopupMessage(RS_POPUP_DOWNLOAD, hash.toStdString(), name, "");
RsServer::notify()->notifyDownloadComplete(hash.toStdString());
RsServer::notify()->notifyDownloadCompleteCount(completeCount);
if(rsEvents)
{
auto ev = std::make_shared<RsFileTransferEvent>();
ev->mHash = hash;
ev->mFileTransferEventCode = RsFileTransferEventCode::DOWNLOAD_COMPLETE;
rsEvents->postEvent(ev);
}
rsFiles->ForceDirectoryCheck(true) ;
@ -1412,7 +1415,12 @@ bool ftController::FileClearCompleted()
IndicateConfigChanged();
}
RsServer::notify()->notifyDownloadCompleteCount(0);
if(rsEvents)
{
auto ev = std::make_shared<RsFileTransferEvent>();
ev->mFileTransferEventCode = RsFileTransferEventCode::COMPLETED_FILES_REMOVED;
rsEvents->postEvent(ev);
}
return true;
}

View File

@ -88,7 +88,13 @@ enum class RsEventType : uint32_t
/// @see RsGxsPostedEvent
GXS_IDENTITY = 12,
MAX /// Used to detect invalid event type passed
/// @see RsFiles
SHARED_DIRECTORIES = 13,
/// @see RsFiles
FILE_TRANSFER = 14,
MAX /// Used to detect invalid event type passed
};
/**

View File

@ -33,6 +33,7 @@
#include "serialiser/rsserializable.h"
#include "rsturtle.h"
#include "util/rstime.h"
#include "retroshare/rsevents.h"
class RsFiles;
@ -114,6 +115,55 @@ const TransferRequestFlags RS_FILE_REQ_NO_SEARCH ( 0x02000000 ); // di
const uint32_t RS_FILE_EXTRA_DELETE = 0x0010;
enum class RsSharedDirectoriesEventCode: uint8_t {
UNKNOWN = 0x00,
STARTING_DIRECTORY_SWEEP = 0x01, // (void)
HASHING_FILE = 0x02, // mMessage: full path and hashing speed of the file being hashed
DIRECTORY_SWEEP_ENDED = 0x03, // (void)
SAVING_FILE_INDEX = 0x04, // (void)
};
enum class RsFileTransferEventCode: uint8_t {
UNKNOWN = 0x00,
DOWNLOAD_COMPLETE = 0x01, // mHash: hash of the complete file
COMPLETED_FILES_REMOVED = 0x02, //
};
struct RsSharedDirectoriesEvent: RsEvent
{
RsSharedDirectoriesEvent() : RsEvent(RsEventType::SHARED_DIRECTORIES), mEventCode(RsSharedDirectoriesEventCode::UNKNOWN) {}
~RsSharedDirectoriesEvent() override = default;
///* @see RsEvent @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ) override
{
RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mEventCode);
RS_SERIAL_PROCESS(mMessage);
}
RsSharedDirectoriesEventCode mEventCode;
std::string mMessage;
};
struct RsFileTransferEvent: RsEvent
{
RsFileTransferEvent() : RsEvent(RsEventType::FILE_TRANSFER), mFileTransferEventCode(RsFileTransferEventCode::UNKNOWN) {}
~RsFileTransferEvent() override = default;
///* @see RsEvent @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ) override
{
RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mFileTransferEventCode);
RS_SERIAL_PROCESS(mHash);
}
RsFileTransferEventCode mFileTransferEventCode;
RsFileHash mHash;
};
struct SharedDirInfo : RsSerializable
{
static bool sameLists(const std::list<RsNodeGroupId>& l1,const std::list<RsNodeGroupId>& l2)

View File

@ -18,6 +18,7 @@
* *
*******************************************************************************/
#include "retroshare/rsfiles.h"
#include "TransferUserNotify.h"
#include "gui/notifyqt.h"
#include "gui/MainWindow.h"
@ -27,7 +28,7 @@ TransferUserNotify::TransferUserNotify(QObject *parent) :
{
newTransferCount = 0;
connect(NotifyQt::getInstance(), SIGNAL(downloadCompleteCountChanged(int)), this, SLOT(downloadCountChanged(int)));
// connect(NotifyQt::getInstance(), SIGNAL(downloadCompleteCountChanged(int)), this, SLOT(downloadCountChanged(int)));
}
bool TransferUserNotify::hasSetting(QString *name, QString *group)
@ -50,7 +51,17 @@ QIcon TransferUserNotify::getMainIcon(bool hasNew)
unsigned int TransferUserNotify::getNewCount()
{
return newTransferCount;
std::list<RsFileHash> hashs;
rsFiles->FileDownloads(hashs);
FileInfo info;
newTransferCount = 0;
for(auto hash: hashs)
if(rsFiles->FileDetails(hash, RS_FILE_HINTS_DOWNLOAD, info) && info.downloadStatus==FT_STATE_COMPLETE)
++newTransferCount;
return newTransferCount;
}
QString TransferUserNotify::getTrayMessage(bool plural)
@ -68,8 +79,3 @@ void TransferUserNotify::iconClicked()
MainWindow::showWindow(MainWindow::Transfers);
}
void TransferUserNotify::downloadCountChanged(int count)
{
newTransferCount = count;
updateIcon();
}

View File

@ -32,9 +32,6 @@ public:
virtual bool hasSetting(QString *name, QString *group);
private slots:
void downloadCountChanged(int count);
private:
virtual QIcon getIcon();
virtual QIcon getMainIcon(bool hasNew);

View File

@ -1091,6 +1091,28 @@ TransfersDialog::TransfersDialog(QWidget *parent)
registerHelpButton(ui.helpButton,help_str,"TransfersDialog") ;
mEventHandlerId=0;
rsEvents->registerEventsHandler(RsEventType::FILE_TRANSFER, [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId );
}
void TransfersDialog::handleEvent(std::shared_ptr<const RsEvent> event)
{
if(event->mType != RsEventType::FILE_TRANSFER)
return;
const RsFileTransferEvent *fe = dynamic_cast<const RsFileTransferEvent*>(event.get());
if(!fe)
return;
switch (fe->mFileTransferEventCode)
{
case RsFileTransferEventCode::DOWNLOAD_COMPLETE:
case RsFileTransferEventCode::COMPLETED_FILES_REMOVED:
getUserNotify()->updateIcon();
default:
break;
}
}
TransfersDialog::~TransfersDialog()

View File

@ -24,6 +24,7 @@
#include <set>
#include <retroshare/rstypes.h>
#include <retroshare/rsevents.h>
#include "RsAutoUpdatePage.h"
#include "ui_TransfersDialog.h"
@ -259,6 +260,7 @@ private:
bool controlTransferFile(uint32_t flags);
void changePriority(int priority);
void setChunkStrategy(FileChunksInfo::ChunkStrategy s) ;
void handleEvent(std::shared_ptr<const RsEvent> event);
QTreeView *downloadList;
@ -273,6 +275,7 @@ private:
/** Qt Designer generated object */
Ui::TransfersDialog ui;
RsEventsHandlerId_t mEventHandlerId;
public slots:
// these four functions add entries to the transfers dialog, and return the row id of the entry modified/added
// int addDLItem(int row, const FileInfo &fileInfo);

View File

@ -349,6 +349,7 @@ void NotifyQt::notifyDiscInfoChanged()
emit discInfoChanged() ;
}
#ifdef TO_REMOVE
void NotifyQt::notifyDownloadComplete(const std::string& fileHash)
{
{
@ -376,6 +377,7 @@ void NotifyQt::notifyDownloadCompleteCount(uint32_t count)
emit downloadCompleteCountChanged(count);
}
#endif
void NotifyQt::notifyDiskFull(uint32_t loc,uint32_t size_in_mb)
{

View File

@ -85,8 +85,10 @@ class NotifyQt: public QObject, public NotifyClient
virtual void notifyHistoryChanged(uint32_t msgId, int type);
virtual void notifyDiscInfoChanged() ;
#ifdef TO_REMOVE
virtual void notifyDownloadComplete(const std::string& fileHash);
virtual void notifyDownloadCompleteCount(uint32_t count);
#endif
virtual bool askForPassword(const std::string& title, const std::string& key_details, bool prev_is_bad, std::string& password, bool &cancelled);
virtual bool askForPluginConfirmation(const std::string& plugin_filename, const std::string& plugin_file_hash,bool first_time);
@ -153,8 +155,6 @@ class NotifyQt: public QObject, public NotifyClient
void chatMessageReceived(ChatMessage msg);
void groupsChanged(int type) const ;
void discInfoChanged() const ;
void downloadComplete(const QString& /* fileHash */);
void downloadCompleteCountChanged(int /* count */);
#ifdef REMOVE
void forumMsgReadSatusChanged(const QString& forumId, const QString& msgId, int status);
void channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status);

View File

@ -52,7 +52,37 @@ HashingStatus::HashingStatus(QWidget *parent)
hashloader->hide();
statusHashing->hide();
connect(NotifyQt::getInstance(), SIGNAL(hashingInfoChanged(const QString&)), SLOT(updateHashingInfo(const QString&)));
mEventHandlerId=0;
rsEvents->registerEventsHandler(RsEventType::SHARED_DIRECTORIES, [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId );
}
void HashingStatus::handleEvent(std::shared_ptr<const RsEvent> event)
{
if(event->mType != RsEventType::SHARED_DIRECTORIES)
return;
const RsSharedDirectoriesEvent *fe = dynamic_cast<const RsSharedDirectoriesEvent*>(event.get());
if(!fe)
return;
QString info;
switch (fe->mEventCode)
{
case RsSharedDirectoriesEventCode::STARTING_DIRECTORY_SWEEP:
info = tr("Examining shared files...");
break;
case RsSharedDirectoriesEventCode::DIRECTORY_SWEEP_ENDED:
break;
case RsSharedDirectoriesEventCode::HASHING_FILE:
info = tr("Hashing file") + " " + QString::fromUtf8(fe->mMessage.c_str());
break;
case RsSharedDirectoriesEventCode::SAVING_FILE_INDEX:
info = tr("Saving file index...");
break;
}
updateHashingInfo(info);
}
HashingStatus::~HashingStatus()

View File

@ -22,6 +22,7 @@
#define HASHINGSTATUS_H
#include <QWidget>
#include "retroshare/rsevents.h"
class QLabel;
class ElidedLabel;
@ -37,15 +38,16 @@ public:
void setCompactMode(bool compact) {_compactMode = compact; }
void mousePressEvent(QMouseEvent *);
public slots:
void updateHashingInfo(const QString&) ;
private:
void updateHashingInfo(const QString& s);
void handleEvent(std::shared_ptr<const RsEvent> event);
ElidedLabel *statusHashing;
QLabel *hashloader;
QString mLastText ;
QMovie *movie;
bool _compactMode;
RsEventsHandlerId_t mEventHandlerId;
};
#endif