PageRenderTime 89ms CodeModel.GetById 40ms app.highlight 8ms RepoModel.GetById 32ms app.codeStats 7ms

/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
  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_MISC_H
 21#define LASTFM_MISC_H
 22
 23#include <lastfm/global.h>
 24#include <QCryptographicHash>
 25#include <QDir>
 26#include <QString>
 27
 28#ifdef Q_WS_MAC
 29typedef const struct __CFString* CFStringRef;
 30#endif
 31
 32namespace lastfm
 33{
 34    namespace dir
 35    {
 36    #ifdef Q_WS_WIN
 37        LASTFM_DLLEXPORT QDir programFiles();
 38    #endif
 39    #ifdef Q_WS_MAC
 40        LASTFM_DLLEXPORT QDir bundle();
 41    #endif
 42        LASTFM_DLLEXPORT QDir runtimeData();
 43        LASTFM_DLLEXPORT QDir cache();
 44        LASTFM_DLLEXPORT QDir logs();
 45    }
 46   
 47#ifdef Q_WS_MAC 
 48    LASTFM_DLLEXPORT QByteArray CFStringToUtf8( CFStringRef );
 49    LASTFM_DLLEXPORT CFStringRef QStringToCFString( const QString& );
 50    inline QString CFStringToQString( CFStringRef s );
 51#endif
 52
 53    inline const char* platform()
 54    {
 55        #ifdef Q_WS_WIN
 56        switch (QSysInfo::WindowsVersion)
 57        {
 58            case QSysInfo::WV_32s:        return "Windows 3.1 with Win32s";
 59            case QSysInfo::WV_95:         return "Windows 95";
 60            case QSysInfo::WV_98:         return "Windows 98";
 61            case QSysInfo::WV_Me:         return "Windows Me";
 62            case QSysInfo::WV_DOS_based:  return "MS-DOS-based Windows";
 63
 64            case QSysInfo::WV_NT:         return "Windows NT";
 65            case QSysInfo::WV_2000:       return "Windows 2000";
 66            case QSysInfo::WV_XP:         return "Windows XP";
 67            case QSysInfo::WV_2003:       return "Windows Server 2003";
 68            case QSysInfo::WV_VISTA:      return "Windows Vista";
 69            case QSysInfo::WV_NT_based:   return "NT-based Windows";
 70
 71            case QSysInfo::WV_CE:         return "Windows CE";
 72            case QSysInfo::WV_CENET:      return "Windows CE.NET";
 73            case QSysInfo::WV_CE_based:   return "CE-based Windows";
 74
 75            default:                      return "Unknown";
 76        }
 77        #elif defined Q_WS_MAC
 78        switch (QSysInfo::MacintoshVersion)
 79        {
 80            case QSysInfo::MV_Unknown:    return "Unknown Mac";
 81            case QSysInfo::MV_9:          return "Mac OS 9";
 82            case QSysInfo::MV_10_0:       return "Mac OS X 10.0";
 83            case QSysInfo::MV_10_1:       return "Mac OS X 10.1";
 84            case QSysInfo::MV_10_2:       return "Mac OS X 10.2";
 85            case QSysInfo::MV_10_3:       return "Mac OS X 10.3";
 86            case QSysInfo::MV_10_4:       return "Mac OS X 10.4";
 87            case QSysInfo::MV_10_5:       return "Mac OS X 10.5";
 88
 89            default:                      return "Unknown";
 90        }
 91        #elif defined Q_WS_X11
 92            return "UNIX X11";
 93        #else
 94            return "Unknown";
 95        #endif
 96    }
 97    
 98    inline QString md5( const QByteArray& src )
 99    {
100        QByteArray const digest = QCryptographicHash::hash( src, QCryptographicHash::Md5 );
101        return QString::fromLatin1( digest.toHex() ).rightJustified( 32, '0' ).toLower();
102    }
103}
104
105#ifdef Q_WS_MAC
106inline QString lastfm::CFStringToQString( CFStringRef s )
107{
108    return QString::fromUtf8( CFStringToUtf8( s ) );
109}
110#endif
111#endif //LASTFM_MISC_H