1 /*
2  * Copyright (C) by Kevin Ottens <kevin.ottens@nextcloud.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12  * for more details.
13  */
14 
15 #ifndef CONFLICTSOLVER_H
16 #define CONFLICTSOLVER_H
17 
18 #include <QObject>
19 
20 class QWidget;
21 
22 namespace OCC {
23 
24 class ConflictSolver : public QObject
25 {
26     Q_OBJECT
27     Q_PROPERTY(QString localVersionFilename READ localVersionFilename WRITE setLocalVersionFilename NOTIFY localVersionFilenameChanged)
28     Q_PROPERTY(QString remoteVersionFilename READ remoteVersionFilename WRITE setRemoteVersionFilename NOTIFY remoteVersionFilenameChanged)
29 public:
30     enum Solution {
31         KeepLocalVersion,
32         KeepRemoteVersion,
33         KeepBothVersions
34     };
35 
36     explicit ConflictSolver(QWidget *parent = nullptr);
37 
38     QString localVersionFilename() const;
39     QString remoteVersionFilename() const;
40 
41     bool exec(Solution solution);
42 
43 public slots:
44     void setLocalVersionFilename(const QString &localVersionFilename);
45     void setRemoteVersionFilename(const QString &remoteVersionFilename);
46 
47 signals:
48     void localVersionFilenameChanged();
49     void remoteVersionFilenameChanged();
50 
51 private:
52     bool deleteLocalVersion();
53     bool renameLocalVersion();
54     bool overwriteRemoteVersion();
55 
56     QWidget *_parentWidget;
57     QString _localVersionFilename;
58     QString _remoteVersionFilename;
59 };
60 
61 } // namespace OCC
62 
63 #endif // CONFLICTSOLVER_H
64