kpilot

doc-conflictdialog.cc

Go to the documentation of this file.
00001 /* KPilot
00002 **
00003 ** Copyright (C) 2002 by Reinhold Kainhofer
00004 **
00005 */
00006 
00007 /*
00008 ** This program is free software; you can redistribute it and/or modify
00009 ** it under the terms of the GNU General Public License as published by
00010 ** the Free Software Foundation; either version 2 of the License, or
00011 ** (at your option) any later version.
00012 **
00013 ** This program is distributed in the hope that it will be useful,
00014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016 ** GNU General Public License for more details.
00017 **
00018 ** You should have received a copy of the GNU General Public License
00019 ** along with this program in a file called COPYING; if not, write to
00020 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00021 ** MA 02110-1301, USA.
00022 */
00023 
00024 /*
00025 ** Bug reports and questions can be sent to kde-pim@kde.org
00026 */
00027 
00028 #include "options.h"
00029 #include "doc-conflictdialog.moc"
00030 
00031 #include <qlabel.h>
00032 #include <qpushbutton.h>
00033 #include <qlayout.h>
00034 #include <qbuttongroup.h>
00035 #include <kmessagebox.h>
00036 #include <qtimer.h>
00037 #include <qtable.h>
00038 #include <qcombobox.h>
00039 #include <qscrollview.h>
00040 
00041 
00042 ResolutionDialog::ResolutionDialog( QWidget* parent, const QString& caption, syncInfoList*sinfo, KPilotLink*lnk )
00043     : KDialogBase( parent, "resolutionDialog", true, caption, KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true), tickleTimer(0L), fHandle(lnk) {
00044     FUNCTIONSETUP;
00045     syncInfo=sinfo;
00046     hasConflicts=false;
00047 
00048     QWidget *page = new QWidget( this );
00049     setMainWidget(page);
00050     QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00051 
00052     // First, insert the texts on top:
00053     textLabel1 = new QLabel(i18n("Here is a list of all text files and DOC databases the conduit found. The conduit tried to determine the correct sync direction, but for databases in bold red letters a conflict occurred (i.e. the text was changed both on the desktop and on the handheld). For these databases please specify which version is the current one."), page);
00054     textLabel1->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) );
00055     topLayout->addWidget(textLabel1);
00056 
00057     textLabel2 = new QLabel(i18n("You can also change the sync direction for databases without a conflict." ),  page );
00058     textLabel2->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) );
00059     topLayout->addWidget(textLabel2);
00060 
00061     resolutionGroupBox = new QGroupBox(i18n("DOC Databases"), page );
00062     QVBoxLayout*playout = new QVBoxLayout(resolutionGroupBox);
00063     QScrollView* sv = new QScrollView(resolutionGroupBox);
00064     playout->addWidget(sv);
00065     sv->setResizePolicy(QScrollView::AutoOneFit);
00066     sv->setHScrollBarMode(QScrollView::AlwaysOff);
00067     sv->setMargin(5);
00068     QFrame* big_box = new QFrame(sv->viewport());
00069     sv->addChild(big_box);
00070 
00071 
00072     resolutionGroupBoxLayout = new QGridLayout( big_box, syncInfo->size(), 3 );
00073     resolutionGroupBoxLayout->setAlignment( Qt::AlignTop );
00074 
00075     // Invisible button group for the information buttons to use the same slot for all of them (see Dallheimer's book, page 309f)
00076     QButtonGroup *bgroup = new QButtonGroup( this );
00077     bgroup->hide();
00078     QObject::connect(bgroup, SIGNAL(clicked(int)), this, SLOT(slotInfo(int)));
00079 
00080     if (syncInfo) {
00081         DEBUGKPILOT<<"Adding resolution options for the databases "<<endl;
00082         syncInfoList::Iterator it;
00083         int nr=0;
00084         DEBUGKPILOT<<"We're having "<<(*syncInfo).size()<<" entries in the database list"<<endl;
00085         for (it=syncInfo->begin(); it!=syncInfo->end(); ++it ) {
00086             docSyncInfo si=(*it);
00087             conflictEntry cE;
00088             cE.index=nr;
00089             cE.conflict=(si.direction==eSyncConflict);
00090             DEBUGKPILOT<<"Adding "<<si.handheldDB<<" to the conflict resolution dialog"<<endl;
00091 
00092             QString text=si.handheldDB;
00093             if  (cE.conflict) {
00094                 text=CSL1("<qt><b><font color=red>")+text+CSL1("</font></b></qt>");
00095                 DEBUGKPILOT<<"We have a conflict for database "<<si.handheldDB<<endl;
00096                 hasConflicts=true;
00097             }
00098             cE.dbname=new QLabel(text, big_box);
00099             resolutionGroupBoxLayout->addWidget( cE.dbname, cE.index, 0 );
00100 
00101             cE.resolution=new QComboBox( FALSE, big_box);
00102             cE.resolution->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7,
00103                 (QSizePolicy::SizeType)0, 0, 0,
00104                 cE.resolution->sizePolicy().hasHeightForWidth() ) );
00105             cE.resolution->clear();
00106             cE.resolution->insertItem( i18n( "No Sync" ) );
00107             cE.resolution->insertItem( i18n( "Sync Handheld to PC" ) );
00108             cE.resolution->insertItem( i18n( "Sync PC to Handheld" ) );
00109             cE.resolution->insertItem( i18n( "Delete Both Databases" ) );
00110             cE.resolution->setCurrentItem((int)si.direction);
00111             resolutionGroupBoxLayout->addWidget( cE.resolution, cE.index, 1);
00112 
00113             cE.info = new QPushButton( i18n("More Info..."), big_box );
00114             resolutionGroupBoxLayout->addWidget(cE.info, cE.index, 2);
00115             bgroup->insert(cE.info);
00116 
00117             conflictEntries.append(cE);
00118             ++nr;
00119         }
00120     } else {
00121         WARNINGKPILOT << "The list of text files is not available to the resolution dialog." << endl;
00122     }
00123 
00124 
00125     topLayout->addWidget( resolutionGroupBox );
00126     resize( QSize(600, 480).expandedTo(minimumSizeHint()) );
00127 
00128     if (fHandle) tickleTimer=new QTimer(this, "TickleTimer");
00129     if (tickleTimer) {
00130         connect( tickleTimer, SIGNAL(timeout()), this, SLOT(_tickle()) );
00131         tickleTimer->start( 10000 ); // tickle the palm every 10 seconds to prevent a timeout until the sync is really finished.
00132     }
00133 
00134 }
00135 
00136 /*
00137  *  Destroys the object and frees any allocated resources
00138  */
00139 ResolutionDialog::~ResolutionDialog()
00140 {
00141     // no need to delete child widgets, Qt does it all for us
00142 }
00143 
00144 /* virtual slot */ void ResolutionDialog::slotOk() {
00145     FUNCTIONSETUP;
00146     QValueList<conflictEntry>::Iterator ceIt;
00147     for (ceIt=conflictEntries.begin(); ceIt!=conflictEntries.end(); ++ceIt) {
00148         (*syncInfo)[(*ceIt).index].direction=(eSyncDirectionEnum)((*ceIt).resolution->currentItem());
00149     }
00150     KDialogBase::slotOk();
00151 }
00152 
00153 QString eTextStatusToString(eTextStatus stat) {
00154     switch(stat) {
00155         case eStatNone: return i18n("unchanged");
00156         case eStatNew: return i18n("new");
00157         case eStatChanged: return i18n("changed");
00158         case eStatBookmarksChanged: return i18n("only bookmarks changed");
00159         case eStatDeleted: return i18n("deleted");
00160         case eStatDoesntExist: return i18n("does not exist");
00161         default: return i18n("unknown");
00162     }
00163 }
00164 
00165 void ResolutionDialog::slotInfo(int index) {
00166     FUNCTIONSETUP;
00167     conflictEntry cE=conflictEntries[index];
00168     int ix=cE.index;
00169     if (!syncInfo) return;
00170     docSyncInfo si=(*syncInfo)[ix];
00171     QString text=i18n("Status of the database %1:\n\n").arg(si.handheldDB);
00172     text+=i18n("Handheld: %1\n").arg(eTextStatusToString(si.fPalmStatus));
00173     text+=i18n("Desktop: %1\n").arg(eTextStatusToString(si.fPCStatus));
00174 
00175     KMessageBox::information(this, text, i18n("Database information"));
00176 }
00177 
00178 
00179 void ResolutionDialog::_tickle() {
00180     FUNCTIONSETUP;
00181     if (fHandle) fHandle->tickle();
00182 }