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();
}
Exemple #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;
    }
    }
void OwncloudSetupWizard::startWizard()
{
    MirallConfigFile cfgFile;

    QString url = cfgFile.ownCloudUrl();
    if( !url.isEmpty() ) {
        _ocWizard->setOCUrl( url );
    }
    _ocWizard->restart();
    _ocWizard->show();
}
Exemple #4
0
QString ownCloudFolder::secondPath() const
{
    QString re(_secondPath);
    MirallConfigFile cfg;
    const QString ocUrl = cfg.ownCloudUrl(QString::null, true);
    // qDebug() << "**** " << ocUrl << " <-> " << re;
    if( re.startsWith( ocUrl ) ) {
        re.remove( ocUrl );
    }

    return re;
}
Exemple #5
0
void ownCloudFolder::startSync(const QStringList &pathList)
{
    if (_thread && _thread->isRunning()) {
        qCritical() << "* ERROR csync is still running and new sync requested.";
        return;
    }

    delete _csync;
    delete _thread;
    _errors.clear();
    _csyncError = false;
    _csyncUnavail = false;
    _wipeDb = false;

    MirallConfigFile cfgFile;

    _syncResult.clearErrors();
    // we now have watchers for everything, so every sync is remote.
    _syncResult.setLocalRunOnly( false );
    _syncResult.setStatus( SyncResult::SyncPrepare );
    emit syncStateChange();

    QString url = replaceScheme(_secondPath);

    qDebug() << "*** Start syncing url to ownCloud: " << url;
    _thread = new QThread(this);
    _csync = new CSyncThread( path(), url);
    _csync->moveToThread(_thread);

    QList<QNetworkProxy> proxies = QNetworkProxyFactory::proxyForQuery(QUrl(cfgFile.ownCloudUrl()));
    // We set at least one in Application
    Q_ASSERT(proxies.count() > 0);
    QNetworkProxy proxy = proxies.first();

    _csync->setConnectionDetails( CredentialStore::instance()->user(),
                                  CredentialStore::instance()->password(),
                                  proxy );
    qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector");
    connect( _csync, SIGNAL(treeWalkResult(const SyncFileItemVector&)),
              this, SLOT(slotThreadTreeWalkResult(const SyncFileItemVector&)), Qt::QueuedConnection);

    connect(_csync, SIGNAL(started()),  SLOT(slotCSyncStarted()), Qt::QueuedConnection);
    connect(_csync, SIGNAL(finished()), SLOT(slotCSyncFinished()), Qt::QueuedConnection);
    connect(_csync, SIGNAL(csyncError(QString)), SLOT(slotCSyncError(QString)), Qt::QueuedConnection);
    connect(_csync, SIGNAL(csyncUnavailable()), SLOT(slotCsyncUnavailable()), Qt::QueuedConnection);
    _thread->start();
    QMetaObject::invokeMethod(_csync, "startSync", Qt::QueuedConnection);
    emit syncStarted();
}
// 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;
        if( prevCfg.ownCloudUrl() != cfg.ownCloudUrl() ) {
            qDebug() << "ownCloud URL has changed, journals needs to be wiped.";
            _folderMan->wipeAllJournals();
        }

        // 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->property("localFolder").toString();
        if( !( localFolder.isEmpty() || _remoteFolder.isEmpty() ) ) { // both variables are set.
            if( _folderMan ) {
                _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 {
                qDebug() << "WRN: Folderman is zero in Setup Wizzard.";
            }
        }
    } 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 );
}
bool OwncloudAdvancedSetupPage::dataChanged()
{
    OwncloudWizard* ocWizard(dynamic_cast< OwncloudWizard* >(wizard()));

    if (!ocWizard) {
        return false;
    }

    MirallConfigFile cfgFile;
    const QString url(field("OCUrl").toString());
    AbstractCredentials* newCredentials(ocWizard->getCredentials());
    AbstractCredentials* oldCredentials(cfgFile.getCredentials());
    const bool differentCreds(oldCredentials->changed(newCredentials));
    delete newCredentials;
    const QString newLocalFolder(QDir::toNativeSeparators(_ui.pbSelectLocalFolder->text()));
    const QString oldLocalFolder(QDir::toNativeSeparators(_oldLocalFolder));

    return ((url != cfgFile.ownCloudUrl()) || differentCreds || (oldLocalFolder != newLocalFolder));
}
Exemple #8
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 );
}
ownCloudFolder::ownCloudFolder(const QString &alias,
                               const QString &mpath,
                               const QString &secondPath,
                               QObject *parent)
    : Folder(alias, mpath, secondPath, parent)
    , _thread(0)
    , _csync(0)
    , _csyncError(false)
    , _csyncUnavail(false)
    , _wipeDb(false)
{
    ServerActionNotifier *notifier = new ServerActionNotifier(this);
    connect(notifier, SIGNAL(guiLog(QString,QString)), Logger::instance(), SIGNAL(guiLog(QString,QString)));
    connect(this, SIGNAL(syncFinished(SyncResult)), notifier, SLOT(slotSyncFinished(SyncResult)));
    qDebug() << "****** ownCloud folder using watcher *******";
    // The folder interval is set in the folder parent class.

    QString url = replaceScheme(secondPath);
    QString localpath = path();

    if( csync_create( &_csync_ctx, localpath.toUtf8().data(), url.toUtf8().data() ) < 0 ) {
        qDebug() << "Unable to create csync-context!";
        _csync_ctx = 0;
    } else {
        csync_set_log_callback(   _csync_ctx, csyncLogCatcher );
        csync_set_log_verbosity(_csync_ctx, 11);

        MirallConfigFile cfgFile;
        csync_set_config_dir( _csync_ctx, cfgFile.configPath().toUtf8() );

        csync_enable_conflictcopys(_csync_ctx);
        QString excludeList = cfgFile.excludeFile();
        if( !excludeList.isEmpty() ) {
            qDebug() << "==== added CSync exclude List: " << excludeList.toUtf8();
            csync_add_exclude_list( _csync_ctx, excludeList.toUtf8() );
        }
        csync_set_auth_callback( _csync_ctx, getauth );

        if( csync_init( _csync_ctx ) < 0 ) {
            qDebug() << "Could not initialize csync!";
            _csync_ctx = 0;
        }

        if( _csync_ctx ) {
            /* Store proxy */
            QList<QNetworkProxy> proxies = QNetworkProxyFactory::proxyForQuery(QUrl(cfgFile.ownCloudUrl()));
            // We set at least one in Application
            Q_ASSERT(proxies.count() > 0);
            QNetworkProxy proxy = proxies.first();
            int proxyPort = proxy.port();

            csync_set_module_property(_csync_ctx, "proxy_type", (char*) proxyTypeToCStr(proxy.type()) );
            csync_set_module_property(_csync_ctx, "proxy_host", proxy.hostName().toUtf8().data() );
            csync_set_module_property(_csync_ctx, "proxy_port", &proxyPort );
            csync_set_module_property(_csync_ctx, "proxy_user", proxy.user().toUtf8().data()     );
            csync_set_module_property(_csync_ctx, "proxy_pwd" , proxy.password().toUtf8().data() );

            csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx);
        }
    }
}