diff --git a/core.cpp b/core.cpp index ad0d943a3..795752161 100644 --- a/core.cpp +++ b/core.cpp @@ -15,9 +15,9 @@ */ #include "core.h" -#include "cdata.h" -#include "cstring.h" -#include "settings.h" +#include "misc/cdata.h" +#include "misc/cstring.h" +#include "misc/settings.h" #include "widget/widget.h" #include @@ -280,7 +280,7 @@ void Core::onUserStatusChanged(Tox*/* tox*/, int friendId, uint8_t userstatus, v } if (status == Status::Online || status == Status::Away) - tox_request_avatar_data(static_cast(core)->tox, friendId); + tox_request_avatar_info(static_cast(core)->tox, friendId); emit static_cast(core)->friendStatusChanged(friendId, status); } @@ -507,28 +507,40 @@ void Core::onFileDataCallback(Tox*, int32_t friendnumber, uint8_t filenumber, co } void Core::onAvatarInfoCallback(Tox*, int32_t friendnumber, uint8_t format, - uint8_t *, void* core) + uint8_t* hash, void* _core) { - qDebug() << "Core: Got avatar info from "<(_core); if (format == TOX_AVATAR_FORMAT_NONE) - emit static_cast(core)->friendAvatarRemoved(friendnumber); + { + qDebug() << "Core: Got null avatar info from" << friendnumber; + emit core->friendAvatarRemoved(friendnumber); + } else - tox_request_avatar_data(static_cast(core)->tox, friendnumber); + { + QByteArray oldHash = Settings::getInstance().getAvatarHash(core->getFriendAddress(friendnumber)); + if (QByteArray((char*)hash, TOX_HASH_LENGTH) != oldHash) // comparison failed miserably if I didn't convert hash to QByteArray + { + qDebug() << "Core: got different avatar hash from" << friendnumber; + tox_request_avatar_data(core->tox, friendnumber); + } + else + qDebug() << "Core: Got old avatar info from" << friendnumber; + } } void Core::onAvatarDataCallback(Tox*, int32_t friendnumber, uint8_t, - uint8_t *, uint8_t *data, uint32_t datalen, void *core) + uint8_t *hash, uint8_t *data, uint32_t datalen, void *core) { QPixmap pic; pic.loadFromData((uchar*)data, datalen); if (pic.isNull()) - qDebug() << "Core: Got invalid avatar data from "<(core)->getFriendAddress(friendnumber)); + Settings::getInstance().saveAvatarHash(QByteArray((char*)hash, TOX_HASH_LENGTH), static_cast(core)->getFriendAddress(friendnumber)); emit static_cast(core)->friendAvatarChanged(friendnumber, pic); } } diff --git a/filetransferinstance.cpp b/filetransferinstance.cpp index 75ab36d3e..0561454b4 100644 --- a/filetransferinstance.cpp +++ b/filetransferinstance.cpp @@ -29,7 +29,7 @@ uint FileTransferInstance::Idconter = 0; FileTransferInstance::FileTransferInstance(ToxFile File) - : lastUpdate{QDateTime::currentDateTime()}, lastBytesSent{0}, + : lastBytesSent{0}, fileNum{File.fileNum}, friendId{File.friendId}, direction{File.direction} { id = Idconter++; @@ -77,16 +77,16 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t // state = tsProcessing; QDateTime newtime = QDateTime::currentDateTime(); - int timediff = lastUpdate.secsTo(newtime); + int timediff = started.secsTo(newtime); if (timediff <= 0) return; - qint64 diff = BytesSent - lastBytesSent; - if (diff < 0) + qint64 totalbytes = BytesSent + lastBytesSent; // bytes sent so far + if (totalbytes < 0) { qWarning() << "FileTransferInstance::onFileTransferInfo: Negative transfer speed !"; - diff = 0; + totalbytes = 0; } - long rawspeed = diff / timediff; + long rawspeed = totalbytes / timediff; speed = getHumanReadableSize(rawspeed)+"/s"; size = getHumanReadableSize(Filesize); totalBytes = Filesize; @@ -96,8 +96,7 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t QTime etaTime(0,0); etaTime = etaTime.addSecs(etaSecs); eta = etaTime.toString("mm:ss"); - lastUpdate = newtime; - lastBytesSent = BytesSent; + lastBytesSent = totalbytes; emit stateUpdated(); } @@ -202,7 +201,7 @@ void FileTransferInstance::acceptRecvRequest() QString path; while (true) { - path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::current().filePath(filename)); + path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(filename)); if (path.isEmpty()) return; else @@ -222,6 +221,8 @@ void FileTransferInstance::acceptRecvRequest() Core::getInstance()->acceptFileRecvRequest(friendId, fileNum, path); state = tsProcessing; + started = QDateTime::currentDateTime(); + emit stateUpdated(); } diff --git a/filetransferinstance.h b/filetransferinstance.h index c627fb3ee..0168f3c61 100644 --- a/filetransferinstance.h +++ b/filetransferinstance.h @@ -74,7 +74,7 @@ private: QImage pic; QString filename, size, speed, eta; QString filenameElided; - QDateTime lastUpdate; + QDateTime started; long long lastBytesSent, totalBytes; int fileNum; int friendId; diff --git a/main.cpp b/main.cpp index 1cdac827e..8e981baa5 100644 --- a/main.cpp +++ b/main.cpp @@ -15,7 +15,7 @@ */ #include "widget/widget.h" -#include "settings.h" +#include "misc/settings.h" #include #include #include diff --git a/cdata.cpp b/misc/cdata.cpp similarity index 100% rename from cdata.cpp rename to misc/cdata.cpp diff --git a/cdata.h b/misc/cdata.h similarity index 100% rename from cdata.h rename to misc/cdata.h diff --git a/cstring.cpp b/misc/cstring.cpp similarity index 100% rename from cstring.cpp rename to misc/cstring.cpp diff --git a/cstring.h b/misc/cstring.h similarity index 100% rename from cstring.h rename to misc/cstring.h diff --git a/settings.cpp b/misc/settings.cpp similarity index 95% rename from settings.cpp rename to misc/settings.cpp index 3e9f33426..31cbd158e 100644 --- a/settings.cpp +++ b/misc/settings.cpp @@ -280,12 +280,35 @@ QPixmap Settings::getSavedAvatar(const QString &ownerId) void Settings::saveAvatar(QPixmap& pic, const QString& ownerId) { QDir dir(getSettingsDirPath()); - dir.mkdir("avatars/"); // remove this in a week or two hopefully + dir.mkdir("avatars/"); // ignore nospam (good idea, and also the addFriend funcs which call getAvatar don't have it) QString filePath = dir.filePath("avatars/"+ownerId.left(64)+".png"); pic.save(filePath, "png"); } +void Settings::saveAvatarHash(const QByteArray& hash, const QString& ownerId) +{ + QDir dir(getSettingsDirPath()); + dir.mkdir("avatars/"); + QFile file(dir.filePath("avatars/"+ownerId.left(64)+".hash")); + if (!file.open(QIODevice::WriteOnly)) + return; + file.write(hash); + file.close(); +} + +QByteArray Settings::getAvatarHash(const QString& ownerId) +{ + QDir dir(getSettingsDirPath()); + dir.mkdir("avatars/"); + QFile file(dir.filePath("avatars/"+ownerId.left(64)+".hash")); + if (!file.open(QIODevice::ReadOnly)) + return QByteArray(); + QByteArray out = file.readAll(); + file.close(); + return out; +} + const QList& Settings::getDhtServerList() const { return dhtServerList; diff --git a/settings.h b/misc/settings.h similarity index 97% rename from settings.h rename to misc/settings.h index b796211cb..9f379e886 100644 --- a/settings.h +++ b/misc/settings.h @@ -61,6 +61,9 @@ public: QPixmap getSavedAvatar(const QString& ownerId); void saveAvatar(QPixmap& pic, const QString& ownerId); + QByteArray getAvatarHash(const QString& ownerId); + void saveAvatarHash(const QByteArray& hash, const QString& ownerId); + // Assume all widgets have unique names // Don't use it to save every single thing you want to save, use it // for some general purpose widgets, such as MainWindows or Splitters, diff --git a/smileypack.cpp b/misc/smileypack.cpp similarity index 100% rename from smileypack.cpp rename to misc/smileypack.cpp diff --git a/smileypack.h b/misc/smileypack.h similarity index 100% rename from smileypack.h rename to misc/smileypack.h diff --git a/style.cpp b/misc/style.cpp similarity index 100% rename from style.cpp rename to misc/style.cpp diff --git a/style.h b/misc/style.h similarity index 100% rename from style.h rename to misc/style.h diff --git a/qtox.pro b/qtox.pro index c5bf81c1b..f7bd7bf3a 100644 --- a/qtox.pro +++ b/qtox.pro @@ -91,17 +91,17 @@ HEADERS += widget/form/addfriendform.h \ friend.h \ group.h \ grouplist.h \ - settings.h \ + misc/settings.h \ core.h \ friendlist.h \ - cdata.h \ - cstring.h \ + misc/cdata.h \ + misc/cstring.h \ widget/selfcamview.h \ widget/camera.h \ widget/netcamview.h \ - smileypack.h \ + misc/smileypack.h \ widget/emoticonswidget.h \ - style.h \ + misc/style.h \ widget/adjustingscrollarea.h \ widget/croppinglabel.h \ widget/friendlistwidget.h \ @@ -135,15 +135,15 @@ SOURCES += \ group.cpp \ grouplist.cpp \ main.cpp \ - settings.cpp \ - cdata.cpp \ - cstring.cpp \ + misc/settings.cpp \ + misc/cdata.cpp \ + misc/cstring.cpp \ widget/selfcamview.cpp \ widget/camera.cpp \ widget/netcamview.cpp \ - smileypack.cpp \ + misc/smileypack.cpp \ widget/emoticonswidget.cpp \ - style.cpp \ + misc/style.cpp \ widget/adjustingscrollarea.cpp \ widget/croppinglabel.cpp \ widget/friendlistwidget.cpp \ diff --git a/widget/emoticonswidget.cpp b/widget/emoticonswidget.cpp index f471e8729..1e3d0ea4e 100644 --- a/widget/emoticonswidget.cpp +++ b/widget/emoticonswidget.cpp @@ -15,8 +15,8 @@ */ #include "emoticonswidget.h" -#include "smileypack.h" -#include "style.h" +#include "misc/smileypack.h" +#include "misc/style.h" #include #include diff --git a/widget/form/genericchatform.cpp b/widget/form/genericchatform.cpp index c992ba563..26bd958ba 100644 --- a/widget/form/genericchatform.cpp +++ b/widget/form/genericchatform.cpp @@ -17,11 +17,11 @@ #include "genericchatform.h" #include "ui_mainwindow.h" #include -#include "smileypack.h" +#include "misc/smileypack.h" #include "widget/emoticonswidget.h" -#include "style.h" +#include "misc/style.h" #include "widget/widget.h" -#include "settings.h" +#include "misc/settings.h" #include "widget/tool/chatactions/messageaction.h" #include "widget/tool/chatactions/systemmessageaction.h" #include "widget/chatareawidget.h" diff --git a/widget/groupwidget.cpp b/widget/groupwidget.cpp index 7bd1683c9..d803063ce 100644 --- a/widget/groupwidget.cpp +++ b/widget/groupwidget.cpp @@ -17,7 +17,7 @@ #include "groupwidget.h" #include "grouplist.h" #include "group.h" -#include "settings.h" +#include "misc/settings.h" #include "widget/form/groupchatform.h" #include "widget/maskablepixmapwidget.h" #include diff --git a/widget/settingsdialog.cpp b/widget/settingsdialog.cpp index d81973286..947395350 100644 --- a/widget/settingsdialog.cpp +++ b/widget/settingsdialog.cpp @@ -1,10 +1,10 @@ #include "settingsdialog.h" -#include "settings.h" +#include "misc/settings.h" #include "widget.h" #include "camera.h" #include "selfcamview.h" #include "core.h" -#include "smileypack.h" +#include "misc/smileypack.h" #include #include diff --git a/widget/tool/chatactions/messageaction.cpp b/widget/tool/chatactions/messageaction.cpp index 84ce86194..9904be470 100644 --- a/widget/tool/chatactions/messageaction.cpp +++ b/widget/tool/chatactions/messageaction.cpp @@ -15,7 +15,7 @@ */ #include "messageaction.h" -#include "smileypack.h" +#include "misc/smileypack.h" MessageAction::MessageAction(const QString &author, const QString &message, const QString &date, const bool &me) : ChatAction(me, author, date), diff --git a/widget/widget.cpp b/widget/widget.cpp index 2b322eecd..a70fac605 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -17,7 +17,7 @@ #include "widget.h" #include "ui_mainwindow.h" #include "core.h" -#include "settings.h" +#include "misc/settings.h" #include "friend.h" #include "friendlist.h" #include "widget/tool/friendrequestdialog.h" @@ -26,7 +26,7 @@ #include "group.h" #include "widget/groupwidget.h" #include "widget/form/groupchatform.h" -#include "style.h" +#include "misc/style.h" #include "selfcamview.h" #include "widget/friendlistwidget.h" #include "camera.h"