--- sargasso2/sargasso.c 2006/09/26 21:31:28 77 +++ sargasso2/sargasso.c 2009/07/06 01:59:16 83 @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -17,7 +18,6 @@ #include #include #include "feed.h" -#include "netsurf/utils/log.h" #define MAX_LINES 20 @@ -26,6 +26,9 @@ #define FEEDS_WRITE ".Sargasso.Feeds" #define CHOICES_READ "Choices:Sargasso.Choices" #define CHOICES_WRITE ".Sargasso.Choices" +#define WRITE_DIR ".Sargasso" + +#define LOG(x) (printf(__FILE__ " %s %i: ", __PRETTY_FUNCTION__, __LINE__), printf x, fputc('\n', stdout)); typedef void (*click_callback)(unsigned int i); @@ -53,6 +56,9 @@ struct paragraph *main_window_paragraphs = 0; struct paragraph *feed_window_paragraphs = 0; unsigned int current_feed = 0; +char font_headings[100] = "Homerton"; +char font_summaries[100] = "NewHall"; +char font_links[100] = "Homerton"; #define ICON_FLAGS (wimp_ICON_TEXT | \ (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT)) @@ -70,6 +76,7 @@ { wimp_MENU_LAST, 0, ICON_FLAGS, { "Remove feed" } } } }; wimp_menu *current_menu; unsigned int current_removing = 0; +wimp_i current_font_menu; const char *default_feeds[] = { "http://news.google.co.uk/?output=rss", @@ -124,7 +131,7 @@ char error[200]; struct stat s; - memdebug_memdebug("memdump"); +/* memdebug_memdebug("memdump"); */ if (!feed_init()) die(feed_error); @@ -136,6 +143,7 @@ if (stat(FEEDS_READ, &s)) { warn("Welcome to Sargasso! A selection of feeds have been " "added. To add more feeds, use the main menu."); + mkdir(WRITE_DIR, S_IRWXU); for (unsigned int i = 0; i != sizeof default_feeds / sizeof default_feeds[0]; i++) feed_add(default_feeds[i]); @@ -175,12 +183,6 @@ { "!sargasso" } } }; os_error *error; - code = rufl_init(); - if (code != rufl_OK) { - LOG(("rufl_init: %i", code)); - die("Failed to initialise Unicode font library"); - } - error = xwimp_initialise(wimp_VERSION_RO3, "Sargasso", (const wimp_message_list *) &messages, 0, &task); if (error) { @@ -189,6 +191,12 @@ die(error->errmess); } + code = rufl_init(); + if (code != rufl_OK) { + LOG(("rufl_init: %i", code)); + die("Failed to initialise Unicode font library"); + } + error = xosfile_read_stamped_no_path(".Sprites", &obj_type, 0, 0, &size, 0, 0); if (error) { @@ -526,6 +534,22 @@ set_icon_string(choices_window, 1, minutes); xwimp_set_caret_position(choices_window, 1, 0, 0, -1, strlen(minutes)); + } else if (i == 7 || i == 8 || + i == 10 || i == 11 || + i == 13 || i == 14) { + if (i == 8 || i == 11 || i == 14) + i--; + wimp_window_state state; + wimp_icon_state icon_state; + state.w = w; + xwimp_get_window_state(&state); + icon_state.w = w; + icon_state.i = i; + xwimp_get_icon_state(&icon_state); + open_menu((wimp_menu *) rufl_family_menu, + state.visible.x0 + icon_state.icon.extent.x1, + state.visible.y1 + icon_state.icon.extent.y1); + current_font_menu = i; } } } @@ -603,12 +627,18 @@ void menu_selection(wimp_selection *selection) { char minutes[10]; + wimp_pointer pointer; + + xwimp_get_pointer_info(&pointer); if (current_menu == (wimp_menu *) &iconbar_menu) { switch (selection->items[0]) { case 1: snprintf(minutes, sizeof minutes, "%i", interval / 60); set_icon_string(choices_window, 1, minutes); + set_icon_string(choices_window, 8, font_headings); + set_icon_string(choices_window, 11, font_summaries); + set_icon_string(choices_window, 14, font_links); open_window(choices_window); xwimp_set_caret_position(choices_window, 1, 0, 0, -1, strlen(minutes)); @@ -638,7 +668,25 @@ warn(feed_error); break; } + } else if (current_menu == (wimp_menu *) rufl_family_menu) { + char *font = ((wimp_menu *) rufl_family_menu)-> + entries[selection->items[0]].data.indirected_text.text; + if (current_font_menu == 7) + strncpy(font_headings, font, sizeof font_headings); + else if (current_font_menu == 10) + strncpy(font_summaries, font, sizeof font_summaries); + else if (current_font_menu == 13) + strncpy(font_links, font, sizeof font_links); + set_icon_string(choices_window, 8, font_headings); + set_icon_string(choices_window, 11, font_summaries); + set_icon_string(choices_window, 14, font_links); + update_main_window(); + if (feed_count) + update_feed_window(current_feed); } + + if (pointer.buttons == wimp_CLICK_ADJUST) + xwimp_create_menu(current_menu, pointer.pos.x, pointer.pos.y); } @@ -747,7 +795,7 @@ p = add_paragraph(&main_window_paragraphs, 0, y, 700, 0xffaa99, 0x000000, - "Homerton", style, 200, + font_headings, style, 200, feeds[i].title ? (char *) feeds[i].title : feeds[i].url, click_main_window, i); @@ -776,7 +824,7 @@ } p = add_paragraph(&main_window_paragraphs, 700, y, 1000, 0xffaa99, 0x000000, - "Homerton", style, 200, + font_headings, style, 200, status + i * 40, click_main_window, i); y = p->y1 = y1; @@ -784,7 +832,7 @@ if (feeds[i].error) { p = add_paragraph(&main_window_paragraphs, 0, y, 1000, 0, 0x0000a0, - "NewHall", style, 200, + font_summaries, style, 200, feeds[i].error, click_main_window, i); y = p->y1; @@ -793,7 +841,7 @@ if (feeds[i].description) { p = add_paragraph(&main_window_paragraphs, 0, y, 1000, 0, 0x000000, - "NewHall", rufl_WEIGHT_400, 200, + font_summaries, rufl_WEIGHT_400, 200, feeds[i].description, click_main_window, i); y = p->y1; @@ -875,7 +923,7 @@ p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, 0xffaa99, 0x000000, - "Homerton", rufl_WEIGHT_400, 200, + font_headings, rufl_WEIGHT_400, 200, feeds[i].title ? (char *) feeds[i].title : feeds[i].url, 0, 0); y = p->y1; @@ -883,7 +931,7 @@ if (feeds[i].link) { p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, 0, 0xff0000, - "Homerton", rufl_WEIGHT_400, 160, + font_links, rufl_WEIGHT_400, 160, feeds[i].link, click_feed_link, i); y = p->y1; @@ -891,7 +939,8 @@ if (feeds[i].pub_date) { p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, 0, 0x0060ee, - "NewHall", rufl_WEIGHT_400 | rufl_SLANTED, 160, + font_summaries, rufl_WEIGHT_400 | rufl_SLANTED, + 160, feeds[i].pub_date, 0, 0); y = p->y1; @@ -899,7 +948,7 @@ if (feeds[i].description) { p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, 0, 0x000000, - "NewHall", rufl_WEIGHT_400, 200, + font_summaries, rufl_WEIGHT_400, 200, feeds[i].description, 0, 0); y = p->y1; @@ -907,7 +956,7 @@ if (feeds[i].copyright) { p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, 0, 0x666666, - "NewHall", rufl_WEIGHT_400 | rufl_SLANTED, 160, + font_summaries, rufl_WEIGHT_400 | rufl_SLANTED, 160, feeds[i].copyright, 0, 0); y = p->y1; @@ -921,7 +970,7 @@ p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, 0xa0dddd, 0x000000, - "Homerton", style, 200, + font_headings, style, 200, feeds[i].item[j].title ? (char *) feeds[i].item[j].title : "", 0, j); @@ -930,7 +979,7 @@ if (feeds[i].item[j].pub_date) { p = add_paragraph(&feed_window_paragraphs, 0, y, 420, 0, 0x0060ee, - "NewHall", + font_summaries, rufl_WEIGHT_400 | rufl_SLANTED, 160, feeds[i].item[j].pub_date, 0, j); @@ -940,7 +989,7 @@ if (feeds[i].item[j].author) { p = add_paragraph(&feed_window_paragraphs, 420, y, 720, 0, 0x666666, - "NewHall", + font_summaries, rufl_WEIGHT_400 | rufl_SLANTED, 160, feeds[i].item[j].author, 0, j); @@ -950,7 +999,7 @@ if (feeds[i].item[j].category) { p = add_paragraph(&feed_window_paragraphs, 720, y, 1000, 0, 0xee6000, - "NewHall", rufl_WEIGHT_400, 160, + font_summaries, rufl_WEIGHT_400, 160, feeds[i].item[j].category, 0, j); if (y1 < p->y1) @@ -961,7 +1010,7 @@ if (feeds[i].item[j].link) { p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, 0, 0xff0000, - "Homerton", rufl_WEIGHT_400, 160, + font_links, rufl_WEIGHT_400, 160, feeds[i].item[j].link, click_item_link, j); y = p->y1; @@ -970,7 +1019,7 @@ if (feeds[i].item[j].description) { p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, 0, 0x000000, - "NewHall", rufl_WEIGHT_400, 180, + font_summaries, rufl_WEIGHT_400, 180, feeds[i].item[j].description, 0, j); y = p->y1; @@ -1171,6 +1220,9 @@ return; } fprintf(choices, "interval: %i\n", interval); + fprintf(choices, "font_headings: %s\n", font_headings); + fprintf(choices, "font_summaries: %s\n", font_summaries); + fprintf(choices, "font_links: %s\n", font_links); fclose(choices); } @@ -1194,6 +1246,9 @@ } while (fgets(s, sizeof s, choices)) { sscanf(s, "interval: %i", &interval); + sscanf(s, "font_headings: %s", font_headings); + sscanf(s, "font_summaries: %s", font_summaries); + sscanf(s, "font_links: %s", font_links); } fclose(choices); } @@ -1285,4 +1340,3 @@ xwimp_set_icon_state(w, i, 0, 0); } -