1 /**********************************************************************
2 *
3 * FreeDoko a Doppelkopf-Game
4 *
5 * Copyright (C) 2001 – 2018 by Diether Knof and Borg Enders
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You can find this license in the file 'gpl.txt'.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 * Contact:
24 * Diether Knof dknof@posteo.de
25 *
26 *********************************************************************/
27
28 #include "constants.h"
29
30 #ifdef USE_UI_GTKMM
31
32 #include "program_updated.h"
33
34 #include "ui.h"
35
36 #include "../../party/party.h"
37 #include "../../player/player.h"
38 #include "../../player/aiconfig.h"
39
40 #include <gtkmm/image.h>
41 #include <gtkmm/scrolledwindow.h>
42 #include <gtkmm/textview.h>
43 #include <gtkmm/texttag.h>
44
45 namespace UI_GTKMM_NS {
46
47 /** constructor
48 **
49 ** @param parent the parent object
50 ** @param old_version last version
51 **/
ProgramUpdated(Base * const parent,Version const & old_version)52 ProgramUpdated::ProgramUpdated(Base* const parent,
53 Version const& old_version) :
54 Base(parent),
55 Dialog("FreeDoko – " + _("Window::program updated")),
56 old_version(old_version)
57 {
58 this->ui->add_window(*this);
59
60 this->set_icon(this->ui->icon);
61
62 this->set_default_size(static_cast<int>(this->ui->logo->get_width() * 1.5),
63 static_cast<int>(this->ui->logo->get_height() * 2.5));
64 #ifdef POSTPONED
65 this->get_window()->set_decorations(Gdk::DECOR_BORDER
66 | Gdk::DECOR_RESIZEH
67 | Gdk::DECOR_TITLE
68 | Gdk::DECOR_MENU);
69 #endif
70
71 { // action area
72 { // reset ais button
73 auto reset_ais_button = Gtk::manage(new Gtk::Button(_("Button::reset ais")));
74 this->add_action_widget(*reset_ais_button, Gtk::RESPONSE_NONE);
75
76 // signals
77 reset_ais_button->signal_clicked().connect(sigc::mem_fun(*this, &ProgramUpdated::reset_ais));
78 } // reset ais button
79 add_close_button(*this);
80 } // action area
81
82
83 { // the image
84 auto image = Gtk::manage(new Gtk::Image(parent->ui->logo));
85 this->get_content_area()->pack_start(*image, Gtk::PACK_SHRINK);
86 } // the image
87 { // the text
88 auto const text = Gtk::manage(new Gtk::TextView());
89 this->text_buffer = text->get_buffer();
90 {
91 auto tag_title = this->text_buffer->create_tag("title");
92 //tag_title->set_property("weight", Pango::WEIGHT_BOLD);
93 tag_title->set_property("scale", Pango::SCALE_X_LARGE);
94 tag_title->set_property("justification", Gtk::JUSTIFY_CENTER);
95
96 auto tag_subtitle = this->text_buffer->create_tag("subtitle");
97 tag_title->set_property("weight", Pango::WEIGHT_BOLD);
98 }
99 { // title
100 this->text_buffer->insert_with_tag(this->text_buffer->begin(),
101 "\n"
102 // gettext: %s = version
103 + _("Greeting::%s", ::version->number_to_string()),
104 "title");
105 } // title
106 for (auto v = ::all_versions.rbegin();
107 ( (v != ::all_versions.rend())
108 && (this->old_version < **v) );
109 ++v) {
110 this->text_buffer->insert_with_tag(this->text_buffer->end(),
111 "\n\n"
112 // gettext: %s = version
113 + _("ChangeLog::for %s", (*v)->number_to_string()),
114 "subtitle");
115 this->text_buffer->insert(this->text_buffer->end(),
116 "\n"
117 + _("ChangeLog::" + (*v)->number_to_string()));
118 } // for (v \in ::all_versions)
119
120
121 auto text_window = Gtk::manage(new Gtk::ScrolledWindow());
122 text_window->add(*text);
123 text_window->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
124 text->set_editable(false);
125 text->set_wrap_mode(Gtk::WRAP_WORD);
126 text->set_cursor_visible(false);
127
128 this->get_content_area()->pack_end(*text_window);
129 } // the text
130
131 this->show_all_children();
132 } // ProgramUpdated::ProgramUpdated(Base* parent, Version old_version)
133
134 /** destructor
135 **/
136 ProgramUpdated::~ProgramUpdated() = default;
137
138 /** reset the ais
139 **/
140 void
reset_ais()141 ProgramUpdated::reset_ais()
142 {
143 unsigned n = 0;
144 for (auto& p : this->ui->party().players())
145 if (dynamic_cast<Aiconfig*>(&p))
146 dynamic_cast<Aiconfig&>(p).reset_to_hardcoded(n);
147
148 this->hide();
149 } // void ProgramUpdated::reset_ais()
150
151 } // namespace UI_GTKMM_NS
152
153 #endif // #ifdef USE_UI_GTKMM
154