~ubuntu-branches/ubuntu/maverick/kdeutils/maverick-proposed

« back to all changes in this revision

Viewing changes to ktimer/ktimer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-05-28 09:49:30 UTC
  • mfrom: (1.2.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20100528094930-jzynf0obv1n2v13a
Tags: 4:4.4.80-0ubuntu1~ppa1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
    }
64
64
 
65
65
    void update() {
66
 
        setText( 0, QString::number(m_job->value()) );
 
66
        setText( 0, m_job->formatTime(m_job->value()) );
67
67
 
68
68
        if( m_error )
69
69
            setIcon( 0, KIcon("process-stop") );
70
70
        else
71
71
            setIcon( 0, QPixmap() );
72
72
 
73
 
        setText( 1, QString::number(m_job->delay()) );
 
73
        setText( 1, m_job->formatTime(m_job->delay()) );
74
74
 
75
75
        switch( m_job->state() ) {
76
76
            case KTimerJob::Stopped: setIcon( 2, KIcon("media-playback-stop") ); break;
189
189
        m_state->setEnabled( true );
190
190
        m_settings->setEnabled( true );
191
191
        m_remove->setEnabled( true );
192
 
 
 
192
        m_delayH->disconnect();
 
193
        m_delayM->disconnect();
193
194
        m_delay->disconnect();
194
195
        m_loop->disconnect();
195
196
        m_one->disconnect();
201
202
                m_commandLine->disconnect();
202
203
                m_commandLine->lineEdit()->disconnect();
203
204
 
 
205
        // Set hour, minute and second QSpinBoxes before we connect to signals.
 
206
        int h, m, s;
 
207
        job->secondsToHMS( job->delay(), &h, &m, &s );
 
208
        m_delayH->setValue( h );
 
209
        m_delayM->setValue( m );
 
210
        m_delay->setValue( s );
 
211
 
204
212
        connect( m_commandLine->lineEdit(), SIGNAL(textChanged(const QString &)),
205
213
                 job, SLOT(setCommand(const QString &)) );
 
214
        connect( m_delayH, SIGNAL(valueChanged(int)),
 
215
                 SLOT(delayChanged()) );
 
216
        connect( m_delayM, SIGNAL(valueChanged(int)),
 
217
                 SLOT(delayChanged()) );
206
218
        connect( m_delay, SIGNAL(valueChanged(int)),
207
 
                 job, SLOT(setDelay(int)) );
 
219
                 SLOT(delayChanged()) );
208
220
        connect( m_loop, SIGNAL(toggled(bool)),
209
221
                 job, SLOT(setLoop(bool)) );
210
222
        connect( m_one, SIGNAL(toggled(bool)),
219
231
                 job, SLOT(setValue(int)) );
220
232
 
221
233
        m_commandLine->lineEdit()->setText( job->command() );
222
 
        m_delay->setValue( job->delay() );
223
234
        m_loop->setChecked( job->loop() );
224
235
        m_one->setChecked( job->oneInstance() );
225
236
        m_counter->display( (int)job->value() );
233
244
    }
234
245
}
235
246
 
236
 
const QString KTimerPref::formatSeconds( int seconds ) {
237
 
   if(seconds<60) return QString("%1").arg(seconds);
238
 
        return QString("%1:%2").arg( (int)seconds/60, 2, 10, QChar('0') ).arg( (int)seconds%60, 2, 10, QChar('0') ); 
239
 
}
240
247
 
241
248
void KTimerPref::jobChanged( KTimerJob *job )
242
249
{
263
270
    m_list->update();
264
271
}
265
272
 
 
273
/* Hour/Minute/Second was changed. This slot calculates the seconds until we start
 
274
    the job and inform the current job */
 
275
void KTimerPref::delayChanged()
 
276
{
 
277
    KTimerJobItem *item = static_cast<KTimerJobItem*>(m_list->currentItem());
 
278
    if ( item ) {
 
279
        KTimerJob *job = item->job();
 
280
        int time_sec = job->timeToSeconds( m_delayH->value(), m_delayM->value(), m_delay->value() );
 
281
        job->setDelay( time_sec );
 
282
    }
 
283
}
 
284
 
266
285
// Realy quits the application
267
286
void KTimerPref::exit() {
268
287
    done(0);
381
400
}
382
401
 
383
402
 
 
403
// Format given seconds to hour:minute:seconds and return QString 
 
404
QString KTimerJob::formatTime( int seconds ) const
 
405
{
 
406
    int h, m, s;
 
407
    secondsToHMS( seconds, &h, &m, &s );
 
408
    return QString( "%1:%2:%3" ).arg( h ).arg( m, 2, 10, QChar( '0' ) ).arg( s,2, 10, QChar( '0' ) );
 
409
}
 
410
 
 
411
 
 
412
// calculate seconds from hour, minute and seconds, returns seconds
 
413
int KTimerJob::timeToSeconds( int hours, int minutes, int seconds ) const
 
414
{
 
415
    return hours * 3600 + minutes * 60 + seconds;
 
416
}
 
417
 
 
418
 
 
419
// calculates hours, minutes and seconds from given secs.
 
420
void KTimerJob::secondsToHMS( int secs, int *hours, int *minutes, int *seconds ) const
 
421
{
 
422
    int s = secs;
 
423
    (*hours) = s / 3600;
 
424
    s = s % 3600;
 
425
    (*minutes) = s / 60;
 
426
    (*seconds) = s % 60;
 
427
}
 
428
 
384
429
void *KTimerJob::user()
385
430
{
386
431
    return d->user;