Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F620636
singleapplication.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
singleapplication.cpp
View Options
#include
"singleapplication.h"
#include
<cstdlib>
/**
* @brief Constructor. Checks and fires up LocalServer or closes the program
* if another instance already exists
* @param argc
* @param argv
*/
SingleApplication
::
SingleApplication
(
int
argc
,
char
*
argv
[])
:
QApplication
(
argc
,
argv
)
{
QString
serverName
=
QApplication
::
organizationName
()
+
QApplication
::
applicationName
();
serverName
.
replace
(
QRegExp
(
"[^
\\
w
\\
-. ]"
),
""
);
// Attempt to connect to the LocalServer
socket
=
new
QLocalSocket
();
socket
->
connectToServer
(
serverName
);
if
(
socket
->
waitForConnected
(
1000
)){
socket
->
close
();
::
exit
(
EXIT_SUCCESS
);
// Terminate the program using STDLib's exit function
}
else
{
// If the connection is insuccessful, this is the main process
// So we create a Local Server
server
=
new
QLocalServer
();
server
->
removeServer
(
serverName
);
server
->
listen
(
serverName
);
QObject
::
connect
(
server
,
SIGNAL
(
newConnection
()),
this
,
SLOT
(
slotConnectionEstablished
()));
}
}
/**
* @brief Destructor
*/
SingleApplication
::~
SingleApplication
()
{
server
->
close
();
}
/**
* @brief Executed when the showUp command is sent to LocalServer
*/
void
SingleApplication
::
slotConnectionEstablished
()
{
server
->
nextPendingConnection
();
emit
showUp
();
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sat, Nov 14, 6:15 PM (15 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
131625
Default Alt Text
singleapplication.cpp (1 KB)
Attached To
Mode
R64 cKaiser's QSingleApplicaiton
Attached
Detach File
Event Timeline