From 453c1d451f6cf60d4b0d80cf7f760641c60f32ab Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 17 Jun 2021 00:05:03 +0200 Subject: [PATCH] Hardcore print-debugging --- connector/syncthingconnection.cpp | 4 ++++ connector/syncthingnotifier.cpp | 4 ++++ model/syncthingdirectorymodel.cpp | 4 ++++ model/syncthingicons.cpp | 21 +++++++++++++++++- model/syncthingmodel.cpp | 5 +++++ model/syncthingrecentchangesmodel.cpp | 3 +++ model/syncthingsortfiltermodel.h | 4 ++++ tray/application/main.cpp | 31 ++++++++++++++++++++++++++- tray/gui/trayicon.cpp | 6 ++++++ tray/gui/traymenu.cpp | 4 ++++ tray/gui/traywidget.cpp | 4 ++++ 11 files changed, 88 insertions(+), 2 deletions(-) diff --git a/connector/syncthingconnection.cpp b/connector/syncthingconnection.cpp index 044ad85..41d1524 100644 --- a/connector/syncthingconnection.cpp +++ b/connector/syncthingconnection.cpp @@ -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"); } /*! diff --git a/connector/syncthingnotifier.cpp b/connector/syncthingnotifier.cpp index ce60fbe..550223c 100644 --- a/connector/syncthingnotifier.cpp +++ b/connector/syncthingnotifier.cpp @@ -9,6 +9,8 @@ #include +#include + 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) diff --git a/model/syncthingdirectorymodel.cpp b/model/syncthingdirectorymodel.cpp index 51de6c3..8bcd4f1 100644 --- a/model/syncthingdirectorymodel.cpp +++ b/model/syncthingdirectorymodel.cpp @@ -9,6 +9,8 @@ #include +#include + 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 SyncthingDirectoryModel::roleNames() const diff --git a/model/syncthingicons.cpp b/model/syncthingicons.cpp index e555c74..67e45c1 100644 --- a/model/syncthingicons.cpp +++ b/model/syncthingicons.cpp @@ -8,6 +8,8 @@ #include #include +#include + namespace Data { /*! @@ -117,15 +119,21 @@ QByteArray makeSyncthingIcon(const StatusIconColorSet &colors, StatusEmblem stat namespace Detail { template 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 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 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; } diff --git a/model/syncthingmodel.cpp b/model/syncthingmodel.cpp index aa1f701..14f9194 100644 --- a/model/syncthingmodel.cpp +++ b/model/syncthingmodel.cpp @@ -3,6 +3,8 @@ #include +#include + 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 &SyncthingModel::colorRoles() const diff --git a/model/syncthingrecentchangesmodel.cpp b/model/syncthingrecentchangesmodel.cpp index 9692739..aa612af 100644 --- a/model/syncthingrecentchangesmodel.cpp +++ b/model/syncthingrecentchangesmodel.cpp @@ -11,6 +11,8 @@ #include +#include + 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); } diff --git a/model/syncthingsortfiltermodel.h b/model/syncthingsortfiltermodel.h index 8b08c1c..9231351 100644 --- a/model/syncthingsortfiltermodel.h +++ b/model/syncthingsortfiltermodel.h @@ -5,6 +5,8 @@ #include +#include + 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 diff --git a/tray/application/main.cpp b/tray/application/main.cpp index 7c256a4..0623461 100644 --- a/tray/application/main.cpp +++ b/tray/application/main.cpp @@ -30,6 +30,7 @@ #include #include +#include using namespace std; using namespace CppUtilities; @@ -55,6 +56,10 @@ int initSyncthingTray(bool windowed, bool waitForTray, const Argument &connectio // get settings auto &settings = Settings::values(); static const auto defaultConnection = std::vector({ "" }); + 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 +90,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 +148,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 +177,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 +196,30 @@ 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(argv)); QGuiApplication::setQuitOnLastWindowClosed(false); + + const auto data = loadFontAwesomeIcon(QStringLiteral("hashtag"), QColor()); + const auto i = renderSvgImage(data, QSize(64, 64), 0); + std::cerr << "before sleep\n"; + std::this_thread::sleep_for(2000ms); + std::cerr << "after sleep\n"; + const auto i2 = renderSvgImage(loadFontAwesomeIcon(QStringLiteral("globe"), QColor(10, 10, 10)), 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 +230,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()); diff --git a/tray/gui/trayicon.cpp b/tray/gui/trayicon.cpp index d3c113e..c37f5a0 100644 --- a/tray/gui/trayicon.cpp +++ b/tray/gui/trayicon.cpp @@ -24,6 +24,8 @@ #include #endif +#include + 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(¬ifier, &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. diff --git a/tray/gui/traymenu.cpp b/tray/gui/traymenu.cpp index 99604cc..03bfe84 100644 --- a/tray/gui/traymenu.cpp +++ b/tray/gui/traymenu.cpp @@ -9,6 +9,8 @@ #include #include +#include + 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); diff --git a/tray/gui/traywidget.cpp b/tray/gui/traywidget.cpp index 34111f4..30c7efe 100644 --- a/tray/gui/traywidget.cpp +++ b/tray/gui/traywidget.cpp @@ -47,6 +47,8 @@ #include #include +#include + 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();