[Mp3blaster-devel] [patch] mp3blaster: Add 'readonly' mode

Bernhard Fischer rep.nop at aon.at
Sun Jan 9 23:01:55 CET 2005


Package: mp3blaster
Version: 1:3.2.0-6
Severity: wishlist
Tags: patch

http://www.stack.nl/~brama/mp3blaster/index.html?page=todo
has these lines in the IMPORTANT section:
-Add 'readonly' mode (similar to '%' in mutt), enable it by default, to
prevent
 people from accidentally deleting their mp3 collection.

The attached patch 'fixes' it for me.

doc/sample.mp3blasterrc, mp3blaster.1
	* document new keywords: ReadOnly = yes
	  and Key.ToggleReadonly = %
src/config.cc,src/keybindings.h,src/main.cc,src/mp3blaster.h
	* implement readonly mode, make it the default and print
	  an indicator beneath the status-window for good visibility.


-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.6.8-p4-smp
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

Versions of packages mp3blaster depends on:
ii  libc6                       2.3.2.ds1-20 GNU C Library: Shared libraries an
ii  libgcc1                     1:3.4.3-6    GCC support library
ii  libncurses5                 5.4-4        Shared libraries for terminal hand
ii  libsidplay1-c102            1.36.59-2    SID (MOS 6581) emulation library
ii  libstdc++5                  1:3.3.5-5    The GNU Standard C++ Library v3
ii  libvorbis0a                 1.0.1-1      The Vorbis General Audio Compressi
ii  libvorbisfile3              1.0.1-1      The Vorbis General Audio Compressi

-- no debconf information
-------------- next part --------------
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/doc/sample.mp3blasterrc mp3blaster-3.2.0/doc/sample.mp3blasterrc
--- mp3blaster-3.2.0.oorig/doc/sample.mp3blasterrc	2002-09-20 22:40:14.000000000 +0200
+++ mp3blaster-3.2.0/doc/sample.mp3blasterrc	2005-01-09 22:39:40.000000000 +0100
@@ -7,6 +7,10 @@
 #Threads=250
 #SoundDevice = /dev/dsp
 
+#Read-only mode (default): no file deletion is allowed.
+#ReadOnly = yes
+#Key.ToggleReadonly = %
+
 #AudiofileMatching is a list of regular expressions that determine which file
 #is considered a valid audiofile. matching is done using default settings and
 #regexec(3). Extended, case-insensitive regular expression matchins is used 
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/mp3blaster.1 mp3blaster-3.2.0/mp3blaster.1
--- mp3blaster-3.2.0.oorig/mp3blaster.1	2003-09-08 23:25:48.000000000 +0200
+++ mp3blaster-3.2.0/mp3blaster.1	2005-01-09 22:47:48.000000000 +0100
@@ -315,6 +319,11 @@ to the koi8-r charset is included.
 If true, downsample audio output to 22Khz instead of 44Khz (necessary on some
 ancient soundcards, like genuine Soundblaster Pro's)
 .TP
+\fBReadonly\fR (boolean)
+If true, deleting files and marking files as bad is not allowed. This setting
+is useful to prevent people from accidentally deleting their mp3 collection.
+The default value for Readonly is true.
+.TP
 \fBFile.ID3Names\fR (boolean)
 If enabled, the display mode in the file manager will show mp3's
 by their ID3-tag by default, instead of their filename. (default: disabled)
@@ -557,6 +566,8 @@ which function they're attached to.
 \fBKey.ClearPlaylist\fR (keybinding)
 .TP
 \fBKey.DeleteMark\fR (keybinding)
+.TP
+\fBKey.ToggleReadonly\fR (keybinding)
 .SH BUGS
 .PP
 If you find bugs, please send reports to mp3blaster-devel at stack.nl. An archive
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/src/config.cc mp3blaster-3.2.0/src/config.cc
--- mp3blaster-3.2.0.oorig/src/config.cc	2002-09-20 22:40:15.000000000 +0200
+++ mp3blaster-3.2.0/src/config.cc	2005-01-09 19:24:41.000000000 +0100
@@ -162,6 +165,8 @@ struct _confopts
 { "Key.Home", 2 },
 { "Key.End", 2 },
 { "PanSize", 0 },
+{ "Readonly", 1 },
+{ "Key.ToggleReadonly", 2 },
 { NULL, 0 }, /* last entry's keyword MUST be NULL */
 };
 
@@ -534,6 +553,8 @@ cf_add_keyword(int keyword, const char *
 			return 0;
 		}
 		break;
+	case 104: globalopts.readonly = cf_type_yesno(v); break;
+	case 105: bindkey(CMD_TOGGLE_READONLY, cf_type_key(v)); break;
 	}
 
 	return 1;
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/src/keybindings.h mp3blaster-3.2.0/src/keybindings.h
--- mp3blaster-3.2.0.oorig/src/keybindings.h	2002-09-20 22:40:15.000000000 +0200
+++ mp3blaster-3.2.0/src/keybindings.h	2005-01-09 22:36:05.000000000 +0100
@@ -72,6 +72,7 @@ keybind_t keys[] = 
 	{ '-', CMD_HELP_PREV, PM_ANY, "Scroll Up Helptext" },
 	{ '+', CMD_HELP_NEXT, PM_ANY, "Scroll Down Helptxt" },
 	{ 'E', CMD_PLAY_SKIPEND, PM_ANY, "Skip to End Song" },
+	{ '%', CMD_TOGGLE_READONLY, PM_ANY, "Toggle readonly" },
 	{ 0, CMD_NONE, PM_ANY, "" } //this should *always* be the last struct here */
 };
 
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/src/main.cc mp3blaster-3.2.0/src/main.cc
--- mp3blaster-3.2.0.oorig/src/main.cc	2003-09-09 23:22:55.000000000 +0200
+++ mp3blaster-3.2.0/src/main.cc	2005-01-09 22:41:41.000000000 +0100
@@ -198,6 +198,7 @@ void select_files_by_pattern(char *, voi
 void playlist_write(char *playlistfile, void *args);
 void fw_rename_file(char *newname, void *args);
 void *lirc_loop(void *);
+void cw_draw_readonly();
 #ifdef TEMPIE
 #define LOCK_NCURSES (!pthread_mutex_trylock(&ncurses_mutex))
 #define UPDATE_CURSES pthread_cond_signal(&ncurses_cond)
@@ -518,6 +523,7 @@ main(int argc, char *argv[], char *envp[
 		globalopts.debug = 1;
 		debug("Debugging of mp3blaster started.\n");
 	}
+	globalopts.readonly = 1;
 
 	//read .mp3blasterrc
 	if (!cf_parse_config_file(config_file) &&
@@ -1074,15 +1086,20 @@ draw_static(int file_mode)
 	getmaxyx(stdscr,maxy,maxx);
 	r = maxx - 12;
 
-	if (file_mode);
 	//First, the border
 	box(stdscr, ACS_VLINE, ACS_HLINE);
+
 	//Now, the line under the function keys and above the status window
 	move(5,1); hline(ACS_HLINE, maxx-2);
 	move(5,0); addch(ACS_LTEE); move(5,maxx-1); addch(ACS_RTEE);
 	move(maxy-4,1); hline(ACS_HLINE, maxx-2);
 	move(maxy-4,0); addch(ACS_LTEE); move(maxy-4,maxx-1); addch(ACS_RTEE);
 
+	if (file_mode); /* silence gcc */
+	// readonly indicator
+	move(maxy-1,4); addstr("[ ] readonly ");
+	cw_draw_readonly();
+
 	//draw the box bottom-right from the function keys
 	move(10,r); hline(ACS_HLINE, 11);
 	move(6,r-1); vline(ACS_VLINE,4);
@@ -1110,8 +1127,8 @@ draw_static(int file_mode)
 	move(maxy-3,maxx-13); addch(ACS_VLINE);
 	move(maxy-2,maxx-13); addch(ACS_VLINE);
 	move(maxy-1,maxx-13); addch(ACS_BTEE);
-	//draw cd-style keys
 
+	//draw cd-style keys
 	draw_play_key(0);
 	attrset(COLOR_PAIR(CP_LABEL));
 	move(maxy-9,  r); addstr(" |<"); move(maxy-8,  r);
@@ -3745,6 +3763,13 @@ handle_input(short no_delay)
 			else if (progmode == PM_HELP)
 				bighelpwin->jumpBottom();
 		break;
+		case CMD_TOGGLE_READONLY:
+			globalopts.readonly = !globalopts.readonly;
+			debug("Readonly: %s\n",
+					globalopts.readonly?"true":"false");
+			cw_draw_readonly();
+			refresh();
+		break;
 		case CMD_NONE: break;
 		default:
 			if (mixer)
@@ -4694,7 +4719,17 @@ cw_draw_repeat()
 	else
 		addch(' ');
 }
- 
+
+void
+cw_draw_readonly()
+{
+	move(LINES-1,5);
+	if (globalopts.readonly)
+		addch('X');
+	else
+		addch(' ');
+}
+
 /* Function   : init_helpwin
  * Description: sets up the helpwin that's on top of the ncurses window.
  *            : Do this whenever you change program mode (normal mode to
@@ -4971,6 +5006,7 @@ init_globalopts()
 	globalopts.selectitems_caseinsensitive = 1; //only works for regexp search
 	globalopts.scan_mp3s = 0; //scan mp3's to calculate correct total time.
 	globalopts.wraplist = true;
+	globalopts.readonly = 1; /* readonly is true per default */
 }
 
 void
@@ -5054,7 +5090,12 @@ fw_markfilebad(const char *file)
 	short
 		result = 0;
 
-if (file){ debug("FILE: ");debug(file);debug("\n");}
+	if (file)
+		debug("FILE: %s\n", file);
+	if (globalopts.readonly) {
+		//warning("Could not mark file as bad -- readonly mode.");
+		return 0;
+	}
 	baditem = chop_path(file);
 	oldpath = chop_file(file); //must be delete[]'d
 
@@ -5086,16 +5127,16 @@ if (file){ debug("FILE: ");debug(file);d
 	}
 
 	strcat(baddir, baditem);
-	debug("baddir(2): ");
-	debug(baddir);
-	debug("\n");
+	debug("baddir(2): %s\n", baddir);
 	int rsuccess = rename(file, (const char*)baddir);
 	if (rsuccess < 0)
 		result = 0;
-	else
+	else {
 		result = 1;
+		mw_settxt("File marked as bad.");
+	}
 	//warning("Failed to mark file as bad.\n");
-	
+
 	delete[] baddir;
 	delete[] oldpath;
 
@@ -5372,14 +5413,14 @@ fw_delete()
 {
 	const char
 		*file = file_window->getSelectedItem();
-	
 	if (file && !is_dir(file))
 	{
-		if (unlink(file) < 0)
-			warning("Could not delete file.");
+		if (globalopts.readonly || unlink(file) < 0)
+			warning("Could not delete file: readonly-mode.");
 		else
 		{
 			fw_changedir(".");
+			debug("Deleted file: %s\n",file);
 			mw_settxt("File deleted.");
 		}
 	}
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/src/mp3blaster.h mp3blaster-3.2.0/src/mp3blaster.h
--- mp3blaster-3.2.0.oorig/src/mp3blaster.h	2002-09-20 22:40:15.000000000 +0200
+++ mp3blaster-3.2.0/src/mp3blaster.h	2005-01-09 16:02:06.000000000 +0100
@@ -51,7 +51,8 @@ enum command_t { 
 	CMD_CLEAR_PLAYLIST, CMD_DEL_MARK, CMD_FILE_TOGGLE_SORT,
 	CMD_FILE_DELETE, CMD_PLAY_SKIPEND, CMD_PLAY_NEXTGROUP, CMD_PLAY_PREVGROUP,
 	CMD_SELECT_ITEMS, CMD_DESELECT_ITEMS, CMD_FILE_RENAME, CMD_TOGGLE_DISPLAY,
-	CMD_JUMP_TOP, CMD_JUMP_BOT, CMD_TOGGLE_WRAP, CMD_LEFT, CMD_RIGHT
+	CMD_JUMP_TOP, CMD_JUMP_BOT, CMD_TOGGLE_WRAP, CMD_LEFT, CMD_RIGHT,
+	CMD_TOGGLE_READONLY
 };
 
 /* how to sort files in dirs ? */
@@ -132,6 +133,7 @@ struct _globalopts /* global options, ex
 	short scan_mp3s;
 	bool wraplist;	// non-zero if user wants scrollwins to wrap on scrolling
 	short pan_size;
+	short readonly; /* readonly mode; no file deletion */
 };
 
 enum keydescs { Main_SelectFiles, Fileman_AddFiles, Playwin_Previous };


More information about the Mp3blaster-devel mailing list