mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 12:24:38 +02:00
Unify filedialog and browsedialog code
This commit is contained in:
parent
6361dde213
commit
8b862b8398
@ -1,9 +1,8 @@
|
||||
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 listviewitem.cpp menu.cpp menusettingbool.cpp menusetting.cpp menusettingdir.cpp menusettingfile.cpp menusettingimage.cpp menusettingint.cpp menusettingmultistring.cpp menusettingrgba.cpp menusettingstring.cpp messagebox.cpp pxml.cpp selector.cpp selectordetector.cpp settingsdialog.cpp sfontplus.cpp surfacecollection.cpp surface.cpp textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp utilities.cpp wallpaperdialog.cpp listview.cpp tinyxml/tinystr.cpp tinyxml/tinyxml.cpp tinyxml/tinyxmlerror.cpp tinyxml/tinyxmlparser.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 jz4740.h linkaction.h linkapp.h link.h listview.h listviewitem.h menu.h menusettingbool.h menusettingdir.h menusettingfile.h menusetting.h menusettingimage.h menusettingint.h menusettingmultistring.h menusettingrgba.h menusettingstring.h messagebox.h pxml.h selectordetector.h selector.h settingsdialog.h sfontplus.h surfacecollection.h surface.h textdialog.h textmanualdialog.h touchscreen.h translator.h utilities.h wallpaperdialog.h tinyxml/tinystr.h tinyxml/tinyxml.h
|
||||
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 listviewitem.cpp menu.cpp menusettingbool.cpp menusetting.cpp menusettingdir.cpp menusettingfile.cpp menusettingimage.cpp menusettingint.cpp menusettingmultistring.cpp menusettingrgba.cpp menusettingstring.cpp messagebox.cpp pxml.cpp selector.cpp selectordetector.cpp settingsdialog.cpp sfontplus.cpp surfacecollection.cpp surface.cpp textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp utilities.cpp wallpaperdialog.cpp listview.cpp tinyxml/tinystr.cpp tinyxml/tinyxml.cpp tinyxml/tinyxmlerror.cpp tinyxml/tinyxmlparser.cpp browsedialog.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 jz4740.h linkaction.h linkapp.h link.h listview.h listviewitem.h menu.h menusettingbool.h menusettingdir.h menusettingfile.h menusetting.h menusettingimage.h menusettingint.h menusettingmultistring.h menusettingrgba.h menusettingstring.h messagebox.h pxml.h selectordetector.h selector.h settingsdialog.h sfontplus.h surfacecollection.h surface.h textdialog.h textmanualdialog.h touchscreen.h translator.h utilities.h wallpaperdialog.h tinyxml/tinystr.h tinyxml/tinyxml.h browsedialog.h
|
||||
AM_CFLAGS= @CFLAGS@ @SDL_CFLAGS@
|
||||
|
||||
AM_CXXFLAGS = @CXXFLAGS@ @SDL_CFLAGS@
|
||||
|
236
src/browsedialog.cpp
Normal file
236
src/browsedialog.cpp
Normal file
@ -0,0 +1,236 @@
|
||||
#include <string>
|
||||
|
||||
#include "browsedialog.h"
|
||||
|
||||
#include "FastDelegate.h"
|
||||
#include "filelister.h"
|
||||
|
||||
using namespace fastdelegate;
|
||||
|
||||
BrowseDialog::BrowseDialog(GMenu2X *gmenu2x, const string &title,
|
||||
const string &subtitle) :
|
||||
gmenu2x(gmenu2x), title(title), subtitle(subtitle)
|
||||
{
|
||||
ButtonAction actionUp = MakeDelegate(this, &BrowseDialog::directoryUp);
|
||||
ButtonAction actionEnter = MakeDelegate(this, &BrowseDialog::directoryEnter);
|
||||
ButtonAction actionConfirm = MakeDelegate(this, &BrowseDialog::confirm);
|
||||
|
||||
btnUp = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Up one folder"]);
|
||||
btnUp->setAction(actionUp);
|
||||
|
||||
btnEnter = new IconButton(gmenu2x, "skin:imgs/buttons/b.png", gmenu2x->tr["Enter folder"]);
|
||||
btnEnter->setAction(actionEnter);
|
||||
|
||||
btnConfirm = new IconButton(gmenu2x, "skin:imgs/buttons/start.png", gmenu2x->tr["Confirm"]);
|
||||
btnConfirm->setAction(actionConfirm);
|
||||
|
||||
iconGoUp = gmenu2x->sc.skinRes("imgs/go-up.png");
|
||||
iconFolder = gmenu2x->sc.skinRes("imgs/folder.png");
|
||||
iconFile = gmenu2x->sc.skinRes("imgs/file.png");
|
||||
}
|
||||
|
||||
bool BrowseDialog::exec()
|
||||
{
|
||||
if (!fl)
|
||||
return false;
|
||||
|
||||
string path = fl->getPath();
|
||||
if (path.empty() || !fileExists(path))
|
||||
setPath("/card");
|
||||
|
||||
fl->browse();
|
||||
|
||||
rowHeight = gmenu2x->font->getHeight()+1; // gp2x=15+1 / pandora=19+1
|
||||
numRows = (gmenu2x->resY-gmenu2x->skinConfInt["topBarHeight"]-20)/rowHeight;
|
||||
clipRect = (SDL_Rect){0, gmenu2x->skinConfInt["topBarHeight"]+1, gmenu2x->resX-9, gmenu2x->resY-gmenu2x->skinConfInt["topBarHeight"]-25};
|
||||
touchRect = (SDL_Rect){2, gmenu2x->skinConfInt["topBarHeight"]+4, gmenu2x->resX-12, clipRect.h};
|
||||
|
||||
selected = 0;
|
||||
while (!close) {
|
||||
if (gmenu2x->f200) gmenu2x->ts.poll();
|
||||
|
||||
paint();
|
||||
|
||||
handleInput();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BrowseDialog::Action BrowseDialog::getAction()
|
||||
{
|
||||
BrowseDialog::Action action = BrowseDialog::ACT_NONE;
|
||||
|
||||
if (gmenu2x->input[ACTION_SELECT])
|
||||
action = BrowseDialog::ACT_CLOSE;
|
||||
else if (gmenu2x->input[ACTION_UP])
|
||||
action = BrowseDialog::ACT_UP;
|
||||
else if (gmenu2x->input[ACTION_L])
|
||||
action = BrowseDialog::ACT_SCROLLUP;
|
||||
else if (gmenu2x->input[ACTION_DOWN])
|
||||
action = BrowseDialog::ACT_DOWN;
|
||||
else if (gmenu2x->input[ACTION_R])
|
||||
action = BrowseDialog::ACT_SCROLLDOWN;
|
||||
else if (gmenu2x->input[ACTION_X] || gmenu2x->input[ACTION_LEFT])
|
||||
action = BrowseDialog::ACT_GOUP;
|
||||
else if (gmenu2x->input[ACTION_B])
|
||||
action = BrowseDialog::ACT_SELECT;
|
||||
else if (gmenu2x->input[ACTION_START])
|
||||
action = BrowseDialog::ACT_CONFIRM;
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
bool BrowseDialog::handleInput()
|
||||
{
|
||||
BrowseDialog::Action action;
|
||||
|
||||
gmenu2x->input.update();
|
||||
|
||||
if (ts_pressed && !gmenu2x->ts.pressed()) {
|
||||
action = BrowseDialog::ACT_SELECT;
|
||||
ts_pressed = false;
|
||||
} else {
|
||||
action = getAction();
|
||||
}
|
||||
|
||||
if (gmenu2x->f200 && gmenu2x->ts.pressed() && !gmenu2x->ts.inRect(touchRect)) ts_pressed = false;
|
||||
|
||||
if (action == BrowseDialog::ACT_SELECT && (*fl)[selected] == "..")
|
||||
action = BrowseDialog::ACT_GOUP;
|
||||
switch (action) {
|
||||
case BrowseDialog::ACT_CLOSE:
|
||||
close = true;
|
||||
result = false;
|
||||
break;
|
||||
case BrowseDialog::ACT_UP:
|
||||
if (selected == 0)
|
||||
selected = fl->size() - 1;
|
||||
else
|
||||
selected -= 1;
|
||||
break;
|
||||
case BrowseDialog::ACT_SCROLLUP:
|
||||
if (selected <= numRows - 2)
|
||||
selected = 0;
|
||||
else
|
||||
selected -= numRows - 2;
|
||||
break;
|
||||
case BrowseDialog::ACT_DOWN:
|
||||
if (fl->size() - 1 <= selected)
|
||||
selected = 0;
|
||||
else
|
||||
selected += 1;
|
||||
break;
|
||||
case BrowseDialog::ACT_SCROLLDOWN:
|
||||
if (selected+(numRows-2)>=fl->size())
|
||||
selected = fl->size()-1;
|
||||
else
|
||||
selected += numRows-2;
|
||||
break;
|
||||
case BrowseDialog::ACT_GOUP:
|
||||
directoryUp();
|
||||
break;
|
||||
case BrowseDialog::ACT_SELECT:
|
||||
if (fl->isDirectory(selected)) {
|
||||
directoryEnter();
|
||||
break;
|
||||
}
|
||||
/* Falltrough */
|
||||
case BrowseDialog::ACT_CONFIRM:
|
||||
confirm();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void BrowseDialog::directoryUp()
|
||||
{
|
||||
string path = fl->getPath();
|
||||
string::size_type p = path.rfind("/");
|
||||
|
||||
if (p == path.size() - 1)
|
||||
p = path.rfind("/", p - 1);
|
||||
|
||||
if (p == string::npos || p < 4 || path.compare(0, 5, "/card") != 0) {
|
||||
close = true;
|
||||
result = false;
|
||||
} else {
|
||||
selected = 0;
|
||||
setPath(path.substr(0, p));
|
||||
}
|
||||
}
|
||||
|
||||
void BrowseDialog::directoryEnter()
|
||||
{
|
||||
setPath(fl->getPath() + "/" + fl->at(selected));
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
void BrowseDialog::confirm()
|
||||
{
|
||||
close = true;
|
||||
}
|
||||
|
||||
void BrowseDialog::paint()
|
||||
{
|
||||
unsigned int i, iY;
|
||||
unsigned int firstElement, lastElement;
|
||||
unsigned int offsetY;
|
||||
Surface *icon;
|
||||
|
||||
gmenu2x->bg->blit(gmenu2x->s, 0, 0);
|
||||
gmenu2x->drawTitleIcon("icons/explorer.png", true);
|
||||
gmenu2x->writeTitle(title);
|
||||
gmenu2x->writeSubTitle(subtitle);
|
||||
|
||||
gmenu2x->drawButton(btnConfirm,
|
||||
gmenu2x->drawButton(btnUp,
|
||||
gmenu2x->drawButton(btnEnter, 5)));
|
||||
|
||||
if (selected>firstElement+numRows-1)
|
||||
firstElement = selected-numRows+1;
|
||||
else if (selected < firstElement)
|
||||
firstElement = selected;
|
||||
|
||||
//Selection
|
||||
iY = selected-firstElement;
|
||||
iY = gmenu2x->skinConfInt["topBarHeight"]+1+(iY*rowHeight);
|
||||
gmenu2x->s->box(2, iY, gmenu2x->resX-12, rowHeight-1, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
||||
|
||||
lastElement = firstElement + numRows;
|
||||
if (lastElement > fl->size())
|
||||
lastElement = fl->size();
|
||||
|
||||
offsetY = gmenu2x->skinConfInt["topBarHeight"]+1;
|
||||
|
||||
beforeFileList();
|
||||
|
||||
//Files & Directories
|
||||
gmenu2x->s->setClipRect(clipRect);
|
||||
for (i = firstElement; i < lastElement; i++) {
|
||||
if (fl->isDirectory(i)) {
|
||||
if ((*fl)[i]=="..")
|
||||
icon = iconGoUp;
|
||||
else
|
||||
icon = iconFolder;
|
||||
} else {
|
||||
icon = iconFile;
|
||||
}
|
||||
icon->blit(gmenu2x->s, 5, offsetY);
|
||||
gmenu2x->s->write(gmenu2x->font, (*fl)[i], 24, offsetY + 8, SFontHAlignLeft, SFontVAlignMiddle);
|
||||
|
||||
if (gmenu2x->f200 && gmenu2x->ts.pressed() && gmenu2x->ts.inRect(touchRect.x, offsetY + 3, touchRect.w, rowHeight)) {
|
||||
ts_pressed = true;
|
||||
selected = i;
|
||||
}
|
||||
|
||||
offsetY += rowHeight;
|
||||
}
|
||||
gmenu2x->s->clearClipRect();
|
||||
|
||||
gmenu2x->drawScrollBar(numRows,fl->size(),firstElement,clipRect.y,clipRect.h);
|
||||
gmenu2x->s->flip();
|
||||
}
|
106
src/browsedialog.h
Normal file
106
src/browsedialog.h
Normal file
@ -0,0 +1,106 @@
|
||||
/***************************************************************************
|
||||
* 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 BROWSEDIALOG_H_
|
||||
#define BROWSEDIALOG_H_
|
||||
|
||||
#include <string>
|
||||
#include "filelister.h"
|
||||
#include "gmenu2x.h"
|
||||
|
||||
class FileLister;
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
class BrowseDialog {
|
||||
protected:
|
||||
enum Action {
|
||||
ACT_NONE,
|
||||
ACT_SELECT,
|
||||
ACT_CLOSE,
|
||||
ACT_UP,
|
||||
ACT_DOWN,
|
||||
ACT_SCROLLUP,
|
||||
ACT_SCROLLDOWN,
|
||||
ACT_GOUP,
|
||||
ACT_CONFIRM,
|
||||
};
|
||||
|
||||
BrowseDialog(GMenu2X *gmenu2x, const string &title, const string &subtitle);
|
||||
|
||||
virtual void beforeFileList() {};
|
||||
virtual void onChangeDir() {};
|
||||
|
||||
void setPath(const string &path) {
|
||||
fl->setPath(path);
|
||||
onChangeDir();
|
||||
}
|
||||
|
||||
FileLister *fl;
|
||||
unsigned int selected;
|
||||
GMenu2X *gmenu2x;
|
||||
|
||||
private:
|
||||
int selRow;
|
||||
bool close, result;
|
||||
|
||||
string title;
|
||||
string subtitle;
|
||||
|
||||
IconButton *btnUp, *btnEnter, *btnConfirm;
|
||||
|
||||
SDL_Rect clipRect;
|
||||
SDL_Rect touchRect;
|
||||
|
||||
unsigned int numRows;
|
||||
unsigned int rowHeight;
|
||||
|
||||
|
||||
bool ts_pressed;
|
||||
|
||||
Surface *iconGoUp;
|
||||
Surface *iconFolder;
|
||||
Surface *iconFile;
|
||||
|
||||
Action getAction();
|
||||
bool handleInput();
|
||||
|
||||
void paint();
|
||||
|
||||
void directoryUp();
|
||||
void directoryEnter();
|
||||
void confirm();
|
||||
|
||||
public:
|
||||
|
||||
bool exec();
|
||||
|
||||
const std::string &getPath()
|
||||
{
|
||||
return fl->getPath();
|
||||
}
|
||||
std::string getFile()
|
||||
{
|
||||
return (*fl)[selected];
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*INPUTDIALOG_H_*/
|
@ -18,185 +18,17 @@
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_gfxPrimitives.h>
|
||||
|
||||
//for browsing the filesystem
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "dirdialog.h"
|
||||
#include "filelister.h"
|
||||
#include "FastDelegate.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace fastdelegate;
|
||||
|
||||
DirDialog::DirDialog(GMenu2X *gmenu2x, const string &text, const string &dir) {
|
||||
this->gmenu2x = gmenu2x;
|
||||
this->text = text;
|
||||
selRow = 0;
|
||||
if (dir.empty())
|
||||
path = "/card";
|
||||
else
|
||||
path = dir;
|
||||
|
||||
//Delegates
|
||||
ButtonAction actionUp = MakeDelegate(this, &DirDialog::up);
|
||||
ButtonAction actionEnter = MakeDelegate(this, &DirDialog::enter);
|
||||
ButtonAction actionConfirm = MakeDelegate(this, &DirDialog::confirm);
|
||||
|
||||
btnUp = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Up one folder"]);
|
||||
btnUp->setAction(actionUp);
|
||||
|
||||
btnEnter = new IconButton(gmenu2x, "skin:imgs/buttons/b.png", gmenu2x->tr["Enter folder"]);
|
||||
btnEnter->setAction(actionEnter);
|
||||
|
||||
btnConfirm = new IconButton(gmenu2x, "skin:imgs/buttons/start.png", gmenu2x->tr["Confirm"]);
|
||||
btnConfirm->setAction(actionConfirm);
|
||||
DirDialog::DirDialog(GMenu2X *gmenu2x, const string &text, const string &dir) :
|
||||
BrowseDialog(gmenu2x, "Directory Browser", text)
|
||||
{
|
||||
fl = new FileLister(dir, true, false);
|
||||
}
|
||||
|
||||
bool DirDialog::exec() {
|
||||
bool ts_pressed = false;
|
||||
uint i, firstElement = 0, iY, action;
|
||||
|
||||
if (!fileExists(path))
|
||||
path = "/card";
|
||||
|
||||
fl = new FileLister(path,true,false);
|
||||
fl->browse();
|
||||
|
||||
selected = 0;
|
||||
close = false;
|
||||
result = true;
|
||||
|
||||
uint rowHeight = gmenu2x->font->getHeight()+1; // gp2x=15+1 / pandora=19+1
|
||||
uint numRows = (gmenu2x->resY-gmenu2x->skinConfInt["topBarHeight"]-20)/rowHeight;
|
||||
SDL_Rect clipRect = {0, gmenu2x->skinConfInt["topBarHeight"]+1, gmenu2x->resX-9, gmenu2x->resY-gmenu2x->skinConfInt["topBarHeight"]-25};
|
||||
SDL_Rect touchRect = {2, gmenu2x->skinConfInt["topBarHeight"]+4, gmenu2x->resX-12, clipRect.h};
|
||||
while (!close) {
|
||||
action = DirDialog::ACT_NONE;
|
||||
if (gmenu2x->f200) gmenu2x->ts.poll();
|
||||
|
||||
gmenu2x->bg->blit(gmenu2x->s,0,0);
|
||||
gmenu2x->drawTitleIcon("icons/explorer.png",true);
|
||||
gmenu2x->writeTitle("Directory Browser");
|
||||
gmenu2x->writeSubTitle(text);
|
||||
|
||||
gmenu2x->drawButton(btnConfirm,
|
||||
gmenu2x->drawButton(btnUp,
|
||||
gmenu2x->drawButton(btnEnter, 5)));
|
||||
|
||||
if (selected>firstElement+numRows-1) firstElement=selected-numRows+1;
|
||||
if (selected<firstElement) firstElement=selected;
|
||||
|
||||
//Selection
|
||||
iY = selected-firstElement;
|
||||
iY = gmenu2x->skinConfInt["topBarHeight"]+1+(iY*rowHeight);
|
||||
gmenu2x->s->box(2, iY, gmenu2x->resX-12, rowHeight-1, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
||||
|
||||
//Directories
|
||||
gmenu2x->s->setClipRect(clipRect);
|
||||
if (ts_pressed && !gmenu2x->ts.pressed()) {
|
||||
action = DirDialog::ACT_SELECT;
|
||||
ts_pressed = false;
|
||||
}
|
||||
if (gmenu2x->f200 && gmenu2x->ts.pressed() && !gmenu2x->ts.inRect(touchRect)) ts_pressed = false;
|
||||
for (i=firstElement; i<fl->size() && i<firstElement+numRows; i++) {
|
||||
iY = i-firstElement;
|
||||
gmenu2x->sc.skinRes("imgs/folder.png")->blit(gmenu2x->s, 5, gmenu2x->skinConfInt["topBarHeight"]+1+(iY*rowHeight));
|
||||
gmenu2x->s->write(gmenu2x->font, fl->at(i), 24, gmenu2x->skinConfInt["topBarHeight"]+9+(iY*rowHeight), SFontHAlignLeft, SFontVAlignMiddle);
|
||||
if (gmenu2x->f200 && gmenu2x->ts.pressed() && gmenu2x->ts.inRect(touchRect.x, touchRect.y+(iY*rowHeight), touchRect.w, rowHeight)) {
|
||||
ts_pressed = true;
|
||||
selected = i;
|
||||
}
|
||||
}
|
||||
gmenu2x->s->clearClipRect();
|
||||
|
||||
gmenu2x->drawScrollBar(numRows,fl->size(),firstElement,clipRect.y,clipRect.h);
|
||||
gmenu2x->s->flip();
|
||||
|
||||
btnConfirm->handleTS();
|
||||
btnUp->handleTS();
|
||||
btnEnter->handleTS();
|
||||
gmenu2x->input.update();
|
||||
if ( gmenu2x->input[ACTION_SELECT] ) action = DirDialog::ACT_CLOSE;
|
||||
if ( gmenu2x->input[ACTION_UP ] ) action = DirDialog::ACT_UP;
|
||||
if ( gmenu2x->input[ACTION_L ] ) action = DirDialog::ACT_SCROLLUP;
|
||||
if ( gmenu2x->input[ACTION_DOWN ] ) action = DirDialog::ACT_DOWN;
|
||||
if ( gmenu2x->input[ACTION_R ] ) action = DirDialog::ACT_SCROLLDOWN;
|
||||
if ( gmenu2x->input[ACTION_X] || gmenu2x->input[ACTION_LEFT] ) action = DirDialog::ACT_GOUP;
|
||||
if ( gmenu2x->input[ACTION_B ] ) action = DirDialog::ACT_SELECT;
|
||||
if ( gmenu2x->input[ACTION_START ] ) action = DirDialog::ACT_CONFIRM;
|
||||
|
||||
if (action == DirDialog::ACT_SELECT && fl->at(selected)=="..") action = DirDialog::ACT_GOUP;
|
||||
switch (action) {
|
||||
case DirDialog::ACT_CLOSE: {
|
||||
close = true;
|
||||
result = false;
|
||||
} break;
|
||||
case DirDialog::ACT_UP: {
|
||||
if (selected==0)
|
||||
selected = fl->size()-1;
|
||||
else
|
||||
selected -= 1;
|
||||
} break;
|
||||
case DirDialog::ACT_SCROLLUP: {
|
||||
if ((int)(selected-(numRows-2))<0) {
|
||||
selected = 0;
|
||||
} else {
|
||||
selected -= numRows-2;
|
||||
}
|
||||
} break;
|
||||
case DirDialog::ACT_DOWN: {
|
||||
if (selected+1>=fl->size())
|
||||
selected = 0;
|
||||
else
|
||||
selected += 1;
|
||||
} break;
|
||||
case DirDialog::ACT_SCROLLDOWN: {
|
||||
if (selected+(numRows-2)>=fl->size()) {
|
||||
selected = fl->size()-1;
|
||||
} else {
|
||||
selected += numRows-2;
|
||||
}
|
||||
} break;
|
||||
case DirDialog::ACT_GOUP: {
|
||||
up();
|
||||
} break;
|
||||
case DirDialog::ACT_SELECT: {
|
||||
enter();
|
||||
} break;
|
||||
case DirDialog::ACT_CONFIRM: {
|
||||
confirm();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
delete(fl);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void DirDialog::up() {
|
||||
string::size_type p = path.rfind("/");
|
||||
if (p==string::npos || path.compare(0, 5, "/card") != 0 || p<4) {
|
||||
close = true;
|
||||
result = false;
|
||||
} else {
|
||||
path = path.substr(0,p);
|
||||
selected = 0;
|
||||
fl->setPath(path);
|
||||
}
|
||||
}
|
||||
|
||||
void DirDialog::enter() {
|
||||
path += "/"+fl->at(selected);
|
||||
selected = 0;
|
||||
fl->setPath(path);
|
||||
}
|
||||
|
||||
void DirDialog::confirm() {
|
||||
close = true;
|
||||
DirDialog::~DirDialog()
|
||||
{
|
||||
delete fl;
|
||||
}
|
||||
|
@ -24,41 +24,13 @@
|
||||
#include <string>
|
||||
#include "gmenu2x.h"
|
||||
|
||||
class FileLister;
|
||||
#include "browsedialog.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
class DirDialog {
|
||||
protected:
|
||||
static const uint ACT_NONE = 0;
|
||||
static const uint ACT_SELECT = 1;
|
||||
static const uint ACT_CLOSE = 2;
|
||||
static const uint ACT_UP = 3;
|
||||
static const uint ACT_DOWN = 4;
|
||||
static const uint ACT_SCROLLUP = 5;
|
||||
static const uint ACT_SCROLLDOWN = 6;
|
||||
static const uint ACT_GOUP = 7;
|
||||
static const uint ACT_CONFIRM = 8;
|
||||
|
||||
private:
|
||||
int selRow;
|
||||
uint selected;
|
||||
bool close, result;
|
||||
FileLister *fl;
|
||||
string text;
|
||||
IconButton *btnUp, *btnEnter, *btnConfirm;
|
||||
GMenu2X *gmenu2x;
|
||||
|
||||
void up();
|
||||
void enter();
|
||||
void confirm();
|
||||
|
||||
class DirDialog : public BrowseDialog {
|
||||
public:
|
||||
string path;
|
||||
DirDialog(GMenu2X *gmenu2x, const string &text, const string &dir="");
|
||||
|
||||
bool exec();
|
||||
~DirDialog();
|
||||
};
|
||||
|
||||
#endif /*INPUTDIALOG_H_*/
|
||||
|
@ -18,170 +18,26 @@
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_gfxPrimitives.h>
|
||||
|
||||
//for browsing the filesystem
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "filedialog.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FileDialog::FileDialog(GMenu2X *gmenu2x, const string &text, const string &filter, const string &file) {
|
||||
this->gmenu2x = gmenu2x;
|
||||
this->text = text;
|
||||
this->filter = filter;
|
||||
this->file = "";
|
||||
setPath("/card");
|
||||
title = "File Browser";
|
||||
FileDialog::FileDialog(GMenu2X *gmenu2x, const string &text,
|
||||
const string &filter, const string &file, const string &title) :
|
||||
BrowseDialog(gmenu2x, title, text)
|
||||
{
|
||||
string path = "/card";
|
||||
if (!file.empty()) {
|
||||
string::size_type pos = file.rfind("/");
|
||||
if (pos != string::npos) {
|
||||
setPath( file.substr(0, pos) );
|
||||
this->file = file.substr(pos+1,file.length());
|
||||
}
|
||||
}
|
||||
selRow = 0;
|
||||
}
|
||||
|
||||
bool FileDialog::exec() {
|
||||
bool close = false, result = true, ts_pressed = false;
|
||||
if (!fileExists(path()))
|
||||
setPath("/card");
|
||||
|
||||
fl.setFilter(filter);
|
||||
fl.browse();
|
||||
|
||||
uint i, firstElement = 0, iY, action;
|
||||
uint rowHeight = gmenu2x->font->getHeight()+1; // gp2x=15+1 / pandora=19+1
|
||||
uint numRows = (gmenu2x->resY-gmenu2x->skinConfInt["topBarHeight"]-20)/rowHeight;
|
||||
SDL_Rect clipRect = {0, gmenu2x->skinConfInt["topBarHeight"]+1, gmenu2x->resX-9, gmenu2x->resY-gmenu2x->skinConfInt["topBarHeight"]-25};
|
||||
SDL_Rect touchRect = {2, gmenu2x->skinConfInt["topBarHeight"]+4, gmenu2x->resX-12, clipRect.h};
|
||||
|
||||
selected = 0;
|
||||
while (!close) {
|
||||
action = FD_NO_ACTION;
|
||||
if (gmenu2x->f200) gmenu2x->ts.poll();
|
||||
|
||||
gmenu2x->bg->blit(gmenu2x->s,0,0);
|
||||
gmenu2x->drawTitleIcon("icons/explorer.png",true);
|
||||
gmenu2x->writeTitle(title);
|
||||
gmenu2x->writeSubTitle(text);
|
||||
|
||||
gmenu2x->drawButton(gmenu2x->s, "x", gmenu2x->tr["Up one folder"],
|
||||
gmenu2x->drawButton(gmenu2x->s, "b", gmenu2x->tr["Enter folder/Confirm"], 5));
|
||||
|
||||
if (selected>firstElement+numRows-1) firstElement=selected-numRows+1;
|
||||
if (selected<firstElement) firstElement=selected;
|
||||
|
||||
//Selection
|
||||
iY = selected-firstElement;
|
||||
iY = gmenu2x->skinConfInt["topBarHeight"]+1+(iY*rowHeight);
|
||||
gmenu2x->s->box(2, iY, gmenu2x->resX-12, rowHeight-1, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
||||
|
||||
beforeFileList();
|
||||
|
||||
//Files & Directories
|
||||
gmenu2x->s->setClipRect(clipRect);
|
||||
if (ts_pressed && !gmenu2x->ts.pressed()) {
|
||||
action = FD_ACTION_SELECT;
|
||||
ts_pressed = false;
|
||||
}
|
||||
if (gmenu2x->f200 && gmenu2x->ts.pressed() && !gmenu2x->ts.inRect(touchRect)) ts_pressed = false;
|
||||
for (i=firstElement; i<fl.size() && i<firstElement+numRows; i++) {
|
||||
iY = i-firstElement;
|
||||
if (fl.isDirectory(i)) {
|
||||
if (fl[i]=="..")
|
||||
gmenu2x->sc.skinRes("imgs/go-up.png")->blit(gmenu2x->s, 5, gmenu2x->skinConfInt["topBarHeight"]+1+(iY*rowHeight));
|
||||
else
|
||||
gmenu2x->sc.skinRes("imgs/folder.png")->blit(gmenu2x->s, 5, gmenu2x->skinConfInt["topBarHeight"]+1+(iY*rowHeight));
|
||||
} else {
|
||||
gmenu2x->sc.skinRes("imgs/file.png")->blit(gmenu2x->s, 5, gmenu2x->skinConfInt["topBarHeight"]+1+(iY*rowHeight));
|
||||
}
|
||||
gmenu2x->s->write(gmenu2x->font, fl[i], 24, gmenu2x->skinConfInt["topBarHeight"]+9+(iY*rowHeight), SFontHAlignLeft, SFontVAlignMiddle);
|
||||
if (gmenu2x->f200 && gmenu2x->ts.pressed() && gmenu2x->ts.inRect(touchRect.x, touchRect.y+(iY*rowHeight), touchRect.w, rowHeight)) {
|
||||
ts_pressed = true;
|
||||
selected = i;
|
||||
}
|
||||
}
|
||||
gmenu2x->s->clearClipRect();
|
||||
|
||||
gmenu2x->drawScrollBar(numRows,fl.size(),firstElement,clipRect.y,clipRect.h);
|
||||
gmenu2x->s->flip();
|
||||
|
||||
gmenu2x->input.update();
|
||||
if ( gmenu2x->input[ACTION_SELECT] ) action = FD_ACTION_CLOSE;
|
||||
if ( gmenu2x->input[ACTION_UP ] ) action = FD_ACTION_UP;
|
||||
if ( gmenu2x->input[ACTION_L ] ) action = FD_ACTION_SCROLLUP;
|
||||
if ( gmenu2x->input[ACTION_DOWN ] ) action = FD_ACTION_DOWN;
|
||||
if ( gmenu2x->input[ACTION_R ] ) action = FD_ACTION_SCROLLDOWN;
|
||||
if ( gmenu2x->input[ACTION_X] || gmenu2x->input[ACTION_LEFT] ) action = FD_ACTION_GOUP;
|
||||
if ( gmenu2x->input[ACTION_B ] ) action = FD_ACTION_SELECT;
|
||||
|
||||
if (action == FD_ACTION_SELECT && fl[selected]=="..") action = FD_ACTION_GOUP;
|
||||
switch (action) {
|
||||
case FD_ACTION_CLOSE: {
|
||||
close = true;
|
||||
result = false;
|
||||
} break;
|
||||
case FD_ACTION_UP: {
|
||||
if (selected==0)
|
||||
selected = fl.size()-1;
|
||||
else
|
||||
selected -= 1;
|
||||
} break;
|
||||
case FD_ACTION_SCROLLUP: {
|
||||
if ((int)(selected-(numRows-2))<0) {
|
||||
selected = 0;
|
||||
} else {
|
||||
selected -= numRows-2;
|
||||
}
|
||||
} break;
|
||||
case FD_ACTION_DOWN: {
|
||||
if (selected+1>=fl.size())
|
||||
selected = 0;
|
||||
else
|
||||
selected += 1;
|
||||
} break;
|
||||
case FD_ACTION_SCROLLDOWN: {
|
||||
if (selected+(numRows-2)>=fl.size()) {
|
||||
selected = fl.size()-1;
|
||||
} else {
|
||||
selected += numRows-2;
|
||||
}
|
||||
} break;
|
||||
case FD_ACTION_GOUP: {
|
||||
string::size_type p = path().rfind("/");
|
||||
if (p==string::npos || path().compare(0, 5, "/card") != 0 || p<4)
|
||||
return false;
|
||||
else
|
||||
setPath( path().substr(0,p) );
|
||||
} break;
|
||||
case FD_ACTION_SELECT: {
|
||||
if (fl.isDirectory(selected)) {
|
||||
setPath( path()+"/"+fl[selected] );
|
||||
} else {
|
||||
if (fl.isFile(selected)) {
|
||||
file = fl[selected];
|
||||
close = true;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
if (pos != string::npos)
|
||||
path = file.substr(0, pos);
|
||||
}
|
||||
|
||||
return result;
|
||||
fl = new FileLister(path);
|
||||
fl->setFilter(filter);
|
||||
}
|
||||
|
||||
void FileDialog::setPath(const string &path) {
|
||||
path_v = path;
|
||||
fl.setPath(path);
|
||||
selected = 0;
|
||||
onChangeDir();
|
||||
FileDialog::~FileDialog()
|
||||
{
|
||||
delete fl;
|
||||
}
|
||||
|
||||
void FileDialog::beforeFileList() {}
|
||||
void FileDialog::onChangeDir() {}
|
||||
|
@ -22,44 +22,17 @@
|
||||
#define FILEDIALOG_H_
|
||||
|
||||
#include <string>
|
||||
#include "filelister.h"
|
||||
#include "gmenu2x.h"
|
||||
|
||||
#define FD_NO_ACTION 0
|
||||
#define FD_ACTION_CLOSE 1
|
||||
#define FD_ACTION_UP 2
|
||||
#define FD_ACTION_DOWN 3
|
||||
#define FD_ACTION_LEFT 4
|
||||
#define FD_ACTION_RIGHT 5
|
||||
#define FD_ACTION_SCROLLDOWN 6
|
||||
#define FD_ACTION_SCROLLUP 7
|
||||
#define FD_ACTION_GOUP 8
|
||||
#define FD_ACTION_SELECT 9
|
||||
#include "browsedialog.h"
|
||||
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
class FileDialog {
|
||||
protected:
|
||||
int selRow;
|
||||
string text, title;
|
||||
GMenu2X *gmenu2x;
|
||||
string filter;
|
||||
FileLister fl;
|
||||
uint selected;
|
||||
string path_v;
|
||||
|
||||
class FileDialog : public BrowseDialog {
|
||||
public:
|
||||
string file;
|
||||
FileDialog(GMenu2X *gmenu2x, const string &text, const string &filter="", const string &file="");
|
||||
virtual ~FileDialog() {};
|
||||
|
||||
virtual const string &path() { return path_v; };
|
||||
virtual void setPath(const string &path);
|
||||
|
||||
inline virtual void beforeFileList();
|
||||
inline virtual void onChangeDir();
|
||||
bool exec();
|
||||
FileDialog(GMenu2X *gmenu2x, const string &text, const string &filter="",
|
||||
const string &file="", const string &title = "File Dialog");
|
||||
virtual ~FileDialog();
|
||||
};
|
||||
|
||||
#endif /*INPUTDIALOG_H_*/
|
||||
|
@ -37,13 +37,13 @@ public:
|
||||
void browse();
|
||||
|
||||
vector<string> directories, files, exclude;
|
||||
uint size();
|
||||
uint dirCount();
|
||||
uint fileCount();
|
||||
string operator[](uint);
|
||||
string at(uint);
|
||||
bool isFile(uint);
|
||||
bool isDirectory(uint);
|
||||
unsigned int size();
|
||||
unsigned int dirCount();
|
||||
unsigned int fileCount();
|
||||
string operator[](unsigned int);
|
||||
string at(unsigned int);
|
||||
bool isFile(unsigned int);
|
||||
bool isDirectory(unsigned int);
|
||||
|
||||
const string &getPath();
|
||||
void setPath(const string &path, bool doBrowse=true);
|
||||
|
@ -1010,8 +1010,8 @@ void GMenu2X::explorer() {
|
||||
writeConfigOpen2x();
|
||||
|
||||
//string command = cmdclean(fd.path()+"/"+fd.file) + "; sync & cd "+cmdclean(getExePath())+"; exec ./gmenu2x";
|
||||
string command = cmdclean(fd.path()+"/"+fd.file);
|
||||
chdir(fd.path().c_str());
|
||||
string command = cmdclean(fd.getPath()+"/"+fd.getFile());
|
||||
chdir(fd.getPath().c_str());
|
||||
quit();
|
||||
setClock(200);
|
||||
execlp("/bin/sh","/bin/sh","-c",command.c_str(),NULL);
|
||||
@ -1404,7 +1404,7 @@ void GMenu2X::addLink() {
|
||||
FileDialog fd(this,tr["Select an application"]);
|
||||
if (fd.exec()) {
|
||||
ledOn();
|
||||
menu->addLink(fd.path(), fd.file);
|
||||
menu->addLink(fd.getPath(), fd.getFile());
|
||||
sync();
|
||||
ledOff();
|
||||
}
|
||||
|
@ -31,21 +31,18 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
ImageDialog::ImageDialog(GMenu2X *gmenu2x, const string &text, const string &filter, const string &file) : FileDialog(gmenu2x, text, filter, file) {
|
||||
this->text = text;
|
||||
this->filter = filter;
|
||||
setPath("/card");
|
||||
title = "Image Browser";
|
||||
ImageDialog::ImageDialog(GMenu2X *gmenu2x, const string &text,
|
||||
const string &filter, const string &file) :
|
||||
FileDialog(gmenu2x, text, filter, file, "Image Browser") {
|
||||
|
||||
string path;
|
||||
|
||||
if (!file.empty()) {
|
||||
this->file = strreplace(file,"skin:",gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]+"/");
|
||||
string::size_type pos = this->file.rfind("/");
|
||||
if (pos != string::npos) {
|
||||
setPath( this->file.substr(0, pos) );
|
||||
cout << "ib: " << path() << endl;
|
||||
this->file = this->file.substr(pos+1,file.length());
|
||||
}
|
||||
path = strreplace(file, "skin:", gmenu2x->getExePath()+"skins/"+gmenu2x->confStr["skin"]+"/");
|
||||
string::size_type pos = path.rfind("/");
|
||||
if (pos != string::npos)
|
||||
setPath(path.substr(0, pos));
|
||||
}
|
||||
selRow = 0;
|
||||
}
|
||||
|
||||
ImageDialog::~ImageDialog() {
|
||||
@ -53,8 +50,8 @@ ImageDialog::~ImageDialog() {
|
||||
}
|
||||
|
||||
void ImageDialog::beforeFileList() {
|
||||
if (fl.isFile(selected) && fileExists(path()+"/"+fl[selected]))
|
||||
previews[path()+"/"+fl[selected]]->blitRight(gmenu2x->s, 310, 43);
|
||||
if (fl->isFile(selected) && fileExists(getPath()+"/"+(*fl)[selected]))
|
||||
previews[getPath()+"/"+(*fl)[selected]]->blitRight(gmenu2x->s, 310, 43);
|
||||
}
|
||||
|
||||
void ImageDialog::onChangeDir() {
|
||||
|
@ -33,8 +33,9 @@ protected:
|
||||
public:
|
||||
ImageDialog(GMenu2X *gmenu2x, const string &text, const string &filter="", const string &file="");
|
||||
virtual ~ImageDialog();
|
||||
inline virtual void beforeFileList();
|
||||
inline virtual void onChangeDir();
|
||||
|
||||
virtual void beforeFileList();
|
||||
virtual void onChangeDir();
|
||||
};
|
||||
|
||||
#endif /*IMAGEDIALOG_H_*/
|
||||
|
@ -161,7 +161,7 @@ string Menu::sectionPath(int section) {
|
||||
/*====================================
|
||||
LINKS MANAGEMENT
|
||||
====================================*/
|
||||
bool Menu::addActionLink(uint section, const string &title, const LinkRunAction &action, const string &description, const string &icon) {
|
||||
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,action);
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
uint firstDispSection();
|
||||
uint firstDispRow();
|
||||
|
||||
bool addActionLink(uint section, const string &title, const LinkRunAction &action, const string &description="", const string &icon="");
|
||||
bool addActionLink(uint section, const string &title, LinkRunAction action, const string &description="", const string &icon="");
|
||||
bool addLink(string path, string file, string section="");
|
||||
bool addSection(const string §ionName);
|
||||
void deleteSelectedLink();
|
||||
|
@ -57,7 +57,7 @@ void MenuSettingDir::clear() {
|
||||
|
||||
void MenuSettingDir::select() {
|
||||
DirDialog dd(gmenu2x, description, value());
|
||||
if (dd.exec()) setValue( dd.path );
|
||||
if (dd.exec()) setValue( dd.getPath() );
|
||||
}
|
||||
|
||||
void MenuSettingDir::setValue(const string &value) {
|
||||
|
@ -58,7 +58,7 @@ void MenuSettingFile::clear() {
|
||||
|
||||
void MenuSettingFile::select() {
|
||||
FileDialog fd(gmenu2x, description, filter, value());
|
||||
if (fd.exec()) setValue( fd.path()+"/"+fd.file );
|
||||
if (fd.exec()) setValue( fd.getPath()+"/"+fd.getFile() );
|
||||
}
|
||||
|
||||
void MenuSettingFile::setValue(const string &value) {
|
||||
|
@ -34,7 +34,7 @@ void MenuSettingImage::manageInput() {
|
||||
if ( gmenu2x->input[ACTION_X] ) setValue("");
|
||||
if ( gmenu2x->input[ACTION_B] ) {
|
||||
ImageDialog id(gmenu2x, description, filter, value());
|
||||
if (id.exec()) setValue( id.path()+"/"+id.file );
|
||||
if (id.exec()) setValue( id.getPath()+"/"+id.getFile() );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user