21 #include "conflictresolvedialog_p.h"
23 #include "abstractdifferencesreporter.h"
24 #include "differencesalgorithminterface.h"
25 #include "typepluginloader_p.h"
27 #include <QVBoxLayout>
30 #include <kcolorscheme.h>
32 #include <kpushbutton.h>
33 #include <ktextbrowser.h>
35 using namespace Akonadi;
37 static inline QString textToHTML(
const QString &text )
39 return Qt::convertFromPlainText( text );
45 HtmlDifferencesReporter()
49 QString toHtml()
const
51 return header() + mContent + footer();
54 void setPropertyNameTitle(
const QString &title )
59 void setLeftPropertyValueTitle(
const QString &title )
64 void setRightPropertyValueTitle(
const QString &title )
69 void addProperty( Mode mode,
const QString &name,
const QString &leftValue,
const QString &rightValue )
73 mContent.append( QString::fromLatin1(
"<tr><td align=\"right\"><b>%1:</b></td><td>%2</td><td></td><td>%3</td></tr>" )
75 textToHTML( leftValue ),
76 textToHTML( rightValue ) ) );
79 mContent.append( QString::fromLatin1(
"<tr><td align=\"right\"><b>%1:</b></td><td bgcolor=\"#ff8686\">%2</td><td></td><td bgcolor=\"#ff8686\">%3</td></tr>" )
81 textToHTML( leftValue ),
82 textToHTML( rightValue ) ) );
84 case AdditionalLeftMode:
85 mContent.append( QString::fromLatin1(
"<tr><td align=\"right\"><b>%1:</b></td><td bgcolor=\"#9cff83\">%2</td><td></td><td></td></tr>" )
87 textToHTML( leftValue ) ) );
89 case AdditionalRightMode:
90 mContent.append( QString::fromLatin1(
"<tr><td align=\"right\"><b>%1:</b></td><td></td><td></td><td bgcolor=\"#9cff83\">%2</td></tr>" )
92 textToHTML( rightValue ) ) );
98 QString header()
const
100 QString header = QLatin1String(
"<html>" );
101 header += QString::fromLatin1(
"<body text=\"%1\" bgcolor=\"%2\">" )
102 .arg( KColorScheme( QPalette::Active, KColorScheme::View ).foreground().color().name() )
103 .arg( KColorScheme( QPalette::Active, KColorScheme::View ).background().color().name() );
104 header += QLatin1String(
"<center><table>" );
105 header += QString::fromLatin1(
"<tr><th align=\"center\">%1</th><th align=\"center\">%2</th><td> </td><th align=\"center\">%3</th></tr>" )
113 QString footer()
const
115 return QLatin1String(
"</table></center>"
130 KGlobal::locale()->formatDateTime( localItem.
modificationTime(), KLocale::ShortDate, true ),
131 KGlobal::locale()->formatDateTime( otherItem.
modificationTime(), KLocale::ShortDate, true ) );
134 if ( localItem.
flags() != otherItem.
flags() ) {
135 QStringList localFlags;
136 foreach (
const QByteArray &localFlag, localItem.
flags() ) {
137 localFlags.append( QString::fromUtf8( localFlag ) );
140 QStringList otherFlags;
141 foreach (
const QByteArray &otherFlag, otherItem.
flags() ) {
142 otherFlags.append( QString::fromUtf8( otherFlag ) );
146 localFlags.join( QLatin1String(
", " ) ),
147 otherFlags.join( QLatin1String(
", " ) ) );
150 QHash<QByteArray, QByteArray> localAttributes;
152 localAttributes.insert( attribute->
type(), attribute->
serialized() );
155 QHash<QByteArray, QByteArray> otherAttributes;
157 otherAttributes.insert( attribute->
type(), attribute->
serialized() );
160 if ( localAttributes != otherAttributes ) {
161 foreach (
const QByteArray &localKey, localAttributes ) {
162 if ( !otherAttributes.contains( localKey ) ) {
164 QString::fromUtf8( localAttributes.value( localKey ) ),
167 const QByteArray localValue = localAttributes.value( localKey );
168 const QByteArray otherValue = otherAttributes.value( localKey );
169 if ( localValue != otherValue ) {
171 QString::fromUtf8( localValue ),
172 QString::fromUtf8( otherValue ) );
177 foreach (
const QByteArray &otherKey, otherAttributes ) {
178 if ( !localAttributes.contains( otherKey ) ) {
181 QString::fromUtf8( otherAttributes.value( otherKey ) ) );
190 setCaption( i18nc(
"@title:window",
"Conflict Resolution" ) );
191 setButtons( User1 | User2 | User3 );
192 setDefaultButton( User3 );
194 button( User3 )->setText( i18n(
"Take left one" ) );
195 button( User2 )->setText( i18n(
"Take right one" ) );
196 button( User1 )->setText( i18n(
"Keep both" ) );
198 connect(
this, SIGNAL(user1Clicked()), SLOT(slotUseBothItemsChoosen()) );
199 connect(
this, SIGNAL(user2Clicked()), SLOT(slotUseOtherItemChoosen()) );
200 connect(
this, SIGNAL(user3Clicked()), SLOT(slotUseLocalItemChoosen()) );
202 QWidget *mainWidget =
new QWidget;
203 QVBoxLayout *layout =
new QVBoxLayout( mainWidget );
205 QLabel* label =
new QLabel( i18nc(
"@label",
"Two updates conflict with each other.<nl/>Please choose which update(s) to apply." ), mainWidget );
206 layout->addWidget( label );
208 mView =
new KTextBrowser;
210 layout->addWidget( mView );
212 setMainWidget( mainWidget );
217 mLocalItem = localItem;
218 mOtherItem = otherItem;
220 HtmlDifferencesReporter reporter;
221 compareItems( &reporter, localItem, otherItem );
229 algorithm->
compare( &reporter, localItem, otherItem );
230 mView->setHtml( reporter.toHtml() );
235 reporter.addProperty( HtmlDifferencesReporter::NormalMode, i18n(
"Data" ),
240 mView->setHtml( reporter.toHtml() );
245 return mResolveStrategy;
248 void ConflictResolveDialog::slotUseLocalItemChoosen()
254 void ConflictResolveDialog::slotUseOtherItemChoosen()
260 void ConflictResolveDialog::slotUseBothItemsChoosen()
266 #include "moc_conflictresolvedialog_p.cpp"