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

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 MICROBLOGWIDGET_H
0010 #define MICROBLOGWIDGET_H
0011 
0012 #include <QMap>
0013 #include <QWidget>
0014 
0015 #include "choqoktabbar.h"
0016 #include "choqoktypes.h"
0017 #include "microblog.h"
0018 #include "choqok_export.h"
0019 
0020 class QLabel;
0021 
0022 namespace Choqok
0023 {
0024 class Account;
0025 
0026 namespace UI
0027 {
0028 class ComposerWidget;
0029 class TimelineWidget;
0030 
0031 /**
0032  * \brief MicroBlogWidget class.
0033  * Every MicroBlog plugin can use this or a drived class!
0034  *
0035  * @author Mehrdad Momeny \<mehrdad.momeny@gmail.com\>
0036  */
0037 class CHOQOK_EXPORT MicroBlogWidget : public QWidget
0038 {
0039     Q_OBJECT
0040 public:
0041     explicit MicroBlogWidget(Account *account, QWidget *parent = nullptr);
0042     virtual ~MicroBlogWidget();
0043     virtual void initUi();
0044     /**
0045     Set a @ref Choqok::ComposerWidget on read/write accounts!
0046     */
0047     Account *currentAccount() const;
0048 
0049     /**
0050     @return Current active timeline widget
0051     */
0052     TimelineWidget *currentTimeline();
0053 
0054     /**
0055      * @return the number of unread posts between all timelines.
0056      */
0057     uint unreadCount() const;
0058 
0059 public Q_SLOTS:
0060     void removeOldPosts();
0061     /**
0062     @brief Manage changed settings on this timeline and forward it to all posts.
0063     */
0064     virtual void settingsChanged();
0065 
0066     /**
0067     @brief Call markAllAsRead() on all timelines
0068     */
0069     virtual void markAllAsRead();
0070 
0071     /**
0072     Call for @ref MicroBlog::updateTimelines() to update timelines!
0073 
0074     @see newTimelineDataRecieved()
0075     */
0076     virtual void updateTimelines();
0077 
0078     /**
0079     Using to give focus to composer()->editot() on tab change
0080     */
0081     virtual void setFocus();
0082 
0083 Q_SIGNALS:
0084     /**
0085     @brief Emit to tell MainWindow to show this MicroBlog
0086     */
0087     void showMe();
0088     /**
0089     Emit to show a message on MainWindow::StatusBar
0090     */
0091 //     void showStatusMessage( const QString & message, bool isPermanent = false );
0092 
0093     /**
0094     @brief Emit to inform MicroBlogWidget about changes on count of unread posts
0095 
0096     @param change changes of unread Count, can be positive or negative.
0097     positive means addition, and negative means subtraction
0098     @param sum of unread count on this blog
0099     */
0100     void updateUnreadCount(int change, int sum);
0101 
0102     /**
0103     Emitted when all timelines are loaded fine!
0104     @note This will use for splash screen management!
0105     */
0106     void loaded();
0107 
0108 protected Q_SLOTS:
0109     /**
0110     Connected to @ref MicroBlog::timelineDataReceived() to update timelines
0111 
0112     @see updateTimelines()
0113     */
0114     virtual void newTimelineDataRecieved(Choqok::Account *theAccount, const QString &type,
0115                                          QList< Choqok::Post * > data);
0116     void slotUpdateUnreadCount(int change, TimelineWidget *widget = nullptr);
0117     void error(Choqok::Account *theAccount, Choqok::MicroBlog::ErrorType errorType,
0118                const QString &errorMsg, Choqok::MicroBlog::ErrorLevel level);
0119     void errorPost(Choqok::Account *theAccount, Choqok::Post *, Choqok::MicroBlog::ErrorType errorType,
0120                    const QString &errorMsg, Choqok::MicroBlog::ErrorLevel level);
0121     void slotAbortAllJobs();
0122 
0123     virtual void keyPressEvent(QKeyEvent *) override;
0124 
0125     void slotAccountModified(Choqok::Account *theAccount);
0126 protected:
0127     virtual QLayout *createToolbar();
0128     virtual TimelineWidget *addTimelineWidgetToUi(const QString &name);
0129     void initTimelines();
0130 
0131     void setComposerWidget(ComposerWidget *widget);
0132     ComposerWidget *composer();
0133     QMap<QString, TimelineWidget *> &timelines();
0134     Choqok::UI::ChoqokTabBar *timelinesTabWidget();
0135     QLabel *latestUpdate();
0136 
0137 private:
0138     class Private;
0139     Private *const d;
0140 };
0141 }
0142 }
0143 #endif // MICROBLOGWIDGET_H