diff options
author | jstebbins <[email protected]> | 2009-06-26 17:18:51 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2009-06-26 17:18:51 +0000 |
commit | af876ffaa55ba8c063703a18c4e0329349362144 (patch) | |
tree | ce5e44b1344975916592a150b17370b84eb21f3e /gtk | |
parent | 1456b9deb100c144680b9658c7b54e0dffb07e90 (diff) |
LinGui: add preference option for what to do when encode is complete
- Options are nothing, notify, sleep, shutdown
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2629 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/src/callbacks.c | 315 | ||||
-rw-r--r-- | gtk/src/ghb.ui | 46 | ||||
-rw-r--r-- | gtk/src/hb-backend.c | 15 | ||||
-rw-r--r-- | gtk/src/internal_defaults.xml | 2 |
4 files changed, 370 insertions, 8 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c index ae30c9ab0..cc6ab7643 100644 --- a/gtk/src/callbacks.c +++ b/gtk/src/callbacks.c @@ -62,6 +62,10 @@ 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 @@ -1753,6 +1757,95 @@ prefs_dialog_cb(GtkWidget *xwidget, signal_user_data_t *ud) 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 (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) { @@ -3287,13 +3380,201 @@ dbus_init (void) 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() { @@ -3317,11 +3598,11 @@ 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; } @@ -3373,11 +3654,11 @@ ghb_uninhibit_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; } @@ -3846,6 +4127,9 @@ ghb_notify_done(signal_user_data_t *ud) { GtkStatusIcon *si; + if (ghb_settings_combo_int(ud->settings, "WhenComplete") == 0) + return; + si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status")); #if !defined(_WIN32) @@ -3859,4 +4143,25 @@ ghb_notify_done(signal_user_data_t *ud) 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); + } + } } diff --git a/gtk/src/ghb.ui b/gtk/src/ghb.ui index 2faec4d7d..ee3bfdd7d 100644 --- a/gtk/src/ghb.ui +++ b/gtk/src/ghb.ui @@ -3467,6 +3467,46 @@ no-dct-decimate=0:cabac=1</property> </packing> </child> <child> + <object class="GtkAlignment" id="alignment62"> + <property name="visible">True</property> + <property name="left_padding">12</property> + <property name="right_padding">12</property> + <property name="top_padding">6</property> + <property name="bottom_padding">6</property> + <child> + <object class="GtkHBox" id="hbox82"> + <property name="visible">True</property> + <property name="spacing">4</property> + <child> + <object class="GtkComboBox" id="WhenComplete"> + <property name="visible">True</property> + <signal name="changed" handler="pref_changed_cb"/> + </object> + <packing> + <property name="expand">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="labela1"> + <property name="visible">True</property> + <property name="label" translatable="yes">When all encodes are complete</property> + <property name="use_markup">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + <child> <object class="GtkAlignment" id="alignment5"> <property name="visible">True</property> <property name="left_padding">12</property> @@ -3555,7 +3595,7 @@ no-dct-decimate=0:cabac=1</property> </object> <packing> <property name="expand">False</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> <child> @@ -3600,7 +3640,7 @@ no-dct-decimate=0:cabac=1</property> </object> <packing> <property name="expand">False</property> - <property name="position">2</property> + <property name="position">3</property> </packing> </child> <child> @@ -3622,7 +3662,7 @@ no-dct-decimate=0:cabac=1</property> </object> <packing> <property name="expand">False</property> - <property name="position">3</property> + <property name="position">4</property> </packing> </child> </object> diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c index 94c5d5e8c..a015eb7a5 100644 --- a/gtk/src/hb-backend.c +++ b/gtk/src/hb-backend.c @@ -69,6 +69,19 @@ index_str_init(gint max_index) } } +static options_map_t d_when_complete_opts[] = +{ + {"Do Nothing", "nothing", 0, "0"}, + {"Show Notification", "notify", 1, "1"}, + {"Put Computer To Sleep", "sleep", 2, "2"}, + {"Shutdown Computer", "shutdown", 3, "3"}, +}; +combo_opts_t when_complete_opts = +{ + sizeof(d_when_complete_opts)/sizeof(options_map_t), + d_when_complete_opts +}; + static options_map_t d_par_opts[] = { {"Off", "0", 0, "0"}, @@ -331,6 +344,7 @@ typedef struct combo_name_map_t combo_name_map[] = { + {"WhenComplete", &when_complete_opts}, {"PicturePAR", &par_opts}, {"PictureModulus", &alignment_opts}, {"LoggingLevel", &logging_opts}, @@ -2232,6 +2246,7 @@ ghb_update_ui_combo_box( audio_track_opts_set(ud->builder, "AudioTrack", user_data); subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data); generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts); + generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts); generic_opts_set(ud->builder, "PicturePAR", &par_opts); generic_opts_set(ud->builder, "PictureModulus", &alignment_opts); generic_opts_set(ud->builder, "LoggingLevel", &logging_opts); diff --git a/gtk/src/internal_defaults.xml b/gtk/src/internal_defaults.xml index 6f1cde11b..fd8ac4119 100644 --- a/gtk/src/internal_defaults.xml +++ b/gtk/src/internal_defaults.xml @@ -167,6 +167,8 @@ <true /> <key>constant_rate_factor</key> <true /> + <key>WhenComplete</key> + <string>notify</string> </dict> <key>XlatPresets</key> <dict> |