예제 #1
0
void IssuesWidget::addError(const QString &folderAlias, const QString &message,
    ErrorCategory category)
{
    auto folder = FolderMan::instance()->folder(folderAlias);
    if (!folder)
        return;

    QStringList columns;
    QDateTime timestamp = QDateTime::currentDateTime();
    const QString timeStr = ProtocolItem::timeString(timestamp);
    const QString longTimeStr = ProtocolItem::timeString(timestamp, QLocale::LongFormat);

    columns << timeStr;
    columns << ""; // no "File" entry
    columns << folder->shortGuiLocalPath();
    columns << message;

    QIcon icon = Theme::instance()->syncStateIcon(SyncResult::Error);

    QTreeWidgetItem *twitem = new ProtocolItem(columns);
    twitem->setData(0, Qt::SizeHintRole, QSize(0, ActivityItemDelegate::rowHeight()));
    twitem->setData(0, Qt::UserRole, timestamp);
    twitem->setIcon(0, icon);
    twitem->setToolTip(0, longTimeStr);
    twitem->setData(2, Qt::UserRole, folderAlias);
    twitem->setToolTip(3, message);
    twitem->setData(3, Qt::UserRole, SyncFileItem::NormalError);

    addItem(twitem);
    addErrorWidget(twitem, message, category);
}
예제 #2
0
QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (role == Qt::EditRole)
        return QVariant();

    switch (classify(index)) {
    case AddButton: {
        if (role == FolderStatusDelegate::AddButton) {
            return QVariant(true);
        } else if (role == Qt::ToolTipRole) {
            if (!_accountState->isConnected()) {
                return tr("You need to be connected to add a folder");
            }
            return tr("Click this button to add a folder to synchronize.");
        }
        return QVariant();
    }
    case SubFolder: {
        const auto &x = static_cast<SubFolderInfo *>(index.internalPointer())->_subs[index.row()];
        switch (role) {
        case Qt::DisplayRole:
            //: Example text: "File.txt (23KB)"
            return x._size < 0 ? x._name : tr("%1 (%2)").arg(x._name, Utility::octetsToString(x._size));
        case Qt::ToolTipRole:
            return QString(QLatin1String("<qt>") + Utility::escape(x._size < 0 ? x._name : tr("%1 (%2)").arg(x._name, Utility::octetsToString(x._size))) + QLatin1String("</qt>"));
        case Qt::CheckStateRole:
            return x._checked;
        case Qt::DecorationRole:
            return QFileIconProvider().icon(x._isExternal ? QFileIconProvider::Network : QFileIconProvider::Folder);
        case Qt::ForegroundRole:
            if (x._isUndecided) {
                return QColor(Qt::red);
            }
            break;
        case FolderStatusDelegate::FolderPathRole: {
            auto f = x._folder;
            if (!f)
                return QVariant();
            return QVariant(f->path() + x._path);
        }
        }
    }
        return QVariant();
    case FetchLabel: {
        const auto x = static_cast<SubFolderInfo *>(index.internalPointer());
        switch (role) {
        case Qt::DisplayRole:
            if (x->_hasError) {
                return QVariant(tr("Error while loading the list of folders from the server.")
                    + QString("\n") + x->_lastErrorString);
            } else {
                return tr("Fetching folder list from server...");
            }
            break;
        default:
            return QVariant();
        }
    }
    case RootFolder:
        break;
    }

    const SubFolderInfo &folderInfo = _folders.at(index.row());
    auto f = folderInfo._folder;
    if (!f)
        return QVariant();

    const SubFolderInfo::Progress &progress = folderInfo._progress;
    const bool accountConnected = _accountState->isConnected();

    switch (role) {
    case FolderStatusDelegate::FolderPathRole:
        return f->shortGuiLocalPath();
    case FolderStatusDelegate::FolderSecondPathRole:
        return f->remotePath();
    case FolderStatusDelegate::FolderConflictMsg:
        return (f->syncResult().hasUnresolvedConflicts())
            ? QStringList(tr("There are unresolved conflicts. Click for details."))
            : QStringList();
    case FolderStatusDelegate::FolderErrorMsg:
        return f->syncResult().errorStrings();
    case FolderStatusDelegate::FolderInfoMsg:
        return f->useVirtualFiles()
            ? QStringList(tr("New files are being created as virtual files."))
            : QStringList();
    case FolderStatusDelegate::SyncRunning:
        return f->syncResult().status() == SyncResult::SyncRunning;
    case FolderStatusDelegate::HeaderRole:
        return f->shortGuiRemotePathOrAppName();
    case FolderStatusDelegate::FolderAliasRole:
        return f->alias();
    case FolderStatusDelegate::FolderSyncPaused:
        return f->syncPaused();
    case FolderStatusDelegate::FolderAccountConnected:
        return accountConnected;
    case Qt::ToolTipRole: {
        QString toolTip;
        if (!progress.isNull()) {
            return progress._progressString;
        }
        if (accountConnected)
            toolTip = Theme::instance()->statusHeaderText(f->syncResult().status());
        else
            toolTip = tr("Signed out");
        toolTip += "\n";
        toolTip += folderInfo._folder->path();
        return toolTip;
    }
    case FolderStatusDelegate::FolderStatusIconRole:
        if (accountConnected) {
            auto theme = Theme::instance();
            auto status = f->syncResult().status();
            if (f->syncPaused()) {
                return theme->folderDisabledIcon();
            } else {
                if (status == SyncResult::SyncPrepare) {
                    return theme->syncStateIcon(SyncResult::SyncRunning);
                } else if (status == SyncResult::Undefined) {
                    return theme->syncStateIcon(SyncResult::SyncRunning);
                } else {
                    // The "Problem" *result* just means some files weren't
                    // synced, so we show "Success" in these cases. But we
                    // do use the "Problem" *icon* for unresolved conflicts.
                    if (status == SyncResult::Success || status == SyncResult::Problem) {
                        if (f->syncResult().hasUnresolvedConflicts()) {
                            return theme->syncStateIcon(SyncResult::Problem);
                        } else {
                            return theme->syncStateIcon(SyncResult::Success);
                        }
                    } else {
                        return theme->syncStateIcon(status);
                    }
                }
            }
        } else {
            return Theme::instance()->folderOfflineIcon();
        }
    case FolderStatusDelegate::SyncProgressItemString:
        return progress._progressString;
    case FolderStatusDelegate::WarningCount:
        return progress._warningCount;
    case FolderStatusDelegate::SyncProgressOverallPercent:
        return progress._overallPercent;
    case FolderStatusDelegate::SyncProgressOverallString:
        return progress._overallSyncString;
    }
    return QVariant();
}