~ubuntu-branches/debian/stretch/cheese/stretch

« back to all changes in this revision

Viewing changes to libcheese/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
  gint   burst_count;
 
44
  gchar *burst_raw_name;
 
45
} CheeseFileUtilPrivate;
 
46
 
 
47
gchar *
 
48
cheese_fileutil_get_video_path (CheeseFileUtil *fileutil)
 
49
{
 
50
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
 
51
 
 
52
  gchar *path;
 
53
 
 
54
  path = priv->video_path;
 
55
 
 
56
  return path;
 
57
}
 
58
 
 
59
gchar *
 
60
cheese_fileutil_get_photo_path (CheeseFileUtil *fileutil)
 
61
{
 
62
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
 
63
 
 
64
  gchar *path;
 
65
 
 
66
  path = priv->photo_path;
 
67
 
 
68
  return path;
 
69
}
 
70
 
 
71
gchar *
 
72
cheese_fileutil_get_path_before_224 (CheeseFileUtil *fileutil)
 
73
{
 
74
  return g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", "media", NULL);
 
75
}
 
76
 
 
77
gchar *
 
78
cheese_fileutil_get_log_path (CheeseFileUtil *fileutil)
 
79
{
 
80
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
 
81
 
 
82
  gchar *path;
 
83
 
 
84
  path = priv->log_path;
 
85
 
 
86
  return path;
 
87
}
 
88
 
 
89
gchar *
 
90
cheese_fileutil_get_new_media_filename (CheeseFileUtil *fileutil, CheeseMediaMode mode)
 
91
{
 
92
  struct tm *ptr;
 
93
  time_t     tm;
 
94
  char       date[21];
 
95
  gchar     *path;
 
96
  char      *filename;
 
97
  GFile     *file;
 
98
  int        num;
 
99
 
 
100
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
 
101
 
 
102
  tm  = time (NULL);
 
103
  ptr = localtime (&tm);
 
104
  strftime (date, 20, "%F-%H%M%S", ptr);
 
105
 
 
106
  if ((mode == CHEESE_MEDIA_MODE_PHOTO) || (mode == CHEESE_MEDIA_MODE_BURST))
 
107
    path = cheese_fileutil_get_photo_path (fileutil);
 
108
  else
 
109
    path = cheese_fileutil_get_video_path (fileutil);
 
110
 
 
111
  if (mode == CHEESE_MEDIA_MODE_PHOTO)
 
112
  {
 
113
    filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, PHOTO_NAME_SUFFIX);
 
114
  }
 
115
  else if (mode == CHEESE_MEDIA_MODE_BURST)
 
116
  {
 
117
    priv->burst_count++;
 
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);
 
120
 
 
121
    filename = g_strdup_printf ("%s_%d%s", priv->burst_raw_name, priv->burst_count, PHOTO_NAME_SUFFIX);
 
122
  }
 
123
  else
 
124
  {
 
125
    filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, VIDEO_NAME_SUFFIX);
 
126
  }
 
127
 
 
128
  file = g_file_new_for_path (filename);
 
129
 
 
130
  if (g_file_query_exists (file, NULL))
 
131
  {
 
132
    num = 1;
 
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);
 
137
    else
 
138
      filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, VIDEO_NAME_SUFFIX);
 
139
 
 
140
    file = g_file_new_for_path (filename);
 
141
 
 
142
    while (g_file_query_exists (file, NULL))
 
143
    {
 
144
      num++;
 
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);
 
149
      else
 
150
        filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, VIDEO_NAME_SUFFIX);
 
151
 
 
152
      file = g_file_new_for_path (filename);
 
153
    }
 
154
  }
 
155
 
 
156
  return filename;
 
157
}
 
158
 
 
159
void
 
160
cheese_fileutil_reset_burst (CheeseFileUtil *fileutil)
 
161
{
 
162
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
 
163
 
 
164
  priv->burst_count    = 0;
 
165
  priv->burst_raw_name = "";
 
166
}
 
167
 
 
168
static void
 
169
cheese_fileutil_finalize (GObject *object)
 
170
{
 
171
  CheeseFileUtil *fileutil;
 
172
 
 
173
  fileutil = CHEESE_FILEUTIL (object);
 
174
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
 
175
 
 
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);
 
180
}
 
181
 
 
182
static void
 
183
cheese_fileutil_class_init (CheeseFileUtilClass *klass)
 
184
{
 
185
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
186
 
 
187
  object_class->finalize = cheese_fileutil_finalize;
 
188
 
 
189
  g_type_class_add_private (klass, sizeof (CheeseFileUtilPrivate));
 
190
}
 
191
 
 
192
static void
 
193
cheese_fileutil_init (CheeseFileUtil *fileutil)
 
194
{
 
195
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
 
196
 
 
197
  priv->burst_count    = 0;
 
198
  priv->burst_raw_name = "";
 
199
 
 
200
  CheeseGConf *gconf;
 
201
 
 
202
  gconf = cheese_gconf_new ();
 
203
 
 
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);
 
206
 
 
207
  /* get the video path from gconf, xdg or hardcoded */
 
208
  if (!priv->video_path || strcmp (priv->video_path, "") == 0)
 
209
  {
 
210
    /* get xdg */
 
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)
 
213
    {
 
214
      /* get "~/.gnome2/cheese/media" */
 
215
      priv->video_path = cheese_fileutil_get_path_before_224 (fileutil);
 
216
    }
 
217
  }
 
218
 
 
219
  /* get the photo path from gconf, xdg or hardcoded */
 
220
  if (!priv->photo_path || strcmp (priv->photo_path, "") == 0)
 
221
  {
 
222
    /* get xdg */
 
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)
 
225
    {
 
226
      /* get "~/.gnome2/cheese/media" */
 
227
      priv->photo_path = cheese_fileutil_get_path_before_224 (fileutil);
 
228
    }
 
229
  }
 
230
 
 
231
  /* FIXME: use the xdg log path */
 
232
  priv->log_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", NULL);
 
233
 
 
234
  g_object_unref (gconf);
 
235
}
 
236
 
 
237
CheeseFileUtil *
 
238
cheese_fileutil_new ()
 
239
{
 
240
  static CheeseFileUtil *fileutil = NULL;
 
241
 
 
242
  if (fileutil != NULL)
 
243
    return g_object_ref (fileutil);
 
244
 
 
245
  fileutil = g_object_new (CHEESE_TYPE_FILEUTIL, NULL);
 
246
  g_object_add_weak_pointer (G_OBJECT (fileutil),
 
247
                             (gpointer) & fileutil);
 
248
  return fileutil;
 
249
}