PageRenderTime 194ms CodeModel.GetById 93ms app.highlight 14ms RepoModel.GetById 84ms app.codeStats 1ms

/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
 21#pragma once
 22#ifndef TOMAHAWKUTILS_H
 23#define TOMAHAWKUTILS_H
 24
 25#include "DllMacro.h"
 26
 27#include <QtCore/QThread>
 28#include <QtNetwork/QNetworkProxy>
 29#include <QtCore/QStringList>
 30#include <Typedefs.h>
 31
 32#define RESPATH ":/data/"
 33
 34class QDir;
 35class QNetworkAccessManager;
 36
 37namespace TomahawkUtils
 38{
 39    enum MediaType
 40    {
 41        MediaTypeArtist,
 42        MediaTypeAlbum,
 43        MediaTypeTrack
 44    };
 45
 46    enum ImageType
 47    {
 48        DefaultAlbumCover,
 49        DefaultArtistImage,
 50        DefaultTrackImage,
 51        DefaultSourceAvatar,
 52        DefaultCollection,
 53        DefaultResolver,
 54        NowPlayingSpeaker,
 55        NowPlayingSpeakerDark,
 56        InfoIcon,
 57        PlayButton,
 58        PlayButtonPressed,
 59        PauseButton,
 60        PauseButtonPressed,
 61        PrevButton,
 62        PrevButtonPressed,
 63        NextButton,
 64        NextButtonPressed,
 65        ShuffleOff,
 66        ShuffleOffPressed,
 67        ShuffleOn,
 68        ShuffleOnPressed,
 69        RepeatOne,
 70        RepeatOnePressed,
 71        RepeatAll,
 72        RepeatAllPressed,
 73        RepeatOff,
 74        RepeatOffPressed,
 75        Volume,
 76        Share,
 77        NotLoved,
 78        Loved,
 79        Configure,
 80        GreenDot,
 81        AddContact,
 82        SubscribeOn,
 83        SubscribeOff,
 84        JumpLink,
 85        ProcessStop,
 86        HeadphonesOn,
 87        HeadphonesOff,
 88        PadlockClosed,
 89        PadlockOpen,
 90        Downloading,
 91        Uploading,
 92        ViewRefresh,
 93        SuperCollection,
 94        LovedPlaylist,
 95        NewReleases,
 96        NewAdditions,
 97        RecentlyPlayed,
 98        Queue,
 99        AutomaticPlaylist,
100        Charts,
101        Station,
102        Playlist,
103        Search,
104        ListRemove,
105        ListAdd,
106        AdvancedSettings,
107        DownloadsSettings,
108        AccountSettings,
109        MusicSettings,
110        Add,
111        DropSong,
112        DropAlbum,
113        DropAllSongs,
114        DropLocalSongs,
115        DropTopSongs,
116        LastfmIcon,
117        SpotifyIcon,
118        SoundcloudIcon,
119        AccountNone,
120        Starred,
121        Unstarred,
122        StarHovered,
123        SipPluginOnline,
124        SipPluginOffline,
125        ResolverBundle,
126        Inbox,
127        Invalid,
128        InboxNewItem,
129        Outbox,
130        NetworkActivity
131    };
132
133    enum ImageMode
134    {
135        Original,
136        CoverInCase,
137        DropShadow,
138        RoundedCorners
139    };
140
141
142    DLLEXPORT bool headless();
143    DLLEXPORT void setHeadless( bool headless );
144
145    DLLEXPORT QString appFriendlyVersion();
146
147    DLLEXPORT QDir appConfigDir();
148    DLLEXPORT QDir appDataDir();
149    DLLEXPORT QDir appLogDir();
150    DLLEXPORT const QString logFilePath();
151
152    DLLEXPORT void installTranslator( QObject* parent );
153
154    DLLEXPORT QString timeToString( int seconds );
155    DLLEXPORT QString ageToString( const QDateTime& time, bool appendAgoString = false );
156    DLLEXPORT QString filesizeToString( unsigned int size );
157    DLLEXPORT QByteArray percentEncode( const QUrl& url );
158
159    DLLEXPORT QStringList supportedExtensions();
160    DLLEXPORT QString extensionToMimetype( const QString& extension );
161
162    DLLEXPORT void msleep( unsigned int ms );
163    DLLEXPORT bool newerVersion( const QString& oldVersion, const QString& newVersion );
164    DLLEXPORT int levenshtein( const QString& source, const QString& target );
165
166    DLLEXPORT quint64 infosystemRequestId();
167
168    DLLEXPORT QString md5( const QByteArray& data );
169    DLLEXPORT bool removeDirectory( const QString& dir );
170
171    /**
172      * Check if this URL refers to a http-Result.
173      *
174      * Attention: This only checks for a http result, not a httpS result.
175      */
176    DLLEXPORT bool isHttpResult( const QString& url );
177    DLLEXPORT bool isHttpsResult( const QString& url );
178    DLLEXPORT bool isLocalResult( const QString& url );
179    DLLEXPORT bool isRtmpResult( const QString& url );
180
181    DLLEXPORT bool verifyFile( const QString& filePath, const QString& signature );
182    DLLEXPORT QString extractScriptPayload( const QString& filename, const QString& resolverId, const QString& dirName = "atticaresolvers" );
183    DLLEXPORT bool unzipFileInFolder( const QString& zipFileName, const QDir& folder );
184
185    // Extracting may be asynchronous, pass in a receiver object with the following slots:
186    //  extractSucceeded( const QString& path ) and extractFailed() to be notified/
187    DLLEXPORT void extractBinaryResolver( const QString& zipFilename, QObject* receiver );
188
189    // Used by the above, not exported
190    void copyWithAuthentication( const QString& srcFile, const QDir dest, QObject* receiver );
191
192    DLLEXPORT bool whitelistedHttpResultHint( const QUrl& url );
193
194    DLLEXPORT int compareVersionStrings( const QString& first, const QString& second );
195
196    /**
197     * This helper is designed to help "update" an existing playlist with a newer revision of itself.
198     * To avoid re-loading the whole playlist and re-resolving tracks that are the same in the old playlist,
199     * it goes through the new playlist and adds only new tracks.
200     *
201     * The new list of tracks is returned
202     *
203     * \return true if some changes were made, false if the new tracks are the same as the current tracks in \param orig
204     */
205    DLLEXPORT QList< Tomahawk::query_ptr > mergePlaylistChanges( const QList< Tomahawk::query_ptr >& orig, const QList< Tomahawk::query_ptr >& newTracks, bool& changed );
206
207    DLLEXPORT void crash();
208
209    /**
210     *  User-Agent header helpers
211     */
212    DLLEXPORT const QString operatingSystemVersionDetail();
213    DLLEXPORT const QString userAgentString( const QString& applicationName, const QString& applicationVersion );
214
215    /**
216     * Qt4 / Qt5 compatibility layer
217     */
218
219    /* QUrl */
220    DLLEXPORT void urlAddQueryItem( QUrl& url, const QString& key, const QString& value );
221    DLLEXPORT QString urlQueryItemValue( const QUrl& url, const QString& key );
222    DLLEXPORT bool urlHasQueryItem( const QUrl& url, const QString& key );
223    DLLEXPORT QList<QPair<QString, QString> > urlQueryItems( const QUrl& url );
224    DLLEXPORT void urlSetQuery( QUrl& url, const QString& query );
225    DLLEXPORT QByteArray encodedQuery( const QUrl& url );
226
227}
228
229#endif // TOMAHAWKUTILS_H