MythTV  master
mythnewseditor.cpp
Go to the documentation of this file.
1 
2 // MythTV headers
3 #include <mythuibutton.h>
4 #include <mythuitext.h>
5 #include <mythuitextedit.h>
6 #include <mythuicheckbox.h>
7 #include <mythmainwindow.h>
8 #include <mythdialogbox.h>
9 #include <mythdate.h>
10 #include <mythcontext.h>
11 #include <mythdbcon.h>
12 
13 // MythNews headers
14 #include "mythnewseditor.h"
15 #include "newsdbutil.h"
16 #include "newssite.h"
17 
18 #define LOC QString("MythNewsEditor: ")
19 #define LOC_WARN QString("MythNewsEditor, Warning: ")
20 #define LOC_ERR QString("MythNewsEditor, Error: ")
21 
30  MythScreenStack *parent,
31  const QString &name) :
32  MythScreenType(parent, name),
33  m_site(site),
34  m_siteName((edit && site) ? site->name() : QString()),
35  m_editing(edit)
36 {
37 }
38 
40 {
41  QMutexLocker locker(&m_lock);
42 }
43 
45 {
46  QMutexLocker locker(&m_lock);
47 
48  // Load the theme for this screen
49  bool foundtheme = LoadWindowFromXML("news-ui.xml", "editor", this);
50 
51  if (!foundtheme)
52  return false;
53 
54  bool err = false;
55  UIUtilW::Assign(this, m_titleText, "title", &err);
56  UIUtilW::Assign(this, m_nameLabelText, "namelabel", &err);
57  UIUtilW::Assign(this, m_urlLabelText, "urllabel", &err);
58  UIUtilW::Assign(this, m_iconLabelText, "iconlabel", &err);
59  UIUtilW::Assign(this, m_podcastLabelText, "podcastlabel", &err);
60  UIUtilE::Assign(this, m_nameEdit, "name", &err);
61  UIUtilE::Assign(this, m_urlEdit, "url", &err);
62  UIUtilE::Assign(this, m_iconEdit, "icon", &err);
63  UIUtilE::Assign(this, m_podcastCheck, "podcast_check", &err);
64  UIUtilE::Assign(this, m_okButton, "ok", &err);
65  UIUtilE::Assign(this, m_cancelButton, "cancel", &err);
66 
67  if (err)
68  {
69  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'editor'");
70  return false;
71  }
72 
73  if (m_titleText)
74  {
76  (m_editing) ? tr("Edit Site Details") : tr("Enter Site Details"));
77  }
78 
79  if (m_nameLabelText)
80  m_nameLabelText->SetText(tr("Name:"));
81  if (m_urlLabelText)
82  m_urlLabelText->SetText(tr("URL:"));
83  if (m_iconLabelText)
84  m_iconLabelText->SetText(tr("Icon:"));
86  m_podcastLabelText->SetText(tr("Podcast:"));
87 
88  m_okButton->SetText(tr("OK"));
89  m_cancelButton->SetText(tr("Cancel"));
90 
91  connect(m_okButton, SIGNAL(Clicked()), this, SLOT(Save()));
92  connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Close()));
93 
94  if (m_editing)
95  {
99  if (m_site->podcast())
101  }
102 
103  BuildFocusList();
104 
106 
107  return true;
108 }
109 
110 bool MythNewsEditor::keyPressEvent(QKeyEvent *event)
111 {
112  if (GetFocusWidget()->keyPressEvent(event))
113  return true;
114 
115  QStringList actions;
116  bool handled = GetMythMainWindow()->TranslateKeyPress("News", event, actions);
117 
118  if (!handled && MythScreenType::keyPressEvent(event))
119  handled = true;
120 
121  return handled;
122 }
123 
125 {
126  {
127  QMutexLocker locker(&m_lock);
128 
129  if (m_editing && !m_siteName.isEmpty())
131 
133  m_iconEdit->GetText(), "custom",
135  }
136  Close();
137 }
MythNewsEditor::m_nameLabelText
MythUIText * m_nameLabelText
Definition: mythnewseditor.h:39
MythNewsEditor::m_iconLabelText
MythUIText * m_iconLabelText
Definition: mythnewseditor.h:41
newsdbutil.h
NewsSite::url
QString url(void) const
Definition: newssite.cpp:90
NewsSite::imageURL
QString imageURL(void) const
Definition: newssite.cpp:128
mythuitext.h
insertInDB
bool insertInDB(RSSSite *site)
Definition: netutils.cpp:644
MythNewsEditor::m_titleText
MythUIText * m_titleText
Definition: mythnewseditor.h:38
NewsSite::podcast
bool podcast(void) const
Definition: newssite.cpp:108
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:402
MythNewsEditor::Create
bool Create(void) override
Definition: mythnewseditor.cpp:44
MythNewsEditor::m_iconEdit
MythUITextEdit * m_iconEdit
Definition: mythnewseditor.h:46
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
MythNewsEditor::m_lock
QMutex m_lock
Definition: mythnewseditor.h:33
MythNewsEditor::MythNewsEditor
MythNewsEditor(NewsSite *site, bool edit, MythScreenStack *parent, const QString &name="MythNewsEditor")
Creates a new MythNewsEditor Screen.
Definition: mythnewseditor.cpp:29
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
mythdbcon.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
MythUITextEdit::GetText
QString GetText(void) const
Definition: mythuitextedit.h:47
MythNewsEditor::m_podcastCheck
MythUICheckBox * m_podcastCheck
Definition: mythnewseditor.h:51
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:112
MythNewsEditor::m_urlLabelText
MythUIText * m_urlLabelText
Definition: mythnewseditor.h:40
MythUITextEdit::SetText
void SetText(const QString &text, bool moveCursor=true)
Definition: mythuitextedit.cpp:216
mythdate.h
mythnewseditor.h
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:117
removeFromDB
bool removeFromDB(RSSSite *site)
Definition: netutils.cpp:686
MythUIButton::SetText
void SetText(const QString &msg)
Definition: mythuibutton.cpp:226
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:222
MythNewsEditor::m_okButton
MythUIButton * m_okButton
Definition: mythnewseditor.h:48
NewsSite::name
QString name(void) const
Definition: newssite.cpp:96
MythNewsEditor::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythnewseditor.cpp:110
MythUIStateType::Full
@ Full
Definition: mythuistatetype.h:25
MythNewsEditor::Save
void Save(void)
Definition: mythnewseditor.cpp:124
MythNewsEditor::m_editing
bool m_editing
Definition: mythnewseditor.h:36
NewsSite
Definition: newssite.h:53
UIUtilDisp::Assign
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
newssite.h
MythNewsEditor::m_nameEdit
MythUITextEdit * m_nameEdit
Definition: mythnewseditor.h:44
MythNewsEditor::m_site
NewsSite * m_site
Definition: mythnewseditor.h:34
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:414
mythuitextedit.h
MythUICheckBox::SetCheckState
void SetCheckState(MythUIStateType::StateType state)
Definition: mythuicheckbox.cpp:66
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:692
MythNewsEditor::m_siteName
QString m_siteName
Definition: mythnewseditor.h:35
MythNewsEditor::m_urlEdit
MythUITextEdit * m_urlEdit
Definition: mythnewseditor.h:45
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:134
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
MythNewsEditor::m_cancelButton
MythUIButton * m_cancelButton
Definition: mythnewseditor.h:49
mythuibutton.h
mythuicheckbox.h
MythUICheckBox::GetCheckState
MythUIStateType::StateType GetCheckState() const
Definition: mythuicheckbox.cpp:98
mythmainwindow.h
MythNewsEditor::~MythNewsEditor
~MythNewsEditor() override
Definition: mythnewseditor.cpp:39
MythNewsEditor::m_podcastLabelText
MythUIText * m_podcastLabelText
Definition: mythnewseditor.h:42