void playqueue_display(gint argc, gchar **argv)
{
	gint i, ii, position, frames, length, total;
	gchar *songname;
	gchar *fmt = NULL, *p;
	gint column;

	i = mlplayer_remote_get_playqueue_length(dbus_proxy);

	mlptool_report("%d queued tracks.", i);

	total = 0;

	for (ii = 0; ii < i; ii++)
	{
		position = mlplayer_remote_get_playqueue_list_position(dbus_proxy, ii);
		songname = mlplayer_remote_get_playlist_title(dbus_proxy, position);
		frames = mlplayer_remote_get_playlist_time(dbus_proxy, position);
		length = frames / 1000;
		total += length;

		/* adjust width for multi byte characters */
		column = 60;
		if(songname) {
			p = songname;
			while(*p){
				gint stride;
				stride = g_utf8_next_char(p) - p;
				if(g_unichar_iswide(g_utf8_get_char(p))
				   || g_unichar_iswide_cjk(g_utf8_get_char(p))
				){
					column += (stride - 2);
				}
				else {
					column += (stride - 1);
				}
				p = g_utf8_next_char(p);
			}
		}

		fmt = g_strdup_printf("%%4d | %%4d | %%-%ds | %%d:%%.2d", column);
		mlptool_report(fmt, ii + 1, position + 1, songname, length / 60, length % 60);
		g_free(fmt);
	}

	mlptool_report("Total length: %d:%.2d", total / 60, total % 60);
}
Esempio n. 2
0
static guint
utf8_n_spaces (const gchar *string)
{
    guint n = 0;

    for (; string[0]; string = g_utf8_next_char(string)) {
        if (g_unichar_iswide_cjk(g_utf8_get_char(string))) {
            n += 2;
        } else if (string[0] == '\t') {
            n += 8;
        } else {
            n++;
        }
    }

    return n;
}
Esempio n. 3
0
void playlist_display (int argc, char * * argv)
{
    int entries = get_playlist_length ();

    fauxdtool_report ("%d track%s.", entries, entries != 1 ? "s" : "");

    int total = 0;

    for (int entry = 0; entry < entries; entry ++)
    {
        char * title = get_entry_title (entry);
        int length = get_entry_length (entry) / 1000;

        total += length;

        /* adjust width for multi byte characters */
        int column = 60;

        for (const char * p = title; * p; p = g_utf8_next_char (p))
        {
            int stride = g_utf8_next_char (p) - p;

            if (g_unichar_iswide (g_utf8_get_char (p)) ||
             g_unichar_iswide_cjk (g_utf8_get_char (p)))
                column += (stride - 2);
            else
                column += (stride - 1);
        }

        char * fmt = g_strdup_printf ("%%4d | %%-%ds | %%d:%%.2d", column);
        fauxdtool_report (fmt, entry + 1, title, length / 60, length % 60);

        g_free (fmt);
        g_free (title);
    }

    fauxdtool_report ("Total length: %d:%.2d", total / 60, total % 60);
}
Esempio n. 4
0
void playqueue_display (int argc, char * * argv)
{
    int qlength = get_queue_length ();

    audtool_report ("%d queued tracks.", qlength);

    int total = 0;

    for (int qpos = 0; qpos < qlength; qpos ++)
    {
        int pos = get_queue_entry (qpos);
        char * title = get_entry_title (pos);
        int length = get_entry_length (pos) / 1000;

        total += length;

        /* adjust width for multi byte characters */
        int column = 60;

        for (const char * p = title; * p; p = g_utf8_next_char (p))
        {
            int stride = g_utf8_next_char (p) - p;

            if (g_unichar_iswide (g_utf8_get_char (p)) ||
             g_unichar_iswide_cjk (g_utf8_get_char (p)))
                column += (stride - 2);
            else
                column += (stride - 1);
        }

        char * fmt = g_strdup_printf ("%%4d | %%4d | %%-%ds | %%d:%%.2d", column);
        audtool_report (fmt, qpos + 1, pos + 1, title, length / 60, length % 60);
        g_free (fmt);
    }

    audtool_report ("Total length: %d:%.2d", total / 60, total % 60);
}
Esempio n. 5
0
void
cut_diff_writer_write_spaces (CutDiffWriter *writer,
                              const gchar *string, guint begin, guint end,
                              CutDiffWriterTag tag)
{
    GString *buffer;
    const gchar *last;

    buffer = g_string_new(NULL);
    last = g_utf8_offset_to_pointer(string, end);
    for (string = g_utf8_offset_to_pointer(string, begin);
         string < last;
         string = g_utf8_next_char(string)) {
        if (g_unichar_iswide_cjk(g_utf8_get_char(string))) {
            g_string_append(buffer, "  ");
        } else if (string[0] == '\t') {
            g_string_append_c(buffer, '\t');
        } else {
            g_string_append_c(buffer, ' ');
        }
    }
    cut_diff_writer_write(writer, buffer->str, tag);
    g_string_free(buffer, TRUE);
}