-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 4 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/mainwindow.cpp | 4 | ||||
-rw-r--r-- | noncore/settings/sshkeys/sshkeys.cpp | 14 |
3 files changed, 11 insertions, 11 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index 0091a3b..420863c 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp | |||
@@ -1,521 +1,521 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | 3 | ||
4 | =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> | 4 | =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> |
5 | .=l. Dan Williams <drw@handhelds.org> | 5 | .=l. Dan Williams <drw@handhelds.org> |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This file is free software; you can | 7 | _;:, .> :=|. This file is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This file is distributed in the hope that | 14 | .i_,=:_. -<s. This file is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
19 | ..}^=.= = ; Public License for more details. | 19 | ..}^=.= = ; Public License for more details. |
20 | ++= -. .` .: | 20 | ++= -. .` .: |
21 | : = ...= . :.=- You should have received a copy of the GNU | 21 | : = ...= . :.=- You should have received a copy of the GNU |
22 | -. .:....=;==+<; General Public License along with this file; | 22 | -. .:....=;==+<; General Public License along with this file; |
23 | -_. . . )=. = see the file COPYING. If not, write to the | 23 | -_. . . )=. = see the file COPYING. If not, write to the |
24 | -- :-=` Free Software Foundation, Inc., | 24 | -- :-=` Free Software Foundation, Inc., |
25 | 59 Temple Place - Suite 330, | 25 | 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <opie2/oprocess.h> | 30 | #include <opie2/oprocess.h> |
31 | 31 | ||
32 | #ifdef QWS | 32 | #ifdef QWS |
33 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
34 | #else | 34 | #else |
35 | #include <qapplication.h> | 35 | #include <qapplication.h> |
36 | #endif | 36 | #endif |
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qfile.h> | 38 | #include <qfile.h> |
39 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
40 | 40 | ||
41 | #include "utils.h" | 41 | #include "utils.h" |
42 | #include "ipkg.h" | 42 | #include "ipkg.h" |
43 | #include "global.h" | 43 | #include "global.h" |
44 | 44 | ||
45 | using namespace Opie::Core; | 45 | using namespace Opie::Core; |
46 | Ipkg :: Ipkg() | 46 | Ipkg :: Ipkg() |
47 | { | 47 | { |
48 | proc = 0; | 48 | proc = 0; |
49 | } | 49 | } |
50 | 50 | ||
51 | Ipkg :: ~Ipkg() | 51 | Ipkg :: ~Ipkg() |
52 | { | 52 | { |
53 | } | 53 | } |
54 | 54 | ||
55 | // Option is what we are going to do - install, upgrade, download, reinstall | 55 | // Option is what we are going to do - install, upgrade, download, reinstall |
56 | // package is the package name to install - either a fully qualified path and ipk | 56 | // package is the package name to install - either a fully qualified path and ipk |
57 | // file (if stored locally) or just the name of the package (for a network package) | 57 | // file (if stored locally) or just the name of the package (for a network package) |
58 | // packageName is the package name - (for a network package this will be the same as | 58 | // packageName is the package name - (for a network package this will be the same as |
59 | // package parameter) | 59 | // package parameter) |
60 | // dest is the destination alias (from ipk.conf) | 60 | // dest is the destination alias (from ipk.conf) |
61 | // destDir is the dir that the destination alias points to (used to link to root) | 61 | // destDir is the dir that the destination alias points to (used to link to root) |
62 | // flags is the ipkg options flags | 62 | // flags is the ipkg options flags |
63 | // dir is the directory to run ipkg in (defaults to "") | 63 | // dir is the directory to run ipkg in (defaults to "") |
64 | void Ipkg :: runIpkg() | 64 | void Ipkg :: runIpkg() |
65 | { | 65 | { |
66 | error = false; | 66 | error = false; |
67 | QStringList commands; | 67 | QStringList commands; |
68 | 68 | ||
69 | QDir::setCurrent( "/tmp" ); | 69 | QDir::setCurrent( "/tmp" ); |
70 | 70 | ||
71 | if ( runtimeDir != "" ) | 71 | if ( runtimeDir != "" ) |
72 | { | 72 | { |
73 | commands << "cd "; | 73 | commands << "cd "; |
74 | commands << runtimeDir; | 74 | commands << runtimeDir; |
75 | commands << ";"; | 75 | commands << ";"; |
76 | } | 76 | } |
77 | commands << "ipkg" << "-V" << QString::number( infoLevel ) << "-force-defaults"; | 77 | commands << "ipkg" << "-V" << QString::number( infoLevel ) << "-force-defaults"; |
78 | 78 | ||
79 | // only set the destination for an install operation | 79 | // only set the destination for an install operation |
80 | if ( option == "install" ) | 80 | if ( option == "install" ) |
81 | commands << "-dest" << destination; | 81 | commands << "-dest" << destination; |
82 | 82 | ||
83 | 83 | ||
84 | if ( option != "update" && option != "download" ) | 84 | if ( option != "update" && option != "download" ) |
85 | { | 85 | { |
86 | if ( flags & FORCE_DEPENDS ) | 86 | if ( flags & FORCE_DEPENDS ) |
87 | commands << "-force-depends"; | 87 | commands << "-force-depends"; |
88 | if ( flags & FORCE_REINSTALL ) | 88 | if ( flags & FORCE_REINSTALL ) |
89 | commands << "-force-reinstall"; | 89 | commands << "-force-reinstall"; |
90 | if ( flags & FORCE_REMOVE ) | 90 | if ( flags & FORCE_REMOVE ) |
91 | commands << "-force-removal-of-essential-packages"; | 91 | commands << "-force-removal-of-essential-packages"; |
92 | if ( flags & FORCE_OVERWRITE ) | 92 | if ( flags & FORCE_OVERWRITE ) |
93 | commands << "-force-overwrite"; | 93 | commands << "-force-overwrite"; |
94 | if ( infoLevel == 3 ) | 94 | if ( infoLevel == 3 ) |
95 | commands << "-verbose_wget"; | 95 | commands << "-verbose_wget"; |
96 | 96 | ||
97 | // Handle make links | 97 | // Handle make links |
98 | // Rules - If make links is switched on, create links to root | 98 | // Rules - If make links is switched on, create links to root |
99 | // if destDir is NOT / | 99 | // if destDir is NOT / |
100 | if ( flags & MAKE_LINKS ) | 100 | if ( flags & MAKE_LINKS ) |
101 | { | 101 | { |
102 | // If destDir == / turn off make links as package is being insalled | 102 | // If destDir == / turn off make links as package is being insalled |
103 | // to root already. | 103 | // to root already. |
104 | if ( destDir == "/" ) | 104 | if ( destDir == "/" ) |
105 | flags ^= MAKE_LINKS; | 105 | flags ^= MAKE_LINKS; |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | #ifdef X86 | 109 | #ifdef X86 |
110 | commands << "-f"; | 110 | commands << "-f"; |
111 | commands << IPKG_CONF; | 111 | commands << IPKG_CONF; |
112 | #endif | 112 | #endif |
113 | 113 | ||
114 | 114 | ||
115 | if ( option == "reinstall" ) | 115 | if ( option == "reinstall" ) |
116 | commands << "install"; | 116 | commands << "install"; |
117 | else | 117 | else |
118 | commands << option; | 118 | commands << option; |
119 | if ( package != "" ) | 119 | if ( package != "" ) |
120 | commands << package; | 120 | commands << package; |
121 | 121 | ||
122 | 122 | ||
123 | if ( package != "" ) | 123 | if ( package != "" ) |
124 | emit outputText( tr( "Dealing with package %1" ).arg( package) ); | 124 | emit outputText( tr( "Dealing with package %1" ).arg( package) ); |
125 | 125 | ||
126 | qApp->processEvents(); | 126 | qApp->processEvents(); |
127 | 127 | ||
128 | // If we are removing, reinstalling or upgrading packages and make links option is selected | 128 | // If we are removing, reinstalling or upgrading packages and make links option is selected |
129 | // create the links | 129 | // create the links |
130 | if ( option == "remove" || option == "reinstall" || option == "upgrade" ) | 130 | if ( option == "remove" || option == "reinstall" || option == "upgrade" ) |
131 | { | 131 | { |
132 | createLinks = false; | 132 | createLinks = false; |
133 | if ( flags & MAKE_LINKS ) | 133 | if ( flags & MAKE_LINKS ) |
134 | { | 134 | { |
135 | emit outputText( tr( "Removing symbolic links...\n" ) ); | 135 | emit outputText( tr( "Removing symbolic links...\n" ) ); |
136 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 136 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
137 | emit outputText( QString( " " ) ); | 137 | emit outputText( QString( " " ) ); |
138 | } | 138 | } |
139 | } | 139 | } |
140 | 140 | ||
141 | // Execute command | 141 | // Execute command |
142 | dependantPackages = new QList<QString>; | 142 | dependantPackages = new QList<QString>; |
143 | dependantPackages->setAutoDelete( true ); | 143 | dependantPackages->setAutoDelete( true ); |
144 | 144 | ||
145 | executeIpkgCommand( commands, option ); | 145 | executeIpkgCommand( commands, option ); |
146 | 146 | ||
147 | } | 147 | } |
148 | 148 | ||
149 | void Ipkg :: createSymLinks() | 149 | void Ipkg :: createSymLinks() |
150 | { | 150 | { |
151 | if ( option == "install" || option == "reinstall" || option == "upgrade" ) | 151 | if ( option == "install" || option == "reinstall" || option == "upgrade" ) |
152 | { | 152 | { |
153 | // If we are not removing packages and make links option is selected | 153 | // If we are not removing packages and make links option is selected |
154 | // create the links | 154 | // create the links |
155 | createLinks = true; | 155 | createLinks = true; |
156 | if ( flags & MAKE_LINKS ) | 156 | if ( flags & MAKE_LINKS ) |
157 | { | 157 | { |
158 | emit outputText( " " ); | 158 | emit outputText( " " ); |
159 | emit outputText( tr( "Creating symbolic links for %1." ).arg( package) ); | 159 | emit outputText( tr( "Creating symbolic links for %1." ).arg( package) ); |
160 | 160 | ||
161 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 161 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
162 | 162 | ||
163 | // link dependant packages that were installed with this release | 163 | // link dependant packages that were installed with this release |
164 | QString *pkg; | 164 | QString *pkg; |
165 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) | 165 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) |
166 | { | 166 | { |
167 | if ( *pkg == package ) | 167 | if ( *pkg == package ) |
168 | continue; | 168 | continue; |
169 | emit outputText( " " ); | 169 | emit outputText( " " ); |
170 | emit outputText( tr( "Creating symbolic links for %1" ).arg( *pkg ) ); | 170 | emit outputText( tr( "Creating symbolic links for %1" ).arg( *pkg ) ); |
171 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); | 171 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); |
172 | } | 172 | } |
173 | } | 173 | } |
174 | } | 174 | } |
175 | 175 | ||
176 | delete dependantPackages; | 176 | delete dependantPackages; |
177 | 177 | ||
178 | emit outputText( tr("Finished") ); | 178 | emit outputText( tr("Finished") ); |
179 | emit outputText( "" ); | 179 | emit outputText( "" ); |
180 | } | 180 | } |
181 | 181 | ||
182 | void Ipkg :: removeStatusEntry() | 182 | void Ipkg :: removeStatusEntry() |
183 | { | 183 | { |
184 | QString statusFile = destDir; | 184 | QString statusFile = destDir; |
185 | if ( statusFile.right( 1 ) != "/" ) | 185 | if ( statusFile.right( 1 ) != "/" ) |
186 | statusFile.append( "/" ); | 186 | statusFile.append( "/" ); |
187 | statusFile.append( "usr/lib/ipkg/status" ); | 187 | statusFile.append( "usr/lib/ipkg/status" ); |
188 | QString outStatusFile = statusFile; | 188 | QString outStatusFile = statusFile; |
189 | outStatusFile.append( ".tmp" ); | 189 | outStatusFile.append( ".tmp" ); |
190 | 190 | ||
191 | emit outputText( "" ); | 191 | emit outputText( "" ); |
192 | emit outputText( tr("Removing status entry...") ); | 192 | emit outputText( tr("Removing status entry...") ); |
193 | QString tempstr = tr("status file - "); | 193 | QString tempstr = tr("status file - "); |
194 | tempstr.append( statusFile ); | 194 | tempstr.append( statusFile ); |
195 | emit outputText( tempstr ); | 195 | emit outputText( tempstr ); |
196 | tempstr = tr("package - "); | 196 | tempstr = tr("package - "); |
197 | tempstr.append( package ); | 197 | tempstr.append( package ); |
198 | emit outputText( tempstr ); | 198 | emit outputText( tempstr ); |
199 | 199 | ||
200 | QFile readFile( statusFile ); | 200 | QFile readFile( statusFile ); |
201 | QFile writeFile( outStatusFile ); | 201 | QFile writeFile( outStatusFile ); |
202 | 202 | ||
203 | if ( !readFile.open( IO_ReadOnly ) ) | 203 | if ( !readFile.open( IO_ReadOnly ) ) |
204 | { | 204 | { |
205 | tempstr = tr("Couldn't open status file - "); | 205 | tempstr = tr("Couldn't open status file - "); |
206 | tempstr.append( statusFile ); | 206 | tempstr.append( statusFile ); |
207 | emit outputText( tempstr ); | 207 | emit outputText( tempstr ); |
208 | return; | 208 | return; |
209 | } | 209 | } |
210 | 210 | ||
211 | if ( !writeFile.open( IO_WriteOnly ) ) | 211 | if ( !writeFile.open( IO_WriteOnly ) ) |
212 | { | 212 | { |
213 | tempstr = tr("Couldn't create tempory status file - "); | 213 | tempstr = tr("Couldn't create tempory status file - "); |
214 | tempstr.append( outStatusFile ); | 214 | tempstr.append( outStatusFile ); |
215 | emit outputText( tempstr ); | 215 | emit outputText( tempstr ); |
216 | return; | 216 | return; |
217 | } | 217 | } |
218 | 218 | ||
219 | int i = 0; | 219 | int i = 0; |
220 | 220 | ||
221 | QTextStream readStream( &readFile ); | 221 | QTextStream readStream( &readFile ); |
222 | QTextStream writeStream( &writeFile ); | 222 | QTextStream writeStream( &writeFile ); |
223 | QString line; | 223 | QString line; |
224 | 224 | ||
225 | char k[21]; | 225 | char k[21]; |
226 | char v[1001]; | 226 | char v[1001]; |
227 | QString key; | 227 | QString key; |
228 | QString value; | 228 | QString value; |
229 | 229 | ||
230 | while ( !readStream.atEnd() ) | 230 | while ( !readStream.atEnd() ) |
231 | { | 231 | { |
232 | //read new line | 232 | //read new line |
233 | line = readStream.readLine(); | 233 | line = readStream.readLine(); |
234 | 234 | ||
235 | if ( line.contains( ":", TRUE ) ) | 235 | if ( line.contains( ":", TRUE ) ) |
236 | { | 236 | { |
237 | //grep key and value from line | 237 | //grep key and value from line |
238 | k[0] = '\0'; | 238 | k[0] = '\0'; |
239 | v[0] = '\0'; | 239 | v[0] = '\0'; |
240 | sscanf( line, "%[^:]: %[^\n]", k, v ); | 240 | sscanf( line, "%[^:]: %[^\n]", k, v ); |
241 | key = k; | 241 | key = k; |
242 | value = v; | 242 | value = v; |
243 | key = key.stripWhiteSpace(); | 243 | key = key.stripWhiteSpace(); |
244 | value = value.stripWhiteSpace(); | 244 | value = value.stripWhiteSpace(); |
245 | } else { | 245 | } else { |
246 | key = ""; | 246 | key = ""; |
247 | value = ""; | 247 | value = ""; |
248 | } | 248 | } |
249 | 249 | ||
250 | if ( key == "Package" && value == package ) | 250 | if ( key == "Package" && value == package ) |
251 | { | 251 | { |
252 | //skip lines from the deleted package | 252 | //skip lines from the deleted package |
253 | while ( ( !readStream.atEnd() ) && ( line.stripWhiteSpace() != "" ) ) | 253 | while ( ( !readStream.atEnd() ) && ( line.stripWhiteSpace() != "" ) ) |
254 | { | 254 | { |
255 | line = readStream.readLine(); | 255 | line = readStream.readLine(); |
256 | } | 256 | } |
257 | } else { | 257 | } else { |
258 | 258 | ||
259 | //write other lines into the tempfile | 259 | //write other lines into the tempfile |
260 | writeStream << line << "\n"; | 260 | writeStream << line << "\n"; |
261 | 261 | ||
262 | // Improve UI responsiveness | 262 | // Improve UI responsiveness |
263 | i++; | 263 | i++; |
264 | if ( ( i % 50 ) == 0 ) | 264 | if ( ( i % 50 ) == 0 ) |
265 | qApp->processEvents(); | 265 | qApp->processEvents(); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | readFile.close(); | 269 | readFile.close(); |
270 | writeFile.close(); | 270 | writeFile.close(); |
271 | 271 | ||
272 | // Remove old status file and put tmp stats file in its place | 272 | // Remove old status file and put tmp stats file in its place |
273 | remove( statusFile ); | 273 | remove( statusFile ); |
274 | rename( outStatusFile, statusFile ); | 274 | rename( outStatusFile, statusFile ); |
275 | } | 275 | } |
276 | 276 | ||
277 | int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ ) | 277 | int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ ) |
278 | { | 278 | { |
279 | // If one is already running - should never be but just to be safe | 279 | // If one is already running - should never be but just to be safe |
280 | if ( proc ) | 280 | if ( proc ) |
281 | { | 281 | { |
282 | delete proc; | 282 | delete proc; |
283 | proc = 0; | 283 | proc = 0; |
284 | } | 284 | } |
285 | 285 | ||
286 | // OK we're gonna use OProcess to run this thing | 286 | // OK we're gonna use OProcess to run this thing |
287 | proc = new OProcess(); | 287 | proc = new OProcess(); |
288 | aborted = false; | 288 | aborted = false; |
289 | 289 | ||
290 | 290 | ||
291 | // Connect up our slots | 291 | // Connect up our slots |
292 | connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)), | 292 | connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)), |
293 | this, SLOT( processFinished())); | 293 | this, SLOT( processFinished())); |
294 | 294 | ||
295 | connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), | 295 | connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), |
296 | this, SLOT(commandStdout(OProcess*,char*,int))); | 296 | this, SLOT(commandStdout(Opie::Core::OProcess*,char*,int))); |
297 | 297 | ||
298 | connect(proc, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), | 298 | connect(proc, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), |
299 | this, SLOT(commandStderr(OProcess*,char*,int))); | 299 | this, SLOT(commandStderr(Opie::Core::OProcess*,char*,int))); |
300 | 300 | ||
301 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) | 301 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) |
302 | { | 302 | { |
303 | *proc << (*it).latin1(); | 303 | *proc << (*it).latin1(); |
304 | } | 304 | } |
305 | 305 | ||
306 | // Start the process going | 306 | // Start the process going |
307 | finished = false; | 307 | finished = false; |
308 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) | 308 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) |
309 | { | 309 | { |
310 | emit outputText( tr("Couldn't start ipkg process" ) ); | 310 | emit outputText( tr("Couldn't start ipkg process" ) ); |
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) | 314 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) |
315 | { | 315 | { |
316 | QString lineStr = buffer; | 316 | QString lineStr = buffer; |
317 | if ( lineStr[buflen-1] == '\n' ) | 317 | if ( lineStr[buflen-1] == '\n' ) |
318 | buflen --; | 318 | buflen --; |
319 | lineStr = lineStr.left( buflen ); | 319 | lineStr = lineStr.left( buflen ); |
320 | emit outputText( lineStr ); | 320 | emit outputText( lineStr ); |
321 | 321 | ||
322 | // check if we are installing dependant packages | 322 | // check if we are installing dependant packages |
323 | if ( option == "install" || option == "reinstall" ) | 323 | if ( option == "install" || option == "reinstall" ) |
324 | { | 324 | { |
325 | // Need to keep track of any dependant packages that get installed | 325 | // Need to keep track of any dependant packages that get installed |
326 | // so that we can create links to them as necessary | 326 | // so that we can create links to them as necessary |
327 | if ( lineStr.startsWith( "Installing " ) ) | 327 | if ( lineStr.startsWith( "Installing " ) ) |
328 | { | 328 | { |
329 | int start = lineStr.find( " " ) + 1; | 329 | int start = lineStr.find( " " ) + 1; |
330 | int end = lineStr.find( " ", start ); | 330 | int end = lineStr.find( " ", start ); |
331 | QString *package = new QString( lineStr.mid( start, end-start ) ); | 331 | QString *package = new QString( lineStr.mid( start, end-start ) ); |
332 | dependantPackages->append( package ); | 332 | dependantPackages->append( package ); |
333 | } | 333 | } |
334 | } | 334 | } |
335 | else if ( option == "remove" && !( flags & FORCE_DEPENDS ) && | 335 | else if ( option == "remove" && !( flags & FORCE_DEPENDS ) && |
336 | lineStr.find( "is depended upon by packages:" ) != -1 ) | 336 | lineStr.find( "is depended upon by packages:" ) != -1 ) |
337 | { | 337 | { |
338 | // Ipkg should send this to STDERR, but doesn't - so trap here | 338 | // Ipkg should send this to STDERR, but doesn't - so trap here |
339 | error = true; | 339 | error = true; |
340 | } | 340 | } |
341 | 341 | ||
342 | buffer[0] = '\0'; | 342 | buffer[0] = '\0'; |
343 | } | 343 | } |
344 | 344 | ||
345 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) | 345 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) |
346 | { | 346 | { |
347 | QString lineStr = buffer; | 347 | QString lineStr = buffer; |
348 | if ( lineStr[buflen-1] == '\n' ) | 348 | if ( lineStr[buflen-1] == '\n' ) |
349 | buflen --; | 349 | buflen --; |
350 | lineStr=lineStr.left( buflen ); | 350 | lineStr=lineStr.left( buflen ); |
351 | emit outputText( lineStr ); | 351 | emit outputText( lineStr ); |
352 | buffer[0] = '\0'; | 352 | buffer[0] = '\0'; |
353 | error = true; | 353 | error = true; |
354 | } | 354 | } |
355 | 355 | ||
356 | void Ipkg::processFinished() | 356 | void Ipkg::processFinished() |
357 | { | 357 | { |
358 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file | 358 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file |
359 | // to workaround an ipkg bug which stops reinstall to a different location | 359 | // to workaround an ipkg bug which stops reinstall to a different location |
360 | 360 | ||
361 | if ( !error && option == "remove" ) | 361 | if ( !error && option == "remove" ) |
362 | removeStatusEntry(); | 362 | removeStatusEntry(); |
363 | 363 | ||
364 | delete proc; | 364 | delete proc; |
365 | proc = 0; | 365 | proc = 0; |
366 | finished = true; | 366 | finished = true; |
367 | 367 | ||
368 | emit ipkgFinished(); | 368 | emit ipkgFinished(); |
369 | } | 369 | } |
370 | 370 | ||
371 | 371 | ||
372 | void Ipkg :: abort() | 372 | void Ipkg :: abort() |
373 | { | 373 | { |
374 | if ( proc ) | 374 | if ( proc ) |
375 | { | 375 | { |
376 | proc->kill(); | 376 | proc->kill(); |
377 | aborted = true; | 377 | aborted = true; |
378 | } | 378 | } |
379 | } | 379 | } |
380 | 380 | ||
381 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) | 381 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) |
382 | { | 382 | { |
383 | if ( dest == "root" || dest == "/" ) | 383 | if ( dest == "root" || dest == "/" ) |
384 | return; | 384 | return; |
385 | 385 | ||
386 | qApp->processEvents(); | 386 | qApp->processEvents(); |
387 | QStringList *fileList = getList( packFileName, destDir ); | 387 | QStringList *fileList = getList( packFileName, destDir ); |
388 | qApp->processEvents(); | 388 | qApp->processEvents(); |
389 | processFileList( fileList, destDir ); | 389 | processFileList( fileList, destDir ); |
390 | delete fileList; | 390 | delete fileList; |
391 | } | 391 | } |
392 | 392 | ||
393 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) | 393 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) |
394 | { | 394 | { |
395 | QString packageFileDir = destDir; | 395 | QString packageFileDir = destDir; |
396 | packageFileDir.append( "/usr/lib/ipkg/info/" ); | 396 | packageFileDir.append( "/usr/lib/ipkg/info/" ); |
397 | packageFileDir.append( packageFilename ); | 397 | packageFileDir.append( packageFilename ); |
398 | packageFileDir.append( ".list" ); | 398 | packageFileDir.append( ".list" ); |
399 | QFile f( packageFileDir ); | 399 | QFile f( packageFileDir ); |
400 | 400 | ||
401 | if ( !f.open(IO_ReadOnly) ) | 401 | if ( !f.open(IO_ReadOnly) ) |
402 | { | 402 | { |
403 | // Couldn't open from dest, try from / | 403 | // Couldn't open from dest, try from / |
404 | f.close(); | 404 | f.close(); |
405 | 405 | ||
406 | packageFileDir = "/usr/lib/ipkg/info/"; | 406 | packageFileDir = "/usr/lib/ipkg/info/"; |
407 | packageFileDir.append( packageFilename ); | 407 | packageFileDir.append( packageFilename ); |
408 | packageFileDir.append( ".list" ); | 408 | packageFileDir.append( ".list" ); |
409 | f.setName( packageFileDir ); | 409 | f.setName( packageFileDir ); |
410 | if ( ! f.open(IO_ReadOnly) ) | 410 | if ( ! f.open(IO_ReadOnly) ) |
411 | { | 411 | { |
412 | QString tempstr = tr("Could not open :"); | 412 | QString tempstr = tr("Could not open :"); |
413 | tempstr.append( packageFileDir ); | 413 | tempstr.append( packageFileDir ); |
414 | emit outputText( tempstr ); | 414 | emit outputText( tempstr ); |
415 | return (QStringList*)0; | 415 | return (QStringList*)0; |
416 | } | 416 | } |
417 | } | 417 | } |
418 | QStringList *fileList = new QStringList(); | 418 | QStringList *fileList = new QStringList(); |
419 | QTextStream t( &f ); | 419 | QTextStream t( &f ); |
420 | while ( !t.eof() ) | 420 | while ( !t.eof() ) |
421 | *fileList += t.readLine(); | 421 | *fileList += t.readLine(); |
422 | 422 | ||
423 | f.close(); | 423 | f.close(); |
424 | return fileList; | 424 | return fileList; |
425 | } | 425 | } |
426 | 426 | ||
427 | void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) | 427 | void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) |
428 | { | 428 | { |
429 | if ( !fileList || fileList->isEmpty() ) | 429 | if ( !fileList || fileList->isEmpty() ) |
430 | return; | 430 | return; |
431 | 431 | ||
432 | QString baseDir = ROOT; | 432 | QString baseDir = ROOT; |
433 | 433 | ||
434 | if ( createLinks == true ) | 434 | if ( createLinks == true ) |
435 | { | 435 | { |
436 | for ( uint i=0; i < fileList->count(); i++ ) | 436 | for ( uint i=0; i < fileList->count(); i++ ) |
437 | { | 437 | { |
438 | processLinkDir( (*fileList)[i], baseDir, destDir ); | 438 | processLinkDir( (*fileList)[i], baseDir, destDir ); |
439 | qApp->processEvents(); | 439 | qApp->processEvents(); |
440 | } | 440 | } |
441 | } | 441 | } |
442 | else | 442 | else |
443 | { | 443 | { |
444 | for ( int i = fileList->count()-1; i >= 0 ; i-- ) | 444 | for ( int i = fileList->count()-1; i >= 0 ; i-- ) |
445 | { | 445 | { |
446 | processLinkDir( (*fileList)[i], baseDir, destDir ); | 446 | processLinkDir( (*fileList)[i], baseDir, destDir ); |
447 | qApp->processEvents(); | 447 | qApp->processEvents(); |
448 | } | 448 | } |
449 | } | 449 | } |
450 | } | 450 | } |
451 | 451 | ||
452 | void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) | 452 | void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) |
453 | { | 453 | { |
454 | 454 | ||
455 | QString sourceFile = baseDir; | 455 | QString sourceFile = baseDir; |
456 | sourceFile.append( file ); | 456 | sourceFile.append( file ); |
457 | 457 | ||
458 | QString linkFile = destDir; | 458 | QString linkFile = destDir; |
459 | if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) | 459 | if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) |
460 | { | 460 | { |
461 | linkFile.append( file.mid( 1 ) ); | 461 | linkFile.append( file.mid( 1 ) ); |
462 | } | 462 | } |
463 | else | 463 | else |
464 | { | 464 | { |
465 | linkFile.append( file ); | 465 | linkFile.append( file ); |
466 | } | 466 | } |
467 | QString text; | 467 | QString text; |
468 | if ( createLinks ) | 468 | if ( createLinks ) |
469 | { | 469 | { |
470 | // If this file is a directory (ends with a /) and it doesn't exist, | 470 | // If this file is a directory (ends with a /) and it doesn't exist, |
471 | // we need to create it | 471 | // we need to create it |
472 | if ( file.right(1) == "/" ) | 472 | if ( file.right(1) == "/" ) |
473 | { | 473 | { |
474 | QFileInfo f( linkFile ); | 474 | QFileInfo f( linkFile ); |
475 | if ( !f.exists() ) | 475 | if ( !f.exists() ) |
476 | { | 476 | { |
477 | QString tempstr = tr("Creating directory "); | 477 | QString tempstr = tr("Creating directory "); |
478 | tempstr.append( linkFile ); | 478 | tempstr.append( linkFile ); |
479 | emit outputText( tempstr ); | 479 | emit outputText( tempstr ); |
480 | QDir d; | 480 | QDir d; |
481 | d.mkdir( linkFile, true ); | 481 | d.mkdir( linkFile, true ); |
482 | } | 482 | } |
483 | // else | 483 | // else |
484 | // emit outputText( QString( "Directory " ) + linkFile + " already exists" ); | 484 | // emit outputText( QString( "Directory " ) + linkFile + " already exists" ); |
485 | 485 | ||
486 | } | 486 | } |
487 | else | 487 | else |
488 | { | 488 | { |
489 | int rc = symlink( sourceFile, linkFile ); | 489 | int rc = symlink( sourceFile, linkFile ); |
490 | text = ( rc == 0 ? tr( "Linked %1 to %2" ) : tr( "Failed to link %1 to %2" ) ). | 490 | text = ( rc == 0 ? tr( "Linked %1 to %2" ) : tr( "Failed to link %1 to %2" ) ). |
491 | arg( sourceFile ). | 491 | arg( sourceFile ). |
492 | arg( linkFile ); | 492 | arg( linkFile ); |
493 | emit outputText( text ); | 493 | emit outputText( text ); |
494 | } | 494 | } |
495 | } | 495 | } |
496 | else | 496 | else |
497 | { | 497 | { |
498 | QFileInfo f( linkFile ); | 498 | QFileInfo f( linkFile ); |
499 | if ( f.exists() ) | 499 | if ( f.exists() ) |
500 | { | 500 | { |
501 | if ( f.isFile() ) | 501 | if ( f.isFile() ) |
502 | { | 502 | { |
503 | QFile f( linkFile ); | 503 | QFile f( linkFile ); |
504 | bool rc = f.remove(); | 504 | bool rc = f.remove(); |
505 | 505 | ||
506 | text = ( rc ? tr( "Removed %1" ) : tr( "Failed to remove %1" ) ).arg( linkFile ); | 506 | text = ( rc ? tr( "Removed %1" ) : tr( "Failed to remove %1" ) ).arg( linkFile ); |
507 | emit outputText( text ); | 507 | emit outputText( text ); |
508 | } | 508 | } |
509 | else if ( f.isDir() ) | 509 | else if ( f.isDir() ) |
510 | { | 510 | { |
511 | QDir d; | 511 | QDir d; |
512 | bool rc = d.rmdir( linkFile, true ); | 512 | bool rc = d.rmdir( linkFile, true ); |
513 | if ( rc ) | 513 | if ( rc ) |
514 | { | 514 | { |
515 | text = ( rc ? tr( "Removed " ) : tr( "Failed to remove " ) ).arg( linkFile ); | 515 | text = ( rc ? tr( "Removed " ) : tr( "Failed to remove " ) ).arg( linkFile ); |
516 | emit outputText( text ); | 516 | emit outputText( text ); |
517 | } | 517 | } |
518 | } | 518 | } |
519 | } | 519 | } |
520 | } | 520 | } |
521 | } | 521 | } |
diff --git a/noncore/settings/netsystemtime/mainwindow.cpp b/noncore/settings/netsystemtime/mainwindow.cpp index ba96f33..385d355 100644 --- a/noncore/settings/netsystemtime/mainwindow.cpp +++ b/noncore/settings/netsystemtime/mainwindow.cpp | |||
@@ -1,398 +1,398 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> | 4 | .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "mainwindow.h" | 29 | #include "mainwindow.h" |
30 | #include "timetabwidget.h" | 30 | #include "timetabwidget.h" |
31 | #include "formattabwidget.h" | 31 | #include "formattabwidget.h" |
32 | #include "settingstabwidget.h" | 32 | #include "settingstabwidget.h" |
33 | #include "ntptabwidget.h" | 33 | #include "ntptabwidget.h" |
34 | #include "predicttabwidget.h" | 34 | #include "predicttabwidget.h" |
35 | 35 | ||
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | #include <qpe/datebookdb.h> | 37 | #include <qpe/datebookdb.h> |
38 | #include <qpe/qpeapplication.h> | 38 | #include <qpe/qpeapplication.h> |
39 | #include <qpe/qpedialog.h> | 39 | #include <qpe/qpedialog.h> |
40 | 40 | ||
41 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 41 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
42 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #include <qlayout.h> | 45 | #include <qlayout.h> |
46 | #include <qmessagebox.h> | 46 | #include <qmessagebox.h> |
47 | #include <qsocket.h> | 47 | #include <qsocket.h> |
48 | #include <qstring.h> | 48 | #include <qstring.h> |
49 | #include <qtimer.h> | 49 | #include <qtimer.h> |
50 | 50 | ||
51 | using namespace Opie::Ui; | 51 | using namespace Opie::Ui; |
52 | using namespace Opie::Core; | 52 | using namespace Opie::Core; |
53 | MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags f ) | 53 | MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags f ) |
54 | : QDialog( 0x0, 0x0, TRUE, 0 ) | 54 | : QDialog( 0x0, 0x0, TRUE, 0 ) |
55 | { | 55 | { |
56 | setCaption( tr( "SystemTime" ) ); | 56 | setCaption( tr( "SystemTime" ) ); |
57 | 57 | ||
58 | QVBoxLayout *layout = new QVBoxLayout( this ); | 58 | QVBoxLayout *layout = new QVBoxLayout( this ); |
59 | layout->setMargin( 2 ); | 59 | layout->setMargin( 2 ); |
60 | layout->setSpacing( 4 ); | 60 | layout->setSpacing( 4 ); |
61 | 61 | ||
62 | // Create main tabbed control | 62 | // Create main tabbed control |
63 | mainWidget = new OTabWidget( this ); | 63 | mainWidget = new OTabWidget( this ); |
64 | 64 | ||
65 | // Default object pointers to null | 65 | // Default object pointers to null |
66 | ntpProcess = 0x0; | 66 | ntpProcess = 0x0; |
67 | ntpTab = 0x0; | 67 | ntpTab = 0x0; |
68 | 68 | ||
69 | // Add tab widgets | 69 | // Add tab widgets |
70 | mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) ); | 70 | mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) ); |
71 | mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) ); | 71 | mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) ); |
72 | mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) ); | 72 | mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) ); |
73 | mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) ); | 73 | mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) ); |
74 | Config config( "ntp" ); | 74 | Config config( "ntp" ); |
75 | config.setGroup( "settings" ); | 75 | config.setGroup( "settings" ); |
76 | slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", FALSE ) ); | 76 | slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", FALSE ) ); |
77 | slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", FALSE ) ); | 77 | slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", FALSE ) ); |
78 | 78 | ||
79 | mainWidget->setCurrentTab( tr( "Time" ) ); | 79 | mainWidget->setCurrentTab( tr( "Time" ) ); |
80 | layout->addWidget( mainWidget ); | 80 | layout->addWidget( mainWidget ); |
81 | 81 | ||
82 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), | 82 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
83 | this, SLOT(slotQCopReceive(const QCString&,const QByteArray&)) ); | 83 | this, SLOT(slotQCopReceive(const QCString&,const QByteArray&)) ); |
84 | 84 | ||
85 | 85 | ||
86 | // Create NTP socket | 86 | // Create NTP socket |
87 | ntpSock = new QSocket( this ); | 87 | ntpSock = new QSocket( this ); |
88 | connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) ); | 88 | connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) ); |
89 | slotProbeNTPServer(); | 89 | slotProbeNTPServer(); |
90 | 90 | ||
91 | // Create timer for automatic time lookups | 91 | // Create timer for automatic time lookups |
92 | ntpTimer = new QTimer( this ); | 92 | ntpTimer = new QTimer( this ); |
93 | 93 | ||
94 | // Connect everything together | 94 | // Connect everything together |
95 | connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); | 95 | connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); |
96 | connect( timeTab, SIGNAL(tzChanged(const QString&)), predictTab, SLOT(slotTZChanged(const QString&)) ); | 96 | connect( timeTab, SIGNAL(tzChanged(const QString&)), predictTab, SLOT(slotTZChanged(const QString&)) ); |
97 | connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) ); | 97 | connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) ); |
98 | connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime(int)) ); | 98 | connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime(int)) ); |
99 | connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat&)), | 99 | connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat&)), |
100 | timeTab, SLOT(slotDateFormatChanged(const DateFormat&)) ); | 100 | timeTab, SLOT(slotDateFormatChanged(const DateFormat&)) ); |
101 | connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) ); | 101 | connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) ); |
102 | connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) ); | 102 | connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) ); |
103 | connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) ); | 103 | connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) ); |
104 | connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) ); | 104 | connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) ); |
105 | connect( predictTab, SIGNAL(setTime(const QDateTime&)), this, SLOT(slotSetTime(const QDateTime&)) ); | 105 | connect( predictTab, SIGNAL(setTime(const QDateTime&)), this, SLOT(slotSetTime(const QDateTime&)) ); |
106 | 106 | ||
107 | // Do initial time server check | 107 | // Do initial time server check |
108 | slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) ); | 108 | slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) ); |
109 | slotCheckNtp( -1 ); | 109 | slotCheckNtp( -1 ); |
110 | 110 | ||
111 | // Display app | 111 | // Display app |
112 | //showMaximized(); | 112 | //showMaximized(); |
113 | (void)new QPEDialogListener(this); | 113 | (void)new QPEDialogListener(this); |
114 | } | 114 | } |
115 | 115 | ||
116 | MainWindow::~MainWindow() | 116 | MainWindow::~MainWindow() |
117 | { | 117 | { |
118 | if ( ntpProcess ) | 118 | if ( ntpProcess ) |
119 | delete ntpProcess; | 119 | delete ntpProcess; |
120 | } | 120 | } |
121 | 121 | ||
122 | void MainWindow::accept() | 122 | void MainWindow::accept() |
123 | { | 123 | { |
124 | // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends) | 124 | // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends) |
125 | { | 125 | { |
126 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 126 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
127 | disableScreenSaver << 0 << 0 << 0; | 127 | disableScreenSaver << 0 << 0 << 0; |
128 | } | 128 | } |
129 | 129 | ||
130 | // Update the systemtime | 130 | // Update the systemtime |
131 | timeTab->saveSettings( TRUE ); | 131 | timeTab->saveSettings( TRUE ); |
132 | 132 | ||
133 | // Save format options | 133 | // Save format options |
134 | formatTab->saveSettings( TRUE ); | 134 | formatTab->saveSettings( TRUE ); |
135 | 135 | ||
136 | // Save settings options | 136 | // Save settings options |
137 | settingsTab->saveSettings(); | 137 | settingsTab->saveSettings(); |
138 | 138 | ||
139 | // Since time has changed quickly load in the DateBookDB to allow the alarm server to get a better | 139 | // Since time has changed quickly load in the DateBookDB to allow the alarm server to get a better |
140 | // grip on itself (example re-trigger alarms for when we travel back in time). | 140 | // grip on itself (example re-trigger alarms for when we travel back in time). |
141 | DateBookDB db; | 141 | DateBookDB db; |
142 | 142 | ||
143 | // Turn back on the screensaver | 143 | // Turn back on the screensaver |
144 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 144 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
145 | enableScreenSaver << -1 << -1 << -1; | 145 | enableScreenSaver << -1 << -1 << -1; |
146 | 146 | ||
147 | // Exit app | 147 | // Exit app |
148 | qApp->quit(); | 148 | qApp->quit(); |
149 | } | 149 | } |
150 | 150 | ||
151 | void MainWindow::reject() | 151 | void MainWindow::reject() |
152 | { | 152 | { |
153 | // Reset time settings | 153 | // Reset time settings |
154 | timeTab->saveSettings( FALSE ); | 154 | timeTab->saveSettings( FALSE ); |
155 | 155 | ||
156 | // Send notifications but do not save settings | 156 | // Send notifications but do not save settings |
157 | formatTab->saveSettings( FALSE ); | 157 | formatTab->saveSettings( FALSE ); |
158 | 158 | ||
159 | // Exit app | 159 | // Exit app |
160 | qApp->quit(); | 160 | qApp->quit(); |
161 | } | 161 | } |
162 | 162 | ||
163 | void MainWindow::runNTP() | 163 | void MainWindow::runNTP() |
164 | { | 164 | { |
165 | if ( !ntpDelayElapsed() && ntpInteractive ) | 165 | if ( !ntpDelayElapsed() && ntpInteractive ) |
166 | { | 166 | { |
167 | QString msg = tr( "You asked for a delay of %1 minutes, but only %2 minutes elapsed since last lookup.<br>Continue?" ).arg( QString::number( ntpDelay ) ).arg( QString::number( _lookupDiff / 60 ) ); | 167 | QString msg = tr( "You asked for a delay of %1 minutes, but only %2 minutes elapsed since last lookup.<br>Continue?" ).arg( QString::number( ntpDelay ) ).arg( QString::number( _lookupDiff / 60 ) ); |
168 | 168 | ||
169 | switch ( | 169 | switch ( |
170 | QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No ) | 170 | QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No ) |
171 | ) | 171 | ) |
172 | { | 172 | { |
173 | case QMessageBox::Yes: break; | 173 | case QMessageBox::Yes: break; |
174 | case QMessageBox::No: return; | 174 | case QMessageBox::No: return; |
175 | default: return; | 175 | default: return; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | QString srv = settingsTab->ntpServer(); | 179 | QString srv = settingsTab->ntpServer(); |
180 | 180 | ||
181 | // Send information to time server tab if enabled | 181 | // Send information to time server tab if enabled |
182 | if ( ntpTabEnabled ) | 182 | if ( ntpTabEnabled ) |
183 | { | 183 | { |
184 | ntpTab->setStartTime( QDateTime::currentDateTime().toString() ); | 184 | ntpTab->setStartTime( QDateTime::currentDateTime().toString() ); |
185 | QString output = tr( "Running:\nntpdate " ); | 185 | QString output = tr( "Running:\nntpdate " ); |
186 | output.append( srv ); | 186 | output.append( srv ); |
187 | ntpTab->addNtpOutput( output ); | 187 | ntpTab->addNtpOutput( output ); |
188 | } | 188 | } |
189 | 189 | ||
190 | if ( !ntpProcess ) | 190 | if ( !ntpProcess ) |
191 | { | 191 | { |
192 | ntpProcess = new OProcess(); | 192 | ntpProcess = new OProcess(); |
193 | connect( ntpProcess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), | 193 | connect( ntpProcess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), |
194 | this, SLOT(slotNtpOutput(OProcess*,char*,int)) ); | 194 | this, SLOT(slotNtpOutput(Opie::Core::OProcess*,char*,int)) ); |
195 | connect( ntpProcess, SIGNAL(processExited(Opie::Core::OProcess*)), | 195 | connect( ntpProcess, SIGNAL(processExited(Opie::Core::OProcess*)), |
196 | this, SLOT(slotNtpFinished(OProcess*)) ); | 196 | this, SLOT(slotNtpFinished(Opie::Core::OProcess*)) ); |
197 | } | 197 | } |
198 | 198 | ||
199 | else | 199 | else |
200 | ntpProcess->clearArguments(); | 200 | ntpProcess->clearArguments(); |
201 | 201 | ||
202 | *ntpProcess << "ntpdate" << srv; | 202 | *ntpProcess << "ntpdate" << srv; |
203 | bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput ); | 203 | bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput ); |
204 | if ( !ret ) | 204 | if ( !ret ) |
205 | { | 205 | { |
206 | QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) ); | 206 | QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) ); |
207 | if ( ntpTabEnabled ) | 207 | if ( ntpTabEnabled ) |
208 | ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) ); | 208 | ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) ); |
209 | } | 209 | } |
210 | } | 210 | } |
211 | 211 | ||
212 | bool MainWindow::ntpDelayElapsed() | 212 | bool MainWindow::ntpDelayElapsed() |
213 | { | 213 | { |
214 | // Determine if time elapsed is greater than time delay | 214 | // Determine if time elapsed is greater than time delay |
215 | Config config( "ntp" ); | 215 | Config config( "ntp" ); |
216 | config.setGroup( "lookups" ); | 216 | config.setGroup( "lookups" ); |
217 | _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 ); | 217 | _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 ); |
218 | if ( _lookupDiff < 0 ) | 218 | if ( _lookupDiff < 0 ) |
219 | return true; | 219 | return true; |
220 | return ( _lookupDiff - ( ntpDelay * 60) ) > 0; | 220 | return ( _lookupDiff - ( ntpDelay * 60) ) > 0; |
221 | } | 221 | } |
222 | 222 | ||
223 | void MainWindow::slotSetTime( const QDateTime &dt ) | 223 | void MainWindow::slotSetTime( const QDateTime &dt ) |
224 | { | 224 | { |
225 | timeTab->setDateTime( dt ); | 225 | timeTab->setDateTime( dt ); |
226 | } | 226 | } |
227 | 227 | ||
228 | void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & ) | 228 | void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & ) |
229 | { | 229 | { |
230 | if ( msg == "ntpLookup(QString)" ) | 230 | if ( msg == "ntpLookup(QString)" ) |
231 | { | 231 | { |
232 | ntpInteractive = false; | 232 | ntpInteractive = false; |
233 | runNTP(); | 233 | runNTP(); |
234 | } | 234 | } |
235 | if ( msg == "setPredictedTime(QString)" ) | 235 | if ( msg == "setPredictedTime(QString)" ) |
236 | { | 236 | { |
237 | //setPredictTime(); | 237 | //setPredictTime(); |
238 | } | 238 | } |
239 | } | 239 | } |
240 | 240 | ||
241 | void MainWindow::slotDisplayNTPTab( bool display ) | 241 | void MainWindow::slotDisplayNTPTab( bool display ) |
242 | { | 242 | { |
243 | ntpTabEnabled = display; | 243 | ntpTabEnabled = display; |
244 | 244 | ||
245 | // Create widget if it hasn't needed | 245 | // Create widget if it hasn't needed |
246 | if ( display && !ntpTab ) | 246 | if ( display && !ntpTab ) |
247 | { | 247 | { |
248 | ntpTab = new NTPTabWidget( mainWidget ); | 248 | ntpTab = new NTPTabWidget( mainWidget ); |
249 | connect( ntpTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); | 249 | connect( ntpTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); |
250 | } | 250 | } |
251 | 251 | ||
252 | // Display/hide tab | 252 | // Display/hide tab |
253 | display ? mainWidget->addTab( ntpTab, "netsystemtime/ntptab", tr( "Time Server" ) ) | 253 | display ? mainWidget->addTab( ntpTab, "netsystemtime/ntptab", tr( "Time Server" ) ) |
254 | : mainWidget->removePage( ntpTab ); | 254 | : mainWidget->removePage( ntpTab ); |
255 | } | 255 | } |
256 | 256 | ||
257 | void MainWindow::slotDisplayPredictTab( bool display ) | 257 | void MainWindow::slotDisplayPredictTab( bool display ) |
258 | { | 258 | { |
259 | predictTabEnabled = display; | 259 | predictTabEnabled = display; |
260 | 260 | ||
261 | // Create widget if it hasn't needed | 261 | // Create widget if it hasn't needed |
262 | if ( display && !predictTab ) | 262 | if ( display && !predictTab ) |
263 | { | 263 | { |
264 | } | 264 | } |
265 | // Display/hide tab | 265 | // Display/hide tab |
266 | display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) ) | 266 | display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) ) |
267 | : mainWidget->removePage( predictTab ); | 267 | : mainWidget->removePage( predictTab ); |
268 | } | 268 | } |
269 | 269 | ||
270 | void MainWindow::slotGetNTPTime() | 270 | void MainWindow::slotGetNTPTime() |
271 | { | 271 | { |
272 | ntpInteractive = TRUE; | 272 | ntpInteractive = TRUE; |
273 | runNTP(); | 273 | runNTP(); |
274 | } | 274 | } |
275 | 275 | ||
276 | void MainWindow::slotTimerGetNTPTime() | 276 | void MainWindow::slotTimerGetNTPTime() |
277 | { | 277 | { |
278 | ntpInteractive = FALSE; | 278 | ntpInteractive = FALSE; |
279 | runNTP(); | 279 | runNTP(); |
280 | } | 280 | } |
281 | 281 | ||
282 | void MainWindow::slotProbeNTPServer() | 282 | void MainWindow::slotProbeNTPServer() |
283 | { | 283 | { |
284 | ntpSock->connectToHost( settingsTab->ntpServer(), 123 ); | 284 | ntpSock->connectToHost( settingsTab->ntpServer(), 123 ); |
285 | } | 285 | } |
286 | 286 | ||
287 | void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen ) | 287 | void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen ) |
288 | { | 288 | { |
289 | QString output = QString( buffer ).left( buflen ); | 289 | QString output = QString( buffer ).left( buflen ); |
290 | ntpOutput.append( output ); | 290 | ntpOutput.append( output ); |
291 | 291 | ||
292 | if ( ntpTabEnabled ) | 292 | if ( ntpTabEnabled ) |
293 | ntpTab->addNtpOutput( output ); | 293 | ntpTab->addNtpOutput( output ); |
294 | } | 294 | } |
295 | 295 | ||
296 | void MainWindow::slotNtpFinished( OProcess *p ) | 296 | void MainWindow::slotNtpFinished( OProcess *p ) |
297 | { | 297 | { |
298 | QString output; | 298 | QString output; |
299 | QDateTime dt = QDateTime::currentDateTime(); | 299 | QDateTime dt = QDateTime::currentDateTime(); |
300 | 300 | ||
301 | // Verify run was successful | 301 | // Verify run was successful |
302 | if ( p->exitStatus() != 0 || !p->normalExit() ) | 302 | if ( p->exitStatus() != 0 || !p->normalExit() ) |
303 | { | 303 | { |
304 | if ( isVisible() && ntpInteractive ) | 304 | if ( isVisible() && ntpInteractive ) |
305 | { | 305 | { |
306 | output = tr( "Error while getting time from\n server: " ); | 306 | output = tr( "Error while getting time from\n server: " ); |
307 | output.append( settingsTab->ntpServer() ); | 307 | output.append( settingsTab->ntpServer() ); |
308 | QMessageBox::critical(this, tr( "Error" ), output ); | 308 | QMessageBox::critical(this, tr( "Error" ), output ); |
309 | } | 309 | } |
310 | // slotCheckNtp(-1); | 310 | // slotCheckNtp(-1); |
311 | return; | 311 | return; |
312 | } | 312 | } |
313 | 313 | ||
314 | // Set controls on time tab to new time value | 314 | // Set controls on time tab to new time value |
315 | timeTab->setDateTime( dt ); | 315 | timeTab->setDateTime( dt ); |
316 | 316 | ||
317 | // Write out lookup information | 317 | // Write out lookup information |
318 | Config config( "ntp" ); | 318 | Config config( "ntp" ); |
319 | config.setGroup( "lookups" ); | 319 | config.setGroup( "lookups" ); |
320 | int lastLookup = config.readNumEntry( "time", 0 ); | 320 | int lastLookup = config.readNumEntry( "time", 0 ); |
321 | int lookupCount = config.readNumEntry( "count", 0 ); | 321 | int lookupCount = config.readNumEntry( "count", 0 ); |
322 | bool lastNtp = config.readBoolEntry( "lastNtp", FALSE ); | 322 | bool lastNtp = config.readBoolEntry( "lastNtp", FALSE ); |
323 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 323 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
324 | config.writeEntry( "time", time ); | 324 | config.writeEntry( "time", time ); |
325 | 325 | ||
326 | // Calculate new time/time shift | 326 | // Calculate new time/time shift |
327 | QString _offset = "offset"; | 327 | QString _offset = "offset"; |
328 | QString _sec = "sec"; | 328 | QString _sec = "sec"; |
329 | QRegExp _reOffset = QRegExp( _offset ); | 329 | QRegExp _reOffset = QRegExp( _offset ); |
330 | QRegExp _reEndOffset = QRegExp( _sec ); | 330 | QRegExp _reEndOffset = QRegExp( _sec ); |
331 | int posOffset = _reOffset.match( ntpOutput ); | 331 | int posOffset = _reOffset.match( ntpOutput ); |
332 | int posEndOffset = _reEndOffset.match( ntpOutput, posOffset ); | 332 | int posEndOffset = _reEndOffset.match( ntpOutput, posOffset ); |
333 | posOffset += _offset.length() + 1; | 333 | posOffset += _offset.length() + 1; |
334 | QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 ); | 334 | QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 ); |
335 | 335 | ||
336 | float timeShift = diff.toFloat(); | 336 | float timeShift = diff.toFloat(); |
337 | if ( timeShift == 0.0 ) | 337 | if ( timeShift == 0.0 ) |
338 | return; | 338 | return; |
339 | int secsSinceLast = time - lastLookup; | 339 | int secsSinceLast = time - lastLookup; |
340 | output = tr( "%1 seconds").arg(QString::number( timeShift )); | 340 | output = tr( "%1 seconds").arg(QString::number( timeShift )); |
341 | 341 | ||
342 | // Display information on time server tab | 342 | // Display information on time server tab |
343 | if ( ntpTabEnabled ) | 343 | if ( ntpTabEnabled ) |
344 | { | 344 | { |
345 | ntpTab->setTimeShift( output ); | 345 | ntpTab->setTimeShift( output ); |
346 | ntpTab->setNewTime( dt.toString() ); | 346 | ntpTab->setNewTime( dt.toString() ); |
347 | } | 347 | } |
348 | 348 | ||
349 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) | 349 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) |
350 | { | 350 | { |
351 | QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); | 351 | QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); |
352 | config.setGroup( grpname ); | 352 | config.setGroup( grpname ); |
353 | lookupCount++; | 353 | lookupCount++; |
354 | predictTab->setShiftPerSec( timeShift / secsSinceLast ); | 354 | predictTab->setShiftPerSec( timeShift / secsSinceLast ); |
355 | config.writeEntry( "secsSinceLast", secsSinceLast ); | 355 | config.writeEntry( "secsSinceLast", secsSinceLast ); |
356 | config.writeEntry( "timeShift", QString::number( timeShift ) ); | 356 | config.writeEntry( "timeShift", QString::number( timeShift ) ); |
357 | config.setGroup( "lookups" ); | 357 | config.setGroup( "lookups" ); |
358 | config.writeEntry( "count", lookupCount ); | 358 | config.writeEntry( "count", lookupCount ); |
359 | config.writeEntry( "lastNtp", TRUE ); | 359 | config.writeEntry( "lastNtp", TRUE ); |
360 | } | 360 | } |
361 | } | 361 | } |
362 | 362 | ||
363 | void MainWindow::slotNTPDelayChanged( int delay ) | 363 | void MainWindow::slotNTPDelayChanged( int delay ) |
364 | { | 364 | { |
365 | ntpTimer->changeInterval( delay * 1000 * 60 ); | 365 | ntpTimer->changeInterval( delay * 1000 * 60 ); |
366 | ntpDelay = delay; | 366 | ntpDelay = delay; |
367 | } | 367 | } |
368 | 368 | ||
369 | void MainWindow::slotCheckNtp( int i ) | 369 | void MainWindow::slotCheckNtp( int i ) |
370 | { | 370 | { |
371 | if ( i == 0 ) | 371 | if ( i == 0 ) |
372 | { | 372 | { |
373 | if ( ntpDelayElapsed() ) | 373 | if ( ntpDelayElapsed() ) |
374 | { | 374 | { |
375 | runNTP(); | 375 | runNTP(); |
376 | disconnect( ntpTimer, SIGNAL(timeout()), this, SLOT(slotProbeNTPServer()) ); | 376 | disconnect( ntpTimer, SIGNAL(timeout()), this, SLOT(slotProbeNTPServer()) ); |
377 | connect( ntpTimer, SIGNAL(timeout()), SLOT(slotTimerGetNTPTime()) ); | 377 | connect( ntpTimer, SIGNAL(timeout()), SLOT(slotTimerGetNTPTime()) ); |
378 | } | 378 | } |
379 | else | 379 | else |
380 | { | 380 | { |
381 | disconnect(ntpTimer, SIGNAL(timeout()), this, SLOT(slotTimerGetNTPTime()) ); | 381 | disconnect(ntpTimer, SIGNAL(timeout()), this, SLOT(slotTimerGetNTPTime()) ); |
382 | connect(ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) ); | 382 | connect(ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) ); |
383 | } | 383 | } |
384 | } | 384 | } |
385 | else | 385 | else |
386 | { | 386 | { |
387 | predictTab->slotPredictTime(); | 387 | predictTab->slotPredictTime(); |
388 | if ( i > 0 ) | 388 | if ( i > 0 ) |
389 | { | 389 | { |
390 | QString output = tr( "Could not connect to server " ); | 390 | QString output = tr( "Could not connect to server " ); |
391 | output.append( settingsTab->ntpServer() ); | 391 | output.append( settingsTab->ntpServer() ); |
392 | ntpOutput.append( output ); | 392 | ntpOutput.append( output ); |
393 | if ( ntpTabEnabled ) | 393 | if ( ntpTabEnabled ) |
394 | ntpTab->addNtpOutput( output ); | 394 | ntpTab->addNtpOutput( output ); |
395 | } | 395 | } |
396 | connect( ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) ); | 396 | connect( ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) ); |
397 | } | 397 | } |
398 | } | 398 | } |
diff --git a/noncore/settings/sshkeys/sshkeys.cpp b/noncore/settings/sshkeys/sshkeys.cpp index 31f6b85..cebc845 100644 --- a/noncore/settings/sshkeys/sshkeys.cpp +++ b/noncore/settings/sshkeys/sshkeys.cpp | |||
@@ -1,294 +1,294 @@ | |||
1 | /* | 1 | /* |
2 | * ssh-agent key manipulation utility | 2 | * ssh-agent key manipulation utility |
3 | * | 3 | * |
4 | * (C) 2002 David Woodhouse <dwmw2@infradead.org> | 4 | * (C) 2002 David Woodhouse <dwmw2@infradead.org> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | * | 10 | * |
11 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU General Public License | 16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | * | 19 | * |
20 | */ | 20 | */ |
21 | #include "sshkeys.h" | 21 | #include "sshkeys.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | #include <qmultilineedit.h> | 24 | #include <qmultilineedit.h> |
25 | #include <qpushbutton.h> | 25 | #include <qpushbutton.h> |
26 | #include <qlistview.h> | 26 | #include <qlistview.h> |
27 | #include <qcombobox.h> | 27 | #include <qcombobox.h> |
28 | 28 | ||
29 | #include <sys/types.h> | 29 | #include <sys/types.h> |
30 | #include <sys/stat.h> | 30 | #include <sys/stat.h> |
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #include <stdio.h> | 33 | #include <stdio.h> |
34 | #include <ctype.h> | 34 | #include <ctype.h> |
35 | 35 | ||
36 | using namespace Opie::Core; | 36 | using namespace Opie::Core; |
37 | static char *keynames[] = { "identity", "id_rsa", "id_dsa" }; | 37 | static char *keynames[] = { "identity", "id_rsa", "id_dsa" }; |
38 | 38 | ||
39 | SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl ) | 39 | SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl ) |
40 | : SSHKeysBase( parent, name, fl ) | 40 | : SSHKeysBase( parent, name, fl ) |
41 | { | 41 | { |
42 | char *home = getenv("HOME"); | 42 | char *home = getenv("HOME"); |
43 | unsigned i; | 43 | unsigned i; |
44 | 44 | ||
45 | connect(AddButton, SIGNAL(clicked()), this, SLOT(doAddButton())); | 45 | connect(AddButton, SIGNAL(clicked()), this, SLOT(doAddButton())); |
46 | connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton())); | 46 | connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton())); |
47 | connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton())); | 47 | connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton())); |
48 | 48 | ||
49 | connect(&addprocess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), | 49 | connect(&addprocess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), |
50 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 50 | this, SLOT(log_sshadd_output(Opie::Core::OProcess*,char*,int))); |
51 | connect(&addprocess, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), | 51 | connect(&addprocess, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), |
52 | this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); | 52 | this, SLOT(log_sshadd_stderr(Opie::Core::OProcess*,char*,int))); |
53 | connect(&addprocess, SIGNAL(processExited(Opie::Core::OProcess*)), | 53 | connect(&addprocess, SIGNAL(processExited(Opie::Core::OProcess*)), |
54 | this, SLOT(ssh_add_exited(OProcess*))); | 54 | this, SLOT(ssh_add_exited(Opie::Core::OProcess*))); |
55 | 55 | ||
56 | connect(KeyFileName, SIGNAL(textChanged(const QString&)), | 56 | connect(KeyFileName, SIGNAL(textChanged(const QString&)), |
57 | this, SLOT(add_text_changed(const QString&))); | 57 | this, SLOT(add_text_changed(const QString&))); |
58 | 58 | ||
59 | if (home) { | 59 | if (home) { |
60 | for (i = 0; i < sizeof(keynames)/sizeof(keynames[0]); i++) { | 60 | for (i = 0; i < sizeof(keynames)/sizeof(keynames[0]); i++) { |
61 | char thiskeyname[32]; | 61 | char thiskeyname[32]; |
62 | 62 | ||
63 | thiskeyname[31] = 0; | 63 | thiskeyname[31] = 0; |
64 | snprintf(thiskeyname, 31, "%s/.ssh/%s", home, keynames[i]); | 64 | snprintf(thiskeyname, 31, "%s/.ssh/%s", home, keynames[i]); |
65 | if (!access(thiskeyname, R_OK)) { | 65 | if (!access(thiskeyname, R_OK)) { |
66 | KeyFileName->insertItem(thiskeyname); | 66 | KeyFileName->insertItem(thiskeyname); |
67 | } | 67 | } |
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | doRefreshListButton(); | 71 | doRefreshListButton(); |
72 | } | 72 | } |
73 | 73 | ||
74 | SSHKeysApp::~SSHKeysApp() | 74 | SSHKeysApp::~SSHKeysApp() |
75 | { | 75 | { |
76 | } | 76 | } |
77 | 77 | ||
78 | void SSHKeysApp::doRefreshListButton() | 78 | void SSHKeysApp::doRefreshListButton() |
79 | { | 79 | { |
80 | OProcess sshadd_process; | 80 | OProcess sshadd_process; |
81 | QListViewItem *t = KeyList->firstChild(); | 81 | QListViewItem *t = KeyList->firstChild(); |
82 | 82 | ||
83 | while(t) { | 83 | while(t) { |
84 | QListViewItem *next = t->nextSibling(); | 84 | QListViewItem *next = t->nextSibling(); |
85 | KeyList->takeItem(t); | 85 | KeyList->takeItem(t); |
86 | delete(t); | 86 | delete(t); |
87 | t = next; | 87 | t = next; |
88 | } | 88 | } |
89 | 89 | ||
90 | connect(&sshadd_process, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), | 90 | connect(&sshadd_process, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), |
91 | this, SLOT(get_list_keys_output(OProcess*,char*,int))); | 91 | this, SLOT(get_list_keys_output(Opie::Core::OProcess*,char*,int))); |
92 | connect(&sshadd_process, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), | 92 | connect(&sshadd_process, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), |
93 | this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); | 93 | this, SLOT(log_sshadd_stderr(Opie::Core::OProcess*,char*,int))); |
94 | 94 | ||
95 | keystate = KeySize; | 95 | keystate = KeySize; |
96 | incoming_keyname=""; | 96 | incoming_keyname=""; |
97 | incoming_keysize=""; | 97 | incoming_keysize=""; |
98 | incoming_keyfingerprint=""; | 98 | incoming_keyfingerprint=""; |
99 | 99 | ||
100 | // log_text("Running ssh-add -l"); | 100 | // log_text("Running ssh-add -l"); |
101 | sshadd_process << "ssh-add" << "-l"; | 101 | sshadd_process << "ssh-add" << "-l"; |
102 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); | 102 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); |
103 | if (!ret) { | 103 | if (!ret) { |
104 | log_text(tr("Error running ssh-add")); | 104 | log_text(tr("Error running ssh-add")); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | flush_sshadd_output(); | 107 | flush_sshadd_output(); |
108 | if (sshadd_process.exitStatus() == 2) { | 108 | if (sshadd_process.exitStatus() == 2) { |
109 | setEnabled(FALSE); | 109 | setEnabled(FALSE); |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) | 113 | void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) |
114 | { | 114 | { |
115 | int i; | 115 | int i; |
116 | (void) proc; | 116 | (void) proc; |
117 | 117 | ||
118 | for (i=0; i<buflen; i++) { | 118 | for (i=0; i<buflen; i++) { |
119 | switch(keystate) { | 119 | switch(keystate) { |
120 | case Noise: | 120 | case Noise: |
121 | noise: | 121 | noise: |
122 | if (buffer[i] == '\n') { | 122 | if (buffer[i] == '\n') { |
123 | log_text(incoming_noise.local8Bit()); | 123 | log_text(incoming_noise.local8Bit()); |
124 | incoming_noise = ""; | 124 | incoming_noise = ""; |
125 | keystate = KeySize; | 125 | keystate = KeySize; |
126 | } else { | 126 | } else { |
127 | incoming_noise += buffer[i]; | 127 | incoming_noise += buffer[i]; |
128 | } | 128 | } |
129 | break; | 129 | break; |
130 | 130 | ||
131 | case KeySize: | 131 | case KeySize: |
132 | if (isdigit(buffer[i])) { | 132 | if (isdigit(buffer[i])) { |
133 | incoming_keysize += buffer[i]; | 133 | incoming_keysize += buffer[i]; |
134 | } else if (buffer[i] == ' ') { | 134 | } else if (buffer[i] == ' ') { |
135 | keystate = KeyFingerprint; | 135 | keystate = KeyFingerprint; |
136 | } else { | 136 | } else { |
137 | incoming_keysize = ""; | 137 | incoming_keysize = ""; |
138 | incoming_noise = ""; | 138 | incoming_noise = ""; |
139 | keystate = Noise; | 139 | keystate = Noise; |
140 | goto noise; | 140 | goto noise; |
141 | } | 141 | } |
142 | break; | 142 | break; |
143 | 143 | ||
144 | case KeyFingerprint: | 144 | case KeyFingerprint: |
145 | if (isxdigit(buffer[i]) || buffer[i] == ':') { | 145 | if (isxdigit(buffer[i]) || buffer[i] == ':') { |
146 | incoming_keyfingerprint += buffer[i]; | 146 | incoming_keyfingerprint += buffer[i]; |
147 | } else if (buffer[i] == ' ') { | 147 | } else if (buffer[i] == ' ') { |
148 | keystate = KeyName; | 148 | keystate = KeyName; |
149 | } else { | 149 | } else { |
150 | incoming_keysize = ""; | 150 | incoming_keysize = ""; |
151 | incoming_keyfingerprint = ""; | 151 | incoming_keyfingerprint = ""; |
152 | incoming_noise = ""; | 152 | incoming_noise = ""; |
153 | keystate = Noise; | 153 | keystate = Noise; |
154 | goto noise; | 154 | goto noise; |
155 | } | 155 | } |
156 | break; | 156 | break; |
157 | 157 | ||
158 | case KeyName: | 158 | case KeyName: |
159 | if (buffer[i] == '\n') { | 159 | if (buffer[i] == '\n') { |
160 | /* Wheee. Got one. */ | 160 | /* Wheee. Got one. */ |
161 | KeyList->insertItem(new | 161 | KeyList->insertItem(new |
162 | QListViewItem(KeyList, incoming_keyname, incoming_keysize, incoming_keyfingerprint)); | 162 | QListViewItem(KeyList, incoming_keyname, incoming_keysize, incoming_keyfingerprint)); |
163 | incoming_keysize = ""; | 163 | incoming_keysize = ""; |
164 | incoming_keyfingerprint = ""; | 164 | incoming_keyfingerprint = ""; |
165 | incoming_keyname = ""; | 165 | incoming_keyname = ""; |
166 | keystate = KeySize; | 166 | keystate = KeySize; |
167 | } else if (isprint(buffer[i])) { | 167 | } else if (isprint(buffer[i])) { |
168 | incoming_keyname += buffer[i]; | 168 | incoming_keyname += buffer[i]; |
169 | } else { | 169 | } else { |
170 | incoming_keysize = ""; | 170 | incoming_keysize = ""; |
171 | incoming_keyfingerprint = ""; | 171 | incoming_keyfingerprint = ""; |
172 | incoming_noise = ""; | 172 | incoming_noise = ""; |
173 | keystate = Noise; | 173 | keystate = Noise; |
174 | goto noise; | 174 | goto noise; |
175 | } | 175 | } |
176 | break; | 176 | break; |
177 | } | 177 | } |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | void SSHKeysApp::flush_sshadd_output(void) | 181 | void SSHKeysApp::flush_sshadd_output(void) |
182 | { | 182 | { |
183 | if (pending_stdout.length()) { | 183 | if (pending_stdout.length()) { |
184 | log_text(pending_stdout.ascii()); | 184 | log_text(pending_stdout.ascii()); |
185 | } | 185 | } |
186 | pending_stdout = ""; | 186 | pending_stdout = ""; |
187 | 187 | ||
188 | if (pending_stderr.length()) { | 188 | if (pending_stderr.length()) { |
189 | log_text(pending_stderr.ascii()); | 189 | log_text(pending_stderr.ascii()); |
190 | } | 190 | } |
191 | pending_stderr = ""; | 191 | pending_stderr = ""; |
192 | } | 192 | } |
193 | 193 | ||
194 | void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) | 194 | void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) |
195 | { | 195 | { |
196 | (void) proc; | 196 | (void) proc; |
197 | 197 | ||
198 | while (buflen) { | 198 | while (buflen) { |
199 | if (*buffer == '\n') { | 199 | if (*buffer == '\n') { |
200 | log_text(pending_stdout); | 200 | log_text(pending_stdout); |
201 | pending_stdout = ""; | 201 | pending_stdout = ""; |
202 | } else { | 202 | } else { |
203 | pending_stdout += *buffer; | 203 | pending_stdout += *buffer; |
204 | } | 204 | } |
205 | buffer++; | 205 | buffer++; |
206 | buflen--; | 206 | buflen--; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | void SSHKeysApp::log_sshadd_stderr(OProcess *proc, char *buffer, int buflen) | 210 | void SSHKeysApp::log_sshadd_stderr(OProcess *proc, char *buffer, int buflen) |
211 | { | 211 | { |
212 | (void) proc; | 212 | (void) proc; |
213 | 213 | ||
214 | while (buflen) { | 214 | while (buflen) { |
215 | if (*buffer == '\n') { | 215 | if (*buffer == '\n') { |
216 | log_text(pending_stderr); | 216 | log_text(pending_stderr); |
217 | pending_stderr = ""; | 217 | pending_stderr = ""; |
218 | } else { | 218 | } else { |
219 | pending_stderr += *buffer; | 219 | pending_stderr += *buffer; |
220 | } | 220 | } |
221 | buffer++; | 221 | buffer++; |
222 | buflen--; | 222 | buflen--; |
223 | } | 223 | } |
224 | } | 224 | } |
225 | 225 | ||
226 | void SSHKeysApp::ssh_add_exited(OProcess *proc) | 226 | void SSHKeysApp::ssh_add_exited(OProcess *proc) |
227 | { | 227 | { |
228 | (void)proc; | 228 | (void)proc; |
229 | 229 | ||
230 | doRefreshListButton(); | 230 | doRefreshListButton(); |
231 | setEnabled(TRUE); | 231 | setEnabled(TRUE); |
232 | if (proc->exitStatus() == 2) { | 232 | if (proc->exitStatus() == 2) { |
233 | setEnabled(FALSE); | 233 | setEnabled(FALSE); |
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
237 | void SSHKeysApp::add_text_changed(const QString &text) | 237 | void SSHKeysApp::add_text_changed(const QString &text) |
238 | { | 238 | { |
239 | struct stat sbuf; | 239 | struct stat sbuf; |
240 | 240 | ||
241 | if (!text.length() || (!access(text.ascii(), R_OK) && | 241 | if (!text.length() || (!access(text.ascii(), R_OK) && |
242 | !stat(text.ascii(), &sbuf) && | 242 | !stat(text.ascii(), &sbuf) && |
243 | S_ISREG(sbuf.st_mode))) | 243 | S_ISREG(sbuf.st_mode))) |
244 | AddButton->setEnabled(TRUE); | 244 | AddButton->setEnabled(TRUE); |
245 | else | 245 | else |
246 | AddButton->setEnabled(FALSE); | 246 | AddButton->setEnabled(FALSE); |
247 | } | 247 | } |
248 | 248 | ||
249 | void SSHKeysApp::doAddButton() | 249 | void SSHKeysApp::doAddButton() |
250 | { | 250 | { |
251 | addprocess.clearArguments(); | 251 | addprocess.clearArguments(); |
252 | 252 | ||
253 | setEnabled(FALSE); | 253 | setEnabled(FALSE); |
254 | 254 | ||
255 | if (KeyFileName->currentText().length()) { | 255 | if (KeyFileName->currentText().length()) { |
256 | addprocess << "ssh-add" << "--" << KeyFileName->currentText(); | 256 | addprocess << "ssh-add" << "--" << KeyFileName->currentText(); |
257 | // log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); | 257 | // log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); |
258 | } else { | 258 | } else { |
259 | addprocess << "ssh-add"; | 259 | addprocess << "ssh-add"; |
260 | // log_text(tr("Running ssh-add")); | 260 | // log_text(tr("Running ssh-add")); |
261 | } | 261 | } |
262 | bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); | 262 | bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); |
263 | if (!ret) { | 263 | if (!ret) { |
264 | log_text(tr("Error running ssh-add")); | 264 | log_text(tr("Error running ssh-add")); |
265 | doRefreshListButton(); | 265 | doRefreshListButton(); |
266 | setEnabled(TRUE); | 266 | setEnabled(TRUE); |
267 | } | 267 | } |
268 | flush_sshadd_output(); | 268 | flush_sshadd_output(); |
269 | } | 269 | } |
270 | 270 | ||
271 | void SSHKeysApp::log_text(const char *text) | 271 | void SSHKeysApp::log_text(const char *text) |
272 | { | 272 | { |
273 | TextOutput->append(text); | 273 | TextOutput->append(text); |
274 | TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE); | 274 | TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE); |
275 | } | 275 | } |
276 | 276 | ||
277 | void SSHKeysApp::doRemoveAllButton() | 277 | void SSHKeysApp::doRemoveAllButton() |
278 | { | 278 | { |
279 | OProcess sshadd_process; | 279 | OProcess sshadd_process; |
280 | 280 | ||
281 | connect(&sshadd_process, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), | 281 | connect(&sshadd_process, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), |
282 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 282 | this, SLOT(log_sshadd_output(Opie::Core::OProcess*,char*,int))); |
283 | connect(&sshadd_process, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), | 283 | connect(&sshadd_process, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), |
284 | this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); | 284 | this, SLOT(log_sshadd_stderr(Opie::Core::OProcess*,char*,int))); |
285 | 285 | ||
286 | // log_text(tr("Running ssh-add -D")); | 286 | // log_text(tr("Running ssh-add -D")); |
287 | sshadd_process << "ssh-add" << "-D"; | 287 | sshadd_process << "ssh-add" << "-D"; |
288 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); | 288 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); |
289 | if (!ret) { | 289 | if (!ret) { |
290 | log_text(tr("Error running ssh-add")); | 290 | log_text(tr("Error running ssh-add")); |
291 | } | 291 | } |
292 | flush_sshadd_output(); | 292 | flush_sshadd_output(); |
293 | doRefreshListButton(); | 293 | doRefreshListButton(); |
294 | } | 294 | } |