File indexing completed on 2025-01-05 04:25:46

0001 /****************************************************************************************
0002  * Copyright (c) 2009-2010 Ludovic Deveaux <deveaux.ludovic31@gmail.com>                *
0003  * Copyright (c) 2010 Hormiere Guillaume <hormiere.guillaume@gmail.com>                 *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef UPCOMING_EVENTS_WIDGET_H
0019 #define UPCOMING_EVENTS_WIDGET_H
0020 
0021 #include "NetworkAccessManagerProxy.h"
0022 #include "LastFmEvent.h"
0023 
0024 #include <QUrl>
0025 #include <Plasma/ScrollWidget>
0026 
0027 #include <QGraphicsWidget>
0028 
0029 class KDateTime;
0030 class QLabel;
0031 class QGraphicsLinearLayout;
0032 class QGraphicsProxyWidget;
0033 class QSignalMapper;
0034 namespace Plasma {
0035     class Label;
0036     class PushButton;
0037 }
0038 
0039 class UpcomingEventsWidget : public QGraphicsWidget
0040 {
0041     Q_OBJECT
0042 
0043     public:
0044         /**
0045          * UpcomingEventsWidget constructor
0046          * @param event the pointer to event
0047          * @param parent like QGraphicsWidget constructor
0048          * @param wFlags the Qt::WindowFlags
0049          */
0050         explicit UpcomingEventsWidget( const LastFmEventPtr &event,
0051                               QGraphicsItem *parent = nullptr,
0052                               Qt::WindowFlags wFlags = 0 );
0053         ~UpcomingEventsWidget();
0054 
0055         /**
0056          * The upcoming event associated with this widget
0057          */
0058         LastFmEventPtr eventPtr() const
0059         { return m_event; }
0060 
0061         /**
0062          * Set the event's image in Plasma::Label from an url
0063          * @param url image's url to be displayed
0064          */
0065         void setImage( const QUrl &url );
0066 
0067         /**
0068          * Set attendance for this event
0069          * @param count number of attendees
0070          */
0071         void setAttendance( int count );
0072 
0073         /**
0074          *Set the event's participants text in Plasma::Label from a QString
0075          *@param participants participants text to be displayed
0076          */
0077         void setParticipants( const QStringList &participants );
0078 
0079         /**
0080          *Set the event's date in Plasma::Label from a KDateTime
0081          *@param date date to be displayed
0082          */
0083         void setDate( const KDateTime &date );
0084 
0085         /**
0086          *Set the event's name in Plasma::Label from a QString
0087          *@param name name's text to be displayed
0088          */
0089         void setName( const QString &name );
0090 
0091         /**
0092          *Set the event's location in a Plasma::Label from a QString
0093          *@param location location's text to be displayed
0094          */
0095         void setLocation( const LastFmLocationPtr &location );
0096 
0097         /**
0098          * Set event venue
0099          * @param venue Last.fm's venue
0100          */
0101         void setVenue( const LastFmVenuePtr &venue );
0102 
0103         /**
0104          *Set the event's url in Plasma::Label from a QUrl
0105          *@param url url to be displayed
0106          */
0107         void setUrl( const QUrl &url );
0108 
0109         /**
0110          * Set the events tags
0111          * @param tags list of tags
0112          */
0113         void setTags( const QStringList &tags );
0114 
0115     protected:
0116         Plasma::PushButton *m_mapButton;
0117 
0118     private:
0119         Plasma::PushButton *m_urlButton;
0120         QGraphicsProxyWidget *m_attendance;
0121         QGraphicsProxyWidget *m_date;
0122         QGraphicsProxyWidget *m_location;
0123         QGraphicsProxyWidget *m_name;
0124         QGraphicsProxyWidget *m_participants;
0125         QGraphicsProxyWidget *m_tags;
0126         QGraphicsProxyWidget *m_venue;
0127         QLabel *m_image;
0128         QUrl m_imageUrl;
0129         const LastFmEventPtr m_event;
0130 
0131         QGraphicsProxyWidget *createLabel( const QString &text = QString(),
0132                                            QSizePolicy::Policy hPolicy = QSizePolicy::Expanding );
0133 
0134         friend class UpcomingEventsListWidget;
0135 
0136     private Q_SLOTS:
0137         void loadImage();
0138         void openUrl();
0139 };
0140 
0141 class UpcomingEventsListWidget : public Plasma::ScrollWidget
0142 {
0143     Q_OBJECT
0144     Q_PROPERTY( QString name READ name WRITE setName )
0145     Q_PROPERTY( LastFmEvent::List events READ events )
0146 
0147 public:
0148     explicit UpcomingEventsListWidget( QGraphicsWidget *parent = nullptr );
0149     ~UpcomingEventsListWidget();
0150 
0151     int count() const;
0152     bool isEmpty() const;
0153 
0154     void addEvent( const LastFmEventPtr &event );
0155     void addEvents( const LastFmEvent::List &events );
0156 
0157     LastFmEvent::List events() const;
0158     QString name() const;
0159     void setName( const QString &name );
0160 
0161     void clear();
0162 
0163 Q_SIGNALS:
0164     void mapRequested( QObject *widget );
0165     void eventAdded( const LastFmEventPtr &event );
0166     void eventRemoved( const LastFmEventPtr &event );
0167 
0168 private:
0169     QString m_name;
0170     LastFmEvent::List m_events;
0171     QMap<uint, UpcomingEventsWidget*> m_sortMap;
0172     QGraphicsLinearLayout *m_layout;
0173     QSignalMapper *m_sigmap;
0174     Q_DISABLE_COPY( UpcomingEventsListWidget )
0175 };
0176 
0177 #endif /* UPCOMINGEVENTSWIDGET_H */