Hallo zusammen,
es gab hier im board ja bereits das Thema Filebrowser unter E1 und ich habe aus dem was dort veröffentlicht wurde einen kleines Demo-Plugin gebastelt.
Damit alle was davon haben und weiterhin gute plugins für E1 entwickelt werden, möchte ich diesen code hier posten. Viel Spaß damit.
C
/*
eBrowser [Beta]
Date: 2007-09-13
Funktionaliät eines Dir/File Browsers
*/
#include <plugin.h>
#include <stdio.h>
#include <lib/gui/ewindow.h>
#include <lib/gui/elabel.h>
#include <lib/gui/ebutton.h>
#include <lib/gui/emessage.h>
#include <lib/gui/textinput.h>
#include <lib/gui/combobox.h>
#include <lib/gui/statusbar.h>
#include <lib/gui/eskin.h>
#include <lib/gdi/gfbdc.h>
#include <stdlib.h>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <lib/gui/listbox.h>
#include <lib/gdi/font.h>
using namespace std;
eString cur_moviepath="/";
/*
#include "enigma_bouquet.h"
#include <enigma.h>
#include <enigma_main.h>
#include <sselect.h>
#include <lib/dvb/servicestructure.h>
#include <lib/dvb/frontend.h>
#include <lib/gui/actions.h>
#include <lib/system/info.h>
*/
extern "C" int plugin_exec( PluginParam *par );
class eDemoDialog: public eWindow {
eListBox<eListBoxEntryText> *listbox;
eButton *bt_abort, *bt_ok;
eLabel *lb_selected, *lb_pfad;
void selectedItem(eListBoxEntryText *item);
void selectionChanged(eListBoxEntryText *item);
void makelist();
public:
eDemoDialog();
~eDemoDialog();
};
int plugin_exec( PluginParam *par )
{
eDemoDialog dlg;
dlg.show();
int result=dlg.exec();
dlg.hide();
// if (result) {
// eMessageBox msg("enigma demo", "User Abort", eMessageBox::iconWarning|eMessageBox::btOK);
// msg.show(); msg.exec(); msg.hide();
// }
return 0;
}
eDemoDialog::eDemoDialog(): eWindow(1)
{
cmove(ePoint(100, 100));
cresize(eSize(520, 376));
setText("enigma demo");
bt_ok=new eButton(this);
bt_ok->move(ePoint(clientrect.width()-110, clientrect.height()-40));
bt_ok->resize(eSize(100, 30));
bt_ok->setShortcut("green");
bt_ok->setShortcutPixmap("green");
bt_ok->loadDeco();
bt_ok->setText("START");
CONNECT(bt_ok->selected, eWidget::accept);
lb_selected=new eLabel(this);
lb_selected->move(ePoint(120, clientrect.height()-40));
lb_selected->resize(eSize(clientrect.width()-120-120, 30)); // leave space for both buttons
lb_selected->setText("");
lb_pfad=new eLabel(this);
lb_pfad->move(ePoint(120, clientrect.height()-60));
lb_pfad->resize(eSize(clientrect.width()-120-120, 30)); // leave space for both buttons
lb_pfad->setText("");
bt_abort=new eButton(this);
bt_abort->move(ePoint(10, clientrect.height()-40)); // listbox goes to height()-40
bt_abort->resize(eSize(100, 30));
bt_abort->setShortcut("red");
bt_abort->setShortcutPixmap("red");
bt_abort->loadDeco();
bt_abort->setText("STOP");
CONNECT(bt_abort->selected, eWidget::reject);
listbox=new eListBox<eListBoxEntryText>(this);
listbox->move(ePoint(10, 10));
listbox->resize(eSize(clientrect.width()-20, clientrect.height()-80));
listbox->loadDeco();
makelist();
CONNECT(listbox->selected, eDemoDialog::selectedItem);
CONNECT(listbox->selchanged, eDemoDialog::selectionChanged);
setFocus(listbox);
}
eDemoDialog::~eDemoDialog(){
}
void eDemoDialog::selectedItem(eListBoxEntryText *item) {
int item_eintrag;
eString item_text;
eString message;
eString folder;
if (item) {
item_eintrag=(int)item->getKey();
eString item_text = item->getText();
if(item_text.compare("[eine Ebene nach oben]")== 0){ //cutting the last folder of cur_path
int last_dir = cur_moviepath.find_last_of("/");
cur_moviepath.erase(last_dir);
last_dir = cur_moviepath.find_last_of("/");
cur_moviepath.erase(last_dir+1);
message = "Eine Ebene nach oben.";
eMessageBox msg(message, "parent", eMessageBox::iconWarning|eMessageBox::btOK);
msg.show(); msg.exec(); msg.hide();
makelist();
}
else {
struct stat64 s;
stat64(eString().sprintf("%s%s",cur_moviepath.c_str(),item_text.c_str()).c_str(), &s);
if (S_ISREG(s.st_mode)) { //&& (filen_tmp.substr(filen.length()-4, 4).compare("") == 0))
message = eString().sprintf("%s%s",cur_moviepath.c_str(),item_text.c_str()).c_str();
eMessageBox msg(message, "Datei", eMessageBox::iconWarning|eMessageBox::btOK);
msg.show(); msg.exec(); msg.hide();
}
else if (S_ISDIR(s.st_mode)) {
cur_moviepath = cur_moviepath + item_text + "/";
makelist();
}
}
}
else { reject(); }
}
void eDemoDialog::selectionChanged(eListBoxEntryText *item) {
int item_eintrag=(int)item->getKey();
eString item_text, message;
item_text = item->getText();
message = eString().sprintf("%s%s",cur_moviepath.c_str(),item_text.c_str()).c_str();
if (item) {
struct stat64 s;
stat64(eString().sprintf("%s%s",cur_moviepath.c_str(),item_text.c_str()).c_str(), &s);
if (S_ISREG(s.st_mode)) {
lb_pfad->setText(message);
lb_selected->setText("Datei");
}
else if (S_ISDIR(s.st_mode)) {
lb_pfad->setText(message);
lb_selected->setText("Verzeichnis");
}
}
}
void eDemoDialog::makelist() {
eString filen, filen_tmp;
int i;
listbox->beginAtomic();
listbox->clearList();
if(cur_moviepath.compare("") != 0) {
new eListBoxEntryText(listbox, "[eine Ebene nach oben]", (void *)0);
}
if ((access(cur_moviepath.c_str(),0)) ==0) {
struct dirent64 **namelist;
int n = scandir64(cur_moviepath.c_str(), &namelist, 0, alphasort64);
if (n > 0) {
for (i = 0; i < n; i++) {
filen = namelist[i]->d_name;
filen_tmp = namelist[i]->d_name;
filen_tmp.upper();
if ((filen != ".") && (filen != "..")) {
struct stat64 s;
stat64(eString().sprintf("%s/%s",cur_moviepath.c_str(),filen.c_str()).c_str(), &s);
if (S_ISREG(s.st_mode)) { //&& (filen_tmp.substr(filen.length()-4, 4).compare("") == 0))
new eListBoxEntryText(listbox, eString(filen), (void *)i);
}
else if (S_ISDIR(s.st_mode)) {
//new eListBoxEntryText(listbox, eString("[DIR] ")+eString(filen), (void *)i);
new eListBoxEntryText(listbox,eString(filen), (void *)i);
}
}
free(namelist[i]);
}
}
free(namelist);
listbox->endAtomic();
listbox->moveSelection(eListBoxBase::dirFirst);
setFocus(listbox);
}
else {
eDebug("Verzeichnis nicht gefunden : %s",cur_moviepath.c_str());
}
}
//EOF
Alles anzeigen
Dieser Code ist durch code-schnippsel von unterschiedlichen Leuten entstanden, ich bedanke mich bei allen die in den vorangegangenen threads Ihre codes veröffentlicht haben.