9#include "quickengine.h"
11#include "core/author.h"
12#include "core/provider.h"
16namespace KNewStuffQuick
19typedef QHash<QString, std::shared_ptr<KNSCore::Author>> AllAuthorsHash;
20Q_GLOBAL_STATIC(AllAuthorsHash, allAuthors)
25 AuthorPrivate(Author *qq)
30 bool componentCompleted{
false};
31 Engine *engine{
nullptr};
35 QSharedPointer<KNSCore::Provider> provider;
36 void resetConnections()
38 if (!componentCompleted) {
42 provider->disconnect(q);
45 provider = engine->provider(providerId);
47 provider = engine->defaultProvider();
52 allAuthors()->insert(QStringLiteral(
"%1 %2").arg(provider->id(), author->id()), author);
53 Q_EMIT q->dataChanged();
60 std::shared_ptr<KNSCore::Author> author()
62 std::shared_ptr<KNSCore::Author> ret;
63 if (provider && !username.isEmpty()) {
64 ret = allAuthors()->value(QStringLiteral(
"%1 %2").arg(provider->id(), username));
66 provider->loadPerson(username);
74using namespace KNewStuffQuick;
78 , d(new AuthorPrivate(this))
80 connect(
this, &Author::engineChanged, &Author::dataChanged);
81 connect(
this, &Author::providerIdChanged, &Author::dataChanged);
82 connect(
this, &Author::usernameChanged, &Author::dataChanged);
85Author::~Author() =
default;
87void Author::classBegin()
91void Author::componentComplete()
93 d->componentCompleted =
true;
94 d->resetConnections();
102void Author::setEngine(Engine *newEngine)
104 if (d->engine != newEngine) {
105 d->engine = newEngine;
106 d->resetConnections();
113 return d->providerId;
116void Author::setProviderId(
const QString &providerId)
120 d->resetConnections();
121 Q_EMIT providerIdChanged();
130void Author::setUsername(
const QString &username)
134 d->resetConnections();
139QString Author::name()
const
141 std::shared_ptr<KNSCore::Author> author = d->author();
142 if (author.get() && !author->name().isEmpty()) {
143 return author->name();
148QString Author::description()
const
150 std::shared_ptr<KNSCore::Author> author = d->author();
152 return author->description();
157QString Author::homepage()
const
159 std::shared_ptr<KNSCore::Author> author = d->author();
161 return author->homepage();
166QString Author::profilepage()
const
168 std::shared_ptr<KNSCore::Author> author = d->author();
170 return author->profilepage();
175QUrl Author::avatarUrl()
const
177 std::shared_ptr<KNSCore::Author> author = d->author();
179 return author->avatarUrl();
184#include "moc_author.cpp"
void personLoaded(const std::shared_ptr< KNSCore::Author > author)
Fired when the details of a person have been loaded.
Engine * engine
The NewStuffQuickEngine to interact with servers through.
QString username
The user ID for the user this object represents.
QString providerId
The ID of the provider which the user is registered on.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)