]> granicus.if.org Git - handbrake/commitdiff
LinGui: simplify dest name selection
authorJohn Stebbins <jstebbins.hb@gmail.com>
Tue, 10 Jul 2018 19:36:48 +0000 (12:36 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Tue, 10 Jul 2018 19:37:47 +0000 (12:37 -0700)
Removes cruft that wasn't realy used.

gtk/src/callbacks.c
gtk/src/hb-backend.c
gtk/src/hb-backend.h

index 97cf705b3d0a828b64292cb5f7e39a624643201e..d496187ac0ba83e2c615942de51dce1f9644f76e 100644 (file)
@@ -798,7 +798,7 @@ quit_action_cb(GSimpleAction *action, GVariant *param, signal_user_data_t *ud)
     g_application_quit(G_APPLICATION(ud->app));
 }
 
-gboolean
+static gboolean
 uppers_and_unders(gchar *str)
 {
     if (str == NULL) return FALSE;
@@ -824,7 +824,7 @@ enum
     CAMEL_OTHER
 };
 
-void
+static void
 camel_convert(gchar *str)
 {
     gint state = CAMEL_OTHER;
@@ -1183,161 +1183,6 @@ set_destination(signal_user_data_t *ud)
         ghb_dict_get_value(ud->settings, "dest_file"));
 }
 
-static gchar*
-get_file_label(const gchar *filename)
-{
-    gchar *base, *pos, *end;
-
-    base = g_path_get_basename(filename);
-    pos = strrchr(base, '.');
-    if (pos != NULL)
-    {
-        // 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;
-    }
-    return base;
-}
-
-static gchar*
-resolve_drive_name(gchar *filename)
-{
-#if defined(_WIN32)
-    if (filename[1] == ':')
-    {
-        gchar drive[4];
-        gchar *name;
-        gint dtype;
-
-        g_strlcpy(drive, filename, 4);
-        dtype = GetDriveType(drive);
-        if (dtype == DRIVE_CDROM)
-        {
-            gchar vname[51], fsname[51];
-            GetVolumeInformation(drive, vname, 50, NULL,
-                                NULL, NULL, fsname, 50);
-            name = g_strdup(vname);
-            return name;
-        }
-    }
-    return NULL;
-#else
-    return NULL;
-#endif
-}
-
-static gboolean
-update_source_label(signal_user_data_t *ud, const gchar *source)
-{
-    GStatBuf stat_buf;
-    gchar *label = NULL;
-    gint len;
-    gchar **path;
-    gchar *start;
-    gchar *filename = g_strdup(source);
-
-    g_debug("update_source_label()");
-    if (g_stat(filename, &stat_buf) == 0)
-    {
-        len = strlen(filename);
-        if (S_ISDIR(stat_buf.st_mode))
-        {
-            // Skip dos drive letters
-#if defined(_WIN32)
-            start = strchr(filename, ':');
-#else
-            start = filename;
-#endif
-            label = resolve_drive_name(filename);
-            if (label != NULL)
-            {
-                if (uppers_and_unders(label))
-                {
-                    camel_convert(label);
-                }
-            }
-            else
-            {
-                if (filename[len-1] == G_DIR_SEPARATOR) filename[len-1] = 0;
-                if (start != NULL)
-                    start++;
-                else
-                    start = filename;
-
-                path = g_strsplit(start, G_DIR_SEPARATOR_S, -1);
-                len = g_strv_length (path);
-                if ((len > 1) && (strcmp("VIDEO_TS", path[len-1]) == 0))
-                {
-                    label = g_strdup(path[len-2]);
-                    if (uppers_and_unders(label))
-                    {
-                        camel_convert(label);
-                    }
-                }
-                else if (len > 0)
-                {
-                    if (path[len-1][0] != 0)
-                    {
-                        label = g_strdup(path[len-1]);
-                        if (uppers_and_unders(label))
-                        {
-                            camel_convert(label);
-                        }
-                    }
-                    else
-                        label = g_strdup("new_video");
-                }
-                else
-                    label = g_strdup("new_video");
-                g_strfreev (path);
-            }
-        }
-        else if (S_ISBLK(stat_buf.st_mode))
-        {
-            // Is regular file or block dev.
-            // Check to see if it is a dvd image
-            label = ghb_dvd_volname(filename);
-            if (label == NULL)
-            {
-                label = get_file_label(filename);
-            }
-            else
-            {
-                if (uppers_and_unders(label))
-                {
-                    camel_convert(label);
-                }
-            }
-        }
-        else
-        {
-            label = get_file_label(filename);
-        }
-    }
-    else
-    {
-        label = get_file_label(filename);
-    }
-    g_free(filename);
-    GtkWidget *widget = GHB_WIDGET (ud->builder, "source_label");
-    if (label != NULL)
-    {
-        gtk_label_set_text (GTK_LABEL(widget), label);
-        ghb_dict_set_string(ud->globals, "volume", label);
-        g_free(label);
-    }
-    else
-    {
-        label = _("No Title Found");
-        gtk_label_set_text (GTK_LABEL(widget), label);
-        ghb_dict_set_string(ud->globals, "volume", label);
-        return FALSE;
-    }
-    return TRUE;
-}
-
 G_MODULE_EXPORT void
 chooser_file_selected_cb(GtkFileChooser *dialog, signal_user_data_t *ud)
 {
@@ -1831,24 +1676,18 @@ ghb_do_scan(
     last_scan_file = NULL;
     if (filename != NULL)
     {
+        const gchar *path;
+        gint preview_count;
+
         last_scan_file = g_strdup(filename);
         ghb_dict_set_string(ud->globals, "scan_source", filename);
-        if (update_source_label(ud, filename))
-        {
-            const gchar *path;
-            gint preview_count;
 
-            show_scan_progress(ud);
-            path = ghb_dict_get_string(ud->globals, "scan_source");
-            prune_logs(ud);
+        show_scan_progress(ud);
+        path = ghb_dict_get_string(ud->globals, "scan_source");
+        prune_logs(ud);
 
-            preview_count = ghb_dict_get_int(ud->prefs, "preview_count");
-            start_scan(ud, path, title_id, preview_count);
-        }
-        else
-        {
-            // TODO: error dialog
-        }
+        preview_count = ghb_dict_get_int(ud->prefs, "preview_count");
+        start_scan(ud, path, title_id, preview_count);
     }
 }
 
@@ -4129,9 +3968,6 @@ ghb_backend_events(signal_user_data_t *ud)
     }
     else if (status.scan.state & GHB_STATE_SCANDONE)
     {
-        const gchar *source;
-        GtkLabel *label;
-
         GtkWidget *widget;
 
         widget = GHB_WIDGET(ud->builder, "sourcetoolbutton");
@@ -4144,9 +3980,6 @@ ghb_backend_events(signal_user_data_t *ud)
         widget = GHB_WIDGET(ud->builder, "source_title_open");
         gtk_widget_set_sensitive(widget, TRUE);
 
-        source = ghb_dict_get_string(ud->globals, "scan_source");
-        update_source_label(ud, source);
-
         hide_scan_progress(ud);
 
         int title_id, titleindex;
@@ -4156,13 +3989,10 @@ ghb_backend_events(signal_user_data_t *ud)
         ghb_update_ui_combo_box(ud, "title", NULL, FALSE);
         load_all_titles(ud, titleindex);
 
-        label = GTK_LABEL(GHB_WIDGET (ud->builder, "source_label"));
-
         ghb_clear_scan_state(GHB_STATE_SCANDONE);
         // Are there really any titles.
         if (title == NULL)
         {
-            gtk_label_set_text(label, _("No Title Found"));
             ghb_ui_update(ud, "title", ghb_string_value("none"));
         }
         else
@@ -5328,7 +5158,6 @@ handle_media_change(const gchar *device, gboolean insert, signal_user_data_t *ud
                 strcmp(device, ud->current_dvd_device) == 0)
             {
                 show_scan_progress(ud);
-                update_source_label(ud, device);
                 gint preview_count;
                 preview_count = ghb_dict_get_int(ud->prefs, "preview_count");
                 ghb_dict_set_string(ud->globals, "scan_source", device);
@@ -5433,7 +5262,6 @@ drive_changed_cb(GVolumeMonitor *gvm, GDrive *gd, signal_user_data_t *ud)
         if (ghb_dict_get_bool(ud->prefs, "AutoScan"))
         {
             show_scan_progress(ud);
-            update_source_label(ud, device);
             gint preview_count;
             preview_count = ghb_dict_get_int(ud->prefs, "preview_count");
             ghb_dict_set_string(ud->globals, "scan_source", device);
index 9208db5a7cb9645527176a52176f13d49c939ae5..dc0d1f3326b16d482ae4799dadead75ebf140ab7 100644 (file)
@@ -2049,6 +2049,31 @@ language_opts_set(signal_user_data_t *ud, const gchar *name,
     g_signal_connect(combo, "key-press-event", combo_search_key_press_cb, ud);
 }
 
+static void
+ghb_dvd_sanitize_volname(gchar *name)
+{
+    gchar *a, *b;
+
+    a = b = name;
+    while (*b)
+    {
+        switch(*b)
+        {
+        case '<':
+            b++;
+            break;
+        case '>':
+            b++;
+            break;
+        default:
+            *a = *b & 0x7f;
+            a++; b++;
+            break;
+        }
+    }
+    *a = 0;
+}
+
 gchar*
 ghb_create_source_label(const hb_title_t * title)
 {
@@ -2060,7 +2085,7 @@ ghb_create_source_label(const hb_title_t * title)
         volname = strdup(title->name);
         if (title->type == HB_DVD_TYPE)
         {
-            ghb_sanitize_volname(volname);
+            ghb_dvd_sanitize_volname(volname);
         }
         if (title->type == HB_BD_TYPE)
         {
@@ -2080,17 +2105,117 @@ ghb_create_source_label(const hb_title_t * title)
     return source;
 }
 
+static gboolean
+uppers_and_unders(gchar *str)
+{
+    if (str == NULL) return FALSE;
+    str = g_strchomp(g_strchug(str));
+    while (*str)
+    {
+        if (*str == ' ')
+        {
+            return FALSE;
+        }
+        if (*str >= 'a' && *str <= 'z')
+        {
+            return FALSE;
+        }
+        str++;
+    }
+    return TRUE;
+}
+
+enum
+{
+    CAMEL_FIRST_UPPER,
+    CAMEL_OTHER
+};
+
+static void
+camel_convert(gchar *str)
+{
+    gint state = CAMEL_OTHER;
+
+    if (str == NULL) return;
+    while (*str)
+    {
+        if (*str == '_') *str = ' ';
+        switch (state)
+        {
+            case CAMEL_OTHER:
+            {
+                if (*str >= 'A' && *str <= 'Z')
+                    state = CAMEL_FIRST_UPPER;
+                else
+                    state = CAMEL_OTHER;
+
+            } break;
+            case CAMEL_FIRST_UPPER:
+            {
+                if (*str >= 'A' && *str <= 'Z')
+                    *str = *str - 'A' + 'a';
+                else
+                    state = CAMEL_OTHER;
+            } break;
+        }
+        str++;
+    }
+}
+
+static gchar*
+get_file_label(const gchar *filename)
+{
+    gchar *base, *pos, *end;
+
+    base = g_path_get_basename(filename);
+    pos = strrchr(base, '.');
+    if (pos != NULL)
+    {
+        // 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;
+    }
+    return base;
+}
+
 gchar*
 ghb_create_volume_label(const hb_title_t * title)
 {
-    char * volname;
+    char * volname = NULL;
 
     if (title != NULL && title->name != NULL && title->name[0] != 0)
     {
-        volname = strdup(title->name);
-        if (title->type == HB_DVD_TYPE)
+        GStatBuf stat_buf;
+
+        if (g_stat(title->path, &stat_buf) == 0)
         {
-            ghb_sanitize_volname(volname);
+            if (!S_ISBLK(stat_buf.st_mode))
+            {
+                volname = get_file_label(title->path);
+            }
+            else
+            {
+                // DVD and BD volume labels are often all upper case
+                volname = strdup(title->name);
+                if (title->type == HB_DVD_TYPE)
+                {
+                    ghb_dvd_sanitize_volname(volname);
+                }
+                if (uppers_and_unders(volname))
+                {
+                    camel_convert(volname);
+                }
+            }
+        }
+        if (volname == NULL)
+        {
+            volname = strdup(title->name);
+            if (title->type == HB_DVD_TYPE)
+            {
+                ghb_dvd_sanitize_volname(volname);
+            }
         }
     }
     else
@@ -4780,31 +4905,6 @@ ghb_get_preview_image(
     return preview;
 }
 
-void
-ghb_sanitize_volname(gchar *name)
-{
-    gchar *a, *b;
-
-    a = b = name;
-    while (*b)
-    {
-        switch(*b)
-        {
-        case '<':
-            b++;
-            break;
-        case '>':
-            b++;
-            break;
-        default:
-            *a = *b & 0x7f;
-            a++; b++;
-            break;
-        }
-    }
-    *a = 0;
-}
-
 gchar*
 ghb_dvd_volname(const gchar *device)
 {
@@ -4813,7 +4913,7 @@ ghb_dvd_volname(const gchar *device)
     if (name != NULL && name[0] != 0)
     {
         name = g_strdup(name);
-        ghb_sanitize_volname(name);
+        ghb_dvd_sanitize_volname(name);
         return name;
     }
     return NULL;
index ed46f55b0bec28cb2cabb981aa57001f095d9fff..22b5c9629a41e5a373bf545ce240ad8b2c765fa6 100644 (file)
@@ -230,7 +230,6 @@ char * ghb_get_display_aspect_string(double disp_width, double disp_height);
 hb_handle_t* ghb_scan_handle(void);
 hb_handle_t* ghb_queue_handle(void);
 hb_handle_t* ghb_live_handle(void);
-void ghb_sanitize_volname(gchar *name);
 gchar* ghb_create_title_label(const hb_title_t *title);
 gchar* ghb_create_source_label(const hb_title_t * title);
 gchar* ghb_create_volume_label(const hb_title_t * title);