Menu

[04607a]: / doorpointerapplication.cpp  Maximize  Restore  History

Download this file

70 lines (47 with data), 1.6 kB

 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
#include "doorpointerapplication.h"
DoorPointerApplication::DoorPointerApplication(){
QMenu* contextMenu = new QMenu();
connect( contextMenu->addAction( "Exit" ) , SIGNAL(triggered()) , qApp , SLOT(quit()) );
m_trayIcon.setIcon( QIcon( ":/door" ) );
m_trayIcon.setContextMenu( contextMenu );
m_trayIcon.show();
loadIniFile( "nat.ini" );
}
void DoorPointerApplication::loadIniFile( QString file ){
DoorServer* serv;
foreach( serv , m_servers ){
serv->deleteLater();
}
m_servers.clear();
QFile natFile( file );
if( !natFile.open( QIODevice::ReadOnly ) )
return;
QString line;
QStringList lineList;
while( !natFile.atEnd() ){
line = natFile.readLine(512);
lineList = line.split( "," );
if( lineList.count() != 3 )
continue;
bool done = false;
int p = lineList[0].toInt( &done );
if( !done ) continue;
QString ha = lineList[1].trimmed();
int hp = lineList[2].toInt( &done );
if( !done ) continue;
m_servers.append( new DoorServer( p , ha , hp ) );
}
}
void DoorPointerApplication::saveConfiguration(){
DoorServer* serv;
QStringList data;
QFile fop( "nat.ini" );
if( !fop.open( QIODevice::WriteOnly ) ){
return;
}
foreach( serv , m_servers ){
fop.write( QString( QString::number( serv->fromPort() ) + " , " +
serv->toHost() + " , " +
QString::number( serv->toPort() ) + "\n" ).toLocal8Bit() );
}
}