/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. 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_URL_BUILDER_H
  17. #define LASTFM_URL_BUILDER_H
  18. #include <lastfm/global.h>
  19. #include <QLocale>
  20. #include <QString>
  21. #include <QUrl>
  22. namespace lastfm
  23. {
  24. /** For building www.last.fm urls. We have special rules for encoding and that */
  25. class LASTFM_DLLEXPORT UrlBuilder
  26. {
  27. QByteArray path;
  28. public:
  29. /** Careful, the base is not encoded at all, we assume it is ASCII!
  30. * If you need it encoded at all you must use the slash function.
  31. * eg. UrlBuilder( "user" ).slash( "mxcl" ) ==> http://last.fm/user/mxcl
  32. */
  33. UrlBuilder( const QString& base ) : path( '/' + base.toAscii() )
  34. {}
  35. UrlBuilder& slash( const QString& path ) { this->path += '/' + encode( path ); return *this; }
  36. QUrl url() const;
  37. /** www.last.fm becomes the local version, eg www.lastfm.de */
  38. static QUrl localize( QUrl );
  39. /** www.last.fm becomes m.last.fm, localisation is preserved */
  40. static QUrl mobilize( QUrl );
  41. /** Use this to URL encode any database item (artist, track, album). It
  42. * internally calls UrlEncodeSpecialChars to double encode some special
  43. * symbols according to the same pattern as that used on the website.
  44. *
  45. * &, /, ;, +, #
  46. *
  47. * Use for any urls that go to www.last.fm
  48. * Do not use for ws.audioscrobbler.com
  49. */
  50. static QByteArray encode( QString );
  51. /** returns eg. www.lastfm.de */
  52. static QString host( const QLocale& = QLocale() );
  53. };
  54. }
  55. #endif