kradio4  r778
stationlist.h
Go to the documentation of this file.
1 /***************************************************************************
2  stationlist.h - description
3  -------------------
4  begin : Sat March 29 2003
5  copyright : (C) 2003 by Klas Kalass
6  email : klas@kde.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef STATIONLIST_H
19 #define STATIONLIST_H
20 
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 
25 #include "stationlistmetadata.h"
26 #include "errorlog_interfaces.h"
27 
28 #include <QtCore/QList>
29 
30 class RadioStation;
31 class KUrl;
32 
33 /*
34 
35  Why an own Station List ?
36 
37  RadioStations are used everywhere. But who is responsible for them?
38  Especially after a list merge?
39 
40  A very simple solution should be a StationList with "deep copies". Though
41  this is not very efficient, we can assume, that copy operations do not
42  take place very often and thus are not critical.
43 
44 
45  Why don't we use QValueList then?
46 
47  We are using polymorphic radio stations, thus we cannot use a template
48  using instances of a base class and copying them with a copy constructor.
49  But as each derived class has its own copy() function, we are able to create
50  exact copies from a pointer with the type of our base class "RadioStation".
51 
52 */
53 
54 //#warning "FIXME: abolish RawStationList. only use qlist<RadioStation*> as member of StationList"
55 // class RawStationList : protected QList<RadioStation*>
56 // {
57 // public:
58 //
59 // typedef QList<RadioStation*>::iterator Iterator;
60 // typedef QList<RadioStation*> BaseClass;
61 //
62 // public:
63 // RawStationList ();
64 // RawStationList (const RawStationList &sl);
65 // ~RawStationList ();
66 //
67 // // 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...
68 //
69 //
70 // size_t count() const { return QList<RadioStation*>::count(); }
71 //
72 // // // overwrite all insert-methods in order to change
73 // // // multiple insertion of same station_id into an update
74 // //
75 // // bool insert (uint index, const RadioStation *item);
76 // // bool insert (const RadioStation *item);
77 // // void inSort (const RadioStation *item);
78 // // void prepend (const RadioStation *item);
79 // // void append (const RadioStation *item);
80 // // bool replace (uint index, const RadioStation *item);
81 //
82 // // simplify stationIDSearch
83 //
84 // const RadioStation & stationWithID(const QString &sid) const;
85 // RadioStation & stationWithID(const QString &sid);
86 //
87 // int idxWithID(const QString &sid) const;
88 //
89 // bool operator == (const RawStationList &l) const;
90 // bool operator != (const RawStationList &l) const { return !operator==(l); }
91 //
92 // protected:
93 //
94 // /* value_type newItem (value_type s);
95 // void deleteItem (value_type s);
96 //
97 // int compareItems (value_type a, value_type b);*/
98 // };
99 
100 
101 
102 class QXmlInputSource;
103 
104 
110 class KDE_EXPORT StationList {
111 public:
112  StationList();
113  StationList(const StationList &sl);
114  ~StationList();
115 
116  // some usefull "proxy" functions
117 
118  int count() const { return m_stations.count(); }
119  const RadioStation & at(int idx) const;
120  RadioStation & at(int idx);
121 
122  void moveStation(int old_idx, int new_idx);
123 
124  const RadioStation & stationWithID(const QString &sid) const;
125  RadioStation & stationWithID(const QString &sid);
126  int idxWithID(const QString &sid) const;
127 
128  // all stations, with full access
129 // RawStationList & all() { return m_all; }
130 // RawStationList const & all() const { return m_all; }
131 
132  // the meta data for this station List, with full access
133  StationListMetaData & metaData() { return m_metaData; }
134  StationListMetaData const & metaData() const { return m_metaData; }
135 
136  // we do not need a special matchingStation/find/... method because
137  // it is already implemented in RawStationList
138 
142  void merge(const StationList &other);
143 
144 
145 
146 
147  // assignment
148 
149  StationList &operator = (const StationList &sl);
150  StationList &clearStations();
151  StationList &setStations(const StationList &x);
152  StationList &addStations(const StationList &x);
153  StationList &addStation (const RadioStation &x);
154  StationList &removeStationAt(int idx);
155 
156 
157  // xml in/out
158 
159  bool readXML (const QXmlInputSource &xmlInp, const IErrorLogClient &logger, bool enableMessageBox = true);
160  bool readXML (const KUrl &url, const IErrorLogClient &logger, bool enableMessageBox = true);
161 
162  QString writeXML (const IErrorLogClient &logger) const;
163  bool writeXML (const KUrl &url, const IErrorLogClient &logger, bool enableMessageBox = true) const;
164 
165 
166  bool operator == (const StationList &x) const;
167  bool operator != (const StationList &x) const { return !operator ==(x); }
168 
169 
170  // iteration stuff
171 
172  typedef QList<RadioStation*>::iterator iterator;
173  typedef QList<RadioStation*>::const_iterator const_iterator;
174 
175  iterator begin() { return m_stations.begin(); }
176  const_iterator begin() const { return m_stations.begin(); }
177 
178  iterator end() { return m_stations.end(); }
179  const_iterator end() const { return m_stations.end(); }
180 
181 protected:
182  QList<RadioStation*> m_stations;
184 };
185 
186 
187 extern const StationList emptyStationList;
188 
189 #endif
iterator begin()
Definition: stationlist.h:175
iterator end()
Definition: stationlist.h:178
Contains a list of stations, including meta data.
Definition: stationlist.h:110
QList< RadioStation * > m_stations
Definition: stationlist.h:182
int count() const
Definition: stationlist.h:118
QList< RadioStation * >::iterator iterator
Definition: stationlist.h:172
Meta Data about a stationlist.
const StationList emptyStationList
QList< RadioStation * >::const_iterator const_iterator
Definition: stationlist.h:173
const_iterator end() const
Definition: stationlist.h:179
StationListMetaData m_metaData
Definition: stationlist.h:183
StationListMetaData & metaData()
Definition: stationlist.h:133
StationListMetaData const & metaData() const
Definition: stationlist.h:134
const_iterator begin() const
Definition: stationlist.h:176