diff --git a/applets/locationchooser/Engine.cpp b/applets/locationchooser/Engine.cpp index 3c4715ac..ac46a61d 100644 --- a/applets/locationchooser/Engine.cpp +++ b/applets/locationchooser/Engine.cpp @@ -1,233 +1,248 @@ /* * Copyright (C) 2012 Ivan Cukic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, as published by the Free * Software Foundation * * 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 "Engine.h" #include #include #include #define LOCATION_MANAGER_DBUS_PATH "org.kde.LocationManager" #define LOCATION_MANAGER_DBUS_OBJECT "/LocationManager" class Engine::Private { public: org::kde::LocationManager * locationManager; Plasma::PopupApplet * parent; QSizeF regularSize; - QStringList locations; + QVariantHash locations; qreal listItemHeight; QDBusServiceWatcher * watcher; }; Engine::Engine(Plasma::PopupApplet * parent) : QObject(parent), d(new Private()) { d->locationManager = NULL; d->parent = parent; } void Engine::init() { d->watcher = new QDBusServiceWatcher(QLatin1String(LOCATION_MANAGER_DBUS_PATH), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this); connect(d->watcher, SIGNAL(serviceRegistered(QString)), this, SLOT(onServiceRegistered())); connect(d->watcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(onServiceUnregistered())); bool servicePresent = QDBusConnection::sessionBus().interface()->isServiceRegistered(LOCATION_MANAGER_DBUS_PATH); if (servicePresent) { onServiceRegistered(); } else { onServiceUnregistered(); } } void Engine::onServiceRegistered() { d->locationManager = new org::kde::LocationManager( LOCATION_MANAGER_DBUS_PATH, LOCATION_MANAGER_DBUS_OBJECT, QDBusConnection::sessionBus(), this); // This would be so much nicer as a .\ in C++11 // Heck, it would be nicer even with boost::bind class GetLocations: public QThread { public: GetLocations(Engine * parent_, Engine::Private * d_) : parent(parent_), d(d_) { } protected: void run() { foreach (const QString & id, d->locationManager->knownLocations().value()) { if (id.isEmpty()) continue; - d->locations << d->locationManager->locationName(id); + QVariantHash loc; + loc["id"] = id; + loc["name"] = QString(d->locationManager->locationName(id)); + d->locations[id] = loc; } QMetaObject::invokeMethod(parent, "knownLocationsChanged", - Qt::QueuedConnection, Q_ARG(QStringList, d->locations)); + Qt::QueuedConnection, Q_ARG(QVariantList, d->locations.values())); deleteLater(); } private: Engine * const parent; Engine::Private * const d; }; connect(d->locationManager, SIGNAL(currentLocationChanged(QString,QString)), this, SLOT(onCurrentLocationChanged(QString,QString))); connect(d->locationManager, SIGNAL(locationAdded(QString,QString)), this, SLOT(onLocationAdded(QString,QString))); connect(d->locationManager, SIGNAL(locationRemoved(QString,QString)), this, SLOT(onLocationRemoved(QString,QString))); connect(d->locationManager, SIGNAL(locationNameChanged(QString,QString,QString)), this, SLOT(onLocationNameChanged(QString,QString,QString))); // Starting the async getter (new GetLocations(this, d))->start(); emit locationManagerPresenceChanged(); setIcon("location"); } void Engine::onServiceUnregistered() { delete d->locationManager; d->locationManager = NULL; setState("Error"); emit locationManagerPresenceChanged(); d->parent->setPopupIcon("application-exit"); } void Engine::setIcon(const QString & icon) { if (d->locationManager) { d->parent->setPopupIcon("plasmaapplet-" + icon); } else { d->parent->setPopupIcon("application-exit"); } } QString Engine::currentLocationId() const { if (d->locationManager) return d->locationManager->currentLocationId(); else return i18n("The location manager is not running"); } QString Engine::currentLocationName() const { if (d->locationManager) return d->locationManager->currentLocationName(); else return i18n("The location manager is not running"); } void Engine::onCurrentLocationChanged(const QString & id, const QString & name) { emit currentLocationIdChanged(id); emit currentLocationNameChanged(name); } void Engine::setCurrentLocation(const QString & location) { if (d->locationManager) { d->locationManager->setCurrentLocation(location); } d->parent->hidePopup(); } +void Engine::removeLocation(const QString & location) +{ + if (d->locationManager) { + d->locationManager->removeLocation(location); + } +} + void Engine::requestUiReset() { setIcon("location"); emit resetUiRequested(); } void Engine::setState(const QString & state) { if (state == "Showing" || state == "Error") { d->parent->graphicsWidget()->resize(d->regularSize); } else if (state == "Querying") { d->regularSize = d->parent->graphicsWidget()->size(); QSizeF bigSize(d->regularSize); qreal height = bigSize.height() + d->locations.size() * (4 + d->listItemHeight); if (height > 400) { height = 400; } bigSize.setHeight(height); d->parent->graphicsWidget()->resize(bigSize); } } void Engine::setListItemHeight(qreal height) { d->listItemHeight = height; } -QStringList Engine::knownLocations() const +QVariantList Engine::knownLocations() const { - return d->locations; + return d->locations.values(); } void Engine::onLocationAdded(const QString & id, const QString & name) { Q_UNUSED(id) - d->locations << name; - emit knownLocationsChanged(d->locations); + QVariantHash location; + location["id"] = id; + location["name"] = name; + d->locations[id] = location; + emit knownLocationsChanged(d->locations.values()); } void Engine::onLocationRemoved(const QString & id, const QString & name) { Q_UNUSED(id) - d->locations.removeAll(name); - emit knownLocationsChanged(d->locations); + d->locations.remove(id); + emit knownLocationsChanged(d->locations.values()); } void Engine::onLocationNameChanged(const QString & id, const QString & oldname, const QString & newname) { Q_UNUSED(id) - d->locations.removeAll(oldname); - d->locations << newname; - emit knownLocationsChanged(d->locations); + QVariantHash location; + location["id"] = id; + location["name"] = newname; + d->locations[id] = location; + emit knownLocationsChanged(d->locations.values()); } bool Engine::locationManagerPresent() const { return (d->locationManager != NULL); } diff --git a/applets/locationchooser/Engine.h b/applets/locationchooser/Engine.h index bb2eb938..91d990b1 100644 --- a/applets/locationchooser/Engine.h +++ b/applets/locationchooser/Engine.h @@ -1,74 +1,76 @@ /* * Copyright (C) 2012 Ivan Cukic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, as published by the Free * Software Foundation * * 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 ENGINE_H_ #define ENGINE_H_ #include class Engine: public QObject { Q_OBJECT Q_PROPERTY(QString currentLocationId READ currentLocationId NOTIFY currentLocationIdChanged) Q_PROPERTY(QString currentLocationName READ currentLocationName NOTIFY currentLocationNameChanged) - Q_PROPERTY(QStringList knownLocations READ knownLocations NOTIFY knownLocationsChanged) + Q_PROPERTY(QVariantList knownLocations READ knownLocations NOTIFY knownLocationsChanged) Q_PROPERTY(bool locationManagerPresent READ locationManagerPresent NOTIFY locationManagerPresenceChanged) public: Engine(Plasma::PopupApplet * parent); void init(); public Q_SLOTS: void setIcon(const QString & icon); void setCurrentLocation(const QString & location); + void removeLocation(const QString & location); + QString currentLocationId() const; QString currentLocationName() const; - QStringList knownLocations() const; + QVariantList knownLocations() const; bool locationManagerPresent() const; void requestUiReset(); void setState(const QString & state); void setListItemHeight(qreal height); Q_SIGNALS: void currentLocationIdChanged(const QString & id); void currentLocationNameChanged(const QString & name); - void knownLocationsChanged(const QStringList & names); + void knownLocationsChanged(const QVariantList & names); void locationManagerPresenceChanged(); void resetUiRequested(); private Q_SLOTS: void onCurrentLocationChanged(const QString & id, const QString & name); void onLocationAdded(const QString & id, const QString & name); void onLocationRemoved(const QString & id, const QString & name); void onLocationNameChanged(const QString & id, const QString & oldname, const QString & newname); void onServiceRegistered(); void onServiceUnregistered(); private: class Private; Private * const d; }; #endif // ENGINE_H_ diff --git a/applets/locationchooser/package/ui/LocationChooser.qml b/applets/locationchooser/package/ui/LocationChooser.qml index cd0783f6..16596039 100644 --- a/applets/locationchooser/package/ui/LocationChooser.qml +++ b/applets/locationchooser/package/ui/LocationChooser.qml @@ -1,99 +1,104 @@ /* vim:set foldenable foldmethod=marker: * * Copyright (C) 2012 Ivan Cukic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, as published by the Free * Software Foundation * * 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. */ import QtQuick 1.0 as QML import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.components 0.1 as PlasmaComponents QML.Item { id: main /* property declarations --------------------------{{{ */ property alias location: textLocation.text property alias locationModel: listLocations.model /* }}} */ /* signal declarations ----------------------------{{{ */ signal requestChange(string location) /* }}} */ /* JavaScript functions ---------------------------{{{ */ /* }}} */ /* object properties ------------------------------{{{ */ /* }}} */ /* child objects ----------------------------------{{{ */ PlasmaComponents.TextField { id: textLocation anchors { bottom: parent.bottom top: buttonSet.top right: buttonSet.left left: parent.left } } PlasmaComponents.Button { id: buttonSet text: "Set" width: parent.width / 3 onClicked: main.requestChange(textLocation.text) anchors { bottom: parent.bottom right: parent.right } } + PlasmaCore.Svg { + id: configIconsSvg + imagePath: "widgets/configuration-icons" + } QML.ListView { id: listLocations clip: true delegate: LocationDelegate { - title: model.modelData + title: model.modelData.name onClicked: { print ("clicked") - main.requestChange(model.modelData) + main.requestChange(model.modelData.name) } + onRemoveAsked: locationManager.removeLocation(model.modelData.id) } anchors { top: parent.top left: parent.left right: parent.right bottom: buttonSet.top } } /* }}} */ /* states -----------------------------------------{{{ */ /* }}} */ /* transitions ------------------------------------{{{ */ /* }}} */ } diff --git a/applets/locationchooser/package/ui/LocationDelegate.qml b/applets/locationchooser/package/ui/LocationDelegate.qml index 4a0ee4f3..e9d0d691 100644 --- a/applets/locationchooser/package/ui/LocationDelegate.qml +++ b/applets/locationchooser/package/ui/LocationDelegate.qml @@ -1,71 +1,137 @@ /* vim:set foldenable foldmethod=marker: * * Copyright (C) 2012 Ivan Cukic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, as published by the Free * Software Foundation * * 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. */ -import QtQuick 1.0 as QML +import QtQuick 1.1 as QML import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.components 0.1 as PlasmaComponents PlasmaComponents.ListItem { id: main + enabled: true + opacity: 1-Math.abs(x)/width + signal removeAsked /* property declarations --------------------------{{{ */ property alias title: label.text /* }}} */ /* signal declarations ----------------------------{{{ */ /* }}} */ /* JavaScript functions ---------------------------{{{ */ /* }}} */ /* object properties ------------------------------{{{ */ /* }}} */ /* child objects ----------------------------------{{{ */ PlasmaComponents.Label { id: label elide: QML.Text.ElideRight anchors { fill: parent leftMargin: 8 rightMargin: 8 } } - QML.MouseArea { anchors.fill: parent onClicked: main.clicked() onPressAndHold: { // show actions... } + drag { + target: main + axis: QML.Drag.XAxis + } + onReleased: { + if (main.x < -main.width/2) { + removeAnimation.exitFromRight = false + removeAnimation.running = true + } else if (main.x > main.width/2 ) { + removeAnimation.exitFromRight = true + removeAnimation.running = true + } else { + resetAnimation.running = true + } + } + } + PlasmaCore.SvgItem { + svg: configIconsSvg + elementId: "close" + width: theme.mediumIconSize + height: theme.mediumIconSize + anchors { + top: parent.top + right: parent.right + rightMargin: 12 + } + QML.MouseArea { + anchors.fill: parent + onClicked: { + removeAnimation.running = true + } + } + } + + QML.SequentialAnimation { + id: removeAnimation + property bool exitFromRight: true + QML.NumberAnimation { + target: main + properties: "x" + to: removeAnimation.exitFromRight ? main.width : -main.width + duration: 250 + easing.type: QML.Easing.InQuad + } + QML.NumberAnimation { + target: main + properties: "height" + to: 0 + duration: 250 + easing.type: QML.Easing.InOutQuad + } + QML.ScriptAction { + script: removeAsked() + } + } + QML.SequentialAnimation { + id: resetAnimation + QML.NumberAnimation { + target: main + properties: "x" + to: 0 + duration: 250 + easing.type: QML.Easing.InOutQuad + } } /* }}} */ /* states -----------------------------------------{{{ */ /* }}} */ /* transitions ------------------------------------{{{ */ /* }}} */ } diff --git a/applets/notifications/contents/ui/NotificationDelegate.qml b/applets/notifications/contents/ui/NotificationDelegate.qml index d476584c..486e73c9 100644 --- a/applets/notifications/contents/ui/NotificationDelegate.qml +++ b/applets/notifications/contents/ui/NotificationDelegate.qml @@ -1,146 +1,147 @@ /* * Copyright 2011 Marco Martin * * 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 Library 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. */ import QtQuick 1.0 import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.components 0.1 as PlasmaComponents import org.kde.qtextracomponents 0.1 PlasmaComponents.ListItem { id: notificationItem + opacity: 1-Math.abs(x)/width width: popupFlickable.width Timer { interval: 30*60*1000 repeat: false running: true onTriggered: { notificationsModel.remove(index) } } MouseArea { width: popupFlickable.width height: childrenRect.height drag { target: notificationItem axis: Drag.XAxis } onReleased: { if (notificationItem.x < -notificationItem.width/2) { removeAnimation.exitFromRight = false removeAnimation.running = true } else if (notificationItem.x > notificationItem.width/2 ) { removeAnimation.exitFromRight = true removeAnimation.running = true } else { resetAnimation.running = true } } SequentialAnimation { id: removeAnimation property bool exitFromRight: true NumberAnimation { target: notificationItem properties: "x" to: removeAnimation.exitFromRight ? notificationItem.width : -notificationItem.width duration: 250 easing.type: Easing.InOutQuad } NumberAnimation { target: notificationItem properties: "height" to: 0 duration: 250 easing.type: Easing.InOutQuad } ScriptAction { script: notificationsModel.remove(index) } } SequentialAnimation { id: resetAnimation NumberAnimation { target: notificationItem properties: "x" to: 0 duration: 250 easing.type: Easing.InOutQuad } } Column { spacing: 8 width: popupFlickable.width Item { width: parent.width height: appNameLabel.height QIconItem { id: appIconItem icon: QIcon(appIcon) width: theme.mediumIconSize height: theme.mediumIconSize } PlasmaComponents.Label { id: appNameLabel text: appName font.bold: true height: paintedHeight anchors { left: appIconItem.right right: parent.right } horizontalAlignment: Text.AlignHCenter elide: Text.ElideRight } PlasmaCore.SvgItem { svg: configIconsSvg elementId: "close" width: theme.mediumIconSize height: theme.mediumIconSize anchors { top: parent.top right: parent.right rightMargin: 12 } MouseArea { anchors.fill: parent anchors.margins: -6 onClicked: { removeAnimation.running = true } } } } PlasmaComponents.Label { text: body color: theme.textColor anchors { left: parent.left right:parent.right leftMargin: theme.mediumIconSize+6 rightMargin: theme.mediumIconSize+6 } wrapMode: Text.Wrap } } } }