improved error handling

This commit is contained in:
Klaas Freitag 2011-09-26 18:19:01 +02:00
parent 0000caa632
commit b3eecf54a5
8 changed files with 60 additions and 27 deletions

View File

@ -174,7 +174,8 @@ void Application::slotAddFolder()
alias, /* _folderWizard->field("OCSiteAlias").toString(), site alias */
_folderWizard->field("OCUrl").toString(), /* site URL */
_folderWizard->field("OCUser").toString(),
_folderWizard->field("OCPasswd").toString() );
_folderWizard->field("OCPasswd").toString(),
_folderWizard->field("targetOCFolder").toString() );
} else {
qWarning() << "* Folder not local and note remote?";
return;

View File

@ -19,7 +19,7 @@
#include <QUrl>
#include <QValidator>
#include <QWizardPage>
#include <QDir>
#include <stdlib.h>
#include "mirall/folderwizard.h"
@ -31,7 +31,9 @@ FolderWizardSourcePage::FolderWizardSourcePage()
{
_ui.setupUi(this);
registerField("sourceFolder*", _ui.localFolderLineEdit);
_ui.localFolderLineEdit->setText( QString( "%1/%2").arg( QDir::homePath() ).arg("/Owncloud" ) );
registerField("alias*", _ui.aliasLineEdit);
_ui.aliasLineEdit->setText( QString::fromLatin1("Owncloud") );
}
FolderWizardSourcePage::~FolderWizardSourcePage()
@ -62,16 +64,17 @@ FolderWizardTargetPage::FolderWizardTargetPage()
{
_ui.setupUi(this);
registerField("local?", _ui.localFolderRadioBtn);
registerField("remote?", _ui.urlFolderRadioBtn);
registerField("OC?", _ui.OCRadioBtn);
registerField("local?", _ui.localFolderRadioBtn);
registerField("remote?", _ui.urlFolderRadioBtn);
registerField("OC?", _ui.OCRadioBtn);
registerField("targetLocalFolder", _ui.localFolder2LineEdit);
registerField("targetURLFolder", _ui.urlFolderLineEdit);
registerField("targetOCFolder", _ui.OCFolderLineEdit);
registerField("targetURLFolder", _ui.urlFolderLineEdit);
registerField("targetOCFolder", _ui.OCFolderLineEdit);
}
FolderWizardTargetPage::~FolderWizardTargetPage()
{
}
bool FolderWizardTargetPage::isComplete() const

View File

@ -170,7 +170,7 @@
<item row="5" column="2">
<widget class="QLineEdit" name="OCFolderLineEdit">
<property name="placeholderText">
<string>Sync</string>
<string>Sync-directory</string>
</property>
</widget>
</item>

View File

@ -23,7 +23,8 @@ SitecopyConfig::SitecopyConfig()
void SitecopyConfig::writeSiteConfig( const QString& localPath,
const QString& siteAlias, const QString& url,
const QString& user, const QString& passwd )
const QString& user, const QString& passwd,
const QString& remoteFolder )
{
parseSiteConfig( );
qDebug() << "*** Writing Site Alias " << siteAlias;
@ -47,10 +48,13 @@ void SitecopyConfig::writeSiteConfig( const QString& localPath,
ocDefs["server"] = host;
ocDefs["protocol"] = "webdav";
ocDefs["local"] = localPath;
ocDefs["remote"] = path + "/files/webdav.php";
QString webdavBase = "/files/webdav.php";
if( !remoteFolder.isEmpty() ) {
webdavBase += "/" + remoteFolder;
}
ocDefs["remote"] = path + webdavBase;
ocDefs["password"] = passwd;
// QString user( getenv("USER"));
ocDefs["username"] = user;
_Sites.insert( siteAlias, ocDefs );
@ -70,20 +74,20 @@ void SitecopyConfig::writeSiteConfig( const QString& localPath,
out << " " << configKey << " " << configs[configKey] << '\n';
qDebug() << " Setting: " << configKey << ": " << configs[configKey];
}
out << '\n';
}
configFile.close();
configFile.setPermissions( QFile::ReadOwner | QFile::WriteOwner );
out << '\n';
}
configFile.close();
configFile.setPermissions( QFile::ReadOwner | QFile::WriteOwner );
// check if the .sitecopy dir is there, if not, create
if( !QFile::exists( QDir::homePath() + "/.sitecopy" ) ) {
QDir home( QDir::homePath() );
if( home.mkdir( ".sitecopy" ) ) {
QFile::setPermissions( QDir::homePath() + "/.sitecopy",
QFile::ReadOwner | QFile::WriteOwner | QFile::ExeUser );
}
}
}
// check if the .sitecopy dir is there, if not, create
if( !QFile::exists( QDir::homePath() + "/.sitecopy" ) ) {
QDir home( QDir::homePath() );
if( home.mkdir( ".sitecopy" ) ) {
QFile::setPermissions( QDir::homePath() + "/.sitecopy",
QFile::ReadOwner | QFile::WriteOwner | QFile::ExeUser );
}
}
}
bool SitecopyConfig::parseSiteConfig( )
{

View File

@ -24,7 +24,8 @@ public:
void writeSiteConfig( const QString& localPath, const QString& siteAlias,
const QString& host, const QString& user,
const QString& passwd );
const QString& passwd,
const QString& remoteFolder = QString() );
bool parseSiteConfig();
private:

View File

@ -115,6 +115,17 @@ void SiteCopyFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
emit( syncFinished( SyncResult( SyncResult::Error )));
}
if( exitCode > 0 ) {
// error has happened.
QString out( _lastOutput );
SyncResult res( SyncResult::Error );
res.setErrorString( out );
qDebug() << "An error happened: " << out;
emit syncFinished( res );
return;
}
if( _NextStep == Sync ) {
startSiteCopy( "--sync", Finish ); // sync local with cloud data.
} else if( _NextStep == Update ) {
@ -212,7 +223,7 @@ void SiteCopyFolder::slotReadyReadStandardOutput()
}
emit statusString( _StatusString );
} else if( _NextStep == DisplayStatus ) {
} else { /* if( _NextStep == DisplayStatus ) { */
_lastOutput += arr;
}
@ -223,7 +234,7 @@ void SiteCopyFolder::slotReadyReadStandardOutput()
void SiteCopyFolder::slotReadyReadStandardError()
{
QTextStream stream(&_lastOutput);
stream << _SiteCopy->readAllStandardError();;
stream << _SiteCopy->readAllStandardError();
}
void SiteCopyFolder::slotStateChanged(QProcess::ProcessState state)

View File

@ -28,6 +28,16 @@ SyncResult::Result SyncResult::result() const
return _result;
}
void SyncResult::setErrorString( const QString& err )
{
_errorMsg = err;
}
QString SyncResult::errorString() const
{
return _errorMsg;
}
SyncResult::~SyncResult()
{

View File

@ -31,6 +31,8 @@ public:
SyncResult(Result result);
~SyncResult();
void setErrorString( const QString& );
QString errorString() const;
Result result() const;
@ -41,6 +43,7 @@ private:
*/
QStringList _deletedSource;
QStringList _deletedDestination;
QString _errorMsg;
};
}