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

« back to all changes in this revision

Viewing changes to src/cheese-effects-manager.vala

  • 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:
 
1
/*
 
2
 * Copyright © 2010 Yuvaraj Pandian T <yuvipanda@yuvi.in>
 
3
 * Copyright © 2010 daniel g. siegel <dgsiegel@gnome.org>
 
4
 * Copyright © 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
 
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
using GLib;
 
23
using Gee;
 
24
 
 
25
const string GROUP_NAME = "Effect";
 
26
 
 
27
internal class Cheese.EffectsManager : GLib.Object
 
28
{
 
29
  public static Cheese.Effect? parse_effect_file (string filename)
 
30
  {
 
31
    KeyFile kf     = new KeyFile ();
 
32
    Effect  eff    = new Effect ();
 
33
    var     locale = Intl.setlocale (LocaleCategory.ALL, "");
 
34
 
 
35
    try
 
36
    {
 
37
      kf.load_from_file (filename, KeyFileFlags.NONE);
 
38
      eff.name          = kf.get_locale_string (GROUP_NAME, "Name", locale);
 
39
      eff.pipeline_desc = kf.get_string (GROUP_NAME, "PipelineDescription");
 
40
    }
 
41
    catch (KeyFileError err)
 
42
    {
 
43
      warning ("Error: %s\n", err.message);
 
44
      return null;
 
45
    }
 
46
    catch (FileError err)
 
47
    {
 
48
      warning ("Error: %s\n", err.message);
 
49
      return null;
 
50
    }
 
51
 
 
52
    return eff;
 
53
  }
 
54
 
 
55
  public ArrayList<Effect> effects;
 
56
 
 
57
  private ArrayList<Effect> ? load_effects_from_directory (string directory)
 
58
  {
 
59
    ArrayList<Effect> list = new ArrayList<Effect>();
 
60
 
 
61
    if (FileUtils.test (directory, FileTest.EXISTS | FileTest.IS_DIR))
 
62
    {
 
63
      Dir    dir;
 
64
      string cur_file;
 
65
      try
 
66
      {
 
67
        dir = Dir.open (directory);
 
68
      }
 
69
      catch (FileError err)
 
70
      {
 
71
        warning ("Error: %s\n", err.message);
 
72
        return null;
 
73
      }
 
74
 
 
75
 
 
76
      cur_file = dir.read_name ();
 
77
      while (cur_file != null)
 
78
      {
 
79
        if (cur_file.has_suffix (".effect"))
 
80
        {
 
81
          Effect effect = EffectsManager.parse_effect_file (GLib.Path.build_filename (directory, cur_file));
 
82
          if (!effects.contains (effect))
 
83
          {
 
84
            message ("Found %s (%s)", effect.name, effect.pipeline_desc);
 
85
            list.add (effect);
 
86
          }
 
87
        }
 
88
        cur_file = dir.read_name ();
 
89
      }
 
90
    }
 
91
    return list;
 
92
  }
 
93
 
 
94
  public EffectsManager ()
 
95
  {
 
96
    effects = new ArrayList<Effect>((EqualFunc) cmp_value);
 
97
  }
 
98
 
 
99
  public void load_effects ()
 
100
  {
 
101
    string system_effects;
 
102
 
 
103
    foreach (string dir in Environment.get_system_data_dirs ())
 
104
    {
 
105
      system_effects = GLib.Path.build_filename (dir, "gnome-video-effects");
 
106
      effects.add_all (load_effects_from_directory (system_effects));
 
107
    }
 
108
 
 
109
    string user_effects = GLib.Path.build_filename (Environment.get_user_data_dir (), "gnome-video-effects");
 
110
    effects.add_all (load_effects_from_directory (user_effects));
 
111
 
 
112
    effects.sort ((CompareFunc) sort_value);
 
113
 
 
114
    /* add identity effect as the first in the effect list */
 
115
    if (effects.size > 0)
 
116
    {
 
117
      Effect e = new Effect ();
 
118
      e.name          = _("No Effect");
 
119
      e.pipeline_desc = "identity";
 
120
      effects.insert (0, e);
 
121
    }
 
122
  }
 
123
 
 
124
  public Effect ? get_effect (string name)
 
125
  {
 
126
    foreach (Effect eff in effects)
 
127
    {
 
128
      if (eff.name == name)
 
129
        return eff;
 
130
    }
 
131
    return null;
 
132
  }
 
133
 
 
134
  private static bool cmp_value (Effect a, Effect b)
 
135
  {
 
136
    return a.pipeline_desc == b.pipeline_desc;
 
137
  }
 
138
 
 
139
  private static int sort_value (Effect a, Effect b)
 
140
  {
 
141
    if (a.name.down () < b.name.down ())
 
142
      return -1;
 
143
    else if (a.name.down () > b.name.down ())
 
144
      return 1;
 
145
    else
 
146
      return 0;
 
147
  }
 
148
}