/src/libtomahawk/utils/TomahawkUtils.h

http://github.com/tomahawk-player/tomahawk · C Header · 229 lines · 155 code · 31 blank · 43 comment · 0 complexity · 6bcf7b6a9a0fe896c42742ec89e0ecd7 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  5. * Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
  6. *
  7. * Tomahawk is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tomahawk is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #pragma once
  21. #ifndef TOMAHAWKUTILS_H
  22. #define TOMAHAWKUTILS_H
  23. #include "DllMacro.h"
  24. #include <QtCore/QThread>
  25. #include <QtNetwork/QNetworkProxy>
  26. #include <QtCore/QStringList>
  27. #include <Typedefs.h>
  28. #define RESPATH ":/data/"
  29. class QDir;
  30. class QNetworkAccessManager;
  31. namespace TomahawkUtils
  32. {
  33. enum MediaType
  34. {
  35. MediaTypeArtist,
  36. MediaTypeAlbum,
  37. MediaTypeTrack
  38. };
  39. enum ImageType
  40. {
  41. DefaultAlbumCover,
  42. DefaultArtistImage,
  43. DefaultTrackImage,
  44. DefaultSourceAvatar,
  45. DefaultCollection,
  46. DefaultResolver,
  47. NowPlayingSpeaker,
  48. NowPlayingSpeakerDark,
  49. InfoIcon,
  50. PlayButton,
  51. PlayButtonPressed,
  52. PauseButton,
  53. PauseButtonPressed,
  54. PrevButton,
  55. PrevButtonPressed,
  56. NextButton,
  57. NextButtonPressed,
  58. ShuffleOff,
  59. ShuffleOffPressed,
  60. ShuffleOn,
  61. ShuffleOnPressed,
  62. RepeatOne,
  63. RepeatOnePressed,
  64. RepeatAll,
  65. RepeatAllPressed,
  66. RepeatOff,
  67. RepeatOffPressed,
  68. Volume,
  69. Share,
  70. NotLoved,
  71. Loved,
  72. Configure,
  73. GreenDot,
  74. AddContact,
  75. SubscribeOn,
  76. SubscribeOff,
  77. JumpLink,
  78. ProcessStop,
  79. HeadphonesOn,
  80. HeadphonesOff,
  81. PadlockClosed,
  82. PadlockOpen,
  83. Downloading,
  84. Uploading,
  85. ViewRefresh,
  86. SuperCollection,
  87. LovedPlaylist,
  88. NewReleases,
  89. NewAdditions,
  90. RecentlyPlayed,
  91. Queue,
  92. AutomaticPlaylist,
  93. Charts,
  94. Station,
  95. Playlist,
  96. Search,
  97. ListRemove,
  98. ListAdd,
  99. AdvancedSettings,
  100. DownloadsSettings,
  101. AccountSettings,
  102. MusicSettings,
  103. Add,
  104. DropSong,
  105. DropAlbum,
  106. DropAllSongs,
  107. DropLocalSongs,
  108. DropTopSongs,
  109. LastfmIcon,
  110. SpotifyIcon,
  111. SoundcloudIcon,
  112. AccountNone,
  113. Starred,
  114. Unstarred,
  115. StarHovered,
  116. SipPluginOnline,
  117. SipPluginOffline,
  118. ResolverBundle,
  119. Inbox,
  120. Invalid,
  121. InboxNewItem,
  122. Outbox,
  123. NetworkActivity
  124. };
  125. enum ImageMode
  126. {
  127. Original,
  128. CoverInCase,
  129. DropShadow,
  130. RoundedCorners
  131. };
  132. DLLEXPORT bool headless();
  133. DLLEXPORT void setHeadless( bool headless );
  134. DLLEXPORT QString appFriendlyVersion();
  135. DLLEXPORT QDir appConfigDir();
  136. DLLEXPORT QDir appDataDir();
  137. DLLEXPORT QDir appLogDir();
  138. DLLEXPORT const QString logFilePath();
  139. DLLEXPORT void installTranslator( QObject* parent );
  140. DLLEXPORT QString timeToString( int seconds );
  141. DLLEXPORT QString ageToString( const QDateTime& time, bool appendAgoString = false );
  142. DLLEXPORT QString filesizeToString( unsigned int size );
  143. DLLEXPORT QByteArray percentEncode( const QUrl& url );
  144. DLLEXPORT QStringList supportedExtensions();
  145. DLLEXPORT QString extensionToMimetype( const QString& extension );
  146. DLLEXPORT void msleep( unsigned int ms );
  147. DLLEXPORT bool newerVersion( const QString& oldVersion, const QString& newVersion );
  148. DLLEXPORT int levenshtein( const QString& source, const QString& target );
  149. DLLEXPORT quint64 infosystemRequestId();
  150. DLLEXPORT QString md5( const QByteArray& data );
  151. DLLEXPORT bool removeDirectory( const QString& dir );
  152. /**
  153. * Check if this URL refers to a http-Result.
  154. *
  155. * Attention: This only checks for a http result, not a httpS result.
  156. */
  157. DLLEXPORT bool isHttpResult( const QString& url );
  158. DLLEXPORT bool isHttpsResult( const QString& url );
  159. DLLEXPORT bool isLocalResult( const QString& url );
  160. DLLEXPORT bool isRtmpResult( const QString& url );
  161. DLLEXPORT bool verifyFile( const QString& filePath, const QString& signature );
  162. DLLEXPORT QString extractScriptPayload( const QString& filename, const QString& resolverId, const QString& dirName = "atticaresolvers" );
  163. DLLEXPORT bool unzipFileInFolder( const QString& zipFileName, const QDir& folder );
  164. // Extracting may be asynchronous, pass in a receiver object with the following slots:
  165. // extractSucceeded( const QString& path ) and extractFailed() to be notified/
  166. DLLEXPORT void extractBinaryResolver( const QString& zipFilename, QObject* receiver );
  167. // Used by the above, not exported
  168. void copyWithAuthentication( const QString& srcFile, const QDir dest, QObject* receiver );
  169. DLLEXPORT bool whitelistedHttpResultHint( const QUrl& url );
  170. DLLEXPORT int compareVersionStrings( const QString& first, const QString& second );
  171. /**
  172. * This helper is designed to help "update" an existing playlist with a newer revision of itself.
  173. * To avoid re-loading the whole playlist and re-resolving tracks that are the same in the old playlist,
  174. * it goes through the new playlist and adds only new tracks.
  175. *
  176. * The new list of tracks is returned
  177. *
  178. * \return true if some changes were made, false if the new tracks are the same as the current tracks in \param orig
  179. */
  180. DLLEXPORT QList< Tomahawk::query_ptr > mergePlaylistChanges( const QList< Tomahawk::query_ptr >& orig, const QList< Tomahawk::query_ptr >& newTracks, bool& changed );
  181. DLLEXPORT void crash();
  182. /**
  183. * User-Agent header helpers
  184. */
  185. DLLEXPORT const QString operatingSystemVersionDetail();
  186. DLLEXPORT const QString userAgentString( const QString& applicationName, const QString& applicationVersion );
  187. /**
  188. * Qt4 / Qt5 compatibility layer
  189. */
  190. /* QUrl */
  191. DLLEXPORT void urlAddQueryItem( QUrl& url, const QString& key, const QString& value );
  192. DLLEXPORT QString urlQueryItemValue( const QUrl& url, const QString& key );
  193. DLLEXPORT bool urlHasQueryItem( const QUrl& url, const QString& key );
  194. DLLEXPORT QList<QPair<QString, QString> > urlQueryItems( const QUrl& url );
  195. DLLEXPORT void urlSetQuery( QUrl& url, const QString& query );
  196. DLLEXPORT QByteArray encodedQuery( const QUrl& url );
  197. }
  198. #endif // TOMAHAWKUTILS_H