Ticket #8398: mythbrowser-custom-homepage-new2.patch

File mythbrowser-custom-homepage-new2.patch, 14.3 KB (added by Robert S, 9 years ago)

simplified the logic

  • mythbrowser/mythbrowser/bookmarkmanager.cpp

     
    226226                    m_bookmarkList, "", "", true, MythUIButtonListItem::NotChecked);
    227227            item->SetText(site->name, "name");
    228228            item->SetText(site->url, "url");
     229            if (site->isHomepage)
     230                item->DisplayState("yes", "homepage");
    229231            item->SetData(qVariantFromValue(site));
    230232            item->setChecked(site->selected ?
    231233                    MythUIButtonListItem::FullChecked : MythUIButtonListItem::NotChecked);
     
    279281
    280282            m_menuPopup->SetReturnEvent(this, "action");
    281283
     284            m_menuPopup->AddButton(tr("Set Homepage"), SLOT(slotSetHomepage()));
    282285            m_menuPopup->AddButton(tr("Add Bookmark"), SLOT(slotAddBookmark()));
    283286
    284287            if (m_bookmarkList->GetItemCurrent())
     
    295298                m_menuPopup->AddButton(tr("Clear Marked"), SLOT(slotClearMarked()));
    296299            }
    297300
     301            m_menuPopup->AddButton(tr("Settings"), SLOT(slotSettings()));
    298302            m_menuPopup->AddButton(tr("Cancel"));
    299303
    300304            popupStack->AddScreen(m_menuPopup);
     
    455459    }
    456460}
    457461
     462void BookmarkManager::slotSettings(void)
     463{
     464    MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
     465    BrowserConfig *config = new BrowserConfig(mainStack, "browserconfig");
     466
     467    if (config->Create())
     468        mainStack->AddScreen(config);
     469}
     470
     471void BookmarkManager::slotSetHomepage(void)
     472{
     473    // Clear all homepage information
     474    ResetHomepageFromDB();
     475
     476    // Set the homepage information for selected bookmark
     477    MythUIButtonListItem *item = m_bookmarkList->GetItemCurrent();
     478    if (item && item->GetData().isValid())
     479    {
     480        Bookmark *site = qVariantValue<Bookmark*>(item->GetData());
     481        if (site)
     482            UpdateHomepageInDB(site);
     483    }
     484    ReloadBookmarks();
     485}
     486
    458487void BookmarkManager::slotAddBookmark(void)
    459488{
    460489    ShowEditDialog(false);
     
    514543    if (GetMarkedCount() == 0)
    515544        return;
    516545
    517      MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
     546    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
    518547
    519548    QString message = tr("Are you sure you want to delete the marked bookmarks");
    520549
  • mythbrowser/mythbrowser/bookmarkeditor.h

     
    55#include <mythscreentype.h>
    66#include <mythdialogbox.h>
    77#include <mythuibutton.h>
     8#include <mythuicheckbox.h>
    89#include <mythuitext.h>
    910#include <mythuitextedit.h>
    1011
     
    3839    MythUITextEdit *m_categoryEdit;
    3940    MythUITextEdit *m_nameEdit;
    4041    MythUITextEdit *m_urlEdit;
     42    MythUICheckBox *m_isHomepage;
    4143
    4244    MythUIButton *m_okButton;
    4345    MythUIButton *m_cancelButton;
  • mythbrowser/mythbrowser/main.cpp

     
    4242    return 0;
    4343}
    4444
     45void runBookmarkManager()
     46{
     47    mythplugin_run();
     48}
     49
     50/** \fn runHomepage()
     51 *  \brief Loads the specified homepage from the database (the name starts
     52           with an underscore) and calls handleMedia() if it exists.
     53 *  \return void.
     54 */
     55void runHomepage()
     56{
     57    // Get the homepage from the database. The url
     58    // that is set as a homepage starts with a space.
     59    MSqlQuery query(MSqlQuery::InitCon());
     60
     61    if (!query.exec("SELECT url FROM `websites` WHERE `homepage` = true;"))
     62        VERBOSE(VB_IMPORTANT, "Error loading homepage from DB");
     63
     64    if (query.size() > 0)
     65    {
     66        query.next();
     67        handleMedia( query.value(0).toString(), "", "", "", "", 0, 0, 0, "");
     68    }
     69    else
     70    {
     71        // show a dialog that no homepage is specified
     72        QString message = "No homepage was specified.\n"
     73                          "If required you can do this in the bookmark manager";
     74
     75        MythScreenStack *m_popupStack =
     76                GetMythMainWindow()->GetStack("popup stack");
     77
     78        MythConfirmationDialog *okPopup =
     79                new MythConfirmationDialog(m_popupStack, message, false);
     80
     81        if (okPopup->Create())
     82            m_popupStack->AddScreen(okPopup);
     83    }
     84}
     85
    4586void setupKeys(void)
    4687{
    4788    REG_KEY("Browser", "NEXTTAB", QT_TRANSLATE_NOOP("MythControls",
     
    4990    REG_KEY("Browser", "PREVTAB", QT_TRANSLATE_NOOP("MythControls",
    5091        "Move to previous browser tab"), "");
    5192
     93    REG_JUMP("Bookmarks", QT_TRANSLATE_NOOP("MythControls",
     94        "Show the bookmark manager"), "", runBookmarkManager);
     95    REG_JUMP("Homepage", QT_TRANSLATE_NOOP("MythControls",
     96        "Show the webbrowser homepage"), "", runHomepage);
     97
    5298    REG_MEDIAPLAYER("WebBrowser", QT_TRANSLATE_NOOP("MythControls",
    5399        "Internal Web Browser"), handleMedia);
    54100}
  • mythbrowser/mythbrowser/bookmarkmanager.h

     
    2222        category = "";
    2323        name = "";
    2424        url = "";
     25        isHomepage = false;
    2526        selected = false;
    2627    }
    2728
    2829    QString category;
    2930    QString name;
    3031    QString url;
     32    bool    isHomepage;
    3133    bool    selected;
    3234
    3335    inline bool operator == (const Bookmark &b) const
     
    8284    void slotDoDeleteMarked(bool doDelete);
    8385    void slotBrowserClosed(void);
    8486
     87    void slotSettings(void);
     88    void slotSetHomepage(void);
    8589    void slotAddBookmark(void);
    8690    void slotEditBookmark(void);
    8791    void slotDeleteCurrent(void);
  • mythbrowser/mythbrowser/browserdbutil.cpp

     
    99#include "browserdbutil.h"
    1010#include "bookmarkmanager.h"
    1111
    12 const QString currentDatabaseVersion = "1002";
     12const QString currentDatabaseVersion = "1003";
    1313
    1414static bool UpdateDBVersionNumber(const QString &newnumber)
    1515{
     
    110110            return false;
    111111    }
    112112
     113    if (dbver == "1002")
     114    {
     115        const QString updates[] =
     116        {
     117            "ALTER TABLE `websites` ADD `homepage` BOOL NOT NULL;",
     118            ""
     119        };
     120        if (!performActualUpdate(updates, "1003", dbver))
     121            return false;
     122    }
     123
    113124    return true;
    114125}
    115126
     
    129140    return (query.size() > 0);
    130141}
    131142
     143bool ResetHomepageFromDB()
     144{
     145    MSqlQuery query(MSqlQuery::InitCon());
     146    query.prepare("UPDATE `websites` SET `homepage` = '0' WHERE `homepage` = '1';");
     147
     148    return query.exec();
     149}
     150
     151bool UpdateHomepageInDB(Bookmark* site)
     152{
     153    MSqlQuery query(MSqlQuery::InitCon());
     154    query.prepare("UPDATE `websites` SET `homepage` = '1' "
     155                  "WHERE `category` = :CATEGORY "
     156                  "AND `name` = :NAME;");
     157    query.bindValue(":CATEGORY", site->category);
     158    query.bindValue(":NAME", site->name);
     159
     160    return query.exec();
     161}
     162
    132163bool InsertInDB(Bookmark* site)
    133164{
    134165    if (!site)
    135166        return false;
    136167
    137     return InsertInDB(site->category, site->name, site->url);
     168    return InsertInDB(site->category, site->name, site->url, site->isHomepage);
    138169}
    139170
    140171bool InsertInDB(const QString &category,
    141                 const QString &name, const QString &url)
     172                const QString &name,
     173                const QString &url,
     174                const bool &isHomepage)
    142175{
    143176    if (category.isEmpty() || name.isEmpty() || url.isEmpty())
    144177        return false;
     
    154187    _url.replace("&amp;","&");
    155188
    156189    MSqlQuery query(MSqlQuery::InitCon());
    157     query.prepare("INSERT INTO websites (category, name, url) "
    158                   "VALUES(:CATEGORY, :NAME, :URL);");
     190    query.prepare("INSERT INTO websites (category, name, url, homepage) "
     191                  "VALUES(:CATEGORY, :NAME, :URL, :HOMEPAGE);");
    159192    query.bindValue(":CATEGORY", category);
    160193    query.bindValue(":NAME", name);
    161194    query.bindValue(":URL", _url);
     195    query.bindValue(":HOMEPAGE", isHomepage);
    162196    if (!query.exec())
    163197    {
    164198        MythDB::DBError("mythbrowser: inserting in DB", query);
     
    221255
    222256    MSqlQuery query(MSqlQuery::InitCon());
    223257
    224     if (!query.exec("SELECT category, name, url FROM websites "
     258    if (!query.exec("SELECT category, name, url, homepage FROM websites "
    225259               "ORDER BY category, name"))
    226260    {
    227261        VERBOSE(VB_IMPORTANT, "BookmarkManager: Error in loading from DB");
     
    234268            site->category = query.value(0).toString();
    235269            site->name = query.value(1).toString();
    236270            site->url = query.value(2).toString();
     271            site->isHomepage = query.value(3).toBool();
    237272            site->selected = false;
    238273            siteList.append(site);
    239274        }
  • mythbrowser/mythbrowser/bookmarkeditor.cpp

     
    2323      m_siteCategory(),           m_editing(edit),
    2424      m_titleText(NULL),          m_categoryEdit(NULL),
    2525      m_nameEdit(NULL),           m_urlEdit(NULL),
     26      m_isHomepage(NULL),
    2627      m_okButton(NULL),           m_cancelButton(NULL),
    2728      m_findCategoryButton(NULL), m_searchDialog(NULL)
    2829{
     
    3940
    4041bool BookmarkEditor::Create()
    4142{
    42 
    4343    bool foundtheme = false;
    4444
    4545    // Load the theme for this screen
     
    6161    m_categoryEdit = dynamic_cast<MythUITextEdit *> (GetChild("category"));
    6262    m_nameEdit = dynamic_cast<MythUITextEdit *> (GetChild("name"));
    6363    m_urlEdit = dynamic_cast<MythUITextEdit *> (GetChild("url"));
     64    m_isHomepage = dynamic_cast<MythUICheckBox *> (GetChild("homepage"));
    6465
    6566    m_okButton = dynamic_cast<MythUIButton *> (GetChild("ok"));
    6667    m_cancelButton = dynamic_cast<MythUIButton *> (GetChild("cancel"));
    6768
    6869    m_findCategoryButton = dynamic_cast<MythUIButton *> (GetChild("findcategory"));
    6970
    70     if (!m_categoryEdit || !m_nameEdit || !m_urlEdit || !m_okButton
     71    if (!m_categoryEdit || !m_nameEdit || !m_urlEdit || !m_isHomepage || !m_okButton
    7172        || !m_cancelButton || !m_findCategoryButton)
    7273    {
    7374        VERBOSE(VB_IMPORTANT, "Theme is missing critical theme elements.");
     
    8384        m_categoryEdit->SetText(m_site->category);
    8485        m_nameEdit->SetText(m_site->name);
    8586        m_urlEdit->SetText(m_site->url);
     87
     88        if (m_site->isHomepage)
     89            m_isHomepage->SetCheckState(MythUIStateType::Full);
    8690    }
    8791
    8892    BuildFocusList();
     
    117121    if (m_editing && m_siteCategory != "" && m_siteName != "")
    118122        RemoveFromDB(m_siteCategory, m_siteName);
    119123
    120     InsertInDB(m_categoryEdit->GetText(), m_nameEdit->GetText(), m_urlEdit->GetText());
     124    ResetHomepageFromDB();
    121125
     126    bool isHomepage = (m_isHomepage->GetCheckState() == MythUIStateType::Full) ? true : false;
     127    InsertInDB(m_categoryEdit->GetText(), m_nameEdit->GetText(), m_urlEdit->GetText(), isHomepage );
     128   
    122129    if (m_site)
    123130    {
    124131        m_site->category = m_categoryEdit->GetText();
    125132        m_site->name = m_nameEdit->GetText();
    126133        m_site->url = m_urlEdit->GetText();
     134        m_site->isHomepage = isHomepage;
    127135    }
    128136
    129137    Exit();
  • mythbrowser/mythbrowser/browserdbutil.h

     
    99
    1010bool FindInDB(const QString &category, const QString& name);
    1111bool InsertInDB(Bookmark *site);
    12 bool InsertInDB(const QString &category, const QString &name, const QString &url);
     12bool InsertInDB(const QString &category, const QString &name, const QString &url, const bool &isHomepage);
    1313
     14bool ResetHomepageFromDB();
     15bool UpdateHomepageInDB(Bookmark* site);
     16
    1417bool RemoveFromDB(Bookmark *site);
    1518bool RemoveFromDB(const QString &category, const QString &name);
    1619
  • mythbrowser/theme/default/browser-ui.xml

     
    245245            <position>195,340</position>
    246246        </textedit>
    247247
     248        <textarea name="homepagelabel" from="basetextarea">
     249            <area>80,450,100,30</area>
     250            <align>right,vcenter</align>
     251            <value>Homepage:</value>
     252        </textarea>
     253
     254        <checkbox name="homepage" from="basecheckbox">
     255            <position>195,440</position>
     256        </checkbox>
     257
    248258        <button name="cancel" from="basebutton">
    249             <position>60,480</position>
     259            <position>60,530</position>
    250260            <value>Cancel</value>
    251261        </button>
    252262
    253263        <button name="ok" from="basebutton">
    254             <position>590,480</position>
     264            <position>590,530</position>
    255265            <value>Ok</value>
    256266        </button>
    257267
  • mythbrowser/theme/default-wide/browser-ui.xml

     
    248248            <position>395,340</position>
    249249        </textedit>
    250250
     251        <textarea name="homepagelabel" from="basetextarea">
     252            <area>180,450,200,30</area>
     253            <align>right,vcenter</align>
     254            <value>Homepage:</value>
     255        </textarea>
     256
     257        <checkbox name="homepage" from="basecheckbox">
     258            <position>395,440</position>
     259        </checkbox>
     260
    251261        <button name="cancel" from="basebutton">
    252             <position>395,480</position>
     262            <position>395,530</position>
    253263            <value>Cancel</value>
    254264        </button>
    255265
    256266        <button name="ok" from="basebutton">
    257             <position>620,480</position>
     267            <position>620,530</position>
    258268            <value>Ok</value>
    259269        </button>
    260270