зеркало из https://github.com/nextcloud/desktop.git
Added check on correct oC Credentials on startup.
This commit is contained in:
Родитель
903c8ca220
Коммит
ccd1623528
|
@ -45,7 +45,7 @@ namespace Mirall {
|
|||
|
||||
Application::Application(int argc, char **argv) :
|
||||
QApplication(argc, argv),
|
||||
_tray(0),
|
||||
_tray(new QSystemTrayIcon(this)),
|
||||
_networkMgr(new QNetworkConfigurationManager(this)),
|
||||
_contextMenu(0),
|
||||
_ocInfo(0)
|
||||
|
@ -93,6 +93,9 @@ Application::Application(int argc, char **argv) :
|
|||
connect( _ocInfo,SIGNAL(noOwncloudFound(QNetworkReply::NetworkError)),
|
||||
SLOT(slotNoOwnCloudFound(QNetworkReply::NetworkError)));
|
||||
|
||||
connect( _ocInfo,SIGNAL(ownCloudDirExists(QString,QNetworkReply*)),
|
||||
this,SLOT(slotAuthCheck(QString,QNetworkReply*)));
|
||||
|
||||
_owncloudSetupWizard = new OwncloudSetupWizard( _folderMan, _theme );
|
||||
connect( _owncloudSetupWizard, SIGNAL(ownCloudWizardDone(int)), SLOT(slotStartFolderSetup()));
|
||||
|
||||
|
@ -120,7 +123,6 @@ Application::Application(int argc, char **argv) :
|
|||
}
|
||||
|
||||
setupActions();
|
||||
setupSystemTray();
|
||||
|
||||
QTimer::singleShot( 5000, this, SLOT(slotHideSplash()) );
|
||||
QTimer::singleShot( 0, this, SLOT( slotStartFolderSetup() ));
|
||||
|
@ -134,12 +136,13 @@ Application::~Application()
|
|||
|
||||
delete _networkMgr;
|
||||
delete _folderMan;
|
||||
delete _tray;
|
||||
delete _ocInfo;
|
||||
}
|
||||
|
||||
void Application::slotStartFolderSetup()
|
||||
{
|
||||
setupSystemTray();
|
||||
|
||||
if( _ocInfo->isConfigured() ) {
|
||||
_ocInfo->checkInstallation();
|
||||
} else {
|
||||
|
@ -150,16 +153,8 @@ void Application::slotStartFolderSetup()
|
|||
void Application::slotOwnCloudFound( const QString& url , const QString& version )
|
||||
{
|
||||
qDebug() << "** Application: ownCloud found: " << url << " with version " << version;
|
||||
int cnt = _folderMan->setupFolders();
|
||||
if( cnt ) {
|
||||
_tray->setIcon(_theme->folderIcon("owncloud", 24));
|
||||
_tray->show();
|
||||
if( _tray )
|
||||
_tray->showMessage(tr("ownCloud Sync Started"), tr("Sync started for %1 configured sync folder(s).").arg(cnt));
|
||||
}
|
||||
_actionAddFolder->setEnabled( true );
|
||||
|
||||
setupContextMenu();
|
||||
// now check the authentication!
|
||||
QTimer::singleShot( 0, this, SLOT( slotCheckAuthentication() ));
|
||||
}
|
||||
|
||||
void Application::slotNoOwnCloudFound( QNetworkReply::NetworkError err )
|
||||
|
@ -170,6 +165,33 @@ void Application::slotNoOwnCloudFound( QNetworkReply::NetworkError err )
|
|||
_actionAddFolder->setEnabled( false );
|
||||
setupContextMenu();
|
||||
}
|
||||
void Application::slotCheckAuthentication()
|
||||
{
|
||||
_ocInfo->getRequest("/", true ); // this call needs to be authenticated.
|
||||
// simply GET the webdav root, will fail if credentials are wrong.
|
||||
// continue in slotAuthCheck here :-)
|
||||
}
|
||||
|
||||
void Application::slotAuthCheck( const QString& ,QNetworkReply *reply )
|
||||
{
|
||||
if( reply->error() == QNetworkReply::AuthenticationRequiredError ) {
|
||||
qDebug() << "******** Credentials are wrong!";
|
||||
QMessageBox::warning(0, tr("No ownCloud Connection"),
|
||||
tr("Your ownCloud credentials are not correct. Please correct them by clicking on the tray icon!"));
|
||||
_actionAddFolder->setEnabled( false );
|
||||
} else {
|
||||
qDebug() << "######## Credentials are ok!";
|
||||
int cnt = _folderMan->setupFolders();
|
||||
if( cnt ) {
|
||||
_tray->setIcon(_theme->folderIcon("owncloud", 24));
|
||||
_tray->show();
|
||||
if( _tray )
|
||||
_tray->showMessage(tr("ownCloud Sync Started"), tr("Sync started for %1 configured sync folder(s).").arg(cnt));
|
||||
}
|
||||
_actionAddFolder->setEnabled( true );
|
||||
}
|
||||
setupContextMenu();
|
||||
}
|
||||
|
||||
void Application::slotHideSplash()
|
||||
{
|
||||
|
@ -190,8 +212,8 @@ void Application::setupActions()
|
|||
|
||||
void Application::setupSystemTray()
|
||||
{
|
||||
_tray = new QSystemTrayIcon(this);
|
||||
_tray->setIcon( _theme->folderIcon("none", 22) ); // load the grey icon
|
||||
// _tray = new QSystemTrayIcon(this);
|
||||
_tray->setIcon( _theme->folderIcon("none", 48) ); // load the grey icon
|
||||
|
||||
connect(_tray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
||||
SLOT(slotTrayClicked(QSystemTrayIcon::ActivationReason)));
|
||||
|
|
|
@ -78,6 +78,9 @@ protected slots:
|
|||
void slotStartFolderSetup();
|
||||
void slotOwnCloudFound( const QString&, const QString& );
|
||||
void slotNoOwnCloudFound( QNetworkReply::NetworkError );
|
||||
void slotCheckAuthentication();
|
||||
void slotAuthCheck( const QString& ,QNetworkReply* );
|
||||
|
||||
private:
|
||||
// configuration file -> folder
|
||||
QSystemTrayIcon *_tray;
|
||||
|
|
|
@ -172,8 +172,8 @@ FolderWizardTargetPage::FolderWizardTargetPage()
|
|||
|
||||
_ownCloudDirCheck = new ownCloudInfo();
|
||||
|
||||
connect( _ownCloudDirCheck, SIGNAL(ownCloudDirExists(QString,bool)),
|
||||
SLOT(slotDirCheckReply(QString,bool)));
|
||||
connect( _ownCloudDirCheck, SIGNAL(ownCloudDirExists(QString,QNetworkReply*)),
|
||||
SLOT(slotDirCheckReply(QString,QNetworkReply*)));
|
||||
}
|
||||
|
||||
void FolderWizardTargetPage::slotFolderTextChanged( const QString& t)
|
||||
|
@ -197,10 +197,10 @@ void FolderWizardTargetPage::slotTimerFires()
|
|||
_ownCloudDirCheck->getWebDAVPath( folder );
|
||||
}
|
||||
|
||||
void FolderWizardTargetPage::slotDirCheckReply(const QString &url, bool exists )
|
||||
void FolderWizardTargetPage::slotDirCheckReply(const QString &url, QNetworkReply *reply)
|
||||
{
|
||||
qDebug() << "Got reply from owncloud dir check: " << url << " :" << exists;
|
||||
_dirChecked = exists;
|
||||
qDebug() << "Got reply from owncloud dir check: " << url << " :" << reply->error();
|
||||
_dirChecked = (reply->error() == QNetworkReply::NoError);
|
||||
if( _dirChecked ) {
|
||||
showWarn();
|
||||
} else {
|
||||
|
|
|
@ -89,7 +89,7 @@ protected slots:
|
|||
|
||||
void slotFolderTextChanged( const QString& );
|
||||
void slotTimerFires();
|
||||
void slotDirCheckReply( const QString&, bool );
|
||||
void slotDirCheckReply( const QString&, QNetworkReply* );
|
||||
void showWarn( const QString& = QString(), bool showCreateButton = false ) const;
|
||||
void slotCreateRemoteFolder();
|
||||
void slotCreateRemoteFolderFinished( QNetworkReply* );
|
||||
|
|
|
@ -85,8 +85,8 @@ void ownCloudInfo::getRequest( const QString& path, bool webdav )
|
|||
request.setUrl( QUrl( url ) );
|
||||
request.setRawHeader( "User-Agent", QString("mirall-%1").arg(MIRALL_STRINGIFY(MIRALL_VERSION)).toAscii());
|
||||
request.setRawHeader( "Authorization", cfgFile.basicAuthHeader() );
|
||||
_reply = _manager->get( request );
|
||||
_readBuffer.clear();
|
||||
_reply = _manager->get( request );
|
||||
|
||||
connect( _reply, SIGNAL( error(QNetworkReply::NetworkError )),
|
||||
this, SLOT(slotError( QNetworkReply::NetworkError )));
|
||||
|
@ -138,7 +138,7 @@ void ownCloudInfo::slotReplyFinished( QNetworkReply *reply )
|
|||
}
|
||||
} else {
|
||||
// it was a general GET request.
|
||||
emit ownCloudDirExists( _directory, reply->error() == QNetworkReply::NoError );
|
||||
emit ownCloudDirExists( _directory, reply );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,8 +152,8 @@ void ownCloudInfo::slotReadyRead()
|
|||
|
||||
void ownCloudInfo::slotError( QNetworkReply::NetworkError err)
|
||||
{
|
||||
qDebug() << "Network Error: " << err;
|
||||
emit noOwncloudFound( err );
|
||||
qDebug() << "ownCloudInfo Network Error: " << err;
|
||||
// emit noOwncloudFound( err );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ signals:
|
|||
// result signal with url- and version string.
|
||||
void ownCloudInfoFound( const QString&, const QString& );
|
||||
void noOwncloudFound( QNetworkReply::NetworkError );
|
||||
void ownCloudDirExists( const QString&, bool );
|
||||
void ownCloudDirExists( const QString&, QNetworkReply* );
|
||||
|
||||
public slots:
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче