}
void ApplicationFrameWork::on_action_file_quit() {
+ save();
windows.clear();
Gtk::Main::quit();
}
#include <gtkmm/main.h>
#include <boost/lambda/lambda.hpp>
#include <boost/foreach.hpp>
+#include <boost/archive/xml_iarchive.hpp>
+#include <boost/archive/xml_oarchive.hpp>
+#include <boost/serialization/nvp.hpp>
+#include <boost/serialization/vector.hpp>
+#include <boost/filesystem.hpp>
+#include <fstream>
+#include <iostream>
+#include <cstdlib>
+#include "uri_opener.hxx"
namespace dialektos {
return false;
}
+void ApplicationWindow::load() {
+ std::string homedir = std::getenv("HOME");
+ boost::filesystem::path dir(homedir);
+ boost::filesystem::path session = dir / ".dialektos" / "session.xml";
+
+ std::vector<std::string> uris;
+
+ if (boost::filesystem::exists(session) &&
+ boost::filesystem::is_regular(session)) {
+ std::ifstream ifs(session.file_string().c_str());
+ try {
+ boost::archive::xml_iarchive ia(ifs);
+ ia >> boost::serialization::make_nvp("Session", uris);
+ } catch (const boost::archive::archive_exception& e) {
+ std::cerr << "ApplicationWindow::load(): " << e.what() << std::endl;
+ }
+ }
+
+ BOOST_FOREACH(const std::string& uri, uris) {
+ uri_opener::open(uri);
+ }
+
+ if (uris.empty()) {
+ uri_opener::open("http://dubai.2ch.net/morningcoffee/");
+ }
+}
+
+void ApplicationWindow::save() {
+ std::vector<std::string> uris;
+ BOOST_FOREACH(const ApplicationWindow& window, windows) {
+ uris.push_back(window.get_uri());
+ }
+
+ std::string homedir = std::getenv("HOME");
+ boost::filesystem::path dir(homedir);
+ boost::filesystem::path session = dir / ".dialektos" / "session.xml";
+
+ std::ofstream ofs(session.file_string().c_str());
+ try {
+ boost::archive::xml_oarchive oa(ofs);
+ oa << boost::serialization::make_nvp("Session", uris);
+ } catch (const boost::archive::archive_exception& e) {
+ std::cerr << "save(): " << e.what() << std::endl;
+ }
+}
+
//bool ApplicationWindow::is_same(const bbs_detail::Base& bbs) const {
// return false;
//}
void ApplicationWindow::regist(ApplicationWindow* window) {
windows.push_back(window);
+ save();
}
bool ApplicationWindow::on_delete_event(GdkEventAny* /*event*/) {
using namespace boost::lambda;
// using boost::lambda::_1;
windows.erase_if(&_1 == this);
+ if (!windows.empty()) save();
if (windows.empty()) Gtk::Main::quit();
return false;
}
public:
virtual ~ApplicationWindow();
static bool is_opened(const bbs_detail::Base& bbs);
+ static void load();
protected:
ApplicationWindow();
static void regist(ApplicationWindow* window);
+ static void save();
virtual bool on_delete_event(GdkEventAny*);
private:
virtual bool is_same(const bbs_detail::Base& bbs) const = 0;
+ virtual std::string get_uri() const = 0;
protected:
static boost::ptr_vector<ApplicationWindow> windows;
};
return "http://" + host_ + "/" + board_ + "/dat/" + thread_ + ".dat";
}
+std::string Base::get_thread_uri() const {
+ assert(!thread_.empty());
+ std::stringstream ss;
+ ss << boost::format("http://%1%/test/read.cgi/%2%/%3%/")
+ % host_ % board_ % thread_ << std::flush;
+ return ss.str();
+}
+
std::string Base::get_another_thread_uri(const std::string& thread) const {
return "http://" + host_ + "/test/read.cgi/" + board_ + "/" + thread + "/";
}
return ss.str();
}
+std::string Base::get_board_uri() const {
+ std::stringstream ss;
+ ss << boost::format("http://%1%/%2%/") % host_ % board_ << std::flush;
+ return ss.str();
+}
+
std::string Base::get_board_subject_idx_path() const {
boost::filesystem::path dir(get_board_dir_path());
dir = dir / "subject.xml";
virtual std::string get_thread_file_path() const;
virtual std::string get_thread_idx_path() const;
virtual std::string get_thread_dat_uri() const;
+ virtual std::string get_thread_uri() const;
virtual std::string get_another_thread_uri(const std::string& thread) const;
virtual std::string get_board_subject_path() const;
virtual std::string get_board_subject_uri() const;
+ virtual std::string get_board_uri() const;
virtual std::string get_board_subject_idx_path() const;
virtual std::string get_board_idx_dir_path() const;
virtual http::Header get_board_subject_request_header() const;
return *bbs_ == bbs;
}
+std::string BoardWindow::get_uri() const {
+ return bbs_->get_board_uri();
+}
+
+
void BoardWindow::load() {
boost::unordered_map<model_column::ID::type, ModelColumns> buffer;
virtual void on_action_view_stop();
private:
virtual bool is_same(const bbs_detail::Base& bbs) const;
+ virtual std::string get_uri() const;
void on_row_activated(const Gtk::TreeModel::Path&,
Gtk::TreeViewColumn*);
#include <gtkmm/main.h>
#include <sigc++/functors/ptr_fun.h>
#include "uri_opener.hxx"
+#include "application_window.hxx"
/*! @brief namespace for dialektos */
bool window() {
- dialektos::uri_opener::open(
- "http://localhost.2ch.net/test/read.cgi/hagehage/1234567890/");
- dialektos::uri_opener::open("http://localhost.2ch.net/hagehage/");
+ dialektos::ApplicationWindow::load();
return false;
}
return lhs == bbs;
}
+std::string ThreadWindow::get_uri() const {
+ return bbs_->get_thread_uri();
+}
+
+
void ThreadWindow::on_action_view_refresh() {
if (http_getter_) return;
virtual void on_action_view_stop();
private:
virtual bool is_same(const bbs_detail::Base& bbs) const;
+ virtual std::string get_uri() const;
void on_http_get_end(bool);
void on_refresh_end(const http::StatusLine&, const http::Header&);