removed UI stuff from backend controller

This commit is contained in:
Lasan Mahaliyana
2026-06-27 11:43:00 +05:30
parent 98f01a84aa
commit 4b7a4bff0e
6 changed files with 49 additions and 46 deletions
+34 -41
View File
@@ -1,6 +1,5 @@
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_qt//:qt.bzl", "qt_cc_binary", "qt_cc_library", "qt_resource_via_qrc")
load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")
@@ -19,17 +18,17 @@ refresh_compile_commands(
# And if you're working on a header-only library, specify a test or binary target that compiles it.
)
# 1. Compile QML files into a C++ source file using Qt's Resource Compiler (rcc)
genrule(
name = "qrc_generation",
srcs = [
"resources.qrc",
qt_resource_via_qrc(
name = "app_resources",
qrc_file = "resources.qrc",
files = [
"main.qml",
"AppContent.qml",
"Drop.qml",
"Sidebar.qml",
"ShareTarget.qml",
"Targets.qml",
"IncomingShare.qml",
"googlesans_var.ttf",
"icons/file.svg",
"icons/laptop.svg",
@@ -37,44 +36,38 @@ genrule(
"icons/tablet.svg",
"icons/up_file.svg",
],
outs = ["qrc_resources.cpp"],
cmd = "/usr/lib64/qt6/libexec/rcc $(location resources.qrc) -o $(location qrc_resources.cpp)",
)
# 2. MOC generation for backend.h
genrule(
name = "moc_backend",
srcs = ["backend.h"],
outs = ["moc_backend.cpp"],
cmd = "/usr/lib64/qt6/libexec/moc $(location backend.h) -o $(location moc_backend.cpp) ",
)
cc_binary(
name = "app",
srcs = [
"backend.cc",
"main.cc",
"backend.h",
":qrc_generation", # Include the generated QRC file
":moc_backend",
],
copts = [
# Base Qt6 directory
"-I/usr/include/qt6",
# Individual module directories required for QGuiApplication and QQmlApplicationEngine
"-I/usr/include/qt6/QtCore",
"-I/usr/include/qt6/QtGui",
"-I/usr/include/qt6/QtQml",
"-I/usr/include/qt6/QtQuick",
],
linkopts = [
"-lQt6Core",
"-lQt6Gui",
"-lQt6Qml",
"-lQt6Quick",
],
qt_cc_library(
name = "backend",
srcs = ["backend.cc"],
hdrs = ["backend.h"],
deps = [
":nearby_sharing_dbus_client",
"@rules_qt//:qt_core",
"@rules_qt//:qt_hdrs",
"@rules_qt//:qt_qml",
"@rules_qt//:qt_qml_meta",
],
)
qt_cc_binary(
name = "app",
srcs = ["main.cc"],
deps = [
":app_resources",
":backend",
"@rules_qt//:qt_core",
"@rules_qt//:qt_gui",
"@rules_qt//:qt_hdrs",
"@rules_qt//:qt_opengl",
"@rules_qt//:qt_qml",
"@rules_qt//:qt_qml_meta",
"@rules_qt//:qt_qml_workerscript",
"@rules_qt//:qt_quick",
"@rules_qt//:qt_quick_controls2",
"@rules_qt//:qt_quick_layouts",
"@rules_qt//:qt_quick_shapes",
],
)
+2 -3
View File
@@ -7,7 +7,7 @@ Row {
spacing: 10
Repeater {
model: ["Lasan's A55", "Lasan's Tab S9+", "lasan-laptop", "Somethign else"]
model: backend.targets
// Your original delegate structure
Rectangle {
@@ -23,11 +23,10 @@ Row {
anchors.right: parent.right
spacing: 5
ShareTarget{
ShareTarget {
progressValue: 0.7
}
}
}
}
+5 -2
View File
@@ -11,13 +11,15 @@
#include <QString>
#include <QVariantList>
#include "QtQmlIntegration/qqmlintegration.h"
#include "qtmetamacros.h"
#include "sharing/linux/app/nearby_sharing_dbus_client.h"
class Backend
: public QObject,
public nearby::sharing::linux::app::NearbySharingDbusClient::Observer {
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged)
Q_PROPERTY(bool receiveRegistered READ receiveRegistered NOTIFY statusChanged)
Q_PROPERTY(
@@ -81,9 +83,10 @@ class Backend
const std::function<std::tuple<bool, std::string>()>& operation);
void SetStatusText(const QString& text);
int counter_ = 0;
QString status_text_;
Status status_;
std::map<int64_t, ShareTarget> targets_;
std::unique_ptr<Client> client_;
Transfer current_transfer_;
bool is_incoming_transfer_ = false;
};
+6
View File
@@ -7,6 +7,8 @@
#include <QObject>
#include <QTimer>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "backend.h"
namespace {
@@ -129,7 +131,11 @@ int main(int argc, char* argv[]) {
return app.exec();
}
// 1. Create the backend instance in C++
Backend backend;
// 2. Inject it into the QML root context
engine.rootContext()->setContextProperty("backend", &backend);
// Loaded via the qrc scheme since it's compiled into the binary
const QUrl url(QStringLiteral("qrc:/main.qml"));
+1
View File
@@ -9,6 +9,7 @@ Window {
title: qsTr("QuickShare")
color: "#DCF5FF"
FontLoader {
id: googlesans
source: "qrc:/googlesans_var.ttf"
+1
View File
@@ -5,6 +5,7 @@
<file>Sidebar.qml</file>
<file>Drop.qml</file>
<file>ShareTarget.qml</file>
<file>IncomingShare.qml</file>
<file>Targets.qml</file>
<file>googlesans_var.ttf</file>
<file>icons/file.svg</file>