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 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(); } }
gboolean is_dst_in_effect(struct tm *time, gchar **zone_token) { guchar year; guchar start_hour, end_hour; guchar start_day, end_day; guchar start_week, end_week; guchar start_wkday, end_wkday; guchar start_month, end_month; gboolean rc; guchar zone_index; rc = FALSE; year = time->tm_year; if (zone_token[2] == NULL) { zone_index = 1; } else { zone_index = atoi(zone_token[2]); } if (zone_index != 0) zone_index--; start_hour = DST_TABLE[zone_index].start_hour; start_day = DST_TABLE[zone_index].start_day; start_week = DST_TABLE[zone_index].start_week; start_wkday = DST_TABLE[zone_index].start_weekday; start_month = DST_TABLE[zone_index].start_month; end_hour = DST_TABLE[zone_index].end_hour; end_day = DST_TABLE[zone_index].end_day; end_week = DST_TABLE[zone_index].end_week; end_wkday = DST_TABLE[zone_index].end_weekday; end_month = DST_TABLE[zone_index].end_month; /* * If start_day not provided, use information from start_week and * start_weekday to calculate start_day */ if (start_day == 0) start_day = get_day_of_month(start_wkday, start_week, start_month, year); /* * If end_day not provided, use information from end_week and * end_weekday to calculate end_day */ if (end_day == 0) end_day = get_day_of_month(end_wkday, end_week, end_month, year); // It is daylight saving time if: // the month consists entirely of daylight saving days // it is the starting month but after the begin date // it is the begin date but past the starting hour // it is the ending month but before the end date // it is the end date but before the ending hour if (((end_month > start_month) && // Northern hemisphere check (time->tm_mon > start_month) && (time->tm_mon < end_month)) || ((start_month > end_month) && // Southern hemisphere check ((time->tm_mon > start_month) || (time->tm_mon < end_month))) || ((time->tm_mon == start_month) && ((time->tm_mday > start_day) || ((time->tm_mday == start_day) && (time->tm_hour >= start_hour)))) || ((time->tm_mon == end_month) && ((time->tm_mday < end_day) || ((time->tm_mday == end_day) && (time->tm_hour < (end_hour-1)))))) { rc = TRUE; } return(rc); }