Exemple #1
0
 def refreshServerStatus(self):
     """
         refresh server status and overall speed in the status bar
     """
     s = self.connector.statusServer()
     if s.pause:
         self.mainWindow.status.setText(_("paused"))
     else:
         self.mainWindow.status.setText(_("running"))
     self.mainWindow.speed.setText(formatSpeed(s.speed))
     self.mainWindow.space.setText(formatSize(self.serverStatus["freespace"]))
     self.mainWindow.actions["toggle_status"].setChecked(not s.pause)
Exemple #2
0
    def data(self, index, role=Qt.DisplayRole):
        """
            return cell data
        """
        if not index.isValid():
            return QVariant()
        if role == Qt.DisplayRole:
            if index.column() == 0:
                return QVariant(index.internalPointer().data["name"])
            elif index.column() == 1:
                item = index.internalPointer()
                plugins = []
                if isinstance(item, Package):
                    for child in item.children:
                        if not child.data["plugin"] in plugins:
                            plugins.append(child.data["plugin"])
                else:
                    plugins.append(item.data["plugin"])
                return QVariant(", ".join(plugins))
            elif index.column() == 2:
                item = index.internalPointer()
                status = 0
                speed = self.getSpeed(item)
                if isinstance(item, Package):
                    for child in item.children:
                        if child.data["status"] > status:
                            status = child.data["status"]
                else:
                    status = item.data["status"]

                if speed is None or status == 7 or status == 10 or status == 5:
                    return QVariant(
                        self.translateStatus(statusMapReverse[status]))
                else:
                    return QVariant("%s (%s)" % (self.translateStatus(
                        statusMapReverse[status]), formatSpeed(speed)))
            elif index.column() == 3:
                item = index.internalPointer()
                if isinstance(item, Link):
                    if item.data["status"] == 0:  #TODO needs change??
                        #self.getProgress(item, False) == 100:
                        return QVariant(formatSize(item.data["size"]))
                    elif self.getProgress(item, False) == 0:
                        try:
                            return QVariant(
                                "%s / %s" %
                                (formatSize(item.data["size"] -
                                            item.data["downloading"]["bleft"]),
                                 formatSize(item.data["size"])))
                        except:
                            return QVariant("0 B / %s" %
                                            formatSize(item.data["size"]))
                    else:
                        try:
                            return QVariant(
                                "%s / %s" %
                                (formatSize(item.data["size"] -
                                            item.data["downloading"]["bleft"]),
                                 formatSize(item.data["size"])))
                        except:
                            return QVariant("? / %s" %
                                            formatSize(item.data["size"]))
                else:
                    ms = 0
                    cs = 0
                    for c in item.children:
                        try:
                            s = c.data["downloading"]["size"]
                        except:
                            s = c.data["size"]
                        if c.data["downloading"]:
                            cs += s - c.data["downloading"]["bleft"]
                        elif self.getProgress(c, False) == 100:
                            cs += s
                        ms += s
                    if cs == 0 or cs == ms:
                        return QVariant(formatSize(ms))
                    else:
                        return QVariant("%s / %s" %
                                        (formatSize(cs), formatSize(ms)))
            elif index.column() == 4:
                item = index.internalPointer()
                if isinstance(item, Link):
                    if item.data["downloading"]:
                        return QVariant(item.data["downloading"]["format_eta"])
        elif role == Qt.EditRole:
            if index.column() == 0:
                return QVariant(index.internalPointer().data["name"])
        return QVariant()
Exemple #3
0
    def data(self, index, role=Qt.DisplayRole):
        """
            return cell data
        """
        if not index.isValid():
            return QVariant()
        if role == Qt.DisplayRole:
            if index.column() == 0:
                return QVariant(index.internalPointer().data["name"])
            elif index.column() == 1:
                item = index.internalPointer()
                plugins = []
                if isinstance(item, Package):
                    for child in item.children:
                        if not child.data["plugin"] in plugins:
                            plugins.append(child.data["plugin"])
                else:
                    plugins.append(item.data["plugin"])
                return QVariant(", ".join(plugins))
            elif index.column() == 2:
                item = index.internalPointer()
                status = 0
                speed = self.getSpeed(item)
                if isinstance(item, Package):
                    for child in item.children:
                        if child.data["status"] > status:
                            status = child.data["status"]
                else:
                    status = item.data["status"]
                
                if speed is None or status == 7 or status == 10 or status == 5:
                    return QVariant(self.translateStatus(statusMapReverse[status]))
                else:
                    return QVariant("%s (%s)" % (self.translateStatus(statusMapReverse[status]), formatSpeed(speed)))
            elif index.column() == 3:
                item = index.internalPointer()
                if isinstance(item, Link):
                    if item.data["status"] == 0: #TODO needs change??
		            #self.getProgress(item, False) == 100:
                        return QVariant(formatSize(item.data["size"]))
                    elif self.getProgress(item, False) == 0:
                        try:
                            return QVariant("%s / %s" % (formatSize(item.data["size"]-item.data["downloading"]["bleft"]), formatSize(item.data["size"])))
                        except:
                            return QVariant("0 B / %s" % formatSize(item.data["size"]))
                    else:
                        try:
                            return QVariant("%s / %s" % (formatSize(item.data["size"]-item.data["downloading"]["bleft"]), formatSize(item.data["size"])))
                        except:
                            return QVariant("? / %s" % formatSize(item.data["size"]))
                else:
                    ms = 0
                    cs = 0
                    for c in item.children:
                        try:
                            s = c.data["downloading"]["size"]
                        except:
                            s = c.data["size"]
                        if c.data["downloading"]:
                            cs += s - c.data["downloading"]["bleft"]
                        elif self.getProgress(c, False) == 100:
                            cs += s
                        ms += s
                    if cs == 0 or cs == ms:
                        return QVariant(formatSize(ms))
                    else:
                        return QVariant("%s / %s" % (formatSize(cs), formatSize(ms)))
            elif index.column() == 4:
                item = index.internalPointer()
                if isinstance(item, Link):
                    if item.data["downloading"]:
                        return QVariant(item.data["downloading"]["format_eta"])
        elif role == Qt.EditRole:
            if index.column() == 0:
                return QVariant(index.internalPointer().data["name"])
        return QVariant()
Exemple #4
0
 def paint(self, painter, option, index):
     option.rect.setHeight(59+16)
     option.rect.setWidth(self.parent.width()-20)
     
     #if option.state & QStyle.State_Selected:
     #    painter.fillRect(option.rect, option.palette.color(QPalette.Highlight))
     
     packagename = index.data(OverviewModel.PackageName).toString()
     partsf = index.data(OverviewModel.PartsFinished).toString()
     parts = index.data(OverviewModel.Parts).toString()
     eta = int(index.data(OverviewModel.ETA).toString())
     speed = index.data(OverviewModel.Speed).toString() or 0
     progress = int(index.data(OverviewModel.Progress).toString())
     currentSize = int(index.data(OverviewModel.CurrentSize).toString())
     maxSize = int(index.data(OverviewModel.MaxSize).toString())
     status = index.data(OverviewModel.Status).toString()
     
     def formatEta(seconds): #TODO add to utils
         if seconds <= 0: return ""
         hours, seconds = divmod(seconds, 3600)
         minutes, seconds = divmod(seconds, 60)
         return _("ETA: ") + "%.2i:%.2i:%.2i" % (hours, minutes, seconds)
     
     statusline = QString(_("Parts: ") + "%s/%s" % (partsf, parts))
     if partsf == parts:
         speedline = _("Finished")
     elif not status == _("Downloading"):
         speedline = QString(status)
     else:
         speedline = QString(formatEta(eta) + "     " + _("Speed: %s") % formatSpeed(speed))
     
     if progress in (0,100):
         sizeline = QString(_("Size:") + "%s" % formatSize(maxSize))
     else:
         sizeline = QString(_("Size:") + "%s / %s" % (formatSize(currentSize), formatSize(maxSize)))
     
     f = painter.font()
     f.setPointSize(12)
     f.setBold(True)
     painter.setFont(f)
     
     r = option.rect.adjusted(4, 4, -4, -4)
     painter.drawText(r.left(), r.top(), r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, packagename)
     newr = painter.boundingRect(r.left(), r.top(), r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, packagename)
     
     f.setPointSize(10)
     f.setBold(False)
     painter.setFont(f)
     
     painter.drawText(r.left(), newr.bottom()+5, r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, statusline)
     painter.drawText(r.left(), newr.bottom()+5, r.width(), r.height(), Qt.AlignTop | Qt.AlignHCenter, sizeline)
     painter.drawText(r.left(), newr.bottom()+5, r.width(), r.height(), Qt.AlignTop | Qt.AlignRight, speedline)
     newr = painter.boundingRect(r.left(), newr.bottom()+2, r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, statusline)
     newr.setTop(newr.bottom()+8)
     newr.setBottom(newr.top()+20)
     newr.setRight(self.parent.width()-25)
     
     f.setPointSize(10)
     painter.setFont(f)
     
     opts = QStyleOptionProgressBarV2()
     opts.maximum = 100
     opts.minimum = 0
     opts.progress = progress
     opts.rect = newr
     opts.textVisible = True
     opts.textAlignment = Qt.AlignCenter
     opts.text = QString.number(opts.progress) + "%"
     QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter)
Exemple #5
0
    def paint(self, painter, option, index):
        option.rect.setHeight(59 + 16)
        option.rect.setWidth(self.parent.width() - 20)

        #if option.state & QStyle.State_Selected:
        #    painter.fillRect(option.rect, option.palette.color(QPalette.Highlight))

        packagename = index.data(OverviewModel.PackageName).toString()
        partsf = index.data(OverviewModel.PartsFinished).toString()
        parts = index.data(OverviewModel.Parts).toString()
        eta = int(index.data(OverviewModel.ETA).toString())
        speed = index.data(OverviewModel.Speed).toString() or 0
        progress = int(index.data(OverviewModel.Progress).toString())
        currentSize = int(index.data(OverviewModel.CurrentSize).toString())
        maxSize = int(index.data(OverviewModel.MaxSize).toString())
        status = index.data(OverviewModel.Status).toString()

        def formatEta(seconds):  #TODO add to utils
            if seconds <= 0: return ""
            hours, seconds = divmod(seconds, 3600)
            minutes, seconds = divmod(seconds, 60)
            return _("ETA: ") + "%.2i:%.2i:%.2i" % (hours, minutes, seconds)

        statusline = QString(_("Parts: ") + "%s/%s" % (partsf, parts))
        if partsf == parts:
            speedline = _("Finished")
        elif not status == _("Downloading"):
            speedline = QString(status)
        else:
            speedline = QString(
                formatEta(eta) + "     " + _("Speed: %s") % formatSpeed(speed))

        if progress in (0, 100):
            sizeline = QString(_("Size:") + "%s" % formatSize(maxSize))
        else:
            sizeline = QString(
                _("Size:") + "%s / %s" %
                (formatSize(currentSize), formatSize(maxSize)))

        f = painter.font()
        f.setPointSize(12)
        f.setBold(True)
        painter.setFont(f)

        r = option.rect.adjusted(4, 4, -4, -4)
        painter.drawText(r.left(), r.top(), r.width(), r.height(),
                         Qt.AlignTop | Qt.AlignLeft, packagename)
        newr = painter.boundingRect(r.left(), r.top(), r.width(), r.height(),
                                    Qt.AlignTop | Qt.AlignLeft, packagename)

        f.setPointSize(10)
        f.setBold(False)
        painter.setFont(f)

        painter.drawText(r.left(),
                         newr.bottom() + 5, r.width(), r.height(),
                         Qt.AlignTop | Qt.AlignLeft, statusline)
        painter.drawText(r.left(),
                         newr.bottom() + 5, r.width(), r.height(),
                         Qt.AlignTop | Qt.AlignHCenter, sizeline)
        painter.drawText(r.left(),
                         newr.bottom() + 5, r.width(), r.height(),
                         Qt.AlignTop | Qt.AlignRight, speedline)
        newr = painter.boundingRect(r.left(),
                                    newr.bottom() + 2, r.width(), r.height(),
                                    Qt.AlignTop | Qt.AlignLeft, statusline)
        newr.setTop(newr.bottom() + 8)
        newr.setBottom(newr.top() + 20)
        newr.setRight(self.parent.width() - 25)

        f.setPointSize(10)
        painter.setFont(f)

        opts = QStyleOptionProgressBarV2()
        opts.maximum = 100
        opts.minimum = 0
        opts.progress = progress
        opts.rect = newr
        opts.textVisible = True
        opts.textAlignment = Qt.AlignCenter
        opts.text = QString.number(opts.progress) + "%"
        QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter)