File indexing completed on 2019-07-28 10:35:09

0001 /*
0002 This file is part of Choqok, the KDE micro-blogging client
0003 
0004 Copyright (C) 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0005 
0006 This program is free software; you can redistribute it and/or
0007 modify it under the terms of the GNU General Public License as
0008 published by the Free Software Foundation; either version 2 of
0009 the License or (at your option) version 3 or any later version
0010 accepted by the membership of KDE e.V. (or its successor approved
0011 by the membership of KDE e.V.), which shall act as a proxy
0012 defined in Section 14 of version 3 of the license.
0013 
0014 This program is distributed in the hope that it will be useful,
0015 but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0017 GNU General Public License for more details.
0018 
0019 You should have received a copy of the GNU General Public License
0020 along with this program; if not, see http://www.gnu.org/licenses/
0021 */
0022 
0023 #ifndef MICROBLOGWIDGET_H
0024 #define MICROBLOGWIDGET_H
0025 
0026 #include <QMap>
0027 #include <QWidget>
0028 
0029 #include "choqoktabbar.h"
0030 #include "choqoktypes.h"
0031 #include "microblog.h"
0032 #include "choqok_export.h"
0033 
0034 class QLabel;
0035 
0036 namespace Choqok
0037 {
0038 class Account;
0039 
0040 namespace UI
0041 {
0042 class ComposerWidget;
0043 class TimelineWidget;
0044 
0045 /**
0046  * \brief MicroBlogWidget class.
0047  * Every MicroBlog plugin can use this or a drived class!
0048  *
0049  * @author Mehrdad Momeny \<mehrdad.momeny@gmail.com\>
0050  */
0051 class CHOQOK_EXPORT MicroBlogWidget : public QWidget
0052 {
0053     Q_OBJECT
0054 public:
0055     explicit MicroBlogWidget(Account *account, QWidget *parent = nullptr);
0056     virtual ~MicroBlogWidget();
0057     virtual void initUi();
0058     /**
0059     Set a @ref Choqok::ComposerWidget on read/write accounts!
0060     */
0061     Account *currentAccount() const;
0062 
0063     /**
0064     @return Current active timeline widget
0065     */
0066     TimelineWidget *currentTimeline();
0067 
0068     /**
0069      * @return the number of unread posts between all timelines.
0070      */
0071     uint unreadCount() const;
0072 
0073 public Q_SLOTS:
0074     void removeOldPosts();
0075     /**
0076     @brief Manage changed settings on this timeline and forward it to all posts.
0077     */
0078     virtual void settingsChanged();
0079 
0080     /**
0081     @brief Call markAllAsRead() on all timelines
0082     */
0083     virtual void markAllAsRead();
0084 
0085     /**
0086     Call for @ref MicroBlog::updateTimelines() to update timelines!
0087 
0088     @see newTimelineDataRecieved()
0089     */
0090     virtual void updateTimelines();
0091 
0092     /**
0093     Using to give focus to composer()->editot() on tab change
0094     */
0095     virtual void setFocus();
0096 
0097 Q_SIGNALS:
0098     /**
0099     @brief Emit to tell MainWindow to show this MicroBlog
0100     */
0101     void showMe();
0102     /**
0103     Emit to show a message on MainWindow::StatusBar
0104     */
0105 //     void showStatusMessage( const QString & message, bool isPermanent = false );
0106 
0107     /**
0108     @brief Emit to inform MicroBlogWidget about changes on count of unread posts
0109 
0110     @param change changes of unread Count, can be positive or negative.
0111     positive means addition, and negative means subtraction
0112     @param sum of unread count on this blog
0113     */
0114     void updateUnreadCount(int change, int sum);
0115 
0116     /**
0117     Emitted when all timelines are loaded fine!
0118     @note This will use for splash screen management!
0119     */
0120     void loaded();
0121 
0122 protected Q_SLOTS:
0123     /**
0124     Connected to @ref MicroBlog::timelineDataReceived() to update timelines
0125 
0126     @see updateTimelines()
0127     */
0128     virtual void newTimelineDataRecieved(Choqok::Account *theAccount, const QString &type,
0129                                          QList< Choqok::Post * > data);
0130     void slotUpdateUnreadCount(int change, TimelineWidget *widget = nullptr);
0131     void error(Choqok::Account *theAccount, Choqok::MicroBlog::ErrorType errorType,
0132                const QString &errorMsg, Choqok::MicroBlog::ErrorLevel level);
0133     void errorPost(Choqok::Account *theAccount, Choqok::Post *, Choqok::MicroBlog::ErrorType errorType,
0134                    const QString &errorMsg, Choqok::MicroBlog::ErrorLevel level);
0135     void slotAbortAllJobs();
0136 
0137     virtual void keyPressEvent(QKeyEvent *) override;
0138 
0139     void slotAccountModified(Choqok::Account *theAccount);
0140 protected:
0141     virtual QLayout *createToolbar();
0142     virtual TimelineWidget *addTimelineWidgetToUi(const QString &name);
0143     void initTimelines();
0144 
0145     void setComposerWidget(ComposerWidget *widget);
0146     ComposerWidget *composer();
0147     QMap<QString, TimelineWidget *> &timelines();
0148     Choqok::UI::ChoqokTabBar *timelinesTabWidget();
0149     QLabel *latestUpdate();
0150 
0151 private:
0152     class Private;
0153     Private *const d;
0154 };
0155 }
0156 }
0157 #endif // MICROBLOGWIDGET_H