Refactored logging
FossilOrigin-Name: 9c198b023e2df1b5cfe64dd745d070732b5ab843
This commit is contained in:
13
src/Bridge.h
13
src/Bridge.h
@ -5,6 +5,7 @@ class QStringList;
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#include <QTextBrowser>
|
||||
|
||||
|
||||
class Bridge : public QObject
|
||||
@ -14,7 +15,7 @@ public:
|
||||
: QObject(0)
|
||||
, parentWidget(0)
|
||||
, abortOperation(false)
|
||||
, logCallbackObject(0)
|
||||
, logTextBrowser(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -31,14 +32,14 @@ public:
|
||||
RUNFLAGS_DETACHED = 1<<2
|
||||
};
|
||||
|
||||
typedef void(*log_callback_t)(const QString &text, bool isHTML, QObject *object);
|
||||
typedef void(*log_callback_t)(QTextBrowser *textBrowser, const QString &text, bool isHTML);
|
||||
|
||||
|
||||
void Init(QWidget *parent, log_callback_t callback, QObject *callbackObject, const QString &fossPath, const QString &workspace)
|
||||
void Init(QWidget *parent, log_callback_t callback, QTextBrowser *textBrowser, const QString &fossPath, const QString &workspace)
|
||||
{
|
||||
parentWidget = parent;
|
||||
logCallback = callback;
|
||||
logCallbackObject = callbackObject;
|
||||
logTextBrowser = textBrowser;
|
||||
|
||||
fossilPath = fossPath;
|
||||
currentWorkspace = workspace;
|
||||
@ -68,7 +69,7 @@ private:
|
||||
void log(const QString &text, bool isHTML=false)
|
||||
{
|
||||
if(logCallback)
|
||||
(*logCallback)(text, isHTML, logCallbackObject);
|
||||
(*logCallback)(logTextBrowser, text, isHTML);
|
||||
}
|
||||
|
||||
const QString &getCurrentWorkspace()
|
||||
@ -82,7 +83,7 @@ private:
|
||||
bool abortOperation; // FIXME: No GUI for it yet
|
||||
|
||||
log_callback_t logCallback;
|
||||
QObject *logCallbackObject;
|
||||
QTextBrowser *logTextBrowser;
|
||||
QString currentWorkspace;
|
||||
QString fossilPath; // The value from the settings
|
||||
|
||||
|
@ -34,8 +34,6 @@ static const unsigned char UTF8_BOM[] = { 0xEF, 0xBB, 0xBF };
|
||||
// 19: [5c46757d4b9765] on 2012-04-22 04:41:15
|
||||
static const QRegExp REGEX_STASH("\\s*(\\d+):\\s+\\[(.*)\\] on (\\d+)-(\\d+)-(\\d+) (\\d+):(\\d+):(\\d+)", Qt::CaseInsensitive);
|
||||
|
||||
//#define BRIDGE_DISABLED
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
enum
|
||||
{
|
||||
@ -236,7 +234,9 @@ MainWindow::MainWindow(Settings &_settings, QWidget *parent, QString *workspaceP
|
||||
|
||||
applySettings();
|
||||
|
||||
bridge.Init(this, 0, 0, "", "");
|
||||
#ifdef BRIDGE_ENABLED
|
||||
bridge.Init(this, &log, ui->textBrowser, "", "");
|
||||
#endif
|
||||
|
||||
// Apply any explicit workspace path if available
|
||||
if(workspacePath && !workspacePath->isEmpty())
|
||||
@ -983,7 +983,7 @@ void MainWindow::updateFileView()
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#ifdef BRIDGE_DISABLED
|
||||
#ifndef BRIDGE_ENABLED
|
||||
MainWindow::RepoStatus MainWindow::getRepoStatus()
|
||||
{
|
||||
QStringList res;
|
||||
@ -1050,16 +1050,22 @@ void MainWindow::updateStashView()
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void MainWindow::log(const QString &text, bool isHTML)
|
||||
void MainWindow::log(QTextBrowser *textBrowser, const QString &text, bool isHTML)
|
||||
{
|
||||
QTextCursor c = ui->textBrowser->textCursor();
|
||||
QTextCursor c = textBrowser->textCursor();
|
||||
c.movePosition(QTextCursor::End);
|
||||
ui->textBrowser->setTextCursor(c);
|
||||
textBrowser->setTextCursor(c);
|
||||
|
||||
if(isHTML)
|
||||
ui->textBrowser->insertHtml(text);
|
||||
textBrowser->insertHtml(text);
|
||||
else
|
||||
ui->textBrowser->insertPlainText(text);
|
||||
textBrowser->insertPlainText(text);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void MainWindow::log(const QString &text, bool isHTML)
|
||||
{
|
||||
log(ui->textBrowser, text, isHTML);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1075,7 +1081,7 @@ void MainWindow::on_actionClearLog_triggered()
|
||||
}
|
||||
|
||||
|
||||
#ifdef BRIDGE_DISABLED
|
||||
#ifndef BRIDGE_ENABLED
|
||||
//------------------------------------------------------------------------------
|
||||
bool MainWindow::runFossil(const QStringList &args, QStringList *output, int runFlags)
|
||||
{
|
||||
@ -1722,7 +1728,7 @@ void MainWindow::on_actionDiff_triggered()
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#ifdef BRIDGE_DISABLED
|
||||
#ifndef BRIDGE_ENABLED
|
||||
bool MainWindow::startUI()
|
||||
{
|
||||
if(uiRunning())
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include "SettingsDialog.h"
|
||||
#include "Bridge.h"
|
||||
|
||||
#define BRIDGE_ENABLED
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
@ -143,6 +145,7 @@ private:
|
||||
void updateSettings();
|
||||
const QString &getCurrentWorkspace();
|
||||
void setCurrentWorkspace(const QString &workspace);
|
||||
static void log(QTextBrowser *textBrowser, const QString &text, bool isHTML);
|
||||
void log(const QString &text, bool isHTML=false);
|
||||
void setStatus(const QString &text);
|
||||
bool uiRunning() const;
|
||||
@ -262,7 +265,9 @@ private:
|
||||
ViewMode viewMode;
|
||||
stringset_t selectedDirs; // The directory selected in the tree
|
||||
|
||||
#ifdef BRIDGE_ENABLED
|
||||
Bridge bridge;
|
||||
#endif
|
||||
|
||||
// Repository State
|
||||
typedef QList<RepoFile*> filelist_t;
|
||||
|
Reference in New Issue
Block a user