2 * Copyright (C) 2009 by Aiwota Programmer
3 * aiwotaprog@tetteke.tk
5 * This file is part of Dialektos.
7 * Dialektos is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * Dialektos 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.
17 * You should have received a copy of the GNU General Public License
18 * along with Dialektos. If not, see <http://www.gnu.org/licenses/>.
21 #include "board_view_column.hxx"
23 #include <sigc++/functors/mem_fun.h>
24 #include <glibmm/ustring.h>
25 #include <gtkmm/cellrenderer.h>
26 #include <gtkmm/treeviewcolumn.h>
27 #include <gtkmm/treemodel.h>
29 #include <boost/date_time/posix_time/posix_time.hpp>
30 #include <boost/lexical_cast.hpp>
31 #include <boost/mpl/find.hpp>
33 #include "thread_list_model.hxx"
38 namespace view_column {
41 Base::Base(const Glib::ustring& title) :
42 Gtk::TreeViewColumn(title) {
44 set_reorderable(true);
46 set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
48 // set_fixed_width(30); // specify in a derived class.
50 Gtk::CellRendererText* cell = Gtk::manage(new Gtk::CellRendererText);
51 pack_start(*cell, true);
52 set_cell_data_func(*cell,
53 sigc::mem_fun(*this, &Base::on_cell_data));
57 void Base::on_cell_data(Gtk::CellRenderer* cell,
58 const Gtk::TreeModel::iterator& iter) {
59 do_cell_data(cell, iter);
62 StartTime::StartTime() : Base("Since") {
65 StartTime::~StartTime() {}
67 void StartTime::do_cell_data(Gtk::CellRenderer* cell,
68 const Gtk::TreeModel::iterator& iter) {
70 model_column::ID::type value;
71 iter->get_value(boost::mpl::find<ModelColumns::type,
72 model_column::ID>::type::pos::value, value);
75 std::time_t t = boost::lexical_cast<std::time_t>(value);
76 boost::posix_time::ptime ptime = boost::posix_time::from_time_t(t);
77 boost::posix_time::time_facet* facet =
78 new boost::posix_time::time_facet("%Y/%m/%d %H:%M:%S");
80 ss.imbue(std::locale(ss.getloc(), facet));
83 } catch (const std::exception& /*e*/) {
87 cell->set_property("text", value);
91 Average::Average() : Base("Average") {
94 Average::~Average() {}
96 void Average::do_cell_data(Gtk::CellRenderer* cell,
97 const Gtk::TreeModel::iterator& iter) {
98 on_cell_data_int<model_column::Average>(cell, iter);
102 Title::Title() : Base("Title") {
103 set_fixed_width(200);
106 void Title::do_cell_data(Gtk::CellRenderer* cell,
107 const Gtk::TreeModel::iterator& iter) {
108 on_cell_data_string<model_column::Title>(cell, iter);
112 ResNum::ResNum() : Base("ResNum") {
116 void ResNum::do_cell_data(Gtk::CellRenderer* cell,
117 const Gtk::TreeModel::iterator& iter) {
118 on_cell_data_int<model_column::ResNum>(cell, iter);
122 Number::Number() : Base("No.") {
126 void Number::do_cell_data(Gtk::CellRenderer* cell,
127 const Gtk::TreeModel::iterator& iter) {
128 on_cell_data_int<model_column::Number>(cell, iter);
132 LineCount::LineCount() : Base("Read") {
135 LineCount::~LineCount() {}
136 void LineCount::do_cell_data(Gtk::CellRenderer* cell,
137 const Gtk::TreeModel::iterator& iter) {
138 on_cell_data_int<model_column::LineCount>(cell, iter);
142 } // namespace view_column
144 } // namespace dialektos