7884ca56d817439718f404b151d69f3f72f85155
[synfig.git] / synfig-studio / src / gtkmm / dialog_targetparam.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dialog_targetparam.cpp
3 **      \brief Implementation for the TargetParam Dialog
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2010 Carlos López González
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "dialog_targetparam.h"
33
34 #include "general.h"
35
36 #endif
37
38 /* === U S I N G =========================================================== */
39
40 using namespace std;
41 using namespace studio;
42
43 /* === M A C R O S ========================================================= */
44
45 #define CUSTOM_VCODEC _("Custom Video Codec")
46
47 /* === G L O B A L S ======================================================= */
48 //! Allowed video codecs
49 /*! \warning This variable is linked to allowed_video_codecs_description,
50  *  if you change this you must change the other acordingly.
51  *  \warning These codecs are linked to the filename extensions for
52  *  mod_ffmpeg. If you change this you must change the others acordingly.
53  */
54 const char* allowed_video_codecs[] =
55 {
56         "flv", "h263p", "huffyuv", "libtheora", "libx264",
57         "mjpeg", "mpeg1video", "mpeg2video", "mpeg4", "msmpeg4",
58         "msmpeg4v1", "msmpeg4v2", "wmv1", "wmv2", "customvc", NULL
59 };
60
61 //! Allowed video codecs description.
62 /*! \warning This variable is linked to allowed_video_codecs,
63  *  if you change this you must change the other acordingly.
64  */
65 const char* allowed_video_codecs_description[] =
66 {
67         _("Flash Video (FLV) / Sorenson Spark / Sorenson H.263."),
68         _("H.263+ / H.263-1998 / H.263 version 2."),
69         _("Huffyuv / HuffYUV."),
70         _("libtheora Theora."),
71         _("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10."),
72         _("MJPEG (Motion JPEG)."),
73         _("raw MPEG-1 video."),
74         _("raw MPEG-2 video."),
75         _("MPEG-4 part 2. (XviD/DivX)"),
76         _("MPEG-4 part 2 Microsoft variant version 3."),
77         _("MPEG-4 part 2 Microsoft variant version 1."),
78         _("MPEG-4 part 2 Microsoft variant version 2."),
79         _("Windows Media Video 7."),
80         _("Windows Media Video 8."),
81         CUSTOM_VCODEC,
82         NULL
83 };
84 /* === P R O C E D U R E S ================================================= */
85
86 /* === M E T H O D S ======================================================= */
87
88 /* === E N T R Y P O I N T ================================================= */
89
90 Dialog_TargetParam::Dialog_TargetParam(synfig::TargetParam &tparam)
91 {
92         set_title(_("TargetParam Dialog"));
93         set_tparam(tparam);
94         // Custom Video Codec Entry
95         Gtk::Label* custom_label(manage(new Gtk::Label(CUSTOM_VCODEC)));
96         custom_label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
97         get_vbox()->pack_start(*custom_label, true, true, 0);
98         customvcodec=Gtk::manage(new Gtk::Entry());
99         get_vbox()->pack_start(*customvcodec, true, true, 0);
100         // Available Video Codecs Combo Box Text.
101         vcodec = Gtk::manage(new Gtk::ComboBoxText());
102         Gtk::Label* label(manage(new Gtk::Label(_("Available Video Codecs:"))));
103         label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
104         get_vbox()->pack_start(*label, true, true, 0);
105         // Appends the codec descriptions to the Combo Box
106         for (int i = 0; allowed_video_codecs[i] != NULL &&
107                                         allowed_video_codecs_description[i] != NULL; i++)
108                 vcodec->append_text(allowed_video_codecs_description[i]);
109         //Adds the Combo Box to the vertical box
110         get_vbox()->pack_start(*vcodec, true, true, 0);
111         // Connect the signal change to the handler
112         vcodec->signal_changed().connect(sigc::mem_fun(*this, &Dialog_TargetParam::on_vcodec_change));
113         // By defaut, set the active text to the Custom Video Codec
114         vcodec->set_active_text(CUSTOM_VCODEC);
115         customvcodec->set_text("customvc");
116         //Compare the passed vcodec to the available and set it active if found
117         for (int i = 0; allowed_video_codecs[i] != NULL &&
118                                         allowed_video_codecs_description[i] != NULL; i++)
119                 if(!get_tparam().video_codec.compare(allowed_video_codecs[i]))
120                 {
121                         vcodec->set_active_text(allowed_video_codecs_description[i]);
122                         customvcodec->set_text(allowed_video_codecs[i]);
123                 }
124
125         //Bitrate Spin Button
126         Gtk::Adjustment* bradj(manage(new class Gtk::Adjustment(double(tparam.bitrate), 10.0,1000.0)));
127         bitrate = Gtk::manage(new class Gtk::SpinButton(*bradj));
128         Gtk::Label* label2(manage(new Gtk::Label(_("Video Bit Rate:"))));
129         label2->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
130         get_vbox()->pack_start(*label2, true, true, 0);
131         get_vbox()->pack_start(*bitrate,true, true, 0);
132
133         get_vbox()->show_all();
134
135         ok_button = manage(new class Gtk::Button(Gtk::StockID("gtk-ok")));
136         ok_button->show();
137         add_action_widget(*ok_button,Gtk::RESPONSE_OK);
138         ok_button->signal_clicked().connect(sigc::mem_fun(*this,&Dialog_TargetParam::on_ok));
139
140         cancel_button = manage(new class Gtk::Button(Gtk::StockID("gtk-cancel")));
141         cancel_button->show();
142         add_action_widget(*cancel_button,Gtk::RESPONSE_CANCEL);
143         cancel_button->signal_clicked().connect(sigc::mem_fun(*this,&Dialog_TargetParam::on_cancel));
144
145 }
146
147 void
148 Dialog_TargetParam::on_ok()
149 {
150         tparam_.video_codec=customvcodec->get_text().c_str();
151         tparam_.bitrate=bitrate->get_value();
152         hide();
153 }
154
155 void
156 Dialog_TargetParam::on_cancel()
157 {
158         hide();
159 }
160
161 void
162 Dialog_TargetParam::on_vcodec_change()
163 {
164         std::string codecnamed = vcodec->get_active_text();
165         customvcodec->set_sensitive(false);
166         for (int i = 0; allowed_video_codecs[i] != NULL &&
167                                         allowed_video_codecs_description[i] != NULL; i++)
168                 if(!codecnamed.compare(allowed_video_codecs_description[i]))
169                 {
170                         if(!codecnamed.compare(CUSTOM_VCODEC))
171                                 customvcodec->set_sensitive(true);
172                         else
173                                 customvcodec->set_text(allowed_video_codecs[i]);
174                 }
175 }
176
177 Dialog_TargetParam::~Dialog_TargetParam()
178 {
179 }
180