-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.cpp
94 lines (80 loc) · 2.12 KB
/
functions.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
//unit functions.cpp
#include <QtCore>
#include <QMessageBox>
#include <iostream>
#include <fstream>
#include <time.h>
#if defined(Q_OS_UNIX)
#include <X11/Xlib.h>
#elif defined(Q_OS_WIN)
#include <windows.h>
#endif
#include "functions.h"
//var
CIniFile rIniFile;
//endvar
bool Graphic() {
#if defined(Q_OS_UNIX)
//var
Display* pDisplay;
//endvar
if ( (pDisplay = XOpenDisplay(getenv(QString2PChar("DISPLAY")))) == NULL )
return false;
else
#endif
return true;
}
QString PChar2QString(const char* psPChar) {
return QString("%1").arg(psPChar);
}
char* QString2PChar(const QString sString) {
return sString.toAscii().data();
}
bool WriteToFile(const QString sDestFile, const QString sToFile, const bool fRewrite) {
//var
QFile rFileStream(sDestFile);
QTextStream* prTextStream;
//endvar
if ( fRewrite ) {
rFileStream.open(QIODevice::WriteOnly | QIODevice::Text);
} else
rFileStream.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
if ( rFileStream.isOpen() ) {
prTextStream = new QTextStream(&rFileStream);
prTextStream->operator << (sToFile);
rFileStream.close();
delete(prTextStream);
return true;
}
return false;
}
void Sleep(const signed int nMilliSeconds)
{
#if defined(Q_OS_WIN)
Sleep(nMilliSeconds);
#else
usleep(nMilliSeconds);
#endif
}
QString CIniFile::Read(const QString sFileName, const QString sSection, const QString sValue,
const QString sDefault) {
//var
QSettings Settings(m_sIniFile, QSettings::IniFormat);
//endvar
m_sIniFile = sFileName;
Settings.beginGroup(sSection);
m_sResult = Settings.value(sValue, "").toString();
if ( m_sResult == "" )
m_sResult = sDefault;
Settings.endGroup();
return m_sResult;
}
void CIniFile::Save(const QString sFileName, const QString sSection, const QString sValue, const QString sInValue) {
//var
QSettings Settings(m_sIniFile, QSettings::IniFormat);
//endvar
m_sIniFile = sFileName;
Settings.beginGroup(sSection);
Settings.setValue(sValue, sInValue);
Settings.endGroup();
}