#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 ghb_can_shutdown_gpm();
+static void ghb_shutdown_gpm();
+static gboolean ghb_can_suspend_gpm();
+static void ghb_suspend_gpm();
+static gboolean appcast_busy = FALSE;
// This is a dependency map used for greying widgets
// that are dependent on the state of another widget.
g_debug("on_quit1_activate ()");
if (state & GHB_STATE_WORKING)
{
- if (ghb_cancel_encode("Closing HandBrake will terminate encoding.\n"))
+ if (ghb_cancel_encode2(ud, "Closing HandBrake will terminate encoding.\n"))
{
ghb_hb_cleanup(FALSE);
prune_logs(ud);
}
#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
+
+ if (GetVolumeInformation(drive, vname, 50, NULL, NULL, NULL, fsname, 50))
{
- 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 *result;
+
+ result = ghb_dvd_volname (drive);
+ return result;
+}
+#endif
+
+static gchar*
+get_dvd_volume_name(gpointer gd)
{
- gchar *label;
+ 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))
- {
- camel_convert(label);
- }
- result = g_strdup_printf("%s - %s", drive, label);
- g_free(label);
- }
- else
+ if (uppers_and_unders(label))
{
- 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 const gchar*
+get_extension(signal_user_data_t *ud)
+{
+ int container;
+ const gchar *extension = "error";
+ GValue *audio_list;
+
+ container = ghb_settings_combo_int(ud->settings, "FileFormat");
+ if (container == HB_MUX_MP4)
+ {
+ extension = "mp4";
+ audio_list = ghb_settings_get_value(ud->settings, "audio_list");
+ if (ghb_ac3_in_audio_list (audio_list))
+ {
+ extension = "m4v";
+ }
+ else if (ghb_settings_get_boolean(ud->settings, "ChapterMarkers"))
+ {
+ extension = "m4v";
+ }
+ else if (ghb_settings_get_boolean(ud->settings, "UseM4v"))
+ {
+ extension = "m4v";
+ }
+ }
+ else if (container == HB_MUX_MKV)
+ {
+ extension = "mkv";
+ }
+ return extension;
+}
static void
set_destination(signal_user_data_t *ud)
if (ghb_settings_get_boolean(ud->settings, "use_source_name"))
{
GString *str = g_string_new("");
- gchar *vol_name, *filename, *extension;
+ gchar *vol_name, *filename;
+ const gchar *extension;
gchar *new_name;
gint title;
filename = ghb_settings_get_string(ud->settings, "dest_file");
- extension = ghb_settings_get_string(ud->settings, "FileFormat");
+ extension = get_extension(ud);
vol_name = ghb_settings_get_string(ud->settings, "volume_label");
g_string_append_printf(str, "%s", vol_name);
title = ghb_settings_combo_int(ud->settings, "title");
new_name = g_string_free(str, FALSE);
ghb_ui_update(ud, "dest_file", ghb_string_value(new_name));
g_free(filename);
- g_free(extension);
g_free(vol_name);
g_free(new_name);
}
static gchar*
get_file_label(const gchar *filename)
{
- static gchar *containers[] =
- {".vob", ".mpg", ".m2ts", ".mkv", ".mp4", ".m4v", ".avi", ".ogm", NULL};
- gchar *base;
- gint ii;
+ gchar *base, *pos, *end;
base = g_path_get_basename(filename);
- for (ii = 0; containers[ii] != NULL; ii++)
+ pos = strrchr(base, '.');
+ if (pos != NULL)
{
- if (g_str_has_suffix(base, containers[ii]))
- {
- gchar *pos;
- pos = strrchr(base, '.');
+ // If the last '.' is within 4 chars of end of name, assume
+ // there is an extension we want to strip.
+ end = &base[strlen(base) - 1];
+ if (end - pos <= 4)
*pos = 0;
- break;
- }
}
return base;
}
}
static gboolean
-update_source_label(signal_user_data_t *ud, const gchar *source)
+update_source_label(signal_user_data_t *ud, const gchar *source, gboolean update_dest)
{
gchar *label = NULL;
gint len;
gchar *start;
gchar *filename = g_strdup(source);
+ g_debug("update_source_label()");
len = strlen(filename);
- if (filename[len-1] == G_DIR_SEPARATOR) filename[len-1] = 0;
if (g_file_test(filename, G_FILE_TEST_IS_DIR))
{
// Skip dos drive letters
}
else
{
+ if (filename[len-1] == G_DIR_SEPARATOR) filename[len-1] = 0;
if (start != NULL)
start++;
else
gtk_label_set_text (GTK_LABEL(widget), label);
ghb_settings_set_string(ud->settings, "volume_label", label);
g_free(label);
- set_destination(ud);
+ if (update_dest)
+ set_destination(ud);
}
else
{
G_MODULE_EXPORT void
chooser_file_selected_cb(GtkFileChooser *dialog, signal_user_data_t *ud)
{
- const gchar *name = gtk_file_chooser_get_filename (dialog);
+ gchar *name = gtk_file_chooser_get_filename (dialog);
GtkTreeModel *store;
GtkTreeIter iter;
const gchar *device;
gtk_combo_box_set_active_iter (combo, &iter);
else
gtk_combo_box_set_active (combo, 0);
+
+ g_free(name);
}
G_MODULE_EXPORT void
ii = gtk_combo_box_get_active (combo);
if (ii > 0)
{
- const gchar *device, *name;
+ const gchar *device;
+ gchar *name;
dialog = GHB_WIDGET(ud->builder, "source_dialog");
device = gtk_combo_box_get_active_text (combo);
name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog));
if (name == NULL || strcmp(name, device) != 0)
gtk_file_chooser_select_filename (GTK_FILE_CHOOSER(dialog), device);
+ if (name != NULL)
+ g_free(name);
}
}
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);
extern GValue *ghb_queue_edit_settings;
static gchar *last_scan_file = NULL;
+static void
+show_scan_progress(signal_user_data_t *ud)
+{
+ GtkProgressBar *progress;
+ GtkLabel *label;
+
+ progress = GTK_PROGRESS_BAR(GHB_WIDGET(ud->builder, "scan_prog"));
+ gtk_progress_bar_set_fraction (progress, 0);
+ gtk_widget_show(GTK_WIDGET(progress));
+
+ label = GTK_LABEL(GHB_WIDGET(ud->builder, "source_title"));
+ gtk_label_set_text( label, "Scanning ..." );
+}
+
+static void
+start_scan(
+ signal_user_data_t *ud,
+ const gchar *path,
+ gint titlenum,
+ gint preview_count)
+{
+ GtkWidget *widget;
+ GtkAction *action;
+ ghb_status_t status;
+
+ ghb_get_status(&status);
+ if (status.scan.state != GHB_STATE_IDLE)
+ return;
+
+ widget = GHB_WIDGET(ud->builder, "sourcetoolbutton");
+ gtk_widget_set_sensitive(widget, FALSE);
+ action = GHB_ACTION(ud->builder, "source_action");
+ gtk_action_set_sensitive(action, FALSE);
+ action = GHB_ACTION(ud->builder, "source_single_action");
+ gtk_action_set_sensitive(action, FALSE);
+ ghb_backend_scan(path, titlenum, preview_count);
+}
+
void
ghb_do_scan(
signal_user_data_t *ud,
gint titlenum,
gboolean force)
{
+ g_debug("ghb_do_scan()");
if (!force && last_scan_file != NULL &&
strcmp(last_scan_file, filename) == 0)
{
{
last_scan_file = g_strdup(filename);
ghb_settings_set_string(ud->settings, "source", filename);
- if (update_source_label(ud, filename))
+ if (update_source_label(ud, filename, TRUE))
{
- GtkProgressBar *progress;
- progress = GTK_PROGRESS_BAR(GHB_WIDGET(ud->builder, "progressbar"));
gchar *path;
+ gint preview_count;
+
+ show_scan_progress(ud);
path = ghb_settings_get_string( ud->settings, "source");
- gtk_progress_bar_set_fraction (progress, 0);
- gtk_progress_bar_set_text (progress, "Scanning ...");
prune_logs(ud);
- gint preview_count;
+
preview_count = ghb_settings_get_int(ud->settings, "preview_count");
- ghb_backend_scan(path, titlenum, preview_count);
+ start_scan(ud, path, titlenum, preview_count);
g_free(path);
}
else
gtk_widget_hide(dialog);
if (response == GTK_RESPONSE_ACCEPT)
{
- char *filename;
+ gchar *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
if (filename != NULL)
g_free(sourcename);
}
-static void
-update_destination_extension(signal_user_data_t *ud)
+void
+ghb_update_destination_extension(signal_user_data_t *ud)
{
- static gchar *containers[] = {".mkv", ".mp4", ".m4v", ".avi", ".ogm", NULL};
+ static gchar *containers[] = {".mkv", ".mp4", ".m4v", NULL};
gchar *filename;
- gchar *extension;
+ const gchar *extension;
gint ii;
GtkEntry *entry;
+ static gboolean busy = FALSE;
- g_debug("update_destination_extension ()");
- extension = ghb_settings_get_string(ud->settings, "FileFormat");
+ g_debug("ghb_update_destination_extension ()");
+ // Since this function modifies the thing that triggers it's
+ // invocation, check to see if busy to prevent accidental infinite
+ // recursion.
+ if (busy)
+ return;
+ busy = TRUE;
+ extension = get_extension(ud);
entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "dest_file"));
filename = g_strdup(gtk_entry_get_text(entry));
for (ii = 0; containers[ii] != NULL; ii++)
break;
}
}
- g_free(extension);
g_free(filename);
+ busy = FALSE;
}
static void
gchar *dest_file, *dest_dir, *dest;
g_debug("dest_file_changed_cb ()");
- update_destination_extension(ud);
+ ghb_update_destination_extension(ud);
ghb_widget_to_setting(ud->settings, (GtkWidget*)entry);
// This signal goes off with ever keystroke, so I'm putting this
// update on the timer.
g_debug("window_delete_event_cb ()");
if (state & GHB_STATE_WORKING)
{
- if (ghb_cancel_encode("Closing HandBrake will terminate encoding.\n"))
+ if (ghb_cancel_encode2(ud, "Closing HandBrake will terminate encoding.\n"))
{
ghb_hb_cleanup(FALSE);
prune_logs(ud);
G_MODULE_EXPORT void
container_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
- const GValue *audio_list;
- gboolean markers;
-
g_debug("container_changed_cb ()");
ghb_widget_to_setting(ud->settings, widget);
- update_destination_extension(ud);
ghb_check_dependency(ud, widget);
update_acodec_combo(ud);
+ ghb_update_destination_extension(ud);
ghb_clear_presets_selection(ud);
ghb_live_reset(ud);
-
- audio_list = ghb_settings_get_value(ud->settings, "audio_list");
- if (ghb_ac3_in_audio_list (audio_list))
- {
- gchar *container;
-
- container = ghb_settings_get_string(ud->settings, "FileFormat");
- if (strcmp(container, "mp4") == 0)
- {
- ghb_ui_update(ud, "FileFormat", ghb_string_value("m4v"));
- }
- g_free(container);
- }
- markers = ghb_settings_get_boolean(ud->settings, "ChapterMarkers");
- if (markers)
- {
- gchar *container;
-
- container = ghb_settings_get_string(ud->settings, "FileFormat");
- if (strcmp(container, "mp4") == 0)
- {
- ghb_ui_update(ud, "FileFormat", ghb_string_value("m4v"));
- }
- g_free(container);
- }
ghb_subtitle_prune(ud);
}
ghb_update_ui_combo_box (ud, "AudioTrack", titleindex, FALSE);
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);
G_MODULE_EXPORT void
chapter_markers_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
- gboolean markers;
-
ghb_widget_to_setting(ud->settings, widget);
ghb_check_dependency(ud, widget);
ghb_clear_presets_selection(ud);
ghb_live_reset(ud);
- markers = ghb_settings_get_boolean(ud->settings, "ChapterMarkers");
- if (markers)
- {
- gchar *container;
-
- container = ghb_settings_get_string(ud->settings, "FileFormat");
- if (strcmp(container, "mp4") == 0)
- {
- ghb_ui_update(ud, "FileFormat", ghb_string_value("m4v"));
- }
- g_free(container);
- }
+ ghb_update_destination_extension(ud);
}
G_MODULE_EXPORT void
gtk_widget_hide(dialog);
}
+typedef struct
+{
+ GtkMessageDialog *dlg;
+ const gchar *msg;
+ const gchar *action;
+ gint timeout;
+} countdown_t;
+
+static gboolean
+shutdown_cb(countdown_t *cd)
+{
+ gchar *str;
+
+ cd->timeout--;
+ if (cd->timeout == 0)
+ {
+ ghb_shutdown_gpm();
+ gtk_main_quit();
+ return FALSE;
+ }
+ str = g_strdup_printf("%s\n\n%s in %d seconds ...",
+ cd->msg, cd->action, cd->timeout);
+ gtk_message_dialog_set_markup(cd->dlg, str);
+ g_free(str);
+ return TRUE;
+}
+
+static gboolean
+suspend_cb(countdown_t *cd)
+{
+ gchar *str;
+
+ cd->timeout--;
+ if (cd->timeout == 0)
+ {
+ gtk_widget_destroy (GTK_WIDGET(cd->dlg));
+ ghb_suspend_gpm();
+ return FALSE;
+ }
+ str = g_strdup_printf("%s\n\n%s in %d seconds ...",
+ cd->msg, cd->action, cd->timeout);
+ gtk_message_dialog_set_markup(cd->dlg, str);
+ g_free(str);
+ return TRUE;
+}
+
+void
+ghb_countdown_dialog(
+ GtkMessageType type,
+ const gchar *message,
+ const gchar *action,
+ const gchar *cancel,
+ GSourceFunc action_func,
+ gint timeout)
+{
+ GtkWidget *dialog;
+ GtkResponseType response;
+ guint timeout_id;
+ countdown_t cd;
+
+ cd.msg = message;
+ cd.action = action;
+ cd.timeout = timeout;
+
+ // Toss up a warning dialog
+ dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
+ type, GTK_BUTTONS_NONE,
+ "%s\n\n%s in %d seconds ...",
+ message, action, timeout);
+ gtk_dialog_add_buttons( GTK_DIALOG(dialog),
+ cancel, GTK_RESPONSE_CANCEL,
+ NULL);
+
+ cd.dlg = GTK_MESSAGE_DIALOG(dialog);
+ timeout_id = g_timeout_add(1000, action_func, &cd);
+ response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy (dialog);
+ if (response == GTK_RESPONSE_CANCEL)
+ {
+ GMainContext *mc;
+ GSource *source;
+
+ mc = g_main_context_default();
+ source = g_main_context_find_source_by_id(mc, timeout_id);
+ if (source != NULL)
+ g_source_destroy(source);
+ }
+}
+
gboolean
ghb_message_dialog(GtkMessageType type, const gchar *message, const gchar *no, const gchar *yes)
{
return TRUE;
}
+void
+ghb_error_dialog(GtkMessageType type, const gchar *message, const gchar *cancel)
+{
+ GtkWidget *dialog;
+ GtkResponseType response;
+
+ // Toss up a warning dialog
+ dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
+ type, GTK_BUTTONS_NONE,
+ "%s", message);
+ gtk_dialog_add_buttons( GTK_DIALOG(dialog),
+ cancel, GTK_RESPONSE_CANCEL, NULL);
+ response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy (dialog);
+}
+
+void
+ghb_cancel_encode(signal_user_data_t *ud, const gchar *extra_msg)
+{
+ GtkWidget *dialog;
+ GtkResponseType response;
+
+ if (extra_msg == NULL) extra_msg = "";
+ // Toss up a warning dialog
+ dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
+ GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
+ "%sYour movie will be lost if you don't continue encoding.",
+ extra_msg);
+ gtk_dialog_add_buttons( GTK_DIALOG(dialog),
+ "Cancel Current and Stop", 1,
+ "Cancel Current, Start Next", 2,
+ "Finish Current, then Stop", 3,
+ "Continue Encoding", 4,
+ NULL);
+ response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy (dialog);
+ switch (response)
+ {
+ case 1:
+ ghb_stop_queue();
+ ud->cancel_encode = GHB_CANCEL_ALL;
+ break;
+ case 2:
+ ghb_stop_queue();
+ ud->cancel_encode = GHB_CANCEL_CURRENT;
+ break;
+ case 3:
+ ud->cancel_encode = GHB_CANCEL_FINISH;
+ break;
+ case 4:
+ default:
+ ud->cancel_encode = GHB_CANCEL_NONE;
+ break;
+ }
+}
+
gboolean
-ghb_cancel_encode(const gchar *extra_msg)
+ghb_cancel_encode2(signal_user_data_t *ud, const gchar *extra_msg)
{
GtkWidget *dialog;
GtkResponseType response;
"%sYour movie will be lost if you don't continue encoding.",
extra_msg);
gtk_dialog_add_buttons( GTK_DIALOG(dialog),
- "Continue Encoding", GTK_RESPONSE_NO,
- "Stop Encoding", GTK_RESPONSE_YES, NULL);
+ "Cancel Current and Stop", 1,
+ "Continue Encoding", 4,
+ NULL);
response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy (dialog);
- if (response == GTK_RESPONSE_NO) return FALSE;
- ghb_stop_queue();
- return TRUE;
+ switch (response)
+ {
+ case 1:
+ ghb_stop_queue();
+ ud->cancel_encode = GHB_CANCEL_ALL;
+ return TRUE;
+ case 4:
+ default:
+ break;
+ }
+ return FALSE;
}
static void
prune_logs(signal_user_data_t *ud)
{
gchar *dest_dir;
+ gint days;
// Only prune logs stored in the default config dir location
+ days = ghb_settings_combo_int(ud->settings, "LogLongevity");
+ if (days > 365)
+ return;
+
dest_dir = ghb_get_user_config_dir("EncodeLogs");
if (g_file_test(dest_dir, G_FILE_TEST_IS_DIR))
{
const gchar *file;
- int week = 7*24*60*60;
+ gint duration = days * 24 * 60 * 60;
+
GDir *gdir = g_dir_open(dest_dir, 0, NULL);
time_t now;
path = g_strdup_printf("%s/%s", dest_dir, file);
g_stat(path, &stbuf);
- if (now - stbuf.st_mtime > week)
+ if (now - stbuf.st_mtime > duration)
{
g_unlink(path);
}
{
*pos = 0;
}
- log_path = g_strdup_printf("%s/%d-%02d-%02d %02d-%02d-%02d %s.log",
+ log_path = g_strdup_printf("%s/%s %d-%02d-%02d %02d-%02d-%02d.log",
dest_dir,
+ basename,
now->tm_year + 1900, now->tm_mon + 1, now->tm_mday,
- now->tm_hour, now->tm_min, now->tm_sec, basename);
+ now->tm_hour, now->tm_min, now->tm_sec);
g_free(basename);
g_free(dest_dir);
if (ud->job_activity_log)
g_free(path);
}
+static gint
+queue_pending_count(GValue *queue)
+{
+ gint nn, ii, count;
+ GValue *js;
+ gint status;
+
+ nn = 0;
+ count = ghb_array_len(queue);
+ for (ii = 0; ii < count; ii++)
+ {
+
+ js = ghb_array_get_nth(queue, ii);
+ status = ghb_settings_get_int(js, "job_status");
+ if (status == GHB_QUEUE_PENDING)
+ {
+ nn++;
+ }
+ }
+ return nn;
+}
+
+void
+ghb_update_pending(signal_user_data_t *ud)
+{
+ GtkLabel *label;
+ gint pending;
+ gchar *str;
+
+ label = GTK_LABEL(GHB_WIDGET(ud->builder, "pending_status"));
+ pending = queue_pending_count(ud->queue);
+ str = g_strdup_printf("%d encode(s) pending", pending);
+ gtk_label_set_text(label, str);
+ g_free(str);
+}
+
GValue*
ghb_start_next_job(signal_user_data_t *ud, gboolean find_first)
{
gint count, ii, jj;
GValue *js;
gint status;
+ GtkWidget *prog;
g_debug("start_next_job");
+ prog = GHB_WIDGET(ud->builder, "progressbar");
+ gtk_widget_show(prog);
+
count = ghb_array_len(ud->queue);
if (find_first)
{ // Start the first pending item in the queue
current = ii;
ghb_inhibit_gpm();
queue_scan(ud, js);
+ ghb_update_pending(ud);
return js;
}
}
current = jj;
ghb_inhibit_gpm();
queue_scan(ud, js);
+ ghb_update_pending(ud);
return js;
}
}
current = ii;
ghb_inhibit_gpm();
queue_scan(ud, js);
+ ghb_update_pending(ud);
return js;
}
}
// Nothing found
ghb_uninhibit_gpm();
ghb_notify_done(ud);
+ ghb_update_pending(ud);
+ gtk_widget_hide(prog);
return NULL;
}
*job = NULL;
g_debug("find_queue_job");
+ if (unique_id == 0) // Invalid Id
+ return -1;
+
count = ghb_array_len(queue);
for (ii = 0; ii < count; ii++)
{
gint qcount;
gint index;
GValue *js;
+ gboolean subtitle_scan = FALSE;
- if (status->job_count > 1)
- {
- task_str = g_strdup_printf("pass %d of %d, ",
- status->job_cur, status->job_count);
- }
- else
+ qcount = ghb_array_len(ud->queue);
+ index = find_queue_job(ud->queue, status->unique_id, &js);
+ if (js != NULL)
{
- task_str = g_strdup("");
+ subtitle_scan = ghb_settings_get_boolean(js, "subtitle_scan");
}
- qcount = ghb_array_len(ud->queue);
if (qcount > 1)
{
- index = find_queue_job(ud->queue, status->unique_id, &js);
job_str = g_strdup_printf("job %d of %d, ", index+1, qcount);
}
else
{
job_str = g_strdup("");
}
+ if (status->job_count > 1)
+ {
+ if (status->job_cur == 1 && subtitle_scan)
+ {
+ task_str = g_strdup_printf("pass %d (subtitle scan) of %d, ",
+ status->job_cur, status->job_count);
+ }
+ else
+ {
+ task_str = g_strdup_printf("pass %d of %d, ",
+ status->job_cur, status->job_count);
+ }
+ }
+ else
+ {
+ task_str = g_strdup("");
+ }
if(status->seconds > -1)
{
status_str= g_strdup_printf(
ghb_status_t status;
gchar *status_str;
GtkProgressBar *progress;
+ GtkLabel *work_status;
gint titleindex;
GValue *js;
gint index;
GtkTreeView *treeview;
GtkTreeStore *store;
GtkTreeIter iter;
- static gint working = 0;
- static gboolean work_started = FALSE;
+ static gint prev_scan_state = 0;
+ static gint prev_queue_state = 0;
ghb_track_status();
ghb_get_status(&status);
+ if (prev_scan_state != status.scan.state ||
+ prev_queue_state != status.queue.state)
+ {
+ ghb_queue_buttons_grey(ud);
+ prev_scan_state = status.scan.state;
+ prev_queue_state = status.queue.state;
+ }
progress = GTK_PROGRESS_BAR(GHB_WIDGET (ud->builder, "progressbar"));
+ work_status = GTK_LABEL(GHB_WIDGET (ud->builder, "work_status"));
if (status.scan.state == GHB_STATE_IDLE &&
status.queue.state == GHB_STATE_IDLE)
{
// Then handle the status of the queue
if (status.scan.state & GHB_STATE_SCANNING)
{
+ GtkProgressBar *scan_prog;
+ GtkLabel *label;
+
+ scan_prog = GTK_PROGRESS_BAR(GHB_WIDGET (ud->builder, "scan_prog"));
+ label = GTK_LABEL(GHB_WIDGET (ud->builder, "source_title"));
+
if (status.scan.title_cur == 0)
{
status_str = g_strdup ("Scanning...");
status_str = g_strdup_printf ("Scanning title %d of %d...",
status.scan.title_cur, status.scan.title_count );
}
- gtk_progress_bar_set_text (progress, status_str);
+ gtk_label_set_text (label, status_str);
g_free(status_str);
if (status.scan.title_count > 0)
{
- gtk_progress_bar_set_fraction (progress,
+ gtk_progress_bar_set_fraction (scan_prog,
(gdouble)status.scan.title_cur / status.scan.title_count);
}
}
else if (status.scan.state & GHB_STATE_SCANDONE)
{
- status_str = g_strdup_printf ("Scan done");
- gtk_progress_bar_set_text (progress, status_str);
- g_free(status_str);
- gtk_progress_bar_set_fraction (progress, 1.0);
+ gchar *source;
+ GtkProgressBar *scan_prog;
+ GtkLabel *label;
+
+ GtkWidget *widget;
+ GtkAction *action;
+
+ widget = GHB_WIDGET(ud->builder, "sourcetoolbutton");
+ gtk_widget_set_sensitive(widget, TRUE);
+ action = GHB_ACTION(ud->builder, "source_action");
+ gtk_action_set_sensitive(action, TRUE);
+ action = GHB_ACTION(ud->builder, "source_single_action");
+ gtk_action_set_sensitive(action, TRUE);
+
+ source = ghb_settings_get_string(ud->settings, "source");
+ update_source_label(ud, source, FALSE);
+
+ scan_prog = GTK_PROGRESS_BAR(GHB_WIDGET (ud->builder, "scan_prog"));
+ gtk_progress_bar_set_fraction (scan_prog, 1.0);
+ gtk_widget_hide(GTK_WIDGET(scan_prog));
ghb_title_info_t tinfo;
titleindex = ghb_longest_title();
ghb_ui_update(ud, "title", ghb_int64_value(titleindex));
+ label = GTK_LABEL(GHB_WIDGET (ud->builder, "source_title"));
// Are there really any titles.
if (!ghb_get_title_info(&tinfo, titleindex))
{
- GtkProgressBar *progress;
- progress = GTK_PROGRESS_BAR(GHB_WIDGET (ud->builder, "progressbar"));
- gtk_progress_bar_set_fraction (progress, 0);
- gtk_progress_bar_set_text (progress, "No Source");
+ gtk_label_set_text(label, "None");
}
ghb_clear_scan_state(GHB_STATE_SCANDONE);
- ghb_queue_buttons_grey(ud, work_started);
if (ghb_queue_edit_settings)
{
gint jstatus;
ghb_queue_edit_settings = NULL;
}
}
- else if (status.queue.state & GHB_STATE_SCANNING)
+
+ if (status.queue.state & GHB_STATE_SCANNING)
{
- status_str = g_strdup_printf ("Scanning ...");
- gtk_progress_bar_set_text (progress, status_str);
- g_free(status_str);
+ // This needs to be in scanning and working since scanning
+ // happens fast enough that it can be missed
+ gtk_label_set_text (work_status, "Scanning ...");
gtk_progress_bar_set_fraction (progress, 0);
}
else if (status.queue.state & GHB_STATE_SCANDONE)
ghb_clear_queue_state(GHB_STATE_SCANDONE);
usleep(2000000);
submit_job(ud->current_job);
+ ghb_update_pending(ud);
}
else if (status.queue.state & GHB_STATE_PAUSED)
{
- status_str = g_strdup_printf ("Paused");
- gtk_progress_bar_set_text (progress, status_str);
- g_free(status_str);
+ gtk_label_set_text (work_status, "Paused");
}
else if (status.queue.state & GHB_STATE_WORKING)
{
+ static gint working = 0;
+
+ // This needs to be in scanning and working since scanning
+ // happens fast enough that it can be missed
+ index = find_queue_job(ud->queue, status.queue.unique_id, &js);
+ if (status.queue.unique_id != 0 && index >= 0)
+ {
+ gchar working_icon[] = "hb-working0";
+ working_icon[10] = '0' + working;
+ working = (working+1) % 6;
+ treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
+ store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
+ gchar *path = g_strdup_printf ("%d", index);
+ if (gtk_tree_model_get_iter_from_string(
+ GTK_TREE_MODEL(store), &iter, path))
+ {
+ gtk_tree_store_set(store, &iter, 0, working_icon, -1);
+ }
+ g_free(path);
+ }
+ GtkLabel *label;
+ gchar *status_str;
+
status_str = working_status_string(ud, &status.queue);
- gtk_progress_bar_set_text (progress, status_str);
+ 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
+ gtk_label_set_text (work_status, status_str);
gtk_progress_bar_set_fraction (progress, status.queue.progress);
g_free(status_str);
}
{
gint qstatus;
- work_started = FALSE;
- ghb_queue_buttons_grey(ud, FALSE);
index = find_queue_job(ud->queue, status.queue.unique_id, &js);
treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
- if (ud->cancel_encode)
+ if (ud->cancel_encode == GHB_CANCEL_ALL ||
+ ud->cancel_encode == GHB_CANCEL_CURRENT)
status.queue.error = GHB_ERROR_CANCELED;
switch( status.queue.error )
{
case GHB_ERROR_NONE:
- gtk_progress_bar_set_text( progress, "Rip done!" );
+ gtk_label_set_text (work_status, "Rip Done!");
qstatus = GHB_QUEUE_DONE;
if (js != NULL)
{
}
break;
case GHB_ERROR_CANCELED:
- gtk_progress_bar_set_text( progress, "Rip canceled." );
+ gtk_label_set_text (work_status, "Rip Canceled.");
qstatus = GHB_QUEUE_CANCELED;
if (js != NULL)
{
}
break;
default:
- gtk_progress_bar_set_text( progress, "Rip failed.");
+ gtk_label_set_text (work_status, "Rip Failed.");
qstatus = GHB_QUEUE_CANCELED;
if (js != NULL)
{
if (ud->job_activity_log)
g_io_channel_unref(ud->job_activity_log);
ud->job_activity_log = NULL;
- if (!ud->cancel_encode)
+ if (ud->cancel_encode != GHB_CANCEL_ALL &&
+ ud->cancel_encode != GHB_CANCEL_FINISH)
{
ud->current_job = ghb_start_next_job(ud, FALSE);
}
{
ghb_uninhibit_gpm();
ud->current_job = NULL;
+ gtk_widget_hide(GTK_WIDGET(progress));
}
if (js)
ghb_settings_set_int(js, "job_status", qstatus);
ghb_save_queue(ud->queue);
- ud->cancel_encode = FALSE;
+ ud->cancel_encode = GHB_CANCEL_NONE;
+#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)
{
- gtk_progress_bar_set_text(progress, "Muxing: this may take awhile...");
+ gtk_label_set_text (work_status, "Muxing: This may take a while...");
}
- if (status.queue.state & GHB_STATE_SCANNING)
- {
- // This needs to be in scanning and working since scanning
- // happens fast enough that it can be missed
- if (!work_started)
- {
- work_started = TRUE;
- ghb_queue_buttons_grey(ud, TRUE);
- }
- }
- if (status.queue.state & GHB_STATE_WORKING)
- {
- // This needs to be in scanning and working since scanning
- // happens fast enough that it can be missed
- if (!work_started)
- {
- work_started = TRUE;
- ghb_queue_buttons_grey(ud, TRUE);
- }
- index = find_queue_job(ud->queue, status.queue.unique_id, &js);
- if (status.queue.unique_id != 0 && index >= 0)
- {
- gchar working_icon[] = "hb-working0";
- working_icon[10] = '0' + working;
- working = (working+1) % 6;
- treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
- store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
- gchar *path = g_strdup_printf ("%d", index);
- if (gtk_tree_model_get_iter_from_string(
- GTK_TREE_MODEL(store), &iter, path))
- {
- gtk_tree_store_set(store, &iter, 0, working_icon, -1);
- }
- g_free(path);
- }
- GtkLabel *label;
- gchar *status_str;
- status_str = working_status_string(ud, &status.queue);
- label = GTK_LABEL(GHB_WIDGET(ud->builder, "queue_status"));
- gtk_label_set_text (label, status_str);
- g_free(status_str);
- }
if (status.scan.state & GHB_STATE_WORKING)
{
GtkProgressBar *live_progress;
}
}
+#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;
}
ghb_log_cb(GIOChannel *source, GIOCondition cond, gpointer data)
{
gchar *text = NULL;
- gsize length;
+ gsize length, outlength;
GtkTextView *textview;
GtkTextBuffer *buffer;
GtkTextIter iter;
signal_user_data_t *ud = (signal_user_data_t*)data;
status = g_io_channel_read_line (source, &text, &length, NULL, &gerror);
- if (text != NULL)
+ // Trim nils from end of text, they cause g_io_channel_write_chars to
+ // fail with an assertion that aborts
+ while (length > 0 && text[length-1] == 0)
+ length--;
+ if (text != NULL && length > 0)
{
GdkWindow *window;
gint width, height;
text[length-1] = '\r';
#endif
g_io_channel_write_chars (ud->activity_log, text,
- length, &length, NULL);
+ length, &outlength, NULL);
#if defined(_WIN32)
g_io_channel_write_chars (ud->activity_log, "\n",
one, &one, NULL);
if (ud->job_activity_log)
{
g_io_channel_write_chars (ud->job_activity_log, text,
- length, &length, NULL);
+ length, &outlength, NULL);
#if defined(_WIN32)
g_io_channel_write_chars (ud->activity_log, "\n",
- one, &one, NULL);
+ one, &outlength, NULL);
#endif
g_io_channel_flush(ud->job_activity_log, NULL);
}
- g_free(text);
}
+ if (text != NULL)
+ g_free(text);
+
if (status != G_IO_STATUS_NORMAL)
{
// This should never happen, but if it does I would get into an
_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
+use_m4v_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
+{
+ g_debug("use_m4v_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);
+ ghb_update_destination_extension(ud);
+}
+
+G_MODULE_EXPORT void
+show_status_cb(GtkWidget *widget, signal_user_data_t *ud)
+{
+ g_debug("show_status_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);
+
+ GtkStatusIcon *si;
+
+ si = GTK_STATUS_ICON(GHB_OBJECT (ud->builder, "hb_status"));
+ gtk_status_icon_set_visible(si,
+ ghb_settings_get_boolean(ud->settings, "show_status"));
+}
+
+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);
LibHalDriveType dtype;
device = g_drive_get_identifier(gd, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
+ if (device == NULL)
+ return FALSE;
halDrive = libhal_drive_from_device_file (hal_ctx, device);
+ g_free(device);
+ if (halDrive == NULL)
+ return FALSE;
dtype = libhal_drive_get_type(halDrive);
libhal_drive_free(halDrive);
- g_free(device);
return (dtype == LIBHAL_DRIVE_TYPE_CDROM);
#else
return FALSE;
ins_count++;
if (ins_count == 2)
{
- ghb_file_menu_add_dvd(ud);
- if (ud->current_dvd_device != NULL &&
+ g_thread_create((GThreadFunc)ghb_cache_volnames, ud, FALSE, NULL);
+ if (ghb_settings_get_boolean(ud->settings, "AutoScan") &&
+ ud->current_dvd_device != NULL &&
strcmp(device, ud->current_dvd_device) == 0)
{
- GtkProgressBar *progress;
- progress = GTK_PROGRESS_BAR(GHB_WIDGET (ud->builder, "progressbar"));
- gtk_progress_bar_set_text (progress, "Scanning ...");
- gtk_progress_bar_set_fraction (progress, 0);
- update_source_label(ud, device);
+ show_scan_progress(ud);
+ update_source_label(ud, device, TRUE);
gint preview_count;
preview_count = ghb_settings_get_int(ud->settings, "preview_count");
- ghb_backend_scan(device, 0, preview_count);
+ start_scan(ud, device, 0, preview_count);
}
}
}
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)
{
ghb_hb_cleanup(TRUE);
prune_logs(ud);
- ghb_backend_scan("/dev/null", 0, 1);
+ ghb_settings_set_string(ud->settings, "source", "/dev/null");
+ start_scan(ud, "/dev/null", 0, 1);
}
}
}
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);
}
if (g_drive_has_media(gd))
{
- GtkProgressBar *progress;
- progress = GTK_PROGRESS_BAR(GHB_WIDGET (ud->builder, "progressbar"));
- gtk_progress_bar_set_text (progress, "Scanning ...");
- gtk_progress_bar_set_fraction (progress, 0);
- update_source_label(ud, device);
- gint preview_count;
- preview_count = ghb_settings_get_int(ud->settings, "preview_count");
- ghb_backend_scan(device, 0, preview_count);
+ if (ghb_settings_get_boolean(ud->settings, "AutoScan"))
+ {
+ show_scan_progress(ud);
+ update_source_label(ud, device, TRUE);
+ gint preview_count;
+ preview_count = ghb_settings_get_int(ud->settings, "preview_count");
+ start_scan(ud, device, 0, preview_count);
+ }
}
else
{
ghb_hb_cleanup(TRUE);
prune_logs(ud);
- ghb_backend_scan("/dev/null", 0, 1);
+ ghb_settings_set_string(ud->settings, "source", "/dev/null");
+ start_scan(ud, "/dev/null", 0, 1);
}
}
#endif
dbus_g_thread_init();
}
-#define GPM_DBUS_SERVICE "org.freedesktop.PowerManagement"
+#define GPM_DBUS_PM_SERVICE "org.freedesktop.PowerManagement"
+#define GPM_DBUS_PM_PATH "/org/freedesktop/PowerManagement"
+#define GPM_DBUS_PM_INTERFACE "org.freedesktop.PowerManagement"
#define GPM_DBUS_INHIBIT_PATH "/org/freedesktop/PowerManagement/Inhibit"
#define GPM_DBUS_INHIBIT_INTERFACE "org.freedesktop.PowerManagement.Inhibit"
static gboolean gpm_inhibited = FALSE;
static guint gpm_cookie = -1;
#endif
+static gboolean
+ghb_can_suspend_gpm()
+{
+ gboolean can_suspend = FALSE;
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+
+ g_debug("ghb_can_suspend_gpm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return FALSE;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
+ GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return FALSE;
+ }
+ res = dbus_g_proxy_call(proxy, "CanSuspend", &error,
+ G_TYPE_INVALID,
+ G_TYPE_BOOLEAN, &can_suspend,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_warning("CanSuspend failed: %s", error->message);
+ g_error_free(error);
+ }
+ else
+ g_warning("CanSuspend failed");
+ // Try to shutdown anyway
+ can_suspend = TRUE;
+ }
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+#endif
+ return can_suspend;
+}
+
+static void
+ghb_suspend_gpm()
+{
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+
+ g_debug("ghb_suspend_gpm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
+ GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return;
+ }
+ res = dbus_g_proxy_call(proxy, "Suspend", &error,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_warning("Suspend failed: %s", error->message);
+ g_error_free(error);
+ }
+ else
+ g_warning("Suspend failed");
+ }
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+#endif
+}
+
+static gboolean
+ghb_can_shutdown_gpm()
+{
+ gboolean can_shutdown = FALSE;
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+
+ g_debug("ghb_can_shutdown_gpm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return FALSE;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
+ GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return FALSE;
+ }
+ res = dbus_g_proxy_call(proxy, "CanShutdown", &error,
+ G_TYPE_INVALID,
+ G_TYPE_BOOLEAN, &can_shutdown,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_warning("CanShutdown failed: %s", error->message);
+ g_error_free(error);
+ }
+ else
+ g_warning("CanShutdown failed");
+ // Try to shutdown anyway
+ can_shutdown = TRUE;
+ }
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+#endif
+ return can_shutdown;
+}
+
+static void
+ghb_shutdown_gpm()
+{
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+
+ g_debug("ghb_shutdown_gpm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
+ GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return;
+ }
+ res = dbus_g_proxy_call(proxy, "Shutdown", &error,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_warning("Shutdown failed: %s", error->message);
+ g_error_free(error);
+ }
+ else
+ g_warning("Shutdown failed");
+ }
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+#endif
+}
+
void
ghb_inhibit_gpm()
{
g_error_free(error);
return;
}
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_SERVICE,
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
GPM_DBUS_INHIBIT_PATH, GPM_DBUS_INHIBIT_INTERFACE);
if (proxy == NULL)
{
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SERVICE);
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
dbus_g_connection_unref(conn);
return;
}
g_error_free(error);
return;
}
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_SERVICE,
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
GPM_DBUS_INHIBIT_PATH, GPM_DBUS_INHIBIT_INTERFACE);
if (proxy == NULL)
{
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SERVICE);
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
dbus_g_connection_unref(conn);
return;
}
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)
+ appcast_busy = TRUE;
+ regex = g_regex_new("^http://(.+)/(.+)$", 0, 0, NULL);
+ if (!g_regex_match(regex, HB_PROJECT_URL_APPCAST, 0, &mi))
{
- query =
- "GET /appcast_unstable.xml HTTP/1.0\r\nHost: handbrake.fr\r\n\r\n";
- }
- else
- {
- 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;
- 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);
+ query = g_strdup_printf( "GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n",
+ appcast, host);
+
+ 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;
}
+G_MODULE_EXPORT gboolean
+hb_visibility_event_cb(
+ GtkWidget *widget,
+ GdkEventVisibility *vs,
+ signal_user_data_t *ud)
+{
+ ud->hb_visibility = vs->state;
+ return FALSE;
+}
+
G_MODULE_EXPORT void
status_activate_cb(GtkStatusIcon *si, signal_user_data_t *ud)
{
GtkWindow *window;
+ GdkWindowState state;
window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window"));
- gtk_window_present(window);
+ state = gdk_window_get_state(GTK_WIDGET(window)->window);
+ if ((state & GDK_WINDOW_STATE_ICONIFIED) ||
+ (ud->hb_visibility != GDK_VISIBILITY_UNOBSCURED))
+ {
+ gtk_window_present(window);
+ gtk_window_set_skip_taskbar_hint(window, FALSE);
+ }
+ else
+ {
+ gtk_window_set_skip_taskbar_hint(window, TRUE);
+ gtk_window_iconify(window);
+ }
}
#if !defined(_WIN32)
{
GtkStatusIcon *si;
+ if (ghb_settings_combo_int(ud->settings, "WhenComplete") == 0)
+ return;
+
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;
g_signal_connect(notification, "closed", (GCallback)notify_closed_cb, ud);
notify_notification_show(notification, NULL);
#endif
+
+ if (ghb_settings_combo_int(ud->settings, "WhenComplete") == 3)
+ {
+ if (ghb_can_shutdown_gpm())
+ {
+ ghb_countdown_dialog(GTK_MESSAGE_WARNING,
+ "Your encode is complete.",
+ "Shutting down the computer",
+ "Cancel", (GSourceFunc)shutdown_cb, 60);
+ }
+ }
+ if (ghb_settings_combo_int(ud->settings, "WhenComplete") == 2)
+ {
+ if (ghb_can_suspend_gpm())
+ {
+ ghb_countdown_dialog(GTK_MESSAGE_WARNING,
+ "Your encode is complete.",
+ "Putting computer to sleep",
+ "Cancel", (GSourceFunc)suspend_cb, 60);
+ }
+ }
}