repo-item-delegate.cpp (seafile-client-9.0.1) | : | repo-item-delegate.cpp (seafile-client-9.0.2) | ||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
#include "settings-mgr.h" | #include "settings-mgr.h" | |||
#include "api/server-repo.h" | #include "api/server-repo.h" | |||
#include "repo-item.h" | #include "repo-item.h" | |||
#include "repo-tree-view.h" | #include "repo-tree-view.h" | |||
#include "repo-tree-model.h" | #include "repo-tree-model.h" | |||
#include "rpc/rpc-client.h" | #include "rpc/rpc-client.h" | |||
#include "rpc/local-repo.h" | #include "rpc/local-repo.h" | |||
#include "account-mgr.h" | #include "account-mgr.h" | |||
#include "repo-service.h" | #include "repo-service.h" | |||
#include "QtAwesome.h" | #include "QtAwesome.h" | |||
#include "sync-error-service.h" | ||||
#include "utils/seafile-error.h" | ||||
#include "repo-item-delegate.h" | #include "repo-item-delegate.h" | |||
namespace { | namespace { | |||
/** | /** | |||
RepoName | RepoName | |||
RepoIcon statusIcon | RepoIcon statusIcon | |||
subtitle | subtitle | |||
*/ | */ | |||
skipping to change at line 224 | skipping to change at line 226 | |||
int indent_left = 0; | int indent_left = 0; | |||
if (item->level() > 0) { | if (item->level() > 0) { | |||
indent_left = kRepoCategoryIndicatorWidth + kMarginBetweenIndicatorAndNa me; | indent_left = kRepoCategoryIndicatorWidth + kMarginBetweenIndicatorAndNa me; | |||
} | } | |||
// Paint repo icon | // Paint repo icon | |||
QPoint repo_icon_pos(kMarginLeft + kPadding + indent_left, kRepoItemVertical Margin); | QPoint repo_icon_pos(kMarginLeft + kPadding + indent_left, kRepoItemVertical Margin); | |||
repo_icon_pos += option.rect.topLeft(); | repo_icon_pos += option.rect.topLeft(); | |||
// get the device pixel radio from current painter device | // get the device pixel radio from current painter device | |||
int scale_factor = 1; | int scale_factor = painter->device()->devicePixelRatio(); | |||
scale_factor = painter->device()->devicePixelRatio(); | ||||
QPixmap repo_icon = repo.getIcon().pixmap(QSize(kRepoIconWidthAlpha, kRepoIc onHeightAlpha)); | QPixmap repo_icon = repo.getIcon().pixmap(QSize(kRepoIconWidthAlpha, kRepoIc onHeightAlpha)); | |||
QRect repo_icon_rect(repo_icon_pos, QSize(kRepoIconWidthAlpha, kRepoIconHeig htAlpha)); | QRect repo_icon_rect(repo_icon_pos, QSize(kRepoIconWidthAlpha, kRepoIconHeig htAlpha)); | |||
painter->save(); | painter->save(); | |||
painter->drawPixmap(repo_icon_rect, repo_icon); | painter->drawPixmap(repo_icon_rect, repo_icon); | |||
painter->restore(); | painter->restore(); | |||
// Paint repo name | // Paint repo name | |||
int vertical_margin_between_icon_and_name = 0; | int vertical_margin_between_icon_and_name = 0; | |||
#ifdef Q_OS_WIN32 | #ifdef Q_OS_WIN32 | |||
skipping to change at line 260 | skipping to change at line 261 | |||
painter->setFont(changeFontSize(painter->font(), kRepoNameFontSize)); | painter->setFont(changeFontSize(painter->font(), kRepoNameFontSize)); | |||
painter->drawText(repo_name_rect, | painter->drawText(repo_name_rect, | |||
Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, | Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, | |||
fitTextToWidth(repo.name, painter->font(), repo_name_width ), | fitTextToWidth(repo.name, painter->font(), repo_name_width ), | |||
&repo_name_rect); | &repo_name_rect); | |||
painter->restore(); | painter->restore(); | |||
// Paint repo description | // Paint repo description | |||
QString description; | QString description; | |||
const LocalRepo& r = item->localRepo(); | const LocalRepo& r = item->localRepo(); | |||
int repo_err_id = LastSyncError::instance()->getRepoSyncError(r.id); | ||||
if (r.isValid()) { | if (r.isValid()) { | |||
if (r.sync_state == LocalRepo::SYNC_STATE_ING) { | if (r.sync_state == LocalRepo::SYNC_STATE_ING) { | |||
description = r.sync_state_str; | description = r.sync_state_str; | |||
if (r.has_data_transfer) { | if (r.has_data_transfer) { | |||
int rate, percent; | int rate, percent; | |||
if (seafApplet->rpcClient()->getRepoTransferInfo(r.id, &rate, &p ercent) == 0) { | if (seafApplet->rpcClient()->getRepoTransferInfo(r.id, &rate, &p ercent) == 0) { | |||
description += ", " + QString::number(percent) + "%"; | description += ", " + QString::number(percent) + "%"; | |||
} | } | |||
} | } | |||
} else if (r.sync_state == LocalRepo::SYNC_STATE_ERROR) { | } else if (r.sync_state == LocalRepo::SYNC_STATE_ERROR) { | |||
description = r.getErrorString(); | description = r.getErrorString(); | |||
} else if (r.sync_state == LocalRepo::SYNC_STATE_DONE && repo_err_id >= | ||||
0) { | ||||
description = translateSyncErrorCode(repo_err_id); | ||||
} | } | |||
} else { | } else { | |||
const CloneTask& task = item->cloneTask(); | const CloneTask& task = item->cloneTask(); | |||
if (task.isValid() && task.isDisplayable()) { | if (task.isValid() && task.isDisplayable()) { | |||
if (task.error_str.length() > 0) { | if (task.error_str.length() > 0) { | |||
description = task.error_str; | description = task.error_str; | |||
} else { | } else { | |||
description = task.state_str; | description = task.state_str; | |||
} | } | |||
} | } | |||
skipping to change at line 336 | skipping to change at line 340 | |||
&repo_owner_rect); | &repo_owner_rect); | |||
painter->restore(); | painter->restore(); | |||
} | } | |||
// Paint repo status icon | // Paint repo status icon | |||
QPoint status_icon_pos = option.rect.topRight() - QPoint(41, 0); | QPoint status_icon_pos = option.rect.topRight() - QPoint(41, 0); | |||
status_icon_pos.setY(option.rect.center().y() - (kRepoStatusIconHeightAlpha / 2)); | status_icon_pos.setY(option.rect.center().y() - (kRepoStatusIconHeightAlpha / 2)); | |||
QRect status_icon_rect(status_icon_pos, QSize(kRepoStatusIconWidthAlpha, kRe poStatusIconHeightAlpha)); | QRect status_icon_rect(status_icon_pos, QSize(kRepoStatusIconWidthAlpha, kRe poStatusIconHeightAlpha)); | |||
QPixmap status_icon_pixmap = getSyncStatusIcon(item).pixmap(status_icon_rect .size()); | QPixmap status_icon_pixmap = getSyncStatusIcon(item, repo_err_id).pixmap(sta tus_icon_rect.size()); | |||
painter->save(); | painter->save(); | |||
painter->drawPixmap(status_icon_rect, status_icon_pixmap); | painter->drawPixmap(status_icon_rect, status_icon_pixmap); | |||
painter->restore(); | painter->restore(); | |||
// Update the metrics of this item | // Update the metrics of this item | |||
RepoItem::Metrics metrics; | RepoItem::Metrics metrics; | |||
QPoint shift(-option.rect.topLeft().x(), -option.rect.topLeft().y()); | QPoint shift(-option.rect.topLeft().x(), -option.rect.topLeft().y()); | |||
metrics.icon_rect = repo_icon_rect; | metrics.icon_rect = repo_icon_rect; | |||
metrics.name_rect = repo_name_rect; | metrics.name_rect = repo_name_rect; | |||
skipping to change at line 390 | skipping to change at line 394 | |||
int repo_category_text_height = ::textHeightInFont(item->name(), changeFontS ize(option.font, kRepoCategoryNameFontSize)); | int repo_category_text_height = ::textHeightInFont(item->name(), changeFontS ize(option.font, kRepoCategoryNameFontSize)); | |||
int vertical_padding_between_indicator_and_name = (repo_category_text_height - kRepoCategoryIndicatorHeight) / 2; | int vertical_padding_between_indicator_and_name = (repo_category_text_height - kRepoCategoryIndicatorHeight) / 2; | |||
// [(size of category icon) - (size of repo icon)] / 2 | // [(size of category icon) - (size of repo icon)] / 2 | |||
int indicator_offset = (24 - 20) / 2; | int indicator_offset = (24 - 20) / 2; | |||
QRect indicator_rect(option.rect.topLeft() + | QRect indicator_rect(option.rect.topLeft() + | |||
QPoint(kPadding + indicator_offset + kMarginLeft + inde nt_left, | QPoint(kPadding + indicator_offset + kMarginLeft + inde nt_left, | |||
kRepoCategoryVerticalMargin + vertical_padding_b etween_indicator_and_name), | kRepoCategoryVerticalMargin + vertical_padding_b etween_indicator_and_name), | |||
QSize(kRepoCategoryIndicatorWidth, kRepoCategoryIndicat orHeight)); | QSize(kRepoCategoryIndicatorWidth, kRepoCategoryIndicat orHeight)); | |||
// get the device pixel radio from current painter device | // get the device pixel radio from current painter device | |||
int scale_factor = 1; | int scale_factor = painter->device()->devicePixelRatio(); | |||
scale_factor = painter->device()->devicePixelRatio(); | ||||
QIcon icon(expanded ? awesome->icon(icon_caret_down, kRepoCategoryIndicatorC olor) | QIcon icon(expanded ? awesome->icon(icon_caret_down, kRepoCategoryIndicatorC olor) | |||
: awesome->icon(icon_caret_right, kRepoCategoryIndicator Color)); | : awesome->icon(icon_caret_right, kRepoCategoryIndicator Color)); | |||
QPixmap icon_pixmap(icon.pixmap(QSize(kRepoCategoryIndicatorWidth, kRepoCate goryIndicatorWidth))); | QPixmap icon_pixmap(icon.pixmap(QSize(kRepoCategoryIndicatorWidth, kRepoCate goryIndicatorWidth))); | |||
painter->drawPixmap(indicator_rect, icon_pixmap); | painter->drawPixmap(indicator_rect, icon_pixmap); | |||
painter->restore(); | painter->restore(); | |||
// Paint category name | // Paint category name | |||
// calculate the count of synced repos | // calculate the count of synced repos | |||
skipping to change at line 451 | skipping to change at line 454 | |||
QRect category_count_rect(category_count_pos, | QRect category_count_rect(category_count_pos, | |||
option.rect.bottomRight() - QPoint(kRepoCategoryCo untMarginRightAlpha, kRepoCategoryVerticalMargin)); | option.rect.bottomRight() - QPoint(kRepoCategoryCo untMarginRightAlpha, kRepoCategoryVerticalMargin)); | |||
painter->setFont(changeFontSize(option.font, kRepoCategoryCountFontSizeAlpha )); | painter->setFont(changeFontSize(option.font, kRepoCategoryCountFontSizeAlpha )); | |||
painter->setPen(QColor(kRepoCategoryCountColor)); | painter->setPen(QColor(kRepoCategoryCountColor)); | |||
painter->drawText(category_count_rect, | painter->drawText(category_count_rect, | |||
Qt::AlignLeft | Qt::AlignTop, | Qt::AlignLeft | Qt::AlignTop, | |||
category_count_text); | category_count_text); | |||
painter->restore(); | painter->restore(); | |||
} | } | |||
QIcon RepoItemDelegate::getSyncStatusIcon(const RepoItem *item) const | QIcon RepoItemDelegate::getSyncStatusIcon(const RepoItem *item, int err_id) cons t | |||
{ | { | |||
const QString prefix = ":/images/sync/"; | const QString prefix = ":/images/sync/"; | |||
const LocalRepo& repo = item->localRepo(); | const LocalRepo& repo = item->localRepo(); | |||
QString icon; | QString icon; | |||
if (!repo.isValid()) { | if (!repo.isValid()) { | |||
icon = "cloud-unsynced"; | icon = "cloud-unsynced"; | |||
} else if (!seafApplet->settingsManager()->autoSync()) { | } else if (!seafApplet->settingsManager()->autoSync()) { | |||
icon = "pause"; | icon = "pause"; | |||
} else if (repo.sync_state == LocalRepo::SYNC_STATE_DONE && err_id >= 0) { | ||||
icon = "exclamation"; | ||||
} else { | } else { | |||
switch (repo.sync_state) { | switch (repo.sync_state) { | |||
case LocalRepo::SYNC_STATE_DONE: | case LocalRepo::SYNC_STATE_DONE: | |||
icon = "cloud-synced"; | icon = "cloud-synced"; | |||
break; | break; | |||
case LocalRepo::SYNC_STATE_ING: | case LocalRepo::SYNC_STATE_ING: | |||
icon = "cloud-sync"; | icon = "cloud-sync"; | |||
break; | break; | |||
case LocalRepo::SYNC_STATE_ERROR: | case LocalRepo::SYNC_STATE_ERROR: | |||
icon = "exclamation"; | icon = "exclamation"; | |||
End of changes. 8 change blocks. | ||||
6 lines changed or deleted | 12 lines changed or added |