Rename is_wap to is_mobile
authorMatt <matt@uncensored.citadel.org>
Mon, 7 Jul 2008 05:30:08 +0000 (05:30 +0000)
committerMatt <matt@uncensored.citadel.org>
Mon, 7 Jul 2008 05:30:08 +0000 (05:30 +0000)
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

webcit/messages.c
webcit/siteconfig.c
webcit/static/mobile.css
webcit/static/mobile.js
webcit/subst.c
webcit/webcit.c
webcit/webcit.h

index f376002b7267efd46393cb617243ebd2ec8379f8..e0ab860823a1ab90e3760983ee176878fee43ac4 100644 (file)
@@ -1797,7 +1797,6 @@ ENDBODY:
  */
 void display_summarized(int num) {
        char datebuf[64];
-
        wprintf("<tr id=\"m%ld\" style=\"font-weight:%s;\" "
                "onMouseDown=\"CtdlMoveMsgMouseDown(event,%ld)\">",
                WC->summ[num].msgnum,
@@ -1821,8 +1820,26 @@ void display_summarized(int num) {
 
        wprintf("</tr>\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<div><div id=\"m%ld\" style=\"font-weight:%s;\" "
+               "onClick=\"CtdlLoadMsgMouseDown(event,%ld)\">",
+               WC->summ[num].msgnum,
+               (WC->summ[num].is_new ? "bold" : "normal"),
+               WC->summ[num].msgnum
+       );
+               wprintf("<span>%s</span>",WC->summ[num].from);
+               wprintf("<span style=\"float: right;\">");
+               webcit_fmt_date(datebuf, WC->summ[num].date, 1);        /* brief */
+       escputs(datebuf);
+               wprintf("</span><br/><span class=\"subject\">");
+               wprintf(WC->summ[num].subj);
+               wprintf("</span></div><div id=\"m_%ld\" class=\"msgview\" onMouseDown=\"\"></div></div>",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("<div id=\"new_notes_here\"></div>\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("</table></div></div>\n");
-
                wprintf("<div id=\"message_list\">"
 
                        "<div class=\"fix_scrollbar_bug\">\n"
-
                        "<table class=\"mailbox_summary\" id=\"summary_headers\" "
                        "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
                );
+       } else if (WCC->is_mobile) {
+               wprintf("<div id=\"message_list\">");
        }
 
 
@@ -2708,7 +2729,6 @@ void readloop(char *oper)
                wprintf("</p></form>\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("</table>"
                        "</div>\n");                    /**< end of 'fix_scrollbar_bug' div */
                wprintf("</div>");                      /**< end of 'message_list' div */
-
+               
                /** Here's the grab-it-to-resize-the-message-list widget */
                wprintf("<div id=\"resize_msglist\" "
                        "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
@@ -2780,6 +2802,8 @@ void readloop(char *oper)
                );
 
                wprintf("<div id=\"preview_pane\">");   /**< The preview pane will initially be empty */
+       } else if (WCC->is_mobile) {
+               wprintf("</div>");
        }
 
        /**
index b062a391d8eb13f8e49c6f7d95477a2b61289ea4..a18bbd18e56602a5064b329de0d90d85454e15a0 100644 (file)
@@ -577,7 +577,7 @@ void display_siteconfig(void)
                        break;
                case 56:
                        sprintf(&funambol[strlen(funambol)], "<TR><TD>");
-                       sprintf(&funambol[strlen(funambol)], _("Funambol auth details (user:pass in Base64)"));
+                       sprintf(&funambol[strlen(funambol)], _("Funambol auth details (user:pass)"));
                        sprintf(&funambol[strlen(funambol)], "</TD><TD>");
                        sprintf(&funambol[strlen(funambol)], "<input type=\"text\" NAME=\"c_funambol_auth\" MAXLENGTH=\"255\" VALUE=\"%s\">", buf);
                        sprintf(&funambol[strlen(funambol)], "</TD></TR>\n");
index 8b761fd490303e1f7456d06ef89f738b4ddda556..e21f3046f6d554c292e526da30812fcab53542f0 100644 (file)
@@ -22,6 +22,7 @@ body[orient="portrait"] {
 }
 body {
        font-family: sans-serif;
+       font-size: 11px;
 }
 .msgview {
        display: none;
index 4181130912142ff5e138207b426b65f66f5c1371..273a6303180ba2c562d37529e3aeaa71fe21474c 100644 (file)
@@ -1,6 +1,5 @@
 var currentMsgDisplay = null;
 function CtdlLoadMsgMouseDown(event, msgnum) {
-       alert("CtdlLoadMsgMouseDown");
        if (currentMsgDisplay != null) {
                currentMsgDisplay.style.display = "none";
        } 
index e3f57773276a2ea3c65b38f020d3175f858ce8d6..aa255b9a3984a0d4adb73e98857ec577c0b8116f 100644 (file)
@@ -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");
index 9c50938438744b4dea9d415f26f4848e13b4f1fd..f06c546a988790a2b1f76286b1ac0abea613da05 100644 (file)
@@ -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
  */
index 2c542ad50a356e5b2fe7f3f23b68e31ece2ca872..21cf11f844c4bf2677f9b59450c9a52fd87bf481 100644 (file)
@@ -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);