特殊:Badtitle/NS100:RotateWallpapers:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
第13行: | 第13行: | ||
<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行: | 第42行: | ||
#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行: | 第54行: | ||
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行: | 第60行: | ||
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行: | 第67行: | ||
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行: | 第86行: | ||
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行: | 第99行: | ||
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行: | 第117行: | ||
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 | |||
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行: | 第146行: | ||
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行: | 第152行: | ||
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; | ||
} | } |
2007年12月6日 (四) 10:53的版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/RotateWallpapers }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/af | • {{#if: UbuntuHelp:RotateWallpapers|Afrikaans| [[::RotateWallpapers/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/ar | • {{#if: UbuntuHelp:RotateWallpapers|العربية| [[::RotateWallpapers/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/az | • {{#if: UbuntuHelp:RotateWallpapers|azərbaycanca| [[::RotateWallpapers/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/bcc | • {{#if: UbuntuHelp:RotateWallpapers|جهلسری بلوچی| [[::RotateWallpapers/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/bg | • {{#if: UbuntuHelp:RotateWallpapers|български| [[::RotateWallpapers/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/br | • {{#if: UbuntuHelp:RotateWallpapers|brezhoneg| [[::RotateWallpapers/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/ca | • {{#if: UbuntuHelp:RotateWallpapers|català| [[::RotateWallpapers/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/cs | • {{#if: UbuntuHelp:RotateWallpapers|čeština| [[::RotateWallpapers/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/de | • {{#if: UbuntuHelp:RotateWallpapers|Deutsch| [[::RotateWallpapers/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/el | • {{#if: UbuntuHelp:RotateWallpapers|Ελληνικά| [[::RotateWallpapers/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/es | • {{#if: UbuntuHelp:RotateWallpapers|español| [[::RotateWallpapers/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/fa | • {{#if: UbuntuHelp:RotateWallpapers|فارسی| [[::RotateWallpapers/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/fi | • {{#if: UbuntuHelp:RotateWallpapers|suomi| [[::RotateWallpapers/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/fr | • {{#if: UbuntuHelp:RotateWallpapers|français| [[::RotateWallpapers/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/gu | • {{#if: UbuntuHelp:RotateWallpapers|ગુજરાતી| [[::RotateWallpapers/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/he | • {{#if: UbuntuHelp:RotateWallpapers|עברית| [[::RotateWallpapers/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/hu | • {{#if: UbuntuHelp:RotateWallpapers|magyar| [[::RotateWallpapers/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/id | • {{#if: UbuntuHelp:RotateWallpapers|Bahasa Indonesia| [[::RotateWallpapers/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/it | • {{#if: UbuntuHelp:RotateWallpapers|italiano| [[::RotateWallpapers/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/ja | • {{#if: UbuntuHelp:RotateWallpapers|日本語| [[::RotateWallpapers/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/ko | • {{#if: UbuntuHelp:RotateWallpapers|한국어| [[::RotateWallpapers/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/ksh | • {{#if: UbuntuHelp:RotateWallpapers|Ripoarisch| [[::RotateWallpapers/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/mr | • {{#if: UbuntuHelp:RotateWallpapers|मराठी| [[::RotateWallpapers/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/ms | • {{#if: UbuntuHelp:RotateWallpapers|Bahasa Melayu| [[::RotateWallpapers/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/nl | • {{#if: UbuntuHelp:RotateWallpapers|Nederlands| [[::RotateWallpapers/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/no | • {{#if: UbuntuHelp:RotateWallpapers|norsk| [[::RotateWallpapers/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/oc | • {{#if: UbuntuHelp:RotateWallpapers|occitan| [[::RotateWallpapers/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/pl | • {{#if: UbuntuHelp:RotateWallpapers|polski| [[::RotateWallpapers/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/pt | • {{#if: UbuntuHelp:RotateWallpapers|português| [[::RotateWallpapers/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/ro | • {{#if: UbuntuHelp:RotateWallpapers|română| [[::RotateWallpapers/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/ru | • {{#if: UbuntuHelp:RotateWallpapers|русский| [[::RotateWallpapers/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/si | • {{#if: UbuntuHelp:RotateWallpapers|සිංහල| [[::RotateWallpapers/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/sq | • {{#if: UbuntuHelp:RotateWallpapers|shqip| [[::RotateWallpapers/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/sr | • {{#if: UbuntuHelp:RotateWallpapers|српски / srpski| [[::RotateWallpapers/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/sv | • {{#if: UbuntuHelp:RotateWallpapers|svenska| [[::RotateWallpapers/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/th | • {{#if: UbuntuHelp:RotateWallpapers|ไทย| [[::RotateWallpapers/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/tr | • {{#if: UbuntuHelp:RotateWallpapers|Türkçe| [[::RotateWallpapers/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/vi | • {{#if: UbuntuHelp:RotateWallpapers|Tiếng Việt| [[::RotateWallpapers/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/yue | • {{#if: UbuntuHelp:RotateWallpapers|粵語| [[::RotateWallpapers/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/zh | • {{#if: UbuntuHelp:RotateWallpapers|中文| [[::RotateWallpapers/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/zh-hans | • {{#if: UbuntuHelp:RotateWallpapers|中文(简体)| [[::RotateWallpapers/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RotateWallpapers | UbuntuHelp:RotateWallpapers | {{#if: | :}}RotateWallpapers}}/zh-hant | • {{#if: UbuntuHelp:RotateWallpapers|中文(繁體)| [[::RotateWallpapers/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:RotateWallpapers|:RotateWallpapers|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :RotateWallpapers/zh | | {{#ifexist: RotateWallpapers/zh | | {{#ifeq: {{#titleparts:RotateWallpapers|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:RotateWallpapers|1|-1|}} | zh | | }}
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