diff options
author | John Stebbins <[email protected]> | 2018-07-10 12:36:48 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2018-07-10 12:37:47 -0700 |
commit | f2ce3838e9dbc1e6cffb3db875be723fd88cdbd3 (patch) | |
tree | 5b07639c282d173df9ac6c27bb4d5baf1b6a7d7b /gtk | |
parent | f6a000f1c97f4aa0e4fc6f7751dc5bedb8e3a0bf (diff) |
LinGui: simplify dest name selection
Removes cruft that wasn't realy used.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/src/callbacks.c | 192 | ||||
-rw-r--r-- | gtk/src/hb-backend.c | 162 | ||||
-rw-r--r-- | gtk/src/hb-backend.h | 1 |
3 files changed, 141 insertions, 214 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c index 97cf705b3..d496187ac 100644 --- a/gtk/src/callbacks.c +++ b/gtk/src/callbacks.c @@ -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); diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c index 9208db5a7..dc0d1f332 100644 --- a/gtk/src/hb-backend.c +++ b/gtk/src/hb-backend.c @@ -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; diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h index ed46f55b0..22b5c9629 100644 --- a/gtk/src/hb-backend.h +++ b/gtk/src/hb-backend.h @@ -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); |