OESystemComponent.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "settings/SettingsComponent.h"
  2. #include "OESystemComponent.h"
  3. #include "QsLog.h"
  4. #include <unistd.h>
  5. #include <QFile>
  6. ///////////////////////////////////////////////////////////////////////////////////////////////////
  7. OESystemComponent::OESystemComponent(QObject *parent) : ComponentBase(parent)
  8. {
  9. }
  10. ///////////////////////////////////////////////////////////////////////////////////////////////////
  11. bool OESystemComponent::componentInitialize()
  12. {
  13. setHostName(SettingsComponent::Get().value(SETTINGS_SECTION_OPENELEC, "systemname").toString());
  14. return true;
  15. }
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////
  17. bool OESystemComponent::setHostName(QString name)
  18. {
  19. // first we change the hostname name for this session
  20. char* hostname = name.toUtf8().data();
  21. sethostname(hostname, strlen(hostname));
  22. // then edit the hostname file so that its persistent
  23. QFile file("/storage/.cache/hostname");
  24. if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
  25. {
  26. QLOG_ERROR() << "setHostName : Failed to open" << file.fileName();
  27. return false;
  28. }
  29. QTextStream writer(&file);
  30. writer << name;
  31. file.close();
  32. return true;
  33. }