/thirdparty/liblastfm2/src/core/misc.h

http://github.com/tomahawk-player/tomahawk · C Header · 111 lines · 81 code · 11 blank · 19 comment · 2 complexity · 1d60e41c581cce534695bbe6ae391d15 MD5 · raw file

  1. /*
  2. Copyright 2009 Last.fm Ltd.
  3. - Primarily authored by Max Howell, Jono Cole and Doug Mansell
  4. This file is part of liblastfm.
  5. liblastfm is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. liblastfm is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef LASTFM_MISC_H
  17. #define LASTFM_MISC_H
  18. #include <lastfm/global.h>
  19. #include <QCryptographicHash>
  20. #include <QDir>
  21. #include <QString>
  22. #ifdef Q_WS_MAC
  23. typedef const struct __CFString* CFStringRef;
  24. #endif
  25. namespace lastfm
  26. {
  27. namespace dir
  28. {
  29. #ifdef Q_WS_WIN
  30. LASTFM_DLLEXPORT QDir programFiles();
  31. #endif
  32. #ifdef Q_WS_MAC
  33. LASTFM_DLLEXPORT QDir bundle();
  34. #endif
  35. LASTFM_DLLEXPORT QDir runtimeData();
  36. LASTFM_DLLEXPORT QDir cache();
  37. LASTFM_DLLEXPORT QDir logs();
  38. }
  39. #ifdef Q_WS_MAC
  40. LASTFM_DLLEXPORT QByteArray CFStringToUtf8( CFStringRef );
  41. LASTFM_DLLEXPORT CFStringRef QStringToCFString( const QString& );
  42. inline QString CFStringToQString( CFStringRef s );
  43. #endif
  44. inline const char* platform()
  45. {
  46. #ifdef Q_WS_WIN
  47. switch (QSysInfo::WindowsVersion)
  48. {
  49. case QSysInfo::WV_32s: return "Windows 3.1 with Win32s";
  50. case QSysInfo::WV_95: return "Windows 95";
  51. case QSysInfo::WV_98: return "Windows 98";
  52. case QSysInfo::WV_Me: return "Windows Me";
  53. case QSysInfo::WV_DOS_based: return "MS-DOS-based Windows";
  54. case QSysInfo::WV_NT: return "Windows NT";
  55. case QSysInfo::WV_2000: return "Windows 2000";
  56. case QSysInfo::WV_XP: return "Windows XP";
  57. case QSysInfo::WV_2003: return "Windows Server 2003";
  58. case QSysInfo::WV_VISTA: return "Windows Vista";
  59. case QSysInfo::WV_NT_based: return "NT-based Windows";
  60. case QSysInfo::WV_CE: return "Windows CE";
  61. case QSysInfo::WV_CENET: return "Windows CE.NET";
  62. case QSysInfo::WV_CE_based: return "CE-based Windows";
  63. default: return "Unknown";
  64. }
  65. #elif defined Q_WS_MAC
  66. switch (QSysInfo::MacintoshVersion)
  67. {
  68. case QSysInfo::MV_Unknown: return "Unknown Mac";
  69. case QSysInfo::MV_9: return "Mac OS 9";
  70. case QSysInfo::MV_10_0: return "Mac OS X 10.0";
  71. case QSysInfo::MV_10_1: return "Mac OS X 10.1";
  72. case QSysInfo::MV_10_2: return "Mac OS X 10.2";
  73. case QSysInfo::MV_10_3: return "Mac OS X 10.3";
  74. case QSysInfo::MV_10_4: return "Mac OS X 10.4";
  75. case QSysInfo::MV_10_5: return "Mac OS X 10.5";
  76. default: return "Unknown";
  77. }
  78. #elif defined Q_WS_X11
  79. return "UNIX X11";
  80. #else
  81. return "Unknown";
  82. #endif
  83. }
  84. inline QString md5( const QByteArray& src )
  85. {
  86. QByteArray const digest = QCryptographicHash::hash( src, QCryptographicHash::Md5 );
  87. return QString::fromLatin1( digest.toHex() ).rightJustified( 32, '0' ).toLower();
  88. }
  89. }
  90. #ifdef Q_WS_MAC
  91. inline QString lastfm::CFStringToQString( CFStringRef s )
  92. {
  93. return QString::fromUtf8( CFStringToUtf8( s ) );
  94. }
  95. #endif
  96. #endif //LASTFM_MISC_H