Exemple #1
0
static void
cockpit_channel_class_init (CockpitChannelClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  GSocketAddress *address;
  GInetAddress *inet;
  const gchar *port;

  gobject_class->constructed = cockpit_channel_constructed;
  gobject_class->get_property = cockpit_channel_get_property;
  gobject_class->set_property = cockpit_channel_set_property;
  gobject_class->dispose = cockpit_channel_dispose;
  gobject_class->finalize = cockpit_channel_finalize;

  klass->prepare = cockpit_channel_real_prepare;
  klass->close = cockpit_channel_real_close;

  /**
   * CockpitChannel:transport:
   *
   * The transport to send and receive messages over.
   */
  g_object_class_install_property (gobject_class, PROP_TRANSPORT,
                                   g_param_spec_object ("transport", "transport", "transport", COCKPIT_TYPE_TRANSPORT,
                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));

  /**
   * CockpitChannel:channel:
   *
   * The numeric channel to receive and send messages on.
   */
  g_object_class_install_property (gobject_class, PROP_ID,
                                   g_param_spec_string ("id", "id", "id", NULL,
                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));

  /**
   * CockpitChannel:options:
   *
   * The JSON options used to open this channel. The exact contents are
   * dependent on the derived channel class ... but this must at the
   * very least contain a 'payload' field describing what kind of channel
   * this should be.
   */
  g_object_class_install_property (gobject_class, PROP_OPTIONS,
                                   g_param_spec_boxed ("options", "options", "options", JSON_TYPE_OBJECT,
                                                       G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));

                                                         /**
   * CockpitChannel:capabilities:
   *
   * The capabilties that this channel supports.
   */
  g_object_class_install_property (gobject_class, PROP_CAPABILITIES,
                                   g_param_spec_boxed ("capabilities",
                                                       "Capabilities",
                                                       "Channel Capabilities",
                                                       G_TYPE_STRV,
                                                       G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));

  /**
   * CockpitChannel:frozen:
   *
   * Whether the channel starts off frozen or not.
   */
  g_object_class_install_property (gobject_class, PROP_FROZEN,
                                   g_param_spec_boolean ("frozen", "frozen", "frozen", FALSE,
                                                         G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));

  /**
   * CockpitChannel::closed:
   *
   * Emitted when the channel closes. This is similar to CockpitTransport::closed
   * but only applies to the individual channel.
   *
   * The channel will also be closed when the transport closes.
   */
  cockpit_channel_sig_closed = g_signal_new ("closed", COCKPIT_TYPE_CHANNEL, G_SIGNAL_RUN_LAST,
                                             G_STRUCT_OFFSET (CockpitChannelClass, closed),
                                             NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_STRING);

  g_type_class_add_private (klass, sizeof (CockpitChannelPrivate));


  /*
   * If we're running under a test server, register that server's HTTP address
   * as an internal address, available for use in cockpit channels.
   */

  port = g_getenv ("COCKPIT_TEST_SERVER_PORT");
  if (port)
    {
      inet = g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4);
      address = g_inet_socket_address_new (inet, atoi (port));
      cockpit_channel_internal_address ("/test-server", address);
      g_object_unref (address);
      g_object_unref (inet);
    }
}
Exemple #2
0
static void
lcms_layers_transform_rgb (gint                     *layers,
                           gint                      num_layers,
                           cmsHPROFILE               src_profile,
                           cmsHPROFILE               dest_profile,
                           GimpColorRenderingIntent  intent,
                           gboolean                  bpc)
{
  gint i;

  for (i = 0; i < num_layers; i++)
    {
      gint32           layer_id = layers[i];
      const Babl      *layer_format;
      gboolean         has_alpha;
      const Babl      *type;
      const Babl      *iter_format = NULL;
      cmsUInt32Number  lcms_format = 0;
      cmsHTRANSFORM    transform   = NULL;
      gint            *children;
      gint             num_children;

      children = gimp_item_get_children (layer_id, &num_children);

      if (children)
        {
          lcms_layers_transform_rgb (children, num_children,
                                     src_profile, dest_profile,
                                     intent, bpc);

          g_free (children);

          continue;
        }

      layer_format = gimp_drawable_get_format (layer_id);
      has_alpha    = babl_format_has_alpha (layer_format);
      type         = babl_format_get_type (layer_format, 0);

      if (type == babl_type ("u8"))
        {
          if (has_alpha)
            {
              lcms_format = TYPE_RGBA_8;
              iter_format = babl_format ("R'G'B'A u8");
            }
          else
            {
              lcms_format = TYPE_RGB_8;
              iter_format = babl_format ("R'G'B' u8");
            }
        }
      else if (type == babl_type ("u16"))
        {
          if (has_alpha)
            {
              lcms_format = TYPE_RGBA_16;
              iter_format = babl_format ("R'G'B'A u16");
            }
          else
            {
              lcms_format = TYPE_RGB_16;
              iter_format = babl_format ("R'G'B' u16");
            }
        }
      else if (type == babl_type ("half")) /* 16-bit floating point (half) */
        {
#ifdef TYPE_RGB_HALF_FLT
          /* half float types are only in lcms 2.4 and newer */
          if (has_alpha)
            {
              lcms_format = TYPE_RGBA_HALF_FLT;
              iter_format = babl_format ("R'G'B'A half");
            }
          else
            {
              lcms_format = TYPE_RGB_HALF_FLT;
              iter_format = babl_format ("R'G'B' float");
            }
#endif /* TYPE_RGB_HALF_FLT */
        }
      else if (type == babl_type ("float"))
        {
          if (has_alpha)
            {
              lcms_format = TYPE_RGBA_FLT;
              iter_format = babl_format ("R'G'B'A float");
            }
          else
            {
              lcms_format = TYPE_RGB_FLT;
              iter_format = babl_format ("R'G'B' float");
            }
        }
      else if (type == babl_type ("double"))
        {
          if (has_alpha)
            {
#ifdef TYPE_RGBA_DBL
              /* RGBA double not implemented in lcms */
              lcms_format = TYPE_RGBA_DBL;
              iter_format = babl_format ("R'G'B'A double");
#endif /* TYPE_RGBA_DBL */
            }
          else
            {
              lcms_format = TYPE_RGB_DBL;
              iter_format = babl_format ("R'G'B' double");
            }
        }

      if (lcms_format == 0)
        {
          g_printerr ("lcms: layer format %s not supported, "
                      "falling back to float\n",
                      babl_get_name (layer_format));

          if (has_alpha)
            {
              lcms_format = TYPE_RGBA_FLT;
              iter_format = babl_format ("R'G'B'A float");
            }
          else
            {
              lcms_format = TYPE_RGB_FLT;
              iter_format = babl_format ("R'G'B' float");
            }
        }

      transform = cmsCreateTransform (src_profile,  lcms_format,
                                      dest_profile, lcms_format,
                                      intent,
                                      cmsFLAGS_NOOPTIMIZE |
                                      bpc ? cmsFLAGS_BLACKPOINTCOMPENSATION : 0);

      if (transform)
        {
          GeglBuffer         *src_buffer;
          GeglBuffer         *dest_buffer;
          GeglBufferIterator *iter;
          gint                layer_width;
          gint                layer_height;
          gint                layer_bpp;
          gboolean            layer_alpha;
          gdouble             progress_start = (gdouble) i / num_layers;
          gdouble             progress_end   = (gdouble) (i + 1) / num_layers;
          gdouble             range          = progress_end - progress_start;
          gint                count          = 0;
          gint                done           = 0;

          src_buffer   = gimp_drawable_get_buffer (layer_id);
          dest_buffer  = gimp_drawable_get_shadow_buffer (layer_id);
          layer_width  = gegl_buffer_get_width (src_buffer);
          layer_height = gegl_buffer_get_height (src_buffer);
          layer_bpp    = babl_format_get_bytes_per_pixel (iter_format);
          layer_alpha  = babl_format_has_alpha (iter_format);

          iter = gegl_buffer_iterator_new (src_buffer, NULL, 0,
                                           iter_format,
                                           GEGL_BUFFER_READ, GEGL_ABYSS_NONE);

          gegl_buffer_iterator_add (iter, dest_buffer, NULL, 0,
                                    iter_format,
                                    GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);

          while (gegl_buffer_iterator_next (iter))
            {
              /*  lcms doesn't touch the alpha channel, simply
               *  copy everything to dest before the transform
               */
              if (layer_alpha)
                memcpy (iter->data[1], iter->data[0],
                        iter->length * layer_bpp);

              cmsDoTransform (transform,
                              iter->data[0], iter->data[1], iter->length);
            }

          g_object_unref (src_buffer);
          g_object_unref (dest_buffer);

          gimp_drawable_merge_shadow (layer_id, TRUE);
          gimp_drawable_update (layer_id, 0, 0, layer_width, layer_height);

          if (count++ % 32 == 0)
            {
              gimp_progress_update (progress_start +
                                    (gdouble) done /
                                    (layer_width * layer_height) * range);
            }

          cmsDeleteTransform (transform);
        }
    }
}
Exemple #3
0
gboolean upload_results(AppData *app_data) {
    GError *error = NULL;
    SoupURI *result_uri = NULL;

    guint ret = 0;

    SoupSession *session;
    SoupMessage *server_msg;
    SoupRequest *request;

    gchar *form_data;
    GHashTable *data_table = g_hash_table_new (NULL, NULL);

    result_uri = soup_uri_new (app_data->server);
    if (result_uri == NULL) {
        g_set_error (&error, RESTRAINT_ERROR,
                     RESTRAINT_PARSE_ERROR_BAD_SYNTAX,
                     "Malformed server url: %s", app_data->server);
        goto cleanup;
    }
    session = soup_session_new_with_options("timeout", 3600, NULL);

    g_hash_table_insert (data_table, "path", app_data->test_name);
    g_hash_table_insert (data_table, "result", app_data->test_result);

    // if AVC_ERROR=+no_avc_check then disable the selinux check plugin
    // This is for legacy rhts tests.. please use --disable-plugin
    gchar *avc_error = getenv("AVC_ERROR");
    if (g_strcmp0 (avc_error, "+no_avc_check") == 0) {
        g_ptr_array_add (app_data->disable_plugin, g_strdup ("10_avc_check"));
    }

    if (app_data->disable_plugin->pdata) {
        g_ptr_array_add (app_data->disable_plugin, NULL);
        g_hash_table_insert (data_table, "disable_plugin",
                             g_strjoinv (" ", (gchar **)app_data->disable_plugin->pdata));
    }
    if (app_data->no_plugins)
      g_hash_table_insert (data_table, "no_plugins", &app_data->no_plugins);
    if (app_data->score)
      g_hash_table_insert (data_table, "score", app_data->score);
    if (app_data->result_msg)
      g_hash_table_insert (data_table, "message", app_data->result_msg);

    request = (SoupRequest *)soup_session_request_http_uri (session, "POST", result_uri, &error);
    server_msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
    g_object_unref(request);
    form_data = soup_form_encode_hash (data_table);
    soup_message_set_request (server_msg, "application/x-www-form-urlencoded",
                              SOUP_MEMORY_TAKE, form_data, strlen (form_data));
    g_print ("** %s %s Score:%s\n", app_data->test_name, app_data->test_result,
        app_data->score != NULL ? app_data->score : "N/A");

    ret = soup_session_send_message (session, server_msg);
    if (SOUP_STATUS_IS_SUCCESSFUL (ret)) {
        gchar *location = g_strdup_printf ("%s/logs/",
                                           soup_message_headers_get_one (server_msg->response_headers, "Location"));
        soup_uri_free (result_uri);
        result_uri = soup_uri_new (location);
        g_free (location);
        if (app_data->outputfile != NULL &&
            g_file_test (app_data->outputfile, G_FILE_TEST_EXISTS))
        {
            g_print ("Uploading %s ", app_data->filename);
            if (upload_file (session, app_data->outputfile, app_data->filename, result_uri, &error)) {
                g_print ("done\n");
            } else {
                g_print ("failed\n");
            }
        }
    } else {
       g_warning ("Failed to submit result, status: %d Message: %s\n", ret, server_msg->reason_phrase);
    }
    g_object_unref(server_msg);
    soup_session_abort(session);
    g_object_unref(session);

cleanup:
    g_hash_table_destroy(data_table);
    if (result_uri != NULL) {
        soup_uri_free (result_uri);
    }

    if (error) {
        g_printerr("%s [%s, %d]\n", error->message,
                g_quark_to_string(error->domain), error->code);
        g_clear_error(&error);
        return FALSE;
    } else {
        return TRUE;
    }
}
Exemple #4
0
int
main (int argc, char **argv)
{
    GOptionContext *ctx;
    GError *error = NULL;
    int ecode;
    g_setenv ("CLUTTER_DISABLE_XINPUT", "1", TRUE);
    g_type_init ();

    bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);

    g_setenv ("GDK_SCALE", "1", TRUE);

    ctx = meta_get_option_context ();
    g_option_context_add_main_entries (ctx, gnome_cinnamon_options, GETTEXT_PACKAGE);
    if (!g_option_context_parse (ctx, &argc, &argv, &error))
    {
        g_printerr ("%s: %s\n", argv[0], error->message);
        exit (1);
    }

    g_option_context_free (ctx);

    meta_plugin_type_register (gnome_cinnamon_plugin_get_type ());

    /* Prevent meta_init() from causing gtk to load gail and at-bridge */
    g_setenv ("NO_GAIL", "1", TRUE);
    g_setenv ("NO_AT_BRIDGE", "1", TRUE);
    meta_init ();
    g_unsetenv ("NO_GAIL");
    g_unsetenv ("NO_AT_BRIDGE");
    g_unsetenv ("CLUTTER_DISABLE_XINPUT");

    /* FIXME: Add gjs API to set this stuff and don't depend on the
     * environment.  These propagate to child processes.
     */
    g_setenv ("GJS_DEBUG_OUTPUT", "stderr", TRUE);
    g_setenv ("GJS_DEBUG_TOPICS", "JS ERROR;JS LOG", TRUE);

    g_setenv ("CINNAMON_VERSION", VERSION, TRUE);


    center_pointer_on_screen();

    cinnamon_dbus_init (meta_get_replace_current_wm ());
    cinnamon_a11y_init ();
    cinnamon_perf_log_init ();

    g_irepository_prepend_search_path (CINNAMON_PKGLIBDIR);
#if HAVE_BLUETOOTH
    g_irepository_prepend_search_path (BLUETOOTH_DIR);
#endif

    /* Disable debug spew from various libraries */
    g_log_set_handler ("Gvc", G_LOG_LEVEL_DEBUG,
                       muted_log_handler, NULL);
    g_log_set_handler ("AccountsService", G_LOG_LEVEL_DEBUG,
                       muted_log_handler, NULL);
    g_log_set_handler ("Bluetooth", G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE,
                       muted_log_handler, NULL);

    /* Initialize the global object */
    _cinnamon_global_init (NULL);

    g_unsetenv ("GDK_SCALE");

    ecode = meta_run ();

    if (g_getenv ("CINNAMON_ENABLE_CLEANUP"))
    {
        g_printerr ("Doing final cleanup...\n");
        g_object_unref (cinnamon_global_get ());
    }

    return ecode;
}
Exemple #5
0
gint
main (gint argc,
      gchar **argv)
{
  
  if (argv[1])
  {
    input_path = argv[1];
    if (argv[2])
      output_path = argv[2];
  }


  gegl_init (&argc, &argv);

  gegl_dec  = gegl_node_new ();
  decode = gegl_node_new_child (gegl_dec, "operation", "gegl:ff-load", "path", input_path, NULL);
  store_buf = gegl_node_new_child (gegl_dec, "operation", "gegl:buffer-sink", "buffer", &buffer, NULL);
  gegl_node_link_many (decode, store_buf, NULL);
  
  gegl_enc = gegl_node_new ();
  load_buf = gegl_node_new_child (gegl_enc, "operation", "gegl:buffer-source", NULL);
  invert = gegl_node_new_child (gegl_enc,   "operation", "gegl:gray", NULL);
  encode = gegl_node_new_child (gegl_dec,   "operation", "gegl:ff-save", "path", output_path, NULL);

  gegl_node_link_many (load_buf, invert, /*invert2, invert3,*/ encode, NULL);

  {
    gint frame_no;
    gint frame_count = 100;
    gint audio_sample_rate = 44100;
    gint audio_channels = 0;

    for (frame_no = 0; frame_no < frame_count; frame_no++)
    {
      GeglAudioFragment *audio;
      fprintf (stderr, "\r%i/%i", frame_no, frame_count);
      gegl_node_set (decode, "frame", frame_no, NULL);
      if (buffer){
        g_object_unref (buffer);
        buffer = NULL;
      }
      gegl_node_process (store_buf);
      if (buffer)
      {
        if (frame_no == 0)
        {
          gegl_node_get (decode, "frame-rate", &fps, 
                                 "frames", &frame_count, 
                                 "audio-sample-rate", &audio_sample_rate, 
                                 "audio-channels", &audio_channels,
                                 NULL);
          fprintf (stderr, "frame-rate: %f\n", fps);
          gegl_node_set (encode, "frame-rate", fps, NULL);
        }
        gegl_node_get (decode, "audio", &audio, NULL);
        gegl_node_set (encode, "audio", audio, NULL);
        gegl_node_set (load_buf, "buffer", buffer, NULL);
        gegl_node_process (encode);
      }
    }
  }
  fprintf (stderr, "\n");
  g_object_unref (gegl_enc);
  g_object_unref (gegl_dec);
  g_object_unref (buffer);

  gegl_exit ();
  return 0;
}
Exemple #6
0
END_TEST

START_TEST (test_empathy_chatroom_manager_change_favorite)
{
  EmpathyChatroomManager *mgr;
  gchar *file;
  EmpathyAccount *account;
  EmpathyAccountManager *account_manager;
  struct chatroom_t chatrooms[] = {
        { "name1", "room1", TRUE, TRUE },
        { "name2", "room2", FALSE, FALSE }};
  EmpathyChatroom *chatroom;

  account_manager = empathy_account_manager_dup_singleton ();
  account = get_test_account ();

  copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);

  file = get_user_xml_file (CHATROOM_FILE);

  /* change the chatrooms XML file to use the account we just created */
  fail_unless (change_account_name_in_file (account, file));

  mgr = empathy_chatroom_manager_dup_singleton (file);

  /* room2 is not favorite anymore */
  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
  fail_if (chatroom == NULL);
  g_object_set (chatroom, "favorite", FALSE, NULL);

  check_chatrooms_list (mgr, account, chatrooms, 2);

  /* reload chatrooms file */
  g_object_unref (mgr);
  mgr = empathy_chatroom_manager_dup_singleton (file);

  /* room2 is not present in the XML file anymore as it's not a favorite */
  check_chatrooms_list (mgr, account, chatrooms, 1);

  /* re-add room2 */
  chatroom = empathy_chatroom_new_full (account, "room2", "name2", FALSE);
  empathy_chatroom_manager_add (mgr, chatroom);

  check_chatrooms_list (mgr, account, chatrooms, 2);

  /* set room2 as favorite */
  g_object_set (chatroom, "favorite", TRUE, NULL);

  chatrooms[1].favorite = TRUE;
  check_chatrooms_list (mgr, account, chatrooms, 2);

  /* reload chatrooms file */
  g_object_unref (mgr);
  mgr = empathy_chatroom_manager_dup_singleton (file);

  /* room2 is back in the XML file now */
  check_chatrooms_list (mgr, account, chatrooms, 2);

  g_object_unref (mgr);
  g_object_unref (chatroom);
  g_free (file);
  g_object_unref (account_manager);
  g_object_unref (account);
}
Exemple #7
0
int main (int argc,
          char *argv[])
{
  GtkWidget *window, *treeview, *scrolled_win;
  GtkTreeStore *store;
  GtkTreeIter iter, child;
  guint i = 0, j;
  
  gtk_init (&argc, &argv);
  
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Grocery List");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  gtk_widget_set_size_request (window, 275, 300);
  
  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);
  
  treeview = gtk_tree_view_new ();  
  setup_tree_view (treeview);
  
  store = gtk_tree_store_new (COLUMNS, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_STRING);
  
  while (list[i].product != NULL)
  {
    /* If the product type is a category, count the quantity of all of the products
     * in the category that are going to be boughty. */
    if (list[i].product_type == PRODUCT_CATEGORY)
    {
      j = i + 1;
      
      /* Calculate how many products will be bought in the category. */
      while (list[j].product != NULL && list[j].product_type != PRODUCT_CATEGORY)
      {
        if (list[j].buy)
          list[i].quantity += list[j].quantity;
        j++;
      }
      
      /* Add the category as a new root element. */
      gtk_tree_store_append (store, &iter, NULL);
      gtk_tree_store_set (store, &iter, BUY_IT, list[i].buy, 
                          QUANTITY, list[i].quantity, PRODUCT, list[i].product, -1);
    }
    /* Otherwise, add the product as a child of the category. */
    else
    {
      gtk_tree_store_append (store, &child, &iter);
      gtk_tree_store_set (store, &child, BUY_IT, list[i].buy, 
                          QUANTITY, list[i].quantity, PRODUCT, list[i].product, -1);
    }
    
    i++;
  }
  
  gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
  gtk_tree_view_expand_all (GTK_TREE_VIEW (treeview));
  g_object_unref (store);
  
  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  
  gtk_container_add (GTK_CONTAINER (scrolled_win), treeview);
  gtk_container_add (GTK_CONTAINER (window), scrolled_win);
  gtk_widget_show_all (window);
  
  gtk_main ();
  return 0;
}
static void
protocol_choosers_add_cm (EmpathyProtocolChooser *chooser,
    TpConnectionManager *cm)
{
  EmpathyProtocolChooserPriv *priv = GET_PRIV (chooser);
  const TpConnectionManagerProtocol * const *iter;

  for (iter = cm->protocols; iter != NULL && *iter != NULL; iter++)
    {
      const TpConnectionManagerProtocol *proto = *iter;
      gchar *icon_name;
      const gchar *display_name;
      const gchar *saved_cm_name;

      saved_cm_name = g_hash_table_lookup (priv->protocols, proto->name);

      if (!tp_strdiff (cm->name, "haze") && saved_cm_name != NULL &&
          tp_strdiff (saved_cm_name, "haze"))
        /* the CM we're adding is a haze implementation of something we already
         * have; drop it.
         */
        continue;

      if (!tp_strdiff (cm->name, "haze") &&
          !tp_strdiff (proto->name, "facebook"))
        /* Facebook now supports XMPP so drop the purple facebook plugin; user
         * should use Gabble */
        continue;

      if (!tp_strdiff (cm->name, "haze") &&
          !tp_strdiff (proto->name, "sip"))
        /* Haze's SIP implementation is pretty useless (bgo #629736) */
        continue;

      if (!tp_strdiff (cm->name, "butterfly"))
        /* Butterfly isn't supported any more */
        continue;

      if (tp_strdiff (cm->name, "haze") && !tp_strdiff (saved_cm_name, "haze"))
        {
          GtkTreeIter titer;
          gboolean valid;
          TpConnectionManager *haze_cm;

          /* let's this CM replace the haze implementation */
          valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store),
              &titer);

          while (valid)
            {
              gchar *haze_proto_name = NULL;

              gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &titer,
                  COL_PROTOCOL_NAME, &haze_proto_name,
                  COL_CM, &haze_cm, -1);

              if (haze_cm == NULL)
                continue;

              if (!tp_strdiff (haze_cm->name, "haze") &&
                  !tp_strdiff (haze_proto_name, proto->name))
                {
                  gtk_list_store_remove (priv->store, &titer);
                  g_object_unref (haze_cm);
                  g_free (haze_proto_name);
                  break;
                }

              g_object_unref (haze_cm);
              g_free (haze_proto_name);
              valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->store),
                  &titer);
            }
        }

      g_hash_table_insert (priv->protocols,
          g_strdup (proto->name), g_strdup (cm->name));

      icon_name = empathy_protocol_icon_name (proto->name);

      display_name = empathy_protocol_name_to_display_name (proto->name);

      gtk_list_store_insert_with_values (priv->store,
          NULL, 0,
          COL_ICON, icon_name,
          COL_LABEL, display_name,
          COL_CM, cm,
          COL_PROTOCOL_NAME, proto->name,
          -1);

      if (!tp_strdiff (proto->name, "jabber") &&
          !tp_strdiff (cm->name, "gabble"))
        {
          display_name = empathy_service_name_to_display_name ("google-talk");
          gtk_list_store_insert_with_values (priv->store,
             NULL, 0,
             COL_ICON, "im-google-talk",
             COL_LABEL, display_name,
             COL_CM, cm,
             COL_PROTOCOL_NAME, proto->name,
             COL_SERVICE, "google-talk",
             -1);

          display_name = empathy_service_name_to_display_name ("facebook");
          gtk_list_store_insert_with_values (priv->store,
             NULL, 0,
             COL_ICON, "im-facebook",
             COL_LABEL, display_name,
             COL_CM, cm,
             COL_PROTOCOL_NAME, proto->name,
             COL_SERVICE, "facebook",
             -1);
        }

      g_free (icon_name);
    }
}
static void
mnp_clock_construct (MnpClockTile *tile)
{
	MnpDateFormat *fmt;
	ClutterActor *box1, *label1, *label2, *label3;
	ClutterActor *icon;
	MnpClockTilePriv *priv = tile->priv;
	GConfClient *client = gconf_client_get_default();

	fmt = mnp_format_time_from_location (tile->priv->loc, 
					     tile->priv->time_now,
					     gconf_client_get_bool (client, "/apps/date-time-panel/24_h_clock", NULL)
					     );

	g_object_unref(client);
 

	label1 = mx_label_new_with_text (fmt->date);
	tile->priv->date = (MxLabel *)label1;
	clutter_actor_set_name (label1, "ClockTileDate");

	label2 = mx_label_new_with_text (fmt->time);
	tile->priv->time = (MxLabel *)label2;
	clutter_actor_set_name (label2, fmt->day ? "ClockTileTimeDay" : "ClockTileTimeNight");

	label3 = mx_label_new_with_text (fmt->city);
	tile->priv->city = (MxLabel *)label3;
	clutter_actor_set_name (label3, "ClockTileCity");

	box1 = mx_box_layout_new ();
	clutter_actor_set_name (box1, "ClockTileDateCityBox");
	mx_box_layout_set_orientation ((MxBoxLayout *)box1, MX_ORIENTATION_VERTICAL);

	mx_box_layout_add_actor ((MxBoxLayout *)box1, label3, 0);
	clutter_container_child_set ((ClutterContainer *)box1, label3,
				   	"expand", FALSE,
					"y-fill", FALSE,
					"y-align", MX_ALIGN_END,
                                   	NULL);
	
	mx_box_layout_add_actor ((MxBoxLayout *)box1, label1, 1);
	clutter_container_child_set ((ClutterContainer *)box1, label1,
				   	"expand", TRUE,
					"y-fill", FALSE,
					"y-align", MX_ALIGN_START,
                                   	NULL);

	mx_box_layout_set_orientation ((MxBoxLayout *)tile, MX_ORIENTATION_HORIZONTAL);
	mx_box_layout_add_actor ((MxBoxLayout *)tile, box1, 0);
	clutter_container_child_set ((ClutterContainer *)tile, box1,
				   	"expand", TRUE,
					"x-fill", TRUE,
					"y-fill", FALSE,
                                   	NULL);

	mx_box_layout_add_actor ((MxBoxLayout *)tile, label2, 1);
	clutter_container_child_set ((ClutterContainer *)tile, label2,
				   	"expand", TRUE,
					"x-fill", FALSE,
					"y-fill", FALSE,
					"y-align", MX_ALIGN_MIDDLE,
					"x-align", MX_ALIGN_END,					
                                   	NULL);
	FREE_DFMT(fmt);

 	
	priv->remove_button = (MxButton *)mx_button_new ();
	g_signal_connect (priv->remove_button, "clicked", G_CALLBACK(remove_tile), tile);
	mx_box_layout_add_actor ((MxBoxLayout *)tile, (ClutterActor *)priv->remove_button, 2);
  	clutter_container_child_set ((ClutterContainer *)tile, (ClutterActor *)priv->remove_button,
				   	"expand", FALSE,
					"x-fill", FALSE,
					"y-fill", FALSE,					
					"y-align", MX_ALIGN_MIDDLE,
					"x-align", MX_ALIGN_END,
                                   	NULL);

	mx_stylable_set_style_class (MX_STYLABLE (priv->remove_button),
                               			"ClockTileRemoveButton");
  	icon = (ClutterActor *)mx_icon_new ();
  	mx_stylable_set_style_class (MX_STYLABLE (icon),
                               		"ClockTileRemoveIcon");
  	mx_bin_set_child (MX_BIN (priv->remove_button),
                      		  (ClutterActor *)icon);
	
}
Exemple #10
0
static gboolean
g_file_real_deep_count (GFile                     *file,
                        GCancellable              *cancellable,
                        GFileCountProgressCallback progress_callback,
                        gpointer                   progress_callback_data,
                        ProgressData              *progress_data,
                        GError                   **error)
{
  GFileEnumerator *enumerator;
  GFileInfo       *info;
  GFileInfo       *child_info;
  GFile           *child;
  gboolean         success = TRUE;
  
  g_return_val_if_fail (G_IS_FILE (file), FALSE);

  info = g_file_query_info (file, "standard::*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);

  if (g_cancellable_is_cancelled (cancellable))
    return FALSE;

  if (info == NULL)
    return FALSE;

  progress_data->current_num_files += 1;
  progress_data->current_num_bytes += g_file_info_get_size (info);

  if (progress_callback != NULL)
    progress_callback (progress_data->current_num_files, progress_data->current_num_bytes, progress_callback_data);

  if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
    {
      enumerator = g_file_enumerate_children (file, "standard::*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
    
      if (!g_cancellable_is_cancelled (cancellable))
        {
          if (enumerator != NULL)
            {
              while (!g_cancellable_is_cancelled (cancellable) && success)
                {
                  child_info = g_file_enumerator_next_file (enumerator, cancellable, error);

                  if (g_cancellable_is_cancelled (cancellable))
                    break;

                  if (child_info == NULL)
                    {
                      if (*error != NULL)
                        success = FALSE;
                      break;
                    }

                  child = g_file_resolve_relative_path (file, g_file_info_get_name (child_info));
                  success = success && g_file_real_deep_count (child, cancellable, progress_callback, progress_callback_data, progress_data, error);
                  g_object_unref (child);

                  g_object_unref (child_info);
                }

              g_object_unref (enumerator);
            }
        }
    }

  g_object_unref (info);

  return !g_cancellable_is_cancelled (cancellable) && success;
}
void
nemo_menus_append_bookmark_to_menu (NemoWindow *window, 
					NemoBookmark *bookmark, 
					const char *parent_path,
					const char *parent_id,
					guint index_in_parent,
					GtkActionGroup *action_group,
					guint merge_id,
					GCallback refresh_callback,
					NemoBookmarkFailedCallback failed_callback)
{
	BookmarkHolder *bookmark_holder;
	char action_name[128];
	const char *name;
	char *path;
	GIcon *icon;
	GtkAction *action;
	GtkWidget *menuitem;

	g_assert (NEMO_IS_WINDOW (window));
	g_assert (NEMO_IS_BOOKMARK (bookmark));

	bookmark_holder = bookmark_holder_new (bookmark, window, refresh_callback, failed_callback);
	name = nemo_bookmark_get_name (bookmark);

	/* Create menu item with pixbuf */
	icon = nemo_bookmark_get_icon (bookmark);

	g_snprintf (action_name, sizeof (action_name), "%s%d", parent_id, index_in_parent);

	action = gtk_action_new (action_name,
				 name,
				 _("Go to the location specified by this bookmark"),
				 NULL);
	
	g_object_set_data_full (G_OBJECT (action), "menu-icon",
				icon,
				g_object_unref);

	g_signal_connect_data (action, "activate",
			       G_CALLBACK (activate_bookmark_in_menu_item),
			       bookmark_holder, 
			       bookmark_holder_free_cover, 0);

	gtk_action_group_add_action (action_group,
				     GTK_ACTION (action));

	g_object_unref (action);

	gtk_ui_manager_add_ui (window->details->ui_manager,
			       merge_id,
			       parent_path,
			       action_name,
			       action_name,
			       GTK_UI_MANAGER_MENUITEM,
			       FALSE);

	path = g_strdup_printf ("%s/%s", parent_path, action_name);
	menuitem = gtk_ui_manager_get_widget (window->details->ui_manager,
					      path);
	gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem),
						   TRUE);

	g_free (path);
}
Exemple #12
0
static void
deep_count_async_data_free (DeepCountAsyncData *data)
{
  g_object_unref (data->file);
  g_free (data);
}
Exemple #13
0
static gboolean
xmms_gvfs_init (xmms_xform_t *xform)
{
    xmms_gvfs_data_t *data;
    GFile *file;
    GFileInfo *info;
    GFileInputStream *handle;
    GError *error = NULL;
    const gchar *url;

    url = xmms_xform_indata_get_str (xform, XMMS_STREAM_TYPE_URL);
    g_return_val_if_fail (url, FALSE);

    /* This is an ugly hack to handle files with
       chars needing url encoding */
    if (!g_ascii_strncasecmp (url, "file://", 7)) {
        file = g_file_new_for_path (url+7);
    } else {
        file = g_file_new_for_uri (url);
    }
    handle = g_file_read (file, NULL, &error);
    g_object_unref (file);

    if (!handle) {
        xmms_log_error ("Failed to upen url %s for reading: %s",
                        url, error->message);
        return FALSE;
    }

    data = g_new (xmms_gvfs_data_t, 1);
    data->handle = G_INPUT_STREAM (handle);
    xmms_xform_private_data_set (xform, data);

    info = g_file_input_stream_query_info (handle, (char *)query_attributes,
                                           NULL, &error);

    if (!info) {
        xmms_log_info ("failed to query information for %s", url);
    } else {
        int i;

        for (i = 0; i < G_N_ELEMENTS (attr_map); i++) {
            if (!g_file_info_has_attribute (info, attr_map[i].gvfs)) {
                continue;
            }

            switch (attr_map[i].type) {
            case XMMSV_TYPE_STRING: {
                gchar *attr = g_file_info_get_attribute_as_string (info,
                              attr_map[i].gvfs);
                xmms_xform_metadata_set_str (xform, attr_map[i].mlib, attr);
                g_free (attr);
                break;
            }
            case XMMSV_TYPE_INT32: {
                /* right now the xform metadata api only handles strings
                 * and 32 bit ints. however the gvfs api returns uint64 for
                 * the numeric attributes we're interested in and we just
                 * pass that to the xform and pray that it doesn't overflow
                 * as we know it's unsafe.
                 */

                gint64 attr = g_file_info_get_attribute_uint64 (info,
                              attr_map[i].gvfs);
                xmms_xform_metadata_set_int (xform, attr_map[i].mlib, attr);
                break;
            }
            default:
                g_assert_not_reached ();
            }
        }

        g_object_unref (info);
    }

    xmms_xform_outdata_type_add (xform,
                                 XMMS_STREAM_TYPE_MIMETYPE,
                                 "application/octet-stream",
                                 XMMS_STREAM_TYPE_END);

    return TRUE;
}
/**
 * ldap_favorite_selector_new
 *
 * Returns: a new #GtkWidget
 */
GtkWidget *
ldap_favorite_selector_new (TConnection *tcnc)
{
	LdapFavoriteSelector *fsel;
	GdaTreeManager *manager;
	gchar *signame;

	g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
	fsel = LDAP_FAVORITE_SELECTOR (g_object_new (LDAP_FAVORITE_SELECTOR_TYPE, NULL));

	fsel->priv->tcnc = g_object_ref (tcnc);
	signame = g_strdup_printf ("favorites-changed::%s",
				   t_favorites_type_to_string (T_FAVORITES_LDAP_DN));
	g_signal_connect (t_connection_get_favorites (fsel->priv->tcnc), signame,
			  G_CALLBACK (favorites_changed_cb), fsel);
	g_free (signame);
	signame = g_strdup_printf ("favorites-changed::%s",
				   t_favorites_type_to_string (T_FAVORITES_LDAP_CLASS));
	g_signal_connect (t_connection_get_favorites (fsel->priv->tcnc), signame,
			  G_CALLBACK (favorites_changed_cb), fsel);
	g_free (signame);
	
	/* create tree managers */
	fsel->priv->tree = gda_tree_new ();
	manager = mgr_favorites_new (tcnc, T_FAVORITES_LDAP_DN, ORDER_KEY_LDAP);
        gda_tree_add_manager (fsel->priv->tree, manager);
	g_object_unref (manager);
	manager = mgr_favorites_new (tcnc, T_FAVORITES_LDAP_CLASS, ORDER_KEY_LDAP);
        gda_tree_add_manager (fsel->priv->tree, manager);
	g_object_unref (manager);

	/* update the tree's contents */
	if (! gda_tree_update_all (fsel->priv->tree, NULL)) {
		if (fsel->priv->idle_update_favorites == 0)
			fsel->priv->idle_update_favorites = g_idle_add ((GSourceFunc) idle_update_favorites, fsel);
	}

	/* header */
	GtkWidget *label;
	gchar *str;
	str = g_strdup_printf ("<b>%s</b>", _("Favorites"));
	label = gdaui_bar_new (str);
	g_free (str);
	gdaui_bar_set_icon_from_pixbuf (GDAUI_BAR (label), ui_get_pixbuf_icon (UI_ICON_BOOKMARK));
        gtk_box_pack_start (GTK_BOX (fsel), label, FALSE, FALSE, 0);
        gtk_widget_show (label);

	/* tree model & tree view */
	GtkTreeModel *model;
	GtkWidget *treeview;
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *column;

	model = gdaui_tree_store_new (fsel->priv->tree, COLUMN_LAST,
				      G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME,
				      G_TYPE_STRING, MGR_FAVORITES_CONTENTS_ATT_NAME,
				      G_TYPE_OBJECT, "icon",
				      G_TYPE_STRING, "markup",
				      G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME,
				      G_TYPE_STRING, "descr",
				      G_TYPE_UINT, MGR_FAVORITES_TYPE_ATT_NAME);

	treeview = ui_make_tree_view (model);
	fsel->priv->treeview = treeview;
	g_object_unref (model);

	g_signal_connect (G_OBJECT (treeview), "row-activated",
			  G_CALLBACK (selection_changed_cb), fsel);
	g_signal_connect (G_OBJECT (treeview), "key-press-event",
			  G_CALLBACK (key_press_event_cb), fsel);
	g_signal_connect (G_OBJECT (treeview), "popup-menu",
			  G_CALLBACK (popup_menu_cb), fsel);
	g_signal_connect (G_OBJECT (treeview), "button-press-event",
			  G_CALLBACK (button_press_event_cb), fsel);

	/* icon */
	column = gtk_tree_view_column_new ();

	renderer = gtk_cell_renderer_pixbuf_new ();
	gtk_tree_view_column_pack_start (column, renderer, FALSE);
	gtk_tree_view_column_add_attribute (column, renderer, "pixbuf", COLUMN_ICON);
	g_object_set ((GObject*) renderer, "yalign", 0., NULL);

	/* text */
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_column_pack_start (column, renderer, TRUE);
	gtk_tree_view_column_add_attribute (column, renderer, "markup", COLUMN_MARKUP);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
	gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
	
	/* scrolled window packing */
	GtkWidget *sw;
	sw = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
					     GTK_SHADOW_ETCHED_IN);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
					GTK_POLICY_NEVER,
					GTK_POLICY_AUTOMATIC);
	gtk_container_add (GTK_CONTAINER (sw), treeview);
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);	

	gtk_box_pack_start (GTK_BOX (fsel), sw, TRUE, TRUE, 0);
	gtk_widget_show_all (sw);

	/* DnD */
	gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW (treeview), dbo_table, G_N_ELEMENTS (dbo_table),
					      GDK_ACTION_COPY);
	gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (treeview), GDK_BUTTON1_MASK,
						dbo_table, G_N_ELEMENTS (dbo_table),
						GDK_ACTION_COPY | GDK_ACTION_MOVE);
	g_signal_connect (model, "drag-drop",
			  G_CALLBACK (tree_store_drag_drop_cb), fsel);
	g_signal_connect (model, "drag-can-drag",
			  G_CALLBACK (tree_store_drag_can_drag_cb), fsel);
	g_signal_connect (model, "drag-get",
			  G_CALLBACK (tree_store_drag_get_cb), fsel);

	return (GtkWidget*) fsel;
}
Exemple #15
0
gint
main (gint argc,
      gchar **argv)
{
	CamelStream *source;
	CamelStream *correct;
	CamelStream *stream;
	CamelMimeFilter *sh;
	gchar *work;
	gint i;
	gssize comp_progress, comp_correct_chunk, comp_filter_chunk;
	gint comp_i;
	gchar comp_correct[CHUNK_SIZE], comp_filter[CHUNK_SIZE];

	camel_test_init (argc, argv);

	for (i = 0; i < NUM_CASES; i++) {
		gint j;

		work = g_strdup_printf ("CRLF/DOT filter, test case %d", i);
		camel_test_start (work);
		g_free (work);

		for (j = CRLF_ENCODE; j < CRLF_DONE; j++) {
			CamelMimeFilterCRLFDirection direction;
			gchar *infile = NULL, *outfile = NULL;

			switch (j) {
			case CRLF_ENCODE:
				camel_test_push ("Test of the encoder");
				direction = CAMEL_MIME_FILTER_CRLF_ENCODE;
				infile = g_strdup_printf ("%s/crlf-%d.in", SOURCEDIR, i + 1);
				outfile = g_strdup_printf ("%s/crlf-%d.out", SOURCEDIR, i + 1);
				break;
			case CRLF_DECODE:
				camel_test_push ("Test of the decoder");
				direction = CAMEL_MIME_FILTER_CRLF_DECODE;
				infile = g_strdup_printf ("%s/crlf-%d.out", SOURCEDIR, i + 1);
				outfile = g_strdup_printf ("%s/crlf-%d.in", SOURCEDIR, i + 1);
				break;
			default:
				break;
			}

			camel_test_push ("Initializing objects");
			source = camel_stream_fs_new_with_name (infile, 0, O_RDONLY, NULL);
			if (!source) {
				camel_test_fail ("Failed to open input case in \"%s\"", infile);
				g_free (infile);
				continue;
			}
			g_free (infile);

			correct = camel_stream_fs_new_with_name (outfile, 0, O_RDONLY, NULL);
			if (!correct) {
				camel_test_fail ("Failed to open correct output in \"%s\"", outfile);
				g_free (outfile);
				continue;
			}
			g_free (outfile);

			stream = camel_stream_filter_new (source);
			if (!stream) {
				camel_test_fail ("Couldn't create CamelStreamFilter??");
				continue;
			}

			sh = camel_mime_filter_crlf_new (direction, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS);
			if (!sh) {
				camel_test_fail ("Couldn't create CamelMimeFilterCrlf??");
				continue;
			}

			camel_stream_filter_add (
				CAMEL_STREAM_FILTER (stream), sh);
			camel_test_pull ();

			camel_test_push ("Running filter and comparing to correct result");

			comp_progress = 0;

			while (1) {
				comp_correct_chunk = camel_stream_read (
					correct, comp_correct,
					CHUNK_SIZE, NULL, NULL);
				comp_filter_chunk = 0;

				if (comp_correct_chunk == 0)
					break;

				while (comp_filter_chunk < comp_correct_chunk) {
					gssize delta;

					delta = camel_stream_read (
						stream,
						comp_filter + comp_filter_chunk,
						CHUNK_SIZE - comp_filter_chunk,
						NULL, NULL);

					if (delta == 0) {
						camel_test_fail ("Chunks are different sizes: correct is %d, "
							"filter is %d, %d bytes into stream",
							comp_correct_chunk, comp_filter_chunk, comp_progress);
					}

					comp_filter_chunk += delta;
				}

				for (comp_i = 0; comp_i < comp_filter_chunk; comp_i++) {
					if (comp_correct[comp_i] != comp_filter[comp_i]) {
						camel_test_fail ("Difference: correct is %c, filter is %c, "
							"%d bytes into stream",
							comp_correct[comp_i],
							comp_filter[comp_i],
							comp_progress + comp_i);
					}
				}

				comp_progress += comp_filter_chunk;
			}

			camel_test_pull ();

			/* inefficient */
			camel_test_push ("Cleaning up");
			g_object_unref (stream);
			g_object_unref (correct);
			g_object_unref (source);
			g_object_unref (sh);
			camel_test_pull ();

			camel_test_pull ();
		}

		camel_test_end ();
	}

	return 0;
}
Exemple #16
0
static void
gimp_warp_tool_animate (GimpWarpTool *wt)
{
  GimpTool        *tool    = GIMP_TOOL (wt);
  GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (wt);
  GimpImage       *orig_image;
  GimpImage       *image;
  GimpLayer       *layer;
  GimpLayer       *first_layer;
  GeglNode        *scale_node;
  GimpProgress    *progress;
  GtkWidget       *widget;
  gint             i;

  if (! gimp_warp_tool_get_undo_desc (tool, tool->display))
    {
      gimp_tool_message_literal (tool, tool->display,
                                 _("Please add some warp strokes first."));
      return;
    }

  /*  get rid of the image map so we can use wt->graph  */
  if (wt->image_map)
    {
      gimp_image_map_abort (wt->image_map);
      g_object_unref (wt->image_map);
      wt->image_map = NULL;
    }

  gimp_progress_start (GIMP_PROGRESS (tool), FALSE,
                       _("Rendering Frame %d"), 1);

  orig_image = gimp_item_get_image (GIMP_ITEM (tool->drawable));

  image = gimp_create_image (orig_image->gimp,
                             gimp_item_get_width  (GIMP_ITEM (tool->drawable)),
                             gimp_item_get_height (GIMP_ITEM (tool->drawable)),
                             gimp_drawable_get_base_type (tool->drawable),
                             gimp_drawable_get_precision (tool->drawable),
                             TRUE);

  /*  the first frame is always the unwarped image  */
  layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (tool->drawable), image,
                                         GIMP_TYPE_LAYER));
  gimp_object_take_name (GIMP_OBJECT (layer),
                         g_strdup_printf (_("Frame %d"), 1));

  gimp_item_set_offset (GIMP_ITEM (layer), 0, 0);
  gimp_item_set_visible (GIMP_ITEM (layer), TRUE, FALSE);
  gimp_layer_set_mode (layer, GIMP_NORMAL_MODE, FALSE);
  gimp_layer_set_opacity (layer, GIMP_OPACITY_OPAQUE, FALSE);
  gimp_image_add_layer (image, layer, NULL, 0, FALSE);

  first_layer = layer;

  scale_node = gegl_node_new_child (NULL,
                                    "operation",    "gimp:scalar-multiply",
                                    "n-components", 2,
                                    NULL);
  gimp_warp_tool_add_op (wt, scale_node);

  progress = gimp_sub_progress_new (GIMP_PROGRESS (tool));

  for (i = 1; i < options->n_animation_frames; i++)
    {
      gimp_progress_set_text (GIMP_PROGRESS (tool),
                              _("Rendering Frame %d"), i + 1);

      gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (progress),
                                  i, options->n_animation_frames);

      layer = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (first_layer),
                                               GIMP_TYPE_LAYER));
      gimp_object_take_name (GIMP_OBJECT (layer),
                             g_strdup_printf (_("Frame %d"), i + 1));

      gegl_node_set (scale_node,
                     "factor", (gdouble) i /
                               (gdouble) (options->n_animation_frames - 1),
                     NULL);

      gimp_gegl_apply_operation (gimp_drawable_get_buffer (GIMP_DRAWABLE (first_layer)),
                                 progress,
                                 _("Frame"),
                                 wt->graph,
                                 gimp_drawable_get_buffer (GIMP_DRAWABLE (layer)),
                                 NULL);

      gimp_image_add_layer (image, layer, NULL, 0, FALSE);
    }

  g_object_unref (progress);

  gimp_warp_tool_remove_op (wt, scale_node);

  gimp_progress_end (GIMP_PROGRESS (tool));

  /*  recreate the image map  */
  gimp_warp_tool_create_image_map (wt, tool->drawable);
  gimp_image_map_apply (wt->image_map, NULL);

  widget = GTK_WIDGET (gimp_display_get_shell (tool->display));
  gimp_create_display (orig_image->gimp, image, GIMP_UNIT_PIXEL, 1.0,
                       G_OBJECT (gtk_widget_get_screen (widget)),
                       gimp_widget_get_monitor (widget));
  g_object_unref (image);
}
Exemple #17
0
END_TEST

START_TEST (test_empathy_chatroom_manager_add)
{
  EmpathyChatroomManager *mgr;
  gchar *file;
  EmpathyAccount *account;
  EmpathyAccountManager *account_manager;
  struct chatroom_t chatrooms[] = {
        { "name1", "room1", TRUE, TRUE },
        { "name2", "room2", FALSE, TRUE },
        { "name3", "room3", FALSE, TRUE },
        { "name4", "room4", FALSE, FALSE }};
  EmpathyChatroom *chatroom;

  account_manager = empathy_account_manager_dup_singleton ();

  account = get_test_account ();

  copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);

  file = get_user_xml_file (CHATROOM_FILE);

  /* change the chatrooms XML file to use the account we just created */
  fail_unless (change_account_name_in_file (account, file));

  mgr = empathy_chatroom_manager_dup_singleton (file);

  /* add a favorite chatroom */
  chatroom = empathy_chatroom_new_full (account, "room3", "name3", FALSE);
  g_object_set (chatroom, "favorite", TRUE, NULL);
  empathy_chatroom_manager_add (mgr, chatroom);
  g_object_unref (chatroom);

  check_chatrooms_list (mgr, account, chatrooms, 3);

  /* reload chatrooms file */
  g_object_unref (mgr);
  mgr = empathy_chatroom_manager_dup_singleton (file);

  /* chatroom has been added to the XML file as it's a favorite */
  check_chatrooms_list (mgr, account, chatrooms, 3);

  /* add a non favorite chatroom */
  chatroom = empathy_chatroom_new_full (account, "room4", "name4", FALSE);
  g_object_set (chatroom, "favorite", FALSE, NULL);
  empathy_chatroom_manager_add (mgr, chatroom);
  g_object_unref (chatroom);

  check_chatrooms_list (mgr, account, chatrooms, 4);

  /* reload chatrooms file */
  g_object_unref (mgr);
  mgr = empathy_chatroom_manager_dup_singleton (file);

  /* chatrooms has not been added to the XML file */
  check_chatrooms_list (mgr, account, chatrooms, 3);

  g_object_unref (mgr);
  g_free (file);
  g_object_unref (account_manager);
  g_object_unref (account);
}
Exemple #18
0
int
main(int argc, char *argv[])
{
	IAnjutaProject *project = NULL;
	AnjutaProjectNode *node;
	AnjutaProjectNode *child;
	AnjutaProjectNode *sibling;
	AnjutaProjectNode *root = NULL;
	char **command;
	GOptionContext *context;
	GError *error = NULL;

	/* Initialize program */
	g_type_init ();


	/* Parse options */
 	context = g_option_context_new ("list [args]");
  	g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
	g_option_context_set_summary (context, "test new autotools project manger");
	if (!g_option_context_parse (context, &argc, &argv, &error))
    {
		exit (1);
    }
	if (argc < 2)
	{
		printf ("PROJECT: %s", g_option_context_get_help (context, TRUE, NULL));
		exit (1);
	}

	open_output ();

	/* Execute commands */
	for (command = &argv[1]; *command != NULL; command++)
	{
		if (g_ascii_strcasecmp (*command, "load") == 0)
		{
			GFile *file = g_file_new_for_commandline_arg (*(++command));

			if (project == NULL)
			{
				gint best = 0;
				gint probe;
				GType type;
				GTypeModule *module;

				/* Register project types */
				module = g_object_new (dummy_type_module_get_type (), NULL);
				amp_project_register (module);

				/* Check for project type */
				probe = amp_project_probe (file, NULL);
				if (probe > best)
				{
					best = probe;
					type = AMP_TYPE_PROJECT;
				}

				if (best == 0)
				{
					print_error ("Error: No backend for loading project in %s", *command);
					break;
				}
				else
				{
					project = IANJUTA_PROJECT (amp_project_new (file, NULL, NULL));
				}
			}

			root = ianjuta_project_get_root (project, &error);
			ianjuta_project_load_node (project, root, &error);
			g_object_unref (file);
		}
		else if (g_ascii_strcasecmp (*command, "list") == 0)
		{
			list_root (project, root);
		}
		else if (g_ascii_strcasecmp (*command, "move") == 0)
		{
			if (AMP_IS_PROJECT (project))
			{
				amp_project_move (AMP_PROJECT (project), *(++command));
			}
		}
		else if (g_ascii_strcasecmp (*command, "save") == 0)
		{
			ianjuta_project_save_node (project, root, NULL);
		}
		else if (g_ascii_strcasecmp (*command, "remove") == 0)
		{
			node = get_node (project, root, *(++command));
			ianjuta_project_remove_node (project, node, NULL);
		}
		else if (g_ascii_strcasecmp (*command, "dump") == 0)
		{
			if (g_ascii_strcasecmp (command[1], "makefile") == 0)
			{
				node = get_node (project, root, command[2]);
				amp_project_dump (AMP_PROJECT (project), node, DUMP_MAKEFILE);
				command +=2;
			}
			else if (g_ascii_strcasecmp (command[1], "configure") == 0)
			{
				amp_project_dump (AMP_PROJECT (project), root, DUMP_CONFIGURE);
				command +=1;
			}
			else
			{
				print_error ("Error: unknown command %s %s", *command, command[1]);
				break;
			}
		}
		else if (g_ascii_strcasecmp (command[0], "add") == 0)
		{
			node = get_node (project, root, command[2]);
			if (g_ascii_strcasecmp (command[1], "group") == 0)
			{
				if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "before") == 0))
				{
					sibling = get_node (project, root, command[5]);
					child = ianjuta_project_add_node_before (project, node, sibling, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
					command += 2;
				}
				else if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "after") == 0))
				{
					sibling = get_node (project, root, command[5]);
					child = ianjuta_project_add_node_after (project, node, sibling, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
					command += 2;
				}
				else
				{
					child = ianjuta_project_add_node_before (project, node, NULL, ANJUTA_PROJECT_GROUP, NULL, command[3], &error);
				}
			}
			else if (g_ascii_strcasecmp (command[1], "target") == 0)
			{
				if ((command[5] != NULL) && (g_ascii_strcasecmp (command[5], "before") == 0))
				{
					sibling = get_node (project, root, command[6]);
					child = ianjuta_project_add_node_before (project, node, sibling, ANJUTA_PROJECT_TARGET | get_target_type (project, command[4]), NULL, command[3], &error);
					command += 2;
				}
				else if ((command[5] != NULL) && (g_ascii_strcasecmp (command[5], "after") == 0))
				{
					sibling = get_node (project, root, command[6]);
					child = ianjuta_project_add_node_after (project, node, sibling, ANJUTA_PROJECT_TARGET | get_target_type (project, command[4]), NULL, command[3], &error);
					command += 2;
				}
				else
				{
					child = ianjuta_project_add_node_before (project, node, NULL, ANJUTA_PROJECT_TARGET | get_target_type (project, command[4]), NULL, command[3], &error);
				}
				command++;
			}
			else if (g_ascii_strcasecmp (command[1], "source") == 0)
			{
				GFile *file = get_file (node, command[3]);

				if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "before") == 0))
				{
					sibling = get_node (project, root, command[5]);
					child = ianjuta_project_add_node_before (project, node, sibling, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
					command += 2;
				}
				else if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "after") == 0))
				{
					sibling = get_node (project, root, command[5]);
					child = ianjuta_project_add_node_after (project, node, sibling, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
					command += 2;
				}
				else
				{
					child = ianjuta_project_add_node_before (project, node, NULL, ANJUTA_PROJECT_SOURCE, file, NULL, &error);
				}
				g_object_unref (file);
			}
			else if (g_ascii_strcasecmp (command[1], "module") == 0)
			{
				if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "before") == 0))
				{
					sibling = get_node (project, root, command[5]);
					child = ianjuta_project_add_node_before (project, node, sibling, ANJUTA_PROJECT_MODULE, NULL, command[3], &error);
					command += 2;
				}
				else if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "after") == 0))
				{
					sibling = get_node (project, root, command[5]);
					child = ianjuta_project_add_node_after (project, node, sibling, ANJUTA_PROJECT_MODULE, NULL, command[3], &error);
					command += 2;
				}
				else
				{
					child = ianjuta_project_add_node_before (project, node, NULL, ANJUTA_PROJECT_MODULE, NULL, command[3], &error);
				}
			}
			else if (g_ascii_strcasecmp (command[1], "package") == 0)
			{
				if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "before") == 0))
				{
					sibling = get_node (project, root, command[5]);
					child = ianjuta_project_add_node_before (project, node, sibling, ANJUTA_PROJECT_PACKAGE, NULL, command[3], &error);
					command += 2;
				}
				else if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "after") == 0))
				{
					sibling = get_node (project, root, command[5]);
					child = ianjuta_project_add_node_after (project, node, sibling, ANJUTA_PROJECT_PACKAGE, NULL, command[3], &error);
					command += 2;
				}
				else
				{
					child = ianjuta_project_add_node_before (project, node, NULL, ANJUTA_PROJECT_PACKAGE, NULL, command[3], &error);
				}
			}
			else
			{
				print_error ("Error: unknown command %s", *command);

				break;
			}
			command += 3;
		}
		else if (g_ascii_strcasecmp (command[0], "set") == 0)
		{
			if (AMP_IS_PROJECT (project))
			{
				AnjutaProjectPropertyInfo *info;

				node = get_node (project, root, command[1]);
				info = get_project_property (project, node, command[2]);
				if (info != NULL)
				{
					gchar *value = g_shell_unquote (command[3], NULL);
					ianjuta_project_set_property (project, node, info->id, NULL, value, NULL);
					g_free (value);
				}
			}
			command += 3;
		}
		else if (g_ascii_strcasecmp (command[0], "clear") == 0)
		{
			if (AMP_IS_PROJECT (project))
			{
				AnjutaProjectPropertyInfo *info;

				node = get_node (project, root, command[1]);
				info = get_project_property (project, node, command[2]);
				if (info != NULL)
				{
					ianjuta_project_remove_property (project, node, info->id, NULL, NULL);
				}
			}
			command += 2;
		}
		else
		{
			print_error ("Error: unknown command %s", *command);

			break;
		}
		amp_project_wait_ready (project);
		if (error != NULL)
		{
			print_error ("Error: %s", error->message == NULL ? "unknown error" : error->message);

			g_error_free (error);
			error = NULL;
		}
	}

	/* Free objects */
	if (project) g_object_unref (project);
	close_output ();

	return (0);
}
Exemple #19
0
END_TEST

START_TEST (test_empathy_chatroom_manager_change_chatroom)
{
  EmpathyChatroomManager *mgr;
  gchar *file;
  EmpathyAccount *account;
  EmpathyAccountManager *account_manager;
  struct chatroom_t chatrooms[] = {
        { "name1", "room1", TRUE, TRUE },
        { "name2", "room2", FALSE, TRUE }};
  EmpathyChatroom *chatroom;

  account_manager = empathy_account_manager_dup_singleton ();
  account = get_test_account ();

  copy_xml_file (CHATROOM_SAMPLE, "foo.xml");

  file = get_user_xml_file ("foo.xml");

  /* change the chatrooms XML file to use the account we just created */
  fail_unless (change_account_name_in_file (account, file));

  mgr = empathy_chatroom_manager_dup_singleton (file);

  check_chatrooms_list (mgr, account, chatrooms, 2);

  /* change room2 name */
  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
  fail_if (chatroom == NULL);
  empathy_chatroom_set_name (chatroom, "new_name");

  /* reload chatrooms file */
  g_object_unref (mgr);
  mgr = empathy_chatroom_manager_dup_singleton (file);

  chatrooms[1].name = "new_name";
  check_chatrooms_list (mgr, account, chatrooms, 2);

  /* change room2 auto-connect status */
  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
  fail_if (chatroom == NULL);
  empathy_chatroom_set_auto_connect (chatroom, TRUE);

  /* reload chatrooms file */
  g_object_unref (mgr);
  mgr = empathy_chatroom_manager_dup_singleton (file);

  chatrooms[1].auto_connect = TRUE;
  check_chatrooms_list (mgr, account, chatrooms, 2);

  /* change room2 room */
  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
  fail_if (chatroom == NULL);
  empathy_chatroom_set_room (chatroom, "new_room");

  /* reload chatrooms file */
  g_object_unref (mgr);
  mgr = empathy_chatroom_manager_dup_singleton (file);

  chatrooms[1].room = "new_room";
  check_chatrooms_list (mgr, account, chatrooms, 2);

  g_object_unref (mgr);
  g_free (file);
  g_object_unref (account);
  g_object_unref (account_manager);
}
Exemple #20
0
static void
deactivate (NMDevice *device)
{
	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);

	priv->have_iface = FALSE;
	priv->connected = FALSE;

	if (priv->bt_type == NM_BT_CAPABILITY_DUN) {

		if (priv->modem) {
			nm_modem_deactivate (priv->modem, device);

			/* Since we're killing the Modem object before it'll get the
			 * state change signal, simulate the state change here.
			 */
			nm_modem_device_state_changed (priv->modem,
			                               NM_DEVICE_STATE_DISCONNECTED,
			                               NM_DEVICE_STATE_ACTIVATED,
			                               NM_DEVICE_STATE_REASON_USER_REQUESTED);
			g_object_unref (priv->modem);
			priv->modem = NULL;
		}

		if (priv->type_proxy) {
			/* Don't ever pass NULL through dbus; rfcomm_iface
			 * might happen to be NULL for some reason.
			 */
			if (priv->rfcomm_iface) {
				dbus_g_proxy_call_no_reply (priv->type_proxy, "Disconnect",
				                            G_TYPE_STRING, priv->rfcomm_iface,
				                            G_TYPE_INVALID);
			}
			g_object_unref (priv->type_proxy);
			priv->type_proxy = NULL;
		}
	} else if (priv->bt_type == NM_BT_CAPABILITY_NAP) {
		if (priv->type_proxy) {
			dbus_g_proxy_call_no_reply (priv->type_proxy, "Disconnect",
			                            G_TYPE_INVALID);
			g_object_unref (priv->type_proxy);
			priv->type_proxy = NULL;
		}
	}

	if (priv->dev_proxy) {
		g_object_unref (priv->dev_proxy);
		priv->dev_proxy = NULL;
	}

	if (priv->timeout_id) {
		g_source_remove (priv->timeout_id);
		priv->timeout_id = 0;
	}

	priv->bt_type = NM_BT_CAPABILITY_NONE;

	g_free (priv->rfcomm_iface);
	priv->rfcomm_iface = NULL;

	if (NM_DEVICE_CLASS (nm_device_bt_parent_class)->deactivate)
		NM_DEVICE_CLASS (nm_device_bt_parent_class)->deactivate (device);
}
static void
thunar_folder_finished (ThunarVfsJob *job,
                        ThunarFolder *folder)
{
  ThunarFile *file;
  GList      *files;
  GList      *lp;

  _thunar_return_if_fail (THUNAR_IS_FOLDER (folder));
  _thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
  _thunar_return_if_fail (THUNAR_IS_FILE (folder->corresponding_file));
  _thunar_return_if_fail (folder->handle == NULL);
  _thunar_return_if_fail (folder->job == job);

  /* check if we need to merge new files with existing files */
  if (G_UNLIKELY (folder->files != NULL))
    {
      /* determine all added files (files on new_files, but not on files) */
      for (files = NULL, lp = folder->new_files; lp != NULL; lp = lp->next)
        if (g_list_find (folder->files, lp->data) == NULL)
          {
            /* put the file on the added list */
            files = g_list_prepend (files, lp->data);

            /* add to the internal files list */
            folder->files = g_list_prepend (folder->files, lp->data);
            g_object_ref (G_OBJECT (lp->data));
          }

      /* check if any files were added */
      if (G_UNLIKELY (files != NULL))
        {
          /* emit a "files-added" signal for the added files */
          g_signal_emit (G_OBJECT (folder), folder_signals[FILES_ADDED], 0, files);

          /* release the added files list */
          g_list_free (files);
        }

      /* determine all removed files (files on files, but not on new_files) */
      for (files = NULL, lp = folder->files; lp != NULL; )
        {
          /* determine the file */
          file = THUNAR_FILE (lp->data);

          /* determine the next list item */
          lp = lp->next;

          /* check if the file is not on new_files */
          if (g_list_find (folder->new_files, file) == NULL)
            {
              /* put the file on the removed list (owns the reference now) */
              files = g_list_prepend (files, file);

              /* remove from the internal files list */
              folder->files = g_list_remove (folder->files, file);
            }
        }

      /* check if any files were removed */
      if (G_UNLIKELY (files != NULL))
        {
          /* emit a "files-removed" signal for the removed files */
          g_signal_emit (G_OBJECT (folder), folder_signals[FILES_REMOVED], 0, files);

          /* release the removed files list */
          thunar_file_list_free (files);
        }

      /* drop the temporary new_files list */
      thunar_file_list_free (folder->new_files);
      folder->new_files = NULL;
    }
  else
    {
      /* just use the new files for the files list */
      folder->files = folder->new_files;
      folder->new_files = NULL;

      /* emit a "files-added" signal for the new files */
      g_signal_emit (G_OBJECT (folder), folder_signals[FILES_ADDED], 0, folder->files);
    }

  /* we did it, the folder is loaded */
  g_signal_handlers_disconnect_matched (folder->job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, folder);
  g_object_unref (G_OBJECT (folder->job));
  folder->job = NULL;

  /* add us to the file alteration monitor */
  folder->handle = thunar_vfs_monitor_add_directory (folder->monitor, thunar_file_get_path (folder->corresponding_file),
                                                     thunar_folder_monitor, folder);

  /* tell the consumers that we have loaded the directory */
  g_object_notify (G_OBJECT (folder), "loading");
}
Exemple #22
0
gboolean
nm_device_bt_modem_added (NMDeviceBt *self,
                          NMModem *modem,
                          const char *driver)
{
	NMDeviceBtPrivate *priv;
	const gchar *modem_data_port;
	const gchar *modem_control_port;
	char *base;
	NMDeviceState state;
	NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (NM_IS_DEVICE_BT (self), FALSE);
	g_return_val_if_fail (modem != NULL, FALSE);
	g_return_val_if_fail (NM_IS_MODEM (modem), FALSE);

	priv = NM_DEVICE_BT_GET_PRIVATE (self);
	modem_data_port = nm_modem_get_data_port (modem);
	modem_control_port = nm_modem_get_control_port (modem);
	g_return_val_if_fail (modem_data_port != NULL || modem_control_port != NULL, FALSE);

	if (!priv->rfcomm_iface)
		return FALSE;

	base = g_path_get_basename (priv->rfcomm_iface);
	if (g_strcmp0 (base, modem_data_port) && g_strcmp0 (base, modem_control_port)) {
		g_free (base);
		return FALSE;
	}
	g_free (base);

	/* Got the modem */
	if (priv->timeout_id) {
		g_source_remove (priv->timeout_id);
		priv->timeout_id = 0;
	}

	/* Can only accept the modem in stage2, but since the interface matched
	 * what we were expecting, don't let anything else claim the modem either.
	 */
	state = nm_device_get_state (NM_DEVICE (self));
	if (state != NM_DEVICE_STATE_CONFIG) {
		nm_log_warn (LOGD_BT | LOGD_MB,
		             "(%s): modem found but device not in correct state (%d)",
		             nm_device_get_iface (NM_DEVICE (self)),
		             nm_device_get_state (NM_DEVICE (self)));
		return TRUE;
	}

	nm_log_info (LOGD_BT | LOGD_MB,
	             "Activation (%s/bluetooth) Stage 2 of 5 (Device Configure) modem found.",
	             nm_device_get_iface (NM_DEVICE (self)));

	if (priv->modem) {
		g_warn_if_reached ();
		g_object_unref (priv->modem);
	}

	priv->modem = g_object_ref (modem);
	g_signal_connect (modem, NM_MODEM_PPP_STATS, G_CALLBACK (ppp_stats), self);
	g_signal_connect (modem, NM_MODEM_PPP_FAILED, G_CALLBACK (ppp_failed), self);
	g_signal_connect (modem, NM_MODEM_PREPARE_RESULT, G_CALLBACK (modem_prepare_result), self);
	g_signal_connect (modem, NM_MODEM_IP4_CONFIG_RESULT, G_CALLBACK (modem_ip4_config_result), self);
	g_signal_connect (modem, NM_MODEM_AUTH_REQUESTED, G_CALLBACK (modem_auth_requested), self);
	g_signal_connect (modem, NM_MODEM_AUTH_RESULT, G_CALLBACK (modem_auth_result), self);

	/* In the old ModemManager the data port is known from the very beginning;
	 * while in the new ModemManager the data port is set afterwards when the bearer gets
	 * created */
	if (modem_data_port)
		nm_device_set_ip_iface (NM_DEVICE (self), modem_data_port);
	g_signal_connect (modem, "notify::" NM_MODEM_DATA_PORT, G_CALLBACK (data_port_changed_cb), self);

	/* Kick off the modem connection */
	if (!modem_stage1 (self, modem, &reason))
		nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_FAILED, reason);

	return TRUE;
}
Exemple #23
0
static void
cinnamon_dbus_init (gboolean replace)
{
    GError *error = NULL;
    DBusGConnection *session;
    DBusGProxy *bus;
    guint32 request_name_flags;
    guint32 request_name_result;

    /** TODO:
     * In the future we should use GDBus for this.  However, in
     * order to do that, we need to port all of the JavaScript
     * code.  Otherwise, the name will be claimed on the wrong
     * connection.
     */
    session = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);

    bus = dbus_g_proxy_new_for_name (session,
                                     DBUS_SERVICE_DBUS,
                                     DBUS_PATH_DBUS,
                                     DBUS_INTERFACE_DBUS);

    request_name_flags = DBUS_NAME_FLAG_DO_NOT_QUEUE | DBUS_NAME_FLAG_ALLOW_REPLACEMENT;
    if (replace)
        request_name_flags |= DBUS_NAME_FLAG_REPLACE_EXISTING;
    if (!dbus_g_proxy_call (bus, "RequestName", &error,
                            G_TYPE_STRING, CINNAMON_DBUS_SERVICE,
                            G_TYPE_UINT, request_name_flags,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &request_name_result,
                            G_TYPE_INVALID))
    {
        g_printerr ("failed to acquire org.Cinnamon: %s\n", error->message);
        exit (1);
    }
    if (!(request_name_result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER
            || request_name_result == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER))
    {
        g_printerr ("%s already exists on bus and --replace not specified\n",
                    CINNAMON_DBUS_SERVICE);
        exit (1);
    }

    /* Also grab org.gnome.Panel to replace any existing panel process */
    if (!dbus_g_proxy_call (bus, "RequestName", &error, G_TYPE_STRING,
                            "org.gnome.Panel", G_TYPE_UINT,
                            DBUS_NAME_FLAG_REPLACE_EXISTING | request_name_flags,
                            G_TYPE_INVALID, G_TYPE_UINT,
                            &request_name_result, G_TYPE_INVALID))
    {
        g_print ("failed to acquire org.gnome.Panel: %s\n", error->message);
        exit (1);
    }

    /* ...and the org.gnome.Magnifier service.
     */
    if (!dbus_g_proxy_call (bus, "RequestName", &error,
                            G_TYPE_STRING, MAGNIFIER_DBUS_SERVICE,
                            G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING | request_name_flags,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &request_name_result,
                            G_TYPE_INVALID))
    {
        g_print ("failed to acquire %s: %s\n", MAGNIFIER_DBUS_SERVICE, error->message);
        /* Failing to acquire the magnifer service is not fatal.  Log the error,
         * but keep going. */
    }

    /* ...and the org.freedesktop.Notifications service; we always
     * specify REPLACE_EXISTING to ensure we kill off
     * notification-daemon if it was running.
     */
    if (!dbus_g_proxy_call (bus, "RequestName", &error,
                            G_TYPE_STRING, "org.freedesktop.Notifications",
                            G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING | request_name_flags,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &request_name_result,
                            G_TYPE_INVALID))
    {
        g_print ("failed to acquire org.freedesktop.Notifications: %s\n", error->message);
    }

    /* ...and the on-screen keyboard service */
    if (!dbus_g_proxy_call (bus, "RequestName", &error,
                            G_TYPE_STRING, "org.gnome.Caribou.Keyboard",
                            G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &request_name_result,
                            G_TYPE_INVALID))
    {
        g_print ("failed to acquire org.gnome.Caribou.Keyboard: %s\n", error->message);
    }

    g_object_unref (bus);
}
Exemple #24
0
GtkWidget *
na_tray_child_new (GdkScreen *screen,
                   Window     icon_window)
{
  XWindowAttributes window_attributes;
  Display *xdisplay;
  NaTrayChild *child;
  GdkVisual *visual;
  gboolean visual_has_alpha;
#if !GTK_CHECK_VERSION (3, 0, 0)
  GdkColormap *colormap;
  gboolean new_colormap;
#endif
  int red_prec, green_prec, blue_prec, depth;
  int result;

  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
  g_return_val_if_fail (icon_window != None, NULL);

  xdisplay = GDK_SCREEN_XDISPLAY (screen);

  /* We need to determine the visual of the window we are embedding and create
   * the socket in the same visual.
   */

  gdk_error_trap_push ();
  result = XGetWindowAttributes (xdisplay, icon_window,
                                 &window_attributes);
#if GTK_CHECK_VERSION (3, 0, 0)
  gdk_error_trap_pop_ignored ();
#else
  gdk_error_trap_pop ();
#endif

  if (!result) /* Window already gone */
    return NULL;

  visual = gdk_x11_screen_lookup_visual (screen,
                                         window_attributes.visual->visualid);
  if (!visual) /* Icon window is on another screen? */
    return NULL;

#if !GTK_CHECK_VERSION (3, 0, 0)
  new_colormap = FALSE;

  if (visual == gdk_screen_get_rgb_visual (screen))
    colormap = gdk_screen_get_rgb_colormap (screen);
  else if (visual == gdk_screen_get_rgba_visual (screen))
    colormap = gdk_screen_get_rgba_colormap (screen);
  else if (visual == gdk_screen_get_system_visual (screen))
    colormap = gdk_screen_get_system_colormap (screen);
  else
    {
      colormap = gdk_colormap_new (visual, FALSE);
      new_colormap = TRUE;
    }
#endif

  child = g_object_new (NA_TYPE_TRAY_CHILD, NULL);
  child->icon_window = icon_window;

#if GTK_CHECK_VERSION (3, 0, 0)
  gtk_widget_set_visual (GTK_WIDGET (child), visual);
#else
  gtk_widget_set_colormap (GTK_WIDGET (child), colormap);
#endif

  /* We have alpha if the visual has something other than red, green,
   * and blue */
  gdk_visual_get_red_pixel_details (visual, NULL, NULL, &red_prec);
  gdk_visual_get_green_pixel_details (visual, NULL, NULL, &green_prec);
  gdk_visual_get_blue_pixel_details (visual, NULL, NULL, &blue_prec);
  depth = gdk_visual_get_depth (visual);

  visual_has_alpha = red_prec + blue_prec + green_prec < depth;
  child->has_alpha = (visual_has_alpha &&
                      gdk_display_supports_composite (gdk_screen_get_display (screen)));

  child->composited = child->has_alpha;

#if !GTK_CHECK_VERSION (3, 0, 0)
  if (new_colormap)
    g_object_unref (colormap);
#endif

  return GTK_WIDGET (child);
}
Exemple #25
0
static void
run (const gchar      *name,
     gint              nparams,
     const GimpParam  *param,
     gint             *nreturn_vals,
     GimpParam       **return_vals)
{
  GimpPDBStatusType         status   = GIMP_PDB_CALLING_ERROR;
  gint                      proc     = NONE;
  GimpRunMode               run_mode = GIMP_RUN_NONINTERACTIVE;
  gint32                    image    = -1;
  const gchar              *filename = NULL;
  GimpColorConfig          *config   = NULL;
  gboolean                  dont_ask = FALSE;
  GimpColorRenderingIntent  intent;
  gboolean                  bpc;
  static GimpParam          values[6];

  INIT_I18N ();
  gegl_init (NULL, NULL);

  values[0].type = GIMP_PDB_STATUS;

  *nreturn_vals = 1;
  *return_vals  = values;

  for (proc = 0; proc < G_N_ELEMENTS (procedures); proc++)
    {
      if (strcmp (name, procedures[proc].name) == 0)
        break;
    }

  if (proc == NONE)
    goto done;

  if (nparams < procedures[proc].min_params)
    goto done;

  if (proc != PROC_FILE_INFO)
    {
      config = gimp_get_color_configuration ();
      /* Later code relies on config != NULL if proc != PROC_FILE_INFO */
      g_return_if_fail (config != NULL);
      intent = config->display_intent;
    }
  else
    intent = GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL;

  bpc = (intent == GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC);

  switch (proc)
    {
    case PROC_SET:
      run_mode = param[0].data.d_int32;
      image    = param[1].data.d_image;
      if (nparams > 2)
        filename = param[2].data.d_string;
      break;

    case PROC_APPLY:
      run_mode = param[0].data.d_int32;
      image    = param[1].data.d_image;
      if (nparams > 2)
        filename = param[2].data.d_string;
      if (nparams > 3)
        intent = param[3].data.d_int32;
      if (nparams > 4)
        bpc    = param[4].data.d_int32 ? TRUE : FALSE;
      break;

    case PROC_SET_RGB:
      run_mode = param[0].data.d_int32;
      image    = param[1].data.d_image;
      break;

    case PROC_APPLY_RGB:
      run_mode = param[0].data.d_int32;
      image    = param[1].data.d_image;
      if (nparams > 2)
        intent = param[2].data.d_int32;
      if (nparams > 3)
        bpc    = param[3].data.d_int32 ? TRUE : FALSE;
      break;

    case PROC_INFO:
      image    = param[0].data.d_image;
      break;

    case PROC_FILE_INFO:
      filename = param[0].data.d_string;
      break;
    }

  if (run_mode == GIMP_RUN_INTERACTIVE)
    {
      LcmsValues values = { intent, bpc };

      switch (proc)
        {
        case PROC_SET:
          status = lcms_dialog (config, image, FALSE, &values);
          goto done;

        case PROC_APPLY:
          gimp_get_data (name, &values);

          status = lcms_dialog (config, image, TRUE, &values);

          if (status == GIMP_PDB_SUCCESS)
            gimp_set_data (name, &values, sizeof (LcmsValues));
          goto done;

        default:
          break;
        }
    }

  switch (proc)
    {
    case PROC_SET:
    case PROC_SET_RGB:
      status = lcms_icc_set (config, image, filename);
      break;

    case PROC_APPLY:
    case PROC_APPLY_RGB:
      status = lcms_icc_apply (config, run_mode,
                               image, filename, intent, bpc,
                               &dont_ask);

      if (run_mode == GIMP_RUN_INTERACTIVE)
        {
          *nreturn_vals = 2;

          values[1].type         = GIMP_PDB_INT32;
          values[1].data.d_int32 = dont_ask;
        }
      break;

    case PROC_INFO:
    case PROC_FILE_INFO:
      {
        gchar  *name  = NULL;
        gchar  *desc  = NULL;
        gchar  *info  = NULL;
        GError *error = NULL;

        if (proc == PROC_INFO)
          status = lcms_icc_info (config, image, &name, &desc, &info);
        else
          status = lcms_icc_file_info (filename, &name, &desc, &info, &error);

        if (status == GIMP_PDB_SUCCESS)
          {
            *nreturn_vals = NUM_RETURN_VALS;

            values[PROFILE_NAME].type          = GIMP_PDB_STRING;
            values[PROFILE_NAME].data.d_string = name;

            values[PROFILE_DESC].type          = GIMP_PDB_STRING;
            values[PROFILE_DESC].data.d_string = desc;

            values[PROFILE_INFO].type          = GIMP_PDB_STRING;
            values[PROFILE_INFO].data.d_string = info;
          }
        else if (error)
          {
            *nreturn_vals = 2;

            values[1].type          = GIMP_PDB_STRING;
            values[1].data.d_string = error->message;
          }
      }
      break;
    }

 done:
  if (run_mode != GIMP_RUN_NONINTERACTIVE)
    gimp_displays_flush ();

  if (config)
    g_object_unref (config);

  values[0].data.d_status = status;
}
/**
 * fo_property_keep_together_within_page_validate:
 * @datatype: #FoDatatype to be validated against allowed datatypes and
 *            values for current property.
 * @context:  #FoContext object from which to possibly inherit values.
 * @error:    Information about any error that has occurred.
 * 
 * Validates @datatype against allowed values.  Returns @datatype, a
 * replacement datatype value, or NULL if validation failed.
 * 
 * Return value: Valid datatype value or NULL.
 **/
FoDatatype*
fo_property_keep_together_within_page_validate (FoDatatype *datatype,
                                                FoContext  *context,
                                                GError    **error)
{
  FoDatatype *new_datatype;
  GError     *tmp_error = NULL;
  gchar      *token;

  g_return_val_if_fail (datatype != NULL, NULL);
  g_return_val_if_fail (FO_IS_DATATYPE (datatype), NULL);
  g_return_val_if_fail (context != NULL, NULL);
  g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (FO_IS_ENUM (datatype))
    {
      return datatype;
    }
  else if (FO_IS_STRING (datatype))
    {
      token = fo_string_get_value (datatype);

      new_datatype =
        fo_property_util_resolve_auto_always_enum (token, context, &tmp_error);

      g_object_unref (datatype);

      if (tmp_error != NULL)
	{
	  g_propagate_error (error, tmp_error);
	  return NULL;
	}

      return new_datatype;
    }
  else if (FO_IS_NAME (datatype))
    {
      token = fo_name_get_value (datatype);

      new_datatype =
        fo_property_util_resolve_auto_always_enum (token, context, &tmp_error);

      g_object_unref (datatype);

      if (tmp_error != NULL)
	{
	  g_propagate_error (error, tmp_error);
	  return NULL;
	}

      return new_datatype;
    }
  else if (FO_IS_INTEGER (datatype))
    {
      return datatype;
    }
  else if (FO_IS_NUMBER (datatype))
    {
      new_datatype =
        fo_integer_new_with_value ((gint) fo_number_get_value (datatype));

      g_object_unref (datatype);

      return new_datatype;
    }
  else
    {
      gchar *datatype_sprintf = fo_object_sprintf (datatype);

      g_set_error (error,
		   FO_FO_ERROR,
		   FO_FO_ERROR_DATATYPE,
		   _(fo_fo_error_messages[FO_FO_ERROR_DATATYPE]),
		   class_name,
		   datatype_sprintf,
		   g_type_name (G_TYPE_FROM_INSTANCE (datatype)));

      g_object_unref (datatype);

      g_free (datatype_sprintf);

      return NULL;
    }
}
Exemple #27
0
GList*
seaf_share_manager_list_org_share_repos (SeafShareManager *mgr,
                                         int org_id,
                                         const char *email,
                                         const char *type,
                                         int start, int limit)
{
    GList *ret = NULL, *p;
    char sql[512];

    if (start == -1 && limit == -1) {
        if (g_strcmp0 (type, "from_email") == 0) {
            snprintf (sql, sizeof(sql),
                      "SELECT SharedRepo.repo_id, VirtualRepo.repo_id, "
                      "to_email, permission, commit_id FROM "
                      "SharedRepo LEFT JOIN VirtualRepo ON "
                      "SharedRepo.repo_id = VirtualRepo.repo_id, "
                      "OrgRepo, Branch "
                      "WHERE from_email='%s' AND "
                      "OrgRepo.org_id=%d AND "
                      "SharedRepo.repo_id=OrgRepo.repo_id AND "
                      "SharedRepo.repo_id = Branch.repo_id AND "
                      "Branch.name = 'master'",
                      email, org_id);
        } else if (g_strcmp0 (type, "to_email") == 0) {
            snprintf (sql, sizeof(sql),
                      "SELECT SharedRepo.repo_id, NULL, "
                      "from_email, permission, commit_id FROM "
                      "SharedRepo, OrgRepo, Branch "
                      "WHERE to_email='%s' AND "
                      "OrgRepo.org_id=%d AND "
                      "SharedRepo.repo_id=OrgRepo.repo_id AND "
                      "SharedRepo.repo_id = Branch.repo_id AND "
                      "Branch.name = 'master'",
                      email, org_id);
        } else {
            /* should never reach here */
            g_warning ("[share mgr] Wrong column type");
            return NULL;
        }
    }
    else {
        if (g_strcmp0 (type, "from_email") == 0) {
            snprintf (sql, sizeof(sql),
                      "SELECT SharedRepo.repo_id, VirtualRepo.repo_id, "
                      "to_email, permission, commit_id FROM "
                      "SharedRepo LEFT JOIN VirtualRepo ON "
                      "SharedRepo.repo_id = VirtualRepo.repo_id, "
                      "OrgRepo, Branch "
                      "WHERE from_email='%s' AND "
                      "OrgRepo.org_id=%d AND "
                      "SharedRepo.repo_id=OrgRepo.repo_id AND "
                      "SharedRepo.repo_id = Branch.repo_id AND "
                      "Branch.name = 'master' "
                      "ORDER BY SharedRepo.repo_id "
                      "LIMIT %d OFFSET %d",
                      email, org_id, limit, start);
        } else if (g_strcmp0 (type, "to_email") == 0) {
            snprintf (sql, sizeof(sql),
                      "SELECT SharedRepo.repo_id, NULL, "
                      "from_email, permission FROM "
                      "SharedRepo, OrgRepo, Branch WHERE "
                      "to_email='%s' AND "
                      "OrgRepo.org_id=%d AND "
                      "SharedRepo.repo_id=OrgRepo.repo_id "
                      "SharedRepo.repo_id = Branch.repo_id AND "
                      "Branch.name = 'master' "
                      "ORDER BY SharedRepo.repo_id "
                      "LIMIT %d OFFSET %d",
                      email, org_id, limit, start);
        } else {
            /* should never reach here */
            g_warning ("[share mgr] Wrong column type");
            return NULL;
        }
    }

    if (seaf_db_foreach_selected_row (mgr->seaf->db, sql,
                                      collect_repos, &ret) < 0) {
        g_warning ("[share mgr] DB error when get shared repo id and email "
                   "for %s.\n", email);
        for (p = ret; p; p = p->next)
            g_object_unref (p->data);
        g_list_free (ret);
        return NULL;
    }

    return g_list_reverse (ret);
}
Exemple #28
0
static gboolean
gsf_outfile_open_pkg_close (GsfOutput *output)
{
	GsfOutfileOpenPkg *open_pkg = GSF_OUTFILE_OPEN_PKG (output);
	GsfOutput *dir;
	gboolean res = FALSE;
	char *rels_name;

	if (NULL == open_pkg->sink || gsf_output_is_closed (open_pkg->sink))
		return TRUE;

	/* Generate [Content_types].xml when we close the root dir */
	if (NULL == gsf_output_name (output)) {
		GsfOutput *out = gsf_outfile_new_child (GSF_OUTFILE (open_pkg->sink),
			"[Content_Types].xml", FALSE);
		GsfXMLOut *xml = gsf_xml_out_new (out);

		gsf_xml_out_start_element (xml, "Types");
		gsf_xml_out_add_cstr_unchecked (xml, "xmlns",
			"http://schemas.openxmlformats.org/package/2006/content-types");
		gsf_open_pkg_write_content_default (xml, "rels",
			"application/vnd.openxmlformats-package.relationships+xml");
		gsf_open_pkg_write_content_default (xml, "xlbin",
			"application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings");
		gsf_open_pkg_write_content_default (xml, "xml",
			"application/xml");
		gsf_open_pkg_write_content_override (open_pkg, "/", xml);
		gsf_xml_out_end_element (xml); /* </Types> */
		g_object_unref (xml);

		gsf_output_close (out);
		g_object_unref (out);

		dir = open_pkg->sink;
		rels_name = g_strdup (".rels");
	} else {
		res = gsf_output_close (open_pkg->sink);

		dir = (GsfOutput *)gsf_output_container (open_pkg->sink);
		rels_name = g_strconcat (gsf_output_name (output), ".rels", NULL);
	}

	if (NULL != open_pkg->relations) {
		GsfOutput *rels;
		GsfXMLOut *xml;
		GsfOpenPkgRel *rel;
		GSList *ptr;

		dir = gsf_outfile_new_child (GSF_OUTFILE (dir), "_rels", TRUE);
		rels = gsf_outfile_new_child (GSF_OUTFILE (dir), rels_name, FALSE);
		xml = gsf_xml_out_new (rels);

		gsf_xml_out_start_element (xml, "Relationships");
		gsf_xml_out_add_cstr_unchecked (xml, "xmlns",
			"http://schemas.openxmlformats.org/package/2006/relationships");

		for (ptr = open_pkg->relations ; ptr != NULL ; ptr = ptr->next) {
			rel = ptr->data;
			gsf_xml_out_start_element (xml, "Relationship");
			gsf_xml_out_add_cstr (xml, "Id", rel->id);
			gsf_xml_out_add_cstr (xml, "Type", rel->type);
			gsf_xml_out_add_cstr (xml, "Target", rel->target);
			if (rel->is_extern)
				gsf_xml_out_add_cstr_unchecked (xml, "TargetMode", "External");
			gsf_xml_out_end_element (xml); /* </Relationship> */

			g_free (rel->id);
			g_free (rel->type);
			g_free (rel->target);
			g_free (rel);
		}
		g_slist_free (open_pkg->relations);

		gsf_xml_out_end_element (xml); /* </Relationships> */
		g_object_unref (xml);
		gsf_output_close (rels);
		g_object_unref (rels);
		g_object_unref (dir);
	}
	g_free (rels_name);

	/* close the container */
	if (NULL == gsf_output_name (output))
		return gsf_output_close (open_pkg->sink);
	return res;
}
Exemple #29
0
static void ipcam_itrain_before_start(IpcamBaseService *base_service)
{
    IpcamITrain *itrain = IPCAM_ITRAIN(base_service);
    IpcamITrainPrivate *priv = ipcam_itrain_get_instance_private(itrain);
    const gchar *addr = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "itrain:address");
    const gchar *port = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "itrain:port");
	const gchar *osd_port = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "itrain:osd-port");
	JsonBuilder *builder;
	const gchar *token = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "token");
	IpcamRequestMessage *req_msg;

    if (!addr || !port)
    {
        g_critical("address and port must be specified.\n");
        return;
    }
    priv->itrain_server = g_object_new(IPCAM_TYPE_ITRAIN_SERVER,
                                       "itrain", itrain,
                                       "address", addr,
                                       "port", strtoul(port, NULL, 0),
                                       "osd-port", strtoul(osd_port, NULL, 0),
                                       NULL);

    ipcam_base_app_register_notice_handler(IPCAM_BASE_APP(itrain), "video_occlusion_event", IPCAM_TYPE_ITRAIN_EVENT_HANDLER);
    ipcam_base_app_register_notice_handler(IPCAM_BASE_APP(itrain), "set_base_info", IPCAM_TYPE_ITRAIN_EVENT_HANDLER);
    ipcam_base_app_register_notice_handler(IPCAM_BASE_APP(itrain), "set_szyc", IPCAM_TYPE_ITRAIN_EVENT_HANDLER);

	/* Request the Base Information */
	builder = json_builder_new();
	json_builder_begin_object(builder);
	json_builder_set_member_name(builder, "items");
	json_builder_begin_array(builder);
	json_builder_add_string_value(builder, "device_name");
	json_builder_add_string_value(builder, "comment");
	json_builder_add_string_value(builder, "location");
	json_builder_add_string_value(builder, "hardware");
	json_builder_add_string_value(builder, "firmware");
	json_builder_add_string_value(builder, "manufacturer");
	json_builder_add_string_value(builder, "model");
	json_builder_add_string_value(builder, "serial");
    json_builder_add_string_value(builder, "device_type");
	json_builder_end_array(builder);
	json_builder_end_object(builder);
	req_msg = g_object_new(IPCAM_REQUEST_MESSAGE_TYPE,
	                       "action", "get_base_info",
	                       "body", json_builder_get_root(builder),
	                       NULL);
	ipcam_base_app_send_message(IPCAM_BASE_APP(itrain), IPCAM_MESSAGE(req_msg),
	                            "iconfig", token,
	                            base_info_message_handler, 60);
	g_object_unref(req_msg);
	g_object_unref(builder);

    /* Request the SZYC Information */
	builder = json_builder_new();
	json_builder_begin_object(builder);
	json_builder_set_member_name(builder, "items");
	json_builder_begin_array(builder);
	json_builder_add_string_value(builder, "train_num");
	json_builder_add_string_value(builder, "carriage_num");
	json_builder_add_string_value(builder, "position_num");
	json_builder_end_array(builder);
	json_builder_end_object(builder);
	req_msg = g_object_new(IPCAM_REQUEST_MESSAGE_TYPE,
	                       "action", "get_szyc",
	                       "body", json_builder_get_root(builder),
	                       NULL);
	ipcam_base_app_send_message(IPCAM_BASE_APP(itrain), IPCAM_MESSAGE(req_msg),
	                            "iconfig", token,
	                            szyc_message_handler, 60);
	g_object_unref(req_msg);
	g_object_unref(builder);
}
Exemple #30
0
static gboolean
parse_stream_options (CockpitChannel *self,
                      CockpitConnectable *connectable)
{
  gboolean ret = FALSE;
  GTlsCertificate *cert = NULL;
  GTlsDatabase *database = NULL;
  gboolean use_tls = FALSE;
  GError *error = NULL;
  GString *pem = NULL;
  JsonObject *options;
  JsonNode *node;

  /* No validation for local servers by default */
  gboolean validate = !connectable->local;

  node = json_object_get_member (self->priv->open_options, "tls");
  if (node && !JSON_NODE_HOLDS_OBJECT (node))
    {
      cockpit_channel_fail (self, "protocol-error", "invalid \"tls\" option for channel");
      goto out;
    }
  else if (node)
    {
      options = json_node_get_object (node);
      use_tls = TRUE;

      /*
       * The only function in GLib to parse private keys takes
       * them in PEM concatenated form. This is a limitation of GLib,
       * rather than concatenated form being a decent standard for
       * certificates and keys. So build a combined PEM as expected by
       * GLib here.
       */

      pem = g_string_sized_new (8192);

      if (!parse_cert_option_as_pem (self, options, "certificate", pem))
        goto out;

      if (pem->len)
        {
          if (!parse_cert_option_as_pem (self, options, "key", pem))
            goto out;

          cert = g_tls_certificate_new_from_pem (pem->str, pem->len, &error);
          if (error != NULL)
            {
              cockpit_channel_fail (self, "internal-error",
                                    "invalid \"certificate\" or \"key\" content: %s", error->message);
              g_error_free (error);
              goto out;
            }
        }

      if (!parse_cert_option_as_database (self, options, "authority", &database))
        goto out;

      if (!cockpit_json_get_bool (options, "validate", validate, &validate))
        {
          cockpit_channel_fail (self, "protocol-error", "invalid \"validate\" option");
          goto out;
        }
    }

  ret = TRUE;

out:
  if (ret)
    {
      connectable->tls = use_tls;
      connectable->tls_cert = cert;
      cert = NULL;

      if (database)
        {
          connectable->tls_database = database;
          connectable->tls_flags = G_TLS_CERTIFICATE_VALIDATE_ALL;
          if (!validate)
              connectable->tls_flags &= ~(G_TLS_CERTIFICATE_INSECURE | G_TLS_CERTIFICATE_BAD_IDENTITY);
          database = NULL;
        }
      else
        {
          if (validate)
            connectable->tls_flags = G_TLS_CERTIFICATE_VALIDATE_ALL;
          else
            connectable->tls_flags = G_TLS_CERTIFICATE_GENERIC_ERROR;
        }
    }

  if (pem)
    g_string_free (pem, TRUE);
  if (cert)
    g_object_unref (cert);
  if (database)
    g_object_unref (database);

  return ret;
}