Compare commits

...

2 Commits

Author SHA1 Message Date
Martchus 5ed21ba0d6 Minimum example 2021-06-21 17:06:09 +02:00
Martchus 453c1d451f Hardcore print-debugging 2021-06-21 17:05:52 +02:00
11 changed files with 105 additions and 2 deletions

View File

@ -103,6 +103,8 @@ SyncthingConnection::SyncthingConnection(
, m_dirStatsAltered(false)
, m_recordFileChanges(false)
{
std::cerr << ("before conn c'tor\n");
m_trafficPollTimer.setInterval(SyncthingConnectionSettings::defaultTrafficPollInterval);
m_trafficPollTimer.setTimerType(Qt::VeryCoarseTimer);
m_trafficPollTimer.setSingleShot(true);
@ -173,6 +175,7 @@ QString SyncthingConnection::statusText(SyncthingStatus status)
*/
void SyncthingConnection::setLoggingFlags(SyncthingConnectionLoggingFlags flags)
{
std::cerr << ("before logging flags\n");
m_loggingFlags = flags;
if (flags & SyncthingConnectionLoggingFlags::FromEnvironment) {
if (!(flags & SyncthingConnectionLoggingFlags::All) && qEnvironmentVariableIntValue(PROJECT_VARNAME_UPPER "_LOG_ALL")) {
@ -209,6 +212,7 @@ void SyncthingConnection::setLoggingFlags(SyncthingConnectionLoggingFlags flags)
});
m_loggingFlagsHandler |= SyncthingConnectionLoggingFlags::DirsOrDevsResetted;
}
std::cerr << ("after logging flags\n");
}
/*!

View File

@ -9,6 +9,8 @@
#include <c++utilities/chrono/datetime.h>
#include <iostream>
using namespace CppUtilities;
namespace Data {
@ -37,6 +39,7 @@ SyncthingNotifier::SyncthingNotifier(const SyncthingConnection &connection, QObj
, m_ignoreInavailabilityAfterStart(15)
, m_initialized(false)
{
std::cerr << ("before notifier\n");
connect(&connection, &SyncthingConnection::statusChanged, this, &SyncthingNotifier::handleStatusChangedEvent);
connect(&connection, &SyncthingConnection::dirCompleted, this, &SyncthingNotifier::emitSyncComplete);
connect(&connection, &SyncthingConnection::newDevAvailable, this, &SyncthingNotifier::handleNewDevEvent);
@ -44,6 +47,7 @@ SyncthingNotifier::SyncthingNotifier(const SyncthingConnection &connection, QObj
if (m_process) {
connect(m_process, &SyncthingProcess::errorOccurred, this, &SyncthingNotifier::handleSyncthingProcessError);
}
std::cerr << ("after notifier\n");
}
void SyncthingNotifier::handleStatusChangedEvent(SyncthingStatus newStatus)

View File

@ -9,6 +9,8 @@
#include <QStringBuilder>
#include <iostream>
using namespace std;
using namespace CppUtilities;
@ -23,8 +25,10 @@ SyncthingDirectoryModel::SyncthingDirectoryModel(SyncthingConnection &connection
: SyncthingModel(connection, parent)
, m_dirs(connection.dirInfo())
{
std::cerr << ("before dm\n");
updateRowCount();
connect(&m_connection, &SyncthingConnection::dirStatusChanged, this, &SyncthingDirectoryModel::dirStatusChanged);
std::cerr << ("after dm\n");
}
QHash<int, QByteArray> SyncthingDirectoryModel::roleNames() const

View File

@ -8,6 +8,8 @@
#include <QStringBuilder>
#include <QSvgRenderer>
#include <iostream>
namespace Data {
/*!
@ -117,15 +119,21 @@ QByteArray makeSyncthingIcon(const StatusIconColorSet &colors, StatusEmblem stat
namespace Detail {
template <typename SourceType> QPixmap renderSvgImage(const SourceType &source, const QSize &givenSize, int margin)
{
std::cerr << "before render svg: "
<< "\n";
const auto scaleFactor =
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
!QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1.0 :
#endif
qGuiApp->devicePixelRatio();
std::cerr << "before scaled: "
<< "\n";
const auto scaledSize = QSize(givenSize * scaleFactor);
auto renderer = QSvgRenderer(source);
auto renderSize = QSize(renderer.defaultSize());
renderSize.scale(scaledSize.width() - margin, scaledSize.height() - margin, Qt::KeepAspectRatio);
std::cerr << "before render bounds: "
<< "\n";
auto renderBounds = QRect(QPoint(), scaledSize);
if (renderSize.width() < renderBounds.width()) {
const auto diff = (renderBounds.width() - renderSize.width()) / 2;
@ -137,11 +145,17 @@ template <typename SourceType> QPixmap renderSvgImage(const SourceType &source,
renderBounds.setY(diff);
renderBounds.setHeight(renderSize.height());
}
std::cerr << "before pixmap: " << scaledSize.width() << " x " << scaledSize.height() << "\n";
auto pm = QPixmap(scaledSize);
pm.fill(QColor(Qt::transparent));
auto painter = QPainter(&pm);
auto painter = QPainter();
std::cerr << "begin: " << painter.begin(&pm) << std::endl;
std::cerr << "before render svg render: " << renderBounds.top() << ", " << renderBounds.left() << " - " << renderBounds.width() << " x "
<< renderBounds.height() << "\n";
renderer.render(&painter, renderBounds);
pm.setDevicePixelRatio(scaleFactor);
std::cerr << "after render svg: "
<< "\n";
return pm;
}
} // namespace Detail
@ -154,6 +168,7 @@ template <typename SourceType> QPixmap renderSvgImage(const SourceType &source,
*/
QPixmap renderSvgImage(const QString &path, const QSize &size, int margin)
{
std::cerr << "path: " << path.toStdString() << "\n";
return Detail::renderSvgImage(path, size, margin);
}
@ -162,6 +177,7 @@ QPixmap renderSvgImage(const QString &path, const QSize &size, int margin)
*/
QPixmap renderSvgImage(const QByteArray &contents, const QSize &size, int margin)
{
std::cerr << "contents: " << std::string_view(contents) << "\n";
return Detail::renderSvgImage(contents, size, margin);
}
@ -170,6 +186,7 @@ QPixmap renderSvgImage(const QByteArray &contents, const QSize &size, int margin
*/
QByteArray loadFontAwesomeIcon(const QString &iconName, const QColor &color, bool solid)
{
std::cerr << "fas: " << iconName.toStdString() << "\n";
auto result = QByteArray();
auto icon = QFile(QString((solid ? QStringLiteral(":/icons/hicolor/scalable/fa/") : QStringLiteral(":/icons/hicolor/scalable/fa-non-solid/"))
% iconName % QStringLiteral(".svg")));
@ -319,7 +336,9 @@ IconManager::IconManager()
IconManager &IconManager::instance()
{
std::cerr << "before im\n";
static IconManager iconManager;
std::cerr << "after im\n";
return iconManager;
}

View File

@ -3,6 +3,8 @@
#include <syncthingconnector/syncthingconnection.h>
#include <iostream>
namespace Data {
SyncthingModel::SyncthingModel(SyncthingConnection &connection, QObject *parent)
@ -10,9 +12,12 @@ SyncthingModel::SyncthingModel(SyncthingConnection &connection, QObject *parent)
, m_connection(connection)
, m_brightColors(false)
{
std::cerr << ("before dm innner\n");
std::cerr << "conn: " << &m_connection << "\n";
connect(&m_connection, &SyncthingConnection::newConfig, this, &SyncthingModel::handleConfigInvalidated);
connect(&m_connection, &SyncthingConnection::newConfigApplied, this, &SyncthingModel::handleNewConfigAvailable);
connect(&IconManager::instance(), &IconManager::statusIconsChanged, this, &SyncthingModel::handleStatusIconsChanged);
std::cerr << ("after dm innner\n");
}
const QVector<int> &SyncthingModel::colorRoles() const

View File

@ -11,6 +11,8 @@
#include <limits>
#include <iostream>
using namespace std;
using namespace CppUtilities;
@ -20,6 +22,7 @@ SyncthingRecentChangesModel::SyncthingRecentChangesModel(SyncthingConnection &co
: SyncthingModel(connection, parent)
, m_maxRows(maxRows)
{
std::cerr << ("before recent changes model\n");
connect(&m_connection, &SyncthingConnection::fileChanged, this, &SyncthingRecentChangesModel::fileChanged);
connect(&m_connection, &SyncthingConnection::statusChanged, this, &SyncthingRecentChangesModel::handleStatusChanged);
}

View File

@ -5,6 +5,8 @@
#include <QSortFilterProxyModel>
#include <iostream>
namespace Data {
enum class SyncthingSortBehavior {
@ -32,9 +34,11 @@ inline SyncthingSortFilterModel::SyncthingSortFilterModel(QAbstractItemModel *so
: QSortFilterProxyModel(parent)
, m_behavior(SyncthingSortBehavior::Alphabetically)
{
std::cerr << ("before sfm\n");
setSortCaseSensitivity(Qt::CaseInsensitive);
setFilterCaseSensitivity(Qt::CaseInsensitive);
setSourceModel(sourceModel);
std::cerr << ("after sfm\n");
}
inline SyncthingSortBehavior SyncthingSortFilterModel::behavior() const

View File

@ -29,7 +29,12 @@
#include <QSettings>
#include <QStringBuilder>
#include <QSvgRenderer>
#include <QPainter>
#include <QPixmap>
#include <iostream>
#include <thread>
using namespace std;
using namespace CppUtilities;
@ -55,6 +60,10 @@ int initSyncthingTray(bool windowed, bool waitForTray, const Argument &connectio
// get settings
auto &settings = Settings::values();
static const auto defaultConnection = std::vector<const char *>({ "" });
std::cerr << "present: " << connectionConfigArg.isPresent() << "\n";
if (connectionConfigArg.isPresent()) {
std::cerr << "size: " << connectionConfigArg.values().size() << "\n";
}
const auto &connectionConfigurations
= connectionConfigArg.isPresent() && !connectionConfigArg.values().empty() ? connectionConfigArg.values() : defaultConnection;
@ -85,11 +94,14 @@ int initSyncthingTray(bool windowed, bool waitForTray, const Argument &connectio
}
// launch Syncthing if configured
std::cerr << ("before autostart\n");
settings.launcher.autostart();
// show a tray icon for each connection
TrayWidget *widget;
std::cerr << ("before conn loop\n");
for (const auto *const connectionConfig : connectionConfigurations) {
std::cerr << ("conn loop: ") << connectionConfig << "\n";
auto *const trayIcon = new TrayIcon(QString::fromLocal8Bit(connectionConfig), QApplication::instance());
trayIcon->show();
widget = &trayIcon->trayMenu().widget();
@ -140,6 +152,7 @@ void shutdownSyncthingTray()
int runApplication(int argc, const char *const *argv)
{
std::cerr << ("run application\n");
// setup argument parser
SET_APPLICATION_INFO;
CMD_UTILS_CONVERT_ARGS_TO_UTF8;
@ -168,14 +181,15 @@ int runApplication(int argc, const char *const *argv)
widgetsGuiArg.addSubArgument(&connectionArg);
widgetsGuiArg.addSubArgument(&configPathArg);
widgetsGuiArg.addSubArgument(&newInstanceArg);
parser.setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), &parser.noColorArg(), &parser.helpArg() });
std::cerr << ("before parsing args\n");
parser.parseArgs(argc, argv);
if (!qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
return 0;
}
// handle override for config dir
std::cerr << ("before overriding config dir\n");
if (const char *const configPathDir = configPathArg.firstValue()) {
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, QString::fromLocal8Bit(configPathDir));
}
@ -186,16 +200,34 @@ int runApplication(int argc, const char *const *argv)
firstRun = false;
// do first-time initializations
std::cerr << ("before first-time init\n");
SET_QT_APPLICATION_INFO;
QApplication application(argc, const_cast<char **>(argv));
QGuiApplication::setQuitOnLastWindowClosed(false);
const auto data = loadFontAwesomeIcon(QStringLiteral("hashtag"), QColor());
const auto i = renderSvgImage(data, QSize(64, 64), 0);
const auto data3 = loadFontAwesomeIcon(QStringLiteral("hashtag"), QColor());
const auto i3 = renderSvgImage(data, QSize(64, 64), 0);
std::cerr << "before sleep\n";
std::this_thread::sleep_for(2000ms);
std::cerr << "after sleep\n";
//const auto data2 = loadFontAwesomeIcon(QStringLiteral("globe"), QColor(10, 10, 10));
//const auto i2 = renderSvgImage(data2, QSize(64, 64), 0);
//static auto &m = IconManager::instance();
//const auto fas = FontAwesomeIcons(QColor(10, 10, 10), QSize(64, 64), 8);
std::cerr << ("before single instance\n");
SingleInstance singleInstance(argc, argv, newInstanceArg.isPresent());
networkAccessManager().setParent(&singleInstance);
QObject::connect(&singleInstance, &SingleInstance::newInstance, &runApplication);
std::cerr << ("before settings\n");
Settings::restore();
Settings::values().qt.apply();
qtConfigArgs.applySettings(true);
LOAD_QT_TRANSLATIONS;
std::cerr << ("before launcher\n");
SyncthingLauncher launcher;
SyncthingLauncher::setMainInstance(&launcher);
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
@ -206,24 +238,29 @@ int runApplication(int argc, const char *const *argv)
#endif
// init Syncthing Tray and immediately shutdown on failure
std::cerr << ("before init tray\n");
if (const auto res = initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent(), connectionArg)) {
std::cerr << ("before shutdown\n");
shutdownSyncthingTray();
return res;
}
// trigger UI and enter event loop
std::cerr << ("before first run trigger\n");
QObject::connect(&application, &QCoreApplication::aboutToQuit, &shutdownSyncthingTray);
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
return application.exec();
}
// trigger actions if --webui or --trigger is present but don't create a new tray icon
std::cerr << ("before triggering\n");
if (!TrayWidget::instances().empty() && (showWebUiArg.isPresent() || triggerArg.isPresent())) {
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
return 0;
}
// create new/additional tray icon
std::cerr << ("before init additional\n");
const auto res = initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent(), connectionArg);
if (!res) {
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
@ -233,5 +270,14 @@ int runApplication(int argc, const char *const *argv)
int main(int argc, char *argv[])
{
const auto application = QApplication(argc, const_cast<char **>(argv));
const auto data2 = QByteArray("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 496 512\"><path fill=\"#000000\" d=\"M336.5 160C322 70.7 287.8 8 248 8s-74 62.7-88.5 152h177zM152 256c0 22.2 1.2 43.5 3.3 64h185.3c2.1-20.5 3.3-41.8 3.3-64s-1.2-43.5-3.3-64H155. 3c-2.1 20.5-3.3 41.8-3.3 64zm324.7-96c-28.6-67.9-86.5-120.4-158-141.6 24.4 33.8 41.2 84.7 50 141.6h108zM177.2 18.4C105.8 39.6 47.8 92.1 19.3 160h108c8.7-56.9 25.5-107.8 49.9-141.6zM487.4 192H372.7c2.1 21 3.3 42.5 3.3 64s-1.2 43-3.3 64h1 14.6c5.5-20.5 8.6-41.8 8.6-64s-3.1-43.5-8.5-64zM120 256c0-21.5 1.2-43 3.3-64H8.6C3.2 212.5 0 233.8 0 256s3.2 43.5 8.6 64h114.6c-2-21-3.2-42.5-3.2-64zm39.5 96c14.5 89.3 48.7 152 88.5 152s74-62.7 88.5-152h-177zm159.3 141.6c71.4-21.2 129.4 -73.7 158-141.6h-108c-8.8 56.9-25.6 107.8-50 141.6zM19.3 352c28.6 67.9 86.5 120.4 158 141.6-24.4-33.8-41.2-84.7-50-141.6h-108z\"/></svg>");
auto renderer = QSvgRenderer(data2);
auto pm = QPixmap(QSize(64, 64));
pm.fill(QColor(Qt::transparent));
auto painter = QPainter(&pm);
renderer.render(&painter);
return 0;
return runApplication(argc, argv);
}

View File

@ -24,6 +24,8 @@
#include <QNetworkReply>
#endif
#include <iostream>
using namespace std;
using namespace QtUtilities;
using namespace Data;
@ -42,6 +44,8 @@ TrayIcon::TrayIcon(const QString &connectionConfig, QObject *parent)
, m_notifyOnSyncthingErrors(Settings::values().notifyOn.syncthingErrors)
, m_messageClickedAction(TrayIconMessageClickedAction::None)
{
std::cerr << ("before icon\n");
// get widget, connection and notifier
const auto &widget(trayMenu().widget());
const auto &connection(widget.connection());
@ -104,6 +108,8 @@ TrayIcon::TrayIcon(const QString &connectionConfig, QObject *parent)
connect(&notifier, &SyncthingNotifier::connected, &m_dbusNotifier, &DBusStatusNotifier::hideDisconnect);
#endif
std::cerr << ("before settings\n");
// apply settings, this also establishes the connection to Syncthing (according to settings)
// note: It is important to apply settings only after all Signals & Slots have been connected (e.g. to handle SyncthingConnection::error()).
// note: This weirdly calls updateStatusIconAndText(). So there is not need to call it again within this constructor.

View File

@ -9,6 +9,8 @@
#include <QApplication>
#include <QHBoxLayout>
#include <iostream>
using namespace QtUtilities;
namespace QtGui {
@ -17,6 +19,8 @@ TrayMenu::TrayMenu(TrayIcon *trayIcon, QWidget *parent)
: QMenu(parent)
, m_trayIcon(trayIcon)
{
std::cerr << ("before menu\n");
setObjectName(QStringLiteral("QtGui::TrayMenu"));
auto *const menuLayout = new QHBoxLayout;
menuLayout->setContentsMargins(0, 0, 0, 0);

View File

@ -47,6 +47,8 @@
#include <algorithm>
#include <functional>
#include <iostream>
using namespace CppUtilities;
using namespace QtUtilities;
using namespace Data;
@ -82,6 +84,8 @@ TrayWidget::TrayWidget(TrayMenu *parent)
, m_selectedConnection(nullptr)
, m_startStopButtonTarget(StartStopButtonTarget::None)
{
std::cerr << ("before widget\n");
// don't show connection status within connection settings if there are multiple tray widgets/icons (would be ambiguous)
if (!s_instances.empty() && s_settingsDlg) {
s_settingsDlg->hideConnectionStatus();