1
// Copyright (C) 2008, Ben Asselstine
3
// This program 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 2 of the License, or
6
// (at your option) any later version.
8
// This program is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
// GNU Library General Public License for more details.
13
// You should have received a copy of the GNU General Public License
14
// along with this program; if not, write to the Free Software
15
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
#include <sigc++/functors/mem_fun.h>
26
#include <sigc++/functors/ptr_fun.h>
28
#include <gtkmm/widget.h>
29
#include <gtkmm/eventbox.h>
30
#include <gtkmm/image.h>
31
#include <gtkmm/box.h>
32
#include <gtkmm/dialog.h>
34
#include "rewardlist-dialog.h"
36
#include "../gui/input-helpers.h"
37
#include "../gui/error-utils.h"
40
#include "../Configuration.h"
41
#include "../rewardlist.h"
43
#include "../ucompose.hpp"
44
#include "../playerlist.h"
46
#include "glade-helpers.h"
47
#include "reward-dialog.h"
50
RewardlistDialog::RewardlistDialog()
52
Glib::RefPtr<Gnome::Glade::Xml> xml
53
= Gnome::Glade::Xml::create(get_glade_path() +
54
"/reward-list-dialog.glade");
57
xml->get_widget("dialog", d);
60
xml->get_widget("rewards_treeview", rewards_treeview);
61
xml->get_widget("add_button", add_button);
62
add_button->signal_clicked().connect
63
(sigc::mem_fun(this, &RewardlistDialog::on_add_clicked));
64
xml->get_widget("remove_button", remove_button);
65
remove_button->signal_clicked().connect
66
(sigc::mem_fun(this, &RewardlistDialog::on_remove_clicked));
67
xml->get_widget("edit_button", edit_button);
68
edit_button->signal_clicked().connect
69
(sigc::mem_fun(this, &RewardlistDialog::on_edit_clicked));
71
rewards_list = Gtk::ListStore::create(rewards_columns);
72
rewards_treeview->set_model(rewards_list);
73
rewards_treeview->append_column("", rewards_columns.name);
74
rewards_treeview->set_headers_visible(false);
76
Rewardlist *rewardlist = Rewardlist::getInstance();
77
Rewardlist::iterator iter = rewardlist->begin();
78
for (;iter != rewardlist->end(); iter++)
81
Uint32 max = rewardlist->size();
84
Gtk::TreeModel::Row row;
85
row = rewards_treeview->get_model()->children()[0];
87
rewards_treeview->get_selection()->select(row);
91
update_rewardlist_buttons();
92
rewards_treeview->get_selection()->signal_changed().connect
93
(sigc::mem_fun(*this, &RewardlistDialog::on_reward_selected));
97
RewardlistDialog::update_rewardlist_buttons()
99
if (!rewards_treeview->get_selection()->get_selected())
101
remove_button->set_sensitive(false);
102
edit_button->set_sensitive(false);
106
remove_button->set_sensitive(true);
107
edit_button->set_sensitive(true);
111
RewardlistDialog::~RewardlistDialog()
115
void RewardlistDialog::addReward(Reward *reward)
117
Gtk::TreeIter i = rewards_list->append();
118
(*i)[rewards_columns.name] = reward->getName();
119
(*i)[rewards_columns.reward] = reward;
122
void RewardlistDialog::on_reward_selected()
124
update_rewardlist_buttons();
127
void RewardlistDialog::on_add_clicked()
129
Player *neutral = Playerlist::getInstance()->getNeutral();
130
RewardDialog d(neutral, true, NULL);
134
Reward *reward = d.get_reward();
135
Gtk::TreeIter i = rewards_list->append();
136
(*i)[rewards_columns.name] = reward->getName();
137
(*i)[rewards_columns.reward] = reward;
138
Rewardlist::getInstance()->push_back(reward);
143
void RewardlistDialog::on_remove_clicked()
145
//erase the selected row from the treeview
146
//remove the reward from the rewardlist
147
Glib::RefPtr<Gtk::TreeSelection> selection = rewards_treeview->get_selection();
148
Gtk::TreeModel::iterator iterrow = selection->get_selected();
152
Gtk::TreeModel::Row row = *iterrow;
153
Reward *a = row[rewards_columns.reward];
154
rewards_list->erase(iterrow);
155
Rewardlist::getInstance()->remove(a);
159
void RewardlistDialog::on_edit_clicked()
161
Glib::RefPtr<Gtk::TreeSelection> selection =
162
rewards_treeview->get_selection();
163
Gtk::TreeModel::iterator iterrow = selection->get_selected();
167
Gtk::TreeModel::Row row = *iterrow;
168
Reward *reward = row[rewards_columns.reward];
169
Player *neutral = Playerlist::getInstance()->getNeutral();
170
RewardDialog d(neutral, true, reward);
174
Rewardlist::getInstance()->remove(reward);
175
reward = d.get_reward();
176
(*iterrow)[rewards_columns.name] = reward->getName();
177
(*iterrow)[rewards_columns.reward] = reward;
178
Rewardlist::getInstance()->push_back(reward);
182
rewards_list->erase(iterrow);
183
Rewardlist::getInstance()->remove(reward);
189
void RewardlistDialog::set_parent_window(Gtk::Window &parent)
191
dialog->set_transient_for(parent);
192
//dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
195
void RewardlistDialog::run()
198
int response = dialog->run();