Ticket #8398: mythbrowser-custom-homepage-new.patch
File mythbrowser-custom-homepage-new.patch, 14.6 KB (added by , 14 years ago) |
---|
-
mythbrowser/mythbrowser/bookmarkmanager.cpp
226 226 m_bookmarkList, "", "", true, MythUIButtonListItem::NotChecked); 227 227 item->SetText(site->name, "name"); 228 228 item->SetText(site->url, "url"); 229 if (site->isHomepage) 230 item->DisplayState("yes", "homepage"); 229 231 item->SetData(qVariantFromValue(site)); 230 232 item->setChecked(site->selected ? 231 233 MythUIButtonListItem::FullChecked : MythUIButtonListItem::NotChecked); … … 279 281 280 282 m_menuPopup->SetReturnEvent(this, "action"); 281 283 284 m_menuPopup->AddButton(tr("Set Homepage"), SLOT(slotSetHomepage())); 282 285 m_menuPopup->AddButton(tr("Add Bookmark"), SLOT(slotAddBookmark())); 283 286 284 287 if (m_bookmarkList->GetItemCurrent()) … … 295 298 m_menuPopup->AddButton(tr("Clear Marked"), SLOT(slotClearMarked())); 296 299 } 297 300 301 m_menuPopup->AddButton(tr("Settings"), SLOT(slotSettings())); 298 302 m_menuPopup->AddButton(tr("Cancel")); 299 303 300 304 popupStack->AddScreen(m_menuPopup); … … 455 459 } 456 460 } 457 461 462 void 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 471 void 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 458 509 void BookmarkManager::slotAddBookmark(void) 459 510 { 460 511 ShowEditDialog(false); … … 514 565 if (GetMarkedCount() == 0) 515 566 return; 516 567 517 568 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); 518 569 519 570 QString message = tr("Are you sure you want to delete the marked bookmarks"); 520 571 -
mythbrowser/mythbrowser/bookmarkeditor.h
5 5 #include <mythscreentype.h> 6 6 #include <mythdialogbox.h> 7 7 #include <mythuibutton.h> 8 #include <mythuicheckbox.h> 8 9 #include <mythuitext.h> 9 10 #include <mythuitextedit.h> 10 11 … … 38 39 MythUITextEdit *m_categoryEdit; 39 40 MythUITextEdit *m_nameEdit; 40 41 MythUITextEdit *m_urlEdit; 42 MythUICheckBox *m_isHomepage; 41 43 42 44 MythUIButton *m_okButton; 43 45 MythUIButton *m_cancelButton; -
mythbrowser/mythbrowser/main.cpp
42 42 return 0; 43 43 } 44 44 45 void 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 */ 55 void 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 45 97 void setupKeys(void) 46 98 { 47 99 REG_KEY("Browser", "NEXTTAB", QT_TRANSLATE_NOOP("MythControls", … … 49 101 REG_KEY("Browser", "PREVTAB", QT_TRANSLATE_NOOP("MythControls", 50 102 "Move to previous browser tab"), ""); 51 103 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 52 109 REG_MEDIAPLAYER("WebBrowser", QT_TRANSLATE_NOOP("MythControls", 53 110 "Internal Web Browser"), handleMedia); 54 111 } -
mythbrowser/mythbrowser/bookmarkmanager.h
22 22 category = ""; 23 23 name = ""; 24 24 url = ""; 25 isHomepage = false; 25 26 selected = false; 26 27 } 27 28 28 29 QString category; 29 30 QString name; 30 31 QString url; 32 bool isHomepage; 31 33 bool selected; 32 34 33 35 inline bool operator == (const Bookmark &b) const … … 82 84 void slotDoDeleteMarked(bool doDelete); 83 85 void slotBrowserClosed(void); 84 86 87 void slotSettings(void); 88 void slotSetHomepage(void); 85 89 void slotAddBookmark(void); 86 90 void slotEditBookmark(void); 87 91 void slotDeleteCurrent(void); -
mythbrowser/mythbrowser/browserdbutil.cpp
9 9 #include "browserdbutil.h" 10 10 #include "bookmarkmanager.h" 11 11 12 const QString currentDatabaseVersion = "100 2";12 const QString currentDatabaseVersion = "1003"; 13 13 14 14 static bool UpdateDBVersionNumber(const QString &newnumber) 15 15 { … … 110 110 return false; 111 111 } 112 112 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 113 124 return true; 114 125 } 115 126 … … 134 145 if (!site) 135 146 return false; 136 147 137 return InsertInDB(site->category, site->name, site->url );148 return InsertInDB(site->category, site->name, site->url, site->isHomepage); 138 149 } 139 150 140 151 bool InsertInDB(const QString &category, 141 const QString &name, const QString &url) 152 const QString &name, 153 const QString &url, 154 const bool &isHomepage) 142 155 { 143 156 if (category.isEmpty() || name.isEmpty() || url.isEmpty()) 144 157 return false; … … 154 167 _url.replace("&","&"); 155 168 156 169 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);"); 159 172 query.bindValue(":CATEGORY", category); 160 173 query.bindValue(":NAME", name); 161 174 query.bindValue(":URL", _url); 175 query.bindValue(":HOMEPAGE", isHomepage); 162 176 if (!query.exec()) 163 177 { 164 178 MythDB::DBError("mythbrowser: inserting in DB", query); … … 221 235 222 236 MSqlQuery query(MSqlQuery::InitCon()); 223 237 224 if (!query.exec("SELECT category, name, url FROM websites "238 if (!query.exec("SELECT category, name, url, homepage FROM websites " 225 239 "ORDER BY category, name")) 226 240 { 227 241 VERBOSE(VB_IMPORTANT, "BookmarkManager: Error in loading from DB"); … … 234 248 site->category = query.value(0).toString(); 235 249 site->name = query.value(1).toString(); 236 250 site->url = query.value(2).toString(); 251 site->isHomepage = query.value(3).toBool(); 237 252 site->selected = false; 238 253 siteList.append(site); 239 254 } -
mythbrowser/mythbrowser/bookmarkeditor.cpp
23 23 m_siteCategory(), m_editing(edit), 24 24 m_titleText(NULL), m_categoryEdit(NULL), 25 25 m_nameEdit(NULL), m_urlEdit(NULL), 26 m_isHomepage(NULL), 26 27 m_okButton(NULL), m_cancelButton(NULL), 27 28 m_findCategoryButton(NULL), m_searchDialog(NULL) 28 29 { … … 39 40 40 41 bool BookmarkEditor::Create() 41 42 { 42 43 43 bool foundtheme = false; 44 44 45 45 // Load the theme for this screen … … 61 61 m_categoryEdit = dynamic_cast<MythUITextEdit *> (GetChild("category")); 62 62 m_nameEdit = dynamic_cast<MythUITextEdit *> (GetChild("name")); 63 63 m_urlEdit = dynamic_cast<MythUITextEdit *> (GetChild("url")); 64 m_isHomepage = dynamic_cast<MythUICheckBox *> (GetChild("homepage")); 64 65 65 66 m_okButton = dynamic_cast<MythUIButton *> (GetChild("ok")); 66 67 m_cancelButton = dynamic_cast<MythUIButton *> (GetChild("cancel")); 67 68 68 69 m_findCategoryButton = dynamic_cast<MythUIButton *> (GetChild("findcategory")); 69 70 70 if (!m_categoryEdit || !m_nameEdit || !m_urlEdit || !m_okButton71 if (!m_categoryEdit || !m_nameEdit || !m_urlEdit || !m_isHomepage || !m_okButton 71 72 || !m_cancelButton || !m_findCategoryButton) 72 73 { 73 74 VERBOSE(VB_IMPORTANT, "Theme is missing critical theme elements."); … … 83 84 m_categoryEdit->SetText(m_site->category); 84 85 m_nameEdit->SetText(m_site->name); 85 86 m_urlEdit->SetText(m_site->url); 87 88 if (m_site->isHomepage) 89 m_isHomepage->SetCheckState(MythUIStateType::Full); 86 90 } 87 91 88 92 BuildFocusList(); … … 117 121 if (m_editing && m_siteCategory != "" && m_siteName != "") 118 122 RemoveFromDB(m_siteCategory, m_siteName); 119 123 120 InsertInDB(m_categoryEdit->GetText(), m_nameEdit->GetText(), m_urlEdit->GetText());124 bool isHomepage = (m_isHomepage->GetCheckState() == MythUIStateType::Full) ? true : false; 121 125 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 122 136 if (m_site) 123 137 { 124 138 m_site->category = m_categoryEdit->GetText(); 125 139 m_site->name = m_nameEdit->GetText(); 126 140 m_site->url = m_urlEdit->GetText(); 141 m_site->isHomepage = isHomepage; 127 142 } 128 143 129 144 Exit(); -
mythbrowser/mythbrowser/browserdbutil.h
9 9 10 10 bool FindInDB(const QString &category, const QString& name); 11 11 bool InsertInDB(Bookmark *site); 12 bool InsertInDB(const QString &category, const QString &name, const QString &url );12 bool InsertInDB(const QString &category, const QString &name, const QString &url, const bool &isHomepage); 13 13 14 14 bool RemoveFromDB(Bookmark *site); 15 15 bool RemoveFromDB(const QString &category, const QString &name); -
mythbrowser/theme/default/browser-ui.xml
245 245 <position>195,340</position> 246 246 </textedit> 247 247 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 248 258 <button name="cancel" from="basebutton"> 249 <position>60, 480</position>259 <position>60,530</position> 250 260 <value>Cancel</value> 251 261 </button> 252 262 253 263 <button name="ok" from="basebutton"> 254 <position>590, 480</position>264 <position>590,530</position> 255 265 <value>Ok</value> 256 266 </button> 257 267 -
mythbrowser/theme/default-wide/browser-ui.xml
248 248 <position>395,340</position> 249 249 </textedit> 250 250 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 251 261 <button name="cancel" from="basebutton"> 252 <position>395, 480</position>262 <position>395,530</position> 253 263 <value>Cancel</value> 254 264 </button> 255 265 256 266 <button name="ok" from="basebutton"> 257 <position>620, 480</position>267 <position>620,530</position> 258 268 <value>Ok</value> 259 269 </button> 260 270