-
Notifications
You must be signed in to change notification settings - Fork 817
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
- Loading branch information
Showing
5 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "syncconflictsmodel.h" | ||
|
||
namespace OCC { | ||
|
||
SyncConflictsModel::SyncConflictsModel(QObject *parent) | ||
: QAbstractListModel(parent) | ||
{ | ||
} | ||
|
||
int SyncConflictsModel::rowCount(const QModelIndex &parent) const | ||
{ | ||
if (parent.isValid()) { | ||
return 0; | ||
} | ||
|
||
return mData.size(); | ||
} | ||
|
||
QVariant SyncConflictsModel::data(const QModelIndex &index, int role) const | ||
{ | ||
auto result = QVariant{}; | ||
|
||
Q_ASSERT(checkIndex(index, CheckIndexOption::IndexIsValid | CheckIndexOption::ParentIsInvalid)); | ||
|
||
if (!index.parent().isValid()) { | ||
return result; | ||
} | ||
|
||
if (role >= static_cast<int>(SyncConflictRoles::ExistingFileName) && role <= static_cast<int>(SyncConflictRoles::ConflictPreviewUrl)) { | ||
auto convertedRole = static_cast<SyncConflictRoles>(role); | ||
|
||
switch (convertedRole) { | ||
case SyncConflictRoles::ExistingFileName: | ||
result = mData[index.row()]._file; | ||
break; | ||
case SyncConflictRoles::ConflictFileName: | ||
break; | ||
case SyncConflictRoles::ExistingSize: | ||
break; | ||
case SyncConflictRoles::ConflictSize: | ||
break; | ||
case SyncConflictRoles::ExistingDate: | ||
break; | ||
case SyncConflictRoles::ConflictDate: | ||
break; | ||
case SyncConflictRoles::ExistingSelected: | ||
break; | ||
case SyncConflictRoles::ConflictSelected: | ||
break; | ||
case SyncConflictRoles::ExistingPreviewUrl: | ||
break; | ||
case SyncConflictRoles::ConflictPreviewUrl: | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
QHash<int, QByteArray> SyncConflictsModel::roleNames() const | ||
{ | ||
auto result = QAbstractListModel::roleNames(); | ||
|
||
result[static_cast<int>(SyncConflictRoles::ExistingFileName)] = "existingFileName"; | ||
result[static_cast<int>(SyncConflictRoles::ConflictFileName)] = "conflictFileName"; | ||
result[static_cast<int>(SyncConflictRoles::ExistingSize)] = "existingSize"; | ||
result[static_cast<int>(SyncConflictRoles::ConflictSize)] = "conflictSize"; | ||
result[static_cast<int>(SyncConflictRoles::ExistingDate)] = "existingDate"; | ||
result[static_cast<int>(SyncConflictRoles::ConflictDate)] = "conflictDate"; | ||
result[static_cast<int>(SyncConflictRoles::ExistingSelected)] = "existingSelected"; | ||
result[static_cast<int>(SyncConflictRoles::ConflictSelected)] = "conflictSelected"; | ||
result[static_cast<int>(SyncConflictRoles::ExistingPreviewUrl)] = "existingPreviewUrl"; | ||
result[static_cast<int>(SyncConflictRoles::ConflictPreviewUrl)] = "conflictPreviewUrl"; | ||
|
||
return result; | ||
} | ||
|
||
ActivityList SyncConflictsModel::conflictActivities() const | ||
{ | ||
return mData; | ||
} | ||
|
||
void SyncConflictsModel::setConflictActivities(ActivityList conflicts) | ||
{ | ||
if (mData == conflicts) { | ||
return; | ||
} | ||
|
||
beginResetModel(); | ||
|
||
mData = conflicts; | ||
emit conflictActivitiesChanged(); | ||
|
||
updateConflictsData(); | ||
|
||
endResetModel(); | ||
} | ||
|
||
void SyncConflictsModel::updateConflictsData() | ||
{ | ||
mConflictData.clear(); | ||
|
||
for (const auto &oneConflict : qAsConst(mData)) { | ||
auto newConflictData = ConflictInfo{}; | ||
|
||
const auto info = QFileInfo(oneConflict._file); | ||
// mtimeLabel->setText(info.lastModified().toString()); | ||
// sizeLabel->setText(locale().formattedDataSize(info.size())); | ||
|
||
// const auto mime = mimeDb.mimeTypeForFile(filename); | ||
// if (QIcon::hasThemeIcon(mime.iconName())) { | ||
// button->setIcon(QIcon::fromTheme(mime.iconName())); | ||
// } else { | ||
// button->setIcon(QIcon(":/qt-project.org/styles/commonstyle/images/file-128.png")); | ||
// } | ||
|
||
mConflictData.push_back(std::move(newConflictData)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#ifndef SYNCCONFLICTSMODEL_H | ||
#define SYNCCONFLICTSMODEL_H | ||
|
||
#include <QAbstractListModel> | ||
|
||
#include "tray/activitydata.h" | ||
|
||
namespace OCC { | ||
|
||
class SyncConflictsModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
|
||
Q_PROPERTY(OCC::ActivityList conflictActivities READ conflictActivities WRITE setConflictActivities NOTIFY conflictActivitiesChanged) | ||
|
||
struct ConflictInfo { | ||
}; | ||
|
||
public: | ||
enum class SyncConflictRoles : int { | ||
ExistingFileName = Qt::UserRole, | ||
ConflictFileName, | ||
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; | ||
|
||
[[nodiscard]] QHash<int,QByteArray> roleNames() const override; | ||
|
||
[[nodiscard]] OCC::ActivityList conflictActivities() const; | ||
|
||
public slots: | ||
void setConflictActivities(OCC::ActivityList conflicts); | ||
|
||
signals: | ||
void conflictActivitiesChanged(); | ||
|
||
private: | ||
void updateConflictsData(); | ||
|
||
OCC::ActivityList mData; | ||
|
||
QVector<ConflictInfo> mConflictData; | ||
}; | ||
|
||
} | ||
|
||
#endif // SYNCCONFLICTSMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) by Claudio Cambra <claudio.cambra@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. | ||
*/ | ||
|
||
#include "gui/syncconflictsmodel.h" | ||
|
||
#include <QTest> | ||
#include <QAbstractItemModelTester> | ||
#include <QSignalSpy> | ||
|
||
using namespace OCC; | ||
|
||
class TestSyncConflictsModel : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
private: | ||
|
||
private slots: | ||
void initTestCase() | ||
{ | ||
} | ||
|
||
void testSuccessfulFetchShares() | ||
{ | ||
SyncConflictsModel model; | ||
QAbstractItemModelTester modelTester(&model); | ||
|
||
OCC::ActivityList allConflicts; | ||
allConflicts.push_back(OCC::Activity{}); | ||
allConflicts.push_back(OCC::Activity{}); | ||
allConflicts.push_back(OCC::Activity{}); | ||
allConflicts.push_back(OCC::Activity{}); | ||
|
||
model.setConflictActivities(allConflicts); | ||
} | ||
|
||
}; | ||
|
||
QTEST_MAIN(TestSyncConflictsModel) | ||
#include "testsyncconflictsmodel.moc" |