-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 02f2d62
Showing
16 changed files
with
1,325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include "ambiencemanager.h" | ||
#include <QStandardPaths> | ||
#include <QDebug> | ||
#include <QImage> | ||
#include <QFileInfo> | ||
#include <QDir> | ||
|
||
AmbienceManager::AmbienceManager(QObject *parent) : | ||
QObject(parent), mThumbnailReply(0), mFullImageReply(0) | ||
{ | ||
mPictureLocation = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); | ||
mCacheLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation); | ||
QDir root(QDir::rootPath()); | ||
if (!root.mkpath(mCacheLocation)) | ||
{ | ||
qDebug() << "failed to create cachedir"; | ||
} | ||
} | ||
|
||
QString AmbienceManager::thumbnail(QString name) | ||
{ | ||
return mCacheLocation + "/" + name; | ||
} | ||
|
||
bool AmbienceManager::hasThumbnail(QString name) | ||
{ | ||
QString filePath = mCacheLocation + "/" + name; | ||
return (QFile::exists(filePath)); | ||
} | ||
|
||
void AmbienceManager::saveImageToGallery(QString name) | ||
{ | ||
if (QFile::exists(mCacheLocation + "/" + "ambience-" + name)) | ||
{ | ||
QFile::copy(mCacheLocation + "/" + "ambience-" + name, mPictureLocation + "/" + "ambience-" + name); | ||
emit saveImageToGallerySucceeded(); | ||
} | ||
else | ||
{ | ||
qDebug() << name << "does not exist, cannot copy to gallery"; | ||
} | ||
} | ||
|
||
void AmbienceManager::saveThumbnail(QUrl fileUrl, QString name) | ||
{ | ||
mThumbnailQueue.enqueue(qMakePair(fileUrl, name)); | ||
if (!mThumbnailReply) // if no ongoing thumbnail download | ||
{ | ||
saveNextThumbnail(); | ||
} | ||
} | ||
|
||
void AmbienceManager::saveNextThumbnail() | ||
{ | ||
|
||
QPair<QUrl, QString> thumbnail = mThumbnailQueue.dequeue(); | ||
QNetworkRequest request; | ||
request.setUrl(QUrl(thumbnail.first)); | ||
mThumbnailReply = mNam.get(request); | ||
connect(mThumbnailReply, &QNetworkReply::finished, | ||
this, &AmbienceManager::onSaveThumbnailFinished); | ||
|
||
mThumbnail = new QFile; | ||
mThumbnail->setFileName(mCacheLocation + "/" + thumbnail.second); | ||
mThumbnail->open(QIODevice::WriteOnly); | ||
} | ||
|
||
void AmbienceManager::onSaveThumbnailFinished() | ||
{ | ||
disconnect(mThumbnailReply, &QNetworkReply::finished, | ||
this, &AmbienceManager::onSaveThumbnailFinished); | ||
if (!mThumbnailReply->error()) | ||
{ | ||
qDebug() << "no error, saving file"; | ||
QImage* fullSizeImage = new QImage; | ||
fullSizeImage->loadFromData(mThumbnailReply->readAll()); | ||
QImage thumbnailImage(fullSizeImage->scaled(QSize(250, 740))); | ||
delete fullSizeImage; | ||
thumbnailImage.save(mThumbnail); | ||
qDebug() << "saved: " << mThumbnail->fileName(); | ||
mThumbnail->close(); | ||
QFileInfo info(mThumbnail->fileName()); | ||
delete mThumbnail; | ||
mThumbnail = 0; | ||
emit saveThumbnailSucceeded(info.fileName()); | ||
} | ||
mThumbnailReply->deleteLater(); | ||
mThumbnailReply = 0; | ||
|
||
if (!mThumbnailQueue.isEmpty()) | ||
{ | ||
saveNextThumbnail(); | ||
} | ||
} | ||
|
||
void AmbienceManager::saveFullImage(QUrl fileUrl, QString name) | ||
{ | ||
QNetworkRequest request; | ||
request.setUrl(QUrl(fileUrl)); | ||
mFullImageReply = mNam.get(request); | ||
connect(mFullImageReply, &QNetworkReply::finished, | ||
this, &AmbienceManager::onSaveFullImageFinished); | ||
|
||
mFullImage = new QFile; | ||
mFullImage->setFileName(mCacheLocation + "/" + "ambience-" + name); | ||
mFullImage->open(QIODevice::WriteOnly); | ||
} | ||
|
||
void AmbienceManager::onSaveFullImageFinished() | ||
{ | ||
disconnect(mFullImageReply, &QNetworkReply::finished, | ||
this, &AmbienceManager::onSaveFullImageFinished); | ||
if (!mFullImageReply->error()) | ||
{ | ||
qDebug() << "no error, saving file"; | ||
mFullImage->write(mFullImageReply->readAll()); | ||
mFullImage->close(); | ||
emit saveFullImageSucceeded(mFullImage->fileName()); | ||
} | ||
mFullImageReply->deleteLater(); | ||
mFullImageReply = 0; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef AMBIENCEMANAGER_H | ||
#define AMBIENCEMANAGER_H | ||
|
||
#include <QObject> | ||
#include <QNetworkAccessManager> | ||
#include <QNetworkRequest> | ||
#include <QNetworkReply> | ||
#include <QFile> | ||
#include <QQueue> | ||
|
||
class AmbienceManager : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit AmbienceManager(QObject *parent = 0); | ||
Q_INVOKABLE QString thumbnail(QString name); | ||
Q_INVOKABLE bool hasThumbnail(QString name); | ||
Q_INVOKABLE void saveImageToGallery(QString name); | ||
|
||
signals: | ||
void saveImageToGallerySucceeded(); | ||
void saveThumbnailSucceeded(QString); | ||
void saveFullImageSucceeded(QString); | ||
|
||
public slots: | ||
Q_INVOKABLE void saveThumbnail(QUrl fileUrl, QString name); | ||
void onSaveThumbnailFinished(); | ||
Q_INVOKABLE void saveFullImage(QUrl fileUrl, QString name); | ||
void onSaveFullImageFinished(); | ||
|
||
private: // methods | ||
void saveNextThumbnail(); | ||
|
||
private: // data | ||
QNetworkAccessManager mNam; | ||
QNetworkReply* mThumbnailReply; | ||
QNetworkReply* mFullImageReply; | ||
QFile* mThumbnail; | ||
QFile* mFullImage; | ||
QString mPictureLocation; | ||
QString mCacheLocation; | ||
QQueue<QPair<QUrl, QString> > mThumbnailQueue; | ||
}; | ||
|
||
#endif // AMBIENCEMANAGER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[Desktop Entry] | ||
Type=Application | ||
X-Nemo-Application-Type=silica-qt5 | ||
Name=harbour-trulyyours | ||
Icon=harbour-trulyyours | ||
Exec=harbour-trulyyours | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# NOTICE: | ||
# | ||
# Application name defined in TARGET has a corresponding QML filename. | ||
# If name defined in TARGET is changed, the following needs to be done | ||
# to match new name: | ||
# - corresponding QML filename must be changed | ||
# - desktop icon filename must be changed | ||
# - desktop filename must be changed | ||
# - icon definition filename in desktop file must be changed | ||
# - translation filenames have to be changed | ||
|
||
# The name of your application | ||
TARGET = harbour-trulyyours | ||
|
||
CONFIG += sailfishapp | ||
|
||
SOURCES += src/harbour-trulyyours.cpp \ | ||
ambiencemanager.cpp | ||
|
||
OTHER_FILES += qml/harbour-trulyyours.qml \ | ||
qml/cover/CoverPage.qml \ | ||
rpm/$${TARGET}.spec \ | ||
rpm/$${TARGET}.yaml \ | ||
translations/*.ts \ | ||
$${TARGET}.desktop \ | ||
qml/pages/AmbienceDetailPage.qml \ | ||
qml/pages/BrowseAmbienceListPage.qml | ||
|
||
# to disable building translations every time, comment out the | ||
# following CONFIG line | ||
CONFIG += sailfishapp_i18n | ||
TRANSLATIONS += translations/$${TARGET}-de.ts | ||
|
||
HEADERS += \ | ||
ambiencemanager.h | ||
|
Oops, something went wrong.