Show webfinger if displayName is unknown for an author.
[larjonas-pumpa.git] / src / collectionwidget.cpp
blobc7b4986637f8cf6b69a4065eb501ecdd19440e6c
1 /*
2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #include "collectionwidget.h"
21 #include "pumpa_defines.h"
22 #include "activitywidget.h"
24 #include <QDebug>
26 //------------------------------------------------------------------------------
28 CollectionWidget::CollectionWidget(QWidget* parent, int widgetLimit,
29 int purgeWait) :
30 ASWidget(parent, widgetLimit, purgeWait),
31 m_loadOlderButton(NULL)
34 //------------------------------------------------------------------------------
36 QASAbstractObjectList* CollectionWidget::initList(QString endpoint,
37 QObject* parent) {
38 m_asMode = QAS_COLLECTION;
39 return QASCollection::initCollection(endpoint, parent);
42 //------------------------------------------------------------------------------
44 void CollectionWidget::clear() {
45 ASWidget::clear();
47 m_loadOlderButton = new QPushButton(this);
48 m_loadOlderButton->setFocusPolicy(Qt::NoFocus);
49 connect(m_loadOlderButton, SIGNAL(clicked()),
50 this, SLOT(onLoadOlderClicked()));
51 m_loadOlderButton->setVisible(false);
54 //------------------------------------------------------------------------------
56 void CollectionWidget::onLoadOlderClicked() {
57 updateLoadOlderButton(true);
58 fetchOlder();
61 //------------------------------------------------------------------------------
63 void CollectionWidget::updateLoadOlderButton(bool wait) {
64 if (m_list->nextLink().isEmpty()) {
65 m_loadOlderButton->setVisible(false);
66 m_itemLayout->removeWidget(m_loadOlderButton);
67 return;
69 QString text = tr("Load older");
70 if (wait)
71 text = "...";
73 m_loadOlderButton->setText(text);
74 m_loadOlderButton->setVisible(true);
75 m_itemLayout->addWidget(m_loadOlderButton);
78 //------------------------------------------------------------------------------
80 void CollectionWidget::update() {
81 ASWidget::update();
82 updateLoadOlderButton();
85 //------------------------------------------------------------------------------
87 ObjectWidgetWithSignals*
88 CollectionWidget::createWidget(QASAbstractObject* aObj) {
89 QASActivity* act = qobject_cast<QASActivity*>(aObj);
90 if (!act) {
91 qDebug() << "ERROR CollectionWidget::createWidget passed non-activity";
92 return NULL;
95 ActivityWidget* aw = new ActivityWidget(act, isFullObject(act), this);
96 connect(aw, SIGNAL(showContext(QASObject*)),
97 this, SIGNAL(showContext(QASObject*)));
99 // Add new object to shown objects set
100 QASObject* obj = act->object();
101 if (obj)
102 m_objects_shown.insert(obj);
104 return aw;
107 //------------------------------------------------------------------------------
109 void CollectionWidget::changeWidgetObject(ObjectWidgetWithSignals* ow,
110 QASAbstractObject* aObj) {
111 QASActivity* act = qobject_cast<QASActivity*>(aObj);
112 ActivityWidget* aw = qobject_cast<ActivityWidget*>(ow);
113 if (!act || !aw) {
114 if (!act)
115 qDebug() << "[ERROR] CollectionWidget::changeWidgetObject, bad object";
116 if (!aw)
117 qDebug() << "[ERROR] CollectionWidget::changeWidgetObject, bad widget";
118 return ASWidget::changeWidgetObject(ow, aObj);
121 aw->changeObject(act, isFullObject(act));
123 // Remove old object from shown objects set
124 QASActivity* oldAct = aw->activity();
125 QASObject* oldObj = oldAct->object();
126 if (oldObj)
127 m_objects_shown.remove(oldObj);
129 // Add new object to shown objects set
130 QASObject* obj = act->object();
131 if (obj)
132 m_objects_shown.insert(obj);
135 //------------------------------------------------------------------------------
137 bool CollectionWidget::isFullObject(QASActivity* act) {
138 QString verb = act->verb();
139 QASObject* obj = act->object();
140 bool objAlreadyShown = obj && m_objects_shown.contains(obj);
141 QASActor* actor = act->actor();
142 bool directedAtYou = ((act->to() && act->to()->containsYou()) ||
143 (act->cc() && act->cc()->containsYou())) &&
144 !act->skipNotify();
145 bool hiddenActor = actor && actor->isHidden();
147 return (!(hiddenActor && !directedAtYou) &&
148 ((verb == "post" || verb == "share") &&
149 (!objAlreadyShown || directedAtYou)));
152 //------------------------------------------------------------------------------
154 bool CollectionWidget::hasObject(QASAbstractObject* aObj) {
155 QASObject* obj = qobject_cast<QASObject*>(aObj);
156 return (m_object_set.contains(aObj) ||
157 (obj && m_objects_shown.contains(obj)));
160 //------------------------------------------------------------------------------
162 bool CollectionWidget::countAsNew(QASAbstractObject* aObj) {
163 QASActivity* act = qobject_cast<QASActivity*>(aObj);
164 if (!act)
165 return false;
167 return !act->actor()->isYou();