Skip to content

Commit

Permalink
Added setting ambience directly from the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
SfietKonstantin committed Sep 6, 2014
1 parent 2e01a9a commit a80ff5a
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pro.user
build
10 changes: 8 additions & 2 deletions harbour-trulyyours.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ TEMPLATE = app
TARGET = harbour-trulyyours
CONFIG += sailfishapp

QT += dbus

system(qdbusxml2cpp -p src/ambienced.h:src/ambienced.cpp src/ambienced.xml)

HEADERS += \
src/ambiencemanager.h \
src/tagmanager.h
src/tagmanager.h \
src/ambienced.h

SOURCES += src/harbour-trulyyours.cpp \
src/ambiencemanager.cpp \
src/tagmanager.cpp
src/tagmanager.cpp \
src/ambienced.cpp

OTHER_FILES += rpm/$${TARGET}.spec \
rpm/$${TARGET}.yaml \
Expand Down
9 changes: 9 additions & 0 deletions qml/pages/AmbienceDetailPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ Page {
contentHeight: fullImage.height

PullDownMenu {
MenuItem {
text: qsTr("Save and create ambience")
visible: fullImage.source != "" && !savingInProgress
onClicked: {
savingInProgress = true;
ambienceMgr.saveImageToGalleryAndApplyAmbience(name)
}
}

MenuItem {
text: qsTr("Save to gallery")
visible: fullImage.source != "" && !savingInProgress
Expand Down
2 changes: 2 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ambienced.h
ambienced.cpp
60 changes: 60 additions & 0 deletions src/ambienced.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"https://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="com.jolla.ambienced">
<method name="indexFile">
<arg direction="in" type="s" name="url"/>
</method>
<method name="createAmbience">
<arg direction="in" type="s" name="url"/>
</method>
<method name="setAmbience">
<arg direction="in" type="s" name="url"/>
</method>
<method name="remove">
<arg direction="in" type="i" name="contentType"/>
<arg direction="in" type="x" name="contentId"/>
</method>
<method name="installPackage">
<arg direction="in" type="s" name="path"/>
</method>
<method name="saveAttributes">
<arg direction="in" type="i" name="contentType"/>
<arg direction="in" type="x" name="contentId"/>
<arg direction="in" type="a{sv}" name="args"/>
<annotation value="QVariantMap" name="org.qtproject.QtDBus.QtTypeName.In2"/>
</method>
<method name="refreshAmbiences"/>
<signal name="contentChanged">
<arg direction="out" type="i" name="type"/>
</signal>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface_name" type="s" direction="in"/>
<arg name="property_name" type="s" direction="in"/>
<arg name="value" type="v" direction="out"/>
</method>
<method name="Set">
<arg name="interface_name" type="s" direction="in"/>
<arg name="property_name" type="s" direction="in"/>
<arg name="value" type="v" direction="in"/>
</method>
<method name="GetAll">
<arg name="interface_name" type="s" direction="in"/>
<arg name="values" type="a{sv}" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml_data" type="s" direction="out"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Peer">
<method name="Ping"/>
<method name="GetMachineId">
<arg name="machine_uuid" type="s" direction="out"/>
</method>
</interface>
</node>
42 changes: 33 additions & 9 deletions src/ambiencemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
#include <QImage>
#include <QFileInfo>
#include <QDir>
#include <QUrl>
#include <QVariant>

static const char *AMBIENCED_SERVICE = "com.jolla.ambienced";
static const char *AMBIENCED_PATH = "/com/jolla/ambienced";

AmbienceManager::AmbienceManager(QObject *parent) :
QObject(parent),
mThumbnailReply(0),
mFullImageReply(0),
mThumbnail(0),
mFullImage(0)
mFullImage(0),
mInterface(0)
{
mPictureLocation = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
mCacheLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
Expand All @@ -20,6 +25,8 @@ AmbienceManager::AmbienceManager(QObject *parent) :
{
qDebug() << "failed to create cachedir";
}

mInterface = new ComJollaAmbiencedInterface(AMBIENCED_SERVICE, AMBIENCED_PATH, QDBusConnection::sessionBus(), this);
}

AmbienceManager::~AmbienceManager()
Expand Down Expand Up @@ -70,18 +77,35 @@ bool AmbienceManager::hasThumbnail(QString name)
return (QFile::exists(filePath));
}

void AmbienceManager::saveImageToGallery(QString name)
static inline QString createAmbienceImage(const QString &pictureLocation, const QString &name)
{
if (QFile::exists(mCacheLocation + "/ambience-" + name))
{
QFile::copy(mCacheLocation + "/ambience-" + name, mPictureLocation + "/ambience-" + name);
mSavedFullImages.append(mCacheLocation + "/ambience-" + name);
emit saveImageToGallerySucceeded();
}
else
return pictureLocation + "/ambience-" + name;
}

bool AmbienceManager::saveImageToGallery(QString name)
{
if (!QFile::exists(mCacheLocation + "/ambience-" + name))
{
qDebug() << name << "does not exist, cannot copy to gallery";
return false;
}

QFile::copy(mCacheLocation + "/ambience-" + name, createAmbienceImage(mPictureLocation, name));
mSavedFullImages.append(mCacheLocation + "/ambience-" + name);
emit saveImageToGallerySucceeded();
return true;
}

bool AmbienceManager::saveImageToGalleryAndApplyAmbience(const QString &name)
{
if (!saveImageToGallery(name)) {
return false;
}

QString url = QUrl::fromLocalFile(createAmbienceImage(mPictureLocation, name)).toString();
mInterface->createAmbience(url);
mInterface->setAmbience(url);
return true;
}

void AmbienceManager::saveThumbnail(QUrl fileUrl, QString name)
Expand Down
5 changes: 4 additions & 1 deletion src/ambiencemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QFile>
#include <QQueue>
#include <QStringList>
#include "ambienced.h"

class AmbienceManager : public QObject
{
Expand All @@ -17,7 +18,8 @@ class AmbienceManager : public QObject
virtual ~AmbienceManager();
Q_INVOKABLE QString thumbnail(QString name);
Q_INVOKABLE bool hasThumbnail(QString name);
Q_INVOKABLE void saveImageToGallery(QString name);
Q_INVOKABLE bool saveImageToGallery(QString name);
Q_INVOKABLE bool saveImageToGalleryAndApplyAmbience(const QString &name);

signals:
void saveImageToGallerySucceeded();
Expand All @@ -43,6 +45,7 @@ public slots:
QString mCacheLocation;
QQueue<QPair<QUrl, QString> > mThumbnailQueue;
QStringList mSavedFullImages;
ComJollaAmbiencedInterface *mInterface;
};

#endif // AMBIENCEMANAGER_H

0 comments on commit a80ff5a

Please sign in to comment.