Handle startup network errors correctly.

This commit is contained in:
Klaas Freitag 2013-09-11 10:24:31 +02:00
parent 3c5c432e1d
commit ec06663dee
7 changed files with 78 additions and 31 deletions

View File

@ -210,6 +210,11 @@ void AccountSettings::setListWidgetItem( QListWidgetItem *item )
_item = item;
}
void AccountSettings::setGeneralErrors( const QStringList& errors )
{
_generalErrors = errors;
}
void AccountSettings::folderToModelItem( QStandardItem *item, Folder *f )
{
if( ! item || !f ) return;
@ -307,6 +312,22 @@ void AccountSettings::slotDoubleClicked( const QModelIndex& indx )
emit openFolderAlias( alias );
}
void AccountSettings::showConnectionLabel( const QString& message, const QString& tooltip )
{
const QString errStyle = QLatin1String("color:#ffffff; background-color:#bb4d4d;padding:5px;"
"border-width: 1px; border-style: solid; border-color: #aaaaaa;"
"border-radius:5px;");
if( _generalErrors.isEmpty() ) {
ui->connectLabel->setText( message );
ui->connectLabel->setToolTip(tooltip);
} else {
const QString msg = _generalErrors.join(QLatin1String("\n"));
ui->connectLabel->setText( msg );
ui->connectLabel->setToolTip(QString());
ui->connectLabel->setStyleSheet(errStyle);
}
}
void AccountSettings::slotCheckConnection()
{
if( ownCloudInfo::instance()->isConfigured() ) {
@ -315,12 +336,12 @@ void AccountSettings::slotCheckConnection()
connect(ownCloudInfo::instance(), SIGNAL(noOwncloudFound(QNetworkReply*)),
this, SLOT(slotOCInfoFail(QNetworkReply*)));
ui->connectLabel->setText( tr("Checking %1 connection...").arg(Theme::instance()->appNameGUI()));
showConnectionLabel( tr("Checking %1 connection...").arg(Theme::instance()->appNameGUI()));
qDebug() << "Check status.php from statusdialog.";
ownCloudInfo::instance()->checkInstallation();
} else {
// ownCloud is not yet configured.
ui->connectLabel->setText( tr("No %1 connection configured.").arg(Theme::instance()->appNameGUI()));
showConnectionLabel( tr("No %1 connection configured.").arg(Theme::instance()->appNameGUI()) );
ui->_ButtonAdd->setEnabled( false);
}
}
@ -449,8 +470,8 @@ void AccountSettings::slotOCInfo( const QString& url, const QString& versionStr,
ui->connectLabel->setOpenExternalLinks(true);
QUrl safeUrl(url);
safeUrl.setPassword(QString()); // Remove the password from the URL to avoid showing it in the UI
ui->connectLabel->setText( tr("Connected to <a href=\"%1\">%2</a>.").arg(url, safeUrl.toString()) );
ui->connectLabel->setToolTip( tr("Version: %1 (%2)").arg(versionStr).arg(version));
showConnectionLabel( tr("Connected to <a href=\"%1\">%2</a>.").arg(url, safeUrl.toString()),
tr("Version: %1 (%2)").arg(versionStr).arg(version) );
ui->_ButtonAdd->setEnabled(true);
disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudInfoFound(const QString&, const QString&, const QString&, const QString&)),
@ -464,7 +485,7 @@ void AccountSettings::slotOCInfoFail( QNetworkReply *reply)
QString errStr = tr("unknown problem.");
if( reply ) errStr = reply->errorString();
ui->connectLabel->setText( tr("<p>Failed to connect to %1: <tt>%2</tt></p>").arg(Theme::instance()->appNameGUI()).arg(errStr) );
showConnectionLabel( tr("<p>Failed to connect to %1: <tt>%2</tt></p>").arg(Theme::instance()->appNameGUI()).arg(errStr) );
ui->_ButtonAdd->setEnabled( false);
disconnect(ownCloudInfo::instance(), SIGNAL(ownCloudInfoFound(const QString&, const QString&, const QString&, const QString&)),

View File

@ -74,6 +74,8 @@ public slots:
void slotUpdateQuota( qint64,qint64 );
void slotIgnoreFilesEditor();
void setGeneralErrors( const QStringList& errors );
protected slots:
void slotAddFolder();
void slotAddFolder( Folder* );
@ -90,6 +92,7 @@ private:
QString shortenFilename( const QString& folder, const QString& file ) const;
void folderToModelItem( QStandardItem *, Folder * );
QStandardItem* itemForFolder(const QString& );
void showConnectionLabel( const QString& message, const QString& tooltip = QString() );
Ui::AccountSettings *ui;
QPointer<ItemProgressDialog> _fileItemDialog;
@ -99,6 +102,7 @@ private:
QUrl _OCUrl;
QHash<QStandardItem*, QTimer*> _hideProgressTimers;
QString _kindContext;
QStringList _generalErrors;
};

View File

@ -231,6 +231,8 @@ void Application::slotCredentialsFetched()
void Application::runValidator()
{
_startupFail.clear();
_conValidator = new ConnectionValidator();
connect( _conValidator, SIGNAL(connectionResult(ConnectionValidator::Status)),
this, SLOT(slotConnectionValidatorResult(ConnectionValidator::Status)) );
@ -255,14 +257,15 @@ void Application::slotConnectionValidatorResult(ConnectionValidator::Status stat
// queue up the sync for all folders.
folderMan->slotScheduleAllFolders();
computeOverallSyncStatus();
setupContextMenu();
} else if( status == ConnectionValidator::NotConfigured ) {
// this can not happen, it should be caught in first step of startup.
} else {
// What else?
// if we have problems here, it's unlikely that syncing will work.
FolderMan::instance()->setSyncEnabled(false);
_startupFail = _conValidator->errors();
}
computeOverallSyncStatus();
setupContextMenu();
_conValidator->deleteLater();
}
@ -694,6 +697,8 @@ void Application::slotSettings()
_settingsDialog->setAttribute( Qt::WA_DeleteOnClose, true );
_settingsDialog->show();
}
_settingsDialog->setGeneralErrors( _startupFail );
Utility::raiseDialog(_settingsDialog);
}
@ -816,23 +821,31 @@ void Application::computeOverallSyncStatus()
Folder::Map map = folderMan->map();
SyncResult overallResult = FolderMan::accountStatus(map.values());
// create the tray blob message, check if we have an defined state
if( overallResult.status() != SyncResult::Undefined ) {
QStringList allStatusStrings;
foreach(Folder* folder, map.values()) {
qDebug() << "Folder in overallStatus Message: " << folder << " with name " << folder->alias();
QString folderMessage = folderMan->statusToString(folder->syncResult().status(), folder->syncEnabled());
allStatusStrings += tr("Folder %1: %2").arg(folder->alias(), folderMessage);
}
if( ! allStatusStrings.isEmpty() )
trayMessage = allStatusStrings.join(QLatin1String("\n"));
else
trayMessage = tr("No sync folders configured.");
QIcon statusIcon = _theme->syncStateIcon( overallResult.status(), true);
// if there have been startup problems, show an error message.
if( !_startupFail.isEmpty() ) {
trayMessage = _startupFail.join(QLatin1String("\n"));
QIcon statusIcon = _theme->syncStateIcon( SyncResult::Error, true );
_tray->setIcon( statusIcon );
_tray->setToolTip(trayMessage);
} else {
// create the tray blob message, check if we have an defined state
if( overallResult.status() != SyncResult::Undefined ) {
QStringList allStatusStrings;
foreach(Folder* folder, map.values()) {
qDebug() << "Folder in overallStatus Message: " << folder << " with name " << folder->alias();
QString folderMessage = folderMan->statusToString(folder->syncResult().status(), folder->syncEnabled());
allStatusStrings += tr("Folder %1: %2").arg(folder->alias(), folderMessage);
}
if( ! allStatusStrings.isEmpty() )
trayMessage = allStatusStrings.join(QLatin1String("\n"));
else
trayMessage = tr("No sync folders configured.");
QIcon statusIcon = _theme->syncStateIcon( overallResult.status(), true);
_tray->setIcon( statusIcon );
_tray->setToolTip(trayMessage);
}
}
}

View File

@ -140,6 +140,7 @@ private:
QString _logFile;
QString _logDirectory;
QStringList _startupFail;
int _logExpire;
bool _showLogWindow;

View File

@ -89,6 +89,7 @@ void ConnectionValidator::checkConnection()
// checks for status.php
ownCloudInfo::instance()->checkInstallation();
} else {
_errors << tr("No ownCloud connection configured");
emit connectionResult( NotConfigured );
}
}
@ -109,8 +110,8 @@ void ConnectionValidator::slotStatusFound( const QString& url, const QString& ve
this, SLOT(slotNoStatusFound(QNetworkReply*)));
if( version.startsWith("4.0") ) {
_errors.append( tr("<p>The configured server for this client is too old.</p>"
"<p>Please update to the latest server and restart the client.</p>"));
_errors.append( tr("The configured server for this client is too old") );
_errors.append( tr("Please update to the latest server and restart the client.") );
emit connectionResult( ServerVersionMismatch );
return;
}
@ -144,15 +145,17 @@ void ConnectionValidator::slotCheckAuthentication()
// continue in slotAuthCheck here :-)
}
void ConnectionValidator::slotAuthCheck( const QString& ,QNetworkReply *reply )
void ConnectionValidator::slotAuthCheck( const QString&, QNetworkReply *reply )
{
Status stat = Connected;
if( reply->error() == QNetworkReply::AuthenticationRequiredError ||
reply->error() == QNetworkReply::OperationCanceledError ) { // returned if the user is wrong.
qDebug() << "******** Password is wrong!";
_errors << "The provided credentials are wrong.";
_errors << tr("The provided credentials are not correct");
stat = CredentialsWrong;
} else if( reply->error() != QNetworkReply::NoError ) {
_errors << reply->errorString();
}
// disconnect from ownCloud Info signals

View File

@ -123,4 +123,9 @@ void SettingsDialog::slotUpdateAccountState()
_accountItem->setIcon(Theme::instance()->syncStateIcon(state.status()));
}
void SettingsDialog::setGeneralErrors(const QStringList &errors)
{
_accountSettings->setGeneralErrors(errors);
}
} // namespace Mirall

View File

@ -40,6 +40,7 @@ public:
~SettingsDialog();
void addAccount(const QString &title, QWidget *widget);
void setGeneralErrors( const QStringList& errors );
protected slots:
void slotUpdateAccountState();
@ -48,7 +49,6 @@ private:
Ui::SettingsDialog *_ui;
AccountSettings *_accountSettings;
QListWidgetItem *_accountItem;
};
}