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"
26 //------------------------------------------------------------------------------
28 CollectionWidget::CollectionWidget(QWidget
* parent
, int widgetLimit
,
30 ASWidget(parent
, widgetLimit
, purgeWait
),
31 m_loadOlderButton(NULL
)
34 //------------------------------------------------------------------------------
36 QASAbstractObjectList
* CollectionWidget::initList(QString endpoint
,
38 m_asMode
= QAS_COLLECTION
;
39 return QASCollection::initCollection(endpoint
, parent
);
42 //------------------------------------------------------------------------------
44 void CollectionWidget::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);
61 //------------------------------------------------------------------------------
63 void CollectionWidget::updateLoadOlderButton(bool wait
) {
64 if (m_list
->nextLink().isEmpty()) {
65 m_loadOlderButton
->setVisible(false);
66 m_itemLayout
->removeWidget(m_loadOlderButton
);
69 QString text
= tr("Load older");
73 m_loadOlderButton
->setText(text
);
74 m_loadOlderButton
->setVisible(true);
75 m_itemLayout
->addWidget(m_loadOlderButton
);
78 //------------------------------------------------------------------------------
80 void CollectionWidget::update() {
82 updateLoadOlderButton();
85 //------------------------------------------------------------------------------
87 ObjectWidgetWithSignals
*
88 CollectionWidget::createWidget(QASAbstractObject
* aObj
) {
89 QASActivity
* act
= qobject_cast
<QASActivity
*>(aObj
);
91 qDebug() << "ERROR CollectionWidget::createWidget passed non-activity";
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();
102 m_objects_shown
.insert(obj
);
107 //------------------------------------------------------------------------------
109 void CollectionWidget::changeWidgetObject(ObjectWidgetWithSignals
* ow
,
110 QASAbstractObject
* aObj
) {
111 QASActivity
* act
= qobject_cast
<QASActivity
*>(aObj
);
112 ActivityWidget
* aw
= qobject_cast
<ActivityWidget
*>(ow
);
115 qDebug() << "[ERROR] CollectionWidget::changeWidgetObject, bad object";
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();
127 m_objects_shown
.remove(oldObj
);
129 // Add new object to shown objects set
130 QASObject
* obj
= act
->object();
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())) &&
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
);
167 return !act
->actor()->isYou();