-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
152 lines (126 loc) · 2.97 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "qt4phonedlg.h"
#include <QtGui/QApplication>
#include <QTextCodec>
#include <QMessageBox>
#include <QObject>
/////////////////////////////////////////////////////////////////////////////////////////////////
CheckOneApp::CheckOneApp()
{
}
CheckOneApp::~CheckOneApp()
{
fWork = false;
delete shmem;
sem->release();
wait(500);
}
bool CheckOneApp::isRun()
{
sem = new QSystemSemaphore("Qt4PhoneSem", 1);
bool isRunning = false;
shmem = new QSharedMemory("Qt4PhoneShM");
shmem->attach();
shmem->detach();
if (shmem->attach())
{
QMessageBox::critical(0, QObject::tr("Çàâåðøåíèå ðàáîòû"),
QObject::tr("Íåâîçìîæíî çàãðóçèòü ïðèëîæåíèå.\nÏðèëîæåíèå óæå çàïóùåíî!"));
sem->release();
isRunning = true;
}
else
{
shmem->create(1);
isRunning = false;
start();
}
return isRunning;
}
void CheckOneApp::run()
{
sem->acquire();
fWork = true;
while(fWork)
{
if(sem->acquire())
emit signalShow();
msleep(100);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
class Qt4Phone : public PProcess
{
PCLASSINFO(Qt4Phone, PProcess)
public:
Qt4Phone();
~Qt4Phone();
virtual void Main();
};
PCREATE_PROCESS(Qt4Phone);
Qt4Phone::Qt4Phone()
: PProcess("Qt4Phone", "Qt4Phone", 1, 0, AlphaCode, 0)
{
}
Qt4Phone::~Qt4Phone()
{
}
void Qt4Phone::Main()
{
PArgList &args = GetArguments();
int argCount = args.GetCount();
const char **argV = (const char**)calloc(argCount+1, sizeof(const char*));
bool fCreateConsole = false;
for (int i = 0; i < argCount; i++)
{
argV[i] = (const char*)args.GetParameter(i);
if(strcmp(argV[i], "-c")==0)
fCreateConsole = true;
}
argV[argCount] = NULL;
QTextCodec::setCodecForTr(QTextCodec::codecForName("windows-1251"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("windows-1251"));
#ifdef _WIN32
if(fCreateConsole)
{
#ifdef WIN32
WCHAR title[256];
#else
char title[256];
#endif
if(GetConsoleTitle(title,sizeof(title))==0)
{
AllocConsole();
freopen("CONOUT$","wt", stdout);
freopen("CONOUT$","wt", stderr);
freopen("CONIN$","rt", stdin);
GetConsoleTitle(title,sizeof(title));
HWND hConsoleWindow = FindWindow(NULL,title);
ShowWindow(hConsoleWindow,SW_SHOWMINNOACTIVE);
}
}
#endif
QApplication a(argCount, (char**)argV);
QtPhoneDlg *w = new QtPhoneDlg;
/////////////////////////////////////////////////////////////////////////////////////////
CheckOneApp checkOneApp;
if(checkOneApp.isRun())
{
delete w;
return;
}
int rc = QObject::connect(&checkOneApp, SIGNAL(signalShow()), w, SLOT(showSlot()));
/////////////////////////////////////////////////////////////////////////////////////////
if (QSystemTrayIcon::isSystemTrayAvailable())
{
puts("SystemTray - Available");
QApplication::setQuitOnLastWindowClosed(false);
}
else
{
puts("SystemTray - NOT Available");
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
w->show();
}
rc = a.exec();
delete w;
}