summaryrefslogtreecommitdiffstats
path: root/gtk/src/hb-backend.c
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2018-07-10 12:36:48 -0700
committerJohn Stebbins <[email protected]>2018-07-10 12:37:47 -0700
commitf2ce3838e9dbc1e6cffb3db875be723fd88cdbd3 (patch)
tree5b07639c282d173df9ac6c27bb4d5baf1b6a7d7b /gtk/src/hb-backend.c
parentf6a000f1c97f4aa0e4fc6f7751dc5bedb8e3a0bf (diff)
LinGui: simplify dest name selection
Removes cruft that wasn't realy used.
Diffstat (limited to 'gtk/src/hb-backend.c')
-rw-r--r--gtk/src/hb-backend.c162
1 files changed, 131 insertions, 31 deletions
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;