Merge branch 'master' into nikitakit_restructure
[synfig.git] / synfig-studio / src / gui / dialogs / 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 "dialogs/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_DESCRIPTION _("Custom Video Codec")
46 #define CUSTOM_VCODEC _("write your video codec here")
47
48 /* === G L O B A L S ======================================================= */
49 //! Allowed video codecs
50 /*! \warning This variable is linked to allowed_video_codecs_description,
51  *  if you change this you must change the other acordingly.
52  *  \warning These codecs are linked to the filename extensions for
53  *  mod_ffmpeg. If you change this you must change the others acordingly.
54  */
55 const char* allowed_video_codecs[] =
56 {
57         "flv", "h263p", "huffyuv", "libtheora", "libx264",
58         "mjpeg", "mpeg1video", "mpeg2video", "mpeg4", "msmpeg4",
59         "msmpeg4v1", "msmpeg4v2", "wmv1", "wmv2", CUSTOM_VCODEC, NULL
60 };
61
62 //! Allowed video codecs description.
63 /*! \warning This variable is linked to allowed_video_codecs,
64  *  if you change this you must change the other acordingly.
65  */
66 const char* allowed_video_codecs_description[] =
67 {
68         _("Flash Video (FLV) / Sorenson Spark / Sorenson H.263."),
69         _("H.263+ / H.263-1998 / H.263 version 2."),
70         _("Huffyuv / HuffYUV."),
71         _("libtheora Theora."),
72         _("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10."),
73         _("MJPEG (Motion JPEG)."),
74         _("raw MPEG-1 video."),
75         _("raw MPEG-2 video."),
76         _("MPEG-4 part 2. (XviD/DivX)"),
77         _("MPEG-4 part 2 Microsoft variant version 3."),
78         _("MPEG-4 part 2 Microsoft variant version 1."),
79         _("MPEG-4 part 2 Microsoft variant version 2."),
80         _("Windows Media Video 7."),
81         _("Windows Media Video 8."),
82         CUSTOM_VCODEC_DESCRIPTION,
83         NULL
84 };
85 /* === P R O C E D U R E S ================================================= */
86
87 /* === M E T H O D S ======================================================= */
88
89 /* === E N T R Y P O I N T ================================================= */
90
91 Dialog_TargetParam::Dialog_TargetParam(Gtk::Window &parent, synfig::TargetParam &tparam):
92         Gtk::Dialog(_("Target Parameters"), parent, false, true)
93 {
94         set_tparam(tparam);
95         // Custom Video Codec Entry
96         Gtk::Label* custom_label(manage(new Gtk::Label(std::string(CUSTOM_VCODEC_DESCRIPTION)+":")));
97         custom_label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
98         customvcodec=Gtk::manage(new Gtk::Entry());
99         // Available Video Codecs Combo Box Text.
100         Gtk::Label* label(manage(new Gtk::Label(_("Available Video Codecs:"))));
101         label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
102         vcodec = Gtk::manage(new Gtk::ComboBoxText());
103         // Appends the codec descriptions to the Combo Box
104         for (int i = 0; allowed_video_codecs[i] != NULL &&
105                                         allowed_video_codecs_description[i] != NULL; i++)
106                 vcodec->append_text(allowed_video_codecs_description[i]);
107         //Adds the Combo Box and the Custom Video Codec entry to the vertical box
108         get_vbox()->pack_start(*label, true, true, 0);
109         get_vbox()->pack_start(*vcodec, true, true, 0);
110         get_vbox()->pack_start(*custom_label, true, true, 0);
111         get_vbox()->pack_start(*customvcodec, true, true, 0);
112
113         // Connect the signal change to the handler
114         vcodec->signal_changed().connect(sigc::mem_fun(*this, &Dialog_TargetParam::on_vcodec_change));
115         // By defaut, set the active text to the Custom Video Codec
116         vcodec->set_active_text(CUSTOM_VCODEC_DESCRIPTION);
117         customvcodec->set_text(CUSTOM_VCODEC);
118         //Compare the passed vcodec to the available and set it active if found
119         for (int i = 0; allowed_video_codecs[i] != NULL &&
120                                         allowed_video_codecs_description[i] != NULL; i++)
121                 if(!get_tparam().video_codec.compare(allowed_video_codecs[i]))
122                 {
123                         vcodec->set_active_text(allowed_video_codecs_description[i]);
124                         customvcodec->set_text(allowed_video_codecs[i]);
125                 }
126
127         //Bitrate Spin Button
128         Gtk::Adjustment* bradj(manage(new class Gtk::Adjustment(double(tparam.bitrate), 10.0,1000.0)));
129         bitrate = Gtk::manage(new class Gtk::SpinButton(*bradj));
130         Gtk::Label* label2(manage(new Gtk::Label(_("Video Bit Rate:"))));
131         label2->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
132         get_vbox()->pack_start(*label2, true, true, 0);
133         get_vbox()->pack_start(*bitrate,true, true, 0);
134
135         get_vbox()->show_all();
136
137         ok_button = manage(new class Gtk::Button(Gtk::StockID("gtk-ok")));
138         ok_button->show();
139         add_action_widget(*ok_button,Gtk::RESPONSE_OK);
140         ok_button->signal_clicked().connect(sigc::mem_fun(*this,&Dialog_TargetParam::on_ok));
141
142         cancel_button = manage(new class Gtk::Button(Gtk::StockID("gtk-cancel")));
143         cancel_button->show();
144         add_action_widget(*cancel_button,Gtk::RESPONSE_CANCEL);
145         cancel_button->signal_clicked().connect(sigc::mem_fun(*this,&Dialog_TargetParam::on_cancel));
146
147 }
148
149 void
150 Dialog_TargetParam::on_ok()
151 {
152         tparam_.video_codec=customvcodec->get_text().c_str();
153         tparam_.bitrate=bitrate->get_value();
154         hide();
155 }
156
157 void
158 Dialog_TargetParam::on_cancel()
159 {
160         hide();
161 }
162
163 void
164 Dialog_TargetParam::on_vcodec_change()
165 {
166         std::string codecnamed = vcodec->get_active_text();
167         customvcodec->set_sensitive(false);
168         for (int i = 0; allowed_video_codecs[i] != NULL &&
169                                         allowed_video_codecs_description[i] != NULL; i++)
170                 if(!codecnamed.compare(allowed_video_codecs_description[i]))
171                 {
172                         if(!codecnamed.compare(CUSTOM_VCODEC_DESCRIPTION))
173                                 customvcodec->set_sensitive(true);
174                         else
175                                 customvcodec->set_text(allowed_video_codecs[i]);
176                 }
177 }
178
179 Dialog_TargetParam::~Dialog_TargetParam()
180 {
181 }
182