• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • management
kmdbcreator.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "kmdbcreator.h"
21 #include "kmfactory.h"
22 #include "kmmanager.h"
23 
24 #include <tqprogressdialog.h>
25 #include <tqfileinfo.h>
26 #include <tqdir.h>
27 #include <tdelocale.h>
28 #include <tdeapplication.h>
29 #include <kstandarddirs.h>
30 #include <kdebug.h>
31 
32 KMDBCreator::KMDBCreator(TQObject *parent, const char *name)
33 : TQObject(parent,name)
34 {
35  m_dlg = 0;
36  m_status = true;
37 
38  connect(&m_proc,TQT_SIGNAL(receivedStdout(TDEProcess*,char*,int)),TQT_SLOT(slotReceivedStdout(TDEProcess*,char*,int)));
39  connect(&m_proc,TQT_SIGNAL(receivedStderr(TDEProcess*,char*,int)),TQT_SLOT(slotReceivedStderr(TDEProcess*,char*,int)));
40  connect(&m_proc,TQT_SIGNAL(processExited(TDEProcess*)),TQT_SLOT(slotProcessExited(TDEProcess*)));
41 }
42 
43 KMDBCreator::~KMDBCreator()
44 {
45  if (m_proc.isRunning())
46  m_proc.kill();
47  // do not delete the progress dialog anymore: it's persistent and owned by
48  // it's parent. It will be destroyed along with its parent.
49 }
50 
51 bool KMDBCreator::checkDriverDB(const TQString& dirname, const TQDateTime& d)
52 {
53  // don't block GUI
54  kapp->processEvents();
55 
56  // first check current directory
57  TQFileInfo dfi(dirname);
58  if (dfi.lastModified() > d)
59  return false;
60 
61  // then check most recent file in current directory
62  TQDir dir(dirname);
63  const TQFileInfoList *list = dir.entryInfoList(TQDir::Files,TQDir::Time);
64  if (list && list->count() > 0 && list->getFirst()->lastModified() > d)
65  return false;
66 
67  // then loop into subdirs
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))
71  return false;
72 
73  // everything is OK
74  return true;
75 }
76 
77 bool KMDBCreator::createDriverDB(const TQString& dirname, const TQString& filename, TQWidget *parent)
78 {
79  bool started(true);
80 
81  // initialize status
82  m_status = false;
83  m_firstflag = true;
84 
85  // start the child process
86  m_proc.clearArguments();
87  TQString exestr = KMFactory::self()->manager()->driverDbCreationProgram();
88  m_proc << exestr << dirname << filename;
89  kdDebug() << "executing : " << exestr << " " << dirname << " " << filename << endl;
90  TQString msg;
91  if (exestr.isEmpty())
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);
101  if (!msg.isEmpty())
102  {
103  KMManager::self()->setErrorMsg(msg);
104  started = false;
105  }
106 
107  // Create the dialog if the process is running and if needed
108  if (started)
109  {
110  if (!m_dlg)
111  {
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,TQT_SIGNAL(canceled()),TQT_SLOT(slotCancelled()));
116  }
117  m_dlg->setMinimumDuration(0); // always show the dialog
118  m_dlg->setProgress(0); // to force showing
119  }
120  else
121  // be sure to emit this signal otherwise the DB widget won't never be notified
122  emit dbCreated();
123 
124  return started;
125 }
126 
127 void KMDBCreator::slotReceivedStdout(TDEProcess*, char *buf, int len)
128 {
129  // save buffer
130  TQString str( TQCString(buf, len) );
131 
132  // get the number, cut the string at the first '\n' otherwise
133  // the toInt() will return 0. If that occurs for the first number,
134  // then the number of steps will be also 0.
135  bool ok;
136  int p = str.find('\n');
137  int n = str.mid(0, p).toInt(&ok);
138 
139  // process the number received
140  if (ok && m_dlg)
141  {
142  if (m_firstflag)
143  {
144  m_dlg->setTotalSteps(n);
145  m_firstflag = false;
146  }
147  else
148  {
149  m_dlg->setProgress(n);
150  }
151  }
152 }
153 
154 void KMDBCreator::slotReceivedStderr(TDEProcess*, char*, int)
155 {
156  // just discard it for the moment
157 }
158 
159 void KMDBCreator::slotProcessExited(TDEProcess*)
160 {
161  // delete the progress dialog
162  if (m_dlg)
163  {
164  m_dlg->reset();
165  }
166 
167  // set exit status
168  m_status = (m_proc.normalExit() && m_proc.exitStatus() == 0);
169  if (!m_status)
170  {
171  KMFactory::self()->manager()->setErrorMsg(i18n("Error while creating driver database: abnormal child-process termination."));
172  // remove the incomplete driver DB file so that, it will be
173  // reconstructed on next check
174  TQFile::remove(m_proc.args()[2]);
175  }
176  //else
177  emit dbCreated();
178 }
179 
180 void KMDBCreator::slotCancelled()
181 {
182  if (m_proc.isRunning())
183  m_proc.kill();
184  else
185  emit dbCreated();
186 }
187 #include "kmdbcreator.moc"

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.