summaryrefslogtreecommitdiffstats
path: root/tderadio3/src/include/radiostation.h
blob: 68d03258854fcdba98ea6199471e7f7db802634e (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
161
162
163
164
/***************************************************************************
                          radiostation.h  -  description
                             -------------------
    begin                : Sat Feb 2 2002
    copyright            : (C) 2003 by Martin Witte, Klas Kalass
    email                : [email protected] / [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 KRADIO_RADIOSTATION_H
#define KRADIO_RADIOSTATION_H

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

//#include "utils.h"
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqdict.h>

#include <tdelocale.h>

/**
  *@author Martin Witte, Klas Kalass
  */

/*

   RadioStation

   RadioStation is an abstract base class for any type of radio station,
   e.g. AM/FM stations or internet radio stations. Thus no specific knowledge
   about the frequency or URL is included in this class. A radio station
   should not contain information on a matching device as well. The device has
   to decide on its own to use or not to use a station.

   There are some important abstract functions, that have to be overwritten by
   a derived radio station:

      copy         create an exact copy of a station (in case we only have a RadioStation*
      longName     return a verbous station description
      isValid      is this station setup correctly ?
      compare      is this station equivalent to another station, e.g. approximately same frequency
      getclassname classname string for station registry

   Other methods "should" be overwritten, but still call inherited methods for completeness!

      get/setProperty
      getPropertyNames

*/

/////////////////////////////////////////////////////////////////////////////

extern struct RegisterStationClass {} registerStationClass;

/////////////////////////////////////////////////////////////////////////////

class RadioStationConfig;

class RadioStation
{
protected:
    RadioStation (RegisterStationClass, const TQString &classname);
public:
    RadioStation ();
    RadioStation (const TQString &name, const TQString &shortName);
    RadioStation (const RadioStation &);
    virtual ~RadioStation();

    const TQString  &stationID() const { return m_stationID; }

    virtual TQString    longName()    const = 0;
    virtual TQString    description() const = 0;

    const TQString  &name()           const { return m_name;          }
    const TQString  &shortName()      const { return m_shortName;     }
    const TQString  &iconName()       const { return m_iconName;      }
    float           initialVolume()  const { return m_initialVolume; }

    void  setName         (const TQString &name)       { m_name          = name;          }
    void  setShortName    (const TQString &shortName)  { m_shortName     = shortName;     }
    void  setIconName     (const TQString &iconName)   { m_iconName      = iconName;      }
    void  setInitialVolume(float initialVolume)       { m_initialVolume = initialVolume; }

    void  copyDescriptionFrom(const RadioStation &rs);

    // for XML-Parsing/Export
    virtual bool        setProperty(const TQString &property_name, const TQString &val);
    virtual TQString     getProperty(const TQString &property_name) const;
    virtual TQStringList getPropertyNames() const;
    virtual TQString     getClassName() const = 0;

    // get empty derived stations by classname from registry
    static RadioStation const *getStationClass(const TQString &classname);
           RadioStation const *getStationClass() const { return getStationClass(getClassName()); }

    // = 0 : "this" is same as "s", e.g. approximately same frequency, same url, ...
    // > 0 : "this" is numerically (frequencies) or alphanumerically (urls) or ... greater than "s"
    // < 0 : "this" is numerically (frequencies) or alphanumerically (urls) or ... smaller than "s"
    virtual int compare(const RadioStation &s) const = 0;

    // is this station setup correctly ?
    virtual bool isValid() const = 0;

    /** returns an exact copy of this station */
    virtual RadioStation *copy() const = 0;
    /** returns an exact copy of this station, BUT with a new station ID */
    virtual RadioStation *copyNewID() const = 0;

    void generateNewStationID();

    virtual RadioStationConfig *createEditor() const = 0;

    virtual bool operator == (const RadioStation &x) const;
    virtual bool operator != (const RadioStation &x) const { return !operator==(x); }

protected :
    TQString  m_stationID;

    TQString  m_name;
    TQString  m_shortName;
    float    m_initialVolume;        // <0: => Don't use
    TQString  m_iconName;

private:
    static TQDict<RadioStation>  *stationClassRegistry;
};







class UndefinedRadioStation : public RadioStation
{
public:
    UndefinedRadioStation (RegisterStationClass) : RadioStation (registerStationClass, getClassName()) {}

    virtual TQString       longName()    const { return i18n("unknown"); }
    virtual TQString       description() const { return i18n("unknown"); }
    virtual bool          isValid()     const { return false; }
    virtual RadioStation *copy()        const { return new UndefinedRadioStation(*this); }
    virtual RadioStation *copyNewID()   const { RadioStation *x = new UndefinedRadioStation(*this); x->generateNewStationID(); return x;  }
    virtual int           compare(const RadioStation &s) const;

    virtual TQString       getClassName() const { return "UndefinedRadioStation"; }
    virtual RadioStationConfig *createEditor() const;
};


extern const UndefinedRadioStation undefinedRadioStation;

#endif