xlsxmediafile.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /****************************************************************************
  2. ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
  3. ** All right reserved.
  4. **
  5. ** Permission is hereby granted, free of charge, to any person obtaining
  6. ** a copy of this software and associated documentation files (the
  7. ** "Software"), to deal in the Software without restriction, including
  8. ** without limitation the rights to use, copy, modify, merge, publish,
  9. ** distribute, sublicense, and/or sell copies of the Software, and to
  10. ** permit persons to whom the Software is furnished to do so, subject to
  11. ** the following conditions:
  12. **
  13. ** The above copyright notice and this permission notice shall be
  14. ** included in all copies or substantial portions of the Software.
  15. **
  16. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. **
  24. ****************************************************************************/
  25. #include "xlsxmediafile_p.h"
  26. #include <QCryptographicHash>
  27. namespace QXlsx {
  28. MediaFile::MediaFile(const QByteArray &bytes, const QString &suffix, const QString &mimeType)
  29. : m_contents(bytes), m_suffix(suffix), m_mimeType(mimeType)
  30. , m_index(0), m_indexValid(false)
  31. {
  32. m_hashKey = QCryptographicHash::hash(m_contents, QCryptographicHash::Md5);
  33. }
  34. MediaFile::MediaFile(const QString &fileName)
  35. :m_fileName(fileName), m_index(0), m_indexValid(false)
  36. {
  37. }
  38. void MediaFile::set(const QByteArray &bytes, const QString &suffix, const QString &mimeType)
  39. {
  40. m_contents = bytes;
  41. m_suffix = suffix;
  42. m_mimeType = mimeType;
  43. m_hashKey = QCryptographicHash::hash(m_contents, QCryptographicHash::Md5);
  44. m_indexValid = false;
  45. }
  46. void MediaFile::setFileName(const QString &name)
  47. {
  48. m_fileName = name;
  49. }
  50. QString MediaFile::fileName() const
  51. {
  52. return m_fileName;
  53. }
  54. QString MediaFile::suffix() const
  55. {
  56. return m_suffix;
  57. }
  58. QString MediaFile::mimeType() const
  59. {
  60. return m_mimeType;
  61. }
  62. QByteArray MediaFile::contents() const
  63. {
  64. return m_contents;
  65. }
  66. int MediaFile::index() const
  67. {
  68. return m_index;
  69. }
  70. bool MediaFile::isIndexValid() const
  71. {
  72. return m_indexValid;
  73. }
  74. void MediaFile::setIndex(int idx)
  75. {
  76. m_index = idx;
  77. m_indexValid = true;
  78. }
  79. QByteArray MediaFile::hashKey() const
  80. {
  81. return m_hashKey;
  82. }
  83. } // namespace QXlsx