filefind.c File Reference

#include <gtk/gtk.h>
#include "liberkeyb/ergtk-keyb.h"
#include "i18n.h"
#include "log.h"
#include "filefind.h"
#include "measures.h"
Include dependency graph for filefind.c:

Go to the source code of this file.

Defines

#define UNUSED(x)   (void)(x)

Functions

static void filefind_on_hbox_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data)
static void filefind_on_search_button_clicked (GtkWidget *widget, gpointer data)
static void filefind_on_cancel_button_clicked (GtkWidget *widget, gpointer data)
GtkWidget * filefind_dialog_create (GtkWidget *parent)
void filefind_locale_changed ()
const gchar * filefind_get_text ()

Variables

static GtkWidget * g_dialog = NULL
static GtkWidget * g_search_label = NULL
static GtkWidget * g_input_entry = NULL
static GtkWidget * g_search_button = NULL
static GtkWidget * g_cancel_button = NULL
static gchar * g_lastsearch = NULL

Define Documentation

#define UNUSED (  )     (void)(x)

Function Documentation

GtkWidget* filefind_dialog_create ( GtkWidget *  parent  ) 

File Name : filefind.h

Description: File find dialog Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Definition at line 67 of file filefind.c.

References BUTTON_HEIGHT, BUTTON_WIDTH, ergtk_keyb_new(), filefind_locale_changed(), filefind_on_cancel_button_clicked(), filefind_on_hbox_size_allocate(), filefind_on_search_button_clicked(), g_cancel_button, g_dialog, g_input_entry, g_lastsearch, g_search_button, g_search_label, POPUP_DIALOG_H_PADDING, POPUP_DIALOG_H_SPACING, POPUP_DIALOG_V_PADDING, POPUP_DIALOG_V_SPACING, POPUP_DIALOG_WIDTH, TEXT_ENTRY_HEIGHT, and TEXT_ENTRY_WIDTH.

Referenced by fileview_show_search_dialog().

00068 {
00069     // dialog
00070     GtkWidget* dialog = gtk_dialog_new ();
00071     gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
00072     gtk_window_set_title (GTK_WINDOW(dialog), "");
00073     gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
00074     gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
00075     gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
00076     g_dialog = dialog;
00077 
00078     // alignment
00079     GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 0);
00080     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 
00081                               POPUP_DIALOG_V_PADDING, 
00082                               POPUP_DIALOG_V_PADDING, 
00083                               POPUP_DIALOG_H_PADDING, 
00084                               POPUP_DIALOG_H_PADDING);
00085     gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), alignment);
00086 
00087     // vbox
00088     GtkWidget* vbox = gtk_vbox_new(FALSE, POPUP_DIALOG_V_SPACING);
00089     gtk_container_add(GTK_CONTAINER(alignment), vbox);
00090 
00091     // search_label_widget
00092     GtkWidget * search_label_widget = gtk_label_new("");
00093     gtk_widget_set_name(search_label_widget, "irex-uds-search-label");
00094     gtk_widget_set_size_request(search_label_widget, 
00095             POPUP_DIALOG_WIDTH - 2 * POPUP_DIALOG_H_PADDING, -1);
00096     gtk_misc_set_alignment(GTK_MISC(search_label_widget), 0.0, 0.0);
00097     gtk_label_set_justify(GTK_LABEL(search_label_widget), GTK_JUSTIFY_LEFT);
00098     gtk_label_set_single_line_mode(GTK_LABEL(search_label_widget), FALSE);
00099     gtk_label_set_line_wrap(GTK_LABEL(search_label_widget), TRUE);
00100     gtk_label_set_ellipsize(GTK_LABEL(search_label_widget), PANGO_ELLIPSIZE_NONE);
00101     gtk_box_pack_start(GTK_BOX(vbox), search_label_widget, TRUE, TRUE, 0);
00102     g_search_label = search_label_widget;
00103 
00104     // hbox
00105     GtkWidget* hbox = gtk_hbox_new(FALSE, POPUP_DIALOG_H_SPACING);
00106     gtk_widget_set_size_request(hbox, -1, -1);
00107     gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
00108 
00109     // input_entry
00110     GtkWidget* entry_widget = gtk_entry_new();
00111     gtk_widget_set_size_request(entry_widget, TEXT_ENTRY_WIDTH, TEXT_ENTRY_HEIGHT);
00112     if (g_lastsearch)
00113         gtk_entry_set_text(GTK_ENTRY(entry_widget), g_lastsearch);
00114     else 
00115         gtk_entry_set_text(GTK_ENTRY(entry_widget), "");
00116     gtk_box_pack_start(GTK_BOX(hbox), entry_widget, TRUE, TRUE, 0); 
00117     g_object_set(G_OBJECT(entry_widget), "im-context-inhibit", TRUE, NULL );
00118     g_object_set(G_OBJECT(entry_widget), "activates-default", TRUE, NULL );
00119     g_input_entry = entry_widget;
00120 
00121     // sub_hbox
00122     GtkWidget* sub_hbox = gtk_hbox_new(FALSE, POPUP_DIALOG_H_SPACING);
00123     gtk_box_pack_start(GTK_BOX(hbox), sub_hbox, FALSE, FALSE, 0); 
00124 
00125     // search_button
00126     GtkWidget* button_widget = gtk_button_new();
00127     gtk_widget_set_size_request(button_widget, BUTTON_WIDTH, BUTTON_HEIGHT);
00128     gtk_box_pack_start(GTK_BOX(sub_hbox), button_widget, FALSE, FALSE, 0); 
00129     g_search_button = button_widget;
00130     GTK_WIDGET_SET_FLAGS(g_search_button, GTK_CAN_DEFAULT);
00131     gtk_window_set_default(GTK_WINDOW(dialog), g_search_button);
00132     
00133     // cancel_button
00134     GtkWidget* cancel_widget = gtk_button_new();
00135     gtk_widget_set_size_request(cancel_widget, BUTTON_WIDTH, BUTTON_HEIGHT);
00136     gtk_box_pack_start(GTK_BOX(sub_hbox), cancel_widget, FALSE, FALSE, 0); 
00137     g_cancel_button = cancel_widget;
00138 
00139     // keyboard_widget
00140     GtkWidget* keyboard_widget = ergtk_keyb_new();
00141     gtk_box_pack_start(GTK_BOX(vbox), keyboard_widget, TRUE, TRUE, 10);
00142 
00143     // install signal hanlders.
00144     g_signal_connect(G_OBJECT(sub_hbox), "size-allocate",  
00145             G_CALLBACK(filefind_on_hbox_size_allocate), sub_hbox); 
00146     g_signal_connect(G_OBJECT(button_widget), "clicked", 
00147             G_CALLBACK(filefind_on_search_button_clicked), (gpointer) dialog);
00148     g_signal_connect(G_OBJECT(cancel_widget), "clicked", 
00149             G_CALLBACK(filefind_on_cancel_button_clicked), (gpointer) dialog);
00150 
00151 
00152     // Focus on the entry in order to show keyboard automatically.
00153     gtk_widget_grab_focus(entry_widget);
00154     
00155     filefind_locale_changed();
00156 
00157     gtk_widget_show_all(dialog);
00158     return dialog;
00159 }

Here is the call graph for this function:

Here is the caller graph for this function:

const gchar* filefind_get_text (  ) 

Definition at line 172 of file filefind.c.

References g_lastsearch.

Referenced by fileview_show_search_dialog().

00173 {
00174     return g_lastsearch;
00175 }

Here is the caller graph for this function:

void filefind_locale_changed (  ) 

Definition at line 162 of file filefind.c.

References g_cancel_button, g_search_button, and g_search_label.

Referenced by filefind_dialog_create().

00163 {
00164     gtk_label_set_text(GTK_LABEL(g_search_label), 
00165                        _("Type the name or author of the item you are looking for. Tap the Find button; the device will begin searching."));
00166 
00167     gtk_button_set_label(GTK_BUTTON(g_search_button), _("Find"));
00168     gtk_button_set_label(GTK_BUTTON(g_cancel_button), _("Cancel"));
00169 }

Here is the caller graph for this function:

static void filefind_on_cancel_button_clicked ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 193 of file filefind.c.

References g_dialog, g_input_entry, g_lastsearch, and UNUSED.

Referenced by filefind_dialog_create().

00194 {
00195     UNUSED(widget);
00196     UNUSED(data);
00197     const gchar* text = gtk_entry_get_text(GTK_ENTRY(g_input_entry));
00198     g_free(g_lastsearch);
00199     g_lastsearch = g_strdup(text);
00200     gtk_dialog_response(GTK_DIALOG(g_dialog), GTK_RESPONSE_CLOSE);
00201 }

Here is the caller graph for this function:

static void filefind_on_hbox_size_allocate ( GtkWidget *  widget,
GtkAllocation *  allocation,
gpointer  user_data 
) [static]

Definition at line 203 of file filefind.c.

References BUTTON_WIDTH, ERRORPRINTF, LOGPRINTF, and UNUSED.

Referenced by filefind_dialog_create().

00206 {
00207     UNUSED(widget);
00208     UNUSED(allocation);
00209     if (!user_data || !GTK_IS_HBOX(user_data))
00210     {
00211         ERRORPRINTF("Can't adjust for this widget because it's not a HBOX!");
00212         return;
00213     }
00214 
00215     // Get child widgets.
00216     GList * children = gtk_container_get_children(GTK_CONTAINER(user_data));
00217     if (!children)
00218     {
00219         ERRORPRINTF("The hbox hasn't any children!");
00220         return;
00221     }
00222     int n_children = g_list_length(children);
00223 
00224     // Calculate the button's width.
00225     int request_width = BUTTON_WIDTH;
00226     int index = 0;
00227     while (index < n_children)
00228     {
00229         gpointer gp = g_list_nth_data(children, index);
00230         GtkWidget * child = GTK_WIDGET(gp);
00231         GtkRequisition requisition;
00232         gtk_widget_size_request(child, &requisition);
00233         if (request_width < requisition.width)
00234         {
00235             request_width = requisition.width;
00236         }
00237 
00238         LOGPRINTF("index [%d] width [%d]", index, requisition.width);
00239         index++;
00240     }
00241 
00242     // Set the buttons's width to be the request_width.
00243     index = 0;
00244     while (index < n_children)
00245     {
00246         gpointer gp = g_list_nth_data(children, index);
00247         GtkWidget * child = GTK_WIDGET(gp);
00248         GtkRequisition requisition;
00249         gtk_widget_size_request(child, &requisition);
00250         if (requisition.width != request_width)
00251         {   
00252             gtk_widget_set_size_request(child,
00253                     request_width,
00254                     requisition.height);
00255         }
00256         index++;
00257     }
00258 }

Here is the caller graph for this function:

static void filefind_on_search_button_clicked ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 178 of file filefind.c.

References g_dialog, g_input_entry, g_lastsearch, and UNUSED.

Referenced by filefind_dialog_create().

00179 {
00180     UNUSED(widget);
00181     UNUSED(data);
00182     const gchar* text = gtk_entry_get_text(GTK_ENTRY(g_input_entry));
00183     g_free(g_lastsearch);
00184     g_lastsearch = g_strdup(text);
00185     if (strcmp(text, "") == 0) {
00186         gtk_dialog_response(GTK_DIALOG(g_dialog), GTK_RESPONSE_CLOSE);
00187     } else {
00188         gtk_dialog_response(GTK_DIALOG(g_dialog), GTK_RESPONSE_ACCEPT);
00189     }
00190 }

Here is the caller graph for this function:


Variable Documentation

GtkWidget* g_cancel_button = NULL [static]

Definition at line 49 of file filefind.c.

Referenced by filefind_dialog_create(), and filefind_locale_changed().

GtkWidget* g_dialog = NULL [static]

Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Definition at line 45 of file filefind.c.

Referenced by filefind_dialog_create(), filefind_on_cancel_button_clicked(), and filefind_on_search_button_clicked().

GtkWidget* g_input_entry = NULL [static]
gchar* g_lastsearch = NULL [static]
GtkWidget* g_search_button = NULL [static]

Definition at line 48 of file filefind.c.

Referenced by filefind_dialog_create(), and filefind_locale_changed().

GtkWidget* g_search_label = NULL [static]

Definition at line 46 of file filefind.c.

Referenced by filefind_dialog_create(), and filefind_locale_changed().

Generated by  doxygen 1.6.2-20100208