#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <time.h>
#if !defined(_WIN32)
#include <poll.h>
#include <netinet/in.h>
#include <netdb.h>
-#include <gtkhtml/gtkhtml.h>
+#include <webkit/webkit.h>
#include <libnotify/notify.h>
#else
#define WINVER 0x0500
static GList* dvd_device_list();
static void prune_logs(signal_user_data_t *ud);
void ghb_notify_done(signal_user_data_t *ud);
+gpointer ghb_check_update(signal_user_data_t *ud);
+static gboolean appcast_busy = FALSE;
// This is a dependency map used for greying widgets
// that are dependent on the state of another widget.
}
#endif
+static GHashTable *volname_hash = NULL;
+static GMutex *volname_mutex = NULL;
+
+static void
+free_volname_key(gpointer data)
+{
+ if (data != NULL)
+ g_free(data);
+}
+
+static void
+free_volname_value(gpointer data)
+{
+ if (data != NULL)
+ g_free(data);
+}
+
#if defined(_WIN32)
static gchar*
-get_dvd_volume_name(const gchar *drive)
+get_direct_dvd_volume_name(const gchar *drive)
{
- gchar *result;
+ gchar *result = NULL;
gchar vname[51], fsname[51];
+
if (GetVolumeInformation(drive, vname, 50, NULL, NULL, NULL, fsname, 51))
{
- result = g_strdup_printf("%s (%s)", vname, drive);
- }
- else
- {
- result = g_strdup_printf("%s", drive);
+ result = g_strdup_printf("%s", vname);
}
return result;
}
#else
static gchar*
-get_dvd_volume_name(GDrive *gd)
+get_direct_dvd_volume_name(const gchar *drive)
{
- gchar *label;
+ gchar *result;
+
+ result = ghb_dvd_volname (drive);
+ return result;
+}
+#endif
+
+static gchar*
+get_dvd_volume_name(gpointer gd)
+{
+ gchar *label = NULL;
gchar *result;
gchar *drive;
- drive = g_drive_get_identifier(gd, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
- if (g_drive_has_media (gd))
+ drive = get_dvd_device_name(gd);
+ g_mutex_lock(volname_mutex);
+ label = g_strdup(g_hash_table_lookup(volname_hash, drive));
+ g_mutex_unlock(volname_mutex);
+ if (label != NULL)
{
- label = ghb_dvd_volname (drive);
- if (label != NULL)
+ if (uppers_and_unders(label))
{
- if (uppers_and_unders(label))
- {
- camel_convert(label);
- }
- result = g_strdup_printf("%s - %s", drive, label);
- g_free(label);
- }
- else
- {
- result = g_strdup_printf("%s", drive);
+ camel_convert(label);
}
+#if defined(_WIN32)
+ result = g_strdup_printf("%s (%s)", label, drive);
+#else
+ result = g_strdup_printf("%s - %s", drive, label);
+#endif
+ g_free(label);
}
else
{
g_free(drive);
return result;
}
+
+void
+ghb_volname_cache_init(void)
+{
+ volname_mutex = g_mutex_new();
+ volname_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ free_volname_key, free_volname_value);
+}
+
+static void
+free_drive(gpointer drive)
+{
+#if defined(_WIN32)
+ g_free(drive);
+#else
+ g_object_unref(drive);
#endif
+}
+gpointer
+ghb_cache_volnames(signal_user_data_t *ud)
+{
+ GList *link, *drives;
+
+ g_debug("ghb_cache_volnames()");
+ link = drives = dvd_device_list();
+ if (drives == NULL)
+ return NULL;
+
+ g_mutex_lock(volname_mutex);
+ g_hash_table_remove_all(volname_hash);
+ while (link != NULL)
+ {
+ gchar *name, *drive;
+
+#if !defined(_WIN32)
+ if (!g_drive_has_media (link->data))
+ {
+ g_object_unref(link->data);
+ link = link->next;
+ continue;
+ }
+#endif
+ drive = get_dvd_device_name(link->data);
+ name = get_direct_dvd_volume_name(drive);
+
+ if (drive != NULL && name != NULL)
+ {
+ g_hash_table_insert(volname_hash, drive, name);
+ }
+ else
+ {
+ if (drive != NULL)
+ g_free(drive);
+ if (name != NULL)
+ g_free(name);
+ }
+
+ free_drive(link->data);
+ link = link->next;
+ }
+ g_mutex_unlock(volname_mutex);
+
+ g_list_free(drives);
+
+ g_idle_add((GSourceFunc)ghb_file_menu_add_dvd, ud);
+
+ return NULL;
+}
static void
set_destination(signal_user_data_t *ud)
gchar *name = get_dvd_device_name(link->data);
gtk_combo_box_append_text(combo, name);
g_free(name);
- g_object_unref(link->data);
+ free_drive(link->data);
link = link->next;
}
g_list_free(drives);
}
g_free(container);
}
- ghb_subtitle_adjust_burn(ud);
+ ghb_subtitle_prune(ud);
}
static gchar*
titleindex = ghb_settings_combo_int(ud->settings, "title");
ghb_update_ui_combo_box (ud, "AudioTrack", titleindex, FALSE);
- ghb_subtitle_track_model(ud, titleindex);
+ ghb_update_ui_combo_box (ud, "SubtitleTrack", titleindex, FALSE);
- ghb_set_pref_subtitle(titleindex, ud);
if (ghb_get_title_info (&tinfo, titleindex))
{
show_title_info(ud, &tinfo);
update_chapter_list (ud);
ghb_adjust_audio_rate_combos(ud);
ghb_set_pref_audio(titleindex, ud);
+ ghb_set_pref_subtitle(titleindex, ud);
if (ghb_settings_get_boolean(ud->settings, "vquality_type_target"))
{
gint bitrate = ghb_calculate_target_bitrate (ud->settings, titleindex);
if (GTK_WIDGET_SENSITIVE(widget))
ghb_set_scale (ud, GHB_PIC_KEEP_DISPLAY_WIDTH);
- gint pic_par;
-
- pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
- if (pic_par == 3)
- {
- gint par_width, par_height;
-
- par_width = ghb_settings_get_int(ud->settings, "par_width");
- par_height = ghb_settings_get_int(ud->settings, "par_height");
- ghb_settings_set_int(ud->settings, "PicturePARWidth", par_width);
- ghb_settings_set_int(ud->settings, "PicturePARHeight", par_height);
- }
update_preview = TRUE;
}
-void
+G_MODULE_EXPORT void
display_height_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
g_debug("display_height_changed_cb ()");
if (GTK_WIDGET_SENSITIVE(widget))
ghb_set_scale (ud, GHB_PIC_KEEP_DISPLAY_HEIGHT);
- gint pic_par;
+ update_preview = TRUE;
+}
- pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
- if (pic_par == 3)
- {
- gint par_width, par_height;
+G_MODULE_EXPORT void
+par_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
+{
+ g_debug("par_changed_cb ()");
+ ghb_widget_to_setting(ud->settings, widget);
+ ghb_check_dependency(ud, widget);
+ ghb_clear_presets_selection(ud);
+ ghb_live_reset(ud);
+ if (GTK_WIDGET_SENSITIVE(widget))
+ ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
- par_width = ghb_settings_get_int(ud->settings, "par_width");
- par_height = ghb_settings_get_int(ud->settings, "par_height");
- ghb_settings_set_int(ud->settings, "PicturePARWidth", par_width);
- ghb_settings_set_int(ud->settings, "PicturePARHeight", par_height);
- }
update_preview = TRUE;
}
-void
+G_MODULE_EXPORT void
scale_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
g_debug("scale_changed_cb ()");
}
G_MODULE_EXPORT void
+show_crop_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
+{
+ g_debug("show_crop_changed_cb ()");
+ ghb_widget_to_setting(ud->settings, widget);
+ ghb_check_dependency(ud, widget);
+ ghb_live_reset(ud);
+ if (GTK_WIDGET_SENSITIVE(widget))
+ ghb_set_scale (ud, 0);
+ update_preview = TRUE;
+}
+
+G_MODULE_EXPORT void
generic_entry_changed_cb(GtkEntry *entry, signal_user_data_t *ud)
{
// Normally (due to user input) I only want to process the entry
ghb_settings_set_int(js, "job_status", qstatus);
ghb_save_queue(ud->queue);
ud->cancel_encode = FALSE;
+#if !GTK_CHECK_VERSION(2, 16, 0)
+ GtkStatusIcon *si;
+
+ si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));
+ gtk_status_icon_set_tooltip(si, "HandBrake");
+#endif
}
else if (status.queue.state & GHB_STATE_MUXING)
{
status_str = working_status_string(ud, &status.queue);
label = GTK_LABEL(GHB_WIDGET(ud->builder, "queue_status"));
gtk_label_set_text (label, status_str);
+#if !GTK_CHECK_VERSION(2, 16, 0)
+ GtkStatusIcon *si;
+
+ si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));
+ gtk_status_icon_set_tooltip(si, status_str);
+#endif
g_free(status_str);
}
if (status.scan.state & GHB_STATE_WORKING)
}
}
+#if GTK_CHECK_VERSION(2, 16, 0)
+G_MODULE_EXPORT gboolean
+status_icon_query_tooltip_cb(
+ GtkStatusIcon *si,
+ gint x,
+ gint y,
+ gboolean kbd_mode,
+ GtkTooltip *tt,
+ signal_user_data_t *ud)
+{
+ ghb_status_t status;
+ gchar *status_str;
+
+ ghb_get_status(&status);
+ if (status.queue.state & GHB_STATE_WORKING)
+ status_str = working_status_string(ud, &status.queue);
+ else if (status.queue.state & GHB_STATE_WORKDONE)
+ status_str = g_strdup("Encode Complete");
+ else
+ status_str = g_strdup("HandBrake");
+
+ gtk_tooltip_set_text(tt, status_str);
+ gtk_tooltip_set_icon_from_icon_name(tt, "hb-icon", GTK_ICON_SIZE_BUTTON);
+ g_free(status_str);
+ return TRUE;
+}
+#endif
+
G_MODULE_EXPORT gboolean
ghb_timer_cb(gpointer data)
{
ghb_set_preview_image (ud);
update_preview = FALSE;
}
+
+ if (!appcast_busy)
+ {
+ gchar *updates;
+ updates = ghb_settings_get_string(ud->settings, "check_updates");
+ gint64 duration = 0;
+ if (strcmp(updates, "daily") == 0)
+ duration = 60 * 60 * 24;
+ else if (strcmp(updates, "weekly") == 0)
+ duration = 60 * 60 * 24 * 7;
+ else if (strcmp(updates, "monthly") == 0)
+ duration = 60 * 60 * 24 * 7;
+
+ g_free(updates);
+ if (duration != 0)
+ {
+ gint64 last;
+ time_t tt;
+
+ last = ghb_settings_get_int64(ud->settings, "last_update_check");
+ time(&tt);
+ if (last + duration < tt)
+ {
+ ghb_settings_set_int64(ud->settings,
+ "last_update_check", tt);
+ ghb_pref_save(ud->settings, "last_update_check");
+ g_thread_create((GThreadFunc)ghb_check_update, ud,
+ FALSE, NULL);
+ }
+ }
+ }
return TRUE;
}
_now = time(NULL);
now = localtime( &_now );
- snprintf(fmt, 362, "[%02d:%02d:%02d] lingui: %s\n",
+ snprintf(fmt, 362, "[%02d:%02d:%02d] gtkgui: %s\n",
now->tm_hour, now->tm_min, now->tm_sec, log);
va_start(args, log);
vfprintf(stderr, fmt, args);
}
G_MODULE_EXPORT void
+skip_taskbar_cb(GtkWidget *widget, signal_user_data_t *ud)
+{
+ g_debug("pref_changed_cb");
+ ghb_widget_to_setting (ud->settings, widget);
+ ghb_check_dependency(ud, widget);
+ const gchar *name = gtk_widget_get_name(widget);
+ ghb_pref_save(ud->settings, name);
+
+ GtkWindow *window;
+ window = GTK_WINDOW(GHB_WIDGET (ud->builder, "hb_window"));
+ gtk_window_set_skip_taskbar_hint(window,
+ ghb_settings_get_boolean(ud->settings, "skip_taskbar"));
+}
+
+G_MODULE_EXPORT void
vqual_granularity_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
g_debug("vqual_granularity_changed_cb");
static GtkActionGroup *agroup = NULL;
static gint merge_id;
+ g_debug("ghb_file_menu_add_dvd()");
link = drives = dvd_device_list();
if (drives != NULL)
{
(GCallback)dvd_source_activate_cb, ud);
g_free(name);
g_free(drive);
- g_object_unref(link->data);
+ free_drive(link->data);
link = link->next;
}
g_list_free(drives);
ins_count++;
if (ins_count == 2)
{
- ghb_file_menu_add_dvd(ud);
+ g_thread_create((GThreadFunc)ghb_cache_volnames, ud, FALSE, NULL);
if (ud->current_dvd_device != NULL &&
strcmp(device, ud->current_dvd_device) == 0)
{
rem_count++;
if (rem_count == 2)
{
- ghb_file_menu_add_dvd(ud);
+ g_thread_create((GThreadFunc)ghb_cache_volnames, ud, FALSE, NULL);
if (ud->current_dvd_device != NULL &&
strcmp(device, ud->current_dvd_device) == 0)
{
gint state;
g_debug("drive_changed_cb()");
- ghb_file_menu_add_dvd(ud);
+ g_thread_create((GThreadFunc)ghb_cache_volnames, ud, FALSE, NULL);
state = ghb_get_scan_state();
device = g_drive_get_identifier(gd, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if (error != NULL)
{
- g_debug("DBUS cannot connect: %s", error->message);
+ g_warning("DBUS cannot connect: %s", error->message);
g_error_free(error);
return;
}
GPM_DBUS_INHIBIT_PATH, GPM_DBUS_INHIBIT_INTERFACE);
if (proxy == NULL)
{
- g_debug("Could not get DBUS proxy: %s", GPM_DBUS_SERVICE);
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SERVICE);
dbus_g_connection_unref(conn);
return;
}
G_TYPE_INVALID,
G_TYPE_UINT, &gpm_cookie,
G_TYPE_INVALID);
+ gpm_inhibited = TRUE;
if (!res)
{
- g_warning("Inhibit method failed");
- gpm_cookie = -1;
- }
- if (error != NULL)
- {
- g_warning("Inhibit problem: %s", error->message);
- g_error_free(error);
+ if (error != NULL)
+ {
+ g_warning("Inhibit failed: %s", error->message);
+ g_error_free(error);
+ gpm_cookie = -1;
+ }
+ else
+ g_warning("Inhibit failed");
gpm_cookie = -1;
+ gpm_inhibited = FALSE;
}
- gpm_inhibited = TRUE;
g_object_unref(G_OBJECT(proxy));
dbus_g_connection_unref(conn);
#endif
conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if (error != NULL)
{
- g_debug("DBUS cannot connect: %s", error->message);
+ g_warning("DBUS cannot connect: %s", error->message);
g_error_free(error);
return;
}
GPM_DBUS_INHIBIT_PATH, GPM_DBUS_INHIBIT_INTERFACE);
if (proxy == NULL)
{
- g_debug("Could not get DBUS proxy: %s", GPM_DBUS_SERVICE);
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SERVICE);
dbus_g_connection_unref(conn);
return;
}
G_TYPE_INVALID);
if (!res)
{
- g_warning("UnInhibit method failed");
- }
- if (error != NULL)
- {
- g_warning("UnInhibit problem: %s", error->message);
- g_error_free(error);
+ if (error != NULL)
+ {
+ g_warning("UnInhibit failed: %s", error->message);
+ g_error_free(error);
+ }
+ else
+ g_warning("UnInhibit failed");
}
gpm_inhibited = FALSE;
dbus_g_connection_unref(conn);
return g_strdup_printf("QP: %.1f / %.1f%%", val, percent);
}
-#if !defined(_WIN32)
-G_MODULE_EXPORT void
-html_link_cb(GtkHTML *html, const gchar *url, signal_user_data_t *ud)
-{
- browse_url(url);
-}
-#endif
-
-static gpointer check_stable_update(signal_user_data_t *ud);
-static gboolean stable_update_lock = FALSE;
-
static void
process_appcast(signal_user_data_t *ud)
{
gchar *description = NULL, *build = NULL, *version = NULL, *msg;
#if !defined(_WIN32)
- GtkWidget *html, *window;
+ GtkWidget *window;
+ static GtkWidget *html = NULL;
#endif
GtkWidget *dialog, *label;
gint response, ibuild = 0, skip;
if (ud->appcast == NULL || ud->appcast_len < 15 ||
strncmp(&(ud->appcast[9]), "200 OK", 6))
{
- if (!stable_update_lock && hb_get_build(NULL) % 100)
- g_idle_add((GSourceFunc)check_stable_update, ud);
goto done;
}
ghb_appcast_parse(ud->appcast, &description, &build, &version);
if (description == NULL || build == NULL || version == NULL
|| ibuild <= hb_get_build(NULL) || skip == ibuild)
{
- if (!stable_update_lock && hb_get_build(NULL) % 100)
- g_thread_create((GThreadFunc)check_stable_update, ud, FALSE, NULL);
goto done;
}
msg = g_strdup_printf("HandBrake %s/%s is now available (you have %s/%d).",
version, build, hb_get_version(NULL), hb_get_build(NULL));
label = GHB_WIDGET(ud->builder, "update_message");
gtk_label_set_text(GTK_LABEL(label), msg);
+
#if !defined(_WIN32)
- html = gtk_html_new_from_string(description, -1);
- g_signal_connect(html, "link_clicked", G_CALLBACK(html_link_cb), ud);
- window = GHB_WIDGET(ud->builder, "update_scroll");
- gtk_container_add(GTK_CONTAINER(window), html);
- // Show it
- gtk_widget_set_size_request(html, 420, 240);
- gtk_widget_show(html);
+ if (html == NULL)
+ {
+ html = webkit_web_view_new();
+ window = GHB_WIDGET(ud->builder, "update_scroll");
+ gtk_container_add(GTK_CONTAINER(window), html);
+ // Show it
+ gtk_widget_set_size_request(html, 420, 240);
+ gtk_widget_show(html);
+ }
+ webkit_web_view_open(WEBKIT_WEB_VIEW(html), description);
#endif
dialog = GHB_WIDGET(ud->builder, "update_dialog");
response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_hide(dialog);
-#if !defined(_WIN32)
- gtk_widget_destroy(html);
-#endif
if (response == GTK_RESPONSE_OK)
{
// Skip
g_free(ud->appcast);
ud->appcast_len = 0;
ud->appcast = NULL;
+ appcast_busy = FALSE;
}
void
if( !( host = gethostbyname( address ) ) )
{
g_warning( "gethostbyname failed (%s)", address );
+ appcast_busy = FALSE;
return NULL;
}
if( fd < 0 )
{
g_debug( "socket failed" );
+ appcast_busy = FALSE;
return NULL;
}
if(connect(fd, (struct sockaddr*)&sock, sizeof(struct sockaddr_in )) < 0 )
{
g_debug( "connect failed" );
+ appcast_busy = FALSE;
return NULL;
}
ioc = g_io_channel_unix_new(fd);
gsize len;
GIOChannel *ioc;
GError *gerror = NULL;
+ GRegex *regex;
+ GMatchInfo *mi;
+ gchar *host, *appcast;
g_debug("ghb_check_update");
- if (hb_get_build(NULL) % 100)
- {
- query =
- "GET /appcast_unstable.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
- }
- else
+ appcast_busy = TRUE;
+ regex = g_regex_new("^http://(.+)/(.+)$", 0, 0, NULL);
+ if (!g_regex_match(regex, HB_PROJECT_URL_APPCAST, 0, &mi))
{
- stable_update_lock = TRUE;
- query = "GET /appcast.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
- }
- ioc = ghb_net_open(ud, "handbrake.fr", 80);
- if (ioc == NULL)
return NULL;
+ }
- g_io_channel_write_chars(ioc, query, strlen(query), &len, &gerror);
- g_io_channel_flush(ioc, &gerror);
- // This function is initiated by g_idle_add. Must return false
- // so that it is not called again
- return NULL;
-}
+ host = g_match_info_fetch(mi, 1);
+ appcast = g_match_info_fetch(mi, 2);
-static gpointer
-check_stable_update(signal_user_data_t *ud)
-{
- gchar *query;
- gsize len;
- GIOChannel *ioc;
- GError *gerror = NULL;
+ if (host == NULL || appcast == NULL)
+ return NULL;
+
+ query = g_strdup_printf( "GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n",
+ appcast, host);
- g_debug("check_stable_update");
- stable_update_lock = TRUE;
- query = "GET /appcast.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
- ioc = ghb_net_open(ud, "handbrake.fr", 80);
+ ioc = ghb_net_open(ud, host, 80);
if (ioc == NULL)
return NULL;
g_io_channel_write_chars(ioc, query, strlen(query), &len, &gerror);
g_io_channel_flush(ioc, &gerror);
- // This function is initiated by g_idle_add. Must return false
- // so that it is not called again
+ g_free(query);
+ g_free(host);
+ g_free(appcast);
+ g_match_info_free(mi);
+ g_regex_unref(regex);
return NULL;
}
GtkStatusIcon *si;
si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));
- gtk_status_icon_set_from_icon_name(si, "hb-status-empty");
#if !defined(_WIN32)
NotifyNotification *notification;