OSDN Git Service

5b29b4e330c6ab4f4b6b0009bdbc3b2918bee52c
[fukui-no-namari/dialektos.git] / src / board_window.hxx
1 /*
2  * Copyright (C) 2009 by Aiwota Programmer
3  * aiwotaprog@tetteke.tk
4  *
5  * This file is part of Dialektos.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 #ifndef BOARD_WINDOW_HXX
22 #define BOARD_WINDOW_HXX
23
24 #include <glibmm/refptr.h>
25 #include <gtkmm/treeview.h>
26 #include <gtkmm/scrolledwindow.h>
27 #include <boost/scoped_ptr.hpp>
28 #include <boost/foreach.hpp>
29 #include <memory>
30 #include "application_framework.hxx"
31 #include "thread_list_model.hxx"
32 #include "http_get.hxx"
33 #include "board_subject_item.hxx"
34 #include "board_subject_idx.hxx"
35 #include "board_window_state.hxx"
36
37
38 namespace dialektos {
39
40 namespace bbs_detail {
41   class Base;
42 }
43
44 struct ThreadIdx;
45
46
47 class BoardWindow: public dialektos::ApplicationFrameWork {
48 public:
49   static void create(std::auto_ptr<bbs_detail::Base> bbs);
50   virtual ~BoardWindow();
51   virtual void save_state() const;
52   void on_informed_from(const bbs_detail::Base&, const ThreadIdx&);
53 protected:
54   BoardWindow(std::auto_ptr<bbs_detail::Base> bbs);
55
56   void on_action_file_open();
57
58   virtual void on_action_edit_copy();
59   virtual void on_action_view_refresh();
60   virtual void on_action_view_stop();
61 private:
62   virtual bool is_same(const bbs_detail::Base& bbs) const;
63   virtual std::string get_uri() const;
64
65   void on_row_activated(const Gtk::TreeModel::Path&,
66       Gtk::TreeViewColumn*);
67   void load();
68
69   void merge_subject_txt(
70       const std::vector<SubjectItem>&,
71       boost::unordered_map<std::string, ModelColumns>&);
72   void unmerge_subject_txt(
73       boost::unordered_map<std::string, ModelColumns>&);
74
75   void on_http_get_end(bool);
76   void on_refresh_end(const http::StatusLine&, const http::Header&);
77
78   void save_content(const http::Response&);
79
80   template <typename ColumnType>
81   void on_column_clicked(ColumnType& column);
82
83   template <typename ColumnType>
84   void add_column(const BoardWindowState&);
85
86   Gtk::TreeView tree_view_;
87   boost::scoped_ptr<bbs_detail::Base> bbs_;
88   Gtk::ScrolledWindow scrolled_;
89   Glib::RefPtr<ThreadListModel> tree_model_;
90   boost::scoped_ptr<http::GetInThread> http_getter_;
91   SubjectIdx idx_;
92 };
93
94 template <typename ColumnType>
95 void BoardWindow::on_column_clicked(ColumnType& column) {
96   typedef typename ColumnType::sort_model_column_type SortColumn;
97   BOOST_FOREACH(Gtk::TreeViewColumn* kolumn, tree_view_.get_columns()){
98     if (kolumn == &column) {
99       if (kolumn->get_sort_indicator()) {
100         if (kolumn->get_sort_order() == Gtk::SORT_ASCENDING)
101           kolumn->set_sort_order(Gtk::SORT_DESCENDING);
102         else kolumn->set_sort_order(Gtk::SORT_ASCENDING);
103       }
104       kolumn->set_sort_indicator(true);
105     } else {
106       if (kolumn->get_sort_indicator())
107         kolumn->set_sort_order(Gtk::SORT_ASCENDING);
108       kolumn->set_sort_indicator(false);
109     }
110   }
111   tree_model_->set_sort_function<SortColumn>(
112       column.get_sort_order() == Gtk::SORT_ASCENDING);
113   tree_model_->sort();
114 }
115
116 template <typename ColumnType>
117 void BoardWindow::add_column(const BoardWindowState& state) {
118   ColumnType* p = Gtk::manage(new ColumnType);
119   tree_view_.append_column(*p);
120   p->signal_clicked().connect(sigc::bind<ColumnType&>(
121       sigc::mem_fun(*this, &BoardWindow::on_column_clicked<ColumnType>),
122       *p));
123
124   if (state.sort.column == p->get_id()) {
125     typedef typename ColumnType::sort_model_column_type SortColumn;
126     p->set_sort_indicator(true);
127     p->set_sort_order(
128         state.sort.ascendant ? Gtk::SORT_ASCENDING : Gtk::SORT_DESCENDING);
129     tree_model_->set_sort_function<SortColumn>(state.sort.ascendant);
130   }
131
132 }
133
134
135 } // namespace dialektos
136
137 #endif