def send2twitter(self): """ Send a post title to twitter. Just must be called if twitter is enabled """ if BLOG.posts: idx = self.body.current() if BLOG.post_is_remote(idx): if self.download_contents(idx): self.lock_ui(LABELS.loc.pt_info_send_twt+u".") link = BLOG.posts[idx]['permaLink'] title = BLOG.posts[idx]['title'] api = s60twitter.TwitterApi(DB["twitter_user"], DB["twitter_pass"], BLOG.proxy) self.set_title(LABELS.loc.pt_info_send_twt+u"..") try: tiny_link = api.tinyfy_url(link) except: note(LABELS.loc.pt_err_cant_tiny_url,"error") else: msg = title[:140-len(tiny_link)-1] + " " + tiny_link # twitter: 140 chars max self.set_title(LABELS.loc.pt_info_send_twt+u"...") try: api.update(msg) except: note(LABELS.loc.pt_err_cant_send_twitter,"error") else: note(LABELS.loc.pt_info_twitter_updated,"info") self.set_title(u"") self.unlock_ui() self.refresh()
def delete(self): if BLOG.posts: idx = app.body.current() if BLOG.post_is_local(idx) and BLOG.post_is_remote(idx): # remote post with local changes - many delete option options = ((LABELS.loc.gm_no,lambda x: False), (LABELS.loc.pt_list_yes_rem_pst,BLOG.delete_only_remote_post), (LABELS.loc.pt_list_yes_loc_ch,BLOG.delete_only_local_post), (LABELS.loc.pt_list_yes_del_all,BLOG.delete_post)) else: # just local or remote - delete options = ((LABELS.loc.gm_no,lambda x: False), (LABELS.loc.gm_yes,BLOG.delete_post)) ny = popup_menu(map(lambda x:x[0],options),LABELS.loc.pt_pmenu_del_post) if ny is not None: if ny > 0: self.lock_ui(LABELS.loc.pt_info_del_post) funcs = map(lambda x:x[1],options) res = funcs[ny](idx) if res: note(LABELS.loc.pt_info_post_del,"info") else: note(LABELS.loc.pt_err_cant_del_pt,"error") self.unlock_ui() self.refresh()
def comments(self): def cbk(): self.refresh() return True if BLOG.posts: idx = app.body.current() if BLOG.post_is_remote(idx): self.dlg = Comments(cbk) self.dlg.run() self.dlg.update(idx) # update comments for current post
def popup_menu(self): idx = app.body.current() self.last_idx = idx menu = [(LABELS.loc.pt_menu_updt, self.update), (LABELS.loc.pt_menu_cnew, self.new)] if BLOG.posts: menu += [(LABELS.loc.pt_menu_view, self.contents), (LABELS.loc.pt_menu_dele, self.delete)] if BLOG.post_is_remote(idx): menu += [(LABELS.loc.pt_menu_lstc, self.comments)] if DB["twitter_enabled"] == u"True": menu += [(LABELS.loc.pt_menu_s2tw, self.send2twitter)] if BLOG.post_is_local(idx): menu += [(LABELS.loc.pt_menu_offl_publ,self.offline_publish)] op = popup_menu(map(lambda x: x[0], menu) , LABELS.loc.pt_pmenu_posts) if op is not None: map(lambda x: x[1], menu)[op]()