Commit 454ee305 authored by Victor Ananjevsky's avatar Victor Ananjevsky

initial implementation of custom about dialog

parent 06d526a0
......@@ -19,26 +19,83 @@
#include "yad.h"
static void
yad_set_about_license (GtkWidget *dlg)
{
if (options.about_data.license == NULL)
{
gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG (dlg), GTK_LICENSE_UNKNOWN);
return;
}
gtk_about_dialog_set_wrap_license (GTK_ABOUT_DIALOG (dlg), TRUE);
/* check for predefined */
if (strncmp (options.about_data.license, "GPL2", 4) == 0)
{
gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG (dlg), GTK_LICENSE_GPL_2_0);
return;
}
if (strncmp (options.about_data.license, "GPL3", 4) == 0)
{
gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG (dlg), GTK_LICENSE_GPL_3_0);
return;
}
if (strncmp (options.about_data.license, "LGPL2", 5) == 0)
{
gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG (dlg), GTK_LICENSE_LGPL_2_1);
return;
}
if (strncmp (options.about_data.license, "LGPL3", 5) == 0)
{
gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG (dlg), GTK_LICENSE_LGPL_3_0);
return;
}
if (strncmp (options.about_data.license, "BSD", 3) == 0)
{
gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG (dlg), GTK_LICENSE_BSD);
return;
}
if (strncmp (options.about_data.license, "MIT", 3) == 0)
{
gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG (dlg), GTK_LICENSE_MIT_X11);
return;
}
if (strncmp (options.about_data.license, "ARTISTIC", 8) == 0)
{
gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG (dlg), GTK_LICENSE_ARTISTIC);
return;
}
/* user specified */
gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG (dlg), GTK_LICENSE_CUSTOM);
if (g_file_test (options.about_data.license, G_FILE_TEST_EXISTS))
{
gchar *buf;
if (g_file_get_contents (options.about_data.license, &buf, NULL, NULL))
{
gtk_about_dialog_set_license (GTK_ABOUT_DIALOG (dlg), buf);
return;
}
}
/* set as is */
gtk_about_dialog_set_license (GTK_ABOUT_DIALOG (dlg), options.about_data.license);
return;
}
gint
yad_about (void)
{
GtkWidget *dialog;
const gchar *const authors[] = {
"Victor Ananjevsky <ananasik@gmail.com>",
NULL
};
const gchar *translators = N_("translator-credits");
const gchar *license =
N_("YAD 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.\n\n"
"YAD 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.\n\n"
"You should have received a copy of the GNU General Public License "
"along with YAD. If not, see <http://www.gnu.org/licenses/>.");
gchar *comments = g_strdup_printf (_("Yet Another Dialog\n"
"(show dialog boxes from shell scripts)\n"
......@@ -56,19 +113,41 @@ yad_about (void)
gtk_major_version, gtk_minor_version, gtk_micro_version);
dialog = gtk_about_dialog_new ();
gtk_window_set_icon_name (GTK_WINDOW (dialog), "yad");
g_object_set (G_OBJECT (dialog),
"name", PACKAGE_NAME,
"version", PACKAGE_VERSION,
"copyright", "Copyright \xc2\xa9 2008-2021, Victor Ananjevsky <ananasik@gmail.com>",
"comments", comments,
"authors", authors,
"website", PACKAGE_URL,
"translator-credits", translators,
"wrap-license", TRUE,
"license", license,
"logo-icon-name", "yad",
NULL);
if (options.about_data.name != NULL)
{
/* custom about dialog */
gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG (dialog), options.about_data.name);
if (options.about_data.version)
gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (dialog), options.about_data.version);
if (options.about_data.copyright)
gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG (dialog), options.about_data.copyright);
if (options.about_data.comments)
gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG (dialog), options.about_data.comments);
if (options.about_data.authors)
gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (dialog), (const gchar **) g_strsplit (options.about_data.authors, ",", -1));
if (options.about_data.website)
gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (dialog), options.about_data.website);
if (options.about_data.website_lbl)
gtk_about_dialog_set_website_label (GTK_ABOUT_DIALOG (dialog), options.about_data.website_lbl);
yad_set_about_license (dialog);
}
else
{
gtk_window_set_icon_name (GTK_WINDOW (dialog), "yad");
g_object_set (G_OBJECT (dialog),
"name", PACKAGE_NAME,
"version", PACKAGE_VERSION,
"copyright", "Copyright \xc2\xa9 2008-2021, Victor Ananjevsky <ananasik@gmail.com>",
"comments", comments,
"authors", authors,
"website", PACKAGE_URL,
"translator-credits", translators,
"wrap-license", TRUE,
"license-type", GTK_LICENSE_GPL_3_0,
"logo-icon-name", "yad",
NULL);
}
return gtk_dialog_run (GTK_DIALOG (dialog));
}
......@@ -239,6 +239,28 @@ static GOptionEntry common_options[] = {
{ NULL }
};
static GOptionEntry about_options[] = {
{ "about", 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &about_mode,
N_("Display about dialog"), NULL },
{ "pname", 0, 0, G_OPTION_ARG_STRING, &options.about_data.name,
N_("Set application name"), N_("STRING") },
{ "version", 0, 0, G_OPTION_ARG_STRING, &options.about_data.version,
N_("Set application version"), N_("STRING") },
{ "copyright", 0, 0, G_OPTION_ARG_STRING, &options.about_data.copyright,
N_("Set application copyright string"), N_("STRING") },
{ "comments", 0, 0, G_OPTION_ARG_STRING, &options.about_data.comments,
N_("Set application comments string"), N_("TEXT") },
{ "license", 0, 0, G_OPTION_ARG_STRING, &options.about_data.license,
N_("Set application license"), N_("TEXT") },
{ "authors", 0, 0, G_OPTION_ARG_STRING, &options.about_data.authors,
N_("Set application authors"), N_("LIST") },
{ "website", 0, 0, G_OPTION_ARG_STRING, &options.about_data.website,
N_("Set application website"), N_("URI") },
{ "website-label", 0, 0, G_OPTION_ARG_STRING, &options.about_data.website_lbl,
N_("Set application website label"), N_("STRING") },
{ NULL }
};
static GOptionEntry app_options[] = {
{ "app", 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &app_mode,
N_("Display application selection dialog"), NULL },
......@@ -647,8 +669,6 @@ static GOptionEntry filter_options[] = {
};
static GOptionEntry misc_options[] = {
{ "about", 0, 0, G_OPTION_ARG_NONE, &about_mode,
N_("Show about dialog"), NULL },
{ "version", 0, 0, G_OPTION_ARG_NONE, &version_mode,
N_("Print version"), NULL },
#ifdef HAVE_SPELL
......@@ -1587,6 +1607,15 @@ yad_options_init (void)
options.common_data.spell_lang = NULL;
#endif
/* initialize about data */
options.about_data.name = NULL;
options.about_data.copyright = NULL;
options.about_data.comments = NULL;
options.about_data.license = NULL;
options.about_data.authors = NULL;
options.about_data.website = NULL;
options.about_data.website_lbl = NULL;
/* Initialize application data */
options.app_data.show_fallback = FALSE;
options.app_data.show_other = FALSE;
......@@ -1799,6 +1828,12 @@ yad_create_context (void)
g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE);
g_option_context_add_group (tmp_ctx, a_group);
/* Adds about option entries */
a_group = g_option_group_new ("about", _("About dialog options"), _("Show custom about dialog options"), NULL, NULL);
g_option_group_add_entries (a_group, about_options);
g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE);
g_option_context_add_group (tmp_ctx, a_group);
/* Adds app option entries */
a_group = g_option_group_new ("app", _("Application selection options"), _("Show application selection options"), NULL, NULL);
g_option_group_add_entries (a_group, app_options);
......
......@@ -263,6 +263,17 @@ typedef struct {
} YadAppData;
typedef struct {
gchar *name;
gchar *version;
gchar *copyright;
gchar *comments;
gchar *license;
gchar *authors;
gchar *website;
gchar *website_lbl;
} YadAboutData;
typedef struct {
gint day;
gint month;
gint year;
......@@ -498,6 +509,7 @@ typedef struct {
YadData data;
YadCommonData common_data;
YadAboutData about_data;
YadAppData app_data;
YadCalendarData calendar_data;
YadColorData color_data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment