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

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #ifndef TIMELINEWIDGET_H
0010 #define TIMELINEWIDGET_H
0011 
0012 #include <QIcon>
0013 #include <QMap>
0014 #include <QWidget>
0015 
0016 #include "choqoktypes.h"
0017 #include "choqok_export.h"
0018 
0019 class QLabel;
0020 class QHBoxLayout;
0021 class QVBoxLayout;
0022 
0023 namespace Choqok
0024 {
0025 class Account;
0026 
0027 namespace UI
0028 {
0029 
0030 class PostWidget;
0031 /**
0032 @brief Choqok base Timeline Widget
0033 
0034 @author Mehrdad Momeny \<mehrdad.momeny@gmail.com\>
0035 */
0036 class CHOQOK_EXPORT TimelineWidget : public QWidget
0037 {
0038     Q_OBJECT
0039 public:
0040     TimelineWidget(Account *account, const QString &timelineName, QWidget *parent = nullptr);
0041     virtual ~TimelineWidget();
0042     void setTimelineName(const QString &type);
0043 
0044     /**
0045     @brief Return Timeline name
0046     Related to whatever sets previouslly by @ref setTimelineName()
0047     */
0048     QString timelineName();
0049 
0050     /**
0051     @brief Return Timeline name for UI
0052     */
0053     QString timelineInfoName();
0054 
0055     /**
0056     @brief Return Timeline icon name
0057     */
0058     QString timelineIconName();
0059 
0060     /**
0061     @brief Return Timeline icon
0062     If timelineIconName() is empty this can be useful
0063      */
0064     QIcon &timelineIcon() const;
0065     void setTimelineIcon(const QIcon &icon);
0066 
0067     /**
0068      @brief Add new posts to UI.
0069     */
0070     virtual void addNewPosts(QList< Choqok::Post * > &postList);
0071 
0072     /**
0073      @brief Adds a message in place of an empty timeline. Placeholder is removed when a post gets added.
0074     */
0075     virtual void addPlaceholderMessage(const QString &message);
0076 
0077     /**
0078     @brief Return count of unread posts on this timeline.
0079     */
0080     int unreadCount() const;
0081 
0082     /**
0083     @brief remove old posts, about to user selected count of posts on timelines
0084     */
0085     void removeOldPosts();
0086 
0087     /**
0088     @return list of all widgets available on this timeline
0089     */
0090     QList<PostWidget *> postWidgets();
0091 
0092     /**
0093      * @return true if this timeline is closable!
0094      */
0095     bool isClosable() const;
0096 
0097     void setClosable(bool isClosable = true);
0098 
0099 public Q_SLOTS:
0100     /**
0101     @brief Mark all posts as read
0102     */
0103     virtual void markAllAsRead();
0104     /**
0105     @brief Manage changed settings on this timeline and forward it to all posts.
0106     */
0107     virtual void settingsChanged();
0108     /**
0109     @brief Scroll to the bottom of the timeline
0110     */
0111     virtual void scrollToBottom();
0112 
0113 Q_SIGNALS:
0114     void forwardResendPost(const QString &post);
0115     void forwardReply(const QString &txt, const QString &replyToId, const QString &replyToUsername);
0116     /**
0117     @brief Emit to inform MicroBlogWidget about changes on count of unread posts
0118 
0119     @param change changes of unread Count, can be positive or negative.
0120         positive means addition, and negative means subtraction
0121     */
0122     void updateUnreadCount(int change);
0123 
0124 protected Q_SLOTS:
0125     void slotOnePostReaded();
0126     virtual void saveTimeline();
0127     virtual void loadTimeline();
0128     void postWidgetClosed(const QString &postId, PostWidget *widget);
0129 
0130 protected:
0131     /**
0132     Add a PostWidget to UI
0133     @Note This will call @ref PostWidget::initUi()
0134     */
0135     virtual void addPostWidgetToUi(PostWidget *widget);
0136     Account *currentAccount();
0137     QMap<QString, PostWidget *> &posts() const;
0138     QMultiMap<QDateTime, PostWidget *> &sortedPostsList() const;
0139 
0140     QVBoxLayout *mainLayout();
0141     QHBoxLayout *titleBarLayout();
0142     QLabel *timelineDescription();
0143     virtual void setUnreadCount(int unread);
0144     virtual void showMarkAllAsReadButton();
0145 
0146 private:
0147     void setupUi();
0148     class Private;
0149     Private *const d;
0150 };
0151 }
0152 }
0153 #endif // TIMELINEWIDGET_H