File indexing completed on 2024-04-28 04:55:47

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2013-2014 Andrea Scarpino <scarpino@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #include "pumpioshowthread.h"
0010 
0011 #include <KLocalizedString>
0012 
0013 #include "pumpiodebug.h"
0014 #include "pumpiomicroblog.h"
0015 #include "pumpiopost.h"
0016 #include "pumpiopostwidget.h"
0017 
0018 class PumpIOShowThread::Private
0019 {
0020 public:
0021     Choqok::Account *account;
0022     QString postId;
0023 };
0024 
0025 PumpIOShowThread::PumpIOShowThread(Choqok::Account *account, Choqok::Post *post,
0026                                    QWidget *parent): QWidget(parent)
0027     , d(new Private)
0028 {
0029     d->account = account;
0030     d->postId = post->postId;
0031 
0032     setupUi(this);
0033 
0034     setWindowTitle(i18nc("Thread of specified user", "Choqok: %1's thread", post->author.userName));
0035 
0036     connect(account->microblog(), &Choqok::MicroBlog::postFetched, this,
0037             &PumpIOShowThread::slotAddPost);
0038 
0039     PumpIOPost *p = dynamic_cast<PumpIOPost *>(post);
0040     if (p) {
0041         PumpIOPostWidget *widget = new PumpIOPostWidget(account, p, this);
0042         widget->initUi();
0043         widget->setRead();
0044         mainLayout->insertWidget(0, widget);
0045         connect(widget, &PumpIOPostWidget::reply, this, &PumpIOShowThread::forwardReply);
0046 
0047         PumpIOMicroBlog *microblog = qobject_cast<PumpIOMicroBlog * >(account->microblog());
0048         if (microblog) {
0049             microblog->fetchReplies(account, p->replies);
0050         } else {
0051             qCDebug(CHOQOK) << "Microblog is not a PumpIOMicroBlog";
0052         }
0053     } else {
0054         qCDebug(CHOQOK) << "Post is not a PumpIOPost";
0055     }
0056 }
0057 
0058 PumpIOShowThread::~PumpIOShowThread()
0059 {
0060     delete d;
0061 }
0062 
0063 void PumpIOShowThread::slotAddPost(Choqok::Account *theAccount, Choqok::Post *post)
0064 {
0065     qCDebug(CHOQOK);
0066     if (theAccount == d->account && post->replyToPostId == d->postId) {
0067         PumpIOPostWidget *widget = new PumpIOPostWidget(theAccount, post, this);
0068         widget->initUi();
0069         widget->setRead();
0070         connect(widget, &PumpIOPostWidget::reply, this, &PumpIOShowThread::forwardReply);
0071         mainLayout->insertWidget(mainLayout->count() - 1, widget);
0072     }
0073 }
0074 
0075 #include "moc_pumpioshowthread.cpp"