PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

/thirdparty/liblastfm2/src/core/UrlBuilder.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 69 lines | 23 code | 10 blank | 36 comment | 0 complexity | 99fb6b588229451454cfa1ea78e01e95 MD5 | raw file
 1/*
 2   Copyright 2009 Last.fm Ltd. 
 3      - Primarily authored by Max Howell, Jono Cole and Doug Mansell
 4
 5   This file is part of liblastfm.
 6
 7   liblastfm 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   liblastfm 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 liblastfm.  If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef LASTFM_URL_BUILDER_H
21#define LASTFM_URL_BUILDER_H
22
23#include <lastfm/global.h>
24#include <QLocale>
25#include <QString>
26#include <QUrl>
27  
28
29namespace lastfm
30{
31    /** For building www.last.fm urls. We have special rules for encoding and that */
32    class LASTFM_DLLEXPORT UrlBuilder
33    {
34        QByteArray path;
35
36    public:
37        /** Careful, the base is not encoded at all, we assume it is ASCII!
38          * If you need it encoded at all you must use the slash function.
39          * eg. UrlBuilder( "user" ).slash( "mxcl" ) ==> http://last.fm/user/mxcl
40          */
41        UrlBuilder( const QString& base ) : path( '/' + base.toAscii() )
42        {}
43
44        UrlBuilder& slash( const QString& path ) { this->path += '/' + encode( path ); return *this; }
45
46        QUrl url() const;
47
48        /** www.last.fm becomes the local version, eg www.lastfm.de */
49        static QUrl localize( QUrl );
50        /** www.last.fm becomes m.last.fm, localisation is preserved */
51        static QUrl mobilize( QUrl );
52
53        /** Use this to URL encode any database item (artist, track, album). It
54          * internally calls UrlEncodeSpecialChars to double encode some special
55          * symbols according to the same pattern as that used on the website.
56          *
57          * &, /, ;, +, #
58          *
59          * Use for any urls that go to www.last.fm
60          * Do not use for ws.audioscrobbler.com
61          */
62        static QByteArray encode( QString );
63
64        /** returns eg. www.lastfm.de */
65        static QString host( const QLocale& = QLocale() );
66    };
67}
68
69#endif