~ubuntu-branches/debian/sid/cheese/sid

« back to all changes in this revision

Viewing changes to src/cheese-fileutil.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2010-05-04 17:37:18 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20100504173718-k2rx3nryi4vd0xyx
Tags: 2.30.1-1
* New upstream release.
  - HAL dependency has been dropped. Use (g)udev for v4l capability probing
    on Linux. Closes: #573774
  - Split code into separate libraries.
* debian/control.in
  - Drop Build-Depends on libhal-dev.
  - Drop Build-Depends on libebook1.2-dev.
  - Bump Build-Depends on libgtk2.0-dev to (>= 2.19.1).
  - Bump Build-Depends on libgstreamer*-dev to (>= 0.10.23).
  - Add Build-Depends on libcanberra-gtk-dev.
  - Add Build-Depends on libxtst-dev.
  - Add Build-Depends on libgudev-1.0-dev on Linux.
  - Bump Standards-Version to 3.8.4. No further changes.
* Switch to source format 3.0 (quilt)
  - Add debian/source/format.
* debian/rules
  - Drop lpia specific configure flags, lpia is dead.
* Update package layout (based on work by Ubuntu)
  - Move data files into new cheese-common package.
  - Keep binary along with its desktop and dbus service file in the cheese
    package.
  - Add libcheese-gtk18 and libcheese-gtk-dev package for the new
    libcheese-gtk library. Use a symbols file for improved shlibs
    dependencies.
  - Add Conflicts/Replaces to cheese-common to ensure proper upgrades from
    previous versions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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>
5
 
 *
6
 
 * Licensed under the GNU General Public License Version 2
7
 
 *
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.
12
 
 *
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.
17
 
 *
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/>.
20
 
 */
21
 
 
22
 
#ifdef HAVE_CONFIG_H
23
 
  #include <cheese-config.h>
24
 
#endif
25
 
 
26
 
#include <glib.h>
27
 
#include <gio/gio.h>
28
 
#include <string.h>
29
 
 
30
 
#include "cheese-fileutil.h"
31
 
#include "cheese-gconf.h"
32
 
 
33
 
G_DEFINE_TYPE (CheeseFileUtil, cheese_fileutil, G_TYPE_OBJECT)
34
 
 
35
 
#define CHEESE_FILEUTIL_GET_PRIVATE(o) \
36
 
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_FILEUTIL, CheeseFileUtilPrivate))
37
 
 
38
 
typedef struct
39
 
{
40
 
  gchar *video_path;
41
 
  gchar *photo_path;
42
 
  gchar *log_path;
43
 
} CheeseFileUtilPrivate;
44
 
 
45
 
gchar *
46
 
cheese_fileutil_get_video_path (CheeseFileUtil *fileutil)
47
 
{
48
 
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
49
 
 
50
 
  gchar *path;
51
 
 
52
 
  path = priv->video_path;
53
 
 
54
 
  return path;
55
 
}
56
 
 
57
 
gchar *
58
 
cheese_fileutil_get_photo_path (CheeseFileUtil *fileutil)
59
 
{
60
 
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
61
 
 
62
 
  gchar *path;
63
 
 
64
 
  path = priv->photo_path;
65
 
 
66
 
  return path;
67
 
}
68
 
 
69
 
gchar *
70
 
cheese_fileutil_get_path_before_224 (CheeseFileUtil *fileutil)
71
 
{
72
 
  return g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", "media", NULL);
73
 
}
74
 
 
75
 
gchar *
76
 
cheese_fileutil_get_log_path (CheeseFileUtil *fileutil)
77
 
{
78
 
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
79
 
 
80
 
  gchar *path;
81
 
 
82
 
  path = priv->log_path;
83
 
 
84
 
  return path;
85
 
}
86
 
 
87
 
gchar *
88
 
cheese_fileutil_get_new_media_filename (CheeseFileUtil *fileutil, CheeseMediaMode mode)
89
 
{
90
 
  struct tm *ptr;
91
 
  time_t     tm;
92
 
  char       date[21];
93
 
  gchar     *path;
94
 
  char      *filename;
95
 
  GFile     *file;
96
 
  int        num;
97
 
 
98
 
  tm  = time (NULL);
99
 
  ptr = localtime (&tm);
100
 
  strftime (date, 20, "%F-%H%M%S", ptr);
101
 
 
102
 
  if (mode == CHEESE_MEDIA_MODE_PHOTO)
103
 
    path = cheese_fileutil_get_photo_path (fileutil);
104
 
  else
105
 
    path = cheese_fileutil_get_video_path (fileutil);
106
 
 
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);
109
 
  else
110
 
    filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, VIDEO_NAME_SUFFIX);
111
 
 
112
 
  file = g_file_new_for_path (filename);
113
 
 
114
 
  if (g_file_query_exists (file, NULL))
115
 
  {
116
 
    num = 1;
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);
119
 
    else
120
 
      filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, VIDEO_NAME_SUFFIX);
121
 
 
122
 
    file = g_file_new_for_path (filename);
123
 
 
124
 
    while (g_file_query_exists (file, NULL))
125
 
    {
126
 
      num++;
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);
129
 
      else
130
 
        filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, VIDEO_NAME_SUFFIX);
131
 
 
132
 
      file = g_file_new_for_path (filename);
133
 
    }
134
 
  }
135
 
 
136
 
  return filename;
137
 
}
138
 
 
139
 
static void
140
 
cheese_fileutil_finalize (GObject *object)
141
 
{
142
 
  CheeseFileUtil *fileutil;
143
 
 
144
 
  fileutil = CHEESE_FILEUTIL (object);
145
 
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
146
 
 
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);
151
 
}
152
 
 
153
 
static void
154
 
cheese_fileutil_class_init (CheeseFileUtilClass *klass)
155
 
{
156
 
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
157
 
 
158
 
  object_class->finalize = cheese_fileutil_finalize;
159
 
 
160
 
  g_type_class_add_private (klass, sizeof (CheeseFileUtilPrivate));
161
 
}
162
 
 
163
 
static void
164
 
cheese_fileutil_init (CheeseFileUtil *fileutil)
165
 
{
166
 
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
167
 
 
168
 
  CheeseGConf *gconf;
169
 
 
170
 
  gconf = cheese_gconf_new ();
171
 
 
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);
174
 
 
175
 
  /* get the video path from gconf, xdg or hardcoded */
176
 
  if (!priv->video_path || strcmp (priv->video_path, "") == 0)
177
 
  {
178
 
    /* get xdg */
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)
181
 
    {
182
 
      /* get "~/.gnome2/cheese/media" */
183
 
      priv->video_path = cheese_fileutil_get_path_before_224 (fileutil);
184
 
    }
185
 
  }
186
 
 
187
 
  /* get the photo path from gconf, xdg or hardcoded */
188
 
  if (!priv->photo_path || strcmp (priv->photo_path, "") == 0)
189
 
  {
190
 
    /* get xdg */
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)
193
 
    {
194
 
      /* get "~/.gnome2/cheese/media" */
195
 
      priv->photo_path = cheese_fileutil_get_path_before_224 (fileutil);
196
 
    }
197
 
  }
198
 
 
199
 
  /* FIXME: use the xdg log path */
200
 
  priv->log_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", NULL);
201
 
 
202
 
  g_object_unref (gconf);
203
 
}
204
 
 
205
 
CheeseFileUtil *
206
 
cheese_fileutil_new ()
207
 
{
208
 
  CheeseFileUtil *fileutil;
209
 
 
210
 
  fileutil = g_object_new (CHEESE_TYPE_FILEUTIL, NULL);
211
 
  return fileutil;
212
 
}