#include <gtk/gtk.h>
Go to the source code of this file.
Classes | |
struct | cmMetadata_t |
Defines | |
#define | METADATA_BK_IMG_WIDTH 666 |
#define | METADATA_BK_IMG_HEIGHT 345 |
#define | METADATA_WND_SPACE_ABOVE 50 |
#define | METADATA_WND_ITEM_SPACING 8 |
#define | METADATA_VBORDER 10 |
#define | METADATA_HBORDER 20 |
#define | METADATA_ENTRY_WIDTH (METADATA_BK_IMG_WIDTH - 2*METADATA_HBORDER) |
#define | METADATA_TAG_HEIGHT 40 |
#define | METADATA_NAME_HEIGHT 30 |
#define | METADATA_DESC_HEIGHT 30 |
#define | MD_MAX_TITLE_SIZE 256 |
#define | MD_MAX_SUBTITLE_SIZE 256 |
#define | MD_MAX_DESCRIPTION_SIZE 512 |
Functions | |
GtkWidget * | create_content_metadata_wnd (GtkWidget *parent) |
void | content_metadata_set_text (void) |
gboolean | content_metadata_read_manifest (const gchar *szManifest) |
gboolean | content_metadata_rename_container (const gchar *szManifest, gchar *szContainer, gint len) |
gboolean | content_metadata_write_manifest (const gchar *szContainer) |
<File description>=""> The eReader content customization window provides gtk widget to enable user customize content title and description. Which are created and updated with the following API
Definition in file gtkMetadataWnd.h.
#define MD_MAX_DESCRIPTION_SIZE 512 |
Definition at line 57 of file gtkMetadataWnd.h.
#define MD_MAX_SUBTITLE_SIZE 256 |
Definition at line 56 of file gtkMetadataWnd.h.
#define MD_MAX_TITLE_SIZE 256 |
Definition at line 55 of file gtkMetadataWnd.h.
#define METADATA_BK_IMG_HEIGHT 345 |
Definition at line 41 of file gtkMetadataWnd.h.
#define METADATA_BK_IMG_WIDTH 666 |
Definition at line 40 of file gtkMetadataWnd.h.
#define METADATA_DESC_HEIGHT 30 |
Definition at line 52 of file gtkMetadataWnd.h.
#define METADATA_ENTRY_WIDTH (METADATA_BK_IMG_WIDTH - 2*METADATA_HBORDER) |
Definition at line 48 of file gtkMetadataWnd.h.
#define METADATA_HBORDER 20 |
Definition at line 47 of file gtkMetadataWnd.h.
#define METADATA_NAME_HEIGHT 30 |
Definition at line 51 of file gtkMetadataWnd.h.
#define METADATA_TAG_HEIGHT 40 |
Definition at line 50 of file gtkMetadataWnd.h.
#define METADATA_VBORDER 10 |
Definition at line 46 of file gtkMetadataWnd.h.
#define METADATA_WND_ITEM_SPACING 8 |
Definition at line 44 of file gtkMetadataWnd.h.
#define METADATA_WND_SPACE_ABOVE 50 |
Definition at line 43 of file gtkMetadataWnd.h.
gboolean content_metadata_read_manifest | ( | const gchar * | szManifest | ) |
read manifest file into content data
pathname | of the manifest file |
Definition at line 410 of file gtkMetadataWnd.c.
00411 { 00412 CL_LOGPRINTF("entry"); 00413 00414 g_assert(szManifest != NULL); 00415 00416 int ret; 00417 gchar szTitle[MD_MAX_TITLE_SIZE]; 00418 gchar szDescription[MD_MAX_DESCRIPTION_SIZE]; 00419 00420 // open manifest file 00421 erManifest manifest; 00422 if (RET_OK != ermXmlOpenFile(szManifest, &manifest)) 00423 { 00424 CL_ERRORPRINTF("Could not open manifest file [%s]", szManifest); 00425 return FALSE; 00426 } 00427 00428 // get title 00429 ret = ermXmlGetString(&manifest, "/package/metadata/dc-metadata/Title", szTitle, sizeof(szTitle)); 00430 if (ret != RET_OK) 00431 { 00432 strcpy(szTitle, ""); 00433 } 00434 gtk_entry_set_text(GTK_ENTRY(g_wnd.nameEntry), szTitle); 00435 00436 // get description 00437 ret = ermXmlGetString(&manifest, "/package/metadata/dc-metadata/Description", szDescription, sizeof(szDescription)); 00438 if (ret != RET_OK) 00439 { 00440 strcpy(szDescription, ""); 00441 } 00442 /**** 00443 * Problems with multi-line text editor, see createDescEntry(); 00444 * 00445 GtkTextBuffer* buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_wnd.descEntry)); 00446 gtk_text_buffer_set_text(buffer, szDescription, -1); 00447 ****/ 00448 char* cp = strchr(szDescription, '\n'); 00449 if (cp) 00450 { 00451 *cp = '\0'; 00452 gtk_entry_set_text(GTK_ENTRY(g_wnd.descEntry2), cp + 1); 00453 } 00454 else 00455 { 00456 gtk_entry_set_text(GTK_ENTRY(g_wnd.descEntry2), ""); 00457 } 00458 gtk_entry_set_text(GTK_ENTRY(g_wnd.descEntry), szDescription); 00459 00460 // close manifest file 00461 ermXmlClose(&manifest); 00462 return TRUE; 00463 }
gboolean content_metadata_rename_container | ( | const gchar * | szManifest, | |
gchar * | szContainer, | |||
gint | len | |||
) |
rename container when needed, depending on current title
in | szManifest pathname of manifest file | |
out | szContainer pathname of container directory | |
in | len size in bytes of szContainer buffer |
Definition at line 466 of file gtkMetadataWnd.c.
00467 { 00468 CL_LOGPRINTF("entry: manifest [%s]", szManifest); 00469 00470 g_return_val_if_fail((szManifest != NULL), FALSE); 00471 00472 gboolean retval = FALSE; 00473 00474 00475 // retrieve container path 00476 char* cp = strrchr(szManifest, '/'); 00477 if (cp) 00478 { 00479 *cp = '\0'; 00480 snprintf(szContainer, len, "%s", szManifest); 00481 *cp = '/'; 00482 } 00483 else 00484 { 00485 CL_ERRORPRINTF("Illegal manifest path [%s]", szManifest); 00486 } 00487 00488 // retrieve container name 00489 char* szContainerName = strrchr(szContainer, '/'); 00490 if (szContainerName) 00491 { 00492 szContainerName++; 00493 } 00494 else 00495 { 00496 CL_ERRORPRINTF("Illegal container path [%s]", szContainer); 00497 } 00498 00499 // retrieve title from screen object 00500 const char* szTitle = gtk_entry_get_text(GTK_ENTRY(g_wnd.nameEntry)); 00501 00502 // set container name to (modified) title 00503 if ( strlen(szTitle) > 0 00504 && strcmp(szTitle, szContainerName) != 0 ) 00505 { 00506 // container name is different from title: rename container 00507 00508 // determine new container name 00509 int n = strlen(szContainer) - strlen(szContainerName); 00510 char* newContainer = alloca(n + strlen(szTitle) + 1); 00511 g_return_val_if_fail((newContainer != NULL), FALSE); 00512 strncpy(newContainer, szContainer, n); 00513 strcpy(&newContainer[n], szTitle); 00514 CL_LOGPRINTF("New container name [%s]", newContainer); 00515 00516 // rename container, but only when newName does not exist 00517 struct stat statbuf; 00518 if ( stat(newContainer, &statbuf) == -1 00519 && rename(szContainer, newContainer) == 0 ) 00520 { 00521 CL_LOGPRINTF("Renamed container ok"); 00522 snprintf(szContainer, len, "%s", newContainer); 00523 retval = TRUE; 00524 } 00525 else 00526 { 00527 CL_ERRORPRINTF("Cannot rename container [%s]", strerror(errno)); 00528 00529 // rename failed: force title to container name 00530 gtk_entry_set_text(GTK_ENTRY(g_wnd.nameEntry), szContainerName); 00531 } 00532 } 00533 00534 return retval; 00535 }
void content_metadata_set_text | ( | void | ) |
Set constant texts for metedata editor window
Definition at line 394 of file gtkMetadataWnd.c.
00395 { 00396 CL_LOGPRINTF("entry"); 00397 00398 // name item 00399 gtk_label_set_text( GTK_LABEL(g_wnd.nameTag), _("Step 1: Please enter a name for the content") ); 00400 00401 // desc item 00402 gtk_label_set_text( GTK_LABEL(g_wnd.descTag), _("Step 2: Enter a description by which you can identify the content") ); 00403 00404 // finish item 00405 gtk_label_set_text( GTK_LABEL(g_wnd.finishTag), _("Step 3: Click on the 'Tagging' icon to save your changes") ); 00406 }
gboolean content_metadata_write_manifest | ( | const gchar * | szContainer | ) |
update the content metadata according to input parameter
pathname | of container directory |
Definition at line 538 of file gtkMetadataWnd.c.
00539 { 00540 CL_LOGPRINTF("entry: manifest [%s]", szContainer); 00541 00542 g_return_val_if_fail((szContainer != NULL), FALSE); 00543 00544 gboolean retval = FALSE; 00545 00546 00547 // retrieve title from screen object 00548 const char* szTitle = gtk_entry_get_text(GTK_ENTRY(g_wnd.nameEntry)); 00549 00550 // retrieve description from screen object 00551 /**** 00552 * Problems with multi-line text editor, see createDescEntry(); 00553 * 00554 GtkTextBuffer * buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_wnd.descEntry)); 00555 GtkTextIter start, end; 00556 gtk_text_buffer_get_bounds(buffer, &start, &end); 00557 char* szDescription = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); 00558 ****/ 00559 const char* szDescription = gtk_entry_get_text(GTK_ENTRY(g_wnd.descEntry)); 00560 const char* szDescription2 = gtk_entry_get_text(GTK_ENTRY(g_wnd.descEntry2)); 00561 if (szDescription2 != NULL && szDescription2[0] != '\0') 00562 { 00563 char* cp = alloca( strlen(szDescription) + strlen(szDescription2) + 2 ); 00564 if (cp) 00565 { 00566 sprintf(cp, "%s\n%s", szDescription, szDescription2); 00567 szDescription = cp; 00568 } 00569 } 00570 00571 // open manifest file and update it 00572 erManifest manifest; 00573 if (RET_OK == ermXmlOpenManifest(szContainer, &manifest)) 00574 { 00575 // update title 00576 if (RET_OK == ermXmlExist(&manifest, "/package/metadata/dc-metadata/Title")) 00577 { 00578 ermXmlSetString( &manifest, 00579 "/package/metadata/dc-metadata/Title", 00580 szTitle ); 00581 } 00582 else 00583 { 00584 ermXmlNewString( &manifest, 00585 "/package/metadata/dc-metadata", 00586 "Title", 00587 szTitle ); 00588 } 00589 00590 // update description 00591 if (RET_OK == ermXmlExist(&manifest, "/package/metadata/dc-metadata/Description")) 00592 { 00593 ermXmlSetString( &manifest, 00594 "/package/metadata/dc-metadata/Description", 00595 szDescription ); 00596 } 00597 else 00598 { 00599 ermXmlNewString( &manifest, 00600 "/package/metadata/dc-metadata", 00601 "Description", 00602 szDescription ); 00603 } 00604 00605 // save manifest 00606 ermXmlSaveAndClose(&manifest); 00607 00608 retval = TRUE; 00609 } 00610 else 00611 { 00612 CL_ERRORPRINTF("Could not open manifest file in [%s]", szContainer); 00613 } 00614 00615 return retval; 00616 }
GtkWidget* create_content_metadata_wnd | ( | GtkWidget * | parent | ) |
Create content metadata editor window
data | - |
Definition at line 344 of file gtkMetadataWnd.c.
00345 { 00346 CL_LOGPRINTF("entry"); 00347 00348 // main window 00349 g_wnd.window = parent; 00350 // g_signal_connect(G_OBJECT(g_wnd.window), "focus-in-event", G_CALLBACK(on_main_wnd_focus_in), wnd); 00351 // g_signal_connect(G_OBJECT(g_wnd.window), "key_press_event", G_CALLBACK(on_keypress), wnd); 00352 g_signal_connect(G_OBJECT(g_wnd.window), "expose-event", G_CALLBACK(on_expose), NULL); 00353 00354 // background 00355 GtkWidget* background = gtk_event_box_new(); 00356 gtk_widget_set_name(GTK_WIDGET(background), "content_wnd_background"); 00357 gtk_widget_set_size_request(GTK_WIDGET(background), METADATA_BK_IMG_WIDTH, METADATA_BK_IMG_HEIGHT); 00358 gtk_container_add(GTK_CONTAINER(parent), background); 00359 gtk_widget_show(background); 00360 00361 // alignment 00362 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 0.0, 0.0); 00363 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), METADATA_VBORDER, METADATA_VBORDER, METADATA_HBORDER, METADATA_HBORDER); 00364 gtk_container_add(GTK_CONTAINER(background), alignment); 00365 gtk_widget_show(alignment); 00366 00367 // vbox 00368 GtkWidget* vbox = gtk_vbox_new(FALSE, METADATA_WND_ITEM_SPACING); 00369 gtk_container_add(GTK_CONTAINER(alignment), vbox); 00370 gtk_widget_show(vbox); 00371 00372 // name item 00373 createNameItem(vbox); 00374 00375 // desc item 00376 createDescItem(vbox); 00377 00378 // finish item 00379 createFinishItem(vbox); 00380 00381 // set screen texts 00382 content_metadata_set_text(); 00383 00384 // instance-private data 00385 g_wnd.on_change_occurred = FALSE; 00386 g_wnd.on_movecursor_occurred = FALSE; 00387 g_wnd.display_update_pending = FALSE; 00388 00389 return background; 00390 }