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

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Nathan Sala <sala.nathan@gmail.com>                               *
0003  * Copyright (c) 2009-2010 Ludovic Deveaux <deveaux.ludovic31@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 LASTFMEVENT_H
0019 #define LASTFMEVENT_H
0020 
0021 #include <KDateTime>
0022 #include <KSharedPtr>
0023 #include <QUrl>
0024 
0025 #include <QSharedData>
0026 #include <QStringList>
0027 #include <QHash>
0028 
0029 class LastFmEvent;
0030 class LastFmLocation;
0031 class LastFmVenue;
0032 
0033 typedef KSharedPtr<LastFmEvent> LastFmEventPtr;
0034 typedef KSharedPtr<LastFmVenue> LastFmVenuePtr;
0035 typedef KSharedPtr<LastFmLocation> LastFmLocationPtr;
0036 
0037 /**
0038  * A class to store an event fetched from the last.fm API
0039  * by the request artist.getEvents
0040  */
0041 class LastFmEvent : public QSharedData
0042 {
0043 public:
0044     enum ImageSize
0045     {
0046         Small      = 0,
0047         Medium     = 1,
0048         Large      = 2,
0049         ExtraLarge = 3,
0050         Mega       = 4
0051     };
0052 
0053     typedef QList< LastFmEventPtr > List;
0054     typedef QHash<ImageSize, QUrl> ImageUrls;
0055 
0056     /**
0057      * Creates an empty LastFmEvent
0058      */
0059     LastFmEvent();
0060 
0061     /**
0062      * Creates a copy of a LastFmEvent
0063      * @param event the event to be copied from
0064      */
0065     LastFmEvent( const LastFmEvent& );
0066 
0067     /**
0068      * Destroys a LastFmEvent instance
0069      */
0070     ~LastFmEvent();
0071 
0072     /**
0073      * A getter for the artists list.
0074      * It consists of the headliner + participants.
0075      * @return the list of all artists participating the event
0076      */
0077     QStringList artists() const;
0078 
0079     /**
0080      * The number of people attending the event
0081      * @return number of people attending the event
0082      */
0083     int attendance() const
0084     { return m_attendance; }
0085 
0086     /**
0087      * A getter for the event's date
0088      * @return the event's date
0089      */
0090     KDateTime date() const;
0091 
0092     /**
0093      * The event's description
0094      * @return event's description
0095      */
0096     QString description() const
0097     { return m_description; }
0098 
0099     /**
0100      * The event's headlining artist
0101      * @return event's headlining artist
0102      */
0103     QString headliner() const
0104     { return m_headliner; }
0105 
0106     /**
0107      * Gets the URL for the event's event at \p size;
0108      * @param size size of the image
0109      * @return image URL
0110      */
0111     QUrl imageUrl( ImageSize size ) const
0112     { return m_imageUrls.value(size); }
0113 
0114     /**
0115      * Whether the event is cancelled
0116      * @return true if the event is cancelled
0117      */
0118     bool isCancelled() const
0119     { return m_cancelled; }
0120 
0121     /**
0122      * A getter for the event's name
0123      * @return the event's name
0124      */
0125     QString name() const;
0126 
0127     /**
0128      * The list of participating artists (excluding the headliner)
0129      * @return list of participating artists (excluding the headliner)
0130      */
0131     QStringList participants() const
0132     { return m_participants; }
0133 
0134     /**
0135      * The List of Last.fm tags
0136      * @return list of Last.fm tags
0137      */
0138     QStringList tags() const
0139     { return m_tags; }
0140 
0141     /**
0142      * A getter for the event's page
0143      * @return the URL to the event's page
0144      */
0145     QUrl url() const;
0146 
0147     /**
0148      * Get the venue associated with this event
0149      * @return the venue
0150      */
0151     LastFmVenuePtr venue() const
0152     { return m_venue; }
0153 
0154     /**
0155      * Set the number of attendance
0156      * @param number the number of attendance
0157      */
0158     void setAttendance( int number )
0159     { m_attendance = number; }
0160 
0161     /**
0162      * Set whether the event has been cancelled
0163      * @param isCancelled whether the event has been cancelled
0164      */
0165     void setCancelled( bool isCancelled )
0166     { m_cancelled = isCancelled; }
0167 
0168     /**
0169      * Sets the event's date
0170      * @param date the event's date
0171      */
0172     void setDate( const KDateTime &date );
0173 
0174     /**
0175      * Sets the event's description
0176      * @param text the event's description
0177      */
0178     void setDescription( const QString &text )
0179     { m_description = text; }
0180 
0181     /**
0182      * Sets the headlining artist for this event
0183      * @param headliner the headlining artist for this event
0184      */
0185     void setHeadliner( const QString &headliner )
0186     { m_headliner = headliner; }
0187 
0188     /**
0189      * Sets the \p url for the event's image at \p size
0190      * @param size size of the image
0191      * @param url url of the image
0192      */
0193     void setImageUrl( ImageSize size, const QUrl &url )
0194     { m_imageUrls[size] = url; }
0195 
0196     /**
0197      * Sets the event's name
0198      * @param name the event's name
0199      */
0200     void setName( const QString &name );
0201 
0202     /**
0203      * Sets the participating artists (excluding headliner) at this event
0204      * @param participants artists participating at this event
0205      */
0206     void setParticipants( const QStringList &participants )
0207     { m_participants = participants; }
0208 
0209     /**
0210      * Sets the tags for this event
0211      * @param tags the tags for this event
0212      */
0213     void setTags( const QStringList &tags )
0214     { m_tags = tags; }
0215 
0216     /**
0217      * Sets the event's page
0218      * @param url the URL to the event's page
0219      */
0220     void setUrl( const QUrl &url );
0221 
0222     /**
0223      * Sets the venue of this event
0224      * @param venue the venue of this event
0225      */
0226     void setVenue( LastFmVenuePtr venue ) { m_venue = venue; }
0227 
0228     /**
0229      * Convert an ImageSize to a QString
0230      */
0231     static QString imageSizeToString( ImageSize size );
0232 
0233     /**
0234      * Convert a QString to an ImageSize
0235      */
0236     static ImageSize stringToImageSize( const QString &string );
0237 
0238 private:
0239     int m_attendance;            //!< Number of the event's attendance
0240     bool m_cancelled;            //!< Whether the event has been cancelled
0241     KDateTime m_date;            //!< The event's start date
0242     QUrl m_url;                  //!< The URL to the event's page
0243     ImageUrls m_imageUrls;       //!< URLs to the event's image
0244     QString m_description;       //!< Description of the event
0245     QString m_name;              //!< The event's name
0246     QString m_headliner;         //!< The headline artist of this event
0247     QStringList m_participants;  //!< Other artists participating in the event
0248     QStringList m_tags;          //!< Contextual tags
0249     LastFmVenuePtr m_venue;      //!< Venue info
0250 };
0251 
0252 class LastFmLocation : public QSharedData
0253 {
0254 public:
0255     LastFmLocation();
0256     ~LastFmLocation();
0257     LastFmLocation( const LastFmLocation &cpy );
0258 
0259     QString city;
0260     QString country;
0261     QString street;
0262     QString postalCode;
0263     double latitude;
0264     double longitude;
0265 };
0266 
0267 class LastFmVenue : public QSharedData
0268 {
0269 public:
0270     LastFmVenue();
0271     ~LastFmVenue();
0272     LastFmVenue( const LastFmVenue &cpy );
0273 
0274     int id;
0275     QString name;
0276     QUrl url;
0277     QUrl website;
0278     QString phoneNumber;
0279     QHash<LastFmEvent::ImageSize, QUrl> imageUrls;
0280     LastFmLocationPtr location;
0281 };
0282 
0283 Q_DECLARE_METATYPE(LastFmEvent)
0284 Q_DECLARE_METATYPE(LastFmEventPtr)
0285 Q_DECLARE_METATYPE(LastFmEvent::List)
0286 Q_DECLARE_METATYPE(LastFmLocation)
0287 Q_DECLARE_METATYPE(LastFmLocationPtr)
0288 Q_DECLARE_METATYPE(LastFmVenue)
0289 Q_DECLARE_METATYPE(LastFmVenuePtr)
0290 
0291 #endif // LASTFMEVENT_H