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

« back to all changes in this revision

Viewing changes to libcheese/cheese-fileutil.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-07-17 21:04:16 UTC
  • mfrom: (15.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20110717210416-nt5qi659qei7a2yy
Tags: 3.0.1-2
* debian/control.in:
  - Change gir1.2-cheese-3.0 Section to libs
  - Make library packages depend against cheese-common package
  - Make cheese package recommends against hicolor-icon-theme
  - Move gst Dependency to libcheese package
* debian/patches/0002-fix-linking.patch: Add missing library to fix linking
* debian/watch:
  - Switch to .bz2 tarballs.
  - Bump version to 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <string.h>
29
29
 
30
30
#include "cheese-fileutil.h"
31
 
#include "cheese-gconf.h"
32
31
 
33
32
G_DEFINE_TYPE (CheeseFileUtil, cheese_fileutil, G_TYPE_OBJECT)
34
33
 
39
38
{
40
39
  gchar *video_path;
41
40
  gchar *photo_path;
42
 
  gchar *log_path;
43
41
  gint   burst_count;
44
42
  gchar *burst_raw_name;
45
43
} CheeseFileUtilPrivate;
46
44
 
47
 
gchar *
 
45
const gchar *
48
46
cheese_fileutil_get_video_path (CheeseFileUtil *fileutil)
49
47
{
50
48
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
51
49
 
52
 
  gchar *path;
53
 
 
54
 
  path = priv->video_path;
55
 
 
56
 
  return path;
 
50
  return priv->video_path;
57
51
}
58
52
 
59
 
gchar *
 
53
const gchar *
60
54
cheese_fileutil_get_photo_path (CheeseFileUtil *fileutil)
61
55
{
62
56
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
63
57
 
64
 
  gchar *path;
65
 
 
66
 
  path = priv->photo_path;
67
 
 
68
 
  return path;
 
58
  return priv->photo_path;
69
59
}
70
60
 
71
61
gchar *
75
65
}
76
66
 
77
67
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
68
cheese_fileutil_get_new_media_filename (CheeseFileUtil *fileutil, CheeseMediaMode mode)
91
69
{
92
 
  struct tm *ptr;
93
 
  time_t     tm;
94
 
  char       date[21];
95
 
  gchar     *path;
96
 
  char      *filename;
97
 
  GFile     *file;
98
 
  int        num;
 
70
  struct tm   *ptr;
 
71
  time_t       tm;
 
72
  char         date[21];
 
73
  const gchar *path;
 
74
  char        *filename;
 
75
  GFile       *file;
 
76
  int          num;
99
77
 
100
78
  CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
101
79
 
108
86
  else
109
87
    path = cheese_fileutil_get_video_path (fileutil);
110
88
 
 
89
  g_mkdir_with_parents (path, 0775);
 
90
 
111
91
  if (mode == CHEESE_MEDIA_MODE_PHOTO)
112
92
  {
113
 
    filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, PHOTO_NAME_SUFFIX);
 
93
    filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, CHEESE_PHOTO_NAME_SUFFIX);
114
94
  }
115
95
  else if (mode == CHEESE_MEDIA_MODE_BURST)
116
96
  {
118
98
    if (strlen (priv->burst_raw_name) == 0)
119
99
      priv->burst_raw_name = g_strdup_printf ("%s%s%s", path, G_DIR_SEPARATOR_S, date);
120
100
 
121
 
    filename = g_strdup_printf ("%s_%d%s", priv->burst_raw_name, priv->burst_count, PHOTO_NAME_SUFFIX);
 
101
    filename = g_strdup_printf ("%s_%d%s", priv->burst_raw_name, priv->burst_count, CHEESE_PHOTO_NAME_SUFFIX);
122
102
  }
123
103
  else
124
104
  {
125
 
    filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, VIDEO_NAME_SUFFIX);
 
105
    filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, CHEESE_VIDEO_NAME_SUFFIX);
126
106
  }
127
107
 
128
108
  file = g_file_new_for_path (filename);
 
109
  num = 0;
129
110
 
130
 
  if (g_file_query_exists (file, NULL))
 
111
  while (g_file_query_exists (file, NULL))
131
112
  {
132
 
    num = 1;
 
113
    num++;
 
114
 
 
115
    g_object_unref (file);
 
116
    g_free (filename);
 
117
 
133
118
    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);
 
119
      filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, CHEESE_PHOTO_NAME_SUFFIX);
135
120
    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);
 
121
      filename = g_strdup_printf ("%s_%d (%d)%s", priv->burst_raw_name, priv->burst_count, num, CHEESE_PHOTO_NAME_SUFFIX);
137
122
    else
138
 
      filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, VIDEO_NAME_SUFFIX);
 
123
      filename = g_strdup_printf ("%s%s%s (%d)%s", path, G_DIR_SEPARATOR_S, date, num, CHEESE_VIDEO_NAME_SUFFIX);
139
124
 
140
125
    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
126
  }
155
127
 
 
128
  g_object_unref (file);
 
129
 
156
130
  return filename;
157
131
}
158
132
 
175
149
 
176
150
  g_free (priv->video_path);
177
151
  g_free (priv->photo_path);
178
 
  g_free (priv->log_path);
179
152
  G_OBJECT_CLASS (cheese_fileutil_parent_class)->finalize (object);
180
153
}
181
154
 
197
170
  priv->burst_count    = 0;
198
171
  priv->burst_raw_name = "";
199
172
 
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 */
 
173
  GSettings *settings;
 
174
 
 
175
  settings = g_settings_new ("org.gnome.Cheese");
 
176
 
 
177
  g_settings_get (settings, "video-path", "s", &priv->video_path);
 
178
  g_settings_get (settings, "photo-path", "s", &priv->photo_path);
 
179
 
 
180
  /* get the video path from gsettings, xdg or hardcoded */
208
181
  if (!priv->video_path || strcmp (priv->video_path, "") == 0)
209
182
  {
210
183
    /* get xdg */
216
189
    }
217
190
  }
218
191
 
219
 
  /* get the photo path from gconf, xdg or hardcoded */
 
192
  /* get the photo path from gsettings, xdg or hardcoded */
220
193
  if (!priv->photo_path || strcmp (priv->photo_path, "") == 0)
221
194
  {
222
195
    /* get xdg */
228
201
    }
229
202
  }
230
203
 
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);
 
204
  g_object_unref (settings);
235
205
}
236
206
 
237
207
CheeseFileUtil *