Re: count the number of file "executions" ? - crude implementation (patch)

Janek Kozicki <[email protected]>
Newsgroups gmane.comp.desktop.rox.devel
Message-ID <20080525023044.587b92c7@absurd>
Hi,

Finally I got around to implement this thing in rox. The
implementation is totally inefficient and slow, due to my very
limited gtk and rox core knowledge. So the patch I'm attaching here
is by no means supposed to be applied to rox filer source.

Instead this patch is to demonstrate how this feature should work.
And how it works for me currently, albeit very slowly:

  1. Select option Display->Count Here All Items Executions

     (it should be a "<ToggleItem>" option, the "Here" in that option
     name means "This Directory", but it would make the label too long perhaps?)

  2. If the current view is view with extra details (view_details.c),
     the number of times you execute each file in this directory will be
     shown.

Features:

  1. files are identified by size and time, so that they can be
     renamed without losing execution count. Remember that this is
     intended to work with media files (movies, music) and such files
     can often change name while still being the same movie/music file.
     But if their size or time changes it means that they have been
     edited, and so - the execution count should be reset to zero.

  2. directories in which files stay can be renamed as well, and all
     information about execution count of files in this directory is
     preserved.

Bugs:

  3. if some file is moved from one directory to another - its
     execution count is reset to zero.

  4. it relies on creating an extra .RunCount file in each directory.
     I think that instead this information should be stored somewhere in
     $XDG_CONFIG_HOME path

  5. if you look at my implementation you can get a heart attack.


This feature is extremely useful, because it's the only thing I need
when playing movies for my kids. I don't need extremely bloated
kaffeine, totem or whatever. Just rox! Come to think about it -
adding single simple feature removes the need to have kaffeine
installed on system.


I have high hopes, that rox developers will like this feature, and
agree to add it to rox using a better implementation.

In fact I want it so badly, that I offer 30 euros to person (or
persons, in which case money are divided as you decide to divide it)
who will work to make it into an official rox release.

Well... yes - I prefer to pay for this, than to learn GTK (which is a
hell more difficult than QT3/4 which I know quite good). If it
offends you, I'm really sorry.

I'm attaching my patch against version 2.7.1 and a screenshot with
counts visible for some barbie movies (I got three daughters, they
love barbie ;/)

So for now I'll be using my crazy inefficient implementation, hoping
that someone can make it better.

thanks for trying this :)
-- 
Janek Kozicki                                                         |

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
rox-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rox-devel
crude_RunCount.diff (text/x-patch, 6 KB)
diff -ur ./ROX-Filer/src/menu.c ./RunCount-ROX-Filer/src/menu.c
--- ./ROX-Filer/src/menu.c	2008-01-08 21:02:41.000000000 +0100
+++ ./RunCount-ROX-Filer/src/menu.c	2008-05-25 01:21:08.000000000 +0200
@@ -137,6 +137,7 @@
 static void show_thumbs(gpointer data, guint action, GtkWidget *widget);
 static void refresh(gpointer data, guint action, GtkWidget *widget);
 static void save_settings(gpointer data, guint action, GtkWidget *widget);
+static void run_count(gpointer data, guint action, GtkWidget *widget);
 
 static void file_op(gpointer data, FileOp action, GtkWidget *widget);
 
@@ -209,6 +210,7 @@
 {">" N_("Show Thumbnails"),	NULL, show_thumbs, 0, "<ToggleItem>"},
 {">" N_("Refresh"),		NULL, refresh, 0, "<StockItem>", GTK_STOCK_REFRESH},
 {">" N_("Save Current Display Settings..."),	 NULL, save_settings, 0, NULL},
+{">" N_("Count Here All Items Executions"),	 NULL, run_count, 0, NULL}, //FIXME - should be a "<ToggleItem>"
 {N_("File"),			NULL, NULL, 0, "<Branch>"},
 {">" N_("Copy..."),		"<Ctrl>C", file_op, FILE_COPY_ITEM, "<StockItem>", GTK_STOCK_COPY},
 {">" N_("Rename..."),		NULL, file_op, FILE_RENAME_ITEM, NULL},
@@ -1012,6 +1014,32 @@
 	filer_save_settings(window_with_focus);
 }
 
+static void run_count(gpointer data, guint action, GtkWidget *widget)
+{
+	if (updating_menu)
+		return;
+
+	g_return_if_fail(window_with_focus != NULL);
+	
+	const char *runcount, *tmp;
+	runcount = make_path(window_with_focus->sym_path, ".RunCount");
+	if (file_exists(runcount))
+	{
+		printf("%s Deleted!\n",runcount);//DEBUG
+
+		tmp = g_strdup_printf("rm %s\n", runcount);
+		// FIXME - add dialog box Yes/No to confirm deleting file .RunCount (because it contains useful information!)
+		system(tmp);
+	}
+	else
+	{
+		printf("%s Created!\n",runcount);//DEBUG
+
+		tmp = g_strdup_printf("touch %s\n", runcount);
+		system(tmp);// in fact this works correctly even if permission denied (.RunCount file is not created)
+	}
+}
+
 static void delete(FilerWindow *filer_window)
 {
 	GList *paths;
diff -ur ./ROX-Filer/src/run.c ./RunCount-ROX-Filer/src/run.c
--- ./ROX-Filer/src/run.c	2008-01-08 21:02:41.000000000 +0100
+++ ./RunCount-ROX-Filer/src/run.c	2008-05-25 01:21:10.000000000 +0200
@@ -280,6 +280,54 @@
 				filer_opendir(full_path, src_window, NULL);
 			return TRUE;
 		case TYPE_FILE:
+
+			{// count executions if file .RunCount is present
+				const char *runcount;
+				runcount = g_strdup_printf("%s/.RunCount", filer_window->sym_path);
+				if (file_exists(runcount))
+				{
+					printf("%s Exists, incrementing counter!\n",runcount); //DEBUG
+
+					gchar *time,*mtime_size,*command;
+					time = pretty_time(&item->mtime);
+					mtime_size = g_strdup_printf("mtime: %s size: %i",time,item->size);
+//					printf("%s\n",mtime_size);//DEBUG
+
+/* 
+ * That's a shell script which increments counter for a given file
+ * (identified by mtime+size pair so that renaming movies will not reset the
+ * counter). 
+ * 
+*/
+
+					command = g_strdup_printf(
+"IDENTIFIER=\"%s\"; \
+FILER_PATH=\"%s\"; \
+grep \"$IDENTIFIER\" $FILER_PATH/.RunCount \
+	&& ( \
+		grep -v \"$IDENTIFIER\" $FILER_PATH/.RunCount > $FILER_PATH/.RunCount.TMP ; \
+		COUNT=$((`grep \"$IDENTIFIER\" $FILER_PATH/.RunCount | sed -e 's/%s count: //'`+1)) ; \
+		echo \"$IDENTIFIER count: $COUNT\" >> $FILER_PATH/.RunCount.TMP ; \
+		mv $FILER_PATH/.RunCount.TMP $FILER_PATH/.RunCount \
+	) \
+	|| ( \
+		echo \"$IDENTIFIER count: 1\" >> $FILER_PATH/.RunCount \
+	)"
+,mtime_size,filer_window->sym_path,mtime_size);
+					system(command);
+					//printf("%s\n",command);
+
+					g_free(time);
+					g_free(mtime_size);
+					g_free(command);
+
+				}
+				else
+				{
+					printf("%s Doesn't Exist, skipping counter!\n",runcount); //DEBUG
+				}
+			}
+
 			if (EXECUTABLE_FILE(item) && !edit)
 			{
 				const char *argv[] = {NULL, NULL};
diff -ur ./ROX-Filer/src/view_details.c ./RunCount-ROX-Filer/src/view_details.c
--- ./ROX-Filer/src/view_details.c	2008-01-08 21:02:41.000000000 +0100
+++ ./RunCount-ROX-Filer/src/view_details.c	2008-05-25 01:46:47.000000000 +0200
@@ -380,7 +380,56 @@
 						   item->flags & ITEM_FLAG_APPDIR? "Application" :
 						   mime_type_comment(item->mime_type));
 			else
-				g_value_set_string(value, 
+			{
+
+				gchar *counter;
+				counter = g_strdup_printf("     ");
+				{// show count value if file .RunCount is present
+					gchar *runcount;
+					runcount = g_strdup_printf("%s/.RunCount", view_details->filer_window->sym_path);
+					if (file_exists(runcount))
+					{
+						gchar *mtime_size,*command;
+						mtime_size = g_strdup_printf("mtime: %s size: %i",pretty_time(&item->mtime),item->size);
+
+					// place the value in file /tmp/ROX_RunCount
+						command = g_strdup_printf(
+"grep \"%s\" %s/.RunCount | sed -e 's/%s count: //' > /tmp/ROX_RunCount"
+,mtime_size,view_details->filer_window->sym_path,mtime_size);
+						
+						//printf("%s\n",command); //DEBUG
+						system(command);
+
+					//read the number from /tmp/ROX_RunCount into string *counter
+						FILE *fp = fopen("/tmp/ROX_RunCount", "r");
+						fread (counter, 1, 4, fp);
+						fclose(fp);
+					// there's an unwanted \n character - we got to remove it.
+						int i=-1;
+						while(counter[++i]!='\n' && i<5);
+						if(counter[i]=='\n')
+							counter[i]=' ';
+						if(i==5) // if there's no count present for a file - put zero there
+							counter[0]='0';
+
+					//delete temporary file
+						system("rm /tmp/ROX_RunCount");
+
+						g_free(mtime_size);
+						g_free(command);
+
+						//printf("%s Exists, showing value! %s.\n",runcount,counter); //DEBUG
+					}
+					else
+					{
+						//printf("%s Doesn't Exist, not showing value!\n",runcount); //DEBUG
+					}
+					g_free(runcount);
+				}
+
+				gchar *txt;
+				txt = g_strdup_printf("%s %s",
+						   counter,
 						   item->flags & ITEM_FLAG_APPDIR? "App" :
 						   S_ISDIR(m) ? "Dir" :
 						   S_ISCHR(m) ? "Char" :
@@ -390,6 +439,10 @@
 						   S_ISFIFO(m) ? "Pipe" :
 						   S_ISDOOR(m) ? "Door" :
 						   "File");
+				g_value_set_string(value,txt);
+				g_free(txt);
+				g_free(counter);
+			}
 			
 			break;
 		case COL_WEIGHT:
crude_RunCount.png (image/png, 11.1 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.