1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-28 00:17:42 +02:00

Use shared_ptr for layers

This allows transient layers to be deleted automatically when they are
dismissed, while persistent layers will be kept alive by their other
owner(s).
This commit is contained in:
Maarten ter Huurne 2013-08-06 02:34:03 +02:00
parent 6d868a895a
commit 63029d85d7
2 changed files with 8 additions and 17 deletions

View File

@ -231,8 +231,6 @@ GMenu2X::GMenu2X()
bg = NULL;
font = NULL;
menu = NULL;
helpPopup = nullptr;
btnContextMenu = nullptr;
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
initMenu();
@ -256,7 +254,7 @@ GMenu2X::GMenu2X()
DEBUG("Loading system input.conf file: %s.\n", input_file.c_str());
}
input.init(input_file, menu);
input.init(input_file, menu.get());
if (confInt["backlightTimeout"] > 0)
PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] );
@ -279,8 +277,6 @@ GMenu2X::~GMenu2X() {
delete Clock::getInstance();
quit();
delete menu;
delete helpPopup;
delete btnContextMenu;
delete font;
delete monitor;
@ -372,7 +368,7 @@ void GMenu2X::initFont() {
void GMenu2X::initMenu() {
//Menu structure handler
menu = new Menu(this, ts);
menu.reset(new Menu(this, ts));
for (uint i=0; i<menu->getSections().size(); i++) {
//Add virtual links in the applications section
if (menu->getSections()[i]=="applications") {
@ -608,7 +604,7 @@ void GMenu2X::paint() {
//Background
sc["bgmain"]->blit(s,0,0);
for (Layer *layer : layers) {
for (auto layer : layers) {
layer->paint(*s);
}
@ -679,8 +675,7 @@ void GMenu2X::main() {
if (!handled) {
switch (button) {
case InputManager::CANCEL:
helpPopup = new HelpPopup(*this);
layers.push_back(helpPopup);
layers.push_back(make_shared<HelpPopup>(*this));
break;
case InputManager::SETTINGS:
options();
@ -694,13 +689,9 @@ void GMenu2X::main() {
}
for (auto it = layers.begin(); it != layers.end(); ) {
Layer *layer = *it;
auto layer = *it;
if (layer->wasDismissed()) {
it = layers.erase(it);
if (layer == helpPopup) {
delete helpPopup;
helpPopup = nullptr;
}
} else {
++it;
}

View File

@ -28,6 +28,7 @@
#include "surface.h"
#include <iostream>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
@ -67,12 +68,11 @@ typedef std::unordered_map<std::string, int, std::hash<std::string> > ConfIntHas
class GMenu2X {
private:
Touchscreen ts;
Menu *menu;
HelpPopup *helpPopup;
std::shared_ptr<Menu> menu;
MediaMonitor *monitor;
std::string batteryIcon;
std::vector<Layer *> layers;
std::vector<std::shared_ptr<Layer>> layers;
/*!
Retrieves the free disk space on the sd