MythTV  master
neteditorbase.cpp
Go to the documentation of this file.
1 #include <QDomDocument>
2 
3 // MythTV headers
4 #include <mythuibuttonlist.h>
5 #include <mythmainwindow.h>
6 #include <mythdialogbox.h>
7 #include <mythcontext.h>
8 #include <mythdbcon.h>
9 #include <mythdirs.h>
10 #include <netutils.h>
11 
12 // Tree headers
13 #include "neteditorbase.h"
14 #include "netcommon.h"
15 
16 #define LOC QString("NetEditorBase: ")
17 #define LOC_WARN QString("NetEditorBase, Warning: ")
18 #define LOC_ERR QString("NetEditorBase, Error: ")
19 
25  const QString &name) :
26  MythScreenType(parent, name)
27 {
28  m_popupStack = GetMythMainWindow()->GetStack("popup stack");
29 }
30 
32 {
33  if (m_manager)
34  {
35  m_manager->disconnect();
36  m_manager->deleteLater();
37  m_manager = nullptr;
38  }
39 
40  qDeleteAll(m_grabberList);
41  m_grabberList.clear();
42 
43  if (m_changed)
44  emit ItemsChanged();
45 }
46 
48 {
49  // Load the theme for this screen
50  bool foundtheme = LoadWindowFromXML("netvision-ui.xml", "treeeditor", this);
51 
52  if (!foundtheme)
53  return false;
54 
55  bool err = false;
56  UIUtilE::Assign(this, m_grabbers, "grabbers", &err);
57 
58  if (err)
59  {
60  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'treeeditor'");
61  return false;
62  }
63 
64  connect(m_grabbers, SIGNAL(itemClicked(MythUIButtonListItem*)),
65  this, SLOT(ToggleItem(MythUIButtonListItem*)));
66 
68 
69  LoadData();
70 
71  return true;
72 }
73 
75 {
76  QString msg = tr("Querying Backend for Internet Content Sources...");
77  CreateBusyDialog(msg);
78 
79  m_manager = new QNetworkAccessManager();
80 
81  connect(m_manager, SIGNAL(finished(QNetworkReply*)),
82  SLOT(SlotLoadedData(void)));
83 
84  QUrl url(GetMythXMLURL() + "GetInternetSources");
85  m_reply = m_manager->get(QNetworkRequest(url));
86 }
87 
88 bool NetEditorBase::keyPressEvent(QKeyEvent *event)
89 {
90  if (GetFocusWidget()->keyPressEvent(event))
91  return true;
92 
93  QStringList actions;
94  bool handled = GetMythMainWindow()->TranslateKeyPress("Internet Video",
95  event, actions);
96 
97  if (!handled && MythScreenType::keyPressEvent(event))
98  handled = true;
99 
100  return handled;
101 }
102 
104 {
105  QDomDocument doc;
106  doc.setContent(m_reply->readAll());
107  QDomElement root = doc.documentElement();
108  QDomElement content = root.firstChildElement("InternetContent");
109  QDomElement grabber = content.firstChildElement("grabber");
110 
111  while (!grabber.isNull())
112  {
113  QString title;
114  QString author;
115  QString image;
116  QString description;
117  QString type;
118  QString commandline;
119  bool search = false;
120  bool tree = false;
121 
122  title = grabber.firstChildElement("name").text();
123  commandline = grabber.firstChildElement("command").text();
124  author = grabber.firstChildElement("author").text();
125  image = grabber.firstChildElement("thumbnail").text();
126  type = grabber.firstChildElement("type").text();
127  description = grabber.firstChildElement("description").text();
128  double version = grabber.firstChildElement("version").text().toDouble();
129 
130  QString searchstring = grabber.firstChildElement("search").text();
131 
132  if (!searchstring.isEmpty() &&
133  (searchstring.toLower() == "true" ||
134  searchstring.toLower() == "yes" ||
135  searchstring == "1"))
136  search = true;
137 
138  QString treestring = grabber.firstChildElement("tree").text();
139 
140  if (!treestring.isEmpty() &&
141  (treestring.toLower() == "true" ||
142  treestring.toLower() == "yes" ||
143  treestring == "1"))
144  tree = true;
145 
146  if (type.toLower() == "video" && Matches(search, tree))
147  {
148  LOG(VB_GENERAL, LOG_INFO,
149  QString("Found Source %1...").arg(title));
150  m_grabberList.append(new GrabberScript(title, image, VIDEO_FILE,
151  author, search, tree,
152  description, commandline,
153  version));
154  }
155 
156  grabber = grabber.nextSiblingElement("grabber");
157  }
158 
159  ParsedData();
160  }
161 
163 {
164  if (m_busyPopup)
165  {
166  m_busyPopup->Close();
167  m_busyPopup = nullptr;
168  }
169 
171 }
172 
174 {
175  if (m_busyPopup)
176  return;
177 
178  const QString& message = title;
179 
181  "mythvideobusydialog");
182 
183  if (m_busyPopup->Create())
185  else
186  {
187  delete m_busyPopup;
188  m_busyPopup = nullptr;
189  }
190 }
191 
193 {
194  for (const auto & g : qAsConst(m_grabberList))
195  {
196  auto *item = new MythUIButtonListItem(m_grabbers, g->GetTitle());
197  item->SetText(g->GetTitle(), "title");
198  item->SetData(QVariant::fromValue(g));
199  const QString& img = g->GetImage();
200  QString thumb;
201 
202  if (!img.startsWith("/") && !img.isEmpty())
203  {
204  thumb = QString("%1mythnetvision/icons/%2").arg(GetShareDir())
205  .arg(g->GetImage());
206  }
207  else
208  {
209  thumb = img;
210  }
211 
212  item->SetImage(thumb);
213  item->setCheckable(true);
214  item->setChecked(MythUIButtonListItem::NotChecked);
215  QFileInfo fi(g->GetCommandline());
216 
217  if (FindGrabberInDB(fi.fileName()))
218  item->setChecked(MythUIButtonListItem::FullChecked);
219  }
220 }
221 
223 {
224  if (!item)
225  return;
226 
227  auto *script = item->GetData().value<GrabberScript*>();
228  if (!script)
229  return;
230 
231  bool checked = (item->state() == MythUIButtonListItem::FullChecked);
232 
233  if (!checked)
234  {
235  if (InsertInDB(script))
236  {
237  m_changed = true;
239  }
240  }
241  else if (RemoveFromDB(script))
242  {
243  m_changed = true;
245  }
246 }
NetEditorBase::m_manager
QNetworkAccessManager * m_manager
Definition: neteditorbase.h:43
NetEditorBase::m_busyPopup
MythUIBusyDialog * m_busyPopup
Definition: neteditorbase.h:40
root
QDomElement root
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:653
NetEditorBase::RemoveFromDB
virtual bool RemoveFromDB(GrabberScript *script)=0
NetEditorBase::FillGrabberButtonList
void FillGrabberButtonList()
Definition: neteditorbase.cpp:192
NetEditorBase::~NetEditorBase
~NetEditorBase() override
Definition: neteditorbase.cpp:31
NetEditorBase::Matches
virtual bool Matches(bool search, bool tree)=0
NetEditorBase::FindGrabberInDB
virtual bool FindGrabberInDB(const QString &filename)=0
doc
QDomDocument doc("MYTHARCHIVEITEM")
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:402
title
QString title
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:633
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1106
MythUIBusyDialog::Create
bool Create(void) override
Definition: mythprogressdialog.cpp:32
build_compdb.content
content
Definition: build_compdb.py:38
NetEditorBase::m_popupStack
MythScreenStack * m_popupStack
Definition: neteditorbase.h:41
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
arg
arg(title).arg(filename).arg(doDelete))
mythdbcon.h
MythUIButtonListItem::FullChecked
@ FullChecked
Definition: mythuibuttonlist.h:34
NetEditorBase::InsertInDB
virtual bool InsertInDB(GrabberScript *script)=0
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
NetEditorBase::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: neteditorbase.cpp:88
NetEditorBase::SlotLoadedData
void SlotLoadedData(void)
Definition: neteditorbase.cpp:103
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
mythdirs.h
netcommon.h
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &stackname)
Definition: mythmainwindow.cpp:309
mythuibuttonlist.h
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:112
MythUIButtonListItem
Definition: mythuibuttonlist.h:28
NetEditorBase::NetEditorBase
NetEditorBase(MythScreenStack *parent, const QString &name)
Creates a new NetEditorBase Screen.
Definition: neteditorbase.cpp:24
NetEditorBase::ParsedData
void ParsedData()
Definition: neteditorbase.cpp:162
NetEditorBase::CreateBusyDialog
void CreateBusyDialog(const QString &title)
Definition: neteditorbase.cpp:173
neteditorbase.h
NetEditorBase::m_grabbers
MythUIButtonList * m_grabbers
Definition: neteditorbase.h:39
GetMythXMLURL
QString GetMythXMLURL(void)
Definition: netcommon.cpp:32
GetShareDir
QString GetShareDir(void)
Definition: mythdirs.cpp:222
NetEditorBase::ToggleItem
void ToggleItem(MythUIButtonListItem *item)
Definition: neteditorbase.cpp:222
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:222
NetEditorBase::m_changed
bool m_changed
Definition: neteditorbase.h:45
netutils.h
NetEditorBase::ItemsChanged
void ItemsChanged(void)
GrabberScript
Definition: netgrabbermanager.h:17
MythUIBusyDialog
Definition: mythprogressdialog.h:37
MythUIButtonListItem::GetData
QVariant GetData()
Definition: mythuibuttonlist.cpp:3588
UIUtilDisp::Assign
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:414
NetEditorBase::m_grabberList
GrabberScript::scriptList m_grabberList
Definition: neteditorbase.h:38
NetEditorBase::m_reply
QNetworkReply * m_reply
Definition: neteditorbase.h:44
VIDEO_FILE
@ VIDEO_FILE
Definition: rssparse.h:21
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:692
MythUIButtonListItem::state
CheckState state() const
Definition: mythuibuttonlist.cpp:3542
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
NetEditorBase::LoadData
void LoadData(void)
Definition: neteditorbase.cpp:74
NetEditorBase::Create
bool Create(void) override
Definition: neteditorbase.cpp:47
mythmainwindow.h
MythUIButtonListItem::setChecked
void setChecked(CheckState state)
Definition: mythuibuttonlist.cpp:3552
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:49
nv_python_libs.bbciplayer.bbciplayer_api.version
string version
Definition: bbciplayer_api.py:81
MythUIButtonListItem::NotChecked
@ NotChecked
Definition: mythuibuttonlist.h:32