2011-09-28 20:14:48 +04:00
|
|
|
#include <QtCore>
|
|
|
|
#include <QProcess>
|
2011-09-29 19:17:50 +04:00
|
|
|
#include <QMessageBox>
|
2011-09-29 21:05:49 +04:00
|
|
|
#include <QDesktopServices>
|
2011-09-28 20:14:48 +04:00
|
|
|
|
|
|
|
#include "owncloudsetup.h"
|
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
|
|
|
OwncloudSetup::OwncloudSetup( QObject *parent ) :
|
|
|
|
QObject( parent )
|
|
|
|
{
|
|
|
|
_process = new QProcess( this );
|
|
|
|
|
|
|
|
QObject::connect(_process, SIGNAL(readyReadStandardOutput()),
|
|
|
|
SLOT(slotReadyReadStandardOutput()));
|
|
|
|
|
|
|
|
QObject::connect(_process, SIGNAL(readyReadStandardError()),
|
|
|
|
SLOT(slotReadyReadStandardError()));
|
|
|
|
|
|
|
|
QObject::connect(_process, SIGNAL(stateChanged(QProcess::ProcessState)),
|
|
|
|
SLOT(slotStateChanged(QProcess::ProcessState)));
|
|
|
|
|
|
|
|
QObject::connect(_process, SIGNAL(error(QProcess::ProcessError)),
|
|
|
|
SLOT(slotError(QProcess::ProcessError)));
|
|
|
|
|
|
|
|
QObject::connect(_process, SIGNAL(started()),
|
|
|
|
SLOT(slotStarted()));
|
|
|
|
|
|
|
|
QObject::connect(_process, SIGNAL(finished(int, QProcess::ExitStatus)),
|
|
|
|
SLOT(slotFinished(int, QProcess::ExitStatus)));
|
|
|
|
|
|
|
|
|
|
|
|
_ocWizard = new OwncloudWizard();
|
2011-09-29 21:05:49 +04:00
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
connect( _ocWizard, SIGNAL(connectToOCUrl( const QString& ) ),
|
|
|
|
this, SLOT(slotConnectToOCUrl( const QString& )));
|
2011-09-28 20:14:48 +04:00
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
connect( _ocWizard, SIGNAL(installOCServer()),
|
|
|
|
this, SLOT(slotInstallOCServer()));
|
|
|
|
|
|
|
|
connect( _ocWizard, SIGNAL(installOCLocalhost()),
|
|
|
|
this, SLOT(slotCreateOCLocalhost()));
|
2011-09-28 20:14:48 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void OwncloudSetup::slotConnectToOCUrl( const QString& url )
|
|
|
|
{
|
|
|
|
qDebug() << "Connect to url: " << url;
|
2011-09-29 21:05:49 +04:00
|
|
|
_ocWizard->setField("OCUrl", url );
|
|
|
|
_ocWizard->appendToResultWidget(tr("Connecting to ownCloud at %1").arg(url ));
|
|
|
|
slotFinished( 0, QProcess::NormalExit );
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
bool OwncloudSetup::isBusy()
|
2011-09-28 20:14:48 +04:00
|
|
|
{
|
2011-09-29 18:36:27 +04:00
|
|
|
return _process->state() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OwncloudSetup::slotCreateOCLocalhost()
|
|
|
|
{
|
|
|
|
if( isBusy() ) {
|
|
|
|
qDebug() << "Can not install now, busy. Come back later.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Install OC on localhost";
|
|
|
|
|
|
|
|
QStringList args;
|
|
|
|
|
|
|
|
args << "install";
|
|
|
|
args << "--server-type" << "local";
|
|
|
|
args << "--root_helper" << "kdesu -c";
|
2011-09-29 19:17:50 +04:00
|
|
|
runOwncloudAdmin( args );
|
2011-09-29 21:05:49 +04:00
|
|
|
|
|
|
|
// define
|
|
|
|
_ocWizard->setField( "OCUrl", QString( "http://localhost/owncloud/") );
|
2011-09-29 18:36:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void OwncloudSetup::slotInstallOCServer()
|
|
|
|
{
|
|
|
|
if( isBusy() ) {
|
|
|
|
qDebug() << "Can not install now, busy. Come back later.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-28 20:14:48 +04:00
|
|
|
const QString server = _ocWizard->field("ftpUrl").toString();
|
|
|
|
const QString user = _ocWizard->field("ftpUser").toString();
|
|
|
|
const QString passwd = _ocWizard->field("ftpPasswd").toString();
|
2011-09-29 18:36:27 +04:00
|
|
|
const QString dir; // = _ocWizard->field("ftpDir").toString();
|
2011-09-28 20:14:48 +04:00
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
qDebug() << "Install OC on " << server << " as user " << user;
|
2011-09-28 20:14:48 +04:00
|
|
|
|
|
|
|
QStringList args;
|
|
|
|
args << "install";
|
|
|
|
args << "--server-type" << "ftp";
|
2011-09-29 18:36:27 +04:00
|
|
|
args << "--server" << server;
|
|
|
|
args << "--user" << user;
|
2011-09-29 19:17:50 +04:00
|
|
|
if( ! passwd.isEmpty() ) {
|
|
|
|
args << "--password" << passwd;
|
|
|
|
}
|
2011-09-29 18:36:27 +04:00
|
|
|
if( !dir.isEmpty() ) {
|
|
|
|
args << "--ftpdir" << dir;
|
|
|
|
}
|
2011-09-29 19:17:50 +04:00
|
|
|
runOwncloudAdmin( args );
|
2011-09-29 21:05:49 +04:00
|
|
|
_ocWizard->setField( "OCUrl", QString( "%1/owncloud/").arg(_ocWizard->field("myOCDomain").toString() ));
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 19:17:50 +04:00
|
|
|
void OwncloudSetup::runOwncloudAdmin( const QStringList& args )
|
|
|
|
{
|
|
|
|
const QString bin("/usr/bin/owncloud-admin");
|
|
|
|
|
|
|
|
if( checkOwncloudAdmin( bin )) {
|
|
|
|
_process->start( bin, args );
|
|
|
|
} else {
|
|
|
|
slotFinished( 1, QProcess::NormalExit );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
void OwncloudSetup::slotReadyReadStandardOutput()
|
2011-09-28 20:14:48 +04:00
|
|
|
{
|
2011-09-29 18:36:27 +04:00
|
|
|
QByteArray arr = _process->readAllStandardOutput();
|
|
|
|
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
|
|
|
// render the output to status line
|
|
|
|
QString string = codec->toUnicode( arr );
|
|
|
|
_ocWizard->appendToResultWidget( string );
|
2011-09-28 20:14:48 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
void OwncloudSetup::slotReadyReadStandardError()
|
2011-09-28 20:14:48 +04:00
|
|
|
{
|
2011-09-29 18:36:27 +04:00
|
|
|
qDebug() << _process->readAllStandardError();
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void OwncloudSetup::slotStateChanged( QProcess::ProcessState )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void OwncloudSetup::slotError( QProcess::ProcessError )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void OwncloudSetup::slotStarted()
|
|
|
|
{
|
2011-09-29 18:36:27 +04:00
|
|
|
_ocWizard->button( QWizard::FinishButton )->setEnabled( false );
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
void OwncloudSetup::slotFinished( int res, QProcess::ExitStatus )
|
2011-09-28 20:14:48 +04:00
|
|
|
{
|
2011-09-29 18:36:27 +04:00
|
|
|
_ocWizard->button( QWizard::FinishButton )->setEnabled( true );
|
2011-09-28 20:14:48 +04:00
|
|
|
|
2011-09-29 18:36:27 +04:00
|
|
|
if( res ) {
|
2011-09-29 19:17:50 +04:00
|
|
|
_ocWizard->appendToResultWidget( tr("<font color=\"red\">Installation of ownCloud failed!</font>") );
|
2011-09-29 18:36:27 +04:00
|
|
|
} else {
|
2011-09-29 21:05:49 +04:00
|
|
|
// Successful installation. Write the config.
|
2011-09-29 19:17:50 +04:00
|
|
|
_ocWizard->appendToResultWidget( tr("<font color=\"green\">Installation of ownCloud succeeded!</font>") );
|
2011-09-29 21:05:49 +04:00
|
|
|
|
|
|
|
writeOwncloudConfig();
|
2011-09-29 18:36:27 +04:00
|
|
|
}
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 21:05:49 +04:00
|
|
|
void OwncloudSetup::startWizard()
|
2011-09-28 20:14:48 +04:00
|
|
|
{
|
|
|
|
_ocWizard->exec();
|
|
|
|
}
|
|
|
|
|
2011-09-29 21:05:49 +04:00
|
|
|
QString OwncloudSetup::mirallConfigFile() const
|
|
|
|
{
|
|
|
|
const QString dir = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/mirall.cfg";
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OwncloudSetup::writeOwncloudConfig()
|
|
|
|
{
|
|
|
|
qDebug() << "*** writing mirall config to " << mirallConfigFile();
|
|
|
|
QSettings settings( mirallConfigFile(), QSettings::IniFormat);
|
|
|
|
settings.setValue("ownCloud/url", _ocWizard->field("OCUrl").toString() );
|
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* method to check the if the owncloud admin script is existing
|
|
|
|
*/
|
2011-09-29 19:17:50 +04:00
|
|
|
bool OwncloudSetup::checkOwncloudAdmin( const QString& bin )
|
|
|
|
{
|
|
|
|
QFileInfo fi( bin );
|
|
|
|
qDebug() << "checking owncloud-admin " << bin;
|
|
|
|
if( ! (fi.exists() && fi.isExecutable() ) ) {
|
|
|
|
_ocWizard->appendToResultWidget( tr("The owncloud admin script can not be found.\n"
|
|
|
|
"Setup can not be done.") );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2011-09-28 20:14:48 +04:00
|
|
|
}
|
2011-09-29 18:36:27 +04:00
|
|
|
|
2011-09-29 19:17:50 +04:00
|
|
|
}
|
2011-09-29 18:36:27 +04:00
|
|
|
#include "owncloudsetup.moc"
|