Skip to content

Commit

Permalink
Add services to support channel restore data
Browse files Browse the repository at this point in the history
Add methods GetRestoreData and SaveRestoreData to Channel
service.
  • Loading branch information
bennettpeter committed Mar 30, 2024
1 parent becf165 commit db8c584
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 27 deletions.
110 changes: 84 additions & 26 deletions mythtv/libs/libmythtv/restoredata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,37 @@ class RestoreIcon : public TransMythUICheckBoxSetting
};
};

RestoreData::RestoreData(uint sourceid) :
m_sourceid(sourceid)
RestoreData *RestoreData::s_Instance = nullptr;

RestoreData *RestoreData::getInstance(uint sourceid)
{
if (s_Instance != nullptr)
{
if (sourceid != s_Instance->m_sourceid)
{
delete s_Instance;
s_Instance = nullptr;
}
}
if (s_Instance == nullptr)
s_Instance = new RestoreData(sourceid, false);
return s_Instance;
}

void RestoreData::freeInstance()
{
if (s_Instance != nullptr)
{
delete s_Instance;
s_Instance = nullptr;
}
}

RestoreData::RestoreData(uint sourceid, bool useGUI) :
m_sourceid(sourceid), m_useGUI(useGUI)
{
if (!m_useGUI)
return;
setLabel(tr("Restore Data"));

m_videosource = new VideoSourceShow(m_sourceid);
Expand Down Expand Up @@ -133,10 +161,16 @@ RestoreData::RestoreData(uint sourceid) :

void RestoreData::Restore()
{
if (!m_useGUI)
return;
bool do_xmltvid = m_restoreXMLTVID->boolValue();
bool do_icon = m_restoreIcon->boolValue();
bool do_visible = m_restoreVisible->boolValue();
doRestore(do_xmltvid, do_icon, do_visible);
}

QString RestoreData::doRestore(bool do_xmltvid, bool do_icon, bool do_visible)
{
if (do_xmltvid || do_icon || do_visible)
{
QString msg = QString("Restore data from deleted channels for fields ");
Expand Down Expand Up @@ -175,7 +209,7 @@ void RestoreData::Restore()
if (!query.exec() || !query.isActive())
{
MythDB::DBError("RestoreData::Restore(1)", query);
return;
return QString();
}
while (query.next())
{
Expand All @@ -190,10 +224,17 @@ void RestoreData::Restore()
cd.icon = query.value(7).toString();
cd.visible = query.value(8).toInt();

bool nullNetwork = query.isNull(5);
cd.found_xmltvid = false;
cd.found_icon = false;
cd.found_visible = false;

QString networkCheck;
if (nullNetwork)
networkCheck = " networkid IS NULL";
else
networkCheck = " networkid = :NETWORKID ";

// Get xmltvid from the last deleted channel
// from any video source or from a channel
// on a different video source
Expand All @@ -204,20 +245,21 @@ void RestoreData::Restore()
"FROM channel, dtv_multiplex "
"WHERE serviceid = :SERVICEID "
" AND transportid = :TRANSPORTID "
" AND networkid = :NETWORKID "
" AND " + networkCheck +
" AND channel.mplexid = dtv_multiplex.mplexid "
" AND xmltvid != ''"
" AND (deleted IS NOT NULL OR "
" channel.sourceid != :SOURCEID)"
"ORDER BY deleted DESC;");
query2.bindValue(":SERVICEID", cd.serviceid);
query2.bindValue(":TRANSPORTID", cd.transportid);
query2.bindValue(":NETWORKID", cd.networkid);
if (!nullNetwork)
query2.bindValue(":NETWORKID", cd.networkid);
query2.bindValue(":SOURCEID", m_sourceid);
if (!query2.exec() || !query2.isActive())
{
MythDB::DBError("RestoreData::Restore(2)", query);
return;
return QString();
}
if (query2.next())
{
Expand All @@ -236,20 +278,20 @@ void RestoreData::Restore()
"FROM channel, dtv_multiplex "
"WHERE serviceid = :SERVICEID "
" AND transportid = :TRANSPORTID "
" AND networkid = :NETWORKID "
" AND channel.mplexid = dtv_multiplex.mplexid "
" AND icon != ''"
" AND (deleted IS NOT NULL OR "
" channel.sourceid != :SOURCEID)"
"ORDER BY deleted DESC;");
query2.bindValue(":SERVICEID", cd.serviceid);
query2.bindValue(":TRANSPORTID", cd.transportid);
query2.bindValue(":NETWORKID", cd.networkid);
if (!nullNetwork)
query2.bindValue(":NETWORKID", cd.networkid);
query2.bindValue(":SOURCEID", m_sourceid);
if (!query2.exec() || !query2.isActive())
{
MythDB::DBError("RestoreData::Restore(3)", query);
return;
return QString();
}
if (query2.next())
{
Expand All @@ -267,19 +309,20 @@ void RestoreData::Restore()
"FROM channel, dtv_multiplex "
"WHERE serviceid = :SERVICEID "
" AND transportid = :TRANSPORTID "
" AND networkid = :NETWORKID "
" AND " + networkCheck +
" AND channel.sourceid = :SOURCEID "
" AND channel.mplexid = dtv_multiplex.mplexid "
" AND deleted IS NOT NULL "
"ORDER BY deleted DESC;");
query2.bindValue(":SERVICEID", cd.serviceid);
query2.bindValue(":TRANSPORTID", cd.transportid);
query2.bindValue(":NETWORKID", cd.networkid);
if (!nullNetwork)
query2.bindValue(":NETWORKID", cd.networkid);
query2.bindValue(":SOURCEID", m_sourceid);
if (!query2.exec() || !query2.isActive())
{
MythDB::DBError("RestoreData::Restore(4)", query);
return;
return QString();
}
if (query2.next())
{
Expand Down Expand Up @@ -311,29 +354,30 @@ void RestoreData::Restore()
}

// Log of all channels that will be updated
int num_xmltvid = 0;
int num_icon = 0;
int num_visible = 0;
m_num_xmltvid = 0;
m_num_icon = 0;
m_num_visible = 0;
for (auto & cd : m_ocd)
{
QString msg = QString("Channel %1 \'%2\' update ").arg(cd.channum, cd.name);
if (cd.found_xmltvid)
{
msg += QString("xmltvid(%1) ").arg(cd.xmltvid);
num_xmltvid++;
m_num_xmltvid++;
}
if (cd.found_icon)
{
msg += QString("icon(%1) ").arg(cd.icon);
num_icon++;
m_num_icon++;
}
if (cd.found_visible)
{
msg += QString("visible(%1) ").arg(cd.visible);
num_visible++;
m_num_visible++;
}
LOG(VB_GENERAL, LOG_INFO, LOC + msg);
}
m_num_channels = m_ocd.size();

// Show totals of what has been found.
{
Expand All @@ -345,21 +389,24 @@ void RestoreData::Restore()
else
{
msg = QString("Found data for %1 channels\n").arg(m_ocd.size());
if (num_xmltvid > 0)
if (m_num_xmltvid > 0)
{
msg += QString("xmltvid: %1 ").arg(num_xmltvid);
msg += QString("xmltvid: %1 ").arg(m_num_xmltvid);
}
if (num_icon > 0)
if (m_num_icon > 0)
{
msg += QString("icon: %1 ").arg(num_icon);
msg += QString("icon: %1 ").arg(m_num_icon);
}
if (num_visible > 0)
if (m_num_visible > 0)
{
msg += QString("visible: %1").arg(num_visible);
msg += QString("visible: %1").arg(m_num_visible);
}
}
WaitFor(ShowOkPopup(msg));
if (m_useGUI)
WaitFor(ShowOkPopup(msg));
return msg;
}

}

// Load value of selected video source (for display only)
Expand All @@ -371,6 +418,16 @@ void RestoreData::Load(void)
// Do the actual updating if "Save and Exit" is selected in the "Exit Settings?" dialog.
void RestoreData::Save(void)
{
doSave();
}

bool RestoreData::doSave(void)
{
if (m_ocd.empty())
{
LOG(VB_GENERAL, LOG_INFO, LOC + QString("No data to Restore"));
return false;
}
MSqlQuery query(MSqlQuery::InitCon());
for (auto & cd : m_ocd)
{
Expand All @@ -387,8 +444,9 @@ void RestoreData::Save(void)
if (!query.exec() || !query.isActive())
{
MythDB::DBError("RestoreData::Restore(5)", query);
return;
return false;
}
}
LOG(VB_GENERAL, LOG_INFO, LOC + QString("Restored data for %1 channels").arg(m_ocd.size()));
return true;
}
16 changes: 15 additions & 1 deletion mythtv/libs/libmythtv/restoredata.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,36 @@ class MTV_PUBLIC RestoreData : public GroupSetting
{
Q_OBJECT
public:
explicit RestoreData(uint sourceid);
explicit RestoreData(uint sourceid, bool useGUI = true);
static RestoreData * getInstance(uint sourceid);
static void freeInstance();
void Load(void) override; // StandardSetting
void Save(void) override; // StandardSetting
bool doSave(void);
QString doRestore(bool do_xmltvid, bool do_icon, bool do_visible);

public slots:
void Restore(void);

private:
static RestoreData *s_Instance;
VideoSourceShow *m_videosource {nullptr};
RestoreXMLTVID *m_restoreXMLTVID {nullptr};
RestoreVisible *m_restoreVisible {nullptr};
RestoreIcon *m_restoreIcon {nullptr};

uint m_sourceid {0};
bool m_useGUI {false};

std::vector<OldChannelData> m_ocd;

public:
// Return values for the API
int m_num_channels {0};
int m_num_xmltvid {0};
int m_num_icon {0};
int m_num_visible {0};

};

#endif // RESTOREDATA_H
1 change: 1 addition & 0 deletions mythtv/programs/mythbackend/mythbackend.pro
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ HEADERS += servicesv2/v2guide.h servicesv2/v2programGuide.h
HEADERS += servicesv2/v2channel.h servicesv2/v2channelScan.h
HEADERS += servicesv2/v2commMethod.h
HEADERS += servicesv2/v2channelInfoList.h servicesv2/v2lineup.h
HEADERS += servicesv2/v2channelRestore.h
HEADERS += servicesv2/v2videoSource.h servicesv2/v2videoSourceList.h
HEADERS += servicesv2/v2videoMultiplex.h servicesv2/v2videoMultiplexList.h
HEADERS += servicesv2/v2status.h
Expand Down
27 changes: 27 additions & 0 deletions mythtv/programs/mythbackend/servicesv2/v2channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "libmythbase/mythdate.h"
#include "libmythtv/frequencies.h"
#include "libmythbase/mythsystemlegacy.h"
#include "libmythtv/restoredata.h"

// MythBackend
#include "v2artworkInfoList.h"
Expand Down Expand Up @@ -90,6 +91,7 @@ void V2Channel::RegisterCustomTypes()
qRegisterMetaType<V2ScanStatus*>("V2ScanStatus");
qRegisterMetaType<V2Scan*>("V2Scan");
qRegisterMetaType<V2ScanList*>("V2ScanList");
qRegisterMetaType<V2ChannelRestore*>("V2ChannelRestore");
}

V2Channel::V2Channel() : MythHTTPService(s_service)
Expand Down Expand Up @@ -1140,3 +1142,28 @@ bool V2Channel::SendScanDialogResponse ( uint Cardid,
}
return false;
}

V2ChannelRestore* V2Channel::GetRestoreData ( uint SourceId,
bool XmltvId,
bool Icon,
bool Visible)
{
auto * pResult = new V2ChannelRestore();
RestoreData* rd = RestoreData::getInstance(SourceId);
QString result = rd->doRestore(XmltvId, Icon, Visible);
if (result.isEmpty())
throw( QString("GetRestoreData failed."));
pResult->setNumChannels(rd->m_num_channels);
pResult->setNumXLMTVID(rd->m_num_xmltvid);
pResult->setNumIcon(rd->m_num_icon);
pResult->setNumVisible(rd->m_num_visible);
return pResult;
}

bool V2Channel::SaveRestoreData ( uint SourceId )
{
RestoreData* rd = RestoreData::getInstance(SourceId);
bool result = rd->doSave();
RestoreData::freeInstance();
return result;
}
9 changes: 9 additions & 0 deletions mythtv/programs/mythbackend/servicesv2/v2channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "v2grabber.h"
#include "v2commMethod.h"
#include "v2channelScan.h"
#include "v2channelRestore.h"

#define CHANNEL_SERVICE QString("/Channel/")
#define CHANNEL_HANDLE QString("Channel")
Expand All @@ -56,6 +57,7 @@ class V2Channel : public MythHTTPService
Q_CLASSINFO("StartScan", "methods=POST;name=bool")
Q_CLASSINFO("StopScan", "methods=POST;name=bool")
Q_CLASSINFO("SendScanDialogResponse", "methods=POST;name=bool")
Q_CLASSINFO("SaveRestoreData", "methods=POST;name=bool")

public:
V2Channel();
Expand Down Expand Up @@ -231,6 +233,13 @@ class V2Channel : public MythHTTPService
const QString &DialogString,
int DialogButton );

static V2ChannelRestore* GetRestoreData ( uint SourceId,
bool XmltvId,
bool Icon,
bool Visible);

static bool SaveRestoreData ( uint SourceId);

private:
Q_DISABLE_COPY(V2Channel)

Expand Down
Loading

0 comments on commit db8c584

Please sign in to comment.