00001
00002
00003 #include <mythuibutton.h>
00004 #include <mythuitext.h>
00005 #include <mythuitextedit.h>
00006 #include <mythuicheckbox.h>
00007 #include <mythmainwindow.h>
00008 #include <mythdialogbox.h>
00009 #include <mythmiscutil.h>
00010 #include <mythcontext.h>
00011 #include <mythdbcon.h>
00012
00013
00014 #include "mythnewseditor.h"
00015 #include "newsdbutil.h"
00016 #include "newssite.h"
00017
00018 #define LOC QString("MythNewsEditor: ")
00019 #define LOC_WARN QString("MythNewsEditor, Warning: ")
00020 #define LOC_ERR QString("MythNewsEditor, Error: ")
00021
00026 MythNewsEditor::MythNewsEditor(NewsSite *site, bool edit,
00027 MythScreenStack *parent,
00028 const QString &name) :
00029 MythScreenType(parent, name),
00030 m_lock(QMutex::Recursive),
00031 m_site(site),
00032 m_siteName((edit && site) ? site->name() : QString()),
00033 m_editing(edit),
00034 m_titleText(NULL), m_nameLabelText(NULL),
00035 m_urlLabelText(NULL), m_iconLabelText(NULL),
00036 m_podcastLabelText(NULL),
00037 m_nameEdit(NULL), m_urlEdit(NULL),
00038 m_iconEdit(NULL),
00039 m_okButton(NULL), m_cancelButton(NULL),
00040 m_podcastCheck(NULL)
00041 {
00042 }
00043
00044 MythNewsEditor::~MythNewsEditor()
00045 {
00046 QMutexLocker locker(&m_lock);
00047 }
00048
00049 bool MythNewsEditor::Create(void)
00050 {
00051 QMutexLocker locker(&m_lock);
00052
00053
00054 bool foundtheme = LoadWindowFromXML("news-ui.xml", "editor", this);
00055
00056 if (!foundtheme)
00057 return false;
00058
00059 bool err = false;
00060 UIUtilW::Assign(this, m_titleText, "title", &err);
00061 UIUtilW::Assign(this, m_nameLabelText, "namelabel", &err);
00062 UIUtilW::Assign(this, m_urlLabelText, "urllabel", &err);
00063 UIUtilW::Assign(this, m_iconLabelText, "iconlabel", &err);
00064 UIUtilW::Assign(this, m_podcastLabelText, "podcastlabel", &err);
00065 UIUtilE::Assign(this, m_nameEdit, "name", &err);
00066 UIUtilE::Assign(this, m_urlEdit, "url", &err);
00067 UIUtilE::Assign(this, m_iconEdit, "icon", &err);
00068 UIUtilE::Assign(this, m_podcastCheck, "podcast_check", &err);
00069 UIUtilE::Assign(this, m_okButton, "ok", &err);
00070 UIUtilE::Assign(this, m_cancelButton, "cancel", &err);
00071
00072 if (err)
00073 {
00074 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'editor'");
00075 return false;
00076 }
00077
00078 if (m_titleText)
00079 {
00080 m_titleText->SetText(
00081 (m_editing) ? tr("Edit Site Details") : tr("Enter Site Details"));
00082 }
00083
00084 if (m_nameLabelText)
00085 m_nameLabelText->SetText(tr("Name:"));
00086 if (m_urlLabelText)
00087 m_urlLabelText->SetText(tr("URL:"));
00088 if (m_iconLabelText)
00089 m_iconLabelText->SetText(tr("Icon:"));
00090 if (m_podcastLabelText)
00091 m_podcastLabelText->SetText(tr("Podcast:"));
00092
00093 m_okButton->SetText(tr("OK"));
00094 m_cancelButton->SetText(tr("Cancel"));
00095
00096 connect(m_okButton, SIGNAL(Clicked()), this, SLOT(Save()));
00097 connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Close()));
00098
00099 if (m_editing)
00100 {
00101 m_nameEdit->SetText(m_site->name());
00102 m_urlEdit->SetText(m_site->url());
00103 m_iconEdit->SetText(m_site->imageURL());
00104 if (m_site->podcast() == 1)
00105 m_podcastCheck->SetCheckState(MythUIStateType::Full);
00106 }
00107
00108 BuildFocusList();
00109
00110 SetFocusWidget(m_nameEdit);
00111
00112 return true;
00113 }
00114
00115 bool MythNewsEditor::keyPressEvent(QKeyEvent *event)
00116 {
00117 if (GetFocusWidget()->keyPressEvent(event))
00118 return true;
00119
00120 bool handled = false;
00121 QStringList actions;
00122 handled = GetMythMainWindow()->TranslateKeyPress("News", event, actions);
00123
00124 if (!handled && MythScreenType::keyPressEvent(event))
00125 handled = true;
00126
00127 return handled;
00128 }
00129
00130 void MythNewsEditor::Save(void)
00131 {
00132 {
00133 QMutexLocker locker(&m_lock);
00134
00135 if (m_editing && !m_siteName.isEmpty())
00136 removeFromDB(m_siteName);
00137
00138 insertInDB(m_nameEdit->GetText(), m_urlEdit->GetText(),
00139 m_iconEdit->GetText(), "custom",
00140 (m_podcastCheck->GetCheckState() == MythUIStateType::Full));
00141 }
00142 Close();
00143 }