diff --git a/microblogs/pumpio/pumpioaccount.cpp b/microblogs/pumpio/pumpioaccount.cpp index ebc1974e..a0dafcc7 100644 --- a/microblogs/pumpio/pumpioaccount.cpp +++ b/microblogs/pumpio/pumpioaccount.cpp @@ -1,150 +1,150 @@ /* 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 "pumpioaccount.h" #include #include "passwordmanager.h" #include "pumpiomicroblog.h" class PumpIOAccount::Private { public: QString consumerKey; QString consumerSecret; QString host; QString token; QString tokenSecret; QStringList following; QOAuth::Interface *oAuth; }; PumpIOAccount::PumpIOAccount(PumpIOMicroBlog* parent, const QString& alias): Account(parent, alias), d(new Private) { d->host = configGroup()->readEntry("Host", QString()); d->token = configGroup()->readEntry("Token", QString()); d->consumerKey = configGroup()->readEntry("ConsumerKey", QString()); d->consumerSecret = Choqok::PasswordManager::self()->readPassword(QString("%1_consumerSecret").arg(alias)); d->tokenSecret = Choqok::PasswordManager::self()->readPassword(QString("%1_tokenSecret").arg(alias)); d->oAuth = new QOAuth::Interface(new KIO::AccessManager(this), this); d->oAuth->setConsumerKey(d->consumerKey.toLocal8Bit()); d->oAuth->setConsumerSecret(d->consumerSecret.toLocal8Bit()); d->following = configGroup()->readEntry("Following", QStringList()); parent->fetchFollowing(this); } PumpIOAccount::~PumpIOAccount() { d->oAuth->deleteLater(); delete d; } QString PumpIOAccount::host() { return d->host; } void PumpIOAccount::setHost(const QString& host) { d->host = host; } QString PumpIOAccount::consumerKey() { return d->consumerKey; } void PumpIOAccount::setConsumerKey(const QString& consumerKey) { d->consumerKey = consumerKey; } QString PumpIOAccount::consumerSecret() { return d->consumerSecret; } void PumpIOAccount::setConsumerSecret(const QString& consumerSecret) { d->consumerSecret = consumerSecret; } QString PumpIOAccount::token() { return d->token; } void PumpIOAccount::setToken(const QString& token) { d->token = token; } QString PumpIOAccount::tokenSecret() { return d->tokenSecret; } void PumpIOAccount::setTokenSecret(const QString& tokenSecret) { d->tokenSecret = tokenSecret; } QStringList PumpIOAccount::following() { return d->following; } void PumpIOAccount::setFollowing(const QStringList following) { d->following = following; d->following.sort(); d->following.removeDuplicates(); writeConfig(); } QString PumpIOAccount::webfingerID() { - return username() + '@' + d->host.remove("https://").remove("http://"); + return username() + '@' + QString(d->host).remove("https://").remove("http://"); } QOAuth::Interface* PumpIOAccount::oAuth() { return d->oAuth; } void PumpIOAccount::writeConfig() { configGroup()->writeEntry("Host", d->host); configGroup()->writeEntry("Token", d->token); configGroup()->writeEntry("ConsumerKey", d->consumerKey); Choqok::PasswordManager::self()->writePassword(QString("%1_consumerSecret").arg(alias()), d->consumerSecret); Choqok::PasswordManager::self()->writePassword(QString("%1_tokenSecret").arg(alias()), d->tokenSecret); configGroup()->writeEntry("Following", d->following); Choqok::Account::writeConfig(); } diff --git a/microblogs/pumpio/pumpiopostwidget.cpp b/microblogs/pumpio/pumpiopostwidget.cpp index 1c3d8729..3f60ace7 100644 --- a/microblogs/pumpio/pumpiopostwidget.cpp +++ b/microblogs/pumpio/pumpiopostwidget.cpp @@ -1,169 +1,174 @@ /* 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 "pumpiopostwidget.h" #include #include #include #include "mediamanager.h" #include "pumpioaccount.h" #include "pumpiomicroblog.h" #include "pumpiopost.h" const KIcon PumpIOPostWidget::unFavIcon(Choqok::MediaManager::convertToGrayScale(KIcon("rating").pixmap(16))); class PumpIOPostWidget::Private { public: KPushButton *btnFav; }; PumpIOPostWidget::PumpIOPostWidget(Choqok::Account* account, Choqok::Post* post, QWidget* parent): PostWidget(account, post, parent), d(new Private) { } PumpIOPostWidget::~PumpIOPostWidget() { delete d->btnFav; delete d; } QString PumpIOPostWidget::generateSign() { QString ss; - const PumpIOPost *post = dynamic_cast(currentPost()); - const PumpIOMicroBlog *microblog = qobject_cast(currentAccount()->microblog()); + PumpIOPost *post = dynamic_cast(currentPost()); + PumpIOAccount *account = qobject_cast(currentAccount()); + PumpIOMicroBlog *microblog = qobject_cast(account->microblog()); if (post) { - ss = "author.description - + "\">" + post->author.userName + " - "; + ss = "author.description + "\">" + + post->author.userName + " - "; ss += "link + "\" title=\"" + post->creationDateTime.toString(Qt::DefaultLocaleLongDate) + "\">%1"; if (!post->source.isEmpty()) { ss += " - " + post->source; } const QRegExp followers("/api/user/\\w+/followers"); if (!post->to.isEmpty()) { ss += " - "; ss += i18n("To: "); Q_FOREACH (const QString& id, post->to) { if (id == "http://activityschema.org/collection/public") { ss += "Public"; } else if (followers.indexIn(id) != -1) { ss += "Followers"; + } else if (id == "acct:" + account->webfingerID()) { + ss += "You"; } else { - ss += "profileUrl(currentAccount(), id) + ss += "profileUrl(account, id) + "\">" + microblog->userNameFromAcct(id) + " "; } } ss = ss.trimmed(); } if (!post->cc.isEmpty()) { ss += " - "; ss += i18n("Cc: "); Q_FOREACH (const QString& id, post->cc) { if (id == "http://activityschema.org/collection/public") { ss += "Public"; } else if (followers.indexIn(id) != -1) { ss += "Followers"; + } else if (id == "acct:" + account->webfingerID()) { + ss += "You"; } else { - ss += "profileUrl(currentAccount(), id) + ss += "profileUrl(account, id) + "\">" + microblog->userNameFromAcct(id) + ""; } } ss = ss.trimmed(); } } else { kDebug() << "post is not a PumpIOPost!"; } return ss; } void PumpIOPostWidget::initUi() { Choqok::UI::PostWidget::initUi(); d->btnFav = addButton("btnFavorite", i18nc("@info:tooltip", "Favorite"), "rating"); d->btnFav->setCheckable(true); connect(d->btnFav, SIGNAL(clicked(bool)), this, SLOT(toggleFavorite())); updateFavStat(); } void PumpIOPostWidget::toggleFavorite() { setReadWithSignal(); PumpIOMicroBlog* microBlog = qobject_cast(currentAccount()->microblog()); connect(microBlog, SIGNAL(favorite(Choqok::Account*, Choqok::Post*)), this, SLOT(slotToggleFavorite(Choqok::Account*, Choqok::Post*))); microBlog->toggleFavorite(currentAccount(), currentPost()); } void PumpIOPostWidget::slotToggleFavorite(Choqok::Account*, Choqok::Post*) { updateFavStat(); } void PumpIOPostWidget::slotPostError(Choqok::Account* theAccount, Choqok::Post* post, Choqok::MicroBlog::ErrorType error, const QString& errorMessage) { Q_UNUSED(error) if (theAccount == currentAccount() && post == currentPost()) { kDebug() << errorMessage; disconnect(currentAccount()->microblog(), SIGNAL(postRemoved(Choqok::Account*,Choqok::Post*)), this, SLOT(slotCurrentPostRemoved(Choqok::Account*,Choqok::Post*)) ); disconnect(currentAccount()->microblog(), SIGNAL(errorPost(Choqok::Account*,Choqok::Post*,Choqok::MicroBlog::ErrorType,QString,Choqok::MicroBlog::ErrorLevel)), this, SLOT(slotPostError(Choqok::Account*,Choqok::Post*,Choqok::MicroBlog::ErrorType,QString))); } } void PumpIOPostWidget::slotResendPost() { setReadWithSignal(); PumpIOMicroBlog* microBlog = qobject_cast(currentAccount()->microblog()); microBlog->share(currentAccount(), currentPost()); } void PumpIOPostWidget::updateFavStat() { d->btnFav->setChecked(currentPost()->isFavorited); if (currentPost()->isFavorited){ d->btnFav->setIcon(KIcon("rating")); } else { d->btnFav->setIcon(unFavIcon); } }