~ubuntu-branches/ubuntu/karmic/amarok/karmic

« back to all changes in this revision

Viewing changes to src/services/lastfm/lastfm/core/CoreDir.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2009-09-03 23:49:07 UTC
  • mfrom: (1.77.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090903234907-rk4lt6hnxwckvuon
Tags: 2:2.1.80-0ubuntu1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright 2005-2008 Last.fm Ltd.                                      *
3
 
 *                                                                         *
4
 
 *   This program is free software; you can redistribute it and/or modify  *
5
 
 *   it under the terms of the GNU General Public License as published by  *
6
 
 *   the Free Software Foundation; either version 2 of the License, or     *
7
 
 *   (at your option) any later version.                                   *
8
 
 *                                                                         *
9
 
 *   This program 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
 
 *                                                                         *
14
 
 *   You should have received a copy of the GNU General Public License     *
15
 
 *   along with this program; if not, write to the                         *
16
 
 *   Free Software Foundation, Inc.,                                       *
17
 
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18
 
 ***************************************************************************/
19
 
 
20
 
#include "CoreDir.h"
21
 
#include <QDebug>
22
 
#include <QDir>
23
 
#ifdef WIN32
24
 
    #include <shlobj.h>
25
 
#endif
26
 
#ifdef Q_WS_MAC
27
 
    #include <QCoreApplication>
28
 
    #include <Carbon/Carbon.h>
29
 
#endif
30
 
 
31
 
 
32
 
#ifdef Q_WS_MAC
33
 
QDir
34
 
CoreDir::bundle()
35
 
{
36
 
    return QDir( qApp->applicationDirPath() ).absoluteFilePath( "../.." );
37
 
}
38
 
#endif
39
 
 
40
 
 
41
 
QDir
42
 
CoreDir::dataDotDot()
43
 
{
44
 
#ifdef WIN32
45
 
    if ((QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) == 0)
46
 
    {
47
 
        // Use this for non-DOS-based Windowses
48
 
        char path[MAX_PATH];
49
 
        HRESULT h = SHGetFolderPathA( NULL, 
50
 
                                      CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE,
51
 
                                      NULL, 
52
 
                                      0, 
53
 
                                      path );
54
 
        if (h == S_OK)
55
 
            return QString::fromLocal8Bit( path );
56
 
    }
57
 
    return QDir::home();
58
 
 
59
 
#elif defined(Q_WS_MAC)
60
 
 
61
 
    #define EIT( x ) { OSErr err = x; if (err != noErr) throw 1; }
62
 
    try
63
 
    {
64
 
        short vRefNum = 0;
65
 
        long dirId;
66
 
        EIT( ::FindFolder( kOnAppropriateDisk, 
67
 
                           kApplicationSupportFolderType,
68
 
                           kDontCreateFolder, 
69
 
                           &vRefNum, 
70
 
                           &dirId ) );
71
 
 
72
 
        // Now we have a vRefNum and a dirID - but *not* an Unix-Path as string.
73
 
        // Lets make one based from this:
74
 
        FSSpec fsspec;
75
 
        EIT( ::FSMakeFSSpec( vRefNum, dirId, NULL, &fsspec ) );
76
 
 
77
 
        // ...and build an FSRef based on thes FSSpec.
78
 
        FSRef fsref;
79
 
        EIT( ::FSpMakeFSRef( &fsspec, &fsref ) );
80
 
 
81
 
        // ...then extract the Unix Path as a C-String from the FSRef
82
 
        unsigned char path[512];
83
 
        EIT( ::FSRefMakePath( &fsref, path, 512 ) );
84
 
 
85
 
        return QDir::homePath() + QString::fromUtf8( (char*)path );
86
 
    }
87
 
    catch (int)
88
 
    {
89
 
        return QDir::home().filePath( "Library/Application Support" );
90
 
    }
91
 
 
92
 
#elif defined(Q_WS_X11)
93
 
    return QDir::home().filePath( ".local/share" );
94
 
 
95
 
#else
96
 
    return QDir::home();
97
 
#endif
98
 
}
99
 
 
100
 
 
101
 
#ifdef WIN32
102
 
QDir
103
 
CoreDir::programFiles()
104
 
{
105
 
    char path[MAX_PATH];
106
 
 
107
 
    // TODO: this call is dependant on a specific version of shell32.dll.
108
 
    // Need to degrade gracefully. Need to bundle SHFolder.exe with installer
109
 
    // and execute it on install for this to work on Win98.
110
 
    HRESULT h = SHGetFolderPathA( NULL,
111
 
                                 CSIDL_PROGRAM_FILES, 
112
 
                                 NULL,
113
 
                                 0, // current path
114
 
                                 path );
115
 
 
116
 
    if (h != S_OK)
117
 
    {
118
 
        qCritical() << "Couldn't get Program Files dir. Possibly Win9x?";
119
 
        return "";
120
 
    }
121
 
 
122
 
    return QString::fromLocal8Bit( path );
123
 
}
124
 
#endif