diff --git a/kcontrol/dateandtime/main.cpp b/kcontrol/dateandtime/main.cpp index f6746ece..d05d5c45 100644 --- a/kcontrol/dateandtime/main.cpp +++ b/kcontrol/dateandtime/main.cpp @@ -112,8 +112,11 @@ void KclockModule::save() } else { // explicit load() in case its not the timezone that is changed load(); + // not watched for +#if 0 QDBusMessage msg = QDBusMessage::createSignal("/org/kde/kcmshell_clock", "org.kde.kcmshell_clock", "clockUpdated"); QDBusConnection::sessionBus().send(msg); +#endif } } diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 9e425a61..6769a7be 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -6,7 +6,6 @@ include_directories( add_subdirectory(konq) add_subdirectory(kworkspace) add_subdirectory(oxygen) -add_subdirectory(plasmaclock) add_subdirectory(plasmagenericshell) add_subdirectory(ksysguard) diff --git a/libs/plasmaclock/CMakeLists.txt b/libs/plasmaclock/CMakeLists.txt deleted file mode 100644 index 6f2ef176..00000000 --- a/libs/plasmaclock/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -set(plasmaclock_LIB_SRCS - clockapplet.cpp - calendar.cpp - wheelytoolbutton.cpp - timezonesConfig.ui -) - -add_library(plasmaclock SHARED ${plasmaclock_LIB_SRCS}) - -target_link_libraries(plasmaclock - KDE4::plasma - KDE4::kdeui - KDE4::kio -) - -set_target_properties(plasmaclock PROPERTIES - VERSION ${GENERIC_LIB_VERSION} - SOVERSION ${GENERIC_LIB_SOVERSION} -) - -generate_export_header(plasmaclock) - -#clockapplet.h -install( - FILES - clockapplet.h - calendar.h - ${CMAKE_CURRENT_BINARY_DIR}/plasmaclock_export.h - DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/plasmaclock -) -install( - TARGETS plasmaclock - EXPORT kdeworkspaceTargets - DESTINATION ${KDE4_LIB_INSTALL_DIR} -) diff --git a/libs/plasmaclock/Messages.sh b/libs/plasmaclock/Messages.sh deleted file mode 100755 index 890d2750..00000000 --- a/libs/plasmaclock/Messages.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -$EXTRACTRC *.ui >> rc.cpp -$XGETTEXT *.cpp -o $podir/libplasmaclock.pot -rm -f rc.cpp diff --git a/libs/plasmaclock/calendar.cpp b/libs/plasmaclock/calendar.cpp deleted file mode 100644 index bfdf6555..00000000 --- a/libs/plasmaclock/calendar.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2008,2010 Davide Bettio - * Copyright 2009 John Layt - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 Library 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. - */ - -#include "calendar.h" - -//Qt -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//KDECore -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//Plasma -#include -#include -#include -#include -#include -#include -#include -#include - -#include "wheelytoolbutton.h" - -namespace Plasma -{ - -static const int s_yearWidgetIndex = 3; - -class CalendarPrivate -{ - public: - CalendarPrivate(Calendar *calendar) - : q(calendar), - calendarWidget(nullptr), - layout(nullptr), - currentDate(QDate::currentDate()) - { - } - - void init(const QDate &date = QDate()); - void popupMonthsMenu(); - void updateSize(); - - Calendar *q; - Plasma::CalendarWidget *calendarWidget; - QGraphicsLinearLayout *layout; - QDate currentDate; -}; - -Calendar::Calendar(const QDate &date, QGraphicsWidget *parent) - : QGraphicsWidget(parent), - d(new CalendarPrivate(this)) -{ - d->init(date); -} - -Calendar::Calendar(QGraphicsWidget *parent) - : QGraphicsWidget(parent), - d(new CalendarPrivate(this)) -{ - d->init(); -} - -Calendar::~Calendar() -{ - delete d; -} - -void CalendarPrivate::init(const QDate &initialDate) -{ - q->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - - layout = new QGraphicsLinearLayout(Qt::Horizontal, q); - - calendarWidget = new CalendarWidget(q); - calendarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - QObject::connect(calendarWidget, SIGNAL(clicked(QDate)), q, SLOT(dateUpdated())); - QObject::connect(calendarWidget, SIGNAL(activated(QDate)), q, SLOT(dateUpdated())); - - layout->addItem(calendarWidget); - - q->setDate(initialDate); - updateSize(); -} - -void Calendar::focusInEvent(QFocusEvent* event) -{ - Q_UNUSED(event); - d->calendarWidget->setFocus(); -} - -void Calendar::setDate(const QDate &toDate) -{ - // New date must be valid one - if (!toDate.isValid()) { - if (!toDate.isNull()) { - KNotification::beep(); - } - return; - } - - // If new date is the same as old date don't actually need to do anything - if (toDate == d->currentDate) { - return; - } - - d->calendarWidget->setSelectedDate(toDate); -} - -QDate Calendar::date() const -{ - return d->calendarWidget->selectedDate(); -} - -void Calendar::setCurrentDate(const QDate &date) -{ - d->currentDate = date; -} - -QDate Calendar::currentDate() const -{ - return d->currentDate; -} - -void CalendarPrivate::updateSize() -{ - QSize minSize = QSize(300, 250); - QSize prefSize = calendarWidget ? calendarWidget->size().toSize() : QSize(300, 250); - - q->setMinimumSize(minSize); - q->setPreferredSize(prefSize); -} - -void Calendar::dateUpdated() -{ - emit dateChanged(date()); -} - -} - -#include "moc_calendar.cpp" diff --git a/libs/plasmaclock/calendar.h b/libs/plasmaclock/calendar.h deleted file mode 100644 index 3c3ec8b1..00000000 --- a/libs/plasmaclock/calendar.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2008,2010 Davide Bettio - * Copyright 2009 John Layt - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 Library 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. - */ - -#ifndef PLASMA_CALENDAR_H -#define PLASMA_CALENDAR_H - -#include - -#include "plasmaclock_export.h" - -class KConfigDialog; -class KConfigGroup; - -namespace Plasma -{ - -class CalendarPrivate; -class DataEngine; - -class PLASMACLOCK_EXPORT Calendar : public QGraphicsWidget -{ - Q_OBJECT - -public: - explicit Calendar(QGraphicsWidget *parent = 0); - explicit Calendar(const QDate &, QGraphicsWidget *parent = 0); - ~Calendar(); - - void setAutomaticUpdateEnabled(bool automatic); - bool isAutomaticUpdateEnabled() const; - - void setDate(const QDate &date); - QDate date() const; - - void setCurrentDate(const QDate &date); - QDate currentDate() const; - -Q_SIGNALS: - void dateChanged(const QDate &newDate, const QDate &oldDate); - void dateChanged(const QDate &newDate); - -protected: - void focusInEvent(QFocusEvent* event); - -private Q_SLOTS: - void dateUpdated(); - -private: - CalendarPrivate* const d; -}; - -} - -#endif diff --git a/libs/plasmaclock/clockapplet.cpp b/libs/plasmaclock/clockapplet.cpp deleted file mode 100644 index d54513b9..00000000 --- a/libs/plasmaclock/clockapplet.cpp +++ /dev/null @@ -1,603 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 by Riccardo Iaconelli * - * Copyright (C) 2007-2008 by Sebastian Kuegler * - * Copyright (C) 2008-2009 by Davide Bettio * - * Copyright (C) 2009 by John Layt * - * * - * 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 . * - ***************************************************************************/ - -#include "clockapplet.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "calendar.h" - -#include "ui_timezonesConfig.h" - -class ClockApplet::Private -{ -public: - Private(ClockApplet *clockapplet) - : q(clockapplet), - timezone(ClockApplet::localTimezoneUntranslated()), - clipboardMenu(nullptr), - adjustSystemTimeAction(nullptr), - label(nullptr), - calendarWidget(nullptr), - forceTzDisplay(false) - {} - - ClockApplet *q; - Ui::timezonesConfig timezonesUi; - QString timezone; - QString defaultTimezone; - QPoint clicked; - QStringList selectedTimezones; - KMenu *clipboardMenu; - QAction *adjustSystemTimeAction; - QString prettyTimezone; - Plasma::Label *label; - Plasma::Calendar *calendarWidget; - QTime lastTimeSeen; - bool forceTzDisplay; - - QDate addTzToTipText(QString &subText, const Plasma::DataEngine::Data &data, const QDate &prevDate, bool highlight) - { - const QDate date = data["Date"].toDate(); - // show the date if it is different from the previous date in its own row - if (date != prevDate) { - subText.append(" ") - .append("") - .append(KGlobal::locale()->formatDate(data["Date"].toDate()).replace(' ', " ")) - .append(""); - } - - // start the row - subText.append(""); - - // put the name of the city in the first cell - // highlight the name of the place if requested - subText.append(highlight ? "" : ""); - subText.append(data["Timezone City"].toString().replace('_', " ")); - subText.append(':').append(highlight ? "" : ""); - - // now the time - subText.append("") - .append(KGlobal::locale()->formatTime(data["Time"].toTime()).replace(' ', " ")) - .append(""); - - // and close out the row. - subText.append(""); - return date; - } - - void createCalendar() - { - if (q->config().readEntry("ShowCalendarPopup", true)) { - if (!calendarWidget) { - calendarWidget = new Plasma::Calendar(); - calendarWidget->setFlag(QGraphicsItem::ItemIsFocusable); - } - } else { - delete calendarWidget; - calendarWidget = 0; - } - - q->setGraphicsWidget(calendarWidget); - } - - void setPrettyTimezone() - { - QString timezonetranslated = i18n(timezone.toUtf8().data()); - if (timezone == "UTC") { - prettyTimezone = timezonetranslated; - } else if (!q->isLocalTimezone()) { - QStringList tzParts = timezonetranslated.split('/', QString::SkipEmptyParts); - if (tzParts.count() == 1) { - prettyTimezone = timezonetranslated; - } else if (tzParts.count() > 0) { - prettyTimezone = tzParts.last(); - } else { - prettyTimezone = timezonetranslated; - } - } else { - prettyTimezone = localTimezone(); - } - - prettyTimezone = prettyTimezone.replace('_', ' '); - } -}; - -ClockApplet::ClockApplet(QObject *parent, const QVariantList &args) - : Plasma::PopupApplet(parent, args), - d(new Private(this)) -{ - setPopupIcon(QIcon()); -} - -ClockApplet::~ClockApplet() -{ - delete d->clipboardMenu; - delete d; -} - -void ClockApplet::toolTipAboutToShow() -{ - updateTipContent(); -} - -void ClockApplet::toolTipHidden() -{ - Plasma::ToolTipManager::self()->clearContent(this); -} - -//bool sortTzByData(const Plasma::DataEngine::Data &left, const Plasma::DataEngine::Data &right) -bool sortTzByData(const QHash &left, const QHash &right) -{ - const int leftOffset = left.value("Offset").toInt(); - const int rightOffset = right.value("Offset").toInt(); - if (leftOffset == rightOffset) { - return left.value("Timezone City").toString() < right.value("Timezone City").toString(); - } - - return leftOffset < rightOffset; -} - -void ClockApplet::updateTipContent() -{ - Plasma::ToolTipContent tipData; - - QString subText(""); - QList tzs; - Plasma::DataEngine *engine = dataEngine("time"); - Plasma::DataEngine::Data data = engine->query("Local"); - const QString localTz = data["Timezone"].toString(); - tzs.append(data); - bool highlightLocal = false; - - tipData.setMainText(i18n("Current Time")); - - foreach (const QString &tz, d->selectedTimezones) { - if (tz != "UTC") { - highlightLocal = true; - } - - if (tz != localTz) { - data = engine->query(tz); - tzs.append(data); - } - } - - qSort(tzs.begin(), tzs.end(), sortTzByData); - QDate currentDate; - foreach (const Plasma::DataEngine::Data &data, tzs) { - bool shouldHighlight = highlightLocal && (data["Timezone"].toString() == localTz); - currentDate = d->addTzToTipText(subText, data, currentDate, shouldHighlight); - } - - subText.append("
"); - - tipData.setSubText(subText); - - // query for custom content - Plasma::ToolTipContent customContent = toolTipContent(); - if (!customContent.image().isNull()) { - tipData.setImage(customContent.image()); - } - - if (!customContent.mainText().isEmpty()) { - // add their main text - tipData.setMainText(customContent.mainText()); - } - - if (!customContent.subText().isEmpty()) { - // add their sub text - tipData.setSubText(customContent.subText() + "
" + tipData.subText()); - } - - tipData.setAutohide(false); - Plasma::ToolTipManager::self()->setContent(this, tipData); -} - -void ClockApplet::updateClockApplet() -{ - Plasma::DataEngine::Data data = dataEngine("time")->query(currentTimezone()); - updateClockApplet(data); -} - -void ClockApplet::updateClockApplet(const Plasma::DataEngine::Data &data) -{ - if (d->calendarWidget) { - d->calendarWidget->setDate(data["Date"].toDate()); - } - - d->lastTimeSeen = data["Time"].toTime(); -} - -QTime ClockApplet::lastTimeSeen() const -{ - return d->lastTimeSeen; -} - -void ClockApplet::resetLastTimeSeen() -{ - d->lastTimeSeen = QTime(); -} - -Plasma::ToolTipContent ClockApplet::toolTipContent() -{ - return Plasma::ToolTipContent(); -} - -void ClockApplet::createConfigurationInterface(KConfigDialog *parent) -{ - createClockConfigurationInterface(parent); - - QWidget *widget = new QWidget(); - d->timezonesUi.setupUi(widget); - d->timezonesUi.searchLine->addTreeWidget(d->timezonesUi.timeZones); - - parent->addPage(widget, i18n("Time Zones"), "preferences-desktop-locale"); - - foreach (const QString &tz, d->selectedTimezones) { - d->timezonesUi.timeZones->setSelected(tz, true); - } - - updateClockDefaultsTo(); - int defaultSelection = d->timezonesUi.clockDefaultsTo->findData(d->defaultTimezone); - if (defaultSelection < 0) { - defaultSelection = 0; //if it's something unexpected default to local - //kDebug() << d->defaultTimezone << "not in list!?"; - } - d->timezonesUi.clockDefaultsTo->setCurrentIndex(defaultSelection); - - connect(d->timezonesUi.timeZones, SIGNAL(itemChanged(QTreeWidgetItem*,int)), parent, SLOT(settingsModified())); - connect(d->timezonesUi.timeZones, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(updateClockDefaultsTo())); - connect(d->timezonesUi.clockDefaultsTo,SIGNAL(activated(QString)), parent, SLOT(settingsModified())); -} - -void ClockApplet::createClockConfigurationInterface(KConfigDialog *parent) -{ - Q_UNUSED(parent) -} - -void ClockApplet::clockConfigChanged() -{ - -} - -void ClockApplet::configChanged() -{ - d->createCalendar(); - - if (isUserConfiguring()) { - configAccepted(); - } - - KConfigGroup cg = config(); - d->selectedTimezones = cg.readEntry("timeZones", QStringList() << "UTC"); - d->timezone = cg.readEntry("timezone", d->timezone); - d->defaultTimezone = cg.readEntry("defaultTimezone", d->timezone); - d->forceTzDisplay = d->timezone != d->defaultTimezone; - d->setPrettyTimezone(); - - clockConfigChanged(); - - if (isUserConfiguring()) { - constraintsEvent(Plasma::SizeConstraint); - update(); - } else if (d->calendarWidget) { - // setCurrentTimezone() is called in configAccepted(), - // so we only need to do this in the case where the user hasn't been - // configuring things - Plasma::DataEngine::Data data = dataEngine("time")->query(d->timezone); - d->calendarWidget->setDate(data["Date"].toDate()); - } -} - -void ClockApplet::clockConfigAccepted() -{ - -} - -void ClockApplet::configAccepted() -{ - KConfigGroup cg = config(); - - cg.writeEntry("timeZones", d->timezonesUi.timeZones->selection()); - - if (d->timezonesUi.clockDefaultsTo->currentIndex() == 0) { - //The first position in timezonesUi.clockDefaultsTo is "Local" - d->defaultTimezone = localTimezoneUntranslated(); - } else { - d->defaultTimezone = d->timezonesUi.clockDefaultsTo->itemData(d->timezonesUi.clockDefaultsTo->currentIndex()).toString(); - } - - cg.writeEntry("defaultTimezone", d->defaultTimezone); - QString cur = currentTimezone(); - setCurrentTimezone(d->defaultTimezone); - changeEngineTimezone(cur, d->defaultTimezone); - - clockConfigAccepted(); - - emit configNeedsSaving(); -} - -void ClockApplet::updateClockDefaultsTo() -{ - QString oldSelection = d->timezonesUi.clockDefaultsTo->currentText(); - d->timezonesUi.clockDefaultsTo->clear(); - d->timezonesUi.clockDefaultsTo->addItem(localTimezone(), localTimezone()); - foreach(const QString &tz, d->timezonesUi.timeZones->selection()) { - d->timezonesUi.clockDefaultsTo->addItem(KTimeZoneWidget::displayName(KTimeZone(tz)), tz); - } - int newPosition = d->timezonesUi.clockDefaultsTo->findText(oldSelection); - if (newPosition >= 0) { - d->timezonesUi.clockDefaultsTo->setCurrentIndex(newPosition); - } - if (d->timezonesUi.clockDefaultsTo->count() > 1) { - d->timezonesUi.clockDefaultsTo->setEnabled(true); - } else { - // Only "Local" in timezonesUi.clockDefaultsTo - d->timezonesUi.clockDefaultsTo->setEnabled(false); - } -} - -void ClockApplet::changeEngineTimezone(const QString &oldTimezone, const QString &newTimezone) -{ - // reimplemented by subclasses to get the new data - Q_UNUSED(oldTimezone); - Q_UNUSED(newTimezone); -} - -bool ClockApplet::shouldDisplayTimezone() const -{ - return d->forceTzDisplay; -} - -QList ClockApplet::contextualActions() -{ - if (!d->clipboardMenu) { - d->clipboardMenu = new KMenu(i18n("C&opy to Clipboard")); - d->clipboardMenu->setIcon(KIcon("edit-copy")); - connect(d->clipboardMenu, SIGNAL(aboutToShow()), this, SLOT(updateClipboardMenu())); - connect(d->clipboardMenu, SIGNAL(triggered(QAction*)), this, SLOT(copyToClipboard(QAction*))); - - KService::List offers = KServiceTypeTrader::self()->query("KCModule", "Library == 'kcm_clock'"); - if (!offers.isEmpty()) { - d->adjustSystemTimeAction = new QAction(this); - d->adjustSystemTimeAction->setText(i18n("Adjust Date and Time...")); - d->adjustSystemTimeAction->setIcon(KIcon(icon())); - connect(d->adjustSystemTimeAction, SIGNAL(triggered()), this, SLOT(launchTimeControlPanel())); - } - } - - QList contextualActions; - contextualActions << d->clipboardMenu->menuAction(); - - if (d->adjustSystemTimeAction) { - contextualActions << d->adjustSystemTimeAction; - } - return contextualActions; -} - -void ClockApplet::launchTimeControlPanel() -{ - KService::List offers = KServiceTypeTrader::self()->query("KCModule", "Library == 'kcm_clock'"); - if (offers.isEmpty()) { - kDebug() << "fail"; - return; - } - - KUrl::List urls; - KService::Ptr service = offers.first(); - KRun::run(*service, urls, 0); -} - -void ClockApplet::wheelEvent(QGraphicsSceneWheelEvent *event) -{ - if (d->selectedTimezones.isEmpty()) { - return; - } - - QString newTimezone; - - if (isLocalTimezone()) { - if (event->delta() > 0) { - newTimezone = d->selectedTimezones.last(); - } else { - newTimezone = d->selectedTimezones.first(); - } - } else { - int current = d->selectedTimezones.indexOf(currentTimezone()); - - if (event->delta() > 0) { - int previous = current - 1; - if (previous < 0) { - newTimezone = localTimezoneUntranslated(); - } else { - newTimezone = d->selectedTimezones.at(previous); - } - } else { - int next = current + 1; - if (next > d->selectedTimezones.count() - 1) { - newTimezone = localTimezoneUntranslated(); - } else { - newTimezone = d->selectedTimezones.at(next); - } - } - } - - QString cur = currentTimezone(); - setCurrentTimezone(newTimezone); - changeEngineTimezone(cur, newTimezone); - update(); -} - -void ClockApplet::init() -{ - configChanged(); - Plasma::ToolTipManager::self()->registerWidget(this); -} - -void ClockApplet::focusInEvent(QFocusEvent* event) -{ - Q_UNUSED(event); - if (d->calendarWidget) { - d->calendarWidget->setFocus(); - } -} - -void ClockApplet::popupEvent(bool show) -{ - if (show && d->calendarWidget) { - Plasma::DataEngine::Data data = dataEngine("time")->query(currentTimezone()); - const QDate date = data["Date"].toDate(); - d->calendarWidget->setCurrentDate(date.addDays(-1)); - d->calendarWidget->setDate(date); - d->calendarWidget->setCurrentDate(date); - } -} - -void ClockApplet::constraintsEvent(Plasma::Constraints constraints) -{ - Q_UNUSED(constraints) -} - -void ClockApplet::setCurrentTimezone(const QString &tz) -{ - if (d->timezone == tz) { - return; - } - - if (tz == localTimezone()) { - // catch people accidentally passing in the translation of "Local" - d->timezone = localTimezoneUntranslated(); - } else { - d->timezone = tz; - } - - d->forceTzDisplay = d->timezone != d->defaultTimezone; - d->setPrettyTimezone(); - - if (d->calendarWidget) { - Plasma::DataEngine::Data data = dataEngine("time")->query(d->timezone); - d->calendarWidget->setDate(data["Date"].toDate()); - } - - KConfigGroup cg = config(); - cg.writeEntry("timezone", d->timezone); - emit configNeedsSaving(); -} - -QString ClockApplet::currentTimezone() const -{ - return d->timezone; -} - -QString ClockApplet::prettyTimezone() const -{ - return d->prettyTimezone; -} - -bool ClockApplet::isLocalTimezone() const -{ - return d->timezone == localTimezoneUntranslated(); -} - -QString ClockApplet::localTimezone() -{ - return i18nc("Local time zone", "Local"); -} - -QString ClockApplet::localTimezoneUntranslated() -{ - return "Local"; -} - -void ClockApplet::updateClipboardMenu() -{ - d->clipboardMenu->clear(); - QList actions; - Plasma::DataEngine::Data data = dataEngine("time")->query(currentTimezone()); - QDateTime dateTime = QDateTime(data["Date"].toDate(), data["Time"].toTime()); - - d->clipboardMenu->addAction(KGlobal::locale()->formatDate(dateTime.date(), QLocale::LongFormat)); - d->clipboardMenu->addAction(KGlobal::locale()->formatDate(dateTime.date(), QLocale::ShortFormat)); - - QAction *sep0 = new QAction(this); - sep0->setSeparator(true); - d->clipboardMenu->addAction(sep0); - - d->clipboardMenu->addAction(KGlobal::locale()->formatTime(dateTime.time(), QLocale::LongFormat)); - d->clipboardMenu->addAction(KGlobal::locale()->formatTime(dateTime.time(), QLocale::ShortFormat)); - - QAction *sep1 = new QAction(this); - sep1->setSeparator(true); - d->clipboardMenu->addAction(sep1); - - d->clipboardMenu->addAction(KGlobal::locale()->formatDateTime(dateTime, QLocale::LongFormat)); - d->clipboardMenu->addAction(KGlobal::locale()->formatDateTime(dateTime, QLocale::ShortFormat)); - d->clipboardMenu->addAction(KGlobal::locale()->formatDateTime(dateTime, QLocale::NarrowFormat)); - - QAction *sep2 = new QAction(this); - sep2->setSeparator(true); - d->clipboardMenu->addAction(sep2); -} - -void ClockApplet::copyToClipboard(QAction* action) -{ - QString text = action->text(); - text.remove(QChar('&')); - - QApplication::clipboard()->setText(text); -} - -#include "moc_clockapplet.cpp" diff --git a/libs/plasmaclock/clockapplet.h b/libs/plasmaclock/clockapplet.h deleted file mode 100644 index cefa2b66..00000000 --- a/libs/plasmaclock/clockapplet.h +++ /dev/null @@ -1,98 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 by Riccardo Iaconelli * - * Copyright (C) 2007-2008 by Sebastian Kuegler * - * Copyright (C) 2009 by John Layt * - * * - * 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 . * - ***************************************************************************/ - -#ifndef CLOCKAPPLET_H -#define CLOCKAPPLET_H - -#include -#include - -#include -#include -#include -#include - -#include "plasmaclock_export.h" - -class KDialog; -class KConfigDialog; - -namespace Plasma -{ - class Svg; -} - -class PLASMACLOCK_EXPORT ClockApplet : public Plasma::PopupApplet -{ - Q_OBJECT - public: - ClockApplet(QObject *parent, const QVariantList &args); - ~ClockApplet(); - - void init(); - - QString currentTimezone() const; - QString prettyTimezone() const; - bool isLocalTimezone() const; - bool shouldDisplayTimezone() const; - QList contextualActions(); - - static QString localTimezone(); - static QString localTimezoneUntranslated(); - - public Q_SLOTS: - void configChanged(); - void toolTipAboutToShow(); - void toolTipHidden(); - - protected: - virtual void createClockConfigurationInterface(KConfigDialog *parent); - virtual void clockConfigChanged(); - virtual void clockConfigAccepted(); - virtual void changeEngineTimezone(const QString &oldTimezone, const QString &newTimezone); - virtual Plasma::ToolTipContent toolTipContent(); - void wheelEvent(QGraphicsSceneWheelEvent *event); - void createConfigurationInterface(KConfigDialog *parent); - void updateTipContent(); - void updateClockApplet(); - void updateClockApplet(const Plasma::DataEngine::Data &data); - void popupEvent(bool show); - void constraintsEvent(Plasma::Constraints constraints); - QTime lastTimeSeen() const; - void resetLastTimeSeen(); - void focusInEvent(QFocusEvent * event); - - protected Q_SLOTS: - void setCurrentTimezone(const QString &tz); - void configAccepted(); - void updateClockDefaultsTo(); - void launchTimeControlPanel(); - - private Q_SLOTS: - void updateClipboardMenu(); - void copyToClipboard(QAction* action); - - private: - class Private; - Private * const d; -}; - -#endif diff --git a/libs/plasmaclock/timezonesConfig.ui b/libs/plasmaclock/timezonesConfig.ui deleted file mode 100644 index fc2276ac..00000000 --- a/libs/plasmaclock/timezonesConfig.ui +++ /dev/null @@ -1,122 +0,0 @@ - - - timezonesConfig - - - - 0 - 0 - 318 - 227 - - - - - - - false - - - Search - - - - - - - - 300 - 150 - - - - Select one or several time zones. - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Your <span style=" font-weight:600;">Local</span> time and time zone are defined in System Settings, in the Date and Time tab. As default, your plasma clock will use this setting.</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The plasma clock tooltip can display the time in several other time zones: to do so, select one or several more time zones in the list. Click on a line to select it and click on it again to deselect it. </p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">After you validate your choices with the OK button, when your mouse is over the clock, a tooltip will display the time in all the selected time zones.</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">To select a <span style=" font-weight:600;">Default</span> time zone: you can either scroll over the clock with your mouse wheel and set the one you want or you can set it with "Clock defaults to:". .</p></body></html> - - - QAbstractItemView::MultiSelection - - - true - - - - Area - - - - - Region - - - - - Comment - - - - - - - - - - Clock defaults to: - - - clockDefaultsTo - - - - - - - - 0 - 0 - - - - The time the clock will display - - - The clock will display the time for the selected default zone. -Local is the time you set in System Settings. - - - QComboBox::InsertAlphabetically - - - - - - - - - - KTimeZoneWidget - QTreeWidget -
ktimezonewidget.h
-
- - KTreeWidgetSearchLine - KLineEdit -
ktreewidgetsearchline.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
-
- -
diff --git a/libs/plasmaclock/wheelytoolbutton.cpp b/libs/plasmaclock/wheelytoolbutton.cpp deleted file mode 100644 index ed1653c3..00000000 --- a/libs/plasmaclock/wheelytoolbutton.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2010 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 Library 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. - */ - -#include "wheelytoolbutton.h" - -#include - -WheelyToolButton::WheelyToolButton(QGraphicsWidget *parent) - : Plasma::ToolButton(parent) -{ -} - -void WheelyToolButton::wheelEvent(QGraphicsSceneWheelEvent *event) -{ - if (event->delta() > 0) { - emit wheelUp(); - } else { - emit wheelDown(); - } -} - -#include "moc_wheelytoolbutton.cpp" - diff --git a/libs/plasmaclock/wheelytoolbutton.h b/libs/plasmaclock/wheelytoolbutton.h deleted file mode 100644 index f061a489..00000000 --- a/libs/plasmaclock/wheelytoolbutton.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, 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 Library 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. - */ - -#ifndef WHEELYTOOLBUTTON -#define WHEELYTOOLBUTTON - -#include - -class WheelyToolButton : public Plasma::ToolButton -{ - Q_OBJECT - -public: - WheelyToolButton(QGraphicsWidget *parent); - -protected: - void wheelEvent(QGraphicsSceneWheelEvent *event); - -Q_SIGNALS: - void wheelUp(); - void wheelDown(); -}; - -#endif - diff --git a/plasma/applets/CMakeLists.txt b/plasma/applets/CMakeLists.txt index 0c89ac40..62d88d0f 100644 --- a/plasma/applets/CMakeLists.txt +++ b/plasma/applets/CMakeLists.txt @@ -1,7 +1,6 @@ add_subdirectory(icon) add_subdirectory(lockout) add_subdirectory(panelspacer) -add_subdirectory(analog-clock) add_subdirectory(batterymonitor) add_subdirectory(calendar) add_subdirectory(calculator) diff --git a/plasma/applets/analog-clock/CMakeLists.txt b/plasma/applets/analog-clock/CMakeLists.txt deleted file mode 100644 index 732418ac..00000000 --- a/plasma/applets/analog-clock/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -include_directories( - # for plasmaclock_export.h - ${CMAKE_BINARY_DIR}/libs/plasmaclock -) - -set(clock_SRCS - clock.cpp - clockConfig.ui -) - -kde4_add_plugin(plasma_applet_clock ${clock_SRCS}) -target_link_libraries(plasma_applet_clock - KDE4::plasma - KDE4::kio - plasmaclock -) - -install(TARGETS plasma_applet_clock DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}) -install(FILES plasma-applet-analogclock.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR}) diff --git a/plasma/applets/analog-clock/Messages.sh b/plasma/applets/analog-clock/Messages.sh deleted file mode 100644 index 27d166fc..00000000 --- a/plasma/applets/analog-clock/Messages.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -$EXTRACTRC *.ui >> rc.cpp -$XGETTEXT *.cpp -o $podir/plasma_applet_clock.pot -rm -f rc.cpp - diff --git a/plasma/applets/analog-clock/clock.cpp b/plasma/applets/analog-clock/clock.cpp deleted file mode 100644 index 1ca1da4f..00000000 --- a/plasma/applets/analog-clock/clock.cpp +++ /dev/null @@ -1,472 +0,0 @@ -/*************************************************************************** - * Copyright 2007 by Aaron Seigo * - * Copyright 2007 by Riccardo Iaconelli * - * * - * 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 . * - ***************************************************************************/ - -#include "clock.h" - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -Clock::Clock(QObject *parent, const QVariantList &args) - : ClockApplet(parent, args), - m_showSecondHand(false), - m_showTimezoneString(false), - m_showingTimezone(false), - m_tzFrame(0), - m_repaintCache(RepaintAll), - m_faceCache(QPixmap()), - m_handsCache(QPixmap()), - m_glassCache(QPixmap()), - m_secondHandUpdateTimer(0), - m_animateSeconds(false) -{ - KGlobal::locale()->insertCatalog("libplasmaclock"); - // this catalog is only used once on the first start of the clock to translate the timezone in the configuration file - KGlobal::locale()->insertCatalog("timezones4"); - setHasConfigurationInterface(true); - resize(256, 256); - setAspectRatioMode(Plasma::Square); - setBackgroundHints(NoBackground); - - m_theme = new Plasma::Svg(this); - m_theme->setImagePath("widgets/clock"); - m_theme->setContainsMultipleImages(true); - m_theme->resize(size()); - - connect(m_theme, SIGNAL(repaintNeeded()), this, SLOT(repaintNeeded())); -} - -Clock::~Clock() -{ -} - -void Clock::init() -{ - ClockApplet::init(); - m_oldTimezone = currentTimezone(); - configChanged(); -} - -void Clock::connectToEngine() -{ - resetLastTimeSeen(); - - Plasma::DataEngine* timeEngine = dataEngine("time"); - timeEngine->disconnectSource(m_oldTimezone, this); - m_oldTimezone = currentTimezone(); - - if (m_showSecondHand) { - timeEngine->connectSource(currentTimezone(), this, 500); - } else { - timeEngine->connectSource(currentTimezone(), this, 60000, Plasma::AlignToMinute); - } -} - -void Clock::clockConfigChanged() -{ - KConfigGroup cg = config(); - m_showSecondHand = cg.readEntry("showSecondHand", false); - m_showTimezoneString = cg.readEntry("showTimezoneString", false); - m_showingTimezone = m_showTimezoneString; - m_fancyHands = cg.readEntry("fancyHands", false); - setCurrentTimezone(cg.readEntry("timezone", localTimezone())); - - if (m_showSecondHand) { - //We don't need to cache the applet if it update every seconds - setCacheMode(QGraphicsItem::NoCache); - } else { - setCacheMode(QGraphicsItem::DeviceCoordinateCache); - } - - connectToEngine(); - invalidateCache(); -} - -void Clock::constraintsEvent(Plasma::Constraints constraints) -{ - ClockApplet::constraintsEvent(constraints); - - if (constraints & Plasma::SizeConstraint) { - invalidateCache(); - } - - if (constraints & Plasma::FormFactorConstraint) { - if (formFactor() == Plasma::Planar || formFactor() == Plasma::MediaCenter) { - setPreferredSize(256, 256); - } else { - setPreferredSize(-1, -1); - } - } -} - -QPainterPath Clock::shape() const -{ - if (m_theme->hasElement("hint-square-clock")) { - return Applet::shape(); - } - - QPainterPath path; - // we adjust by 2px all around to allow for smoothing the jaggies - // if the ellipse is too small, we'll get a nastily jagged edge around the clock - path.addEllipse(boundingRect().adjusted(-2, -2, 2, 2)); - return path; -} - -void Clock::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data) -{ - Q_UNUSED(source); - m_time = data["Time"].toTime(); - - if (m_time.minute() != lastTimeSeen().minute() && m_repaintCache == RepaintNone) { - m_repaintCache = RepaintHands; - } - - if (Plasma::ToolTipManager::self()->isVisible(this)) { - updateTipContent(); - } - - if (m_secondHandUpdateTimer) { - m_secondHandUpdateTimer->stop(); - } - - m_animateSeconds = true; - - updateClockApplet(data); - update(); -} - -void Clock::createClockConfigurationInterface(KConfigDialog *parent) -{ - //TODO: Make the size settable - QWidget *widget = new QWidget(); - ui.setupUi(widget); - parent->addPage(widget, i18n("Appearance"), "view-media-visualization"); - - ui.showSecondHandCheckBox->setChecked(m_showSecondHand); - ui.showTimezoneStringCheckBox->setChecked(m_showTimezoneString); - - connect(ui.showSecondHandCheckBox, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); - connect(ui.showTimezoneStringCheckBox, SIGNAL(stateChanged(int)), parent, SLOT(settingsModified())); -} - -void Clock::clockConfigAccepted() -{ - KConfigGroup cg = config(); - m_showTimezoneString = ui.showTimezoneStringCheckBox->isChecked(); - m_showingTimezone = m_showTimezoneString || shouldDisplayTimezone(); - m_showSecondHand = ui.showSecondHandCheckBox->isChecked(); - - if (m_showSecondHand) { - //We don't need to cache the applet if it update every seconds - setCacheMode(QGraphicsItem::NoCache); - } else { - setCacheMode(QGraphicsItem::DeviceCoordinateCache); - } - - cg.writeEntry("showSecondHand", m_showSecondHand); - cg.writeEntry("showTimezoneString", m_showTimezoneString); - update(); - - dataEngine("time")->disconnectSource(currentTimezone(), this); - connectToEngine(); - - constraintsEvent(Plasma::AllConstraints); - emit configNeedsSaving(); -} - -void Clock::changeEngineTimezone(const QString &oldTimezone, const QString &newTimezone) -{ - dataEngine("time")->disconnectSource(oldTimezone, this); - Plasma::DataEngine* timeEngine = dataEngine("time"); - - if (m_showSecondHand) { - timeEngine->connectSource(newTimezone, this, 500); - } else { - timeEngine->connectSource(newTimezone, this, 60000, Plasma::AlignToMinute); - } - - if (m_showingTimezone != (m_showTimezoneString || shouldDisplayTimezone())) { - m_showingTimezone = !m_showingTimezone; - constraintsEvent(Plasma::SizeConstraint); - } - m_repaintCache = RepaintAll; -} - -void Clock::repaintNeeded() -{ - m_repaintCache = RepaintAll; - update(); -} - -void Clock::moveSecondHand() -{ - //kDebug() << "moving second hand"; - update(); -} - -void Clock::drawHand(QPainter *p, const QRect &rect, const qreal verticalTranslation, const qreal rotation, const QString &handName) -{ - // this code assumes the following conventions in the svg file: - // - the _vertical_ position of the hands should be set with respect to the center of the face - // - the _horizontal_ position of the hands does not matter - // - the _shadow_ elements should have the same vertical position as their _hand_ element counterpart - - QRectF elementRect; - QString name = handName + "HandShadow"; - if (m_theme->hasElement(name)) { - p->save(); - - elementRect = m_theme->elementRect(name); - if( rect.height() < KIconLoader::SizeEnormous ) - elementRect.setWidth( elementRect.width() * 2.5 ); - static const QPoint offset = QPoint(2, 3); - - p->translate(rect.x() + (rect.width() / 2) + offset.x(), rect.y() + (rect.height() / 2) + offset.y()); - p->rotate(rotation); - p->translate(-elementRect.width()/2, elementRect.y()-verticalTranslation); - m_theme->paint(p, QRectF(QPointF(0, 0), elementRect.size()), name); - - p->restore(); - } - - p->save(); - - name = handName + "Hand"; - elementRect = m_theme->elementRect(name); - if (rect.height() < KIconLoader::SizeEnormous) { - elementRect.setWidth(elementRect.width() * 2.5); - } - - p->translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2); - p->rotate(rotation); - p->translate(-elementRect.width()/2, elementRect.y()-verticalTranslation); - m_theme->paint(p, QRectF(QPointF(0, 0), elementRect.size()), name); - - p->restore(); -} - -void Clock::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &rect) -{ - Q_UNUSED(option) - - // compute hand angles - const qreal minutes = 6.0 * m_time.minute() - 180; - const qreal hours = 30.0 * m_time.hour() - 180 + - ((m_time.minute() / 59.0) * 30.0); - qreal seconds = 0; - if (m_showSecondHand) { - static const double anglePerSec = 6; - seconds = anglePerSec * m_time.second() - 180; - - if (m_fancyHands) { - if (!m_secondHandUpdateTimer) { - m_secondHandUpdateTimer = new QTimer(this); - connect(m_secondHandUpdateTimer, SIGNAL(timeout()), this, SLOT(moveSecondHand())); - } - - if (m_animateSeconds && !m_secondHandUpdateTimer->isActive()) { - //kDebug() << "starting second hand movement"; - m_secondHandUpdateTimer->start(50); - m_animationStart = QTime::currentTime().msec(); - } else { - static const int runTime = 500; - static const double m = 1; // Mass - static const double b = 1; // Drag coefficient - static const double k = 1.5; // Spring constant - static const double PI = 3.141592653589793; // the universe is irrational - static const double gamma = b / (2 * m); // Dampening constant - static const double omega0 = sqrt(k / m); - static const double omega1 = sqrt(omega0 * omega0 - gamma * gamma); - const double elapsed = QTime::currentTime().msec() - m_animationStart; - const double t = (4 * PI) * (elapsed / runTime); - const double val = 1 + exp(-gamma * t) * -cos(omega1 * t); - - if (elapsed > runTime) { - m_secondHandUpdateTimer->stop(); - m_animateSeconds = false; - } else { - seconds += -anglePerSec + (anglePerSec * val); - } - } - } else { - if (!m_secondHandUpdateTimer) { - m_secondHandUpdateTimer = new QTimer(this); - connect(m_secondHandUpdateTimer, SIGNAL(timeout()), this, SLOT(moveSecondHand())); - } - - if (m_animationStart != seconds && !m_secondHandUpdateTimer->isActive()) { - m_secondHandUpdateTimer->start(50); - m_animationStart = seconds; //we don't want to have a second animation if there is a external update (wallpaper etc). - seconds += 1; - } else { - m_secondHandUpdateTimer->stop(); - } - } - } - - if (contentsRect().size().toSize() != m_theme->size()) { - invalidateCache(); - } - - // paint face and glass cache - QRect faceRect = m_faceCache.rect(); - if (m_repaintCache == RepaintAll) { - m_faceCache.fill(Qt::transparent); - m_glassCache.fill(Qt::transparent); - - QPainter facePainter(&m_faceCache); - QPainter glassPainter(&m_glassCache); - facePainter.setRenderHint(QPainter::SmoothPixmapTransform); - glassPainter.setRenderHint(QPainter::SmoothPixmapTransform); - - m_theme->paint(&facePainter, faceRect, "ClockFace"); - - glassPainter.save(); - QRectF elementRect = QRectF(QPointF(0, 0), m_theme->elementSize("HandCenterScrew")); - glassPainter.translate(faceRect.width() / 2 - elementRect.width() / 2, faceRect.height() / 2 - elementRect.height() / 2); - m_theme->paint(&glassPainter, elementRect, "HandCenterScrew"); - glassPainter.restore(); - - m_theme->paint(&glassPainter, faceRect, "Glass"); - - // get vertical translation, see drawHand() for more details - m_verticalTranslation = m_theme->elementRect("ClockFace").center().y(); - } - - // paint hour and minute hands cache - if (m_repaintCache == RepaintHands || m_repaintCache == RepaintAll) { - m_handsCache.fill(Qt::transparent); - - QPainter handsPainter(&m_handsCache); - handsPainter.drawPixmap(faceRect, m_faceCache, faceRect); - handsPainter.setRenderHint(QPainter::SmoothPixmapTransform); - - drawHand(&handsPainter, faceRect, m_verticalTranslation, hours, "Hour"); - drawHand(&handsPainter, faceRect, m_verticalTranslation, minutes, "Minute"); - } - - // reset repaint cache flag - m_repaintCache = RepaintNone; - - // paint caches and second hand - QRect targetRect = faceRect; - if (targetRect.width() < rect.width()) { - targetRect.moveLeft((rect.width() - targetRect.width()) / 2); - } - targetRect.translate(rect.topLeft()); - - p->drawPixmap(targetRect, m_handsCache, faceRect); - if (m_showSecondHand) { - p->setRenderHint(QPainter::SmoothPixmapTransform); - drawHand(p, targetRect, m_verticalTranslation, seconds, "Second"); - } - p->drawPixmap(targetRect, m_glassCache, faceRect); - - // optionally paint the time string - if (m_showingTimezone) { - QString time = prettyTimezone(); - - if (!time.isEmpty()) { - QRect textRect = tzRect(time); - tzFrame()->paintFrame(p, textRect, QRect(QPoint(0, 0), textRect.size())); - - qreal left, top, right, bottom; - tzFrame()->getMargins(left, top, right, bottom); - - p->setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)); - p->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont)); - p->drawText(textRect.adjusted(left, 0, -right, 0), Qt::AlignCenter, time); - } - } -} - -QRect Clock::tzRect(const QString &text) -{ - QRect rect = contentsRect().toRect(); - - QFont font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont); - QFontMetrics fontMetrics(font); - - qreal left, top, right, bottom; - tzFrame()->getMargins(left, top, right, bottom); - - int width = left + right + fontMetrics.width(text) + fontMetrics.averageCharWidth() * 2; - int height = top + bottom + fontMetrics.height(); - width = qMin(width, rect.width()); - height = qMin(height, rect.height()); - - return QRect((rect.width() - width) / 2, rect.bottom() - height, width, height); -} - -Plasma::FrameSvg *Clock::tzFrame() -{ - if (!m_tzFrame) { - m_tzFrame = new Plasma::FrameSvg(this); - m_tzFrame->setImagePath("widgets/background"); - } - - return m_tzFrame; -} - -void Clock::invalidateCache() -{ - m_repaintCache = RepaintAll; - - QSize pixmapSize = contentsRect().size().toSize(); - const int squareEdge = qMin(pixmapSize.width(), pixmapSize.height()); - - if (m_showingTimezone) { - QRect tzArea = tzRect(prettyTimezone()); - pixmapSize.setHeight(qMax(10, squareEdge - tzArea.height())); - tzFrame()->resizeFrame(tzArea.size()); - } - - pixmapSize.setWidth(pixmapSize.height()); - m_faceCache = QPixmap(pixmapSize); - m_handsCache = QPixmap(pixmapSize); - m_glassCache = QPixmap(pixmapSize); - - m_faceCache.fill(Qt::transparent); - m_glassCache.fill(Qt::transparent); - m_handsCache.fill(Qt::transparent); - - m_theme->resize(pixmapSize); -} - -#include "moc_clock.cpp" diff --git a/plasma/applets/analog-clock/clock.h b/plasma/applets/analog-clock/clock.h deleted file mode 100644 index d32ffd31..00000000 --- a/plasma/applets/analog-clock/clock.h +++ /dev/null @@ -1,104 +0,0 @@ -/*************************************************************************** - * Copyright 2007 by Aaron Seigo * - * Copyright 2007 by Riccardo Iaconelli * - * * - * 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 . * - ***************************************************************************/ - -#ifndef CLOCK_H -#define CLOCK_H - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include "ui_clockConfig.h" - -#include - -namespace Plasma -{ - class FrameSvg; - class Svg; - class Dialog; -} - -class Clock : public ClockApplet -{ - Q_OBJECT - public: - Clock(QObject *parent, const QVariantList &args); - ~Clock(); - - void init(); - void constraintsEvent(Plasma::Constraints constraints); - QPainterPath shape() const; - void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect); - - public slots: - void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data); - - protected: - void createClockConfigurationInterface(KConfigDialog *parent); - void changeEngineTimezone(const QString &oldTimezone, const QString &newTimezone); - - protected slots: - void clockConfigAccepted(); - void clockConfigChanged(); - void repaintNeeded(); - void moveSecondHand(); - - private: - void connectToEngine(); - void drawHand(QPainter *p, const QRect &rect, const qreal verticalTranslation, const qreal rotation, const QString &handName); - QRect tzRect(const QString &text); - Plasma::FrameSvg *tzFrame(); - void invalidateCache(); - - QString m_oldTimezone; - bool m_showSecondHand; - bool m_fancyHands; - bool m_showTimezoneString; - bool m_showingTimezone; - Plasma::FrameSvg *m_tzFrame; - Plasma::Svg *m_theme; - QTime m_time; - enum RepaintCache { - RepaintNone, - RepaintAll, - RepaintHands - }; - RepaintCache m_repaintCache; - QPixmap m_faceCache; - QPixmap m_handsCache; - QPixmap m_glassCache; - qreal m_verticalTranslation; - QTimer *m_secondHandUpdateTimer; - bool m_animateSeconds; - int m_animationStart; - /// Designer Config file - Ui::clockConfig ui; -}; - -K_EXPORT_PLASMA_APPLET(clock, Clock) - -#endif diff --git a/plasma/applets/analog-clock/clockConfig.ui b/plasma/applets/analog-clock/clockConfig.ui deleted file mode 100644 index 8c04d678..00000000 --- a/plasma/applets/analog-clock/clockConfig.ui +++ /dev/null @@ -1,64 +0,0 @@ - - clockConfig - - - - 0 - 0 - 449 - 300 - - - - - 400 - 300 - - - - - - - Show the seconds - - - Check this if you want to show the seconds. - - - Show &seconds hand - - - - - - - Show the Timezone in text - - - Check this if you want to display Timezone in text. - - - Show &time zone - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 235 - - - - - - - - diff --git a/plasma/applets/analog-clock/plasma-applet-analogclock.desktop b/plasma/applets/analog-clock/plasma-applet-analogclock.desktop deleted file mode 100644 index 2cebfce2..00000000 --- a/plasma/applets/analog-clock/plasma-applet-analogclock.desktop +++ /dev/null @@ -1,165 +0,0 @@ -[Desktop Entry] -Name=Analog Clock -Name[af]=Analooghorlosie -Name[ar]=ساعة عادية -Name[ast]=Reló analóxicu -Name[be]=Аналагавы гадзіннік -Name[be@latin]=Analahavy hadzińnik -Name[bg]=Аналогов часовник -Name[bn]=অ্যানালগ ঘড়ি -Name[bs]=analogni sat -Name[ca]=Rellotge analògic -Name[ca@valencia]=Rellotge analògic -Name[cs]=Analogové hodiny -Name[csb]=Analogòwi zédżer -Name[da]=Analogt ur -Name[de]=Analoge Uhr -Name[el]=Αναλογικό ρολόι -Name[en_GB]=Analogue Clock -Name[eo]=Analoga horloĝo -Name[es]=Reloj analógico -Name[et]=Analoogkell -Name[eu]=Erloju analogikoa -Name[fa]=ساعت قیاسی -Name[fi]=Analoginen kello -Name[fr]=Horloge analogique -Name[fy]=Analoge klok -Name[ga]=Clog Analógach -Name[gl]=Reloxo analóxico -Name[gu]=સાદી ઘડિયાળ -Name[he]=שעון מחוגים -Name[hi]=एनॉलॉग घड़ी -Name[hne]=एनालाग घड़ी -Name[hr]=Analogni sat -Name[hsb]=Analogny časnik -Name[hu]=Mutatós óra -Name[ia]=Horologio analogic -Name[id]=Jam Analog -Name[is]=Skífuklukka -Name[it]=Orologio analogico -Name[ja]=アナログ時計 -Name[kk]=Аналогты сағат -Name[km]=នាឡិកា​អាណាឡូក -Name[kn]=ಅವಿಚ್ಛಿನ್ನಾತ್ಮಕ (ಅನಲಾಗ್, ಸಾಂಪ್ರದಾಯಿಕ) ಗಡಿಯಾರ -Name[ko]=아날로그 시계 -Name[ku]=Demjimêra Analog -Name[lt]=Analoginis laikrodis -Name[lv]=Rādītāju pulkstenis -Name[mai]=एनालाग घडी -Name[mk]=Аналоген часовник -Name[ml]=അനലോഗ് ഘടികാരം -Name[mr]=एनॉलॉग घड्याळ -Name[nb]=Analog klokke -Name[nds]=Analoog Klock -Name[ne]=एनालग घडी -Name[nl]=Analoge klok -Name[nn]=Analog klokke -Name[oc]=Relòtge analogic -Name[pa]=ਐਨਾਲਾਗ ਘੜੀ -Name[pl]=Zegar analogowy -Name[pt]=Relógio Analógico -Name[pt_BR]=Relógio Analógico -Name[ro]=Ceas analog -Name[ru]=Часы с циферблатом -Name[se]=Analogalaš diibmu -Name[si]=ප්‍රතිසම ඔරලෝසුව -Name[sk]=Analógové hodiny -Name[sl]=Analogna ura -Name[sr]=аналогни сат -Name[sr@ijekavian]=аналогни сат -Name[sr@ijekavianlatin]=analogni sat -Name[sr@latin]=analogni sat -Name[sv]=Analog klocka -Name[ta]=சுழல் கடிகாரம் -Name[te]=ఎనలాగ్ గడియారం -Name[tg]=Соати аналогӣ -Name[th]=นาฬิกาแอนะล็อก -Name[tr]=Analog Saat -Name[ug]=ئانالوگ سائەت -Name[uk]=Аналоговий годинник -Name[uz]=Analog soat -Name[uz@cyrillic]=Аналог соат -Name[vi]=Đồng hồ số -Name[wa]=Ôrlodje analodjike -Name[x-test]=xxAnalog Clockxx -Name[zh_CN]=模拟时钟 -Name[zh_TW]=類比時鐘 -Comment=A clock with hands -Comment[ar]=ساعة بعقارب -Comment[ast]=Un reló con manecielles -Comment[bg]=Часовник със стрелки -Comment[bs]=Sat sa kazaljkama -Comment[ca]=Un rellotge amb agulles -Comment[ca@valencia]=Un rellotge amb agulles -Comment[cs]=Ručičkové hodiny -Comment[da]=Et ur med visere -Comment[de]=Eine Uhr mit Zeigern -Comment[el]=Ένα ρολόι με δείκτες -Comment[en_GB]=A clock with hands -Comment[eo]=Horloĝo kun manoj -Comment[es]=Un reloj con manecillas -Comment[et]=Seieritega kell -Comment[eu]=Erloju orrazduna -Comment[fi]=Viisarikello -Comment[fr]=Une horloge à aiguilles -Comment[fy]=In klok mei wizerplaat -Comment[ga]=Clog le lámha -Comment[gl]=Un reloxo con agullas -Comment[he]=שעון עם מחוגים -Comment[hi]=सुई वाली घडी -Comment[hr]=Sat s kazaljkama -Comment[hu]=Óra mutatókkal -Comment[ia]=Un horologio con manos -Comment[id]=Sebuah jam dengan tangan -Comment[is]=Klukka með vísum -Comment[it]=Un orologio con lancette -Comment[ja]=針のある時計 -Comment[kk]=Тілді сағат -Comment[km]=ចាក់សោ​ដោយ​ដៃ -Comment[kn]=ಮುಳ್ಳುಗಳನ್ನು ಹೊಂದಿರುವ ಗಡಿಯಾರ -Comment[ko]=시침과 분침이 있는 시계 -Comment[lt]=Laikrodis su rodyklėmis -Comment[lv]=Rādītāju pulkstenis -Comment[mk]=Часовник со раце -Comment[mr]=हात असलेले घड्याळ -Comment[nb]=En klokke med visere -Comment[nds]=En Klock mit Wiesers -Comment[nl]=Een klok met wijzers -Comment[nn]=Ei klokke med visarar -Comment[pa]=ਸੂਈਆਂ ਨਾਲ ਘੜੀ -Comment[pl]=Zegar ze wskazówkami -Comment[pt]=Um relógio com ponteiros -Comment[pt_BR]=Um relógio com ponteiros -Comment[ro]=Ceas cu mîini -Comment[ru]=Часы со стрелками -Comment[si]=කටු සහිත ඔරලෝසුවක් -Comment[sk]=Ručičkové hodiny -Comment[sl]=Ura s kazalci -Comment[sr]=Сат са казаљкама -Comment[sr@ijekavian]=Сат са казаљкама -Comment[sr@ijekavianlatin]=Sat sa kazaljkama -Comment[sr@latin]=Sat sa kazaljkama -Comment[sv]=En klocka med visare -Comment[tg]=Соат бо ақрабакҳо -Comment[th]=นาฬิกาแบบเข็ม -Comment[tr]=İbreli bir saat -Comment[ug]=تىللىق سائەت -Comment[uk]=Годинник зі стрілками -Comment[wa]=Ène ôrlodje avou des aweyes -Comment[x-test]=xxA clock with handsxx -Comment[zh_CN]=带指针的时钟 -Comment[zh_TW]=有手的時鐘 -Icon=preferences-system-time -Type=Service -X-KDE-ServiceTypes=Plasma/Applet - -X-KDE-Library=plasma_applet_clock -X-KDE-PluginInfo-Author=The Plasma Team -X-KDE-PluginInfo-Email=plasma-devel@kde.org -X-KDE-PluginInfo-Name=clock -X-KDE-PluginInfo-Version=1.0 -X-KDE-PluginInfo-Website= -X-KDE-PluginInfo-Category=Date and Time -X-KDE-PluginInfo-Depends= -X-KDE-PluginInfo-License=GPL -X-KDE-PluginInfo-EnabledByDefault=true diff --git a/plasma/applets/digital-clock/CMakeLists.txt b/plasma/applets/digital-clock/CMakeLists.txt index 6cad5f69..15fa6db9 100644 --- a/plasma/applets/digital-clock/CMakeLists.txt +++ b/plasma/applets/digital-clock/CMakeLists.txt @@ -1,23 +1,22 @@ project(plasma-dig-clock) -include_directories( - # for plasmaclock_export.h - ${CMAKE_BINARY_DIR}/libs/plasmaclock +set(digitalclock_SRCS + digitalclock.cpp ) -set(clock_SRCS - clock.cpp - clockConfig.ui -) - -kde4_add_plugin(plasma_applet_dig_clock ${clock_SRCS}) +kde4_add_plugin(plasma_applet_dig_clock ${digitalclock_SRCS}) target_link_libraries(plasma_applet_dig_clock KDE4::plasma - KDE4::kdeui - KDE4::kio - plasmaclock + KDE4::kcmutils ) -install(TARGETS plasma_applet_dig_clock DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}) -install(FILES plasma-applet-digitalclock.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR}) +install( + TARGETS plasma_applet_dig_clock + DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} +) + +install( + FILES plasma-applet-digitalclock.desktop + DESTINATION ${KDE4_SERVICES_INSTALL_DIR} +) diff --git a/plasma/applets/digital-clock/clock.cpp b/plasma/applets/digital-clock/clock.cpp deleted file mode 100644 index a75c5ba5..00000000 --- a/plasma/applets/digital-clock/clock.cpp +++ /dev/null @@ -1,753 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 by Riccardo Iaconelli * - * Copyright (C) 2007-2010 by Sebastian Kügler * - * Copyright (C) 2011 by Teo Mrnjavac * - * * - * 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 . * - ***************************************************************************/ - - -#include "clock.h" - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -Clock::Clock(QObject *parent, const QVariantList &args) - : ClockApplet(parent, args), - m_plainClockFont(KGlobalSettings::generalFont()), - m_useCustomColor(false), - m_useCustomShadowColor(false), - m_drawShadow(true), - m_dateStyle(0), - m_timeFormat(QLocale::ShortFormat), - m_showTimezone(false), - m_dateTimezoneBesides(false), - m_svg(0) -{ - KGlobal::locale()->insertCatalog("libplasmaclock"); - // this catalog is only used once on the first start of the clock to translate the timezone in the configuration file - KGlobal::locale()->insertCatalog("timezones4"); - setHasConfigurationInterface(true); - resize(150, 75); -} - -Clock::~Clock() -{ -} - -void Clock::init() -{ - ClockApplet::init(); - - dataEngine("time")->connectSource(currentTimezone(), this, updateInterval(), intervalAlignment()); - connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(updateColors())); - connect(KGlobalSettings::self(), SIGNAL(appearanceChanged()), SLOT(resetSize())); - connect(KGlobalSettings::self(), SIGNAL(localeChanged()), SLOT(updateClock())); -} - -void Clock::constraintsEvent(Plasma::Constraints constraints) -{ - ClockApplet::constraintsEvent(constraints); - - if (constraints & Plasma::SizeConstraint || constraints & Plasma::FormFactorConstraint) { - updateSize(); - } -} - -// In case time format has changed, e.g. from 24h to 12h format. -void Clock::updateClock() -{ - generatePixmap(); - update(); -} - -void Clock::resetSize() -{ - // Called when the size of the applet may change externally, such as on - // font size changes - constraintsEvent(Plasma::SizeConstraint); -} - -void Clock::updateSize() -{ - Plasma::FormFactor f = formFactor(); - - if (f != Plasma::Vertical && f != Plasma::Horizontal) { - const QFontMetricsF metrics(KGlobalSettings::smallestReadableFont()); - // calculates based on size of "23:59"! - const QString timeString = KGlobal::locale()->formatTime(QTime(23, 59), m_timeFormat); - setMinimumSize(metrics.size(Qt::TextSingleLine, timeString)); - } - - // more magic numbers - int aspect = 2; - if (m_timeFormat == QLocale::LongFormat) { - aspect = 3; - } - - int w, h; - if (m_dateStyle || showTimezone()) { - const QFont f(KGlobalSettings::smallestReadableFont()); - const QFontMetrics metrics(f); - // if there's enough vertical space, wrap the words - if (contentsRect().height() < f.pointSize() * 6) { - QSize s = metrics.size(Qt::TextSingleLine, m_dateString); - w = s.width() + metrics.width(" "); - h = f.pointSize(); - //kDebug() << "uS: singleline" << w; - } else { - QSize s = metrics.size(Qt::TextWordWrap, m_dateString); - w = s.width(); - h = f.pointSize(); - //kDebug() << "uS: wordwrap" << w; - } - - if (!m_dateTimezoneBesides) { - w = qMax(w, (int)(contentsRect().height() * aspect)); - h = h+(int)(contentsRect().width() / aspect); - } else { - w = w+(int)(contentsRect().height() * aspect); - h = qMax(h, (int)(contentsRect().width() / aspect)); - } - } else { - w = (int)(contentsRect().height() * aspect); - h = (int)(contentsRect().width() / aspect); - } - - if (f == Plasma::Horizontal) { - // We have a fixed height, set some sensible width - setMinimumSize(QSize(w, 0)); - //kDebug() << "DR" << m_dateRect.width() << "CR" << contentsRect().height() * aspect; - // kDebug() << contentsRect(); - } else { - // We have a fixed width, set some sensible height - setMinimumSize(QSize(0, h)); - } - - setPreferredSize(QSize(w, h)); - emit sizeHintChanged(Qt::PreferredSize); - //kDebug() << "minZize: " << minimumSize() << preferredSize(); - - if (m_isDefaultFont) { - const QString fakeTimeString = KGlobal::locale()->formatTime(QTime(23,59,59), m_timeFormat); - expandFontToMax(m_plainClockFont, fakeTimeString); - } - - generatePixmap(); - update(); -} - -void Clock::clockConfigChanged() -{ - KConfigGroup cg = config(); - m_showTimezone = cg.readEntry("showTimezone", !isLocalTimezone()); - - kDebug() << "showTimezone:" << m_showTimezone; - - if (cg.hasKey("showDate")) { //legacy config entry as of 2011-1-4 - m_dateStyle = cg.readEntry("showDate", false) ? 2 : 0; //short date : no date - cg.deleteEntry("showDate"); - } - else { - m_dateStyle = cg.readEntry("dateStyle", 0); - } - - if (cg.hasKey("showYear")) { //legacy config entry as of 2011-1-4 - if( m_dateStyle ) { - m_dateStyle = cg.readEntry("showYear", false) ? 2 : 1; //short date : compact date - } - cg.deleteEntry("showYear"); - } - - m_timeFormat = static_cast(cg.readEntry("timeFormat", int(QLocale::ShortFormat))); - //We don't need to cache the applet if it update every seconds - setCacheMode(QGraphicsItem::NoCache); - - QFont f = cg.readEntry("plainClockFont", m_plainClockFont); - m_isDefaultFont = f == m_plainClockFont; - m_plainClockFont = f; - - m_useCustomColor = cg.readEntry("useCustomColor", m_useCustomColor); - m_plainClockColor = cg.readEntry("plainClockColor", m_plainClockColor); - m_useCustomShadowColor = cg.readEntry("useCustomShadowColor", m_useCustomShadowColor); - m_plainClockShadowColor = cg.readEntry("plainClockShadowColor", m_plainClockShadowColor); - m_drawShadow = cg.readEntry("plainClockDrawShadow", m_drawShadow); - - updateColors(); - - if (m_useCustomColor) { - m_pixmap = QPixmap(); - delete m_svg; - m_svg = 0; - } - - const QFontMetricsF metrics(KGlobalSettings::smallestReadableFont()); - const QString timeString = KGlobal::locale()->formatTime(QTime(23, 59), m_timeFormat); - setMinimumSize(metrics.size(Qt::TextSingleLine, timeString)); - - if (isUserConfiguring()) { - updateSize(); - } -} - -bool Clock::showTimezone() const -{ - return m_showTimezone || shouldDisplayTimezone(); -} - -void Clock::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data) -{ - Q_UNUSED(source); - m_time = data["Time"].toTime(); - m_date = data["Date"].toDate(); - - if (Plasma::ToolTipManager::self()->isVisible(this)) { - updateTipContent(); - } - - updateClockApplet(data); - generatePixmap(); - update(); -} - -void Clock::createClockConfigurationInterface(KConfigDialog *parent) -{ - //TODO: Make the size settable - QWidget *widget = new QWidget(); - ui.setupUi(widget); - parent->addPage(widget, i18n("Appearance"), "view-media-visualization"); - - ui.timeFormatBox->addItem(i18nc("A kind of time representation", "Compact time"), QVariant(int(QLocale::NarrowFormat))); - ui.timeFormatBox->addItem(i18nc("A kind of time representation", "Short time"), QVariant(int(QLocale::ShortFormat))); - ui.timeFormatBox->addItem(i18nc("A kind of time representation", "Long time"), QVariant(int(QLocale::LongFormat))); - ui.timeFormatBox->setCurrentIndex(ui.timeFormatBox->findData(int(m_timeFormat))); - - ui.showTimeZone->setChecked(m_showTimezone); - ui.plainClockFontBold->setChecked(m_plainClockFont.bold()); - ui.plainClockFontItalic->setChecked(m_plainClockFont.italic()); - ui.plainClockFont->setCurrentFont(m_plainClockFont); - ui.useCustomColor->setChecked(m_useCustomColor); - ui.plainClockColor->setColor(m_plainClockColor); - ui.drawShadow->setChecked(m_drawShadow); - ui.useCustomShadowColor->setChecked(m_useCustomShadowColor); - ui.plainClockShadowColor->setColor(m_plainClockShadowColor); - ui.configureDateFormats->setIcon( KIcon( "configure" ) ); - - QStringList dateStyles; - dateStyles << i18nc("A kind of date representation", "No date") - << i18nc("A kind of date representation", "Compact date") - << i18nc("A kind of date representation", "Short date") - << i18nc("A kind of date representation", "Long date"); - - ui.dateStyle->addItems(dateStyles); - ui.dateStyle->setCurrentIndex(m_dateStyle); - - connect(ui.drawShadow, SIGNAL(toggled(bool)), - this, SLOT(configDrawShadowToggled(bool))); - connect(ui.configureDateFormats, SIGNAL(clicked()), - this, SLOT(launchDateKcm())); - configDrawShadowToggled(m_drawShadow); - - connect(ui.plainClockFont, SIGNAL(currentFontChanged(QFont)), - parent, SLOT(settingsModified())); - connect(ui.plainClockFontBold, SIGNAL(stateChanged(int)), - parent, SLOT(settingsModified())); - connect(ui.plainClockFontItalic, SIGNAL(stateChanged(int)), - parent, SLOT(settingsModified())); - connect(ui.useCustomColor, SIGNAL(stateChanged(int)), - parent, SLOT(settingsModified())); - connect(ui.plainClockColor, SIGNAL(changed(QColor)), - parent, SLOT(settingsModified())); - connect(ui.drawShadow, SIGNAL(stateChanged(int)), - parent, SLOT(settingsModified())); - connect(ui.useCustomShadowColor, SIGNAL(stateChanged(int)), - parent, SLOT(settingsModified())); - connect(ui.plainClockShadowColor, SIGNAL(changed(QColor)), - parent, SLOT(settingsModified())); - connect(ui.showTimeZone, SIGNAL(stateChanged(int)), - parent, SLOT(settingsModified())); - connect(ui.timeFormatBox, SIGNAL(currentIndexChanged(int)), - parent, SLOT(settingsModified())); - connect(ui.dateStyle, SIGNAL(currentIndexChanged(int)), - parent, SLOT(settingsModified())); -} - -void Clock::configDrawShadowToggled(bool value) -{ - ui.useCustomShadowColor->setEnabled(value); - ui.customShadowColorLabel->setEnabled(value); - ui.plainClockShadowColor->setEnabled(value && ui.useCustomShadowColor->isChecked()); -} - -void Clock::clockConfigAccepted() -{ - KConfigGroup cg = config(); - - m_showTimezone = ui.showTimeZone->isChecked(); - cg.writeEntry("showTimezone", m_showTimezone); - - if (m_isDefaultFont && ui.plainClockFont->currentFont() != m_plainClockFont) { - m_isDefaultFont = false; - } - m_plainClockFont = ui.plainClockFont->currentFont(); - - m_dateStyle = ui.dateStyle->currentIndex(); - cg.writeEntry("dateStyle", m_dateStyle); - - m_timeFormat = static_cast(ui.timeFormatBox->itemData(ui.timeFormatBox->currentIndex()).toInt()); - cg.writeEntry("timeFormat", int(m_timeFormat)); - - m_useCustomColor = ui.useCustomColor->isChecked(); - cg.writeEntry("useCustomColor", m_useCustomColor); - if (m_useCustomColor) { - m_plainClockColor = ui.plainClockColor->color(); - cg.writeEntry("plainClockColor", m_plainClockColor); - m_pixmap = QPixmap(); - delete m_svg; - m_svg = 0; - } else { - m_plainClockColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); - } - - m_useCustomShadowColor = ui.useCustomShadowColor->isChecked(); - cg.writeEntry("useCustomShadowColor", m_useCustomShadowColor); - if (m_useCustomShadowColor) { - m_plainClockShadowColor = ui.plainClockShadowColor->color(); - cg.writeEntry("plainClockShadowColor", m_plainClockShadowColor); - } else { - m_plainClockShadowColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor); - } - m_drawShadow = ui.drawShadow->isChecked(); - cg.writeEntry("plainClockDrawShadow", m_drawShadow); - - m_plainClockFont.setBold(ui.plainClockFontBold->checkState() == Qt::Checked); - m_plainClockFont.setItalic(ui.plainClockFontItalic->checkState() == Qt::Checked); - cg.writeEntry("plainClockFont", m_plainClockFont); - - constraintsEvent(Plasma::SizeConstraint); - generatePixmap(); - update(); - emit sizeHintChanged(Qt::PreferredSize); - emit configNeedsSaving(); -} - -void Clock::changeEngineTimezone(const QString &oldTimezone, const QString &newTimezone) -{ - resetLastTimeSeen(); - dataEngine("time")->disconnectSource(oldTimezone, this); - dataEngine("time")->connectSource(newTimezone, this, updateInterval(), intervalAlignment()); -} - -QRectF Clock::normalLayout(int subtitleWidth, int subtitleHeight, const QRect &contentsRect) -{ - Q_UNUSED(subtitleWidth); - - QRectF myRect = QRectF(contentsRect.left(), - contentsRect.bottom() - subtitleHeight, - contentsRect.width(), - contentsRect.bottom()); - - //p->fillRect(myRect, QBrush(QColor("green"))); - - // Now find out how much space is left for painting the time - m_timeRect = QRect(contentsRect.left(), - contentsRect.top(), - contentsRect.width(), - contentsRect.height() - subtitleHeight); - - return myRect; -} - -QRectF Clock::sideBySideLayout(int subtitleWidth, int subtitleHeight, const QRect &contentsRect) -{ - QRectF myRect = QRectF(contentsRect.right()-subtitleWidth, - contentsRect.top() + (contentsRect.height()-subtitleHeight)/2, - subtitleWidth, - subtitleHeight); - // kDebug() << "myRect: " << myRect; - // p->fillRect(myRect, QBrush(QColor("grey"))); - - // Now find out how much space is left for painting the time - m_timeRect = QRect(contentsRect.left(), - contentsRect.top(), - contentsRect.right() - subtitleWidth, - contentsRect.bottom()); - - return myRect; -} - -void Clock::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) -{ - Q_UNUSED(option); - - if (!m_time.isValid() || !m_date.isValid()) { - return; - } - - p->setPen(QPen(m_plainClockColor)); - p->setRenderHint(QPainter::SmoothPixmapTransform); - p->setRenderHint(QPainter::Antialiasing); - - /* ... helps debugging contentsRect and sizing ... - QColor c = QColor(Qt::blue); - c.setAlphaF(.5); - p->setBrush(c); - p->drawRect(contentsRect); - */ - - // Paint the date, conditionally, and let us know afterwards how much - // space is left for painting the time on top of it. - QRectF dateRect; - const QString timeString = KGlobal::locale()->formatTime(m_time, m_timeFormat); - const QString fakeTimeString = KGlobal::locale()->formatTime(QTime(23,59,59), m_timeFormat); - QFont smallFont = KGlobalSettings::smallestReadableFont(); - - //create the string for the date and/or the timezone - if (m_dateStyle || showTimezone()) { - QString dateString; - - //Create the localized date string if needed - if (m_dateStyle) { - if (m_dateStyle == 1) { //compact date - dateString = KGlobal::locale()->formatDate(m_date, QLocale::NarrowFormat); - } else if (m_dateStyle == 2) { //short date - dateString = KGlobal::locale()->formatDate(m_date, QLocale::ShortFormat); - } else if (m_dateStyle == 3) { //long date - dateString = KGlobal::locale()->formatDate(m_date, QLocale::LongFormat); - } else { //shouldn't happen - dateString = KGlobal::locale()->formatDate(m_date, QLocale::ShortFormat); - } - - if (showTimezone()) { - QString currentTimezone = prettyTimezone(); - dateString = i18nc("@label Date with currentTimezone: " - "%1 day of the week with date, %2 currentTimezone", - "%1 %2", dateString, currentTimezone); - } - } else if (showTimezone()) { - dateString = prettyTimezone(); - } - - dateString = dateString.trimmed(); - - if (m_dateString != dateString) { - // If this string has changed (for example due to changes in the config - // we have to reset the sizing of the applet - m_dateString = dateString; - updateSize(); - } - - // Check sizes - // magic 10 is for very big spaces, - // where there's enough space to grow without harming time space - QFontMetrics fm(smallFont); - - if (contentsRect.height() > contentsRect.width() * 2) { - //kDebug() << Plasma::Vertical << contentsRect.height() < contentsRect.width()){ - smallFont.setPixelSize((contentsRect.width() * smallFont.pixelSize())/tempWidth); - } - - } else { - smallFont.setPixelSize(qMax(qMin(contentsRect.height(), contentsRect.width())/8, KGlobalSettings::smallestReadableFont().pointSize())); - } - - m_dateRect = preparePainter(p, contentsRect, smallFont, dateString); - } - - // kDebug() << "m_dateRect: " << m_dateRect; - - const int subtitleHeight = m_dateRect.height(); - const int subtitleWidth = m_dateRect.width(); - // kDebug() << "subtitleWitdh: " << subtitleWitdh; - // kDebug() << "subtitleHeight: " << subtitleHeight; - - if (m_dateTimezoneBesides) { - //kDebug() << contentsRect.height() << subtitleHeight << smallFont.pixelSize(); - if (contentsRect.height() - subtitleHeight >= smallFont.pixelSize() || formFactor() != Plasma::Horizontal) { - // to small to display the time on top of the date/timezone - // put them side by side - // kDebug() << "switching to normal"; - m_dateTimezoneBesides = false; - dateRect = normalLayout(subtitleWidth, subtitleHeight, contentsRect); - } else { - dateRect = sideBySideLayout(subtitleWidth, subtitleHeight, contentsRect); - } - } else { - /* kDebug() << "checking timezone placement" - << contentsRect.height() << dateRect.height() << subtitleHeight - << smallFont.pixelSize() << smallFont.pointSize();*/ - if (contentsRect.height() - subtitleHeight < smallFont.pixelSize() && formFactor() == Plasma::Horizontal) { - // to small to display the time on top of the date/timezone - // put them side by side - // kDebug() << "switching to s-b-s"; - m_dateTimezoneBesides = true; - dateRect = sideBySideLayout(subtitleWidth, subtitleHeight, contentsRect); - } else { - dateRect = normalLayout(subtitleWidth, subtitleHeight, contentsRect); - } - } - } else { - m_timeRect = contentsRect; - } - // kDebug() << "timeRect: " << m_timeRect; - // p->fillRect(timeRect, QBrush(QColor("red"))); - - // kDebug() << m_time; - // Choose a relatively big font size to start with - m_plainClockFont.setPointSizeF(qMax(m_timeRect.height(), KGlobalSettings::smallestReadableFont().pointSize())); - preparePainter(p, m_timeRect, m_plainClockFont, fakeTimeString, true); - - if (!m_dateString.isEmpty()) { - if (m_dateTimezoneBesides) { - QFontMetrics fm(m_plainClockFont); - //kDebug() << dateRect << m_timeRect << fm.boundingRect(m_timeRect, Qt::AlignCenter, timeString); - QRect br = fm.boundingRect(m_timeRect, Qt::AlignCenter, timeString); - - QFontMetrics smallfm(smallFont); - dateRect.moveLeft(br.right() + qMin(0, br.left()) + smallfm.width(" ")); - } - - // When we're relatively low, force everything into a single line - QFont f = p->font(); - p->setFont(smallFont); - - QPen datePen = p->pen(); - QColor dateColor = m_plainClockColor; - dateColor.setAlphaF(0.7); - datePen.setColor(dateColor); - p->setPen(datePen); - - if (formFactor() == Plasma::Horizontal && (contentsRect.height() < smallFont.pointSize()*6)) { - p->drawText(dateRect, Qt::TextSingleLine | Qt::AlignHCenter, m_dateString); - } else { - p->drawText(dateRect, Qt::TextWordWrap | Qt::AlignHCenter, m_dateString); - } - - p->setFont(f); - } - - if (m_useCustomColor || !m_svgExistsInTheme) { - QFontMetrics fm(p->font()); - - QPointF timeTextOrigin(QPointF(qMax(0, (m_timeRect.center().x() - fm.width(fakeTimeString) / 2)), - (m_timeRect.center().y() + fm.height() / 3))); - p->translate(-0.5, -0.5); - - if (m_drawShadow) { - QPen tmpPen = p->pen(); - - // Paint a backdrop behind the time's text - qreal shadowOffset = 1.0; - QPen shadowPen; - QColor shadowColor = m_plainClockShadowColor; - shadowColor.setAlphaF(.4); - shadowPen.setColor(shadowColor); - p->setPen(shadowPen); - QPointF shadowTimeTextOrigin = QPointF(timeTextOrigin.x() + shadowOffset, - timeTextOrigin.y() + shadowOffset); - p->drawText(shadowTimeTextOrigin, timeString); - - p->setPen(tmpPen); - - // Paint the time itself with a linear translucency gradient - QLinearGradient gradient = QLinearGradient(QPointF(0, 0), QPointF(0, fm.height())); - - QColor startColor = m_plainClockColor; - startColor.setAlphaF(.95); - QColor stopColor = m_plainClockColor; - stopColor.setAlphaF(.7); - - gradient.setColorAt(0.0, startColor); - gradient.setColorAt(0.5, stopColor); - gradient.setColorAt(1.0, startColor); - QBrush gradientBrush(gradient); - - QPen gradientPen(gradientBrush, tmpPen.width()); - p->setPen(gradientPen); - } - p->drawText(timeTextOrigin, timeString); - //when use the custom theme colors, draw the time textured - } else { - QRect adjustedTimeRect = m_pixmap.rect(); - adjustedTimeRect.moveCenter(m_timeRect.center()); - p->drawPixmap(adjustedTimeRect, m_pixmap); - } -} - -void Clock::generatePixmap() -{ - if (m_useCustomColor || !m_svgExistsInTheme) { - return; - } - - if (!m_svg) { - m_svg = new Plasma::Svg(this); - m_svg->setImagePath("widgets/labeltexture"); - m_svg->setContainsMultipleImages(true); - } - - const QString fakeTimeString = KGlobal::locale()->formatTime(QTime(23,59,59), m_timeFormat); - const QString timeString = KGlobal::locale()->formatTime(m_time, m_timeFormat); - - QRect rect(contentsRect().toRect()); - QFont font(m_plainClockFont); - prepareFont(font, rect, fakeTimeString, true); - m_pixmap = Plasma::PaintUtils::texturedText(timeString, font, m_svg); -} - -void Clock::expandFontToMax(QFont &font, const QString &text) -{ - bool first = true; - const QRect rect = contentsRect().toRect(); - int oldWidth = 0; - int oldHeight = 0; - - // Starting with the given font, increase its size until it'll fill the rect - do { - if (first) { - first = false; - } else { - font.setPointSize(font.pointSize() + 1); - } - - const QFontMetrics fm(font); - QRect fr = fm.boundingRect(rect, Qt::TextSingleLine, text); - if (oldWidth == fr.width() && oldHeight == fr.height()) { - // Largest font size reached. - break; - } - oldWidth = fr.width(); - oldHeight = fr.height(); - - if (fr.width() >= rect.width() || fr.height() >= rect.height()) { - break; - } - } while (true); -} - -void Clock::prepareFont(QFont &font, QRect &rect, const QString &text, bool singleline) -{ - QRect tmpRect; - bool first = true; - const int smallest = KGlobalSettings::smallestReadableFont().pointSize(); - - // Starting with the given font, decrease its size until it'll fit in the - // given rect allowing wrapping where possible - do { - if (first) { - first = false; - } else { - font.setPointSize(qMax(smallest, font.pointSize() - 1)); - } - - const QFontMetrics fm(font); - int flags = (singleline || ((formFactor() == Plasma::Horizontal) && (contentsRect().height() < font.pointSize()*6))) ? - Qt::TextSingleLine : Qt::TextWordWrap; - - tmpRect = fm.boundingRect(rect, flags, text); - } while (font.pointSize() > smallest && - (tmpRect.width() > rect.width() || tmpRect.height() > rect.height())); - - rect = tmpRect; -} - -QRect Clock::preparePainter(QPainter *p, const QRect &rect, const QFont &font, const QString &text, bool singleline) -{ - QRect tmpRect = rect; - QFont tmpFont = font; - - prepareFont(tmpFont, tmpRect, text, singleline); - - p->setFont(tmpFont); - - return tmpRect; -} - -int Clock::updateInterval() const -{ - // even the short format can include seconds - return 1000; -} - -Plasma::IntervalAlignment Clock::intervalAlignment() const -{ - return Plasma::NoAlignment; -} - -void Clock::updateColors() -{ - m_svgExistsInTheme = Plasma::Theme::defaultTheme()->currentThemeHasImage("widgets/labeltexture"); - - if (!m_useCustomColor) { - m_plainClockColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); - } - - if (!m_useCustomShadowColor) { - m_plainClockShadowColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor); - } - - if (!m_useCustomColor || !m_useCustomShadowColor) { - update(); - } -} - -void Clock::launchDateKcm() //SLOT -{ - KService::List offers = KServiceTypeTrader::self()->query("KCModule", "Library == 'kcm_locale'"); - if (!offers.isEmpty()) { - KService::Ptr service = offers.first(); - KRun::run(*service, KUrl::List(), 0); - } - update(); -} - -#include "moc_clock.cpp" diff --git a/plasma/applets/digital-clock/clock.h b/plasma/applets/digital-clock/clock.h deleted file mode 100644 index efdbd0e3..00000000 --- a/plasma/applets/digital-clock/clock.h +++ /dev/null @@ -1,109 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 by Riccardo Iaconelli * - * Copyright (C) 2007-2008 by Sebastian Kuegler * - * * - * 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 . * - ***************************************************************************/ - -#ifndef CLOCK_H -#define CLOCK_H - -#include -#include - -#include -#include -#include - -#include "ui_clockConfig.h" -#include - -namespace Plasma -{ - class Svg; -} - -class Clock : public ClockApplet -{ - Q_OBJECT - public: - Clock(QObject *parent, const QVariantList &args); - ~Clock(); - - void init(); - void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect); - - public slots: - void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data); - void updateColors(); - - protected slots: - void clockConfigAccepted(); - void clockConfigChanged(); - void constraintsEvent(Plasma::Constraints constraints); - void resetSize(); - void updateClock(); - - protected: - void createClockConfigurationInterface(KConfigDialog *parent); - void changeEngineTimezone(const QString &oldTimezone, const QString &newTimezone); - - private slots: - void configDrawShadowToggled(bool value); - void launchDateKcm(); - - private: - void updateSize(); - bool showTimezone() const; - void generatePixmap(); - QRect preparePainter(QPainter *p, const QRect &rect, const QFont &font, const QString &text, bool singleline = false); - void prepareFont(QFont &font, QRect &rect, const QString &text, bool singleline); - void expandFontToMax(QFont &font, const QString &text); - QRectF normalLayout (int subtitleWidth, int subtitleHeight, const QRect &contentsRect); - QRectF sideBySideLayout (int subtitleWidth, int subtitleHeight, const QRect &contentsRect); - - QFont m_plainClockFont; - bool m_isDefaultFont; - bool m_useCustomColor; - QColor m_plainClockColor; - bool m_useCustomShadowColor; - QColor m_plainClockShadowColor; - bool m_drawShadow; - QRect m_timeRect; - QRect m_dateRect; - - int m_dateStyle; //0 = don't show a date - QLocale::FormatType m_timeFormat; - bool m_showTimezone; - bool m_dateTimezoneBesides; - - int updateInterval() const; - Plasma::IntervalAlignment intervalAlignment() const; - - QTime m_time; - QDate m_date; - QString m_dateString; - QPixmap m_toolTipIcon; - /// Designer Config files - Ui::clockConfig ui; - Plasma::Svg *m_svg; - bool m_svgExistsInTheme; - QPixmap m_pixmap; -}; - -K_EXPORT_PLASMA_APPLET(dig_clock, Clock) - -#endif diff --git a/plasma/applets/digital-clock/clockConfig.ui b/plasma/applets/digital-clock/clockConfig.ui deleted file mode 100644 index ad805539..00000000 --- a/plasma/applets/digital-clock/clockConfig.ui +++ /dev/null @@ -1,475 +0,0 @@ - - - clockConfig - - - - 0 - 0 - 469 - 341 - - - - - 0 - - - - - - 75 - true - - - - Font - - - - - - - Font style: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - plainClockFont - - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 0 - 17 - - - - - - - - - - Check if you want the font in bold - - - When this is checked, the clock font will be bold. - - - &Bold - - - - - - - Check if you want the font in italic - - - When this is checked, the clock font will be in italic. - - - &Italic - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - Custom font color: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - useCustomColor - - - - - - - - - - - - - - - - false - - - Color chooser - - - Click on this button and the KDE standard color dialog will show. You can then choose the new color you want for your clock. - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Show shadow: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - drawShadow - - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Custom shadow color: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - useCustomShadowColor - - - - - - - - - false - - - Shadow color chooser - - - Click on this button and the KDE standard color dialog will show. You can then choose the new color you want for the text shadow for your clock. - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - true - - - - - - - - - - - - - 75 - true - - - - Information - - - - - - - Show time zone: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - showTimeZone - - - - - - - - - Display the time zone name - - - Display the time zone name under the time. - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Show seconds: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - timeFormatBox - - - - - - - - - Choose the format you want to show the time in. - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Date format: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::Vertical - - - QSizePolicy::MinimumExpanding - - - - 20 - 2 - - - - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 0 - 20 - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KColorButton - QPushButton -
kcolorbutton.h
-
-
- - - useCustomColor - toggled(bool) - plainClockColor - setEnabled(bool) - - - 168 - 124 - - - 211 - 126 - - - - - useCustomShadowColor - toggled(bool) - plainClockShadowColor - setEnabled(bool) - - - 168 - 185 - - - 209 - 182 - - - - -
diff --git a/plasma/applets/digital-clock/digitalclock.cpp b/plasma/applets/digital-clock/digitalclock.cpp new file mode 100644 index 00000000..c799ba8e --- /dev/null +++ b/plasma/applets/digital-clock/digitalclock.cpp @@ -0,0 +1,209 @@ +/* + This file is part of the KDE project + Copyright (C) 2024 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "digitalclock.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +static QFont kClockFont(const QRectF &contentsRect) +{ + QFont font = KGlobalSettings::smallestReadableFont(); + font.setBold(true); + if (!contentsRect.isNull()) { + font.setPointSize(qMax(qreal(font.pointSize()), contentsRect.height() / 2)); + } + return font; +} + +static QString kClockString() +{ + return KGlobal::locale()->formatTime(QTime::currentTime()); +} + +static QSizeF kClockSize(const QRectF &contentsRect) +{ + QFontMetricsF fontmetricsf(kClockFont(contentsRect)); + QSizeF clocksize = fontmetricsf.size(Qt::TextSingleLine, kClockString()); + if (contentsRect.isNull()) { + clocksize.setHeight(clocksize.height() * 4); + clocksize.setWidth(clocksize.width() * 2); + } + return clocksize; +} + +DigitalClockApplet::DigitalClockApplet(QObject *parent, const QVariantList &args) + : Plasma::Applet(parent, args), + m_svg(nullptr), + m_timer(nullptr), + m_kcmclockproxy(nullptr), + m_kcmlanguageproxy(nullptr) +{ + KGlobal::locale()->insertCatalog("plasma_applet_dig_clock"); + setAspectRatioMode(Plasma::AspectRatioMode::IgnoreAspectRatio); + setHasConfigurationInterface(true); + + m_svg = new Plasma::Svg(this); + m_svg->setImagePath("widgets/labeltexture"); + m_svg->setContainsMultipleImages(true); + + m_timer = new QTimer(this); + // even if the time format contains ms polling and repainting more often that 1sec is overkill + m_timer->setInterval(1000); + connect( + m_timer, SIGNAL(timeout()), + this, SLOT(slotTimeout()) + ); + + m_menu = new KMenu(i18n("C&opy to Clipboard")); + m_menu->setIcon(KIcon("edit-copy")); + connect(m_menu, SIGNAL(triggered(QAction*)), this, SLOT(slotCopyToClipboard(QAction*))); +} + +void DigitalClockApplet::init() +{ + m_timer->start(); +} + +void DigitalClockApplet::paintInterface(QPainter *painter, + const QStyleOptionGraphicsItem *option, + const QRect &contentsRect) +{ + painter->setRenderHint(QPainter::SmoothPixmapTransform); + painter->setRenderHint(QPainter::Antialiasing); + + painter->drawPixmap( + contentsRect, + Plasma::PaintUtils::texturedText(kClockString(), kClockFont(contentsRect), m_svg) + ); +} + +void DigitalClockApplet::createConfigurationInterface(KConfigDialog *parent) +{ + m_kcmclockproxy = new KCModuleProxy("clock"); + parent->addPage( + m_kcmclockproxy, m_kcmclockproxy->moduleInfo().moduleName(), + m_kcmclockproxy->moduleInfo().icon() + ); + + m_kcmlanguageproxy = new KCModuleProxy("language"); + parent->addPage( + m_kcmlanguageproxy, m_kcmlanguageproxy->moduleInfo().moduleName(), + m_kcmlanguageproxy->moduleInfo().icon() + ); + + connect(parent, SIGNAL(applyClicked()), this, SLOT(slotConfigAccepted())); + connect(parent, SIGNAL(okClicked()), this, SLOT(slotConfigAccepted())); + connect(m_kcmclockproxy, SIGNAL(changed(bool)), parent, SLOT(settingsModified())); + connect(m_kcmlanguageproxy, SIGNAL(changed(bool)), parent, SLOT(settingsModified())); +} + +QList DigitalClockApplet::contextualActions() +{ + const QDateTime datetime = QDateTime::currentDateTime(); + const QDate date = datetime.date(); + const QTime time = datetime.time(); + + m_menu->clear(); + m_menu->addAction(KGlobal::locale()->formatDate(date, QLocale::LongFormat)); + m_menu->addAction(KGlobal::locale()->formatDate(date, QLocale::ShortFormat)); + + QAction* separator0 = new QAction(this); + separator0->setSeparator(true); + m_menu->addAction(separator0); + + m_menu->addAction(KGlobal::locale()->formatTime(time, QLocale::LongFormat)); + m_menu->addAction(KGlobal::locale()->formatTime(time, QLocale::ShortFormat)); + + QAction* separator1 = new QAction(this); + separator1->setSeparator(true); + m_menu->addAction(separator1); + + m_menu->addAction(KGlobal::locale()->formatDateTime(datetime, QLocale::LongFormat)); + m_menu->addAction(KGlobal::locale()->formatDateTime(datetime, QLocale::ShortFormat)); + m_menu->addAction(KGlobal::locale()->formatDateTime(datetime, QLocale::NarrowFormat)); + + QList actions; + actions.append(m_menu->menuAction()); + return actions; +} + +void DigitalClockApplet::constraintsEvent(Plasma::Constraints constraints) +{ + if (constraints && Plasma::SizeConstraint || constraints & Plasma::FormFactorConstraint) { + const QSizeF clocksize = kClockSize(contentsRect()); + switch (formFactor()) { + case Plasma::FormFactor::Horizontal: + case Plasma::FormFactor::Vertical: { + // panel + setMinimumSize(0, 0); + setPreferredSize(clocksize); + break; + } + default: { + // desktop-like + setMinimumSize(kClockSize(QRect())); + setPreferredSize(clocksize); + break; + } + } + } +} + +void DigitalClockApplet::changeEvent(QEvent *event) +{ + Plasma::Applet::changeEvent(event); + switch (event->type()) { + // the time format depends on the locale, update the sizes + case QEvent::LocaleChange: + case QEvent::LanguageChange: { + constraintsEvent(Plasma::SizeConstraint); + break; + } + default: { + break; + } + } +} + +void DigitalClockApplet::slotTimeout() +{ + update(); +} + +void DigitalClockApplet::slotConfigAccepted() +{ + m_kcmclockproxy->save(); + m_kcmlanguageproxy->save(); +} + +void DigitalClockApplet::slotCopyToClipboard(QAction *action) +{ + QString actiontext = action->text(); + actiontext.remove(QChar('&')); + QApplication::clipboard()->setText(actiontext); +} + +#include "moc_digitalclock.cpp" diff --git a/plasma/applets/digital-clock/digitalclock.h b/plasma/applets/digital-clock/digitalclock.h new file mode 100644 index 00000000..17ed443c --- /dev/null +++ b/plasma/applets/digital-clock/digitalclock.h @@ -0,0 +1,65 @@ +/* + This file is part of the KDE project + Copyright (C) 2024 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef DIGITALCLOCK_H +#define DIGITALCLOCK_H + +#include +#include +#include +#include +#include +#include + +class DigitalClockApplet : public Plasma::Applet +{ + Q_OBJECT +public: + DigitalClockApplet(QObject *parent, const QVariantList &args); + + // Plasma::Applet reimplementations + void init() final; + void paintInterface(QPainter *painter, + const QStyleOptionGraphicsItem *option, + const QRect &contentsRect); + void createConfigurationInterface(KConfigDialog *parent) final; + QList contextualActions() final; + +protected: + // Plasma::Applet reimplementation + void constraintsEvent(Plasma::Constraints constraints) final; + // QGraphicsWidget reimplementation + void changeEvent(QEvent *event) final; + +private Q_SLOTS: + void slotTimeout(); + void slotConfigAccepted(); + void slotCopyToClipboard(QAction *action); + +private: + Plasma::Svg* m_svg; + QTimer* m_timer; + KCModuleProxy* m_kcmclockproxy; + KCModuleProxy* m_kcmlanguageproxy; + KMenu* m_menu; +}; + +K_EXPORT_PLASMA_APPLET(dig_clock, DigitalClockApplet) + +#endif // DIGITALCLOCK_H diff --git a/plasma/dataengines/CMakeLists.txt b/plasma/dataengines/CMakeLists.txt index 034456a9..a244c68c 100644 --- a/plasma/dataengines/CMakeLists.txt +++ b/plasma/dataengines/CMakeLists.txt @@ -2,5 +2,3 @@ add_subdirectory(applicationjobs) add_subdirectory(apps) add_subdirectory(dict) add_subdirectory(notifications) -add_subdirectory(time) - diff --git a/plasma/dataengines/time/CMakeLists.txt b/plasma/dataengines/time/CMakeLists.txt deleted file mode 100644 index dfe6c821..00000000 --- a/plasma/dataengines/time/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -set(time_engine_SRCS - timeengine.cpp - timesource.cpp - solarsystem.cpp -) - -kde4_add_plugin(plasma_engine_time ${time_engine_SRCS}) -target_link_libraries(plasma_engine_time KDE4::kdecore KDE4::plasma KDE4::solid) - -install(TARGETS plasma_engine_time DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}) -install(FILES plasma-dataengine-time.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR} ) - diff --git a/plasma/dataengines/time/plasma-dataengine-time.desktop b/plasma/dataengines/time/plasma-dataengine-time.desktop deleted file mode 100644 index 008af537..00000000 --- a/plasma/dataengines/time/plasma-dataengine-time.desktop +++ /dev/null @@ -1,165 +0,0 @@ -[Desktop Entry] -Name=Date and Time -Name[ar]=التاريخ و الوقت -Name[as]=তাৰিখ আৰু সময় -Name[ast]=Data y hora -Name[be@latin]=Data j čas -Name[bg]=Дата и час -Name[bn]=তারিখ এবং সময় -Name[bn_IN]=তারিখ ও সময় -Name[bs]=datum i vrijeme -Name[ca]=Data i hora -Name[ca@valencia]=Data i hora -Name[cs]=Datum a čas -Name[csb]=Datum ë czas -Name[da]=Dato og tid -Name[de]=Datum und Zeit -Name[el]=Ημερομηνία και ώρα -Name[en_GB]=Date and Time -Name[eo]=Dato kaj Tempo -Name[es]=Fecha y hora -Name[et]=Kuupäev ja kellaaeg -Name[eu]=Data eta ordua -Name[fa]=تاریخ و زمان -Name[fi]=Aika ja päiväys -Name[fr]=Date et heure -Name[fy]=Datum en tiid -Name[ga]=Dáta agus Am -Name[gl]=Data e hora -Name[gu]=તારીખ અને સમય -Name[he]=תאריך ושעה -Name[hi]=तारीख़ और समय -Name[hne]=तारीक अउ समय -Name[hr]=Datum i vrijeme -Name[hu]=Dátum és idő -Name[ia]=Data e Tempore -Name[id]=Tanggal dan Waktu -Name[is]=Dagur og tími -Name[it]=Data e ora -Name[ja]=日付と時刻 -Name[kk]=Күні мен уақыты -Name[km]=កាល​បរិច្ឆេទ និង​ពេលវេលា -Name[kn]=ದಿನಾಂಕ ಮತ್ತು ಸಮಯ -Name[ko]=날짜와 시간 -Name[ku]=Dîrok û Dem -Name[lt]=Data ir laikas -Name[lv]=Datums un laiks -Name[mai]=दिनाँक आ समय -Name[mk]=Датум и време -Name[ml]=തീയതിയും സമയവും -Name[mr]=दिनांक व वेळ -Name[nb]=Dato og klokkeslett -Name[nds]=Datum un Tiet -Name[nl]=Datum en tijd -Name[nn]=Dato og klokkeslett -Name[or]=ତାରିଖ ଏବଂ ସମୟ -Name[pa]=ਮਿਤੀ ਅਤੇ ਟਾਈਮ -Name[pl]=Data i czas -Name[pt]=Data e Hora -Name[pt_BR]=Data e hora -Name[ro]=Data și ora -Name[ru]=Дата и время -Name[si]=දිනය සහ වේලාව -Name[sk]=Dátum a čas -Name[sl]=Datum in čas -Name[sr]=датум и време -Name[sr@ijekavian]=датум и време -Name[sr@ijekavianlatin]=datum i vreme -Name[sr@latin]=datum i vreme -Name[sv]=Datum och tid -Name[ta]=Date and Time -Name[tg]=Сана ва вақт -Name[th]=วันและเวลา -Name[tr]=Tarih ve Saat -Name[ug]=چېسلا ۋە ۋاقىت -Name[uk]=Дата і час -Name[vi]=Ngày giờ -Name[wa]=Date eyet eure -Name[x-test]=xxDate and Timexx -Name[zh_CN]=日期和时间 -Name[zh_TW]=日期與時間 -Comment=Date and time by timezone -Comment[ar]=التاريخ و الوقت بواسطة المنطقة الزمنية -Comment[ast]=Data y hora por estaya horaria -Comment[bg]=Настройки на датата и часа -Comment[bn]=টাইম-জোন অনুসারে তারিখ এবং সময় -Comment[bs]=Datum i vrijeme po vremenskoj zoni -Comment[ca]=Data i l'hora per zona horària -Comment[ca@valencia]=Data i l'hora per zona horària -Comment[cs]=Datum a čas podle časového pásma -Comment[csb]=Datum ë czas wedle czasowich conów -Comment[da]=Dato og tid efter tidszone -Comment[de]=Datum und Zeit nach Zeitzone -Comment[el]=Ημερομηνία και ώρα ανά ωρολογιακή ζώνη -Comment[en_GB]=Date and time by timezone -Comment[eo]=Dato kaj tempo laŭ horzonoj -Comment[es]=Fecha y hora por zona horaria -Comment[et]=Kuupäev ja kellaaeg ajavööndi põhjal -Comment[eu]=Data eta ordua ordu-eremuaren arabera -Comment[fi]=Aika ja päiväys aikavyöhykkeittäin -Comment[fr]=Date et heure par fuseau horaire -Comment[fy]=Datum en tiid mei help fan tiidsône -Comment[ga]=Dáta agus am de réir creasa ama -Comment[gl]=Data e hora segundo o fuso horario -Comment[gu]=સમયવિસ્તાર વડે તારીખ અને સમય -Comment[he]=תאריך ושעה לפי אזור זמן -Comment[hi]=तारीख़ तथा समय समयक्षेत्र हिसाब से -Comment[hr]=Datum i vrijeme po vremenskoj zoni -Comment[hu]=Dátum és idő (időzónánként) -Comment[ia]=Data e tempore per fuso horari -Comment[id]=Tanggal dan waktu menurut zona waktu -Comment[is]=Stillingar dagssetningar og klukku eftir tímabeltum -Comment[it]=Data e ora per fuso orario -Comment[ja]=タイムゾーンの日付と時刻 -Comment[kk]=Уақыт белдеуінің күн мен уақыты -Comment[km]=កាលបរិច្ឆេទ និង​ពេលវេលា​តាម​តំបន់​ពេលវេលា -Comment[kn]=ಕಾಲವಲಯದಿಂದ ದಿನಾಂಕ ಮತ್ತು ಸಮಯ -Comment[ko]=시간대에 따른 날짜와 시간 -Comment[lt]=Data ir laikas pagal laiko juostas -Comment[lv]=Datums un laiks pa laika joslām -Comment[mk]=Датум и време според временска зона -Comment[ml]=തീയതിയും സമയവും സമയമേഖലയനുസരിച്ചു് -Comment[mr]=वेळक्षेत्रा प्रमाणे दिनांक व वेळ -Comment[nb]=Dato og klokkeslett ved tidssone -Comment[nds]=Datum un Tiet na Tietrebeet -Comment[nl]=Datum en tijd per tijdzone -Comment[nn]=Dato og klokkeslett i ulike tidssoner -Comment[pa]=ਮਿਤੀ ਅਤੇ ਟਾਈਮ ਸਮਾਂ-ਖੇਤਰ ਰਾਹੀਂ -Comment[pl]=Ustawienia daty i czasu na podstawie strefy czasowej -Comment[pt]=Data e hora pelo fuso-horário -Comment[pt_BR]=Data e hora por fuso horário -Comment[ro]=Data și ora după fusul orar -Comment[ru]=Дата и время в различных часовых поясах -Comment[si]=වේලා කලාපය අනුව දිනය සහ වේලාව -Comment[sk]=Dátum a čas podľa časového pásma -Comment[sl]=Datum in čas po časovnih pasovih -Comment[sr]=Датум и време по временској зони -Comment[sr@ijekavian]=Датум и вријеме по временској зони -Comment[sr@ijekavianlatin]=Datum i vrijeme po vremenskoj zoni -Comment[sr@latin]=Datum i vreme po vremenskoj zoni -Comment[sv]=Datum och tid enligt tidszon -Comment[tg]=Танзимоти сана ва вақт -Comment[th]=วันและเวลาตามเขตเวลา -Comment[tr]=Zaman dilimine göre tarih ve saat -Comment[ug]=ۋاقىت رايونىغا ئاساسەن چېسلا ۋە ۋاقىت تەمىنلەيدۇ -Comment[uk]=Дата і час за часовими поясами -Comment[vi]=Ngày giờ theo múi giờ -Comment[wa]=Date et eure pa coisse ås eures -Comment[x-test]=xxDate and time by timezonexx -Comment[zh_CN]=根据时区提供日期和时间 -Comment[zh_TW]=時區的日期和時間 -Type=Service -Icon=preferences-system-time - -X-KDE-ServiceTypes=Plasma/DataEngine -X-KDE-Library=plasma_engine_time - -X-KDE-PluginInfo-Author=Aaron Seigo -X-KDE-PluginInfo-Email=aseigo@kde.org -X-KDE-PluginInfo-Name=time -X-KDE-PluginInfo-Version=1.0 -X-KDE-PluginInfo-Website= -X-KDE-PluginInfo-Category=Date and Time -X-KDE-PluginInfo-Depends= -X-KDE-PluginInfo-License=LGPL -X-KDE-PluginInfo-EnabledByDefault=true diff --git a/plasma/dataengines/time/solarsystem.cpp b/plasma/dataengines/time/solarsystem.cpp deleted file mode 100644 index 88d20db9..00000000 --- a/plasma/dataengines/time/solarsystem.cpp +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (C) 2009 Petri Damsten - * - * 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, see . - */ - -#include "solarsystem.h" -#include -#include - -/* - * Mathematics, ideas, public domain code used for these classes from: - * http://www.stjarnhimlen.se/comp/tutorial.html - * http://www.stjarnhimlen.se/comp/riset.html - * http://www.srrb.noaa.gov/highlights/solarrise/azel.html - * http://www.srrb.noaa.gov/highlights/sunrise/sunrise.html - * http://bodmas.org/astronomy/riset.html - * moontool.c by John Walker - * Wikipedia - */ - -Sun::Sun() - : SolarSystemObject() -{ -} - -void Sun::calcForDateTime(const QDateTime& local, int offset) -{ - SolarSystemObject::calcForDateTime(local, offset); - - N = 0.0; - i = 0.0; - w = rev(282.9404 + 4.70935E-5 * m_day); - a = 1.0; - e = rev(0.016709 - 1.151E-9 * m_day); - M = rev(356.0470 + 0.9856002585 * m_day); - - calc(); -} - -void Sun::rotate(double* y, double* z) -{ - *y *= cosd(m_obliquity); - *z *= sind(m_obliquity); -} - -Moon::Moon(Sun *sunptr) - : m_sun(sunptr) -{ -} - -void Moon::calcForDateTime(const QDateTime& local, int offset) -{ - if (m_sun->dateTime() != local) { - m_sun->calcForDateTime(local, offset); - } - - SolarSystemObject::calcForDateTime(local, offset); - - N = rev(125.1228 - 0.0529538083 * m_day); - i = 5.1454; - w = rev(318.0634 + 0.1643573223 * m_day); - a = 60.2666; - e = 0.054900; - M = rev(115.3654 + 13.0649929509 * m_day); - - calc(); -} - -bool Moon::calcPerturbations(double *lo, double *la, double *r) -{ - double Ms = m_sun->meanAnomaly(); - double D = L - m_sun->meanLongitude(); - double F = L - N; - - *lo += -1.274 * sind(M - 2 * D) - +0.658 * sind(2 * D) - -0.186 * sind(Ms) - -0.059 * sind(2 * M - 2 * D) - -0.057 * sind(M - 2 * D + Ms) - +0.053 * sind(M + 2 * D) - +0.046 * sind(2 * D - Ms) - +0.041 * sind(M - Ms) - -0.035 * sind(D) - -0.031 * sind(M + Ms) - -0.015 * sind(2 * F - 2 * D) - +0.011 * sind(M - 4 * D); - *la += -0.173 * sind(F - 2 * D) - -0.055 * sind(M - F - 2 * D) - -0.046 * sind(M + F - 2 * D) - +0.033 * sind(F + 2 * D) - +0.017 * sind(2 * M + F); - *r += -0.58 * cosd(M - 2 * D) - -0.46 * cosd(2 * D); - return true; -} - -void Moon::topocentricCorrection(double* RA, double* dec) -{ - double HA = rev(siderealTime() - *RA); - double gclat = m_latitude - 0.1924 * sind(2 * m_latitude); - double rho = 0.99833 + 0.00167 * cosd(2 * m_latitude); - double mpar = asind(1 / rad); - double g = atand(tand(gclat) / cosd(HA)); - - *RA -= mpar * rho * cosd(gclat) * sind(HA) / cosd(*dec); - *dec -= mpar * rho * sind(gclat) * sind(g - *dec) / sind(g); -} - -double Moon::phase() -{ - return rev(m_eclipticLongitude - m_sun->lambda()); -} - -void Moon::rotate(double* y, double* z) -{ - double t = *y; - *y = t * cosd(m_obliquity) - *z * sind(m_obliquity); - *z = t * sind(m_obliquity) + *z * cosd(m_obliquity); -} - -void SolarSystemObject::calc() -{ - double x, y, z; - double la, r; - - L = rev(N + w + M); - double E0 = 720.0; - double E = M + (180.0 / M_PI) * e * sind(M) * (1.0 + e * cosd(M)); - for (int j = 0; fabs(E0 - E) > 0.005 && j < 10; ++j) { - E0 = E; - E = E0 - (E0 - (180.0 / M_PI) * e * sind(E0) - M) / (1 - e * cosd(E0)); - } - x = a * (cosd(E) - e); - y = a * sind(E) * sqrt(1.0 - e * e); - r = sqrt(x * x + y * y); - double v = rev(atan2d(y, x)); - m_lambda = rev(v + w); - x = r * (cosd(N) * cosd(m_lambda) - sind(N) * sind(m_lambda) * cosd(i)); - y = r * (sind(N) * cosd(m_lambda) + cosd(N) * sind(m_lambda) * cosd(i)); - z = r * sind(m_lambda); - if (!qFuzzyCompare(i, 0.0)) { - z *= sind(i); - } - toSpherical(x, y, z, &m_eclipticLongitude, &la, &r); - if (calcPerturbations(&m_eclipticLongitude, &la, &r)) { - toRectangular(m_eclipticLongitude, la, r, &x, &y, &z); - } - rotate(&y, &z); - toSpherical(x, y, z, &RA, &dec, &rad); - topocentricCorrection(&RA, &dec); - - HA = rev(siderealTime() - RA); - x = cosd(HA) * cosd(dec) * sind(m_latitude) - sind(dec) * cosd(m_latitude); - y = sind(HA) * cosd(dec); - z = cosd(HA) * cosd(dec) * cosd(m_latitude) + sind(dec) * sind(m_latitude); - m_azimuth = atan2d(y, x) + 180.0; - m_altitude = asind(z); -} - -double SolarSystemObject::siderealTime() -{ - double UT = m_utc.time().hour() + m_utc.time().minute() / 60.0 + - m_utc.time().second() / 3600.0; - double GMST0 = rev(282.9404 + 4.70935E-5 * m_day + 356.0470 + 0.9856002585 * m_day + 180.0); - return GMST0 + UT * 15.0 + m_longitude; -} - -void SolarSystemObject::calcForDateTime(const QDateTime& local, int offset) -{ - m_local = local; - m_utc = local.addSecs(-offset); - m_day = 367 * m_utc.date().year() - (7 * (m_utc.date().year() + - ((m_utc.date().month() + 9) / 12))) / 4 + - (275 * m_utc.date().month()) / 9 + m_utc.date().day() - 730530; - m_day += m_utc.time().hour() / 24.0 + m_utc.time().minute() / (24.0 * 60.0) + - m_utc.time().second() / (24.0 * 60.0 * 60.0); - m_obliquity = 23.4393 - 3.563E-7 * m_day; -} - -SolarSystemObject::SolarSystemObject() - : m_latitude(0.0) - , m_longitude(0.0) -{ -} - -SolarSystemObject::~SolarSystemObject() -{ -} - -void SolarSystemObject::setPosition(double latitude, double longitude) -{ - m_latitude = latitude; - m_longitude = longitude; -} - -double SolarSystemObject::rev(double x) -{ - return x - floor(x / 360.0) * 360.0; -} - -double SolarSystemObject::asind(double x) -{ - return asin(x) * 180.0 / M_PI; -} - -double SolarSystemObject::sind(double x) -{ - return sin(x * M_PI / 180.0); -} - -double SolarSystemObject::cosd(double x) -{ - return cos(x * M_PI / 180.0); -} - -double SolarSystemObject::tand(double x) -{ - return tan(x * M_PI / 180.0); -} - -double SolarSystemObject::atan2d(double y, double x) -{ - return atan2(y, x) * 180.0 / M_PI; -} - -double SolarSystemObject::atand(double x) -{ - return atan(x) * 180.0 / M_PI; -} - -void SolarSystemObject::toRectangular(double lo, double la, double r, double *x, double *y, double *z) -{ - *x = r * cosd(lo) * cosd(la); - *y = r * sind(lo) * cosd(la); - *z = r * sind(la); -} - -void SolarSystemObject::toSpherical(double x, double y, double z, double *lo, double *la, double *r) -{ - *r = sqrt(x * x + y * y + z * z); - *la = asind(z / *r); - *lo = rev(atan2d(y, x)); -} - -QPair SolarSystemObject::zeroPoints(QPointF p1, QPointF p2, QPointF p3) -{ - double a = ((p2.y() - p1.y()) * (p1.x() - p3.x()) + (p3.y() - p1.y()) * (p2.x() - p1.x())) / - ((p1.x() - p3.x()) * (p2.x() * p2.x() - p1.x() * p1.x()) + (p2.x() - p1.x()) * - (p3.x() * p3.x() - p1.x() * p1.x())); - double b = ((p2.y() - p1.y()) - a * (p2.x() * p2.x() - p1.x() * p1.x())) / (p2.x() - p1.x()); - double c = p1.y() - a * p1.x() * p1.x() - b * p1.x(); - double discriminant = b * b - 4.0 * a * c; - double z1 = -1.0, z2 = -1.0; - - if (discriminant >= 0.0) { - z1 = (-b + sqrt(discriminant)) / (2 * a); - z2 = (-b - sqrt(discriminant)) / (2 * a); - } - return QPair(z1, z2); -} - -QList< QPair > SolarSystemObject::timesForAngles(const QList& angles, - const QDateTime& dt, - int offset) -{ - QList altitudes; - QDate d = dt.date(); - QDateTime local(d, QTime(0, 0)); - for (int j = 0; j <= 25; ++j) { - calcForDateTime(local, offset); - altitudes.append(altitude()); - local = local.addSecs(60 * 60); - } - QList< QPair > result; - QTime rise, set; - foreach (double angle, angles) { - for (int j = 3; j <= 25; j += 2) { - QPointF p1((j - 2) * 60 * 60, altitudes[j - 2] - angle); - QPointF p2((j - 1) * 60 * 60, altitudes[j - 1] - angle); - QPointF p3(j * 60 * 60, altitudes[j] - angle); - QPair z = zeroPoints(p1, p2, p3); - if (z.first > p1.x() && z.first < p3.x()) { - if (p1.y() < 0.0) { - rise = QTime(0, 0).addSecs(z.first); - } else { - set = QTime(0, 0).addSecs(z.first); - } - } - if (z.second > p1.x() && z.second < p3.x()) { - if (p3.y() < 0.0) { - set = QTime(0, 0).addSecs(z.second); - } else { - rise = QTime(0, 0).addSecs(z.second); - } - } - } - result.append(QPair(QDateTime(d, rise), QDateTime(d, set))); - } - return result; -} - -double SolarSystemObject::calcElevation() -{ - double refractionCorrection; - - if (m_altitude > 85.0) { - refractionCorrection = 0.0; - } else { - double te = tand(m_altitude); - if (m_altitude > 5.0) { - refractionCorrection = 58.1 / te - 0.07 / (te * te * te) + - 0.000086 / (te * te * te * te * te); - } else if (m_altitude > -0.575) { - refractionCorrection = 1735.0 + m_altitude * - (-518.2 + m_altitude * (103.4 + m_altitude * - (-12.79 + m_altitude * 0.711) ) ); - } else { - refractionCorrection = -20.774 / te; - } - refractionCorrection = refractionCorrection / 3600.0; - } - return m_altitude + refractionCorrection; -} diff --git a/plasma/dataengines/time/solarsystem.h b/plasma/dataengines/time/solarsystem.h deleted file mode 100644 index da43d3da..00000000 --- a/plasma/dataengines/time/solarsystem.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2009 Petri Damsten - * - * 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, see . - */ - -#ifndef SOLARSYSTEM_H -#define SOLARSYSTEM_H - -#include -#include -#include - -/* - * Mathematics, ideas, public domain code used for these classes from: - * http://www.stjarnhimlen.se/comp/tutorial.html - * http://www.stjarnhimlen.se/comp/riset.html - * http://www.srrb.noaa.gov/highlights/solarrise/azel.html - * http://www.srrb.noaa.gov/highlights/sunrise/sunrise.html - * http://bodmas.org/astronomy/riset.html - * moontool.c by John Walker - * Wikipedia - */ - -class SolarSystemObject -{ - public: - SolarSystemObject(); - virtual ~SolarSystemObject(); - - double meanLongitude() const { return L; }; - double meanAnomaly() const { return M; }; - double siderealTime(); - double altitude() const { return m_altitude; }; - double azimuth() const { return m_azimuth; }; - double calcElevation(); - QDateTime dateTime() const { return m_local; }; - double lambda() const { return m_lambda; }; - double eclipticLongitude() const { return m_eclipticLongitude; }; - void setPosition(double latitude, double longitude); - - virtual void calcForDateTime(const QDateTime& local, int offset); - QList< QPair > timesForAngles(const QList& angles, - const QDateTime& dt, - int offset); - - protected: - void calc(); - virtual bool calcPerturbations(double*, double*, double*) { return false; }; - virtual void rotate(double*, double*) { }; - virtual void topocentricCorrection(double*, double*) { }; - - inline double rev(double x); - inline double asind(double x); - inline double sind(double x); - inline double cosd(double x); - inline double atand(double x); - inline double tand(double x); - inline double atan2d(double y, double x); - void toRectangular(double lo, double la, double r, double *x, double *y, double *z); - void toSpherical(double x, double y, double z, double *lo, double *la, double *r); - QPair zeroPoints(QPointF p1, QPointF p2, QPointF p3); - - double N; - double i; - double w; - double a; - double e; - double M; - double m_obliquity; - - QDateTime m_utc; - QDateTime m_local; - double m_day; - double m_latitude; - double m_longitude; - - double L; - double rad; - double RA; - double dec; - double HA; - double m_altitude; - double m_azimuth; - double m_eclipticLongitude; - double m_lambda; -}; - -class Sun : public SolarSystemObject -{ - public: - Sun(); - virtual void calcForDateTime(const QDateTime& local, int offset); - - protected: - virtual void rotate(double*, double*); -}; - -class Moon : public SolarSystemObject -{ - public: - Moon(Sun *sunptr); - virtual ~Moon() {}; // to not delete the Sun - - virtual void calcForDateTime(const QDateTime& local, int offset); - double phase(); - - protected: - virtual bool calcPerturbations(double *RA, double *dec, double *r); - virtual void rotate(double*, double*); - virtual void topocentricCorrection(double*, double*); - - private: - Sun *m_sun; -}; - -#endif diff --git a/plasma/dataengines/time/timeengine.cpp b/plasma/dataengines/time/timeengine.cpp deleted file mode 100644 index 9f2ed344..00000000 --- a/plasma/dataengines/time/timeengine.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2007 Aaron Seigo - * Copyright 2008 Alex Merry - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 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 Library 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. - */ - -#include "timeengine.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "timesource.h" - -TimeEngine::TimeEngine(QObject *parent, const QVariantList &args) - : Plasma::DataEngine(parent, args) -{ - Q_UNUSED(args) - setMinimumPollingInterval(333); - - // To have translated timezone names - // (effectively a noop if the catalog is already present). - KGlobal::locale()->insertCatalog("timezones4"); -} - -TimeEngine::~TimeEngine() -{ -} - -void TimeEngine::init() -{ - QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.connect(QString(), "/org/kde/kcmshell_clock", "org.kde.kcmshell_clock", "clockUpdated", this, SLOT(clockSkewed())); - - connect(Solid::PowerManagement::notifier(), SIGNAL(resumingFromSuspend()), this , SLOT(clockSkewed())); - - m_tz = KSystemTimeZones::local().name(); - QTimer::singleShot(3000, this, SLOT(checkTZ())); -} - -void TimeEngine::clockSkewed() -{ - kDebug() << "Time engine Clock skew signaled"; - updateAllSources(); - forceImmediateUpdateOfAllVisualizations(); -} - -void TimeEngine::checkTZ() -{ - const QString localtz = KSystemTimeZones::local().name(); - if (localtz != m_tz) { - m_tz = localtz; - - TimeSource *s = qobject_cast(containerForSource("Local")); - - if (s) { - s->setTimeZone("Local"); - } - - updateAllSources(); - } - QTimer::singleShot(3000, this, SLOT(checkTZ())); -} - -QStringList TimeEngine::sources() const -{ - const KTimeZoneList timezones = KSystemTimeZones::zones(); - QStringList timezonenames; - timezonenames.reserve(timezones.size()); - foreach (const KTimeZone &zone, timezones) { - timezonenames.append(zone.name()); - } - timezonenames << QString::fromLatin1("Local"); - return timezonenames; -} - -bool TimeEngine::sourceRequestEvent(const QString &name) -{ - addSource(new TimeSource(name, this)); - return true; -} - -bool TimeEngine::updateSourceEvent(const QString &tz) -{ - TimeSource *s = qobject_cast(containerForSource(tz)); - - if (s) { - s->updateTime(); - scheduleSourcesUpdated(); - return true; - } - - return false; -} - -K_EXPORT_PLASMA_DATAENGINE(time, TimeEngine) - -#include "moc_timeengine.cpp" diff --git a/plasma/dataengines/time/timeengine.h b/plasma/dataengines/time/timeengine.h deleted file mode 100644 index c940f713..00000000 --- a/plasma/dataengines/time/timeengine.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2007 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 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 Library 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. - */ - -#ifndef TIMEENGINE_H -#define TIMEENGINE_H - -#include - -/** - * This engine provides the current date and time for a given - * timezone. Optionally it can also provide solar position info. - * - * "Local" is a special source that is an alias for the current - * timezone. - */ -class TimeEngine : public Plasma::DataEngine -{ - Q_OBJECT - - public: - TimeEngine(QObject *parent, const QVariantList &args); - ~TimeEngine(); - - void init(); - QStringList sources() const; - - protected: - bool sourceRequestEvent(const QString &name); - bool updateSourceEvent(const QString &source); - - protected Q_SLOTS: - void clockSkewed(); // call when system time changed and all clocks should be updated - void checkTZ(); - - private: - QString m_tz; -}; - -#endif // TIMEENGINE_H diff --git a/plasma/dataengines/time/timesource.cpp b/plasma/dataengines/time/timesource.cpp deleted file mode 100644 index cc0e62a8..00000000 --- a/plasma/dataengines/time/timesource.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright 2009 Aaron Seigo - * - * Moon Phase: - * Copyright 1998,2000 Stephan Kulow - * Copyright 2009 by Davide Bettio - * - * Solar position: - * Copyright (C) 2009 Petri Damsten - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 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 Library 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. - */ - -#include "timesource.h" - -#include - -#include -#include - -#include "solarsystem.h" - -TimeSource::TimeSource(const QString &name, QObject *parent) - : Plasma::DataContainer(parent), - m_offset(0), - m_latitude(0), - m_longitude(0), - m_sun(0), - m_moon(0), - m_moonPosition(false), - m_solarPosition(false), - m_local(false) -{ - setObjectName(name); - setTimeZone(parseName(name)); -} - -void TimeSource::setTimeZone(const QString &tz) -{ - m_tzName = tz; - m_local = m_tzName == I18N_NOOP("Local"); - if (m_local) { - m_tzName = KSystemTimeZones::local().name(); - } - - const QString trTimezone = i18n(m_tzName.toUtf8()); - setData(I18N_NOOP("Timezone"), trTimezone); - - const QStringList tzParts = trTimezone.split('/', QString::SkipEmptyParts); - if (tzParts.count() == 1) { - // no '/' so just set it as the city - setData(I18N_NOOP("Timezone City"), trTimezone); - } else { - setData(I18N_NOOP("Timezone Continent"), tzParts.value(0)); - setData(I18N_NOOP("Timezone City"), tzParts.value(1)); - } - - updateTime(); -} - -TimeSource::~TimeSource() -{ - // First delete the moon, that does not delete the Sun, and then the Sun - // If the Sun is deleted before the moon, the moon has a invalid pointer - // to where the Sun was pointing. - delete m_moon; - delete m_sun; -} - -void TimeSource::updateTime() -{ - KTimeZone tz; - if (m_local) { - tz = KSystemTimeZones::local(); - } else { - tz = KSystemTimeZones::zone(m_tzName); - if (!tz.isValid()) { - tz = KSystemTimeZones::local(); - } - } - - int offset = tz.currentOffset(); - if (m_offset != offset) { - m_offset = offset; - setData(I18N_NOOP("Offset"), m_offset); - } - - QDateTime dt = m_userDateTime ? data()["DateTime"].toDateTime() - : tz.toZoneTime(QDateTime::currentDateTimeUtc()); - - if (m_solarPosition || m_moonPosition) { - const QDate prev = data()["Date"].toDate(); - const bool updateDailies = prev != dt.date(); - - if (m_solarPosition) { - if (updateDailies) { - addDailySolarPositionData(dt); - } - - addSolarPositionData(dt); - } - - if (m_moonPosition) { - if (updateDailies) { - addDailyMoonPositionData(dt); - } - - addMoonPositionData(dt); - } - } - - if (!m_userDateTime) { - setData(I18N_NOOP("Time"), dt.time()); - setData(I18N_NOOP("Date"), dt.date()); - setData(I18N_NOOP("DateTime"), dt); - } -} - -QString TimeSource::parseName(const QString &name) -{ - m_userDateTime = false; - if (!name.contains('|')) { - // the simple case where it's just a timezone request - return name; - } - - // the various keys we recognize - static const QString latitude = I18N_NOOP("Latitude"); - static const QString longitude = I18N_NOOP("Longitude"); - static const QString solar = I18N_NOOP("Solar"); - static const QString moon = I18N_NOOP("Moon"); - static const QString datetime = I18N_NOOP("DateTime"); - - // now parse out what we got handed in - const QStringList list = name.split('|', QString::SkipEmptyParts); - - // set initial values for latitude and longitude, if available - const KTimeZone timezone = ((list.at(0) == I18N_NOOP("Local")) ? KSystemTimeZones::local() : KSystemTimeZones::zone(list.at(0))); - - if (timezone.isValid() && timezone.latitude() != KTimeZone::UNKNOWN) { - m_latitude = timezone.latitude(); - m_longitude = timezone.longitude(); - } - - const int listSize = list.size(); - for (int i = 1; i < listSize; ++i) { - const QString arg = list[i]; - const int n = arg.indexOf('='); - - if (n != -1) { - const QString key = arg.mid(0, n); - const QString value = arg.mid(n + 1); - - if (key == latitude) { - m_latitude = value.toDouble(); - } else if (key == longitude) { - m_longitude = value.toDouble(); - } else if (key == datetime) { - QDateTime dt = QDateTime::fromString(value, Qt::ISODate); - if (dt.isValid()) { - setData(I18N_NOOP("DateTime"), dt); - setData(I18N_NOOP("Date"), dt.date()); - setData(I18N_NOOP("Time"), dt.time()); - m_userDateTime = true; - } - } - } else if (arg == solar) { - m_solarPosition = true; - } else if (arg == moon) { - m_moonPosition = true; - } - } - - // timezone is first item ... - return list.at(0); -} - -Sun* TimeSource::sunptr() -{ - if (!m_sun) { - m_sun = new Sun(); - } - m_sun->setPosition(m_latitude, m_longitude); - return m_sun; -} - -Moon* TimeSource::moonptr() -{ - if (!m_moon) { - m_moon = new Moon(sunptr()); - } - m_moon->setPosition(m_latitude, m_longitude); - return m_moon; -} - -void TimeSource::addMoonPositionData(const QDateTime &dt) -{ - Moon* m = moonptr(); - m->calcForDateTime(dt, m_offset); - setData("Moon Azimuth", m->azimuth()); - setData("Moon Zenith", 90 - m->altitude()); - setData("Moon Corrected Elevation", m->calcElevation()); - setData("MoonPhaseAngle", m->phase()); -} - -void TimeSource::addDailyMoonPositionData(const QDateTime &dt) -{ - Moon* m = moonptr(); - QList< QPair > times = m->timesForAngles( - QList() << -0.833, dt, m_offset); - setData("Moonrise", times[0].first); - setData("Moonset", times[0].second); - m->calcForDateTime(QDateTime(dt.date(), QTime(12,0)), m_offset); - setData("MoonPhase", int(m->phase() / 360.0 * 29.0)); -} - -void TimeSource::addSolarPositionData(const QDateTime &dt) -{ - Sun* s = sunptr(); - s->calcForDateTime(dt, m_offset); - setData("Azimuth", s->azimuth()); - setData("Zenith", 90.0 - s->altitude()); - setData("Corrected Elevation", s->calcElevation()); -} - -void TimeSource::addDailySolarPositionData(const QDateTime &dt) -{ - Sun* s = sunptr(); - QList< QPair > times = s->timesForAngles( - QList() << -0.833 << -6.0 << -12.0 << -18.0, dt, m_offset); - - setData("Sunrise", times[0].first); - setData("Sunset", times[0].second); - setData("Civil Dawn", times[1].first); - setData("Civil Dusk", times[1].second); - setData("Nautical Dawn", times[2].first); - setData("Nautical Dusk", times[2].second); - setData("Astronomical Dawn", times[3].first); - setData("Astronomical Dusk", times[3].second); -} - diff --git a/plasma/dataengines/time/timesource.h b/plasma/dataengines/time/timesource.h deleted file mode 100644 index 3acb8a1b..00000000 --- a/plasma/dataengines/time/timesource.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2009 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 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 Library 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. - */ - -#ifndef TIMESOURCE_H -#define TIMESOURCE_H - -#include -#include - -class Sun; -class Moon; - -class TimeSource : public Plasma::DataContainer -{ - Q_OBJECT - -public: - explicit TimeSource(const QString &name, QObject *parent = 0); - ~TimeSource(); - void setTimeZone(const QString &name); - void updateTime(); - -private: - QString parseName(const QString &name); - void addMoonPositionData(const QDateTime &dt); - void addDailyMoonPositionData(const QDateTime &dt); - void addSolarPositionData(const QDateTime &dt); - void addDailySolarPositionData(const QDateTime &dt); - Sun* sunptr(); - Moon* moonptr(); - - QString m_tzName; - int m_offset; - double m_latitude; - double m_longitude; - Sun *m_sun; - Moon *m_moon; - bool m_moonPosition : 1; - bool m_solarPosition : 1; - bool m_userDateTime : 1; - bool m_local : 1; -}; - -#endif -