Exemplo n.º 1
0
    def display_files(self, pcs_files):
        '''重新格式化一下文件列表, 去除不需要的信息

        这一操作主要是为了便于接下来的查找工作.
        文件的path都被提取出来, 然后放到了一个list中.
        '''
        tree_iters = []
        for pcs_file in pcs_files:
            path = pcs_file['path']
            pixbuf, type_ = self.app.mime.get(path,
                                              pcs_file['isdir'],
                                              icon_size=self.ICON_SIZE)
            name = os.path.split(path)[NAME_COL]
            tooltip = gutil.escape(name)
            size = pcs_file.get('size', 0)
            if pcs_file['isdir']:
                human_size = '--'
            else:
                human_size = util.get_human_size(pcs_file['size'])[0]
            mtime = pcs_file.get('server_mtime', 0)
            human_mtime = time.ctime(mtime)
            tree_iter = self.liststore.append([
                pixbuf, name, path, tooltip, size, human_size,
                pcs_file['isdir'], mtime, human_mtime, type_,
                json.dumps(pcs_file)
            ])
            tree_iters.append(tree_iter)
        cache_path = Config.get_cache_path(self.app.profile['username'])
        gutil.async_call(gutil.update_liststore_image, self.liststore,
                         tree_iters, PIXBUF_COL, pcs_files, cache_path,
                         self.ICON_SIZE)
Exemplo n.º 2
0
    def display_files(self, pcs_files):
        '''重新格式化一下文件列表, 去除不需要的信息

        这一操作主要是为了便于接下来的查找工作.
        文件的path都被提取出来, 然后放到了一个list中.
        '''
        tree_iters = []
        for pcs_file in pcs_files:
            path = pcs_file['path']
            pixbuf, type_ = self.app.mime.get(path, pcs_file['isdir'],
                                              icon_size=self.ICON_SIZE)
            name = os.path.split(path)[NAME_COL]
            tooltip = gutil.escape(name)
            size = pcs_file.get('size', 0)
            if pcs_file['isdir']:
                human_size = '--'
            else:
                human_size = util.get_human_size(pcs_file['size'])[0]
            mtime = pcs_file.get('server_mtime', 0)
            human_mtime = time.ctime(mtime)
            tree_iter = self.liststore.append([
                pixbuf, name, path, tooltip, size, human_size,
                pcs_file['isdir'], mtime, human_mtime, type_,
                json.dumps(pcs_file)
            ])
            tree_iters.append(tree_iter)
        cache_path = Config.get_cache_path(self.app.profile['username'])
        gutil.async_call(gutil.update_liststore_image, self.liststore,
                         tree_iters, PIXBUF_COL, pcs_files, cache_path,
                         self.ICON_SIZE)
Exemplo n.º 3
0
    def display_filelist(self, filelist):
        '''重新格式化一下文件列表, 去除不需要的信息

        这一操作主要是为了便于接下来的查找工作.
        文件的path都被提取出来, 然后放到了一个list中.
        '''
        if not filelist or filelist['errno'] != 0:
            return
        if 'list' in filelist:
            key = 'list'
        elif 'info' in filelist:
            key = 'info'
        else:
            print('Error: current filelist format not supported!')
            print(filelist)
            return
        cache_path = Config.get_cache_path(self.app.profile['username'])
        for pcs_file in filelist[key]:
            path = pcs_file['path']
            self.filelist.append(pcs_file)
            self.pathlist.append(path)
            pixbuf, type_ = self.app.mime.get(path, pcs_file['isdir'])
            disname = os.path.split(path)[DISNAME_COL]
            #tooltip = gutil.escape(disname)
            tooltip = disname
            tree_iter = self.liststore.append([
                pixbuf, disname, path, tooltip, type_
                ])
            gutil.update_liststore_image(
                self.liststore, tree_iter, PIXBUF_COL, pcs_file,
                cache_path,
                )
Exemplo n.º 4
0
        def on_load_url(filelist, error=None):
            self.url_entry.props.secondary_icon_name = REFRESH_ICON
            if timestamp != self.url_entry.timestamp:
                logger.debug("SharePage.load_url, dirname not match, ignored")
                return
            if error or not filelist:
                self.app.toast(_("Failed to get files, please reload this page"))
                logger.warn("SharePage.load_url: %s, %s, %s" % (self.curr_url, filelist, error))
                self.has_next = False
                return
            state = self.select_all_button.get_active()
            tree_iters = []

            # 插入.. 点击后返回上个目录
            if filelist and self.dirname and self.dirname != "/":
                parent_dirname = os.path.dirname(self.dirname)
                pixbuf, type_ = self.app.mime.get(parent_dirname, True, icon_size=ICON_SIZE)
                large_pixbuf, type_ = self.app.mime.get(parent_dirname, True, icon_size=LARGE_ICON_SIZE)
                self.liststore.append([state, pixbuf, large_pixbuf, "..", parent_dirname, True, 0, "0", 0, ""])

            for file_ in filelist:
                isdir = file_["isdir"] == "1"
                pixbuf, type_ = self.app.mime.get(file_["path"], isdir, icon_size=ICON_SIZE)
                large_pixbuf, type_ = self.app.mime.get(file_["path"], isdir, icon_size=LARGE_ICON_SIZE)
                size = int(file_.get("size", 0))
                human_size = util.get_human_size(size)[0]
                mtime = int(file_.get("server_mtime", 0))
                human_mtime = time.ctime(mtime)
                tree_iter = self.liststore.append(
                    [
                        state,
                        pixbuf,
                        large_pixbuf,
                        file_["server_filename"],
                        file_["path"],
                        isdir,
                        size,
                        human_size,
                        mtime,
                        human_mtime,
                    ]
                )
                tree_iters.append(tree_iter)
            cache_path = Config.get_cache_path(self.app.profile["username"])
            gutil.async_call(
                gutil.update_share_image,
                self.liststore,
                tree_iters,
                ICON_COL,
                LARGE_ICON_COL,
                filelist,
                cache_path,
                ICON_SIZE,
                LARGE_ICON_SIZE,
            )
Exemplo n.º 5
0
 def update_avatar(self):
     '''更新用户头像'''
     def do_update_avatar(img_path, error=None):
         if error or not img_path:
             logger.error('Failed to get user avatar: %s, %s' %
                          (img_path, error))
         else:
             self.img_avatar.set_from_file(img_path)
     cache_path = Config.get_cache_path(self.profile['username'])
     self.img_avatar.props.tooltip_text = self.profile['username']
     gutil.async_call(gutil.update_avatar, self.cookie, cache_path,
                      callback=do_update_avatar)
Exemplo n.º 6
0
    def display_files(self, pcs_files):
        '''重新格式化一下文件列表, 去除不需要的信息

        这一操作主要是为了便于接下来的查找工作.
        文件的path都被提取出来, 然后放到了一个list中.
        '''
        tree_iters = []

        md5Dict = {}
        for pcs_file in pcs_files:
            md5 = pcs_file.get('md5', "")
            if md5 in md5Dict:
                md5Dict[md5] += 1
            else:
                md5Dict[md5] = 1

        for pcs_file in pcs_files:
            path = pcs_file['path']
            pixbuf, type_ = self.app.mime.get(path, pcs_file['isdir'],
                                              icon_size=self.ICON_SIZE)
            name = os.path.split(path)[NAME_COL]
            tooltip = gutil.escape(name)
            size = pcs_file.get('size', 0)
            md5 = pcs_file.get('md5', "")

            if pcs_file['isdir']:
                human_size = '--'
                foregroundColor = "#3a5d96"
                count = 0
            else:
                human_size = util.get_human_size(pcs_file['size'])[0]
                count = md5Dict[md5]
                if count > 1:
                    foregroundColor = "#ff5050"
                else:
                    foregroundColor = "#2e2e2e"
            mtime = pcs_file.get('server_mtime', 0)
            human_mtime = time.ctime(mtime)
            fid = pcs_file.get('fs_id', 0)

            tree_iter = self.liststore.append([
                pixbuf, name, path, tooltip, size, human_size,
                pcs_file['isdir'], mtime, human_mtime, type_,
                json.dumps(pcs_file), fid, md5, foregroundColor, count
            ])
            tree_iters.append(tree_iter)

        cache_path = Config.get_cache_path(self.app.profile['username'])
        gutil.async_call(gutil.update_liststore_image, self.liststore,
                         tree_iters, PIXBUF_COL, pcs_files, cache_path,
                         self.ICON_SIZE)
Exemplo n.º 7
0
    def update_avatar(self):
        """更新用户头像"""

        def do_update_avatar(info, error=None):
            if error or not info:
                logger.error("Failed to get user avatar: %s, %s" % (info, error))
            else:
                uk, uname, img_path = info
                self.img_avatar.set_from_file(img_path)
                self.img_avatar.props.tooltip_text = "\n".join([self.profile["username"], uname])

        if not self.profile["display-avatar"]:
            return
        self.img_avatar.props.tooltip_text = ""
        cache_path = Config.get_cache_path(self.profile["username"])
        gutil.async_call(gutil.update_avatar, self.cookie, self.tokens, cache_path, callback=do_update_avatar)
Exemplo n.º 8
0
 def update_avatar(self):
     '''更新用户头像'''
     def do_update_avatar(info, error=None):
         if error or not info:
             logger.error('Failed to get user avatar: %s, %s' %
                          (info, error))
         else:
             uk, uname, img_path = info
             self.img_avatar.set_from_file(img_path)
             self.img_avatar.props.tooltip_text = '\n'.join([
                 self.profile['username'],
                 uname,
             ])
     self.img_avatar.props.tooltip_text = ''
     cache_path = Config.get_cache_path(self.profile['username'])
     gutil.async_call(gutil.update_avatar, self.cookie, self.tokens,
                      cache_path, callback=do_update_avatar)
Exemplo n.º 9
0
        def on_load_url(filelist, error=None):
            self.url_entry.props.secondary_icon_name = REFRESH_ICON
            if timestamp != self.url_entry.timestamp:
                logger.debug('SharePage.load_url, dirname not match, ignored')
                return
            if error:
                self.app.toast(
                    _('Failed to get files, please reload this page'))
                logger.warn('SharePage.load_url: %s, %s, %s' %
                            (self.curr_url, filelist, error))
                self.has_next = False
                return
            state = self.select_all_button.get_active()
            tree_iters = []

            # 插入.. 点击后返回上个目录
            if self.dirname and self.dirname != '/':
                parent_dirname = os.path.dirname(self.dirname)
                pixbuf, type_ = self.app.mime.get(parent_dirname,
                                                  True,
                                                  icon_size=ICON_SIZE)
                large_pixbuf, type_ = self.app.mime.get(
                    parent_dirname, True, icon_size=LARGE_ICON_SIZE)
                self.liststore.append([
                    state,
                    pixbuf,
                    large_pixbuf,
                    '..',
                    parent_dirname,
                    True,
                    0,
                    '0',
                    0,
                    '',
                ])

            for file_ in filelist:
                if file_['isdir'] == '1' or file_['isdir'] == 1:
                    isdir = True
                else:
                    isdir = False
                pixbuf, type_ = self.app.mime.get(file_['path'],
                                                  isdir,
                                                  icon_size=ICON_SIZE)
                large_pixbuf, type_ = self.app.mime.get(
                    file_['path'], isdir, icon_size=LARGE_ICON_SIZE)
                size = int(file_.get('size', 0))
                human_size = util.get_human_size(size)[0]
                mtime = int(file_.get('server_mtime', 0))
                human_mtime = time.ctime(mtime)
                tree_iter = self.liststore.append([
                    state,
                    pixbuf,
                    large_pixbuf,
                    file_['server_filename'],
                    file_['path'],
                    isdir,
                    size,
                    human_size,
                    mtime,
                    human_mtime,
                ])
                tree_iters.append(tree_iter)
            cache_path = Config.get_cache_path(self.app.profile['username'])
            gutil.async_call(gutil.update_share_image, self.liststore,
                             tree_iters, ICON_COL, LARGE_ICON_COL, filelist,
                             cache_path, ICON_SIZE, LARGE_ICON_SIZE)