void OwncloudSetupWizard::startWizard(bool intro)
{
    // create the ocInfo object
    connect(ownCloudInfo::instance(),SIGNAL(ownCloudInfoFound(QString,QString,QString,QString)),SLOT(slotOwnCloudFound(QString,QString,QString,QString)));
    connect(ownCloudInfo::instance(),SIGNAL(noOwncloudFound(QNetworkReply*)),SLOT(slotNoOwnCloudFound(QNetworkReply*)));
    connect(ownCloudInfo::instance(),SIGNAL(webdavColCreated(QNetworkReply::NetworkError)),SLOT(slotCreateRemoteFolderFinished(QNetworkReply::NetworkError)));

    MirallConfigFile cfgFile;

    QString url = cfgFile.ownCloudUrl();
    if( !url.isEmpty() ) {
        _ocWizard->setOCUrl( url );
    }
#ifdef OWNCLOUD_CLIENT
    QString user = cfgFile.ownCloudUser();
    if( !user.isEmpty() ) {
        _ocWizard->setOCUser( user );
    }

    bool doStore = cfgFile.passwordStorageAllowed();
    _ocWizard->setAllowPasswordStorage( doStore );

    if (intro)
        _ocWizard->setStartId(OwncloudWizard::Page_oCWelcome);
    else
        _ocWizard->setStartId(OwncloudWizard::Page_oCSetup);
#endif
    _ocWizard->restart();
    _ocWizard->show();
}
Beispiel #2
0
void CredentialStore::fetchCredentials()
{
    _state = Fetching;
    MirallConfigFile cfgFile;

    if( ++_tries > MAX_LOGIN_ATTEMPTS ) {
        qDebug() << "Too many attempts to enter password!";
        _state = TooManyAttempts;
        return;
    }

    bool ok = false;
    QString pwd;
    _state = Fetching;
    _user = cfgFile.ownCloudUser();

    switch( _type ) {
    case CredentialStore::User: {
        /* Ask the user for the password */
        /* Fixme: Move user interaction out here. */
        pwd = QInputDialog::getText(0, QApplication::translate("MirallConfigFile","Password Required"),
                                    QApplication::translate("MirallConfigFile","Please enter your %1 password:"******"QtKeyChain: Not yet implemented!";
        _state = Error;
#endif
        break;
    }
    default: {
        break;
    }
    }
Beispiel #3
0
void ownCloudFolder::startSync(const QStringList &pathList)
{
    if (_csync && _csync->isRunning()) {
        qCritical() << "* ERROR csync is still running and new sync requested.";
        return;
    }
    delete _csync;

    MirallConfigFile cfgFile;

    QUrl url( _secondPath );
    url.setScheme( "owncloud" );
    qDebug() << "*** Start syncing to ownCloud, onlyLocal: " << _localCheckOnly;

    _csync = new CSyncThread(path(), url.toEncoded(), _localCheckOnly );
    _csync->setUserPwd( cfgFile.ownCloudUser(), cfgFile.ownCloudPasswd() );
    QObject::connect(_csync, SIGNAL(started()),  SLOT(slotCSyncStarted()));
    QObject::connect(_csync, SIGNAL(finished()), SLOT(slotCSyncFinished()));
    _csync->start();
}
Beispiel #4
0
void OwncloudSetupWizard::startWizard()
{
    // Set useful default values.
    MirallConfigFile cfgFile;
    // Fill the entry fields with existing values.
    QString url = cfgFile.ownCloudUrl();
    QString user = cfgFile.ownCloudUser();
    bool configExists = !( url.isEmpty() || user.isEmpty() );
    _ocWizard->setConfigExists( configExists );

    if( !user.isEmpty() ) {
        _ocWizard->setOCUser( user );
    }

    if( !url.isEmpty() ) {
        _ocWizard->setOCUrl( url );
    }

    _remoteFolder = Theme::instance()->defaultServerFolder();
    // remoteFolder may be empty, which means /

    QString localFolder = Theme::instance()->defaultClientFolder();

    // if its a relative path, prepend with users home dir, otherwise use as absolute path
    if( !localFolder.startsWith(QLatin1Char('/')) ) {
        localFolder = QDir::homePath() + QDir::separator() + Theme::instance()->defaultClientFolder();
    }
    _ocWizard->setProperty("localFolder", localFolder);
    _ocWizard->setRemoteFolder(_remoteFolder);

    _ocWizard->setStartId(OwncloudWizard::Page_oCSetup);

    _ocWizard->restart();

    // settings re-initialized in initPage must be set here after restart
    _ocWizard->setMultipleFoldersExist(_folderMan->map().count() > 1);

    _ocWizard->open();
    _ocWizard->raise();
}
bool OwncloudSetupWizard::createRemoteFolder( const QString& folder )
{
    if( folder.isEmpty() ) return false;

    MirallConfigFile cfgFile;

    QString url = cfgFile.ownCloudUrl( cfgFile.defaultConnection(), true );
    url.append( folder );
    qDebug() << "creating folder on ownCloud: " << url;

    MirallWebDAV *webdav = new MirallWebDAV(this);
    connect( webdav, SIGNAL(webdavFinished(QNetworkReply*)),
             SLOT(slotCreateRemoteFolderFinished(QNetworkReply*)));

    webdav->httpConnect( url, cfgFile.ownCloudUser(), cfgFile.ownCloudPasswd() );
    if( webdav->mkdir(  url  ) ) {
        qDebug() << "WebDAV mkdir request successfully started";
        return true;
    } else {
        qDebug() << "WebDAV mkdir request failed";
        return false;
    }
}
// Method executed when the user ends the wizard, either with 'accept' or 'reject'.
// accept the custom config to be the main one if Accepted.
void OwncloudSetupWizard::slotAssistantFinished( int result )
{
    MirallConfigFile cfg( _configHandle );


    if( result == QDialog::Rejected ) {
        // the old config remains valid. Remove the temporary one.
        cfg.cleanupCustomConfig();
        qDebug() << "Rejected the new config, use the old!";
    } else if( result == QDialog::Accepted ) {
        qDebug() << "Config Changes were accepted!";

        // go through all folders and remove the journals if the server changed.
        MirallConfigFile prevCfg;
        QUrl prevUrl( prevCfg.ownCloudUrl() );
        QUrl newUrl( cfg.ownCloudUrl() );

        bool urlHasChanged = (prevUrl.host() != newUrl.host() || prevUrl.path() != newUrl.path());

        // if the user changed, its also a changed url.
        if( prevCfg.ownCloudUser() != cfg.ownCloudUser() ) {
            urlHasChanged = true;
            qDebug() << "The User has changed, same as url change.";
        }

        const QString localFolder = _ocWizard->localFolder();
        bool acceptCfg = true;

        if( urlHasChanged ) {
            _folderMan->unloadAllFolders();

           bool startFromScratch = _ocWizard->field( "OCSyncFromScratch" ).toBool();
            if( startFromScratch ) {
                // first try to rename (backup) the current local dir.
                bool renameOk = false;
                while( !renameOk ) {
                    renameOk = _folderMan->startFromScratch(localFolder);
                    if( ! renameOk ) {
                        QMessageBox::StandardButton but;
                        but = QMessageBox::question( 0, tr("Folder rename failed"),
                                                     tr("Can't remove and back up the folder because the folder or a file in it is open in another program."
                                                        "Please close the folder or file and hit retry or cancel the setup."), QMessageBox::Retry | QMessageBox::Abort, QMessageBox::Retry);
                        if( but == QMessageBox::Abort ) {
                            renameOk = true;
                            acceptCfg = false;
                        }
                    }
                }
            }
        }
        // save the user credentials and afterwards clear the cred store.
        if( acceptCfg ) {
            cfg.acceptCustomConfig();
        }

        // Now write the resulting folder definition if folder names are set.
        if( acceptCfg && urlHasChanged ) {
            _folderMan->removeAllFolderDefinitions();
            _folderMan->addFolderDefinition( QLatin1String("owncloud"), Theme::instance()->appName(),
                                             localFolder, _remoteFolder, false );
            _ocWizard->appendToConfigurationLog(tr("<font color=\"green\"><b>Local sync folder %1 successfully created!</b></font>").arg(localFolder));
        } else {
            // url is unchanged. Only the password was changed.
            if( acceptCfg ) {
                qDebug() << "Only password was changed, no changes to folder configuration.";
            } else {
                qDebug() << "User interrupted change of configuration.";
            }
        }
    }

    // clear the custom config handle
    _configHandle.clear();
    ownCloudInfo::instance()->setCustomConfigHandle( QString::null );

    // notify others.
    emit ownCloudWizardDone( result );
}
// Method executed when the user ends the wizard, either with 'accept' or 'reject'.
// accept the custom config to be the main one if Accepted.
void OwncloudSetupWizard::slotAssistantFinished( int result )
{
    MirallConfigFile cfg( _configHandle );


    if( result == QDialog::Rejected ) {
        // the old config remains valid. Remove the temporary one.
        cfg.cleanupCustomConfig();
        qDebug() << "Rejected the new config, use the old!";
    } else if( result == QDialog::Accepted ) {
        qDebug() << "Config Changes were accepted!";

        // go through all folders and remove the journals if the server changed.
        MirallConfigFile prevCfg;
        QUrl prevUrl( prevCfg.ownCloudUrl() );
        QUrl newUrl( cfg.ownCloudUrl() );

        bool urlHasChanged = (prevUrl.host() != newUrl.host() || prevUrl.path() != newUrl.path());

        // if the user changed, its also a changed url.
        if( prevCfg.ownCloudUser() != cfg.ownCloudUser() ) {
            urlHasChanged = true;
            qDebug() << "The User has changed, same as url change.";
        }

        // save the user credentials and afterwards clear the cred store.
        cfg.acceptCustomConfig();

        // Now write the resulting folder definition if folder names are set.
        const QString localFolder = _ocWizard->localFolder();
        if( !( localFolder.isEmpty() || _remoteFolder.isEmpty() ) ) { // both variables are set.
            if( urlHasChanged ) {
                _folderMan->removeAllFolderDefinitions();
                _folderMan->addFolderDefinition( QLatin1String("owncloud"), Theme::instance()->appName(),
                                                 localFolder, _remoteFolder, false );
                _ocWizard->appendToConfigurationLog(tr("<font color=\"green\"><b>Local sync folder %1 successfully created!</b></font>").arg(localFolder));

                bool startFromScratch = _ocWizard->field( "OCSyncFromScratch" ).toBool();
                if( startFromScratch ) {
                    // clean the entire directory.
                    if( _folderMan->startFromScratch( localFolder ) ) {
                        _ocWizard->appendToConfigurationLog(tr("<font color=\"green\">Successfully prepared syncing from scratch!</font>"));
                    } else {
                        _ocWizard->appendToConfigurationLog(tr("<font color=\"red\">Failed to prepare syncing from scratch!</font>"));
                    }
                }
            } else {
                // url is unchanged. Only the password was changed.
                qDebug() << "Only password was changed, no changes to folder configuration.";
            }
        }
    } else {
        qDebug() << "WRN: Got unknown dialog result code " << result;
    }

    // clear the custom config handle
    _configHandle.clear();
    ownCloudInfo::instance()->setCustomConfigHandle( QString::null );

    // notify others.
    emit ownCloudWizardDone( result );
}