flipbar.c File Reference

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <libergtk/ergtk.h>
#include "i18n.h"
#include "log.h"
#include "ipc.h"
#include "settings.h"
#include "settings_utils.h"
#include "settings_style.h"
#include "flipbar.h"
Include dependency graph for flipbar.c:

Go to the source code of this file.

Data Structures

struct  FlipBarSettings

Defines

#define NUM_FLIPBAR_MODES   2

Functions

static GtkWidget * create_flipbar_widgets (GtkBox *parent)
static void on_flipbar_changed (GtkWidget *widget, gpointer data)
static void init_widgets_with_settings (void)
static void on_listview_row_activated (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
static void on_listview_navigate_cursor (erGtkListView *er_listview, erGtkListViewKeyPress keycode, gpointer user_data)
static gboolean on_focus_in (GtkWidget *widget, gpointer data)
static gboolean on_focus_out (GtkWidget *widget, gpointer data)
GtkWidget * create_flipbar_window (GtkWidget *parent)
void load_flipbar_settings ()
void save_flipbar_settings ()
static GtkWidget * create_radio_button_item (GtkWidget *group, gchar *title, gchar *subtitle)

Variables

static FlipBarSettings g_orig_flipbar_settings
static FlipBarSettings g_cur_flipbar_settings
static GtkWidget * g_flipbar_radios [NUM_FLIPBAR_MODES]

Define Documentation

#define NUM_FLIPBAR_MODES   2

Function Documentation

static GtkWidget * create_flipbar_widgets ( GtkBox *  parent  )  [static]

Definition at line 316 of file flipbar.c.

References create_radio_button_item(), g_flipbar_radios, ITEM_SPACING, NUM_FLIPBAR_MODES, and on_flipbar_changed().

Referenced by create_flipbar_window().

00317 {
00318 
00319     // Top level vbox.
00320     GtkWidget* top_level_vbox = gtk_vbox_new(FALSE, ITEM_SPACING);
00321     gtk_box_pack_start(parent, top_level_vbox, FALSE, FALSE, 0);
00322 
00323     // The vbox containing radio buttons.
00324     GtkWidget* vbox = gtk_vbox_new(TRUE, 10);
00325     gtk_box_pack_start(GTK_BOX(top_level_vbox), vbox, FALSE, FALSE, 0);
00326 
00327     int i = 0 ;
00328     for (i=0; i<NUM_FLIPBAR_MODES; i++)
00329     {
00330         switch (i)
00331         {
00332             case 0:
00333             {
00334                 // the radio button "Normal mode"
00335                 g_flipbar_radios[i] = create_radio_button_item(NULL, _("Flip pages Left to Right")
00336                         , _("Flip pages like you would expect while using a computer."));
00337                 
00338                 break;
00339             }
00340             case 1:
00341             {
00342                 // The radio button "book mode"
00343                 g_flipbar_radios[i] = create_radio_button_item(g_flipbar_radios[0], _("Flip pages Right to Left")
00344                         , _("Flip pages like you would in a real book."));
00345                 
00346                 break;
00347             }
00348             default:
00349             {
00350                 // never happens
00351                 break;
00352             }
00353         }
00354 
00355         // Add signal handler.
00356         g_signal_connect_after(G_OBJECT(g_flipbar_radios[i]),
00357             "toggled",
00358             G_CALLBACK(on_flipbar_changed),
00359             (gpointer)i);
00360 
00361         gtk_box_pack_start(GTK_BOX(vbox), g_flipbar_radios[i], FALSE, FALSE, 0);
00362     }
00363 
00364     return top_level_vbox;
00365 }

Here is the call graph for this function:

Here is the caller graph for this function:

GtkWidget* create_flipbar_window ( GtkWidget *  parent  ) 

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

Definition at line 118 of file flipbar.c.

References create_flipbar_widgets(), create_settingsview(), create_title(), init_widgets_with_settings(), on_focus_in(), on_focus_out(), on_listview_navigate_cursor(), on_listview_row_activated(), SMALL_SPACING, WINDOW_BORDER_PADDING, WINDOW_BOTTOM_PADDING, WINDOW_H_PADDING, and WINDOW_TOP_ALT_PADDING.

Referenced by create_concrete_win().

00119 {
00120     // create top window
00121     GtkWidget* top_window = parent;
00122     gtk_window_maximize(GTK_WINDOW(top_window));
00123     gtk_window_set_resizable(GTK_WINDOW(top_window), FALSE);
00124     gtk_container_set_border_width(GTK_CONTAINER(top_window),WINDOW_BORDER_PADDING  );
00125     gtk_window_set_modal(GTK_WINDOW(top_window), TRUE);
00126 
00127     // top level vbox (vboxtop)
00128     GtkWidget* vboxtop = gtk_vbox_new(FALSE, 3);
00129     gtk_container_add(GTK_CONTAINER(top_window), vboxtop);
00130 
00131     // add header container the title and subtitle of this settings page
00132     create_title(GTK_VBOX(vboxtop), _("Settings"), _("Flipbar Setup"));
00133     
00134     // add the back/exit bar below the title 
00135     GtkWidget* view = create_settingsview();
00136     gtk_box_pack_start(GTK_BOX(vboxtop), view, FALSE, FALSE,0 ); 
00137     g_signal_connect(view, "row-activated", G_CALLBACK(on_listview_row_activated), NULL ) ;
00138     g_signal_connect(view, "navigate-cursor", G_CALLBACK(on_listview_navigate_cursor), NULL ) ;
00139     g_signal_connect(view, "focus-in-event", G_CALLBACK(on_focus_in), NULL );
00140     g_signal_connect(view, "focus-out-event", G_CALLBACK(on_focus_out), NULL );
00141 
00142     // add an alignment below the exit bar
00143     GtkWidget* alignment = gtk_alignment_new(0, 0, 1.0, 0.0);
00144     gtk_container_add(GTK_CONTAINER(vboxtop), alignment);
00145 
00146     // introdude a frame in the alignment
00147     GtkWidget* frame = gtk_frame_new(NULL);
00148     gtk_widget_set_name(frame, "irex-margins-frame");
00149     gtk_container_add(GTK_CONTAINER(alignment), frame);
00150     gtk_container_set_border_width(GTK_CONTAINER(frame), 3);
00151 
00152     // alignment in frame 
00153     GtkWidget* alignment2 = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
00154     gtk_container_add(GTK_CONTAINER(frame), alignment2);
00155     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment2),
00156                               WINDOW_TOP_ALT_PADDING,
00157                               WINDOW_BOTTOM_PADDING,
00158                               WINDOW_H_PADDING,
00159                               WINDOW_H_PADDING);
00160    
00161     // vbox in alignment2
00162     GtkWidget* innervbox = gtk_vbox_new(FALSE, SMALL_SPACING);
00163     gtk_container_add(GTK_CONTAINER(alignment2), innervbox);
00164     
00165     // The margin settings section.
00166     create_flipbar_widgets(GTK_BOX(innervbox));
00167 
00168     // Update widget with current settings.
00169     init_widgets_with_settings();
00170 
00171     gtk_widget_grab_focus(view);
00172 
00173     gtk_widget_show_all(top_window);
00174     return top_window;
00175 }

Here is the call graph for this function:

Here is the caller graph for this function:

static GtkWidget* create_radio_button_item ( GtkWidget *  group,
gchar *  title,
gchar *  subtitle 
) [static]

Definition at line 261 of file flipbar.c.

References label, and SETTINGS_LABEL_MAX_WIDTH.

Referenced by create_flipbar_widgets().

00262 {
00263     GtkWidget* radio_button = NULL ;
00264     if ( group == NULL ) 
00265     {
00266         radio_button = gtk_radio_button_new(NULL); 
00267     }
00268     else {
00269         radio_button = gtk_radio_button_new_from_widget(GTK_RADIO_BUTTON(group)); 
00270 
00271     }
00272     gtk_widget_set_name(radio_button, "irex-settings-checkbutton");
00273 
00274     // alignment in radio button for some padding
00275     GtkWidget* align = gtk_alignment_new(0, 0.0, 1.0, 1.0);
00276     gtk_container_add(GTK_CONTAINER(radio_button), align);
00277     gtk_alignment_set_padding(GTK_ALIGNMENT(align)
00278                                 , 6 // top
00279                                 , 6 // bottom
00280                                 , 6 // left
00281                                 , 6 // right
00282             );
00283  
00284     // vbox in radio button
00285     GtkWidget* radiovbox = gtk_vbox_new( FALSE, 0);
00286     gtk_container_add(GTK_CONTAINER(align), radiovbox);
00287 
00288     // top level label for radio button ( no margins )
00289     GtkWidget* label = gtk_label_new( title );
00290     gtk_widget_set_name(label, "irex-radio-title");
00291     gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00292     gtk_box_pack_start(GTK_BOX(radiovbox), label, FALSE, FALSE, 0);
00293 
00294     // second level label for radio button ( descriptive test )
00295     label = gtk_label_new( subtitle  );
00296     gtk_widget_set_name(label, "irex-radio-subtitle");
00297     gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00298     gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
00299     gtk_widget_set_size_request(label, SETTINGS_LABEL_MAX_WIDTH - 40 , -1);
00300     gtk_box_pack_start(GTK_BOX(radiovbox), label, FALSE, FALSE, 0);
00301 
00302     return radio_button;
00303 }

Here is the caller graph for this function:

static void init_widgets_with_settings ( void   )  [static]

Definition at line 394 of file flipbar.c.

References g_flipbar_radios, NUM_FLIPBAR_MODES, and FlipBarSettings::pageturn_inverted.

Referenced by create_flipbar_window().

00395 {
00396     int i = 0;
00397     int to_be_activated = 0 ;
00398 
00399     if ( g_cur_flipbar_settings.pageturn_inverted == TRUE )
00400     {
00401         to_be_activated = 1;
00402     }
00403 
00404     for (i = 0; i < NUM_FLIPBAR_MODES; i++)
00405     {
00406         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(g_flipbar_radios[i]),
00407                                       (i == to_be_activated) ? TRUE : FALSE );
00408     }
00409 }

Here is the caller graph for this function:

void load_flipbar_settings (  ) 

Definition at line 239 of file flipbar.c.

References GCONF_PAGETURN_INVERTED, get_value_bool(), and FlipBarSettings::pageturn_inverted.

Referenced by create_concrete_win().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 368 of file flipbar.c.

References ERRORPRINTF, is_active, NUM_FLIPBAR_MODES, and FlipBarSettings::pageturn_inverted.

Referenced by create_flipbar_widgets().

00369 {
00370     int index = (int)data;
00371 
00372     g_assert( 0 <= index );
00373     g_assert( index < NUM_FLIPBAR_MODES );
00374 
00375     gboolean is_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
00376 
00377     if (is_active == TRUE )
00378     {
00379         switch (index)
00380         {
00381             case 0:   // NOT INVERTED
00382                 g_cur_flipbar_settings.pageturn_inverted = FALSE;
00383                 break;
00384             case 1:     // INVERTED
00385                 g_cur_flipbar_settings.pageturn_inverted = TRUE;
00386                 break;
00387             default:
00388                 ERRORPRINTF("Invalid index [%d]", index);
00389                 break;
00390         }
00391     }
00392 }

Here is the caller graph for this function:

static gboolean on_focus_in ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 218 of file flipbar.c.

References ERGTK_LIST_VIEW, and ergtk_list_view_set_cursor().

Referenced by create_flipbar_window().

00219 {
00220     g_assert(widget != NULL ) ;
00221     ergtk_list_view_set_cursor( ERGTK_LIST_VIEW(widget), 0); // row = 0;
00222     return FALSE;
00223 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean on_focus_out ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 225 of file flipbar.c.

Referenced by create_flipbar_window().

00226 {
00227     g_assert(widget != NULL ) ;
00228     GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) widget);
00229     g_assert( my_selection != NULL ) ;
00230     gtk_tree_selection_unselect_all(my_selection);
00231     return FALSE;
00232 }

Here is the caller graph for this function:

static void on_listview_navigate_cursor ( erGtkListView er_listview,
erGtkListViewKeyPress  keycode,
gpointer  user_data 
) [static]

Definition at line 195 of file flipbar.c.

References ERGTK_LIST_VIEW_PRESS_LONG_DOWN, ERGTK_LIST_VIEW_PRESS_SHORT_DOWN, g_flipbar_radios, and LOGPRINTF.

Referenced by create_flipbar_window().

00198 {
00199    GtkTreeSelection* my_selection = gtk_tree_view_get_selection((GtkTreeView*) er_listview);
00200    g_assert( my_selection != NULL ) ;
00201 
00202     // determine new cursor position
00203     switch (keycode)
00204     {
00205         case ERGTK_LIST_VIEW_PRESS_SHORT_DOWN:
00206         case ERGTK_LIST_VIEW_PRESS_LONG_DOWN:
00207             gtk_widget_grab_focus(GTK_WIDGET(g_flipbar_radios[0]));
00208             gtk_tree_selection_unselect_all(my_selection);
00209             break;
00210         default:
00211             LOGPRINTF("illegal erGtkListViewKeyPress [%d]", keycode);
00212             ;  // ignore
00213             break;
00214     }
00215 
00216 }

Here is the caller graph for this function:

static void on_listview_row_activated ( GtkTreeView *  view,
GtkTreePath *  path,
GtkTreeViewColumn *  column,
gpointer  user_data 
) [static]

Definition at line 183 of file flipbar.c.

References main_quit(), and save_flipbar_settings().

Referenced by create_flipbar_window().

00187 {
00188     
00189     save_flipbar_settings();
00190 
00191     main_quit();
00192     return;
00193 }

Here is the call graph for this function:

Here is the caller graph for this function:

void save_flipbar_settings (  ) 

Definition at line 246 of file flipbar.c.

References GCONF_PAGETURN_INVERTED, LOGPRINTF, FlipBarSettings::pageturn_inverted, and set_value_bool().

Referenced by on_listview_row_activated().

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 87 of file flipbar.c.

GtkWidget* g_flipbar_radios[NUM_FLIPBAR_MODES] [static]

Definition at line 86 of file flipbar.c.

Generated by  doxygen 1.6.2-20100208