stationlistModel Class Reference

A model (for model-view-programming) handling radio streams. More...

#include <stationlistmodel.h>

List of all members.

Public Types

enum  columnInfoType {
  columnHeaderTitle, columnHeaderToolTip,
  columnHeaderWhatsThis, columnWidth,
  setColumnWidth, columnVisibility,
  setColumnVisibility, columnData,
  columnDataToolTip, columnDataWhatsThis
}

Public Slots

void addNewStation ()
void deleteStation (const int index)
void record (const int index)
void showConfigDialog (const int index)
void stopRecording (const int index)

Signals

void bandwidthChanged ()
void numberOfActiveStreamsChanged ()
void numberOfActiveStreamsIsZero ()

Public Member Functions

 stationlistModel (const QPointer< QObject > parent=0, const QPointer< QWidget > mainWidget=0)
virtual ~stationlistModel ()
quint64 bandwidth () const
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
QVariant columnInfo (const columnInfoType type, const int column, const qint64 row=(-1), const quint64 value=(-1)) const
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
virtual QVariant headerData (int section, Qt::Orientation orientation, int role) const
int numberOfActiveStreams () const
virtual bool queryClose ()
virtual void readProperties (const KConfigGroup &m_configGroup)
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
virtual void saveProperties (KConfigGroup &m_configGroup)
virtual void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)

Properties

quint64 bandwidth
int numberOfActiveStreams

Private Slots

void recalculate_numberOfActiveStreams_and_bandwidth ()
void reloadBitrate (const qlonglong stationIndex)
void reloadDataSize (const qlonglong stationIndex)
void reloadMetaInterval (const qlonglong stationIndex)
void reloadRelayPort (const qlonglong stationIndex)
void reloadServerName (const qlonglong stationIndex)
void reloadSong (const qlonglong stationIndex)
void reloadStatus (const qlonglong stationIndex)
void reloadStreamName (const qlonglong stationIndex)
void rememberListOfStreamsWhichTheUserWantsToRip_ifNotYetDone ()

Private Member Functions

void helper_connectSignalsAndSlots (QPointer< radioStation > m_stream)
void helper_writeStationListToGeneralSettings ()

Private Attributes

quint64 internal_bandwidth
int internal_numberOfActiveStreams
QStringList * m_listOfStreamsOfWhichTheUserWantsThatTheyRip
QPointer< QWidget > m_mainWidget
QList< QPointer< radioStation > > m_stationlist


Detailed Description

A model (for model-view-programming) handling radio streams.

This class handels radio stations. It reads the list of configuration files of radio stations from settings_general and represents these radio stations. Internally, it uses objects of the class radioStation to handle the stations. This class can also create new radio stations or delete existing ones - and takes care of creating/changing/removing the corresponding config files.

This class inherits from QAbstractTableModel (and this way indirectly from QAbstractItemModel). So it can be used as model for Qt's model-view-programming. Use a QTableView object to watch the data of this model.

Warning:
Use only one instance of this class at the same time! (Otherwise, the same stream could be recorded by more than one instance at the same time - and written by all instances to the same file! That's bad! Also this class uses the config files - and it is bad when more than one instance uses them...

Definition at line 46 of file stationlistmodel.h.


Member Enumeration Documentation

This enum is used in columnInfo() to determinate which action will be performed:

  • stationlistModel::columnHeaderTitle: Get the header title of the given column (QString).
  • stationlistModel::columnHeaderToolTip: Get the tooltip of the header of the given column (QString).
  • stationlistModel::columnHeaderWhatsThis: Get the "What's this"-help of the header of the given column (QString).
  • stationlistModel::columnWidth: Get the width of the given column from settings_general (quint64). A view for this model should take care of this value and read it and apply it in his constructor. In the config file the values aren't saved as a simple list of values (ordered by column number), but each column has an individual entry name for the width. This way it is guaranteed that, also when the model changes the order of columns, each column guards its width. Furthermore, no changes at the "view" widget are necessary as this system works without that the view widget knows about the order of the columns and of there content.
  • stationlistModel::setColumnWidth: Set the width of the given column in settings_general. A view for this model should write this value back in his contructor to guarantee that the last state of the UI is saved.
  • stationlistModel::columnVisibility: Get the visibility of the given column from settings_general (bool). A view for this model should take care of this value and read it and apply it in his constructor. Like stationlistmodel::columnWidth, it is saved individually for each column.
  • stationlistModel::setColumnVisibility: Set the visibility of the given column in settings_general. A view for this model should write this value back in his contructor to guarantee that the last state of the UI is saved.
  • stationlistModel::columnData: Get the data of the field specified by column and row (QString).
  • stationlistModel::columnDataToolTip: Get the tooltip of the field specified by column and row (QString).
  • stationlistModel::columnDataWhatsThis: Get the "What's this"-help of the field specified by column and row (QString).
Enumerator:
columnHeaderTitle 
columnHeaderToolTip 
columnHeaderWhatsThis 
columnWidth 
setColumnWidth 
columnVisibility 
setColumnVisibility 
columnData 
columnDataToolTip 
columnDataWhatsThis 

Definition at line 123 of file stationlistmodel.h.


Constructor & Destructor Documentation

stationlistModel::stationlistModel ( const QPointer< QObject >  parent = 0,
const QPointer< QWidget >  mainWidget = 0 
) [explicit]

The constructor.

Parameters:
parent the parent of this object
mainWidget the widget to which configuration dialogs will be centered.

Definition at line 31 of file stationlistmodel.cpp.

References helper_connectSignalsAndSlots(), helper_writeStationListToGeneralSettings(), m_listOfStreamsOfWhichTheUserWantsThatTheyRip, m_mainWidget, m_stationlist, and recalculate_numberOfActiveStreams_and_bandwidth().

Here is the call graph for this function:

stationlistModel::~stationlistModel (  )  [virtual]

The destructor.

Definition at line 59 of file stationlistmodel.cpp.

References m_listOfStreamsOfWhichTheUserWantsThatTheyRip.


Member Function Documentation

quint64 stationlistModel::bandwidth (  )  const

See property bandwidth.

int stationlistModel::columnCount ( const QModelIndex &  parent = QModelIndex()  )  const [virtual]

Reimplemented from QAbstractTableModel.

Parameters:
parent As this is a table model (non-hirarchical!), this parameter is ignored.
Returns:
the number of columns

Definition at line 97 of file stationlistmodel.cpp.

QVariant stationlistModel::columnInfo ( const columnInfoType  type,
const int  column,
const qint64  row = (-1),
const quint64  value = (-1) 
) const

This function is the central place to access all information about the data in the model and also about related things (column width, visibility, header title...).

Warning:
This function has the const qualifier, but this doesn't mean that nothing changes. You have not only read access, but also write access (to some values).
Parameters:
type Specifies the type of action that will be performed. See columnInfoType for details.
column The column to access.
row The row to access. Is ignored if the action is independent from the row.
value The value to write. Is ignored if the action is not a writing action.
Warning:
Notice that this function takes as argument the column before the row (which is an unusual order).
Returns:
The requested data as QVariant. If the passed arguments were invalid, than an invalid QVariant is returned.

Definition at line 102 of file stationlistmodel.cpp.

References columnData, columnDataToolTip, columnDataWhatsThis, columnHeaderTitle, columnHeaderToolTip, columnHeaderWhatsThis, columnVisibility, columnWidth, m_stationlist, OR, rowCount(), setColumnVisibility, and setColumnWidth.

Referenced by data(), and headerData().

Here is the call graph for this function:

Here is the caller graph for this function:

QVariant stationlistModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const [virtual]

Reimplemented from QAbstractTableModel.

Uses columnInfo() to deliver the data.

Parameters:
index As this is a table model (non-hirarchical!), only rows and columns of the index are relevant. The parent is ignored. If the index doesn't belong to this model, an invalid QVariant is returned.
role The type of information that is requested. Supported are
  • Qt::DisplayRole (the data itself)
  • Qt::ToolTipRole
  • Qt::WhatsThisRole.
For other values, an invalid QVariant is returned.
Returns:
the data of a the spezified item.

Definition at line 503 of file stationlistmodel.cpp.

References columnData, columnDataToolTip, columnDataWhatsThis, columnInfo(), and EQUAL.

Here is the call graph for this function:

QVariant stationlistModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const [virtual]

Reimplemented from QAbstractTableModel.

Uses columnInfo() if orientation is horizontal.

Definition at line 478 of file stationlistmodel.cpp.

References columnHeaderTitle, columnHeaderToolTip, columnHeaderWhatsThis, columnInfo(), and EQUAL.

Here is the call graph for this function:

int stationlistModel::numberOfActiveStreams (  )  const

See property numberOfActiveStreams.

Referenced by queryClose().

Here is the caller graph for this function:

bool stationlistModel::queryClose (  )  [virtual]

void stationlistModel::readProperties ( const KConfigGroup &  m_configGroup  )  [virtual]

TODO

Definition at line 712 of file stationlistmodel.cpp.

References m_stationlist, and rowCount().

Here is the call graph for this function:

int stationlistModel::rowCount ( const QModelIndex &  parent = QModelIndex()  )  const [virtual]

Reimplemented from QAbstractTableModel.

Parameters:
parent As this is a table model (non-hirarchical!), this parameter is ignored.
Returns:
the number of rows

Definition at line 92 of file stationlistmodel.cpp.

References m_stationlist.

Referenced by columnInfo(), readProperties(), and rememberListOfStreamsWhichTheUserWantsToRip_ifNotYetDone().

Here is the caller graph for this function:

void stationlistModel::saveProperties ( KConfigGroup &  m_configGroup  )  [virtual]

void stationlistModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
) [virtual]

Reimplemented from QAbstractTableModel.

This is just a dummy function. It (still) does nothing.

Definition at line 530 of file stationlistmodel.cpp.

void stationlistModel::bandwidthChanged (  )  [signal]

void stationlistModel::numberOfActiveStreamsChanged (  )  [signal]

void stationlistModel::numberOfActiveStreamsIsZero (  )  [signal]

void stationlistModel::addNewStation (  )  [slot]

This slot adds a new radio station: It displays a configuration dialog for the new stream. If accepted by the user (= clicking OK), the new stream is inserted at the end of the list.

Definition at line 535 of file stationlistmodel.cpp.

References helper_connectSignalsAndSlots(), helper_writeStationListToGeneralSettings(), m_mainWidget, and m_stationlist.

void stationlistModel::deleteStation ( const int  index  )  [slot]

Removes the specified radio station from this model and deletes the corresponding config file.

Parameters:
index You must pass the index (= the row) of the stream which you want to delete. When you pass an invalid index, nothing happens.

Definition at line 564 of file stationlistmodel.cpp.

References AND, helper_writeStationListToGeneralSettings(), and m_stationlist.

void stationlistModel::record ( const int  index  )  [slot]

This slot starts the recording of a stream.

Parameters:
index You must pass the index (= the row) of the stream which you want to record. When you pass an invalid index, nothing happens.

Definition at line 613 of file stationlistmodel.cpp.

References AND, and m_stationlist.

void stationlistModel::showConfigDialog ( const int  index  )  [slot]

If exactly one stream is selected, then this slot shows the config dialog. Else nothing happens.

Definition at line 629 of file stationlistmodel.cpp.

References AND, and m_stationlist.

void stationlistModel::stopRecording ( const int  index  )  [slot]

This slot stops the recording of a stream.

Parameters:
index You must pass the index (= the row) of the stream which you want to stop the recording. When you pass an invalid index, nothing happens.

Definition at line 621 of file stationlistmodel.cpp.

References AND, and m_stationlist.

void stationlistModel::helper_connectSignalsAndSlots ( QPointer< radioStation m_stream  )  [private]

This helper function sets up all the necessary connection of signals and slots which are needed to keep this model up to date.

Warning:
Call this function only once for each station.
Parameters:
m_stream a pointer to the station for which you want to set up the connection

Definition at line 64 of file stationlistmodel.cpp.

References recalculate_numberOfActiveStreams_and_bandwidth(), reloadBitrate(), reloadDataSize(), reloadMetaInterval(), reloadRelayPort(), reloadServerName(), reloadSong(), reloadStatus(), and reloadStreamName().

Referenced by addNewStation(), and stationlistModel().

Here is the caller graph for this function:

void stationlistModel::helper_writeStationListToGeneralSettings (  )  [inline, private]

Writes the actual list of streams back to the configuration file.

Definition at line 599 of file stationlistmodel.cpp.

References m_stationlist.

Referenced by addNewStation(), deleteStation(), and stationlistModel().

Here is the caller graph for this function:

void stationlistModel::recalculate_numberOfActiveStreams_and_bandwidth (  )  [private, slot]

This slot recalculates the values for the properties bandwidth and numberOfActiveStreams from scratch. It caches them in the corresponding member. If for one of the properties or for both of them, the new value differs from the old value, the corresponding signal(s) is/are emitted.

We recalculate the value each time from scratch. We could have implemented a solution the reacts on signals of the radiostation objects that the status has changed, and than increment or decrement our properties. This solution would be more efficient, but also more complicate: We would have to worry about a correct initialization, about session management.... The situation would be confusing and complicate. So it's better to have a clean solution, also when it's not so efficient.

Definition at line 404 of file stationlistmodel.cpp.

References bandwidthChanged(), ripping::idle, internal_bandwidth, internal_numberOfActiveStreams, m_stationlist, numberOfActiveStreamsChanged(), numberOfActiveStreamsIsZero(), and PropertyValue::value.

Referenced by helper_connectSignalsAndSlots(), and stationlistModel().

void stationlistModel::reloadBitrate ( const qlonglong  stationIndex  )  [private, slot]

Used internally to emit the signal dataChanged.

Definition at line 458 of file stationlistmodel.cpp.

Referenced by helper_connectSignalsAndSlots().

void stationlistModel::reloadDataSize ( const qlonglong  stationIndex  )  [private, slot]

Used internally to emit the signal dataChanged.

Definition at line 453 of file stationlistmodel.cpp.

Referenced by helper_connectSignalsAndSlots().

void stationlistModel::reloadMetaInterval ( const qlonglong  stationIndex  )  [private, slot]

Used internally to emit the signal dataChanged.

Definition at line 463 of file stationlistmodel.cpp.

Referenced by helper_connectSignalsAndSlots().

void stationlistModel::reloadRelayPort ( const qlonglong  stationIndex  )  [private, slot]

Used internally to emit the signal dataChanged.

Definition at line 473 of file stationlistmodel.cpp.

Referenced by helper_connectSignalsAndSlots().

void stationlistModel::reloadServerName ( const qlonglong  stationIndex  )  [private, slot]

Used internally to emit the signal dataChanged.

Definition at line 468 of file stationlistmodel.cpp.

Referenced by helper_connectSignalsAndSlots().

void stationlistModel::reloadSong ( const qlonglong  stationIndex  )  [private, slot]

Used internally to emit the signal dataChanged.

Definition at line 448 of file stationlistmodel.cpp.

Referenced by helper_connectSignalsAndSlots().

void stationlistModel::reloadStatus ( const qlonglong  stationIndex  )  [private, slot]

Used internally to emit the signal dataChanged.

Definition at line 443 of file stationlistmodel.cpp.

Referenced by helper_connectSignalsAndSlots().

void stationlistModel::reloadStreamName ( const qlonglong  stationIndex  )  [private, slot]

Used internally to emit the signal dataChanged.

Definition at line 438 of file stationlistmodel.cpp.

Referenced by helper_connectSignalsAndSlots().

void stationlistModel::rememberListOfStreamsWhichTheUserWantsToRip_ifNotYetDone (  )  [private, slot]


Member Data Documentation

Used internally to cache the value of the property bandwidth.

Definition at line 260 of file stationlistmodel.h.

Referenced by recalculate_numberOfActiveStreams_and_bandwidth().

Used internally to cache the value of the property numberOfActiveStreams.

Definition at line 262 of file stationlistmodel.h.

Referenced by recalculate_numberOfActiveStreams_and_bandwidth().

Here you can save a list of the streams for which radioStation::doesTheUserWantsThatTheStreamIsRipping() is true. Used for session management handling.

By initialization, this pointer is null.

Warning:
Keep this pointer always valid and set it back to null when deleting the QStringList. The destructor will delete a possibly remaining QStringlist, and this will lead to a crash when the pointer is invalid.

Definition at line 273 of file stationlistmodel.h.

Referenced by rememberListOfStreamsWhichTheUserWantsToRip_ifNotYetDone(), saveProperties(), stationlistModel(), and ~stationlistModel().

QPointer<QWidget> stationlistModel::m_mainWidget [private]

A pointer to the widget to which configuration dialogs should be centered. This member is initialized in the constructor.

Definition at line 276 of file stationlistmodel.h.

Referenced by addNewStation(), queryClose(), and stationlistModel().

QList< QPointer<radioStation> > stationlistModel::m_stationlist [private]


Property Documentation

quint64 stationlistModel::bandwidth [read]

This property holds the total bandwidth that is actually really used by the streams (summation of the bitrate of all streams which are not ripping::idle).

Warning:
The formated version contains the value in kbit/s (with SI prefix which means 1000 bit/s, not 1024 bit/s).
See also:

Definition at line 63 of file stationlistmodel.h.

int stationlistModel::numberOfActiveStreams [read]

This property holds the number of active streams (number of all streams which are not ripping::idle).

See also:

Definition at line 75 of file stationlistmodel.h.


The documentation for this class was generated from the following files:

Generated on Sat May 2 10:44:03 2009 for kradioripper by  doxygen 1.5.6