| 64 | | /* TODO: Put TabLabel into an extra source file */ |
| 65 | | class TabLabel: public Gtk::HBox |
| 66 | | { |
| 67 | | public: |
| 68 | | typedef Glib::SignalProxy0<void> SignalCloseRequest; |
| 69 | | |
| 70 | | TabLabel(Gobby::DocWindow& document, |
| 71 | | const Glib::ustring& title): |
| 72 | | Gtk::HBox(false, 4), m_document(document), |
| 73 | | m_title(title), m_label(title) |
| 74 | | { |
| 75 | | update_icon(); |
| 76 | | m_icon.show(); |
| 77 | | |
| 78 | | m_notify_editable_handle = g_signal_connect( |
| 79 | | document.get_text_view(), "notify::editable", |
| 80 | | G_CALLBACK(on_notify_editable_static), this); |
| 81 | | m_notify_status_handle = g_signal_connect( |
| 82 | | document.get_session(), "notify::status", |
| 83 | | G_CALLBACK(on_notify_status_static), this); |
| 84 | | m_notify_subscription_group_handle = g_signal_connect( |
| 85 | | document.get_session(), |
| 86 | | "notify::subscription-group", |
| 87 | | G_CALLBACK( |
| 88 | | on_notify_subscription_group_static), |
| 89 | | this); |
| 90 | | |
| 91 | | //m_label.set_ellipsize(Pango::ELLIPSIZE_END); |
| 92 | | m_label.show(); |
| 93 | | m_button.show(); |
| 94 | | |
| 95 | | pack_start(m_icon, Gtk::PACK_SHRINK); |
| 96 | | pack_start(m_label, Gtk::PACK_EXPAND_WIDGET); |
| 97 | | pack_start(m_button, Gtk::PACK_SHRINK); |
| 98 | | } |
| 99 | | |
| 100 | | ~TabLabel() |
| 101 | | { |
| 102 | | g_signal_handler_disconnect( |
| 103 | | m_document.get_text_view(), |
| 104 | | m_notify_editable_handle); |
| 105 | | g_signal_handler_disconnect( |
| 106 | | m_document.get_session(), |
| 107 | | m_notify_status_handle); |
| 108 | | g_signal_handler_disconnect( |
| 109 | | m_document.get_session(), |
| 110 | | m_notify_subscription_group_handle); |
| 111 | | } |
| 112 | | |
| 113 | | SignalCloseRequest signal_close_request() { |
| 114 | | return m_button.signal_clicked(); |
| 115 | | } |
| 116 | | |
| 117 | | private: |
| 118 | | static void on_notify_editable_static(GObject* object, |
| 119 | | GParamSpec* pspec, |
| 120 | | gpointer user_data) |
| 121 | | { |
| 122 | | static_cast<TabLabel*>(user_data)->update_icon(); |
| 123 | | } |
| 124 | | |
| 125 | | static void on_notify_status_static(GObject* object, |
| 126 | | GParamSpec* pspec, |
| 127 | | gpointer user_data) |
| 128 | | { |
| 129 | | static_cast<TabLabel*>(user_data)->update_icon(); |
| 130 | | } |
| 131 | | |
| 132 | | static void on_notify_subscription_group_static(GObject* obj, |
| 133 | | GParamSpec* p, |
| 134 | | gpointer data) |
| 135 | | { |
| 136 | | static_cast<TabLabel*>(data)->update_icon(); |
| 137 | | } |
| 138 | | |
| 139 | | void update_icon() |
| 140 | | { |
| 141 | | InfTextSession* session = m_document.get_session(); |
| 142 | | GtkTextView* view = |
| 143 | | GTK_TEXT_VIEW(m_document.get_text_view()); |
| 144 | | |
| 145 | | if(inf_session_get_subscription_group( |
| 146 | | INF_SESSION(session)) == NULL) |
| 147 | | { |
| 148 | | m_icon.set(Gtk::Stock::DISCONNECT, |
| 149 | | Gtk::ICON_SIZE_MENU); |
| 150 | | return; |
| 151 | | } |
| 152 | | |
| 153 | | switch(inf_session_get_status(INF_SESSION(session))) |
| 154 | | { |
| 155 | | case INF_SESSION_SYNCHRONIZING: |
| 156 | | m_icon.set(Gtk::Stock::EXECUTE, |
| 157 | | Gtk::ICON_SIZE_MENU); |
| 158 | | break; |
| 159 | | case INF_SESSION_RUNNING: |
| 160 | | if(gtk_text_view_get_editable(view)) |
| 161 | | { |
| 162 | | m_icon.set(Gtk::Stock::EDIT, |
| 163 | | Gtk::ICON_SIZE_MENU); |
| 164 | | } |
| 165 | | else |
| 166 | | { |
| 167 | | m_icon.set(Gtk::Stock::FILE, |
| 168 | | Gtk::ICON_SIZE_MENU); |
| 169 | | } |
| 170 | | |
| 171 | | break; |
| 172 | | case INF_SESSION_CLOSED: |
| 173 | | m_icon.set(Gtk::Stock::STOP, |
| 174 | | Gtk::ICON_SIZE_MENU); |
| 175 | | break; |
| 176 | | } |
| 177 | | } |
| 178 | | |
| 179 | | Gobby::DocWindow& m_document; |
| 180 | | Glib::ustring m_title; |
| 181 | | |
| 182 | | Gtk::Image m_icon; |
| 183 | | Gtk::Label m_label; |
| 184 | | Gobby::CloseButton m_button; |
| 185 | | |
| 186 | | gulong m_notify_editable_handle; |
| 187 | | gulong m_notify_status_handle; |
| 188 | | gulong m_notify_subscription_group_handle; |
| 189 | | }; |
| 190 | | |