4 * Copyright (C) 2008 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
22 #include "appearanceprefs.h"
23 #include "deleteallindexes.h"
25 #include "edlsession.h"
27 #include "filesystem.h"
30 #include "preferences.h"
31 #include "preferencesthread.h"
32 #include "shbtnprefs.h"
36 AppearancePrefs::AppearancePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
37 : PreferencesDialog(mwindow, pwindow)
48 AppearancePrefs::~AppearancePrefs()
60 void AppearancePrefs::create_objects()
62 BC_Resources *resources = BC_WindowBase::get_resources();
63 int margin = mwindow->theme->widget_border;
64 char string[BCTEXTLEN];
65 int x0 = mwindow->theme->preferencesoptions_x;
66 int y0 = mwindow->theme->preferencesoptions_y;
67 int x = x0, y = y0, x1 = x + 100;
69 add_subwindow(new BC_Title(x, y, _("Layout:"), LARGEFONT,
70 resources->text_default));
74 add_subwindow(new BC_Title(x, y, _("Theme:")));
75 add_subwindow(theme = new ViewTheme(x1, y, pwindow));
76 theme->create_objects();
77 y += theme->get_h() + 5;
80 ViewPluginIcons *plugin_icons;
81 add_subwindow(new BC_Title(x, y, _("Plugin Icons:")));
82 add_subwindow(plugin_icons = new ViewPluginIcons(x1, y, pwindow));
83 plugin_icons->create_objects();
84 y += plugin_icons->get_h() + 5;
87 add_subwindow(new BC_Bar(5, y, get_w() - 10));
90 add_subwindow(new BC_Title(x, y, _("Time Format:"), LARGEFONT,
91 resources->text_default));
94 add_subwindow(new BC_Title(x1, y, _("Flags:"), LARGEFONT,
95 resources->text_default));
97 y += get_text_height(LARGEFONT) + 5;
101 add_subwindow(hms = new TimeFormatHMS(pwindow, this,
102 pwindow->thread->edl->session->time_format == TIME_HMS,
105 add_subwindow(hmsf = new TimeFormatHMSF(pwindow, this,
106 pwindow->thread->edl->session->time_format == TIME_HMSF,
109 add_subwindow(samples = new TimeFormatSamples(pwindow, this,
110 pwindow->thread->edl->session->time_format == TIME_SAMPLES,
113 add_subwindow(hex = new TimeFormatHex(pwindow, this,
114 pwindow->thread->edl->session->time_format == TIME_SAMPLES_HEX,
117 add_subwindow(frames = new TimeFormatFrames(pwindow, this,
118 pwindow->thread->edl->session->time_format == TIME_FRAMES,
121 add_subwindow(feet = new TimeFormatFeet(pwindow, this,
122 pwindow->thread->edl->session->time_format == TIME_FEET_FRAMES,
124 x += feet->get_w() + 15;
126 add_subwindow(title = new BC_Title(x, y, _("Frames per foot:")));
127 x += title->get_w() + margin;
128 sprintf(string, "%0.2f", pwindow->thread->edl->session->frames_per_foot);
129 add_subwindow(new TimeFormatFeetSetting(pwindow,
133 add_subwindow(seconds = new TimeFormatSeconds(pwindow, this,
134 pwindow->thread->edl->session->time_format == TIME_SECONDS,
138 add_subwindow(new BC_Bar(5, y, get_w()/2 - 30));
141 add_subwindow(new BC_Title(x, y, _("Color:"), LARGEFONT,
142 resources->text_default));
144 add_subwindow(title = new BC_Title(x, y, _("Highlighting Inversion color:")));
145 x += title->get_w() + margin;
146 char hex_color[BCSTRLEN];
147 sprintf(hex_color, "%06x", preferences->highlight_inverse);
148 add_subwindow(new HighlightInverseColor(pwindow, x, y, hex_color));
152 add_subwindow(title = new BC_Title(x, y, _("YUV color space:")));
153 x += title->get_w() + margin;
154 add_subwindow(yuv_color_space = new YuvColorSpace(x, y, pwindow));
155 yuv_color_space->create_objects();
156 y += yuv_color_space->get_h() + 5;
159 add_subwindow(title = new BC_Title(x, y, _("YUV color range:")));
160 x += title->get_w() + margin;
161 add_subwindow(yuv_color_range = new YuvColorRange(x, y, pwindow));
162 yuv_color_range->create_objects();
163 y += yuv_color_range->get_h() + 5;
165 UseTipWindow *tip_win = new UseTipWindow(pwindow, x1, y1);
166 add_subwindow(tip_win);
167 y1 += tip_win->get_h() + 5;
168 UseWarnIndecies *idx_win = new UseWarnIndecies(pwindow, x1, y1);
169 add_subwindow(idx_win);
170 y1 += idx_win->get_h() + 5;
171 UseWarnVersion *ver_win = new UseWarnVersion(pwindow, x1, y1);
172 add_subwindow(ver_win);
173 y1 += ver_win->get_h() + 5;
174 BD_WarnRoot *bdwr_win = new BD_WarnRoot(pwindow, x1, y1);
175 add_subwindow(bdwr_win);
176 y1 += bdwr_win->get_h() + 5;
177 PopupMenuBtnup *pop_win = new PopupMenuBtnup(pwindow, x1, y1);
178 add_subwindow(pop_win);
179 y1 += pop_win->get_h() + 5;
180 GrabFocusPolicy *grab_input_focus = new GrabFocusPolicy(pwindow, x1, y1);
181 add_subwindow(grab_input_focus);
182 y1 += grab_input_focus->get_h() + 5;
183 ActivateFocusPolicy *focus_activate = new ActivateFocusPolicy(pwindow, x1, y1);
184 add_subwindow(focus_activate);
185 y1 += focus_activate->get_h() + 5;
186 DeactivateFocusPolicy *focus_deactivate = new DeactivateFocusPolicy(pwindow, x1, y1);
187 add_subwindow(focus_deactivate);
188 y1 += focus_deactivate->get_h() + 5;
189 ForwardRenderDisplacement *displacement = new ForwardRenderDisplacement(pwindow, x1, y1);
190 add_subwindow(displacement);
191 y1 += displacement->get_h() + 5;
192 add_subwindow(thumbnails = new ViewThumbnails(x1, y1, pwindow));
193 y1 += thumbnails->get_h() + 5;
194 PerpetualSession *perpetual = new PerpetualSession(x1, y1, pwindow);
195 add_subwindow(perpetual);
196 y1 += perpetual->get_h() + 5;
200 int AppearancePrefs::update(int new_value)
202 pwindow->thread->redraw_times = 1;
203 pwindow->thread->edl->session->time_format = new_value;
204 hms->update(new_value == TIME_HMS);
205 hmsf->update(new_value == TIME_HMSF);
206 samples->update(new_value == TIME_SAMPLES);
207 hex->update(new_value == TIME_SAMPLES_HEX);
208 frames->update(new_value == TIME_FRAMES);
209 feet->update(new_value == TIME_FEET_FRAMES);
210 seconds->update(new_value == TIME_SECONDS);
215 TimeFormatHMS::TimeFormatHMS(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
216 : BC_Radial(x, y, value, TIME_HMS_TEXT)
217 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
219 int TimeFormatHMS::handle_event()
221 tfwindow->update(TIME_HMS);
225 TimeFormatHMSF::TimeFormatHMSF(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
226 : BC_Radial(x, y, value, TIME_HMSF_TEXT)
227 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
229 int TimeFormatHMSF::handle_event()
231 tfwindow->update(TIME_HMSF);
235 TimeFormatSamples::TimeFormatSamples(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
236 : BC_Radial(x, y, value, TIME_SAMPLES_TEXT)
237 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
239 int TimeFormatSamples::handle_event()
241 tfwindow->update(TIME_SAMPLES);
245 TimeFormatFrames::TimeFormatFrames(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
246 : BC_Radial(x, y, value, TIME_FRAMES_TEXT)
247 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
249 int TimeFormatFrames::handle_event()
251 tfwindow->update(TIME_FRAMES);
255 TimeFormatHex::TimeFormatHex(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
256 : BC_Radial(x, y, value, TIME_SAMPLES_HEX_TEXT)
257 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
259 int TimeFormatHex::handle_event()
261 tfwindow->update(TIME_SAMPLES_HEX);
265 TimeFormatSeconds::TimeFormatSeconds(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
266 : BC_Radial(x, y, value, TIME_SECONDS_TEXT)
268 this->pwindow = pwindow;
269 this->tfwindow = tfwindow;
272 int TimeFormatSeconds::handle_event()
274 tfwindow->update(TIME_SECONDS);
278 TimeFormatFeet::TimeFormatFeet(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
279 : BC_Radial(x, y, value, TIME_FEET_FRAMES_TEXT)
280 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
282 int TimeFormatFeet::handle_event()
284 tfwindow->update(TIME_FEET_FRAMES);
288 TimeFormatFeetSetting::TimeFormatFeetSetting(PreferencesWindow *pwindow, int x, int y, char *string)
289 : BC_TextBox(x, y, 90, 1, string)
290 { this->pwindow = pwindow; }
292 int TimeFormatFeetSetting::handle_event()
294 pwindow->thread->edl->session->frames_per_foot = atof(get_text());
295 if(pwindow->thread->edl->session->frames_per_foot < 1) pwindow->thread->edl->session->frames_per_foot = 1;
300 ViewTheme::ViewTheme(int x, int y, PreferencesWindow *pwindow)
301 : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->theme, 1)
303 this->pwindow = pwindow;
305 ViewTheme::~ViewTheme()
309 void ViewTheme::create_objects()
311 ArrayList<PluginServer*> themes;
312 MWindow::search_plugindb(0, 0, 0, 0, 1, themes);
314 for(int i = 0; i < themes.total; i++) {
315 add_item(new ViewThemeItem(this, themes.values[i]->title));
319 int ViewTheme::handle_event()
324 ViewThemeItem::ViewThemeItem(ViewTheme *popup, const char *text)
330 int ViewThemeItem::handle_event()
332 popup->set_text(get_text());
333 strcpy(popup->pwindow->thread->preferences->theme, get_text());
334 popup->handle_event();
339 ViewPluginIcons::ViewPluginIcons(int x, int y, PreferencesWindow *pwindow)
340 : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->plugin_icons, 1)
342 this->pwindow = pwindow;
344 ViewPluginIcons::~ViewPluginIcons()
348 void ViewPluginIcons::create_objects()
350 add_item(new ViewPluginIconItem(this, DEFAULT_PICON));
352 const char *plugin_path = File::get_plugin_path();
353 char picon_path[BCTEXTLEN];
354 snprintf(picon_path,sizeof(picon_path)-1,"%s/picon", plugin_path);
355 if( fs.update(picon_path) ) return;
356 for( int i=0; i<fs.dir_list.total; ++i ) {
357 char *fs_path = fs.dir_list[i]->path;
358 if( !fs.is_dir(fs_path) ) continue;
359 char *cp = strrchr(fs_path,'/');
360 cp = !cp ? fs_path : cp+1;
361 if( !strcmp(cp,DEFAULT_PICON) ) continue;
362 add_item(new ViewPluginIconItem(this, cp));
366 int ViewPluginIcons::handle_event()
371 ViewPluginIconItem::ViewPluginIconItem(ViewPluginIcons *popup, const char *text)
377 int ViewPluginIconItem::handle_event()
379 popup->set_text(get_text());
380 strcpy(popup->pwindow->thread->preferences->plugin_icons, get_text());
381 popup->handle_event();
386 ViewThumbnails::ViewThumbnails(int x,
388 PreferencesWindow *pwindow)
391 pwindow->thread->preferences->use_thumbnails, _("Use thumbnails in resource window"))
393 this->pwindow = pwindow;
396 int ViewThumbnails::handle_event()
398 pwindow->thread->preferences->use_thumbnails = get_value();
404 UseTipWindow::UseTipWindow(PreferencesWindow *pwindow, int x, int y)
407 pwindow->thread->preferences->use_tipwindow,
408 _("Show tip of the day"))
410 this->pwindow = pwindow;
412 int UseTipWindow::handle_event()
414 pwindow->thread->preferences->use_tipwindow = get_value();
419 UseWarnIndecies::UseWarnIndecies(PreferencesWindow *pwindow, int x, int y)
420 : BC_CheckBox(x, y, pwindow->thread->preferences->warn_indexes,
421 _("ffmpeg probe warns rebuild indexes"))
423 this->pwindow = pwindow;
426 int UseWarnIndecies::handle_event()
428 pwindow->thread->preferences->warn_indexes = get_value();
432 UseWarnVersion::UseWarnVersion(PreferencesWindow *pwindow, int x, int y)
433 : BC_CheckBox(x, y, pwindow->thread->preferences->warn_version,
434 _("EDL version warns if mismatched"))
436 this->pwindow = pwindow;
439 int UseWarnVersion::handle_event()
441 pwindow->thread->preferences->warn_version = get_value();
445 BD_WarnRoot::BD_WarnRoot(PreferencesWindow *pwindow, int x, int y)
446 : BC_CheckBox(x, y, pwindow->thread->preferences->bd_warn_root,
447 _("Create Bluray warns if not root"))
449 this->pwindow = pwindow;
452 int BD_WarnRoot::handle_event()
454 pwindow->thread->preferences->bd_warn_root = get_value();
458 PopupMenuBtnup::PopupMenuBtnup(PreferencesWindow *pwindow, int x, int y)
459 : BC_CheckBox(x, y, pwindow->thread->preferences->popupmenu_btnup,
460 _("Popups activate on button up"))
462 this->pwindow = pwindow;
465 int PopupMenuBtnup::handle_event()
467 pwindow->thread->preferences->popupmenu_btnup = get_value();
471 GrabFocusPolicy::GrabFocusPolicy(PreferencesWindow *pwindow, int x, int y)
472 : BC_CheckBox(x, y, (pwindow->thread->preferences->grab_input_focus) != 0,
473 _("Set Input Focus when window entered"))
475 this->pwindow = pwindow;
478 int GrabFocusPolicy::handle_event()
480 pwindow->thread->preferences->grab_input_focus = get_value();
484 ActivateFocusPolicy::ActivateFocusPolicy(PreferencesWindow *pwindow, int x, int y)
485 : BC_CheckBox(x, y, (pwindow->thread->preferences->textbox_focus_policy & CLICK_ACTIVATE) != 0,
486 _("Click to activate text focus"))
488 this->pwindow = pwindow;
491 int ActivateFocusPolicy::handle_event()
494 pwindow->thread->preferences->textbox_focus_policy |= CLICK_ACTIVATE;
496 pwindow->thread->preferences->textbox_focus_policy &= ~CLICK_ACTIVATE;
500 DeactivateFocusPolicy::DeactivateFocusPolicy(PreferencesWindow *pwindow, int x, int y)
501 : BC_CheckBox(x, y, (pwindow->thread->preferences->textbox_focus_policy & CLICK_DEACTIVATE) != 0,
502 _("Click to deactivate text focus"))
504 this->pwindow = pwindow;
507 int DeactivateFocusPolicy::handle_event()
510 pwindow->thread->preferences->textbox_focus_policy |= CLICK_DEACTIVATE;
512 pwindow->thread->preferences->textbox_focus_policy &= ~CLICK_DEACTIVATE;
516 ForwardRenderDisplacement::ForwardRenderDisplacement(PreferencesWindow *pwindow, int x, int y)
517 : BC_CheckBox(x, y, pwindow->thread->preferences->forward_render_displacement,
518 _("Always show next frame"))
520 this->pwindow = pwindow;
523 int ForwardRenderDisplacement::handle_event()
525 pwindow->thread->preferences->forward_render_displacement = get_value();
529 HighlightInverseColor::HighlightInverseColor(PreferencesWindow *pwindow, int x, int y, const char *hex)
530 : BC_TextBox(x, y, 80, 1, hex)
532 this->pwindow = pwindow;
535 int HighlightInverseColor::handle_event()
537 int inverse_color = strtoul(get_text(),0,16);
538 if( (inverse_color &= 0xffffff) == 0 ) {
539 inverse_color = 0xffffff;
540 char string[BCSTRLEN];
541 sprintf(string,"%06x", inverse_color);
544 pwindow->thread->preferences->highlight_inverse = inverse_color;
549 const char *YuvColorSpace::color_space[] = {
555 YuvColorSpace::YuvColorSpace(int x, int y, PreferencesWindow *pwindow)
556 : BC_PopupMenu(x, y, 100,
557 _(color_space[pwindow->thread->preferences->yuv_color_space]), 1)
559 this->pwindow = pwindow;
561 YuvColorSpace::~YuvColorSpace()
565 void YuvColorSpace::create_objects()
567 for( int id=0,nid=sizeof(color_space)/sizeof(color_space[0]); id<nid; ++id )
568 add_item(new YuvColorSpaceItem(this, _(color_space[id]), id));
572 int YuvColorSpace::handle_event()
574 set_text(color_space[pwindow->thread->preferences->yuv_color_space]);
578 YuvColorSpaceItem::YuvColorSpaceItem(YuvColorSpace *popup, const char *text, int id)
585 int YuvColorSpaceItem::handle_event()
587 popup->set_text(get_text());
588 popup->pwindow->thread->preferences->yuv_color_space = id;
589 return popup->handle_event();
593 const char *YuvColorRange::color_range[] = {
598 YuvColorRange::YuvColorRange(int x, int y, PreferencesWindow *pwindow)
599 : BC_PopupMenu(x, y, 100,
600 _(color_range[pwindow->thread->preferences->yuv_color_range]), 1)
602 this->pwindow = pwindow;
604 YuvColorRange::~YuvColorRange()
608 void YuvColorRange::create_objects()
610 for( int id=0,nid=sizeof(color_range)/sizeof(color_range[0]); id<nid; ++id )
611 add_item(new YuvColorRangeItem(this, _(color_range[id]), id));
615 int YuvColorRange::handle_event()
617 set_text(color_range[pwindow->thread->preferences->yuv_color_range]);
621 YuvColorRangeItem::YuvColorRangeItem(YuvColorRange *popup, const char *text, int id)
628 int YuvColorRangeItem::handle_event()
630 popup->set_text(get_text());
631 popup->pwindow->thread->preferences->yuv_color_range = id;
632 return popup->handle_event();
635 PerpetualSession::PerpetualSession(int x, int y, PreferencesWindow *pwindow)
637 pwindow->thread->preferences->perpetual_session, _("Perpetual session"))
639 this->pwindow = pwindow;
642 int PerpetualSession::handle_event()
644 pwindow->thread->preferences->perpetual_session = get_value();