From 926f7ce4a53de9e89d28739c6852789b737222ae Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Tue, 5 Jun 2012 15:11:29 +0200 Subject: [PATCH 1/7] Added a window for log output. Added log handlers for both the cmake logging and the mirall logging. Push all logging to a log window with the ability to save to a file. --- src/CMakeLists.txt | 13 +- src/mirall/application.cpp | 32 +++- src/mirall/application.h | 4 +- src/mirall/logbrowser.cpp | 252 ++++++++++++++++++++++++++++++++ src/mirall/logbrowser.h | 104 +++++++++++++ src/mirall/mirallconfigfile.cpp | 14 ++ src/mirall/mirallconfigfile.h | 5 + src/mirall/statusdialog.cpp | 1 + src/mirall/statusdialog.h | 1 + src/mirall/statusdialog.ui | 152 +++++++++++-------- 10 files changed, 505 insertions(+), 73 deletions(-) create mode 100644 src/mirall/logbrowser.cpp create mode 100644 src/mirall/logbrowser.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 456cbd414..eb764c26f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,7 +43,7 @@ mirall/mirallconfigfile.cpp mirall/updatedetector.cpp mirall/occinfo.cpp mirall/sslerrordialog.cpp - +mirall/logbrowser.cpp ) set(mirall_HEADERS @@ -63,6 +63,7 @@ set(mirall_HEADERS mirall/csyncthread.h mirall/updatedetector.h mirall/sslerrordialog.h + mirall/logbrowser.h ) if( UNIX AND NOT APPLE) @@ -182,11 +183,11 @@ endif() find_program(KRAZY2_EXECUTABLE krazy2) if(KRAZY2_EXECUTABLE) -# s/y k/y ALL k/ for building this target always -add_custom_target( krazy krazy2 --check-sets c++,qt4,foss - ${PROJECT_SOURCE_DIR}/src/mirall/*.ui - ${PROJECT_SOURCE_DIR}/src/mirall/*.h - ${PROJECT_SOURCE_DIR}/src/mirall/*.cpp + # s/y k/y ALL k/ for building this target always + add_custom_target( krazy krazy2 --check-sets c++,qt4,foss + ${PROJECT_SOURCE_DIR}/src/mirall/*.ui + ${PROJECT_SOURCE_DIR}/src/mirall/*.h + ${PROJECT_SOURCE_DIR}/src/mirall/*.cpp ) endif() diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index b483e6da8..0386d7bae 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -12,6 +12,8 @@ * for more details. */ +#define LOG_TO_CALLBACK // FIXME: This should be in csync. + #include "mirall/application.h" #include "mirall/folder.h" #include "mirall/folderwatcher.h" @@ -34,6 +36,8 @@ #endif #include "mirall/inotify.h" +#include + #include #include #include @@ -44,6 +48,20 @@ namespace Mirall { +// application logging handler. +void mirallLogCatcher(QtMsgType type, const char *msg) +{ + Q_UNUSED(type) + Logger::instance()->mirallLog( msg ); +} + +void csyncLogCatcher(const char *msg) +{ + Logger::instance()->csyncLog( msg ); +} + +// ---------------------------------------------------------------------------------- + Application::Application(int &argc, char **argv) : QApplication(argc, argv), _tray(0), @@ -117,6 +135,9 @@ Application::Application(int &argc, char **argv) : connect( _statusDialog, SIGNAL(removeFolderAlias( const QString&)), SLOT(slotRemoveFolder(const QString&))); + + connect( _statusDialog, SIGNAL(openLogBrowser()), this, SLOT(slotOpenLogBrowser())); + #if 0 connect( _statusDialog, SIGNAL(fetchFolderAlias(const QString&)), SLOT(slotFetchFolder( const QString&))); @@ -141,6 +162,10 @@ Application::Application(int &argc, char **argv) : setupSystemTray(); processEvents(); + _logBrowser = new LogBrowser; + qInstallMsgHandler( mirallLogCatcher ); + csync_set_log_callback( csyncLogCatcher ); + QTimer::singleShot( 0, this, SLOT( slotStartFolderSetup() )); MirallConfigFile cfg; @@ -259,7 +284,6 @@ void Application::setupActions() _actionConfigure = new QAction(tr("Configure..."), this); QObject::connect(_actionConfigure, SIGNAL(triggered(bool)), SLOT(slotConfigure())); - _actionQuit = new QAction(tr("Quit"), this); QObject::connect(_actionQuit, SIGNAL(triggered(bool)), SLOT(quit())); } @@ -446,6 +470,12 @@ void Application::slotOpenStatus() } } +void Application::slotOpenLogBrowser() +{ + _logBrowser->show(); + _logBrowser->raise(); +} + /* * the folder is to be removed. The slot is called from a signal emitted by * the status dialog, which removes the folder from its list by itself. diff --git a/src/mirall/application.h b/src/mirall/application.h index 9dba5d66a..0ce711519 100644 --- a/src/mirall/application.h +++ b/src/mirall/application.h @@ -21,7 +21,7 @@ #include "mirall/syncresult.h" #include "mirall/folder.h" - +#include "mirall/logbrowser.h" #include "mirall/folderman.h" class QAction; @@ -75,6 +75,7 @@ protected slots: void slotNoOwnCloudFound( QNetworkReply* ); void slotCheckAuthentication(); void slotAuthCheck( const QString& ,QNetworkReply* ); + void slotOpenLogBrowser(); void slotStartUpdateDetector(); @@ -104,6 +105,7 @@ private: ownCloudInfo *_ocInfo; UpdateDetector *_updateDetector; QMap _overallStatusStrings; + LogBrowser *_logBrowser; }; } // namespace Mirall diff --git a/src/mirall/logbrowser.cpp b/src/mirall/logbrowser.cpp new file mode 100644 index 000000000..b15cc6c17 --- /dev/null +++ b/src/mirall/logbrowser.cpp @@ -0,0 +1,252 @@ +/* + * Copyright (C) by Klaas Freitag + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "logbrowser.h" + +#include "stdio.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mirall/mirallconfigfile.h" + +namespace Mirall { + +Logger* Logger::_instance=0; + +Logger::Logger( QObject* parent) +: QObject(parent), + _showTime(true), + _doLogging(false) +{ + +} + +Logger *Logger::instance() +{ + if( !Logger::_instance ) Logger::_instance = new Logger; + return Logger::_instance; +} + +void Logger::destroy() +{ + if( Logger::_instance ) { + delete Logger::_instance; + Logger::_instance = 0; + } +} + +void Logger::log(Log log) +{ + if( ! _doLogging ) return; + + QString msg; + if( _showTime ) { + msg = log.timeStamp.toString("MM-dd hh:mm:ss:zzz") + " "; + } + + if( log.source == Log::CSync ) { + // msg += "csync - "; + } else { + // msg += "ownCloud - "; + } + msg += log.message; + // _logs.append(log); + // std::cout << qPrintable(log.message) << std::endl; + emit newLog(msg); +} + +void Logger::csyncLog( const QString& message ) +{ + Log log; + log.source = Log::CSync; + log.timeStamp = QDateTime::currentDateTime(); + log.message = message; + + Logger::instance()->log(log); +} + +void Logger::mirallLog( const QString& message ) +{ + Log log_; + log_.source = Log::Mirall; + log_.timeStamp = QDateTime::currentDateTime(); + log_.message = message; + + Logger::instance()->log( log_ ); +} + +void Logger::setEnabled( bool state ) +{ + _doLogging = state; +} + +// ============================================================================== + +LogWidget::LogWidget(QWidget *parent) + :QTextEdit(parent) +{ + setReadOnly( true ); + setLineWrapMode( QTextEdit::NoWrap ); + QFont font; + font.setFamily("Courier New"); + font.setFixedPitch(true); + document()->setDefaultFont( font ); + + MirallConfigFile cfg; + int lines = cfg.maxLogLines(); + qDebug() << "# ## Have " << lines << " Loglines!"; + document()->setMaximumBlockCount( lines ); +} + +// ============================================================================== + +LogBrowser::LogBrowser(QWidget *parent) : + QDialog(parent), + _logWidget( new LogWidget(parent) ) +{ + setWindowTitle(tr("Log Output")); + setMinimumWidth(600); + + QVBoxLayout *mainLayout = new QVBoxLayout; + // mainLayout->setMargin(0); + + mainLayout->addWidget( _logWidget ); + + QHBoxLayout *toolLayout = new QHBoxLayout; + mainLayout->addLayout( toolLayout ); + + // Search input field + QLabel *lab = new QLabel(tr("&Search: ")); + _findTermEdit = new QLineEdit; + lab->setBuddy( _findTermEdit ); + toolLayout->addWidget(lab); + toolLayout->addWidget( _findTermEdit ); + + // find button + QPushButton *findBtn = new QPushButton; + findBtn->setText( tr("&Find") ); + connect( findBtn, SIGNAL(clicked()), this, SLOT(slotFind())); + toolLayout->addWidget( findBtn ); + + // stretch + toolLayout->addStretch(1); + _statusLabel = new QLabel; + toolLayout->addWidget( _statusLabel ); + toolLayout->addStretch(5); + + QDialogButtonBox *btnbox = new QDialogButtonBox; + QPushButton *closeBtn = btnbox->addButton( QDialogButtonBox::Close ); + connect(closeBtn,SIGNAL(clicked()),this,SLOT(close())); + + mainLayout->addWidget( btnbox ); + + // save Button + _saveBtn = new QPushButton; + _saveBtn->setText( tr("S&ave") ); + _saveBtn->setToolTip(tr("Save the log file to a file on disk for debugging.")); + btnbox->addButton(_saveBtn, QDialogButtonBox::ActionRole); + connect( _saveBtn, SIGNAL(clicked()),this, SLOT(slotSave())); + + setLayout( mainLayout ); + + setModal(false); + + // needs to be a queued connection as logs from other threads come in + connect(Logger::instance(), SIGNAL(newLog(QString)),this,SLOT(slotNewLog(QString)), Qt::QueuedConnection); +} + +void LogBrowser::show() +{ + QDialog::show(); + Logger::instance()->setEnabled(true); +} + +void LogBrowser::close() +{ + Logger::instance()->setEnabled(false); + QDialog::close(); +} + +void LogBrowser::slotNewLog( const QString& msg ) +{ + _logWidget->append( msg ); +} + +void LogBrowser::slotFind() +{ + QString searchText = _findTermEdit->text(); + + if( searchText.isEmpty() ) return; + + search( searchText ); +} + +void LogBrowser::search( const QString& str ) +{ + QList extraSelections; + + _logWidget->moveCursor(QTextCursor::Start); + QColor color = QColor(Qt::gray).lighter(130); + _statusLabel->clear(); + + while(_logWidget->find(str)) + { + QTextEdit::ExtraSelection extra; + extra.format.setBackground(color); + + extra.cursor = _logWidget->textCursor(); + extraSelections.append(extra); + } + + QString stat = QString("Search term %1 with %2 search results.").arg(str).arg(extraSelections.count()); + _statusLabel->setText(stat); + + _logWidget->setExtraSelections(extraSelections); +} + +void LogBrowser::slotSave() +{ + _saveBtn->setEnabled(false); + QCoreApplication::processEvents(); + + QString saveFile = QFileDialog::getSaveFileName( this, tr("Save log file"), QDir::homePath() ); + + if( ! saveFile.isEmpty() ) { + QFile file(saveFile); + + if (file.open(QIODevice::ReadWrite)) { + QTextStream stream(&file); + stream << _logWidget->toPlainText(); + file.flush(); + file.close(); + } else { + QMessageBox::critical(this, tr("Error"), tr("Could not write to log file ")+ saveFile); + } + } + _saveBtn->setEnabled(true); + +} + +} // namespace diff --git a/src/mirall/logbrowser.h b/src/mirall/logbrowser.h new file mode 100644 index 000000000..8239c603c --- /dev/null +++ b/src/mirall/logbrowser.h @@ -0,0 +1,104 @@ +/* + * Copyright (C) by Klaas Freitag + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef LOGBROWSER_H +#define LOGBROWSER_H + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Mirall { + +struct Log{ + typedef enum{ + Mirall, + CSync + } Source; + + QDateTime timeStamp; + Source source; + QString message; +}; + +class Logger : public QObject +{ + Q_OBJECT +public: + void log(Log log); + + static void csyncLog( const QString& message ); + static void mirallLog( const QString& message ); + + const QList& logs() const {return _logs;} + + static Logger* instance(); + static void destroy(); + + void setEnabled( bool ); + +signals: + void newLog(const QString&); + +protected: + Logger(QObject* parent=0); + QList _logs; + bool _showTime; + bool _doLogging; + + static Logger* _instance; +}; + +class LogWidget : public QTextEdit +{ + Q_OBJECT +public: + explicit LogWidget(QWidget *parent = 0); + +signals: + +}; + +class LogBrowser : public QDialog +{ + Q_OBJECT +public: + explicit LogBrowser(QWidget *parent = 0); +signals: + +public slots: + void show(); + void close(); + +protected slots: + void slotNewLog( const QString &msg ); + void slotFind(); + void search( const QString& ); + void slotSave(); + +private: + LogWidget *_logWidget; + QLineEdit *_findTermEdit; + QPushButton *_saveBtn; + QLabel *_statusLabel; +}; + +} // namespace + +#endif // LOGBROWSER_H diff --git a/src/mirall/mirallconfigfile.cpp b/src/mirall/mirallconfigfile.cpp index b91783cb1..46fbfe6d0 100644 --- a/src/mirall/mirallconfigfile.cpp +++ b/src/mirall/mirallconfigfile.cpp @@ -350,7 +350,21 @@ bool MirallConfigFile::ownCloudSkipUpdateCheck( const QString& connection ) cons return skipIt; } +bool MirallConfigFile::showLogWindowOnStart() const +{ + QSettings settings( configFile(), QSettings::IniFormat ); + settings.beginGroup("Logging"); + bool showOnStart = settings.value("showLogOnStart", false).toBool(); + return showOnStart; +} +int MirallConfigFile::maxLogLines() const +{ + QSettings settings( configFile(), QSettings::IniFormat ); + settings.beginGroup("Logging"); + int logLines = settings.value( "maxLogLines", 20000 ).toInt(); + return logLines; +} QByteArray MirallConfigFile::basicAuthHeader() const { diff --git a/src/mirall/mirallconfigfile.h b/src/mirall/mirallconfigfile.h index b4f2dc906..5372fbe7b 100644 --- a/src/mirall/mirallconfigfile.h +++ b/src/mirall/mirallconfigfile.h @@ -51,6 +51,11 @@ public: QString ownCloudVersion() const; void setOwnCloudVersion( const QString& ); + // max count of lines in the log window + int maxLogLines() const; + // show the log window on startup? + bool showLogWindowOnStart() const; + bool ownCloudSkipUpdateCheck( const QString& connection = QString() ) const; /* Poll intervals in milliseconds */ diff --git a/src/mirall/statusdialog.cpp b/src/mirall/statusdialog.cpp index 9cecaa76c..8979cf4d1 100644 --- a/src/mirall/statusdialog.cpp +++ b/src/mirall/statusdialog.cpp @@ -191,6 +191,7 @@ StatusDialog::StatusDialog( Theme *theme, QWidget *parent) : connect(_ButtonEnable, SIGNAL(clicked()), this, SLOT(slotEnableFolder())); connect(_ButtonInfo, SIGNAL(clicked()), this, SLOT(slotInfoFolder())); connect(_ButtonAdd, SIGNAL(clicked()), this, SLOT(slotAddSync())); + connect(_ButtonLog, SIGNAL(clicked()), SIGNAL(openLogBrowser())); _ButtonRemove->setEnabled(false); _ButtonFetch->setEnabled(false); diff --git a/src/mirall/statusdialog.h b/src/mirall/statusdialog.h index d750cd56c..de0d77705 100644 --- a/src/mirall/statusdialog.h +++ b/src/mirall/statusdialog.h @@ -77,6 +77,7 @@ signals: void enableFolderAlias( const QString&, const bool ); void infoFolderAlias( const QString& ); void openFolderAlias( const QString& ); + void openLogBrowser(); /* start the add a folder wizard. */ void addASync(); diff --git a/src/mirall/statusdialog.ui b/src/mirall/statusdialog.ui index 29562c421..a6004facd 100644 --- a/src/mirall/statusdialog.ui +++ b/src/mirall/statusdialog.ui @@ -6,8 +6,8 @@ 0 0 - 496 - 327 + 544 + 308 @@ -26,73 +26,84 @@ - + - - - - Add Sync... - - + + + + + + Add Sync... + + + + + + + Remove... + + + + + + + true + + + Fetch... + + + + + + + Push... + + + + + + + Pause + + + + + + + Info... + + + + + + + open Log Window... + + + + + + + Qt::Vertical + + + + 20 + 56 + + + + + - - - - Remove... - - - - - - - true - - - Fetch... - - - - - - - Push... - - - - - - - Pause - - - - - - - Info... - - - - - - - Qt::Vertical - - - - 20 - 56 - - - - - - + + @@ -102,14 +113,14 @@ - + Qt::Horizontal - + Qt::Horizontal @@ -122,7 +133,7 @@ - + Close @@ -130,6 +141,17 @@ + label + _ButtonAdd + _ButtonRemove + _ButtonFetch + _ButtonPush + _ButtonEnable + _ButtonInfo + line + _ButtonClose + _ButtonLog + _ocUrlLabel From 9d0a8d35d8bf2dbb6baa47abf66ac90a34e8bce1 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Tue, 5 Jun 2012 15:49:53 +0200 Subject: [PATCH 2/7] - created setupLogBrowser method in application - removed unused config variable code --- src/mirall/application.cpp | 25 ++++++++++++++++--------- src/mirall/application.h | 1 + src/mirall/logbrowser.cpp | 2 +- src/mirall/mirallconfigfile.cpp | 8 -------- src/mirall/mirallconfigfile.h | 2 -- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index 0386d7bae..faaafc417 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -83,11 +83,7 @@ Application::Application(int &argc, char **argv) : processEvents(); - // Internationalization support. - qDebug() << ""; // relaxing debug output in qtCreator - qDebug() << QString( "################## %1 %2 %3 ").arg(_theme->appName()) - .arg( QLocale::system().name() ) - .arg(_theme->version()); + setupLogBrowser(); QTranslator *qtTranslator = new QTranslator; qtTranslator->load("qt_" + QLocale::system().name(), @@ -162,10 +158,6 @@ Application::Application(int &argc, char **argv) : setupSystemTray(); processEvents(); - _logBrowser = new LogBrowser; - qInstallMsgHandler( mirallLogCatcher ); - csync_set_log_callback( csyncLogCatcher ); - QTimer::singleShot( 0, this, SLOT( slotStartFolderSetup() )); MirallConfigFile cfg; @@ -332,6 +324,21 @@ void Application::setupContextMenu() _tray->setContextMenu(_contextMenu); } +void Application::setupLogBrowser() +{ + // init the log browser. + _logBrowser = new LogBrowser; + qInstallMsgHandler( mirallLogCatcher ); + csync_set_log_callback( csyncLogCatcher ); + + if( arguments().contains("--logwindow") || arguments().contains("-l")) { + slotOpenLogBrowser(); + } + + qDebug() << QString( "################## %1 %2 %3 ").arg(_theme->appName()) + .arg( QLocale::system().name() ) + .arg(_theme->version()); +} /* * open the folder with the given Alais */ diff --git a/src/mirall/application.h b/src/mirall/application.h index 0ce711519..718d43ca4 100644 --- a/src/mirall/application.h +++ b/src/mirall/application.h @@ -62,6 +62,7 @@ protected: void setupActions(); void setupSystemTray(); void setupContextMenu(); + void setupLogBrowser(); //folders have to be disabled while making config changes void computeOverallSyncStatus(); diff --git a/src/mirall/logbrowser.cpp b/src/mirall/logbrowser.cpp index b15cc6c17..fb5f4ec8d 100644 --- a/src/mirall/logbrowser.cpp +++ b/src/mirall/logbrowser.cpp @@ -116,7 +116,7 @@ LogWidget::LogWidget(QWidget *parent) MirallConfigFile cfg; int lines = cfg.maxLogLines(); - qDebug() << "# ## Have " << lines << " Loglines!"; + // qDebug() << "# ## Have " << lines << " Loglines!"; document()->setMaximumBlockCount( lines ); } diff --git a/src/mirall/mirallconfigfile.cpp b/src/mirall/mirallconfigfile.cpp index 46fbfe6d0..f4d5d2724 100644 --- a/src/mirall/mirallconfigfile.cpp +++ b/src/mirall/mirallconfigfile.cpp @@ -350,14 +350,6 @@ bool MirallConfigFile::ownCloudSkipUpdateCheck( const QString& connection ) cons return skipIt; } -bool MirallConfigFile::showLogWindowOnStart() const -{ - QSettings settings( configFile(), QSettings::IniFormat ); - settings.beginGroup("Logging"); - bool showOnStart = settings.value("showLogOnStart", false).toBool(); - return showOnStart; -} - int MirallConfigFile::maxLogLines() const { QSettings settings( configFile(), QSettings::IniFormat ); diff --git a/src/mirall/mirallconfigfile.h b/src/mirall/mirallconfigfile.h index 5372fbe7b..bbbb9525f 100644 --- a/src/mirall/mirallconfigfile.h +++ b/src/mirall/mirallconfigfile.h @@ -53,8 +53,6 @@ public: // max count of lines in the log window int maxLogLines() const; - // show the log window on startup? - bool showLogWindowOnStart() const; bool ownCloudSkipUpdateCheck( const QString& connection = QString() ) const; From c0cf575adaa40693e1edd9fe63190a81095d1bba Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Tue, 5 Jun 2012 16:30:55 +0200 Subject: [PATCH 3/7] Fix csync log encoding --- src/mirall/application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index faaafc417..46bbe4680 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -57,7 +57,7 @@ void mirallLogCatcher(QtMsgType type, const char *msg) void csyncLogCatcher(const char *msg) { - Logger::instance()->csyncLog( msg ); + Logger::instance()->csyncLog( QString::fromUtf8(msg) ); } // ---------------------------------------------------------------------------------- From 9502f10689cbcc89dfb20d7a7ce3a8cb0e881869 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Tue, 5 Jun 2012 16:31:28 +0200 Subject: [PATCH 4/7] bump version to next version 1.0.3 --- VERSION.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.cmake b/VERSION.cmake index d2701063d..7000fa6de 100644 --- a/VERSION.cmake +++ b/VERSION.cmake @@ -1,5 +1,5 @@ set( VERSION_MAJOR 1 ) set( VERSION_MINOR 0 ) -set( VERSION_PATCH 2 ) +set( VERSION_PATCH 3 ) set( VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} ) From 1de72962617bc0ac3fbfbb5b85224032c839cd26 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Tue, 5 Jun 2012 16:31:51 +0200 Subject: [PATCH 5/7] Fix package building for non apple platforms. --- CPackOptions.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CPackOptions.cmake.in b/CPackOptions.cmake.in index d59f79625..3c22d91b1 100644 --- a/CPackOptions.cmake.in +++ b/CPackOptions.cmake.in @@ -23,7 +23,7 @@ else() set( CSYNC_CONFIG_DIR "${MINGW_ROOT}/etc/csync" ) endif() set( BUILD_OWNCLOUD_OSX_BUNDLE @BUILD_OWNCLOUD_OSX_BUNDLE@) -if(NOT BUILD_OWNCLOUD_OSX_BUNDLE) +if(APPLE AND NOT BUILD_OWNCLOUD_OSX_BUNDLE) message( FATAL_ERROR "You're trying to build a bundle although you haven't built mirall in bundle mode.\n Add -DBUILD_OWNCLOUD_O") endif() From 8b38131b4b0d7ba1638a991f4d2b4ba779b43f81 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Tue, 5 Jun 2012 18:37:48 +0200 Subject: [PATCH 6/7] Provide proper return value for getauth --- src/mirall/csyncthread.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index 2366694b8..b9e9eb4b1 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -295,6 +295,8 @@ int CSyncThread::getauth(const char *prompt, void *userdata ) { + int re = 0; + QString qPrompt = QString::fromLocal8Bit( prompt ).trimmed(); _mutex.lock(); @@ -311,9 +313,11 @@ int CSyncThread::getauth(const char *prompt, strncpy( buf, "yes", 3 ); } else { qDebug() << "Unknown prompt: <" << prompt << ">"; + re = -1; } } _mutex.unlock(); + return re; } } From 06b3a50e845570b386414712ec36486c8a76ca81 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Mon, 11 Jun 2012 10:10:07 +0200 Subject: [PATCH 7/7] Wipe the csync statedb after a sync definition is removed. --- src/mirall/csyncthread.cpp | 18 +++++++++++++++--- src/mirall/csyncthread.h | 4 +++- src/mirall/folder.cpp | 5 +++++ src/mirall/folder.h | 5 +++++ src/mirall/folderman.cpp | 1 + src/mirall/owncloudfolder.cpp | 34 ++++++++++++++++++++++++++++++++++ src/mirall/owncloudfolder.h | 4 ++++ 7 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index b9e9eb4b1..c60e2464c 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -137,11 +137,12 @@ void CSyncThread::run() wStats->seenFiles = 0; wStats->conflicts = 0; wStats->error = 0; + const char *statedb = 0; _mutex.lock(); if( csync_create(&csync, - _source.toLocal8Bit().data(), - _target.toLocal8Bit().data()) < 0 ) { + _source.toLocal8Bit().data(), + _target.toLocal8Bit().data()) < 0 ) { emit csyncError( tr("CSync create failed.") ); } // FIXME: Check if we really need this stringcopy! @@ -214,6 +215,17 @@ void CSyncThread::run() goto cleanup; } + // After csync_init the statedb file name can be emitted + statedb = csync_get_statedb_file( csync ); + if( statedb ) { + QString stateDbFile = QString::fromUtf8(statedb); + free((void*)statedb); + + emit csyncStateDbFile( stateDbFile ); + } else { + qDebug() << "WRN: Unable to get csync statedb file name"; + } + qDebug() << "############################################################### >>"; if( csync_update(csync) < 0 ) { emit csyncError(tr("CSync Update failed.")); @@ -240,7 +252,6 @@ void CSyncThread::run() emit csyncError(tr("Local filesystem problems. Better disable Syncing and check.")); goto cleanup; } - qDebug() << " ..... Local walk finished: " << walkTime.elapsed(); // emit the treewalk results. Do not touch the wStats after this. emit treeWalkResult(wStats); @@ -248,6 +259,7 @@ void CSyncThread::run() _mutex.lock(); if( _localCheckOnly ) { _mutex.unlock(); + qDebug() << " ..... Local only walk finished: " << walkTime.elapsed(); // we have to go out here as its local check only. goto cleanup; } else { diff --git a/src/mirall/csyncthread.h b/src/mirall/csyncthread.h index 152fe398d..c4836cfed 100644 --- a/src/mirall/csyncthread.h +++ b/src/mirall/csyncthread.h @@ -68,7 +68,9 @@ public: signals: void treeWalkResult(WalkStats*); - void csyncError(const QString&); + void csyncError( const QString& ); + + void csyncStateDbFile( const QString& ); private: static int getauth(const char *prompt, diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index adeff3449..b3cdb1f7d 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -262,5 +262,10 @@ QString Folder::backend() const return _backend; } +void Folder::wipe() +{ + +} + } // namespace Mirall diff --git a/src/mirall/folder.h b/src/mirall/folder.h index dd66c5bf7..8cc57dc8d 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -129,6 +129,11 @@ public: */ QString backend() const; + /** + * This is called if the sync folder definition is removed. Do cleanups here. + */ + virtual void wipe(); + QIcon icon( int size ) const; QTimer *_pollTimer; diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp index 9f440c890..b351009f0 100644 --- a/src/mirall/folderman.cpp +++ b/src/mirall/folderman.cpp @@ -337,6 +337,7 @@ void FolderMan::removeFolder( const QString& alias ) if( _folderMap.contains( alias )) { qDebug() << "Removing " << alias; Folder *f = _folderMap.take( alias ); + f->wipe(); f->deleteLater(); } else { qDebug() << "!! Can not remove " << alias << ", not in folderMap."; diff --git a/src/mirall/owncloudfolder.cpp b/src/mirall/owncloudfolder.cpp index 84170b7b3..fde4e70d6 100644 --- a/src/mirall/owncloudfolder.cpp +++ b/src/mirall/owncloudfolder.cpp @@ -68,6 +68,7 @@ ownCloudFolder::ownCloudFolder(const QString &alias, ownCloudFolder::~ownCloudFolder() { + } #ifndef USE_INOTIFY @@ -144,6 +145,7 @@ void ownCloudFolder::startSync(const QStringList &pathList) QObject::connect(_csync, SIGNAL(finished()), SLOT(slotCSyncFinished())); QObject::connect(_csync, SIGNAL(terminated()), SLOT(slotCSyncTerminated())); connect(_csync, SIGNAL(csyncError(const QString)), SLOT(slotCSyncError(const QString))); + connect(_csync, SIGNAL(csyncStateDbFile(QString)), SLOT(slotCsyncStateDbFile(QString))); connect( _csync, SIGNAL(treeWalkResult(WalkStats*)), this, SLOT(slotThreadTreeWalkResult(WalkStats*))); @@ -200,6 +202,12 @@ void ownCloudFolder::slotCSyncError(const QString& err) _csyncError = true; } +void ownCloudFolder::slotCsyncStateDbFile( const QString& file ) +{ + qDebug() << "Got csync statedb file: " << file; + _csyncStateDbFile = file; +} + void ownCloudFolder::slotCSyncTerminated() { // do not ask csync here for reasons. @@ -253,5 +261,31 @@ void ownCloudFolder::slotTerminateSync() } } +// This removes the csync File database if the sync folder definition is removed +// permanentely. This is needed to provide a clean startup again in case another +// local folder is synced to the same ownCloud. +// See http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-788 +void ownCloudFolder::wipe() +{ + if( !_csyncStateDbFile.isEmpty() ) { + QFile file(_csyncStateDbFile); + if( file.exists() ) { + if( !file.remove()) { + qDebug() << "WRN: Failed to remove existing csync StateDB " << _csyncStateDbFile; + } else { + qDebug() << "wipe: Removed csync StateDB " << _csyncStateDbFile; + } + } else { + qDebug() << "WRN: statedb is empty, can not remove."; + } + // Check if the tmp database file also exists + QString ctmpName = _csyncStateDbFile + ".ctmp"; + QFile ctmpFile( ctmpName ); + if( ctmpFile.exists() ) { + ctmpFile.remove(); + } + } +} + } // ns diff --git a/src/mirall/owncloudfolder.h b/src/mirall/owncloudfolder.h index 031da91ce..4647d9bc4 100644 --- a/src/mirall/owncloudfolder.h +++ b/src/mirall/owncloudfolder.h @@ -38,6 +38,8 @@ public: virtual bool isBusy() const; virtual void startSync(const QStringList &pathList); + virtual void wipe(); + public slots: void startSync(); void slotTerminateSync(); @@ -48,6 +50,7 @@ private slots: void slotCSyncFinished(); void slotThreadTreeWalkResult( WalkStats* ); void slotCSyncTerminated(); + void slotCsyncStateDbFile(const QString&); #ifndef USE_INOTIFY void slotPollTimerRemoteCheck(); @@ -62,6 +65,7 @@ private: QStringList _errors; bool _csyncError; ulong _lastSeenFiles; + QString _csyncStateDbFile; }; }