#include <stationlistmodel.h>
Public Types | |
enum | columnInfoType { columnHeaderTitle, columnHeaderToolTip, columnHeaderWhatsThis, columnWidth, setColumnWidth, columnVisibility, setColumnVisibility, columnData } |
Public Slots | |
void | enableListeningIn () |
void | disableListeningIn () |
void | paste () |
void | pasteSelection () |
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 (stationlistWidget *parent, QWidget *mainWidget=0) | |
virtual | ~stationlistModel () |
QModelIndex | addNewStation () |
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), QList< radioStation * > listOfStations=QList< radioStation * >()) const |
virtual QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const |
virtual bool | dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) |
virtual Qt::ItemFlags | flags (const QModelIndex &index) const |
virtual QVariant | headerData (int section, Qt::Orientation orientation, int role) const |
virtual QStringList | mimeTypes () const |
int | numberOfActiveStreams () const |
virtual bool | queryClose () |
virtual void | readProperties (const KConfigGroup &m_configGroup) |
virtual bool | removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) |
virtual int | rowCount (const QModelIndex &parent=QModelIndex()) const |
virtual void | saveProperties (KConfigGroup &m_configGroup) |
virtual void | sort (int column, Qt::SortOrder order=Qt::AscendingOrder) |
Protected Attributes | |
QPointer< stationlistWidget > | view |
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 | reloadMetaInterval_milliSeconds (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 | reloadUri (const qlonglong stationIndex) |
void | rememberListOfStreamsWhichTheUserWantsToRip_ifNotYetDone () |
Private Member Functions | |
void | helper_connectSignalsAndSlots (radioStation *m_stream) |
QList< QUrl > | helper_convertToUrl (const QMimeData *data) |
bool | helper_firstIsAfterSecond (const PropertyValue &firstValue, const PropertyValue &secondValue, Qt::SortOrder order) |
bool | helper_isNumericValue (const QVariant &value) |
qlonglong | helper_toLongLong (const PropertyValue &value) |
void | helper_writeStationListToGeneralSettings () |
Private Attributes | |
quint64 | internal_bandwidth |
int | internal_numberOfActiveStreams |
listenSupport | listen |
QStringList * | m_listOfStreamsOfWhichTheUserWantsThatTheyRip |
QPointer< QWidget > | m_mainWidget |
QList< radioStation * > | m_stationlist |
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.
You can use only one view to show the content of this model!
Definition at line 54 of file stationlistmodel.h.
This enum is used in columnInfo() to determinate which action will be performed:
columnHeaderTitle | |
columnHeaderToolTip | |
columnHeaderWhatsThis | |
columnWidth | |
setColumnWidth | |
columnVisibility | |
setColumnVisibility | |
columnData |
Definition at line 128 of file stationlistmodel.h.
stationlistModel::stationlistModel | ( | stationlistWidget * | parent, | |
QWidget * | mainWidget = 0 | |||
) | [explicit] |
The constructor.
parent | The parent of this object. This is important for the necessary interaction between model and view (for example: selection handling). | |
mainWidget | The widget to which configuration dialogs will be centered. |
Definition at line 37 of file stationlistmodel.cpp.
References helper_connectSignalsAndSlots(), helper_writeStationListToGeneralSettings(), m_listOfStreamsOfWhichTheUserWantsThatTheyRip, m_mainWidget, m_stationlist, recalculate_numberOfActiveStreams_and_bandwidth(), and view.
stationlistModel::~stationlistModel | ( | ) | [virtual] |
The destructor.
Definition at line 67 of file stationlistmodel.cpp.
References m_listOfStreamsOfWhichTheUserWantsThatTheyRip.
QModelIndex stationlistModel::addNewStation | ( | ) |
This function 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.
QModelIndex()
(if canceled by the user). Definition at line 785 of file stationlistmodel.cpp.
References helper_connectSignalsAndSlots(), helper_writeStationListToGeneralSettings(), m_mainWidget, and m_stationlist.
quint64 stationlistModel::bandwidth | ( | ) | const |
See property bandwidth.
void stationlistModel::bandwidthChanged | ( | ) | [signal] |
See property bandwidth.
Referenced by recalculate_numberOfActiveStreams_and_bandwidth().
int stationlistModel::columnCount | ( | const QModelIndex & | parent = QModelIndex() |
) | const [virtual] |
Reimplemented from QAbstractTableModel.
parent | As this is a table model (non-hirarchical!), this parameter is ignored. |
Definition at line 113 of file stationlistmodel.cpp.
Referenced by dropMimeData(), and sort().
QVariant stationlistModel::columnInfo | ( | const columnInfoType | type, | |
const int | column, | |||
const qint64 | row = (-1) , |
|||
const quint64 | value = (-1) , |
|||
QList< radioStation * > | listOfStations = QList<radioStation *>() | |||
) | 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...).
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. | |
listOfStations | The list of stations from which this function gets the data of the fields. If the list is empty (which is the default value), than m_stationlist is used instead. |
Definition at line 122 of file stationlistmodel.cpp.
References columnData, columnHeaderTitle, columnHeaderToolTip, columnHeaderWhatsThis, columnVisibility, columnWidth, PropertyValue::error, PropertyValue::formatedValue, PropertyValue::internalValue, m_stationlist, OR, setColumnVisibility, setColumnWidth, PropertyValue::toolTip, PropertyValue::type, PropertyValue::unset, PropertyValue::value, and PropertyValue::whatsThis.
Referenced by data(), headerData(), and sort().
QVariant stationlistModel::data | ( | const QModelIndex & | index, | |
int | role = Qt::DisplayRole | |||
) | const [virtual] |
Reimplemented from QAbstractTableModel.
Uses columnInfo() to deliver the data.
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
|
Definition at line 589 of file stationlistmodel.cpp.
References AND, columnData, columnInfo(), and EQUAL.
void stationlistModel::disableListeningIn | ( | ) | [slot] |
Disables listening in.
Definition at line 1097 of file stationlistmodel.cpp.
References listen, and listenSupport::setStation().
bool stationlistModel::dropMimeData | ( | const QMimeData * | data, | |
Qt::DropAction | action, | |||
int | row, | |||
int | column, | |||
const QModelIndex & | parent | |||
) | [virtual] |
Reimplemented function that provides support for dropping URL lists via "drag and drop.
Definition at line 1029 of file stationlistmodel.cpp.
References columnCount(), helper_connectSignalsAndSlots(), helper_convertToUrl(), helper_writeStationListToGeneralSettings(), m_mainWidget, m_stationlist, and view.
Referenced by paste(), and pasteSelection().
void stationlistModel::enableListeningIn | ( | ) | [slot] |
Enables the listening in to the actually selected stream.
Definition at line 1087 of file stationlistmodel.cpp.
References listen, m_stationlist, listenSupport::setStation(), and view.
Qt::ItemFlags stationlistModel::flags | ( | const QModelIndex & | index | ) | const [virtual] |
Reimplemented function that says that dropping streams via "drag and drop" is accepted at each place in the view widget.
Definition at line 1075 of file stationlistmodel.cpp.
QVariant stationlistModel::headerData | ( | int | section, | |
Qt::Orientation | orientation, | |||
int | role | |||
) | const [virtual] |
Reimplemented from QAbstractTableModel.
Uses columnInfo() if orientation is horizontal.
Definition at line 564 of file stationlistmodel.cpp.
References columnHeaderTitle, columnHeaderToolTip, columnHeaderWhatsThis, columnInfo(), and EQUAL.
void stationlistModel::helper_connectSignalsAndSlots | ( | 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.
m_stream | a pointer to the station for which you want to set up the connection |
Definition at line 72 of file stationlistmodel.cpp.
References recalculate_numberOfActiveStreams_and_bandwidth(), reloadBitrate(), reloadDataSize(), reloadMetaInterval(), reloadMetaInterval_milliSeconds(), reloadRelayPort(), reloadServerName(), reloadSong(), reloadStatus(), reloadStreamName(), and reloadUri().
Referenced by addNewStation(), dropMimeData(), and stationlistModel().
QList< QUrl > stationlistModel::helper_convertToUrl | ( | const QMimeData * | data | ) | [private] |
Extracts a list of URLs from mime data.
Definition at line 985 of file stationlistmodel.cpp.
Referenced by dropMimeData().
bool stationlistModel::helper_firstIsAfterSecond | ( | const PropertyValue & | firstValue, | |
const PropertyValue & | secondValue, | |||
Qt::SortOrder | order | |||
) | [private] |
This function compares 2 values for sorting. It uses the following sort order:
If both values have the same order, it returns always true.
Definition at line 723 of file stationlistmodel.cpp.
References PropertyValue::error, PropertyValue::formatedValue, helper_isNumericValue(), helper_toLongLong(), PropertyValue::internalValue, PropertyValue::type, PropertyValue::unset, and PropertyValue::value.
Referenced by sort().
bool stationlistModel::helper_isNumericValue | ( | const QVariant & | value | ) | [private] |
Definition at line 690 of file stationlistmodel.cpp.
Referenced by helper_firstIsAfterSecond().
qlonglong stationlistModel::helper_toLongLong | ( | const PropertyValue & | value | ) | [private] |
Converts a PropertyValue.internalValue to a qlonglong is possible (integer values or ripping::statusType).
Definition at line 713 of file stationlistmodel.cpp.
References PropertyValue::internalValue.
Referenced by helper_firstIsAfterSecond().
void stationlistModel::helper_writeStationListToGeneralSettings | ( | ) | [inline, private] |
Writes the actual list of streams back to the configuration file.
Definition at line 857 of file stationlistmodel.cpp.
References m_stationlist.
Referenced by addNewStation(), dropMimeData(), removeRows(), and stationlistModel().
QStringList stationlistModel::mimeTypes | ( | ) | const [virtual] |
Reimplemented from Qt. Provides a list of the mime types that are accepted for dropping streams via "drag and drop".
Definition at line 1080 of file stationlistmodel.cpp.
int stationlistModel::numberOfActiveStreams | ( | ) | const |
See property numberOfActiveStreams.
Referenced by queryClose().
void stationlistModel::numberOfActiveStreamsChanged | ( | ) | [signal] |
See property numberOfActiveStreams.
Referenced by recalculate_numberOfActiveStreams_and_bandwidth().
void stationlistModel::numberOfActiveStreamsIsZero | ( | ) | [signal] |
See property numberOfActiveStreams.
Referenced by queryClose(), and recalculate_numberOfActiveStreams_and_bandwidth().
void stationlistModel::paste | ( | ) | [slot] |
Pastes the content of the clipboard (using dropMimeData()).
Definition at line 1011 of file stationlistmodel.cpp.
References dropMimeData().
void stationlistModel::pasteSelection | ( | ) | [slot] |
Pastes the content of the mouse selection (using dropMimeData()).
Definition at line 1020 of file stationlistmodel.cpp.
References dropMimeData().
bool stationlistModel::queryClose | ( | ) | [virtual] |
# Remembers a list of running streams (which is necessary if we do session management) # Shuts them down. As this can take a while, a "busy" dialog is displayed.
Definition at line 922 of file stationlistmodel.cpp.
References m_mainWidget, m_stationlist, numberOfActiveStreams(), numberOfActiveStreamsIsZero(), and rememberListOfStreamsWhichTheUserWantsToRip_ifNotYetDone().
void stationlistModel::readProperties | ( | const KConfigGroup & | m_configGroup | ) | [virtual] |
Reads properties for restoring the previous session (using session management).
m_configGroup | The location where to read the properties from |
Definition at line 970 of file stationlistmodel.cpp.
References m_stationlist, and rowCount().
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 480 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::record | ( | const int | index | ) | [slot] |
This slot starts the recording of a stream.
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 871 of file stationlistmodel.cpp.
References AND, and m_stationlist.
void stationlistModel::reloadBitrate | ( | const qlonglong | stationIndex | ) | [private, slot] |
Used internally to emit the signal dataChanged
.
Definition at line 539 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 534 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 544 of file stationlistmodel.cpp.
Referenced by helper_connectSignalsAndSlots().
void stationlistModel::reloadMetaInterval_milliSeconds | ( | const qlonglong | stationIndex | ) | [private, slot] |
Used internally to emit the signal dataChanged
.
Definition at line 549 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 559 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 554 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 529 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 524 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 514 of file stationlistmodel.cpp.
Referenced by helper_connectSignalsAndSlots().
void stationlistModel::reloadUri | ( | const qlonglong | stationIndex | ) | [private, slot] |
Used internally to emit the signal dataChanged
.
Definition at line 519 of file stationlistmodel.cpp.
Referenced by helper_connectSignalsAndSlots().
void stationlistModel::rememberListOfStreamsWhichTheUserWantsToRip_ifNotYetDone | ( | ) | [private, slot] |
If the application is closed using session management, it is undefined, if saveProperties() or queryClose() is executed first. Because queryClose() shuts the streams down, if saveProperties() is executed later it would not be able to know which streams were running.
To solve this problem, queryClose() and saveProperties() call this function (in the case of queryClose() of course before shutting down streams). This function writes a list of running streams to the member m_listOfStreamsOfWhichTheUserWantsThatTheyRip - but only if there is not yet a list. This way, saveProperties() can call this function and be sure to have now a correct list of running streams at m_listOfStreamsOfWhichTheUserWantsThatTheyRip, indepentently from the execution order of saveProperties() and readProperties().
Definition at line 905 of file stationlistmodel.cpp.
References m_listOfStreamsOfWhichTheUserWantsThatTheyRip, m_stationlist, and rowCount().
Referenced by queryClose(), and saveProperties().
bool stationlistModel::removeRows | ( | int | row, | |
int | count, | |||
const QModelIndex & | parent = QModelIndex() | |||
) | [virtual] |
Reimplemented from QAbstractItemModel.
Removes count radio stations starting with the given row (radio station) from this model and deletes the corresponding config files.
row | You must pass the index (= the row) of the first stream which you want to delete. When you pass an invalid index, nothing happens. | |
count | number of streams that will be deleted. | |
parent | is ignored. |
Definition at line 817 of file stationlistmodel.cpp.
References helper_writeStationListToGeneralSettings(), and m_stationlist.
int stationlistModel::rowCount | ( | const QModelIndex & | parent = QModelIndex() |
) | const [virtual] |
Reimplemented from QAbstractTableModel.
parent | As this is a table model (non-hirarchical!), this parameter is ignored. |
Definition at line 104 of file stationlistmodel.cpp.
References m_stationlist.
Referenced by readProperties(), and rememberListOfStreamsWhichTheUserWantsToRip_ifNotYetDone().
void stationlistModel::saveProperties | ( | KConfigGroup & | m_configGroup | ) | [virtual] |
Saves properties for restoring this session later (using session management).
m_configGroup | The location where to save the properties |
Definition at line 962 of file stationlistmodel.cpp.
References m_listOfStreamsOfWhichTheUserWantsThatTheyRip, and rememberListOfStreamsWhichTheUserWantsToRip_ifNotYetDone().
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 887 of file stationlistmodel.cpp.
References AND, and m_stationlist.
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 623 of file stationlistmodel.cpp.
References columnCount(), columnData, columnInfo(), helper_firstIsAfterSecond(), m_stationlist, and view.
void stationlistModel::stopRecording | ( | const int | index | ) | [slot] |
This slot stops the recording of a stream.
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 879 of file stationlistmodel.cpp.
References AND, and m_stationlist.
quint64 stationlistModel::internal_bandwidth [private] |
Used internally to cache the value of the property bandwidth.
Definition at line 345 of file stationlistmodel.h.
Referenced by recalculate_numberOfActiveStreams_and_bandwidth().
int stationlistModel::internal_numberOfActiveStreams [private] |
Used internally to cache the value of the property numberOfActiveStreams.
Definition at line 347 of file stationlistmodel.h.
Referenced by recalculate_numberOfActiveStreams_and_bandwidth().
listenSupport stationlistModel::listen [private] |
With this object, we can listen in streams.
Definition at line 349 of file stationlistmodel.h.
Referenced by disableListeningIn(), and enableListeningIn().
QStringList* stationlistModel::m_listOfStreamsOfWhichTheUserWantsThatTheyRip [private] |
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.
Definition at line 361 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 364 of file stationlistmodel.h.
Referenced by addNewStation(), dropMimeData(), queryClose(), and stationlistModel().
QList<radioStation *> stationlistModel::m_stationlist [private] |
This is a QList of objects of the radiostation class used internally to handle the stations.
Definition at line 367 of file stationlistmodel.h.
Referenced by addNewStation(), columnInfo(), dropMimeData(), enableListeningIn(), helper_writeStationListToGeneralSettings(), queryClose(), readProperties(), recalculate_numberOfActiveStreams_and_bandwidth(), record(), rememberListOfStreamsWhichTheUserWantsToRip_ifNotYetDone(), removeRows(), rowCount(), showConfigDialog(), sort(), stationlistModel(), and stopRecording().
QPointer<stationlistWidget> stationlistModel::view [protected] |
A pointer to the view that shows this model.
Definition at line 308 of file stationlistmodel.h.
Referenced by dropMimeData(), enableListeningIn(), sort(), and stationlistModel().
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).
quint64 bandwidth() const
void bandwidthChanged()
quint64 internal_bandwidth
Definition at line 71 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).
int numberOfActiveStreams() const
void numberOfActiveStreamsChanged()
void numberOfActiveIsZero()
Definition at line 83 of file stationlistmodel.h.