Marble

ConflictDialog.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2013 Utku Aydın <utkuaydin34@gmail.com>
4//
5
6#include "ConflictDialog.h"
7
8#include "MergeItem.h"
9
10#include <QDialogButtonBox>
11#include <QHBoxLayout>
12#include <QLabel>
13#include <QPushButton>
14#include <QVBoxLayout>
15#include <QVariant>
16
17namespace Marble
18{
19
20ConflictDialog::ConflictDialog(QWidget *parent)
21 : QDialog(parent)
22 , m_mergeItem(nullptr)
23 , m_box(nullptr)
24 , m_resolveAction(ConflictDialog::AskUser)
25{
26 // nothing to do
27}
28
29void ConflictDialog::setMergeItem(MergeItem *item)
30{
31 m_mergeItem = item;
32}
33
34void ConflictDialog::stopAutoResolve()
35{
36 m_resolveAction = ConflictDialog::AskUser;
37}
38
39void ConflictDialog::open()
40{
41 if (m_mergeItem == nullptr) {
42 return;
43 }
44
45 switch (m_resolveAction) {
46 case ConflictDialog::AskUser:
47 prepareLayout();
49 break;
50 case ConflictDialog::PreferLocal:
51 m_mergeItem->setResolution(MergeItem::A);
52 Q_EMIT resolveConflict(m_mergeItem);
53 break;
54 case ConflictDialog::PreferCloud:
55 m_mergeItem->setResolution(MergeItem::B);
56 Q_EMIT resolveConflict(m_mergeItem);
57 break;
58 }
59}
60
61void ConflictDialog::resolveConflict(QAbstractButton *button)
62{
63 accept();
64
65 QDialogButtonBox::StandardButton standardButton = m_box->standardButton(button);
66 switch (standardButton) {
68 int actionRole = button->property("ActionRole").toInt();
69 switch (actionRole) {
70 case ConflictDialog::Local:
71 m_mergeItem->setResolution(MergeItem::A);
72 Q_EMIT resolveConflict(m_mergeItem);
73 break;
74 case ConflictDialog::Cloud:
75 m_mergeItem->setResolution(MergeItem::B);
76 Q_EMIT resolveConflict(m_mergeItem);
77 break;
78 case ConflictDialog::AllLocal:
79 m_mergeItem->setResolution(MergeItem::A);
80 m_resolveAction = ConflictDialog::PreferLocal;
81 Q_EMIT resolveConflict(m_mergeItem);
82 break;
83 case ConflictDialog::AllCloud:
84 m_mergeItem->setResolution(MergeItem::B);
85 m_resolveAction = ConflictDialog::PreferCloud;
86 Q_EMIT resolveConflict(m_mergeItem);
87 break;
88 default:
89 break;
90 }
91 }
92
93 default:
94 break;
95 }
96}
97
98void ConflictDialog::prepareLayout()
99{
100 delete layout();
101 qDeleteAll(children());
103
104 auto localButton = new QPushButton(tr("Use local"));
105 auto cloudButton = new QPushButton(tr("Use cloud"));
106 auto allLocalButton = new QPushButton(tr("Always use local"));
107 auto allCloudButton = new QPushButton(tr("Always use cloud"));
108
109 localButton->setDefault(true);
110 localButton->setProperty("ActionRole", ConflictDialog::Local);
111 cloudButton->setProperty("ActionRole", ConflictDialog::Cloud);
112 allLocalButton->setProperty("ActionRole", ConflictDialog::AllLocal);
113 allCloudButton->setProperty("ActionRole", ConflictDialog::AllCloud);
114
115 m_box->addButton(localButton, QDialogButtonBox::ActionRole);
116 m_box->addButton(cloudButton, QDialogButtonBox::ActionRole);
117 m_box->addButton(allLocalButton, QDialogButtonBox::ActionRole);
118 m_box->addButton(allCloudButton, QDialogButtonBox::ActionRole);
119
120 auto leftLayout = new QVBoxLayout();
121 QString localHeaderText = tr("Local placemark");
122 QString localDetailText =
123 tr("Path: %0 <br /> Name: %1 <br /> Description: %2 <br /> Status: %3").arg(m_mergeItem->pathA(), m_mergeItem->nameA(), m_mergeItem->descriptionA());
124 switch (m_mergeItem->actionA()) {
125 case MergeItem::Changed:
126 localDetailText = localDetailText.arg(tr("Changed"));
127 break;
128 case MergeItem::Deleted:
129 localDetailText = localDetailText.arg(tr("Deleted"));
130 break;
131 default:
132 break;
133 }
134
135 auto localHeaderLabel = new QLabel(localHeaderText);
136 auto localDetailLabel = new QLabel(localDetailText);
137 leftLayout->addWidget(localHeaderLabel);
138 leftLayout->addWidget(localDetailLabel);
139
140 auto rightLayout = new QVBoxLayout();
141 QString cloudHeaderText = tr("Cloud placemark");
142 QString cloudDetailText =
143 tr("Path: %0 <br /> Name: %1 <br /> Description: %2 <br /> Status: %3").arg(m_mergeItem->pathB(), m_mergeItem->nameB(), m_mergeItem->descriptionB());
144 switch (m_mergeItem->actionB()) {
145 case MergeItem::Changed:
146 cloudDetailText = cloudDetailText.arg(tr("Changed"));
147 break;
148 case MergeItem::Deleted:
149 cloudDetailText = cloudDetailText.arg(tr("Deleted"));
150 break;
151 default:
152 break;
153 }
154 auto cloudHeaderLabel = new QLabel(cloudHeaderText);
155 auto cloudDetailLabel = new QLabel(cloudDetailText);
156 rightLayout->addWidget(cloudHeaderLabel);
157 rightLayout->addWidget(cloudDetailLabel);
158
159 auto detailLayout = new QHBoxLayout();
160 detailLayout->addLayout(leftLayout);
161 detailLayout->addLayout(rightLayout);
162
163 auto descriptionLabel = new QLabel();
164 QString descriptionText =
165 tr("A bookmark on this device conflicts "
166 "with a cloud bookmark. Which one do "
167 "you want to keep?");
168 descriptionLabel->setText(descriptionText);
169
170 auto mainLayout = new QVBoxLayout();
171 mainLayout->addWidget(descriptionLabel);
172 mainLayout->addLayout(detailLayout);
173 mainLayout->addWidget(m_box);
174
175 setLayout(mainLayout);
176 setWindowTitle(tr("Synchronization Conflict"));
177
178 connect(m_box, SIGNAL(clicked(QAbstractButton *)), this, SLOT(resolveConflict(QAbstractButton *)));
179}
180
181}
182
183#include "moc_ConflictDialog.cpp"
Binds a QML item to a specific geodetic location in screen coordinates.
virtual void open()
QVariant property(const char *name) const const
QString arg(Args &&... args) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
int toInt(bool *ok) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.