Example #1
0
 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()
Example #2
0
 def close_app(self):
     ny = popup_menu( [LABELS.loc.gm_yes, LABELS.loc.gm_no], LABELS.loc.wm_pmenu_exit )
     if ny is not None:
         if ny == 0:
             BLOG.save()
             self.clear_cache()
             Application.close_app(self)
Example #3
0
 def offline_publish(self):
     if BLOG.posts:
         idx = self.body.current()
         if BLOG.post_is_local(idx):
             self.lock_ui()
             BLOG.offline_publish(idx)
             self.unlock_ui()
             self.refresh()
Example #4
0
 def moderate(self):
     t = self.get_title()
     idx = app.body.current()
     self.lock_ui(LABELS.loc.cm_info_aprv_cmt % utf8_to_unicode( BLOG.comments[idx]['content'][:15] ))
     BLOG.approve_comment(idx)
     self.unlock_ui()
     self.set_title( t )
     self.refresh()
Example #5
0
 def blog_cbk(self):
     self.lock_ui()
     if not self.dlg.cancel:
         DB["blog_list"]=json.dumps(self.dlg.blogs)
         DB.save()
         BLOG.check_persistence(self.dlg.blogs)
     self.unlock_ui()
     self.refresh()
     return True
Example #6
0
    def update(self):
        self.lock_ui(LABELS.loc.pt_info_downld_pt)
        BLOG.update_posts_cats_and_tags()
        self.unlock_ui()            

        if not BLOG.posts:
            note(LABELS.loc.pt_info_no_posts, "info")
        
        self.refresh()
Example #7
0
 def delete(self):
     item = self.body.current()
     cat_name = self.headlines[item]
     ny = popup_menu([LABELS.loc.gm_no, LABELS.loc.gm_yes], LABELS.loc.ca_pmenu_delete % cat_name)
     if ny is not None:
         if ny == 1:
             self.lock_ui(LABELS.loc.ca_info_del_cat % cat_name)
             BLOG.delete_category(item)
             self.unlock_ui()
             self.refresh()
Example #8
0
 def contents(self):
     if BLOG.posts:
         idx = self.body.current()
         if self.download_contents(idx):
             publish = BLOG.posts[idx]['post_status'] == 'publish' # 'publish' or 'draft'
             self.dlg = EditPost(self.contents_cbk,
                                 BLOG.category_names_list(),
                                 BLOG.tag_names_list(),
                                 idx,
                                 publish)
             self.dlg.run()
Example #9
0
 def delete(self):
     if not BLOG.comments:
         note( LABELS.loc.cm_info_udt_cmts_lst, "info" )
         return
     
     ny = popup_menu( [LABELS.loc.gm_no, LABELS.loc.gm_yes], LABELS.loc.cm_pmenu_del_cmt)
     if ny == 1:
         idx = app.body.current()
         self.lock_ui(LABELS.loc.cm_info_del_cmt % utf8_to_unicode( BLOG.comments[idx]['content'][:15] ))
         BLOG.delete_comment(idx)
         
         self.unlock_ui()
         self.refresh()
Example #10
0
 def new(self):
     t = self.get_title()
     if not BLOG.comments:
         # no comments ... user need to select a post to add the comment
         if not BLOG.posts:
             self.lock_ui(LABELS.loc.cm_info_downld_pt)
             upd = BLOG.update_posts_cats_and_tags()
             self.set_title( t )
             self.unlock_ui()
             if not upd:
                 return False
     
         self.set_title(LABELS.loc.cm_info_which_post)
         post_idx = selection_list( [ utf8_to_unicode( p['title'] )[:70] for p in BLOG.posts ], search_field=1)
         # idx may be -1 if list is empty and user press OK... strange ... why not None ?
         if post_idx is None or post_idx == -1:
             return False
         post_id = BLOG.posts[post_idx]['postid']
         post_title = BLOG.posts[post_idx]['title']
     else:
         comment_idx = self.body.current()
         post_id = BLOG.comments[comment_idx]['post_id']
         post_title = BLOG.comments[comment_idx]['post_title']
         
     self.dlg = NewComment( self.new_cbk,
                            0,
                            post_id,
                            utf8_to_unicode(post_title))
     self.dlg.run()
Example #11
0
 def view_image(self, img):
     if os.path.isfile(img):
         local = True
     else:
         local = False
         
     if local:
         viewer = Content_handler(self.refresh)
         try:
             viewer.open(img)
         except:
             note(LABELS.loc.pt_err_cant_open % img,"error") 
     else:
         local_file = "img_" + time.strftime("%Y%m%d_%H%M%S", time.localtime())
         local_file = os.path.join(DEFDIR, "cache", local_file)
         d = img.rfind(".")
         if d >= 0:
             local_file = local_file + img[d:]
             self.lock_ui(LABELS.loc.pt_info_downld_img % img)
             try:
                 urlprx = UrllibProxy(BLOG.get_proxy())
                 urlprx.urlretrieve(img, local_file)
             except:
                 note(LABELS.loc.pt_err_cant_downld % img,"error")
                 self.unlock_ui()
                 return
             self.unlock_ui()
             viewer = Content_handler(self.refresh)
             try:
                 viewer.open(local_file)
             except:
                 note(LABELS.loc.pt_err_cant_open % img,"error") 
         else:
             note(LABELS.loc.pt_err_unknown_ext % img,"error")
Example #12
0
    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()
Example #13
0
    def refresh(self):
        Dialog.refresh(self) # must be called *before* 
        
        self.headlines = BLOG.category_names_list()
        self.last_idx = min( self.last_idx, len(self.headlines)-1 ) # avoiding problems after removing
        self.set_title( LABELS.loc.ca_info_cat_pos % ( self.body.current()+1,len(self.headlines) ) )

        self.body.set_list( self.headlines, self.last_idx )
Example #14
0
 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]()
Example #15
0
 def new(self):
     cat_name = query(LABELS.loc.ca_query_cat_name, "text", u"" )
     if cat_name is not None:
         self.lock_ui(LABELS.loc.ca_info_create_cat % cat_name)
         ret = BLOG.new_category( cat_name )
         self.unlock_ui()
         if ret:
             self.update()
         self.refresh()
Example #16
0
 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
Example #17
0
 def download_contents(self,idx):
     # if post was not totally retrieved yet, fetch all data
     # only call this function if you have posts
     if BLOG.posts[idx].has_key('description') == False:
         self.lock_ui(LABELS.loc.pt_info_downld_post)
         ok = BLOG.get_post(idx)
         self.unlock_ui()
         if not ok:
             note(LABELS.loc.pt_err_cant_pst_cont, "error")
             return False
         
     return True
Example #18
0
    def update_comment(self, post_idx, comment_status):
        """ Update comments for a given post (post_idx) with status comment_status
            post_idx = -1 means comments for all posts
        """
        BLOG.comments = []
        self.set_title(LABELS.loc.cm_info_downld_cmt)
        if not BLOG.get_comment(post_idx, self.status_list[comment_status]):
            return False

        if not BLOG.comments:
            note(LABELS.loc.cm_info_no_cmts_st % comment_status,"info")
            return False
  
        return True        
Example #19
0
 def new_cbk(self):
     if not self.dlg.cancel:
         self.lock_ui()
         # send to WP
         np = BLOG.new_post(self.dlg.post_title,
                            self.dlg.contents,
                            self.dlg.categories,
                            self.dlg.tags,
                            self.dlg.publish)
         self.unlock_ui()
         
         if np == -1:
             return False
     elif self.dlg.save:
         # just save
         BLOG.save_new_post(self.dlg.post_title,
                            self.dlg.contents,
                            self.dlg.categories,
                            self.dlg.tags,
                            self.dlg.publish)
         
     self.refresh()
     return True
Example #20
0
 def language(self):
     langs = [(LABELS.loc.st_menu_en_us, u"en_us"),
              (LABELS.loc.st_menu_pt_br, u"pt_br"),
              (LABELS.loc.st_menu_es, u"es"),
              (LABELS.loc.st_menu_tr, u"tr"),
              (LABELS.loc.st_menu_it, u"it"),
              (LABELS.loc.st_menu_nl, u"nl"),
              (LABELS.loc.st_menu_de, u"de"),
              (LABELS.loc.st_menu_ro, u"ro"),
              (LABELS.loc.st_menu_zh_cn, u"zh_cn"),
              (LABELS.loc.st_menu_fr, u"fr"),
              (LABELS.loc.st_menu_ru, u"ru"),
              (LABELS.loc.st_menu_id, u"id")]
     langs.sort()
     item = popup_menu(map(lambda x:x[0], langs), LABELS.loc.st_pmenu_lang )
     if item is not None:
         loc = langs[item][1]
         if DB["language"] != loc:
             LABELS.set_locale(loc)
             DB["language"] = loc
             DB.save()
             self.refresh()
             BLOG.refresh() # update global defines
             self.lang_changed = True
Example #21
0
    def refresh(self):
        Dialog.refresh(self) # must be called *before* 

        if not BLOG.posts:
            self.headlines = [ (LABELS.loc.pt_info_empty, LABELS.loc.pt_info_updt_pst_lst) ]
        else:
            self.headlines = []
            for p in BLOG.posts:
                status = u""
                (y, mo, d, h, m, s) = parse_iso8601(p['dateCreated'].value)
                if BLOG.post_is_only_local(p):
                    status = u"[@] "
                elif BLOG.post_is_local(p):
                    status = u"[*] "
                elif p.has_key('post_status'):
                    if p['post_status'] != 'publish':
                        status = u"[#]"

                line1 = status + u"%02d/%s/%02d  %02d:%02d " % (d,MONTHS[mo-1],y,h,m) 
                line2 = utf8_to_unicode(p['title'])
                self.headlines.append((line1 , line2))
                               
        self.last_idx = min(self.last_idx, len(self.headlines)-1) # avoiding problems after removing
        self.body.set_list(self.headlines, self.last_idx)
Example #22
0
 def new_cbk(self):
     if not self.dlg.cancel:
         self.lock_ui(LABELS.loc.cm_info_upld_cmt)
         ok = BLOG.new_comment(self.dlg.post_id,
                                        self.dlg.email,
                                        self.dlg.realname,
                                        self.dlg.website,
                                        self.dlg.contents)
         self.unlock_ui()
         
         if not ok:
             return False
     self.set_title(LABELS.loc.wm_menu_comm)
     self.refresh()
     return True
Example #23
0
 def contents_cbk(self):
     if not self.dlg.cancel:
         self.lock_ui()
         # send post to WP
         ok = BLOG.edit_post(self.dlg.post_title,
                             self.dlg.contents,
                             self.dlg.categories,
                             self.dlg.tags,
                             self.dlg.post_idx,
                             self.dlg.publish)
         self.unlock_ui()
         
         if not ok:
             return False
     elif self.dlg.save:
         # just save post
         BLOG.save_exist_post(self.dlg.post_title,
                              self.dlg.contents,
                              self.dlg.categories,
                              self.dlg.tags,
                              self.dlg.post_idx,
                              self.dlg.publish)
     self.refresh()
     return True
Example #24
0
 def contents_cbk(self):
     if not self.dlg.cancel:
         self.lock_ui(LABELS.loc.cm_info_updt_cmt)
         ok = BLOG.edit_comment(self.dlg.comment_idx,
                                         self.dlg.email,
                                         self.dlg.realname,
                                         self.dlg.website,
                                         self.dlg.contents)
         self.unlock_ui()
         
         if not ok:
             return False
         
     self.refresh()
     return True
Example #25
0
    def refresh(self):
        #Dialog.refresh(self) # must be called *before*        
        #self.headlines = BLOG.tag_names_list()
        Dialog.refresh(self) # must be called *before* 

        self.headlines = BLOG.tag_names_list()
        if not self.headlines:
            self.headlines = [ LABELS.loc.tg_info_udt_tags_lst ]
            
        #self.headlines = []
        #for t in BLOG.tags:
        #    line = u"%s (%s)" % (t['name'],t['count'])
        #    self.headlines.append(line)
                               
        self.last_idx = min( self.last_idx, len(self.headlines)-1 ) # avoiding problems after removing
        app.body.set_list( self.headlines, self.last_idx )

        
Example #26
0
    def update(self, post_idx=None):
        k = self.status_list.keys()
        item = popup_menu(k, LABELS.loc.cm_pmenu_cmt_status)
        if item is None:
            return False
        comment_status = k[item]

        t = self.get_title()
        if not BLOG.posts:
            self.lock_ui(LABELS.loc.cm_info_downld_pt)
            upd = BLOG.update_posts_cats_and_tags()
            self.set_title(t)
            self.unlock_ui()
            if not upd:
                self.refresh()
                return False

        if post_idx is None:
            comment_set = popup_menu([LABELS.loc.cm_list_one_post,
                                      LABELS.loc.cm_list_all_posts],
                                     LABELS.loc.cm_pmenu_updt_for)
            if comment_set is None:
                return False
            
            if comment_set == 0:
                self.set_title( LABELS.loc.cm_info_which_post )
                post_idx = selection_list([utf8_to_unicode( p['title'] )[:70] for p in BLOG.posts], search_field=1)
                self.set_title(t)
                if post_idx is None or post_idx == -1:
                    return False
            else:
                post_idx = -1

        self.lock_ui()
        upd = self.update_comment(post_idx, comment_status)
        self.set_title( LABELS.loc.wm_menu_comm )
        self.unlock_ui()
        self.refresh()
        
        return upd
Example #27
0
 def new(self):
     self.dlg = NewPost(self.new_cbk, u"", u"",
                        BLOG.category_names_list(), [],
                        BLOG.tag_names_list(), [],
                        True)
     self.dlg.run()
Example #28
0
    def upgrade(self):
        self.lock_ui(LABELS.loc.wm_info_check_updt)
        
        url = "http://code.google.com/p/wordmobi/wiki/LatestVersion"
        local_file = "web_" + time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".html"
        local_file = os.path.join(DEFDIR, "cache", local_file)

        try:
            urlprx = UrllibProxy(BLOG.get_proxy())
            urlprx.urlretrieve(url, local_file)
        except:
            note(LABELS.loc.wm_err_upd_page % url,"error")
            ok = False
        else:
            ok = True

        if ok:
            html = open(local_file).read()
            soup = BeautifulSoup( html )
            addrs = soup.findAll('a')
            version = ""
            file_url = ""
            file_url_py19 = ""
            for addr in addrs:
                if addr.contents[0] == "latest_wordmobi_version":
                    version = addr["href"]
                elif addr.contents[0] == "wordmobi_sis_url":
                    file_url = addr["href"]
                elif addr.contents[0] == "wordmobi_sis_url_py19":
                    file_url_py19 = addr["href"]

            if version and file_url and file_url_py19:
                version = version[version.rfind("/")+1:]
                num_rem_ver = self.ver2num(version)
                num_loc_ver = self.ver2num(VERSION)
                if (num_loc_ver >= num_rem_ver) and (VERSION.find('RC') == -1):
                    # RC versions gives to the user the upgrading decision
                    note(LABELS.loc.wm_info_ver_is_updt, "info")
                else:
                    yn = popup_menu( [LABELS.loc.gm_yes,LABELS.loc.gm_no],
                                     LABELS.loc.wm_pmenu_download % (version) )
                    if yn is not None:
                        if yn == 0:
                            if float(e32.pys60_version[:3]) >= 1.9:
                                furl = file_url_py19
                            else:
                                furl = file_url
                            sis_name = furl[furl.rfind("/")+1:]
                            local_file = os.path.join(DEFDIR, "updates", sis_name)

                            self.set_title( LABELS.loc.wm_info_downloading )
                            try:
                                urlprx = UrllibProxy(BLOG.get_proxy())
                                urlprx.urlretrieve(furl, local_file)
                            except:
                                note(LABELS.loc.wm_err_downld_fail % sis_name, "error")
                            else:
                                msg = LABELS.loc.wm_info_downld_ok % (sis_name,DEFDIR)
                                note( msg , "info")

            else:
                note(LABELS.loc.wm_err_upd_info,"error")
                
        self.set_title( u"Wordmobi" )
        self.unlock_ui()
        self.refresh()
Example #29
0
 def check_update_value(self):
     if not self.ui_is_locked():
         idx = self.body.current()
         BLOG.set_blog(idx)
         self.dlg = BlogManager(self.default_cbk,self.blogs[idx]['account'])
         self.dlg.run()
Example #30
0
    def update(self):
        self.lock_ui(LABELS.loc.tg_info_downld_tags)
        BLOG.update_tags()
        self.unlock_ui()

        self.refresh()