~ubuntu-branches/ubuntu/oneiric/kde-workspace/oneiric

« back to all changes in this revision

Viewing changes to libs/plasmaclock/clockapplet.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2011-09-25 00:42:41 UTC
  • Revision ID: package-import@ubuntu.com-20110925004241-c5ck55dokn3yt1kg
Tags: 4:4.7.1-0ubuntu3
* Update debian/kdm.upstart to match latest gdm.upstart improvements:
  - Also export LC_MESSAGES with the rest of locale information
  - When kdm is shut down by a runlevel call, emit an upstart event that can
    be caught by plymouth so it can distinguish between the DM shutting down
    for a runlevel change vs. other causes (LP: #854329)
* Update patches for post-4.7.1 changes.  Add to debian/patches:
    0001-SVN_SILENT-made-messages-.desktop-file.patch
    0003-SVN_SILENT-made-messages-.desktop-file.patch
    0004-SVN_SILENT-made-messages-.desktop-file.patch
    0005-SVN_SILENT-made-messages-.desktop-file.patch
    0006-preferred-app-launchers-need-to-use-the-type-of-the-.patch
    0007-SVN_SILENT-made-messages-.desktop-file.patch
    0009-SVN_SILENT-made-messages-.desktop-file.patch
    0010-add-some-missing-connects-for-the-ruleswidget.patch
    0011-fix-yet-another-fun-with-pointers-tabbing-segfault.patch
    0013-catch-changeMaximize-recursion-from-setNoBorder.patch
    0014-Clear-thumbnails-for-deleted-windows.patch
    0015-Fix-pointer-accesses-in-tiling-code.patch
    0016-SVN_SILENT-made-messages-.desktop-file.patch
    0017-SVN_SILENT-made-messages-.desktop-file.patch
    0018-SVN_SILENT-made-messages-.desktop-file.patch
    0019-Test-for-widget-creation-before-deleting-property-at.patch
    0020-SVN_SILENT-made-messages-.desktop-file.patch
    0023-fix-kiosk-restrictions-for-user-switching-and-logout.patch
    0024-Fix-typo-use-the-right-signal-signature.patch
    0025-Repaint-old-area-of-the-thumbnail.patch
    0026-Use-Client-layoutMetric-to-access-shadowSize-instead.patch
    0027-ShowCalendarPopup-false-suppresses-calendar-popup-an.patch
    0028-show-the-keyboard-on-immediately-entering-a-text-are.patch
    0029-Repaint-the-whole-window-in-the-taskbar-thumbnail.patch
    0030-SVN_SILENT-made-messages-.desktop-file.patch
    0031-Fix-wrong-inital-tab-in-keyboard-kcm.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
 
119
119
    void createCalendarExtender()
120
120
    {
121
 
        if (!q->extender()->hasItem("calendar")) {
122
 
            Plasma::ExtenderItem *eItem = new Plasma::ExtenderItem(q->extender());
123
 
            eItem->setName("calendar");
124
 
            q->initExtenderItem(eItem);
125
 
        }
126
 
    }
127
 
 
128
 
    void createToday()
129
 
    {
130
 
        QString tmpStr = "isHoliday" + QString(':') + calendarWidget->holidaysRegions().join(QString(','))
131
 
                                     + QString(':') + QDate::currentDate().toString(Qt::ISODate);
132
 
        bool isHoliday = q->dataEngine("calendar")->query(tmpStr).value(tmpStr).toBool();
133
 
 
134
 
        Plasma::ExtenderItem *todayExtender = q->extender()->item("today");
135
 
 
136
 
        if (!todayExtender && isHoliday) {
137
 
            Plasma::ExtenderItem *eItem = new Plasma::ExtenderItem(q->extender());
138
 
            eItem->setName("today");
139
 
            q->initExtenderItem(eItem);
140
 
        } else if (todayExtender && !isHoliday) {
141
 
            todayExtender->destroy();
 
121
        const bool hasExtender = q->extender()->hasItem("calendar");
 
122
 
 
123
        if (q->config().readEntry("ShowCalendarPopup", true)) {
 
124
            if (!hasExtender) {
 
125
                Plasma::ExtenderItem *eItem = new Plasma::ExtenderItem(q->extender());
 
126
                eItem->setName("calendar");
 
127
                q->initExtenderItem(eItem);
 
128
            }
 
129
        } else {
 
130
            q->extender()->deleteLater();
 
131
            calendarWidget = 0;
142
132
        }
143
133
    }
144
134
 
319
309
 
320
310
void ClockApplet::updateClockApplet(const Plasma::DataEngine::Data &data)
321
311
{
322
 
    bool updateSelectedDate = (d->calendarWidget->currentDate() == d->calendarWidget->date());
323
 
    d->calendarWidget->setCurrentDate(data["Date"].toDate());
 
312
    if (d->calendarWidget) {
 
313
        bool updateSelectedDate = (d->calendarWidget->currentDate() == d->calendarWidget->date());
 
314
        d->calendarWidget->setCurrentDate(data["Date"].toDate());
324
315
 
325
 
    if (updateSelectedDate){
326
 
        d->calendarWidget->setDate(d->calendarWidget->currentDate());
 
316
        if (updateSelectedDate){
 
317
            d->calendarWidget->setDate(d->calendarWidget->currentDate());
 
318
        }
327
319
    }
328
320
 
329
321
    const QTime t = d->lastTimeSeen;
357
349
    parent->addPage(generalWidget, i18nc("General configuration page", "General"), Applet::icon());
358
350
    d->generalUi.interval->setValue(d->announceInterval);
359
351
 
360
 
    d->calendarWidget->createConfigurationInterface(parent);
 
352
    if (d->calendarWidget) {
 
353
        d->calendarWidget->createConfigurationInterface(parent);
 
354
    }
361
355
 
362
356
    QWidget *widget = new QWidget();
363
357
    d->timezonesUi.setupUi(widget);
395
389
 
396
390
void ClockApplet::configChanged()
397
391
{
 
392
    d->createCalendarExtender();
 
393
 
398
394
    if (isUserConfiguring()) {
399
395
        configAccepted();
400
396
    }
412
408
    if (isUserConfiguring()) {
413
409
        constraintsEvent(Plasma::SizeConstraint);
414
410
        update();
415
 
    } else {
 
411
    } else if (d->calendarWidget) {
416
412
        // d->calendarWidget->configAccepted(cg); is called in configAccepted(), 
417
413
        // as is setCurrentTimezone
418
414
        // so we only need to do this in the case where the user hasn't been
446
442
    setCurrentTimezone(d->defaultTimezone);
447
443
    changeEngineTimezone(cur, d->defaultTimezone);
448
444
 
449
 
    d->calendarWidget->configAccepted(cg);
 
445
    if (d->calendarWidget) {
 
446
        d->calendarWidget->configAccepted(cg);
 
447
    }
450
448
 
451
449
    cg.writeEntry("announceInterval", d->generalUi.interval->value());
452
450
 
569
567
void ClockApplet::initExtenderItem(Plasma::ExtenderItem *item)
570
568
{
571
569
    if (item->name() == "calendar") {
 
570
        if (!d->calendarWidget) {
 
571
            d->calendarWidget = new Plasma::Calendar();
 
572
            d->calendarWidget->setAutomaticUpdateEnabled(false);
 
573
            d->calendarWidget->setMinimumSize(QSize(230, 220));
 
574
        }
 
575
 
572
576
        item->setTitle(i18n("Calendar"));
573
577
        item->setIcon("view-pim-calendar");
574
578
        item->setWidget(d->calendarWidget);
575
 
    } else if (item->name() == "today") {
576
 
        item->setTitle(i18n("Today"));
577
 
        item->setIcon("view-pim-calendar");
578
 
        d->label = new Plasma::Label();
579
 
        item->setWidget(d->label);
580
579
    }
581
580
}
582
581
 
583
582
void ClockApplet::init()
584
583
{
 
584
    configChanged();
585
585
    Plasma::ToolTipManager::self()->registerWidget(this);
586
 
 
587
 
    d->calendarWidget = new Plasma::Calendar();
588
 
    d->calendarWidget->setAutomaticUpdateEnabled(false);
589
 
    d->calendarWidget->setMinimumSize(QSize(230, 220));
590
 
    d->createCalendarExtender();
591
 
 
592
 
    extender();
593
 
 
594
 
    configChanged();
595
 
    QTimer::singleShot(0, this, SLOT(createToday()));
596
586
}
597
587
 
598
588
void ClockApplet::focusInEvent(QFocusEvent* event)
599
589
{
600
590
    Q_UNUSED(event);
601
 
    d->calendarWidget->setFlag(QGraphicsItem::ItemIsFocusable);
602
 
    d->calendarWidget->setFocus();
 
591
    if (d->calendarWidget) {
 
592
        d->calendarWidget->setFlag(QGraphicsItem::ItemIsFocusable);
 
593
        d->calendarWidget->setFocus();
 
594
    }
603
595
}
604
596
 
605
597
void ClockApplet::popupEvent(bool show)
606
598
{
607
 
    if (!show) {
608
 
        return;
 
599
    if (show && d->calendarWidget) {
 
600
        Plasma::DataEngine::Data data = dataEngine("time")->query(currentTimezone());
 
601
        d->calendarWidget->setDate(data["Date"].toDate());
609
602
    }
610
 
 
611
 
    Plasma::DataEngine::Data data = dataEngine("time")->query(currentTimezone());
612
 
    d->calendarWidget->setDate(data["Date"].toDate());
613
603
}
614
604
 
615
605
void ClockApplet::constraintsEvent(Plasma::Constraints constraints)
633
623
    d->forceTzDisplay = d->timezone != d->defaultTimezone;
634
624
    d->setPrettyTimezone();
635
625
 
636
 
    Plasma::DataEngine::Data data = dataEngine("time")->query(d->timezone);
637
 
    d->calendarWidget->setDate(data["Date"].toDate());
 
626
    if (d->calendarWidget) {
 
627
        Plasma::DataEngine::Data data = dataEngine("time")->query(d->timezone);
 
628
        d->calendarWidget->setDate(data["Date"].toDate());
 
629
    }
638
630
 
639
631
    KConfigGroup cg = config();
640
632
    cg.writeEntry("timezone", d->timezone);
697
689
    d->clipboardMenu->addAction(sep1);
698
690
 
699
691
    KLocale tempLocale(*KGlobal::locale());
700
 
    tempLocale.setCalendar(calendar()->calendarType());
 
692
    tempLocale.setCalendarSystem(calendar()->calendarSystem());
701
693
    d->clipboardMenu->addAction(tempLocale.formatDateTime(dateTime, KLocale::LongDate));
702
694
    d->clipboardMenu->addAction(tempLocale.formatDateTime(dateTime, KLocale::LongDate, true));
703
695
    d->clipboardMenu->addAction(tempLocale.formatDateTime(dateTime, KLocale::ShortDate));
713
705
    d->clipboardMenu->addAction(sep2);
714
706
 
715
707
    QMenu *calendarMenu = d->clipboardMenu->addMenu( i18nc( "@item:inmenu Submenu for alternative calendar dates", "Other Calendars" ) );
716
 
    QStringList calendars = KCalendarSystem::calendarSystems();
717
 
    foreach ( const QString &cal, calendars ) {
718
 
        if (cal != calendar()->calendarType()) {
 
708
    QList<KLocale::CalendarSystem> calendars = KCalendarSystem::calendarSystemsList();
 
709
    foreach (const KLocale::CalendarSystem &cal, calendars) {
 
710
        if (cal != calendar()->calendarSystem()) {
719
711
            KCalendarSystem *tempCal = KCalendarSystem::create(cal);
720
712
            QString text = tempCal->formatDate(dateTime.date(), KLocale::LongDate) + " (" + KCalendarSystem::calendarLabel(cal) + ')';
721
713
            calendarMenu->addAction(text);
736
728
 
737
729
const KCalendarSystem *ClockApplet::calendar() const
738
730
{
739
 
    return d->calendarWidget->calendar();
 
731
    if (d->calendarWidget) {
 
732
        return d->calendarWidget->calendar();
 
733
    } else {
 
734
        return KGlobal::locale()->calendar();
 
735
    }
740
736
}
741
737
 
742
738
#include "clockapplet.moc"