From: Matt Date: Mon, 7 Jul 2008 05:30:08 +0000 (+0000) Subject: Rename is_wap to is_mobile X-Git-Tag: v7.86~2119 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=6af728cfac4414a7b937d2b5658e03a75710c59b Rename is_wap to is_mobile Detect iPhone Safari,S60 WebKit and WinCE browsers (opera, pocket ie) by user-agent Different and experimental message view - code is messy at the moment so cleanup will come soon --- diff --git a/webcit/messages.c b/webcit/messages.c index f376002b7..e0ab86082 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -1797,7 +1797,6 @@ ENDBODY: */ void display_summarized(int num) { char datebuf[64]; - wprintf("", WC->summ[num].msgnum, @@ -1821,8 +1820,26 @@ void display_summarized(int num) { wprintf("\n"); } - - +/** + * \brief Output a message row for the mobile view + * \param The row number + */ +void display_mobile_summary(int num) { + char datebuf[64]; + wprintf("\n
", + WC->summ[num].msgnum, + (WC->summ[num].is_new ? "bold" : "normal"), + WC->summ[num].msgnum + ); + wprintf("%s",WC->summ[num].from); + wprintf(""); + webcit_fmt_date(datebuf, WC->summ[num].date, 1); /* brief */ + escputs(datebuf); + wprintf("
"); + wprintf(WC->summ[num].subj); + wprintf("
",WC->summ[num].msgnum); +} /** * \brief display the adressbook overview @@ -2364,7 +2381,7 @@ void readloop(char *oper) startmsg = lbstr("startmsg"); maxmsgs = ibstr("maxmsgs"); - is_summary = ibstr("is_summary"); + is_summary = (ibstr("is_summary") && !WCC->is_mobile); if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS; snprintf(sortpref_name, sizeof sortpref_name, "sort %s", WCC->wc_roomname); @@ -2406,7 +2423,7 @@ void readloop(char *oper) strcpy(cmd, "MSGS ALL"); } - if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1)) { + if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) { is_summary = 1; if (!strcmp(oper, "do_search")) { snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query")); @@ -2427,13 +2444,17 @@ void readloop(char *oper) maxmsgs = 9999999; } - if (is_summary) { /**< fetch header summary */ + if (is_summary || WCC->is_mobile) { /**< fetch header summary */ snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1", (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"), (!strcmp(oper, "do_search") ? bstr("query") : "") ); startmsg = 1; maxmsgs = 9999999; + } + if (WCC->is_mobile) { + maxmsgs = 20; + sortby = "rdate"; } /** @@ -2442,7 +2463,7 @@ void readloop(char *oper) * new messages. */ strcpy(old_msgs, ""); - if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){ + if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){ serv_puts("GTSN"); serv_getln(buf, sizeof buf); if (buf[0] == '2') { @@ -2472,7 +2493,7 @@ void readloop(char *oper) wprintf("
\n"); } - nummsgs = load_msg_ptrs(cmd, is_summary); + nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile)); if (nummsgs == 0) { if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) { @@ -2490,7 +2511,7 @@ void readloop(char *oper) goto DONE; } - if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){ + if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){ for (a = 0; a < nummsgs; ++a) { /** Are you a new message, or an old message? */ if (is_summary) { @@ -2513,7 +2534,7 @@ void readloop(char *oper) } } - if (is_summary) { + if (is_summary || WCC->is_mobile) { if (!strcasecmp(sortby, "subject")) { qsort(WCC->summ, WCC->num_summ, sizeof(struct message_summary), summcmp_subj); @@ -2605,14 +2626,14 @@ void readloop(char *oper) _("Delete") ); wprintf("\n"); - wprintf("
" "
\n" - "" ); + } else if (WCC->is_mobile) { + wprintf("
"); } @@ -2708,7 +2729,6 @@ void readloop(char *oper) wprintf("

\n"); /** end bbview scroller */ } - for (a = 0; a < nummsgs; ++a) { if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) { @@ -2733,6 +2753,8 @@ void readloop(char *oper) } else if (is_notes) { display_note(WCC->msgarr[a], WCC->summ[a].is_new); + } else if (WCC->is_mobile) { + display_mobile_summary(a); } else { if (displayed_msgs == NULL) { @@ -2771,7 +2793,7 @@ void readloop(char *oper) wprintf("
" "
\n"); /**< end of 'fix_scrollbar_bug' div */ wprintf("
"); /**< end of 'message_list' div */ - + /** Here's the grab-it-to-resize-the-message-list widget */ wprintf("
" @@ -2780,6 +2802,8 @@ void readloop(char *oper) ); wprintf("
"); /**< The preview pane will initially be empty */ + } else if (WCC->is_mobile) { + wprintf("
"); } /** diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c index b062a391d..a18bbd18e 100644 --- a/webcit/siteconfig.c +++ b/webcit/siteconfig.c @@ -577,7 +577,7 @@ void display_siteconfig(void) break; case 56: sprintf(&funambol[strlen(funambol)], ""); - sprintf(&funambol[strlen(funambol)], _("Funambol auth details (user:pass in Base64)")); + sprintf(&funambol[strlen(funambol)], _("Funambol auth details (user:pass)")); sprintf(&funambol[strlen(funambol)], ""); sprintf(&funambol[strlen(funambol)], "", buf); sprintf(&funambol[strlen(funambol)], "\n"); diff --git a/webcit/static/mobile.css b/webcit/static/mobile.css index 8b761fd49..e21f3046f 100644 --- a/webcit/static/mobile.css +++ b/webcit/static/mobile.css @@ -22,6 +22,7 @@ body[orient="portrait"] { } body { font-family: sans-serif; + font-size: 11px; } .msgview { display: none; diff --git a/webcit/static/mobile.js b/webcit/static/mobile.js index 418113091..273a63031 100644 --- a/webcit/static/mobile.js +++ b/webcit/static/mobile.js @@ -1,6 +1,5 @@ var currentMsgDisplay = null; function CtdlLoadMsgMouseDown(event, msgnum) { - alert("CtdlLoadMsgMouseDown"); if (currentMsgDisplay != null) { currentMsgDisplay.style.display = "none"; } diff --git a/webcit/subst.c b/webcit/subst.c index e3f577732..aa255b9a3 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -357,7 +357,7 @@ void do_template(void *templatename) { struct stat mystat; strcpy(flat_filename, templatename); - if (WC->is_wap) + if (WC->is_mobile) strcat(flat_filename, ".m.html"); else strcat(flat_filename, ".html"); diff --git a/webcit/webcit.c b/webcit/webcit.c index 9c5093843..f06c546a9 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -1314,7 +1314,19 @@ void seconds_since_last_gexp(void) end_ajax_response(); } - +/** + * \brief Detects a 'mobile' user agent + */ +int is_mobile_ua(char *user_agent) { + if (strstr(user_agent,"iPhone OS") != NULL) { + return 1; + } else if (strstr(user_agent,"Windows CE") != NULL) { + return 1; + } else if (strstr(user_agent,"SymbianOS") != NULL) { + return 1; + } + return 0; +} /* @@ -1364,7 +1376,7 @@ void session_loop(struct httprequest *req) WC->upload_length = 0; WC->upload = NULL; - WC->is_wap = 0; + WC->is_mobile = 0; hptr = req; if (hptr == NULL) return; @@ -1422,6 +1434,9 @@ void session_loop(struct httprequest *req) } else if (!strncasecmp(buf, "User-agent: ", 12)) { safestrncpy(user_agent, &buf[12], sizeof user_agent); + if (is_mobile_ua(&buf[12])) { + WC->is_mobile = 1; + } } else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) { if (follow_xff) { @@ -1440,12 +1455,6 @@ void session_loop(struct httprequest *req) } striplt(browser_host); } - /** Only WAP gateways explicitly name this content-type */ - else if (strstr(buf, "text/vnd.wap.wml")) { - /* since we don't have wap pages we disable this. - * WC->is_wap = 1; - */ - } } if (ContentLength > 0) { @@ -2110,6 +2119,7 @@ SKIP_ALL_THIS_CRAP: } } + /* * Replacement for sleep() that uses select() in order to avoid SIGALRM */ diff --git a/webcit/webcit.h b/webcit/webcit.h index 2c542ad50..21cf11f84 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -397,7 +397,7 @@ struct wcsession { long msgarr[10000]; /**< for read operations */ int num_summ; /**< number of messages in mailbox summary view */ struct message_summary *summ; /**< array of messages for mailbox summary view */ - int is_wap; /**< Client is a WAP gateway */ + int is_mobile; /**< Client is a handheld browser */ HashList *urlstrings; /**< variables passed to webcit in a URL */ HashList *vars; /**< HTTP variable substitutions for this page */ char this_page[512]; /**< URL of current page */ @@ -815,6 +815,7 @@ int xtoi(char *in, size_t len); void webcit_fmt_date(char *buf, time_t thetime, int brief); int fetch_http(char *url, char *target_buf, int maxbytes); +int is_mobile_ua(char *user_agent); #ifdef HAVE_ICONV iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode);