summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 9572993..fbd65a2 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -45,129 +45,129 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
45 45
46 makeChannel(); 46 makeChannel();
47 47
48 ntpTimer = new QTimer(this); 48 ntpTimer = new QTimer(this);
49 49
50 ntpProcess = new OProcess( ); 50 ntpProcess = new OProcess( );
51 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), 51 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
52 SLOT(slotNtpDelayChanged(int)) ); 52 SLOT(slotNtpDelayChanged(int)) );
53 53
54 ntpSock = new QSocket( this ); 54 ntpSock = new QSocket( this );
55 connect( ntpSock, SIGNAL( error(int) ), 55 connect( ntpSock, SIGNAL( error(int) ),
56 SLOT(slotCheckNtp(int)) ); 56 SLOT(slotCheckNtp(int)) );
57 slotProbeNtpServer(); 57 slotProbeNtpServer();
58 58
59 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 59 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
60 this, SLOT(getNtpOutput(OProcess*,char*,int))); 60 this, SLOT(getNtpOutput(OProcess*,char*,int)));
61 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 61 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
62 this, SLOT(ntpFinished(OProcess*))); 62 this, SLOT(ntpFinished(OProcess*)));
63 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); 63 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp()));
64 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 64 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
65 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); 65 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
66 slotCheckNtp(-1); 66 slotCheckNtp(-1);
67 readLookups(); 67 readLookups();
68} 68}
69 69
70Ntp::~Ntp() 70Ntp::~Ntp()
71{ 71{
72 delete ntpProcess; 72 delete ntpProcess;
73 Config ntpSrvs("/etc/ntpservers",Config::File); 73 Config ntpSrvs("/etc/ntpservers",Config::File);
74 ntpSrvs.setGroup("servers"); 74 ntpSrvs.setGroup("servers");
75 int srvCount = ComboNtpSrv->count(); 75 int srvCount = ComboNtpSrv->count();
76 ntpSrvs.writeEntry("count", srvCount); 76 ntpSrvs.writeEntry("count", srvCount);
77 for (int i = 0; i < srvCount; i++) 77 for (int i = 0; i < srvCount; i++)
78 { 78 {
79 ntpSrvs.setGroup(QString::number(i)); 79 ntpSrvs.setGroup(QString::number(i));
80 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); 80 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
81 } 81 }
82 Config cfg("ntp",Config::User); 82 Config cfg("ntp",Config::User);
83 cfg.setGroup("settings"); 83 cfg.setGroup("settings");
84 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); 84 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
85 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 85 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
86 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); 86 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
87} 87}
88 88
89bool Ntp::ntpDelayElapsed() 89bool Ntp::ntpDelayElapsed()
90{ 90{
91 Config cfg("ntp",Config::User); 91 Config cfg("ntp",Config::User);
92 cfg.setGroup("lookups"); 92 cfg.setGroup("lookups");
93 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 93 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
94 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; 94 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60;
95} 95}
96 96
97QString Ntp::getNtpServer() 97QString Ntp::getNtpServer()
98{ 98{
99 return ComboNtpSrv->currentText(); 99 return ComboNtpSrv->currentText();
100} 100}
101 101
102void Ntp::slotRunNtp() 102void Ntp::slotRunNtp()
103{ 103{
104 if ( !ntpDelayElapsed() ) 104 if ( !ntpDelayElapsed() )
105 { 105 {
106 switch ( 106 switch (
107 QMessageBox::warning(this, tr("Run NTP?"), 107 QMessageBox::warning(this, tr("Run NTP?"),
108 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 108 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
109 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ 109 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+
110 "<br>"+tr("Rerun NTP?"), 110 "<br>"+tr("Rerun NTP?"),
111 QMessageBox::Ok,QMessageBox::Cancel) 111 QMessageBox::Ok,QMessageBox::Cancel)
112 ) { 112 ) {
113 case QMessageBox::Ok: break; 113 case QMessageBox::Ok: break;
114 case QMessageBox::Cancel: return; 114 case QMessageBox::Cancel: return;
115 default: return; 115 default: return;
116 } 116 }
117 } 117 }
118 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 118 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
119 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 119 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
120 120
121 ntpProcess->clearArguments(); 121 ntpProcess->clearArguments();
122 *ntpProcess << "ntpdate" << getNtpServer(); 122 *ntpProcess << "ntpdate" << getNtpServer();
123 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 123 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
124 if ( !ret ) { 124 if ( !ret ) {
125 qDebug("Error while executing ntpdate"); 125 qDebug("Error while executing ntpdate");
126 ntpOutPut( tr("Error while executing ntpdate")); 126 ntpOutPut( tr("Error while executing ntpdate"));
127 } 127 }
128} 128}
129 129
130void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 130void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
131{ 131{
132 QString lineStr, lineStrOld; 132 QString lineStr, lineStrOld;
133 lineStr = buffer; 133 lineStr = buffer;
134 lineStr=lineStr.left(buflen); 134 lineStr=lineStr.left(buflen);
135 if (lineStr!=lineStrOld) 135 if (lineStr!=lineStrOld)
136 { 136 {
137 ntpOutPut(lineStr); 137 ntpOutPut(lineStr);
138 _ntpOutput += lineStr; 138 _ntpOutput += lineStr;
139 } 139 }
140 lineStrOld = lineStr; 140 lineStrOld = lineStr;
141} 141}
142 142
143void Ntp::ntpFinished(OProcess *p) 143void Ntp::ntpFinished(OProcess *p)
144{ 144{
145 qDebug("p->exitStatus() %i",p->exitStatus()); 145 qDebug("p->exitStatus() %i",p->exitStatus());
146 if (p->exitStatus()!=0 || !p->normalExit()) 146 if (p->exitStatus()!=0 || !p->normalExit())
147 { 147 {
148 slotProbeNtpServer(); 148 slotProbeNtpServer();
149 return; 149 return;
150 } 150 }
151 151
152 Global::writeHWClock(); 152 Global::writeHWClock();
153 // since time has changed quickly load in the datebookdb 153 // since time has changed quickly load in the datebookdb
154 // to allow the alarm server to get a better grip on itself 154 // to allow the alarm server to get a better grip on itself
155 // (example re-trigger alarms for when we travel back in time) 155 // (example re-trigger alarms for when we travel back in time)
156 DateBookDB db; 156 DateBookDB db;
157 157
158// QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); 158// QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" );
159// timeApplet << ""; 159// timeApplet << "";
160 160
161 Config cfg("ntp",Config::User); 161 Config cfg("ntp",Config::User);
162 cfg.setGroup("lookups"); 162 cfg.setGroup("lookups");
163 int lastLookup = cfg.readNumEntry("time",0); 163 int lastLookup = cfg.readNumEntry("time",0);
164 int lookupCount = cfg.readNumEntry("count",0); 164 int lookupCount = cfg.readNumEntry("count",0);
165 bool lastNtp = cfg.readBoolEntry("lastNtp",false); 165 bool lastNtp = cfg.readBoolEntry("lastNtp",false);
166 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 166 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
167 cfg.writeEntry("time", time); 167 cfg.writeEntry("time", time);
168 168
169 float timeShift = getTimeShift(); 169 float timeShift = getTimeShift();
170 if (timeShift == 0.0) return; 170 if (timeShift == 0.0) return;
171 int secsSinceLast = time - lastLookup; 171 int secsSinceLast = time - lastLookup;
172 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 172 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
173 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); 173 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));