Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/util/qdesktopservices_win.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4242#include <qsettings.h>
    4343#include <qdir.h>
     44#include <qlibrary.h>
    4445#include <qurl.h>
    4546#include <qstringlist.h>
     
    4849#include <qcoreapplication.h>
    4950
    50 #include <windows.h>
     51#include <qt_windows.h>
    5152#include <shlobj.h>
    5253#if !defined(Q_OS_WINCE)
     
    5960#endif
    6061
     62#if defined(Q_CC_MINGW) && !defined(CSIDL_MYMUSIC)
     63#define CSIDL_MYMUSIC   13
     64#define CSIDL_MYVIDEO   14
     65#endif
     66
    6167#ifndef QT_NO_DESKTOPSERVICES
    6268
    6369QT_BEGIN_NAMESPACE
    64 
    65 //#undef UNICODE
    6670
    6771static bool openDocument(const QUrl &file)
     
    6973    if (!file.isValid())
    7074        return false;
    71 
    72     quintptr returnValue;
    73     QT_WA({
    74                 returnValue = (quintptr)ShellExecute(0, 0, (TCHAR *)file.toString().utf16(), 0, 0, SW_SHOWNORMAL);
    75             } , {
    76                 returnValue = (quintptr)ShellExecuteA(0, 0, file.toString().toLocal8Bit().constData(), 0, 0, SW_SHOWNORMAL);
    77             });
     75    QString filePath = file.toLocalFile();
     76    if (filePath.isEmpty())
     77        filePath = file.toString();
     78    quintptr returnValue = (quintptr)ShellExecute(0, 0, (wchar_t*)filePath.utf16(), 0, 0, SW_SHOWNORMAL);
    7879    return (returnValue > 32); //ShellExecute returns a value greater than 32 if successful
    7980}
     
    8182static QString expandEnvStrings(const QString &command)
    8283{
    83 
    8484#if defined(Q_OS_WINCE)
    8585    return command;
    8686#else
    87     QByteArray path = command.toLocal8Bit();
    88     char commandValue[2 * MAX_PATH] = {0};
    89     DWORD returnValue = ExpandEnvironmentStringsA(path.data(), commandValue, MAX_PATH);
    90     if (returnValue)
    91         return QString::fromLocal8Bit(commandValue);
     87    wchar_t buffer[MAX_PATH];
     88    if (ExpandEnvironmentStrings((wchar_t*)command.utf16(), buffer, MAX_PATH))
     89        return QString::fromWCharArray(buffer);
    9290    else
    9391        return command;
     
    9997    if (url.scheme() == QLatin1String("mailto")) {
    10098        //Retrieve the commandline for the default mail client
    101         //the key used below is the command line for the mailto: shell command
     99        //the default key used below is the command line for the mailto: shell command
    102100        DWORD  bufferSize = 2 * MAX_PATH;
    103101        long  returnValue =  -1;
     
    106104        HKEY handle;
    107105        LONG res;
    108         QT_WA ({
    109             res = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"mailto\\Shell\\Open\\Command", 0, KEY_READ, &handle);
    110             if (res != ERROR_SUCCESS)
    111                 return false;
    112 
    113             wchar_t keyValue[2 * MAX_PATH] = {0};
    114             returnValue = RegQueryValueExW(handle, L"", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize);
     106        wchar_t keyValue[2 * MAX_PATH] = {0};
     107        QString keyName(QLatin1String("mailto"));
     108
     109        //Check if user has set preference, otherwise use default.
     110        res = RegOpenKeyExW(HKEY_CURRENT_USER,
     111                            L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice",
     112                            0, KEY_READ, &handle);
     113        if (res == ERROR_SUCCESS) {
     114            returnValue = RegQueryValueEx(handle, L"Progid", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize);
    115115            if (!returnValue)
    116                 command = QString::fromRawData((QChar*)keyValue, bufferSize);
    117         }, {
    118             res = RegOpenKeyExA(HKEY_CLASSES_ROOT, "mailto\\Shell\\Open\\Command", 0, KEY_READ, &handle);
    119             if (res != ERROR_SUCCESS)
    120                 return false;
    121 
    122             char keyValue[2 * MAX_PATH] = {0};
    123             returnValue = RegQueryValueExA(handle, "", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize);
    124             if (!returnValue)
    125                 command = QString::fromLocal8Bit(keyValue);
    126         });
     116                keyName = QString::fromUtf16((const ushort*)keyValue);
     117            RegCloseKey(handle);
     118        }
     119        keyName += QLatin1String("\\Shell\\Open\\Command");
     120        res = RegOpenKeyExW(HKEY_CLASSES_ROOT, (const wchar_t*)keyName.utf16(), 0, KEY_READ, &handle);
     121        if (res != ERROR_SUCCESS)
     122            return false;
     123
     124        bufferSize = 2 * MAX_PATH;
     125        returnValue = RegQueryValueExW(handle, L"", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize);
     126        if (!returnValue)
     127            command = QString::fromRawData((QChar*)keyValue, bufferSize);
    127128        RegCloseKey(handle);
    128129
    129         if(returnValue)
     130        if (returnValue)
    130131            return false;
     132
    131133        command = expandEnvStrings(command);
    132134        command = command.trimmed();
     
    146148        PROCESS_INFORMATION pi;
    147149        ZeroMemory(&pi, sizeof(pi));
    148         QT_WA ({
    149             STARTUPINFO si;
    150             ZeroMemory(&si, sizeof(si));
    151             si.cb = sizeof(si);
    152 
    153             returnValue = CreateProcess(NULL, (TCHAR*)command.utf16(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
    154         }, {
    155             STARTUPINFOA si;
    156             ZeroMemory(&si, sizeof(si));
    157             si.cb = sizeof(si);
    158 
    159             returnValue = CreateProcessA(NULL, command.toLocal8Bit().data(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
    160         });
     150        STARTUPINFO si;
     151        ZeroMemory(&si, sizeof(si));
     152        si.cb = sizeof(si);
     153
     154        returnValue = CreateProcess(NULL, (wchar_t*)command.utf16(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
    161155
    162156        if (!returnValue)
     
    171165        return false;
    172166
    173     quintptr returnValue;
    174      QT_WA ({
    175          returnValue = (quintptr)ShellExecute(0, 0, (TCHAR *) QString::fromUtf8(url.toEncoded().constData()).utf16(), 0, 0, SW_SHOWNORMAL);
    176             } , {
    177                 returnValue = (quintptr)ShellExecuteA(0, 0, url.toEncoded().constData(), 0, 0, SW_SHOWNORMAL);
    178             });
     167    if (url.scheme().isEmpty())
     168        return openDocument(url);
     169
     170    quintptr returnValue = (quintptr)ShellExecute(0, 0, (wchar_t *)QString::fromUtf8(url.toEncoded().constData()).utf16(),
     171                                                  0, 0, SW_SHOWNORMAL);
    179172    return (returnValue > 32);
    180173}
     
    182175QString QDesktopServices::storageLocation(StandardLocation type)
    183176{
    184 #if !defined(QT_NO_SETTINGS)   
    185     QSettings settings(QSettings::UserScope, QLatin1String("Microsoft"), QLatin1String("Windows"));
    186     settings.beginGroup(QLatin1String("CurrentVersion/Explorer/Shell Folders"));
     177    QString result;
     178
     179#ifndef Q_OS_WINCE
     180        QLibrary library(QLatin1String("shell32"));
     181#else
     182        QLibrary library(QLatin1String("coredll"));
     183#endif // Q_OS_WINCE
     184    typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL);
     185    static GetSpecialFolderPath SHGetSpecialFolderPath =
     186            (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
     187    if (!SHGetSpecialFolderPath)
     188        return QString();
     189
     190    wchar_t path[MAX_PATH];
     191
    187192    switch (type) {
     193    case DataLocation:
     194#if defined Q_WS_WINCE
     195        if (SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE))
     196#else
     197        if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE))
     198#endif
     199            result = QString::fromWCharArray(path);
     200        if (!QCoreApplication::organizationName().isEmpty())
     201            result = result + QLatin1String("\\") + QCoreApplication::organizationName();
     202        if (!QCoreApplication::applicationName().isEmpty())
     203            result = result + QLatin1String("\\") + QCoreApplication::applicationName();
     204        break;
     205
     206    case DesktopLocation:
     207        if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, FALSE))
     208            result = QString::fromWCharArray(path);
     209        break;
     210
     211    case DocumentsLocation:
     212        if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE))
     213            result = QString::fromWCharArray(path);
     214        break;
     215
     216    case FontsLocation:
     217        if (SHGetSpecialFolderPath(0, path, CSIDL_FONTS, FALSE))
     218            result = QString::fromWCharArray(path);
     219        break;
     220
     221    case ApplicationsLocation:
     222        if (SHGetSpecialFolderPath(0, path, CSIDL_PROGRAMS, FALSE))
     223            result = QString::fromWCharArray(path);
     224        break;
     225
     226    case MusicLocation:
     227        if (SHGetSpecialFolderPath(0, path, CSIDL_MYMUSIC, FALSE))
     228            result = QString::fromWCharArray(path);
     229        break;
     230
     231    case MoviesLocation:
     232        if (SHGetSpecialFolderPath(0, path, CSIDL_MYVIDEO, FALSE))
     233            result = QString::fromWCharArray(path);
     234        break;
     235
     236    case PicturesLocation:
     237        if (SHGetSpecialFolderPath(0, path, CSIDL_MYPICTURES, FALSE))
     238            result = QString::fromWCharArray(path);
     239        break;
     240
    188241    case CacheLocation:
    189242        // Although Microsoft has a Cache key it is a pointer to IE's cache, not a cache
     
    191244        // cache directory located in their AppData directory
    192245        return storageLocation(DataLocation) + QLatin1String("\\cache");
    193     case DataLocation:
    194         if (!settings.contains(QLatin1String("Local AppData")))
    195             break;
    196         return settings.value(QLatin1String("Local AppData")).toString()
    197             + QLatin1String("\\") + QCoreApplication::organizationName()
    198             + QLatin1String("\\") + QCoreApplication::applicationName();
    199         break;
    200     case DesktopLocation:
    201         return settings.value(QLatin1String("Desktop")).toString();
    202         break;
    203 
    204     case DocumentsLocation:
    205         return settings.value(QLatin1String("Personal")).toString();
    206         break;
    207 
    208     case FontsLocation:
    209         return settings.value(QLatin1String("Fonts")).toString();
    210         break;
    211 
    212     case ApplicationsLocation:
    213         return settings.value(QLatin1String("Programs")).toString();
    214         break;
    215 
    216     case MusicLocation:
    217         return settings.value(QLatin1String("My Music")).toString();
    218         break;
    219 
    220     case MoviesLocation:
    221         return settings.value(QLatin1String("My Video")).toString();
    222         break;
    223 
    224     case PicturesLocation:
    225         return settings.value(QLatin1String("My Pictures")).toString();
    226         break;
    227246
    228247    case QDesktopServices::HomeLocation:
     
    235254        break;
    236255    }
    237 #endif
    238     return QString();
     256    return result;
    239257}
    240258
Note: See TracChangeset for help on using the changeset viewer.