Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[vdr] Re: Pacth: add delete button to mp3/mplayer plugin
Andrey Kuzmin wrote:
This is a small contribution. With this patch you can use the '1' button
to delete a file when you are under the file browser menu.
It will be nice also to have a possibility to remove whole directory,
not only a single file.
I know, that's why I did some modification ;-) I think you want the
extra part. I took the code form the vdrc plugin which is not maintained
anymore.
diff -u mp3-ori--0.9.8/menu.c mp3-0.9.8/menu.c
--- mp3-ori--0.9.8/menu.c 2004-12-21 10:39:20.000000000 +0100
+++ mp3-0.9.8/menu.c 2004-12-21 18:51:43.649096545 +0100
@@ -72,6 +72,11 @@
#endif
}
+eKeys Confirm(const char *text)
+{
+ return Skins.Message(mtInfo,text,3);
+}
+
// --- cMenuBrowseItem ---------------------------------------------------------
class cMenuBrowseItem : public cOsdItem {
@@ -226,6 +231,66 @@
return osContinue;
}
+bool Remove_Recursive(char* sPath)
+{
+ bool bReturn = false;
+ DIR *dDir;
+ struct dirent *stDir;
+
+ dDir = opendir(sPath);
+ if (dDir) {
+ bool bNoError = true;
+ while ( (stDir = readdir(dDir)) && bNoError) {
+ struct stat statFile;
+ if ( strcmp(stDir->d_name, ".") == 0 || strcmp(stDir->d_name, "..") == 0 ) continue;
+ char *sFullFile;
+ asprintf(&sFullFile, "%s/%s", sPath, stDir->d_name);
+ bNoError = (lstat(sFullFile, &statFile) == 0);
+ if (bNoError) {
+ if ( S_ISDIR(statFile.st_mode) )
+ bNoError = Remove_Recursive(sFullFile);
+ else {
+ bNoError = ( unlink(sFullFile) == 0 );
+ }
+ }
+ if (sFullFile) free(sFullFile);
+ }
+ if (bNoError) {
+ closedir(dDir);
+ bNoError = (rmdir(sPath) == 0);
+ }
+ if (bNoError) bReturn = true;
+ }
+ return bReturn;
+}
+
+eOSState cMenuBrowse::Delete(void)
+{
+ eOSState res=osContinue;
+ cFileObj *item;
+ char *s;
+
+ if((item=CurrentItem())) {
+ switch(item->Type()) {
+ case otDir:
+ case otFile:
+ asprintf(&s, "Delete \"%s\" ?", item->Path());
+ if ( Confirm(s) == kOk ) {
+ if( Remove_Recursive( (char *) item->FullPath() ) == -1 )
+ Error(tr("Error deleting file"));
+ else
+ Del(Current());
+ Display();
+ }
+ free(s);
+ break;
+ default:
+ break;
+ }
+ }
+ return res;
+}
+
eOSState cMenuBrowse::ProcessStdKey(eKeys Key, eOSState state)
{
if(state==osUnknown) {
@@ -236,6 +301,7 @@
case kBlue: if(withID3) state=ID3Info();
break;
//case kMenu: state=osEnd; break;
+ case k1: return Delete();
default: break;
}
}
diff -u mp3-ori--0.9.8/menu.h mp3-0.9.8/menu.h
--- mp3-ori--0.9.8/menu.h 2004-12-21 10:39:20.000000000 +0100
+++ mp3-0.9.8/menu.h 2004-12-21 15:09:09.000000000 +0100
@@ -63,6 +63,7 @@
cFileObj *CurrentItem(void);
virtual void SetButtons(void);
virtual eOSState ID3Info(void);
+ eOSState Delete(void);
virtual eOSState ProcessStdKey(eKeys Key, eOSState state);
public:
cMenuBrowse(cFileSource *Source, bool Dirselect, bool WithID3, const char *title);
Home |
Main Index |
Thread Index