Ticket #6856: weather_leaks.patch
File weather_leaks.patch, 18.6 KB (added by , 15 years ago) |
---|
-
mythplugins/mythweather/mythweather/weather.cpp
152 152 { 153 153 mainStack->AddScreen(ssetup); 154 154 } 155 else 156 { 157 delete ssetup; 158 } 155 159 156 160 m_firstSetup = false; 157 161 } … … 169 173 units_t units = db.value(2).toUInt(); 170 174 uint draworder = db.value(3).toUInt(); 171 175 172 ScreenListInfo *screenListInfo = m_allScreens[container];176 ScreenListInfo &screenListInfo = m_allScreens[container]; 173 177 174 WeatherScreen *ws = WeatherScreen::loadScreen(m_weatherStack, screenListInfo, id);178 WeatherScreen *ws = WeatherScreen::loadScreen(m_weatherStack, &screenListInfo, id); 175 179 if (!ws->Create()) 180 { 181 delete ws; 176 182 continue; 183 } 177 184 178 185 ws->setUnits(units); 179 186 ws->setInUse(true); … … 319 326 clearScreens(); 320 327 mainStack->AddScreen(ssetup); 321 328 } 329 else 330 { 331 delete ssetup; 332 } 322 333 323 334 m_firstRun = true; 324 335 } … … 351 362 { 352 363 WeatherScreen *nxt = nextScreen(); 353 364 354 if (nxt ->canShowScreen())365 if (nxt && nxt->canShowScreen()) 355 366 { 356 367 hideScreen(); 357 368 showScreen(nxt); -
mythplugins/mythweather/mythweather/weatherScreen.cpp
25 25 } 26 26 27 27 WeatherScreen::WeatherScreen(MythScreenStack *parent, const QString &name, 28 ScreenListInfo *screenDefn, int id) 29 : MythScreenType (parent, name) 28 ScreenListInfo *screenDefn, int id) : 29 MythScreenType (parent, name), 30 m_screenDefn(screenDefn), 31 m_name(m_screenDefn->name), 32 m_inuse(false), 33 m_prepared(false), 34 m_id(id) 30 35 { 31 m_screenDefn = screenDefn;32 m_name = m_screenDefn->name;33 m_id = id;34 m_prepared = false;35 36 36 m_inuse = false;37 38 37 QStringList types = m_screenDefn->dataTypes; 39 38 40 39 for (int i = 0; i < types.size(); ++i) -
mythplugins/mythweather/mythweather/sourceManager.h
21 21 22 22 public: 23 23 SourceManager(); 24 ~SourceManager(); 24 25 WeatherSource *needSourceFor(int id, const QString &loc, units_t units); 25 26 QStringList getLocationList(ScriptInfo *si, const QString &str); 26 27 void startTimers(); -
mythplugins/mythweather/mythweather/weatherUtils.cpp
67 67 { 68 68 if ( (e.tagName() == "screen") && !screens.contains(e.attribute("name")) ) 69 69 { 70 ScreenListInfo *screendef = new ScreenListInfo(); 71 screendef->multiLoc = false; 72 screendef->name = e.attribute("name"); 70 screens[e.attribute("name")].multiLoc = false; 71 screens[e.attribute("name")].name = e.attribute("name"); 73 72 QString hasUnits = e.attribute("hasunits"); 74 73 if (hasUnits.toLower() == "no") 75 screen def->hasUnits = false;74 screens[e.attribute("name")].hasUnits = false; 76 75 else 77 screendef->hasUnits = true; 78 screendef->dataTypes = loadScreen(e); 79 screens[screendef->name] = screendef; 76 screens[e.attribute("name")].hasUnits = true; 77 screens[e.attribute("name")].dataTypes = loadScreen(e); 80 78 } 81 79 } 82 80 } -
mythplugins/mythweather/mythweather/weatherSetup.cpp
110 110 m_sourceManager->findScriptsDB(); 111 111 m_sourceManager->setupSources(); 112 112 } 113 114 // Deallocate the ScreenListInfo objects created for the inactive screen list. 115 for (int i=0; i < m_inactiveList->GetCount(); i++) 116 { 117 MythUIButtonListItem *item = m_inactiveList->GetItemAt(i); 118 if (item->GetData().isValid()) 119 delete qVariantValue<ScreenListInfo *>(item->GetData()); 120 } 121 122 // Deallocate the ScreenListInfo objects created for the active screen list. 123 for (int i=0; i < m_activeList->GetCount(); i++) 124 { 125 MythUIButtonListItem *item = m_activeList->GetItemAt(i); 126 if (item->GetData().isValid()) 127 delete qVariantValue<ScreenListInfo *>(item->GetData()); 128 } 113 129 } 114 130 115 131 bool ScreenSetup::Create() … … 264 280 265 281 QStringList types; 266 282 267 ScreenListMap m_ScreenListMap = loadScreens();283 ScreenListMap screenListMap = loadScreens(); 268 284 269 ScreenListMap::const_iterator i = m_ScreenListMap.constBegin(); 270 while (i != m_ScreenListMap.constEnd()) 285 // Fill the inactive screen button list. 286 ScreenListMap::const_iterator i = screenListMap.constBegin(); 287 while (i != screenListMap.constEnd()) 271 288 { 272 289 273 si = m_ScreenListMap[i.key()];290 si = &screenListMap[i.key()]; 274 291 types = si->dataTypes; 275 292 si->units = ENG_UNITS; 276 293 … … 295 312 } 296 313 MythUIButtonListItem *item = 297 314 new MythUIButtonListItem(m_inactiveList, i.key()); 298 item->SetData(qVariantFromValue( si));315 item->SetData(qVariantFromValue(new ScreenListInfo(*si))); 299 316 } 300 317 301 318 ++i; … … 320 337 return; 321 338 } 322 339 340 // Fill the active screen button list. 323 341 while (db.next()) 324 342 { 325 343 QString name = db.value(0).toString(); … … 329 347 QString src = db.value(4).toString(); 330 348 uint draworder = db.value(5).toUInt(); 331 349 332 si = m_ScreenListMap[name]; 333 // Clear types first as we will re-insert the values from the database 334 si->types.clear(); 335 types = si->dataTypes; 350 types = screenListMap[name].dataTypes; 336 351 337 352 TypeListInfo ti(dataitem, location, 338 353 m_sourceManager->getSourceByName(src)); 339 354 340 355 if (active_screens.find(draworder) == active_screens.end()) 341 356 { 357 si = new ScreenListInfo(screenListMap[name]); 358 // Clear types first as we will re-insert the values from the database 359 si->types.clear(); 360 si->units = units; 361 342 362 MythUIButtonListItem *item = 343 363 new MythUIButtonListItem(m_activeList, name); 344 si->units = units;364 345 365 346 366 // Only insert types meant for this screen 347 367 for (QStringList::Iterator type_i = types.begin(); … … 492 512 "screensetupmenupopup"); 493 513 494 514 if (menuPopup->Create()) 515 { 495 516 popupStack->AddScreen(menuPopup); 496 517 497 menuPopup->SetReturnEvent(this, "options");518 menuPopup->SetReturnEvent(this, "options"); 498 519 499 menuPopup->AddButton(tr("Move Up"), qVariantFromValue(selected)); 500 menuPopup->AddButton(tr("Move Down"), qVariantFromValue(selected)); 501 menuPopup->AddButton(tr("Remove"), qVariantFromValue(selected)); 502 menuPopup->AddButton(tr("Change Location"), qVariantFromValue(selected)); 503 if (si->hasUnits) 504 menuPopup->AddButton(tr("Change Units"), qVariantFromValue(selected)); 505 menuPopup->AddButton(tr("Cancel"), qVariantFromValue(selected)); 520 menuPopup->AddButton(tr("Move Up"), qVariantFromValue(selected)); 521 menuPopup->AddButton(tr("Move Down"), qVariantFromValue(selected)); 522 menuPopup->AddButton(tr("Remove"), qVariantFromValue(selected)); 523 menuPopup->AddButton(tr("Change Location"), qVariantFromValue(selected)); 524 if (si->hasUnits) 525 menuPopup->AddButton(tr("Change Units"), qVariantFromValue(selected)); 526 menuPopup->AddButton(tr("Cancel"), qVariantFromValue(selected)); 527 } 528 else 529 { 530 delete menuPopup; 531 } 506 532 507 533 } 508 534 else if (GetFocusWidget() == m_inactiveList) … … 522 548 QList<ScriptInfo *> tmp; 523 549 if (m_sourceManager->findPossibleSources(type_strs, tmp)) 524 550 { 525 ScreenListInfo *newsi = new ScreenListInfo(*si);526 527 551 if (!m_inactiveList->GetCount()) 528 552 { 529 553 m_inactiveList->SetActive(false); 530 554 NextPrevWidgetFocus(true); 531 555 } 532 556 if (hasUnits) 533 showUnitsPopup(selected->GetText(), newsi);557 showUnitsPopup(selected->GetText(), si); 534 558 else 535 doLocationDialog( newsi);559 doLocationDialog(si); 536 560 } 537 561 else 538 562 VERBOSE(VB_IMPORTANT, "Screen cannot be used, not all required " … … 550 574 551 575 if (locdialog->Create()) 552 576 mainStack->AddScreen(locdialog); 577 else 578 delete locdialog; 553 579 } 554 580 555 581 void ScreenSetup::showUnitsPopup(const QString &name, ScreenListInfo *si) … … 565 591 "weatherunitspopup"); 566 592 567 593 if (menuPopup->Create()) 594 { 568 595 popupStack->AddScreen(menuPopup); 569 596 570 menuPopup->SetReturnEvent(this, "units");597 menuPopup->SetReturnEvent(this, "units"); 571 598 572 menuPopup->AddButton(tr("English Units"), qVariantFromValue(si)); 573 menuPopup->AddButton(tr("SI Units"), qVariantFromValue(si)); 599 menuPopup->AddButton(tr("English Units"), qVariantFromValue(si)); 600 menuPopup->AddButton(tr("SI Units"), qVariantFromValue(si)); 601 } 602 else 603 { 604 delete menuPopup; 605 } 574 606 } 575 607 576 608 void ScreenSetup::deleteScreen() 577 609 { 578 if (m_activeList->GetItemCurrent()) 579 delete m_activeList->GetItemCurrent(); 610 MythUIButtonListItem *item = m_activeList->GetItemCurrent(); 611 if (item) 612 { 613 if (item->GetData().isValid()) 614 delete qVariantValue<ScreenListInfo *>(item->GetData()); 580 615 616 delete item; 617 } 618 581 619 if (!m_activeList->GetCount()) 582 620 { 583 621 NextPrevWidgetFocus(false); 584 622 m_activeList->SetActive(false); 585 623 } 586 587 624 } 588 625 589 626 void ScreenSetup::customEvent(QEvent *event) … … 632 669 if (buttonnum > -1) 633 670 { 634 671 ScreenListInfo *si = qVariantValue<ScreenListInfo *>(dce->GetData()); 672 635 673 if (buttonnum == 0) 636 674 { 637 675 si->units = ENG_UNITS; … … 855 893 MythScreenType *retScreen, ScreenListInfo *si, 856 894 SourceManager *srcman) 857 895 : MythScreenType(parent, name), 858 m_screenListInfo( si), m_sourceManager(srcman),896 m_screenListInfo(new ScreenListInfo(*si)), m_sourceManager(srcman), 859 897 m_retScreen(retScreen), m_locationList(NULL), 860 898 m_locationEdit(NULL), m_searchButton(NULL), 861 899 m_resultsText(NULL), m_sourceText(NULL) … … 868 906 869 907 LocationDialog::~LocationDialog() 870 908 { 909 if(m_locationList) 910 clearResults(); 911 912 delete m_screenListInfo; 871 913 } 872 914 873 915 bool LocationDialog::Create() … … 917 959 "mythweatherbusydialog"); 918 960 919 961 if (busyPopup->Create()) 962 { 920 963 popupStack->AddScreen(busyPopup, false); 964 } 965 else 966 { 967 delete busyPopup; 968 busyPopup = NULL; 969 } 970 921 971 922 972 QMap<ScriptInfo *, QStringList> result_cache; 923 973 int numresults = 0; 924 m_locationList->Reset();974 clearResults(); 925 975 926 976 QString searchingresults = tr("Searching ... Results: %1"); 927 977 … … 978 1028 } 979 1029 } 980 1030 1031 void LocationDialog::clearResults() 1032 { 1033 for (int i=0; i < m_locationList->GetCount(); i++) 1034 { 1035 MythUIButtonListItem *item = m_locationList->GetItemAt(i); 1036 if (item->GetData().isValid()) 1037 delete qVariantValue<ResultListInfo *>(item->GetData()); 1038 } 1039 1040 m_locationList->Reset(); 1041 } 1042 981 1043 void LocationDialog::itemSelected(MythUIButtonListItem *item) 982 1044 { 983 1045 ResultListInfo *ri = qVariantValue<ResultListInfo *>(item->GetData()); … … 1002 1064 1003 1065 DialogCompletionEvent *dce = 1004 1066 new DialogCompletionEvent("location", 0, "", 1005 qVariantFromValue( m_screenListInfo));1067 qVariantFromValue(new ScreenListInfo(*m_screenListInfo))); 1006 1068 QApplication::postEvent(m_retScreen, dce); 1007 1069 1008 1070 Close(); -
mythplugins/mythweather/mythweather/weatherSource.cpp
397 397 } 398 398 } 399 399 400 WeatherSource::WeatherSource(const QString &filename)401 : m_ready(false), m_inuse(false),402 m_info(NULL), m_proc(NULL),403 m_dir(""), m_locale(""),404 m_units(SI_UNITS),405 m_scriptTimer(new QTimer(this)), m_updateTimer(new QTimer(this)),406 m_connectCnt(0)407 {408 connect( m_scriptTimer, SIGNAL(timeout()),409 this, SLOT(scriptTimeout()));410 411 connect( m_updateTimer, SIGNAL(timeout()),412 this, SLOT(updateTimeout()));413 414 415 const QFileInfo fi(filename);416 m_info = ProbeScript(fi);417 418 if (m_info)419 {420 m_proc = new QProcess();421 // program = filename;422 m_proc->setWorkingDirectory(423 QDir(GetShareDir() + "mythweather/scripts/").absolutePath());424 connect(this, SIGNAL(killProcess()),425 m_proc, SLOT(kill()));426 m_ready = true;427 }428 else429 VERBOSE(VB_IMPORTANT, "Error probing script");430 }431 432 400 WeatherSource::~WeatherSource() 433 401 { 434 402 delete m_proc; -
mythplugins/mythweather/mythweather/main.cpp
98 98 99 99 if (gsetup->Create()) 100 100 mainStack->AddScreen(gsetup); 101 else 102 delete gsetup; 101 103 } 102 104 else if (selection == "SETTINGS_SCREEN") 103 105 { … … 105 107 106 108 if (ssetup->Create()) 107 109 mainStack->AddScreen(ssetup); 110 else 111 delete ssetup; 108 112 } 109 113 else if (selection == "SETTINGS_SOURCE") 110 114 { … … 112 116 113 117 if (srcsetup->Create()) 114 118 mainStack->AddScreen(srcsetup); 119 else 120 delete srcsetup; 115 121 // MythPopupBox::showOkPopup(gContext->GetMainWindow(), "no sources", 116 122 // QObject::tr("No Sources defined, Sources are defined by" 117 123 // " adding screens in Screen Setup.")); -
mythplugins/mythweather/mythweather/weatherSetup.h
149 149 void itemClicked(MythUIButtonListItem *item); 150 150 151 151 private: 152 void clearResults(); 153 154 private: 152 155 CacheMap m_cache; 153 156 QStringList m_types; 154 157 ScreenListInfo *m_screenListInfo; -
mythplugins/mythweather/mythweather/weatherSource.h
46 46 struct ScriptInfo &scriptInfo); 47 47 48 48 WeatherSource(ScriptInfo *info); 49 WeatherSource(const QString &filename);50 49 ~WeatherSource(); 51 50 52 51 bool isReady() { return m_ready; } -
mythplugins/mythweather/mythweather/weatherUtils.h
22 22 class TypeListInfo 23 23 { 24 24 public: 25 26 TypeListInfo(const TypeListInfo& info) 27 : name(info.name), location(info.location), src(info.src) 28 { 29 name.detach(); 30 location.detach(); 31 } 32 25 33 TypeListInfo(const QString &_name) 26 34 : name(_name), location(QString::null), src(NULL) 27 35 { … … 51 59 class ScreenListInfo 52 60 { 53 61 public: 62 ScreenListInfo() {} 63 64 ScreenListInfo(const ScreenListInfo& info) : 65 name(info.name), 66 types(info.types), 67 helptxt(info.helptxt), 68 sources(info.sources), 69 units(info.units), 70 hasUnits(info.hasUnits), 71 multiLoc(info.multiLoc) 72 { 73 types.detach(); 74 } 75 54 76 TypeListInfo GetCurrentTypeList(void) const; 55 77 56 78 public: … … 66 88 67 89 Q_DECLARE_METATYPE(ScreenListInfo *); 68 90 69 typedef QMap<QString, ScreenListInfo *> ScreenListMap;91 typedef QMap<QString, ScreenListInfo> ScreenListMap; 70 92 71 93 ScreenListMap loadScreens(); 72 94 QStringList loadScreen(QDomElement ScreenListInfo); -
mythplugins/mythweather/mythweather/sourceManager.cpp
27 27 setupSources(); 28 28 } 29 29 30 SourceManager::~SourceManager() 31 { 32 clearSources(); 33 } 34 30 35 bool SourceManager::findScriptsDB() 31 36 { 32 37 MSqlQuery db(MSqlQuery::InitCon()); … … 91 96 "mythweatherbusydialog"); 92 97 93 98 if (busyPopup->Create()) 99 { 94 100 popupStack->AddScreen(busyPopup, false); 101 } 102 else 103 { 104 delete busyPopup; 105 busyPopup = NULL; 106 } 95 107 96 108 qApp->processEvents(); 97 109 … … 211 223 if (!m_scripts.contains(si)) 212 224 return QStringList(); 213 225 WeatherSource *ws = new WeatherSource(si); 214 return ws->getLocationList(str); 226 227 QStringList locationList(ws->getLocationList(str)); 228 229 delete ws; 230 231 return locationList; 215 232 } 216 233 217 234 WeatherSource *SourceManager::needSourceFor(int id, const QString &loc,