Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sociald] Initial work of multiaccount management. Contributes to JB#…
…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
1 parent
d1ea6d6
commit 75e838d
Showing
14 changed files
with
858 additions
and
435 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,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 {} | ||
} | ||
} |
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,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"]) | ||
} | ||
} |
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,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 |
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
Oops, something went wrong.