MythTV master
neteditorbase.cpp
Go to the documentation of this file.
1#include <QDomDocument>
2
3// MythTV headers
11
12// Tree headers
13#include "netcommon.h"
14#include "neteditorbase.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
66
68
69 LoadData();
70
71 return true;
72}
73
75{
76 QString msg = tr("Querying Backend for Internet Content Sources...");
78
79 m_manager = new QNetworkAccessManager();
80
81 connect(m_manager, &QNetworkAccessManager::finished,
83
84 QUrl url(GetMythXMLURL() + "GetInternetSources");
85 m_reply = m_manager->get(QNetworkRequest(url));
86}
87
88bool 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 {
167 m_busyPopup = nullptr;
168 }
169
171}
172
173void NetEditorBase::CreateBusyDialog(const QString& title)
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 : std::as_const(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")
205 .arg(GetShareDir(), 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}
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
MythScreenStack * GetStack(const QString &Stackname)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Screen in which all other widgets are contained and rendered.
void BuildFocusList(void)
MythUIType * GetFocusWidget(void) const
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
virtual void Close()
bool Create(void) override
CheckState state() const
void setChecked(CheckState state)
void itemClicked(MythUIButtonListItem *item)
MythScreenStack * m_popupStack
Definition: neteditorbase.h:40
virtual bool Matches(bool search, bool tree)=0
virtual bool FindGrabberInDB(const QString &filename)=0
void ItemsChanged(void)
void SlotLoadedData(void)
void LoadData(void)
QNetworkAccessManager * m_manager
Definition: neteditorbase.h:42
virtual bool InsertInDB(GrabberScript *script)=0
MythUIBusyDialog * m_busyPopup
Definition: neteditorbase.h:39
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
virtual bool RemoveFromDB(GrabberScript *script)=0
MythUIButtonList * m_grabbers
Definition: neteditorbase.h:38
void CreateBusyDialog(const QString &title)
void FillGrabberButtonList()
~NetEditorBase() override
GrabberScript::scriptList m_grabberList
Definition: neteditorbase.h:37
QNetworkReply * m_reply
Definition: neteditorbase.h:43
NetEditorBase(MythScreenStack *parent, const QString &name)
Creates a new NetEditorBase Screen.
void ToggleItem(MythUIButtonListItem *item)
bool Create(void) override
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
QString GetShareDir(void)
Definition: mythdirs.cpp:261
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
string version
Definition: giantbomb.py:185
QString GetMythXMLURL(void)
Definition: netcommon.cpp:35
@ VIDEO_FILE
Definition: rssparse.h:21
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27