Files
proton-bridge/internal/frontend/bridge-gui/bridge-gui-tester/MainWindow.cpp
Xavier Michelon 4ed9625959 Other: bridge-gui-tester.
WIP: Added bridge-gui-test app.
WIP: goos.
WIP: event sending.
WIP: include bridge-gui-tester in frontend project
WIP: app end login event buttons.
WIP: login events. .
WIP: moved and renamed tab code
WIP: wired login logic.
WIP: setColorScheme and loginAbort.
WIP: more calls implemented + random users and numbers.
WIP: mail calls.
WIP: bug reports.
WIP: more signal send via the grpc Qt proxy.
WIP: Qt proxy on the event stream tab.
WIP: user change events wiring.
WIP: GUI changes.
WIP: minor refactoring.
WIP: remove event stream tab.
WIP: GUI changes.
WIP: separate logs, cache and keychain implemented.
WIP: Automatic update.

Other: fix linux build.

WIP: fix for live addition/modification/removal of users on the server side.
2022-09-01 13:23:12 +02:00

112 lines
4.8 KiB
C++

// Copyright (c) 2022 Proton AG
//
// This file is part of Proton Mail Bridge.
//
// Proton Mail Bridge 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 3 of the License, or
// (at your option) any later version.
//
// Proton Mail Bridge 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.
//
// You should have received a copy of the GNU General Public License
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
#include "MainWindow.h"
#include <bridgepp/Log/Log.h>
using namespace bridgepp;
namespace
{
//****************************************************************************************************************************************************
/// \param[in] level The log level.
/// \param[in] message The log message.
/// \param[in] logEdit The plain text edit widget that displays the log.
//****************************************************************************************************************************************************
void addEntryToLogEdit(bridgepp::Log::Level level, const QString &message, QPlainTextEdit &logEdit)
{
/// \todo This may cause performance issue when log grows big. A better alternative should be implemented.
QString log = logEdit.toPlainText().trimmed();
if (!log.isEmpty())
log += "\n";
logEdit.setPlainText(log + Log::logEntryToString(level, message));
}
} // Anonymous namespace
//****************************************************************************************************************************************************
/// \param[in] parent The parent widget of the window.
//****************************************************************************************************************************************************
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
ui_.setupUi(this);
ui_.tabTop->setCurrentIndex(0);
ui_.tabBottom->setCurrentIndex(0);
ui_.splitter->setStretchFactor(0, 0);
ui_.splitter->setStretchFactor(1, 1);
ui_.splitter->setSizes({100, 10000});
connect(&app().log(), &Log::entryAdded, this, &MainWindow::addLogEntry);
connect(&app().bridgeGUILog(), &Log::entryAdded, this, &MainWindow::addBridgeGUILogEntry);
}
//****************************************************************************************************************************************************
/// \return A reference to the 'General' tab.
//****************************************************************************************************************************************************
SettingsTab &MainWindow::settingsTab()
{
return *ui_.settingsTab;
}
//****************************************************************************************************************************************************
/// \return A reference to the users tab.
//****************************************************************************************************************************************************
UsersTab &MainWindow::usersTab()
{
return *ui_.usersTab;
}
//****************************************************************************************************************************************************
/// \param[in] level The log level.
/// \param[in] message The log message
//****************************************************************************************************************************************************
void MainWindow::addLogEntry(bridgepp::Log::Level level, const QString &message)
{
addEntryToLogEdit(level, message, *ui_.editLog);
}
//****************************************************************************************************************************************************
/// \param[in] level The log level.
/// \param[in] message The log message
//****************************************************************************************************************************************************
void MainWindow::addBridgeGUILogEntry(bridgepp::Log::Level level, const QString &message)
{
addEntryToLogEdit(level, message, *ui_.editBridgeGUILog);
}
//****************************************************************************************************************************************************
/// \param[in] event The event.
//****************************************************************************************************************************************************
void MainWindow::sendDelayedEvent(SPStreamEvent const &event)
{
QTimer::singleShot(this->settingsTab().eventDelayMs(), [event] { app().grpc().sendEvent(event); });
}