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

File mythbrowser-custom-homepage-new.patch, 14.6 KB (added by Robert S, 14 years ago)

new mythbrowser patch for jumppoints and homepage settings

  • 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    // Delete the old bookmark that was set as homepage
     474    MythUIButtonListItem *item;
     475    Bookmark *site;
     476
     477    // Search all bookmarks and unset the homepage information
     478    // form the one that has is actively set
     479    for (int x = 0; x < m_bookmarkList->GetCount(); x++)
     480    {
     481        item = m_bookmarkList->GetItemAt(x);
     482        if (item)
     483        {
     484            site = qVariantValue<Bookmark*>(item->GetData());
     485            if (site && site->isHomepage)
     486            {
     487                site->isHomepage = false;
     488                RemoveFromDB(site);
     489                InsertInDB(site);
     490            }
     491        }
     492    }
     493
     494    // Set the homepage information for selected bookmark
     495    item = m_bookmarkList->GetItemCurrent();
     496    if (item && item->GetData().isValid())
     497    {
     498        site = qVariantValue<Bookmark*>(item->GetData());
     499        if (site)
     500        {
     501            site->isHomepage = true;
     502            RemoveFromDB(site);
     503            InsertInDB(site);
     504        }
     505    }
     506    ReloadBookmarks();
     507}
     508
    458509void BookmarkManager::slotAddBookmark(void)
    459510{
    460511    ShowEditDialog(false);
     
    514565    if (GetMarkedCount() == 0)
    515566        return;
    516567
    517      MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
     568    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
    518569
    519570    QString message = tr("Are you sure you want to delete the marked bookmarks");
    520571
  • 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    bool homepage = false;
     58    QString url = "";
     59
     60    // Get the homepage from the database. The url
     61    // that is set as a homepage starts with a space.
     62    MSqlQuery query(MSqlQuery::InitCon());
     63
     64    if (!query.exec("SELECT homepage,url FROM `websites` WHERE `homepage` = true;"))
     65        VERBOSE(VB_IMPORTANT, "Error loading homepage from DB");
     66
     67    if (query.size() > 0)
     68    {
     69        while (query.next())
     70        {
     71            homepage = query.value(0).toBool();
     72            url = query.value(1).toString();
     73        }
     74    }
     75
     76    if (homepage)
     77    {
     78        handleMedia( url, "", "", "", "", 0, 0, 0, "");
     79    }
     80    else
     81    {
     82        // show a dialog that no homepage is specified
     83        QString message = "No homepage was specified.\n"
     84                          "If required you can do this in the bookmark manager";
     85
     86        MythScreenStack *m_popupStack =
     87                GetMythMainWindow()->GetStack("popup stack");
     88
     89        MythConfirmationDialog *okPopup =
     90                new MythConfirmationDialog(m_popupStack, message, false);
     91
     92        if (okPopup->Create())
     93            m_popupStack->AddScreen(okPopup);
     94    }
     95}
     96
    4597void setupKeys(void)
    4698{
    4799    REG_KEY("Browser", "NEXTTAB", QT_TRANSLATE_NOOP("MythControls",
     
    49101    REG_KEY("Browser", "PREVTAB", QT_TRANSLATE_NOOP("MythControls",
    50102        "Move to previous browser tab"), "");
    51103
     104    REG_JUMP("Bookmarks", QT_TRANSLATE_NOOP("MythControls",
     105        "Show the bookmark manager"), "", runBookmarkManager);
     106    REG_JUMP("Homepage", QT_TRANSLATE_NOOP("MythControls",
     107        "Show the webbrowser homepage"), "", runHomepage);
     108
    52109    REG_MEDIAPLAYER("WebBrowser", QT_TRANSLATE_NOOP("MythControls",
    53110        "Internal Web Browser"), handleMedia);
    54111}
  • 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
     
    134145    if (!site)
    135146        return false;
    136147
    137     return InsertInDB(site->category, site->name, site->url);
     148    return InsertInDB(site->category, site->name, site->url, site->isHomepage);
    138149}
    139150
    140151bool InsertInDB(const QString &category,
    141                 const QString &name, const QString &url)
     152                const QString &name,
     153                const QString &url,
     154                const bool &isHomepage)
    142155{
    143156    if (category.isEmpty() || name.isEmpty() || url.isEmpty())
    144157        return false;
     
    154167    _url.replace("&amp;","&");
    155168
    156169    MSqlQuery query(MSqlQuery::InitCon());
    157     query.prepare("INSERT INTO websites (category, name, url) "
    158                   "VALUES(:CATEGORY, :NAME, :URL);");
     170    query.prepare("INSERT INTO websites (category, name, url, homepage) "
     171                  "VALUES(:CATEGORY, :NAME, :URL, :HOMEPAGE);");
    159172    query.bindValue(":CATEGORY", category);
    160173    query.bindValue(":NAME", name);
    161174    query.bindValue(":URL", _url);
     175    query.bindValue(":HOMEPAGE", isHomepage);
    162176    if (!query.exec())
    163177    {
    164178        MythDB::DBError("mythbrowser: inserting in DB", query);
     
    221235
    222236    MSqlQuery query(MSqlQuery::InitCon());
    223237
    224     if (!query.exec("SELECT category, name, url FROM websites "
     238    if (!query.exec("SELECT category, name, url, homepage FROM websites "
    225239               "ORDER BY category, name"))
    226240    {
    227241        VERBOSE(VB_IMPORTANT, "BookmarkManager: Error in loading from DB");
     
    234248            site->category = query.value(0).toString();
    235249            site->name = query.value(1).toString();
    236250            site->url = query.value(2).toString();
     251            site->isHomepage = query.value(3).toBool();
    237252            site->selected = false;
    238253            siteList.append(site);
    239254        }
  • 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    bool isHomepage = (m_isHomepage->GetCheckState() == MythUIStateType::Full) ? true : false;
    121125
     126    // reset the homepage flag of all bookmarks
     127    if (isHomepage)
     128    {
     129        MSqlQuery query(MSqlQuery::InitCon());
     130        if (!query.exec("UPDATE `websites` SET `homepage` = '0' WHERE `homepage` = '1';"))
     131            VERBOSE(VB_IMPORTANT, "Could not reset the homepage flag.");
     132    }
     133
     134    InsertInDB(m_categoryEdit->GetText(), m_nameEdit->GetText(), m_urlEdit->GetText(), isHomepage );
     135   
    122136    if (m_site)
    123137    {
    124138        m_site->category = m_categoryEdit->GetText();
    125139        m_site->name = m_nameEdit->GetText();
    126140        m_site->url = m_urlEdit->GetText();
     141        m_site->isHomepage = isHomepage;
    127142    }
    128143
    129144    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
    1414bool RemoveFromDB(Bookmark *site);
    1515bool RemoveFromDB(const QString &category, const QString &name);
  • 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