freemyipod r526 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r525‎ | r526 | r527 >
Date:01:40, 6 February 2011
Author:theseven
Status:new
Tags:
Comment:
libUI: Add timeout to wheel chooser action handler
Modified paths:
  • /libs/ui/chooser_action_handler_wheel.c (modified) (history)
  • /libs/ui/chooser_action_handler_wheel.h (modified) (history)

Diff [purge]

Index: libs/ui/chooser_action_handler_wheel.c
@@ -32,6 +32,12 @@
3333 const struct chooser_action_handler_wheel_params* params;
3434 params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
3535 if (params->version != CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION) return -1;
 36+ data->actionhandlerdata = malloc(sizeof(struct chooser_action_handler_wheel_data));
 37+ if (!data->actionhandlerdata) return -2;
 38+ struct chooser_action_handler_wheel_data* adata;
 39+ adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
 40+ adata->timeout_remaining = params->timeout_initial;
 41+ adata->lasttick = USEC_TIMER;
3642 return 0;
3743 }
3844
@@ -41,8 +47,11 @@
4248 {
4349 const struct chooser_action_handler_wheel_params* params;
4450 params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
 51+ struct chooser_action_handler_wheel_data* adata;
 52+ adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
4553 if (params->eventfilter && params->eventfilter(data, event, which, value))
4654 return CHOOSER_RESULT_OK;
 55+ adata->timeout_remaining = params->timeout_idle;
4756 int spi = params->stepsperitem;
4857 switch (event)
4958 {
@@ -79,6 +88,28 @@
8089 return CHOOSER_RESULT_OK;
8190 }
8291
 92+static enum chooser_result chooser_action_handler_wheel_handletick(struct chooser_data* data)
 93+{
 94+ const struct chooser_action_handler_wheel_params* params;
 95+ params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
 96+ struct chooser_action_handler_wheel_data* adata;
 97+ adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
 98+ if (adata->timeout_remaining == TIMEOUT_BLOCK) return CHOOSER_RESULT_OK;
 99+ long time = USEC_TIMER;
 100+ adata->timeout_remaining -= time - adata->lasttick;
 101+ adata->lasttick = time;
 102+ if (adata->timeout_remaining < 0)
 103+ {
 104+ if (params->timeout_item == CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_NULL)
 105+ return CHOOSER_RESULT_CANCEL;
 106+ else if (params->timeout_item != CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_KEEP)
 107+ data->selected = &data->info->items[params->timeout_item];
 108+ return CHOOSER_RESULT_FINISHED;
 109+ }
 110+ if (params->tick_force_redraw) return CHOOSER_RESULT_REDRAW;
 111+ return CHOOSER_RESULT_OK;
 112+}
 113+
83114 static int chooser_action_handler_wheel_stepsperitem(struct chooser_data* data)
84115 {
85116 const struct chooser_action_handler_wheel_params* params;
@@ -86,13 +117,18 @@
87118 return params->stepsperitem;
88119 }
89120
 121+static void chooser_ction_handler_wheel_destroy(struct chooser_data* data)
 122+{
 123+ free(data->actionhandlerdata);
 124+}
90125
 126+
91127 const struct chooser_action_handler chooser_action_handler_wheel =
92128 {
93129 .version = CHOOSER_ACTION_HANDLER_VERSION,
94130 .init = chooser_action_handler_wheel_init,
95131 .handleevent = chooser_action_handler_wheel_handleevent,
96 - .handletick = NULL,
 132+ .handletick = chooser_action_handler_wheel_handletick,
97133 .stepsperitem = chooser_action_handler_wheel_stepsperitem,
98 - .destroy = NULL
 134+ .destroy = chooser_ction_handler_wheel_destroy
99135 };
Index: libs/ui/chooser_action_handler_wheel.h
@@ -38,6 +38,9 @@
3939 CHOOSER_ACTION_HANDLER_WHEEL_ACTION_CANCEL
4040 };
4141
 42+#define CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_NULL -1
 43+#define CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_KEEP -2
 44+
4245 #define CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION 1
4346
4447 struct chooser_action_handler_wheel_params
@@ -45,11 +48,21 @@
4649 int version;
4750 int stepsperitem;
4851 bool (*eventfilter)(struct chooser_data* data, enum button_event event, int which, int value);
 52+ long timeout_initial;
 53+ long timeout_idle;
 54+ int timeout_item;
 55+ bool tick_force_redraw;
4956 int buttoncount;
5057 enum chooser_action_handler_wheel_action buttonmap[];
5158 };
5259
 60+struct chooser_action_handler_wheel_data
 61+{
 62+ long timeout_remaining;
 63+ long lasttick;
 64+};
5365
 66+
5467 extern const struct chooser_action_handler chooser_action_handler_wheel;
5568
5669