/*
* about:profiles
*
* Copyright (C) 2017 Patrick McDermott
*
* This file is part of Marquee.
*
* Marquee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Marquee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Marquee. If not, see .
*/
#include
#include
#include "../../application.h"
#include "../../config/profiles.h"
#include "../../utils/html.h"
#include "../../utils/profile-icon.h"
#include "../about.h"
#include "paths.h"
static gchar *
generate_div(MqProfiles *profiles, gchar *id)
{
gchar *name;
gchar *editing_str;
gchar *name_str;
gchar *default_str;
gchar *delete_str;
gchar *save_str;
gchar *div;
/* Freed by mq_html_container(). */
name = mq_profiles_get_name(profiles, id);
editing_str = g_strdup_printf("editing_%s", id);
name_str = g_strdup_printf("name_%s", id);
default_str = g_strdup_printf("default_%s", id);
delete_str = g_strdup_printf("delete_%s", id);
save_str = g_strdup_printf("save_%s", id);
div = mq_html_container("div", "profile",
mq_html_input_radio("editing", editing_str, id, NULL, FALSE),
mq_profile_icon_new(mq_profiles_get_color(profiles, id)),
mq_html_container("span", NULL, name, NULL),
mq_html_input_text(name_str, NULL, name),
mq_html_submit(default_str, "Make Default",
mq_profiles_is_default(profiles, id)),
mq_html_submit(delete_str, "Delete", FALSE),
mq_html_label(editing_str, "Edit", FALSE),
mq_html_submit(save_str, "Save", FALSE),
NULL);
g_free(editing_str);
g_free(name_str);
g_free(default_str);
g_free(delete_str);
g_free(save_str);
return div;
}
void
mq_about_profiles_response(MqApplication *application,
GHashTable G_GNUC_UNUSED *query,
WebKitURISchemeRequest *request)
{
MqProfiles *profiles;
gchar *document;
gchar **ids;
gsize length;
gchar **divs;
gsize i;
profiles = mq_application_get_profiles(application);
ids = mq_profiles_get_profiles(profiles, &length);
divs = g_new(gchar *, length);
for (i = 0; i < length; ++i) {
divs[i] = generate_div(profiles, ids[i]);
}
divs[i] = NULL;
document = mq_html_document("Profiles",
mq_html_form_v("Add Profile", NULL, divs),
NULL);
mq_about_response(request, document);
}