| 10 |
#include <stdio.h> |
#include <stdio.h> |
| 11 |
#include <string.h> |
#include <string.h> |
| 12 |
#include <sys/stat.h> |
#include <sys/stat.h> |
| 13 |
|
#include <sys/types.h> |
| 14 |
#include <oslib/colourtrans.h> |
#include <oslib/colourtrans.h> |
| 15 |
#include <oslib/osfile.h> |
#include <oslib/osfile.h> |
| 16 |
#include <oslib/uri.h> |
#include <oslib/uri.h> |
| 18 |
#include <oslib/wimpspriteop.h> |
#include <oslib/wimpspriteop.h> |
| 19 |
#include <rufl.h> |
#include <rufl.h> |
| 20 |
#include "feed.h" |
#include "feed.h" |
|
#include "netsurf/utils/log.h" |
|
| 21 |
|
|
| 22 |
|
|
| 23 |
#define MAX_LINES 20 |
#define MAX_LINES 20 |
| 26 |
#define FEEDS_WRITE "<Choices$Write>.Sargasso.Feeds" |
#define FEEDS_WRITE "<Choices$Write>.Sargasso.Feeds" |
| 27 |
#define CHOICES_READ "Choices:Sargasso.Choices" |
#define CHOICES_READ "Choices:Sargasso.Choices" |
| 28 |
#define CHOICES_WRITE "<Choices$Write>.Sargasso.Choices" |
#define CHOICES_WRITE "<Choices$Write>.Sargasso.Choices" |
| 29 |
|
#define WRITE_DIR "<Choices$Write>.Sargasso" |
| 30 |
|
|
| 31 |
|
#define LOG(x) (printf(__FILE__ " %s %i: ", __PRETTY_FUNCTION__, __LINE__), printf x, fputc('\n', stdout)); |
| 32 |
|
|
| 33 |
typedef void (*click_callback)(unsigned int i); |
typedef void (*click_callback)(unsigned int i); |
| 34 |
|
|
| 56 |
struct paragraph *main_window_paragraphs = 0; |
struct paragraph *main_window_paragraphs = 0; |
| 57 |
struct paragraph *feed_window_paragraphs = 0; |
struct paragraph *feed_window_paragraphs = 0; |
| 58 |
unsigned int current_feed = 0; |
unsigned int current_feed = 0; |
| 59 |
|
char font_headings[100] = "Homerton"; |
| 60 |
|
char font_summaries[100] = "NewHall"; |
| 61 |
|
char font_links[100] = "Homerton"; |
| 62 |
|
|
| 63 |
#define ICON_FLAGS (wimp_ICON_TEXT | \ |
#define ICON_FLAGS (wimp_ICON_TEXT | \ |
| 64 |
(wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT)) |
(wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT)) |
| 76 |
{ wimp_MENU_LAST, 0, ICON_FLAGS, { "Remove feed" } } } }; |
{ wimp_MENU_LAST, 0, ICON_FLAGS, { "Remove feed" } } } }; |
| 77 |
wimp_menu *current_menu; |
wimp_menu *current_menu; |
| 78 |
unsigned int current_removing = 0; |
unsigned int current_removing = 0; |
| 79 |
|
wimp_i current_font_menu; |
| 80 |
|
|
| 81 |
const char *default_feeds[] = { |
const char *default_feeds[] = { |
| 82 |
"http://news.google.co.uk/?output=rss", |
"http://news.google.co.uk/?output=rss", |
| 131 |
char error[200]; |
char error[200]; |
| 132 |
struct stat s; |
struct stat s; |
| 133 |
|
|
| 134 |
memdebug_memdebug("memdump"); |
/* memdebug_memdebug("memdump"); */ |
| 135 |
|
|
| 136 |
if (!feed_init()) |
if (!feed_init()) |
| 137 |
die(feed_error); |
die(feed_error); |
| 143 |
if (stat(FEEDS_READ, &s)) { |
if (stat(FEEDS_READ, &s)) { |
| 144 |
warn("Welcome to Sargasso! A selection of feeds have been " |
warn("Welcome to Sargasso! A selection of feeds have been " |
| 145 |
"added. To add more feeds, use the main menu."); |
"added. To add more feeds, use the main menu."); |
| 146 |
|
mkdir(WRITE_DIR, S_IRWXU); |
| 147 |
for (unsigned int i = 0; i != sizeof default_feeds / |
for (unsigned int i = 0; i != sizeof default_feeds / |
| 148 |
sizeof default_feeds[0]; i++) |
sizeof default_feeds[0]; i++) |
| 149 |
feed_add(default_feeds[i]); |
feed_add(default_feeds[i]); |
| 183 |
{ "!sargasso" } } }; |
{ "!sargasso" } } }; |
| 184 |
os_error *error; |
os_error *error; |
| 185 |
|
|
|
code = rufl_init(); |
|
|
if (code != rufl_OK) { |
|
|
LOG(("rufl_init: %i", code)); |
|
|
die("Failed to initialise Unicode font library"); |
|
|
} |
|
|
|
|
| 186 |
error = xwimp_initialise(wimp_VERSION_RO3, "Sargasso", |
error = xwimp_initialise(wimp_VERSION_RO3, "Sargasso", |
| 187 |
(const wimp_message_list *) &messages, 0, &task); |
(const wimp_message_list *) &messages, 0, &task); |
| 188 |
if (error) { |
if (error) { |
| 191 |
die(error->errmess); |
die(error->errmess); |
| 192 |
} |
} |
| 193 |
|
|
| 194 |
|
code = rufl_init(); |
| 195 |
|
if (code != rufl_OK) { |
| 196 |
|
LOG(("rufl_init: %i", code)); |
| 197 |
|
die("Failed to initialise Unicode font library"); |
| 198 |
|
} |
| 199 |
|
|
| 200 |
error = xosfile_read_stamped_no_path("<Sargasso$Dir>.Sprites", |
error = xosfile_read_stamped_no_path("<Sargasso$Dir>.Sprites", |
| 201 |
&obj_type, 0, 0, &size, 0, 0); |
&obj_type, 0, 0, &size, 0, 0); |
| 202 |
if (error) { |
if (error) { |
| 534 |
set_icon_string(choices_window, 1, minutes); |
set_icon_string(choices_window, 1, minutes); |
| 535 |
xwimp_set_caret_position(choices_window, 1, |
xwimp_set_caret_position(choices_window, 1, |
| 536 |
0, 0, -1, strlen(minutes)); |
0, 0, -1, strlen(minutes)); |
| 537 |
|
} else if (i == 7 || i == 8 || |
| 538 |
|
i == 10 || i == 11 || |
| 539 |
|
i == 13 || i == 14) { |
| 540 |
|
if (i == 8 || i == 11 || i == 14) |
| 541 |
|
i--; |
| 542 |
|
wimp_window_state state; |
| 543 |
|
wimp_icon_state icon_state; |
| 544 |
|
state.w = w; |
| 545 |
|
xwimp_get_window_state(&state); |
| 546 |
|
icon_state.w = w; |
| 547 |
|
icon_state.i = i; |
| 548 |
|
xwimp_get_icon_state(&icon_state); |
| 549 |
|
open_menu((wimp_menu *) rufl_family_menu, |
| 550 |
|
state.visible.x0 + icon_state.icon.extent.x1, |
| 551 |
|
state.visible.y1 + icon_state.icon.extent.y1); |
| 552 |
|
current_font_menu = i; |
| 553 |
} |
} |
| 554 |
} |
} |
| 555 |
} |
} |
| 627 |
void menu_selection(wimp_selection *selection) |
void menu_selection(wimp_selection *selection) |
| 628 |
{ |
{ |
| 629 |
char minutes[10]; |
char minutes[10]; |
| 630 |
|
wimp_pointer pointer; |
| 631 |
|
|
| 632 |
|
xwimp_get_pointer_info(&pointer); |
| 633 |
|
|
| 634 |
if (current_menu == (wimp_menu *) &iconbar_menu) { |
if (current_menu == (wimp_menu *) &iconbar_menu) { |
| 635 |
switch (selection->items[0]) { |
switch (selection->items[0]) { |
| 636 |
case 1: |
case 1: |
| 637 |
snprintf(minutes, sizeof minutes, "%i", interval / 60); |
snprintf(minutes, sizeof minutes, "%i", interval / 60); |
| 638 |
set_icon_string(choices_window, 1, minutes); |
set_icon_string(choices_window, 1, minutes); |
| 639 |
|
set_icon_string(choices_window, 8, font_headings); |
| 640 |
|
set_icon_string(choices_window, 11, font_summaries); |
| 641 |
|
set_icon_string(choices_window, 14, font_links); |
| 642 |
open_window(choices_window); |
open_window(choices_window); |
| 643 |
xwimp_set_caret_position(choices_window, 1, |
xwimp_set_caret_position(choices_window, 1, |
| 644 |
0, 0, -1, strlen(minutes)); |
0, 0, -1, strlen(minutes)); |
| 668 |
warn(feed_error); |
warn(feed_error); |
| 669 |
break; |
break; |
| 670 |
} |
} |
| 671 |
|
} else if (current_menu == (wimp_menu *) rufl_family_menu) { |
| 672 |
|
char *font = ((wimp_menu *) rufl_family_menu)-> |
| 673 |
|
entries[selection->items[0]].data.indirected_text.text; |
| 674 |
|
if (current_font_menu == 7) |
| 675 |
|
strncpy(font_headings, font, sizeof font_headings); |
| 676 |
|
else if (current_font_menu == 10) |
| 677 |
|
strncpy(font_summaries, font, sizeof font_summaries); |
| 678 |
|
else if (current_font_menu == 13) |
| 679 |
|
strncpy(font_links, font, sizeof font_links); |
| 680 |
|
set_icon_string(choices_window, 8, font_headings); |
| 681 |
|
set_icon_string(choices_window, 11, font_summaries); |
| 682 |
|
set_icon_string(choices_window, 14, font_links); |
| 683 |
|
update_main_window(); |
| 684 |
|
if (feed_count) |
| 685 |
|
update_feed_window(current_feed); |
| 686 |
} |
} |
| 687 |
|
|
| 688 |
|
if (pointer.buttons == wimp_CLICK_ADJUST) |
| 689 |
|
xwimp_create_menu(current_menu, pointer.pos.x, pointer.pos.y); |
| 690 |
} |
} |
| 691 |
|
|
| 692 |
|
|
| 795 |
|
|
| 796 |
p = add_paragraph(&main_window_paragraphs, 0, y, 700, |
p = add_paragraph(&main_window_paragraphs, 0, y, 700, |
| 797 |
0xffaa99, 0x000000, |
0xffaa99, 0x000000, |
| 798 |
"Homerton", style, 200, |
font_headings, style, 200, |
| 799 |
feeds[i].title ? (char *) feeds[i].title : |
feeds[i].title ? (char *) feeds[i].title : |
| 800 |
feeds[i].url, |
feeds[i].url, |
| 801 |
click_main_window, i); |
click_main_window, i); |
| 824 |
} |
} |
| 825 |
p = add_paragraph(&main_window_paragraphs, 700, y, 1000, |
p = add_paragraph(&main_window_paragraphs, 700, y, 1000, |
| 826 |
0xffaa99, 0x000000, |
0xffaa99, 0x000000, |
| 827 |
"Homerton", style, 200, |
font_headings, style, 200, |
| 828 |
status + i * 40, |
status + i * 40, |
| 829 |
click_main_window, i); |
click_main_window, i); |
| 830 |
y = p->y1 = y1; |
y = p->y1 = y1; |
| 832 |
if (feeds[i].error) { |
if (feeds[i].error) { |
| 833 |
p = add_paragraph(&main_window_paragraphs, 0, y, 1000, |
p = add_paragraph(&main_window_paragraphs, 0, y, 1000, |
| 834 |
0, 0x0000a0, |
0, 0x0000a0, |
| 835 |
"NewHall", style, 200, |
font_summaries, style, 200, |
| 836 |
feeds[i].error, |
feeds[i].error, |
| 837 |
click_main_window, i); |
click_main_window, i); |
| 838 |
y = p->y1; |
y = p->y1; |
| 841 |
if (feeds[i].description) { |
if (feeds[i].description) { |
| 842 |
p = add_paragraph(&main_window_paragraphs, 0, y, 1000, |
p = add_paragraph(&main_window_paragraphs, 0, y, 1000, |
| 843 |
0, 0x000000, |
0, 0x000000, |
| 844 |
"NewHall", rufl_WEIGHT_400, 200, |
font_summaries, rufl_WEIGHT_400, 200, |
| 845 |
feeds[i].description, |
feeds[i].description, |
| 846 |
click_main_window, i); |
click_main_window, i); |
| 847 |
y = p->y1; |
y = p->y1; |
| 923 |
|
|
| 924 |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
| 925 |
0xffaa99, 0x000000, |
0xffaa99, 0x000000, |
| 926 |
"Homerton", rufl_WEIGHT_400, 200, |
font_headings, rufl_WEIGHT_400, 200, |
| 927 |
feeds[i].title ? (char *) feeds[i].title : feeds[i].url, |
feeds[i].title ? (char *) feeds[i].title : feeds[i].url, |
| 928 |
0, 0); |
0, 0); |
| 929 |
y = p->y1; |
y = p->y1; |
| 931 |
if (feeds[i].link) { |
if (feeds[i].link) { |
| 932 |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
| 933 |
0, 0xff0000, |
0, 0xff0000, |
| 934 |
"Homerton", rufl_WEIGHT_400, 160, |
font_links, rufl_WEIGHT_400, 160, |
| 935 |
feeds[i].link, |
feeds[i].link, |
| 936 |
click_feed_link, i); |
click_feed_link, i); |
| 937 |
y = p->y1; |
y = p->y1; |
| 939 |
if (feeds[i].pub_date) { |
if (feeds[i].pub_date) { |
| 940 |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
| 941 |
0, 0x0060ee, |
0, 0x0060ee, |
| 942 |
"NewHall", rufl_WEIGHT_400 | rufl_SLANTED, 160, |
font_summaries, rufl_WEIGHT_400 | rufl_SLANTED, |
| 943 |
|
160, |
| 944 |
feeds[i].pub_date, |
feeds[i].pub_date, |
| 945 |
0, 0); |
0, 0); |
| 946 |
y = p->y1; |
y = p->y1; |
| 948 |
if (feeds[i].description) { |
if (feeds[i].description) { |
| 949 |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
| 950 |
0, 0x000000, |
0, 0x000000, |
| 951 |
"NewHall", rufl_WEIGHT_400, 200, |
font_summaries, rufl_WEIGHT_400, 200, |
| 952 |
feeds[i].description, |
feeds[i].description, |
| 953 |
0, 0); |
0, 0); |
| 954 |
y = p->y1; |
y = p->y1; |
| 956 |
if (feeds[i].copyright) { |
if (feeds[i].copyright) { |
| 957 |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
| 958 |
0, 0x666666, |
0, 0x666666, |
| 959 |
"NewHall", rufl_WEIGHT_400 | rufl_SLANTED, 160, |
font_summaries, rufl_WEIGHT_400 | rufl_SLANTED, 160, |
| 960 |
feeds[i].copyright, |
feeds[i].copyright, |
| 961 |
0, 0); |
0, 0); |
| 962 |
y = p->y1; |
y = p->y1; |
| 970 |
|
|
| 971 |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
| 972 |
0xa0dddd, 0x000000, |
0xa0dddd, 0x000000, |
| 973 |
"Homerton", style, 200, |
font_headings, style, 200, |
| 974 |
feeds[i].item[j].title ? |
feeds[i].item[j].title ? |
| 975 |
(char *) feeds[i].item[j].title : "", |
(char *) feeds[i].item[j].title : "", |
| 976 |
0, j); |
0, j); |
| 979 |
if (feeds[i].item[j].pub_date) { |
if (feeds[i].item[j].pub_date) { |
| 980 |
p = add_paragraph(&feed_window_paragraphs, 0, y, 420, |
p = add_paragraph(&feed_window_paragraphs, 0, y, 420, |
| 981 |
0, 0x0060ee, |
0, 0x0060ee, |
| 982 |
"NewHall", |
font_summaries, |
| 983 |
rufl_WEIGHT_400 | rufl_SLANTED, 160, |
rufl_WEIGHT_400 | rufl_SLANTED, 160, |
| 984 |
feeds[i].item[j].pub_date, |
feeds[i].item[j].pub_date, |
| 985 |
0, j); |
0, j); |
| 989 |
if (feeds[i].item[j].author) { |
if (feeds[i].item[j].author) { |
| 990 |
p = add_paragraph(&feed_window_paragraphs, 420, y, 720, |
p = add_paragraph(&feed_window_paragraphs, 420, y, 720, |
| 991 |
0, 0x666666, |
0, 0x666666, |
| 992 |
"NewHall", |
font_summaries, |
| 993 |
rufl_WEIGHT_400 | rufl_SLANTED, 160, |
rufl_WEIGHT_400 | rufl_SLANTED, 160, |
| 994 |
feeds[i].item[j].author, |
feeds[i].item[j].author, |
| 995 |
0, j); |
0, j); |
| 999 |
if (feeds[i].item[j].category) { |
if (feeds[i].item[j].category) { |
| 1000 |
p = add_paragraph(&feed_window_paragraphs, 720, y, 1000, |
p = add_paragraph(&feed_window_paragraphs, 720, y, 1000, |
| 1001 |
0, 0xee6000, |
0, 0xee6000, |
| 1002 |
"NewHall", rufl_WEIGHT_400, 160, |
font_summaries, rufl_WEIGHT_400, 160, |
| 1003 |
feeds[i].item[j].category, |
feeds[i].item[j].category, |
| 1004 |
0, j); |
0, j); |
| 1005 |
if (y1 < p->y1) |
if (y1 < p->y1) |
| 1010 |
if (feeds[i].item[j].link) { |
if (feeds[i].item[j].link) { |
| 1011 |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
| 1012 |
0, 0xff0000, |
0, 0xff0000, |
| 1013 |
"Homerton", rufl_WEIGHT_400, 160, |
font_links, rufl_WEIGHT_400, 160, |
| 1014 |
feeds[i].item[j].link, |
feeds[i].item[j].link, |
| 1015 |
click_item_link, j); |
click_item_link, j); |
| 1016 |
y = p->y1; |
y = p->y1; |
| 1019 |
if (feeds[i].item[j].description) { |
if (feeds[i].item[j].description) { |
| 1020 |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
p = add_paragraph(&feed_window_paragraphs, 0, y, 1000, |
| 1021 |
0, 0x000000, |
0, 0x000000, |
| 1022 |
"NewHall", rufl_WEIGHT_400, 180, |
font_summaries, rufl_WEIGHT_400, 180, |
| 1023 |
feeds[i].item[j].description, |
feeds[i].item[j].description, |
| 1024 |
0, j); |
0, j); |
| 1025 |
y = p->y1; |
y = p->y1; |
| 1220 |
return; |
return; |
| 1221 |
} |
} |
| 1222 |
fprintf(choices, "interval: %i\n", interval); |
fprintf(choices, "interval: %i\n", interval); |
| 1223 |
|
fprintf(choices, "font_headings: %s\n", font_headings); |
| 1224 |
|
fprintf(choices, "font_summaries: %s\n", font_summaries); |
| 1225 |
|
fprintf(choices, "font_links: %s\n", font_links); |
| 1226 |
fclose(choices); |
fclose(choices); |
| 1227 |
} |
} |
| 1228 |
|
|
| 1246 |
} |
} |
| 1247 |
while (fgets(s, sizeof s, choices)) { |
while (fgets(s, sizeof s, choices)) { |
| 1248 |
sscanf(s, "interval: %i", &interval); |
sscanf(s, "interval: %i", &interval); |
| 1249 |
|
sscanf(s, "font_headings: %s", font_headings); |
| 1250 |
|
sscanf(s, "font_summaries: %s", font_summaries); |
| 1251 |
|
sscanf(s, "font_links: %s", font_links); |
| 1252 |
} |
} |
| 1253 |
fclose(choices); |
fclose(choices); |
| 1254 |
} |
} |
| 1340 |
|
|
| 1341 |
xwimp_set_icon_state(w, i, 0, 0); |
xwimp_set_icon_state(w, i, 0, 0); |
| 1342 |
} |
} |
|
|
|