summaryrefslogtreecommitdiffstats
path: root/src/include/stationlist.h
blob: 0c8a6ffe906eaa522c3edafd4b27c21555379d2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/***************************************************************************
                          stationlist.h  -  description
                             -------------------
    begin                : Sat March 29 2003
    copyright            : (C) 2003 by Klas Kalass
    email                : klas@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef STATIONLIST_H
#define STATIONLIST_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "stationlistmetadata.h"
#include "errorlog-interfaces.h"

#include <tqptrlist.h>
#include <kdemacros.h>

class RadioStation;
class KURL;

/*

   Why an own Station List ?

   RadioStations are used everywhere. But who is responsible for them?
   Especially after a list merge?

   A very simple solution should be a StationList with "deep copies". Though
   this is not very efficient, we can assume, that copy operations do not
   take place very often and thus are not critical.


   Why don't we use TQValueList then?

   We are using polymorphic radio stations, thus we cannot use a template
   using instances of a base class and copying them with a copy constructor.
   But as each derived class has its own copy() function, we are able to create
   exact copies from a pointer with the type of our base class "RadioStation".

*/


class KDE_EXPORT RawStationList : public TQPtrList<RadioStation>
{
public:

    typedef TQPtrListIterator<RadioStation>  Iterator;
    typedef TQPtrList<RadioStation>          BaseClass;

public:
    RawStationList ();
    RawStationList (const RawStationList &sl);
    ~RawStationList ();

    // overwrite all insert-methods in order to change
    // multiple insertion of same station_id into an update

    bool insert  (uint index, const RadioStation *item);
    bool insert  (const RadioStation *item);
    void inSort  (const RadioStation *item);
    void prepend (const RadioStation *item);
    void append  (const RadioStation *item);
    bool replace (uint index, const RadioStation *item);

    // simplify stationIDSearch

    const RadioStation &  stationWithID(const TQString &sid) const;
          RadioStation &  stationWithID(const TQString &sid);

    int                   idxWithID(const TQString &sid) const;

    bool                  operator == (const RawStationList &l) const;
    bool                  operator != (const RawStationList &l) const { return !operator==(l); }

protected:

    TQPtrCollection::Item newItem (TQPtrCollection::Item s);
    void                 deleteItem (TQPtrCollection::Item s);

    int compareItems (TQPtrCollection::Item a, TQPtrCollection::Item b);
};




/**
 * Contains a list of stations, including meta data
 * @author Klas Kalass, Ernst Martin Witte
 */

class KDE_EXPORT StationList  {
public:
    StationList();
    StationList(const StationList &sl);
    ~StationList();

    // some usefull "proxy" functions

    int                   count() const { return m_all.count(); }
    const RadioStation &  at(int idx) const;
          RadioStation &  at(int idx);

    const RadioStation &  stationWithID(const TQString &sid) const;
          RadioStation &  stationWithID(const TQString &sid);

    // all stations, with full access
    RawStationList &       all()       { return m_all; }
    RawStationList const & all() const { return m_all; }

    // the meta data for this station List, with full access
    StationListMetaData &       metaData()       { return m_metaData; }
    StationListMetaData const & metaData() const { return m_metaData; }

    // we do not need a special matchingStation/find/... method because
    // it is already implemented in RawStationList

    /**
     * merges  the other list into this one. creates copies from the stations.
     */
    void merge(const StationList &other);

    // assignment

    StationList &operator = (const StationList &sl);


    // xml in/out

    bool    readXML (const TQString &dat, const IErrorLogClient &logger, bool enableMessageBox = true);
    bool    readXML (const KURL &url,    const IErrorLogClient &logger, bool enableMessageBox = true);

    TQString writeXML (const IErrorLogClient &logger) const;
    bool    writeXML (const KURL &url, const IErrorLogClient &logger, bool enableMessageBox = true) const;


    bool operator == (const StationList &x) const { return m_all == x.m_all && m_metaData == x.m_metaData; }
    bool operator != (const StationList &x) const { return !operator ==(x); }

protected:
    RawStationList        m_all;
    StationListMetaData   m_metaData;
};


extern const StationList emptyStationList;

#endif