kpilot Library API Documentation

resolutionDialog.cc

00001 /* resolutionDialog.h           KPilot
00002 **
00003 ** Copyright (C) 2002-2003 by Reinhold Kainhofer
00004 **
00005 ** See the .cc file for an explanation of what this file is for.
00006 */
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU General Public License as published by
00011 ** the Free Software Foundation; either version 2 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00022 ** MA 02111-1307, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
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     /* fResItem is only set for the controller */
00069     ResolutionItem*fResItem;
00070     bool isController;
00071     /* The description of the entry, e.g. Backup, PC, Palm for the radio buttons,
00072      * of the field name for the controllers
00073      */
00074     QString fCaption;
00075     /* The currrent value of the entry (for controllers this changes with the
00076      * selected button */
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         // If all three texts are identical, there is no need for
00093         // resolution so don't show the radio items below
00094         bool itemsEqual=true;
00095         QString testtext(QString::null);
00096         const enum eExistItems its[3]={eExistsPC, eExistsPalm, eExistsBackup};
00097         // get a valid text from a valid field, which will serve as the
00098         // test text for the comparison
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                 // Add only existing items
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         // tickle the palm every 10 seconds to prevent a timeout until the
00204         // sync is really finished.
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  *  Destroys the object and frees any allocated resources
00325  */
00326 ResolutionDlg::~ResolutionDlg()
00327 {
00328     // no need to delete child widgets, Qt does it all for us
00329 }
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:49 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003