00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <config.h>
00036
00037 #include <stdio.h>
00038 #include <string.h>
00039 #include <sys/types.h>
00040
00041 #include <gtk/gtk.h>
00042
00043 #include <libermanifest/ermanifest.h>
00044 #include <liberdm/display.h>
00045
00046 #include "contentListerLog.h"
00047 #include "gtkContentListItem.h"
00048 #include "erConnect.h"
00049 #include "system.h"
00050 #include "gtkPincodeScreen.h"
00051 #include "control.h"
00052 #include "displayUpdate.h"
00053 #include "icons.h"
00054 #include "programManager.h"
00055 #include "languages.h"
00056
00057 #define MAX_INT_LEN 50 // integer string buffer length
00058
00059 static lsLister_t g_lister;
00060
00061
00062 static void ls_listItem_press_event(GtkWidget * widget, GdkEventButton * event, gpointer user_data);
00063
00064
00065 static gboolean ls_lister_expose_event(GtkWidget * widget, GdkEventExpose * event, ContentLister * theContentLister);
00066
00067 static void formatSize(const int bytes, char * str, const int length);
00068 static void formatFree(const int kbytes, char * str, const int length);
00069
00070
00071 lsLister_t *lsInit(GtkWidget * topLevelWidget, gpointer data)
00072 {
00073 GtkWidget *alignment;
00074 GtkWidget *listVBox;
00075 GtkWidget *listItem;
00076 GtkWidget *titleBackground;
00077 GtkWidget *titleContainer;
00078
00079 int index;
00080
00081
00082
00083
00084
00085 listVBox = gtk_vbox_new(FALSE, LIST_ITEM_SPACING);
00086 gtk_container_add(GTK_CONTAINER(topLevelWidget), listVBox);
00087 gtk_widget_show(listVBox);
00088
00089
00090
00091
00092 alignment = gtk_alignment_new(0, 0, 0, 0);
00093 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, LISTER_BOX_BORDER, 0);
00094 gtk_box_pack_start(GTK_BOX(listVBox), alignment, FALSE, FALSE, 0);
00095 gtk_widget_show(alignment);
00096
00097 titleBackground = gtk_event_box_new();
00098 gtk_widget_set_size_request(GTK_WIDGET(titleBackground), TITLE_MIN_WIDTH, TITLE_MIN_HEIGHT);
00099 gtk_widget_set_name(GTK_WIDGET(titleBackground), "title_background");
00100 gtk_container_add(GTK_CONTAINER(alignment), titleBackground);
00101 g_signal_connect(G_OBJECT(titleBackground), "expose-event", G_CALLBACK(ls_lister_expose_event), NULL);
00102 gtk_widget_show(titleBackground);
00103
00104
00105
00106
00107
00108 titleContainer = gtk_hbox_new(FALSE, 10);
00109 gtk_widget_set_size_request(GTK_WIDGET(titleContainer), TITLE_MIN_WIDTH, TITLE_MIN_HEIGHT);
00110 gtk_container_add(GTK_CONTAINER(titleBackground), titleContainer);
00111 gtk_widget_show(titleContainer);
00112
00113 g_lister.titleItem = gtk_label_new("");
00114 gtk_misc_set_alignment(GTK_MISC(g_lister.titleItem), 0, 0.5);
00115 gtk_widget_set_name(GTK_WIDGET(g_lister.titleItem), "title_item");
00116 gtk_box_pack_start (GTK_BOX (titleContainer), g_lister.titleItem, FALSE, FALSE, 10);
00117 gtk_widget_show(g_lister.titleItem);
00118
00119 g_lister.titleLocation = gtk_label_new("");
00120 gtk_misc_set_alignment(GTK_MISC(g_lister.titleLocation), 1.0, 0.5);
00121 gtk_label_set_ellipsize(GTK_LABEL(g_lister.titleLocation), PANGO_ELLIPSIZE_START);
00122 gtk_widget_set_name(GTK_WIDGET(g_lister.titleLocation), "title_location");
00123 gtk_box_pack_start (GTK_BOX (titleContainer), g_lister.titleLocation, TRUE, TRUE, 10);
00124 gtk_widget_show(g_lister.titleLocation);
00125
00126
00127
00128
00129
00130 for (index = 0; index < MAX_ITEMS_ON_ONE_PAGE; index++)
00131 {
00132 listItem = gtk_content_list_item_new(index);
00133 gtk_content_list_item_show_cursor(GTK_CONTENT_LIST_ITEM(listItem), FALSE);
00134 gtk_box_pack_start(GTK_BOX(listVBox), listItem, FALSE, FALSE, 0);
00135 g_signal_connect(G_OBJECT(listItem), "button_press_event", G_CALLBACK(ls_listItem_press_event), data);
00136
00137 g_lister.listItems[index] = listItem;
00138 }
00139
00140 return &g_lister;
00141 }
00142
00143 GtkWidget * lsGetListerItem(lsLister_t * lister, int index)
00144 {
00145 g_assert(lister != NULL);
00146 g_assert(index >= 0 && index < MAX_ITEMS_ON_ONE_PAGE);
00147
00148 return lister->listItems[index];
00149 }
00150
00151
00152 void lsUpdatePage(lsLister_t * lister, clDisplayItem_t * items,
00153 int count, int focus, gchar * title, const gchar *path)
00154 {
00155 int index = 0;
00156 GtkWidget *listerItem;
00157 char *location;
00158 char str[MAX_INT_LEN];
00159
00160
00161 if (title)
00162 {
00163 CL_LISTERPRINTF("set title %s", title);
00164 gtk_label_set_text(GTK_LABEL(lister->titleItem), title);
00165 }
00166 else
00167 {
00168 gtk_label_set_text(GTK_LABEL(lister->titleItem), "");
00169 }
00170
00171 if (path)
00172 {
00173
00174 gtk_label_set_text(GTK_LABEL(lister->titleLocation), path);
00175 }
00176 else
00177 {
00178 gtk_label_set_text(GTK_LABEL(lister->titleLocation), "");
00179 }
00180
00181
00182
00183 for (index = 0 ; index < MAX_ITEMS_ON_ONE_PAGE ; index++)
00184 {
00185 listerItem = lister->listItems[index];
00186
00187 if (index < count)
00188 {
00189
00190 CL_LISTERPRINTF("update and display listerItem %p - index %d", listerItem, index);
00191 gtk_content_list_item_set_title(GTK_CONTENT_LIST_ITEM(listerItem), items[index].szTitle);
00192 gtk_content_list_item_set_subtitle(GTK_CONTENT_LIST_ITEM(listerItem), items[index].szSubTitle);
00193 gtk_content_list_item_set_description(GTK_CONTENT_LIST_ITEM(listerItem), items[index].szDescription);
00194
00195 str[0] = '\0';
00196 if (ERCL_INVALID_SIZE != items[index].size)
00197 {
00198 if (items[index].fit == mdsFitStorage)
00199 {
00200 formatFree(items[index].size, str, MAX_INT_LEN);
00201 }
00202 else
00203 {
00204 formatSize(items[index].size, str, MAX_INT_LEN);
00205 }
00206 }
00207 gtk_content_list_item_set_information(GTK_CONTENT_LIST_ITEM(listerItem), str);
00208
00209
00210 if (ctrl_location_is_outbox(path))
00211 {
00212 CL_LISTERPRINTF("clIconOutboxItem");
00213 gtk_content_list_item_set_icon_thumb(GTK_CONTENT_LIST_ITEM(listerItem), clOutboxIcon);
00214 }
00215 else if (items[index].iconID == clIconUrlDefined)
00216 {
00217 CL_LISTERPRINTF("clIconUrlDefined");
00218 gtk_content_list_item_set_thumb(GTK_CONTENT_LIST_ITEM(listerItem), items[index].clIconURL);
00219 }
00220 else if ( (items[index].iconID == clUnknownIcon)
00221 && ((location = pm_getIcon(items[index].szFileExt)) != NULL) )
00222 {
00223 CL_LISTERPRINTF("known extension => location");
00224 gtk_content_list_item_set_thumb(GTK_CONTENT_LIST_ITEM(listerItem), location);
00225 }
00226 else
00227 {
00228 gtk_content_list_item_set_icon_thumb(GTK_CONTENT_LIST_ITEM(listerItem), items[index].iconID);
00229 }
00230
00231
00232 if (index == focus)
00233 {
00234 CL_LISTERPRINTF("focus widget %d", focus);
00235
00236 gtk_content_list_item_show_cursor(GTK_CONTENT_LIST_ITEM(listerItem), TRUE);
00237 }
00238 else
00239 {
00240 gtk_content_list_item_show_cursor(GTK_CONTENT_LIST_ITEM(listerItem), FALSE);
00241 }
00242
00243 gtk_widget_show(listerItem);
00244 }
00245 else
00246 {
00247 CL_LISTERPRINTF("hide and clear listerItem %p - index %d", listerItem, index);
00248 gtk_content_list_item_set_title(GTK_CONTENT_LIST_ITEM(listerItem), "");
00249 gtk_content_list_item_set_subtitle(GTK_CONTENT_LIST_ITEM(listerItem), "");
00250 gtk_content_list_item_set_description(GTK_CONTENT_LIST_ITEM(listerItem), "");
00251 gtk_content_list_item_set_information(GTK_CONTENT_LIST_ITEM(listerItem), "");
00252 gtk_content_list_item_hide_thumb(GTK_CONTENT_LIST_ITEM(listerItem));
00253
00254 gtk_widget_hide(listerItem);
00255 }
00256 }
00257
00258 CL_SCREENPRINTF("");
00259 display_update_increase_level(LISTER_EXPOSE_LEVEL);
00260 }
00261
00262
00263 void ls_listItem_press_event(GtkWidget * widget, GdkEventButton * event, gpointer data)
00264 {
00265 GtkContentListItem *listItem = (GtkContentListItem *) widget;
00266
00267 CL_LISTERPRINTF("index %d", listItem->index);
00268
00269 ctrl_listItem_clicked(listItem->index, data);
00270 }
00271
00272
00273 gboolean ls_lister_expose_event(GtkWidget * widget, GdkEventExpose * event, ContentLister * theContentLister)
00274 {
00275 CL_SCREENPRINTF("entry");
00276 display_update_request_screen_refresh(LISTER_EXPOSE_LEVEL);
00277 return FALSE;
00278 }
00279
00280
00281 void formatSize(const int bytes, char * str, const int length)
00282 {
00283 const int MB = 1024 * 1024;
00284 const int KB = 1024;
00285 const char *title = _("Size");
00286
00287 int ret = 0;
00288 if (bytes >= MB)
00289 {
00290 ret = bytes / MB;
00291 snprintf(str, length, "%s:\n%d.%d %s", title, ret, (bytes - ret * MB) * 10 / MB, _("MB"));
00292 }
00293 else if (bytes >= KB)
00294 {
00295 ret = bytes / KB;
00296 snprintf(str, length, "%s:\n%d.%d %s", title, ret, (bytes - ret * KB) * 10 / KB, _("KB"));
00297 }
00298 else
00299 {
00300 snprintf(str, length, "%s:\n%d %s", title, bytes, _("Bytes"));
00301 }
00302 }
00303
00304
00305 void formatFree(const int kbytes, char * str, const int length)
00306 {
00307 const int KB = 1024;
00308 const char *title = _("Free");
00309
00310 int ret = kbytes / KB;
00311 snprintf(str, length, "%s:\n%d %s", title, ret, _("MB"));
00312 }
00313