~ubuntu-branches/ubuntu/oneiric/kdebindings/oneiric

« back to all changes in this revision

Viewing changes to perl/plasma/examples/applets/analogclock/ClockApplet.pm

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muskovac
  • Date: 2010-12-07 00:10:46 UTC
  • mfrom: (1.1.42 upstream)
  • Revision ID: james.westby@ubuntu.com-20101207001046-h9gf2h54ym29tgui
Tags: 4:4.5.85-0ubuntu1
* New upstream beta release
* Disable libqwt-ruby1.8 and qwt files in libqt4-ruby1.8.examples
* Add libqtdeclarative-ruby1.8, libsmokeqt3support4-3,
  libsmokeqtdeclarative4-3 and libsmokeqthelp4-3

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
use warnings;
27
27
 
28
28
use KDEUi4;
 
29
use KIO4;
29
30
use Plasma4;
30
31
use Ui_GeneralConfig;
31
32
use Ui_TimezonesConfig;
32
 
use Qt4::GlobalSpace qw( i18n );
 
33
use Qt::GlobalSpace qw( i18n );
33
34
 
34
35
sub new {
35
36
    my ( $class, $clockapplet ) = @_;
39
40
        clipboardMenu => 0,
40
41
        adjustSystemTimeAction => 0,
41
42
        label => 0,
42
 
        calendarWidget => 0,
 
43
        calendarWidget => undef,
43
44
        forceTzDisplay => 0,
 
45
        announceInterval => 0,
44
46
    }, $class;
45
47
    return $self;
46
48
}
50
52
    ClockApplet *q;
51
53
    Ui::timezonesConfig ui;
52
54
    Ui::generalConfig generalUi;
53
 
    Qt4::String timezone;
54
 
    Qt4::String defaultTimezone;
55
 
    Qt4::Point clicked;
56
 
    Qt4::StringList selectedTimezones;
 
55
    Qt::String timezone;
 
56
    Qt::String defaultTimezone;
 
57
    Qt::Point clicked;
 
58
    Qt::StringList selectedTimezones;
57
59
    KDE::Menu *clipboardMenu;
58
 
    Qt4::Action *adjustSystemTimeAction;
59
 
    Qt4::String prettyTimezone;
 
60
    Qt::Action *adjustSystemTimeAction;
 
61
    Qt::String prettyTimezone;
60
62
    Plasma::Label *label;
61
63
    Plasma::Calendar *calendarWidget;
62
64
    int announceInterval;
83
85
 
84
86
    my $formatTime = KDE::Global::locale()->formatTime($data->{'Time'}->toTime(), 0);
85
87
    $formatTime =~ s/ / /g;
86
 
    #my $formatDate = $self->{q}->calendar()->formatDate($data->{'Date'}->toDate());
87
 
    #$formatDate =~ s/ / /g;
 
88
    my $formatDate = $self->{q}->calendar()->formatDate($data->{'Date'}->toDate());
 
89
    $formatDate =~ s/ / /g;
88
90
    $$subText .= $formatTime .
89
 
           ', ';
90
 
           #$formatDate;
 
91
           ', ' .
 
92
           $formatDate;
91
93
}
92
94
 
93
95
sub createCalendarExtender
94
96
{
95
97
    my ($self) = @_;
96
 
    #if (!$self->{q}->extender()->hasItem('calendar')) {
97
 
        #my $eItem = Plasma::ExtenderItem($self->{q}->extender());
98
 
        #$eItem->setName('calendar');
99
 
        #$self->{q}->initExtenderItem($eItem);
100
 
    #}
 
98
    if (!$self->{q}->extender()->hasItem('calendar')) {
 
99
        my $eItem = Plasma::ExtenderItem($self->{q}->extender());
 
100
        $eItem->setName('calendar');
 
101
        $self->{q}->initExtenderItem($eItem);
 
102
    }
101
103
}
102
104
 
103
105
sub createToday
104
106
{
105
107
    my ($self) = @_;
106
 
    #my $tmpStr = 'isHoliday:' . $self->{calendarWidget}->holidaysRegion() . ':' . Qt4::Date::currentDate().toString(Qt4::ISODate());
107
 
    #my $isHoliday = $self->{q}->dataEngine('calendar')->query($tmpStr)->value($tmpStr)->toBool();
108
 
#
109
 
    #my $todayExtender = $self->{q}->extender()->item('today');
110
 
#
111
 
    #if (!$todayExtender && $isHoliday) {
112
 
        #my $eItem = Plasma::ExtenderItem($self->{q}->extender());
113
 
        #$eItem->setName('today');
114
 
        #$self->{q}->initExtenderItem($eItem);
115
 
 
116
 
    #} elsif ($todayExtender && !$isHoliday) {
117
 
        #$todayExtender->destroy();
118
 
    #}
119
 
}
120
 
 
121
 
sub createDateExtender
122
 
{
123
 
    my ($self, $date) = @_;
124
 
    my $eItem = Plasma::ExtenderItem($self->{q}->extender());
125
 
    $eItem->setName('dateExtender-' . $date->toString(Qt4::ISODate()));
126
 
    $self->{q}->initExtenderItem($eItem);
127
 
}
128
 
 
129
 
sub destroyDateExtenders
130
 
{
131
 
    my ($self) = @_;
132
 
    my $extenders = $self->{q}->extender()->items();
133
 
    foreach my $eItem ( @{$extenders} ) {
134
 
        if ( $eItem->name() =~ m/^dateExtender-/ && !$eItem->isDetached()){
135
 
            $eItem->destroy();
136
 
        }
 
108
    my $tmpStr = 'isHoliday:' . $self->{calendarWidget}->holidaysRegion() . ':' . Qt::Date::currentDate()->toString(Qt::ISODate());
 
109
    my $data = $self->{q}->dataEngine('calendar')->query($tmpStr);
 
110
    my $isHoliday = exists $data->{$tmpStr} && $data->{$tmpStr}->toBool();
 
111
 
 
112
    my $todayExtender = $self->{q}->extender()->item('today');
 
113
 
 
114
    if (!$todayExtender && $isHoliday) {
 
115
        my $eItem = Plasma::ExtenderItem($self->{q}->extender());
 
116
        $eItem->setName('today');
 
117
        $self->{q}->initExtenderItem($eItem);
 
118
    } elsif ($todayExtender && !$isHoliday) {
 
119
        $todayExtender->destroy();
137
120
    }
138
121
}
139
122
 
148
131
        my @tzParts = split /\//, $timezonetranslated;
149
132
        if (scalar @tzParts == 1) {
150
133
            $prettyTimezone = $timezonetranslated;
151
 
        } else {
 
134
        } elsif ( scalar @tzParts > 0 ) {
152
135
            $prettyTimezone = $tzParts[-1];
153
136
        }
 
137
        else {
 
138
            $prettyTimezone = $timezonetranslated;
 
139
        }
154
140
    } else {
155
141
        $prettyTimezone = $self->{q}->localTimezone();
156
142
    }
167
153
use QtCore4;
168
154
use KDEUi4;
169
155
use Plasma4;
170
 
use Qt4::isa qw( Plasma::PopupApplet );
171
 
use Qt4::GlobalSpace qw( i18n i18nc );
 
156
use QtCore4::isa qw( Plasma::PopupApplet );
 
157
use Qt::GlobalSpace qw( i18n i18nc IconSize );
172
158
 
173
 
use Qt4::slots
 
159
use QtCore4::slots
 
160
    configChanged => [],
174
161
    toolTipAboutToShow => [],
175
162
    toolTipHidden => [],
176
163
    setCurrentTimezone => ['const QString &'],
177
164
    configAccepted => [],
178
165
    updateClockDefaultsTo => [],
179
 
    dateChanged => ['const Qt4::Date &'],
180
 
    speakTime => ['const Qt4::Time &'],
 
166
    speakTime => ['const QTime &'],
181
167
    launchTimeControlPanel => [],
182
168
    updateClipboardMenu => [],
183
 
    copyToClipboard => ['Qt4::Action*'],
 
169
    copyToClipboard => ['QAction*'],
184
170
    createCalendarExtender => [],
185
171
    createToday => [];
186
172
 
 
173
use Calendar;
 
174
 
187
175
sub NEW {
188
176
    my ( $class, $parent, $args ) = @_;
189
177
    $class->SUPER::NEW( $parent, $args );
190
178
    this->{d} = ClockApplet::Private->new(this);
191
 
    this->setPopupIcon(Qt4::Icon());
 
179
    this->setPopupIcon(Qt::Icon());
192
180
    this->setPassivePopup(1);
193
181
}
194
182
 
195
183
sub speakTime
196
184
{
197
185
    my ($time) = @_;
 
186
 
 
187
    if (!this->{d}->{announceInterval}) {
 
188
        return;
 
189
    }
 
190
 
198
191
    print "SpeakTime function not implemented\n";
199
192
    return;
200
193
 
201
194
=begin
202
195
 
203
 
    if (!d->announceInterval) {
204
 
        return;
205
 
    }
206
 
 
207
196
    if (time.minute() != d->prevMinute && (time.minute() % d->announceInterval) == 0) {
208
197
        d->prevHour = time.hour();
209
198
        d->prevMinute = time.minute();
210
199
 
211
 
        # If KDE::TTSD not running, start it.
212
 
        if (!Qt4::DBusConnection::sessionBus().interface()->isServiceRegistered('org.kde.kttsd')) {
213
 
            Qt4::String error;
214
 
            if (KDE::ToolInvocation::startServiceByDesktopName('kttsd', Qt4::StringList(), &error)) {
215
 
                KDE::MessageBox::error(0, i18n( 'Starting KDE::TTSD Failed'), error );
 
200
        # If KTTSD not running, start it.
 
201
        if (!Qt::DBusConnection::sessionBus().interface()->isServiceRegistered('org.kde.kttsd')) {
 
202
            Qt::String error;
 
203
            if (KDE::ToolInvocation::startServiceByDesktopName('kttsd', Qt::StringList(), &error)) {
 
204
                KDE::PassivePopup::message(i18n( 'Starting KTTSD Failed'), error );
216
205
                return;
217
206
            }
218
207
        }
219
208
 
220
 
        Qt4::DBusInterface ktts('org.kde.kttsd', '/KDE::Speech', 'org.kde.KDE::Speech');
 
209
        Qt::DBusInterface ktts('org.kde.kttsd', '/KDE::Speech', 'org.kde.KDE::Speech');
221
210
        ktts.asyncCall('setApplicationName', 'plasmaclock');
222
 
        Qt4::String text;
 
211
        Qt::String text;
223
212
        if (time.minute() == 0) {
224
213
            if (KDE::Global::locale()->use12Clock()) {
225
214
                if (time.hour() < 12) {
286
275
    # the main text contains the current timezone's time and date
287
276
    my $data = this->dataEngine('time')->query(this->currentTimezone());
288
277
    my $mainText = this->{d}->{prettyTimezone} . ' ';
289
 
    $mainText .= KDE::Global::locale()->formatTime($data->{'Time'}->toTime(), 0) . '<br>';
290
 
    my $tipDate = $data->{'Date'}->toDate();
291
 
    #$mainText .= this->calendar()->formatDate($tipDate);
 
278
    $mainText .= KDE::Global::locale()->formatTime($data->{Time}->toTime(), 0) . '<br>';
 
279
    my $tipDate = $data->{Date}->toDate();
 
280
    $mainText .= this->calendar()->formatDate($tipDate);
292
281
    $tipData->setMainText($mainText);
293
282
 
294
283
    my $subText;
304
293
        this->{d}->addTzToTipText($subText, \$tz);
305
294
    }
306
295
 
307
 
    #my $property = this->{d}->{calendarWidget}->dateProperty($tipDate);
308
 
    #if ($property) {
309
 
        #my $countryString = KDE::Global::locale()->countryCodeToName(this->{d}->{calendarWidget}->holidaysRegion());
310
 
        #if (!$countryString) {
311
 
            #$subText .= '<br>' . $property;
312
 
        #} else {
313
 
            #$subText .= '<br><b>' . $countryString . '</b> ' . $property;
314
 
        #}
315
 
    #}
 
296
    if (this->{d}->{calendarWidget}->dateHasDetails($tipDate)) {
 
297
        my $property = this->{d}->{calendarWidget}->dateDetails($tipDate);
 
298
        my $countryString = KDE::Global::locale()->countryCodeToName(this->{d}->{calendarWidget}->holidaysRegion());
 
299
        if (!$countryString) {
 
300
            $subText .= '<br>' . $property;
 
301
        } else {
 
302
            $subText .= '<br><b>' . $countryString . '</b> ' . $property;
 
303
        }
 
304
    }
316
305
 
317
306
    $tipData->setSubText($subText);
318
307
 
319
308
    # query for custom content
320
309
    my $customContent = this->toolTipContent();
321
310
    if ($customContent->image()->isNull()) {
322
 
        #$tipData->setImage(KDE::Icon(this->icon())->pixmap(IconSize(KDE::IconLoader::Desktop)));
323
 
        $tipData->setImage(KDE::Icon(this->icon())->pixmap(KDE::IconLoader::Desktop()));
 
311
        $tipData->setImage(KDE::Icon(this->icon())->pixmap(IconSize(KDE::IconLoader::Desktop())));
324
312
    } else {
325
313
        $tipData->setImage($customContent->image());
326
314
    }
339
327
    Plasma::ToolTipManager::self()->setContent(this, $tipData);
340
328
}
341
329
 
 
330
sub updateClockApplet
 
331
{
 
332
    my $updateSelectedDate = (this->{d}->{calendarWidget}->currentDate() == this->{d}->{calendarWidget}->date());
 
333
 
 
334
    my $data = this->dataEngine('time')->query(currentTimezone());
 
335
    this->{d}->{calendarWidget}->setCurrentDate($data->{Date}->toDate());
 
336
    
 
337
    if ($updateSelectedDate){
 
338
        this->{d}->{calendarWidget}->setDate(this->{d}->{calendarWidget}->currentDate());
 
339
    }
 
340
}
 
341
 
342
342
sub toolTipContent
343
343
{
344
344
    return Plasma::ToolTipContent();
349
349
    my ($parent) = @_;
350
350
    this->createClockConfigurationInterface($parent);
351
351
 
352
 
    my $generalWidget = Qt4::Widget();
 
352
    my $generalWidget = Qt::Widget();
353
353
    this->{d}->{generalUi} = Ui_GeneralConfig->setupUi($generalWidget);
354
354
    $parent->addPage($generalWidget, i18nc('General configuration page', 'General'), Plasma::Applet::icon());
355
355
    this->{d}->{generalUi}->interval->setValue(this->{d}->{announceInterval});
356
356
 
357
 
    #this->{d}->{calendarWidget}->createConfigurationInterface($parent);
 
357
    this->{d}->{calendarWidget}->createConfigurationInterface($parent);
358
358
 
359
 
    my $widget = Qt4::Widget();
 
359
    my $widget = Qt::Widget();
360
360
    this->{d}->{ui} = Ui_TimezonesConfig->setupUi($widget);
361
361
    this->{d}->{ui}->searchLine->addTreeWidget(this->{d}->{ui}->timeZones);
362
362
 
367
367
    }
368
368
 
369
369
    this->updateClockDefaultsTo();
370
 
    my $defaultSelection = this->{d}->{ui}->clockDefaultsTo->findData(Qt4::Variant(this->{d}->{defaultTimezone}));
 
370
    my $defaultSelection = this->{d}->{ui}->clockDefaultsTo->findData(Qt::Variant(Qt::String(this->{d}->{defaultTimezone})));
371
371
    if ($defaultSelection < 0) {
372
372
        $defaultSelection = 0; #if it's something unexpected default to local
373
373
        #kDebug() << this->{d}->defaultTimezone << 'not in list!?';
374
374
    }
375
375
    this->{d}->{ui}->clockDefaultsTo->setCurrentIndex($defaultSelection);
376
376
 
377
 
    $parent->setButtons( ${KDE::Dialog::Ok()} | ${KDE::Dialog::Cancel()} | ${KDE::Dialog::Apply()} );
378
 
    this->connect($parent, SIGNAL 'applyClicked()', this, SLOT 'configAccepted()');
379
 
    this->connect($parent, SIGNAL 'okClicked()', this, SLOT 'configAccepted()');
380
377
    this->connect(this->{d}->{ui}->timeZones, SIGNAL 'itemChanged(QTreeWidgetItem*,int)', this, SLOT 'updateClockDefaultsTo()');
381
378
}
382
379
 
390
387
 
391
388
}
392
389
 
 
390
sub clockConfigChanged
 
391
{
 
392
 
 
393
}
 
394
 
 
395
sub configChanged()
 
396
{
 
397
    if (this->isUserConfiguring()) {
 
398
        this->configAccepted();
 
399
    }
 
400
 
 
401
    my $cg = this->config();
 
402
    this->{d}->{selectedTimezones} = $cg->readEntry(Qt::String('timeZones'), [Qt::String('')]);
 
403
    this->{d}->{timezone} = $cg->readEntry(Qt::String('timezone'), Qt::String(this->{d}->{timezone}));
 
404
    this->{d}->{defaultTimezone} = $cg->readEntry(Qt::String('defaultTimezone'), Qt::String(this->{d}->{timezone}));
 
405
    this->{d}->{forceTzDisplay} = this->{d}->{timezone} ne this->{d}->{defaultTimezone};
 
406
    this->{d}->setPrettyTimezone();
 
407
    this->{d}->{announceInterval} = $cg->readEntry(Qt::String('announceInterval'), Qt::String('0'));
 
408
 
 
409
    this->clockConfigChanged();
 
410
 
 
411
    if (this->isUserConfiguring()) {
 
412
        this->constraintsEvent(Plasma::SizeConstraint());
 
413
        this->update();
 
414
    } else {
 
415
        # d->calendarWidget->configAccepted(cg); is called in configAccepted(), 
 
416
        # as is setCurrentTimezone
 
417
        # so we only need to do this in the case where the user hasn't been
 
418
        # configuring things
 
419
        this->{d}->{calendarWidget}->applyConfiguration($cg);
 
420
        my $data = this->dataEngine('time')->query(this->{d}->{timezone});
 
421
        this->{d}->{calendarWidget}->setDate($data->{Date}->toDate());
 
422
    }
 
423
}
 
424
 
393
425
sub configAccepted
394
426
{
395
427
    my $cg = this->config();
396
428
 
397
 
    this->{d}->{selectedTimezones} = this->{d}->{ui}->timeZones->selection();
398
 
    $cg->writeEntry('timeZones', this->{d}->{selectedTimezones});
 
429
    $cg->writeEntry(Qt::String('timeZones'), this->{d}->{ui}->timeZones->selection());
399
430
 
400
431
    if (this->{d}->{ui}->clockDefaultsTo->currentIndex() == 0) {
401
432
        #The first position in {ui}->clockDefaultsTo is 'Local'
404
435
        this->{d}->{defaultTimezone} = this->{d}->{ui}->clockDefaultsTo->itemData(this->{d}->{ui}->clockDefaultsTo->currentIndex())->value();
405
436
    }
406
437
 
407
 
    $cg->writeEntry('defaultTimezone', this->{d}->{defaultTimezone});
 
438
    $cg->writeEntry(Qt::String('defaultTimezone'), Qt::String(this->{d}->{defaultTimezone}));
408
439
    my $cur = this->currentTimezone();
409
440
    this->setCurrentTimezone(this->{d}->{defaultTimezone});
410
441
    this->changeEngineTimezone($cur, this->{d}->{defaultTimezone});
411
442
 
412
 
    #this->{d}->{calendarWidget}->configAccepted($cg);
 
443
    this->{d}->{calendarWidget}->configAccepted($cg);
413
444
 
414
 
    this->{d}->{announceInterval} = this->{d}->{generalUi}->interval->value();
415
 
    $cg->writeEntry('announceInterval', this->{d}->{announceInterval});
 
445
    $cg->writeEntry(Qt::String('announceInterval'), Qt::String(this->{d}->{generalUi}->interval->value()));
416
446
 
417
447
    this->clockConfigAccepted();
418
 
    this->constraintsEvent(Plasma::SizeConstraint());
419
 
    this->update();
420
448
 
421
449
    emit this->configNeedsSaving();
422
450
}
425
453
{
426
454
    my $oldSelection = this->{d}->{ui}->clockDefaultsTo->currentText();
427
455
    this->{d}->{ui}->clockDefaultsTo->clear();
428
 
    this->{d}->{ui}->clockDefaultsTo->addItem(this->localTimezone(), Qt4::Variant(this->localTimezone()));
 
456
    this->{d}->{ui}->clockDefaultsTo->addItem(this->localTimezone(), Qt::Variant(Qt::String(this->localTimezone())));
429
457
    foreach my $tz ( @{this->{d}->{ui}->timeZones->selection()} ) {
430
 
        this->{d}->{ui}->clockDefaultsTo->addItem(KDE::TimeZoneWidget::displayName(KDE::TimeZone($tz)), Qt4::Variant($tz));
 
458
        this->{d}->{ui}->clockDefaultsTo->addItem(KDE::TimeZoneWidget::displayName(KDE::TimeZone($tz)), Qt::Variant($tz));
431
459
    }
432
460
    my $newPosition = this->{d}->{ui}->clockDefaultsTo->findText($oldSelection);
433
461
    if ($newPosition >= 0) {
460
488
        this->connect(this->{d}->{clipboardMenu}, SIGNAL 'aboutToShow()', this, SLOT 'updateClipboardMenu()');
461
489
        this->connect(this->{d}->{clipboardMenu}, SIGNAL 'triggered(QAction*)', this, SLOT 'copyToClipboard(QAction*)');
462
490
 
463
 
        my $offers = KDE::ServiceTypeTrader::self()->query('KDE::CModule', 'Library == \'kcm_clock\'');
464
 
        if ($offers && this->hasAuthorization('LaunchApp')) {
465
 
            this->{d}->{adjustSystemTimeAction} = Qt4::Action(this);
466
 
            this->{d}->{adjustSystemTimeAction}->setText(i18n('Adjust Date and Time'));
467
 
            this->{d}->{adjustSystemTimeAction}->setIcon(KDE::Icon('preferences-system-time'));
 
491
        my $offers = KDE::ServiceTypeTrader::self()->query('KCModule', 'Library == \'kcm_clock\'');
 
492
        if (scalar @{$offers} && this->hasAuthorization('LaunchApp')) {
 
493
            this->{d}->{adjustSystemTimeAction} = Qt::Action(this);
 
494
            this->{d}->{adjustSystemTimeAction}->setText(i18n('Adjust Date and Time...'));
 
495
            this->{d}->{adjustSystemTimeAction}->setIcon(KDE::Icon(this->icon()));
468
496
            this->connect(this->{d}->{adjustSystemTimeAction}, SIGNAL 'triggered()', this, SLOT 'launchTimeControlPanel()');
469
497
        }
470
498
    }
479
507
 
480
508
sub launchTimeControlPanel
481
509
{
482
 
    my $offers = KDE::ServiceTypeTrader::self()->query('KDE::CModule', 'Library == \'kcm_clock\'');
 
510
    my $offers = KDE::ServiceTypeTrader::self()->query('KCModule', 'Library == \'kcm_clock\'');
483
511
    if (!$offers) {
484
512
        #kDebug() << 'fail';
485
513
        return;
486
514
    }
487
515
 
488
 
    my $urls = KDE::Url::List();
489
516
    my $service = $offers->[0];
490
 
    KDE::Run::run($service, $urls, 0);
 
517
    KDE::Run::run($service, [], undef);
491
518
}
492
519
 
493
520
sub wheelEvent
536
563
sub initExtenderItem
537
564
{
538
565
    my ($item) = @_;
539
 
    if ($item->name() == 'calendar') {
 
566
    if ($item->name() eq 'calendar') {
540
567
        $item->setTitle(i18n('Calendar'));
541
568
        $item->setIcon('view-pim-calendar');
542
 
        #$item->setWidget(this->{d}->{calendarWidget});
 
569
        $item->setWidget(this->{d}->{calendarWidget});
543
570
    } elsif ($item->name() eq 'today') {
544
571
        $item->setTitle(i18n('Today'));
545
572
        $item->setIcon('view-pim-calendar');
546
573
        this->{d}->{label} = Plasma::Label();
547
574
        $item->setWidget(this->{d}->{label});
548
 
    } elsif ($item->name() =~ m/^dateExtender/) {
549
 
        $item->setIcon('view-pim-calendar');
550
 
        $item->showCloseButton();
551
 
        my $date = Qt4::Date::fromString(substr( $item->name(), 13), Qt4::ISODate());
552
 
        my $widget;
553
 
 
554
 
        #$item->setTitle(this->calendar()->formatDate($date));
555
 
        #$widget = DateExtenderWidget(this->{d}->{calendarWidget}->dateProperty($date));
556
 
 
557
 
        $item->setWidget($widget);
558
575
    }
559
576
}
560
577
 
561
578
sub init
562
579
{
563
 
    my $cg = this->config();
564
 
    # Make it call the QStringList copy of readEntry() by making an array ref
565
 
    # of an empty QString.
566
 
    this->{d}->{selectedTimezones} = $cg->readEntry(Qt4::String('timeZones'), [Qt4::String('')]);
567
 
    this->{d}->{selectedTimezones} = [this->localTimezoneUntranslated()]
568
 
        if this->{d}->{selectedTimezones}->[0] eq '';
569
 
    this->{d}->{timezone} = $cg->readEntry(Qt4::String('timezone'), Qt4::String(this->{d}->{timezone}));
570
 
    this->{d}->{defaultTimezone} = $cg->readEntry(Qt4::String('defaultTimezone'), Qt4::String(this->{d}->{timezone}));
571
 
    this->{d}->{forceTzDisplay} = this->{d}->{timezone} ne this->{d}->{defaultTimezone};
572
 
 
573
 
    this->{d}->setPrettyTimezone();
574
 
 
575
 
    this->{d}->{announceInterval} = $cg->readEntry(Qt4::String('announceInterval'), Qt4::String(''));
576
 
 
577
580
    Plasma::ToolTipManager::self()->registerWidget(this);
578
581
 
579
 
    #this->{d}->{calendarWidget} = Plasma::Calendar();
580
 
    #this->{d}->{calendarWidget}->setMinimumSize(Qt4::Size(230, 220));
581
 
    #this->{d}->{calendarWidget}->setDataEngine(this->dataEngine('calendar'));
582
 
    #this->connect(this->{d}->{calendarWidget}, SIGNAL 'dateChanged(const QDate &)', this, SLOT 'dateChanged(const QDate &)');
583
 
    #this->{d}->{calendarWidget}->applyConfiguration($cg);
584
 
    my $data = this->dataEngine('time')->query(this->currentTimezone());
585
 
    #this->{d}->{calendarWidget}->setDate($data->{'Date'}->toDate());
586
 
    #this->{d}->createCalendarExtender();
 
582
    this->{d}->{calendarWidget} = Calendar();
 
583
    this->{d}->{calendarWidget}->setAutomaticUpdateEnabled(0);
 
584
    this->{d}->{calendarWidget}->setMinimumSize(Qt::SizeF(230, 220));
 
585
    this->{d}->{calendarWidget}->setDataEngine(this->dataEngine('calendar'));
 
586
    this->{d}->createCalendarExtender();
587
587
 
588
588
    this->extender();
589
 
    Qt4::Timer::singleShot(0, this, SLOT 'createToday()');
 
589
 
 
590
    this->configChanged();
 
591
    Qt::Timer::singleShot(0, this, SLOT 'createToday()');
590
592
}
591
593
 
592
594
sub popupEvent
597
599
    }
598
600
 
599
601
    my $data = this->dataEngine('time')->query(this->currentTimezone());
600
 
    #this->{d}->{calendarWidget}->setDate($data->{'Date'}->toDate());
601
 
 
602
 
    this->{d}->destroyDateExtenders();
 
602
    this->{d}->{calendarWidget}->setDate($data->{'Date'}->toDate());
603
603
}
604
604
 
605
605
sub constraintsEvent
628
628
    this->{d}->setPrettyTimezone();
629
629
 
630
630
    my $cg = this->config();
631
 
    $cg->writeEntry('timezone', this->{d}->{timezone});
 
631
    $cg->writeEntry(Qt::String('timezone'), Qt::String(this->{d}->{timezone}));
632
632
    emit this->configNeedsSaving();
633
633
}
634
634
 
662
662
    return 'Local';
663
663
}
664
664
 
665
 
sub dateChanged
666
 
{
667
 
    my ($date) = @_;
668
 
    this->{d}->destroyDateExtenders();
669
 
 
670
 
    #if (this->{d}->{calendarWidget}->dateProperty($date)) {
671
 
        #this->{d}->createDateExtender($date);
672
 
    #}
673
 
}
674
 
 
675
665
sub updateClipboardMenu
676
666
{
677
667
    this->{d}->{clipboardMenu}->clear();
678
668
    my $actions;
679
669
    my $data = this->dataEngine('time')->query(this->currentTimezone());
680
 
    my $dateTime = Qt4::DateTime($data->{'Date'}->toDate(), $data->{'Time'}->toTime());
 
670
    my $dateTime = Qt::DateTime($data->{'Date'}->toDate(), $data->{'Time'}->toTime());
681
671
 
682
 
    #this->{d}->{clipboardMenu}->addAction(this->calendar()->formatDate($dateTime->date(), KDE::Locale::LongDate()));
683
 
    #this->{d}->{clipboardMenu}->addAction(this->calendar()->formatDate($dateTime->date(), KDE::Locale::ShortDate()));
 
672
    this->{d}->{clipboardMenu}->addAction(this->calendar()->formatDate($dateTime->date(), KDE::Locale::LongDate()));
 
673
    this->{d}->{clipboardMenu}->addAction(this->calendar()->formatDate($dateTime->date(), KDE::Locale::ShortDate()));
684
674
    # Display ISO Date format if not already displayed
685
675
    if (KDE::Global::locale()->dateFormatShort() ne '%Y-%m-%d') {
686
 
        #this->{d}->{clipboardMenu}->addAction(this->calendar()->formatDate($dateTime->date(), '%Y-%m-%d'));
 
676
        this->{d}->{clipboardMenu}->addAction(this->calendar()->formatDate($dateTime->date(), '%Y-%m-%d'));
687
677
    }
688
678
 
689
 
    my $sep0 = Qt4::Action(this);
 
679
    my $sep0 = Qt::Action(this);
690
680
    $sep0->setSeparator(1);
691
681
    this->{d}->{clipboardMenu}->addAction($sep0);
692
682
 
693
683
    this->{d}->{clipboardMenu}->addAction(KDE::Global::locale()->formatTime($dateTime->time(), 0));
694
684
    this->{d}->{clipboardMenu}->addAction(KDE::Global::locale()->formatTime($dateTime->time(), 1));
695
685
 
696
 
    my $sep1 = Qt4::Action(this);
 
686
    my $sep1 = Qt::Action(this);
697
687
    $sep1->setSeparator(1);
698
688
    this->{d}->{clipboardMenu}->addAction($sep1);
699
689
 
700
690
    my $tempLocale = KDE::Locale(KDE::Global::locale());
701
 
    #$tempLocale->setCalendar(this->calendar()->calendarType());
702
 
    #this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::LongDate()));
703
 
    #this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::LongDate(), 1));
704
 
    #this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::ShortDate()));
705
 
    #this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::ShortDate(), 1));
 
691
    $tempLocale->setCalendar(this->calendar()->calendarType());
 
692
    this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::LongDate()));
 
693
    this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::LongDate(), 1));
 
694
    this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::ShortDate()));
 
695
    this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::ShortDate(), 1));
706
696
    # Display ISO DateTime format if not already displayed
707
 
    #if ($tempLocale->dateFormatShort() ne '%Y-%m-%d') {
708
 
        #$tempLocale->setDateFormatShort('%Y-%m-%d');
709
 
        #this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::ShortDate(), 1));
710
 
    #}
 
697
    if ($tempLocale->dateFormatShort() ne '%Y-%m-%d') {
 
698
        $tempLocale->setDateFormatShort('%Y-%m-%d');
 
699
        this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::ShortDate(), 1));
 
700
    }
711
701
 
712
 
    my $sep2 = Qt4::Action(this);
 
702
    my $sep2 = Qt::Action(this);
713
703
    $sep2->setSeparator(1);
714
704
    this->{d}->{clipboardMenu}->addAction($sep2);
715
705
 
716
 
    #my $calendars = KDE::CalendarSystem::calendarSystems();
717
 
    #foreach my $cal ( @{$calendars} ) {
718
 
        #if ($cal ne this->calendar()->calendarType()) {
719
 
            #my $tempCal = KDE::CalendarSystem::create($cal);
720
 
            #my $text = $tempCal->formatDate($dateTime->date(), KDE::Locale::LongDate()) . ' (' . KDE::CalendarSystem::calendarLabel($cal) . ')';
721
 
            #this->{d}->{clipboardMenu}->addAction($text);
722
 
            #$text = $tempCal->formatDate($dateTime->date(), KDE::Locale::ShortDate()) . ' (' . KDE::CalendarSystem::calendarLabel($cal) . ')';
723
 
            #this->{d}->{clipboardMenu}->addAction($text);
724
 
        #}
725
 
    #}
 
706
    my $calendars = KDE::CalendarSystem::calendarSystems();
 
707
    foreach my $cal ( @{$calendars} ) {
 
708
        if ($cal ne this->calendar()->calendarType()) {
 
709
            my $tempCal = KDE::CalendarSystem::create($cal);
 
710
            my $text = $tempCal->formatDate($dateTime->date(), KDE::Locale::LongDate()) . ' (' . KDE::CalendarSystem::calendarLabel($cal) . ')';
 
711
            this->{d}->{clipboardMenu}->addAction($text);
 
712
            $text = $tempCal->formatDate($dateTime->date(), KDE::Locale::ShortDate()) . ' (' . KDE::CalendarSystem::calendarLabel($cal) . ')';
 
713
            this->{d}->{clipboardMenu}->addAction($text);
 
714
        }
 
715
    }
726
716
}
727
717
 
728
718
sub copyToClipboard
731
721
    my $text = $action->text();
732
722
    $text =~ s/&//g;
733
723
 
734
 
    Qt4::Application::clipboard()->setText($text);
 
724
    Qt::Application::clipboard()->setText($text);
735
725
}
736
726
 
737
727
sub calendar
738
728
{
739
 
    #return this->{d}->{calendarWidget}->calendar();
 
729
    return this->{d}->{calendarWidget}->calendar();
 
730
}
 
731
 
 
732
sub createToday
 
733
{
 
734
    return this->{d}->createToday();
 
735
}
 
736
 
 
737
sub createCalendarExtender 
 
738
{
 
739
    return this->{d}->createCalendarExtender();
740
740
}
741
741
 
742
742
1;