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 <qptrlist.h> 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 00055 class RawStationList : public QPtrList<RadioStation> 00056 { 00057 public: 00058 00059 typedef QPtrListIterator<RadioStation> Iterator; 00060 typedef QPtrList<RadioStation> BaseClass; 00061 00062 public: 00063 RawStationList (); 00064 RawStationList (const RawStationList &sl); 00065 ~RawStationList (); 00066 00067 // overwrite all insert-methods in order to change 00068 // multiple insertion of same station_id into an update 00069 00070 bool insert (uint index, const RadioStation *item); 00071 bool insert (const RadioStation *item); 00072 void inSort (const RadioStation *item); 00073 void prepend (const RadioStation *item); 00074 void append (const RadioStation *item); 00075 bool replace (uint index, const RadioStation *item); 00076 00077 // simplify stationIDSearch 00078 00079 const RadioStation & stationWithID(const QString &sid) const; 00080 RadioStation & stationWithID(const QString &sid); 00081 00082 int idxWithID(const QString &sid) const; 00083 00084 bool operator == (const RawStationList &l) const; 00085 bool operator != (const RawStationList &l) const { return !operator==(l); } 00086 00087 protected: 00088 00089 QPtrCollection::Item newItem (QPtrCollection::Item s); 00090 void deleteItem (QPtrCollection::Item s); 00091 00092 int compareItems (QPtrCollection::Item a, QPtrCollection::Item b); 00093 }; 00094 00095 00096 00097 00103 class StationList { 00104 public: 00105 StationList(); 00106 StationList(const StationList &sl); 00107 ~StationList(); 00108 00109 // some usefull "proxy" functions 00110 00111 int count() const { return m_all.count(); } 00112 const RadioStation & at(int idx) const; 00113 RadioStation & at(int idx); 00114 00115 const RadioStation & stationWithID(const QString &sid) const; 00116 RadioStation & stationWithID(const QString &sid); 00117 00118 // all stations, with full access 00119 RawStationList & all() { return m_all; } 00120 RawStationList const & all() const { return m_all; } 00121 00122 // the meta data for this station List, with full access 00123 StationListMetaData & metaData() { return m_metaData; } 00124 StationListMetaData const & metaData() const { return m_metaData; } 00125 00126 // we do not need a special matchingStation/find/... method because 00127 // it is already implemented in RawStationList 00128 00132 void merge(const StationList &other); 00133 00134 // assignment 00135 00136 StationList &operator = (const StationList &sl); 00137 00138 00139 // xml in/out 00140 00141 bool readXML (const QString &dat, const IErrorLogClient &logger, bool enableMessageBox = true); 00142 bool readXML (const KURL &url, const IErrorLogClient &logger, bool enableMessageBox = true); 00143 00144 QString writeXML (const IErrorLogClient &logger) const; 00145 bool writeXML (const KURL &url, const IErrorLogClient &logger, bool enableMessageBox = true) const; 00146 00147 00148 bool operator == (const StationList &x) const { return m_all == x.m_all && m_metaData == x.m_metaData; } 00149 bool operator != (const StationList &x) const { return !operator ==(x); } 00150 00151 protected: 00152 RawStationList m_all; 00153 StationListMetaData m_metaData; 00154 }; 00155 00156 00157 extern const StationList emptyStationList; 00158 00159 #endif