1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * pipeline-nocodec-ui.cpp:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
18 #include <gdk-pixbuf/gdk-pixbuf.h>
20 #include "pipeline-nocodec-ui.h"
21 #include "downloader.h"
26 bool CodecDownloader::running
= false;
28 CodecDownloader::CodecDownloader (Surface
*surf
)
41 CodecDownloader::~CodecDownloader ()
47 CodecDownloader::ShowUI (Surface
*surface
)
53 if (!(moonlight_flags
& RUNTIME_INIT_ENABLE_MS_CODECS
))
56 CodecDownloader
*cd
= new CodecDownloader (surface
);
61 // ----- Event Proxies -----
64 CodecDownloader::ResponseEventHandler (GtkDialog
*dialog
, gint response
, gpointer data
)
66 ((CodecDownloader
*) data
)->ResponseEvent (dialog
, (GtkResponseType
)response
);
69 // ----- Event Handlers -----
72 CodecDownloader::ResponseEvent (GtkDialog
*dialog
, GtkResponseType response
)
74 LOG_UI ("CodecDownloader::ResponseEvent (%d)\n", response
);
75 SetCurrentDeployment ();
78 case GTK_RESPONSE_DELETE_EVENT
:
82 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dont_ask
))) {
83 LOG_UI ("Setting DontWarnUnsupportedCodecs\n");
84 configuration
.SetBooleanValue ("Codecs", "DontWarnUnsupportedCodecs", true);
85 configuration
.Save ();
95 CodecDownloader::SetHeader (const gchar
*message
)
97 gchar
*message_full
= g_strdup_printf ("<big><b>%s</b></big>", message
);
98 gtk_label_set_markup (GTK_LABEL (header_label
), message_full
);
99 g_free (message_full
);
103 CodecDownloader::SetMessage (const gchar
*message
)
105 gtk_label_set_text (GTK_LABEL (message_label
), message
);
106 gtk_widget_show (message_label
);
110 CodecDownloader::HideMessage ()
112 gtk_widget_hide (message_label
);
116 CodecDownloader::AdaptToParentWindow ()
118 // try to find a parent for our window
119 // there must be a better way of doing this though :|
120 GList
*toplevels
= gtk_window_list_toplevels ();
121 GList
*current
= toplevels
;
122 GtkWindow
*parent
= NULL
;
124 while (current
!= NULL
) {
125 const char *title
= gtk_window_get_title (GTK_WINDOW (current
->data
));
126 if (title
!= NULL
&& strstr (title
, "Mozilla Firefox") != NULL
) {
127 parent
= GTK_WINDOW (current
->data
);
131 current
= current
->next
;
133 g_list_free (toplevels
);
135 if (parent
!= NULL
) {
136 gtk_window_set_transient_for (GTK_WINDOW (dialog
), parent
);
137 gtk_window_set_position (GTK_WINDOW (dialog
), GTK_WIN_POS_CENTER_ON_PARENT
);
139 // If no parent could be found, just center in the screen
140 gtk_window_set_position (GTK_WINDOW (dialog
), GTK_WIN_POS_CENTER
);
144 // ----- Dialog Create/Destroy -----
147 CodecDownloader::Show ()
149 if (configuration
.GetBooleanValue ("Codecs", "DontWarnUnsupportedCodecs")) {
155 fprintf (stderr
, "CodecDownloader::Show (): Can't call Show more than once.\n");
160 gint label_width
= 400;
162 // Build HIG Dialog Box
163 dialog
= gtk_dialog_new_with_buttons ("Moonlight Codecs Installer", NULL
, (GtkDialogFlags
)
164 (GTK_DIALOG_MODAL
| GTK_DIALOG_DESTROY_WITH_PARENT
| GTK_DIALOG_NO_SEPARATOR
), NULL
);
165 ok_button
= gtk_dialog_add_button (GTK_DIALOG (dialog
), "_Ok", GTK_RESPONSE_OK
);
166 gtk_dialog_set_default_response (GTK_DIALOG (dialog
), GTK_RESPONSE_OK
);
168 AdaptToParentWindow ();
169 gtk_container_set_border_width (GTK_CONTAINER (dialog
), 5);
170 gtk_object_set (GTK_OBJECT (dialog
), "resizable", false, NULL
);
173 GtkWidget
*hbox
= gtk_hbox_new (false, 12);
174 gtk_container_set_border_width (GTK_CONTAINER (hbox
), 5);
175 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog
)->vbox
), hbox
, true, true, 0);
178 icon
= gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING
, GTK_ICON_SIZE_DIALOG
);
179 gtk_misc_set_alignment (GTK_MISC (icon
), 0.5f
, 0.0f
);
180 gtk_box_pack_start (GTK_BOX (hbox
), icon
, false, false, 0);
182 // Contents container
183 vbox
= gtk_vbox_new (false, 0);
184 gtk_box_set_spacing (GTK_BOX (vbox
), 10);
185 gtk_box_pack_start (GTK_BOX (hbox
), vbox
, true, true, 0);
188 header_label
= gtk_label_new (NULL
);
189 SetHeader ("This page requires the Microsoft Media Pack to be installed to play multimedia content.");
190 gtk_label_set_line_wrap (GTK_LABEL (header_label
), true);
191 gtk_label_set_justify (GTK_LABEL (header_label
), GTK_JUSTIFY_LEFT
);
192 gtk_misc_set_alignment (GTK_MISC (header_label
), 0.0f
, 0.5f
);
193 gtk_widget_set_size_request (header_label
, label_width
, -1);
194 gtk_box_pack_start (GTK_BOX (vbox
), header_label
, false, false, 0);
197 message_label
= gtk_label_new (NULL
);
198 SetMessage ("The Microsoft Media Pack is currently unavailable for your "
199 "Operating System or Architecture.");
200 gtk_label_set_line_wrap (GTK_LABEL (message_label
), true);
201 gtk_label_set_justify (GTK_LABEL (message_label
), GTK_JUSTIFY_LEFT
);
202 gtk_misc_set_alignment (GTK_MISC (message_label
), 0.0f
, 0.5f
);
203 gtk_widget_set_size_request (message_label
, label_width
, -1);
204 gtk_box_pack_start (GTK_BOX (vbox
), message_label
, false, false, 0);
206 dont_ask
= gtk_check_button_new_with_label ("Do not show me this message again");
207 gtk_box_pack_start (GTK_BOX (vbox
), dont_ask
, false, false, 0);
210 g_signal_connect (G_OBJECT (dialog
), "response", G_CALLBACK (ResponseEventHandler
), this);
212 gtk_object_set (GTK_OBJECT (ok_button
), "has-focus", true, "has-default", true, NULL
);
214 gtk_widget_show_all (dialog
);
216 ref (); // We manage our lifetime ourself
221 CodecDownloader::Close ()
223 LOG_UI ("CodecDownloader::Close ()\n");
225 gtk_widget_destroy (dialog
);