00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "options.h"
00030 #include "resolutionDialog.moc"
00031
00032 #include <qcheckbox.h>
00033 #include <qtimer.h>
00034 #include <qlayout.h>
00035 #include <qlabel.h>
00036 #include <qradiobutton.h>
00037 #include <qpushbutton.h>
00038 #include <qlistview.h>
00039 #include <qgroupbox.h>
00040 #include <qregexp.h>
00041
00042 #include <kpilotlink.h>
00043 #include "abbrowser-conduit.h"
00044 #include "resolutionTable.h"
00045 #include "resolutionDialog_base.h"
00046 #include <typeinfo>
00047
00055 class ResolutionCheckListItem : QCheckListItem {
00056 public:
00057 ResolutionCheckListItem(ResolutionItem*it, ResolutionTable*tb,
00058 QListView*parent);
00059 ResolutionCheckListItem(QString header, QString text,
00060 ResolutionCheckListItem*parent);
00061 ~ResolutionCheckListItem() {};
00062 virtual void stateChange(bool newstate);
00063 virtual void setValue(QString text);
00064 virtual void setCaption(QString caption);
00065
00066 protected:
00067 void updateText();
00068
00069 ResolutionItem*fResItem;
00070 bool isController;
00071
00072
00073
00074 QString fCaption;
00075
00076
00077 QString fText;
00078 };
00079
00080
00081 ResolutionCheckListItem::ResolutionCheckListItem(ResolutionItem*it,
00082 ResolutionTable*tb, QListView*parent) :
00083 QCheckListItem(parent, "", QCheckListItem::Controller),
00084 fResItem(it),
00085 isController(true),
00086 fCaption(it?(it->fName):(QString::null)),
00087 fText(it?(it->fResolved):(QString::null))
00088 {
00089 FUNCTIONSETUP
00090 if (it && tb)
00091 {
00092
00093
00094 bool itemsEqual=true;
00095 QString testtext(QString::null);
00096 const enum eExistItems its[3]={eExistsPC, eExistsPalm, eExistsBackup};
00097
00098
00099 for (int i=0; i<3; i++)
00100 {
00101 if ((testtext.isNull()) && (it->fExistItems & its[i]) )
00102 testtext=it->fEntries[i];
00103 }
00104 for (int i=0; i<3; i++)
00105 {
00106 if (it->fExistItems & its[i])
00107 itemsEqual&=(it->fEntries[i]==testtext);
00108 }
00109 if (!itemsEqual)
00110 {
00111 ResolutionCheckListItem*item;
00112 for (int i=2; i>=0; i--)
00113 {
00114
00115 if (it->fExistItems & its[i])
00116 {
00117 item=new ResolutionCheckListItem(it->fEntries[i], tb->labels[i], this);
00118 item->setOn(it->fEntries[i]==fText);
00119 }
00120 }
00121 }
00122 updateText();
00123 }
00124 setOpen(true);
00125 }
00126
00127 ResolutionCheckListItem::ResolutionCheckListItem(QString text, QString header,
00128 ResolutionCheckListItem*parent) :
00129 QCheckListItem(parent, "", QCheckListItem::RadioButton),
00130 fResItem(0L),
00131 isController(false),
00132 fCaption(header),
00133 fText(text)
00134 {
00135 updateText();
00136 }
00137
00138 void ResolutionCheckListItem::stateChange(bool newstate)
00139 {
00140 if (newstate && !isController)
00141 {
00142 ResolutionCheckListItem*par=static_cast<ResolutionCheckListItem*>(parent());
00143 {
00144 par->setValue(fText);
00145 }
00146 }
00147 }
00148
00149 void ResolutionCheckListItem::setValue(QString text)
00150 {
00151 FUNCTIONSETUP;
00152 fText=text;
00153 if (isController && fResItem)
00154 {
00155 fResItem->fResolved=text;
00156 }
00157 updateText();
00158 }
00159
00160 void ResolutionCheckListItem::setCaption(QString caption)
00161 {
00162 fCaption=caption;
00163 updateText();
00164 }
00165
00166 void ResolutionCheckListItem::updateText()
00167 {
00168 QString newText(i18n("Entries in the resolution dialog. First the name of the field, then the entry from the Handheld or PC after the colon", "%1: %2").arg(fCaption).arg(fText));
00169 newText.replace(QRegExp("\n"),
00170 i18n("Denoting newlines in Address entries. No need to translate", " | "));
00171 setText(0, newText);
00172 }
00173
00174
00175
00176
00177
00178
00179
00180 ResolutionDlg::ResolutionDlg( QWidget* parent, KPilotDeviceLink*fH,
00181 QString caption, QString helpText, ResolutionTable*tab) :
00182 KDialogBase( parent, "ResolutionDlg", false, caption, Apply|Cancel, Apply),
00183 tickleTimer(0L),
00184 fHandle(fH),
00185 fTable(tab)
00186 {
00187 fWidget = new ResolutionDialogBase( this );
00188 setMainWidget(fWidget);
00189 fTable->fResolution=SyncAction::eDoNothing;
00190 fWidget->fIntroText->setText(helpText);
00191
00192 adjustSize();
00193 resize(size());
00194
00195 fillListView();
00196 adjustButtons(tab);
00197
00198 if (fHandle) tickleTimer=new QTimer(this, "TickleTimer");
00199
00200 if (tickleTimer)
00201 {
00202 connect( tickleTimer, SIGNAL(timeout()), this, SLOT(_tickle()));
00203
00204
00205 tickleTimer->start( 10000 );
00206 }
00207
00208 connect(fWidget->fKeepBoth, SIGNAL(clicked()), SLOT(slotKeepBoth()));
00209 connect(fWidget->fBackupValues, SIGNAL(clicked()), SLOT(slotUseBackup()));
00210 connect(fWidget->fPalmValues, SIGNAL(clicked()), SLOT(slotUsePalm()));
00211 connect(fWidget->fPCValues, SIGNAL(clicked()), SLOT(slotUsePC()));
00212 }
00213
00214 void ResolutionDlg::adjustButtons(ResolutionTable*tab)
00215 {
00216 FUNCTIONSETUP;
00217 if (!tab) return;
00218 if (!(tab->fExistItems & eExistsPC) )
00219 {
00220 fWidget->fPCValues->setText("Delete entry");
00221 fWidget->fKeepBoth->setDisabled(TRUE);
00222 fWidget->fKeepBoth->hide();
00223 }
00224 if (!(tab->fExistItems & eExistsPalm) )
00225 {
00226 fWidget->fPalmValues->setText("Delete entry");
00227 fWidget->fKeepBoth->setDisabled(TRUE);
00228 fWidget->fKeepBoth->hide();
00229 }
00230 if (!(tab->fExistItems & eExistsBackup) )
00231 {
00232 fWidget->fBackupValues->setDisabled(TRUE);
00233 }
00234 }
00235
00236 void ResolutionDlg::fillListView()
00237 {
00238 FUNCTIONSETUP;
00239 fWidget->fResolutionView->setSorting(-1, FALSE);
00240 fWidget->fResolutionView->clear();
00241 for ( ResolutionItem* it = fTable->last(); it; it = fTable->prev() )
00242 {
00243 #ifdef DEBUG
00244 DEBUGCONDUIT<<"Building table, items="<<it->fExistItems<<", PC="<<
00245 it->fEntries[0]<<", Palm="<<it->fEntries[1]<<", Backup="<<
00246 it->fEntries[2]<<endl;
00247 #endif
00248 bool hasValidValues=false;
00249 if (it->fExistItems & eExistsPC)
00250 hasValidValues = hasValidValues || !(it->fEntries[0].isEmpty());
00251 if (it->fExistItems & eExistsPalm)
00252 hasValidValues = hasValidValues || !(it->fEntries[1].isEmpty());
00253 if (it->fExistItems & eExistsBackup)
00254 hasValidValues = hasValidValues || !(it->fEntries[2].isEmpty());
00255 if (hasValidValues)
00256 new ResolutionCheckListItem(it, fTable, fWidget->fResolutionView);
00257 }
00258 }
00259
00260 void ResolutionDlg::slotKeepBoth()
00261 {
00262 if ( (fTable->fExistItems & eExistsPC) && (fTable->fExistItems & eExistsPalm) )
00263 {
00264 fTable->fResolution=SyncAction::eDuplicate;
00265 }
00266 else
00267 {
00268 fTable->fResolution=SyncAction::eDoNothing;
00269 }
00270 done(fTable->fResolution);
00271 }
00272
00273 void ResolutionDlg::slotUseBackup()
00274 {
00275 if (fTable->fExistItems & eExistsBackup)
00276 {
00277 fTable->fResolution=SyncAction::ePreviousSyncOverrides;
00278 }
00279 else
00280 {
00281 fTable->fResolution=SyncAction::eDoNothing;
00282 }
00283 done(fTable->fResolution);
00284 }
00285
00286 void ResolutionDlg::slotUsePalm()
00287 {
00288 if (fTable->fExistItems & eExistsPalm)
00289 {
00290 fTable->fResolution=SyncAction::eHHOverrides;
00291 }
00292 else
00293 {
00294 fTable->fResolution=SyncAction::eDelete;
00295 }
00296 done(fTable->fResolution);
00297 }
00298
00299 void ResolutionDlg::slotUsePC()
00300 {
00301 if (fTable->fExistItems & eExistsPC)
00302 {
00303 fTable->fResolution=SyncAction::ePCOverrides;
00304 }
00305 else
00306 {
00307 fTable->fResolution=SyncAction::eDelete;
00308 }
00309 done(fTable->fResolution);
00310 }
00311
00312 void ResolutionDlg::slotApply()
00313 {
00314 fTable->fResolution=SyncAction::eAskUser;
00315 done(fTable->fResolution);
00316 }
00317
00318 void ResolutionDlg::_tickle()
00319 {
00320 if (fHandle) fHandle->tickle();
00321 }
00322
00323
00324
00325
00326 ResolutionDlg::~ResolutionDlg()
00327 {
00328
00329 }