kpilot Library API Documentation

syncAction.cc

00001 /* syncAction.cc KPilot 00002 ** 00003 ** Copyright (C) 1998-2001 by Dan Pilone 00004 ** Copyright (C) 2001 by Waldo Bastian (code in questionYesNo) 00005 ** 00006 */ 00007 00008 /* 00009 ** This program is free software; you can redistribute it and/or modify 00010 ** it under the terms of the GNU Lesser General Public License as published by 00011 ** the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. 00018 ** 00019 ** You should have received a copy of the GNU Lesser 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 static const char *syncAction_id = 00029 "$Id: syncAction.cc,v 1.14.4.1 2004/04/14 16:25:34 binner Exp $"; 00030 00031 #include "options.h" 00032 00033 #include <time.h> 00034 00035 #include <pi-socket.h> 00036 #include <pi-dlp.h> 00037 00038 #include <qtimer.h> 00039 #include <qvbox.h> 00040 #include <qlayout.h> 00041 #include <qcheckbox.h> 00042 #include <qlabel.h> 00043 #include <qmessagebox.h> 00044 #include <qdir.h> 00045 #include <qfile.h> 00046 #include <qfileinfo.h> 00047 #include <qtl.h> 00048 #include <qstyle.h> 00049 00050 #include <kdialogbase.h> 00051 #include <kglobal.h> 00052 #include <kstandarddirs.h> 00053 #include <kconfig.h> 00054 00055 #if KDE_VERSION < 300 00056 #include <kapplication.h> 00057 #else 00058 #include <kapplication.h> 00059 #endif 00060 00061 #include "syncAction.moc" 00062 00063 00064 SyncAction::SyncAction(KPilotDeviceLink *p, 00065 const char *name) : 00066 QObject(p, name), 00067 fHandle(p) 00068 { 00069 FUNCTIONSETUP; 00070 (void) syncAction_id; 00071 } 00072 00073 /* virtual */ QString SyncAction::statusString() const 00074 { 00075 FUNCTIONSETUP; 00076 QString s = CSL1("status="); 00077 00078 s.append(QString::number(status())); 00079 return s; 00080 } 00081 00082 /* slot */ void SyncAction::execConduit() 00083 { 00084 FUNCTIONSETUP; 00085 00086 #ifdef DEBUG 00087 DEBUGCONDUIT << fname 00088 << ": Running conduit " << name() << endl; 00089 #endif 00090 00091 bool r = this->exec(); 00092 00093 #ifdef DEBUG 00094 DEBUGCONDUIT << fname << ": Exec returned " << r << endl; 00095 #endif 00096 00097 if (!r) 00098 { 00099 emit logError(i18n("The conduit %1 could not be executed.") 00100 .arg(QString::fromLatin1(name()))); 00101 delayDone(); 00102 } 00103 } 00104 00105 /* slot */ void SyncAction::delayedDoneSlot() 00106 { 00107 emit syncDone(this); 00108 } 00109 00110 bool SyncAction::delayDone() 00111 { 00112 QTimer::singleShot(0,this,SLOT(delayedDoneSlot())); 00113 return true; 00114 } 00115 00116 InteractiveAction::InteractiveAction(KPilotDeviceLink *p, 00117 QWidget * visibleparent, 00118 const char *name) : 00119 SyncAction(p, name), 00120 fParent(visibleparent), 00121 fTickleTimer(0L), 00122 fTickleCount(0), 00123 fTickleTimeout(0) 00124 { 00125 FUNCTIONSETUP; 00126 } 00127 00128 InteractiveAction::~InteractiveAction() 00129 { 00130 FUNCTIONSETUP; 00131 00132 KPILOT_DELETE(fTickleTimer); 00133 } 00134 00135 00136 void InteractiveAction::startTickle(unsigned timeout) 00137 { 00138 FUNCTIONSETUP; 00139 fTickleTimeout = timeout; 00140 fTickleCount = 0; 00141 if (!fTickleTimer) 00142 { 00143 fTickleTimer = new QTimer(this); 00144 QObject::connect(fTickleTimer, SIGNAL(timeout()), 00145 this, SLOT(tickle())); 00146 } 00147 else 00148 { 00149 fTickleTimer->stop(); 00150 } 00151 00152 fTickleTimer->start(1000, false); 00153 } 00154 00155 void InteractiveAction::stopTickle() 00156 { 00157 FUNCTIONSETUP; 00158 if (fTickleTimer) 00159 { 00160 fTickleTimer->stop(); 00161 } 00162 } 00163 00164 void InteractiveAction::tickle() 00165 { 00166 FUNCTIONSETUP; 00167 fTickleCount++; 00168 00169 // Note that if fTickleTimeout == 0 then this 00170 // test will never be true until unsigned wraps 00171 // around, which is 2^32 seconds, which is a long time. 00172 // 00173 // This is intentional. 00174 // 00175 // 00176 if (fTickleCount == fTickleTimeout) 00177 { 00178 emit timeout(); 00179 } 00180 else 00181 { 00182 if (pi_tickle(pilotSocket())) 00183 { 00184 kdWarning() << k_funcinfo 00185 << "Couldn't tickle Pilot!" << endl; 00186 } 00187 } 00188 } 00189 00190 int InteractiveAction::questionYesNo(const QString & text, 00191 const QString & caption, 00192 const QString & key, 00193 unsigned timeout) 00194 { 00195 FUNCTIONSETUP; 00196 00197 KConfig *config = kapp->config(); 00198 KConfigGroupSaver cfgs(config,"Notification Messages"); 00199 00200 00201 if (!key.isEmpty()) 00202 { 00203 QString prev = config->readEntry(key).lower(); 00204 00205 if (prev == CSL1("yes")) 00206 { 00207 return KDialogBase::Yes; 00208 } 00209 else if (prev == CSL1("no")) 00210 { 00211 return KDialogBase::No; 00212 } 00213 } 00214 00215 KDialogBase *dialog = 00216 new KDialogBase(caption.isNull()? i18n("Question") : caption, 00217 KDialogBase::Yes | KDialogBase::No, 00218 KDialogBase::Yes, KDialogBase::No, 00219 fParent, "questionYesNo", true, true, 00220 KStdGuiItem::yes(), KStdGuiItem::no()); 00221 00222 // The following code is taken from KDialogBase.cc, 00223 // part of the KDE 2.2 libraries. Copyright 2001 00224 // by Waldo Bastian. 00225 // 00226 // 00227 QVBox *topcontents = new QVBox(dialog); 00228 00229 topcontents->setSpacing(KDialog::spacingHint() * 2); 00230 topcontents->setMargin(KDialog::marginHint() * 2); 00231 00232 QWidget *contents = new QWidget(topcontents); 00233 QHBoxLayout *lay = new QHBoxLayout(contents); 00234 00235 lay->setSpacing(KDialog::spacingHint() * 2); 00236 00237 lay->addStretch(1); 00238 QLabel *label1 = new QLabel( contents); 00239 #if QT_VERSION < 300 00240 label1->setPixmap(QMessageBox::standardIcon(QMessageBox::Information, 00241 kapp->style().guiStyle())); 00242 #else 00243 label1->setPixmap(QMessageBox::standardIcon(QMessageBox::Information)); 00244 #endif 00245 lay->add( label1 ); 00246 QLabel *label2 = new QLabel( text, contents); 00247 label2->setMinimumSize(label2->sizeHint()); 00248 lay->add(label2); 00249 lay->addStretch(1); 00250 00251 QSize extraSize = QSize(50, 30); 00252 00253 QCheckBox *checkbox = 0L; 00254 if (!key.isEmpty()) 00255 { 00256 checkbox = new QCheckBox(i18n("Do not ask again"),topcontents); 00257 extraSize = QSize(50,0); 00258 } 00259 00260 dialog->setMainWidget(topcontents); 00261 dialog->enableButtonSeparator(false); 00262 dialog->incInitialSize(extraSize); 00263 00264 QTimer *timer = new QTimer(dialog); 00265 00266 QObject::connect(timer, SIGNAL(timeout()), 00267 dialog, SLOT(slotCancel())); 00268 if (timeout > 0) 00269 { 00270 timer->start(timeout,true); 00271 } 00272 00273 int result = dialog->exec(); 00274 00275 #ifdef DEBUG 00276 DEBUGDAEMON << fname << ": Dialog returned " << result << endl; 00277 #endif 00278 00279 if (!key.isEmpty() && checkbox && checkbox->isChecked()) 00280 { 00281 if (result == KDialogBase::Yes) 00282 { 00283 config->writeEntry(key,"Yes"); 00284 } 00285 else if (result == KDialogBase::No) 00286 { 00287 config->writeEntry(key,"No"); 00288 } 00289 } 00290 00291 delete dialog; 00292 return result; 00293 }
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 Wed Jul 28 23:57:49 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003