File: ClockApplet.pm

package info (click to toggle)
qt4-perl 4.5~~svn1145508-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,144 kB
  • ctags: 5,947
  • sloc: perl: 29,224; cpp: 18,849; xml: 98; makefile: 91; sh: 4
file content (742 lines) | stat: -rw-r--r-- 25,407 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
#/***************************************************************************
#*   Copyright (C) 2007-2008 by Riccardo Iaconelli <riccardo@kde.org>      *
#*   Copyright (C) 2007-2008 by Sebastian Kuegler <sebas@kde.org>          *
#*   Copyright (C) 2009 by John Layt <john@layt.net>                       *
#*   Perl translation by Chris Burel <chrisburel@gmail.com>                *
#*                                                                         *
#*   This program is free software; you can redistribute it and/or modify  *
#*   it under the terms of the GNU General Public License as published by  *
#*   the Free Software Foundation; either version 2 of the License, or     *
#*   (at your option) any later version.                                   *
#*                                                                         *
#*   This program is distributed in the hope that it will be useful,       *
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
#*   GNU General Public License for more details.                          *
#*                                                                         *
#*   You should have received a copy of the GNU General Public License     *
#*   along with this program; if not, write to the                         *
#*   Free Software Foundation, Inc.,                                       *
#*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
#***************************************************************************/

package ClockApplet::Private;

use strict;
use warnings;

use KDEUi4;
use Plasma4;
use Ui_GeneralConfig;
use Ui_TimezonesConfig;
use Qt4::GlobalSpace qw( i18n );

sub new {
    my ( $class, $clockapplet ) = @_;
    my $self = bless {
        q => $clockapplet,
        timezone => ClockApplet::localTimezoneUntranslated(),
        clipboardMenu => 0,
        adjustSystemTimeAction => 0,
        label => 0,
        calendarWidget => 0,
        forceTzDisplay => 0,
    }, $class;
    return $self;
}

=begin

    ClockApplet *q;
    Ui::timezonesConfig ui;
    Ui::generalConfig generalUi;
    Qt4::String timezone;
    Qt4::String defaultTimezone;
    Qt4::Point clicked;
    Qt4::StringList selectedTimezones;
    KDE::Menu *clipboardMenu;
    Qt4::Action *adjustSystemTimeAction;
    Qt4::String prettyTimezone;
    Plasma::Label *label;
    Plasma::Calendar *calendarWidget;
    int announceInterval;
    int prevHour;
    int prevMinute;
    bool forceTzDisplay : 1;

=cut

sub addTzToTipText
{
    my ($self, $subText, $tz) = @_;
    my $data = $self->{q}->dataEngine('time')->query($$tz);

    if ($$tz eq 'UTC')  {
        $$subText .= '<br><b>UTC</b>&nbsp;';
    } else {
        my $tzCity = $data->{'Timezone City'};
        $tzCity =~ s/_/&nbsp;/g;
        $$subText .= '<br><b>' .
            $tzCity .
            '</b> ';
    }

    my $formatTime = KDE::Global::locale()->formatTime($data->{'Time'}->toTime(), 0);
    $formatTime =~ s/ /&nbsp;/g;
    #my $formatDate = $self->{q}->calendar()->formatDate($data->{'Date'}->toDate());
    #$formatDate =~ s/ /&nbsp;/g;
    $$subText .= $formatTime .
           ',&nbsp;';
           #$formatDate;
}

sub createCalendarExtender
{
    my ($self) = @_;
    #if (!$self->{q}->extender()->hasItem('calendar')) {
        #my $eItem = Plasma::ExtenderItem($self->{q}->extender());
        #$eItem->setName('calendar');
        #$self->{q}->initExtenderItem($eItem);
    #}
}

sub createToday
{
    my ($self) = @_;
    #my $tmpStr = 'isHoliday:' . $self->{calendarWidget}->holidaysRegion() . ':' . Qt4::Date::currentDate().toString(Qt4::ISODate());
    #my $isHoliday = $self->{q}->dataEngine('calendar')->query($tmpStr)->value($tmpStr)->toBool();
#
    #my $todayExtender = $self->{q}->extender()->item('today');
#
    #if (!$todayExtender && $isHoliday) {
        #my $eItem = Plasma::ExtenderItem($self->{q}->extender());
        #$eItem->setName('today');
        #$self->{q}->initExtenderItem($eItem);

    #} elsif ($todayExtender && !$isHoliday) {
        #$todayExtender->destroy();
    #}
}

sub createDateExtender
{
    my ($self, $date) = @_;
    my $eItem = Plasma::ExtenderItem($self->{q}->extender());
    $eItem->setName('dateExtender-' . $date->toString(Qt4::ISODate()));
    $self->{q}->initExtenderItem($eItem);
}

sub destroyDateExtenders
{
    my ($self) = @_;
    my $extenders = $self->{q}->extender()->items();
    foreach my $eItem ( @{$extenders} ) {
        if ( $eItem->name() =~ m/^dateExtender-/ && !$eItem->isDetached()){
            $eItem->destroy();
        }
    }
}

sub setPrettyTimezone
{
    my ($self) = @_;
    my $timezonetranslated = i18n($self->{timezone});
    my $prettyTimezone;
    if ($self->{timezone} eq 'UTC')  {
        $prettyTimezone = $timezonetranslated;
    } elsif (!$self->{q}->isLocalTimezone()) {
        my @tzParts = split /\//, $timezonetranslated;
        if (scalar @tzParts == 1) {
            $prettyTimezone = $timezonetranslated;
        } else {
            $prettyTimezone = $tzParts[-1];
        }
    } else {
        $prettyTimezone = $self->{q}->localTimezone();
    }

    $prettyTimezone =~ s/_/ /g;
    $self->{prettyTimezone} = $prettyTimezone; 
}

package ClockApplet;

use strict;
use warnings;

use QtCore4;
use KDEUi4;
use Plasma4;
use Qt4::isa qw( Plasma::PopupApplet );
use Qt4::GlobalSpace qw( i18n i18nc );

use Qt4::slots
    toolTipAboutToShow => [],
    toolTipHidden => [],
    setCurrentTimezone => ['const QString &'],
    configAccepted => [],
    updateClockDefaultsTo => [],
    dateChanged => ['const Qt4::Date &'],
    speakTime => ['const Qt4::Time &'],
    launchTimeControlPanel => [],
    updateClipboardMenu => [],
    copyToClipboard => ['Qt4::Action*'],
    createCalendarExtender => [],
    createToday => [];

sub NEW {
    my ( $class, $parent, $args ) = @_;
    $class->SUPER::NEW( $parent, $args );
    this->{d} = ClockApplet::Private->new(this);
    this->setPopupIcon(Qt4::Icon());
    this->setPassivePopup(1);
}

sub speakTime
{
    my ($time) = @_;
    print "SpeakTime function not implemented\n";
    return;

=begin

    if (!d->announceInterval) {
        return;
    }

    if (time.minute() != d->prevMinute && (time.minute() % d->announceInterval) == 0) {
        d->prevHour = time.hour();
        d->prevMinute = time.minute();

        # If KDE::TTSD not running, start it.
        if (!Qt4::DBusConnection::sessionBus().interface()->isServiceRegistered('org.kde.kttsd')) {
            Qt4::String error;
            if (KDE::ToolInvocation::startServiceByDesktopName('kttsd', Qt4::StringList(), &error)) {
                KDE::MessageBox::error(0, i18n( 'Starting KDE::TTSD Failed'), error );
                return;
            }
        }

        Qt4::DBusInterface ktts('org.kde.kttsd', '/KDE::Speech', 'org.kde.KDE::Speech');
        ktts.asyncCall('setApplicationName', 'plasmaclock');
        Qt4::String text;
        if (time.minute() == 0) {
            if (KDE::Global::locale()->use12Clock()) {
                if (time.hour() < 12) {
                    text = i18ncp('Text sent to the text to speech service '
                                     'when minutes==0 and it is AM',
                                 'It is 1 o clock a m',
                                 'It is %1 o clock a m',
                                 time.hour());
                } else {
                    text = i18ncp('Text sent to the text to speech service '
                                     'when minutes==0 and it is PM',
                                 'It is 1 o clock p m',
                                 'It is %1 o clock p m',
                                 time.hour()-12);
                }
            } else {
                text = i18ncp('Text sent to the text to speech service '
                                 'when minutes==0 and it is the 24 hour clock',
                                 'It is 1 o clock',
                                 'It is %1 o clock',
                                 time.hour());
            }
        } else {
            if (KDE::Global::locale()->use12Clock()) {
                if (time.hour() < 12) {
                    text = i18nc('Text sent to the text to speech service for AM',
                                'It is %1:%2 a m',
                                time.hour(),
                                time.minute());
                } else {
                    text = i18nc('Text sent to the text to speech service for PM',
                                'It is %1:%2 p m',
                                time.hour()-12,
                                time.minute());
                }
            } else {
                text = i18nc('Text sent to the text to speech service for the 24 hour clock',
                                'It is %1:%2',
                                time.hour(),
                                time.minute());
            }
        }
        ktts.asyncCall('say', text, 0);
    }

=cut

}

sub toolTipAboutToShow
{
    this->updateTipContent();
}

sub toolTipHidden
{
    Plasma::ToolTipManager::self()->clearContent(this);
}

sub updateTipContent
{
    my $tipData = Plasma::ToolTipContent();

    # the main text contains the current timezone's time and date
    my $data = this->dataEngine('time')->query(this->currentTimezone());
    my $mainText = this->{d}->{prettyTimezone} . ' ';
    $mainText .= KDE::Global::locale()->formatTime($data->{'Time'}->toTime(), 0) . '<br>';
    my $tipDate = $data->{'Date'}->toDate();
    #$mainText .= this->calendar()->formatDate($tipDate);
    $tipData->setMainText($mainText);

    my $subText;
    if (!this->isLocalTimezone()) {
        this->{d}->addTzToTipText($subText, \this->localTimezone());
    }

    foreach my $tz ( @{this->getSelectedTimezones()} ) {
        if ($tz eq this->currentTimezone()) {
            next;
        }

        this->{d}->addTzToTipText($subText, \$tz);
    }

    #my $property = this->{d}->{calendarWidget}->dateProperty($tipDate);
    #if ($property) {
        #my $countryString = KDE::Global::locale()->countryCodeToName(this->{d}->{calendarWidget}->holidaysRegion());
        #if (!$countryString) {
            #$subText .= '<br>' . $property;
        #} else {
            #$subText .= '<br><b>' . $countryString . '</b> ' . $property;
        #}
    #}

    $tipData->setSubText($subText);

    # query for custom content
    my $customContent = this->toolTipContent();
    if ($customContent->image()->isNull()) {
        #$tipData->setImage(KDE::Icon(this->icon())->pixmap(IconSize(KDE::IconLoader::Desktop)));
        $tipData->setImage(KDE::Icon(this->icon())->pixmap(KDE::IconLoader::Desktop()));
    } else {
        $tipData->setImage($customContent->image());
    }

    if ($customContent->mainText()) {
        # add their main text
        $tipData->setMainText($customContent->mainText() . '<br>' . $tipData->mainText());
    }

    if ($customContent->subText()) {
        # add their sub text
        $tipData->setSubText($customContent->subText() . '<br>' . $tipData->subText());
    }

    $tipData->setAutohide(0);
    Plasma::ToolTipManager::self()->setContent(this, $tipData);
}

sub toolTipContent
{
    return Plasma::ToolTipContent();
}

sub createConfigurationInterface
{
    my ($parent) = @_;
    this->createClockConfigurationInterface($parent);

    my $generalWidget = Qt4::Widget();
    this->{d}->{generalUi} = Ui_GeneralConfig->setupUi($generalWidget);
    $parent->addPage($generalWidget, i18nc('General configuration page', 'General'), Plasma::Applet::icon());
    this->{d}->{generalUi}->interval->setValue(this->{d}->{announceInterval});

    #this->{d}->{calendarWidget}->createConfigurationInterface($parent);

    my $widget = Qt4::Widget();
    this->{d}->{ui} = Ui_TimezonesConfig->setupUi($widget);
    this->{d}->{ui}->searchLine->addTreeWidget(this->{d}->{ui}->timeZones);

    $parent->addPage($widget, i18n('Time Zones'), 'preferences-desktop-locale');

    foreach my $tz ( @{this->{d}->{selectedTimezones}} ) {
        this->{d}->{ui}->timeZones->setSelected($tz, 1);
    }

    this->updateClockDefaultsTo();
    my $defaultSelection = this->{d}->{ui}->clockDefaultsTo->findData(Qt4::Variant(this->{d}->{defaultTimezone}));
    if ($defaultSelection < 0) {
        $defaultSelection = 0; #if it's something unexpected default to local
        #kDebug() << this->{d}->defaultTimezone << 'not in list!?';
    }
    this->{d}->{ui}->clockDefaultsTo->setCurrentIndex($defaultSelection);

    $parent->setButtons( ${KDE::Dialog::Ok()} | ${KDE::Dialog::Cancel()} | ${KDE::Dialog::Apply()} );
    this->connect($parent, SIGNAL 'applyClicked()', this, SLOT 'configAccepted()');
    this->connect($parent, SIGNAL 'okClicked()', this, SLOT 'configAccepted()');
    this->connect(this->{d}->{ui}->timeZones, SIGNAL 'itemChanged(QTreeWidgetItem*,int)', this, SLOT 'updateClockDefaultsTo()');
}

sub createClockConfigurationInterface
{
    my ($parent) = @_;
}

sub clockConfigAccepted
{

}

sub configAccepted
{
    my $cg = this->config();

    this->{d}->{selectedTimezones} = this->{d}->{ui}->timeZones->selection();
    $cg->writeEntry('timeZones', this->{d}->{selectedTimezones});

    if (this->{d}->{ui}->clockDefaultsTo->currentIndex() == 0) {
        #The first position in {ui}->clockDefaultsTo is 'Local'
        this->{d}->{defaultTimezone} = this->localTimezoneUntranslated();
    } else {
        this->{d}->{defaultTimezone} = this->{d}->{ui}->clockDefaultsTo->itemData(this->{d}->{ui}->clockDefaultsTo->currentIndex())->value();
    }

    $cg->writeEntry('defaultTimezone', this->{d}->{defaultTimezone});
    my $cur = this->currentTimezone();
    this->setCurrentTimezone(this->{d}->{defaultTimezone});
    this->changeEngineTimezone($cur, this->{d}->{defaultTimezone});

    #this->{d}->{calendarWidget}->configAccepted($cg);

    this->{d}->{announceInterval} = this->{d}->{generalUi}->interval->value();
    $cg->writeEntry('announceInterval', this->{d}->{announceInterval});

    this->clockConfigAccepted();
    this->constraintsEvent(Plasma::SizeConstraint());
    this->update();

    emit this->configNeedsSaving();
}

sub updateClockDefaultsTo
{
    my $oldSelection = this->{d}->{ui}->clockDefaultsTo->currentText();
    this->{d}->{ui}->clockDefaultsTo->clear();
    this->{d}->{ui}->clockDefaultsTo->addItem(this->localTimezone(), Qt4::Variant(this->localTimezone()));
    foreach my $tz ( @{this->{d}->{ui}->timeZones->selection()} ) {
        this->{d}->{ui}->clockDefaultsTo->addItem(KDE::TimeZoneWidget::displayName(KDE::TimeZone($tz)), Qt4::Variant($tz));
    }
    my $newPosition = this->{d}->{ui}->clockDefaultsTo->findText($oldSelection);
    if ($newPosition >= 0) {
        this->{d}->{ui}->clockDefaultsTo->setCurrentIndex($newPosition);
    }
    if (this->{d}->{ui}->clockDefaultsTo->count() > 1) {
        this->{d}->{ui}->clockDefaultsTo->setEnabled(1);
    } else {
        # Only 'Local' in {ui}->clockDefaultsTo
        this->{d}->{ui}->clockDefaultsTo->setEnabled(0);
    }
}

sub changeEngineTimezone
{
    my ($oldTimezone, $newTimezone) = @_;
    # reimplemented by subclasses to get the new data
}

sub shouldDisplayTimezone
{
    return this->{d}->{forceTzDisplay};
}

sub contextualActions
{
    if (!this->{d}->{clipboardMenu}) {
        this->{d}->{clipboardMenu} = KDE::Menu(i18n('C&opy to Clipboard'));
        this->{d}->{clipboardMenu}->setIcon(KDE::Icon('edit-copy'));
        this->connect(this->{d}->{clipboardMenu}, SIGNAL 'aboutToShow()', this, SLOT 'updateClipboardMenu()');
        this->connect(this->{d}->{clipboardMenu}, SIGNAL 'triggered(QAction*)', this, SLOT 'copyToClipboard(QAction*)');

        my $offers = KDE::ServiceTypeTrader::self()->query('KDE::CModule', 'Library == \'kcm_clock\'');
        if ($offers && this->hasAuthorization('LaunchApp')) {
            this->{d}->{adjustSystemTimeAction} = Qt4::Action(this);
            this->{d}->{adjustSystemTimeAction}->setText(i18n('Adjust Date and Time'));
            this->{d}->{adjustSystemTimeAction}->setIcon(KDE::Icon('preferences-system-time'));
            this->connect(this->{d}->{adjustSystemTimeAction}, SIGNAL 'triggered()', this, SLOT 'launchTimeControlPanel()');
        }
    }

    my $contextualActions = [this->{d}->{clipboardMenu}->menuAction()];

    if (this->{d}->{adjustSystemTimeAction}) {
        push @{$contextualActions},  this->{d}->{adjustSystemTimeAction};
    }
    return $contextualActions;
}

sub launchTimeControlPanel
{
    my $offers = KDE::ServiceTypeTrader::self()->query('KDE::CModule', 'Library == \'kcm_clock\'');
    if (!$offers) {
        #kDebug() << 'fail';
        return;
    }

    my $urls = KDE::Url::List();
    my $service = $offers->[0];
    KDE::Run::run($service, $urls, 0);
}

sub wheelEvent
{
    my ($event) = @_;
    if ( scalar @{this->{d}->{selectedTimezones}} < 1) {
        return;
    }

    my $newTimezone;

    if (this->isLocalTimezone()) {
        if ($event->delta() > 0) {
            $newTimezone = this->{d}->{selectedTimezones}->[-1];
        } else {
            $newTimezone = this->{d}->{selectedTimezones}->[0];
        }
    } else {
        #my $current = this->{d}->{selectedTimezones}->indexOf(currentTimezone());
        my @selectedTimezones = @{this->{d}->{selectedTimezones}};
        my ($current) = grep{ $selectedTimezones[$_] eq this->currentTimezone() } ( 0..$#selectedTimezones );

        if ($event->delta() > 0) {
            my $previous = $current - 1;
            if ($previous < 0) {
                $newTimezone = this->localTimezoneUntranslated();
            } else {
                $newTimezone = this->{d}->{selectedTimezones}->[$previous];
            }
        } else {
            my $next = $current + 1;
            if ($next > @selectedTimezones - 1) {
                $newTimezone = this->localTimezoneUntranslated();
            } else {
                $newTimezone = this->{d}->{selectedTimezones}->[$next];
            }
        }
    }

    my $cur = this->currentTimezone();
    this->setCurrentTimezone($newTimezone);
    this->changeEngineTimezone($cur, $newTimezone);
    this->update();
}

sub initExtenderItem
{
    my ($item) = @_;
    if ($item->name() == 'calendar') {
        $item->setTitle(i18n('Calendar'));
        $item->setIcon('view-pim-calendar');
        #$item->setWidget(this->{d}->{calendarWidget});
    } elsif ($item->name() eq 'today') {
        $item->setTitle(i18n('Today'));
        $item->setIcon('view-pim-calendar');
        this->{d}->{label} = Plasma::Label();
        $item->setWidget(this->{d}->{label});
    } elsif ($item->name() =~ m/^dateExtender/) {
        $item->setIcon('view-pim-calendar');
        $item->showCloseButton();
        my $date = Qt4::Date::fromString(substr( $item->name(), 13), Qt4::ISODate());
        my $widget;

        #$item->setTitle(this->calendar()->formatDate($date));
        #$widget = DateExtenderWidget(this->{d}->{calendarWidget}->dateProperty($date));

        $item->setWidget($widget);
    }
}

sub init
{
    my $cg = this->config();
    # Make it call the QStringList copy of readEntry() by making an array ref
    # of an empty QString.
    this->{d}->{selectedTimezones} = $cg->readEntry(Qt4::String('timeZones'), [Qt4::String('')]);
    this->{d}->{selectedTimezones} = [this->localTimezoneUntranslated()]
        if this->{d}->{selectedTimezones}->[0] eq '';
    this->{d}->{timezone} = $cg->readEntry(Qt4::String('timezone'), Qt4::String(this->{d}->{timezone}));
    this->{d}->{defaultTimezone} = $cg->readEntry(Qt4::String('defaultTimezone'), Qt4::String(this->{d}->{timezone}));
    this->{d}->{forceTzDisplay} = this->{d}->{timezone} ne this->{d}->{defaultTimezone};

    this->{d}->setPrettyTimezone();

    this->{d}->{announceInterval} = $cg->readEntry(Qt4::String('announceInterval'), Qt4::String(''));

    Plasma::ToolTipManager::self()->registerWidget(this);

    #this->{d}->{calendarWidget} = Plasma::Calendar();
    #this->{d}->{calendarWidget}->setMinimumSize(Qt4::Size(230, 220));
    #this->{d}->{calendarWidget}->setDataEngine(this->dataEngine('calendar'));
    #this->connect(this->{d}->{calendarWidget}, SIGNAL 'dateChanged(const QDate &)', this, SLOT 'dateChanged(const QDate &)');
    #this->{d}->{calendarWidget}->applyConfiguration($cg);
    my $data = this->dataEngine('time')->query(this->currentTimezone());
    #this->{d}->{calendarWidget}->setDate($data->{'Date'}->toDate());
    #this->{d}->createCalendarExtender();

    this->extender();
    Qt4::Timer::singleShot(0, this, SLOT 'createToday()');
}

sub popupEvent
{
    my ($show) = @_;
    if (!$show) {
        return;
    }

    my $data = this->dataEngine('time')->query(this->currentTimezone());
    #this->{d}->{calendarWidget}->setDate($data->{'Date'}->toDate());

    this->{d}->destroyDateExtenders();
}

sub constraintsEvent
{
    my ($constraints) = @_;
    if ($constraints & Plasma::FormFactorConstraint()) {
        this->setPassivePopup(this->formFactor() == Plasma::Horizontal() || this->formFactor() == Plasma::Vertical());
    }
}

sub setCurrentTimezone
{
    my ($tz) = @_;
    if (this->{d}->{timezone} eq $tz) {
        return;
    }

    if ($tz eq this->localTimezone()) {
        # catch people accidentally passing in the translation of 'Local'
        this->{d}->{timezone} = this->localTimezoneUntranslated();
    } else {
        this->{d}->{timezone} = $tz;
    }

    this->{d}->{forceTzDisplay} = this->{d}->{timezone} ne this->{d}->{defaultTimezone};
    this->{d}->setPrettyTimezone();

    my $cg = this->config();
    $cg->writeEntry('timezone', this->{d}->{timezone});
    emit this->configNeedsSaving();
}

sub currentTimezone
{
    return this->{d}->{timezone};
}

sub prettyTimezone
{
    return this->{d}->{prettyTimezone};
}

sub getSelectedTimezones
{
    return this->{d}->{selectedTimezones};
}

sub isLocalTimezone
{
    return this->{d}->{timezone} eq this->localTimezoneUntranslated();
}

sub localTimezone
{
    return i18nc('Local time zone', 'Local');
}

sub localTimezoneUntranslated
{
    return 'Local';
}

sub dateChanged
{
    my ($date) = @_;
    this->{d}->destroyDateExtenders();

    #if (this->{d}->{calendarWidget}->dateProperty($date)) {
        #this->{d}->createDateExtender($date);
    #}
}

sub updateClipboardMenu
{
    this->{d}->{clipboardMenu}->clear();
    my $actions;
    my $data = this->dataEngine('time')->query(this->currentTimezone());
    my $dateTime = Qt4::DateTime($data->{'Date'}->toDate(), $data->{'Time'}->toTime());

    #this->{d}->{clipboardMenu}->addAction(this->calendar()->formatDate($dateTime->date(), KDE::Locale::LongDate()));
    #this->{d}->{clipboardMenu}->addAction(this->calendar()->formatDate($dateTime->date(), KDE::Locale::ShortDate()));
    # Display ISO Date format if not already displayed
    if (KDE::Global::locale()->dateFormatShort() ne '%Y-%m-%d') {
        #this->{d}->{clipboardMenu}->addAction(this->calendar()->formatDate($dateTime->date(), '%Y-%m-%d'));
    }

    my $sep0 = Qt4::Action(this);
    $sep0->setSeparator(1);
    this->{d}->{clipboardMenu}->addAction($sep0);

    this->{d}->{clipboardMenu}->addAction(KDE::Global::locale()->formatTime($dateTime->time(), 0));
    this->{d}->{clipboardMenu}->addAction(KDE::Global::locale()->formatTime($dateTime->time(), 1));

    my $sep1 = Qt4::Action(this);
    $sep1->setSeparator(1);
    this->{d}->{clipboardMenu}->addAction($sep1);

    my $tempLocale = KDE::Locale(KDE::Global::locale());
    #$tempLocale->setCalendar(this->calendar()->calendarType());
    #this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::LongDate()));
    #this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::LongDate(), 1));
    #this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::ShortDate()));
    #this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::ShortDate(), 1));
    # Display ISO DateTime format if not already displayed
    #if ($tempLocale->dateFormatShort() ne '%Y-%m-%d') {
        #$tempLocale->setDateFormatShort('%Y-%m-%d');
        #this->{d}->{clipboardMenu}->addAction($tempLocale->formatDateTime($dateTime, KDE::Locale::ShortDate(), 1));
    #}

    my $sep2 = Qt4::Action(this);
    $sep2->setSeparator(1);
    this->{d}->{clipboardMenu}->addAction($sep2);

    #my $calendars = KDE::CalendarSystem::calendarSystems();
    #foreach my $cal ( @{$calendars} ) {
        #if ($cal ne this->calendar()->calendarType()) {
            #my $tempCal = KDE::CalendarSystem::create($cal);
            #my $text = $tempCal->formatDate($dateTime->date(), KDE::Locale::LongDate()) . ' (' . KDE::CalendarSystem::calendarLabel($cal) . ')';
            #this->{d}->{clipboardMenu}->addAction($text);
            #$text = $tempCal->formatDate($dateTime->date(), KDE::Locale::ShortDate()) . ' (' . KDE::CalendarSystem::calendarLabel($cal) . ')';
            #this->{d}->{clipboardMenu}->addAction($text);
        #}
    #}
}

sub copyToClipboard
{
    my ($action) = @_;
    my $text = $action->text();
    $text =~ s/&//g;

    Qt4::Application::clipboard()->setText($text);
}

sub calendar
{
    #return this->{d}->{calendarWidget}->calendar();
}

1;