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 }
bool podcast(void) const
Definition: newssite.cpp:108
QString name(void) const
Definition: newssite.cpp:96
MythUIStateType::StateType GetCheckState() const
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
NewsSite * m_site
bool insertInDB(RSSSite *site)
Definition: netutils.cpp:640
MythUITextEdit * m_nameEdit
MythUICheckBox * m_podcastCheck
bool keyPressEvent(QKeyEvent *) override
Key event handler.
QString m_siteName
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:135
MythUIButton * m_cancelButton
void BuildFocusList(void)
virtual void Close()
MythUIText * m_urlLabelText
MythUITextEdit * m_iconEdit
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
MythUIText * m_titleText
const char * name
Definition: ParseText.cpp:328
bool Create(void) override
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
void SetText(const QString &text, bool moveCursor=true)
MythUIType * GetFocusWidget(void) const
MythMainWindow * GetMythMainWindow(void)
QString url(void) const
Definition: newssite.cpp:90
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
MythNewsEditor(NewsSite *site, bool edit, MythScreenStack *parent, const QString &name="MythNewsEditor")
Creates a new MythNewsEditor Screen.
QString imageURL(void) const
Definition: newssite.cpp:128
void SetCheckState(MythUIStateType::StateType state)
bool removeFromDB(RSSSite *site)
Definition: netutils.cpp:682
bool SetFocusWidget(MythUIType *widget=nullptr)
MythUITextEdit * m_urlEdit
Screen in which all other widgets are contained and rendered.
MythUIText * m_podcastLabelText
void SetText(const QString &msg)
MythUIButton * m_okButton
MythUIText * m_nameLabelText
MythUIText * m_iconLabelText
QString GetText(void) const