Beispiel #1
0
int NoteCollection::compareDates( const Glib::DateTime& a,
		const Glib::DateTime& b )
{
	int yearA = a.get_year();
	int yearB = b.get_year();
	if( yearA == yearB )
	{
		int dayA = a.get_day_of_year();
		int dayB = b.get_day_of_year();
		if( dayA == dayB )
		{
			return 0;
		}
		else if( dayA > dayB )
		{
			return 1;
		}
		else
		{
			return -1;
		}
	}
	else if( yearA > yearB )
	{
		return 1;
	}
	else
	{
		return -1;
	}
}
Beispiel #2
0
chat_action::chat_action(Glib::PropertyProxy_ReadOnly<Glib::ustring> name,
                           Glib::DateTime time,
                           const Glib::ustring& text):
    m_label(name, time.to_local(), text) {
    utils::debug::scope_log log(DBG_LVL_1("gtox"), {
                                    name.get_value().raw(),
                                    time.format("%c").raw(),
                                    text.raw()
                                });
    m_username.show();
    m_username.get_style_context()->add_class("gtox-action-username");
    m_username.property_valign() = Gtk::ALIGN_START;

    m_username_binding = Glib::Binding::bind_property(
                             name,
                             m_username.property_label(),
                             Glib::BINDING_DEFAULT | Glib::BINDING_SYNC_CREATE);

    show();
    add(m_hbox);
    m_hbox.show();
    m_hbox.add(m_username);
    m_hbox.add(m_label);
    property_reveal_child() = false;
    m_dispatcher.emit([this]() {
        utils::debug::scope_log log(DBG_LVL_1("gtox"), {});
        property_reveal_child() = true;
    });
}
Beispiel #3
0
	/* Runs in a separate thread */
	void Manager::check_threads() {
		// Build a list of threads that are past due for an update
		std::vector<std::pair<gint64, std::shared_ptr<Thread> > > threads_to_check;
		Glib::DateTime now = Glib::DateTime::create_now_utc();
			
		{
			Glib::Threads::Mutex::Lock lock(threads_mutex);
			threads_to_check.reserve(threads.size());
			std::copy_if(threads.begin(),
			             threads.end(),
			             std::back_inserter(threads_to_check),
			             [&now](std::pair<gint64, std::shared_ptr<Thread> > pair) {
				             std::shared_ptr<Thread> t = pair.second;
				             Glib::TimeSpan diff = std::abs(now.difference(t->last_checked));
				             return ( diff > t->get_update_interval() &&
				                      !t->is_404 );
			             });
		}

		for ( auto pair : threads_to_check ) {
			auto thread = pair.second;
			try{
				Glib::Threads::Mutex::Lock lock(curler_mutex);
				std::list<Glib::RefPtr<Post> > posts = curler.pullThread(thread);
				thread->last_checked = Glib::DateTime::create_now_utc();

				if (posts.size() > 0) {
					auto iter = posts.rbegin();
					thread->last_post = Glib::DateTime::create_now_utc((*iter)->get_unix_time());
					thread->updatePosts(posts);
					push_updated_thread(thread->id);
				}
			} catch (Thread404 e) {
				thread->is_404 = true;
				push_updated_thread(thread->id);
				on_404(thread->id);
			} catch (Concurrency e) {
				// This should be impossible since we are using the mutex.
				g_critical("Manager's Curler is being used by more than one thread.");
			} catch (TooFast e) {
				g_warning("Attempted to hit the 4chan JSON API faster than once a second.");
			} catch (CurlException e) {
				g_warning("Got Curl error: %s", e.what());
			}
		} // for threads_to_check

		signal_thread_updated();
	}
std::string StringUtils::dateToString(const Glib::DateTime& date){
	/* Recibe una fecha y hora tipo Glib::DateTime y devuelve una cadena formateada "dd/mm/aa-hh:mm" */
	std::stringstream s;
	std::string ss;
	s << date.format("%d/%m/%Y-%H:%M");
	s >> ss;
	return ss;
}
Beispiel #5
0
chat_action::label::label(Glib::PropertyProxy_ReadOnly<Glib::ustring> name,
                           Glib::DateTime time,
                           const Glib::ustring& message):
    widget::label(message),
    m_name(name),
    m_time(time) {
    utils::debug::scope_log log(DBG_LVL_1("gtox"), {
                                    name.get_value().raw(),
                                    time.format("%c").raw(),
                                    message.raw()
                                });
}