00001 /*************************************************************************** 00002 radiostation.h - description 00003 ------------------- 00004 begin : Sat Feb 2 2002 00005 copyright : (C) 2003 by Martin Witte, Klas Kalass 00006 email : witte@kawo1.rwth-aachen.de / 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 KRADIO_RADIOSTATION_H 00019 #define KRADIO_RADIOSTATION_H 00020 00021 #ifdef HAVE_CONFIG_H 00022 #include <config.h> 00023 #endif 00024 00025 //#include "utils.h" 00026 #include <qstring.h> 00027 #include <qstringlist.h> 00028 #include <qdict.h> 00029 00030 #include <klocale.h> 00031 00036 /* 00037 00038 RadioStation 00039 00040 RadioStation is an abstract base class for any type of radio station, 00041 e.g. AM/FM stations or internet radio stations. Thus no specific knowledge 00042 about the frequency or URL is included in this class. A radio station 00043 should not contain information on a matching device as well. The device has 00044 to decide on its own to use or not to use a station. 00045 00046 There are some important abstract functions, that have to be overwritten by 00047 a derived radio station: 00048 00049 copy create an exact copy of a station (in case we only have a RadioStation* 00050 longName return a verbous station description 00051 isValid is this station setup correctly ? 00052 compare is this station equivalent to another station, e.g. approximately same frequency 00053 getclassname classname string for station registry 00054 00055 Other methods "should" be overwritten, but still call inherited methods for completeness! 00056 00057 get/setProperty 00058 getPropertyNames 00059 00060 */ 00061 00063 00064 extern struct RegisterStationClass {} registerStationClass; 00065 00067 00068 class RadioStationConfig; 00069 00070 class RadioStation 00071 { 00072 protected: 00073 RadioStation (RegisterStationClass, const QString &classname); 00074 public: 00075 RadioStation (); 00076 RadioStation (const QString &name, const QString &shortName); 00077 RadioStation (const RadioStation &); 00078 virtual ~RadioStation(); 00079 00080 const QString &stationID() const { return m_stationID; } 00081 00082 virtual QString longName() const = 0; 00083 virtual QString description() const = 0; 00084 00085 const QString &name() const { return m_name; } 00086 const QString &shortName() const { return m_shortName; } 00087 const QString &iconName() const { return m_iconName; } 00088 float initialVolume() const { return m_initialVolume; } 00089 00090 void setName (const QString &name) { m_name = name; } 00091 void setShortName (const QString &shortName) { m_shortName = shortName; } 00092 void setIconName (const QString &iconName) { m_iconName = iconName; } 00093 void setInitialVolume(float initialVolume) { m_initialVolume = initialVolume; } 00094 00095 void copyDescriptionFrom(const RadioStation &rs); 00096 00097 // for XML-Parsing/Export 00098 virtual bool setProperty(const QString &property_name, const QString &val); 00099 virtual QString getProperty(const QString &property_name) const; 00100 virtual QStringList getPropertyNames() const; 00101 virtual QString getClassName() const = 0; 00102 00103 // get empty derived stations by classname from registry 00104 static RadioStation const *getStationClass(const QString &classname); 00105 RadioStation const *getStationClass() const { return getStationClass(getClassName()); } 00106 00107 // = 0 : "this" is same as "s", e.g. approximately same frequency, same url, ... 00108 // > 0 : "this" is numerically (frequencies) or alphanumerically (urls) or ... greater than "s" 00109 // < 0 : "this" is numerically (frequencies) or alphanumerically (urls) or ... smaller than "s" 00110 virtual int compare(const RadioStation &s) const = 0; 00111 00112 // is this station setup correctly ? 00113 virtual bool isValid() const = 0; 00114 00116 virtual RadioStation *copy() const = 0; 00118 virtual RadioStation *copyNewID() const = 0; 00119 00120 void generateNewStationID(); 00121 00122 virtual RadioStationConfig *createEditor() const = 0; 00123 00124 virtual bool operator == (const RadioStation &x) const; 00125 virtual bool operator != (const RadioStation &x) const { return !operator==(x); } 00126 00127 protected : 00128 QString m_stationID; 00129 00130 QString m_name; 00131 QString m_shortName; 00132 float m_initialVolume; // <0: => Don't use 00133 QString m_iconName; 00134 00135 private: 00136 static QDict<RadioStation> *stationClassRegistry; 00137 }; 00138 00139 00140 00141 00142 00143 00144 00145 class UndefinedRadioStation : public RadioStation 00146 { 00147 public: 00148 UndefinedRadioStation (RegisterStationClass) : RadioStation (registerStationClass, getClassName()) {} 00149 00150 virtual QString longName() const { return i18n("unknown"); } 00151 virtual QString description() const { return i18n("unknown"); } 00152 virtual bool isValid() const { return false; } 00153 virtual RadioStation *copy() const { return new UndefinedRadioStation(*this); } 00154 virtual RadioStation *copyNewID() const { RadioStation *x = new UndefinedRadioStation(*this); x->generateNewStationID(); return x; } 00155 virtual int compare(const RadioStation &s) const; 00156 00157 virtual QString getClassName() const { return "UndefinedRadioStation"; } 00158 virtual RadioStationConfig *createEditor() const; 00159 }; 00160 00161 00162 extern const UndefinedRadioStation undefinedRadioStation; 00163 00164 #endif