4 * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 PictureItem::PictureItem()
45 PictureItem::~PictureItem()
49 void PictureItem::copy_from(PictureItem *src)
51 strcpy(this->name, src->name);
52 this->device_id = src->device_id;
55 this->default_ = src->default_;
56 this->step = src->step;
57 this->type = src->type;
58 this->value = src->value;
61 char* PictureItem::get_default_string(char *string)
63 sprintf(string, "VIDEO_%s_VALUE", name);
64 int len = strlen(string);
65 for(int i = 0; i < len; i++)
66 string[i] = toupper(string[i]);
77 PictureConfig::PictureConfig()
80 MWindow::create_defaults_path(path, PICTURE_FILE);
81 defaults = new BC_Hash(path);
97 PictureConfig::~PictureConfig()
99 controls.remove_all_objects();
103 void PictureConfig::copy_settings(PictureConfig *picture)
105 this->brightness = picture->brightness;
106 this->hue = picture->hue;
107 this->color = picture->color;
108 this->contrast = picture->contrast;
109 this->whiteness = picture->whiteness;
112 for(int i = 0; i < picture->controls.total; i++)
114 PictureItem *src_item = picture->controls.values[i];
115 PictureItem *dst_item = 0;
116 for(int j = 0; j < controls.total; j++)
118 if(controls.values[j]->device_id == src_item->device_id)
120 dst_item = controls.values[j];
126 dst_item = new PictureItem;
127 controls.append(dst_item);
129 dst_item->copy_from(src_item);
133 void PictureConfig::copy_usage(PictureConfig *picture)
135 this->use_brightness = picture->use_brightness;
136 this->use_contrast = picture->use_contrast;
137 this->use_color = picture->use_color;
138 this->use_hue = picture->use_hue;
139 this->use_whiteness = picture->use_whiteness;
141 // Add the controls if they don't exists but don't replace existing values.
142 for(int i = 0; i < picture->controls.total; i++)
144 PictureItem *src = picture->controls.values[i];
146 for(int j = 0; j < controls.total; j++)
148 if(controls.values[j]->device_id == src->device_id)
156 PictureItem *dst = new PictureItem;
157 controls.append(dst);
163 void PictureConfig::load_defaults()
167 printf("PictureConfig::load_defaults: no defaults pointer.\n");
173 brightness = defaults->get("VIDEO_BRIGHTNESS", 0);
174 hue = defaults->get("VIDEO_HUE", 0);
175 color = defaults->get("VIDEO_COLOR", 0);
176 contrast = defaults->get("VIDEO_CONTRAST", 0);
177 whiteness = defaults->get("VIDEO_WHITENESS", 0);
179 // The device must be probed first to keep unsupported controls from getting
181 for(int i = 0; i < controls.total; i++)
183 PictureItem *item = controls.values[i];
184 char string[BCTEXTLEN];
185 item->get_default_string(string);
186 item->value = defaults->get(string, item->value);
187 //printf("PictureConfig::load_defaults %s %d %d\n", item->name, item->device_id, item->value);
191 void PictureConfig::save_defaults()
195 printf("PictureConfig::save_defaults: no defaults pointer.\n");
198 defaults->update("VIDEO_BRIGHTNESS", brightness);
199 defaults->update("VIDEO_HUE", hue);
200 defaults->update("VIDEO_COLOR", color);
201 defaults->update("VIDEO_CONTRAST", contrast);
202 defaults->update("VIDEO_WHITENESS", whiteness);
203 for(int i = 0; i < controls.total; i++)
205 PictureItem *item = controls.values[i];
206 char string[BCTEXTLEN];
207 item->get_default_string(string);
208 defaults->update(string, item->value);
209 //printf("PictureConfig::save_defaults %s %d %d\n", string, item->device_id, item->value);
214 void PictureConfig::dump()
216 printf(" VIDEO_BRIGHTNESS=%d\n", brightness);
217 printf(" VIDEO_HUE=%d\n", hue);
218 printf(" VIDEO_COLOR=%d\n", color);
219 printf(" VIDEO_CONTRAST=%d\n", contrast);
220 printf(" VIDEO_WHITENESS=%d\n", whiteness);
221 for(int i = 0; i < controls.total; i++)
223 PictureItem *item = controls.values[i];
224 char string[BCTEXTLEN];
225 item->get_default_string(string);
226 printf(" %s=%d\n", string, item->value);
230 PictureItem* PictureConfig::new_item(const char *name)
232 for(int i = 0; i < controls.total; i++)
234 if(!strcmp(controls.values[i]->name, name)) return controls.values[i];
236 PictureItem *item = new PictureItem;
237 strcpy(item->name, name);
238 controls.append(item);
242 PictureItem* PictureConfig::get_item(const char *name, int id)
244 for(int i = 0; i < controls.total; i++)
246 if(!strcmp(controls.values[i]->name, name) &&
247 controls.values[i]->device_id == id) return controls.values[i];
252 int PictureConfig::set_item(int device_id, int value)
254 for(int i = 0; i < controls.total; i++)
256 if(controls.values[i]->device_id == device_id)
258 if(controls.values[i]->value != value)
260 controls.values[i]->value = value;