1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 11:46:14 +02:00

Use a plain FileLister instead of a pointer in BrowseDialog

Configuration of the FileLister is now left to the subclasses of
BrowseDialog, as the construction of a FileLister and its configuration
(to show or hide directories and files) have been separated.

This allows deleting the destructors of BrowseDialog's subclasses,
which existed solely to delete a FileLister object constructed by
each subclass.

The allocation of a BrowseDialog now also implies allocating enough
space for its FileLister, so remove the check for fl being nullptr in
BrowseDialog::exec().
This commit is contained in:
Nebuleon Fumika 2014-08-13 04:14:19 +00:00 committed by Maarten ter Huurne
parent 1dec6f6f11
commit 0b785770dc
7 changed files with 21 additions and 38 deletions

View File

@ -48,9 +48,6 @@ BrowseDialog::~BrowseDialog()
bool BrowseDialog::exec() bool BrowseDialog::exec()
{ {
if (!fl)
return false;
string path = getPath(); string path = getPath();
if (path.empty() || !fileExists(path) if (path.empty() || !fileExists(path)
|| path.compare(0, strlen(CARD_ROOT), CARD_ROOT) != 0) || path.compare(0, strlen(CARD_ROOT), CARD_ROOT) != 0)
@ -127,7 +124,7 @@ void BrowseDialog::handleInput()
ts_pressed = false; ts_pressed = false;
} }
if (action == BrowseDialog::ACT_SELECT && (*fl)[selected] == "..") { if (action == BrowseDialog::ACT_SELECT && fl[selected] == "..") {
action = BrowseDialog::ACT_GOUP; action = BrowseDialog::ACT_GOUP;
} }
switch (action) { switch (action) {
@ -136,7 +133,7 @@ void BrowseDialog::handleInput()
break; break;
case BrowseDialog::ACT_UP: case BrowseDialog::ACT_UP:
if (selected == 0) if (selected == 0)
selected = fl->size() - 1; selected = fl.size() - 1;
else else
selected -= 1; selected -= 1;
break; break;
@ -147,14 +144,14 @@ void BrowseDialog::handleInput()
selected -= numRows - 2; selected -= numRows - 2;
break; break;
case BrowseDialog::ACT_DOWN: case BrowseDialog::ACT_DOWN:
if (fl->size() - 1 <= selected) if (fl.size() - 1 <= selected)
selected = 0; selected = 0;
else else
selected += 1; selected += 1;
break; break;
case BrowseDialog::ACT_SCROLLDOWN: case BrowseDialog::ACT_SCROLLDOWN:
if (selected+(numRows-2)>=fl->size()) if (selected+(numRows-2)>=fl.size())
selected = fl->size()-1; selected = fl.size()-1;
else else
selected += numRows-2; selected += numRows-2;
break; break;
@ -162,7 +159,7 @@ void BrowseDialog::handleInput()
directoryUp(); directoryUp();
break; break;
case BrowseDialog::ACT_SELECT: case BrowseDialog::ACT_SELECT:
if (fl->isDirectory(selected)) { if (fl.isDirectory(selected)) {
directoryEnter(); directoryEnter();
break; break;
} }
@ -203,7 +200,7 @@ void BrowseDialog::directoryEnter()
path += "/"; path += "/";
} }
setPath(path + fl->at(selected)); setPath(path + fl.at(selected));
selected = 0; selected = 0;
} }
@ -253,8 +250,8 @@ void BrowseDialog::paint()
gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
lastElement = firstElement + numRows; lastElement = firstElement + numRows;
if (lastElement > fl->size()) if (lastElement > fl.size())
lastElement = fl->size(); lastElement = fl.size();
offsetY = topBarHeight + 1; offsetY = topBarHeight + 1;
@ -262,8 +259,8 @@ void BrowseDialog::paint()
s.setClipRect(clipRect); s.setClipRect(clipRect);
for (i = firstElement; i < lastElement; i++) { for (i = firstElement; i < lastElement; i++) {
Surface *icon; Surface *icon;
if (fl->isDirectory(i)) { if (fl.isDirectory(i)) {
if ((*fl)[i] == "..") { if (fl[i] == "..") {
icon = iconGoUp; icon = iconGoUp;
} else { } else {
icon = iconFolder; icon = iconFolder;
@ -272,7 +269,7 @@ void BrowseDialog::paint()
icon = iconFile; icon = iconFile;
} }
icon->blit(s, 5, offsetY); icon->blit(s, 5, offsetY);
gmenu2x->font->write(s, (*fl)[i], 24, offsetY + rowHeight / 2, gmenu2x->font->write(s, fl[i], 24, offsetY + rowHeight / 2,
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
if (ts.available() && ts.pressed() if (ts.available() && ts.pressed()
@ -285,6 +282,6 @@ void BrowseDialog::paint()
} }
s.clearClipRect(); s.clearClipRect();
gmenu2x->drawScrollBar(numRows,fl->size(), firstElement); gmenu2x->drawScrollBar(numRows,fl.size(), firstElement);
s.flip(); s.flip();
} }

View File

@ -41,10 +41,10 @@ protected:
void setPath(const std::string &path) { void setPath(const std::string &path) {
this->path = path; this->path = path;
fl->browse(path); fl.browse(path);
} }
FileLister *fl; FileLister fl;
unsigned int selected; unsigned int selected;
private: private:
@ -98,7 +98,7 @@ public:
return path; return path;
} }
std::string getFile() { std::string getFile() {
return (*fl)[selected]; return fl[selected];
} }
}; };

View File

@ -29,12 +29,6 @@ DirDialog::DirDialog(
const string &text, const string &dir) const string &text, const string &dir)
: BrowseDialog(gmenu2x, ts, "Directory Browser", text) : BrowseDialog(gmenu2x, ts, "Directory Browser", text)
{ {
fl = new FileLister(); fl.setShowFiles(false);
fl->setShowFiles(false);
setPath(dir); setPath(dir);
} }
DirDialog::~DirDialog()
{
delete fl;
}

View File

@ -28,7 +28,6 @@ public:
DirDialog( DirDialog(
GMenu2X *gmenu2x, Touchscreen &ts, GMenu2X *gmenu2x, Touchscreen &ts,
const std::string &text, const std::string &dir = ""); const std::string &text, const std::string &dir = "");
~DirDialog();
}; };
#endif // DIRDIALOG_H #endif // DIRDIALOG_H

View File

@ -37,19 +37,13 @@ FileDialog::FileDialog(
path = file.substr(0, pos); path = file.substr(0, pos);
} }
fl = new FileLister(); fl.setFilter(filter);
fl->setFilter(filter);
setPath(path); setPath(path);
} }
FileDialog::~FileDialog()
{
delete fl;
}
bool FileDialog::exec() { bool FileDialog::exec() {
bool ret = BrowseDialog::exec(); bool ret = BrowseDialog::exec();
if (ret && fl->isDirectory(selected)) { if (ret && fl.isDirectory(selected)) {
// FileDialog must only pick regular files. // FileDialog must only pick regular files.
ret = false; ret = false;
} }

View File

@ -29,7 +29,6 @@ public:
GMenu2X *gmenu2x, Touchscreen &ts, const std::string &text, GMenu2X *gmenu2x, Touchscreen &ts, const std::string &text,
const std::string &filter="*", const std::string &file="", const std::string &filter="*", const std::string &file="",
const std::string &title = "File Dialog"); const std::string &title = "File Dialog");
virtual ~FileDialog();
bool exec(); bool exec();
}; };

View File

@ -54,8 +54,8 @@ ImageDialog::~ImageDialog() {
} }
void ImageDialog::beforeFileList() { void ImageDialog::beforeFileList() {
if (fl->isFile(selected) && fileExists(getPath()+"/"+(*fl)[selected])) if (fl.isFile(selected) && fileExists(getPath()+"/"+fl[selected]))
previews[getPath()+"/"+(*fl)[selected]]->blitRight(*gmenu2x->s, 310, 43); previews[getPath()+"/"+fl[selected]]->blitRight(*gmenu2x->s, 310, 43);
} }
void ImageDialog::onChangeDir() { void ImageDialog::onChangeDir() {