You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

filetask.cpp 1.6 kB

8 years ago
8 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "filetask.h"
  2. FileTask::FileTask()
  3. {
  4. }
  5. FileTask::FileTask(shared_ptr<FileContent> fileContent, FileTaskType type)
  6. :mContent(fileContent), mType(type)
  7. {
  8. mNotifySize = fileContent->size/100;//每1%通知一次
  9. const int minNotifySize = 102400;//至少变化了100k才通知
  10. if (mNotifySize < minNotifySize)
  11. mNotifySize = minNotifySize;
  12. }
  13. void FileTask::setObserver(IFileTaskObserver *observer)
  14. {
  15. mObserver = observer;
  16. }
  17. void FileTask::setProcess(int val)
  18. {
  19. mProcess = val;
  20. if (mProcess - mLastProcess >= mNotifySize
  21. || mProcess >= mContent->size)
  22. {
  23. mLastProcess = mProcess;
  24. mObserver->onProgress(this);
  25. }
  26. }
  27. void FileTask::setState(FileTaskState val, const string &msg)
  28. {
  29. mState = val;
  30. mMsg = msg;
  31. mObserver->onStateChanged(this);
  32. }
  33. void FileTask::setFellow(shared_ptr<Fellow> fellow)
  34. {
  35. mFellow = fellow;
  36. }
  37. void FileTask::cancel()
  38. {
  39. mCancelPending=true;
  40. }
  41. bool FileTask::hasCancelPending()
  42. {
  43. return mCancelPending;
  44. }
  45. shared_ptr<Fellow> FileTask::fellow() const
  46. {
  47. return mFellow;
  48. }
  49. int FileTask::getProcess() const
  50. {
  51. return mProcess;
  52. }
  53. FileTaskState FileTask::getState() const
  54. {
  55. return mState;
  56. }
  57. string FileTask::getDetailInfo() const
  58. {
  59. return mMsg;
  60. }
  61. shared_ptr<FileContent> FileTask::getContent() const
  62. {
  63. return mContent;
  64. }
  65. FileTaskType FileTask::type() const
  66. {
  67. return mType;
  68. }
  69. string FileTask::getTaskTypeDes() const
  70. {
  71. if (mType == FileTaskType::Upload)
  72. return "发送";
  73. else if (mType == FileTaskType::Download)
  74. return "接收";
  75. return "";
  76. }

mac下的“飞秋”大多数只是飞鸽传书协议,而且未发现令人满意的开源项目,所以基于c++与qt实现了基础的飞秋协议。

Contributors (1)