Unverified Commit 66090dcd authored by Haelwenn's avatar Haelwenn

Add .clang-format and apply on relevant files

parent 7ecc846c
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: true
AlignOperands: true
AlignTrailingComments: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AlwaysBreakAfterReturnType: AllDefinitions
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Allman
SpaceBeforeParens: Never
IncludeBlocks: Regroup
ReflowComments: false
SortIncludes: true
UseTab: ForIndentation
IndentWidth: 2
TabWidth: 2
ColumnLimit: 100
NamespaceIndentation: All
......@@ -10,6 +10,8 @@ qmake
make
```
Reformatting non-QML files is done with clang-format: ``clang-format -style=file -assume-filename=.clang-format -i src/*.cpp src/*.h qml/lib/*.js``
If you need a platform to build it, you can use your probably already existent SailfishOS phone (in developer mode), the SailfishOS SDK. Sadly this won't build without some of the proprietary SailfishOS components (otherwise this would be a regular Qt QML application).
## Launching
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "dbus.h"
static const char *PATH = "/";
static const char *PATH = "/";
static const char *SERVICE = SERVICE_NAME;
Dbus::Dbus(QObject *parent) :
QObject(parent)
Dbus::Dbus(QObject *parent) : QObject(parent)
{
m_dbusRegistered = false;
new KyclosAdaptor(this);
registerDBus();
m_dbusRegistered = false;
new KyclosAdaptor(this);
registerDBus();
}
Dbus::~Dbus()
{
if (m_dbusRegistered)
{
QDBusConnection connection = QDBusConnection::sessionBus();
connection.unregisterObject(PATH);
connection.unregisterService(SERVICE);
}
if(m_dbusRegistered)
{
QDBusConnection connection = QDBusConnection::sessionBus();
connection.unregisterObject(PATH);
connection.unregisterService(SERVICE);
}
}
void Dbus::registerDBus()
void
Dbus::registerDBus()
{
if (!m_dbusRegistered)
{
QDBusConnection connection = QDBusConnection::sessionBus();
if (!connection.registerService(SERVICE))
{
QCoreApplication::quit();
return;
}
if(!m_dbusRegistered)
{
QDBusConnection connection = QDBusConnection::sessionBus();
if(!connection.registerService(SERVICE))
{
QCoreApplication::quit();
return;
}
if (!connection.registerObject(PATH, this))
{
QCoreApplication::quit();
return;
}
m_dbusRegistered = true;
}
if(!connection.registerObject(PATH, this))
{
QCoreApplication::quit();
return;
}
m_dbusRegistered = true;
}
}
void Dbus::showtoot(const QStringList &key)
void
Dbus::showtoot(const QStringList &key)
{
emit viewtoot(key.at(0));
emit viewtoot(key.at(0));
}
void Dbus::openapp()
void
Dbus::openapp()
{
emit activateapp();
emit activateapp();
}
#ifndef DBUS_H
#define DBUS_H
#include "dbusAdaptor.h"
#include <QObject>
#include <QtDBus/QtDBus>
#include "dbusAdaptor.h"
#define SERVICE_NAME "social.pleroma.harbour.kyclos"
class QDBusInterface;
class Dbus : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", SERVICE_NAME)
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", SERVICE_NAME)
public:
explicit Dbus(QObject *parent = 0);
~Dbus();
void registerDBus();
explicit Dbus(QObject *parent = 0);
~Dbus();
void registerDBus();
public Q_SLOTS:
Q_NOREPLY void showtoot(const QStringList &key);
Q_NOREPLY void openapp();
Q_NOREPLY void showtoot(const QStringList &key);
Q_NOREPLY void openapp();
signals:
void viewtoot(QString key);
void activateapp();
void viewtoot(QString key);
void activateapp();
private:
bool m_dbusRegistered;
bool m_dbusRegistered;
};
#endif // DBUS_H
......@@ -9,10 +9,11 @@
*/
#include "src/dbusAdaptor.h"
#include <QtCore/QMetaObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QMetaObject>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
......@@ -21,27 +22,27 @@
* Implementation of adaptor class KyclosAdaptor
*/
KyclosAdaptor::KyclosAdaptor(QObject *parent)
: QDBusAbstractAdaptor(parent)
KyclosAdaptor::KyclosAdaptor(QObject *parent) : QDBusAbstractAdaptor(parent)
{
// constructor
setAutoRelaySignals(true);
// constructor
setAutoRelaySignals(true);
}
KyclosAdaptor::~KyclosAdaptor()
{
// destructor
// destructor
}
void KyclosAdaptor::openapp()
void
KyclosAdaptor::openapp()
{
// handle method call social.pleroma.harbour.kyclos.openapp
QMetaObject::invokeMethod(parent(), "openapp");
// handle method call social.pleroma.harbour.kyclos.openapp
QMetaObject::invokeMethod(parent(), "openapp");
}
void KyclosAdaptor::showtoot(const QStringList &key)
void
KyclosAdaptor::showtoot(const QStringList &key)
{
// handle method call social.pleroma.harbour.kyclos.showtoot
QMetaObject::invokeMethod(parent(), "showtoot", Q_ARG(QStringList, key));
// handle method call social.pleroma.harbour.kyclos.showtoot
QMetaObject::invokeMethod(parent(), "showtoot", Q_ARG(QStringList, key));
}
......@@ -12,13 +12,14 @@
#ifndef DBUSADAPTOR_H
#define DBUSADAPTOR_H
#include "dbus.h"
#include <QtCore/QObject>
#include <QtDBus/QtDBus>
#include "dbus.h"
QT_BEGIN_NAMESPACE
class QByteArray;
template<class T> class QList;
template<class Key, class Value> class QMap;
template <class T> class QList;
template <class Key, class Value> class QMap;
class QString;
class QStringList;
class QVariant;
......@@ -27,27 +28,28 @@ QT_END_NAMESPACE
/*
* Adaptor class for interface social.pleroma.harbour.kyclos
*/
class KyclosAdaptor: public QDBusAbstractAdaptor
class KyclosAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "social.pleroma.harbour.kyclos")
Q_CLASSINFO("D-Bus Introspection", ""
" <interface name=\"social.pleroma.harbour.kyclos\">\n"
" <method name=\"showtoot\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Method.NoReply\"/>\n"
" <arg direction=\"in\" type=\"as\" name=\"key\"/>\n"
" </method>\n"
" <method name=\"openapp\"/>\n"
" </interface>\n"
"")
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "social.pleroma.harbour.kyclos")
Q_CLASSINFO("D-Bus Introspection",
""
" <interface name=\"social.pleroma.harbour.kyclos\">\n"
" <method name=\"showtoot\">\n"
" <annotation value=\"true\" name=\"org.freedesktop.DBus.Method.NoReply\"/>\n"
" <arg direction=\"in\" type=\"as\" name=\"key\"/>\n"
" </method>\n"
" <method name=\"openapp\"/>\n"
" </interface>\n"
"")
public:
KyclosAdaptor(QObject *parent);
virtual ~KyclosAdaptor();
KyclosAdaptor(QObject *parent);
virtual ~KyclosAdaptor();
public: // PROPERTIES
public: // PROPERTIES
public Q_SLOTS: // METHODS
void openapp();
Q_NOREPLY void showtoot(const QStringList &key);
void openapp();
Q_NOREPLY void showtoot(const QStringList &key);
Q_SIGNALS: // SIGNALS
};
......
......@@ -8,61 +8,66 @@
*/
#include "filedownloader.h"
#include <QDebug>
FileDownloader::FileDownloader(QQmlEngine *engine, QObject *parent) :
QObject(parent)
FileDownloader::FileDownloader(QQmlEngine *engine, QObject *parent) : QObject(parent)
{
m_engine = engine;
m_engine = engine;
}
void FileDownloader::downloadFile(QUrl url, QString filename)
void
FileDownloader::downloadFile(QUrl url, QString filename)
{
emit downloadStarted();
emit downloadStarted();
m_filename = filename;
qDebug() << "downloading" << url << "to" << filename;
m_filename = filename;
qDebug() << "downloading" << url << "to" << filename;
QNetworkAccessManager *nam = m_engine->networkAccessManager();
QNetworkAccessManager *nam = m_engine->networkAccessManager();
QNetworkRequest request(url);
QNetworkReply *r = nam->get(request);
connect(r, SIGNAL(finished()), this, SLOT(fileDownloaded()));
QNetworkRequest request(url);
QNetworkReply *r = nam->get(request);
connect(r, SIGNAL(finished()), this, SLOT(fileDownloaded()));
}
void FileDownloader::open(QString filename)
void
FileDownloader::open(QString filename)
{
QProcess proc;
QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" + filename;
QProcess proc;
QString path =
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" + filename;
proc.startDetached("/usr/bin/xdg-open" , QStringList() << path);
proc.startDetached("/usr/bin/xdg-open", QStringList() << path);
}
void FileDownloader::fileDownloaded()
void
FileDownloader::fileDownloaded()
{
QNetworkReply *pReply = qobject_cast<QNetworkReply *>(sender());
QNetworkReply *pReply = qobject_cast<QNetworkReply *>(sender());
m_DownloadedData = pReply->readAll();
int httpstatus = pReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug() << "HttpStatusCode" << httpstatus;
m_DownloadedData = pReply->readAll();
int httpstatus = pReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug() << "HttpStatusCode" << httpstatus;
pReply->deleteLater();
pReply->deleteLater();
if (httpstatus == 200)
{
QFile file(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" + m_filename);
if (!file.open(QIODevice::WriteOnly))
{
emit downloadFailed("Download failed, can't create file");
return;
}
file.write(m_DownloadedData);
file.close();
emit downloadSuccess();
open(m_filename);
}
else
{
emit downloadFailed(QString("Download failed, error %1").arg(httpstatus));
}
if(httpstatus == 200)
{
QFile file(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" +
m_filename);
if(!file.open(QIODevice::WriteOnly))
{
emit downloadFailed("Download failed, can't create file");
return;
}
file.write(m_DownloadedData);
file.close();
emit downloadSuccess();
open(m_filename);
}
else
{
emit downloadFailed(QString("Download failed, error %1").arg(httpstatus));
}
}
......@@ -10,36 +10,36 @@
#ifndef FILEDOWNLOADER_H
#define FILEDOWNLOADER_H
#include <QObject>
#include <QByteArray>
#include <QFile>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QFile>
#include <QStandardPaths>
#include <QQmlEngine>
#include <QNetworkRequest>
#include <QObject>
#include <QProcess>
#include <QQmlEngine>
#include <QStandardPaths>
class FileDownloader : public QObject
{
Q_OBJECT
Q_OBJECT
public:
explicit FileDownloader(QQmlEngine *engine, QObject *parent = 0);
Q_INVOKABLE void downloadFile(QUrl url, QString filename);
Q_INVOKABLE void open(QString filename);
explicit FileDownloader(QQmlEngine *engine, QObject *parent = 0);
Q_INVOKABLE void downloadFile(QUrl url, QString filename);
Q_INVOKABLE void open(QString filename);
signals:
void downloadStarted();
void downloadSuccess();
void downloadFailed(QString errorMsg);
void downloadStarted();
void downloadSuccess();
void downloadFailed(QString errorMsg);
private slots:
void fileDownloaded();
void fileDownloaded();
private:
QQmlEngine *m_engine;
QByteArray m_DownloadedData;
QString m_filename;
QQmlEngine *m_engine;
QByteArray m_DownloadedData;
QString m_filename;
};
#endif // FILEDOWNLOADER_H
......@@ -2,41 +2,41 @@
#include <QtQuick>
#endif
#include <sailfishapp.h>
#include <QQuickView>
#include <QtQml>
#include <QScopedPointer>
#include <QQmlEngine>
#include <QCoreApplication>
#include <QGuiApplication>
#include <QQmlContext>
#include <QCoreApplication>
#include <QQmlEngine>
#include <QQuickView>
#include <QScopedPointer>
#include <QtNetwork>
#include <QtQml>
#include <sailfishapp.h>
//#include <QtSystemInfo/QDeviceInfo>
#include "dbus.h"
#include "filedownloader.h"
#include "imageuploader.h"
#include "notifications.h"
#include "dbus.h"
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
QScopedPointer<QQuickView> view(SailfishApp::createView());
//QQmlContext *context = view.data()->rootContext();
QQmlEngine* engine = view->engine();
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
QScopedPointer<QQuickView> view(SailfishApp::createView());
//QQmlContext *context = view.data()->rootContext();
QQmlEngine *engine = view->engine();
FileDownloader *fd = new FileDownloader(engine);
view->rootContext()->setContextProperty("FileDownloader", fd);
qmlRegisterType<ImageUploader>("harbour.kyclos.Uploader", 1, 0, "ImageUploader");
FileDownloader *fd = new FileDownloader(engine);
view->rootContext()->setContextProperty("FileDownloader", fd);
qmlRegisterType<ImageUploader>("harbour.kyclos.Uploader", 1, 0, "ImageUploader");
Notifications *no = new Notifications();
view->rootContext()->setContextProperty("Notifications", no);
QObject::connect(engine, SIGNAL(quit()), app.data(), SLOT(quit()));
Notifications *no = new Notifications();
view->rootContext()->setContextProperty("Notifications", no);
QObject::connect(engine, SIGNAL(quit()), app.data(), SLOT(quit()));
Dbus *dbus = new Dbus();
view->rootContext()->setContextProperty("Dbus", dbus);
Dbus *dbus = new Dbus();
view->rootContext()->setContextProperty("Dbus", dbus);
view->setSource(SailfishApp::pathTo("qml/harbour-kyclos.qml"));
view->show();
return app->exec();
view->setSource(SailfishApp::pathTo("qml/harbour-kyclos.qml"));
view->show();
return app->exec();
}
#include "imageuploader.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QHttpMultiPart>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtNetwork/QHttpMultiPart>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
//static const QUrl IMGUR_UPLOAD_URL("https://httpbin.org/post");
//static const QUrl IMGUR_UPLOAD_URL();
ImageUploader::ImageUploader(QObject *parent) : QObject(parent), m_networkAccessManager(0), m_reply(0) {
m_networkAccessManager = new QNetworkAccessManager(this);
ImageUploader::ImageUploader(QObject *parent)
: QObject(parent), m_networkAccessManager(0), m_reply(0)
{
m_networkAccessManager = new QNetworkAccessManager(this);
}
ImageUploader::~ImageUploader() {
if (m_reply != 0) {
m_reply->disconnect();
m_reply->deleteLater();
m_reply = 0;
}
ImageUploader::~ImageUploader()
{
if(m_reply != 0)
{
m_reply->disconnect();
m_reply->deleteLater();
m_reply = 0;
}
}
void ImageUploader::setFile(const QString &fileName) {
m_fileName = fileName;
void
ImageUploader::setFile(const QString &fileName)
{
m_fileName = fileName;
}
void ImageUploader::setParameters(const QString &album, const QString &title, const QString &description) {
//if (!album.isEmpty()) {
postdata.append(QString("album=").toUtf8());
postdata.append(QUrl::toPercentEncoding(album));
//}
if (!title.isEmpty()) {
postdata.append(QString("&title=").toUtf8());
postdata.append(QUrl::toPercentEncoding(title));
}
if (!description.isEmpty()) {
postdata.append(QString("&description=").toUtf8());
postdata.append(QUrl::toPercentEncoding(description));
}
void
ImageUploader::setParameters(const QString &album, const QString &title, const QString &description)
{
//if (!album.isEmpty()) {
postdata.append(QString("album=").toUtf8());
postdata.append(QUrl::toPercentEncoding(album));
//}
if(!title.isEmpty())
{
postdata.append(QString("&title=").toUtf8());
postdata.append(QUrl::toPercentEncoding(title));
}
if(!description.isEmpty())
{
postdata.append(QString("&description=").toUtf8());
postdata.append(QUrl::toPercentEncoding(description));
}
}
void ImageUploader::setAuthorizationHeader(const QString &authorizationHeader) {
m_authorizationHeader = "Bearer "+authorizationHeader.toUtf8();
void
ImageUploader::setAuthorizationHeader(const QString &authorizationHeader)
{
m_authorizationHeader = "Bearer " + authorizationHeader.toUtf8();
}
void ImageUploader::setUploadUrl(const QString &UrlString) {
qDebug() << "Set Upload URL " + UrlString;
m_uploadUrl = UrlString.toUtf8();
void
ImageUploader::setUploadUrl(const QString &UrlString)
{
qDebug() << "Set Upload URL " + UrlString;
m_uploadUrl = UrlString.toUtf8();
}
void ImageUploader::upload() {
void
ImageUploader::upload()
{
if (!m_networkAccessManager) {
qWarning("ImageUploader::send(): networkAccessManager not set");
return;
}
if(!m_networkAccessManager)
{
qWarning("ImageUploader::send(): networkAccessManager not set");
return;
}
if (m_reply != 0) {
m_reply->disconnect();
m_reply->deleteLater();
m_reply = 0;
}
if(m_reply != 0)
{
m_reply->disconnect();
m_reply->deleteLater();
m_reply = 0;
}
/*QFileInfo fileInfo(QUrl(m_fileName).toLocalFile());
/*QFileInfo fileInfo(QUrl(m_fileName).toLocalFile());
qDebug("fileName: %s", qPrintable(m_fileName));
if (!fileInfo.exists()) {
emit failure(-1, tr("The file %1 does not exists").arg(m_fileName));
......@@ -72,18 +89,18 @@ void ImageUploader::upload() {
return;
}*/
QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart imagePart;
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart imagePart;
//QFile file(fileInfo.absoluteFilePath());
QFileInfo fileInfo(QUrl(m_fileName).toLocalFile());
QFile* file = new QFile(QUrl(m_fileName).toLocalFile());
if (!file->open(QIODevice::ReadWrite)) {
emit failure(-1, tr("The file %1 does not exists").arg(m_fileName));
return;
}
/*bool opened = file.open(QIODevice::ReadOnly);
//QFile file(fileInfo.absoluteFilePath());
QFileInfo fileInfo(QUrl(m_fileName).toLocalFile());
QFile *file = new QFile(QUrl(m_fileName).toLocalFile());
if(!file->open(QIODevice::ReadWrite))
{
emit failure(-1, tr("The file %1 does not exists").arg(m_fileName));
return;
}
/*bool opened = file.open(QIODevice::ReadOnly);
if (!opened) {
qDebug("can't read file: %s", qPrintable(m_fileName));
......@@ -92,60 +109,67 @@ void ImageUploader::upload() {
return;
}*/
//QByteArray fileData = file.readAll().toBase64();
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name=\"file\"; filename=\"%1\"").arg(fileInfo.fileName()).toLatin1()));
imagePart.setBodyDevice(file);
file->setParent(multiPart);
multiPart->append(imagePart);
//imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(fileInfo));
//POST data
QNetworkRequest request(m_uploadUrl);