void OwncloudHttpCredsPage::initializePage() { WizardCommon::initErrorLabel(_ui.errorLabel); OwncloudWizard* ocWizard = qobject_cast< OwncloudWizard* >(wizard()); AbstractCredentials *cred = ocWizard->account()->credentials(); HttpCredentials *httpCreds = qobject_cast<HttpCredentials*>(cred); if (httpCreds) { const QString user = httpCreds->fetchUser(); if (!user.isEmpty()) { _ui.leUsername->setText(user); } } else { QUrl url = ocWizard->account()->url(); // If the final url does not have a username, check the // user specified url too. Sometimes redirects can lose // the user:pw information. if (url.userName().isEmpty()) { url = ocWizard->ocUrl(); } const QString user = url.userName(); const QString password = url.password(); if(!user.isEmpty()) { _ui.leUsername->setText(user); } if(!password.isEmpty()) { _ui.lePassword->setText(password); } } _ui.leUsername->setFocus(); }
void OwncloudHttpCredsPage::initializePage() { WizardCommon::initErrorLabel(_ui.errorLabel); OwncloudWizard* ocWizard = qobject_cast< OwncloudWizard* >(wizard()); AbstractCredentials *cred = ocWizard->account()->credentials(); HttpCredentials *httpCreds = qobject_cast<HttpCredentials*>(cred); if (httpCreds) { const QString user = httpCreds->fetchUser(ocWizard->account()); if (!user.isEmpty()) { _ui.leUsername->setText(user); } } _ui.leUsername->setFocus(); }
int main(int argc, char **argv) { QCoreApplication app(argc, argv); CmdOptions options; options.silent = false; options.trustSSL = false; options.useNetrc = false; options.interactive = true; ClientProxy clientProxy; parseOptions( app.arguments(), &options ); QUrl url = QUrl::fromUserInput(options.target_url); // Fetch username and password. If empty, try to retrieve // from URL and strip URL QString user; QString password; if (options.useNetrc) { NetrcParser parser; if (parser.parse()) { NetrcParser::LoginPair pair = parser.find(url.host()); user = pair.first; password = pair.second; } } else { user = options.user; if (user.isEmpty()) { user = url.userName(); } password = options.password; if (password.isEmpty()) { password = url.password(); } if (options.interactive) { if (user.isEmpty()) { std::cout << "Please enter user name: "; std::string s; std::getline(std::cin, s); user = QString::fromStdString(s); } if (password.isEmpty()) { password = queryPassword(user); } } } // ### ensure URL is free of credentials if (url.userName().isEmpty()) { url.setUserName(user); } if (url.password().isEmpty()) { url.setPassword(password); } Account account; // Find the folder and the original owncloud url QStringList splitted = url.path().split(account.davPath()); url.setPath(splitted.value(0)); url.setScheme(url.scheme().replace("owncloud", "http")); QString folder = splitted.value(1); SimpleSslErrorHandler *sslErrorHandler = new SimpleSslErrorHandler; HttpCredentials *cred = new HttpCredentialsText(user, password); account.setUrl(url); account.setCredentials(cred); account.setSslErrorHandler(sslErrorHandler); AccountManager::instance()->setAccount(&account); restart_sync: CSYNC *_csync_ctx; if( csync_create( &_csync_ctx, options.source_dir.toUtf8(), url.toEncoded().constData()) < 0 ) { qFatal("Unable to create csync-context!"); return EXIT_FAILURE; } int rc = ne_sock_init(); if (rc < 0) { qFatal("ne_sock_init failed!"); } csync_set_log_level(options.silent ? 1 : 11); opts = &options; cred->syncContextPreInit(_csync_ctx); if( csync_init( _csync_ctx ) < 0 ) { qFatal("Could not initialize csync!"); return EXIT_FAILURE; } csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx); if( !options.proxy.isNull() ) { QString host; int port = 0; bool ok; // Set as default and let overwrite later csync_set_module_property(_csync_ctx, "proxy_type", (void*) "NoProxy"); QStringList pList = options.proxy.split(':'); if(pList.count() == 3) { // http: //192.168.178.23 : 8080 // 0 1 2 host = pList.at(1); if( host.startsWith("//") ) host.remove(0, 2); port = pList.at(2).toInt(&ok); if( !host.isNull() ) { csync_set_module_property(_csync_ctx, "proxy_type", (void*) "HttpProxy"); csync_set_module_property(_csync_ctx, "proxy_host", host.toUtf8().data()); if( ok && port ) { csync_set_module_property(_csync_ctx, "proxy_port", (void*) &port); } } } } else { clientProxy.setupQtProxyFromConfig(); QString url( options.target_url ); if( url.startsWith("owncloud")) { url.remove(0, 8); url = QString("http%1").arg(url); } clientProxy.setCSyncProxy(QUrl(url), _csync_ctx); } if (!options.exclude.isEmpty()) { csync_add_exclude_list(_csync_ctx, options.exclude.toLocal8Bit()); } cred->syncContextPreStart(_csync_ctx); Cmd cmd; SyncJournalDb db(options.source_dir); SyncEngine engine(_csync_ctx, options.source_dir, QUrl(options.target_url).path(), folder, &db); QObject::connect(&engine, SIGNAL(finished()), &app, SLOT(quit())); QObject::connect(&engine, SIGNAL(transmissionProgress(Progress::Info)), &cmd, SLOT(transmissionProgressSlot())); // Have to be done async, else, an error before exec() does not terminate the event loop. QMetaObject::invokeMethod(&engine, "startSync", Qt::QueuedConnection); app.exec(); csync_destroy(_csync_ctx); ne_sock_exit(); if (engine.isAnotherSyncNeeded()) { qDebug() << "Restarting Sync, because another sync is needed"; goto restart_sync; } return 0; }