2
* Copyright © 2007,2008 daniel g. siegel <dgsiegel@gnome.org>
3
* Copyright © 2007,2008 Jaap Haitsma <jaap@haitsma.org>
4
* Copyright © 2008 Felix Kaser <f.kaser@gmx.net>
6
* Licensed under the GNU General Public License Version 2
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include <cheese-config.h>
30
#include "cheese-fileutil.h"
31
#include "cheese-gconf.h"
33
G_DEFINE_TYPE (CheeseFileUtil, cheese_fileutil, G_TYPE_OBJECT)
35
#define CHEESE_FILEUTIL_GET_PRIVATE(o) \
36
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_FILEUTIL, CheeseFileUtilPrivate))
44
gchar *burst_raw_name;
45
} CheeseFileUtilPrivate;
48
cheese_fileutil_get_video_path (CheeseFileUtil *fileutil)
50
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
54
path = priv->video_path;
60
cheese_fileutil_get_photo_path (CheeseFileUtil *fileutil)
62
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
66
path = priv->photo_path;
72
cheese_fileutil_get_path_before_224 (CheeseFileUtil *fileutil)
74
return g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", "media", NULL);
78
cheese_fileutil_get_log_path (CheeseFileUtil *fileutil)
80
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
84
path = priv->log_path;
90
cheese_fileutil_get_new_media_filename (CheeseFileUtil *fileutil, CheeseMediaMode mode)
100
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
103
ptr = localtime (&tm);
104
strftime (date, 20, "%F-%H%M%S", ptr);
106
if ((mode == CHEESE_MEDIA_MODE_PHOTO) || (mode == CHEESE_MEDIA_MODE_BURST))
107
path = cheese_fileutil_get_photo_path (fileutil);
109
path = cheese_fileutil_get_video_path (fileutil);
111
if (mode == CHEESE_MEDIA_MODE_PHOTO)
113
filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, PHOTO_NAME_SUFFIX);
115
else if (mode == CHEESE_MEDIA_MODE_BURST)
118
if (strlen (priv->burst_raw_name) == 0)
119
priv->burst_raw_name = g_strdup_printf ("%s%s%s", path, G_DIR_SEPARATOR_S, date);
121
filename = g_strdup_printf ("%s_%d%s", priv->burst_raw_name, priv->burst_count, PHOTO_NAME_SUFFIX);
125
filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, VIDEO_NAME_SUFFIX);
128
file = g_file_new_for_path (filename);
130
if (g_file_query_exists (file, NULL))
133
if (mode == CHEESE_MEDIA_MODE_PHOTO)
134
filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, PHOTO_NAME_SUFFIX);
135
else if (mode == CHEESE_MEDIA_MODE_BURST)
136
filename = g_strdup_printf ("%s_%d (%d)%s", priv->burst_raw_name, priv->burst_count, num, PHOTO_NAME_SUFFIX);
138
filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, VIDEO_NAME_SUFFIX);
140
file = g_file_new_for_path (filename);
142
while (g_file_query_exists (file, NULL))
145
if (mode == CHEESE_MEDIA_MODE_PHOTO)
146
filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, PHOTO_NAME_SUFFIX);
147
else if (mode == CHEESE_MEDIA_MODE_BURST)
148
filename = g_strdup_printf ("%s_%d (%d)%s", priv->burst_raw_name, priv->burst_count, num, PHOTO_NAME_SUFFIX);
150
filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, VIDEO_NAME_SUFFIX);
152
file = g_file_new_for_path (filename);
160
cheese_fileutil_reset_burst (CheeseFileUtil *fileutil)
162
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
164
priv->burst_count = 0;
165
priv->burst_raw_name = "";
169
cheese_fileutil_finalize (GObject *object)
171
CheeseFileUtil *fileutil;
173
fileutil = CHEESE_FILEUTIL (object);
174
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
176
g_free (priv->video_path);
177
g_free (priv->photo_path);
178
g_free (priv->log_path);
179
G_OBJECT_CLASS (cheese_fileutil_parent_class)->finalize (object);
183
cheese_fileutil_class_init (CheeseFileUtilClass *klass)
185
GObjectClass *object_class = G_OBJECT_CLASS (klass);
187
object_class->finalize = cheese_fileutil_finalize;
189
g_type_class_add_private (klass, sizeof (CheeseFileUtilPrivate));
193
cheese_fileutil_init (CheeseFileUtil *fileutil)
195
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
197
priv->burst_count = 0;
198
priv->burst_raw_name = "";
202
gconf = cheese_gconf_new ();
204
g_object_get (gconf, "gconf_prop_video_path", &priv->video_path, NULL);
205
g_object_get (gconf, "gconf_prop_photo_path", &priv->photo_path, NULL);
207
/* get the video path from gconf, xdg or hardcoded */
208
if (!priv->video_path || strcmp (priv->video_path, "") == 0)
211
priv->video_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS), "Webcam", NULL);
212
if (strcmp (priv->video_path, "") == 0)
214
/* get "~/.gnome2/cheese/media" */
215
priv->video_path = cheese_fileutil_get_path_before_224 (fileutil);
219
/* get the photo path from gconf, xdg or hardcoded */
220
if (!priv->photo_path || strcmp (priv->photo_path, "") == 0)
223
priv->photo_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES), "Webcam", NULL);
224
if (strcmp (priv->photo_path, "") == 0)
226
/* get "~/.gnome2/cheese/media" */
227
priv->photo_path = cheese_fileutil_get_path_before_224 (fileutil);
231
/* FIXME: use the xdg log path */
232
priv->log_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", NULL);
234
g_object_unref (gconf);
238
cheese_fileutil_new ()
240
static CheeseFileUtil *fileutil = NULL;
242
if (fileutil != NULL)
243
return g_object_ref (fileutil);
245
fileutil = g_object_new (CHEESE_TYPE_FILEUTIL, NULL);
246
g_object_add_weak_pointer (G_OBJECT (fileutil),
247
(gpointer) & fileutil);