9 #include "quickengine.h" 11 #include "core/author.h" 12 #include "core/engine.h" 13 #include "core/provider.h" 15 #include "knewstuffquick_debug.h" 23 Q_GLOBAL_STATIC(AllAuthorsHash, allAuthors)
31 bool componentCompleted{
false};
37 void resetConnections() {
38 if (!componentCompleted) {
42 provider->disconnect(q);
44 if (engine && engine->engine()) {
47 provider = coreEngine->
provider(providerId);
55 allAuthors()->insert(QStringLiteral(
"%1 %2").arg(provider->id(), author->id()), author);
56 Q_EMIT q->dataChanged();
62 std::shared_ptr<KNSCore::Author> author()
64 std::shared_ptr<KNSCore::Author> ret;
65 if (provider && !username.
isEmpty()) {
66 ret = allAuthors()->value(QStringLiteral(
"%1 %2").arg(provider->id(), username));
68 Q_EMIT provider->loadPerson(username);
80 , d(new Private(this))
82 connect(
this, &Author::engineChanged, &Author::dataChanged);
83 connect(
this, &Author::providerIdChanged, &Author::dataChanged);
84 connect(
this, &Author::usernameChanged, &Author::dataChanged);
92 void Author::classBegin()
95 void Author::componentComplete()
97 d->componentCompleted =
true;
98 d->resetConnections();
101 QObject *Author::engine()
const 106 void Author::setEngine(
QObject *newEngine)
108 if (d->engine != newEngine) {
109 d->engine = qobject_cast<
Engine*>(newEngine);
110 d->resetConnections();
111 Q_EMIT engineChanged();
115 QString Author::providerId()
const 117 return d->providerId;
120 void Author::setProviderId(
const QString &providerId)
122 if (d->providerId != providerId) {
123 d->providerId = providerId;
124 d->resetConnections();
125 Q_EMIT providerIdChanged();
129 QString Author::username()
const 134 void Author::setUsername(
const QString &username)
136 if (d->username != username) {
137 d->username = username;
138 d->resetConnections();
139 Q_EMIT usernameChanged();
145 std::shared_ptr<KNSCore::Author> author = d->author();
146 if (author.get() && !author->name().isEmpty()) {
147 return author->name();
154 std::shared_ptr<KNSCore::Author> author = d->author();
156 return author->description();
163 std::shared_ptr<KNSCore::Author> author = d->author();
165 return author->homepage();
172 std::shared_ptr<KNSCore::Author> author = d->author();
174 return author->profilepage();
181 std::shared_ptr<KNSCore::Author> author = d->author();
183 return author->avatarUrl();
Encapsulates a KNSCore::Author for use in Qt Quick.
Encapsulates a KNSCore::Engine for use in Qt Quick.
QUrl avatarUrl() const
Retrieve the url of the user's avatar image.
bool isEmpty() const const
QString description() const
Retrieve the user's description text.
QSharedPointer< Provider > provider(const QString &providerId) const
The Provider instance with the passed ID.
QString homepage() const
Retrieve the author's homepage.
void personLoaded(const std::shared_ptr< KNSCore::Author > author)
Fired when the details of a person have been loaded.
QString profilepage() const
Retrieve the author's profile page.
QSharedPointer< Provider > defaultProvider() const
Return the first provider in the providers list (usually the default provider)
QString name() const
Retrieve the author's name.