00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026
00027
00028
00029
00030
00031
00032 #include <string.h>
00033
00034 #include <liberdm/display.h>
00035 #include <libermanifest/ermanifest.h>
00036
00037 #include "contentListerLog.h"
00038 #include "gtkContentListItem.h"
00039 #include "icons.h"
00040
00041 #include "lister.h"
00042
00043 #define MAX_CHARACTERS 52 // max characters per line
00044
00045
00046 static void gtk_content_list_item_class_init(GtkContentListItemClass * klass);
00047 static void gtk_content_list_item_init(GtkContentListItem * list_item);
00048 static int get_string_lines(const gchar * string);
00049
00050
00051 GtkWidget *gtk_content_list_item_new(index)
00052 {
00053 GtkContentListItem *listItem;
00054
00055 listItem = (GtkContentListItem *) g_object_new(GTK_CONTENT_LIST_ITEM_TYPE, NULL);
00056
00057 CL_LOGPRINTF("listItem [%p]", listItem);
00058 listItem->index = index;
00059
00060 return GTK_WIDGET(listItem);
00061 }
00062
00063
00064 GType gtk_content_list_item_get_type(void)
00065 {
00066 static GType content_list_item_type = 0;
00067
00068 if (!content_list_item_type)
00069 {
00070 static const GTypeInfo content_list_item_info = {
00071 sizeof(GtkContentListItemClass),
00072 NULL,
00073 NULL,
00074 (GClassInitFunc) gtk_content_list_item_class_init,
00075 NULL,
00076 NULL,
00077 sizeof(GtkContentListItem),
00078 0,
00079 (GInstanceInitFunc) gtk_content_list_item_init,
00080 };
00081
00082 content_list_item_type = g_type_register_static(GTK_TYPE_HBOX, "ListItem", &content_list_item_info, 0);
00083 }
00084 return content_list_item_type;
00085 }
00086
00087
00088 static void gtk_content_list_item_class_init(GtkContentListItemClass * klass)
00089 {
00090
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 static void gtk_content_list_item_init(GtkContentListItem * list_item)
00111 {
00112 GtkWidget *alignment;
00113
00114
00115 gtk_box_set_homogeneous(GTK_BOX(list_item), FALSE);
00116 gtk_box_set_spacing(GTK_BOX(list_item), HBOX_TEXT_THUMB_SPACING);
00117
00118 list_item->cursorspace = gtk_event_box_new();
00119 gtk_widget_set_name(GTK_WIDGET(list_item->cursorspace), "listCursorItem_background");
00120 gtk_widget_set_size_request(GTK_WIDGET(list_item->cursorspace), CURSOR_BOX_MIN_WIDTH, LISTER_ITEM_HEIGHT);
00121 gtk_box_pack_start(GTK_BOX(list_item), list_item->cursorspace, FALSE, FALSE, 0);
00122 list_item->cursorbox = gtk_event_box_new();
00123 gtk_widget_set_name(GTK_WIDGET(list_item->cursorbox), "listCursorItem");
00124 gtk_container_add(GTK_CONTAINER(list_item->cursorspace), list_item->cursorbox);
00125
00126 list_item->thumbbox = gtk_event_box_new();
00127 gtk_widget_set_name(GTK_WIDGET(list_item->thumbbox), "listThumbItem_background");
00128 gtk_widget_set_size_request(GTK_WIDGET(list_item->thumbbox), THUMB_BOX_MIN_WIDTH, LISTER_ITEM_HEIGHT);
00129 gtk_box_pack_start(GTK_BOX(list_item), list_item->thumbbox, FALSE, FALSE, 0);
00130
00131 list_item->textbox = gtk_event_box_new();
00132 gtk_widget_set_name(GTK_WIDGET(list_item->textbox), "listTextItem_background");
00133 gtk_widget_set_size_request(GTK_WIDGET(list_item->textbox), TEXT_BOX_MIN_WIDTH, LISTER_ITEM_HEIGHT);
00134 gtk_box_pack_start(GTK_BOX(list_item), list_item->textbox, FALSE, FALSE, 0);
00135
00136 list_item->image = gtk_image_new();
00137 gtk_container_add(GTK_CONTAINER(list_item->thumbbox), list_item->image);
00138 list_item->pixmap = NULL;
00139
00140
00141 alignment = gtk_alignment_new(0.0, 0.0, 0.0, 0.0);
00142 gtk_widget_set_size_request(GTK_WIDGET(alignment), TEXT_BOX_MIN_WIDTH, LISTER_ITEM_HEIGHT);
00143 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), VBOX_TEXT_BORDER, VBOX_TEXT_BORDER, HBOX_TEXT_BORDER, HBOX_TEXT_BORDER);
00144 gtk_container_add(GTK_CONTAINER(list_item->textbox), alignment);
00145
00146
00147
00148 list_item->table = gtk_table_new (6, 6, TRUE);
00149
00150
00151
00152 gtk_widget_set_size_request(GTK_WIDGET(list_item->table), TEXT_BOX_MIN_WIDTH, (-1));
00153 gtk_table_set_col_spacings((GtkTable *)list_item->table, 10);
00154 gtk_container_add(GTK_CONTAINER(alignment), list_item->table);
00155
00156
00157 list_item->title = gtk_label_new("");
00158 gtk_misc_set_alignment(GTK_MISC(list_item->title), 0.0, 0.0);
00159
00160
00161 gtk_widget_set_name(GTK_WIDGET(list_item->title), "list_item_title");
00162
00163 gtk_table_attach_defaults(GTK_TABLE(list_item->table), list_item->title, 0, 6, 0, 2);
00164
00165 list_item->subtitle = gtk_label_new("");
00166 gtk_misc_set_alignment(GTK_MISC(list_item->subtitle), 0.0, 0.0);
00167
00168
00169 gtk_widget_set_name(GTK_WIDGET(list_item->subtitle), "list_item_subtitle");
00170
00171 gtk_table_attach_defaults(GTK_TABLE(list_item->table), list_item->subtitle, 0, 6, 2, 3 );
00172
00173 list_item->description = gtk_label_new("");
00174 gtk_widget_set_name(GTK_WIDGET(list_item->description), "list_item_description");
00175 gtk_misc_set_alignment(GTK_MISC(list_item->description), 0.0, 0.0);
00176
00177 gtk_widget_set_size_request(GTK_WIDGET(list_item->description), TEXT_BOX_MIN_WIDTH * 4 / 5, -1 );
00178 gtk_label_set_single_line_mode(GTK_LABEL(list_item->description), FALSE);
00179 gtk_label_set_line_wrap(GTK_LABEL(list_item->description), TRUE);
00180 gtk_table_attach_defaults(GTK_TABLE(list_item->table), list_item->description, 0, 5, 3, 6);
00181
00182 list_item->information = gtk_label_new("");
00183 gtk_misc_set_alignment(GTK_MISC(list_item->information), 0.0, 0.0);
00184
00185
00186 gtk_widget_set_name(GTK_WIDGET(list_item->information), "list_item_information");
00187
00188 gtk_table_attach_defaults(GTK_TABLE(list_item->table), list_item->information, 5, 6, 3, 6);
00189
00190 gtk_widget_show_all(GTK_WIDGET(list_item));
00191 }
00192
00193 void gtk_content_list_item_set_title(GtkContentListItem * item, const gchar * text)
00194 {
00195 g_return_if_fail(IS_GTK_CONTENT_LIST_ITEM(item));
00196 g_return_if_fail(text != NULL);
00197
00198 CL_LOGPRINTF("text %s", text);
00199
00200 gtk_label_set_text(GTK_LABEL(item->title), text);
00201 }
00202
00203 void gtk_content_list_item_set_subtitle(GtkContentListItem * item, const gchar * text)
00204 {
00205 g_return_if_fail(IS_GTK_CONTENT_LIST_ITEM(item));
00206 g_return_if_fail(text != NULL);
00207
00208 CL_LOGPRINTF("text %s", text);
00209
00210 gtk_label_set_text(GTK_LABEL(item->subtitle), text);
00211 }
00212
00213 void gtk_content_list_item_set_description(GtkContentListItem * item, const gchar * text)
00214 {
00215 g_return_if_fail(IS_GTK_CONTENT_LIST_ITEM(item));
00216 g_return_if_fail(text != NULL);
00217 CL_LOGPRINTF("text %s", text);
00218
00219
00220 if (strlen(text) >= 2 * MAX_CHARACTERS || get_string_lines(text) >= 2)
00221 {
00222
00223 gtk_label_set_ellipsize(GTK_LABEL(item->description), PANGO_ELLIPSIZE_END);
00224 }
00225 else
00226 {
00227 gtk_label_set_ellipsize(GTK_LABEL(item->description), PANGO_ELLIPSIZE_NONE);
00228 }
00229 gtk_label_set_text(GTK_LABEL(item->description), text);
00230 }
00231
00232 void gtk_content_list_item_set_information(GtkContentListItem * item, const gchar * text)
00233 {
00234 g_return_if_fail(IS_GTK_CONTENT_LIST_ITEM(item));
00235 g_return_if_fail(text != NULL);
00236 CL_LOGPRINTF("text %s", text);
00237 gtk_label_set_text(GTK_LABEL(item->information), text);
00238 }
00239
00240 void gtk_content_list_item_set_thumb(GtkContentListItem * item, const char *iconURL)
00241 {
00242 GdkPixbuf *pixbuf = NULL;
00243
00244 g_return_if_fail(IS_GTK_CONTENT_LIST_ITEM(item));
00245 g_return_if_fail(NULL != iconURL);
00246
00247 pixbuf = icons_load(iconURL);
00248 if (pixbuf)
00249 {
00250
00251 if (item->pixmap)
00252 {
00253 icons_unload(item->pixmap);
00254 item->pixmap = NULL;
00255 }
00256
00257 item->pixmap = pixbuf;
00258
00259 gtk_image_set_from_pixbuf(GTK_IMAGE(item->image), pixbuf);
00260
00261 gtk_widget_show(GTK_WIDGET(item->image));
00262 }
00263 else
00264 {
00265 gtk_widget_hide(GTK_WIDGET(item->image));
00266 }
00267 return;
00268 }
00269
00270 void gtk_content_list_item_set_icon_thumb(GtkContentListItem * item, unsigned int iconID)
00271 {
00272 GdkPixbuf *pixbuf;
00273
00274 g_return_if_fail(IS_GTK_CONTENT_LIST_ITEM(item));
00275
00276 pixbuf = icons_get(iconID);
00277
00278 if (pixbuf)
00279 {
00280 gtk_image_set_from_pixbuf(GTK_IMAGE(item->image), pixbuf);
00281 gtk_widget_show(GTK_WIDGET(item->image));
00282 }
00283 else
00284 {
00285 gtk_widget_hide(GTK_WIDGET(item->image));
00286 }
00287 return;
00288 }
00289
00290 void gtk_content_list_item_hide_thumb(GtkContentListItem * item)
00291 {
00292 g_return_if_fail(IS_GTK_CONTENT_LIST_ITEM(item));
00293 gtk_widget_hide(GTK_WIDGET(item->image));
00294 }
00295
00296 void gtk_content_list_item_show_cursor(GtkContentListItem * item, gboolean show)
00297 {
00298 g_return_if_fail(IS_GTK_CONTENT_LIST_ITEM(item));
00299
00300 CL_CURSORPRINTF("entry %s", (show == TRUE) ? "TRUE" : "FALSE");
00301
00302 if (show)
00303 {
00304 gtk_widget_show(item->cursorbox);
00305 }
00306 else
00307 {
00308 gtk_widget_hide(item->cursorbox);
00309 }
00310 }
00311
00312 int get_string_lines(const gchar * string)
00313 {
00314 int count = 0;
00315 if (NULL == string)
00316 {
00317 return count;
00318 }
00319
00320 while(string && *string != 0)
00321 {
00322 string = strchr(string, '\n');
00323 if (string)
00324 {
00325 ++count; ++string; continue;
00326 }
00327 return count;
00328 }
00329 return count;
00330 }