stationlist.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           stationlist.h  -  description
00003                              -------------------
00004     begin                : Sat March 29 2003
00005     copyright            : (C) 2003 by Klas Kalass
00006     email                : klas@kde.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef STATIONLIST_H
00019 #define STATIONLIST_H
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #include "stationlistmetadata.h"
00026 #include "errorlog_interfaces.h"
00027 
00028 #include <QtCore/QList>
00029 
00030 class RadioStation;
00031 class KUrl;
00032 
00033 /*
00034 
00035    Why an own Station List ?
00036 
00037    RadioStations are used everywhere. But who is responsible for them?
00038    Especially after a list merge?
00039 
00040    A very simple solution should be a StationList with "deep copies". Though
00041    this is not very efficient, we can assume, that copy operations do not
00042    take place very often and thus are not critical.
00043 
00044 
00045    Why don't we use QValueList then?
00046 
00047    We are using polymorphic radio stations, thus we cannot use a template
00048    using instances of a base class and copying them with a copy constructor.
00049    But as each derived class has its own copy() function, we are able to create
00050    exact copies from a pointer with the type of our base class "RadioStation".
00051 
00052 */
00053 
00054 //#warning "FIXME: abolish RawStationList. only use qlist<RadioStation*> as member of StationList"
00055 // class RawStationList : protected QList<RadioStation*>
00056 // {
00057 // public:
00058 // 
00059 //     typedef QList<RadioStation*>::iterator Iterator;
00060 //     typedef QList<RadioStation*>           BaseClass;
00061 // 
00062 // public:
00063 //     RawStationList ();
00064 //     RawStationList (const RawStationList &sl);
00065 //     ~RawStationList ();
00066 // 
00067 //     // inheritance is now protected. all manipulation functions must be declared here as public. Let's see which compiler errors occurr so that we can populate the access/manipulation functions...
00068 // 
00069 // 
00070 //     size_t count() const { return QList<RadioStation*>::count(); }
00071 // 
00072 // //     // overwrite all insert-methods in order to change
00073 // //     // multiple insertion of same station_id into an update
00074 // // 
00075 // //     bool insert  (uint index, const RadioStation *item);
00076 // //     bool insert  (const RadioStation *item);
00077 // //     void inSort  (const RadioStation *item);
00078 // //     void prepend (const RadioStation *item);
00079 // //     void append  (const RadioStation *item);
00080 // //     bool replace (uint index, const RadioStation *item);
00081 // 
00082 //     // simplify stationIDSearch
00083 // 
00084 //     const RadioStation &  stationWithID(const QString &sid) const;
00085 //           RadioStation &  stationWithID(const QString &sid);
00086 // 
00087 //     int                   idxWithID(const QString &sid) const;
00088 // 
00089 //     bool                  operator == (const RawStationList &l) const;
00090 //     bool                  operator != (const RawStationList &l) const { return !operator==(l); }
00091 // 
00092 // protected:
00093 // 
00094 // /*    value_type           newItem (value_type s);
00095 //     void                 deleteItem (value_type s);
00096 // 
00097 //     int compareItems (value_type a, value_type b);*/
00098 // };
00099 
00100 
00101 
00102 class QXmlInputSource;
00103 
00104 
00110 class KDE_EXPORT StationList  {
00111 public:
00112     StationList();
00113     StationList(const StationList &sl);
00114     ~StationList();
00115 
00116     // some usefull "proxy" functions
00117 
00118     int                   count() const { return m_stations.count(); }
00119     const RadioStation &  at(int idx) const;
00120           RadioStation &  at(int idx);
00121 
00122     void                  moveStation(int old_idx, int new_idx);
00123 
00124     const RadioStation &  stationWithID(const QString &sid) const;
00125           RadioStation &  stationWithID(const QString &sid);
00126     int                   idxWithID(const QString &sid) const;
00127 
00128     // all stations, with full access
00129 //     RawStationList &       all()       { return m_all; }
00130 //     RawStationList const & all() const { return m_all; }
00131 
00132     // the meta data for this station List, with full access
00133     StationListMetaData &       metaData()       { return m_metaData; }
00134     StationListMetaData const & metaData() const { return m_metaData; }
00135 
00136     // we do not need a special matchingStation/find/... method because
00137     // it is already implemented in RawStationList
00138 
00142     void merge(const StationList &other);
00143 
00144 
00145 
00146 
00147     // assignment
00148 
00149     StationList &operator = (const StationList &sl);
00150     StationList &clearStations();
00151     StationList &setStations(const StationList &x);
00152     StationList &addStations(const StationList &x);
00153     StationList &addStation (const RadioStation &x);
00154     StationList &removeStationAt(int idx);
00155 
00156 
00157     // xml in/out
00158 
00159     bool    readXML (const QXmlInputSource &xmlInp, const IErrorLogClient &logger, bool enableMessageBox = true);
00160     bool    readXML (const KUrl &url,    const IErrorLogClient &logger, bool enableMessageBox = true);
00161 
00162     QString writeXML (const IErrorLogClient &logger) const;
00163     bool    writeXML (const KUrl &url, const IErrorLogClient &logger, bool enableMessageBox = true) const;
00164 
00165 
00166     bool operator == (const StationList &x) const;
00167     bool operator != (const StationList &x) const { return !operator ==(x); }
00168 
00169 
00170     // iteration stuff
00171 
00172     typedef QList<RadioStation*>::iterator       iterator;
00173     typedef QList<RadioStation*>::const_iterator const_iterator;
00174 
00175     iterator       begin()       { return m_stations.begin(); }
00176     const_iterator begin() const { return m_stations.begin(); }
00177 
00178     iterator       end()         { return m_stations.end(); }
00179     const_iterator end()   const { return m_stations.end(); }
00180 
00181 protected:
00182     QList<RadioStation*>  m_stations;
00183     StationListMetaData   m_metaData;
00184 };
00185 
00186 
00187 extern const StationList emptyStationList;
00188 
00189 #endif

Generated on Tue Jun 2 19:19:57 2009 for kradio4 by  doxygen 1.5.8