OSDN Git Service

Add uri clicked signal handler for ThreadWindow.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 3 Jul 2009 02:06:42 +0000 (11:06 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 3 Jul 2009 02:06:42 +0000 (11:06 +0900)
src/text_view.cxx
src/text_view.hxx
src/thread_window.cxx
src/thread_window.hxx

index 5efd00d..f51125c 100644 (file)
@@ -21,7 +21,6 @@
 #include "text_view.hxx"
 
 #include <boost/foreach.hpp>
-#include <iostream>
 
 #include "text_line.hxx"
 #include "text_element_anchor.hxx"
@@ -57,7 +56,9 @@ void TextView::jump_to_res_num(const int res_num) {
 }
 
 void TextView::on_anchor_click_event(const text_element::Anchor& elem) {
-  std::cout << elem.get_href() << std::endl;
+  const std::string uri = elem.get_href();
+  if (uri.empty()) return;
+  sig_uri_clicked_(uri);
 }
 
 
index 5273b09..4dd6a14 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef TEXT_VIEW_HXX
 #define TEXT_VIEW_HXX
 
+#include <sigc++/signal.h>
+#include <string>
 #include "text_view_popupable.hxx"
 
 
@@ -33,6 +35,7 @@ namespace text_view {
 
 class TextView: public Popupable {
   typedef Popupable SuperClass;
+  typedef sigc::signal<void ,const std::string&> SignalUriClicked;
 public:
   TextView();
   virtual ~TextView();
@@ -41,8 +44,12 @@ public:
   int get_displayed_res_num() const;
   void jump_to_res_num(int res_num);
 
+  SignalUriClicked& signal_uri_clicked() { return sig_uri_clicked_; }
 protected:
   virtual void on_anchor_click_event(const text_element::Anchor& elem);
+
+private:
+  SignalUriClicked sig_uri_clicked_;
 };
 
 
index 29c69a1..deb493a 100644 (file)
 #include <boost/date_time/posix_time/posix_time.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/foreach.hpp>
+#include <boost/format.hpp>
 #include <iostream>
 #include <fstream>
+#include <sstream>
+#include <cstdlib>
 #include "bbs_detail_base.hxx"
 #include "thread_idx.hxx"
 #include "http_get.hxx"
@@ -69,11 +72,8 @@ ThreadWindow::ThreadWindow(std::auto_ptr<bbs_detail::Base> bbs) :
 
   ui_manager_->add_ui_from_string(ui);
 
-  scrolled_.add(*text_view_);
   add(scrolled_);
-
-  text_view_->signal_button_press_event().connect_notify(
-      sigc::mem_fun(*this, &ThreadWindow::on_child_button_press));
+  initialize_text_view();
 
   ThreadWindowState state;
   state.from_xml(boost::filesystem::path(bbs_->get_thread_state_path()));
@@ -88,6 +88,17 @@ ThreadWindow::ThreadWindow(std::auto_ptr<bbs_detail::Base> bbs) :
   text_view_->jump_to_res_num(state.displayed_res_num);
 }
 
+void ThreadWindow::initialize_text_view() {
+  scrolled_.add(*text_view_);
+
+  text_view_->signal_button_press_event().connect_notify(
+      sigc::mem_fun(*this, &ThreadWindow::on_child_button_press));
+  text_view_->signal_uri_clicked().connect(
+      sigc::mem_fun(*this, &ThreadWindow::on_uri_clicked));
+
+  text_view_->show();
+}
+
 bool ThreadWindow::load() {
   using namespace boost::posix_time;
   ptime start = microsec_clock::local_time();
@@ -185,11 +196,8 @@ void ThreadWindow::on_http_get_end(bool success) {
     scrolled_.remove(*text_view_);
     text_view_.reset(new text_view::TextView);
     scrolled_.set_adjustment(text_view_->get_adjustment());
-    scrolled_.add(*text_view_);
 
-    text_view_->signal_button_press_event().connect_notify(
-        sigc::mem_fun(*this, &ThreadWindow::on_child_button_press));
-    text_view_->show();
+    initialize_text_view();
   }
 
   bbs_->load_thread_from_string(response.get_content(), *text_view_);
@@ -255,5 +263,11 @@ void ThreadWindow::inform_to_board(const ThreadIdx& idx) const {
   }
 }
 
+void ThreadWindow::on_uri_clicked(const std::string& uri) const {
+  if (uri_opener::open(uri)) return;
+  std::stringstream ss;
+  ss << boost::format("gnome-open %1%") % uri;
+  std::system(ss.str().c_str());
+}
 
 } // namespace dialektos
index 7a3ae01..bde62a7 100644 (file)
@@ -53,6 +53,7 @@ protected:
   void on_action_file_delete();
   void on_action_file_board();
 private:
+  void initialize_text_view();
   virtual bool is_same(const bbs_detail::Base& bbs) const;
   virtual std::string get_uri() const;
 
@@ -62,6 +63,8 @@ private:
   void save_content(const http::Response&);
   void inform_to_board(const ThreadIdx& idx) const;
 
+  void on_uri_clicked(const std::string& uri) const;
+
   boost::scoped_ptr<text_view::TextView> text_view_;
   ScrolledContainer scrolled_;
   boost::scoped_ptr<bbs_detail::Base> bbs_;