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 "activitywidget.h"
21 #include "texttoolbutton.h"
22 #include "pumpa_defines.h"
26 //------------------------------------------------------------------------------
28 ActivityWidget::ActivityWidget(QASActivity
* a
, bool fullObject
,
30 ObjectWidgetWithSignals(parent
),
35 qDebug() << "Creating ActivityWidget";
38 m_textLabel
= new RichTextLabel(this);
39 connect(m_textLabel
, SIGNAL(linkHovered(const QString
&)),
40 this, SIGNAL(linkHovered(const QString
&)));
42 m_objectWidget
= new ObjectWidget(NULL
, this);
43 ObjectWidgetWithSignals::connectSignals(m_objectWidget
, this);
45 connect(m_objectWidget
, SIGNAL(showContext(QASObject
*)),
46 this, SIGNAL(showContext(QASObject
*)));
48 QVBoxLayout
* layout
= new QVBoxLayout
;
49 layout
->setContentsMargins(0, 0, 0, 0);
50 layout
->addWidget(m_textLabel
, 0, Qt::AlignTop
);
52 layout
->addWidget(m_objectWidget
, 0, Qt::AlignTop
);
53 layout
->addWidget(new QLabel("<hr />"));
55 changeObject(a
, fullObject
);
60 //------------------------------------------------------------------------------
62 ActivityWidget::~ActivityWidget() {
64 qDebug() << "Deleting ActivityWidget" << m_activity
->id();
68 //------------------------------------------------------------------------------
70 void ActivityWidget::changeObject(QASAbstractObject
* aObj
, bool fullObject
) {
71 m_activity
= qobject_cast
<QASActivity
*>(aObj
);
76 const QString verb
= m_activity
->verb();
77 QASObject
* obj
= m_activity
->object();
78 QString objType
= obj
->type();
80 m_objectWidget
->changeObject(obj
, fullObject
);
81 m_objectWidget
->setActivity(m_activity
);
83 bool objectVisible
= !obj
->content().isEmpty() ||
84 !obj
->displayName().isEmpty()
85 || (objType
== "image" && !obj
->imageUrl().isEmpty())
88 m_objectWidget
->setVisible(objectVisible
);
93 //------------------------------------------------------------------------------
95 void ActivityWidget::onObjectChanged() {
99 //------------------------------------------------------------------------------
101 void ActivityWidget::refreshTimeLabels() {
103 m_objectWidget
->refreshTimeLabels();
106 //------------------------------------------------------------------------------
108 void ActivityWidget::updateText() {
109 QString verb
= m_activity
->verb();
110 QString text
= m_activity
->content();
111 QString objType
= m_activity
->object()->type();
113 QString generatorName
= m_activity
->generatorName();
114 if (!generatorName
.isEmpty() && (verb
!= "share"))
115 text
+= QString(tr(" via %1")).arg(generatorName
);
118 text
= QString::fromUtf8("\342\231\273") + " " + text
;
120 if (verb
== "post") {
121 QString toStr
= recipientsToString(m_activity
->to());
122 QString ccStr
= recipientsToString(m_activity
->cc());
123 if (!toStr
.isEmpty())
124 text
+= " " + tr("To:") +" " + toStr
;
126 if (!ccStr
.isEmpty())
127 text
+= " " + tr("CC:") + " " + ccStr
;
130 m_textLabel
->setText(text
);
133 //------------------------------------------------------------------------------
135 QString
ActivityWidget::recipientsToString(QASObjectList
* rec
) {
141 for (size_t i
=0; i
<rec
->size(); ++i
) {
142 QASObject
* r
= rec
->at(i
);
143 if (r
->type() == "collection" && r
->id() == PUBLIC_RECIPIENT_ID
) {
146 QString name
= r
->displayName();
147 QString url
= r
->url();
155 ret
<< QString("<a href=\"%1\">%2</a>").arg(url
).arg(name
);
159 return ret
.join(", ");