Active Topics

 


Reply
Thread Tools
b-man's Avatar
Posts: 549 | Thanked: 502 times | Joined on Feb 2008 @ Bowling Green Ohio (united states)
#1
It seems that I have ran into another problem while using hildon touch selector . I´m trying to have hildon touch selector display l list of files from a directory as items on the selector, but i haven´t been able to find any documentation for this function. Can anyone help me with this?

here´s a code snippet of what i have so far; the ¨const gchar *items[] = {Splash *}; function would be replaced by the file list function.



Code:
#include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
#include <gtk/gtk.h>
#include <hildon/hildon.h>
#include <libintl.h>
#include <locale.h>
#include <libosso.h>
#include <glib.h>

typedef struct _user_data_t user_data_t;

struct _user_data_t
{
	GtkWidget *dialog, *selector, *button;
	gint response;
};

osso_return_t execute(osso_context_t *osso, gpointer user_data, gboolean 
user_activated)
{
	user_data_t *data = g_new0(user_data_t, 1);
	guint i;
	const gchar *items[] =
	{
		"Splash 1",
		"Splash 2",
		"Splash 3",
		"Splash 4",
		"Splash 5",
		"Splash 6",
		"Splash 7",
		"Splash 8",
		"Splash 9",
		"Splash 10"
	};

	g_return_val_if_fail(data != NULL, OSSO_ERROR);

	setlocale(LC_ALL, "");

	data->dialog = gtk_dialog_new_with_buttons(
		"Bootsplash selection",
		GTK_WINDOW(user_data),
		GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
		dgettext("hildon-libs", "wdgt_bd_save"),
		GTK_RESPONSE_OK,
		GTK_STOCK_CANCEL,
		GTK_RESPONSE_CANCEL,
		NULL);

	data->selector = hildon_touch_selector_new_text();
	for (i = 0; i < G_N_ELEMENTS(items); i++)
		
hildon_touch_selector_append_text(HILDON_TOUCH_SELECTOR(data->selector), 
items[i]);

	hildon_touch_selector_set_column_selection_mode 
(HILDON_TOUCH_SELECTOR (data->selector), 
HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);

	data->button = hildon_picker_button_new(HILDON_SIZE_AUTO | 
HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
	
hildon_picker_button_set_selector(HILDON_PICKER_BUTTON(data->button), 
HILDON_TOUCH_SELECTOR(data->selector)); 
	
hildon_picker_button_set_active(HILDON_PICKER_BUTTON(data->button), 0);
	hildon_button_set_title(HILDON_BUTTON(data->button), 
"Selection:");

	gtk_box_pack_start(GTK_BOX (GTK_DIALOG(data->dialog)->vbox), 
data->button, TRUE, TRUE, 0);
	gtk_widget_show(data->button);

	data->response = gtk_dialog_run(GTK_DIALOG(data->dialog));
	if (data->response == GTK_RESPONSE_OK)
	{
		gchar *text, *current_text;
		current_text = 
hildon_touch_selector_get_current_text(HILDON_TOUCH_SELECTOR(data->selector));
		text = g_strdup_printf("Selected: %s, index number: %d", 
current_text, 
hildon_touch_selector_get_active(HILDON_TOUCH_SELECTOR(data->selector), 
0));
		hildon_banner_show_information(NULL, NULL, text);
		g_free(current_text);
		g_free(text);
		text = current_text = NULL;
	}

	gtk_widget_destroy(GTK_WIDGET(data->dialog));
	g_free(data);
	data = NULL;
	return OSSO_OK;
}

osso_return_t save_state(osso_context_t *osso, gpointer data)
{
	/* ... save state ... */
	return OSSO_OK;
}
__________________
I'm an advanced user and a bit of a modder.
----------------------------------------------
I am involved with Mer, Deblet, and NITdroid.
My ports/creations/hacks: GNOME (for Deblet), Cdeb2», Ubuntu, playable flash games in the "Get Started" app, DBS, ect...


enhanced fedora port has been canceled in favor of NITDebian (TBA)
 
Guest | Posts: n/a | Thanked: 0 times | Joined on
#2
It's a shame you and I are using different languages for our apps, because we seem to at a level of experience where we're into a lot of the same challenges. Between us we could probably fill this forum with questions
 
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#3
Originally Posted by b-man View Post
It seems that I have ran into another problem while using hildon touch selector . I´m trying to have hildon touch selector display l list of files from a directory as items on the selector, but i haven´t been able to find any documentation for this function. Can anyone help me with this?

here´s a code snippet of what i have so far; the ¨const gchar *items[] = {Splash *}; function would be replaced by the file list function.

...
I don't know if there is a hildon filechooser. Maybe you can use
GtkFileChooser. Or if you are searching for a way to retrieve a list of files,
look at gio api .
Short snippet:
Code:
#include <gio/gio.h>
#include <stdio.h>

int main(int argc, char** argv)
{
  gtk_init(&argc, &argv);
  char* path = "/home";
  GFile* file = g_file_new_for_path(path);
  printf("path name: %s\n", g_file_get_basename(file));
  GFileEnumerator* files = g_file_enumerate_children(file,
						    G_FILE_ATTRIBUTE_STANDARD_NAME,
						    G_FILE_QUERY_INFO_NONE,
						    NULL,
						    NULL);
  if(files!=NULL)
  {
    GFileInfo* info = g_file_enumerator_next_file(files, NULL, NULL);
    while(info)
    {
      printf("name %s\n", g_file_info_get_name(info));
      info = g_file_enumerator_next_file(files, NULL, NULL);
    }
    g_object_unref(files);
  }
  return 0;
}
nicolai

Last edited by nicolai; 2009-10-22 at 23:41.
 

The Following User Says Thank You to nicolai For This Useful Post:
Posts: 432 | Thanked: 645 times | Joined on Mar 2009
#4
Originally Posted by nicolai View Post
I don't know if there is a hildon filechooser.

Here is the API for the HildonFileChooserDialog.

Cheers Daniel
 
b-man's Avatar
Posts: 549 | Thanked: 502 times | Joined on Feb 2008 @ Bowling Green Ohio (united states)
#5
I got the file list function applied but now i´m having issues with piping the data into my selection menu




code:

Code:
#include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
#include <gtk/gtk.h>
#include <hildon/hildon.h>
#include <libintl.h>
#include <locale.h>
#include <libosso.h>
#include <glib.h>

typedef struct _user_data_t user_data_t;

struct _user_data_t
{
	GtkWidget *dialog, *selector, *button, *label;
	GSList *item;
	GtkListStore *items;
	HildonTouchSelectorColumn *column;
	GtkCellRenderer *renderer;
	gint response;
};

osso_return_t execute(osso_context_t *osso, gpointer user_data, gboolean 
user_activated)
{
	user_data_t *data = g_new0(user_data_t, 1);
	guint i;
	/* get object data for selection objects */
		char* path = "/home/maemo/code";
		GFile* file = g_file_new_for_path(path);
		GFileEnumerator* files = g_file_enumerate_children(file, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NONE, NULL, NULL);
		
		if(file!=NULL)
		{
			GFileInfo* info = g_file_enumerator_next_file(files, NULL, NULL);
					  while(info) {
						  data->items = g_file_info_get_name(info);
						  info = g_file_enumerator_next_file(files, NULL, NULL);
					  }
		g_object_unref(files);
		}
	
	g_return_val_if_fail(data != NULL, OSSO_ERROR);
		
		
	setlocale(LC_ALL, "");

	data->dialog = gtk_dialog_new_with_buttons(
		"Bootsplash selection",
		GTK_WINDOW(user_data),
		GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
		dgettext("hildon-libs", "wdgt_bd_save"),
		GTK_RESPONSE_OK,
		GTK_STOCK_CANCEL,
		GTK_RESPONSE_CANCEL,
		NULL);


	data->selector = hildon_touch_selector_new ();

	data->selector = hildon_touch_selector_new_text();
		for (i = 0; i < G_N_ELEMENTS(data->items); i++)
			hildon_touch_selector_append_text(HILDON_TOUCH_SELECTOR(data->selector), data->items);

	  hildon_touch_selector_set_column_selection_mode 
(HILDON_TOUCH_SELECTOR (data->selector), 
HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);

	data->button = hildon_picker_button_new(HILDON_SIZE_AUTO | 
HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
	
hildon_picker_button_set_selector(HILDON_PICKER_BUTTON(data->button), 
HILDON_TOUCH_SELECTOR(data->selector));
	
hildon_picker_button_set_active(HILDON_PICKER_BUTTON(data->button), 0);
	hildon_button_set_title(HILDON_BUTTON(data->button), 
"Selection:");

	gtk_box_pack_start(GTK_BOX (GTK_DIALOG(data->dialog)->vbox), 
data->button, TRUE, TRUE, 0);
	gtk_widget_show(data->button);

	data->response = gtk_dialog_run(GTK_DIALOG(data->dialog));
	if (data->response == GTK_RESPONSE_OK)
	{
		gchar *text, *current_text;
		current_text = 
hildon_touch_selector_get_current_text(HILDON_TOUCH_SELECTOR(data->selector));
		text = g_strdup_printf("Selected: %s, index number: %d", 
current_text, 
hildon_touch_selector_get_active(HILDON_TOUCH_SELECTOR(data->selector),
0));
		hildon_banner_show_information(NULL, NULL, text);
		g_free(current_text);
		g_free(text);
		text = current_text = NULL;
	}

	gtk_widget_destroy(GTK_WIDGET(data->dialog));
	g_free(data);
	data = NULL;
	return OSSO_OK;
}

osso_return_t save_state(osso_context_t *osso, gpointer data)
{
	/* ... save state ... */
	return OSSO_OK;
}
what am i doing wrong?
__________________
I'm an advanced user and a bit of a modder.
----------------------------------------------
I am involved with Mer, Deblet, and NITdroid.
My ports/creations/hacks: GNOME (for Deblet), Cdeb2», Ubuntu, playable flash games in the "Get Started" app, DBS, ect...


enhanced fedora port has been canceled in favor of NITDebian (TBA)
 
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#6
Originally Posted by b-man View Post
I got the file list function applied but now i´m having issues with piping the data into my selection menu
...
Code:
....
while(info) {
  data->items = g_file_info_get_name(info);
	info = g_file_enumerator_next_file(files, NULL, NULL);
}
....
Every entry overrides data->items. You need to call a function to insert new items into your list.

nicolai
 

The Following User Says Thank You to nicolai For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 08:28.