OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / gtk / src / callbacks.c
index 9f89ba9..c29d4a8 100644 (file)
 
 #if !defined(_WIN32)
 #include <poll.h>
-#include <libhal-storage.h>
+#define G_UDEV_API_IS_SUBJECT_TO_CHANGE 1
+#include <gudev/gudev.h>
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
 #include <netinet/in.h>
 #include <netdb.h>
+
+#if !defined(_NO_UPDATE_CHECK)
 #if defined(_OLD_WEBKIT)
 #include <webkit.h>
 #else
 #include <webkit/webkit.h>
 #endif
+#endif
+
 #include <libnotify/notify.h>
 #include <gdk/gdkx.h>
 #else
@@ -763,6 +768,8 @@ chooser_file_selected_cb(GtkFileChooser *dialog, signal_user_data_t *ud)
        gboolean foundit = FALSE;
        GtkComboBox *combo;
        
+       g_debug("chooser_file_selected_cb ()");
+
        if (name == NULL) return;
        combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, "source_device"));
        store = gtk_combo_box_get_model(combo);
@@ -792,6 +799,7 @@ dvd_device_changed_cb(GtkComboBox *combo, signal_user_data_t *ud)
        GtkWidget *dialog;
        gint ii;
 
+       g_debug("dvd_device_changed_cb ()");
        ii = gtk_combo_box_get_active (combo);
        if (ii > 0)
        {
@@ -808,52 +816,17 @@ dvd_device_changed_cb(GtkComboBox *combo, signal_user_data_t *ud)
        }
 }
 
-G_MODULE_EXPORT void
-source_type_changed_cb(GtkToggleButton *toggle, signal_user_data_t *ud)
-{
-       gchar *folder;
-       GtkFileChooser *chooser;
-       GtkWidget *dvd_device_combo;
-       
-       g_debug("source_type_changed_cb ()");
-       chooser = GTK_FILE_CHOOSER(GHB_WIDGET(ud->builder, "source_dialog"));
-       dvd_device_combo = GHB_WIDGET(ud->builder, "source_device");
-       folder = gtk_file_chooser_get_current_folder (chooser);
-       if (gtk_toggle_button_get_active (toggle))
-       {
-               gtk_file_chooser_set_action (chooser, 
-                                                                       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
-               gtk_widget_set_sensitive (dvd_device_combo, FALSE);
-               gtk_combo_box_set_active (GTK_COMBO_BOX(dvd_device_combo), 0);
-       }
-       else
-       {
-               gtk_file_chooser_set_action (chooser, GTK_FILE_CHOOSER_ACTION_OPEN);
-               gtk_widget_set_sensitive (dvd_device_combo, TRUE);
-       }
-       if (folder != NULL)
-       {
-               gtk_file_chooser_set_current_folder(chooser, folder);
-               g_free(folder);
-       }
-}
-
 static void
 source_dialog_extra_widgets(
        signal_user_data_t *ud,
-       GtkWidget *dialog, 
-       gboolean checkbutton_active)
+       GtkWidget *dialog)
 {
-       GtkToggleButton *checkbutton;
        GtkComboBox *combo;
        GList *drives, *link;
        
-       checkbutton = GTK_TOGGLE_BUTTON(
-               GHB_WIDGET(ud->builder, "source_folder_flag"));
-       gtk_toggle_button_set_active(checkbutton, checkbutton_active);
+       g_debug("source_dialog_extra_widgets ()");
        combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, "source_device"));
-       gtk_list_store_clear(GTK_LIST_STORE(
-                                               gtk_combo_box_get_model(combo)));
+       gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(combo)));
 
        link = drives = dvd_device_list();
        gtk_combo_box_append_text (combo, "Not Selected");
@@ -866,6 +839,7 @@ source_dialog_extra_widgets(
                link = link->next;
        }
        g_list_free(drives);
+       gtk_combo_box_set_active (combo, 0);
 }
 
 extern GValue *ghb_queue_edit_settings;
@@ -910,7 +884,8 @@ start_scan(
        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);
+       ghb_backend_scan(path, titlenum, preview_count, 
+                       90000L * ghb_settings_get_int64(ud->settings, "MinTitleDuration"));
 }
 
 void
@@ -962,41 +937,15 @@ ghb_do_scan(
        }
 }
 
-static gboolean 
-update_source_name(gpointer data)
-{
-       signal_user_data_t *ud = (signal_user_data_t*)data;
-       GtkWidget *dialog;
-       gchar *sourcename;
-
-       sourcename = ghb_settings_get_string(ud->settings, "scan_source");
-       dialog = GHB_WIDGET(ud->builder, "source_dialog");
-       gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), sourcename);
-       g_free(sourcename);
-       return FALSE;
-}
-
 static void
 do_source_dialog(GtkButton *button, gboolean single, signal_user_data_t *ud)
 {
        GtkWidget *dialog;
        gchar *sourcename;
        gint    response;
-       GtkFileChooserAction action;
-       gboolean checkbutton_active;
 
        g_debug("source_browse_clicked_cb ()");
        sourcename = ghb_settings_get_string(ud->settings, "scan_source");
-       checkbutton_active = FALSE;
-       if (g_file_test(sourcename, G_FILE_TEST_IS_DIR))
-       {
-               action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
-               checkbutton_active = TRUE;
-       }
-       else
-       {
-               action = GTK_FILE_CHOOSER_ACTION_OPEN;
-       }
        GtkWidget *widget;
        widget = GHB_WIDGET(ud->builder, "single_title_box");
        if (single)
@@ -1004,16 +953,11 @@ do_source_dialog(GtkButton *button, gboolean single, signal_user_data_t *ud)
        else
                gtk_widget_hide(widget);
        dialog = GHB_WIDGET(ud->builder, "source_dialog");
-       source_dialog_extra_widgets(ud, dialog, checkbutton_active);
-       gtk_file_chooser_set_action(GTK_FILE_CHOOSER(dialog), action);
-       // Updating the filename in the file chooser dialog doesn't seem
-       // to work unless the dialog is running for some reason.
-       // So handle it in an "idle" event.
-       //gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), sourcename);
-       g_idle_add((GSourceFunc)update_source_name, ud);
+       source_dialog_extra_widgets(ud, dialog);
+       gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), sourcename);
        response = gtk_dialog_run(GTK_DIALOG (dialog));
        gtk_widget_hide(dialog);
-       if (response == GTK_RESPONSE_ACCEPT)
+       if (response == GTK_RESPONSE_NO)
        {
                gchar *filename;
 
@@ -1403,6 +1347,7 @@ show_title_info(signal_user_data_t *ud, ghb_title_info_t *tinfo)
                }
        }
        ud->dont_clear_presets = TRUE;
+       ud->scale_busy = TRUE;
        update_title_duration(ud);
        widget = GHB_WIDGET (ud->builder, "source_dimensions");
        text = g_strdup_printf ("%d x %d", tinfo->width, tinfo->height);
@@ -1453,7 +1398,8 @@ show_title_info(signal_user_data_t *ud, ghb_title_info_t *tinfo)
                ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
                ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
        }
-       ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
+       ud->scale_busy = FALSE;
+       ghb_set_scale (ud, GHB_PIC_KEEP_PAR|GHB_PIC_USE_MAX);
        gint width, height, crop[4];
        crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
        crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
@@ -2971,6 +2917,7 @@ ghb_timer_cb(gpointer data)
                update_preview = FALSE;
        }
 
+#if !defined(_NO_UPDATE_CHECK)
        if (!appcast_busy)
        {
                gchar *updates;
@@ -3001,6 +2948,7 @@ ghb_timer_cb(gpointer data)
                        }
                }
        }
+#endif
        return TRUE;
 }
 
@@ -3170,6 +3118,10 @@ ghb_log(gchar *log, ...)
 static void
 browse_url(const gchar *url)
 {
+#if defined(_WIN32)
+       HINSTANCE r;
+       r = ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
+#else
        gboolean result;
        char *argv[] = 
                {"xdg-open",NULL,NULL,NULL};
@@ -3195,6 +3147,7 @@ browse_url(const gchar *url)
        argv[2] = NULL;
        result = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
                                NULL, NULL, NULL);
+#endif
 }
 
 void
@@ -3785,7 +3738,7 @@ dvd_device_list()
 }
 
 #if !defined(_WIN32)
-static LibHalContext *hal_ctx = NULL;
+static GUdevClient *udev_ctx = NULL;
 #endif
 
 gboolean
@@ -3793,27 +3746,43 @@ ghb_is_cd(GDrive *gd)
 {
 #if !defined(_WIN32)
        gchar *device;
-       LibHalDrive *halDrive;
-       LibHalDriveType dtype;
+       GUdevDevice *udd;
 
-       if (hal_ctx == NULL)
+       if (udev_ctx == NULL)
                return FALSE;
 
        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);
+
+       udd = g_udev_client_query_by_device_file(udev_ctx, device);
        g_free(device);
-       if (halDrive == NULL)
+
+       if (udd == NULL)
+       {
+               g_message("udev: Failed to lookup device %s", device);
                return FALSE;
-       dtype = libhal_drive_get_type(halDrive);
-       libhal_drive_free(halDrive);
-       return (dtype == LIBHAL_DRIVE_TYPE_CDROM);
+       }
+
+       gint val;
+       val = g_udev_device_get_property_as_int(udd, "ID_CDROM_DVD");
+       if (val == 1)
+               return TRUE;
+
+       return FALSE;
 #else
        return FALSE;
 #endif
 }
 
+void
+ghb_udev_init()
+{
+#if !defined(_WIN32)
+       udev_ctx = g_udev_client_new(NULL);
+#endif
+}
+
 #if defined(_WIN32)
 static void
 handle_media_change(const gchar *device, gboolean insert, signal_user_data_t *ud)
@@ -3962,12 +3931,6 @@ drive_changed_cb(GVolumeMonitor *gvm, GDrive *gd, signal_user_data_t *ud)
 #endif
 
 #if !defined(_WIN32)
-static void
-dbus_init (void)
-{
-       dbus_g_thread_init();
-}
-
 #define GPM_DBUS_PM_SERVICE                    "org.freedesktop.PowerManagement"
 #define GPM_DBUS_PM_PATH                       "/org/freedesktop/PowerManagement"
 #define GPM_DBUS_PM_INTERFACE          "org.freedesktop.PowerManagement"
@@ -4070,11 +4033,11 @@ ghb_suspend_gpm()
 #endif
 }
 
+#if !defined(_WIN32)
 static gboolean
 ghb_can_shutdown_gpm()
 {
        gboolean can_shutdown = FALSE;
-#if !defined(_WIN32)
        DBusGConnection *conn;
        DBusGProxy      *proxy;
        GError *error = NULL;
@@ -4115,14 +4078,14 @@ ghb_can_shutdown_gpm()
        }
        g_object_unref(G_OBJECT(proxy));
        dbus_g_connection_unref(conn);
-#endif
        return can_shutdown;
 }
+#endif
 
+#if !defined(_WIN32)
 static void
 ghb_shutdown_gpm()
 {
-#if !defined(_WIN32)
        DBusGConnection *conn;
        DBusGProxy      *proxy;
        GError *error = NULL;
@@ -4160,8 +4123,8 @@ ghb_shutdown_gpm()
        }
        g_object_unref(G_OBJECT(proxy));
        dbus_g_connection_unref(conn);
-#endif
 }
+#endif
 
 void
 ghb_inhibit_gpm()
@@ -4480,65 +4443,6 @@ ghb_uninhibit_gsm()
 #endif
 }
 
-void
-ghb_hal_init()
-{
-#if !defined(_WIN32)
-       DBusGConnection *gconn;
-       DBusConnection *conn;
-       GError *gerror = NULL;
-       DBusError error;
-       char **devices;
-       int nr;
-
-       dbus_init ();
-
-       if (!(hal_ctx = libhal_ctx_new ())) {
-               g_warning ("failed to create a HAL context!");
-               return;
-       }
-
-       gconn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &gerror);
-       if (gerror != NULL)
-       {
-               g_warning("DBUS cannot connect: %s", gerror->message);
-               g_error_free(gerror);
-               return;
-       }
-       conn = dbus_g_connection_get_connection(gconn);
-       libhal_ctx_set_dbus_connection (hal_ctx, conn);
-       dbus_error_init (&error);
-       if (!libhal_ctx_init (hal_ctx, &error)) {
-               g_warning ("libhal_ctx_init failed: %s", error.message ? error.message : "unknown");
-               dbus_error_free (&error);
-               libhal_ctx_free (hal_ctx);
-               dbus_g_connection_unref(gconn);
-               hal_ctx = NULL;
-               return;
-       }
-
-       /*
-        * Do something to ping the HAL daemon - the above functions will
-        * succeed even if hald is not running, so long as DBUS is.  But we
-        * want to exit silently if hald is not running, to behave on
-        * pre-2.6 systems.
-        */
-       if (!(devices = libhal_get_all_devices (hal_ctx, &nr, &error))) {
-               g_warning ("seems that HAL is not running: %s", error.message ? error.message : "unknown");
-               dbus_error_free (&error);
-
-               libhal_ctx_shutdown (hal_ctx, NULL);
-               libhal_ctx_free (hal_ctx);
-               hal_ctx = NULL;
-               dbus_g_connection_unref(gconn);
-               return;
-       }
-
-       libhal_free_string_array (devices);
-       dbus_g_connection_unref(gconn);
-#endif
-}
-
 G_MODULE_EXPORT gboolean 
 tweak_setting_cb(
        GtkWidget *widget, 
@@ -4712,6 +4616,7 @@ process_appcast(signal_user_data_t *ud)
        gtk_label_set_text(GTK_LABEL(label), msg);
 
 #if !defined(_WIN32)
+#if !defined(_NO_UPDATE_CHECK)
        if (html == NULL)
        {
                html = webkit_web_view_new();
@@ -4723,6 +4628,7 @@ process_appcast(signal_user_data_t *ud)
        }
        webkit_web_view_open(WEBKIT_WEB_VIEW(html), description);
 #endif
+#endif
        dialog = GHB_WIDGET(ud->builder, "update_dialog");
        response = gtk_dialog_run(GTK_DIALOG(dialog));
        gtk_widget_hide(dialog);
@@ -4778,7 +4684,10 @@ ghb_net_recv_cb(GIOChannel *ioc, GIOCondition cond, gpointer data)
        }
        if (status == G_IO_STATUS_EOF)
        {
-               ud->appcast[ud->appcast_len] = 0;
+               if ( ud->appcast != NULL )
+               {
+                       ud->appcast[ud->appcast_len] = 0;
+               }
                ghb_net_close(ioc);
                process_appcast(ud);
                return FALSE;