syncAction.cc
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 static const char *syncAction_id =
00029 "$Id: syncAction.cc,v 1.14 2003/03/10 23:37:01 adridg 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 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 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 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
00170
00171
00172
00173
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 i18n("Yes"), i18n("No"));
00221
00222
00223
00224
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 }
This file is part of the documentation for kpilot Library Version 3.2.2.