File indexing completed on 2019-04-16 17:04:19

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 
0015 This program is distributed in the hope that it will be useful,
0016 but WITHOUT ANY WARRANTY; without even the implied warranty of
0017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0018 GNU General Public License for more details.
0019 
0020 You should have received a copy of the GNU General Public License
0021 along with this program; if not, see http://www.gnu.org/licenses/
0022 */
0023 #ifndef POSTWIDGET_H
0024 #define POSTWIDGET_H
0025 
0026 #include <QTimer>
0027 
0028 #include <KDateTime>
0029 #include <KIcon>
0030 
0031 #include "account.h"
0032 #include "choqoktypes.h"
0033 #include "microblog.h"
0034 
0035 class KAction;
0036 class KPushButton;
0037 
0038 namespace Choqok {
0039 namespace UI {
0040 
0041 class TextBrowser;
0042 
0043 /**
0044 Post Widget!
0045 Attribute "Qt::WA_DeleteOnClose" is enabled at construtor! So please use close() for deleting an object, instead of deleteLater() or delete
0046 
0047 @author Mehrdad Momeny \<mehrdad.momeny@gmail.com\>
0048 */
0049 class CHOQOK_EXPORT PostWidget : public QWidget
0050 {
0051     Q_OBJECT
0052     Q_PROPERTY (bool read READ isRead)
0053 public:
0054     explicit PostWidget( Choqok::Account* account, Choqok::Post* post, QWidget* parent = 0 );
0055     virtual ~PostWidget();
0056     Post *currentPost() const;
0057     virtual void setRead(bool read = true);
0058 
0059     /**
0060      Sets post widget as read, and emits postReaded() signal
0061      */
0062     void setReadWithSignal();
0063 
0064     virtual bool isRead() const;
0065 
0066     Account *currentAccount();
0067     /**
0068     Setup UI elements
0069     @Note Should call from outside of class, To initialize drived class items too!
0070     */
0071     virtual void initUi();
0072 
0073     /**
0074     Set stylesheet data with new color data! to use later.
0075 
0076     @see setUiStyle()
0077     */
0078     static void setStyle( const QColor& unreadColor, const QColor& unreadBack,
0079                           const QColor& readColor, const QColor& readBack,
0080                           const QColor& ownColor, const QColor& ownBack,
0081                           const QFont& font);
0082 
0083     /**
0084     @brief Set current post
0085 
0086     @note Use with care!
0087 
0088     After changing current post, Don't forget to call @ref initUi() to update post UI.
0089     */
0090     void setCurrentPost( Post *post );
0091 
0092     /**
0093     @brief Sets Post sign
0094     sign is the text that showed as sign of this post under post content.
0095     */
0096     void setSign( const QString &sign );
0097 
0098     /**
0099     @return post sign
0100     sign is an html text that showed as sign of this post under post content.
0101     */
0102     QString sign() const;
0103 
0104     /**
0105     @brief Sets post content
0106     Post content is an html text that showed as post text.
0107     */
0108     void setContent( const QString &content );
0109 
0110     /**
0111     @return post content
0112     Post content is an html text that showed as post text.
0113     */
0114     QString content() const;
0115 
0116     void deleteLater();
0117 
0118     TextBrowser * mainWidget();
0119 
0120     QStringList urls();
0121 
0122     TimelineWidget *timelineWidget() const;
0123 
0124     /**
0125      * Plugins can add status specific actions and process them internally
0126      * 
0127      */
0128     static void addAction( KAction *action );
0129 
0130     static QString getBaseStyle();
0131 
0132 public Q_SLOTS:
0133     /**
0134     Set Style sheet of widget to corresponding data->
0135     @see setStyle()
0136     */
0137     void setUiStyle();
0138 
0139 Q_SIGNALS:
0140     /**
0141     Emit and contain text to resend.
0142     */
0143     void resendPost(const QString &text);
0144     /**
0145     Emit when this post has been readed by pressing mouse on it, And to notify TimelineWidget about it.
0146     */
0147     void postReaded();
0148     /**
0149     Carry reply information, to reply to a post.
0150     */
0151     void reply(const QString &txt, const QString &replyToId, const QString &replyToUsername);
0152 
0153     /**
0154     Emitted when this widget is about to close!
0155     postId and this returned!
0156     */
0157     void aboutClosing( const QString &postId, PostWidget *widget);
0158 
0159 protected Q_SLOTS:
0160 
0161     virtual void checkAnchor(const QUrl & url);
0162     /**
0163     Set height of widget related to text contents
0164     */
0165     virtual void setHeight();
0166 
0167     /**
0168     Update UI after changes, such as timestamp
0169     */
0170     virtual void updateUi();
0171 
0172     /**
0173     Call microblog() to remove this post!
0174     */
0175     virtual void removeCurrentPost();
0176     /**
0177     Prepare text to send for resending this post.
0178     */
0179     virtual void slotResendPost();
0180     /**
0181     Internal slot to remove/close/destroy this post after bing deleted
0182     */
0183     void slotCurrentPostRemoved( Choqok::Account *theAccount, Choqok::Post *post );
0184 
0185     virtual void slotPostError( Choqok::Account *theAccount, Choqok::Post *post,
0186                                 Choqok::MicroBlog::ErrorType error, const QString &errorMessage);
0187 
0188     void avatarFetchError( const QString &remoteUrl, const QString &errMsg );
0189     void avatarFetched( const QString &remoteUrl, const QPixmap &pixmap );
0190 
0191     void slotImageFetched( const QString &remoteUrl, const QPixmap &pixmap );
0192     virtual void mousePressEvent(QMouseEvent* ev);
0193 
0194 protected:
0195     virtual void setupUi();
0196     virtual void closeEvent(QCloseEvent* event);
0197     virtual void setupAvatar();
0198     virtual void fetchImage();
0199     virtual void wheelEvent(QWheelEvent* );
0200     virtual void resizeEvent ( QResizeEvent * event );
0201     virtual void enterEvent ( QEvent * event );
0202     virtual void leaveEvent ( QEvent * event );
0203     virtual QString prepareStatus( const QString &text );
0204     virtual void setDirection();
0205     virtual QString generateSign();
0206     virtual QString formatDateTime( const QDateTime &time );
0207     virtual QString formatDateTime( const KDateTime &time );
0208     virtual bool isResendAvailable() ;
0209     virtual bool isRemoveAvailable() ;
0210     virtual bool isOwnPost();
0211     virtual QString removeTags(const QString& text) const;
0212     /**
0213     @brief Create and Add a new button to widget
0214     This function will add button to UI!
0215     @return added button, for some managements such as connect to a slot
0216     */
0217     KPushButton * addButton(const QString & objName, const QString & toolTip, const QString & icon);
0218     KPushButton * addButton(const QString & objName, const QString & toolTip, const KIcon & icon);
0219     QMap<QString, KPushButton*> &buttons();
0220 
0221 protected:
0222     TextBrowser *_mainWidget;
0223     const QString *baseText;
0224     static const QString baseStyle;
0225     static QString readStyle;
0226     static QString unreadStyle;
0227     static QString ownStyle;
0228     static const QString webIconText;
0229     static const QString ownText;
0230     static const QString hrefTemplate;
0231     static const QString otherText;
0232     static const QRegExp dirRegExp;
0233 
0234     void setAvatarText( const QString &text );
0235     QString avatarText() const;
0236     virtual QString generateResendText();
0237 
0238 private:
0239     class Private;
0240     Private *const d;
0241 };
0242 
0243 class CHOQOK_EXPORT PostWidgetUserData : public QObjectUserData
0244 {
0245 public:
0246     PostWidgetUserData( PostWidget *postWidget );
0247     virtual ~PostWidgetUserData();
0248     PostWidget *postWidget();
0249     void setPostWidget(PostWidget *widget);
0250 
0251 
0252 
0253 private:
0254     class Private;
0255     Private * const d;
0256 };
0257 
0258 }
0259 }
0260 #endif // POSTWIDGET_H