summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 0abb401..083b50f 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -1,124 +1,125 @@
1#include "ntp.h" 1#include "ntp.h"
2#include <qpushbutton.h> 2#include <qpushbutton.h>
3#include <qregexp.h> 3#include <qregexp.h>
4#include <qtimer.h> 4#include <qtimer.h>
5#include <qtable.h> 5#include <qtable.h>
6#include <qlabel.h> 6#include <qlabel.h>
7#include <qsocket.h> 7#include <qsocket.h>
8#include <qlineedit.h> 8#include <qlineedit.h>
9#include <qspinbox.h> 9#include <qspinbox.h>
10#include <qmessagebox.h> 10#include <qmessagebox.h>
11#include <qmultilineedit.h> 11#include <qmultilineedit.h>
12#include <opie/oprocess.h> 12#include <opie/oprocess.h>
13#include <qpe/qpeapplication.h>
13#include <qpe/config.h> 14#include <qpe/config.h>
14#include <qpe/global.h> 15#include <qpe/global.h>
15#include <qpe/timeconversion.h> 16#include <qpe/timeconversion.h>
16#include <qpe/tzselect.h> 17#include <qpe/tzselect.h>
17#include <qpe/timestring.h> 18#include <qpe/timestring.h>
18#include <qpe/qpedialog.h> 19#include <qpe/qpedialog.h>
19#include <sys/time.h> 20#include <sys/time.h>
20#include <time.h> 21#include <time.h>
21#include <stdlib.h> 22#include <stdlib.h>
22 23
23 24
24Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) 25Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
25 : SetDateTime( parent, name, fl ) 26 : SetDateTime( parent, name, fl )
26{ 27{
27 28 qDebug("%s", QPEApplication::qpeDir().latin1());
28 Config ntpSrvs("/etc/ntpservers",Config::File); 29 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
29 ntpSrvs.setGroup("servers"); 30 ntpSrvs.setGroup("servers");
30 int srvCount = ntpSrvs.readNumEntry("count", 0 ); 31 int srvCount = ntpSrvs.readNumEntry("count", 0 );
31 for (int i = 0; i < srvCount; i++) 32 for (int i = 0; i < srvCount; i++)
32 { 33 {
33 ntpSrvs.setGroup(QString::number(i)); 34 ntpSrvs.setGroup(QString::number(i));
34 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); 35 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
35 } 36 }
36 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); 37 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
37 38
38 Config cfg("ntp",Config::User); 39 Config cfg("ntp",Config::User);
39 cfg.setGroup("settings"); 40 cfg.setGroup("settings");
40 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); 41 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) );
41 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); 42 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) );
42 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); 43 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
43 44
44 ntpTimer = new QTimer(this); 45 ntpTimer = new QTimer(this);
45 46
46 ntpProcess = new OProcess( ); 47 ntpProcess = new OProcess( );
47 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), 48 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
48 SLOT(slotNtpDelayChanged(int)) ); 49 SLOT(slotNtpDelayChanged(int)) );
49 50
50 ntpSock = new QSocket( this ); 51 ntpSock = new QSocket( this );
51 connect( ntpSock, SIGNAL( error(int) ), 52 connect( ntpSock, SIGNAL( error(int) ),
52 SLOT(slotCheckNtp(int)) ); 53 SLOT(slotCheckNtp(int)) );
53 slotProbeNtpServer(); 54 slotProbeNtpServer();
54 55
55 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 56 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
56 this, SLOT(getNtpOutput(OProcess*,char*,int))); 57 this, SLOT(getNtpOutput(OProcess*,char*,int)));
57 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 58 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
58 this, SLOT(ntpFinished(OProcess*))); 59 this, SLOT(ntpFinished(OProcess*)));
59 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); 60 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp()));
60 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 61 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
61 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); 62 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
62 slotCheckNtp(-1); 63 slotCheckNtp(-1);
63 readLookups(); 64 readLookups();
64} 65}
65 66
66Ntp::~Ntp() 67Ntp::~Ntp()
67{ 68{
68 delete ntpProcess; 69 delete ntpProcess;
69 Config ntpSrvs("/etc/ntpservers",Config::File); 70 Config ntpSrvs("/etc/ntpservers",Config::File);
70 ntpSrvs.setGroup("servers"); 71 ntpSrvs.setGroup("servers");
71 int srvCount = ComboNtpSrv->count(); 72 int srvCount = ComboNtpSrv->count();
72 ntpSrvs.writeEntry("count", srvCount); 73 ntpSrvs.writeEntry("count", srvCount);
73 for (int i = 0; i < srvCount; i++) 74 for (int i = 0; i < srvCount; i++)
74 { 75 {
75 ntpSrvs.setGroup(QString::number(i)); 76 ntpSrvs.setGroup(QString::number(i));
76 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); 77 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
77 } 78 }
78 Config cfg("ntp",Config::User); 79 Config cfg("ntp",Config::User);
79 cfg.setGroup("settings"); 80 cfg.setGroup("settings");
80 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); 81 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
81 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 82 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
82 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); 83 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
83} 84}
84 85
85bool Ntp::ntpDelayElapsed() 86bool Ntp::ntpDelayElapsed()
86{ 87{
87 Config cfg("ntp",Config::User); 88 Config cfg("ntp",Config::User);
88 cfg.setGroup("lookups"); 89 cfg.setGroup("lookups");
89 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 90 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
90 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; 91 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60;
91} 92}
92 93
93QString Ntp::getNtpServer() 94QString Ntp::getNtpServer()
94{ 95{
95 return ComboNtpSrv->currentText(); 96 return ComboNtpSrv->currentText();
96} 97}
97 98
98void Ntp::slotRunNtp() 99void Ntp::slotRunNtp()
99{ 100{
100 if ( !ntpDelayElapsed() ) 101 if ( !ntpDelayElapsed() )
101 { 102 {
102 switch ( 103 switch (
103 QMessageBox::warning(this, tr("Run NTP?"), 104 QMessageBox::warning(this, tr("Run NTP?"),
104 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 105 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
105 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ 106 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+
106 "<br>"+tr("Rerun NTP?"), 107 "<br>"+tr("Rerun NTP?"),
107 QMessageBox::Ok,QMessageBox::Cancel) 108 QMessageBox::Ok,QMessageBox::Cancel)
108 ) { 109 ) {
109 case QMessageBox::Ok: break; 110 case QMessageBox::Ok: break;
110 case QMessageBox::Cancel: return; 111 case QMessageBox::Cancel: return;
111 default: return; 112 default: return;
112 } 113 }
113 } 114 }
114 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 115 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
115 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 116 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
116 117
117 ntpProcess->clearArguments(); 118 ntpProcess->clearArguments();
118 *ntpProcess << "ntpdate" << getNtpServer(); 119 *ntpProcess << "ntpdate" << getNtpServer();
119 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 120 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
120 if ( !ret ) { 121 if ( !ret ) {
121 qDebug("Error while executing ntpdate"); 122 qDebug("Error while executing ntpdate");
122 ntpOutPut( tr("Error while executing ntpdate")); 123 ntpOutPut( tr("Error while executing ntpdate"));
123 } 124 }
124} 125}