Пример #1
0
void near_snep_core_response_with_info(int client_fd, uint8_t response,
				uint8_t *data, int length)
{
	struct p2p_snep_data *snep_data;
	struct p2p_snep_put_req_data *req;
	struct near_ndef_message *ndef;

	DBG("Response with info 0x%x (len:%d)", response, length);

	req = NULL;
	ndef = NULL;

	/* get the snep data */
	snep_data = g_hash_table_lookup(snep_client_hash,
						GINT_TO_POINTER(client_fd));
	if (!snep_data) {
		DBG("snep_data not found");
		goto done;
	}

	/* Prepare the ndef struct */
	ndef = g_try_malloc0(sizeof(struct near_ndef_message));
	if (!ndef)
		goto done;

	ndef->data = g_try_malloc0(length);
	if (!ndef->data) {
		g_free(ndef);
		ndef = NULL;
		goto done;
	}

	/* Fill the ndef */
	ndef->length = length;
	ndef->offset = 0;
	memcpy(ndef->data, data, length);

	ndef->offset = 0;

	/* Now prepare req struct */
	req = g_try_malloc0(sizeof(struct p2p_snep_put_req_data));
	if (!req)
		goto done;

	/* Prepare the callback */
	snep_data->req = req;

	req->fd = client_fd;
	req->adapter_idx = snep_data->adapter_idx;
	req->target_idx = snep_data->target_idx;
	req->cb = snep_data->cb;

	/* send it !*/
	near_snep_core_response(client_fd, req, response, ndef);

done:
	/* If no fragment, free mem */
	if (req) {
		if (req->fragments == 0) {
			g_free(req);
			snep_data->req = NULL;
		}
	}

	if (ndef)
		g_free(ndef->data);
	g_free(ndef);
}
Пример #2
0
gint
main (gint argc, gchar **argv)
{
  GtkWidget *window, *toolbar, *table, *treeview, *scrolled_window;
  GtkWidget *hbox, *hbox1, *hbox2, *checkbox, *option_menu, *menu;
  gint i;
  static const gchar *toolbar_styles[] = { "icons", "text", "both (vertical)",
					   "both (horizontal)" };
  GtkToolItem *item;
  GtkListStore *store;
  GtkWidget *image;
  GtkWidget *menuitem;
  GtkWidget *button;
  GtkWidget *label;
  GIcon *gicon;
  GSList *group;
  
  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

  table = gtk_table_new (4, 2, FALSE);
  gtk_container_add (GTK_CONTAINER (window), table);

  toolbar = gtk_toolbar_new ();
  gtk_table_attach (GTK_TABLE (table), toolbar,
		    0,2, 0,1, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);

  hbox1 = gtk_hbox_new (FALSE, 3);
  gtk_container_set_border_width (GTK_CONTAINER (hbox1), 5);
  gtk_table_attach (GTK_TABLE (table), hbox1,
		    1,2, 1,2, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);

  hbox2 = gtk_hbox_new (FALSE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (hbox2), 5);
  gtk_table_attach (GTK_TABLE (table), hbox2,
		    1,2, 2,3, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);

  checkbox = gtk_check_button_new_with_mnemonic("_Vertical");
  gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0);
  g_signal_connect (checkbox, "toggled",
		    G_CALLBACK (change_orientation), toolbar);

  checkbox = gtk_check_button_new_with_mnemonic("_Show Arrow");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE);
  gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0);
  g_signal_connect (checkbox, "toggled",
		    G_CALLBACK (change_show_arrow), toolbar);

  checkbox = gtk_check_button_new_with_mnemonic("_Set Toolbar Style:");
  g_signal_connect (checkbox, "toggled", G_CALLBACK (set_toolbar_style_toggled), toolbar);
  gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0);
  
  option_menu = gtk_option_menu_new();
  gtk_widget_set_sensitive (option_menu, FALSE);  
  g_object_set_data (G_OBJECT (checkbox), "option-menu", option_menu);
  
  menu = gtk_menu_new();
  for (i = 0; i < G_N_ELEMENTS (toolbar_styles); i++)
    {
      GtkWidget *menuitem;

      menuitem = gtk_menu_item_new_with_label (toolbar_styles[i]);
      gtk_container_add (GTK_CONTAINER (menu), menuitem);
      gtk_widget_show (menuitem);
    }
  gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
  gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu),
			       GTK_TOOLBAR (toolbar)->style);
  gtk_box_pack_start (GTK_BOX (hbox2), option_menu, FALSE, FALSE, 0);
  g_signal_connect (option_menu, "changed",
		    G_CALLBACK (change_toolbar_style), toolbar);

  checkbox = gtk_check_button_new_with_mnemonic("_Set Icon Size:"); 
  g_signal_connect (checkbox, "toggled", G_CALLBACK (set_icon_size_toggled), toolbar);
  gtk_box_pack_start (GTK_BOX (hbox2), checkbox, FALSE, FALSE, 0);

  option_menu = gtk_option_menu_new();
  g_object_set_data (G_OBJECT (checkbox), "option-menu", option_menu);
  gtk_widget_set_sensitive (option_menu, FALSE);
  menu = gtk_menu_new();
  menuitem = gtk_menu_item_new_with_label ("small toolbar");
  g_object_set_data (G_OBJECT (menuitem), "value-id", GINT_TO_POINTER (GTK_ICON_SIZE_SMALL_TOOLBAR));
  gtk_container_add (GTK_CONTAINER (menu), menuitem);
  gtk_widget_show (menuitem);

  menuitem = gtk_menu_item_new_with_label ("large toolbar");
  g_object_set_data (G_OBJECT (menuitem), "value-id", GINT_TO_POINTER (GTK_ICON_SIZE_LARGE_TOOLBAR));
  gtk_container_add (GTK_CONTAINER (menu), menuitem);
  gtk_widget_show (menuitem);

  gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
  gtk_box_pack_start (GTK_BOX (hbox2), option_menu, FALSE, FALSE, 0);
  g_signal_connect (option_menu, "changed",
		    G_CALLBACK (icon_size_history_changed), toolbar);
  
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_table_attach (GTK_TABLE (table), scrolled_window,
		    1,2, 3,4, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);

  store = create_items_list (&treeview);
  gtk_container_add (GTK_CONTAINER (scrolled_window), treeview);
  
  item = gtk_tool_button_new_from_stock (GTK_STOCK_NEW);
  gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Custom label");
  gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), NULL);
  add_item_to_list (store, item, "New");
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
  gdk_threads_add_timeout (3000, (GSourceFunc) timeout_cb, item);
  gtk_tool_item_set_expand (item, TRUE);

  menu = gtk_menu_new ();
  for (i = 0; i < 20; i++)
    {
      char *text;
      text = g_strdup_printf ("Menuitem %d", i);
      menuitem = gtk_menu_item_new_with_label (text);
      g_free (text);
      gtk_widget_show (menuitem);
      gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
    }

  item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN);
  gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
  add_item_to_list (store, item, "Open");
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
  gdk_threads_add_timeout (3000, (GSourceFunc) timeout_cb1, item);
 
  menu = gtk_menu_new ();
  for (i = 0; i < 20; i++)
    {
      char *text;
      text = g_strdup_printf ("A%d", i);
      menuitem = gtk_menu_item_new_with_label (text);
      g_free (text);
      gtk_widget_show (menuitem);
      gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
    }

  item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_BACK);
  gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
  add_item_to_list (store, item, "BackWithHistory");
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
 
  item = gtk_separator_tool_item_new ();
  add_item_to_list (store, item, "-----");    
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
  
  item = gtk_tool_button_new_from_stock (GTK_STOCK_REFRESH);
  add_item_to_list (store, item, "Refresh");
  g_signal_connect (item, "clicked", G_CALLBACK (reload_clicked), NULL);
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);

  image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
  item = gtk_tool_item_new ();
  gtk_widget_show (image);
  gtk_container_add (GTK_CONTAINER (item), image);
  add_item_to_list (store, item, "(Custom Item)");    
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
  
  item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_BACK);
  add_item_to_list (store, item, "Back");    
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);

  item = gtk_separator_tool_item_new ();
  add_item_to_list (store, item, "-----");  
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
  
  item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD);
  add_item_to_list (store, item, "Forward");  
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);

  item = gtk_toggle_tool_button_new_from_stock (GTK_STOCK_BOLD);
  g_signal_connect (item, "toggled", G_CALLBACK (bold_toggled), NULL);
  add_item_to_list (store, item, "Bold");  
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
  gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);

  item = gtk_separator_tool_item_new ();
  add_item_to_list (store, item, "-----");  
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
  gtk_tool_item_set_expand (item, TRUE);
  gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE);
  g_assert (gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), 0) != 0);
  
  item = gtk_radio_tool_button_new_from_stock (NULL, GTK_STOCK_JUSTIFY_LEFT);
  group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
  add_item_to_list (store, item, "Left");
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
  
  
  item = gtk_radio_tool_button_new_from_stock (group, GTK_STOCK_JUSTIFY_CENTER);
  make_prop_editor (G_OBJECT (item));

  group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
  add_item_to_list (store, item, "Center");
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);

  item = gtk_radio_tool_button_new_from_stock (group, GTK_STOCK_JUSTIFY_RIGHT);
  add_item_to_list (store, item, "Right");
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);

  item = gtk_tool_button_new (gtk_image_new_from_file ("apple-red.png"), "_Apple");
  add_item_to_list (store, item, "Apple");
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
  gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (item), TRUE);

  gicon = g_content_type_get_icon ("video/ogg");
  image = gtk_image_new_from_gicon (gicon, GTK_ICON_SIZE_LARGE_TOOLBAR);
  g_object_unref (gicon);
  item = gtk_tool_button_new (image, "Video");
  add_item_to_list (store, item, "Video");
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);

  image = gtk_image_new_from_icon_name ("utility-terminal", GTK_ICON_SIZE_LARGE_TOOLBAR);
  item = gtk_tool_button_new (image, "Terminal");
  add_item_to_list (store, item, "Terminal");
  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);

  hbox = gtk_hbox_new (FALSE, 5);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
  gtk_table_attach (GTK_TABLE (table), hbox,
		    1,2, 4,5, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);

  button = gtk_button_new_with_label ("Drag me to the toolbar");
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);

  label = gtk_label_new ("Drop index:");
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);

  label = gtk_label_new ("");
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);

  checkbox = gtk_check_button_new_with_mnemonic("_Right to left");
  if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE);
  else
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), FALSE);
  g_signal_connect (checkbox, "toggled", G_CALLBACK (rtl_toggled), NULL);

  gtk_box_pack_end (GTK_BOX (hbox), checkbox, FALSE, FALSE, 0);
  
  gtk_drag_source_set (button, GDK_BUTTON1_MASK,
		       target_table, G_N_ELEMENTS (target_table),
		       GDK_ACTION_MOVE);
  gtk_drag_dest_set (toolbar, GTK_DEST_DEFAULT_DROP,
		     target_table, G_N_ELEMENTS (target_table),
		     GDK_ACTION_MOVE);
  g_signal_connect (toolbar, "drag_motion",
		    G_CALLBACK (toolbar_drag_motion), NULL);
  g_signal_connect (toolbar, "drag_leave",
		    G_CALLBACK (toolbar_drag_leave), NULL);
  g_signal_connect (toolbar, "drag_drop",
		    G_CALLBACK (toolbar_drag_drop), label);

  gtk_widget_show_all (window);

  make_prop_editor (G_OBJECT (toolbar));

  g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
  
  g_signal_connect (toolbar, "popup_context_menu", G_CALLBACK (popup_context_menu), NULL);
  
  gtk_main ();
  
  return 0;
}
Пример #3
0
				    G_TYPE_INT, /*SEEDP */
				    G_TYPE_STRING,/*STEP */
				    G_TYPE_INT, /*STEPP */
				    G_TYPE_STRING,/*TIMING */
				    G_TYPE_STRING,/*ALL */
				    G_TYPE_STRING,/*REST */
				    G_TYPE_STRING,/*ERRLO */
				    G_TYPE_STRING,/*ERRHI */
				    GDK_TYPE_PIXBUF,/*ACTION */
				    G_TYPE_STRING /*COLOR */
				    );
    GtkWidget *view;
    views[ihost]=view=gtk_tree_view_new_with_model(GTK_TREE_MODEL(lists[ihost]));
    g_object_unref(lists[ihost]);
    g_signal_connect(view, "button-press-event", 
		     G_CALLBACK(view_click_event), GINT_TO_POINTER(ihost));
    g_signal_connect(view, "button-release-event", 
		     G_CALLBACK(view_release_event), GINT_TO_POINTER(ihost));
    g_signal_connect(view, "popup-menu", 
		     G_CALLBACK(view_popup_menu), GINT_TO_POINTER(ihost));
    GtkTreeSelection *viewsel=gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
    /*gtk_tree_selection_set_select_function(viewsel, treeselfun,NULL,NULL); */
    gtk_tree_selection_set_mode(viewsel,GTK_SELECTION_MULTIPLE);
    gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(view), COL_FULL);
    /*
      The implementation of GtkTreeView hardcoded GDK_LINE_ON_OFF_DASH in
      gtk_tree_view_set_grid_lines, which makes it impossible to make solid
      lines. In rc_string (monitor.c) "\255\256" in grid-line-pattern means 255
      pixels of on and 1 pixel of off. I can not have \0 for the second part
      because it terminates the string.
    */
Пример #4
0
GtkWidget *
text_create_widget (GtkWidget * dlg)
{
  GtkWidget *w;

  w = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (w), GTK_SHADOW_ETCHED_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (w),
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

  text_view = gtk_text_view_new ();
  gtk_widget_set_name (text_view, "yad-text-widget");
  text_buffer = gtk_text_buffer_new (NULL);
  gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), text_buffer);
  gtk_text_view_set_justification (GTK_TEXT_VIEW (text_view), options.text_data.justify);
  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (text_view), options.text_data.margins);
  gtk_text_view_set_right_margin (GTK_TEXT_VIEW (text_view), options.text_data.margins);
  gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), options.common_data.editable);
  if (!options.common_data.editable)
    gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE);

  if (options.text_data.wrap)
    gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD_CHAR);

  if (options.text_data.fore)
    {
#if GTK_CHECK_VERSION(3,0,0)
      GdkRGBA clr;
      if (gdk_rgba_parse (&clr, options.text_data.fore))
	gtk_widget_override_color (text_view, GTK_STATE_FLAG_NORMAL, &clr);
#else
      GdkColor clr;
      if (gdk_color_parse (options.text_data.fore, &clr))
	gtk_widget_modify_text (text_view, GTK_STATE_NORMAL, &clr);
#endif
    }

  if (options.text_data.back)
    {
#if GTK_CHECK_VERSION(3,0,0)
      GdkRGBA clr;
      if (gdk_rgba_parse (&clr, options.text_data.fore))
	gtk_widget_override_background_color (text_view, GTK_STATE_FLAG_NORMAL, &clr);
#else
      GdkColor clr;
      if (gdk_color_parse (options.text_data.back, &clr))
	gtk_widget_modify_base (text_view, GTK_STATE_NORMAL, &clr);
#endif
    }

  if (options.common_data.font)
    {
      PangoFontDescription *fd =
	pango_font_description_from_string (options.common_data.font);
#if GTK_CHECK_VERSION(3,0,0)
      gtk_widget_override_font (text_view, fd);
#else
      gtk_widget_modify_font (text_view, fd);
#endif
      pango_font_description_free (fd);
    }

  /* Add submit on ctrl+enter */
  g_signal_connect (text_view, "key-press-event", G_CALLBACK (key_press_cb), dlg);

  /* Initialize linkifying */
  if (options.text_data.uri)
    {
      GRegex *regex;

      regex = g_regex_new (YAD_URL_REGEX,
			   G_REGEX_CASELESS | G_REGEX_OPTIMIZE | G_REGEX_EXTENDED,
			   G_REGEX_MATCH_NOTEMPTY,
			   NULL);

      /* Create text tag for URI */
      tag = gtk_text_buffer_create_tag (text_buffer, NULL,
                                        "foreground", "blue",
                                        "underline", PANGO_UNDERLINE_SINGLE,
                                        NULL);
      g_object_set_data (G_OBJECT (tag), "is_link", GINT_TO_POINTER (1));
      g_signal_connect (G_OBJECT (tag), "event", G_CALLBACK (tag_event_cb), NULL);

      /* Create cursors */
      hand = gdk_cursor_new (GDK_HAND2);
      normal= gdk_cursor_new (GDK_XTERM);
      g_signal_connect (G_OBJECT (text_view), "motion-notify-event", G_CALLBACK (motion_cb), NULL);

      g_signal_connect_after (G_OBJECT (text_buffer), "changed", G_CALLBACK (linkify_cb), regex);
    }

  gtk_container_add (GTK_CONTAINER (w), text_view);

  if (options.common_data.uri)
    fill_buffer_from_file ();
  else
    fill_buffer_from_stdin ();

  return w;
}
Пример #5
0
void
test_array_sort(gpointer data)
{
  const gint32 values[] = {
    5, 6, 18, 9, 0, 4, 13, 12, 8, 14, 19, 11, 7, 3, 1, 10, 15, 2, 17, 16
  };
  const int n_values = sizeof(values) / sizeof(values[0]);
  const gchar table_name[] = "Store";
  const gchar column_name[] = "sample_column";
  const int n_keys = 1;
  grn_table_sort_key keys[n_keys];

  grn_obj *table, *column, *result;
  grn_table_cursor *cursor;
  int n_results;
  guint i;

  guint n_expected_values;
  GList *expected_values, *sorted_values = NULL;

  table = grn_table_create(context, table_name, strlen(table_name),
                           NULL,
                           GRN_OBJ_TABLE_NO_KEY | GRN_OBJ_PERSISTENT,
                           NULL,
                           NULL);
  column = grn_column_create(context,
                             table,
                             column_name,
                             strlen(column_name),
                             NULL, 0,
                             get_object("Int32"));

  keys[0].key = column;
  keys[0].flags = GRN_TABLE_SORT_ASC;

  for(i = 0; i < n_values; ++i) {
    grn_obj record_value;
    grn_id record_id;
    record_id = grn_table_add(context, table, NULL, 0, NULL);

    GRN_INT32_INIT(&record_value, 0);
    GRN_INT32_SET(context, &record_value, values[i]);
    grn_test_assert(grn_obj_set_value(context, column, record_id,
                                      &record_value, GRN_OBJ_SET));
    GRN_OBJ_FIN(context, &record_value);
  }
  cut_assert_equal_int(n_values, grn_table_size(context, table));

  result = grn_table_create(context, NULL, 0, NULL, GRN_TABLE_NO_KEY,
                            NULL, table);
  n_results = grn_table_sort(context, table,
                             gcut_data_get_int(data, "offset"),
                             gcut_data_get_int(data, "limit"),
                             result, keys, n_keys);
  expected_values = (GList *)gcut_data_get_pointer(data, "expected_values");
  n_expected_values = g_list_length(expected_values);
  cut_assert_equal_int(n_expected_values, n_results);
  cut_assert_equal_int(n_expected_values, grn_table_size(context, result));

  cursor = grn_table_cursor_open(context, result, NULL, 0, NULL, 0,
                                 0, -1, GRN_CURSOR_ASCENDING);
  while (grn_table_cursor_next(context, cursor) != GRN_ID_NIL) {
    void *value;
    grn_id *id;
    grn_obj record_value;

    grn_table_cursor_get_value(context, cursor, &value);
    id = value;

    GRN_INT32_INIT(&record_value, 0);
    grn_obj_get_value(context, column, *id, &record_value);
    sorted_values = g_list_append(sorted_values,
                                  GINT_TO_POINTER(GRN_INT32_VALUE(&record_value)));
    GRN_OBJ_FIN(context, &record_value);
  }
  gcut_take_list(sorted_values, NULL);
  gcut_assert_equal_list_int(expected_values, sorted_values);

  grn_table_cursor_close(context, cursor);
  grn_obj_close(context, result);
}
Пример #6
0
/** Creates a list of transactions from parsed data. Transactions that
 * could be created from rows are placed in parse_data->transactions;
 * rows that fail are placed in parse_data->error_lines. (Note: there
 * is no way for this function to "fail," i.e. it only returns 0, so
 * it may be changed to a void function in the future.)
 * @param parse_data Data that is being parsed
 * @param account Account with which transactions are created
 * @param redo_errors TRUE to convert only error data, FALSE for all data
 * @return 0 on success, 1 on failure
 */
int gnc_csv_parse_to_trans(GncCsvParseData* parse_data, Account* account,
                           gboolean redo_errors)
{
    gboolean hasBalanceColumn;
    int i, j, max_cols = 0;
    GArray* column_types = parse_data->column_types;
    GList *error_lines = NULL, *begin_error_lines = NULL;

    /* last_transaction points to the last element in
     * parse_data->transactions, or NULL if it's empty. */
    GList* last_transaction = NULL;

    /* Free parse_data->error_lines and parse_data->transactions if they
     * already exist. */
    if (redo_errors) /* If we're redoing errors, we save freeing until the end. */
    {
        begin_error_lines = error_lines = parse_data->error_lines;
    }
    else
    {
        if (parse_data->error_lines != NULL)
        {
            g_list_free(parse_data->error_lines);
        }
        if (parse_data->transactions != NULL)
        {
            g_list_free(parse_data->transactions);
        }
    }
    parse_data->error_lines = NULL;

    if (redo_errors) /* If we're looking only at error data ... */
    {
        if (parse_data->transactions == NULL)
        {
            last_transaction = NULL;
        }
        else
        {
            /* Move last_transaction to the end. */
            last_transaction = parse_data->transactions;
            while (g_list_next(last_transaction) != NULL)
            {
                last_transaction = g_list_next(last_transaction);
            }
        }
        /* ... we use only the lines in error_lines. */
        if (error_lines == NULL)
            i = parse_data->orig_lines->len; /* Don't go into the for loop. */
        else
            i = GPOINTER_TO_INT(error_lines->data);
    }
    else /* Otherwise, we look at all the data. */
    {
        /* The following while-loop effectively behaves like the following for-loop:
         * for(i = 0; i < parse_data->orig_lines->len; i++). */
        i = 0;
        last_transaction = NULL;
    }
    while (i < parse_data->orig_lines->len)
    {
        GPtrArray* line = parse_data->orig_lines->pdata[i];
        /* This flag is TRUE if there are any errors in this row. */
        gboolean errors = FALSE;
        gchar* error_message = NULL;
        TransPropertyList* list = trans_property_list_new(account, parse_data->date_format);
        GncCsvTransLine* trans_line = NULL;

        for (j = 0; j < line->len; j++)
        {
            /* We do nothing in "None" columns. */
            if (column_types->data[j] != GNC_CSV_NONE)
            {
                /* Affect the transaction appropriately. */
                TransProperty* property = trans_property_new(column_types->data[j], list);
                gboolean succeeded = trans_property_set(property, line->pdata[j]);
                /* TODO Maybe move error handling to within TransPropertyList functions? */
                if (succeeded)
                {
                    trans_property_list_add(property);
                }
                else
                {
                    errors = TRUE;
                    error_message = g_strdup_printf(_("%s column could not be understood."),
                                                    _(gnc_csv_column_type_strs[property->type]));
                    trans_property_free(property);
                    break;
                }
            }
        }

        /* If we had success, add the transaction to parse_data->transaction. */
        if (!errors)
        {
            trans_line = trans_property_list_to_trans(list, &error_message);
            errors = trans_line == NULL;
        }

        trans_property_list_free(list);

        /* If there were errors, add this line to parse_data->error_lines. */
        if (errors)
        {
            parse_data->error_lines = g_list_append(parse_data->error_lines,
                                                    GINT_TO_POINTER(i));
            /* If there's already an error message, we need to replace it. */
            if (line->len > (int)(parse_data->orig_row_lengths->data[i]))
            {
                g_free(line->pdata[line->len - 1]);
                line->pdata[line->len - 1] = error_message;
            }
            else
            {
                /* Put the error message at the end of the line. */
                g_ptr_array_add(line, error_message);
            }
        }
        else
        {
            /* If all went well, add this transaction to the list. */
            trans_line->line_no = i;

            /* We keep the transactions sorted by date. We start at the end
             * of the list and go backward, simply because the file itself
             * is probably also sorted by date (but we need to handle the
             * exception anyway). */

            /* If we can just put it at the end, do so and increment last_transaction. */
            if (last_transaction == NULL ||
                    xaccTransGetDate(((GncCsvTransLine*)(last_transaction->data))->trans) <= xaccTransGetDate(trans_line->trans))
            {
                parse_data->transactions = g_list_append(parse_data->transactions, trans_line);
                /* If this is the first transaction, we need to get last_transaction on track. */
                if (last_transaction == NULL)
                    last_transaction = parse_data->transactions;
                else /* Otherwise, we can just continue. */
                    last_transaction = g_list_next(last_transaction);
            }
            /* Otherwise, search backward for the correct spot. */
            else
            {
                GList* insertion_spot = last_transaction;
                while (insertion_spot != NULL &&
                        xaccTransGetDate(((GncCsvTransLine*)(insertion_spot->data))->trans) > xaccTransGetDate(trans_line->trans))
                {
                    insertion_spot = g_list_previous(insertion_spot);
                }
                /* Move insertion_spot one location forward since we have to
                 * use the g_list_insert_before function. */
                if (insertion_spot == NULL) /* We need to handle the case of inserting at the beginning of the list. */
                    insertion_spot = parse_data->transactions;
                else
                    insertion_spot = g_list_next(insertion_spot);

                parse_data->transactions = g_list_insert_before(parse_data->transactions, insertion_spot, trans_line);
            }
        }

        /* Increment to the next row. */
        if (redo_errors)
        {
            /* Move to the next error line in the list. */
            error_lines = g_list_next(error_lines);
            if (error_lines == NULL)
                i = parse_data->orig_lines->len; /* Don't continue the for loop. */
            else
                i = GPOINTER_TO_INT(error_lines->data);
        }
        else
        {
            i++;
        }
    }

    /* If we have a balance column, set the appropriate amounts on the transactions. */
    hasBalanceColumn = FALSE;
    for (i = 0; i < parse_data->column_types->len; i++)
    {
        if (parse_data->column_types->data[i] == GNC_CSV_BALANCE)
        {
            hasBalanceColumn = TRUE;
            break;
        }
    }

    if (hasBalanceColumn)
    {
        GList* transactions = parse_data->transactions;

        /* balance_offset is how much the balance currently in the account
         * differs from what it will be after the transactions are
         * imported. This will be sum of all the previous transactions for
         * any given transaction. */
        gnc_numeric balance_offset = double_to_gnc_numeric(0.0,
                                     xaccAccountGetCommoditySCU(account),
                                     GNC_RND_ROUND);
        while (transactions != NULL)
        {
            GncCsvTransLine* trans_line = (GncCsvTransLine*)transactions->data;
            if (trans_line->balance_set)
            {
                time_t date = xaccTransGetDate(trans_line->trans);
                /* Find what the balance should be by adding the offset to the actual balance. */
                gnc_numeric existing_balance = gnc_numeric_add(balance_offset,
                                               xaccAccountGetBalanceAsOfDate(account, date),
                                               xaccAccountGetCommoditySCU(account),
                                               GNC_RND_ROUND);

                /* The amount of the transaction is the difference between the new and existing balance. */
                gnc_numeric amount = gnc_numeric_sub(trans_line->balance,
                                                     existing_balance,
                                                     xaccAccountGetCommoditySCU(account),
                                                     GNC_RND_ROUND);

                SplitList* splits = xaccTransGetSplitList(trans_line->trans);
                while (splits)
                {
                    SplitList* next_splits = g_list_next(splits);
                    xaccSplitDestroy((Split*)splits->data);
                    splits = next_splits;
                }

                trans_add_split(trans_line->trans, account, gnc_account_get_book(account), amount);

                /* This new transaction needs to be added to the balance offset. */
                balance_offset = gnc_numeric_add(balance_offset,
                                                 amount,
                                                 xaccAccountGetCommoditySCU(account),
                                                 GNC_RND_ROUND);
            }
            transactions = g_list_next(transactions);
        }
    }

    if (redo_errors) /* Now that we're at the end, we do the freeing. */
    {
        g_list_free(begin_error_lines);
    }

    /* We need to resize parse_data->column_types since errors may have added columns. */
    for (i = 0; i < parse_data->orig_lines->len; i++)
    {
        if (max_cols < ((GPtrArray*)(parse_data->orig_lines->pdata[i]))->len)
            max_cols = ((GPtrArray*)(parse_data->orig_lines->pdata[i]))->len;
    }
    i = parse_data->column_types->len;
    parse_data->column_types = g_array_set_size(parse_data->column_types, max_cols);
    for (; i < max_cols; i++)
    {
        parse_data->column_types->data[i] = GNC_CSV_NONE;
    }

    return 0;
}
Пример #7
0
static void schedule_video_controls_disapearance(GtkWidget *w){
	gint timeout=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"timeout"));
	if (timeout != 0) g_source_remove(timeout);
	timeout=g_timeout_add(3000,(GSourceFunc)do_gtk_widget_destroy,w);
	g_object_set_data(G_OBJECT(w),"timeout",GINT_TO_POINTER(timeout));
}
Пример #8
0
/**
 * mono_process_list:
 * @size: a pointer to a location where the size of the returned array is stored
 *
 * Return an array of pid values for the processes currently running on the system.
 * The size of the array is stored in @size.
 */
gpointer*
mono_process_list (int *size)
{
#if USE_SYSCTL
	int res, i;
#ifdef KERN_PROC2
	int mib [6];
	size_t data_len = sizeof (struct kinfo_proc2) * 400;
	struct kinfo_proc2 *processes = malloc (data_len);
#else
	int mib [4];
	size_t data_len = sizeof (struct kinfo_proc) * 400;
	struct kinfo_proc *processes = malloc (data_len);
#endif /* KERN_PROC2 */
	void **buf = NULL;

	if (size)
		*size = 0;
	if (!processes)
		return NULL;

#ifdef KERN_PROC2
	mib [0] = CTL_KERN;
	mib [1] = KERN_PROC2;
	mib [2] = KERN_PROC_ALL;
	mib [3] = 0;
	mib [4] = sizeof(struct kinfo_proc2);
	mib [5] = 400; /* XXX */

	res = sysctl (mib, 6, processes, &data_len, NULL, 0);
#else
	mib [0] = CTL_KERN;
	mib [1] = KERN_PROC;
	mib [2] = KERN_PROC_ALL;
	mib [3] = 0;
	
	res = sysctl (mib, 4, processes, &data_len, NULL, 0);
#endif /* KERN_PROC2 */

	if (res < 0) {
		free (processes);
		return NULL;
	}
#ifdef KERN_PROC2
	res = data_len/sizeof (struct kinfo_proc2);
#else
	res = data_len/sizeof (struct kinfo_proc);
#endif /* KERN_PROC2 */
	buf = g_realloc (buf, res * sizeof (void*));
	for (i = 0; i < res; ++i)
		buf [i] = GINT_TO_POINTER (processes [i].kinfo_pid_member);
	free (processes);
	if (size)
		*size = res;
	return buf;
#elif defined(__HAIKU__)
	/* FIXME: Add back the code from 9185fcc305e43428d0f40f3ee37c8a405d41c9ae */
	g_assert_not_reached ();
	return NULL;
#else
	const char *name;
	void **buf = NULL;
	int count = 0;
	int i = 0;
	GDir *dir = g_dir_open ("/proc/", 0, NULL);
	if (!dir) {
		if (size)
			*size = 0;
		return NULL;
	}
	while ((name = g_dir_read_name (dir))) {
		int pid;
		char *nend;
		pid = strtol (name, &nend, 10);
		if (pid <= 0 || nend == name || *nend)
			continue;
		if (i >= count) {
			if (!count)
				count = 16;
			else
				count *= 2;
			buf = g_realloc (buf, count * sizeof (void*));
		}
		buf [i++] = GINT_TO_POINTER (pid);
	}
	g_dir_close (dir);
	if (size)
		*size = i;
	return buf;
#endif
}
Пример #9
0
/*!
  \brief Enables all applicable 3D display buttons
 */
G_MODULE_EXPORT void enable_3d_buttons_pf(void)
{
	g_list_foreach(get_list("3d_buttons"),set_widget_sensitive,GINT_TO_POINTER(TRUE));
}
static void
_set_name (GESTimelineElement * self, const gchar * wanted_name)
{
  const gchar *type_name;
  gchar *lowcase_type;
  gint count;
  GQuark q;
  guint i, l;
  gchar *name = NULL;

  if (!object_name_counts) {
    g_datalist_init (&object_name_counts);
  }

  q = g_type_qname (G_OBJECT_TYPE (self));
  count = GPOINTER_TO_INT (g_datalist_id_get_data (&object_name_counts, q));

  /* GstFooSink -> foosink<N> */
  type_name = g_quark_to_string (q);
  if (strncmp (type_name, "GES", 3) == 0)
    type_name += 3;

  lowcase_type = g_strdup (type_name);
  l = strlen (lowcase_type);
  for (i = 0; i < l; i++)
    lowcase_type[i] = g_ascii_tolower (lowcase_type[i]);

  if (wanted_name == NULL) {
    /* give the 20th "uriclip" element and the first "uriclip2" (if needed in the future)
     * different names */
    l = strlen (type_name);
    if (l > 0 && g_ascii_isdigit (type_name[l - 1])) {
      name = g_strdup_printf ("%s-%d", lowcase_type, count++);
    } else {
      name = g_strdup_printf ("%s%d", lowcase_type, count++);
    }
  } else {
    /* If the wanted name uses the same 'namespace' as default, make
     * sure it does not badly interfere with our counting system */

    if (g_str_has_prefix (wanted_name, lowcase_type)) {
      guint64 tmpcount =
          g_ascii_strtoull (&wanted_name[strlen (lowcase_type)], NULL, 10);

      if (tmpcount > count) {
        count = tmpcount + 1;
        GST_DEBUG_OBJECT (self, "Using same naming %s but updated count to %i",
            wanted_name, count);
      } else if (tmpcount < count) {
        name = g_strdup_printf ("%s%d", lowcase_type, count);
        count++;
        GST_DEBUG_OBJECT (self, "Name %s already allocated, giving: %s instead"
            " New count is %i", wanted_name, name, count);
      } else {
        count++;
        GST_DEBUG_OBJECT (self, "Perfect name, just bumping object count");
      }
    }

    if (name == NULL)
      name = g_strdup (wanted_name);
  }

  g_free (lowcase_type);
  g_datalist_id_set_data (&object_name_counts, q, GINT_TO_POINTER (count));

  g_free (self->name);
  self->name = name;
}
Пример #11
0
struct near_adapter *__near_adapter_get(uint32_t idx)
{
	return g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
}
static void prefs_display_header_create(void)
{
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *btn_hbox;
    GtkWidget *confirm_area;
    GtkWidget *ok_btn;
    GtkWidget *cancel_btn;

    GtkWidget *vbox1;

    GtkWidget *hbox1;
    GtkWidget *hdr_label;
    GtkWidget *hdr_combo;

    GtkWidget *btn_vbox;
    GtkWidget *reg_btn;
    GtkWidget *del_btn;
    GtkWidget *up_btn;
    GtkWidget *down_btn;

    GtkWidget *clist_hbox;
    GtkWidget *clist_hbox1;
    GtkWidget *clist_hbox2;
    GtkWidget *clist_scrolledwin;
    GtkWidget *headers_clist;
    GtkWidget *hidden_headers_clist;

    GtkWidget *checkbtn_other_headers;

    gchar *title[1];

    debug_print(_("Creating display header setting window...\n"));

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 8);
    gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
    gtk_window_set_modal (GTK_WINDOW (window), TRUE);
    gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE);

    vbox = gtk_vbox_new (FALSE, 6);
    gtk_widget_show (vbox);
    gtk_container_add (GTK_CONTAINER (window), vbox);

    btn_hbox = gtk_hbox_new (FALSE, 8);
    gtk_widget_show (btn_hbox);
    gtk_box_pack_end (GTK_BOX (vbox), btn_hbox, FALSE, FALSE, 0);

    gtkut_stock_button_set_create(&confirm_area, &ok_btn, GTK_STOCK_OK,
                                  &cancel_btn, GTK_STOCK_CANCEL,
                                  NULL, NULL);
    gtk_widget_show (confirm_area);
    gtk_box_pack_end (GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0);
    gtk_widget_grab_default (ok_btn);

    gtk_window_set_title (GTK_WINDOW(window),
                          _("Display header setting"));
    MANAGE_WINDOW_SIGNALS_CONNECT(window);
    g_signal_connect (G_OBJECT(window), "delete_event",
                      G_CALLBACK(prefs_display_header_deleted), NULL);
    g_signal_connect (G_OBJECT(window), "key_press_event",
                      G_CALLBACK(prefs_display_header_key_pressed), NULL);
    g_signal_connect (G_OBJECT(ok_btn), "clicked",
                      G_CALLBACK(prefs_display_header_ok), NULL);
    g_signal_connect (G_OBJECT(cancel_btn), "clicked",
                      G_CALLBACK(prefs_display_header_cancel), NULL);

    vbox1 = gtk_vbox_new (FALSE, VSPACING);
    gtk_widget_show (vbox1);
    gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);

    hbox1 = gtk_hbox_new (FALSE, 8);
    gtk_widget_show (hbox1);
    gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);

    hdr_label = gtk_label_new (_("Header name"));
    gtk_widget_show (hdr_label);
    gtk_box_pack_start (GTK_BOX (hbox1), hdr_label, FALSE, FALSE, 0);

    hdr_combo = gtk_combo_new ();
    gtk_widget_show (hdr_combo);
    gtk_box_pack_start (GTK_BOX (hbox1), hdr_combo, TRUE, TRUE, 0);
    gtk_widget_set_size_request (hdr_combo, 150, -1);
    gtkut_combo_set_items (GTK_COMBO (hdr_combo),
                           "From", "To", "Cc", "Subject", "Date",
                           "Reply-To", "Sender", "User-Agent", "X-Mailer",
                           NULL);

    clist_hbox = gtk_hbox_new (FALSE, 10);
    gtk_widget_show (clist_hbox);
    gtk_box_pack_start (GTK_BOX (vbox1), clist_hbox, TRUE, TRUE, 0);

    /* display headers list */

    clist_hbox1 = gtk_hbox_new (FALSE, 8);
    gtk_widget_show (clist_hbox1);
    gtk_box_pack_start (GTK_BOX (clist_hbox), clist_hbox1, TRUE, TRUE, 0);

    clist_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
    gtk_widget_set_size_request (clist_scrolledwin, 200, 210);
    gtk_widget_show (clist_scrolledwin);
    gtk_box_pack_start (GTK_BOX (clist_hbox1), clist_scrolledwin,
                        TRUE, TRUE, 0);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (clist_scrolledwin),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);

    title[0] = _("Displayed Headers");
    headers_clist = gtk_clist_new_with_titles(1, title);
    gtk_widget_show (headers_clist);
    gtk_container_add (GTK_CONTAINER (clist_scrolledwin), headers_clist);
    gtk_clist_set_selection_mode (GTK_CLIST (headers_clist),
                                  GTK_SELECTION_BROWSE);
    gtk_clist_set_reorderable (GTK_CLIST (headers_clist), TRUE);
    gtk_clist_set_use_drag_icons (GTK_CLIST (headers_clist), FALSE);
    gtkut_clist_set_redraw (GTK_CLIST (headers_clist));
    GTK_WIDGET_UNSET_FLAGS (GTK_CLIST (headers_clist)->column[0].button,
                            GTK_CAN_FOCUS);
    g_signal_connect_after
    (G_OBJECT (headers_clist), "row_move",
     G_CALLBACK (prefs_display_header_row_moved), NULL);

    btn_vbox = gtk_vbox_new (FALSE, 8);
    gtk_widget_show (btn_vbox);
    gtk_box_pack_start (GTK_BOX (clist_hbox1), btn_vbox, FALSE, FALSE, 0);

    reg_btn = gtk_button_new_with_label (_("Add"));
    gtk_widget_show (reg_btn);
    gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
    g_signal_connect (G_OBJECT (reg_btn), "clicked",
                      G_CALLBACK (prefs_display_header_register_cb),
                      GINT_TO_POINTER(FALSE));
    del_btn = gtk_button_new_with_label (_("Delete"));
    gtk_widget_show (del_btn);
    gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
    g_signal_connect (G_OBJECT (del_btn), "clicked",
                      G_CALLBACK (prefs_display_header_delete_cb),
                      headers_clist);

    up_btn = gtk_button_new_with_label (_("Up"));
    gtk_widget_show (up_btn);
    gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
    g_signal_connect (G_OBJECT (up_btn), "clicked",
                      G_CALLBACK (prefs_display_header_up), NULL);

    down_btn = gtk_button_new_with_label (_("Down"));
    gtk_widget_show (down_btn);
    gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
    g_signal_connect (G_OBJECT (down_btn), "clicked",
                      G_CALLBACK (prefs_display_header_down), NULL);

    /* hidden headers list */

    clist_hbox2 = gtk_hbox_new (FALSE, 8);
    gtk_widget_show (clist_hbox2);
    gtk_box_pack_start (GTK_BOX (clist_hbox), clist_hbox2, TRUE, TRUE, 0);

    clist_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
    gtk_widget_set_size_request (clist_scrolledwin, 200, 210);
    gtk_widget_show (clist_scrolledwin);
    gtk_box_pack_start (GTK_BOX (clist_hbox2), clist_scrolledwin,
                        TRUE, TRUE, 0);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (clist_scrolledwin),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);

    title[0] = _("Hidden headers");
    hidden_headers_clist = gtk_clist_new_with_titles(1, title);
    gtk_widget_show (hidden_headers_clist);
    gtk_container_add (GTK_CONTAINER (clist_scrolledwin),
                       hidden_headers_clist);
    gtk_clist_set_selection_mode (GTK_CLIST (hidden_headers_clist),
                                  GTK_SELECTION_BROWSE);
    gtk_clist_set_auto_sort(GTK_CLIST (hidden_headers_clist), TRUE);
    gtkut_clist_set_redraw (GTK_CLIST (hidden_headers_clist));
    GTK_WIDGET_UNSET_FLAGS (GTK_CLIST (hidden_headers_clist)->
                            column[0].button, GTK_CAN_FOCUS);

    btn_vbox = gtk_vbox_new (FALSE, 8);
    gtk_widget_show (btn_vbox);
    gtk_box_pack_start (GTK_BOX (clist_hbox2), btn_vbox, FALSE, FALSE, 0);

    reg_btn = gtk_button_new_with_label (_("Add"));
    gtk_widget_show (reg_btn);
    gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
    g_signal_connect (G_OBJECT (reg_btn), "clicked",
                      G_CALLBACK (prefs_display_header_register_cb),
                      GINT_TO_POINTER (TRUE));
    del_btn = gtk_button_new_with_label (_("Delete"));
    gtk_widget_show (del_btn);
    gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
    g_signal_connect (G_OBJECT (del_btn), "clicked",
                      G_CALLBACK (prefs_display_header_delete_cb),
                      hidden_headers_clist);

    PACK_CHECK_BUTTON (btn_hbox, checkbtn_other_headers,
                       _("Show all unspecified headers"));
    SET_TOGGLE_SENSITIVITY (checkbtn_other_headers, clist_hbox2);

    gtk_widget_show_all(window);

    dispheader.window        = window;

    dispheader.confirm_area  = confirm_area;
    dispheader.ok_btn        = ok_btn;
    dispheader.cancel_btn    = cancel_btn;

    dispheader.hdr_combo     = hdr_combo;
    dispheader.hdr_entry     = GTK_COMBO (hdr_combo)->entry;

    dispheader.headers_clist        = headers_clist;
    dispheader.hidden_headers_clist = hidden_headers_clist;

    dispheader.other_headers = checkbtn_other_headers;
}
Пример #13
0
MetaOutput *
meta_create_xrandr_output (MetaGpuXrandr *gpu_xrandr,
                           XRROutputInfo *xrandr_output,
                           RROutput       output_id,
                           RROutput       primary_output)
{
  MetaOutputXrandr *output_xrandr;
  MetaOutput *output;
  GBytes *edid;
  unsigned int i;

  output = g_object_new (META_TYPE_OUTPUT, NULL);
  output->gpu = META_GPU (gpu_xrandr);
  output->winsys_id = output_id;
  output->name = g_strdup (xrandr_output->name);

  output_xrandr = g_slice_new0 (MetaOutputXrandr);
  output->driver_private = output_xrandr;
  output->driver_notify = (GDestroyNotify)meta_output_xrandr_destroy_notify;

  edid = meta_output_xrandr_read_edid (output);
  meta_output_parse_edid (output, edid);
  g_bytes_unref (edid);

  output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
  output->hotplug_mode_update = output_get_hotplug_mode_update (output);
  output->suggested_x = output_get_suggested_x (output);
  output->suggested_y = output_get_suggested_y (output);
  output->connector_type = output_get_connector_type (output);
  output->panel_orientation_transform =
    output_get_panel_orientation_transform (output);

  if (meta_monitor_transform_is_rotated (
                                output->panel_orientation_transform))
    {
      output->width_mm = xrandr_output->mm_height;
      output->height_mm = xrandr_output->mm_width;
    }
  else
    {
      output->width_mm = xrandr_output->mm_width;
      output->height_mm = xrandr_output->mm_height;
    }

  output_get_tile_info (output);
  output_get_modes (output, xrandr_output);
  output_get_crtcs (output, xrandr_output);

  output->n_possible_clones = xrandr_output->nclone;
  output->possible_clones = g_new0 (MetaOutput *,
                                    output->n_possible_clones);
  /*
   * We can build the list of clones now, because we don't have the list of
   * outputs yet, so temporarily set the pointers to the bare XIDs, and then
   * we'll fix them in a second pass.
   */
  for (i = 0; i < (unsigned int) xrandr_output->nclone; i++)
    {
      output->possible_clones[i] = GINT_TO_POINTER (xrandr_output->clones[i]);
    }

  output->is_primary = ((XID) output->winsys_id == primary_output);
  output->is_presentation = output_get_presentation_xrandr (output);
  output->supports_underscanning =
    output_get_supports_underscanning_xrandr (output, &output_xrandr->underscan_value);
  output->is_underscanning = output_get_underscanning_xrandr (output);
  output_get_backlight_limits_xrandr (output);
  output_get_underscanning_borders_xrandr (output);

  /* Override the 'supports underscanning' property for non HDTV sets.
   * Note that we need to do this after checking if underscanning is on, so
   * that we now the exact values for width and height to be checked. */
  if (output->supports_underscanning && !output_is_hdtv (output))
    output->supports_underscanning = FALSE;

  if (!(output->backlight_min == 0 && output->backlight_max == 0))
    output->backlight = output_get_backlight_xrandr (output);
  else
    output->backlight = -1;

  if (output->n_modes == 0 || output->n_possible_crtcs == 0)
    {
      g_object_unref (output);
      return NULL;
    }
  else
    {
      return output;
    }
}
Пример #14
0
static inline void SetIntIntoHash(int key, int value)
{
    g_hash_table_insert(hash, GINT_TO_POINTER(key), &value);
}
Пример #15
0
static void
create_screenshot_frame (GtkWidget   *outer_vbox,
                         const gchar *frame_title)
{
  GtkWidget *main_vbox, *vbox, *hbox;
  GtkWidget *align;
  GtkWidget *radio;
  GtkWidget *image;
  GtkWidget *spin;
  GtkWidget *label;
  GtkAdjustment *adjust;
  GSList *group;
  gchar *title;

  main_vbox = gtk_vbox_new (FALSE, 6);
  gtk_box_pack_start (GTK_BOX (outer_vbox), main_vbox, FALSE, FALSE, 0);
  gtk_widget_show (main_vbox);

  title = g_strconcat ("<b>", frame_title, "</b>", NULL);
  label = gtk_label_new (title);
  gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_box_pack_start (GTK_BOX (main_vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);
  g_free (title);

  hbox = gtk_hbox_new (FALSE, 12);
  gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  align = gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
  gtk_widget_set_size_request (align, 48, -1);
  gtk_box_pack_start (GTK_BOX (hbox), align, FALSE, FALSE, 0);
  gtk_widget_show (align);

  image = gtk_image_new_from_stock (SCREENSHOOTER_ICON,
                                    GTK_ICON_SIZE_DIALOG);
  gtk_container_add (GTK_CONTAINER (align), image);
  gtk_widget_show (image);

  vbox = gtk_vbox_new (FALSE, 6);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);

  /** Grab whole desktop **/
  group = NULL;
  radio = gtk_radio_button_new_with_mnemonic (group,
                                              _("Grab the whole _desktop"));
  if (take_window_shot || take_area_shot)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), FALSE);
  g_signal_connect (radio, "toggled",
                    G_CALLBACK (target_toggled_cb),
                    GINT_TO_POINTER (TARGET_TOGGLE_DESKTOP));
  gtk_box_pack_start (GTK_BOX (vbox), radio, FALSE, FALSE, 0);
  group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio));
  gtk_widget_show (radio);

  /** Grab current window **/
  radio = gtk_radio_button_new_with_mnemonic (group,
                                              _("Grab the current _window"));
  if (take_window_shot)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
  g_signal_connect (radio, "toggled",
                    G_CALLBACK (target_toggled_cb),
                    GINT_TO_POINTER (TARGET_TOGGLE_WINDOW));
  gtk_box_pack_start (GTK_BOX (vbox), radio, FALSE, FALSE, 0);
  group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio));
  gtk_widget_show (radio);

  /** Grab area of the desktop **/
  radio = gtk_radio_button_new_with_mnemonic (group,
                                              _("Select _area to grab"));
  if (take_area_shot)
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
  g_signal_connect (radio, "toggled",
                    G_CALLBACK (target_toggled_cb),
                    GINT_TO_POINTER (TARGET_TOGGLE_AREA));
  gtk_box_pack_start (GTK_BOX (vbox), radio, FALSE, FALSE, 0);
  gtk_widget_show (radio);

  /** Grab after delay **/
  delay_hbox = gtk_hbox_new (FALSE, 6);
  gtk_box_pack_start (GTK_BOX (vbox), delay_hbox, FALSE, FALSE, 0);
  gtk_widget_show (delay_hbox);

  /* translators: this is the first part of the "grab after a
   * delay of <spin button> seconds".
   */
  label = gtk_label_new_with_mnemonic (_("Grab _after a delay of"));
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_box_pack_start (GTK_BOX (delay_hbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  adjust = GTK_ADJUSTMENT (gtk_adjustment_new ((gdouble) delay,
                                               0.0, 99.0,
                                               1.0,  1.0,
                                               0.0));
  spin = gtk_spin_button_new (adjust, 1.0, 0);
  g_signal_connect (spin, "value-changed",
                    G_CALLBACK (delay_spin_value_changed_cb),
                    NULL);
  gtk_box_pack_start (GTK_BOX (delay_hbox), spin, FALSE, FALSE, 0);
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin);
  gtk_widget_show (spin);

  /* translators: this is the last part of the "grab after a
   * delay of <spin button> seconds".
   */
  label = gtk_label_new (_("seconds"));
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_box_pack_end (GTK_BOX (delay_hbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);
}
Пример #16
0
/*!
  \brief Disables all burn to ecu buttons
 */
G_MODULE_EXPORT void disable_burner_buttons_pf(void)
{
	gdk_threads_enter();
	g_list_foreach(get_list("burners"),set_widget_sensitive,GINT_TO_POINTER(FALSE));
	gdk_threads_leave();
}
Пример #17
0
/** Tests a TransPropertyList for having enough essential properties.
 * Essential properties are "Date" and one of the following: "Balance", "Deposit", or
 * "Withdrawal".
 * @param list The list we are checking
 * @param error Contains an error message on failure
 * @return TRUE if there are enough essentials; FALSE otherwise
 */
static gboolean trans_property_list_verify_essentials(TransPropertyList* list, gchar** error)
{
    int i;
    /* possible_errors lists the ways in which a list can fail this test. */
    enum PossibleErrorTypes {NO_DATE, NO_AMOUNT, NUM_OF_POSSIBLE_ERRORS};
    gchar* possible_errors[NUM_OF_POSSIBLE_ERRORS] =
    {
        N_("No date column."),
        N_("No balance, deposit, or withdrawal column.")
    };
    int possible_error_lengths[NUM_OF_POSSIBLE_ERRORS] = {0};
    GList *properties_begin = list->properties, *errors_list = NULL;

    /* Go through each of the properties and erase possible errors. */
    while (list->properties)
    {
        switch (((TransProperty*)(list->properties->data))->type)
        {
        case GNC_CSV_DATE:
            possible_errors[NO_DATE] = NULL;
            break;

        case GNC_CSV_BALANCE:
        case GNC_CSV_DEPOSIT:
        case GNC_CSV_WITHDRAWAL:
            possible_errors[NO_AMOUNT] = NULL;
            break;
        }
        list->properties = g_list_next(list->properties);
    }
    list->properties = properties_begin;

    /* Accumulate a list of the actual errors. */
    for (i = 0; i < NUM_OF_POSSIBLE_ERRORS; i++)
    {
        if (possible_errors[i] != NULL)
        {
            errors_list = g_list_append(errors_list, GINT_TO_POINTER(i));
            /* Since we added an error, we want to also store its length for
             * when we construct the full error string. */
            possible_error_lengths[i] = strlen(_(possible_errors[i]));
        }
    }

    /* If there are no errors, we can quit now. */
    if (errors_list == NULL)
        return TRUE;
    else
    {
        /* full_error_size is the full length of the error message. */
        int full_error_size = 0, string_length = 0;
        GList* errors_list_begin = errors_list;
        gchar *error_message, *error_message_begin;

        /* Find the value for full_error_size. */
        while (errors_list)
        {
            /* We add an extra 1 to account for spaces in between messages. */
            full_error_size += possible_error_lengths[GPOINTER_TO_INT(errors_list->data)] + 1;
            errors_list = g_list_next(errors_list);
        }
        errors_list = errors_list_begin;

        /* Append the error messages one after another. */
        error_message = error_message_begin = g_new(gchar, full_error_size);
        while (errors_list)
        {
            i = GPOINTER_TO_INT(errors_list->data);
            string_length = possible_error_lengths[i];

            /* Copy the error message and put a space after it. */
            strncpy(error_message, _(possible_errors[i]), string_length);
            error_message += string_length;
            *error_message = ' ';
            error_message++;

            errors_list = g_list_next(errors_list);
        }
        *error_message = '\0'; /* Replace the last space with the null byte. */
        g_list_free(errors_list_begin);

        *error = error_message_begin;
        return FALSE;
    }
}
Пример #18
0
/*!
  \brief Enables the "get data" buttons on all tabs
  */
G_MODULE_EXPORT void enable_get_data_buttons_pf(void)
{
	gdk_threads_enter();
	g_list_foreach(get_list("get_data_buttons"),set_widget_sensitive,GINT_TO_POINTER(TRUE));
	gdk_threads_leave();
}
Пример #19
0
static void
delete_button_clicked (GtkButton *button, gpointer user_data)
{
  dt_lib_module_t *self = (dt_lib_module_t *)user_data;
  dt_lib_tagging_t *d   = (dt_lib_tagging_t *)self->data;

  int res = GTK_RESPONSE_YES;

  guint tagid;
  GtkTreeIter iter;
  GtkTreeModel *model = NULL;
  GtkTreeView *view = d->related;
  GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
  if(!gtk_tree_selection_get_selected(selection, &model, &iter)) return;
  gtk_tree_model_get (model, &iter,
                      DT_LIB_TAGGING_COL_ID, &tagid,
                      -1);

  // First check how many images are affected by the remove
  int count = dt_tag_remove(tagid,FALSE);
  if( count > 0 && dt_conf_get_bool("plugins/lighttable/tagging/ask_before_delete_tag") )
  {
    GtkWidget *dialog;
    GtkWidget *win = dt_ui_main_window(darktable.gui->ui);
    gchar *tagname=dt_tag_get_name(tagid);
    dialog = gtk_message_dialog_new(GTK_WINDOW(win),
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_QUESTION,
                                    GTK_BUTTONS_YES_NO,
                                    ngettext("do you really want to delete the tag `%s'?\n%d image is assigned this tag!",
                                        "do you really want to delete the tag `%s'?\n%d images are assigned this tag!", count),
                                    tagname,count);
    gtk_window_set_title(GTK_WINDOW(dialog), _("delete tag?"));
    res = gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
    free(tagname);
  }
  if(res != GTK_RESPONSE_YES) return;

  GList *tagged_images = NULL;
  sqlite3_stmt *stmt;
  DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select imgid from tagged_images where tagid=?1", -1, &stmt, NULL);
  DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, tagid);
  while(sqlite3_step(stmt) == SQLITE_ROW)
  {
    tagged_images = g_list_append(tagged_images, GINT_TO_POINTER(sqlite3_column_int(stmt, 0)));
  }
  sqlite3_finalize(stmt);

  dt_tag_remove(tagid,TRUE);

  GList *list_iter;
  if((list_iter = g_list_first(tagged_images)) != NULL)
  {
    do
    {
      dt_image_synch_xmp(GPOINTER_TO_INT(list_iter->data));
    }
    while((list_iter=g_list_next(list_iter)) != NULL);
  }
  g_list_free(g_list_first(tagged_images));

  update(self, 0);
  update(self, 1);

  dt_collection_hint_message(darktable.collection);
}
Пример #20
0
static void
create_plugin(GtkWidget *vbox, gint first_create)
	{
	GkrellmDecalbutton	*button;
	GkrellmStyle	*style;
	GkrellmTextstyle *ts, *ts_alt;
	GdkPixmap		*pixmap;
	GdkBitmap		*mask;
	gint			y;
	gint			x;

	/* See comments about first create in demo2.c
	*/
	if (first_create)
		panel = gkrellm_panel_new0();

	style = gkrellm_meter_style(style_id);

	/* Each Style has two text styles.  The theme designer has picked the
	|  colors and font sizes, presumably based on knowledge of what you draw
	|  on your panel.  You just do the drawing.  You can assume that the
	|  ts font is larger than the ts_alt font.
	*/
	ts = gkrellm_meter_textstyle(style_id);
	ts_alt = gkrellm_meter_alt_textstyle(style_id);


	/* ==== Create a text decal that will be used to scroll text. ====
	|  Make it the full panel width (minus the margins).  Position it at top
	|  border and left margin of the style.  The "Ay" string is a vertical
	|  sizing string for the decal and not an initialization string.
	*/
	text1_decal = gkrellm_create_decal_text(panel, "Ay", ts, style,
				-1,     /* x = -1 places at left margin */
				-1,     /* y = -1 places at top margin	*/
				-1);    /* w = -1 makes decal the panel width minus margins */
	y = text1_decal->y + text1_decal->h + 2;


	/* ==== Create a scaled button ====
	|  This is the easiest and most versatile way to create a button and is
	|  a new function for GKrellM 2.0.0.  Here we use the builtin default
	|  button image which is a simple 2 frame in/out image.  If you supply
	|  your own image, there can be as many frames as you wish which can be
	|  used for state indicating purposes.  Make two buttons, one large and one
	|  small to demonstrate scaling capability.  Make the small one auto-hide.
	|  See demo4 for a more complicated scaled button which has an irregular
	|  shape and a custom in_button callback to detect when the mouse is on
	|  a non-transparent part of the button.
	*/
	button = gkrellm_make_scaled_button(panel,
				NULL,               /* GkrellmPiximage image to use to   */
				                    /*   create the button images. Use a */
				                    /*   builtin default if NULL         */
				cb_button,          /* Button clicked callback function  */
				GINT_TO_POINTER(0), /* Arg to callback function          */
				FALSE,              /* auto_hide: if TRUE, button is visible */
				                    /*   only when mouse is in the panel */
				FALSE,              /* set_default_border: if TRUE, apply a */
				                    /*   default border of 1,1,1,1.  If false*/
				                    /*   use the GkrellmPiximage border which*/
				                    /*   in this case is 0,0,0,0         */
				0,                  /* Image depth if image != NULL      */
				0,                  /* Initial out frame if image != NULL */
				0,                  /* Pressed frame if image != NULL    */
				2,                  /* x position of button  */
				y,                  /* y position of button  */
				13,                 /* Width for scaling the button  */
				15);                /* Height for scaling the button */

	x = button->decal->x + button->decal->w + 2;
	button = gkrellm_make_scaled_button(panel, NULL, cb_button,
				GINT_TO_POINTER(1), TRUE, FALSE, 0, 0, 0,
				x, y, 6, 8);


	/* ==== Create a text decal and convert it into a decal button. ====
	|  Text decals are converted into buttons by being put into a meter or
	|  panel button.  This "put" overlays the text decal with special button
	|  in and out images that have a transparent interior and a non-transparent
	|  border. The "Hello" string is not an initialization string, it is just
	|  a vertical sizing string.  After the decal is created, draw the
	|  initial text onto the decal.
	*/
	x = button->decal->x + button->decal->w + 2;
	text2_decal = gkrellm_create_decal_text(panel, "Hello", ts_alt, style,
				x,
				y,      /* Place below the scrolling text1_decal     */
				0);     /* w = 0 makes decal the sizing string width */

	gkrellm_put_decal_in_meter_button(panel, text2_decal,
				cb_button,          /* Button clicked callback function */
				GINT_TO_POINTER(2), /* Arg to callback function      */
				NULL);              /* Optional margin struct to pad the size */

	gkrellm_draw_decal_text(panel, text2_decal, button_text[button_state],
				button_state);


	/* ==== Create a pixmap decal and convert it into a decal button ====
	|  Pixmap decals are directly converted into buttons (no put operation)
	|  because pixmap decals have frames which will provide the in and out
	|  button images.  A plugin custom image may be loaded and rendered to
	|  a pixmap to be used for the button, but here I'm using the pre-loaded
	|  pixmap from the builtin decal_misc.xpm image.  First make a decal out
	|  of the pixmap.  Then pass the decal frames we want to be the in/out
	|  images when we make the decal button.
	*/
	pixmap = gkrellm_decal_misc_pixmap();
	mask = gkrellm_decal_misc_mask();
	x = text2_decal->x + text2_decal->w + 2;

	pixmap_decal = gkrellm_create_decal_pixmap(panel, pixmap, mask,
				N_MISC_DECALS, NULL, x, y);

	gkrellm_make_decal_button(panel, pixmap_decal,
				cb_button,          /* Button clicked callback function */
				GINT_TO_POINTER(3), /* Arg to callback function */
				D_MISC_BUTTON_OUT,  /* Button out (not pressed) frame */
				D_MISC_BUTTON_IN);  /* Button pressed frame */


	/* Configure the panel to hold the above created decals, and create it.
	*/
	gkrellm_panel_configure(panel, NULL, style);
	gkrellm_panel_create(vbox, monitor, panel);

	/* Note: the above gkrellm_draw_decal_text() call will not
	|  appear on the panel until a gkrellm_draw_panel_layers() call is
	|  made.  This will be done in update_plugin(), otherwise we would
	|  make the call here after the panel is created and anytime the
	|  decals are changed.
	*/

	if (first_create)
	    g_signal_connect(G_OBJECT (panel->drawing_area), "expose_event",
    	        G_CALLBACK(panel_expose_event), NULL);
	}
Пример #21
0
/**
 * gda_data_model_array_copy_model_ext:
 * @src: a #GdaDataModel to copy data from
 * @ncols: size of @cols
 * @cols: (array length=ncols): array of @src's columns to copy into the new array, not %NULL
 * @error: a place to store errors, or %NULL
 *
 * Like gda_data_model_array_copy_model(), makes a copy of @src, but copies only some
 * columns.
 *
 * Returns: (transfer full) (allow-none): a new data model, or %NULL if an error occurred
 *
 * Since: 5.2.0
 */
GdaDataModelArray *
gda_data_model_array_copy_model_ext (GdaDataModel *src, gint ncols, gint *cols, GError **error)
{
	GdaDataModel *model;
	gint nbfields, i;

	g_return_val_if_fail (GDA_IS_DATA_MODEL (src), NULL);
	g_return_val_if_fail (cols, NULL);
	g_return_val_if_fail (ncols > 0, NULL);

	/* check columns' validity */
	nbfields = gda_data_model_get_n_columns (src);
	for (i = 0; i < ncols; i++) {
		if ((cols[i] < 0) || (cols[i] >= nbfields)) {
			g_set_error (error, GDA_DATA_MODEL_ERROR,
				     GDA_DATA_MODEL_COLUMN_OUT_OF_RANGE_ERROR,
                                     _("Column %d out of range (0-%d)"), cols[i], nbfields - 1);
			return NULL;
		}
	}

	/* initialize new model */
	model = gda_data_model_array_new (ncols);
	if (g_object_get_data (G_OBJECT (src), "name"))
		g_object_set_data_full (G_OBJECT (model), "name", g_strdup (g_object_get_data (G_OBJECT (src), "name")), g_free);
	if (g_object_get_data (G_OBJECT (src), "descr"))
		g_object_set_data_full (G_OBJECT (model), "descr", g_strdup (g_object_get_data (G_OBJECT (src), "descr")), g_free);


	/* map new columns */
	GHashTable *hash;
	hash = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
	for (i = 0; i < ncols; i++) {
		gint *ptr;
		ptr = g_new (gint, 1);
		*ptr = i;
		g_hash_table_insert (hash, ptr, GINT_TO_POINTER (cols[i]));

		GdaColumn *copycol, *srccol;
		gchar *colid;

		srccol = gda_data_model_describe_column (src, cols[i]);
		copycol = gda_data_model_describe_column (model, i);

		g_object_get (G_OBJECT (srccol), "id", &colid, NULL);
		g_object_set (G_OBJECT (copycol), "id", colid, NULL);
		g_free (colid);
		gda_column_set_description (copycol, gda_column_get_description (srccol));
		gda_column_set_name (copycol, gda_column_get_name (srccol));
		gda_column_set_dbms_type (copycol, gda_column_get_dbms_type (srccol));
		gda_column_set_g_type (copycol, gda_column_get_g_type (srccol));
		gda_column_set_position (copycol, gda_column_get_position (srccol));
		gda_column_set_allow_null (copycol, gda_column_get_allow_null (srccol));
	}

	if (! gda_data_model_import_from_model (model, src, FALSE, hash, error)) {
		g_hash_table_destroy (hash);
		g_object_unref (model);
		model = NULL;
	}
	/*else
	  gda_data_model_dump (model, stdout);*/

	g_hash_table_destroy (hash);
	return (GdaDataModelArray*) model;
}
Пример #22
0
static gboolean
parseLine (CSVImporter *gci,
           EContact *contact,
           gchar *buf)
{
	const gchar *pptr = buf, *field_text;
	gchar *do_free = NULL;
	GString *value;
	gint ii = 0, idx;
	gint flags = 0;
	gint contact_field;
	EContactAddress *home_address = NULL, *work_address = NULL, *other_address = NULL;
	EContactDate *bday = NULL;
	GString *home_street, *work_street, *other_street;
	home_street = g_string_new ("");
	work_street = g_string_new ("");
	other_street = g_string_new ("");
	home_address = g_new0 (EContactAddress, 1);
	work_address = g_new0 (EContactAddress, 1);
	other_address = g_new0 (EContactAddress, 1);
	bday = g_new0 (EContactDate, 1);

	if (!g_utf8_validate (pptr, -1, NULL)) {
		do_free = g_convert (pptr, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
		pptr = do_free;
	}

	while (value = parseNextValue (&pptr), value != NULL) {
		contact_field = NOMAP;
		flags = FLAG_INVALID;
		field_text = NULL;

		idx = ii;
		if (gci->fields_map) {
			gpointer found;

			found = g_hash_table_lookup (
				gci->fields_map, GINT_TO_POINTER (idx));

			if (found == NULL) {
				g_warning ("%s: No map for index %d, skipping it", G_STRFUNC, idx);
				idx = -1;
			} else {
				idx = GPOINTER_TO_INT (found) - 1;
			}
		}

		if (importer == OUTLOOK_IMPORTER) {
			if (idx >= 0 && idx < G_N_ELEMENTS (csv_fields_outlook)) {
				contact_field = csv_fields_outlook[idx].contact_field;
				flags = csv_fields_outlook[idx].flags;
				field_text = csv_fields_outlook[idx].csv_attribute;
			}
		}
		else if (importer == MOZILLA_IMPORTER) {
			if (idx >= 0 && idx < G_N_ELEMENTS (csv_fields_mozilla)) {
				contact_field = csv_fields_mozilla[idx].contact_field;
				flags = csv_fields_mozilla[idx].flags;
				field_text = csv_fields_mozilla[idx].csv_attribute;
			}
		}
		else {
			if (idx >= 0 && idx < G_N_ELEMENTS (csv_fields_evolution)) {
				contact_field = csv_fields_evolution[idx].contact_field;
				flags = csv_fields_evolution[idx].flags;
				field_text = csv_fields_evolution[idx].csv_attribute;
			}
		}

		if (*value->str) {
			if (contact_field != NOMAP) {
				if (importer == OUTLOOK_IMPORTER || importer == MOZILLA_IMPORTER) {
					e_contact_set (contact, contact_field, value->str);
				} else {
					if (contact_field == E_CONTACT_WANTS_HTML)
						e_contact_set (
							contact, contact_field,
							GINT_TO_POINTER (
							g_ascii_strcasecmp (
							value->str, "TRUE") == 0));
					else
						e_contact_set (contact, contact_field, value->str);
				}
			}
			else {
				switch (flags) {

				case FLAG_HOME_ADDRESS | FLAG_STREET:
					if (strlen (home_street->str) != 0) {
						home_street = g_string_append (home_street, ",\n");
					}
					home_street = g_string_append (home_street, value->str);
					break;
				case FLAG_HOME_ADDRESS | FLAG_CITY:
					home_address->locality = g_strdup (value->str);
					break;
				case FLAG_HOME_ADDRESS | FLAG_STATE:
					home_address->region = g_strdup (value->str);
					break;
				case FLAG_HOME_ADDRESS | FLAG_POSTAL_CODE:
					home_address->code = g_strdup (value->str);
					break;
				case FLAG_HOME_ADDRESS | FLAG_POBOX:
					home_address->po = g_strdup (value->str);
					break;
				case FLAG_HOME_ADDRESS | FLAG_COUNTRY:
					home_address->country = g_strdup (value->str);
					break;

				case FLAG_WORK_ADDRESS | FLAG_STREET:
					if (strlen (work_street->str) != 0) {
						work_street = g_string_append (work_street, ",\n");
					}
					work_street = g_string_append (work_street, value->str);
					break;
				case FLAG_WORK_ADDRESS | FLAG_CITY:
					work_address->locality = g_strdup (value->str);
					break;
				case FLAG_WORK_ADDRESS | FLAG_STATE:
					work_address->region = g_strdup (value->str);
					break;
				case FLAG_WORK_ADDRESS | FLAG_POSTAL_CODE:
					work_address->code = g_strdup (value->str);
					break;
				case FLAG_WORK_ADDRESS | FLAG_POBOX:
					work_address->po = g_strdup (value->str);
					break;
				case FLAG_WORK_ADDRESS | FLAG_COUNTRY:
					work_address->country = g_strdup (value->str);
					break;

				case FLAG_OTHER_ADDRESS | FLAG_STREET:
					if (strlen (other_street->str) != 0) {
						other_street = g_string_append (other_street, ",\n");
					}
					other_street = g_string_append (other_street, value->str);
					break;
				case FLAG_OTHER_ADDRESS | FLAG_CITY:
					other_address->locality = g_strdup (value->str);
					break;
				case FLAG_OTHER_ADDRESS | FLAG_STATE:
					other_address->region = g_strdup (value->str);
					break;
				case FLAG_OTHER_ADDRESS | FLAG_POSTAL_CODE:
					other_address->code = g_strdup (value->str);
					break;
				case FLAG_OTHER_ADDRESS | FLAG_POBOX:
					other_address->po = g_strdup (value->str);
					break;
				case FLAG_OTHER_ADDRESS | FLAG_COUNTRY:
					other_address->country = g_strdup (value->str);
					break;

				case FLAG_DATE_BDAY:
					e_contact_set (
						contact,
						E_CONTACT_BIRTH_DATE,
						date_from_string (value->str));
					break;

				case FLAG_DATE_ANNIVERSARY:
					e_contact_set (
						contact,
						E_CONTACT_ANNIVERSARY,
						date_from_string (value->str));
					break;

				case FLAG_BIRTH_DAY:
					bday->day = atoi (value->str);
					break;
				case FLAG_BIRTH_YEAR:
					bday->year = atoi (value->str);
					break;
				case FLAG_BIRTH_MONTH:
					bday->month = atoi (value->str);
					break;

				case FLAG_INVALID:
					break;

				default:
					add_to_notes (contact, field_text, value->str);

				}
			}
		}
		ii++;
		g_string_free (value, TRUE);
	}
	if (strlen (home_street->str) != 0)
		home_address->street = g_strdup (home_street->str);
	if (strlen (work_street->str) != 0)
		work_address->street = g_strdup (work_street->str);
	if (strlen (other_street->str) != 0)
		other_address->street = g_strdup (other_street->str);
	g_string_free (home_street, TRUE);
	g_string_free (work_street, TRUE);
	g_string_free (other_street, TRUE);

	if (home_address->locality || home_address->country ||
	   home_address->code || home_address->region || home_address->street)
		e_contact_set (contact, E_CONTACT_ADDRESS_HOME, home_address);
	if (work_address->locality || work_address->country ||
	   work_address->code || work_address->region || work_address->street)
		e_contact_set (contact, E_CONTACT_ADDRESS_WORK, work_address);
	if (other_address->locality || other_address->country ||
	   other_address->code || other_address->region || other_address->street)
		e_contact_set (contact, E_CONTACT_ADDRESS_OTHER, other_address);

	if (importer != OUTLOOK_IMPORTER) {
		if (bday->day || bday->year || bday->month)
			e_contact_set (contact, E_CONTACT_BIRTH_DATE, bday);
	}

	g_free (do_free);

	return TRUE;
}
Пример #23
0
/**
 * gconf_bridge_bind_window
 * @bridge: A #GConfBridge
 * @key_prefix: The prefix of the GConf keys
 * @window: A #GtkWindow
 * @bind_size: TRUE to bind the size of @window
 * @bind_pos: TRUE to bind the position of @window
 *
 * On calling this function @window will be resized to the values
 * specified by "@key_prefix<!-- -->_width" and "@key_prefix<!-- -->_height"
 * and maximixed if "@key_prefix<!-- -->_maximized is TRUE if
 * @bind_size is TRUE, and moved to the values specified by
 * "@key_prefix<!-- -->_x" and "@key_prefix<!-- -->_y" if @bind_pos is TRUE.
 * The respective GConf values will be updated when the window is resized
 * and/or moved.
 *
 * Return value: The ID of the new binding.
 **/
guint
gconf_bridge_bind_window (GConfBridge *bridge,
                          const gchar *key_prefix,
                          GtkWindow *window,
                          gboolean bind_size,
                          gboolean bind_pos)
{
	WindowBinding *binding;

	g_return_val_if_fail (bridge != NULL, 0);
	g_return_val_if_fail (key_prefix != NULL, 0);
	g_return_val_if_fail (GTK_IS_WINDOW (window), 0);

        /* Create new binding. */
	binding = g_new (WindowBinding, 1);

	binding->type = BINDING_WINDOW;
	binding->id = new_id ();
	binding->bind_size = bind_size;
	binding->bind_pos = bind_pos;
	binding->key_prefix = g_strdup (key_prefix);
	binding->window = window;
	binding->sync_timeout_id = 0;

        /* Set up GConf keys & sync window to GConf values */
	if (bind_size) {
		gchar *key;
		GConfValue *width_val, *height_val, *maximized_val;

                key = g_strconcat (key_prefix, "_width", NULL);
		width_val = gconf_client_get (bridge->client, key, NULL);
		g_free (key);

                key = g_strconcat (key_prefix, "_height", NULL);
		height_val = gconf_client_get (bridge->client, key, NULL);
		g_free (key);

                key = g_strconcat (key_prefix, "_maximized", NULL);
		maximized_val = gconf_client_get (bridge->client, key, NULL);
		g_free (key);

		if (width_val && height_val) {
			gtk_window_resize (window,
					   gconf_value_get_int (width_val),
					   gconf_value_get_int (height_val));

			gconf_value_free (width_val);
			gconf_value_free (height_val);
		} else if (width_val) {
			gconf_value_free (width_val);
		} else if (height_val) {
			gconf_value_free (height_val);
		}

		if (maximized_val) {
			if (gconf_value_get_bool (maximized_val)) {
				/* Maximize is not done immediately, but to
				 * count with proper window size, resize it
				 * before. The previous size is restored
				 * after the maximization is changed,
				 * in window_binding_state_event_cb(). */
				gint width = 0, height = 0;
				GdkScreen *screen;

				gtk_window_get_size (window, &width, &height);
				g_object_set_data (
					G_OBJECT (window),
					"binding-premax-width",
					GINT_TO_POINTER (width));
				g_object_set_data (
					G_OBJECT (window),
					"binding-premax-height",
					GINT_TO_POINTER (height));

				screen = gtk_window_get_screen (window);
				gtk_window_resize (window,
					gdk_screen_get_width (screen),
					gdk_screen_get_height (screen));

				gtk_window_maximize (window);
			}
			gconf_value_free (maximized_val);
		}
	}

	if (bind_pos) {
		gchar *key;
		GConfValue *x_val, *y_val;

                key = g_strconcat (key_prefix, "_x", NULL);
		x_val = gconf_client_get (bridge->client, key, NULL);
		g_free (key);

                key = g_strconcat (key_prefix, "_y", NULL);
		y_val = gconf_client_get (bridge->client, key, NULL);
		g_free (key);

		if (x_val && y_val) {
			gtk_window_move (window,
					 gconf_value_get_int (x_val),
					 gconf_value_get_int (y_val));

			gconf_value_free (x_val);
			gconf_value_free (y_val);
		} else if (x_val) {
			gconf_value_free (x_val);
		} else if (y_val) {
			gconf_value_free (y_val);
		}
	}

        /* Connect to window size change notifications */
	binding->configure_event_id =
		g_signal_connect (window,
                                  "configure-event",
				  G_CALLBACK
					(window_binding_configure_event_cb),
				  binding);

	binding->window_state_event_id =
		g_signal_connect (window,
                                  "window_state_event",
				  G_CALLBACK
					(window_binding_state_event_cb),
				  binding);
	binding->unmap_id =
		g_signal_connect (window,
                                  "unmap",
				  G_CALLBACK (window_binding_unmap_cb),
				  binding);

        /* Handle case where window gets destroyed */
	g_object_weak_ref (G_OBJECT (window),
			   window_binding_window_destroyed, binding);

        /* Insert binding */
	g_hash_table_insert (bridge->bindings,
			     GUINT_TO_POINTER (binding->id), binding);

        /* Done */
	return binding->id;
}
Пример #24
0
INIFile * open_ini_file (VFSFile * file)
{
    GHashTable *ini_file = NULL;
    GHashTable *section = NULL;
    GString *section_name, *key_name, *value;
    gpointer section_hash, key_hash;
    gsize off = 0;

    gint64 filesize = vfs_fsize (file);
    if (filesize < 1)
        return NULL;

    gchar * buffer = g_malloc (filesize);
    filesize = vfs_fread (buffer, 1, filesize, file);

    section_name = g_string_new("");
    key_name = g_string_new(NULL);
    value = g_string_new(NULL);

    ini_file =
        g_hash_table_new_full(NULL, NULL, NULL, close_ini_file_free_section);
    section =
        g_hash_table_new_full(NULL, NULL, NULL, close_ini_file_free_value);
    /* make a nameless section which should store all entries that are not
     * embedded in a section */
    section_hash = GINT_TO_POINTER(g_string_hash(section_name));
    g_hash_table_insert(ini_file, section_hash, section);

    while (off < filesize)
    {
        /* ignore the following characters */
        if (buffer[off] == '\r' || buffer[off] == '\n' || buffer[off] == ' '
            || buffer[off] == '\t')
        {
            if (buffer[off] == '\n')
            {
                g_string_free(key_name, TRUE);
                g_string_free(value, TRUE);
                key_name = g_string_new(NULL);
                value = g_string_new(NULL);
            }

            off++;
            continue;
        }

        /* if we encounter a possible section statement */
        if (buffer[off] == '[')
        {
            g_string_free(section_name, TRUE);
            section_name = g_string_new(NULL);
            off++;

            if (off >= filesize)
                goto return_sequence;

            while (buffer[off] != ']')
            {
                /* if the section statement has not been closed before a
                 * linebreak */
                if (buffer[off] == '\n')
                    break;

                g_string_append_c(section_name, buffer[off]);
                off++;
                if (off >= filesize)
                    goto return_sequence;
            }
            if (buffer[off] == '\n')
                continue;
            if (buffer[off] == ']')
            {
                off++;
                if (off >= filesize)
                    goto return_sequence;

                strip_lower_string(section_name);
                section_hash = GINT_TO_POINTER(g_string_hash(section_name));

                /* if this section already exists, we don't make a new one,
                 * but reuse the old one */
                if (g_hash_table_lookup(ini_file, section_hash) != NULL)
                    section = g_hash_table_lookup(ini_file, section_hash);
                else
                {
                    section =
                        g_hash_table_new_full(NULL, NULL, NULL,
                                              close_ini_file_free_value);
                    g_hash_table_insert(ini_file, section_hash, section);
                }

                continue;
            }
        }

        if (buffer[off] == '=')
        {
            off++;
            if (off >= filesize)
                goto return_sequence;

            while (buffer[off] != '\n' && buffer[off] != '\r')
            {
                g_string_append_c(value, buffer[off]);
                off++;
                if (off >= filesize)
                    break;
            }

            strip_lower_string(key_name);
            key_hash = GINT_TO_POINTER(g_string_hash(key_name));
            strip_string(value);

            if (key_name->len > 0 && value->len > 0)
                g_hash_table_insert(section, key_hash, g_strdup(value->str));
        }
        else
        {
            g_string_append_c(key_name, buffer[off]);
            off++;
            if (off >= filesize)
                goto return_sequence;
        }
    }

  return_sequence:
    g_string_free(section_name, TRUE);
    g_string_free(key_name, TRUE);
    g_string_free(value, TRUE);
    g_free(buffer);
    return ini_file;
}
Пример #25
0
static gboolean
screen_saver_floater_do_draw (ScreenSaver        *screen_saver,
                              ScreenSaverFloater *floater,
                              cairo_t            *context)
{
    gint size;
    CachedSource *source;

    size = CLAMP ((int) (FLOATER_MAX_SIZE * floater->scale),
                  FLOATER_MIN_SIZE, FLOATER_MAX_SIZE);

    source = g_hash_table_lookup (screen_saver->cached_sources, GINT_TO_POINTER (size));

    if (source == NULL)
    {
        GdkPixbuf *pixbuf;
        GError *error;

        pixbuf = NULL;
        error = NULL;

        pixbuf = gdk_pixbuf_new_from_file_at_size (screen_saver->filename, size, -1,
                 &error);
        if (pixbuf == NULL)
        {
            g_assert (error != NULL);
            g_printerr ("%s", _(error->message));
            g_error_free (error);
            return FALSE;
        }

        if (gdk_pixbuf_get_has_alpha (pixbuf))
            gamma_correct (pixbuf);

        gdk_cairo_set_source_pixbuf (context, pixbuf, 0.0, 0.0);

        source = cached_source_new (cairo_get_source (context),
                                    gdk_pixbuf_get_width (pixbuf),
                                    gdk_pixbuf_get_height (pixbuf));
        g_object_unref (pixbuf);
        g_hash_table_insert (screen_saver->cached_sources, GINT_TO_POINTER (size),
                             source);
    }

    cairo_save (context);

    if (screen_saver->should_do_rotations && (abs (floater->angle) > G_MINDOUBLE))
    {
        floater->bounds.width = G_SQRT2 * source->width + 2;
        floater->bounds.height = G_SQRT2 * source->height + 2;
        floater->bounds.x = (int) (floater->position.x - .5 * G_SQRT2 * source->width) - 1;
        floater->bounds.y = (int) (floater->position.y - .5 * G_SQRT2 * source->height) - 1;

        cairo_translate (context,
                         trunc (floater->position.x),
                         trunc (floater->position.y));
        cairo_rotate (context, floater->angle);
        cairo_translate (context,
                         -trunc (floater->position.x),
                         -trunc (floater->position.y));
    }
    else
    {
        floater->bounds.width = source->width + 2;
        floater->bounds.height = source->height + 2;
        floater->bounds.x = (int) (floater->position.x - .5 * source->width) - 1;
        floater->bounds.y = (int) (floater->position.y - .5 * source->height) - 1;
    }

    cairo_translate (context,
                     trunc (floater->position.x - .5 * source->width),
                     trunc (floater->position.y - .5 * source->height));

    cairo_set_source (context, source->pattern);

    cairo_rectangle (context,
                     trunc (.5 * (source->width - floater->bounds.width)),
                     trunc (.5 * (source->height - floater->bounds.height)),
                     floater->bounds.width, floater->bounds.height);

    cairo_clip (context);
    cairo_paint_with_alpha (context, floater->opacity);
    cairo_restore (context);

    if (screen_saver->should_show_paths && (floater->path != NULL))
    {
        gdouble dash_pattern[] = { 5.0 };
        gint size;

        size = CLAMP ((int) (FLOATER_MAX_SIZE * floater->path_start_scale),
                      FLOATER_MIN_SIZE, FLOATER_MAX_SIZE);

        cairo_save (context);
        cairo_set_source_rgba (context, 1.0, 1.0, 1.0, .2 * floater->opacity);
        cairo_move_to (context,
                       floater->path->start_point.x,
                       floater->path->start_point.y);
        cairo_curve_to (context,
                        floater->path->start_control_point.x,
                        floater->path->start_control_point.y,
                        floater->path->end_control_point.x,
                        floater->path->end_control_point.y,
                        floater->path->end_point.x,
                        floater->path->end_point.y);
        cairo_set_line_cap (context, CAIRO_LINE_CAP_ROUND);
        cairo_stroke (context);
        cairo_set_source_rgba (context, 1.0, 0.0, 0.0, .5 * floater->opacity);
        cairo_rectangle (context,
                         floater->path->start_point.x - 3,
                         floater->path->start_point.y - 3,
                         6, 6);
        cairo_fill (context);
        cairo_set_source_rgba (context, 0.0, 0.5, 0.0, .5 * floater->opacity);
        cairo_arc (context,
                   floater->path->start_control_point.x,
                   floater->path->start_control_point.y,
                   3, 0.0, 2.0 * G_PI);
        cairo_stroke (context);
        cairo_set_source_rgba (context, 0.5, 0.0, 0.5, .5 * floater->opacity);
        cairo_arc (context,
                   floater->path->end_control_point.x,
                   floater->path->end_control_point.y,
                   3, 0.0, 2.0 * G_PI);
        cairo_stroke (context);
        cairo_set_source_rgba (context, 0.0, 0.0, 1.0, .5 * floater->opacity);
        cairo_rectangle (context,
                         floater->path->end_point.x - 3,
                         floater->path->end_point.y - 3,
                         6, 6);
        cairo_fill (context);

        cairo_set_dash (context, dash_pattern, G_N_ELEMENTS (dash_pattern), 0);
        cairo_set_source_rgba (context, .5, .5, .5, .2 * floater->scale);
        cairo_move_to (context, floater->path->start_point.x,
                       floater->path->start_point.y);
        cairo_line_to (context, floater->path->start_control_point.x,
                       floater->path->start_control_point.y);
        cairo_stroke (context);

        cairo_move_to (context, floater->path->end_point.x,
                       floater->path->end_point.y);
        cairo_line_to (context, floater->path->end_control_point.x,
                       floater->path->end_control_point.y);
        cairo_stroke (context);

        cairo_restore (context);
    }

    return TRUE;
}
Пример #26
0
GtkWidget *
gimp_paint_mode_menu_new (gboolean with_behind_mode,
                          gboolean with_replace_modes)
{
  GtkListStore *store;
  GtkWidget    *combo;

  store = gimp_enum_store_new_with_values (GIMP_TYPE_LAYER_MODE_EFFECTS,
                                           21,
                                           GIMP_NORMAL_MODE,
                                           GIMP_DISSOLVE_MODE,

                                           GIMP_MULTIPLY_MODE,
                                           GIMP_DIVIDE_MODE,
                                           GIMP_SCREEN_MODE,
                                           GIMP_OVERLAY_MODE,

                                           GIMP_DODGE_MODE,
                                           GIMP_BURN_MODE,
                                           GIMP_HARDLIGHT_MODE,
                                           GIMP_SOFTLIGHT_MODE,
                                           GIMP_GRAIN_EXTRACT_MODE,
                                           GIMP_GRAIN_MERGE_MODE,

                                           GIMP_DIFFERENCE_MODE,
                                           GIMP_ADDITION_MODE,
                                           GIMP_SUBTRACT_MODE,
                                           GIMP_DARKEN_ONLY_MODE,
                                           GIMP_LIGHTEN_ONLY_MODE,

                                           GIMP_HUE_MODE,
                                           GIMP_SATURATION_MODE,
                                           GIMP_COLOR_MODE,
                                           GIMP_VALUE_MODE);

  gimp_int_store_insert_separator_after (GIMP_INT_STORE (store),
                                         GIMP_DISSOLVE_MODE, -1);
  gimp_int_store_insert_separator_after (GIMP_INT_STORE (store),
                                         GIMP_OVERLAY_MODE, -1);
  gimp_int_store_insert_separator_after (GIMP_INT_STORE (store),
                                         GIMP_GRAIN_MERGE_MODE, -1);
  gimp_int_store_insert_separator_after (GIMP_INT_STORE (store),
                                         GIMP_LIGHTEN_ONLY_MODE, -1);

  if (with_behind_mode)
    {
      gimp_enum_store_insert_value_after (GIMP_ENUM_STORE (store),
                                          GIMP_DISSOLVE_MODE,
                                          GIMP_BEHIND_MODE);
      gimp_enum_store_insert_value_after (GIMP_ENUM_STORE (store),
                                          GIMP_BEHIND_MODE,
                                          GIMP_COLOR_ERASE_MODE);
    }

  if (with_replace_modes)
    {
      gimp_enum_store_insert_value_after (GIMP_ENUM_STORE (store),
                                          GIMP_NORMAL_MODE,
                                          GIMP_REPLACE_MODE);
      gimp_enum_store_insert_value_after (GIMP_ENUM_STORE (store),
                                          GIMP_COLOR_ERASE_MODE,
                                          GIMP_ERASE_MODE);
      gimp_enum_store_insert_value_after (GIMP_ENUM_STORE (store),
                                          GIMP_ERASE_MODE,
                                          GIMP_ANTI_ERASE_MODE);
    }

  combo = gimp_enum_combo_box_new_with_model (GIMP_ENUM_STORE (store));
  g_object_unref (store);

  gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
                                        gimp_paint_mode_menu_separator_func,
                                        GINT_TO_POINTER (-1),
                                        NULL);

  return combo;
}
Пример #27
0
void ao_enclose_words_config (GtkButton *button, GtkWidget *config_window)
{
	GtkWidget *dialog;
	GtkWidget *vbox;
	GtkTreeIter chars_iter;
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *label_column, *char_one_column, *char_two_column;
	GtkTreeView *chars_tree_view;
	gchar insert_chars [2] = {0, 0};
	gint i;

	dialog = gtk_dialog_new_with_buttons(_("Plugins"), GTK_WINDOW(config_window),
						GTK_DIALOG_DESTROY_WITH_PARENT, "Accept", GTK_RESPONSE_ACCEPT,
						"Cancel", GTK_RESPONSE_CANCEL, "OK", GTK_RESPONSE_OK, NULL);

	vbox = ui_dialog_vbox_new (GTK_DIALOG (dialog));
	chars_list = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
	renderer = gtk_cell_renderer_text_new ();
	chars_tree_view = (GtkTreeView *) gtk_tree_view_new ();

	for (i = 0; i < 8; i++)
	{
		gchar *title = g_strdup_printf (_("Enclose combo %d"), i + 1);

		gtk_list_store_append (chars_list, &chars_iter);
		gtk_list_store_set (chars_list, &chars_iter, COLUMN_TITLE, title, -1);
		insert_chars [0] = *enclose_chars [i];
		gtk_list_store_set (chars_list, &chars_iter, COLUMN_PRIOR_CHAR, insert_chars, -1);
		insert_chars [0] = *(enclose_chars [i] + 1);
		gtk_list_store_set (chars_list, &chars_iter, COLUMN_END_CHAR, insert_chars, -1);

		g_free(title);
	}

	label_column = gtk_tree_view_column_new_with_attributes ("", renderer, "text", 0, NULL);

	renderer = gtk_cell_renderer_text_new ();
	g_object_set (renderer, "editable", TRUE, NULL);
	char_one_column = gtk_tree_view_column_new_with_attributes (_("Opening Character"), renderer,
		"text", COLUMN_PRIOR_CHAR, NULL);
	g_signal_connect (renderer, "edited", G_CALLBACK (enclose_chars_changed),
		GINT_TO_POINTER (COLUMN_PRIOR_CHAR));

	renderer = gtk_cell_renderer_text_new ();
	g_object_set (renderer, "editable", TRUE, NULL);
	char_two_column = gtk_tree_view_column_new_with_attributes (_("Closing Character"), renderer,
		"text", COLUMN_END_CHAR, NULL);
	g_signal_connect (renderer, "edited", G_CALLBACK (enclose_chars_changed),
		GINT_TO_POINTER (COLUMN_END_CHAR));

	gtk_tree_view_append_column (chars_tree_view, label_column);
	gtk_tree_view_append_column (chars_tree_view, char_one_column);
	gtk_tree_view_append_column (chars_tree_view, char_two_column);

	gtk_tree_view_set_model (chars_tree_view, GTK_TREE_MODEL (chars_list));
	gtk_box_pack_start(GTK_BOX(vbox), (GtkWidget *) chars_tree_view, FALSE, FALSE, 3);

	gtk_widget_show_all (vbox);
	g_signal_connect (dialog, "response", G_CALLBACK (configure_response), NULL);
	while (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT);
	gtk_widget_destroy (GTK_WIDGET (dialog));
}
Пример #28
0
static gboolean
dialog (void)
{
  /* Missing options: Color-dialogs? / own curl layer ? / transparency
     to original drawable / Warp-curl (unsupported yet) */

  GtkWidget *dialog;
  GtkWidget *hbox;
  GtkWidget *vbox;
  GtkWidget *table;
  GtkWidget *frame;
  GtkWidget *button;
  GtkWidget *combo;
  GtkObject *adjustment;
  gboolean   run;

  gimp_ui_init (PLUG_IN_BINARY, FALSE);

  dialog = gimp_dialog_new (_("Pagecurl Effect"), PLUG_IN_BINARY,
                            NULL, 0,
			    gimp_standard_help_func, PLUG_IN_PROC,

			    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
			    GTK_STOCK_OK,     GTK_RESPONSE_OK,

			    NULL);

  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);

  gimp_window_set_transient (GTK_WINDOW (dialog));

  vbox = gtk_vbox_new (FALSE, 12);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
                      vbox, TRUE, TRUE, 0);
  gtk_widget_show (vbox);

  frame = gimp_frame_new (_("Curl Location"));
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

  table = gtk_table_new (3, 2, TRUE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  gtk_container_add (GTK_CONTAINER (frame), table);

  curl_image = gtk_image_new ();

  gtk_table_attach (GTK_TABLE (table), curl_image, 0, 2, 1, 2,
                    GTK_SHRINK, GTK_SHRINK, 0, 0);
  gtk_widget_show (curl_image);

  curl_pixbuf_update ();

  {
    static const gchar *name[] =
    {
      N_("Lower right"),
      N_("Lower left"),
      N_("Upper left"),
      N_("Upper right")
    };
    gint i;

    button = NULL;
    for (i = CURL_EDGE_FIRST; i <= CURL_EDGE_LAST; i++)
      {
        button =
          gtk_radio_button_new_with_label (button == NULL ?
                                           NULL :
                                           gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
                                           gettext (name[i - CURL_EDGE_FIRST]));

        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
                                      curl.edge == i);

        g_object_set_data (G_OBJECT (button),
                           "gimp-item-data", GINT_TO_POINTER (i));

        gtk_table_attach (GTK_TABLE (table), button,
                          CURL_EDGE_LEFT  (i) ? 0 : 1,
                          CURL_EDGE_LEFT  (i) ? 1 : 2,
                          CURL_EDGE_UPPER (i) ? 0 : 2,
                          CURL_EDGE_UPPER (i) ? 1 : 3,
                          GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
        gtk_widget_show (button);

        g_signal_connect (button, "toggled",
                          G_CALLBACK (gimp_radio_button_update),
                          &curl.edge);

        g_signal_connect (button, "toggled",
                          G_CALLBACK (curl_pixbuf_update),
                           NULL);
      }
  }

  gtk_widget_show (table);
  gtk_widget_show (frame);

  frame = gimp_frame_new (_("Curl Orientation"));
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

  hbox = gtk_hbox_new (TRUE, 6);
  gtk_container_add (GTK_CONTAINER (frame), hbox);

  {
    static const gchar *name[] =
    {
      N_("_Vertical"),
      N_("_Horizontal")
    };
    gint i;

    button = NULL;
    for (i = 0; i <= CURL_ORIENTATION_LAST; i++)
      {
        button = gtk_radio_button_new_with_mnemonic (button == NULL ?
                                                     NULL :
                                                     gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
                                                     gettext (name[i]));

        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
                                      curl.orientation == i);

        g_object_set_data (G_OBJECT (button),
                           "gimp-item-data", GINT_TO_POINTER (i));

        gtk_box_pack_end (GTK_BOX (hbox), button, TRUE, TRUE, 0);
        gtk_widget_show (button);

        g_signal_connect (button, "toggled",
                          G_CALLBACK (gimp_radio_button_update),
                          &curl.orientation);

        g_signal_connect (button, "toggled",
                          G_CALLBACK (curl_pixbuf_update),
                          NULL);
      }
  }

  gtk_widget_show (hbox);
  gtk_widget_show (frame);

  button = gtk_check_button_new_with_mnemonic (_("_Shade under curl"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), curl.shade);
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
  gtk_widget_show (button);

  g_signal_connect (button, "toggled",
                    G_CALLBACK (gimp_toggle_button_update),
                    &curl.shade);

  combo = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);

  gimp_int_combo_box_prepend (GIMP_INT_COMBO_BOX (combo),
                              GIMP_INT_STORE_VALUE,    CURL_COLORS_GRADIENT_REVERSE,
                              GIMP_INT_STORE_LABEL,    _("Current gradient (reversed)"),
                              GIMP_INT_STORE_STOCK_ID, GIMP_STOCK_GRADIENT,
                              -1);
  gimp_int_combo_box_prepend (GIMP_INT_COMBO_BOX (combo),
                              GIMP_INT_STORE_VALUE,    CURL_COLORS_GRADIENT,
                              GIMP_INT_STORE_LABEL,    _("Current gradient"),
                              GIMP_INT_STORE_STOCK_ID, GIMP_STOCK_GRADIENT,
                              -1);
  gimp_int_combo_box_prepend (GIMP_INT_COMBO_BOX (combo),
                              GIMP_INT_STORE_VALUE,    CURL_COLORS_FG_BG,
                              GIMP_INT_STORE_LABEL,    _("Foreground / background colors"),
                              GIMP_INT_STORE_STOCK_ID, GIMP_STOCK_DEFAULT_COLORS,
                              -1);

  gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
  gtk_widget_show (combo);

  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              curl.colors,
                              G_CALLBACK (gimp_int_combo_box_get_active),
                              &curl.colors);

  gtk_widget_show (dialog);

  table = gtk_table_new (1, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
  gtk_widget_show (table);

  adjustment = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
                                     _("_Opacity:"), 100, 0,
                                     curl.opacity * 100.0, 0.0, 100.0,
                                     1.0, 1.0, 0.0,
                                     TRUE, 0, 0,
                                     NULL, NULL);
  g_signal_connect (adjustment, "value-changed",
                    G_CALLBACK (dialog_scale_update),
                    &curl.opacity);

  run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);

  gtk_widget_destroy (dialog);

  return run;
}
Пример #29
0
static GtkWidget *create_timer_list(CtkConfig *ctk_config)
{
    GtkTreeModel *model;
    GtkWidget *treeview;
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;
    GtkWidget *sw;
    GtkWidget *vbox;
    GtkWidget *label;
    GtkWidget *alignment;
    
    sw = gtk_scrolled_window_new(NULL, NULL);
    
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);

    ctk_config->list_store =
        gtk_list_store_new(NUM_COLUMNS,
                           G_TYPE_POINTER,  /* TIMER_CONFIG_COLUMN */
                           G_TYPE_POINTER,  /* FUNCTION_COLUMN */
                           G_TYPE_POINTER,  /* DATA_COLUMN */
                           G_TYPE_UINT,     /* HANDLE_COLUMN */
                           G_TYPE_BOOLEAN); /* OWNER_ENABLE_COLUMN */
    
    model = GTK_TREE_MODEL(ctk_config->list_store);
    
    treeview = gtk_tree_view_new_with_model(model);
    
    g_object_unref(ctk_config->list_store);

    /* Enable */

    renderer = gtk_cell_renderer_toggle_new();
    g_signal_connect(renderer, "toggled",
                     G_CALLBACK(timer_enable_toggled), ctk_config);
    column = gtk_tree_view_column_new_with_attributes("Enabled", renderer,
                                                      NULL);
    
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
    gtk_tree_view_column_set_resizable(column, FALSE);

    gtk_tree_view_column_set_cell_data_func(column,
                                            renderer,
                                            enabled_renderer_func,
                                            GINT_TO_POINTER
                                            (TIMER_CONFIG_COLUMN),
                                            NULL);

    /* Description */
    
    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Description",
                                                      renderer,
                                                      NULL);
    
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
    gtk_tree_view_column_set_resizable(column, TRUE);

    gtk_tree_view_column_set_cell_data_func(column,
                                            renderer,
                                            description_renderer_func,
                                            GINT_TO_POINTER
                                            (TIMER_CONFIG_COLUMN),
                                            NULL);
    
    /* Time interval */

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes("Time Interval",
                                                      renderer,
                                                      NULL);

    g_signal_connect(renderer, "edited",
                     G_CALLBACK(time_interval_edited), ctk_config);
    
    gtk_tree_view_column_set_cell_data_func(column,
                                            renderer,
                                            time_interval_renderer_func,
                                            GINT_TO_POINTER
                                            (TIMER_CONFIG_COLUMN),
                                            NULL);
    
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
    gtk_tree_view_column_set_resizable(column, FALSE);


    gtk_container_add(GTK_CONTAINER(sw), treeview);

    vbox = gtk_vbox_new(FALSE, 5);
    
    label = gtk_label_new("Active Timers:");
    alignment = gtk_alignment_new(0.0, 0.0, 0, 0);
    gtk_container_add(GTK_CONTAINER(alignment), label);
    gtk_box_pack_start(GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
    
    /* create the tooltip for the treeview (can't do it per column) */
    
    ctk_config_set_tooltip(ctk_config, treeview,
                           "The Active Timers describe operations that "
                           "nvidia-settings will perform at regular "
                           "intervals.");
    
    return vbox;

} /* create_timer_list() */
Пример #30
0
/*
 * SNEP Core: read function
 *	This function handles SNEP REQUEST codes:
 *	GET, PUT and CONTINUE (REJECT is not handled).
 *
 *	We read the first 6 bytes (the header) and check
 *	- the read size ( should be 6 )
 *	- the version (on MAJOR)
 *
 *	Then, we check snep_data. If it exists, it means that we are in
 *	a fragment/continue situation (a 1st fragment was sent, and we
 *	expect a CONTINUE for the remaining bytes).
 *	If there's no existing snep_data, we create a new one and read the
 *	missing bytes (llcp removes fragmentation issues)
 *
 */
bool near_snep_core_read(int client_fd,
				uint32_t adapter_idx, uint32_t target_idx,
				near_tag_io_cb cb,
				near_server_io req_get,
				near_server_io req_put,
				gpointer data)
{
	struct p2p_snep_data *snep_data;
	struct p2p_snep_req_frame frame;
	int bytes_recv, ret;
	uint32_t ndef_length;

	DBG("");

	/* Check previous/pending snep_data */
	snep_data = g_hash_table_lookup(snep_client_hash,
					GINT_TO_POINTER(client_fd));

	/*
	 * If snep data is already there, and there are more bytes to read
	 * we just go ahead and read more fragments from the client.
	 */
	if (snep_data &&
			snep_data->nfc_data_length !=
					snep_data->nfc_data_current_length) {
		ret = snep_core_read_ndef(client_fd, snep_data);
		if (ret)
			return ret;

		goto process_request;
	}

	/*
	 * We already got something from this client, we should try
	 * to continue reading.
	 */
	/* TODO Try with PEEK */
	bytes_recv = recv(client_fd, &frame, sizeof(frame), 0);
	if (bytes_recv < 0) {
		near_error("Read error SNEP %d %s", bytes_recv,
							strerror(errno));
		return false;
	}

	/* Check frame size */
	if (bytes_recv != sizeof(frame)) {
		near_error("Bad frame size: %d", bytes_recv);
		return false;
	}

	/* If major is different, send UNSUPPORTED VERSION */
	if (NEAR_SNEP_MAJOR(frame.version) != NEAR_SNEP_MAJOR(NEAR_SNEP_VERSION)) {
		near_error("Unsupported version (%d)", frame.version);
		near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_VERSION);
		return true;
	}

	/*
	 * This is a fragmentation SNEP operation since we have pending
	 * frames. But the ndef length and the current data length are
	 * identical. So this is a CONTINUE for a fragmented GET, and
	 * we should just process a CONTINUE frame and send the fragments
	 * back to the client. This will be done from snep_core_process_request().
	 */
	if (snep_data) {
		snep_data->request = frame.request;
		goto process_request;
	}

	/* This is a new request from the client */
	snep_data = g_try_malloc0(sizeof(struct p2p_snep_data));
	if (!snep_data)
		return false;

	/* the whole frame length */
	ndef_length = GINT_FROM_BE(frame.length);

	snep_data->nfc_data = g_try_malloc0(ndef_length + TLV_SIZE);
	if (!snep_data->nfc_data) {
		g_free(snep_data);
		return false;
	}

	/* fill the struct */
	snep_data->nfc_data_length = ndef_length;
	snep_data->nfc_data_ptr = snep_data->nfc_data;
	snep_data->adapter_idx = adapter_idx;
	snep_data->target_idx = target_idx;
	snep_data->request = frame.request;
	snep_data->respond_continue = FALSE;
	snep_data->cb = cb;

	/* Add to the client hash table */
	g_hash_table_insert(snep_client_hash,
					GINT_TO_POINTER(client_fd), snep_data);

	if (ndef_length > 0) {
		if ((frame.request == NEAR_SNEP_REQ_GET) ||
				(frame.request == NEAR_SNEP_REQ_PUT)) {
			/* We should read the missing bytes */
			ret = snep_core_read_ndef(client_fd, snep_data);
			if (ret)
				return ret;
		}
	}

process_request:
	return snep_core_process_request(client_fd, snep_data,
							req_get, req_put);

}