Skip to content

Commit

Permalink
[sociald] Initial work of multiaccount management. Contributes to JB#…
Browse files Browse the repository at this point in the history
…8122, JB#7966, JB#7965

This commit includes the first part of a rework for the database used
by sociald. It splits the account identifier from syncedData and
include a 1 - * relation, so that many accounts can be related to
one account.

It also introduces UI changes to be able to switch accounts and
interact with the post using one of these accounts.

Cleanups, and some other methods are not yet adapted to the change
as they might need some optimization.
  • Loading branch information
SfietKonstantin committed Aug 19, 2013
1 parent d1ea6d6 commit 75e838d
Show file tree
Hide file tree
Showing 14 changed files with 858 additions and 435 deletions.
53 changes: 53 additions & 0 deletions src/eventfeed/SocialAccountPage.qml
@@ -0,0 +1,53 @@
import QtQuick 2.0
import Sailfish.Silica 1.0


Page {
id: container
signal indexSelected(int index)
property int currentIndex
property variant accounts
property string headerText

ListModel {
id: model
}

Component.onCompleted: {
for (var i = 0; i < container.accounts.length; i++) {
model.append({"name": container.accounts[i]["name"]})
}
}

SilicaListView {
anchors.fill: parent
model: model

header: PageHeader {
title: container.headerText
}

delegate: BackgroundItem {
id: listItem
onClicked: {
container.currentIndex = model.index
container.indexSelected(container.currentIndex)
}
Label {
anchors {
left: parent.left
leftMargin: Theme.paddingLarge
right: parent.left
rightMargin: Theme.paddingLarge
verticalCenter: parent.verticalCenter
}
text: model.name
color: (listItem.highlighted || model.index == container.currentIndex) ? Theme.highlightColor
: Theme.primaryColor
}
}


VerticalScrollDecorator {}
}
}
80 changes: 80 additions & 0 deletions src/eventfeed/SocialAccountPullDownMenu.qml
@@ -0,0 +1,80 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.Accounts 1.0

PullDownMenu {
id: container
property int currentAccount
property int currentAccountIndex: -1
property var metaData
property string selectAccountString
property string changeToAccountString
property string accountString
property var pageContainer
onMetaDataChanged: refreshAccountList()

function refreshAccountList() {
internal.accounts = []
internal.accountCount = container.metaData["accountIdCount"]
for (var i = 0; i < internal.accountCount; i++) {
var accountData = new Object
accountData["id"] = container.metaData["accountId" + i]
var account = accountManager.account(accountData["id"])
accountData["name"] = account.displayName
internal.accounts.push(accountData)
}
container.currentAccount = internal.accounts[0]["id"]
container.currentAccountIndex = 0

if (internal.accountCount == 2) {
internal.otherIndex = 1
}
}
resources: [
QtObject {
id: internal
function setIndex(index) {
container.currentAccountIndex = index
pageContainer.pop()
}
property int accountCount
property var accounts
property int otherIndex
},
AccountManager {
id: accountManager
}
]

MenuItem {
text: {
if (internal.accountCount > 2) {
container.selectAccountString
} else if (internal.accountCount == 2) {
container.changeToAccountString.arg(internal.accounts[internal.otherIndex]["name"])
} else {
""
}
}
visible: internal.accountCount > 1

onClicked: {
if (internal.accountCount > 2) {
var page = container.pageContainer.push(Qt.resolvedUrl("SocialAccountPage.qml"),
{"accounts": internal.accounts,
"currentIndex": container.currentAccountIndex,
"headerText": container.selectAccountString})
page.indexSelected.connect(internal.setIndex)
// TODO
} else {
container.currentAccountIndex = internal.otherIndex
container.currentAccount = internal.accounts[container.currentAccountIndex]["id"]
internal.otherIndex = (internal.otherIndex == 0 ? 1 : 0)
}
}
}

MenuLabel {
text: container.accountString.arg(internal.accounts[container.currentAccountIndex]["name"])
}
}
113 changes: 113 additions & 0 deletions src/eventfeedhelper_p.h
@@ -0,0 +1,113 @@
/*
* Copyright (C) 2013 Lucien XU <sfietkonstantin@free.fr>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/

#ifndef EVENTFEEDHELPER_P_H
#define EVENTFEEDHELPER_P_H

#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QDateTime>

#include "syncservice.h"

// meegotouchevents/meventfeed
#include <meventfeed.h>

class EventFeedHelper
{
public:
inline static void manageEvent(const QString &icon, const QString title, const QString &body,
const QStringList &imageList, const QDateTime &createdTime,
const QString &footer, bool isVideo, const QString &url,
const QString &serviceName, const QString &sourceDisplayName,
const QVariantMap &metadata, int accountId,
const QList<int> &accountIds,
const QMap<int, QString> &profileImages,
const QString &localIdentifier, const QString &group,
SyncService::DataType dataType, const QString &postId,
QList<SyncedDatum> &syncedData)
{
QString trueLocalIdentifier = localIdentifier;

QList<int> newAccountIds = accountIds;
std::sort(newAccountIds.begin(), newAccountIds.end());
QVariantMap newMetadata = metadata;
newMetadata.insert("accountIdCount", newAccountIds.count());
for (int i = 0; i < newAccountIds.count(); i++) {
newMetadata.insert(QString("accountId%1").arg(i), newAccountIds.at(i));
newMetadata.insert(QString("profilePicture%1").arg(i),
profileImages.value(newAccountIds.at(i)));
}

if (localIdentifier.isEmpty()) {
// Publish the post to the events feed.
qlonglong eventId = MEventFeed::instance()->addItem(icon, title, body, imageList,
// Conversion from UTC to local time
createdTime.toLocalTime(), footer,
isVideo, url, serviceName,
sourceDisplayName, newMetadata);
if (eventId == 0) {
// failed.
TRACE(SOCIALD_ERROR,
QString(QLatin1String("error: failed to publish post/feed event: %1"))
.arg(body));
return;
} else {
trueLocalIdentifier = QString::number(eventId);
}
} else {
// Update the post to the event feed
MEventFeed::instance()->updateItem(localIdentifier.toLongLong(),
icon, title, body, imageList,
// Conversion from UTC to local time
createdTime.toLocalTime(), footer,
isVideo, url, serviceName,
sourceDisplayName, newMetadata);
}

if (!trueLocalIdentifier.isEmpty()) {
// and store the fact that we have synced it to the events feed.
SyncedDatum datum;
datum.accountIdentifier = QString::number(accountId);
datum.localIdentifier = QString(group + trueLocalIdentifier);
datum.serviceName = serviceName;
datum.dataType = SyncService::dataType(dataType);
datum.createdTimestamp = createdTime;
datum.syncedTimestamp = QDateTime::currentDateTime();
datum.datumIdentifier = postId;

syncedData.append(datum);
}
}
};


#endif // EVENTFEEDHELPER_P_H
31 changes: 28 additions & 3 deletions src/facebook/eventfeed/facebook.qml
Expand Up @@ -28,12 +28,19 @@ Page {
mediaName = container.model.metaData["postAttachmentName"]
mediaCaption = container.model.metaData["postAttachmentCaption"]
mediaDescription = container.model.metaData["postAttachmentDescription"]
account.identifier = container.model.metaData["accountId0"]
console.debug("\n")
for(var k in container.model.metaData) {
console.debug(k + ": " + container.model.metaData[k] + "\n")
}
console.debug("\n")

}

Account {
identifier: container.model != null ? container.model.metaData["accountId"] : -1
onStatusChanged: {
if (status == Account.Initialized) {
id: account
function performSign() {
if (status == Account.Initialized && identifier != -1) {
// Sign in, and get access token.
var params = signInParameters("facebook-sync")
console.debug(container.model.metaData["clientId"])
Expand All @@ -43,6 +50,10 @@ Page {
}
}

identifier: 0
onStatusChanged: performSign()
onIdentifierChanged: performSign()

onSignInResponse: {
var accessTok = data["AccessToken"]
if (accessTok != "") {
Expand Down Expand Up @@ -354,5 +365,19 @@ Page {
}
}
}

VerticalScrollDecorator {}

SocialAccountPullDownMenu {
pageContainer: container.pageContainer
metaData: container.model.metaData
onCurrentAccountChanged: account.identifier = currentAccount
//% "Select account"
selectAccountString: qsTrId("lipstick-jolla-home-la-select-account")
//% "Change to %1"
changeToAccountString: qsTrId("lipstick-jolla-home-la-change-to-account")
//% "Account: %1"
accountString: qsTrId("lipstick-jolla-home-la-account-name")
}
}
}

0 comments on commit 75e838d

Please sign in to comment.