コード例 #1
0
ファイル: spellcheck.c プロジェクト: zakkudo/gwaei
static void 
gw_spellcheck_remove_signals (GwSpellcheck *spellcheck)
{
    //Declarations
    GwSpellcheckPrivate *priv;
    LwPreferences *preferences;
    GtkEntry *entry;
    GSource *source;
    int i;

    priv = spellcheck->priv;
    preferences = gw_application_get_preferences (priv->application);
    entry = priv->entry;

    if (priv->signalid[GW_SPELLCHECK_SIGNALID_DICTIONARY] != 0)
    {
      lw_preferences_remove_change_listener_by_schema (
          preferences, 
          LW_SCHEMA_BASE, 
          priv->signalid[GW_SPELLCHECK_SIGNALID_DICTIONARY]
      );
      priv->signalid[GW_SPELLCHECK_SIGNALID_DICTIONARY] = 0;
    }

    if (priv->signalid[GW_SPELLCHECK_SIGNALID_RK_CONV] != 0)
    {
      lw_preferences_remove_change_listener_by_schema (
          preferences, 
          LW_SCHEMA_BASE, 
          priv->signalid[GW_SPELLCHECK_SIGNALID_RK_CONV]
      );
      priv->signalid[GW_SPELLCHECK_SIGNALID_RK_CONV] = 0;
    }

    for (i = 0; i < TOTAL_GW_SPELLCHECK_SIGNALIDS && entry != NULL; i++)
    {
      if (priv->signalid[i] > 0)
      {
        g_signal_handler_disconnect (G_OBJECT (entry), priv->signalid[i]);
        priv->signalid[i] = 0;
      }
    }

    for (i = 0; i < TOTAL_GW_SPELLCHECK_TIMEOUTIDS; i++)
    {
      if (g_main_current_source () != NULL &&
          !g_source_is_destroyed (g_main_current_source ()) &&
          priv->timeoutid[i] > 0
         )
      {
        source = g_main_context_find_source_by_id (NULL, priv->timeoutid[i]);
        if (source != NULL)
        {
          g_source_destroy (source);
        }
      }
      priv->timeoutid[i] = 0;
    }
}
コード例 #2
0
ファイル: kanjipadwindow.c プロジェクト: kyoushuu/gwaei
static void
gw_kanjipadwindow_finalize (GObject *object)
{
    GwKanjipadWindow *window;
    GwKanjipadWindowPrivate *priv;
    GSource *source;
    GError *error;
    GList *link;

    window = GW_KANJIPADWINDOW (object);
    priv = window->priv;
    error = NULL;

    for (link = priv->strokes; link != NULL; link = link->next)
      gw_kanjipadwindow_free_drawingarea_stroke (link->data);
    if (priv->strokes != NULL) g_list_free (priv->strokes); priv->strokes = NULL;
    if (priv->strokes != NULL) g_list_free (priv->curstroke); priv->curstroke = NULL;

    if (priv->ksurface != NULL) cairo_surface_destroy (priv->ksurface); priv->ksurface = NULL;
    if (priv->surface != NULL) cairo_surface_destroy (priv->surface); priv->surface = NULL;

    if (g_main_current_source () != NULL &&
        !g_source_is_destroyed (g_main_current_source ()) &&
        priv->iowatchid > 0
       )
    {
      source = g_main_context_find_source_by_id (NULL, priv->iowatchid);
      if (source != NULL)
      {
        g_source_destroy (source);
      }
    }
    priv->iowatchid = 0;

    if (error == NULL) 
    {
      g_io_channel_shutdown (priv->from_engine, FALSE, &error);
      g_io_channel_unref (priv->from_engine);
      priv->from_engine = NULL;
    }

    if (error == NULL)
    {
      g_io_channel_shutdown (priv->to_engine, FALSE, &error);
      g_io_channel_unref (priv->to_engine);
      priv->to_engine = NULL;
    }

    g_spawn_close_pid (priv->engine_pid);

    if (error != NULL)
    {
      fprintf(stderr, "Errored: %s\n", error->message);
      exit(EXIT_FAILURE);
    }

    G_OBJECT_CLASS (gw_kanjipadwindow_parent_class)->finalize (object);
}
コード例 #3
0
static gboolean
gum_flush_pending_unignores (gpointer user_data)
{
  GumJscScriptBackend * self = GUM_JSC_SCRIPT_BACKEND (user_data);
  GumJscScriptBackendPrivate * priv = self->priv;

  gum_interceptor_ignore_current_thread (priv->interceptor);

  g_rw_lock_writer_lock (&priv->ignored_lock);

  if (priv->pending_timeout == g_main_current_source ())
  {
    g_source_unref (priv->pending_timeout);
    priv->pending_timeout = NULL;
  }

  while (priv->pending_unignores != NULL)
  {
    GumThreadId thread_id;

    thread_id = GPOINTER_TO_SIZE (priv->pending_unignores->data);
    priv->pending_unignores = g_slist_delete_link (priv->pending_unignores,
        priv->pending_unignores);
    gum_jsc_script_backend_adjust_ignore_level_unlocked (self, thread_id, -1);
  }

  g_rw_lock_writer_unlock (&priv->ignored_lock);

  gum_interceptor_unignore_current_thread (priv->interceptor);

  return FALSE;
}
コード例 #4
0
ファイル: thermal.c プロジェクト: bluemutedwisdom/lxpanel
static gboolean update_display_timeout(gpointer user_data)
{
    if (g_source_is_destroyed(g_main_current_source()))
        return FALSE;
    update_display(user_data);
    return TRUE; /* repeat later */
}
コード例 #5
0
static gboolean
animate_expander (gpointer data)
{
	GtkLayout *layout;
	GdkWindow *window;
	animate_closure_t *closure = (animate_closure_t *) data;
	cairo_t *cr;

	if (g_source_is_destroyed (g_main_current_source ()))
		return FALSE;

	if (closure->finish) {
		e_tree_table_adapter_node_set_expanded (closure->etta, closure->node, !closure->expanded);
		closure->ectv->animate_timeout = 0;
		return FALSE;
	}

	layout = GTK_LAYOUT (closure->ectv->canvas);
	window = gtk_layout_get_bin_window (layout);

	cr = gdk_cairo_create (window);

	draw_expander (
		closure->ectv, cr, closure->expanded ?
		GTK_EXPANDER_SEMI_COLLAPSED :
		GTK_EXPANDER_SEMI_EXPANDED,
		GTK_STATE_NORMAL, &closure->area);
	closure->finish = TRUE;

	cairo_destroy (cr);

	return TRUE;
}
コード例 #6
0
ファイル: shm-writer.c プロジェクト: goodinges/Ciao-Chat
static gboolean
shm_writer_client_fd_cb (GIOChannel *source,
    GIOCondition condition,
    gpointer data)
{
  ShmWriterClientPair *pair = data;
  ShmWriterPrivate *priv = pair->self->priv;

  if (condition == G_IO_IN)
    {
      g_mutex_lock (priv->lock);
      if (sp_writer_recv (pair->self->priv->writer, pair->client) != 0)
        goto error_locked;
      g_mutex_unlock (priv->lock);
    }
  else if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
    {
      goto error;
    }

  return TRUE;

error:
  g_mutex_lock (priv->lock);
error_locked:
  if (priv->writer != NULL)
    sp_writer_close_client (priv->writer, pair->client);
  g_mutex_unlock (priv->lock);

  /* No need to destroy the source when the writer is destroyed.
   * We're destroying it here */
  g_object_weak_unref (G_OBJECT (pair->self),
      shm_writer_destroy_source, g_main_current_source ());
  return FALSE;
}
コード例 #7
0
ファイル: soup-address.c プロジェクト: I486DX2/libsoup
static void
complete_resolve_async (SoupAddressResolveAsyncData *res_data, guint status)
{
	GSource *current_source;
	GMainContext *current_context;

	if (res_data->callback) {
		/* Awful hack; to make soup_socket_connect_async()
		 * with an non-default async_context work correctly,
		 * we need to ensure that the non-default context
		 * (which we're now running in) is the thread-default
		 * when the callbacks are run...
		 */
		current_source = g_main_current_source ();
		if (current_source && !g_source_is_destroyed (current_source))
			current_context = g_source_get_context (current_source);
		else
			current_context = NULL;
		g_main_context_push_thread_default (current_context);

		res_data->callback (res_data->addr, status,
				    res_data->callback_data);

		g_main_context_pop_thread_default (current_context);
	}

	g_object_unref (res_data->addr);
	g_slice_free (SoupAddressResolveAsyncData, res_data);
}
コード例 #8
0
ファイル: discovery.c プロジェクト: slkwyy/libnice
static gboolean priv_discovery_tick (gpointer pointer)
{
  NiceAgent *agent = pointer;
  gboolean ret;

  agent_lock();
  if (g_source_is_destroyed (g_main_current_source ())) {
    nice_debug ("Source was destroyed. "
        "Avoided race condition in priv_discovery_tick");
    agent_unlock ();
    return FALSE;
  }

  ret = priv_discovery_tick_unlocked (pointer);
  if (ret == FALSE) {
    if (agent->discovery_timer_source != NULL) {
      g_source_destroy (agent->discovery_timer_source);
      g_source_unref (agent->discovery_timer_source);
      agent->discovery_timer_source = NULL;
    }
  }
  agent_unlock_and_emit (agent);

  return ret;
}
コード例 #9
0
ファイル: fm-module.c プロジェクト: threarth/libfm
static gboolean _fm_modules_on_idle(gpointer user_data)
{
    /* check if it is destroyed already */
    if(g_source_is_destroyed(g_main_current_source()))
        return FALSE;
    G_LOCK(idle_handler);
    idle_handler = 0;
    G_UNLOCK(idle_handler);
    fm_modules_load();
    return FALSE;
}
コード例 #10
0
static gboolean
async_timeout_cb (GstDiscoverer * dc)
{
  if (!g_source_is_destroyed (g_main_current_source ())) {
    dc->priv->timeoutid = 0;
    GST_DEBUG ("Setting result to TIMEOUT");
    dc->priv->current_info->result = GST_DISCOVERER_TIMEOUT;
    dc->priv->processing = FALSE;
    discoverer_collect (dc);
    discoverer_cleanup (dc);
  }
  return FALSE;
}
コード例 #11
0
ファイル: settingswindow.c プロジェクト: kyoushuu/gwaei
static void 
gw_settingswindow_finalize (GObject *object)
{
    GwSettingsWindow *window;
    GwApplication *application;

    window = GW_SETTINGSWINDOW (object);
    application = gw_window_get_application (GW_WINDOW (window));

    if (g_main_current_source () != NULL) gw_application_unblock_searches (application);

    G_OBJECT_CLASS (gw_settingswindow_parent_class)->finalize (object);
}
コード例 #12
0
static gboolean emit_found_files(gpointer user_data)
{
    /* this callback is called from the main thread */
    FmDirListJob* job = FM_DIR_LIST_JOB(user_data);
    /* g_print("emit_found_files: %d\n", g_slist_length(job->files_to_add)); */

    if(g_source_is_destroyed(g_main_current_source()))
        return FALSE;
    g_signal_emit(job, signals[FILES_FOUND], 0, job->files_to_add);
    g_slist_free_full(job->files_to_add, (GDestroyNotify)fm_file_info_unref);
    job->files_to_add = NULL;
    job->delay_add_files_handler = 0;
    return FALSE;
}
コード例 #13
0
ファイル: gdk.c プロジェクト: 3v1n0/gtk
static gboolean
gdk_threads_dispatch (gpointer data)
{
  GdkThreadsDispatch *dispatch = data;
  gboolean ret = FALSE;

  gdk_threads_enter ();

  if (!g_source_is_destroyed (g_main_current_source ()))
    ret = dispatch->func (dispatch->data);

  gdk_threads_leave ();

  return ret;
}
コード例 #14
0
ファイル: utils_gui.c プロジェクト: menghun3/aqualung
static gboolean
threads_dispatch(gpointer data) {

	threads_dispatch_t * dispatch = data;
	gboolean ret = FALSE;

	GDK_THREADS_ENTER();

	if (!g_source_is_destroyed(g_main_current_source())) {
		ret = dispatch->func(dispatch->data);
	}

	GDK_THREADS_LEAVE();

	return ret;
}
コード例 #15
0
static gboolean on_update_dlg(gpointer user_data)
{
    FmProgressDisplay* data = (FmProgressDisplay*)user_data;
    /* the g_strdup very probably returns the same pointer that was g_free'd
       so we cannot just compare data->old_cur_file with data->cur_file */
    GDK_THREADS_ENTER();
    if(!g_source_is_destroyed(g_main_current_source()) && data->cur_file)
    {
        gtk_label_set_text(data->current, data->cur_file);
        g_free(data->old_cur_file);
        data->old_cur_file = data->cur_file;
        data->cur_file = NULL;
    }
    GDK_THREADS_LEAVE();
    return TRUE;
}
コード例 #16
0
ファイル: shm-writer.c プロジェクト: goodinges/Ciao-Chat
static gboolean
shm_writer_fd_cb (GIOChannel *source,
    GIOCondition condition,
    gpointer data)
{
  ShmWriterPrivate *priv = SHM_WRITER (data)->priv;

  if (condition == G_IO_IN)
    {
      ShmWriterClientPair *pair;
      ShmClient *client;
      int fd;

      client = sp_writer_accept_client (priv->writer);

      if (client == NULL)
        goto out;

      /* Start listening on this socket.
       * This socket is used for the actual shm data transfer signaling
       * of an individual client. So when this socket is closed, the
       * client associated with this particular socket has disconnected */
      pair = g_slice_new0 (ShmWriterClientPair);
      pair->self = data;
      pair->client = client;

      fd = sp_writer_get_client_fd (client);

      shm_writer_add_fd_source (data, fd, shm_writer_client_fd_cb,
          pair, (GDestroyNotify)shm_writer_client_pair_free);
    }
  else if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
    {
      goto out;
    }

  return TRUE;

out:
  shm_writer_close (data);

  /* No need to destroy the source when the writer is destroyed.
   * We're destroying it here */
  g_object_weak_unref (G_OBJECT (data),
      shm_writer_destroy_source, g_main_current_source ());
  return FALSE;
}
コード例 #17
0
ファイル: soup-address.c プロジェクト: NEVERMOR/libsoup
static void
complete_resolve_async (SoupAddress *addr, guint status)
{
	SoupAddressPrivate *priv = SOUP_ADDRESS_GET_PRIVATE (addr);
	SoupAddressResolveAsyncData *res_data;
	GSList *lookups, *l;
	GSource *current_source;
	GMainContext *current_context;

	lookups = priv->async_lookups;
	priv->async_lookups = NULL;

	/* Awful hack; to make soup_socket_connect_async() with an
	 * non-default async_context work correctly, we need to ensure
	 * that the non-default context (which we're now running in)
	 * is the thread-default when the callbacks are run...
	 */
	current_source = g_main_current_source ();
	if (current_source && !g_source_is_destroyed (current_source))
		current_context = g_source_get_context (current_source);
	else
		current_context = NULL;
	g_main_context_push_thread_default (current_context);

	for (l = lookups; l; l = l->next) {
		res_data = l->data;

		if (res_data->callback) {
			res_data->callback (addr, status,
					    res_data->callback_data);
		}
		g_slice_free (SoupAddressResolveAsyncData, res_data);
	}
	g_slist_free (lookups);

	g_main_context_pop_thread_default (current_context);

	g_object_unref (addr);
}
コード例 #18
0
static gboolean
_g_ssl_input_stream_read_ready(gpointer data)
{
	GSSLInputStream *stream = (GSSLInputStream *)data;
	GSimpleAsyncResult *simple;
	GError *error = NULL;
	gssize result;

	g_assert(stream != NULL);
	g_assert(stream->priv->result != NULL);

	if(!g_source_is_destroyed(g_main_current_source()))
	{
		simple = stream->priv->result;
		stream->priv->result = NULL;

		if((result = openssl_read(stream->priv->ssl, stream->priv->buffer, stream->priv->count, stream->priv->cancellable, &error)) > 0)
		{
			g_simple_async_result_set_op_res_gssize(simple, result);
		}

		if(error)
		{
			g_simple_async_result_set_from_error(simple, error);
			g_error_free(error);
		}

		if(stream->priv->cancellable)
		{
			g_object_unref(stream->priv->cancellable);
		}

		g_simple_async_result_complete(simple);
		g_object_unref(simple);
	}

	return FALSE;
}
コード例 #19
0
ファイル: tcp-bsd.c プロジェクト: kakaroto/libnice
static gboolean
socket_send_more (
  GSocket *gsocket,
  GIOCondition condition,
  gpointer data)
{
  NiceSocket *sock = (NiceSocket *) data;
  TcpPriv *priv = sock->priv;

  agent_lock (NULL);

  if (g_source_is_destroyed (g_main_current_source ())) {
    nice_debug ("Source was destroyed. "
        "Avoided race condition in tcp-bsd.c:socket_send_more");
    agent_unlock (NULL);
    return FALSE;
  }

  /* connection hangs up or queue was emptied */
  if (condition & G_IO_HUP ||
      nice_socket_flush_send_queue_to_socket (sock->fileno,
          &priv->send_queue)) {
    g_source_destroy (priv->io_source);
    g_source_unref (priv->io_source);
    priv->io_source = NULL;

    agent_unlock (NULL);

    if (priv->writable_cb)
      priv->writable_cb (sock, priv->writable_data);

    return FALSE;
  }

  agent_unlock (NULL);
  return TRUE;
}
コード例 #20
0
ファイル: monitors.c プロジェクト: setzer22/lxpanel
/*
 * This function is called every UPDATE_PERIOD seconds. It updates all
 * monitors.
 */
static gboolean
monitors_update(gpointer data)
{
    MonitorsPlugin *mp;
    int i;

    if (g_source_is_destroyed(g_main_current_source()))
        return FALSE;
    mp = (MonitorsPlugin *) data;
    if (!mp)
        RET(FALSE);

    for (i = 0; i < N_MONITORS; i++)
    {
        if (mp->monitors[i])
        {
            mp->monitors[i]->update(mp->monitors[i]);
            if (mp->monitors[i]->update_tooltip)
                mp->monitors[i]->update_tooltip(mp->monitors[i]);
        }
    }

    return TRUE;
}
コード例 #21
0
ファイル: dasom-im.c プロジェクト: namwonkeun/dasom
static gboolean
on_incoming_message (GSocket      *socket,
                     GIOCondition  condition,
                     gpointer      user_data)
{
  g_debug (G_STRLOC ": %s: socket fd:%d", G_STRFUNC, g_socket_get_fd (socket));

  DasomIM *im = DASOM_IM (user_data);
  dasom_message_unref (im->result->reply);
  im->result->is_dispatched = TRUE;

  if (condition & (G_IO_HUP | G_IO_ERR))
  {
    /* Because two GSource is created over one socket,
     * when G_IO_HUP | G_IO_ERR, callback can run two times.
     * the following code avoid that callback runs two times. */
    GSource *source = g_main_current_source ();

    if (source == im->default_context_source)
      g_source_destroy (im->sockets_context_source);
    else if (source == im->sockets_context_source)
      g_source_destroy (im->default_context_source);

    if (!g_socket_is_closed (socket))
      g_socket_close (socket, NULL);

    im->result->reply    = NULL;

    g_critical (G_STRLOC ": %s: G_IO_HUP | G_IO_ERR", G_STRFUNC);

    return G_SOURCE_REMOVE;
  }

  DasomMessage *message;
  message = dasom_recv_message (socket);
  im->result->reply = message;
  gboolean retval;

  if (G_UNLIKELY (message == NULL))
  {
    g_critical (G_STRLOC ": NULL message");
    return G_SOURCE_CONTINUE;
  }

  switch (message->header->type)
  {
    /* reply */
    case DASOM_MESSAGE_FILTER_EVENT_REPLY:
    case DASOM_MESSAGE_RESET_REPLY:
    case DASOM_MESSAGE_FOCUS_IN_REPLY:
    case DASOM_MESSAGE_FOCUS_OUT_REPLY:
    case DASOM_MESSAGE_SET_SURROUNDING_REPLY:
    case DASOM_MESSAGE_GET_SURROUNDING_REPLY:
    case DASOM_MESSAGE_SET_CURSOR_LOCATION_REPLY:
    case DASOM_MESSAGE_SET_USE_PREEDIT_REPLY:
      break;
    /* signals */
    case DASOM_MESSAGE_PREEDIT_START:
      g_signal_emit_by_name (im, "preedit-start");
      dasom_send_message (socket, DASOM_MESSAGE_PREEDIT_START_REPLY, NULL, 0, NULL);
      break;
    case DASOM_MESSAGE_PREEDIT_END:
      g_signal_emit_by_name (im, "preedit-end");
      dasom_send_message (socket, DASOM_MESSAGE_PREEDIT_END_REPLY, NULL, 0, NULL);
      break;
    case DASOM_MESSAGE_PREEDIT_CHANGED:
      g_free (im->preedit_string);
      im->preedit_string = g_strndup (message->data,
                                      message->header->data_len - 1 - sizeof (gint));
      im->cursor_pos = *(gint *) (message->data +
                                  message->header->data_len - sizeof (gint));
      g_signal_emit_by_name (im, "preedit-changed");
      dasom_send_message (socket,
                          DASOM_MESSAGE_PREEDIT_CHANGED_REPLY,
                          NULL, 0, NULL);
      break;
    case DASOM_MESSAGE_COMMIT:
      dasom_message_ref (message);
      g_signal_emit_by_name (im, "commit", (const gchar *) message->data);
      dasom_message_unref (message);
      dasom_send_message (socket, DASOM_MESSAGE_COMMIT_REPLY, NULL, 0, NULL);
      break;
    case DASOM_MESSAGE_RETRIEVE_SURROUNDING:
      g_signal_emit_by_name (im, "retrieve-surrounding", &retval);
      dasom_send_message (socket, DASOM_MESSAGE_RETRIEVE_SURROUNDING_REPLY,
                          &retval, sizeof (gboolean), NULL);
      break;
    case DASOM_MESSAGE_DELETE_SURROUNDING:
      dasom_message_ref (message);
      g_signal_emit_by_name (im, "delete-surrounding",
                             ((gint *) message->data)[0],
                             ((gint *) message->data)[1], &retval);
      dasom_message_unref (message);
      dasom_send_message (socket, DASOM_MESSAGE_DELETE_SURROUNDING_REPLY,
                          &retval, sizeof (gboolean), NULL);
      break;
    default:
      g_warning (G_STRLOC ": %s: Unknown message type: %d", G_STRFUNC, message->header->type);
      break;
  }

  return G_SOURCE_CONTINUE;
}
コード例 #22
0
ファイル: fm-progress-dlg.c プロジェクト: lxde/libfm
static gboolean on_update_dlg(gpointer user_data)
{
    FmProgressDisplay* data = (FmProgressDisplay*)user_data;
    gdouble elapsed;

    char* data_transferred_str;
    char trans_size_str[128];
    char total_size_str[128];

    if (g_source_is_destroyed(g_main_current_source()) || data->dlg == NULL)
        return FALSE;
    data->update_timeout = 0;
    /* the g_strdup very probably returns the same pointer that was g_free'd
       so we cannot just compare data->old_cur_file with data->cur_file */
    if(data->cur_file && data->current)
    {
        g_string_printf(data->str, "<i>%s %s</i>", data->op_text, data->cur_file);
        gtk_label_set_markup(data->current, data->str->str);
        gtk_widget_set_tooltip_text(GTK_WIDGET(data->current), data->cur_file);
        g_free(data->old_cur_file);
        data->old_cur_file = data->cur_file;
        data->cur_file = NULL;
    }
    g_string_printf(data->str, "%d %%", data->percent);
    gtk_progress_bar_set_fraction(data->progress, (gdouble)data->percent/100);
    gtk_progress_bar_set_text(data->progress, data->str->str);

    /* display the amount of data transferred */
    fm_file_size_to_str(trans_size_str, sizeof(trans_size_str),
        data->data_transferred_size, fm_config->si_unit);
    fm_file_size_to_str(total_size_str, sizeof(total_size_str),
        data->data_total_size, fm_config->si_unit);
    data_transferred_str = g_strdup_printf("%s / %s", trans_size_str, total_size_str);
    gtk_label_set_text(data->data_transferred, data_transferred_str);
    g_free(data_transferred_str);

    elapsed = g_timer_elapsed(data->timer, NULL);
    if(elapsed >= 0.5 && data->percent > 0)
    {
        gdouble remaining = elapsed * (100 - data->percent) / data->percent;
        if(data->remaining_time)
        {
            char time_str[32];
            guint secs = (guint)remaining;
            guint mins = 0;
            guint hrs = 0;
            if(secs >= 60)
            {
                mins = secs / 60;
                secs %= 60;
                if(mins >= 60)
                {
                    hrs = mins / 60;
                    mins %= 60;
                }
            }
            g_snprintf(time_str, 32, "%02d:%02d:%02d", hrs, mins, secs);
            gtk_label_set_text(data->remaining_time, time_str);
        }
    }
    return FALSE;
}
コード例 #23
0
ファイル: tcp-bsd.c プロジェクト: helloIAmPau/libnice
static gboolean
socket_send_more (
  GSocket *gsocket,
  GIOCondition condition,
  gpointer data)
{
  NiceSocket *sock = (NiceSocket *) data;
  TcpPriv *priv = sock->priv;
  struct to_be_sent *tbs = NULL;
  GError *gerr = NULL;

  agent_lock ();

  if (g_source_is_destroyed (g_main_current_source ())) {
    nice_debug ("Source was destroyed. "
        "Avoided race condition in tcp-bsd.c:socket_send_more");
    agent_unlock ();
    return FALSE;
  }

  while ((tbs = g_queue_pop_head (&priv->send_queue)) != NULL) {
    int ret;

    if(condition & G_IO_HUP) {
      /* connection hangs up */
      ret = -1;
    } else {
      GOutputVector local_bufs = { tbs->buf, tbs->length };
      ret = g_socket_send_message (sock->fileno, NULL, &local_bufs, 1, NULL, 0,
          G_SOCKET_MSG_NONE, NULL, &gerr);
    }

    if (ret < 0) {
      if (g_error_matches (gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
        GOutputVector local_buf = { tbs->buf, tbs->length };
        NiceOutputMessage local_message = {&local_buf, 1};

        add_to_be_sent (sock, &local_message, 0, local_buf.size, TRUE);
        free_to_be_sent (tbs);
        g_error_free (gerr);
        break;
      }
      g_clear_error (&gerr);
    } else if (ret < (int) tbs->length) {
      GOutputVector local_buf = { tbs->buf + ret, tbs->length - ret };
      NiceOutputMessage local_message = {&local_buf, 1};

      add_to_be_sent (sock, &local_message, 0, local_buf.size, TRUE);
      free_to_be_sent (tbs);
      break;
    }

    free_to_be_sent (tbs);
  }

  if (g_queue_is_empty (&priv->send_queue)) {
    g_source_destroy (priv->io_source);
    g_source_unref (priv->io_source);
    priv->io_source = NULL;

    agent_unlock ();
    return FALSE;
  }

  agent_unlock ();
  return TRUE;
}
コード例 #24
0
static gboolean on_show_dlg(gpointer user_data)
{
    FmProgressDisplay* data = (FmProgressDisplay*)user_data;
    GtkBuilder* builder;
    GtkLabel* to;
    GtkWidget *to_label;
    FmPath* dest;
    const char* title = NULL;
    GtkTextTagTable* tag_table;

    GDK_THREADS_ENTER();
    if(g_source_is_destroyed(g_main_current_source()))
        goto _end;

    builder = gtk_builder_new();
    tag_table = gtk_text_tag_table_new();
    gtk_builder_set_translation_domain(builder, GETTEXT_PACKAGE);
    gtk_builder_add_from_file(builder, PACKAGE_UI_DIR "/progress.ui", NULL);

    data->dlg = GTK_DIALOG(gtk_builder_get_object(builder, "dlg"));
    g_object_weak_ref(G_OBJECT(data->dlg), on_progress_dialog_destroy, data);

    g_signal_connect(data->dlg, "response", G_CALLBACK(on_response), data);
    /* FIXME: connect to "close" signal */

    to_label = (GtkWidget*)gtk_builder_get_object(builder, "to_label");
    to = GTK_LABEL(gtk_builder_get_object(builder, "dest"));
    data->icon = GTK_IMAGE(gtk_builder_get_object(builder, "icon"));
    data->msg = GTK_LABEL(gtk_builder_get_object(builder, "msg"));
    data->act = GTK_LABEL(gtk_builder_get_object(builder, "action"));
    data->src = GTK_LABEL(gtk_builder_get_object(builder, "src"));
    data->dest = (GtkWidget*)gtk_builder_get_object(builder, "dest");
    data->current = GTK_LABEL(gtk_builder_get_object(builder, "current"));
    data->progress = GTK_PROGRESS_BAR(gtk_builder_get_object(builder, "progress"));
    data->error_pane = (GtkWidget*)gtk_builder_get_object(builder, "error_pane");
    data->error_msg = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "error_msg"));
    data->remaining_time = GTK_LABEL(gtk_builder_get_object(builder, "remaining_time"));

    data->bold_tag = gtk_text_tag_new("bold");
    g_object_set(data->bold_tag, "weight", PANGO_WEIGHT_BOLD, NULL);
    gtk_text_tag_table_add(tag_table, data->bold_tag);
    data->error_buf = gtk_text_buffer_new(tag_table);
    g_object_unref(tag_table);
    gtk_text_view_set_buffer(data->error_msg, data->error_buf);

    g_object_unref(builder);

    /* set the src label */
    /* FIXME: direct access to job struct! */
    if(data->job->srcs)
    {
        GList* l = fm_path_list_peek_head_link(data->job->srcs);
        int i;
        char* disp;
        FmPath* path;
        GString* str = g_string_sized_new(512);
        path = FM_PATH(l->data);
        disp = fm_path_display_basename(path);
        g_string_assign(str, disp);
        g_free(disp);
        for( i =1, l=l->next; i < 10 && l; l=l->next, ++i)
        {
            path = FM_PATH(l->data);
            g_string_append(str, _(", "));
            disp = fm_path_display_basename(path);
            g_string_append(str, disp);
            g_free(disp);
        }
        if(l)
            g_string_append(str, "...");
        gtk_label_set_text(data->src, str->str);
        g_string_free(str, TRUE);
    }

    /* FIXME: use accessor functions instead */
    /* FIXME: direct access to job struct! */
    switch(data->job->type)
    {
    case FM_FILE_OP_MOVE:
        title = _("Moving files");
        break;
    case FM_FILE_OP_COPY:
        title = _("Copying files");
        break;
    case FM_FILE_OP_TRASH:
        title = _("Trashing files");
        break;
    case FM_FILE_OP_DELETE:
        title = _("Deleting files");
        break;
    case FM_FILE_OP_LINK:
        title = _("Creating symlinks");
        break;
    case FM_FILE_OP_CHANGE_ATTR:
        title = _("Changing file attributes");
        break;
    case FM_FILE_OP_UNTRASH:
        break;
    case FM_FILE_OP_NONE: ;
    }
    if(title)
    {
        gtk_window_set_title(GTK_WINDOW(data->dlg), title);
        gtk_label_set_text(data->act, title);
    }

    dest = fm_file_ops_job_get_dest(data->job);
    if(dest)
    {
        char* dest_str = fm_path_display_name(dest, TRUE);
        gtk_label_set_text(to, dest_str);
        g_free(dest_str);
    }
    else
    {
        gtk_widget_destroy(data->dest);
        gtk_widget_destroy(to_label);
    }

    gtk_window_set_transient_for(GTK_WINDOW(data->dlg), data->parent);
    gtk_window_present(GTK_WINDOW(data->dlg));
    data->update_timeout = g_timeout_add(500, on_update_dlg, data);

    data->delay_timeout = 0;
_end:
    GDK_THREADS_LEAVE();
    return FALSE;
}
コード例 #25
0
ファイル: caja-progress-info.c プロジェクト: City-busz/caja
static gboolean
idle_callback (gpointer data)
{
    CajaProgressInfo *info = data;
    gboolean start_at_idle;
    gboolean finish_at_idle;
    gboolean changed_at_idle;
    gboolean progress_at_idle;
    GSource *source;

    source = g_main_current_source ();

    G_LOCK (progress_info);

    /* Protect agains races where the source has
       been destroyed on another thread while it
       was being dispatched.
       Similar to what gdk_threads_add_idle does.
    */
    if (g_source_is_destroyed (source))
    {
        G_UNLOCK (progress_info);
        return FALSE;
    }

    /* We hadn't destroyed the source, so take a ref.
     * This might ressurect the object from dispose, but
     * that should be ok.
     */
    g_object_ref (info);

    g_assert (source == info->idle_source);

    g_source_unref (source);
    info->idle_source = NULL;

    start_at_idle = info->start_at_idle;
    finish_at_idle = info->finish_at_idle;
    changed_at_idle = info->changed_at_idle;
    progress_at_idle = info->progress_at_idle;

    info->start_at_idle = FALSE;
    info->finish_at_idle = FALSE;
    info->changed_at_idle = FALSE;
    info->progress_at_idle = FALSE;

    G_UNLOCK (progress_info);

    if (start_at_idle)
    {
        g_signal_emit (info,
                       signals[STARTED],
                       0);
    }

    if (changed_at_idle)
    {
        g_signal_emit (info,
                       signals[CHANGED],
                       0);
    }

    if (progress_at_idle)
    {
        g_signal_emit (info,
                       signals[PROGRESS_CHANGED],
                       0);
    }

    if (finish_at_idle)
    {
        g_signal_emit (info,
                       signals[FINISHED],
                       0);
    }

    g_object_unref (info);

    return FALSE;
}
コード例 #26
0
ファイル: fm-progress-dlg.c プロジェクト: lxde/libfm
static gboolean on_show_dlg(gpointer user_data)
{
    if(g_source_is_destroyed(g_main_current_source()))
        return FALSE;
    return _on_show_dlg(user_data);
}
コード例 #27
0
ファイル: settingswindow.c プロジェクト: kyoushuu/gwaei
static void 
gw_settingswindow_constructed (GObject *object)
{
    //Declarations
    GwSettingsWindow *window;
    GwSettingsWindowPrivate *priv;
    GwApplication *application;
    LwDictionaryList *dictionarylist;
    GtkAccelGroup *accelgroup;

    //Chain the parent class
    {
      G_OBJECT_CLASS (gw_settingswindow_parent_class)->constructed (object);
    }

    //Initializations
    window = GW_SETTINGSWINDOW (object);
    priv = window->priv;
    accelgroup = gw_window_get_accel_group (GW_WINDOW (window));
    application = gw_window_get_application (GW_WINDOW (window));
    dictionarylist = LW_DICTIONARYLIST (gw_application_get_installed_dictionarylist (application));

    gw_settingswindow_map_actions (G_ACTION_MAP (window), window);

    priv->manage_dictionaries_treeview = GTK_TREE_VIEW (gw_window_get_object (GW_WINDOW (window), "dictionary_treeview"));
    priv->notebook = GTK_NOTEBOOK (gw_window_get_object (GW_WINDOW (window), "settings_notebook"));
    priv->close_button = GTK_BUTTON (gw_window_get_object (GW_WINDOW (window), "close_button"));
    priv->spellcheck_checkbutton = GTK_TOGGLE_BUTTON (gw_window_get_object (GW_WINDOW (window), "spellcheck_checkbutton"));
    priv->please_install_dictionary_hbox = GTK_BOX (gw_window_get_object (GW_WINDOW (window), "please_install_dictionary_hbox"));
    priv->custom_font_fontbutton = GTK_FONT_BUTTON (gw_window_get_object (GW_WINDOW (window), "custom_font_fontbutton"));

    priv->match_foreground = GTK_COLOR_BUTTON (gw_window_get_object (GW_WINDOW (window), "match_foreground_colorbutton"));
    priv->match_background = GTK_COLOR_BUTTON (gw_window_get_object (GW_WINDOW (window), "match_background_colorbutton"));
    priv->comment_foreground = GTK_COLOR_BUTTON (gw_window_get_object (GW_WINDOW (window), "comment_foreground_colorbutton"));
    priv->header_foreground = GTK_COLOR_BUTTON (gw_window_get_object (GW_WINDOW (window), "header_foreground_colorbutton"));
    priv->header_background = GTK_COLOR_BUTTON (gw_window_get_object (GW_WINDOW (window), "header_background_colorbutton"));
    priv->system_document_font_hbox = GTK_BOX (gw_window_get_object (GW_WINDOW (window), "system_document_font_hbox"));
    priv->system_font_checkbutton = GTK_CHECK_BUTTON (gw_window_get_object (GW_WINDOW (window), "system_font_checkbutton"));
    priv->search_as_you_type_checkbutton = GTK_CHECK_BUTTON (gw_window_get_object (GW_WINDOW (window), "search_as_you_type_checkbutton"));
    priv->romaji_to_kana_combobox = GTK_COMBO_BOX (gw_window_get_object (GW_WINDOW (window), "romaji_to_kana_combobox"));
    priv->hiragana_to_katakana_checkbutton = GTK_CHECK_BUTTON (gw_window_get_object (GW_WINDOW (window), "hiragana_to_katakana_checkbutton"));
    priv->katakana_to_hiragana_checkbutton = GTK_CHECK_BUTTON (gw_window_get_object (GW_WINDOW (window), "katakana_to_hiragana_checkbutton"));
    priv->remove_dictionary_toolbutton = GTK_TOOL_BUTTON (gw_window_get_object (GW_WINDOW (window), "remove_dictionary_toolbutton"));

    gtk_window_set_title (GTK_WINDOW (window), gettext("gWaei Settings"));
    gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
    gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG);
    gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE);
    gtk_window_set_skip_pager_hint (GTK_WINDOW (window), TRUE);
    gtk_window_set_destroy_with_parent (GTK_WINDOW (window), TRUE);
    gtk_window_set_icon_name (GTK_WINDOW (window), "gwaei");
    gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ON_PARENT);

    g_signal_connect (G_OBJECT (window), "destroy",
                      G_CALLBACK (gw_settingswindow_remove_signals), NULL);

    if (g_main_current_source () != NULL) gw_application_block_searches (application);


    gw_settingswindow_init_styles (window);
    gw_settingswindow_init_dictionary_treeview (window);

    if (lw_dictionarylist_get_total (LW_DICTIONARYLIST (dictionarylist)) == 0)
      gtk_notebook_set_current_page (priv->notebook, 1);
    gw_settingswindow_check_for_dictionaries (window);

    #ifdef WITH_HUNSPELL
    gtk_widget_show (GTK_WIDGET (priv->spellcheck_checkbutton));
    #else
    gtk_widget_hide (GTK_WIDGET (priv->spellcheck_checkbutton));
    #endif

    gw_settingswindow_attach_signals (window);

    gtk_widget_add_accelerator (GTK_WIDGET (priv->close_button), "activate", 
      accelgroup, (GDK_KEY_W), GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
    gtk_widget_add_accelerator (GTK_WIDGET (priv->close_button), "activate", 
      accelgroup, (GDK_KEY_Escape), 0, GTK_ACCEL_VISIBLE);

    gw_window_unload_xml (GW_WINDOW (window));
}
コード例 #28
0
ファイル: http-client.c プロジェクト: crazygerbil/gst-httpd
/**
 * gst_http_client_attach:
 * @client: a #GstHTTPClient
 * @channel: a #GIOChannel
 *
 * Accept a new connection for @client on the socket in @channel. 
 *
 * This function should be called when the client properties and urls are fully
 * configured and the client is ready to start.
 *
 * Returns: %TRUE if the client could be accepted.
 */
gboolean
gst_http_client_accept (GstHTTPClient * client, GIOChannel * channel)
{
	int sock, fd;
	union gst_sockaddr sa;
	socklen_t slen = sizeof(sa);
	struct sockaddr_in6 peeraddr;
	struct sockaddr_in6 servaddr;
	GSource *source;
	GMainContext *context;

	/* a new client connected. */
	sock = g_io_channel_unix_get_fd (channel);

	memset (&sa, 0, slen);
	fd = accept (sock, &sa.sa, &slen);
	if (fd == -1)
		return FALSE;
	
	/* get remote endpoint addr */
	g_free (client->peer_ip);
	slen = sizeof(struct sockaddr_in6);	
	memset(&peeraddr, 0, slen);
	getpeername(fd, (struct sockaddr *) &peeraddr, &slen);
	client->peer_ip = g_strdup(sa_straddr(&peeraddr));
	client->port = peeraddr.sin6_port;

	/* get local endpoint addr */
	g_free (client->serv_ip);
	slen = sizeof(struct sockaddr_in6);	
	memset(&servaddr, 0, slen);
	getsockname(fd, (struct sockaddr *) &servaddr, &slen);
	client->serv_ip = g_strdup(sa_straddr(&servaddr));

	GST_DEBUG_OBJECT (client, "Accepted connection %s:%d on %s",
		client->peer_ip, client->port, client->serv_ip);

#if 0 // if we set NONBLOCK we need to check for EAGAIN on each read/write call
	/* set non-blocking mode so that we can cancel the communication */
	fcntl (fd, F_SETFL, O_NONBLOCK);
#endif
	client->sock = fd;

	/* find the context to add the watch */
	if ((source = g_main_current_source ()))
		context = g_source_get_context (source);
	else
		context = NULL;

	/* create watch for the connection and attach */
	channel = g_io_channel_unix_new (fd);
	client->watch = g_io_create_watch (channel, G_IO_IN |
			G_IO_ERR | G_IO_HUP | G_IO_NVAL); 
	g_source_attach (client->watch, context);
	g_io_channel_unref (channel);

	/* configure the callback */
	g_source_set_callback (client->watch,
			(GSourceFunc) gst_http_client_io_func, g_object_ref (client),
			(GDestroyNotify) client_watch_destroyed);

	return TRUE;
}