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 <klocalizedstring.h>
34 #include <kpushbutton.h>
35 #include <ktextbrowser.h>
37 using namespace Akonadi;
39 static inline QString textToHTML(
const QString &text )
41 return Qt::convertFromPlainText( text );
47 HtmlDifferencesReporter()
51 QString toHtml()
const
53 return header() + mContent + footer();
56 void setPropertyNameTitle(
const QString &title )
61 void setLeftPropertyValueTitle(
const QString &title )
66 void setRightPropertyValueTitle(
const QString &title )
71 void addProperty( Mode mode,
const QString &name,
const QString &leftValue,
const QString &rightValue )
75 mContent.append( QString::fromLatin1(
"<tr><td align=\"right\"><b>%1:</b></td><td>%2</td><td></td><td>%3</td></tr>" )
77 textToHTML( leftValue ),
78 textToHTML( rightValue ) ) );
81 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>" )
83 textToHTML( leftValue ),
84 textToHTML( rightValue ) ) );
86 case AdditionalLeftMode:
87 mContent.append( QString::fromLatin1(
"<tr><td align=\"right\"><b>%1:</b></td><td bgcolor=\"#9cff83\">%2</td><td></td><td></td></tr>" )
89 textToHTML( leftValue ) ) );
91 case AdditionalRightMode:
92 mContent.append( QString::fromLatin1(
"<tr><td align=\"right\"><b>%1:</b></td><td></td><td></td><td bgcolor=\"#9cff83\">%2</td></tr>" )
94 textToHTML( rightValue ) ) );
100 QString header()
const
102 QString header = QLatin1String(
"<html>" );
103 header += QString::fromLatin1(
"<body text=\"%1\" bgcolor=\"%2\">" )
104 .arg( KColorScheme( QPalette::Active, KColorScheme::View ).foreground().color().name() )
105 .arg( KColorScheme( QPalette::Active, KColorScheme::View ).background().color().name() );
106 header += QLatin1String(
"<center><table>" );
107 header += QString::fromLatin1(
"<tr><th align=\"center\">%1</th><th align=\"center\">%2</th><td> </td><th align=\"center\">%3</th></tr>" )
115 QString footer()
const
117 return QLatin1String(
"</table></center>"
132 KGlobal::locale()->formatDateTime( localItem.
modificationTime(), KLocale::ShortDate, true ),
133 KGlobal::locale()->formatDateTime( otherItem.
modificationTime(), KLocale::ShortDate, true ) );
136 if ( localItem.
flags() != otherItem.
flags() ) {
137 QStringList localFlags;
138 foreach (
const QByteArray &localFlag, localItem.
flags() ) {
139 localFlags.append( QString::fromUtf8( localFlag ) );
142 QStringList otherFlags;
143 foreach (
const QByteArray &otherFlag, otherItem.
flags() ) {
144 otherFlags.append( QString::fromUtf8( otherFlag ) );
148 localFlags.join( QLatin1String(
", " ) ),
149 otherFlags.join( QLatin1String(
", " ) ) );
152 QHash<QByteArray, QByteArray> localAttributes;
154 localAttributes.insert( attribute->
type(), attribute->
serialized() );
157 QHash<QByteArray, QByteArray> otherAttributes;
159 otherAttributes.insert( attribute->
type(), attribute->
serialized() );
162 if ( localAttributes != otherAttributes ) {
163 foreach (
const QByteArray &localKey, localAttributes ) {
164 if ( !otherAttributes.contains( localKey ) ) {
166 QString::fromUtf8( localAttributes.value( localKey ) ),
169 const QByteArray localValue = localAttributes.value( localKey );
170 const QByteArray otherValue = otherAttributes.value( localKey );
171 if ( localValue != otherValue ) {
173 QString::fromUtf8( localValue ),
174 QString::fromUtf8( otherValue ) );
179 foreach (
const QByteArray &otherKey, otherAttributes ) {
180 if ( !localAttributes.contains( otherKey ) ) {
183 QString::fromUtf8( otherAttributes.value( otherKey ) ) );
192 setCaption( i18nc(
"@title:window",
"Conflict Resolution" ) );
193 setButtons( User1 | User2 | User3 );
194 setDefaultButton( User3 );
196 button( User3 )->setText( i18n(
"Take left one" ) );
197 button( User2 )->setText( i18n(
"Take right one" ) );
198 button( User1 )->setText( i18n(
"Keep both" ) );
200 connect(
this, SIGNAL(user1Clicked()), SLOT(slotUseBothItemsChoosen()) );
201 connect(
this, SIGNAL(user2Clicked()), SLOT(slotUseOtherItemChoosen()) );
202 connect(
this, SIGNAL(user3Clicked()), SLOT(slotUseLocalItemChoosen()) );
204 QWidget *mainWidget =
new QWidget;
205 QVBoxLayout *layout =
new QVBoxLayout( mainWidget );
207 QLabel* label =
new QLabel( i18nc(
"@label",
"Two updates conflict with each other.<nl/>Please choose which update(s) to apply." ), mainWidget );
208 layout->addWidget( label );
210 mView =
new KTextBrowser;
212 layout->addWidget( mView );
214 setMainWidget( mainWidget );
219 mLocalItem = localItem;
220 mOtherItem = otherItem;
222 HtmlDifferencesReporter reporter;
223 compareItems( &reporter, localItem, otherItem );
231 algorithm->
compare( &reporter, localItem, otherItem );
232 mView->setHtml( reporter.toHtml() );
237 reporter.addProperty( HtmlDifferencesReporter::NormalMode, i18n(
"Data" ),
242 mView->setHtml( reporter.toHtml() );
247 return mResolveStrategy;
250 void ConflictResolveDialog::slotUseLocalItemChoosen()
256 void ConflictResolveDialog::slotUseOtherItemChoosen()
262 void ConflictResolveDialog::slotUseBothItemsChoosen()
268 #include "moc_conflictresolvedialog_p.cpp"