From 57ad81e3dfcead9c090bbe45bb7072a5c7d78415 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Fri, 30 Dec 2011 16:54:36 +0100 Subject: [PATCH] Merged LinkAction class into its base class. LinkApp now calls its launch method via the delegate mechanism instead of via an overridden virtual method. This should make it easier to move the launch method out of LinkApp and into the GMenu2X main class. --- src/Makefile.am | 4 ++-- src/gmenu2x.cpp | 1 - src/link.cpp | 7 ++++++- src/link.h | 10 +++++++--- src/linkaction.cpp | 30 ------------------------------ src/linkaction.h | 45 --------------------------------------------- src/linkapp.cpp | 5 +++-- src/linkapp.h | 2 +- src/menu.cpp | 12 ++++++------ src/menu.h | 2 +- 10 files changed, 26 insertions(+), 92 deletions(-) delete mode 100644 src/linkaction.cpp delete mode 100644 src/linkaction.h diff --git a/src/Makefile.am b/src/Makefile.am index 7edaf62..c1746d3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = gmenu2x gmenu2x_SOURCES = asfont.cpp button.cpp cpu.cpp dirdialog.cpp filedialog.cpp \ filelister.cpp gmenu2x.cpp iconbutton.cpp imagedialog.cpp inputdialog.cpp \ - inputmanager.cpp linkaction.cpp linkapp.cpp link.cpp \ + inputmanager.cpp linkapp.cpp link.cpp \ menu.cpp menusettingbool.cpp menusetting.cpp menusettingdir.cpp \ menusettingfile.cpp menusettingimage.cpp menusettingint.cpp \ menusettingmultistring.cpp menusettingrgba.cpp menusettingstring.cpp \ @@ -16,7 +16,7 @@ gmenu2x_SOURCES = asfont.cpp button.cpp cpu.cpp dirdialog.cpp filedialog.cpp \ noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \ filedialog.h filelister.h gmenu2x.h gp2x.h iconbutton.h imagedialog.h \ - inputdialog.h inputmanager.h linkaction.h linkapp.h link.h \ + inputdialog.h inputmanager.h linkapp.h link.h \ menu.h menusettingbool.h menusettingdir.h \ menusettingfile.h menusetting.h menusettingimage.h menusettingint.h \ menusettingmultistring.h menusettingrgba.h menusettingstring.h \ diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index d6a9ff3..60b1bbe 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -28,7 +28,6 @@ #include "gmenu2x.h" #include "iconbutton.h" #include "inputdialog.h" -#include "linkaction.h" #include "linkapp.h" #include "menu.h" #include "menusettingbool.h" diff --git a/src/link.cpp b/src/link.cpp index 65258c7..6679c9a 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -31,9 +31,10 @@ using namespace std; using namespace fastdelegate; -Link::Link(GMenu2X *gmenu2x_, Touchscreen &ts) +Link::Link(GMenu2X *gmenu2x_, Touchscreen &ts, LinkRunAction action_) : Button(ts, true) , gmenu2x(gmenu2x_) + , action(action_) { action = MakeDelegate(this, &Link::run); edited = false; @@ -140,3 +141,7 @@ void Link::recalcCoordinates() { iconX = rect.x+(rect.w-32)/2; padding = (gmenu2x->skinConfInt["linkHeight"] - 32 - gmenu2x->font->getLineHeight()) / 3; } + +void Link::run() { + this->action(); +} diff --git a/src/link.h b/src/link.h index 74476d7..74d1ee4 100644 --- a/src/link.h +++ b/src/link.h @@ -22,12 +22,15 @@ #define LINK_H #include "button.h" +#include "FastDelegate.h" #include +class GMenu2X; class Surface; -class GMenu2X; +typedef fastdelegate::FastDelegate0<> LinkRunAction; + /** Base class that represents a link on screen. @@ -36,6 +39,7 @@ Base class that represents a link on screen. */ class Link : public Button { private: + LinkRunAction action; uint iconX, padding; protected: @@ -50,7 +54,7 @@ protected: void updateSurfaces(); public: - Link(GMenu2X *gmenu2x, Touchscreen &ts); + Link(GMenu2X *gmenu2x, Touchscreen &ts, LinkRunAction action); virtual ~Link() {}; virtual void paint(); @@ -69,7 +73,7 @@ public: const std::string &getIconPath(); void setIconPath(const std::string &icon); - virtual void run() = 0; + void run(); }; #endif diff --git a/src/linkaction.cpp b/src/linkaction.cpp deleted file mode 100644 index b9e222a..0000000 --- a/src/linkaction.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Massimiliano Torromeo * - * massimiliano.torromeo@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "linkaction.h" - -LinkAction::LinkAction(GMenu2X *gmenu2x, Touchscreen &ts, LinkRunAction act) - : Link(gmenu2x, ts) { - this->action = act; -} - -void LinkAction::run() { - this->action(); -} diff --git a/src/linkaction.h b/src/linkaction.h deleted file mode 100644 index 43e18bf..0000000 --- a/src/linkaction.h +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Massimiliano Torromeo * - * massimiliano.torromeo@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef LINKACTION_H -#define LINKACTION_H - -#include "FastDelegate.h" -#include "link.h" - -typedef fastdelegate::FastDelegate0<> LinkRunAction; - -class GMenu2X; - -/** -Executes an action when launched. - - @author Massimiliano Torromeo -*/ -class LinkAction : public Link { -private: - LinkRunAction action; -public: - LinkAction(GMenu2X *gmenu2x, Touchscreen &ts, LinkRunAction act); - virtual ~LinkAction() {}; - virtual void run(); -}; - -#endif // LINKACTION_H diff --git a/src/linkapp.cpp b/src/linkapp.cpp index dc19972..ae093c4 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -36,11 +36,12 @@ #include #include +using fastdelegate::MakeDelegate; using namespace std; LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_, const char* linkfile) - : Link(gmenu2x_, ts) + : Link(gmenu2x_, ts, MakeDelegate(this, &LinkApp::start)) , inputMgr(inputMgr_) { manual = ""; @@ -202,7 +203,7 @@ void LinkApp::drawRun() { gmenu2x->s->flip(); } -void LinkApp::run() { +void LinkApp::start() { if (selectordir!="") selector(); else diff --git a/src/linkapp.h b/src/linkapp.h index b0fab1d..4b41afc 100644 --- a/src/linkapp.h +++ b/src/linkapp.h @@ -49,6 +49,7 @@ private: bool wrapper; bool dontleave; + void start(); void launch( const std::string &selectedFile = "", const std::string &selectedDir = ""); @@ -57,7 +58,6 @@ public: LinkApp(GMenu2X *gmenu2x, Touchscreen &ts, InputManager &inputMgr, const char* linkfile); virtual const std::string &searchIcon(); - virtual void run(); const std::string &getExec(); void setExec(const std::string &exec); diff --git a/src/menu.cpp b/src/menu.cpp index 4a6d3b4..15d64ff 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -173,14 +173,14 @@ void Menu::setSectionIndex(int i) { bool Menu::addActionLink(uint section, const string &title, LinkRunAction action, const string &description, const string &icon) { if (section>=sections.size()) return false; - LinkAction *linkact = new LinkAction(gmenu2x, ts, action); - linkact->setSize(gmenu2x->skinConfInt["linkWidth"],gmenu2x->skinConfInt["linkHeight"]); - linkact->setTitle(title); - linkact->setDescription(description); + Link *link = new Link(gmenu2x, ts, action); + link->setSize(gmenu2x->skinConfInt["linkWidth"], gmenu2x->skinConfInt["linkHeight"]); + link->setTitle(title); + link->setDescription(description); if (gmenu2x->sc.exists(icon) || (icon.substr(0,5)=="skin:" && !gmenu2x->sc.getSkinFilePath(icon.substr(5,icon.length())).empty()) || fileExists(icon)) - linkact->setIcon(icon); + link->setIcon(icon); - sectionLinks(section)->push_back(linkact); + sectionLinks(section)->push_back(link); return true; } diff --git a/src/menu.h b/src/menu.h index ef0bc05..5e7578e 100644 --- a/src/menu.h +++ b/src/menu.h @@ -21,7 +21,7 @@ #ifndef MENU_H #define MENU_H -#include "linkaction.h" +#include "link.h" #include #include