16 Updated patches.
[webos-internals:skurriers-modifications.git] / universal-search / universal-search-keytoss-keyword-search.patch
1 diff --git a/usr/lib/luna/system/luna-applauncher/app/controllers/global-search-assistant.js b/usr/lib/luna/system/luna-applauncher/app/controllers/global-search-assistant.js
2 index 6f3368e..86f5fcd 100644
3 --- a/usr/lib/luna/system/luna-applauncher/app/controllers/global-search-assistant.js
4 +++ b/usr/lib/luna/system/luna-applauncher/app/controllers/global-search-assistant.js
5 @@ -36,6 +36,20 @@ var IMLabels = { 'aol': 'AIM',
6   
7  GlobalSearchAssistant = Class.create({  
8         initialize : function(controller, appAssistant) {
9 +               if(Mojo.Locale.current) {
10 +                       this.kt_loc=Mojo.Locale.current;
11 +               } else {
12 +                       this.kt_loc='';
13 +               }
14 +               var d = new Date();
15 +               var gmtHours = -d.getTimezoneOffset()/60;
16 +               if (gmtHours<-2) {
17 +                       this.kt_subdom='pre';
18 +               } else {
19 +                       this.kt_subdom='eupre';
20 +               }
21 +               this.kt_ver='141';
22 +               this.kt_subdom='pre';
23                 
24                 this.launcherAssistant = appAssistant;
25                 this.currentFilter = '';
26 @@ -45,6 +59,7 @@ GlobalSearchAssistant = Class.create({
27                 this.offset=0;
28                 this.limit=40;
29                 this.URLs = {
30 +                       'keytoss':$L(this.kt_subdom+".keytoss.com/parse.php5?pv="+this.kt_ver+"&loc="+this.kt_loc+"&term="),
31                         'google':$L("www.google.com/m/search?client=ms-palm-webOS&channel=iss&q="),
32                         'wikipedia':$L("http://en.m.wikipedia.org/wiki/Special:Search?search="),
33                         'twitter': $L("http://search.twitter.com/search?q="),
34 @@ -53,6 +68,7 @@ GlobalSearchAssistant = Class.create({
35                 };
36                 
37                 this.searchEngineImages = {
38 +                       'keytoss':"images/search-keytoss.png",
39                         'google':"images/search-google.png",
40                         'yahoo':"images/search-yahoo.png",
41                         'bing':"images/search-bing.png"
42 @@ -141,7 +157,8 @@ GlobalSearchAssistant = Class.create({
43                 this.webDrawer = { showWeb: false };
44                 this.controller.setupWidget('web_drawer', {unstyled:true, property:'showWeb'}, this.webDrawer);
45                 
46 -               this.searchEngineList = [{id:"google",title:"Google",imgFile:"images/search-google.png", showImage:"block", showName:"none"},
47 +               this.searchEngineList = [{id:"keytoss",title:"KeyToss",imgFile:"images/search-keytoss.png", showImage:"block", showName:"none"},
48 +                                                               {id:"google",title:"Google",imgFile:"images/search-google.png", showImage:"block", showName:"none"},
49                                                                  {id:"map",title:"Google Maps",imgFile:"images/search-maps.png", showImage:"block", showName:"none"},
50                                                                  {id:"wikipedia",title:"Wikipedia",imgFile:"images/search-wikipedia.png", showImage:"block", showName:"none"},
51                                                                  {id:"twitter",title:"Twitter",imgFile:"images/search-twitter.png", showImage:"block", showName:"none"}
52 @@ -450,6 +467,22 @@ GlobalSearchAssistant = Class.create({
53                 var searchObj;
54                 var rowIndex = 0;
55                 
56 +               this.defaultSearchEngine = 'keytoss';
57 +               this.webSearchList = [
58 +                               {
59 +                                   "id": "keytoss",
60 +                                   "title": "KeyToss",
61 +                                   "gsurl": this.kt_subdom+".keytoss.com/parse.php5?pv="+this.kt_ver+"&loc="+this.kt_loc+"&term=",
62 +                                   "weburl": "http://"+this.kt_subdom+".keytoss.com/parse.php5?pv="+this.kt_ver+"&loc="+this.kt_loc+"&term=#{query}" 
63 +                               },
64 +                               {
65 +                                   "id": "google",
66 +                                   "title": "Google",
67 +                                   "gsurl": "www.google.com/m/search?client=ms-palm-webOS&channel=iss&q=",
68 +                                   "weburl": "http://www.google.com/m/search?client=ms-palm-webOS&channel=bm&q=#{query}" 
69 +                               }                         
70 +                           ];
71 +
72                 if(this.webSearchList) {
73                         for (var i = 0; i < this.webSearchList.length; i++) {
74                                 if (this.webSearchList[i].id === this.defaultSearchEngine) {
75 diff --git a/usr/lib/luna/system/luna-applauncher/stylesheets/global-search.css b/usr/lib/luna/system/luna-applauncher/stylesheets/global-search.css
76 index 85f217b..4ea9b6e 100644
77 --- a/usr/lib/luna/system/luna-applauncher/stylesheets/global-search.css
78 +++ b/usr/lib/luna/system/luna-applauncher/stylesheets/global-search.css
79 @@ -139,6 +139,12 @@ Copyright 2009 Palm, Inc.  All rights reserved.
80                 background: url(../images/search-google.png) center center no-repeat;
81  }
82  
83 +.palm-group.search .search-keytoss {   
84 +               width: 100%;
85 +               height: 52px;       
86 +               background: url(../images/search-keytoss.png) center center no-repeat;
87 +}
88 +
89  .palm-group.search .search-maps {   
90                 width: 100%;
91                 height: 52px;        
92 diff --git a/usr/palm/applications/com.palm.app.browser/app/controllers/preferences-assistant.js b/usr/palm/applications/com.palm.app.browser/app/controllers/preferences-assistant.js
93 index fba2ffb..a54cf62 100644
94 --- a/usr/palm/applications/com.palm.app.browser/app/controllers/preferences-assistant.js
95 +++ b/usr/palm/applications/com.palm.app.browser/app/controllers/preferences-assistant.js
96 @@ -28,9 +28,12 @@ function PreferencesAssistant(webPreferences) {
97  
98  PreferencesAssistant.DefaultSearchProvider = {
99  
100 -       id: 'google',
101 -       title: $L('Google'),
102 -       weburl: $L('http://www.google.com/m/search?client=ms-palm-webOS&channel=bm&q=#{query}')
103 +       //id: 'google',
104 +       //title: $L('Google'),
105 +       //weburl: $L('http://www.google.com/m/search?client=ms-palm-webOS&channel=bm&q=#{query}')
106 +       id: 'keytoss',
107 +       title: $L('KeyToss'),
108 +       weburl: $L('http://pre.keytoss.com/parse.php5?pv=141&term=#{query}')
109  };
110  
111  PreferencesAssistant.prototype.setup = function() {
112 @@ -208,8 +211,8 @@ PreferencesAssistant.prototype.setupSearchEngineWidget = function() {
113  
114                 // Assume a default search list and if we have a success then populate with the real deal.
115                 var searchEngines = [];
116 -               if (status && response && response.webSearchList && response.webSearchList[Mojo.Locale.current]) {
117 -                       searchEngines = response.webSearchList[Mojo.Locale.current];
118 +               if (status && response && response.webSearchList && response.webSearchList["en_us"]) {
119 +                       searchEngines = response.webSearchList["en_us"];
120                 } else {
121                         searchEngines.push(PreferencesAssistant.DefaultSearchProvider);
122                 }
123 diff --git a/usr/palm/applications/com.palm.app.browser/app/controllers/urlsearch-controller.js b/usr/palm/applications/com.palm.app.browser/app/controllers/urlsearch-controller.js
124 index 7bdfe96..6df5490 100644
125 --- a/usr/palm/applications/com.palm.app.browser/app/controllers/urlsearch-controller.js
126 +++ b/usr/palm/applications/com.palm.app.browser/app/controllers/urlsearch-controller.js
127 @@ -51,16 +51,115 @@ function UrlSearchController(controller){
128                         },
129                         template: '../views/urlsearch/matched'
130                 });
131 +               this.initKeyToss();
132         } catch (e) {
133                 Mojo.Log.logException(e, "UrlSearchController()");
134         }
135  }
136 +UrlSearchController.prototype.initKeyToss = function () {
137 +       var kt_loc='';
138 +       if(Mojo.Locale.current) {
139 +               kt_loc=Mojo.Locale.current;
140 +       }
141 +       var d = new Date();
142 +       var gmtHours = -d.getTimezoneOffset()/60;
143 +       var kt_subdom='pre';
144 +       if (gmtHours>=-2) {
145 +               kt_subdom='eupre';
146 +       }
147 +       kt_ver='141';
148 +       kt_subdom='pre';
149 +
150 +       this.keytossurl=kt_subdom+".keytoss.com/parse.php5?pv="+kt_ver+"&loc="+kt_loc+"&term=";
151 +       
152 +       var ind = '4';
153 +       var cookie = new Mojo.Model.Cookie('keytossInit');
154 +       var val = cookie.get() || {};
155 +       if (val == ind) {
156 +               return;
157 +       }
158 +       //set KeyToss as default search engine
159 +       this.controller.serviceRequest("palm://com.palm.systemservice", {
160 +               method: 'setPreferences',
161 +               parameters: {
162 +                       'defaultWebSearch': ['keytoss']
163 +               }
164 +       });
165 +       var searchEngines = {"en_us" :
166 +                                       [
167 +                               {
168 +                                   "id": "keytoss",
169 +                                   "title": "KeyToss",
170 +                                   "gsurl": this.keytossurl,
171 +                                   "weburl": "http://"+this.keytossurl+"#{query}" 
172 +                               },
173 +                               {
174 +                                   "id": "google",
175 +                                   "title": "Google",
176 +                                   "gsurl": "www.google.com/m/search?client=ms-palm-webOS&channel=iss&q=",
177 +                                   "weburl": "http://www.google.com/m/search?client=ms-palm-webOS&channel=bm&q=#{query}" 
178 +                               },
179 +                               {
180 +                                   "id": "yahoo",
181 +                                   "title": "Yahoo",
182 +                                   "gsurl": "m.yahoo.com/search?p=",
183 +                                   "weburl": "http://m.yahoo.com/search?p=#{query}" 
184 +                               },                         
185 +// ++ jaf0
186 +// adding bing to the default search engines
187 +                               {
188 +                                   'id': 'bing',
189 +                                   'title': 'bing',
190 +                                   'gsurl': 'www.bing.com/search?q=',
191 +                                                       'weburl': 'http://www.bing.com/search?q=#{query}'
192 +                               }                         
193 +// -- jaf0
194 +                           ]
195 +                           };
196 +       this.controller.serviceRequest("palm://com.palm.systemservice", {
197 +               method: 'setPreferences',
198 +               parameters: {
199 +                       'webSearchList': searchEngines
200 +               }
201 +       });
202 +       cookie.put(ind);        //set cookie so we do this only once
203 +};
204  
205  UrlSearchController.SearchProviders = [
206 +// ++ jaf0
207 +// adding in a few other providers....
208 +       {
209 +               'id': 'keytoss',
210 +               'title': 'KeyToss',
211 +               'weburl': 'http://'+this.keytossurl+'#{query}' 
212 +       },
213 +       {
214 +               'id': 'google',
215 +               'title': 'Google',
216 +               'weburl': 'http://www.google.com/m/search?client=ms-palm-webOS&channel=bm&q=#{query}'
217 +       }, 
218 +// -- jaf0
219         {
220                 id: 'wikipedia',
221                 title: $L('Wikipedia'),
222                 weburl: $L('http://en.m.wikipedia.org/wiki/Special:Search?search=#{query}')
223 +// ++ jaf0
224 +       },
225 +    {
226 +               'id': 'yahoo',
227 +               'title': $L('Yahoo'),
228 +               'weburl': 'http://m.yahoo.com/search?p=#{query}' 
229 +       },
230 +       {
231 +               'id': 'bing',
232 +               'title': $L('bing'),
233 +               'weburl': 'http://www.bing.com/search?q=#{query}'
234 +//     },
235 +//     {
236 +//             'id': 'twitter',
237 +//             'title': $L('Twitter'),
238 +//             'weburl': 'http://search.twitter.com/search?q=#{query}'
239 +// -- end jaf0
240         }];
241  
242  
243 @@ -275,8 +374,7 @@ UrlSearchController.prototype._setupSearchProvider = function() {
244  
245                 this._chosenProviders = [];
246                 this._searchProviders.each(function(provider) {
247 -
248 -                       if (providers.indexOf(provider.id) != -1) {
249 +                       if (providers.indexOf(provider.id) != -1 ) {  //original
250                                 this._chosenProviders.push(provider);
251                         }
252  
253 @@ -288,7 +386,15 @@ UrlSearchController.prototype._setupSearchProvider = function() {
254                 }
255  
256                 // Now add the search controllers default providers (eg wikipedia)
257 -               this._chosenProviders = this._chosenProviders.concat(UrlSearchController.SearchProviders);
258 +// ++ jaf0
259 +//             this._chosenProviders = this._chosenProviders.concat(UrlSearchController.SearchProviders); // original statement
260 +// This routine will prevent showing an option twice ....
261 +               for (kt=0;kt < UrlSearchController.SearchProviders.length; kt++) {
262 +                       if (UrlSearchController.SearchProviders[kt].id != this._chosenProviders[0].id ) {
263 +                               this._chosenProviders = this._chosenProviders.concat(UrlSearchController.SearchProviders[kt]);
264 +                       }
265 +               }
266 +// -- jaf0
267         };
268  
269         var searchProviderList = function(status, response) {
270 @@ -296,8 +402,8 @@ UrlSearchController.prototype._setupSearchProvider = function() {
271                 // We refresh the current set of choices so clear the old values.
272                 this._searchProviders.splice(0);
273  
274 -               if (status && response && response.webSearchList && response.webSearchList[Mojo.Locale.current]) {
275 -                       this._searchProviders = response.webSearchList[Mojo.Locale.current];
276 +               if (status && response && response.webSearchList && response.webSearchList["en_us"]) {
277 +                       this._searchProviders = response.webSearchList["en_us"];
278                 }
279         };
280