kmdbcreator.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kmdbcreator.h"
00021 #include "kmfactory.h"
00022 #include "kmmanager.h"
00023
00024 #include <qprogressdialog.h>
00025 #include <qfileinfo.h>
00026 #include <qdir.h>
00027 #include <klocale.h>
00028 #include <kapplication.h>
00029 #include <kstandarddirs.h>
00030 #include <kdebug.h>
00031
00032 KMDBCreator::KMDBCreator(QObject *parent, const char *name)
00033 : QObject(parent,name)
00034 {
00035 m_dlg = 0;
00036 m_status = true;
00037
00038 connect(&m_proc,SIGNAL(receivedStdout(KProcess*,char*,int)),SLOT(slotReceivedStdout(KProcess*,char*,int)));
00039 connect(&m_proc,SIGNAL(receivedStderr(KProcess*,char*,int)),SLOT(slotReceivedStderr(KProcess*,char*,int)));
00040 connect(&m_proc,SIGNAL(processExited(KProcess*)),SLOT(slotProcessExited(KProcess*)));
00041 }
00042
00043 KMDBCreator::~KMDBCreator()
00044 {
00045 if (m_proc.isRunning())
00046 m_proc.kill();
00047
00048
00049 }
00050
00051 bool KMDBCreator::checkDriverDB(const QString& dirname, const QDateTime& d)
00052 {
00053
00054 kapp->processEvents();
00055
00056
00057 QFileInfo dfi(dirname);
00058 if (dfi.lastModified() > d)
00059 return false;
00060
00061
00062 QDir dir(dirname);
00063 const QFileInfoList *list = dir.entryInfoList(QDir::Files,QDir::Time);
00064 if (list && list->count() > 0 && list->getFirst()->lastModified() > d)
00065 return false;
00066
00067
00068 QStringList slist = dir.entryList(QDir::Dirs,QDir::Time);
00069 for (QStringList::ConstIterator it=slist.begin(); it!=slist.end(); ++it)
00070 if ((*it) != "." && (*it) != ".." && !checkDriverDB(dir.absFilePath(*it),d))
00071 return false;
00072
00073
00074 return true;
00075 }
00076
00077 bool KMDBCreator::createDriverDB(const QString& dirname, const QString& filename, QWidget *parent)
00078 {
00079 bool started(true);
00080
00081
00082 m_status = false;
00083 m_firstflag = true;
00084
00085
00086 m_proc.clearArguments();
00087 QString exestr = KMFactory::self()->manager()->driverDbCreationProgram();
00088 m_proc << exestr << dirname << filename;
00089 kdDebug() << "executing : " << exestr << " " << dirname << " " << filename << endl;
00090 QString msg;
00091 if (exestr.isEmpty())
00092 msg = i18n("No executable defined for the creation of the "
00093 "driver database. This operation is not implemented.");
00094 else if (KStandardDirs::findExe(exestr).isEmpty())
00095 msg = i18n("The executable %1 could not be found in your "
00096 "PATH. Check that this program exists and is "
00097 "accessible in your PATH variable.").arg(exestr);
00098 else if (!m_proc.start(KProcess::NotifyOnExit, KProcess::AllOutput))
00099 msg = i18n("Unable to start the creation of the driver "
00100 "database. The execution of %1 failed.").arg(exestr);
00101 if (!msg.isEmpty())
00102 {
00103 KMManager::self()->setErrorMsg(msg);
00104 started = false;
00105 }
00106
00107
00108 if (started)
00109 {
00110 if (!m_dlg)
00111 {
00112 m_dlg = new QProgressDialog(parent->topLevelWidget(),"progress-dialog",true);
00113 m_dlg->setLabelText(i18n("Please wait while KDE rebuilds a driver database."));
00114 m_dlg->setCaption(i18n("Driver Database"));
00115 connect(m_dlg,SIGNAL(canceled()),SLOT(slotCancelled()));
00116 }
00117 m_dlg->setMinimumDuration(0);
00118 m_dlg->setProgress(0);
00119 }
00120 else
00121
00122 emit dbCreated();
00123
00124 return started;
00125 }
00126
00127 void KMDBCreator::slotReceivedStdout(KProcess*, char *buf, int len)
00128 {
00129
00130 QString str( QCString(buf, len) );
00131
00132
00133
00134
00135 bool ok;
00136 int p = str.find('\n');
00137 int n = str.mid(0, p).toInt(&ok);
00138
00139
00140 if (ok && m_dlg)
00141 {
00142 if (m_firstflag)
00143 {
00144 m_dlg->setTotalSteps(n);
00145 m_firstflag = false;
00146 }
00147 else
00148 {
00149 m_dlg->setProgress(n);
00150 }
00151 }
00152 }
00153
00154 void KMDBCreator::slotReceivedStderr(KProcess*, char*, int)
00155 {
00156
00157 }
00158
00159 void KMDBCreator::slotProcessExited(KProcess*)
00160 {
00161
00162 if (m_dlg)
00163 {
00164 m_dlg->reset();
00165 }
00166
00167
00168 m_status = (m_proc.normalExit() && m_proc.exitStatus() == 0);
00169 if (!m_status)
00170 {
00171 KMFactory::self()->manager()->setErrorMsg(i18n("Error while creating driver database: abnormal child-process termination."));
00172
00173
00174 QFile::remove(m_proc.args()[2]);
00175 }
00176
00177 emit dbCreated();
00178 }
00179
00180 void KMDBCreator::slotCancelled()
00181 {
00182 if (m_proc.isRunning())
00183 m_proc.kill();
00184 else
00185 emit dbCreated();
00186 }
00187 #include "kmdbcreator.moc"
|