mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 13:35:58 +03:00
WIP:
- split up owncloudsetup class to have a wizard class and a class that delivers plain config data - renamed ownCloudSetup -> ownCloudSetupWizard - added new class MirallConfigFile - made mirall config file (which currently only contains the owncloud connection) multi-connection aware - removed some sitecopy code - removed fetch- and push slots - adopted readFolderConfigFromFile to new file format
This commit is contained in:
parent
04841c940d
commit
2c6c2625bf
15 changed files with 275 additions and 209 deletions
|
@ -48,7 +48,7 @@ mirall/sitecopyfolder.cpp
|
|||
mirall/sitecopyconfig.cpp
|
||||
mirall/statusdialog.cpp
|
||||
mirall/owncloudwizard.cpp
|
||||
mirall/owncloudsetup.cpp
|
||||
mirall/owncloudsetupwizard.cpp
|
||||
mirall/owncloudinfo.cpp
|
||||
mirall/ownclouddircheck.cpp
|
||||
mirall/mirallwebdav.cpp
|
||||
|
@ -56,6 +56,7 @@ mirall/theme.cpp
|
|||
mirall/miralltheme.cpp
|
||||
mirall/owncloudtheme.cpp
|
||||
mirall/folderman.cpp
|
||||
mirall/mirallconfigfile.cpp
|
||||
)
|
||||
|
||||
if(CSYNC_FOUND)
|
||||
|
|
|
@ -29,8 +29,9 @@
|
|||
#include "mirall/sitecopyconfig.h"
|
||||
#include "mirall/owncloudfolder.h"
|
||||
#include "mirall/statusdialog.h"
|
||||
#include "mirall/owncloudsetup.h"
|
||||
#include "mirall/owncloudsetupwizard.h"
|
||||
#include "mirall/theme.h"
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
|
||||
#include "mirall/miralltheme.h"
|
||||
#include "mirall/owncloudtheme.h"
|
||||
|
@ -61,7 +62,7 @@ Application::Application(int argc, char **argv) :
|
|||
setQuitOnLastWindowClosed(false);
|
||||
|
||||
_folderWizard = new FolderWizard();
|
||||
_owncloudSetup = new OwncloudSetup();
|
||||
_owncloudSetupWizard = new OwncloudSetupWizard();
|
||||
_statusDialog = new StatusDialog();
|
||||
|
||||
connect( _statusDialog, SIGNAL(removeFolderAlias( const QString&)),
|
||||
|
@ -130,15 +131,19 @@ void Application::slotTrayClicked( QSystemTrayIcon::ActivationReason reason )
|
|||
if( reason == QSystemTrayIcon::Trigger ) {
|
||||
_folderMan->disableFoldersWithRestore();
|
||||
// check if there is a mirall.cfg already.
|
||||
if( _owncloudSetup->wizard()->isVisible() ) {
|
||||
_owncloudSetup->wizard()->show();
|
||||
if( _owncloudSetupWizard->wizard()->isVisible() ) {
|
||||
_owncloudSetupWizard->wizard()->show();
|
||||
}
|
||||
QFile fi( QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/mirall.cfg" );
|
||||
if( !fi.exists() ) {
|
||||
|
||||
|
||||
// if no config file is there, start the configuration wizard.
|
||||
MirallConfigFile cfgFile;
|
||||
|
||||
if( !cfgFile.exists() ) {
|
||||
qDebug() << "No configured folders yet, start the Owncloud integration dialog.";
|
||||
_owncloudSetup->startWizard();
|
||||
_owncloudSetupWizard->startWizard();
|
||||
} else {
|
||||
_statusDialog->setOCUrl( QUrl( _owncloudSetup->ownCloudUrl()));
|
||||
_statusDialog->setOCUrl( QUrl( cfgFile.ownCloudUrl()) );
|
||||
|
||||
_statusDialog->show();
|
||||
}
|
||||
|
@ -345,7 +350,7 @@ void Application::slotEnableFolder(const QString& alias, const bool enable)
|
|||
void Application::slotConfigure()
|
||||
{
|
||||
_folderMan->disableFoldersWithRestore();
|
||||
_owncloudSetup->startWizard();
|
||||
_owncloudSetupWizard->startWizard();
|
||||
_folderMan->restoreEnabledFolders();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class Theme;
|
|||
class FolderWatcher;
|
||||
class FolderWizard;
|
||||
class StatusDialog;
|
||||
class OwncloudSetup;
|
||||
class OwncloudSetupWizard;
|
||||
|
||||
class Application : public QApplication
|
||||
{
|
||||
|
@ -80,7 +80,7 @@ private:
|
|||
QNetworkConfigurationManager *_networkMgr;
|
||||
|
||||
FolderWizard *_folderWizard;
|
||||
OwncloudSetup *_owncloudSetup;
|
||||
OwncloudSetupWizard *_owncloudSetupWizard;
|
||||
|
||||
// tray's menu
|
||||
QMenu *_contextMenu;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <QSettings>
|
||||
#include <QUrl>
|
||||
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/unisonfolder.h"
|
||||
#include "mirall/csyncfolder.h"
|
||||
#include "mirall/owncloudfolder.h"
|
||||
|
@ -75,13 +76,17 @@ int FolderMan::setupKnownFolders()
|
|||
{
|
||||
qDebug() << "* Setup folders from " << folderConfigPath();
|
||||
|
||||
_folderMap.clear();
|
||||
_folderMap.clear(); // FIXME: check if delete of folder structure happens
|
||||
|
||||
QDir dir(folderConfigPath());
|
||||
dir.setFilter(QDir::Files);
|
||||
QStringList list = dir.entryList();
|
||||
foreach (QString file, list) {
|
||||
setupFolderFromConfigFile(file);
|
||||
|
||||
foreach ( QString alias, list ) {
|
||||
Folder *f = setupFolderFromConfigFile( alias );
|
||||
}
|
||||
// return the number of valid folders.
|
||||
return _folderMap.size();
|
||||
}
|
||||
|
||||
// filename is the name of the file only, it does not include
|
||||
|
@ -93,74 +98,67 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) {
|
|||
QSettings settings(folderConfigPath() + "/" + file, QSettings::IniFormat);
|
||||
qDebug() << " -> file path: " + settings.fileName();
|
||||
|
||||
if (!settings.contains("folder/path")) {
|
||||
qWarning() << " `->" << file << "is not a valid folder configuration";
|
||||
return folder;
|
||||
}
|
||||
settings.beginGroup( file ); // read the group with the same name as the file which is the folder alias
|
||||
|
||||
QVariant path = settings.value("folder/path").toString();
|
||||
if (path.isNull() || !QFileInfo(path.toString()).isDir()) {
|
||||
qWarning() << " `->" << path.toString() << "does not exist. Skipping folder" << file;
|
||||
QString path = settings.value("localpath").toString();
|
||||
if ( path.isNull() || !QFileInfo( path ).isDir() ) {
|
||||
qWarning() << " `->" << path << "does not exist. Skipping folder" << file;
|
||||
// _tray->showMessage(tr("Unknown folder"),
|
||||
// tr("Folder %1 does not exist").arg(path.toString()),
|
||||
// QSystemTrayIcon::Critical);
|
||||
return folder;
|
||||
}
|
||||
|
||||
QString backend = settings.value("folder/backend").toString();
|
||||
QString backend = settings.value("backend").toString();
|
||||
QString targetPath = settings.value( "targetPath" ).toString();
|
||||
QString connection = settings.value( "connection" ).toString();
|
||||
|
||||
if (!backend.isEmpty()) {
|
||||
if( backend == "sitecopy") {
|
||||
qCritical() << "* sitecopy is not longer supported in this release." << endl;
|
||||
} else if (backend == "unison") {
|
||||
folder = new UnisonFolder(file,
|
||||
path.toString(),
|
||||
settings.value("backend:unison/secondPath").toString(),
|
||||
this);
|
||||
|
||||
if (backend == "unison") {
|
||||
folder = new UnisonFolder(file, path, targetPath, this );
|
||||
} else if (backend == "csync") {
|
||||
#ifdef WITH_CSYNC
|
||||
folder = new CSyncFolder(file,
|
||||
path.toString(),
|
||||
settings.value("backend:csync/secondPath").toString(),
|
||||
this);
|
||||
folder = new CSyncFolder(file, path, targetPath, this );
|
||||
#else
|
||||
qCritical() << "* csync support not enabled!! ignoring:" << file;
|
||||
#endif
|
||||
} else if( backend == "owncloud" ) {
|
||||
#ifdef WITH_CSYNC
|
||||
QUrl url; // ( _owncloudSetup->fullOwnCloudUrl() );
|
||||
|
||||
MirallConfigFile cfgFile;
|
||||
|
||||
// assemble the owncloud url to pass to csync.
|
||||
QUrl url( cfgFile.fullOwnCloudUrl() );
|
||||
QString existPath = url.path();
|
||||
qDebug() << "existing path: " << existPath;
|
||||
QString newPath = settings.value("backend:owncloud/targetPath").toString();
|
||||
|
||||
if( !existPath.isEmpty() ) {
|
||||
// cut off the trailing slash
|
||||
if( existPath.endsWith('/') ) {
|
||||
existPath.truncate( existPath.length()-1 );
|
||||
}
|
||||
// cut off the leading slash
|
||||
if( newPath.startsWith('/') ) {
|
||||
newPath.remove(0,1);
|
||||
if( targetPath.startsWith('/') ) {
|
||||
targetPath.remove(0,1);
|
||||
}
|
||||
}
|
||||
|
||||
url.setPath( QString("%1/files/webdav.php/%2").arg(existPath).arg(newPath) );
|
||||
url.setPath( QString("%1/files/webdav.php/%2").arg(existPath).arg(targetPath) );
|
||||
|
||||
folder = new ownCloudFolder( file, path.toString(),
|
||||
url.toString(),
|
||||
this );
|
||||
folder = new ownCloudFolder( file, path, url.toString(), this );
|
||||
|
||||
|
||||
#else
|
||||
qCritical() << "* owncloud support not enabled!! ignoring:" << file;
|
||||
#endif
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
qWarning() << "unknown backend" << backend;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
folder->setBackend( backend );
|
||||
folder->setOnlyOnlineEnabled(settings.value("folder/onlyOnline", false).toBool());
|
||||
// folder->setOnlyOnlineEnabled(settings.value("folder/onlyOnline", false).toBool());
|
||||
folder->setOnlyThisLANEnabled(settings.value("folder/onlyThisLAN", false).toBool());
|
||||
|
||||
_folderMap[file] = folder;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
namespace Mirall {
|
||||
|
||||
class SyncResult;
|
||||
class OwncloudSetup;
|
||||
|
||||
class FolderMan : public QObject
|
||||
{
|
||||
|
@ -74,6 +75,7 @@ private:
|
|||
Folder::Map _folderMap;
|
||||
QHash<QString, bool> _folderEnabledMap;
|
||||
QString _folderConfigPath;
|
||||
OwncloudSetup *_ownCloudSetup;
|
||||
|
||||
// counter tracking number of folders doing a sync
|
||||
int _folderSyncCount;
|
||||
|
|
|
@ -26,9 +26,8 @@
|
|||
#include "mirall/folderwizard.h"
|
||||
#include "mirall/owncloudinfo.h"
|
||||
#include "mirall/ownclouddircheck.h"
|
||||
#include "mirall/owncloudsetup.h"
|
||||
#include "mirall/mirallwebdav.h"
|
||||
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
@ -215,8 +214,9 @@ void FolderWizardTargetPage::slotCreateRemoteFolder()
|
|||
const QString folder = _ui.OCFolderLineEdit->text();
|
||||
if( folder.isEmpty() ) return;
|
||||
|
||||
OwncloudSetup ocSetup;
|
||||
QString url = ocSetup.ownCloudUrl();
|
||||
MirallConfigFile cfgFile;
|
||||
|
||||
QString url = cfgFile.ownCloudUrl();
|
||||
if( ! url.endsWith('/')) url.append('/');
|
||||
url.append( "files/webdav.php/");
|
||||
url.append( folder );
|
||||
|
@ -226,7 +226,7 @@ void FolderWizardTargetPage::slotCreateRemoteFolder()
|
|||
connect( webdav, SIGNAL(webdavFinished(QNetworkReply*)),
|
||||
SLOT(slotCreateRemoteFolderFinished(QNetworkReply*)));
|
||||
|
||||
webdav->httpConnect( url, ocSetup.ownCloudUser(), ocSetup.ownCloudPasswd() );
|
||||
webdav->httpConnect( url, cfgFile.ownCloudUser(), cfgFile.ownCloudPasswd() );
|
||||
if( webdav->mkdir( url ) ) {
|
||||
qDebug() << "WebDAV mkdir request successfully started";
|
||||
} else {
|
||||
|
|
125
src/mirall/mirallconfigfile.cpp
Normal file
125
src/mirall/mirallconfigfile.cpp
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/owncloudtheme.h"
|
||||
#include "mirall/miralltheme.h"
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
MirallConfigFile::MirallConfigFile()
|
||||
{
|
||||
}
|
||||
|
||||
QString MirallConfigFile::mirallConfigFile() const
|
||||
{
|
||||
#ifdef OWNCLOUD_CLIENT
|
||||
ownCloudTheme theme;
|
||||
#else
|
||||
mirallTheme theme;
|
||||
#endif
|
||||
const QString dir = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + theme.configFileName();
|
||||
return dir;
|
||||
}
|
||||
|
||||
bool MirallConfigFile::exists()
|
||||
{
|
||||
QFile file( mirallConfigFile() );
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
void MirallConfigFile::writeOwncloudConfig( const QString& connection,
|
||||
const QString& url,
|
||||
const QString& user,
|
||||
const QString& passwd )
|
||||
{
|
||||
qDebug() << "*** writing mirall config to " << mirallConfigFile();
|
||||
QSettings settings( mirallConfigFile(), QSettings::IniFormat);
|
||||
QString cloudsUrl( url );
|
||||
|
||||
if( !cloudsUrl.startsWith("http") )
|
||||
cloudsUrl.prepend( "http://" );
|
||||
|
||||
settings.beginGroup( connection );
|
||||
settings.setValue("url", cloudsUrl );
|
||||
settings.setValue("user", user );
|
||||
settings.setValue("password", passwd );
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the configured owncloud url if its already configured, otherwise an empty
|
||||
* string.
|
||||
*/
|
||||
QString MirallConfigFile::ownCloudUrl( const QString& connection ) const
|
||||
{
|
||||
QString con( connection );
|
||||
if( connection.isEmpty() ) con = QString::fromLocal8Bit("ownCloud");
|
||||
|
||||
QSettings settings( mirallConfigFile(), QSettings::IniFormat );
|
||||
settings.beginGroup( con );
|
||||
|
||||
QString url = settings.value( "url" ).toString();
|
||||
|
||||
qDebug() << "Returning configured owncloud url: " << url;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
QUrl MirallConfigFile::fullOwnCloudUrl( const QString& connection ) const
|
||||
{
|
||||
QString con( connection );
|
||||
if( connection.isEmpty() ) con = QString::fromLocal8Bit("ownCloud");
|
||||
|
||||
QSettings settings( mirallConfigFile(), QSettings::IniFormat );
|
||||
settings.beginGroup( con );
|
||||
|
||||
QUrl url( ownCloudUrl( con ) );
|
||||
url.setUserName( ownCloudUser( con ) );
|
||||
url.setPassword( ownCloudPasswd( con ) );
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
QString MirallConfigFile::ownCloudUser( const QString& connection ) const
|
||||
{
|
||||
QString con( connection );
|
||||
if( connection.isEmpty() ) con = QString::fromLocal8Bit("ownCloud");
|
||||
|
||||
QSettings settings( mirallConfigFile(), QSettings::IniFormat );
|
||||
settings.beginGroup( con );
|
||||
|
||||
QString user = settings.value( "user" ).toString();
|
||||
qDebug() << "Returning configured owncloud user: " << user;
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
QString MirallConfigFile::ownCloudPasswd( const QString& connection ) const
|
||||
{
|
||||
QString con( connection );
|
||||
if( connection.isEmpty() ) con = QString::fromLocal8Bit("ownCloud");
|
||||
|
||||
QSettings settings( mirallConfigFile(), QSettings::IniFormat );
|
||||
settings.beginGroup( con );
|
||||
|
||||
QString pwd = settings.value( "password" ).toString();
|
||||
|
||||
return pwd;
|
||||
}
|
||||
|
||||
}
|
44
src/mirall/mirallconfigfile.h
Normal file
44
src/mirall/mirallconfigfile.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef MIRALLCONFIGFILE_H
|
||||
#define MIRALLCONFIGFILE_H
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
|
||||
class MirallConfigFile
|
||||
{
|
||||
public:
|
||||
MirallConfigFile();
|
||||
|
||||
QString mirallConfigFile() const;
|
||||
bool exists();
|
||||
|
||||
void writeOwncloudConfig( const QString& connection,
|
||||
const QString& url,
|
||||
const QString& user,
|
||||
const QString& passwd );
|
||||
|
||||
QString ownCloudUrl( const QString& connection = QString() ) const;
|
||||
|
||||
QUrl fullOwnCloudUrl( const QString& connection = QString() ) const;
|
||||
|
||||
QString ownCloudUser( const QString& connection = QString() ) const;
|
||||
|
||||
QString ownCloudPasswd( const QString& connection = QString() ) const;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // MIRALLCONFIGFILE_H
|
|
@ -26,7 +26,12 @@ mirallTheme::mirallTheme()
|
|||
|
||||
QString mirallTheme::appName() const
|
||||
{
|
||||
return QString("Mirall");
|
||||
return QString::fromLocal8Bit("Mirall");
|
||||
}
|
||||
|
||||
QString mirallTheme::configFileName() const
|
||||
{
|
||||
return QString::fromLocal8Bit("mirall.cfg");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
mirallTheme();
|
||||
|
||||
virtual QString appName() const;
|
||||
|
||||
virtual QString configFileName() const;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -17,14 +17,15 @@
|
|||
#include <QMessageBox>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include "owncloudsetup.h"
|
||||
#include "mirall/owncloudsetupwizard.h"
|
||||
#include "mirall/sitecopyconfig.h"
|
||||
#include "mirall/sitecopyfolder.h"
|
||||
#include "mirall/mirallwebdav.h"
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
OwncloudSetup::OwncloudSetup( QObject *parent ) :
|
||||
OwncloudSetupWizard::OwncloudSetupWizard( QObject *parent ) :
|
||||
QObject( parent )
|
||||
{
|
||||
_process = new QProcess( this );
|
||||
|
@ -64,7 +65,7 @@ OwncloudSetup::OwncloudSetup( QObject *parent ) :
|
|||
|
||||
}
|
||||
|
||||
void OwncloudSetup::slotConnectToOCUrl( const QString& url )
|
||||
void OwncloudSetupWizard::slotConnectToOCUrl( const QString& url )
|
||||
{
|
||||
qDebug() << "Connect to url: " << url;
|
||||
_ocWizard->setField("OCUrl", url );
|
||||
|
@ -72,17 +73,17 @@ void OwncloudSetup::slotConnectToOCUrl( const QString& url )
|
|||
slotFinished( 0, QProcess::NormalExit );
|
||||
}
|
||||
|
||||
bool OwncloudSetup::isBusy()
|
||||
bool OwncloudSetupWizard::isBusy()
|
||||
{
|
||||
return _process->state() > 0;
|
||||
}
|
||||
|
||||
OwncloudWizard *OwncloudSetup::wizard()
|
||||
OwncloudWizard *OwncloudSetupWizard::wizard()
|
||||
{
|
||||
return _ocWizard;
|
||||
}
|
||||
|
||||
void OwncloudSetup::slotCreateOCLocalhost()
|
||||
void OwncloudSetupWizard::slotCreateOCLocalhost()
|
||||
{
|
||||
if( isBusy() ) {
|
||||
qDebug() << "Can not install now, busy. Come back later.";
|
||||
|
@ -109,7 +110,7 @@ void OwncloudSetup::slotCreateOCLocalhost()
|
|||
_ocWizard->setField( "OCUrl", QString( "http://localhost/owncloud/") );
|
||||
}
|
||||
|
||||
void OwncloudSetup::slotInstallOCServer()
|
||||
void OwncloudSetupWizard::slotInstallOCServer()
|
||||
{
|
||||
if( isBusy() ) {
|
||||
qDebug() << "Can not install now, busy. Come back later.";
|
||||
|
@ -139,7 +140,7 @@ void OwncloudSetup::slotInstallOCServer()
|
|||
_ocWizard->setField( "OCUrl", QString( "%1/owncloud/").arg(_ocWizard->field("myOCDomain").toString() ));
|
||||
}
|
||||
|
||||
void OwncloudSetup::runOwncloudAdmin( const QStringList& args )
|
||||
void OwncloudSetupWizard::runOwncloudAdmin( const QStringList& args )
|
||||
{
|
||||
const QString bin("/usr/bin/owncloud-admin");
|
||||
qDebug() << "starting " << bin << " with args. " << args;
|
||||
|
@ -156,7 +157,7 @@ void OwncloudSetup::runOwncloudAdmin( const QStringList& args )
|
|||
}
|
||||
|
||||
|
||||
void OwncloudSetup::slotReadyReadStandardOutput()
|
||||
void OwncloudSetupWizard::slotReadyReadStandardOutput()
|
||||
{
|
||||
QByteArray arr = _process->readAllStandardOutput();
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
|
@ -166,29 +167,29 @@ void OwncloudSetup::slotReadyReadStandardOutput()
|
|||
|
||||
}
|
||||
|
||||
void OwncloudSetup::slotReadyReadStandardError()
|
||||
void OwncloudSetupWizard::slotReadyReadStandardError()
|
||||
{
|
||||
qDebug() << "!! " <<_process->readAllStandardError();
|
||||
}
|
||||
|
||||
void OwncloudSetup::slotStateChanged( QProcess::ProcessState )
|
||||
void OwncloudSetupWizard::slotStateChanged( QProcess::ProcessState )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OwncloudSetup::slotError( QProcess::ProcessError err )
|
||||
void OwncloudSetupWizard::slotError( QProcess::ProcessError err )
|
||||
{
|
||||
qDebug() << "An Error happend with owncloud-admin: " << err << ", exit-Code: " << _process->exitCode();
|
||||
}
|
||||
|
||||
void OwncloudSetup::slotStarted()
|
||||
void OwncloudSetupWizard::slotStarted()
|
||||
{
|
||||
_ocWizard->button( QWizard::FinishButton )->setEnabled( false );
|
||||
_ocWizard->button( QWizard::BackButton )->setEnabled( false );
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
}
|
||||
|
||||
void OwncloudSetup::slotFinished( int res, QProcess::ExitStatus )
|
||||
void OwncloudSetupWizard::slotFinished( int res, QProcess::ExitStatus )
|
||||
{
|
||||
_ocWizard->button( QWizard::FinishButton )->setEnabled( true );
|
||||
_ocWizard->button( QWizard::BackButton)->setEnabled( true );
|
||||
|
@ -203,85 +204,28 @@ void OwncloudSetup::slotFinished( int res, QProcess::ExitStatus )
|
|||
// Successful installation. Write the config.
|
||||
_ocWizard->appendToResultWidget( tr("<font color=\"green\">Installation of ownCloud succeeded!</font>") );
|
||||
_ocWizard->showOCUrlLabel( true );
|
||||
writeOwncloudConfig();
|
||||
|
||||
// FIXME: Write the owncloud config via MirallConfigFile
|
||||
|
||||
emit ownCloudSetupFinished( true );
|
||||
setupLocalSyncFolder();
|
||||
}
|
||||
}
|
||||
|
||||
void OwncloudSetup::startWizard()
|
||||
void OwncloudSetupWizard::startWizard()
|
||||
{
|
||||
_ocWizard->setOCUrl( ownCloudUrl() );
|
||||
_ocWizard->restart();
|
||||
_ocWizard->show();
|
||||
MirallConfigFile cfgFile;
|
||||
|
||||
_ocWizard->setOCUrl( cfgFile.ownCloudUrl() );
|
||||
_ocWizard->restart();
|
||||
_ocWizard->show();
|
||||
}
|
||||
|
||||
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);
|
||||
QString url = _ocWizard->field("OCUrl").toString();
|
||||
if( !url.startsWith("http")) {
|
||||
url.prepend( "http://" );
|
||||
}
|
||||
settings.setValue("ownCloud/url", url );
|
||||
settings.setValue("ownCloud/user", _ocWizard->field("OCUser").toString() );
|
||||
settings.setValue("ownCloud/password", _ocWizard->field("OCPasswd").toString() );
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the configured owncloud url if its already configured, otherwise an empty
|
||||
* string.
|
||||
*/
|
||||
QString OwncloudSetup::ownCloudUrl() const
|
||||
{
|
||||
QSettings settings( mirallConfigFile(), QSettings::IniFormat );
|
||||
QString url = settings.value( "ownCloud/url" ).toString();
|
||||
qDebug() << "Returning configured owncloud url: " << url;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
QUrl OwncloudSetup::fullOwnCloudUrl() const
|
||||
{
|
||||
QUrl url( ownCloudUrl() );
|
||||
url.setUserName( ownCloudUser() );
|
||||
url.setPassword( ownCloudPasswd() );
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
QString OwncloudSetup::ownCloudUser() const
|
||||
{
|
||||
QSettings settings( mirallConfigFile(), QSettings::IniFormat );
|
||||
QString user = settings.value( "ownCloud/user" ).toString();
|
||||
qDebug() << "Returning configured owncloud user: " << user;
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
QString OwncloudSetup::ownCloudPasswd() const
|
||||
{
|
||||
QSettings settings( mirallConfigFile(), QSettings::IniFormat );
|
||||
QString pwd = settings.value( "ownCloud/password" ).toString();
|
||||
|
||||
return pwd;
|
||||
}
|
||||
|
||||
/*
|
||||
* method to check the if the owncloud admin script is existing
|
||||
*/
|
||||
bool OwncloudSetup::checkOwncloudAdmin( const QString& bin )
|
||||
bool OwncloudSetupWizard::checkOwncloudAdmin( const QString& bin )
|
||||
{
|
||||
QFileInfo fi( bin );
|
||||
qDebug() << "checking owncloud-admin " << bin;
|
||||
|
@ -293,7 +237,7 @@ bool OwncloudSetup::checkOwncloudAdmin( const QString& bin )
|
|||
return true;
|
||||
}
|
||||
|
||||
void OwncloudSetup::setupLocalSyncFolder()
|
||||
void OwncloudSetupWizard::setupLocalSyncFolder()
|
||||
{
|
||||
const QString syncFolder( QDir::homePath() + "/ownCloud" );
|
||||
qDebug() << "Setup local sync folder " << syncFolder;
|
||||
|
@ -308,73 +252,18 @@ void OwncloudSetup::setupLocalSyncFolder()
|
|||
} else {
|
||||
|
||||
if( fi.mkpath( syncFolder ) ) {
|
||||
QString targetPath = "mirall"; // Do NOT sync to root dir on ownCloud!
|
||||
|
||||
MirallWebDAV *webdav = new MirallWebDAV;
|
||||
webdav->httpConnect( ownCloudUrl(), ownCloudUser(), ownCloudPasswd() );
|
||||
if( webdav->mkdir( targetPath ) ) {
|
||||
|
||||
qDebug() << "Successfully created " << fi.path();
|
||||
|
||||
// Create a sitecopy config file
|
||||
SitecopyConfig scConfig;
|
||||
|
||||
scConfig.writeSiteConfig( syncFolder, /* local path */
|
||||
"ownCloud", /* _folderWizard->field("OCSiteAlias").toString(), site alias */
|
||||
ownCloudUrl(),
|
||||
ownCloudUser(),
|
||||
ownCloudPasswd(),
|
||||
targetPath );
|
||||
|
||||
// now there is the sitecopy config. A fetch in to the newly created folder mirrors
|
||||
// the files from the ownCloud to local
|
||||
startFetchFromOC( syncFolder );
|
||||
}
|
||||
// FIXME: Create a local sync folder.
|
||||
} else {
|
||||
qDebug() << "Failed to create " << fi.path();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OwncloudSetup::startFetchFromOC( const QString& syncFolder )
|
||||
void OwncloudSetupWizard::startFetchFromOC( const QString& syncFolder )
|
||||
{
|
||||
_scf = new SiteCopyFolder( "ownCloud",
|
||||
syncFolder,
|
||||
QString(), /* Remote folder missing, but thats no problem as the
|
||||
fetching does not rely on the information. Its taken
|
||||
from the sitecopy config in ~/.sitecopyrc */
|
||||
this);
|
||||
connect( _scf, SIGNAL( syncFinished( const SyncResult& )),
|
||||
SLOT( slotFetchFinished( const SyncResult& )));
|
||||
_ocWizard->appendToResultWidget( tr("Starting initial fetch of ownCloud data..."));
|
||||
_scf->fetchFromOC();
|
||||
qCritical( "Fetch not longer support, use full sync!" );
|
||||
}
|
||||
|
||||
void OwncloudSetup::slotFetchFinished( const SyncResult& res )
|
||||
{
|
||||
qDebug() << "Initial fetch finished!";
|
||||
if( res.result() == SyncResult::Error ) {
|
||||
_ocWizard->appendToResultWidget( tr("Initial fetch of data failed: ") + res.errorString() );
|
||||
} else {
|
||||
// fetch of data from ownCloud succeeded.
|
||||
_ocWizard->appendToResultWidget( tr("Initial fetch of data succeeded.") );
|
||||
_ocWizard->appendToResultWidget( tr("Writing mirall folder setting now.") );
|
||||
// create a mirall folder entry.
|
||||
// FIXME: folderConfigPath is a method of application object, copied to here.
|
||||
const QString folderConfigPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/folders";
|
||||
|
||||
const QString syncFolder( QDir::homePath() + "/ownCloud" );
|
||||
const QString targetPath("/");
|
||||
|
||||
QSettings settings(folderConfigPath + "/ownCloud", QSettings::IniFormat);
|
||||
settings.setValue("folder/backend", "sitecopy");
|
||||
settings.setValue("folder/path", syncFolder );
|
||||
settings.setValue("backend:sitecopy/targetPath", targetPath );
|
||||
settings.setValue("backend:sitecopy/alias", "ownCloud" );
|
||||
settings.sync();
|
||||
}
|
||||
_scf->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
#include "owncloudsetup.moc"
|
||||
#include "owncloudsetupwizard.moc"
|
|
@ -12,8 +12,8 @@
|
|||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef OWNCLOUDSETUP_H
|
||||
#define OWNCLOUDSETUP_H
|
||||
#ifndef OWNCLOUDSETUPWIZARD_H
|
||||
#define OWNCLOUDSETUPWIZARD_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
@ -26,11 +26,11 @@ namespace Mirall {
|
|||
class SiteCopyFolder;
|
||||
class SyncResult;
|
||||
|
||||
class OwncloudSetup : public QObject
|
||||
class OwncloudSetupWizard : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OwncloudSetup( QObject *parent = 0 );
|
||||
explicit OwncloudSetupWizard( QObject *parent = 0 );
|
||||
|
||||
void startWizard( );
|
||||
|
||||
|
@ -40,19 +40,12 @@ public:
|
|||
|
||||
void writeOwncloudConfig();
|
||||
|
||||
QString mirallConfigFile() const;
|
||||
|
||||
void startFetchFromOC( const QString& );
|
||||
|
||||
/**
|
||||
* returns the configured owncloud url if its already configured, otherwise an empty
|
||||
* string.
|
||||
*/
|
||||
QString ownCloudUrl() const ;
|
||||
QString ownCloudUser() const ;
|
||||
QString ownCloudPasswd() const ;
|
||||
|
||||
QUrl fullOwnCloudUrl() const;
|
||||
|
||||
void setupLocalSyncFolder();
|
||||
|
||||
|
@ -71,7 +64,6 @@ protected slots:
|
|||
void slotError( QProcess::ProcessError );
|
||||
void slotStarted();
|
||||
void slotFinished( int, QProcess::ExitStatus );
|
||||
void slotFetchFinished( const SyncResult& );
|
||||
|
||||
// wizard dialog signals
|
||||
void slotInstallOCServer();
|
||||
|
@ -84,9 +76,9 @@ private:
|
|||
|
||||
OwncloudWizard *_ocWizard;
|
||||
QProcess *_process;
|
||||
SiteCopyFolder *_scf;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif // OWNCLOUDSETUP_H
|
||||
#endif // OWNCLOUDSETUPWIZARD_H
|
|
@ -26,8 +26,12 @@ ownCloudTheme::ownCloudTheme()
|
|||
|
||||
QString ownCloudTheme::appName() const
|
||||
{
|
||||
return QString("ownCloud");
|
||||
return QString::fromLocal8Bit("ownCloud");
|
||||
}
|
||||
|
||||
QString ownCloudTheme::configFileName() const
|
||||
{
|
||||
return QString::fromLocal8Bit("owncloud.cfg");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
ownCloudTheme();
|
||||
|
||||
virtual QString appName() const;
|
||||
|
||||
QString configFileName() const;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
|
||||
virtual QString appName() const = 0;
|
||||
|
||||
virtual QString configFileName() const = 0;
|
||||
|
||||
private:
|
||||
|
||||
|
|
Loading…
Reference in a new issue