20 #include "kmdbcreator.h"
21 #include "kmfactory.h"
22 #include "kmmanager.h"
24 #include <tqprogressdialog.h>
25 #include <tqfileinfo.h>
27 #include <tdelocale.h>
28 #include <tdeapplication.h>
29 #include <kstandarddirs.h>
32 KMDBCreator::KMDBCreator(TQObject *parent,
const char *name)
33 : TQObject(parent,name)
38 connect(&m_proc,TQ_SIGNAL(receivedStdout(TDEProcess*,
char*,
int)),TQ_SLOT(slotReceivedStdout(TDEProcess*,
char*,
int)));
39 connect(&m_proc,TQ_SIGNAL(receivedStderr(TDEProcess*,
char*,
int)),TQ_SLOT(slotReceivedStderr(TDEProcess*,
char*,
int)));
40 connect(&m_proc,TQ_SIGNAL(processExited(TDEProcess*)),TQ_SLOT(slotProcessExited(TDEProcess*)));
43 KMDBCreator::~KMDBCreator()
45 if (m_proc.isRunning())
51 bool KMDBCreator::checkDriverDB(
const TQString& dirname,
const TQDateTime& d)
54 kapp->processEvents();
57 TQFileInfo dfi(dirname);
58 if (dfi.lastModified() > d)
63 const TQFileInfoList *list = dir.entryInfoList(TQDir::Files,TQDir::Time);
64 if (list && list->count() > 0 && list->getFirst()->lastModified() > d)
68 TQStringList slist = dir.entryList(TQDir::Dirs,TQDir::Time);
69 for (TQStringList::ConstIterator it=slist.begin(); it!=slist.end(); ++it)
70 if ((*it) !=
"." && (*it) !=
".." && !checkDriverDB(dir.absFilePath(*it),d))
77 bool KMDBCreator::createDriverDB(
const TQString& dirname,
const TQString& filename, TQWidget *parent)
86 m_proc.clearArguments();
87 TQString exestr = KMFactory::self()->manager()->driverDbCreationProgram();
88 m_proc << exestr << dirname << filename;
89 kdDebug() <<
"executing : " << exestr <<
" " << dirname <<
" " << filename << endl;
92 msg = i18n(
"No executable defined for the creation of the "
93 "driver database. This operation is not implemented.");
94 else if (TDEStandardDirs::findExe(exestr).isEmpty())
95 msg = i18n(
"The executable %1 could not be found in your "
96 "PATH. Check that this program exists and is "
97 "accessible in your PATH variable.").arg(exestr);
98 else if (!m_proc.start(TDEProcess::NotifyOnExit, TDEProcess::AllOutput))
99 msg = i18n(
"Unable to start the creation of the driver "
100 "database. The execution of %1 failed.").arg(exestr);
103 KMManager::self()->setErrorMsg(msg);
112 m_dlg =
new TQProgressDialog(parent->topLevelWidget(),
"progress-dialog",
true);
113 m_dlg->setLabelText(i18n(
"Please wait while TDE rebuilds a driver database."));
114 m_dlg->setCaption(i18n(
"Driver Database"));
115 connect(m_dlg,TQ_SIGNAL(canceled()),TQ_SLOT(slotCancelled()));
117 m_dlg->setMinimumDuration(0);
118 m_dlg->setProgress(0);
127 void KMDBCreator::slotReceivedStdout(TDEProcess*,
char *buf,
int len)
130 TQString str( TQCString(buf, len) );
136 int p = str.find(
'\n');
137 int n = str.mid(0, p).toInt(&ok);
144 m_dlg->setTotalSteps(n);
149 m_dlg->setProgress(n);
154 void KMDBCreator::slotReceivedStderr(TDEProcess*,
char*,
int)
159 void KMDBCreator::slotProcessExited(TDEProcess*)
168 m_status = (m_proc.normalExit() && m_proc.exitStatus() == 0);
171 KMFactory::self()->manager()->setErrorMsg(i18n(
"Error while creating driver database: abnormal child-process termination."));
174 TQFile::remove(m_proc.args()[2]);
180 void KMDBCreator::slotCancelled()
182 if (m_proc.isRunning())
187 #include "kmdbcreator.moc"