import webbrowser
import datetime
import urlparse
+import base64
import gobject
import gtk
authURL = rtm.getAuthURL()
webbrowser.open(authURL)
- # mb = gtk_toolbox.MessageBox2("You need to authorize DoneIt with\nRemember The Milk.\nClick OK after you authorize.")
- # mb.run()
+ mb = gtk_toolbox.MessageBox2("You need to authorize DoneIt with\nRemember The Milk.\nClick OK after you authorize.")
+ mb.run()
token = rtm.getToken()
return token
-def start_session(credentialsDialog):
- # @todo Figure out storage of credentials
+def get_credentials(credentialsDialog):
username, password = credentialsDialog.request_credentials()
token = get_token(username, rtmilk.RtMilkManager.API_KEY, rtmilk.RtMilkManager.SECRET)
- return rtmilk.RtMilkManager(username, password, token)
+ return username, password, token
class GtkRtMilk(object):
self._projectsCombo = widgetTree.get_widget("projectsCombo")
self._onListActivateId = 0
+ # @todo Need to figure out how to make the list sortable, especially with weird priority sorting
self._itemList = gtk.ListStore(
gobject.TYPE_STRING, # id
gobject.TYPE_BOOLEAN, # is complete
self._onClearId = None
self._onPasteId = None
- self._credentials = gtk_toolbox.LoginWindow(widgetTree)
+ self._credentialsDialog = gtk_toolbox.LoginWindow(widgetTree)
+ self._credentials = "", "", ""
self._manager = None
@staticmethod
def name():
return "Remember The Milk"
- def enable(self):
+ def load_settings(self, config):
+ """
+ @note Thread Agnostic
+ """
+ blobs = (
+ config.get(self.name(), "bin_blob_%i" % i)
+ for i in xrange(len(self._credentials))
+ )
+ creds = (
+ base64.b64decode(blob)
+ for blob in blobs
+ )
+ self._credentials = tuple(creds)
+
+ def save_settings(self, config):
+ """
+ @note Thread Agnostic
+ """
+ config.add_section(self.name())
+ for i, value in enumerate(self._credentials):
+ blob = base64.b64encode(value)
+ config.set(self.name(), "bin_blob_%i" % i, blob)
+
+ def login(self):
"""
@note UI Thread
"""
- self._manager = start_session(self._credentials)
+ if self._manager is not None:
+ return
+
+ credentials = self._credentials
+ while True:
+ try:
+ self._manager = rtmilk.RtMilkManager(*credentials)
+ self._credentials = credentials
+ return # Login succeeded
+ except rtmapi.AuthStateMachine.NoData:
+ # Login failed, grab new credentials
+ credentials = get_credentials(self._credentialsDialog)
+
+ def logout(self):
+ """
+ @note Thread Agnostic
+ """
+ self._credentials = "", "", ""
+ self._manager = None
+ def enable(self):
+ """
+ @note UI Thread
+ """
self._projectsList.clear()
self._populate_projects()
return currentProjectName
def _populate_items(self):
+ # @todo Look into using a button for notes and links, and labels for all else
currentProject = self._get_project()
projId = self._manager.lookup_project(currentProject)["id"]
for taskDetails in self._manager.get_tasks_with_details(projId):
def _on_item_select(self, treeView, path, viewColumn):
# @todo See if there is a way to get a right click / tap'n'hold for more task goodness
+ # https://garage.maemo.org/plugins/wiki/index.php?TapAndHold&id=40&type=g
taskId = self._itemList[path[0]][self.ID_IDX]
if viewColumn is self._priorityColumn: