kexi
KexiStartup_p.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "KexiStartup_p.h"
00021
00022 #include <kstandarddirs.h>
00023 #include <kprogress.h>
00024 #include <kprocess.h>
00025 #include <kdebug.h>
00026 #include <klocale.h>
00027
00028 #include <qfileinfo.h>
00029 #include <qdir.h>
00030 #include <qapplication.h>
00031
00032 SQLite2ToSQLite3Migration::SQLite2ToSQLite3Migration(const QString& filePath)
00033 : m_filePath(filePath)
00034 {
00035 m_process = 0;
00036 m_dlg = 0;
00037 result = false;
00038 m_run = false;
00039 }
00040
00041 SQLite2ToSQLite3Migration::~SQLite2ToSQLite3Migration()
00042 {
00043 delete m_process;
00044 m_dlg->close();
00045 delete m_dlg;
00046 }
00047
00048 tristate SQLite2ToSQLite3Migration::run()
00049 {
00050 if (m_run)
00051 return false;
00052 m_run = true;
00053 const QString ksqlite2to3_app = KStandardDirs::findExe( "ksqlite2to3" );
00054 if (ksqlite2to3_app.isEmpty())
00055 return false;
00056
00057 QFileInfo fi(m_filePath);
00058 if (fi.isSymLink()) {
00059 m_filePath = fi.readLink();
00060 fi = QFileInfo(m_filePath);
00061 }
00062
00063 m_restoreStat = (0==stat(QFile::encodeName(m_filePath), &m_st));
00064
00065 m_process = new KProcess(this, "process");
00066 *m_process << ksqlite2to3_app << m_filePath;
00067 m_process->setWorkingDirectory( fi.dir(true).absPath() );
00068 connect( m_process, SIGNAL(receivedStderr(KProcess*,char*,int)),
00069 this, SLOT(receivedStderr(KProcess*,char*,int)));
00070 connect( m_process, SIGNAL(processExited(KProcess*)), this, SLOT(processExited(KProcess*)) );
00071 if (!m_process->start(KProcess::NotifyOnExit, KProcess::Stderr))
00072 return false;
00073
00074 m_dlg = new KProgressDialog(0, 0, QString::null,
00075 i18n("Saving \"%1\" project file to a new \"%2\" database format...")
00076 .arg(QDir::convertSeparators(QFileInfo(m_filePath).fileName())).arg("SQLite3")
00077 );
00078 m_dlg->setModal(true);
00079 connect(m_dlg, SIGNAL(cancelClicked()), this, SLOT(cancelClicked()));
00080 m_dlg->setMinimumDuration(1000);
00081 m_dlg->setAutoClose(true);
00082 m_dlg->progressBar()->setTotalSteps(100);
00083 m_dlg->progressBar()->setProgress(0);
00084 m_dlg->exec();
00085
00086 if (result!=true)
00087 return result;
00088
00089 return result;
00090 }
00091
00092 extern void updateProgressBar(KProgressDialog *pd, char *buffer, int buflen);
00093
00094 void SQLite2ToSQLite3Migration::receivedStderr(KProcess *, char *buffer, int buflen)
00095 {
00096 updateProgressBar(m_dlg, buffer, buflen);
00097 }
00098
00099 void SQLite2ToSQLite3Migration::processExited(KProcess* process)
00100 {
00101 kdDebug() << "EXIT " << process->name() << endl;
00102
00103 kdDebug() << process->isRunning() << " " << process->exitStatus() << endl;
00104 m_dlg->close();
00105 result = !process->isRunning() && 0==process->exitStatus();
00106 kdDebug() << result << endl;
00107 if (result) {
00108 if (m_restoreStat) {
00109
00110 chmod(QFile::encodeName(m_filePath), m_st.st_mode);
00111 chown(QFile::encodeName(m_filePath), m_st.st_uid, m_st.st_gid);
00112 }
00113 }
00114 }
00115
00116 void SQLite2ToSQLite3Migration::cancelClicked()
00117 {
00118 kdDebug() << result << " cancelClicked() " <<m_process->isRunning() << " "
00119 << m_process->exitStatus() << endl;
00120 if (!m_process->isRunning() && 0==m_process->exitStatus())
00121 return;
00122 result = cancelled;
00123 m_process->kill();
00124 }
00125
00126 #include "KexiStartup_p.moc"
00127
|