MythTV  master
bookmarkeditor.cpp
Go to the documentation of this file.
1 
2 // myth
3 #include <mythmainwindow.h>
4 #include <mythdate.h>
5 #include <mythcontext.h>
6 #include <mythdbcon.h>
7 
8 // mythbrowser
9 #include "bookmarkeditor.h"
10 #include "bookmarkmanager.h"
11 #include "browserdbutil.h"
12 
20  MythScreenStack *parent, const char *name)
21  : MythScreenType (parent, name),
22  m_site(site),
23  m_editing(edit)
24 {
25  if (m_editing)
26  {
29  }
30 }
31 
33 {
34  if (!LoadWindowFromXML("browser-ui.xml", "bookmarkeditor", this))
35  return false;
36 
37  bool err = false;
38 
39  UIUtilW::Assign(this, m_titleText, "title", &err);
40  UIUtilE::Assign(this, m_categoryEdit, "category", &err);
41  UIUtilE::Assign(this, m_nameEdit, "name", &err);
42  UIUtilE::Assign(this, m_urlEdit, "url", &err);
43  UIUtilE::Assign(this, m_isHomepage, "homepage", &err);
44  UIUtilE::Assign(this, m_okButton, "ok", &err);
45  UIUtilE::Assign(this, m_cancelButton, "cancel", &err);
46  UIUtilE::Assign(this, m_findCategoryButton, "findcategory", &err);
47 
48  if (err)
49  {
50  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'bookmarkeditor'");
51  return false;
52  }
53 
54  if (m_titleText)
55  {
56  if (m_editing)
57  m_titleText->SetText(tr("Edit Bookmark Details"));
58  else
59  m_titleText->SetText(tr("Enter Bookmark Details"));
60  }
61 
62  connect(m_okButton, SIGNAL(Clicked()), this, SLOT(Save()));
63  connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Exit()));
64  connect(m_findCategoryButton, SIGNAL(Clicked()), this, SLOT(slotFindCategory()));
65 
66  if (m_editing && m_site)
67  {
71 
72  if (m_site->m_isHomepage)
74  }
75 
77 
79 
80  return true;
81 }
82 
83 bool BookmarkEditor::keyPressEvent(QKeyEvent *event)
84 {
85  if (GetFocusWidget()->keyPressEvent(event))
86  return true;
87 
88  QStringList actions;
89  bool handled = GetMythMainWindow()->TranslateKeyPress("News", event, actions);
90 
91  if (!handled && MythScreenType::keyPressEvent(event))
92  handled = true;
93 
94  return handled;
95 }
96 
98 {
99  Close();
100 }
101 
103 {
104  if (m_editing && m_siteCategory != "" && m_siteName != "")
106 
108 
109  bool isHomepage = m_isHomepage->GetCheckState() == MythUIStateType::Full;
111 
112  if (m_site)
113  {
117  m_site->m_isHomepage = isHomepage;
118  }
119 
120  Exit();
121 }
122 
124 {
125  QStringList list;
126 
127  GetCategoryList(list);
128 
129  QString title = tr("Select a category");
130 
131  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
132 
133  m_searchDialog = new MythUISearchDialog(popupStack, title, list,
134  true, m_categoryEdit->GetText());
135 
136  if (!m_searchDialog->Create())
137  {
138  delete m_searchDialog;
139  m_searchDialog = nullptr;
140  return;
141  }
142 
143  connect(m_searchDialog, SIGNAL(haveResult(QString)), SLOT(slotCategoryFound(QString)));
144 
145  popupStack->AddScreen(m_searchDialog);
146 }
147 
148 void BookmarkEditor::slotCategoryFound(const QString& category)
149 {
150  m_categoryEdit->SetText(category);
151 }
MythUIStateType::StateType GetCheckState() const
bool RemoveFromDB(Bookmark *site)
void slotCategoryFound(const QString &category)
MythUIButton * m_findCategoryButton
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
Bookmark * m_site
QString m_name
MythUITextEdit * m_nameEdit
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:136
MythScreenStack * GetStack(const QString &stackname)
MythUIButton * m_cancelButton
void BuildFocusList(void)
QString m_siteCategory
QString m_siteName
virtual void Close()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
BookmarkEditor(Bookmark *site, bool edit, MythScreenStack *parent, const char *name)
Creates a new BookmarkEditor Screen.
MythUISearchDialog * m_searchDialog
MythUICheckBox * m_isHomepage
bool ResetHomepageFromDB()
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
const char * name
Definition: ParseText.cpp:328
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)
MythUITextEdit * m_urlEdit
QString m_url
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
int GetCategoryList(QStringList &list)
bool Create(void) override
bool InsertInDB(Bookmark *site)
void SetCheckState(MythUIStateType::StateType state)
bool SetFocusWidget(MythUIType *widget=nullptr)
void slotFindCategory(void)
Screen in which all other widgets are contained and rendered.
bool Create(void) override
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
MythUITextEdit * m_categoryEdit
bool m_isHomepage
QString m_category
MythUIText * m_titleText
MythUIButton * m_okButton
Provide a dialog to quickly find an entry in a list.
QString GetText(void) const