Verified 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
......
.pragma library
.import QtQuick.LocalStorage 2.0 as LS
var db = LS.LocalStorage.openDatabaseSync("kyclos", "", "harbour-kyclos", 100000);
var conf = {};
var mediator = (function(){
var subscribe = function(channel, fn){
if(!mediator.channels[channel]) mediator.channels[channel] = [];
mediator.channels[channel].push({ context : this, callback : fn });
return this;
};
var publish = function(channel){
if(!mediator.channels[channel]) return false;
var args = Array.prototype.slice.call(arguments, 1);
for(var i = 0, l = mediator.channels[channel].length; i < l; i++){
var subscription = mediator.channels[channel][i];
subscription.callback.apply(subscription.context.args);
};
return this;
};
return {
channels : {},
publish : publish,
subscribe : subscribe,
installTo : function(obj){
obj.subscribe = subscribe;
obj.publish = publish;
}
};
}());
var init = function(){
console.log("db.version: "+db.version);
if(db.version === '') {
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS settings ('
+ ' key TEXT UNIQUE, '
+ ' value TEXT '
+');');
//tx.executeSql('INSERT INTO settings (key, value) VALUES (?, ?)', ["conf", "{}"]);
});
db.changeVersion('', '0.1', function(tx) {
});
.pragma library.import QtQuick.LocalStorage 2.0 as LS
var db = LS.LocalStorage.openDatabaseSync("kyclos", "", "harbour-kyclos", 100000);
var conf = {};
var mediator = (function() {
var subscribe = function(channel, fn) {
if(!mediator.channels[channel]) mediator.channels[channel] = [];
mediator.channels[channel].push({context : this, callback : fn});
return this;
};
var publish = function(channel) {
if(!mediator.channels[channel]) return false;
var args = Array.prototype.slice.call(arguments, 1);
for(var i = 0, l = mediator.channels[channel].length; i < l; i++)
{
var subscription = mediator.channels[channel][i];
subscription.callback.apply(subscription.context.args);
};
return this;
};
return {
channels : {},
publish : publish,
subscribe : subscribe,
installTo : function(obj) {
obj.subscribe = subscribe;
obj.publish = publish;
}
};
}());
var init = function() {
console.log("db.version: " + db.version);
if(db.version === '')
{
db.transaction(function(tx) {
var rs = tx.executeSql('SELECT * FROM settings;');
console.log("READING CONF FROM DB")
for (var i = 0; i < rs.rows.length; i++) {
//var json = JSON.parse(rs.rows.item(i).value);
console.log(rs.rows.item(i).key+" \t > \t "+rs.rows.item(i).value)
conf[rs.rows.item(i).key] = JSON.parse(rs.rows.item(i).value)
}
console.log("END OF READING")
console.log(JSON.stringify(conf));
mediator.publish('confLoaded', { loaded: true});
tx.executeSql('CREATE TABLE IF NOT EXISTS settings (' +
' key TEXT UNIQUE, ' +
' value TEXT ' +
');');
//tx.executeSql('INSERT INTO settings (key, value) VALUES (?, ?)', ["conf", "{}"]);
});
};
db.changeVersion('', '0.1', function(tx) {
function saveData() {
console.log("SAVING CONF TO DB")
db.transaction(function(tx) {
for (var key in conf) {
if (conf.hasOwnProperty(key)){
console.log(key + "\t>\t"+conf[key]);
if (typeof conf[key] === "object" && conf[key] === null) {
tx.executeSql('DELETE FROM settings WHERE key=? ', [key])
} else {
tx.executeSql('INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?) ', [key, JSON.stringify(conf[key])])
}
}
}
console.log("ENF OF SAVING")
});
}
var tootParser = function(data){
console.log(data)
var ret = {};
ret.id = data.id
ret.content = data.content
ret.created_at = data.created_at
ret.in_reply_to_account_id = data.in_reply_to_account_id
ret.in_reply_to_id = data.in_reply_to_id
}
db.transaction(function(tx) {
var rs = tx.executeSql('SELECT * FROM settings;');
console.log("READING CONF FROM DB")
for(var i = 0; i < rs.rows.length; i++)
{
//var json = JSON.parse(rs.rows.item(i).value);
console.log(rs.rows.item(i).key + " \t > \t " + rs.rows.item(i).value)
conf[rs.rows.item(i).key] = JSON.parse(rs.rows.item(i).value)
}
console.log("END OF READING")
console.log(JSON.stringify(conf));
mediator.publish('confLoaded', {loaded : true});
});
};
ret.user_id = data.account.id
ret.user_locked = data.account.locked
ret.username = data.account.username
ret.display_name = data.account.display_name
ret.avatar_static = data.account.avatar_static
function saveData()
{
console.log("SAVING CONF TO DB")
db.transaction(function(tx) {
for(var key in conf)
{
if(conf.hasOwnProperty(key))
{
console.log(key + "\t>\t" + conf[key]);
if(typeof conf[key] === "object" && conf[key] === null)
{
tx.executeSql('DELETE FROM settings WHERE key=? ', [ key ])
}
else
{
tx.executeSql('INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?) ',
[ key, JSON.stringify(conf[key]) ])
}
}
}
console.log("ENF OF SAVING")
});
}
var tootParser = function(data) {
console.log(data)
var ret = {};
ret.id = data.id
ret.content = data.content
ret.created_at = data.created_at
ret.in_reply_to_account_id = data.in_reply_to_account_id
ret.in_reply_to_id = data.in_reply_to_id
ret.favourited = data.favourited ? true : false
ret.favourites_count = data.favourites_count ? data.favourites_count : 0
ret.user_id = data.account.id
ret.user_locked = data.account.locked
ret.username = data.account.username
ret.display_name = data.account.display_name
ret.avatar_static = data.account.avatar_static
ret.reblog = data.reblog ? true : false
ret.reblogged = data.reblogged ? true : false
ret.reblogs_count = data.reblogs_count ? data.reblogs_count : false
ret.favourited = data.favourited ? true : false
ret.favourites_count = data.favourites_count ? data.favourites_count : 0
ret.muted = data.muted ? true : false
ret.sensitive = data.sensitive ? true : false
ret.visibility = data.visibility ? data.visibility : false
ret.reblog = data.reblog ? true : false
ret.reblogged = data.reblogged ? true : false
ret.reblogs_count = data.reblogs_count ? data.reblogs_count : false
ret.muted = data.muted ? true : false
ret.sensitive = data.sensitive ? true : false
ret.visibility = data.visibility ? data.visibility : false
console.log(ret)
}
var test = 1;
console.log(ret)
} var test = 1;
Qt.include("Mastodon.js")
var modelTLhome = Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
var modelTLpublic = Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
var modelTLlocal = Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
var modelTLnotifications = Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
var modelTLsearch = Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
var modelTLhome =
Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
var modelTLpublic =
Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
var modelTLlocal =
Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
var modelTLnotifications =
Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
var modelTLsearch =
Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
var notificationsList = []
var notificationGenerator = function(item){
var notification;
switch (item.urgency){
case "normal":
notification = Qt.createQmlObject('import org.nemomobile.notifications 1.0; Notification { category: "x-harbour.kyclos.activity"; appName: "Kyclos"; itemCount: 1; remoteActions: [ { "name": "default", "displayName": "Do something", "icon": "icon-s-certificates", "service": "social.pleroma.harbour.kyclos", "path": "/", "iface": "social.pleroma.harbour.kyclos", "method": "openapp", "arguments": [ "'+item.service+'", "'+item.key+'" ] }]; urgency: Notification.Normal; }', Qt.application, 'InternalQmlObject');
break;
case "critical":
notification = Qt.createQmlObject('import org.nemomobile.notifications 1.0; Notification { appName: "Kyclos"; itemCount: 1; remoteActions: [ { "name": "default", "displayName": "Do something", "icon": "icon-s-certificates", "service": "ba.dysko.harbour.kyclos", "path": "/", "iface": "social.pleroma.harbour.kyclos", "method": "openapp", "arguments": [ "'+item.service+'", "'+item.key+'" ] }]; urgency: Notification.Critical; }', Qt.application, 'InternalQmlObject');
break;
default:
notification = Qt.createQmlObject('import org.nemomobile.notifications 1.0; Notification { category: "x-harbour.kyclos.activity"; appName: "Kyclos"; itemCount: 1; remoteActions: [ { "name": "default", "displayName": "Do something", "icon": "icon-s-certificates", "service": "social.pleroma.harbour.kyclos", "path": "/", "iface": "social.pleroma.harbour.kyclos", "method": "openapp", "arguments": [ "'+item.service+'", "'+item.key+'" ] }]; urgency: Notification.Low; }', Qt.application, 'InternalQmlObject');
var notificationGenerator =
function(item) {
var notification;
switch(item.urgency)
{
case "normal":
notification = Qt.createQmlObject(
'import org.nemomobile.notifications 1.0; Notification { category: "x-harbour.kyclos.activity"; appName: "Kyclos"; itemCount: 1; remoteActions: [ { "name": "default", "displayName": "Do something", "icon": "icon-s-certificates", "service": "social.pleroma.harbour.kyclos", "path": "/", "iface": "social.pleroma.harbour.kyclos", "method": "openapp", "arguments": [ "' +
item.service + '", "' + item.key + '" ] }]; urgency: Notification.Normal; }',
Qt.application,
'InternalQmlObject');
break;
case "critical":
notification = Qt.createQmlObject(
'import org.nemomobile.notifications 1.0; Notification { appName: "Kyclos"; itemCount: 1; remoteActions: [ { "name": "default", "displayName": "Do something", "icon": "icon-s-certificates", "service": "ba.dysko.harbour.kyclos", "path": "/", "iface": "social.pleroma.harbour.kyclos", "method": "openapp", "arguments": [ "' +
item.service + '", "' + item.key + '" ] }]; urgency: Notification.Critical; }',
Qt.application,
'InternalQmlObject');
break;
default:
notification = Qt.createQmlObject(
'import org.nemomobile.notifications 1.0; Notification { category: "x-harbour.kyclos.activity"; appName: "Kyclos"; itemCount: 1; remoteActions: [ { "name": "default", "displayName": "Do something", "icon": "icon-s-certificates", "service": "social.pleroma.harbour.kyclos", "path": "/", "iface": "social.pleroma.harbour.kyclos", "method": "openapp", "arguments": [ "' +
item.service + '", "' + item.key + '" ] }]; urgency: Notification.Low; }',
Qt.application,
'InternalQmlObject');
}
console.log(JSON.stringify(notification.remoteActions[0].arguments))
//Notifications.notify("Kyclos", "serverinfo.serverTitle", " new activity", false, "2015-10-15 00:00:00", "aaa")
notification.timestamp = item.timestamp
notification.summary = item.summary
notification.body = item.body
if(item.previewBody)
notification.previewBody = item.previewBody;
else notification.previewBody = item.body;
if(item.previewSummary)
notification.previewSummary = item.previewSummary;
else
notification.previewSummary = item.summary
if(notification.replacesId)
{
notification.replacesId = 0
}
notification.publish()
}
console.log(JSON.stringify(notification.remoteActions[0].arguments))
//Notifications.notify("Kyclos", "serverinfo.serverTitle", " new activity", false, "2015-10-15 00:00:00", "aaa")
notification.timestamp = item.timestamp
notification.summary = item.summary
notification.body = item.body
if(item.previewBody)
notification.previewBody = item.previewBody;
else
notification.previewBody = item.body;
if(item.previewSummary)
notification.previewSummary = item.previewSummary;
else
notification.previewSummary = item.summary
if(notification.replacesId){ notification.replacesId = 0 }
notification.publish()
var notifier =
function(item) {
item.content = item.content.replace(/(<([^>]+)>)/ig, "").replaceAll("&quot;", "\"")
var msg;
switch(item.type)
{
case "favourite":
msg = {
urgency : "normal",
timestamp : item.created_at,
summary : (item.reblog_account_display_name !== "" ? item.reblog_account_display_name
: '@' + item.reblog_account_username) +
' ' + qsTr("favourited"),
body : item.content,
service : 'toot',
key : item.id
} break;
case "follow":
msg = {
urgency : "critical",
timestamp : item.created_at,
summary : (item.account_display_name !== "" ? item.account_display_name
: '@' + item.account_username),
body : qsTr("followed you"),
service : 'profile',
key : item.account_username
} break;
case "reblog":
msg = {
urgency : "low",
timestamp : item.created_at,
summary : (item.reblog_account_display_name !== "" ? item.reblog_account_display_name
: '@' + item.reblog_account_username) +
' ' + qsTr("boosted"),
body : item.content,
service : 'toot',
key : item.id
} break;
case "mention":
msg = {
urgency : "critical",
timestamp : item.created_at,
summary : (item.account_display_name !== "" ? item.account_display_name
: '@' + item.account_username) +
' ' + qsTr("said"),
body : item.content,
previewBody : (item.account_display_name !== "" ? item.account_display_name
: '@' + item.account_username) +
' ' + qsTr("said") + ': ' + item.content,
service : 'toot',
key : item.id
} break;
default:
//console.log(JSON.stringify(messageObject.data))
return;
}
notificationGenerator(msg)
}
var notifier = function(item){
item.content = item.content.replace(/(<([^>]+)>)/ig,"").replaceAll("&quot;", "\"")
var msg;
switch (item.type){
case "favourite":
msg = {
urgency: "normal",
timestamp: item.created_at,
summary: (item.reblog_account_display_name !== "" ? item.reblog_account_display_name : '@'+item.reblog_account_username) + ' ' + qsTr("favourited"),
body: item.content,
service: 'toot',
key: item.id
}
break;
case "follow":
msg = {
urgency: "critical",
timestamp: item.created_at,
summary: (item.account_display_name !== "" ? item.account_display_name : '@'+item.account_username),
body: qsTr("followed you"),
service: 'profile',
key: item.account_username
}
break;
case "reblog":
msg = {
urgency: "low",
timestamp: item.created_at,
summary: (item.reblog_account_display_name !== "" ? item.reblog_account_display_name : '@'+item.reblog_account_username) + ' ' + qsTr("boosted"),
body: item.content,
service: 'toot',
key: item.id
}
break;
case "mention":
msg = {
urgency: "critical",
timestamp: item.created_at,
summary: (item.account_display_name !== "" ? item.account_display_name : '@'+item.account_username) + ' ' + qsTr("said"),
body: item.content,
previewBody: (item.account_display_name !== "" ? item.account_display_name : '@'+item.account_username) + ' ' + qsTr("said") + ': ' + item.content,
service: 'toot',
key: item.id
}
break;
default:
//console.log(JSON.stringify(messageObject.data))
return;
}
notificationGenerator(msg)
}
var api;
function func() {
console.log(api)
}
function func() { console.log(api) }
......@@ -4,105 +4,121 @@
// but please don't hurt it (and keep this header)
var MastodonAPI = function(config) {
var apiBase = config.instance + "/api/v1/";
return {
setConfig: function (key, value) {
// modify initial config afterwards
config[key] = value;
},
getConfig: function(key) {
//get config key
return config[key];
},
get: function (endpoint) {
// for GET API calls
// can be called with two or three parameters
// endpoint, callback
// or
// endpoint, queryData, callback
// where querydata is an object {["paramname1", "paramvalue1], ["paramname2","paramvalue2"]}
// variables
var queryData, callback,
queryStringAppend = "?";
// check with which arguments we're supplied
if (typeof arguments[1] === "function") {
queryData = {};
callback = arguments[1];
} else {
queryData = arguments[1];
callback = arguments[2];
}
// build queryData Object into a URL Query String
for (var i in queryData) {
if (queryData.hasOwnProperty(i)) {
if (typeof queryData[i] === "string") {
queryStringAppend += queryData[i] + "&";
} else if (typeof queryData[i] === "object") {
queryStringAppend += queryData[i].name + "="+ queryData[i].data + "&";
}
}
}
// ajax function
var http = new XMLHttpRequest()
var url = apiBase + endpoint;
console.log(queryStringAppend)
http.open("GET", apiBase + endpoint + queryStringAppend, true);
// Send the proper header information along with the request
http.setRequestHeader("Authorization", "Bearer " + config.api_user_token);
http.setRequestHeader("Content-Type", "application/json");
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() { // Call a function when the state changes.
if (http.readyState == 4) {
if (http.status == 200) {
console.log("Successful GET API request to " +apiBase+endpoint);
callback(JSON.parse(http.response),http.status)
} else {
console.log("error: " + http.status)
}
}
}
http.send();
},
post: function (endpoint) {
// for POST API calls
var postData, callback;
// check with which arguments we're supplied
if (typeof arguments[1] === "function") {
postData = {};
callback = arguments[1];
} else {
postData = arguments[1];
callback = arguments[2];
}
var http = new XMLHttpRequest()
var url = apiBase + endpoint;
var params = JSON.stringify(postData);
http.open("POST", url, true);
// Send the proper header information along with the request
http.setRequestHeader("Authorization", "Bearer " + config.api_user_token);
http.setRequestHeader("Content-Type", "application/json");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() { // Call a function when the state changes.
if (http.readyState == 4) {
if (http.status == 200) {
console.log("Successful POST API request to " +apiBase+endpoint);
callback(JSON.parse(http.response),http.status)
} else {
console.log("error: " + http.status)
}
}
}
http.send(params);
/*$.ajax({
var apiBase = config.instance + "/api/v1/";
return {
setConfig : function(key, value) {
// modify initial config afterwards
config[key] = value;
},
getConfig : function(key) {
//get config key
return config[key];
},
get : function(endpoint) {
// for GET API calls
// can be called with two or three parameters
// endpoint, callback
// or
// endpoint, queryData, callback
// where querydata is an object {["paramname1", "paramvalue1], ["paramname2","paramvalue2"]}
// variables
var queryData, callback, queryStringAppend = "?";
// check with which arguments we're supplied
if(typeof arguments[1] === "function")
{
queryData = {};
callback = arguments[1];
}
else
{
queryData = arguments[1];
callback = arguments[2];
}
// build queryData Object into a URL Query String
for(var i in queryData)
{
if(queryData.hasOwnProperty(i))
{