Ticket #8398: mythbrowser-custom-homepage-new2.patch
File mythbrowser-custom-homepage-new2.patch, 14.3 KB (added by , 15 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 // 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 458 487 void BookmarkManager::slotAddBookmark(void) 459 488 { 460 489 ShowEditDialog(false); … … 514 543 if (GetMarkedCount() == 0) 515 544 return; 516 545 517 546 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); 518 547 519 548 QString message = tr("Are you sure you want to delete the marked bookmarks"); 520 549 -
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 // 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 45 86 void setupKeys(void) 46 87 { 47 88 REG_KEY("Browser", "NEXTTAB", QT_TRANSLATE_NOOP("MythControls", … … 49 90 REG_KEY("Browser", "PREVTAB", QT_TRANSLATE_NOOP("MythControls", 50 91 "Move to previous browser tab"), ""); 51 92 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 52 98 REG_MEDIAPLAYER("WebBrowser", QT_TRANSLATE_NOOP("MythControls", 53 99 "Internal Web Browser"), handleMedia); 54 100 } -
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 … … 129 140 return (query.size() > 0); 130 141 } 131 142 143 bool 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 151 bool 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 132 163 bool InsertInDB(Bookmark* site) 133 164 { 134 165 if (!site) 135 166 return false; 136 167 137 return InsertInDB(site->category, site->name, site->url );168 return InsertInDB(site->category, site->name, site->url, site->isHomepage); 138 169 } 139 170 140 171 bool InsertInDB(const QString &category, 141 const QString &name, const QString &url) 172 const QString &name, 173 const QString &url, 174 const bool &isHomepage) 142 175 { 143 176 if (category.isEmpty() || name.isEmpty() || url.isEmpty()) 144 177 return false; … … 154 187 _url.replace("&","&"); 155 188 156 189 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);"); 159 192 query.bindValue(":CATEGORY", category); 160 193 query.bindValue(":NAME", name); 161 194 query.bindValue(":URL", _url); 195 query.bindValue(":HOMEPAGE", isHomepage); 162 196 if (!query.exec()) 163 197 { 164 198 MythDB::DBError("mythbrowser: inserting in DB", query); … … 221 255 222 256 MSqlQuery query(MSqlQuery::InitCon()); 223 257 224 if (!query.exec("SELECT category, name, url FROM websites "258 if (!query.exec("SELECT category, name, url, homepage FROM websites " 225 259 "ORDER BY category, name")) 226 260 { 227 261 VERBOSE(VB_IMPORTANT, "BookmarkManager: Error in loading from DB"); … … 234 268 site->category = query.value(0).toString(); 235 269 site->name = query.value(1).toString(); 236 270 site->url = query.value(2).toString(); 271 site->isHomepage = query.value(3).toBool(); 237 272 site->selected = false; 238 273 siteList.append(site); 239 274 } -
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 ResetHomepageFromDB(); 121 125 126 bool isHomepage = (m_isHomepage->GetCheckState() == MythUIStateType::Full) ? true : false; 127 InsertInDB(m_categoryEdit->GetText(), m_nameEdit->GetText(), m_urlEdit->GetText(), isHomepage ); 128 122 129 if (m_site) 123 130 { 124 131 m_site->category = m_categoryEdit->GetText(); 125 132 m_site->name = m_nameEdit->GetText(); 126 133 m_site->url = m_urlEdit->GetText(); 134 m_site->isHomepage = isHomepage; 127 135 } 128 136 129 137 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 bool ResetHomepageFromDB(); 15 bool UpdateHomepageInDB(Bookmark* site); 16 14 17 bool RemoveFromDB(Bookmark *site); 15 18 bool RemoveFromDB(const QString &category, const QString &name); 16 19 -
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