20 #include <QtGui/QApplication>
25 #include <QTranslator>
27 #include <QLibraryInfo>
48 QString qt_transl_file =
QString(
"qt_") + QLocale::system().name();
49 qt_transl_file.truncate(5);
51 if (qt_transl->load( qt_transl_file,
52 QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
53 qApp->installTranslator( qt_transl );
73 #include <QtCore/QList>
74 #include <QtCore/QtDebug>
76 static PPERF_OBJECT_TYPE
FirstObject( PPERF_DATA_BLOCK PerfData )
78 return (PPERF_OBJECT_TYPE)((PBYTE)PerfData + PerfData->HeaderLength);
81 static PPERF_INSTANCE_DEFINITION
FirstInstance( PPERF_OBJECT_TYPE PerfObj )
83 return (PPERF_INSTANCE_DEFINITION)((PBYTE)PerfObj + PerfObj->DefinitionLength);
86 static PPERF_OBJECT_TYPE
NextObject( PPERF_OBJECT_TYPE PerfObj )
88 return (PPERF_OBJECT_TYPE)((PBYTE)PerfObj + PerfObj->TotalByteLength);
91 static PPERF_COUNTER_DEFINITION
FirstCounter( PPERF_OBJECT_TYPE PerfObj )
93 return (PPERF_COUNTER_DEFINITION) ((PBYTE)PerfObj + PerfObj->HeaderLength);
96 static PPERF_INSTANCE_DEFINITION
NextInstance( PPERF_INSTANCE_DEFINITION PerfInst )
98 PPERF_COUNTER_BLOCK PerfCntrBlk
99 = (PPERF_COUNTER_BLOCK)((PBYTE)PerfInst + PerfInst->ByteLength);
100 return (PPERF_INSTANCE_DEFINITION)((PBYTE)PerfCntrBlk + PerfCntrBlk->ByteLength);
103 static PPERF_COUNTER_DEFINITION
NextCounter( PPERF_COUNTER_DEFINITION PerfCntr )
105 return (PPERF_COUNTER_DEFINITION)((PBYTE)PerfCntr + PerfCntr->ByteLength);
108 static PPERF_COUNTER_BLOCK
CounterBlock(PPERF_INSTANCE_DEFINITION PerfInst)
110 return (PPERF_COUNTER_BLOCK) ((LPBYTE) PerfInst + PerfInst->ByteLength);
113 #define GETPID_TOTAL 64 * 1024
114 #define GETPID_BYTEINCREMENT 1024
115 #define GETPID_PROCESS_OBJECT_INDEX 230
116 #define GETPID_PROC_ID_COUNTER 784
120 return (
sizeof(
wchar_t) ==
sizeof(QChar)) ? QString::fromUtf16((ushort *)
string, size)
121 : QString::fromUcs4((uint *)
string, size);
127 qDebug() <<
"KApplication_getProcessesIdForName" << processName;
128 PPERF_OBJECT_TYPE perfObject;
129 PPERF_INSTANCE_DEFINITION perfInstance;
130 PPERF_COUNTER_DEFINITION perfCounter, curCounter;
131 PPERF_COUNTER_BLOCK counterPtr;
133 PPERF_DATA_BLOCK perfData = (PPERF_DATA_BLOCK) malloc( bufSize );
138 while( (lRes = RegQueryValueExA( HKEY_PERFORMANCE_DATA,
143 &bufSize )) == ERROR_MORE_DATA )
147 perfData = (PPERF_DATA_BLOCK) realloc( perfData, bufSize );
154 for( uint i = 0; i < perfData->NumObjectTypes; i++ ) {
163 qDebug() <<
"INSTANCES: " << perfObject->NumInstances;
164 for(
int instance = 0; instance < perfObject->NumInstances; instance++ ) {
165 curCounter = perfCounter;
166 const QString foundProcessName(
167 fromWChar( (
wchar_t *)( (PBYTE)perfInstance + perfInstance->NameOffset ) ) );
168 qDebug() <<
"foundProcessName: " << foundProcessName;
169 if ( foundProcessName == processName ) {
171 for( uint counter = 0; counter < perfObject->NumCounters; counter++ ) {
174 DWORD *value = (DWORD*)((LPBYTE) counterPtr + curCounter->CounterOffset);
175 pids.append(
int( *value ) );
176 qDebug() <<
"found PID: " << int( *value );
186 RegCloseKey(HKEY_PERFORMANCE_DATA);
193 int myPid = getpid();
194 foreach (
int pid, pids ) {
209 qWarning() <<
"Killing process \"" << processName <<
" (pid=" << pids[0] <<
")..";
210 int overallResult = 0;
211 foreach(
int pid, pids ) {
212 int result = kill( pid, SIGTERM );
215 result = kill( pid, SIGKILL );
217 overallResult = result;
219 return overallResult == 0;
222 struct EnumWindowsStruct
224 EnumWindowsStruct() : windowId( 0 ) {}
231 if ( GetWindowLong( hwnd, GWL_STYLE ) & WS_VISIBLE ) {
233 GetWindowThreadProcessId(hwnd, &pidwin);
234 if ( pidwin == ((EnumWindowsStruct*)lParam)->pid ) {
235 ((EnumWindowsStruct*)lParam)->windowId = hwnd;
246 int myPid = getpid();
248 foreach (
int pid, pids ) {
250 qDebug() <<
"activateWindowForProcess(): PID to activate:" << pid;
257 EnumWindowsStruct winStruct;
258 winStruct.pid = foundPid;
260 if ( winStruct.windowId == NULL )
QString fromWChar(const wchar_t *string, int size=-1)
static PPERF_OBJECT_TYPE FirstObject(PPERF_DATA_BLOCK PerfData)
static PPERF_OBJECT_TYPE NextObject(PPERF_OBJECT_TYPE PerfObj)
static void forceActiveWindow(WId win, long time=0)
Sets window win to be the active window.
void KApplication_init_windows()
MS Windows-related actions for KApplication startup.
void KApplication_activateWindowForProcess(const QString &executableName)
bool KApplication_killProcesses(const QString &processName)
static PPERF_INSTANCE_DEFINITION NextInstance(PPERF_INSTANCE_DEFINITION PerfInst)
static PPERF_COUNTER_DEFINITION FirstCounter(PPERF_OBJECT_TYPE PerfObj)
#define GETPID_PROC_ID_COUNTER
typedef BOOL(WINAPI *PtrTzSpecificLocalTimeToSystemTime)(LPTIME_ZONE_INFORMATION lpTimeZoneInformation
bool KApplication_otherProcessesExist(const QString &processName)
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
static PPERF_INSTANCE_DEFINITION FirstInstance(PPERF_OBJECT_TYPE PerfObj)
#define GETPID_BYTEINCREMENT
static PPERF_COUNTER_DEFINITION NextCounter(PPERF_COUNTER_DEFINITION PerfCntr)
void KApplication_getProcessesIdForName(const QString &processName, QList< int > &pids)
static PPERF_COUNTER_BLOCK CounterBlock(PPERF_INSTANCE_DEFINITION PerfInst)
#define GETPID_PROCESS_OBJECT_INDEX