1 /*
2  * about.c
3  * Copyright 2011-2013 John Lindgren
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions, and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *    this list of conditions, and the following disclaimer in the documentation
13  *    provided with the distribution.
14  *
15  * This software is provided "as is" and without any warranty, express or
16  * implied. In no event shall the authors be liable for any damages arising from
17  * the use of this software.
18  */
19 
20 #include <gtk/gtk.h>
21 
22 #include <libaudcore/audstrings.h>
23 #include <libaudcore/i18n.h>
24 #include <libaudcore/runtime.h>
25 #include <libaudcore/vfs.h>
26 
27 #include "internal.h"
28 #include "libaudgui.h"
29 #include "libaudgui-gtk.h"
30 
31 static const char about_text[] = "<big><b>Audacious " VERSION "</b></big>\n" COPYRIGHT;
32 static const char website[] = "https://audacious-media-player.org";
33 
create_credits_notebook(const char * credits,const char * license)34 static GtkWidget * create_credits_notebook (const char * credits, const char * license)
35 {
36     const char * titles[2] = {N_("Credits"), N_("License")};
37     const char * text[2] = {credits, license};
38 
39     GtkWidget * notebook = gtk_notebook_new ();
40 
41     for (int i = 0; i < 2; i ++)
42     {
43         GtkWidget * label = gtk_label_new (_(titles[i]));
44 
45         GtkWidget * scrolled = gtk_scrolled_window_new (nullptr, nullptr);
46         gtk_widget_set_size_request (scrolled, -1, 2 * audgui_get_dpi ());
47         gtk_scrolled_window_set_policy ((GtkScrolledWindow *) scrolled,
48          GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
49 
50         GtkTextBuffer * buffer = gtk_text_buffer_new (nullptr);
51         gtk_text_buffer_set_text (buffer, text[i], -1);
52         GtkWidget * text = gtk_text_view_new_with_buffer (buffer);
53         gtk_text_view_set_editable ((GtkTextView *) text, false);
54         gtk_text_view_set_cursor_visible ((GtkTextView *) text, false);
55         gtk_text_view_set_left_margin ((GtkTextView *) text, 6);
56         gtk_text_view_set_right_margin ((GtkTextView *) text, 6);
57         gtk_container_add ((GtkContainer *) scrolled, text);
58 
59         gtk_notebook_append_page ((GtkNotebook *) notebook, scrolled, label);
60     }
61 
62     return notebook;
63 }
64 
create_about_window()65 static GtkWidget * create_about_window ()
66 {
67     const char * data_dir = aud_get_path (AudPath::DataDir);
68 
69     int dpi = audgui_get_dpi ();
70 
71     GtkWidget * about_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
72     gtk_window_set_title ((GtkWindow *) about_window, _("About Audacious"));
73     gtk_window_set_resizable ((GtkWindow *) about_window, false);
74     gtk_container_set_border_width ((GtkContainer *) about_window, 3);
75 
76     audgui_destroy_on_escape (about_window);
77 
78     GtkWidget * vbox = gtk_vbox_new (false, 6);
79     gtk_container_add ((GtkContainer *) about_window, vbox);
80 
81     AudguiPixbuf logo (gdk_pixbuf_new_from_resource_at_scale
82      ("/org/audacious/about-logo.svg", 4 * dpi, 2 * dpi, true, nullptr));
83     GtkWidget * image = gtk_image_new_from_pixbuf (logo.get ());
84     gtk_box_pack_start ((GtkBox *) vbox, image, false, false, 0);
85 
86     GtkWidget * label = gtk_label_new (nullptr);
87     gtk_label_set_markup ((GtkLabel *) label, about_text);
88     gtk_label_set_justify ((GtkLabel *) label, GTK_JUSTIFY_CENTER);
89     gtk_box_pack_start ((GtkBox *) vbox, label, false, false, 0);
90 
91     GtkWidget * align = gtk_alignment_new (0.5, 0.5, 0, 0);
92     gtk_box_pack_start ((GtkBox *) vbox, align, false, false, 0);
93 
94     GtkWidget * button = gtk_link_button_new (website);
95     gtk_container_add ((GtkContainer *) align, button);
96 
97     auto credits = VFSFile::read_file (filename_build ({data_dir, "AUTHORS"}), VFS_APPEND_NULL);
98     auto license = VFSFile::read_file (filename_build ({data_dir, "COPYING"}), VFS_APPEND_NULL);
99 
100     GtkWidget * notebook = create_credits_notebook (credits.begin (), license.begin ());
101     gtk_widget_set_size_request (notebook, 6 * dpi, 2 * dpi);
102     gtk_box_pack_start ((GtkBox *) vbox, notebook, true, true, 0);
103 
104     return about_window;
105 }
106 
audgui_show_about_window()107 EXPORT void audgui_show_about_window ()
108 {
109     if (! audgui_reshow_unique_window (AUDGUI_ABOUT_WINDOW))
110         audgui_show_unique_window (AUDGUI_ABOUT_WINDOW, create_about_window ());
111 }
112 
audgui_hide_about_window()113 EXPORT void audgui_hide_about_window ()
114 {
115     audgui_hide_unique_window (AUDGUI_ABOUT_WINDOW);
116 }
117