Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/systemfile.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/systemfile.cpp | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.cpp b/noncore/settings/networksettings2/networksettings2/systemfile.cpp new file mode 100644 index 0000000..7249976 --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/systemfile.cpp | |||
@@ -0,0 +1,144 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <qpe/qpeapplication.h> | ||
3 | #include <qfileinfo.h> | ||
4 | #include <qmessagebox.h> | ||
5 | #include <qfile.h> | ||
6 | #include <qtextstream.h> | ||
7 | |||
8 | #include "resources.h" | ||
9 | #include "systemfile.h" | ||
10 | |||
11 | #define TEMPLATEDIR "networktemplates/" | ||
12 | QString TemplDir; | ||
13 | |||
14 | SystemFile::SystemFile( const QString & N, const QString & P ){ | ||
15 | Name = N; | ||
16 | Path = P; | ||
17 | F = 0; | ||
18 | // get template info | ||
19 | { QString S; | ||
20 | QFileInfo FI; | ||
21 | |||
22 | // find location of templates | ||
23 | TemplDir = QPEApplication::qpeDir() + "etc/" + TEMPLATEDIR; | ||
24 | FI.setFile( TemplDir ); | ||
25 | if( ! FI.isDir() ) { | ||
26 | // try current dir | ||
27 | TemplDir = "./" TEMPLATEDIR; | ||
28 | FI.setFile( TemplDir ); | ||
29 | if( ! FI.isDir() ) { | ||
30 | hasPreSection = | ||
31 | hasPostSection = | ||
32 | hasPreNodeSection = | ||
33 | hasPostNodeSection = 0; | ||
34 | return; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | // have found location | ||
39 | S = TemplDir + Name + "/presection"; | ||
40 | FI.setFile( S ); | ||
41 | hasPreSection = ( FI.exists() && FI.isReadable() ); | ||
42 | S = TemplDir + Name + "/postsection"; | ||
43 | FI.setFile( S ); | ||
44 | hasPostSection = ( FI.exists() && FI.isReadable() ); | ||
45 | S = TemplDir + Name + "/prenodesection"; | ||
46 | FI.setFile( S ); | ||
47 | hasPreNodeSection = ( FI.exists() && FI.isReadable() ); | ||
48 | S = TemplDir + Name + "/postnodesection"; | ||
49 | FI.setFile( S ); | ||
50 | hasPostNodeSection = ( FI.exists() && FI.isReadable() ); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | SystemFile::~SystemFile( void ) { | ||
55 | if( F ) | ||
56 | delete F; | ||
57 | } | ||
58 | |||
59 | bool SystemFile::open( void ) { | ||
60 | if( F ) { | ||
61 | F->close(); | ||
62 | delete F; | ||
63 | } | ||
64 | |||
65 | F = new QFile( Path + "bup" ); | ||
66 | if( ! F->open( IO_WriteOnly ) ) { | ||
67 | return 0; | ||
68 | } | ||
69 | setDevice( F ); | ||
70 | return 1; | ||
71 | } | ||
72 | |||
73 | bool SystemFile::close( void ) { | ||
74 | if( ! F ) { | ||
75 | return 1 ; | ||
76 | } | ||
77 | |||
78 | QString OldP = Path + "bup"; | ||
79 | |||
80 | F->close(); | ||
81 | delete F; | ||
82 | F = 0; | ||
83 | |||
84 | return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); | ||
85 | } | ||
86 | |||
87 | bool SystemFile::preSection( void ) { | ||
88 | if( hasPreSection ) { | ||
89 | QFile Fl( TemplDir + Name + "/presection" ); | ||
90 | if( ! Fl.open( IO_ReadOnly ) ) | ||
91 | return 1; // error | ||
92 | // copy file to this file | ||
93 | F->writeBlock( Fl.readAll() ); | ||
94 | } | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | bool SystemFile::postSection( void ) { | ||
99 | if( hasPostSection ) { | ||
100 | QFile Fl( TemplDir + Name + "/postsection" ); | ||
101 | if( ! Fl.open( IO_ReadOnly ) ) | ||
102 | return 1; // error | ||
103 | // copy file to this file | ||
104 | F->writeBlock( Fl.readAll() ); | ||
105 | } | ||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) { | ||
110 | if( hasPreNodeSection ) { | ||
111 | QFile Fl( TemplDir + Name + "/prenodesectoin" ); | ||
112 | if( ! Fl.open( IO_ReadOnly ) ) | ||
113 | return 1; // error | ||
114 | QTextStream TX( &Fl ); | ||
115 | QString Out; | ||
116 | QString S = TX.readLine(); | ||
117 | while( ! TX.eof() ) { | ||
118 | Out = S. | ||
119 | arg(NNI->netNode()->nodeName()); | ||
120 | (*this) << Out << endl; | ||
121 | S = TX.readLine(); | ||
122 | } | ||
123 | } | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long DevNr ) { | ||
128 | if( hasPostNodeSection ) { | ||
129 | QFile Fl( TemplDir + Name + "/postnodesectoin" ); | ||
130 | if( ! Fl.open( IO_ReadOnly ) ) | ||
131 | return 1; // error | ||
132 | QTextStream TX( &Fl ); | ||
133 | QString Out; | ||
134 | QString S = TX.readLine(); | ||
135 | while( ! TX.eof() ) { | ||
136 | Out = S. | ||
137 | arg(NNI->nodeName()); | ||
138 | (*this) << Out << endl; | ||
139 | S = TX.readLine(); | ||
140 | } | ||
141 | } | ||
142 | return 0; | ||
143 | } | ||
144 | |||