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))
43
} CheeseFileUtilPrivate;
46
cheese_fileutil_get_video_path (CheeseFileUtil *fileutil)
48
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
52
path = priv->video_path;
58
cheese_fileutil_get_photo_path (CheeseFileUtil *fileutil)
60
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
64
path = priv->photo_path;
70
cheese_fileutil_get_path_before_224 (CheeseFileUtil *fileutil)
72
return g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", "media", NULL);
76
cheese_fileutil_get_log_path (CheeseFileUtil *fileutil)
78
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
82
path = priv->log_path;
88
cheese_fileutil_get_new_media_filename (CheeseFileUtil *fileutil, CheeseMediaMode mode)
99
ptr = localtime (&tm);
100
strftime (date, 20, "%F-%H%M%S", ptr);
102
if (mode == CHEESE_MEDIA_MODE_PHOTO)
103
path = cheese_fileutil_get_photo_path (fileutil);
105
path = cheese_fileutil_get_video_path (fileutil);
107
if (mode == CHEESE_MEDIA_MODE_PHOTO)
108
filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, PHOTO_NAME_SUFFIX);
110
filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, VIDEO_NAME_SUFFIX);
112
file = g_file_new_for_path (filename);
114
if (g_file_query_exists (file, NULL))
117
if (mode == CHEESE_MEDIA_MODE_PHOTO)
118
filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, PHOTO_NAME_SUFFIX);
120
filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, VIDEO_NAME_SUFFIX);
122
file = g_file_new_for_path (filename);
124
while (g_file_query_exists (file, NULL))
127
if (mode == CHEESE_MEDIA_MODE_PHOTO)
128
filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, PHOTO_NAME_SUFFIX);
130
filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, VIDEO_NAME_SUFFIX);
132
file = g_file_new_for_path (filename);
140
cheese_fileutil_finalize (GObject *object)
142
CheeseFileUtil *fileutil;
144
fileutil = CHEESE_FILEUTIL (object);
145
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
147
g_free (priv->video_path);
148
g_free (priv->photo_path);
149
g_free (priv->log_path);
150
G_OBJECT_CLASS (cheese_fileutil_parent_class)->finalize (object);
154
cheese_fileutil_class_init (CheeseFileUtilClass *klass)
156
GObjectClass *object_class = G_OBJECT_CLASS (klass);
158
object_class->finalize = cheese_fileutil_finalize;
160
g_type_class_add_private (klass, sizeof (CheeseFileUtilPrivate));
164
cheese_fileutil_init (CheeseFileUtil *fileutil)
166
CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
170
gconf = cheese_gconf_new ();
172
g_object_get (gconf, "gconf_prop_video_path", &priv->video_path, NULL);
173
g_object_get (gconf, "gconf_prop_photo_path", &priv->photo_path, NULL);
175
/* get the video path from gconf, xdg or hardcoded */
176
if (!priv->video_path || strcmp (priv->video_path, "") == 0)
179
priv->video_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS), "Webcam", NULL);
180
if (strcmp (priv->video_path, "") == 0)
182
/* get "~/.gnome2/cheese/media" */
183
priv->video_path = cheese_fileutil_get_path_before_224 (fileutil);
187
/* get the photo path from gconf, xdg or hardcoded */
188
if (!priv->photo_path || strcmp (priv->photo_path, "") == 0)
191
priv->photo_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES), "Webcam", NULL);
192
if (strcmp (priv->photo_path, "") == 0)
194
/* get "~/.gnome2/cheese/media" */
195
priv->photo_path = cheese_fileutil_get_path_before_224 (fileutil);
199
/* FIXME: use the xdg log path */
200
priv->log_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", NULL);
202
g_object_unref (gconf);
206
cheese_fileutil_new ()
208
CheeseFileUtil *fileutil;
210
fileutil = g_object_new (CHEESE_TYPE_FILEUTIL, NULL);