summaryrefslogtreecommitdiff
path: root/kodereviewer/app.py
blob: eb196d17e5ebb5eeb0aa6300177ce51eed1ab960 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3

import os
import sys
import signal

from KI18n import KLocalizedContext, KLocalizedString
from PySide6.QtGui import QGuiApplication
from PySide6.QtCore import QUrl, QByteArray
from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterType
from PySide6.QtQuickControls2 import QQuickStyle

from kodereviewer.data import PullRequest
from kodereviewer.models.file import FileModel
from kodereviewer.network_manager import NetworkManager
from kodereviewer.models import (
    CommentModel, TreeFileModel, LabelModel, LineModel, PullRequestModel,
    ProjectModel, ReviewerModel, ReviewModel
)
import logging
from rich.logging import RichHandler

FORMAT = "%(message)s"
logging.basicConfig(
    level="INFO", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
)


def main():
    """Initializes and manages the application execution"""
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    # KLocalizedString::setApplicationDomain("tutorial");
    KLocalizedString.setApplicationDomain(QByteArray(b"kodereviewer"))

    app.setOrganizationName("Deprecated")
    app.setOrganizationDomain("deprecated.org")
    app.setApplicationName("Kode Reviewer")
    app.setDesktopFileName("kodereviewer")

    """Needed to close the app with Ctrl+C"""
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    """Needed to get proper KDE style outside of Plasma"""
    if not os.environ.get("QT_QUICK_CONTROLS_STYLE"):
        QQuickStyle.setStyle("org.kde.desktop")


    qmlRegisterType(ProjectModel, "org.deprecated.kodereviewer", 1, 0, "ProjectModel")

    qmlRegisterType(CommentModel, "org.deprecated.kodereviewer", 1, 0, "CommentModel")
    qmlRegisterType(FileModel, "org.deprecated.kodereviewer", 1, 0, "FileModel")
    qmlRegisterType(TreeFileModel, "org.deprecated.kodereviewer", 1, 0, "TreeFileModel")
    qmlRegisterType(LabelModel, "org.deprecated.kodereviewer", 1, 0, "LabelModel")
    qmlRegisterType(LineModel, "org.deprecated.kodereviewer", 1, 0, "LineModel")
    qmlRegisterType(PullRequestModel, "org.deprecated.kodereviewer", 1, 0, "PullRequestModel")
    qmlRegisterType(ReviewerModel, "org.deprecated.kodereviewer", 1, 0, "ReviewerModel")
    qmlRegisterType(ReviewModel, "org.deprecated.kodereviewer", 1, 0, "ReviewModel")
    qmlRegisterType(NetworkManager, "org.deprecated.kodereviewer", 1, 0, "NetworkManager")

    qmlRegisterType(PullRequest, "org.deprecated.kodereviewer", 1, 0, "PullRequest")

    localized_context = KLocalizedContext()
    engine.rootContext().setContextObject(localized_context)
    base_path = os.path.abspath(os.path.dirname(__file__))
    engine.addImportPath(f"file://{base_path}/qml")
    engine.addImportPath(f"file://{base_path}/qml/delegates")
    url = QUrl(f"file://{base_path}/qml/Main.qml")
    engine.load(url)

    if len(engine.rootObjects()) == 0:
        quit()

    app.exec()


if __name__ == "__main__":
    main()