2023-05-02 14:55:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023 by Matthieu Gallien <matthieu.gallien@nextcloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2023-05-16 11:37:40 +03:00
|
|
|
#pragma once
|
2023-05-02 14:55:17 +03:00
|
|
|
|
|
|
|
#include "tray/activitydata.h"
|
|
|
|
|
2023-05-12 16:01:28 +03:00
|
|
|
#include "conflictsolver.h"
|
|
|
|
|
2023-05-02 14:55:17 +03:00
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QMimeDatabase>
|
|
|
|
#include <QLocale>
|
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
|
|
|
class SyncConflictsModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(OCC::ActivityList conflictActivities READ conflictActivities WRITE setConflictActivities NOTIFY conflictActivitiesChanged)
|
|
|
|
|
2023-05-12 14:17:38 +03:00
|
|
|
Q_PROPERTY(bool allExistingsSelected READ allExistingsSelected NOTIFY allExistingsSelectedChanged)
|
|
|
|
|
|
|
|
Q_PROPERTY(bool allConflictingSelected READ allConflictingSelected NOTIFY allConflictingSelectedChanged)
|
|
|
|
|
2023-05-02 14:55:17 +03:00
|
|
|
struct ConflictInfo {
|
2023-05-16 11:37:40 +03:00
|
|
|
enum class ConflictSolution : bool{
|
|
|
|
SolutionSelected = true,
|
|
|
|
SolutionDeselected = false,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-05-02 14:55:17 +03:00
|
|
|
QString mExistingFileName;
|
|
|
|
QString mExistingSize;
|
|
|
|
QString mConflictSize;
|
|
|
|
QString mExistingDate;
|
|
|
|
QString mConflictDate;
|
|
|
|
QUrl mExistingPreviewUrl;
|
|
|
|
QUrl mConflictPreviewUrl;
|
2023-05-16 11:37:40 +03:00
|
|
|
ConflictSolution mExistingSelected = ConflictSolution::SolutionDeselected;
|
|
|
|
ConflictSolution mConflictSelected = ConflictSolution::SolutionDeselected;
|
2023-05-12 16:01:28 +03:00
|
|
|
QString mExistingFilePath;
|
|
|
|
QString mConflictingFilePath;
|
|
|
|
|
|
|
|
[[nodiscard]] ConflictSolver::Solution solution() const;
|
|
|
|
[[nodiscard]] bool isValid() const;
|
2023-05-02 14:55:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum class SyncConflictRoles : int {
|
|
|
|
ExistingFileName = Qt::UserRole,
|
|
|
|
ExistingSize,
|
|
|
|
ConflictSize,
|
|
|
|
ExistingDate,
|
|
|
|
ConflictDate,
|
|
|
|
ExistingSelected,
|
|
|
|
ConflictSelected,
|
|
|
|
ExistingPreviewUrl,
|
|
|
|
ConflictPreviewUrl,
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_ENUM(SyncConflictRoles)
|
|
|
|
|
|
|
|
explicit SyncConflictsModel(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
[[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
|
|
|
|
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
|
|
|
2023-05-12 14:17:38 +03:00
|
|
|
[[nodiscard]] bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
|
|
|
|
2023-05-02 14:55:17 +03:00
|
|
|
[[nodiscard]] QHash<int,QByteArray> roleNames() const override;
|
|
|
|
|
2023-05-12 14:17:38 +03:00
|
|
|
[[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
|
|
|
|
|
2023-05-02 14:55:17 +03:00
|
|
|
[[nodiscard]] OCC::ActivityList conflictActivities() const;
|
|
|
|
|
2023-05-12 14:17:38 +03:00
|
|
|
[[nodiscard]] bool allExistingsSelected() const;
|
|
|
|
|
|
|
|
[[nodiscard]] bool allConflictingSelected() const;
|
|
|
|
|
2023-05-02 14:55:17 +03:00
|
|
|
public slots:
|
|
|
|
void setConflictActivities(OCC::ActivityList conflicts);
|
|
|
|
|
2023-05-12 14:17:38 +03:00
|
|
|
void selectAllExisting(bool selected);
|
|
|
|
|
|
|
|
void selectAllConflicting(bool selected);
|
|
|
|
|
2023-05-16 11:37:40 +03:00
|
|
|
void applySolution();
|
2023-05-12 16:01:28 +03:00
|
|
|
|
2023-05-02 14:55:17 +03:00
|
|
|
signals:
|
|
|
|
void conflictActivitiesChanged();
|
|
|
|
|
2023-05-12 14:17:38 +03:00
|
|
|
void allExistingsSelectedChanged();
|
|
|
|
|
|
|
|
void allConflictingSelectedChanged();
|
|
|
|
|
2023-05-02 14:55:17 +03:00
|
|
|
private:
|
|
|
|
void updateConflictsData();
|
|
|
|
|
2023-05-12 14:17:38 +03:00
|
|
|
void setExistingSelected(bool value,
|
|
|
|
const QModelIndex &index,
|
|
|
|
int role);
|
|
|
|
|
|
|
|
void setConflictingSelected(bool value,
|
|
|
|
const QModelIndex &index,
|
|
|
|
int role);
|
|
|
|
|
2023-05-16 11:37:40 +03:00
|
|
|
OCC::ActivityList _data;
|
2023-05-02 14:55:17 +03:00
|
|
|
|
2023-05-16 11:37:40 +03:00
|
|
|
QVector<ConflictInfo> _conflictData;
|
2023-05-02 14:55:17 +03:00
|
|
|
|
2023-05-16 11:37:40 +03:00
|
|
|
QLocale _locale;
|
2023-05-02 14:55:17 +03:00
|
|
|
|
2023-05-16 11:37:40 +03:00
|
|
|
bool _allExistingsSelected = false;
|
2023-05-12 14:17:38 +03:00
|
|
|
|
2023-05-16 11:37:40 +03:00
|
|
|
bool _allConflictingsSelected = false;
|
2023-05-02 14:55:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|