Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Commit

Permalink
[recorder] Add ability to change channel in timers
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej committed Nov 17, 2013
1 parent 5c59218 commit 5e65dbf
Show file tree
Hide file tree
Showing 23 changed files with 125 additions and 91 deletions.
5 changes: 5 additions & 0 deletions src/config/TanoConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ bool TanoConfig::requiresAuthentication() const
return false;
}

bool TanoConfig::recorderIdUrl() const
{
return true;
}

bool TanoConfig::editorEnabled() const
{
return true;
Expand Down
1 change: 1 addition & 0 deletions src/config/TanoConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Q_INTERFACES(ConfigPlugin)
QString downloadUrl() const;

bool requiresAuthentication() const;
bool recorderIdUrl() const;
bool editorEnabled() const;

QVariantMap defaultSettings() const { return QVariantMap(); }
Expand Down
10 changes: 10 additions & 0 deletions src/core/playlist/containers/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <QtGui/QIcon>

#include "Channel.h"
#include "plugins/Plugins.h"

Channel::Channel(QObject *parent)
: ListItem(parent) { }
Expand All @@ -44,6 +45,7 @@ Channel::~Channel() { }
QHash<int, QByteArray> Channel::roleNames() const
{
QHash<int, QByteArray> names;
names[IdRole] = "id";
names[DisplayRole] = "display";
names[DecorationRole] = "decoration";
names[NameRole] = "name";
Expand All @@ -58,6 +60,14 @@ QHash<int, QByteArray> Channel::roleNames() const
return names;
}

QString Channel::id() const
{
if (globalConfig && globalConfig->recorderIdUrl())
return url();
else
return QString::number(number());
}

QVariant Channel::data(int role) const
{
switch (role)
Expand Down
5 changes: 3 additions & 2 deletions src/core/playlist/containers/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Q_OBJECT
enum Roles {
DisplayRole = Qt::DisplayRole,
DecorationRole = Qt::DecorationRole,
NameRole = Qt::UserRole + 1,
IdRole = Qt::UserRole + 1,
NameRole,
NumberRole,
TypeRole,
LanguageRole,
Expand Down Expand Up @@ -83,7 +84,7 @@ Q_OBJECT
~Channel();

// Implemented virtual functions
inline QString id() const { return _url; }
QString id() const;
QVariant data(int role) const;
QString display() const;
QPixmap decoration() const;
Expand Down
1 change: 1 addition & 0 deletions src/core/plugins/ConfigPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TANO_CORE_EXPORT ConfigPlugin
virtual QString downloadUrl() const = 0;

virtual bool requiresAuthentication() const = 0;
virtual bool recorderIdUrl() const = 0;
virtual bool editorEnabled() const = 0;

virtual QVariantMap defaultSettings() const = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/core/timers/TimersGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ void TimersGenerator::generateItem(Timer *timer)

_out << indent(depth) << "<timer>\n"
<< indent(depth + 1) << "<name>" << escapedText(timer->name()) << "</name>\n"
<< indent(depth + 1) << "<channel>" << escapedText(timer->channel()) << "</channel>\n"
<< indent(depth + 1) << "<url>" << escapedText(timer->url()) << "</url>\n"
<< indent(depth + 1) << "<channelId>" << escapedText(timer->channelId()) << "</channelId>\n"
<< indent(depth + 1) << "<file>" << escapedText(timer->file()) << "</file>\n"
<< indent(depth + 1) << "<date>" << escapedText(timer->date().toString(Qt::ISODate)) << "</date>\n"
<< indent(depth + 1) << "<start>" << escapedText(timer->startTime().toString(Qt::ISODate)) << "</start>\n"
Expand Down
8 changes: 2 additions & 6 deletions src/core/timers/TimersHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,9 @@ bool TimersHandler::endElement(const QString & /* namespaceURI */,
if (_timer) {
_timer->setName(_currentText);
}
} else if (qName == "channel") {
} else if (qName == "channelId") {
if (_timer) {
_timer->setChannel(_currentText);
}
} else if (qName == "url") {
if (_timer) {
_timer->setUrl(_currentText);
_timer->setChannelId(_currentText);
}
} else if (qName == "file") {
if (_timer) {
Expand Down
41 changes: 14 additions & 27 deletions src/core/timers/containers/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
#include "Timer.h"

Timer::Timer(const QString &name,
const QString &channel,
const QString &url,
const QString &channelId,
const Type &type,
QObject *parent)
: ListItem(parent),
_name(name),
_channel(channel),
_url(url),
_channelId(channelId),
_type(type)
{
_file = "";
Expand All @@ -49,8 +47,7 @@ Timer::Timer(Timer *timer)
_state = Enabled;

_name = timer->name();
_channel = timer->channel();
_url = timer->url();
_channelId = timer->channelId();
_date = timer->date();
_startTime = timer->startTime();
_endTime = timer->endTime();
Expand All @@ -68,8 +65,7 @@ QHash<int, QByteArray> Timer::roleNames() const
names[DisplayRole] = "display";
names[DecorationRole] = "decoration";
names[NameRole] = "name";
names[ChannelRole] = "channel";
names[UrlRole] = "url";
names[ChannelIdRole] = "channelId";
names[FileRole] = "file";
names[DateRole] = "date";
names[StartTimeRole] = "start";
Expand All @@ -91,10 +87,8 @@ QVariant Timer::data(int role) const
return decoration();
case NameRole:
return name();
case ChannelRole:
return channel();
case UrlRole:
return url();
case ChannelIdRole:
return channelId();
case DateRole:
return date();
case StartTimeRole:
Expand All @@ -116,13 +110,14 @@ QVariant Timer::data(int role) const

QString Timer::display() const
{
// TODO: new display
if (type() != Once && type() != Instant)
return QString("%1 (%2) - %3 - %4 %5 %6, %7")
.arg(name(), states()[state()], channel(),
return QString("%1 (%2) - %4 %5 %6, %7")
.arg(name(), states()[state()],
date().toString("dd.M.yyyy"), tr("at"), startTime().toString("hh:mm"), typesLong()[type()]);
else
return QString("%1 (%2) - %3 - %4 %5 %6")
.arg(name(), states()[state()], channel(),
return QString("%1 (%2) - %4 %5 %6")
.arg(name(), states()[state()],
date().toString("dd.M.yyyy"), tr("at"), startTime().toString("hh:mm"));
}

Expand All @@ -144,18 +139,10 @@ void Timer::setName(const QString &name)
}
}

void Timer::setChannel(const QString &channel)
void Timer::setChannelId(const QString &channelId)
{
if (_channel != channel) {
_channel = channel;
emit dataChanged();
}
}

void Timer::setUrl(const QString &url)
{
if (_url != url) {
_url = url;
if (_channelId != channelId) {
_channelId = channelId;
emit dataChanged();
}
}
Expand Down
15 changes: 5 additions & 10 deletions src/core/timers/containers/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ Q_OBJECT
DisplayRole = Qt::DisplayRole,
DecorationRole = Qt::DecorationRole,
NameRole = Qt::UserRole + 1,
ChannelRole,
UrlRole,
ChannelIdRole,
FileRole,
DateRole,
StartTimeRole,
Expand Down Expand Up @@ -68,8 +67,7 @@ Q_OBJECT
};

explicit Timer(const QString &name,
const QString &channel,
const QString &url,
const QString &channelId,
const Type &type = Once,
QObject *parent = 0);
explicit Timer(Timer *timer);
Expand All @@ -84,10 +82,8 @@ Q_OBJECT

inline QString name() const { return _name; }
void setName(const QString &name);
inline QString channel() const { return _channel; }
void setChannel(const QString &channel);
inline QString url() const { return _url; }
void setUrl(const QString &url);
inline QString channelId() const { return _channelId; }
void setChannelId(const QString &channelId);
inline QString file() const { return _file; }
void setFile(const QString &file);
inline QDate date() const { return _date; }
Expand All @@ -109,8 +105,7 @@ Q_OBJECT

private:
QString _name;
QString _channel;
QString _url;
QString _channelId;
QString _file;
QDate _date;
QTime _startTime;
Expand Down
5 changes: 2 additions & 3 deletions src/core/timers/models/TimersModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ Timer *TimersModel::takeRow(const int &row)
}

Timer *TimersModel::createTimer(const QString &name,
const QString &channel,
const QString &url,
const QString &channelId,
const Timer::Type &type)
{
Timer *newTimer = new Timer(name, channel, url, type, this);
Timer *newTimer = new Timer(name, channelId, type, this);
appendRow(newTimer);

return newTimer;
Expand Down
3 changes: 1 addition & 2 deletions src/core/timers/models/TimersModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ Q_OBJECT
Timer *takeRow(const int &row);

Timer *createTimer(const QString &name,
const QString &channel,
const QString &url,
const QString &channelId,
const Timer::Type &type = Timer::Once);
void deleteTimer(Timer *timer);
Timer *duplicateTimer(Timer *timer);
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ void MainWindow::recordNow(bool start)

_mediaPlayer->recordNowStop();
} else {
_recording = _recorder->newInstantTimer(_channel->name(), _channel->url());
_recording = _recorder->newInstantTimer(_channel);
_recording->setDate(QDate::currentDate());
_recording->setStartTime(QTime::currentTime());
_recording->setState(Timer::Recording);
Expand Down
41 changes: 28 additions & 13 deletions src/widgets/recorder/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <QtGui/QVBoxLayout>
#endif

#include "core/network/NetworkUdpxy.h"
#include "core/playlist/PlaylistModel.h"
#include "core/playlist/containers/Channel.h"
#include "core/settings/Settings.h"
#include "core/timers/TimersTimeManager.h"
#include "core/timers/containers/Timer.h"
Expand All @@ -54,6 +57,7 @@ Recorder::Recorder(QWidget *parent)
_core = new RecorderCore(this);
_manager = new TimersTimeManager(this);
_model = new TimersModel(this);
_udpxy = new NetworkUdpxy();

_manager->setTimersModel(_model);

Expand Down Expand Up @@ -103,6 +107,8 @@ void Recorder::createSettings()
_directory = settings->recorderDirectory();

_core->setDefaultOutputPath(_directory);

_udpxy->createSettings();
}

void Recorder::currentWidget(QWidget *widget)
Expand All @@ -115,10 +121,9 @@ bool Recorder::isRecording() const
return _core->isRecording();
}

Timer *Recorder::newInstantTimer(const QString &channel,
const QString &url)
Timer *Recorder::newInstantTimer(Channel *channel)
{
Timer *timer = _model->createTimer(tr("Instant %1").arg(channel), channel, url, Timer::Instant);
Timer *timer = _model->createTimer(tr("Instant %1").arg(channel->name()), channel->id(), Timer::Instant);

return timer;
}
Expand All @@ -145,16 +150,25 @@ void Recorder::quickRecord()

void Recorder::recordStart(Timer *timer)
{
if (!QDir(_directory).exists()) {
if (timer->channelId().isEmpty()) {
QMessageBox::critical(this, tr("Recorder"),
tr("Cannot write to %1.")
.arg(_directory));
tr("Recording does not have a channel associated!"));
delete timer;
return;
} else if (timer->url().isEmpty() || timer->channel().isEmpty()) {
}

Channel *c = _playlist->find(timer->channelId());

if (!c) {
QMessageBox::critical(this, tr("Recorder"),
tr("Recording not valid!"));
tr("Recording does not have a valid channel associated!"));
delete timer;
return;
} else if (!QDir(_directory).exists()) {
QMessageBox::critical(this, tr("Recorder"),
tr("Cannot write to %1.")
.arg(_directory));
return;
}

_currentTimer = timer;
Expand All @@ -163,20 +177,20 @@ void Recorder::recordStart(Timer *timer)
timer->setStartTime(QTime::currentTime());
}

_core->record(timer);
_core->record(timer, c->name(), _udpxy->processUrl(c->url()));

if (_core->isTimer())
_info->start(timer->name(), timer->channel(), timer->endTime().toString("hh:mm"));
_info->start(timer->name(), c->name(), timer->endTime().toString("hh:mm"));
else
_info->start(timer->name(), timer->channel());
_info->start(timer->name(), c->name());

if (_actionRecord)
_actionRecord->setEnabled(true);

if (_core->isTimer())
notifications->notify(tr("Recording"), tr("Starting %1 on %2 until %3.").arg(timer->name(), timer->channel(), timer->startTime().toString("hh:mm")));
notifications->notify(tr("Recording"), tr("Starting %1 on %2 until %3.").arg(timer->name(), c->name(), timer->startTime().toString("hh:mm")));
else
notifications->notify(tr("Recording"), tr("Starting %1 on %2.").arg(timer->name(), timer->channel()));
notifications->notify(tr("Recording"), tr("Starting %1 on %2.").arg(timer->name(), c->name()));
}


Expand Down Expand Up @@ -245,6 +259,7 @@ void Recorder::setMediaInstance(VlcInstance *instance)
void Recorder::setPlaylistModel(PlaylistModel *model)
{
_playlist = model;
_info->setPlaylistModel(model);
}

void Recorder::setWidgets(QAction *action)
Expand Down
Loading

0 comments on commit 5e65dbf

Please sign in to comment.