Skip to content

Commit 25cecf6

Browse files
author
Robert McNamara
committed
Hardware Profiler: Update opt-in hardware profile monthly.
Checks for opt-in/existing profile and last date of update. If this was greater than a month ago, update the existing profile. Seems to work nicely in my testing so far. Plans are afoot to have the housekeeper update the hardware profile for backend-only machines, the code should be very simple.
1 parent 4ecbdf5 commit 25cecf6

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

mythtv/libs/libmyth/hardwareprofile.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ const QString SMOLT_SERVER_LOCATION =
2121

2222
HardwareProfile::HardwareProfile() :
2323
m_uuid(QString()), m_publicuuid(QString()),
24-
m_hardwareProfile(QString())
24+
m_lastUpdate(QDateTime()), m_hardwareProfile(QString())
2525
{
2626
m_uuid = gCoreContext->GetSetting("HardwareProfileUUID");
2727
m_publicuuid = gCoreContext->GetSetting("HardwareProfilePublicUUID");
28+
QString lastupdate = gCoreContext->GetSetting("HardwareProfileLastUpdated");
29+
m_lastUpdate = QDateTime::fromString(lastupdate, Qt::ISODate);
2830
}
2931

3032
HardwareProfile::~HardwareProfile()
@@ -131,6 +133,19 @@ bool HardwareProfile::WritePrivateUUIDToFile(QString uuid)
131133
return false;
132134
}
133135

136+
bool HardwareProfile::NeedsUpdate(void)
137+
{
138+
if (!m_lastUpdate.isNull() &&
139+
(m_lastUpdate.addMonths(1) < QDateTime::currentDateTime()) &&
140+
!m_uuid.isEmpty())
141+
{
142+
VERBOSE(VB_GENERAL, QString("Last hardware profile update was > 30 days ago, update required..."));
143+
return true;
144+
}
145+
146+
return false;
147+
}
148+
134149
bool HardwareProfile::SubmitProfile(void)
135150
{
136151
if (m_uuid.isEmpty())
@@ -148,7 +163,14 @@ bool HardwareProfile::SubmitProfile(void)
148163

149164
system.Run();
150165
if (system.Wait() == GENERIC_EXIT_OK)
166+
{
167+
GenerateUUIDs();
168+
gCoreContext->SaveSetting("HardwareProfileUUID", GetPrivateUUID());
169+
gCoreContext->SaveSetting("HardwareProfilePublicUUID", GetPublicUUID());
170+
gCoreContext->SaveSetting("HardwareProfileLastUpdated",
171+
QDateTime::currentDateTime().toString(Qt::ISODate));
151172
return true;
173+
}
152174
else
153175
return false;
154176

@@ -169,7 +191,13 @@ bool HardwareProfile::DeleteProfile(void)
169191

170192
system.Run();
171193
if (system.Wait() == GENERIC_EXIT_OK)
194+
{
195+
gCoreContext->SaveSetting("HardwareProfileUUID", "");
196+
gCoreContext->SaveSetting("HardwareProfilePublicUUID", "");
197+
gCoreContext->SaveSetting("HardwareProfileLastUpdated",
198+
QDateTime::currentDateTime().toString(Qt::ISODate));
172199
return true;
200+
}
173201
else
174202
return false;
175203

mythtv/libs/libmyth/hardwareprofile.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// QT headers
55
#include <QObject>
66
#include <QString>
7+
#include <QDateTime>
78

89
// MythDB headers
910
#include "mythexp.h"
@@ -30,18 +31,20 @@ class MPUBLIC HardwareProfile : public QObject
3031
bool WritePrivateUUIDToFile(QString uuid);
3132
QString GetPublicUUIDFromFile(void);
3233

34+
bool NeedsUpdate(void);
3335
bool SubmitProfile(void);
3436
bool DeleteProfile(void);
3537

36-
QString GetPublicUUID(void) {return m_publicuuid; };
37-
QString GetPrivateUUID(void) {return m_uuid; };
38-
39-
QString GetProfileURL(void);
38+
QString GetPublicUUID(void) { return m_publicuuid; };
39+
QString GetPrivateUUID(void) { return m_uuid; };
40+
QDateTime GetLastUpdate(void) { return m_lastUpdate; };
41+
QString GetProfileURL(void);
4042

4143
private:
42-
QString m_uuid;
43-
QString m_publicuuid;
44-
QString m_hardwareProfile;
44+
QString m_uuid;
45+
QString m_publicuuid;
46+
QDateTime m_lastUpdate;
47+
QString m_hardwareProfile;
4548
};
4649

4750
#endif

mythtv/programs/mythfrontend/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ using namespace std;
4343
#include "dvdringbuffer.h"
4444
#include "scheduledrecording.h"
4545
#include "mythsystemevent.h"
46+
#include "hardwareprofile.h"
4647

4748
#include "compat.h" // For SIG* on MinGW
4849
#include "exitcodes.h"
@@ -1427,6 +1428,15 @@ int main(int argc, char **argv)
14271428
.arg(networkPort));
14281429
}
14291430

1431+
#ifdef __linux__
1432+
#ifdef CONFIG_BINDINGS_PYTHON
1433+
HardwareProfile *profile = new HardwareProfile();
1434+
if (profile && profile->NeedsUpdate())
1435+
profile->SubmitProfile();
1436+
delete profile;
1437+
#endif
1438+
#endif
1439+
14301440
if (!RunMenu(themedir, themename) && !resetTheme(themedir, themename))
14311441
{
14321442
return GENERIC_EXIT_NO_THEME;

mythtv/programs/mythfrontend/setupwizard_general.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ void GeneralSetupWizard::OnSubmitPromptReturn(bool submit)
148148
m_busyPopup->Close();
149149
m_busyPopup = NULL;
150150
}
151-
m_hardwareProfile->GenerateUUIDs();
152-
gCoreContext->SaveSetting("HardwareProfileUUID", m_hardwareProfile->GetPrivateUUID());
153-
gCoreContext->SaveSetting("HardwareProfilePublicUUID", m_hardwareProfile->GetPublicUUID());
154151
ShowOkPopup(tr("Hardware profile submitted. Thank you for supporting "
155152
"MythTV!"));
156153
if (m_profileLocation)
@@ -251,8 +248,6 @@ void GeneralSetupWizard::OnDeletePromptReturn(bool submit)
251248
m_busyPopup->Close();
252249
m_busyPopup = NULL;
253250
}
254-
gCoreContext->SaveSetting("HardwareProfileUUID", "");
255-
gCoreContext->SaveSetting("HardwareProfilePublicUUID", "");
256251
ShowOkPopup(tr("Hardware profile deleted."));
257252
}
258253
else

0 commit comments

Comments
 (0)