Merge lp:~feng-kylin/unity8/OpenUrlInIndicator into lp:unity8

Proposed by handsome_feng
Status: Rejected
Rejected by: Albert Astals Cid
Proposed branch: lp:~feng-kylin/unity8/OpenUrlInIndicator
Merge into: lp:unity8
Diff against target: 274 lines (+244/-1)
2 files modified
qml/Panel/Indicators/MessageMenuItemFactory.qml (+33/-1)
qml/Panel/Indicators/ba-linkify.js (+211/-0)
To merge this branch: bzr merge lp:~feng-kylin/unity8/OpenUrlInIndicator
Reviewer Review Type Date Requested Status
Nick Dedekind (community) Needs Fixing
Albert Astals Cid (community) Needs Information
Renato Araujo Oliveira Filho Pending
Review via email: mp+258836@code.launchpad.net

Commit message

use the same code in messaging-app to implement the function that open url in text viewed in the message indicator.

Description of the change

Use the same code in messaging-app to implement the function that open url in text viewed in the message indicator.

To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote :

If the messaging-app is already doing this shouldn't it just feed the "transformed" text to us instead of us transforming it again?

review: Needs Information
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> If the messaging-app is already doing this shouldn't it just feed the
> "transformed" text to us instead of us transforming it again?

Yeah, no chance here.
Either we need to put this directly in telephony when we receive the message, or it needs to be a function in the Ubuntu.Telephony[.Message] qml plugin.

review: Needs Fixing
Revision history for this message
Albert Astals Cid (aacid) wrote :

Feng?

Revision history for this message
handsome_feng (feng-kylin) wrote :

> Feng?

uhs,So I need to move this code into lp:telephony-service?

Revision history for this message
Albert Astals Cid (aacid) wrote :

What Nick says is that whatever text we get in the UI should be correct already, if lp:telephony-service is the thing feeding those messages, yes, the code should be there so we get the text correctly marked up for display already.

Unmerged revisions

1773. By handsome_feng

use the same code in messaging-app to implement the function that open url in text viewed in the message indicator

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'qml/Panel/Indicators/MessageMenuItemFactory.qml'
--- qml/Panel/Indicators/MessageMenuItemFactory.qml 2015-03-13 10:07:57 +0000
+++ qml/Panel/Indicators/MessageMenuItemFactory.qml 2015-05-12 07:27:56 +0000
@@ -23,6 +23,9 @@
23import Ubuntu.Settings.Menus 0.1 as Menus23import Ubuntu.Settings.Menus 0.1 as Menus
24import QMenuModel 0.1 as QMenuModel24import QMenuModel 0.1 as QMenuModel
25import Utils 0.1 as Utils25import Utils 0.1 as Utils
26import Ubuntu.Telephony.PhoneNumber 0.1 as PhoneNumber
27
28import "ba-linkify.js" as BaLinkify
2629
27Loader {30Loader {
28 id: messageFactoryItem31 id: messageFactoryItem
@@ -92,6 +95,35 @@
92 return defaultValue;95 return defaultValue;
93 }96 }
9497
98 function getCountryCode() {
99 var localeName = Qt.locale().name
100 return localeName.substr(localeName.length - 2, 2)
101 }
102
103 function formatTelSchemeWith(phoneNumber) {
104 return '<a href="tel:///' + phoneNumber + '">' + phoneNumber + '</a>'
105 }
106
107 function parseText(text) {
108 // remove html tags
109 text = text.replace(/</g,'&lt;').replace(/>/g,'<tt>&gt;</tt>');
110 // replace line breaks
111 text = text.replace(/(\n)+/g, '<br />');
112 // check for links
113 var htmlText = BaLinkify.linkify(text);
114 if (htmlText !== text) {
115 return htmlText
116 }
117
118 // linkify phone numbers if no web links were found
119 var phoneNumbers = PhoneNumber.PhoneUtils.matchInText(text, getCountryCode())
120 for (var i = 0; i < phoneNumbers.length; ++i) {
121 var currentNumber = phoneNumbers[i]
122 text = text.replace(currentNumber, formatTelSchemeWith(currentNumber))
123 }
124 return text
125 }
126
95 Component {127 Component {
96 id: simpleMessage128 id: simpleMessage
97129
@@ -144,7 +176,7 @@
144 // text176 // text
145 title: menuData && menuData.label || ""177 title: menuData && menuData.label || ""
146 time: timeFormatter.timeString178 time: timeFormatter.timeString
147 body: getExtendedProperty(extendedData, "xCanonicalText", "")179 body: parseText(getExtendedProperty(extendedData, "xCanonicalText", ""))
148 replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")180 replyButtonText: getExtendedProperty(replyActionDescription, "label", "Send")
149 replyHintText: i18n.ctr("Label: Hint in message indicator line edit", "Reply")181 replyHintText: i18n.ctr("Label: Hint in message indicator line edit", "Reply")
150 // icons182 // icons
151183
=== added file 'qml/Panel/Indicators/ba-linkify.js'
--- qml/Panel/Indicators/ba-linkify.js 1970-01-01 00:00:00 +0000
+++ qml/Panel/Indicators/ba-linkify.js 2015-05-12 07:27:56 +0000
@@ -0,0 +1,211 @@
1/*!
2 * JavaScript Linkify - v0.3 - 6/27/2009
3 * http://benalman.com/projects/javascript-linkify/
4 *
5 * Copyright (c) 2009 "Cowboy" Ben Alman
6 * Dual licensed under the MIT and GPL licenses.
7 * http://benalman.com/about/license/
8 *
9 * Some regexps adapted from http://userscripts.org/scripts/review/7122
10 */
11
12// Script: JavaScript Linkify: Process links in text!
13//
14// *Version: 0.3, Last updated: 6/27/2009*
15//
16// Project Home - http://benalman.com/projects/javascript-linkify/
17// GitHub - http://github.com/cowboy/javascript-linkify/
18// Source - http://github.com/cowboy/javascript-linkify/raw/master/ba-linkify.js
19// (Minified) - http://github.com/cowboy/javascript-linkify/raw/master/ba-linkify.min.js (2.8kb)
20//
21// About: License
22//
23// Copyright (c) 2009 "Cowboy" Ben Alman,
24// Dual licensed under the MIT and GPL licenses.
25// http://benalman.com/about/license/
26//
27// About: Examples
28//
29// This working example, complete with fully commented code, illustrates one way
30// in which this code can be used.
31//
32// Linkify - http://benalman.com/code/projects/javascript-linkify/examples/linkify/
33//
34// About: Support and Testing
35//
36// Information about what browsers this code has been tested in.
37//
38// Browsers Tested - Internet Explorer 6-8, Firefox 2-3.7, Safari 3-4, Chrome, Opera 9.6-10.
39//
40// About: Release History
41//
42// 0.3 - (6/27/2009) Initial release
43
44// Function: linkify
45//
46// Turn text into linkified html.
47//
48// Usage:
49//
50// > var html = linkify( text [, options ] );
51//
52// Arguments:
53//
54// text - (String) Non-HTML text containing links to be parsed.
55// options - (Object) An optional object containing linkify parse options.
56//
57// Options:
58//
59// callback (Function) - If specified, this will be called once for each link-
60// or non-link-chunk with two arguments, text and href. If the chunk is
61// non-link, href will be omitted. If unspecified, the default linkification
62// callback is used.
63// punct_regexp (RegExp) - A RegExp that will be used to trim trailing
64// punctuation from links, instead of the default. If set to null, trailing
65// punctuation will not be trimmed.
66//
67// Returns:
68//
69// (String) An HTML string containing links.
70
71var SCHEME = "[a-z\\d.-]+://",
72IPV4 = "(?:(?:[0-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}(?:[0-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])",
73HOSTNAME = "(?:(?:[^\\s!@#$%^&*()_=+[\\]{}\\\\|;:'\",.<>/?]+)\\.)+",
74TLD = "(?:ac|ad|aero|ae|af|ag|ai|al|am|an|ao|aq|arpa|ar|asia|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|biz|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|cat|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|coop|com|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|info|int|in|io|iq|ir|is|it|je|jm|jobs|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mobi|mo|mp|mq|mr|ms|mt|museum|mu|mv|mw|mx|my|mz|name|na|nc|net|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|travel|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xn--0zwm56d|xn--11b5bs3a9aj6g|xn--80akhbyknj4f|xn--9t4b11yi5a|xn--deba0ad|xn--g6w251d|xn--hgbk6aj7f53bba|xn--hlcj6aya9esc7a|xn--jxalpdlp|xn--kgbechtv|xn--zckzah|ye|yt|yu|za|zm|zw)",
75HOST_OR_IP = "(?:" + HOSTNAME + TLD + "|" + IPV4 + ")",
76PATH = "(?:[;/][^#?<>\\s]*)?",
77QUERY_FRAG = "(?:\\?[^#<>\\s]*)?(?:#[^<>\\s]*)?",
78URI1 = "\\b" + SCHEME + "[^<>\\s]+",
79URI2 = "\\b" + HOST_OR_IP + PATH + QUERY_FRAG + "(?!\\w)",
80
81MAILTO = "mailto:",
82EMAIL = "(?:" + MAILTO + ")?[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@" + HOST_OR_IP + QUERY_FRAG + "(?!\\w)",
83
84URI_RE = new RegExp( "(?:" + URI1 + "|" + URI2 + "|" + EMAIL + ")", "ig" ),
85SCHEME_RE = new RegExp( "^" + SCHEME, "i" ),
86
87quotes = {
88 "'": "`",
89 '>': '<',
90 ')': '(',
91 ']': '[',
92 '}': '{',
93 '»': '«',
94 '›': '‹'
95},
96
97default_options = {
98 callback: function( text, href ) {
99 return href ? '<a href="' + href + '" title="' + href + '">' + text + '</a>' : text;
100 },
101 punct_regexp: /(?:[!?.,:;'"]|(?:&|&amp;)(?:lt|gt|quot|apos|raquo|laquo|rsaquo|lsaquo);)$/
102};
103
104function linkify( txt, options ) {
105 options = options || {};
106
107 // Temp variables.
108 var arr,
109 i,
110 link,
111 href,
112
113 // Output HTML.
114 html = '',
115
116 // Store text / link parts, in order, for re-combination.
117 parts = [],
118
119 // Used for keeping track of indices in the text.
120 idx_prev,
121 idx_last,
122 idx,
123 link_last,
124
125 // Used for trimming trailing punctuation and quotes from links.
126 matches_begin,
127 matches_end,
128 quote_begin,
129 quote_end;
130
131 // Initialize options.
132 for ( i in default_options ) {
133 if ( options[ i ] === undefined ) {
134 options[ i ] = default_options[ i ];
135 }
136 }
137
138 // Find links.
139 while ( arr = URI_RE.exec( txt ) ) {
140
141 link = arr[0];
142 idx_last = URI_RE.lastIndex;
143 idx = idx_last - link.length;
144
145 // Not a link if preceded by certain characters.
146 if ( /[\/:]/.test( txt.charAt( idx - 1 ) ) ) {
147 continue;
148 }
149
150 // Trim trailing punctuation.
151 do {
152 // If no changes are made, we don't want to loop forever!
153 link_last = link;
154
155 quote_end = link.substr( -1 )
156 quote_begin = quotes[ quote_end ];
157
158 // Ending quote character?
159 if ( quote_begin ) {
160 matches_begin = link.match( new RegExp( '\\' + quote_begin + '(?!$)', 'g' ) );
161 matches_end = link.match( new RegExp( '\\' + quote_end, 'g' ) );
162
163 // If quotes are unbalanced, remove trailing quote character.
164 if ( ( matches_begin ? matches_begin.length : 0 ) < ( matches_end ? matches_end.length : 0 ) ) {
165 link = link.substr( 0, link.length - 1 );
166 idx_last--;
167 }
168 }
169
170 // Ending non-quote punctuation character?
171 if ( options.punct_regexp ) {
172 link = link.replace( options.punct_regexp, function(a){
173 idx_last -= a.length;
174 return '';
175 });
176 }
177 } while ( link.length && link !== link_last );
178
179 href = link;
180
181 // Add appropriate protocol to naked links.
182 if ( !SCHEME_RE.test( href ) ) {
183 href = ( href.indexOf( '@' ) !== -1 ? ( !href.indexOf( MAILTO ) ? '' : MAILTO )
184 : !href.indexOf( 'irc.' ) ? 'irc://'
185 : !href.indexOf( 'ftp.' ) ? 'ftp://'
186 : 'http://' )
187 + href;
188 }
189
190 // Push preceding non-link text onto the array.
191 if ( idx_prev != idx ) {
192 parts.push([ txt.slice( idx_prev, idx ) ]);
193 idx_prev = idx_last;
194 }
195
196 // Push massaged link onto the array
197 parts.push([ link, href ]);
198 };
199
200 // Push remaining non-link text onto the array.
201 parts.push([ txt.substr( idx_prev ) ]);
202
203 // Process the array items.
204 for ( i = 0; i < parts.length; i++ ) {
205 html += options.callback.apply( this, parts[i] );
206 }
207
208 // In case of catastrophic failure, return the original text;
209 return html || txt;
210};
211

Subscribers

People subscribed via source and target branches