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>
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/>.
25
const string GROUP_NAME = "Effect";
27
internal class Cheese.EffectsManager : GLib.Object
29
public static Cheese.Effect? parse_effect_file (string filename)
31
KeyFile kf = new KeyFile ();
32
Effect eff = new Effect ();
33
var locale = Intl.setlocale (LocaleCategory.ALL, "");
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");
41
catch (KeyFileError err)
43
warning ("Error: %s\n", err.message);
48
warning ("Error: %s\n", err.message);
55
public ArrayList<Effect> effects;
57
private ArrayList<Effect> ? load_effects_from_directory (string directory)
59
ArrayList<Effect> list = new ArrayList<Effect>();
61
if (FileUtils.test (directory, FileTest.EXISTS | FileTest.IS_DIR))
67
dir = Dir.open (directory);
71
warning ("Error: %s\n", err.message);
76
cur_file = dir.read_name ();
77
while (cur_file != null)
79
if (cur_file.has_suffix (".effect"))
81
Effect effect = EffectsManager.parse_effect_file (GLib.Path.build_filename (directory, cur_file));
82
if (!effects.contains (effect))
84
message ("Found %s (%s)", effect.name, effect.pipeline_desc);
88
cur_file = dir.read_name ();
94
public EffectsManager ()
96
effects = new ArrayList<Effect>((EqualFunc) cmp_value);
99
public void load_effects ()
101
string system_effects;
103
foreach (string dir in Environment.get_system_data_dirs ())
105
system_effects = GLib.Path.build_filename (dir, "gnome-video-effects");
106
effects.add_all (load_effects_from_directory (system_effects));
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));
112
effects.sort ((CompareFunc) sort_value);
114
/* add identity effect as the first in the effect list */
115
if (effects.size > 0)
117
Effect e = new Effect ();
118
e.name = _("No Effect");
119
e.pipeline_desc = "identity";
120
effects.insert (0, e);
124
public Effect ? get_effect (string name)
126
foreach (Effect eff in effects)
128
if (eff.name == name)
134
private static bool cmp_value (Effect a, Effect b)
136
return a.pipeline_desc == b.pipeline_desc;
139
private static int sort_value (Effect a, Effect b)
141
if (a.name.down () < b.name.down ())
143
else if (a.name.down () > b.name.down ())