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

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