diff --git a/microblogs/pumpio/pumpiomicroblog.cpp b/microblogs/pumpio/pumpiomicroblog.cpp index 82f7e766..41b65b26 100644 --- a/microblogs/pumpio/pumpiomicroblog.cpp +++ b/microblogs/pumpio/pumpiomicroblog.cpp @@ -1,801 +1,801 @@ /* This file is part of Choqok, the KDE micro-blogging client Copyright (C) 2013 Andrea Scarpino This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/ */ #include "pumpiomicroblog.h" #include #include #include #include #include #include #include "accountmanager.h" #include "application.h" #include "choqokbehaviorsettings.h" #include "notifymanager.h" #include "pumpioaccount.h" #include "pumpioeditaccountwidget.h" #include "pumpiopost.h" #include "pumpiopostwidget.h" class PumpIOMicroBlog::Private { public: Private():countOfTimelinesToSave(0) {} int countOfTimelinesToSave; }; K_PLUGIN_FACTORY( MyPluginFactory, registerPlugin < PumpIOMicroBlog > (); ) K_EXPORT_PLUGIN( MyPluginFactory( "choqok_pumpio" ) ) const QString PumpIOMicroBlog::inboxActivity("/api/user/%1/inbox"); const QString PumpIOMicroBlog::outboxActivity("/api/user/%1/feed"); PumpIOMicroBlog::PumpIOMicroBlog(QObject* parent, const QVariantList& args): MicroBlog(MyPluginFactory::componentData(), parent), d(new Private) { Q_UNUSED(args) setServiceName("Pump.io"); setServiceHomepageUrl("http://pump.io"); QStringList timelineNames; timelineNames << "Activity" << "Favorites" << "Inbox" << "Outbox"; setTimelineNames(timelineNames); setTimelinesInfo(); } PumpIOMicroBlog::~PumpIOMicroBlog() { } void PumpIOMicroBlog::abortAllJobs(Choqok::Account* theAccount) { Q_FOREACH (KJob *job, m_accountJobs.keys(theAccount)) { job->kill(KJob::EmitResult); } } void PumpIOMicroBlog::abortCreatePost(Choqok::Account* theAccount, Choqok::Post* post) { if (m_createPostJobs.isEmpty()) { return; } if (post) { m_createPostJobs.key(post)->kill(KJob::EmitResult); return; } Q_FOREACH (KJob *job, m_createPostJobs.keys()){ if( m_accountJobs[job] == theAccount) { job->kill(KJob::EmitResult); } } } void PumpIOMicroBlog::aboutToUnload() { Q_FOREACH (Choqok::Account* acc, Choqok::AccountManager::self()->accounts()) { if (acc->microblog() == this){ d->countOfTimelinesToSave += acc->timelineNames().count(); } } emit saveTimelines(); } ChoqokEditAccountWidget* PumpIOMicroBlog::createEditAccountWidget(Choqok::Account* account, QWidget* parent) { PumpIOAccount *acc = qobject_cast(account); if (acc || !account) { return new PumpIOEditAccountWidget(this, acc, parent); } else { kDebug() << "Account passed here was not a valid PumpIOAccount!"; return 0; } } Choqok::Account* PumpIOMicroBlog::createNewAccount(const QString& alias) { PumpIOAccount *acc = qobject_cast( Choqok::AccountManager::self()->findAccount(alias) ); if (!acc) { return new PumpIOAccount(this, alias); } else { kDebug() << "Cannot create a new PumpIOAccount!"; return 0; } } void PumpIOMicroBlog::createPost(Choqok::Account* theAccount, Choqok::Post* post) { PumpIOAccount *acc = qobject_cast(theAccount); if (acc) { QVariantMap object; object.insert("objectType", "note"); object.insert("content", QUrl::toPercentEncoding(post->content)); QVariantList to; QVariantMap thePublic; thePublic.insert("objectType", "collection"); thePublic.insert("id", "http://activityschema.org/collection/public"); to.prepend(thePublic); QVariantMap item; item.insert("verb", "post"); item.insert("object", object); item.insert("to", to); QJson::Serializer serializer; const QByteArray data = serializer.serialize(item); KUrl url(acc->host()); url.addPath(outboxActivity.arg(acc->username())); KIO::StoredTransferJob *job = KIO::storedHttpPost(data, url, KIO::HideProgressInfo); job->addMetaData("content-type", "Content-Type: application/json"); job->addMetaData("customHTTPHeader", authorizationMetaData(acc, url, QOAuth::POST)); if (!job) { kDebug() << "Cannot create an http POST request!"; return; } m_accountJobs[job] = acc; m_createPostJobs[job] = post; connect(job, SIGNAL(result(KJob*)), this, SLOT(slotCreatePost(KJob*))); job->start(); } else { kDebug() << "theAccount is not a PumpIOAccount!"; } } Choqok::UI::PostWidget* PumpIOMicroBlog::createPostWidget(Choqok::Account* account, Choqok::Post* post, QWidget* parent) { return new PumpIOPostWidget(account, post, parent); } void PumpIOMicroBlog::fetchPost(Choqok::Account* theAccount, Choqok::Post* post) { //TODO Choqok::MicroBlog::fetchPost(theAccount, post); } void PumpIOMicroBlog::removePost(Choqok::Account* theAccount, Choqok::Post* post) { PumpIOAccount *acc = qobject_cast(theAccount); if (acc) { QVariantMap object; object.insert("id", post->postId.toString()); object.insert("objectType", post->type); QVariantMap item; item.insert("verb", "delete"); item.insert("object", object); QJson::Serializer serializer; const QByteArray data = serializer.serialize(item); KUrl url(acc->host()); url.addPath(outboxActivity.arg(acc->username())); KIO::StoredTransferJob *job = KIO::storedHttpPost(data, url, KIO::HideProgressInfo); job->addMetaData("content-type", "Content-Type: application/json"); job->addMetaData("customHTTPHeader", authorizationMetaData(acc, url, QOAuth::POST)); if (!job) { kDebug() << "Cannot create an http POST request!"; return; } m_accountJobs[job] = acc; m_removePostJobs[job] = post; connect(job, SIGNAL(result(KJob*)), this, SLOT(slotRemovePost(KJob*))); job->start(); } else { kDebug() << "theAccount is not a PumpIOAccount!"; } } QList< Choqok::Post* > PumpIOMicroBlog::loadTimeline(Choqok::Account* account, const QString& timelineName) { QList< Choqok::Post* > list; const QString fileName = Choqok::AccountManager::generatePostBackupFileName(account->alias(), timelineName); const KConfig postsBackup( "choqok/" + fileName, KConfig::NoGlobals, "data" ); const QStringList tmpList = postsBackup.groupList(); // don't load old archives if (tmpList.isEmpty() || !(QDateTime::fromString(tmpList.first()).isValid())) { return list; } QList groupList; Q_FOREACH (const QString& str, tmpList) { groupList.append(QDateTime::fromString(str)); } qSort(groupList); PumpIOPost *st; Q_FOREACH (const QDateTime& datetime, groupList) { st = new PumpIOPost; KConfigGroup grp(&postsBackup, datetime.toString()); st->creationDateTime = grp.readEntry("creationDateTime", QDateTime::currentDateTime()); st->postId = grp.readEntry("postId", QString()); st->link = grp.readEntry("link", QString()); st->content = grp.readEntry("content", QString()); st->source = grp.readEntry("source", QString()); st->isFavorited = grp.readEntry("favorited", false); st->author.userId = grp.readEntry("authorId", QString()); st->author.userName = grp.readEntry("authorUserName", QString()); st->author.realName = grp.readEntry("authorRealName", QString()); st->author.location = grp.readEntry("authorLocation", QString()); st->author.description = grp.readEntry("authorDescription" , QString()); st->author.profileImageUrl = grp.readEntry("authorProfileImageUrl", QString()); st->author.homePageUrl = grp.readEntry("authorHomePageUrl", QString()); st->type = grp.readEntry("type", QString()); st->isRead = grp.readEntry("isRead", true); st->conversationId = grp.readEntry("conversationId", QString()); st->to = grp.readEntry("to", QStringList()); st->cc = grp.readEntry("cc", QStringList()); st->replies = grp.readEntry("replies", QStringList()); list.append(st); } if (!list.isEmpty()) { setLastTimelineId(account, timelineName, list.last()->conversationId); } return list; } QString PumpIOMicroBlog::postUrl(Choqok::Account* account, const QString& username, const QString& postId) const { Q_UNUSED(account); return QString(postId).replace("/api/", '/' + username + '/'); } QString PumpIOMicroBlog::profileUrl(Choqok::Account* account, const QString& username) const { Q_UNUSED(account) if (username.contains("acct:")) { return QString("https://%1/%2").arg(hostFromAcct(username)).arg(userNameFromAcct(username)); } else { return username; } } void PumpIOMicroBlog::saveTimeline(Choqok::Account* account, const QString& timelineName, const QList< Choqok::UI::PostWidget* >& timeline) { const QString fileName = Choqok::AccountManager::generatePostBackupFileName(account->alias(), timelineName); KConfig postsBackup("choqok/" + fileName, KConfig::NoGlobals, "data"); ///Clear previous data: Q_FOREACH (const QString& group, postsBackup.groupList()) { postsBackup.deleteGroup(group); } QList< Choqok::UI::PostWidget *>::const_iterator it, endIt = timeline.constEnd(); for (it = timeline.constBegin(); it != endIt; ++it) { PumpIOPost *post = dynamic_cast((*it)->currentPost()); KConfigGroup grp(&postsBackup, post->creationDateTime.toString()); grp.writeEntry("creationDateTime", post->creationDateTime); grp.writeEntry("postId", post->postId.toString()); grp.writeEntry("link", post->link); grp.writeEntry("content", post->content); grp.writeEntry("source", post->source); grp.writeEntry("favorited", post->isFavorited); grp.writeEntry("authorId", post->author.userId.toString()); grp.writeEntry("authorRealName", post->author.realName); grp.writeEntry("authorUserName", post->author.userName); grp.writeEntry("authorLocation" , post->author.location); grp.writeEntry("authorDescription" , post->author.description); grp.writeEntry("authorProfileImageUrl", post->author.profileImageUrl); grp.writeEntry("authorHomePageUrl" , post->author.homePageUrl); grp.writeEntry("type" , post->type); grp.writeEntry("isRead", post->isRead); grp.writeEntry("conversationId", post->conversationId.toString()); grp.writeEntry("to", post->to); grp.writeEntry("cc", post->cc); grp.writeEntry("replies", post->replies); } postsBackup.sync(); if (Choqok::Application::isShuttingDown()) { --d->countOfTimelinesToSave; if (d->countOfTimelinesToSave < 1) { emit readyForUnload(); } } } Choqok::TimelineInfo* PumpIOMicroBlog::timelineInfo(const QString& timelineName) { return m_timelinesInfos.value(timelineName); } void PumpIOMicroBlog::updateTimelines(Choqok::Account* theAccount) { PumpIOAccount *acc = qobject_cast(theAccount); if (acc) { Q_FOREACH (const QString& timeline, acc->timelineNames()) { KUrl url(acc->host()); url.addPath(m_timelinesPaths[timeline].arg(acc->username())); QOAuth::ParamMap oAuthParams; const ChoqokId lastActivityId(lastTimelineId(theAccount, timeline)); if (!lastActivityId.isEmpty()) { oAuthParams.insert("count", QByteArray::number(200)); oAuthParams.insert("since", KUrl::toPercentEncoding(lastActivityId.toString())); } else { oAuthParams.insert("count", QByteArray::number(Choqok::BehaviorSettings::countOfPosts())); } KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::Reload, KIO::HideProgressInfo); if (!job) { kDebug() << "Cannot create an http GET request!"; continue; } job->addMetaData("customHTTPHeader", authorizationMetaData(acc, url, QOAuth::GET, oAuthParams)); m_timelinesRequests[job] = timeline; m_accountJobs[job] = acc; connect(job, SIGNAL(result(KJob*)), this, SLOT(slotUpdateTimeline(KJob*))); job->start(); } } else { kDebug() << "theAccount is not a PumpIOAccount!"; } } void PumpIOMicroBlog::fetchFollowing(Choqok::Account* theAccount) { PumpIOAccount *acc = qobject_cast(theAccount); if (acc) { KUrl url(acc->host()); url.addPath(QString("/api/user/%1/following").arg(acc->username())); QOAuth::ParamMap oAuthParams; oAuthParams.insert("count", QByteArray::number(200)); if (!acc->following().isEmpty()) { oAuthParams.insert("since", KUrl::toPercentEncoding(acc->following().last())); } KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::Reload, KIO::HideProgressInfo); if (!job) { kDebug() << "Cannot create an http GET request!"; return; } job->addMetaData("customHTTPHeader", authorizationMetaData(acc, url, QOAuth::GET, oAuthParams)); m_accountJobs[job] = acc; connect(job, SIGNAL(result(KJob*)), this, SLOT(slotFollowing(KJob*))); job->start(); } else { kDebug() << "theAccount is not a PumpIOAccount!"; } } void PumpIOMicroBlog::share(Choqok::Account* theAccount, Choqok::Post* post) { PumpIOAccount *acc = qobject_cast(theAccount); if (acc) { QVariantMap object; object.insert("objectType", post->type); object.insert("id", post->postId.toString()); QVariantMap item; item.insert("verb", "share"); item.insert("object", object); QJson::Serializer serializer; const QByteArray data = serializer.serialize(item); KUrl url(acc->host()); url.addPath(outboxActivity.arg(acc->username())); KIO::StoredTransferJob *job = KIO::storedHttpPost(data, url, KIO::HideProgressInfo); job->addMetaData("content-type", "Content-Type: application/json"); job->addMetaData("customHTTPHeader", authorizationMetaData(acc, url, QOAuth::POST)); if (!job) { kDebug() << "Cannot create an http POST request!"; return; } m_accountJobs[job] = acc; m_shareJobs[job] = post; connect(job, SIGNAL(result(KJob*)), this, SLOT(slotShare(KJob*))); job->start(); } else { kDebug() << "theAccount is not a PumpIOAccount!"; } } void PumpIOMicroBlog::toggleFavorite(Choqok::Account* theAccount, Choqok::Post* post) { PumpIOAccount *acc = qobject_cast(theAccount); if (acc) { QVariantMap object; object.insert("objectType", post->type); object.insert("id", post->postId.toString()); QVariantMap item; item.insert("verb", post->isFavorited ? "unfavorite" : "favorite"); item.insert("object", object); QJson::Serializer serializer; const QByteArray data = serializer.serialize(item); KUrl url(acc->host()); url.addPath(outboxActivity.arg(acc->username())); KIO::StoredTransferJob *job = KIO::storedHttpPost(data, url, KIO::HideProgressInfo); job->addMetaData("content-type", "Content-Type: application/json"); job->addMetaData("customHTTPHeader", authorizationMetaData(acc, url, QOAuth::POST)); if (!job) { kDebug() << "Cannot create an http POST request!"; return; } m_accountJobs[job] = acc; m_favoriteJobs[job] = post; connect(job, SIGNAL(result(KJob*)), this, SLOT(slotFavorite(KJob*))); job->start(); } else { kDebug() << "theAccount is not a PumpIOAccount!"; } } void PumpIOMicroBlog::slotCreatePost(KJob* job) { if (!job) { kDebug() << "Job is null pointer"; return; } Choqok::Post *post = m_createPostJobs.take(job); Choqok::Account *theAccount = m_accountJobs.take(job); if (!post || !theAccount) { kDebug() << "Account or Post is NULL pointer"; return; } int ret = 0; if (job->error()) { ret = 1; } else { KIO::StoredTransferJob* j = qobject_cast(job); QJson::Parser parser; const QVariantMap reply = parser.parse(j->data()).toMap(); if (!reply["object"].toMap().value("id").toString().isEmpty()) { Choqok::NotifyManager::success(i18n("New post submitted successfully")); emit postCreated(theAccount, post); } else { ret = 1; } } if (ret) { kDebug() << "Job Error: " << job->errorString(); emit errorPost(theAccount, post, Choqok::MicroBlog::CommunicationError, i18n("Creating the new post failed. %1", job->errorString()), MicroBlog::Critical); } } void PumpIOMicroBlog::slotFavorite(KJob* job) { if (!job) { kDebug() << "Job is null pointer"; return; } Choqok::Post *post = m_favoriteJobs.take(job); Choqok::Account *theAccount = m_accountJobs.take(job); if (!post || !theAccount) { kDebug() << "Account or Post is NULL pointer"; return; } if (job->error()) { kDebug() << "Job Error: " << job->errorString(); emit error(theAccount, Choqok::MicroBlog::CommunicationError, i18n("Cannot set the post as (un)favorite. %1", job->errorString())); } else { post->isFavorited = !post->isFavorited; emit favorite(theAccount, post); } } void PumpIOMicroBlog::slotFollowing(KJob* job) { if (!job) { kDebug() << "Job is null pointer"; return; } Choqok::Account *theAccount = m_accountJobs.take(job); if (!theAccount) { kDebug() << "Account is NULL pointer"; return; } if (job->error()) { kDebug() << "Job Error: " << job->errorString(); emit error(theAccount, Choqok::MicroBlog::CommunicationError, - i18n("Cannot retrieve the list of following. %1", job->errorString())); + i18n("Cannot retrieve the following list. %1", job->errorString())); } else { PumpIOAccount *acc = qobject_cast(theAccount); if (acc) { Choqok::UI::Global::mainWindow()->showStatusMessage( - i18n("Friends list for account %1 has been updated.", + i18n("Following list for account %1 has been updated.", acc->username())); KIO::StoredTransferJob* j = qobject_cast(job); QJson::Parser parser; const QVariantList items = parser.parse(j->data()).toMap().value("items").toList(); QStringList following; Q_FOREACH (const QVariant& element, items) { following.append(element.toMap().value("preferredUsername").toString()); } acc->setFollowing(following); } else { kDebug() << "theAccount is not a PumpIOAccount!"; } } } void PumpIOMicroBlog::slotShare(KJob* job) { if (!job) { kDebug() << "Job is null pointer"; return; } Choqok::Post *post = m_shareJobs.take(job); Choqok::Account *theAccount = m_accountJobs.take(job); if (!post || !theAccount) { kDebug() << "Account or Post is NULL pointer"; return; } if (job->error()) { kDebug() << "Job Error: " << job->errorString(); emit error(theAccount, Choqok::MicroBlog::CommunicationError, i18n("Cannot share the post. %1", job->errorString())); } else { Choqok::UI::Global::mainWindow()->showStatusMessage( i18n("The post has been shared!.")); KIO::StoredTransferJob* j = qobject_cast(job); QJson::Parser parser; const QVariantMap object = parser.parse(j->data()).toMap().value("object").toMap(); } } void PumpIOMicroBlog::slotRemovePost(KJob* job) { if (!job) { kDebug() << "Job is null pointer"; return; } Choqok::Post *post = m_removePostJobs.take(job); Choqok::Account *theAccount = m_accountJobs.take(job); if (!post || !theAccount) { kDebug() << "Account or Post is NULL pointer"; return; } if (job->error()) { kDebug() << "Job Error: " << job->errorString(); emit errorPost(theAccount, post, Choqok::MicroBlog::CommunicationError, i18n("Removing the post failed. %1", job->errorString()), MicroBlog::Critical); } else { KIO::StoredTransferJob* j = qobject_cast(job); QJson::Parser parser; const QVariantMap object = parser.parse(j->data()).toMap().value("object").toMap(); if (!object["deleted"].toString().isEmpty()) { Choqok::NotifyManager::success(i18n("Post removed successfully")); emit postRemoved(theAccount, post); } } } void PumpIOMicroBlog::slotUpdateTimeline(KJob* job) { if (!job) { kDebug() << "Job is null pointer"; return; } Choqok::Account *account = m_accountJobs.take(job); if (!account) { kDebug() << "Account or Post is NULL pointer"; return; } if (job->error()) { kDebug() << "Job Error: " << job->errorString(); emit error(account, Choqok::MicroBlog::CommunicationError, i18n("An error occurred when fetching the timeline")); } else { KIO::StoredTransferJob* j = qobject_cast(job); const QList list = readTimeline(j->data()); const QString timeline(m_timelinesRequests.take(job)); if (!list.isEmpty()) { setLastTimelineId(account, timeline, list.last()->conversationId); } emit timelineDataReceived(account, timeline, list); } } QString PumpIOMicroBlog::authorizationMetaData(PumpIOAccount* account, const KUrl& url, const QOAuth::HttpMethod& method, const QOAuth::ParamMap& paramMap) const { const QByteArray authorization = account->oAuth()->createParametersString(url.url(), method, account->token().toLocal8Bit(), account->tokenSecret().toLocal8Bit(), QOAuth::HMAC_SHA1, paramMap, QOAuth::ParseForHeaderArguments); return "Authorization: " + authorization; } QString PumpIOMicroBlog::hostFromAcct(const QString& acct) const { if (acct.contains("acct:")) { return acct.split(':')[1].split('@')[1]; } return acct; } ChoqokId PumpIOMicroBlog::lastTimelineId(Choqok::Account* theAccount, const QString& timeline) const { kDebug() << "Latest ID for timeline " << timeline << m_timelinesLatestIds[theAccount][timeline]; return m_timelinesLatestIds[theAccount][timeline]; } Choqok::Post* PumpIOMicroBlog::readPost(const QVariantMap& var, Choqok::Post* post) { PumpIOPost *p = dynamic_cast< PumpIOPost* >(post); if (p) { QVariantMap object; if (var.value("verb") == "post" || var.value("verb") == "share") { object = var["object"].toMap(); } else { object = var; } QTextDocument content; if (!object["displayName"].isNull()) { content.setHtml(object["displayName"].toString()); p->content = content.toPlainText().trimmed(); p->content += '\n'; } content.setHtml(object["content"].toString()); p->content += content.toPlainText().trimmed(); if (!object["fullImage"].isNull()) { const QString imagePath = object["fullImage"].toMap().value("url").toString(); if (!imagePath.isEmpty()) { p->content += '\n' + imagePath; } } p->creationDateTime = QDateTime::fromString(var["published"].toString(), "yyyy-MM-dd'T'hh:mm:ss'Z'"); p->postId = object["id"].toString(); p->link = object["url"].toString(); p->type = object["objectType"].toString(); p->isFavorited = object["liked"].toBool(); p->conversationId = var["id"].toString(); QString author; var["author"].isNull() ? author = "actor" : author = "author"; const QVariantMap actor = var[author].toMap(); p->author.userId = actor["id"].toString(); p->author.userName = actor["preferredUsername"].toString(); p->author.realName = actor["displayName"].toString(); p->author.homePageUrl = actor["url"].toString(); p->author.location = actor["location"].toMap().value("displayName").toString(); p->author.description = actor["summary"].toString(); p->author.profileImageUrl = actor["image"].toMap().value("url").toString(); if (!var["generator"].isNull()) { p->source = var["generator"].toMap().value("displayName").toString(); } const QVariantList to = var["to"].toList(); Q_FOREACH (const QVariant& element, to) { p->to.append(element.toMap().value("id").toString()); } const QVariantList cc = var["cc"].toList(); Q_FOREACH (const QVariant& element, cc) { p->cc.append(element.toMap().value("id").toString()); } const QVariantList replies = object["replies"].toMap().value("items").toList(); Q_FOREACH (const QVariant& element, replies) { p->replies.append(element.toMap().value("id").toString()); } return p; } else { kDebug() << "post is not a PumpIOPost!"; return post; } } QList< Choqok::Post* > PumpIOMicroBlog::readTimeline(const QByteArray& buffer) { QList posts; QJson::Parser parser; const QVariantList list = parser.parse(buffer).toMap().value("items").toList(); Q_FOREACH (const QVariant& element, list) { const QVariantMap elementMap = element.toMap(); if (!elementMap["object"].toMap().value("deleted").isNull()) { // Skip deleted posts continue; } posts.prepend(readPost(elementMap, new PumpIOPost)); } return posts; } void PumpIOMicroBlog::setLastTimelineId(Choqok::Account* theAccount, const QString& timeline, const ChoqokId& id) { m_timelinesLatestIds[theAccount][timeline] = id; } void PumpIOMicroBlog::setTimelinesInfo() { Choqok::TimelineInfo *t = new Choqok::TimelineInfo; t->name = i18nc("Timeline Name", "Activity"); t->description = i18nc("Timeline description", "You and people you follow"); t->icon = "user-home"; m_timelinesInfos["Activity"] = t; m_timelinesPaths["Activity"] = inboxActivity + "/major"; t = new Choqok::TimelineInfo; t->name = i18nc("Timeline Name", "Favorites"); t->description = i18nc("Timeline description", "Posts you favorited"); t->icon = "favorites"; m_timelinesInfos["Favorites"] = t; m_timelinesPaths["Favorites"] = "/api/user/%1/favorites"; t = new Choqok::TimelineInfo; t->name = i18nc("Timeline Name", "Inbox"); t->description = i18nc("Timeline description", "Posts sent to you"); t->icon = "mail-folder-inbox"; m_timelinesInfos["Inbox"] = t; m_timelinesPaths["Inbox"] = inboxActivity + "/direct/major/"; t = new Choqok::TimelineInfo; t->name = i18nc("Timeline Name", "Outbox"); t->description = i18nc("Timeline description", "Posts you sent"); t->icon = "mail-folder-outbox"; m_timelinesInfos["Outbox"] = t; m_timelinesPaths["Outbox"] = outboxActivity + "/major/"; } QString PumpIOMicroBlog::userNameFromAcct(const QString& acct) const { if (acct.contains("acct:")) { return acct.split(':')[1].split('@')[0]; } return acct; }