mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-12-25 07:59:53 +02:00
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.
This commit is contained in:
parent
2d81b13459
commit
57ad81e3df
@ -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 \
|
||||
|
@ -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"
|
||||
|
@ -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();
|
||||
}
|
||||
|
10
src/link.h
10
src/link.h
@ -22,12 +22,15 @@
|
||||
#define LINK_H
|
||||
|
||||
#include "button.h"
|
||||
#include "FastDelegate.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
@ -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();
|
||||
}
|
@ -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 <massimiliano.torromeo@gmail.com>
|
||||
*/
|
||||
class LinkAction : public Link {
|
||||
private:
|
||||
LinkRunAction action;
|
||||
public:
|
||||
LinkAction(GMenu2X *gmenu2x, Touchscreen &ts, LinkRunAction act);
|
||||
virtual ~LinkAction() {};
|
||||
virtual void run();
|
||||
};
|
||||
|
||||
#endif // LINKACTION_H
|
@ -36,11 +36,12 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
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
|
||||
|
@ -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);
|
||||
|
12
src/menu.cpp
12
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;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#ifndef MENU_H
|
||||
#define MENU_H
|
||||
|
||||
#include "linkaction.h"
|
||||
#include "link.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
Loading…
Reference in New Issue
Block a user