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 <QLabel>
11#include <QDialogButtonBox>
12#include <QPushButton>
13#include <QHBoxLayout>
14#include <QVBoxLayout>
15#include <QVariant>
16
17namespace Marble {
18
19ConflictDialog::ConflictDialog( QWidget *parent ) :
20 QDialog( parent ),
21 m_mergeItem( nullptr ),
22 m_box( nullptr ),
23 m_resolveAction(ConflictDialog::AskUser)
24{
25 // nothing to do
26}
27
28void ConflictDialog::setMergeItem( MergeItem *item )
29{
30 m_mergeItem = item;
31}
32
33void ConflictDialog::stopAutoResolve()
34{
35 m_resolveAction = ConflictDialog::AskUser;
36}
37
38void ConflictDialog::open()
39{
40 if( m_mergeItem == nullptr ) {
41 return;
42 }
43
44 switch( m_resolveAction ) {
45 case ConflictDialog::AskUser:
46 prepareLayout();
48 break;
49 case ConflictDialog::PreferLocal:
50 m_mergeItem->setResolution( MergeItem::A );
51 emit resolveConflict( m_mergeItem );
52 break;
53 case ConflictDialog::PreferCloud:
54 m_mergeItem->setResolution( MergeItem::B );
55 emit resolveConflict( m_mergeItem );
56 break;
57 }
58}
59
60void ConflictDialog::resolveConflict( QAbstractButton *button )
61{
62 accept();
63
64 QDialogButtonBox::StandardButton standardButton = m_box->standardButton( button );
65 switch(standardButton) {
67 {
68 int actionRole = button->property( "ActionRole" ).toInt();
69 switch( actionRole ) {
70 case ConflictDialog::Local:
71 m_mergeItem->setResolution( MergeItem::A );
72 emit resolveConflict( m_mergeItem );
73 break;
74 case ConflictDialog::Cloud:
75 m_mergeItem->setResolution( MergeItem::B );
76 emit resolveConflict( m_mergeItem );
77 break;
78 case ConflictDialog::AllLocal:
79 m_mergeItem->setResolution( MergeItem::A );
80 m_resolveAction = ConflictDialog::PreferLocal;
81 emit resolveConflict( m_mergeItem );
82 break;
83 case ConflictDialog::AllCloud:
84 m_mergeItem->setResolution( MergeItem::B );
85 m_resolveAction = ConflictDialog::PreferCloud;
86 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 QPushButton *localButton = new QPushButton( tr( "Use local" ) );
105 QPushButton *cloudButton = new QPushButton( tr( "Use cloud" ) );
106 QPushButton *allLocalButton = new QPushButton( tr( "Always use local" ) );
107 QPushButton *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 QVBoxLayout *leftLayout = new QVBoxLayout();
121 QString localHeaderText = tr( "Local placemark" );
122 QString localDetailText = tr( "Path: %0 <br /> Name: %1 <br /> Description: %2 <br /> Status: %3" )
123 .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 QLabel *localHeaderLabel = new QLabel( localHeaderText );
136 QLabel *localDetailLabel = new QLabel( localDetailText );
137 leftLayout->addWidget( localHeaderLabel );
138 leftLayout->addWidget( localDetailLabel );
139
140 QVBoxLayout *rightLayout = new QVBoxLayout();
141 QString cloudHeaderText = tr( "Cloud placemark" );
142 QString cloudDetailText = tr( "Path: %0 <br /> Name: %1 <br /> Description: %2 <br /> Status: %3" )
143 .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 QLabel *cloudHeaderLabel = new QLabel( cloudHeaderText );
155 QLabel *cloudDetailLabel = new QLabel( cloudDetailText );
156 rightLayout->addWidget( cloudHeaderLabel );
157 rightLayout->addWidget( cloudDetailLabel );
158
159 QHBoxLayout *detailLayout = new QHBoxLayout();
160 detailLayout->addLayout( leftLayout );
161 detailLayout->addLayout( rightLayout );
162
163 QLabel *descriptionLabel = new QLabel();
164 QString descriptionText = tr( "A bookmark on this device conflicts " \
165 "with a cloud bookmark. Which one do " \
166 "you want to keep?" );
167 descriptionLabel->setText( descriptionText );
168
169 QVBoxLayout *mainLayout = new QVBoxLayout();
170 mainLayout->addWidget( descriptionLabel );
171 mainLayout->addLayout( detailLayout );
172 mainLayout->addWidget( m_box );
173
174 setLayout( mainLayout );
175 setWindowTitle( tr( "Synchronization Conflict" ) );
176
177 connect( m_box, SIGNAL(clicked(QAbstractButton*)),
178 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.
void addLayout(QLayout *layout, int stretch)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void open()
void setText(const QString &)
QVariant property(const char *name) const const
bool setProperty(const char *name, QVariant &&value)
void setDefault(bool)
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 Fri Jun 21 2024 12:00:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.