特殊:Badtitle/NS100:RotateWallpapers:修订间差异

来自Ubuntu中文
跳到导航跳到搜索
Wikibot留言 | 贡献
无编辑摘要
Wikibot留言 | 贡献
无编辑摘要
 
(未显示同一用户的2个中间版本)
第1行: 第1行:
{{From|https://help.ubuntu.com/community/RotateWallpapers}}
{{From|https://help.ubuntu.com/community/RotateWallpapers}}
{{Languages|UbuntuHelp:RotateWallpapers}}
{{Languages|UbuntuHelp:RotateWallpapers}}
<<Include(Tag/Deletion)>>
This program was custom made by a developer in the nautilus channel.
This program was custom made by a developer in the nautilus channel.
Thanks gicmo!
Thanks gicmo!
第13行: 第14行:
<pre><nowiki>
<pre><nowiki>
/*  
/*  
Compile with:
 
gcc -Wall -o change-bg `pkg-config --cflags --libs gnome-vfs-2.0 gconf-2.0` change-bg.c
  Compile with:
Copyright (C) 2005, Christian Kellner
  gcc -Wall -o change-bg `pkg-config --cflags --libs gnome-vfs-2.0 gconf-2.0` change-bg.c
The Gnome Library is free software; you can redistribute it and/or
 
modify it under the terms of the GNU Library General Public License as
  Copyright (C) 2005, Christian Kellner
published by the Free Software Foundation; either version 2 of the
 
License, or (at your option) any later version.
  The Gnome Library is free software; you can redistribute it and/or
The Gnome Library is distributed in the hope that it will be useful,
  modify it under the terms of the GNU Library General Public License as
but WITHOUT ANY WARRANTY; without even the implied warranty of
  published by the Free Software Foundation; either version 2 of the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  License, or (at your option) any later version.
Library General Public License for more details.
 
You should have received a copy of the GNU Library General Public
  The Gnome Library is distributed in the hope that it will be useful,
License along with the Gnome Library; see the file COPYING.LIB.  If not,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Boston, MA 02111-1307, USA.
  Library General Public License for more details.
 
  You should have received a copy of the GNU Library General Public
  License along with the Gnome Library; see the file COPYING.LIB.  If not,
  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.
 
 
*/
*/
#include <libgnomevfs/gnome-vfs.h>
#include <libgnomevfs/gnome-vfs.h>
#include <gconf/gconf-client.h>
#include <gconf/gconf-client.h>
第34行: 第43行:
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
GConfClient  *gcc = NULL;
GConfClient  *gcc = NULL;
char        *text_uri = NULL;
char        *text_uri = NULL;
第45行: 第55行:
gboolean result;
gboolean result;
char *path;
char *path;
if (gcc == NULL) {
if (gcc == NULL) {
gcc = gconf_client_get_default ();
gcc = gconf_client_get_default ();
第50行: 第61行:
path = (char *) iter->data;
path = (char *) iter->data;
nuri = gnome_vfs_uri_append_string (uri, path);
nuri = gnome_vfs_uri_append_string (uri, path);
path = gnome_vfs_uri_to_string (nuri, GNOME_VFS_URI_HIDE_USER_NAME |
path = gnome_vfs_uri_to_string (nuri, GNOME_VFS_URI_HIDE_USER_NAME |
GNOME_VFS_URI_HIDE_PASSWORD |
GNOME_VFS_URI_HIDE_PASSWORD |
第56行: 第68行:
GNOME_VFS_URI_HIDE_HOST_PORT |
GNOME_VFS_URI_HIDE_HOST_PORT |
GNOME_VFS_URI_HIDE_HOST_NAME);
GNOME_VFS_URI_HIDE_HOST_NAME);
fprintf (stdout, "Setting bg to %s\n", path);
fprintf (stdout, "Setting bg to %s\n", path);
result = gconf_client_set_string (gcc,
result = gconf_client_set_string (gcc,
  "/desktop/gnome/background/picture_filename",
  "/desktop/gnome/background/picture_filename",
  path,
  path,
  NULL);
  NULL);
g_free (path);
g_free (path);
if (result == FALSE) {
if (result == FALSE) {
fprintf (stderr, "Error setting %s as bg\n", path);
fprintf (stderr, "Error setting %s as bg\n", path);
}
}
if (iter->next != NULL) {
if (iter->next != NULL) {
iter = iter->next;
iter = iter->next;
第70行: 第87行:
iter = files;
iter = files;
}
}
return TRUE;
return TRUE;
}
}
static gboolean
static gboolean
visit_files (const gchar *rel_path,
visit_files (const gchar *rel_path,
第81行: 第100行:
GList **files = (GList **) data;
GList **files = (GList **) data;
*recurse = TRUE;
*recurse = TRUE;
if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE &&
if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE &&
    (g_str_equal (info->mime_type, "image/png") ||
    (g_str_equal (info->mime_type, "image/png") ||
    g_str_equal (info->mime_type, "image/jpeg"))) {
    g_str_equal (info->mime_type, "image/jpeg"))) {
*files = g_list_prepend (*files, g_strdup (rel_path));
*files = g_list_prepend (*files, g_strdup (rel_path));
fprintf (stdout, "Adding %s\n", rel_path);
fprintf (stdout, "Adding %s\n", rel_path);
}
}
return !recursing_will_loop;
return !recursing_will_loop;
}
}
int
int
main (int argc, char **argv)
main (int argc, char **argv)
第95行: 第118行:
GMainLoop      *ml;
GMainLoop      *ml;
int            mins;
int            mins;
if (argc != 3) {
if (argc != 3) {
fprintf (stderr, "Usage: %s <seconds> <uri>\n", argv[0]);
fprintf (stderr, "Usage: %s <seconds> <uri>\n", argv[0]);
return 1;
return 1;
}
}
if (! gnome_vfs_init ()) {
if (! gnome_vfs_init ()) {
fprintf (stderr, "Cannot initialize gnome-vfs.\n");
fprintf (stderr, "Cannot initialize gnome-vfs.\n");
return 1;
return 1;
}
}
text_uri = gnome_vfs_make_uri_from_shell_arg (argv[2]);
text_uri = gnome_vfs_make_uri_from_shell_arg (argv[2]);
mins = atoi (argv[1]);
mins = atoi (argv[1]);
if (text_uri === NULL || mins === 0) {
if (text_uri == NULL || mins == 0) {
fprintf (stderr, "Usage: %s <seconds> 0> <uri>\n", argv[0]);
fprintf (stderr, "Usage: %s <seconds> 0> <uri>\n", argv[0]);
return 1;
return 1;
}
}
fprintf (stdout, "Generating file list ...\n");
fprintf (stdout, "Generating file list ...\n");
files = NULL;
files = NULL;
第118行: 第147行:
    visit_files,
    visit_files,
    &files);
    &files);
if (result != GNOME_VFS_OK) {
if (result != GNOME_VFS_OK) {
fprintf (stderr, "Error: %s\n",
fprintf (stderr, "Error: %s\n",
第123行: 第153行:
return 1;
return 1;
}
}
uri = gnome_vfs_uri_new (text_uri);
uri = gnome_vfs_uri_new (text_uri);
iter = files;
iter = files;
g_timeout_add (1000 * mins, change_picture, NULL);
g_timeout_add (1000 * mins, change_picture, NULL);
ml = g_main_loop_new (NULL, FALSE);
ml = g_main_loop_new (NULL, FALSE);
fprintf (stdout, "Going into main loop (timeout: %d seconds)\n", mins);
fprintf (stdout, "Going into main loop (timeout: %d seconds)\n", mins);
g_main_loop_run (ml);
g_main_loop_run (ml);
return 0;
return 0;
}
}
第162行: 第198行:
done
done
</nowiki></pre>
</nowiki></pre>
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]


[[category:UbuntuHelp]]
[[category:UbuntuHelp]]

2009年11月17日 (二) 20:32的最新版本

{{#ifexist: :RotateWallpapers/zh | | {{#ifexist: RotateWallpapers/zh | | {{#ifeq: {{#titleparts:RotateWallpapers|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:RotateWallpapers|1|-1|}} | zh | | }}

<<Include(Tag/Deletion)>> This program was custom made by a developer in the nautilus channel. Thanks gicmo! change-bg rotates your wallpaper (jpg/png) in a gnome enviornment over a specified amount of time.

Dependencies

Install both of the following. libgnomevfs2-dev build-essential

Source Code

1.Copy this source code into a blank text document. 2.Save as change-bg.c

/* 

   Compile with:
   gcc -Wall -o change-bg `pkg-config --cflags --libs gnome-vfs-2.0 gconf-2.0` change-bg.c
   
   Copyright (C) 2005, Christian Kellner

   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.


*/

#include <libgnomevfs/gnome-vfs.h>
#include <gconf/gconf-client.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>

GConfClient  *gcc = NULL;
char         *text_uri = NULL;
GnomeVFSURI  *uri;
GList        *files = NULL;
GList        *iter = NULL;
static gboolean
change_picture (gpointer data)
{
	GnomeVFSURI *nuri;
	gboolean result;
	char *path;

	if (gcc == NULL) {
		gcc = gconf_client_get_default ();
	}
	path = (char *) iter->data;
	nuri = gnome_vfs_uri_append_string (uri, path);
	
	path = gnome_vfs_uri_to_string (nuri, GNOME_VFS_URI_HIDE_USER_NAME |
					GNOME_VFS_URI_HIDE_PASSWORD |
					GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD |
					GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER |
					GNOME_VFS_URI_HIDE_HOST_PORT |
					GNOME_VFS_URI_HIDE_HOST_NAME);

	fprintf (stdout, "Setting bg to %s\n", path);
	
	result = gconf_client_set_string (gcc,
					  "/desktop/gnome/background/picture_filename",
					  path,
					  NULL);

	g_free (path);

	if (result == FALSE) {
		fprintf (stderr, "Error setting %s as bg\n", path);
	}

	if (iter->next != NULL) {
		iter = iter->next;
	} else {
		iter = files;
	}
	
	return TRUE;
}

static gboolean
visit_files (const gchar *rel_path,
	     GnomeVFSFileInfo *info,
	     gboolean recursing_will_loop,
	     gpointer data,
	     gboolean *recurse)
{
	GList **files = (GList **) data;
	*recurse = TRUE;

	if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE &&
	    (g_str_equal (info->mime_type, "image/png") ||
	     g_str_equal (info->mime_type, "image/jpeg"))) {
		
		*files = g_list_prepend (*files, g_strdup (rel_path));
		fprintf (stdout, "Adding %s\n", rel_path);
	}
	
	return !recursing_will_loop;
}

int
main (int argc, char **argv)
{
	GnomeVFSResult  result;
	GMainLoop      *ml;
	int             mins;
		
	if (argc != 3) {
		fprintf (stderr, "Usage: %s <seconds> <uri>\n", argv[0]);
		return 1;
	}

	if (! gnome_vfs_init ()) {
		fprintf (stderr, "Cannot initialize gnome-vfs.\n");
		return 1;
	}

	text_uri = gnome_vfs_make_uri_from_shell_arg (argv[2]);

	mins = atoi (argv[1]);
	
	if (text_uri == NULL || mins == 0) {
		fprintf (stderr, "Usage: %s <seconds> 0> <uri>\n", argv[0]);
		return 1;
	}
	
	fprintf (stdout, "Generating file list ...\n");
	files = NULL;
	result = gnome_vfs_directory_visit (text_uri,
					    GNOME_VFS_FILE_INFO_GET_MIME_TYPE | 
					    GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE,
					    GNOME_VFS_DIRECTORY_VISIT_LOOPCHECK |
					    GNOME_VFS_DIRECTORY_VISIT_SAMEFS,
					    visit_files,
					    &files);

	if (result != GNOME_VFS_OK) {
		fprintf (stderr, "Error: %s\n",
			 gnome_vfs_result_to_string (result));
		return 1;
	}
	
	uri = gnome_vfs_uri_new (text_uri);
	
	iter = files;
	
	g_timeout_add (1000 * mins, change_picture, NULL);
	
	ml = g_main_loop_new (NULL, FALSE);

	fprintf (stdout, "Going into main loop (timeout: %d seconds)\n", mins);
	g_main_loop_run (ml);
	
	return 0;
}

Compiling

Change directories to where change-bg.c is located and run the following command.

gcc -Wall -o change-bg `pkg-config --cflags --libs gnome-vfs-2.0 gconf-2.0` change-bg.c

Using

./change-bg <seconds> <location of wallpapers>

Doing it with a Bash script

As an alternative you could save the following script and call it from a startup program [Sessions]. Modify the WALLPAPER_LOCATION to the place where you store your wallpaper images.

#!/bin/bash
# change_wp [seconds]	  Changes the wallpaper at a given interval of seconds.
# example: change_wp 3600	 change the wallpaper every hour.
# If you do not supply any time it just changes the wallpaper and exits.
# Copyleft (C) 2007, 	Albert Bicchi 	[email protected]
WALLPAPER_LOCATION="/home/albert/wallpapers"
find "${WALLPAPER_LOCATION}" -iname '*.jp*g' -o -iname '*.png' > /tmp/wallpapers
TOTAL=`cat /tmp/wallpapers | wc -l`
while [ 1 ]
do
	((LINE=RANDOM%TOTAL+1))
	WALLPAPER=`sed -n "$LINE"p /tmp/wallpapers`
	gconftool -t str -s /desktop/gnome/background/picture_filename "${WALLPAPER}"
	if [ "$1" = "" ]; then
		exit 0
	fi
	sleep "$1s"
done