From: epage Date: Sat, 17 Oct 2009 19:55:57 +0000 (+0000) Subject: Starting work on collapsing messages (it'll be annoying due to HTML); removing the... X-Git-Url: http://git.maemo.org/git/?p=gc-dialer;a=commitdiff_plain;h=3098250aac7c5f26d76a53007a7ee72fcab46f77 Starting work on collapsing messages (it'll be annoying due to HTML); removing the auto-cancel login box; 'really' fixing the redirect issue git-svn-id: file:///svnroot/gc-dialer/trunk@540 c39d3808-3fe2-4d86-a59f-b7f623ee9f21 --- diff --git a/src/browser_emu.py b/src/browser_emu.py index e3446ac..056f204 100644 --- a/src/browser_emu.py +++ b/src/browser_emu.py @@ -110,10 +110,10 @@ class MozillaEmulator(object): self.cookies.add_cookie_header(req) if forbidRedirect: redirector = HTTPNoRedirector() - _moduleLogger.info("Redirection disabled") + #_moduleLogger.info("Redirection disabled") else: redirector = urllib2.HTTPRedirectHandler() - _moduleLogger.info("Redirection enabled") + #_moduleLogger.info("Redirection enabled") http_handler = urllib2.HTTPHandler(debuglevel=self.debug) https_handler = urllib2.HTTPSHandler(debuglevel=self.debug) diff --git a/src/dc_glade.py b/src/dc_glade.py index ff6123c..73a6814 100755 --- a/src/dc_glade.py +++ b/src/dc_glade.py @@ -343,17 +343,16 @@ class Dialcentral(object): with gtk_toolbox.gtk_lock(): self._errorDisplay.push_exception() finally: - self._spawn_attempt_login(2) + self._spawn_attempt_login() def _spawn_attempt_login(self, *args): self._loginSink.send(args) - def _attempt_login(self, numOfAttempts = 10, force = False): + def _attempt_login(self, force = False): """ @note This must be run outside of the UI lock """ try: - assert 0 <= numOfAttempts, "That was pointless having 0 or less login attempts" assert self._initDone, "Attempting login before app is fully loaded" serviceId = self.NULL_BACKEND @@ -372,7 +371,7 @@ class Dialcentral(object): hildonize.show_busy_banner_end(banner) if not loggedIn: - loggedIn, serviceId = self._login_by_user(numOfAttempts) + loggedIn, serviceId = self._login_by_user() with gtk_toolbox.gtk_lock(): self._change_loggedin_status(serviceId) @@ -413,30 +412,19 @@ class Dialcentral(object): @note Thread agnostic """ username, password = self._credentials - try: - loggedIn = self._phoneBackends[self._defaultBackendId].login(username, password) - except Exception: - # Retry in case the redirect failed - # luckily is_authed does everything we need for a retry - loggedIn = self._phoneBackends[self._defaultBackendId].is_authed(True) - if not loggedIn: - raise - _moduleLogger.info("Redirection failed on initial login attempt, auto-corrected for this") + loggedIn = self._phoneBackends[self._defaultBackendId].login(username, password) if loggedIn: self._credentials = username, password _moduleLogger.info("Logged into %r through settings" % self._phoneBackends[self._defaultBackendId]) return loggedIn - def _login_by_user(self, numOfAttempts): + def _login_by_user(self): """ @note This must be run outside of the UI lock """ loggedIn, (username, password) = False, self._credentials tmpServiceId = self.GV_BACKEND - for attemptCount in xrange(numOfAttempts): - if loggedIn: - break - + while not loggedIn: with gtk_toolbox.gtk_lock(): credentials = self._credentialsDialog.request_credentials( defaultCredentials = self._credentials @@ -444,19 +432,11 @@ class Dialcentral(object): if not self._phoneBackends[tmpServiceId].get_callback_number(): # subtle reminder to the users to configure things self._notebook.set_current_page(self.ACCOUNT_TAB) - banner = hildonize.show_busy_banner_start(self._window, "Logging In...") + banner = hildonize.show_busy_banner_start(self._window, "Logging In...") try: username, password = credentials - try: - loggedIn = self._phoneBackends[tmpServiceId].login(username, password) - except Exception: - # Retry in case the redirect failed - # luckily is_authed does everything we need for a retry - loggedIn = self._phoneBackends[tmpServiceId].is_authed(True) - if not loggedIn: - raise - _moduleLogger.info("Redirection failed on initial login attempt, auto-corrected for this") + loggedIn = self._phoneBackends[tmpServiceId].login(username, password) finally: with gtk_toolbox.gtk_lock(): hildonize.show_busy_banner_end(banner) @@ -466,6 +446,7 @@ class Dialcentral(object): self._credentials = username, password _moduleLogger.info("Logged into %r through user request" % self._phoneBackends[serviceId]) else: + # Hint to the user that they are not logged in serviceId = self.NULL_BACKEND self._notebook.set_current_page(self.ACCOUNT_TAB) @@ -674,7 +655,7 @@ class Dialcentral(object): if status == conic.STATUS_CONNECTED: if self._initDone: - self._spawn_attempt_login(2) + self._spawn_attempt_login() elif status == conic.STATUS_DISCONNECTED: if self._initDone: self._defaultBackendId = self._selectedBackendId @@ -720,7 +701,7 @@ class Dialcentral(object): self._contactsViews[self._selectedBackendId].clear() self._change_loggedin_status(self.NULL_BACKEND) - self._spawn_attempt_login(2, True) + self._spawn_attempt_login(True) except Exception, e: self._errorDisplay.push_exception() diff --git a/src/dialcentral.glade b/src/dialcentral.glade index b193407..8acdec3 100644 --- a/src/dialcentral.glade +++ b/src/dialcentral.glade @@ -174,10 +174,10 @@ False False - - - + + + True @@ -200,10 +200,10 @@ False False - - - + + + True @@ -226,10 +226,10 @@ False False - - - + + + True @@ -252,10 +252,10 @@ False False - - - + + + True @@ -280,10 +280,10 @@ False False - - - + + + True @@ -308,11 +308,11 @@ False False - - - - + + + + True @@ -335,10 +335,10 @@ False False - - - + + + True @@ -363,11 +363,11 @@ False False - - - - + + + + True @@ -953,7 +953,7 @@ end - gtk-close + gtk-cancel True True True diff --git a/src/gv_backend.py b/src/gv_backend.py index 35da434..b88bcbb 100644 --- a/src/gv_backend.py +++ b/src/gv_backend.py @@ -195,8 +195,13 @@ class GVDialer(object): try: self._grab_account_info(loginSuccessOrFailurePage) except Exception, e: - _moduleLogger.exception(str(e)) - return False + # Retry in case the redirect failed + # luckily is_authed does everything we need for a retry + loggedIn = self.is_authed(True) + if not loggedIn: + _moduleLogger.exception(str(e)) + return False + _moduleLogger.info("Redirection failed on initial login attempt, auto-corrected for this") self._browser.cookies.save() self._lastAuthed = time.time() diff --git a/src/gv_views.py b/src/gv_views.py index c5635fd..4fd6227 100644 --- a/src/gv_views.py +++ b/src/gv_views.py @@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +@todo Collapse voicemails @todo Alternate UI for dialogs (stackables) """ @@ -116,6 +117,54 @@ def abbrev_relative_date(date): return "%s %s" % (parts[0], parts[1][0]) +def _collapse_message(messageLines, maxCharsPerLine, maxLines): + lines = 0 + + numLines = len(messageLines) + for line in messageLines[0:min(maxLines, numLines)]: + linesPerLine = max(1, int(len(line) / maxCharsPerLine)) + allowedLines = maxLines - lines + acceptedLines = min(allowedLines, linesPerLine) + acceptedChars = acceptedLines * maxCharsPerLine + + if acceptedChars < (len(line) + 3): + suffix = "..." + else: + acceptedChars = len(line) # eh, might as well complete the line + suffix = "" + abbrevMessage = "%s%s" % (line[0:acceptedChars], suffix) + yield abbrevMessage + + lines += acceptedLines + if maxLines <= lines: + break + + +def collapse_message(message, maxCharsPerLine, maxLines): + r""" + >>> collapse_message("Hello", 60, 2) + 'Hello' + >>> collapse_message("Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789", 60, 2) + 'Hello world how are you doing today? 01234567890123456789012...' + >>> collapse_message('''Hello world how are you doing today? + ... 01234567890123456789 + ... 01234567890123456789 + ... 01234567890123456789 + ... 01234567890123456789''', 60, 2) + 'Hello world how are you doing today?\n01234567890123456789' + >>> collapse_message(''' + ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789 + ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789 + ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789 + ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789 + ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789 + ... Hello world how are you doing today? 01234567890123456789012345678901234567890123456789012345678901234567890123456789''', 60, 2) + '\nHello world how are you doing today? 01234567890123456789012...' + """ + messageLines = message.split("\n") + return "\n".join(_collapse_message(messageLines, maxCharsPerLine, maxLines)) + + class MergedAddressBook(object): """ Merger of all addressbooks @@ -1230,6 +1279,7 @@ class MessagesView(object): collapsedMessages.extend(messages[-(self._MIN_MESSAGES_SHOWN+0):]) else: collapsedMessages = expandedMessages + #collapsedMessages = _collapse_message(collapsedMessages, 60, self._MIN_MESSAGES_SHOWN) number = make_ugly(number) diff --git a/support/builddeb.py b/support/builddeb.py index 97d84aa..7db45f9 100755 --- a/support/builddeb.py +++ b/support/builddeb.py @@ -34,6 +34,8 @@ __changelog__ = """ * UI Tweak: Increased the size of the SMS dialog * UI Tweak: Disable "Dial" when a text has started to be entered * UI Tweak: Move the sms history scroll bars around the whole sms conversation, giving more room to see with +* UI Tweak: Trying to be clearer by switching the login dialog from "Close" to "Cancel" +* UI Tweak: Remove auto-cancel of login after X attempts * Bug Fix: Expanded the types of the Enter key that are supported for going to full screen * Bug Fix: Random people were reporting login issues * Bug Fix: Hardened against issues with grabbing possible callback numbers diff --git a/tests/test_gv_backend.py b/tests/test_gv_backend.py index e43cb00..6639ec5 100644 --- a/tests/test_gv_backend.py +++ b/tests/test_gv_backend.py @@ -45,7 +45,6 @@ def test_not_logged_in(): with test_utils.expected(RuntimeError): backend.send_sms("5551234567", "Hello World") assert backend.get_account_number() == "", "%s" % backend.get_account_number() - backend.set_sane_callback() assert backend.get_callback_number() == "" with test_utils.expected(Exception): recent = list(backend.get_recent())