1 /**
2 * This file is a part of LuminanceHDR package.
3 * ----------------------------------------------------------------------
4 * Copyright (C) 2006,2007 Giuseppe Rota
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * ----------------------------------------------------------------------
20 *
21 * @author Daniel Kaneider <danielkaneider@users.sourceforge.net>
22 */
23
24 #include <QtGlobal>
25 #include "osintegration.h"
26
27 #include <QSysInfo>
28
29 #ifdef Q_OS_WIN
30 #define _WINSOCKAPI_ // stops windows.h including winsock.h
31 #include <windows.h>
32
33 typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
34 LPFN_ISWOW64PROCESS fnIsWow64Process;
35 #endif
36
37 OsIntegration *OsIntegration::instance = 0;
38
OsIntegration()39 OsIntegration::OsIntegration()
40 : QObject(),
41 m_progressMin(0),
42 m_progressMax(100)
43 #ifdef Q_OS_WIN
44 ,
45 m_winProgressbar(0)
46 #endif
47 {
48 #ifdef Q_OS_WIN
49 if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7)
50 m_winProgressbar = new EcWin7();
51 #endif
52 }
53
~OsIntegration()54 OsIntegration::~OsIntegration() {
55 #ifdef Q_OS_WIN
56 if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7)
57 delete m_winProgressbar;
58 #endif
59 }
60
getInstance()61 OsIntegration &OsIntegration::getInstance() {
62 if (!instance) {
63 instance = new OsIntegration();
64 }
65 return *instance;
66 }
67
getInstancePtr()68 OsIntegration *OsIntegration::getInstancePtr() {
69 if (!instance) {
70 instance = new OsIntegration();
71 }
72 return instance;
73 }
74
init(QWidget * mainWindow)75 void OsIntegration::init(QWidget *mainWindow) {
76 #ifdef Q_OS_WIN
77 if (m_winProgressbar) {
78 m_winProgressbar->init(mainWindow);
79 }
80 #endif
81 }
82
setProgress(int value,int max)83 void OsIntegration::setProgress(int value, int max) {
84 #ifdef Q_OS_WIN
85 if (m_winProgressbar) {
86 m_winProgressbar->setProgressValue(value, max);
87 }
88 #endif
89 }
90
setProgressValue(int value)91 void OsIntegration::setProgressValue(int value) {
92 #ifdef Q_OS_WIN
93 if (m_winProgressbar) {
94 m_winProgressbar->setProgressValue(value,
95 m_progressMax - m_progressMin);
96 }
97 #endif
98 }
99
setProgressRange(int min,int max)100 void OsIntegration::setProgressRange(int min, int max) {
101 m_progressMin = min;
102 m_progressMax = max;
103 }
104
addRecentFile(const QString & filename)105 void OsIntegration::addRecentFile(const QString &filename) {
106 #ifdef Q_OS_WIN
107 if (m_winProgressbar) {
108 m_winProgressbar->addRecentFile(filename);
109 }
110 #endif
111 }
112
isRunningOnSameCpuPlatform()113 bool OsIntegration::isRunningOnSameCpuPlatform() {
114 #if defined(Q_OS_WIN)
115 // 32-bit programs run on both 32-bit and 64-bit Windows
116 // so must sniff
117 BOOL f64 = true;
118 LPFN_ISWOW64PROCESS fnIsWow64Process;
119
120 fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
121 GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
122 if (NULL != fnIsWow64Process) {
123 return !(fnIsWow64Process(GetCurrentProcess(), &f64) && f64);
124 }
125 return true;
126 #else
127 return true;
128 #endif
129 }
130