void WidgetChatBubble::add_filerecv(Toxmm::EventFileRecv file) { auto msg_time = Glib::DateTime::create_now_utc(); // remove seconds msg_time = Glib::DateTime::create_utc(msg_time.get_year(), msg_time.get_month(), msg_time.get_day_of_month(), msg_time.get_hour(), msg_time.get_minute(), 0); bool display_time = true; if (m_last_timestamp != 0) { auto old_time = Glib::DateTime::create_now_utc(m_last_timestamp); // remove seconds old_time = Glib::DateTime::create_utc(old_time.get_year(), old_time.get_month(), old_time.get_day_of_month(), old_time.get_hour(), old_time.get_minute(), 0); // check display_time = !(msg_time.compare(old_time) == 0); } // create a new row auto msg = Gtk::manage(WidgetChatFileRecv::create(observable(), file)); auto time = Gtk::manage(new Gtk::Label()); m_last_timestamp = msg_time.to_unix(); // get local time msg_time = Glib::DateTime::create_now_local(m_last_timestamp); time->set_text(msg_time.format("%R")); // add to grid if (m_side == RIGHT) { rows.emplace_back(m_grid, m_row_count, *msg, *time); } else { rows.emplace_back(m_grid, m_row_count, *time, *msg); } m_row_count += 1; // styling time->set_halign(Gtk::ALIGN_CENTER); time->set_valign(Gtk::ALIGN_START); time->get_style_context()->add_class("bubble_chat_line_time"); msg->set_halign(Gtk::ALIGN_START); msg->set_valign(Gtk::ALIGN_CENTER); msg->show_all(); time->show_all(); time->set_no_show_all(); if (!display_time) { time->hide(); } }
void AwesomeBar::build_widgets() { set_margin_left(20); set_margin_right(20); set_margin_top(20); set_margin_bottom(20); set_no_show_all(); set_valign(Gtk::ALIGN_START); set_halign(Gtk::ALIGN_CENTER); entry_.set_width_chars(50); pack_start(entry_, false, false); entry_.signal_changed().connect([&]() { populate(entry_.get_text().c_str()); }); entry_.signal_activate().connect(sigc::mem_fun(this, &AwesomeBar::execute)); entry_.signal_focus_out_event().connect([=](GdkEventFocus* evt) -> bool { // Horrible hack on old Gtk+ auto minor_version = gtk_get_minor_version(); if(about_to_focus && minor_version < 12) { about_to_focus = false; entry_.grab_focus(); entry_.set_position(-1); return true; } entry_.hide(); entry_.set_text(""); return false; }); entry_.signal_key_press_event().connect([=](GdkEventKey* evt) -> bool { if(evt->keyval == GDK_KEY_Down || evt->keyval == GDK_KEY_Up) { /* * If we key up or down, change the selection in the list but * return false so that we don't lose focus on the box */ auto row = list_.get_selected_row(); if(!row) { return false; } auto idx = row->get_index(); idx += (evt->keyval == GDK_KEY_Down) ? 1 : -1; idx = std::max(idx, 0); idx = std::min(idx, (int32_t) displayed_files_.size()); about_to_focus = true; list_.select_row(*list_.get_row_at_index(idx)); return true; } return false; }); Pango::FontDescription desc("sans-serif 16"); entry_.override_font(desc); pack_start(list_revealer_, false, true, 0); list_window_.set_size_request(-1, 650); list_.set_activate_on_single_click(true); list_window_.add(list_); list_revealer_.add(list_window_); list_.set_hexpand(false); list_.signal_row_activated().connect([this](Gtk::ListBoxRow* row){ auto idx = row->get_index(); auto file = displayed_files_.at(idx); window_.open_document(file); hide(); }); }
void WidgetChatBubble::add_message(Line new_line) { auto msg_time = Glib::DateTime::create_now_utc(new_line.timestamp); // remove seconds msg_time = Glib::DateTime::create_utc(msg_time.get_year(), msg_time.get_month(), msg_time.get_day_of_month(), msg_time.get_hour(), msg_time.get_minute(), 0); bool display_time = true; if (m_last_timestamp != 0) { auto old_time = Glib::DateTime::create_now_utc(m_last_timestamp); // remove seconds old_time = Glib::DateTime::create_utc(old_time.get_year(), old_time.get_month(), old_time.get_day_of_month(), old_time.get_hour(), old_time.get_minute(), 0); // check display_time = !(msg_time.compare(old_time) == 0); } // create a new row auto msg = Gtk::manage(new WidgetChatLabel()); auto time = Gtk::manage(new Gtk::Label()); m_last_timestamp = new_line.timestamp; // get local time msg_time = Glib::DateTime::create_now_local(m_last_timestamp); time->set_text(msg_time.format("%R")); msg->set_text(new_line.message); // add to grid if (m_side == RIGHT) { rows.emplace_back(m_grid, m_row_count, *msg, *time); } else { rows.emplace_back(m_grid, m_row_count, *time, *msg); } if (new_line.wait_for_receipt) { rows.back().set_class("message_pending"); //callback ! auto nr = new_line.nr; auto receipt = new_line.receipt; auto index = rows.size() - 1; rows.back().tox_callback = observer_add([this, index, nr, receipt](const ToxEvent &ev) { //wait for receipt if (ev.type() == typeid(Toxmm::EventReadReceipt)) { auto& row = rows[index]; auto data = ev.get<Toxmm::EventReadReceipt>(); if (data.nr == nr) { if (data.receipt > receipt) { //message failed ! row.set_class("message_failed"); row.tox_callback.reset(); } else if (data.receipt == receipt) { //message got ! row.set_class("message_receipt"); row.tox_callback.reset(); } } } }); } if (new_line.error) { rows.back().set_class("message_failed"); } for(size_t i = 0; i < rows.size(); ++i) { rows[i].set_class(i == 0, i == rows.size()-1); } m_row_count += 1; // styling time->set_halign(Gtk::ALIGN_CENTER); time->set_valign(Gtk::ALIGN_START); time->get_style_context()->add_class("bubble_chat_line_time"); msg->set_halign(Gtk::ALIGN_START); msg->set_valign(Gtk::ALIGN_CENTER); msg->show_all(); time->show_all(); time->set_no_show_all(); if (!display_time) { time->hide(); } }