1 // This file is part of GtkEveMon.
2 //
3 // GtkEveMon is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // You should have received a copy of the GNU General Public License
9 // along with GtkEveMon. If not, see <http://www.gnu.org/licenses/>.
10 
11 #include <iostream>
12 
13 #include <gtkmm.h>
14 
15 #include "util/helpers.h"
16 #include "bits/config.h"
17 #include "imagestore.h"
18 #include "gtkportrait.h"
19 #include "gtkdefines.h"
20 #include "guiskillplanner.h"
21 
GuiSkillPlanner(void)22 GuiSkillPlanner::GuiSkillPlanner (void)
23 {
24   this->skill_browser.set_border_width(5);
25   this->cert_browser.set_border_width(5);
26 
27   this->browser_nb.append_page(this->skill_browser, "Skills");
28   this->browser_nb.append_page(this->cert_browser, "Certificates");
29   this->browser_nb.set_size_request(260, -1);
30 
31   this->details_nb.append_page(this->plan_gui, "Training plan");
32   this->details_nb.append_page(this->details_gui, "Item details");
33 
34   Gtk::Button* close_but = MK_BUT("Close");
35   Gtk::Box* button_hbox = MK_HBOX(5);
36   button_hbox->pack_start(*MK_HSEP, true, true, 0);
37   button_hbox->pack_start(*close_but, false, false, 0);
38 
39   Gtk::Box* details_panechild = MK_VBOX(5);
40   details_panechild->pack_start(this->details_nb, true, true, 0);
41   details_panechild->pack_start(*button_hbox, false, false, 0);
42 
43   this->main_pane.add1(this->browser_nb);
44   this->main_pane.add2(*details_panechild);
45 
46   Gtk::Box* main_vbox = MK_VBOX(5);
47   main_vbox->set_border_width(5);
48   main_vbox->pack_start(this->main_pane, true, true, 0);
49 
50   /* Signals. */
51   this->skill_browser.signal_element_selected().connect
52       (sigc::mem_fun(*this, &GuiSkillPlanner::on_element_selected));
53   this->skill_browser.signal_element_activated().connect
54       (sigc::mem_fun(*this, &GuiSkillPlanner::on_element_activated));
55   this->skill_browser.signal_planning_requested().connect
56       (sigc::mem_fun(*this, &GuiSkillPlanner::on_planning_requested));
57   this->cert_browser.signal_element_selected().connect
58       (sigc::mem_fun(*this, &GuiSkillPlanner::on_element_selected));
59   this->cert_browser.signal_element_activated().connect
60       (sigc::mem_fun(*this, &GuiSkillPlanner::on_element_activated));
61   this->cert_browser.signal_planning_requested().connect
62       (sigc::mem_fun(*this, &GuiSkillPlanner::on_planning_requested));
63 
64   close_but->signal_clicked().connect(sigc::mem_fun(*this, &WinBase::close));
65   this->plan_gui.signal_skill_activated().connect(sigc::mem_fun
66       (*this, &GuiSkillPlanner::on_element_activated));
67   this->details_gui.signal_planning_requested().connect(sigc::mem_fun
68       (*this, &GuiSkillPlanner::on_planning_requested));
69 
70   this->add(*main_vbox);
71   this->set_title("Skill browser - GtkEveMon");
72   this->set_icon(ImageStore::applogo);
73   //this->set_default_size(800, 550);
74   this->init_from_config();
75   this->show_all();
76 }
77 
78 /* ---------------------------------------------------------------- */
79 
~GuiSkillPlanner(void)80 GuiSkillPlanner::~GuiSkillPlanner (void)
81 {
82   this->store_to_config();
83 }
84 
85 /* ---------------------------------------------------------------- */
86 
87 void
init_from_config(void)88 GuiSkillPlanner::init_from_config (void)
89 {
90   ConfSectionPtr planner = Config::conf.get_section("planner");
91   ConfValuePtr gui_dimension = planner->get_value("gui_dimension");
92   ConfValuePtr pane_pos = planner->get_value("pane_position");
93 
94   StringVector dim_xy = Helpers::split_string(**gui_dimension, 'x');
95   if (dim_xy.size() == 2)
96   {
97     int dim_x = Helpers::get_int_from_string(dim_xy[0]);
98     int dim_y = Helpers::get_int_from_string(dim_xy[1]);
99     this->set_default_size(dim_x, dim_y);
100   }
101 
102   this->main_pane.set_position(pane_pos->get_int());
103 }
104 
105 /* ---------------------------------------------------------------- */
106 
107 void
store_to_config(void)108 GuiSkillPlanner::store_to_config (void)
109 {
110   ConfSectionPtr planner = Config::conf.get_section("planner");
111   ConfValuePtr gui_dimension = planner->get_value("gui_dimension");
112   ConfValuePtr pane_pos = planner->get_value("pane_position");
113 
114   int dim_x = 0;
115   int dim_y = 0;
116   this->get_size(dim_x, dim_y);
117   gui_dimension->set(Helpers::get_string_from_int(dim_x) + "x"
118       + Helpers::get_string_from_int(dim_y));
119 
120   pane_pos->set(this->main_pane.get_position());
121 }
122 
123 /* ---------------------------------------------------------------- */
124 
125 void
set_character(CharacterPtr character)126 GuiSkillPlanner::set_character (CharacterPtr character)
127 {
128   this->character = character;
129   this->details_gui.set_character(character);
130   this->plan_gui.set_character(character);
131   /* FIXME: Pass character to browsers to register changed signal? */
132   this->skill_browser.set_character(character->cs);
133   this->cert_browser.set_character(character->cs);
134   this->set_title(character->get_char_name() + " - GtkEveMon");
135 }
136 
137 /* ---------------------------------------------------------------- */
138 
139 void
on_element_selected(ApiElement const * elem)140 GuiSkillPlanner::on_element_selected (ApiElement const* elem)
141 {
142   this->details_gui.set_element(elem);
143 }
144 
145 /* ---------------------------------------------------------------- */
146 
147 void
on_element_activated(ApiElement const * elem)148 GuiSkillPlanner::on_element_activated (ApiElement const* elem)
149 {
150   this->details_nb.set_current_page(1);
151   this->details_gui.set_element(elem);
152 }
153 
154 /* ---------------------------------------------------------------- */
155 
156 void
on_planning_requested(ApiElement const * elem,int level)157 GuiSkillPlanner::on_planning_requested (ApiElement const* elem, int level)
158 {
159   this->details_nb.set_current_page(0);
160   this->plan_gui.append_element(elem, level);
161 }
162