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 "actorwidget.h"
21 #include "filedownloader.h"
23 #include <QMessageBox>
24 #include <QDesktopServices>
26 //------------------------------------------------------------------------------
28 ActorWidget::ActorWidget(QASActor
* a
, QWidget
* parent
, bool small
) :
29 QToolButton(parent
), m_actor(a
)
32 qDebug() << "Creating ActorWidget" << (m_actor
? m_actor
->id() : "NULL");
34 int max_size
= small
? 32 : 64;
36 setStyleSheet("QToolButton::menu-indicator { "
37 "subcontrol-origin: padding; "
38 "subcontrol-position: bottom right; "
40 setIconSize(QSize(max_size
, max_size
));
41 setFocusPolicy(Qt::NoFocus
);
42 setPopupMode(QToolButton::InstantPopup
);
45 m_menu
= new QMenu(this);
46 m_menuTitleAction
= new QAction(this);
47 connect(m_menuTitleAction
, SIGNAL(triggered()), this, SLOT(onMenuTitle()));
49 m_followAction
= new QAction(this);
50 connect(m_followAction
, SIGNAL(triggered()), this, SLOT(onFollowAuthor()));
52 m_hideAuthorAction
= new QAction(this);
53 connect(m_hideAuthorAction
, SIGNAL(triggered()), this, SLOT(onHideAuthor()));
60 //------------------------------------------------------------------------------
62 ActorWidget::~ActorWidget() {
64 qDebug() << "Deleting ActorWidget" << m_actor
->id();
68 //------------------------------------------------------------------------------
70 void ActorWidget::setActor(QASActor
* a
) {
79 //------------------------------------------------------------------------------
81 void ActorWidget::onImageChanged() {
82 m_url
= m_actor
? m_actor
->imageUrl() : "";
86 //------------------------------------------------------------------------------
88 void ActorWidget::updatePixmap() {
89 FileDownloadManager
* fdm
= FileDownloadManager::getManager();
91 if (fdm
->hasFile(m_url
)) {
92 setIcon(QIcon(fdm
->pixmap(m_url
, ":/images/image_broken.png")));
95 if (m_url
.isEmpty()) {
96 setIcon(QIcon(":/images/default.png"));
98 setIcon(QIcon(":/images/image_downloading.png"));
99 FileDownloader
* fd
= fdm
->download(m_url
);
100 connect(fd
, SIGNAL(fileReady()), this, SLOT(updatePixmap()),
101 Qt::UniqueConnection
);
106 //------------------------------------------------------------------------------
108 void ActorWidget::createMenu() {
114 bool isYou
= m_actor
->isYou();
116 m_menuTitleAction
->setText(m_actor
->displayNameOrWebFinger());
118 m_menu
->addAction(m_menuTitleAction
);
119 m_menu
->addSeparator();
122 m_menu
->addAction(m_followAction
);
124 m_menu
->addAction(m_hideAuthorAction
);
131 //------------------------------------------------------------------------------
133 void ActorWidget::updateMenu() {
137 m_followAction
->setText(m_actor
->followed() ? tr("stop following") :
139 m_hideAuthorAction
->setText(m_actor
->isHidden() ?
140 tr("stop minimising posts") :
141 tr("auto-minimise posts"));
144 //------------------------------------------------------------------------------
146 void ActorWidget::onFollowAuthor() {
147 bool doFollow
= !m_actor
->followed();
149 QString msg
= QString(tr("Are you sure you want to stop following %1?")).
150 arg(m_actor
->displayNameOrWebFinger());
151 int ret
= QMessageBox::warning(this, CLIENT_FANCY_NAME
, msg
,
152 QMessageBox::Cancel
| QMessageBox::Yes
,
153 QMessageBox::Cancel
);
154 if (ret
!= QMessageBox::Yes
)
159 if (!m_actor
->isYou())
160 emit
follow(m_actor
->id(), doFollow
);
163 //------------------------------------------------------------------------------
165 void ActorWidget::onHideAuthor() {
166 bool doHide
= !m_actor
->isHidden();
167 m_actor
->setHidden(doHide
);
176 //------------------------------------------------------------------------------
178 void ActorWidget::onMenuTitle() {
179 if (m_actor
&& !m_actor
->url().isEmpty())
180 QDesktopServices::openUrl(m_actor
->url());