summaryrefslogtreecommitdiffstats
path: root/qml/mageiawelcome.py
diff options
context:
space:
mode:
authorPapoteur <papoteur@mageia.org>2018-12-09 18:22:29 +0100
committerPapoteur <papoteur@mageia.org>2018-12-17 10:19:29 +0100
commit7438cd8ea20fd04b3273329cae3a1410d4b8ad89 (patch)
tree1febe341be67a8edeecb01d5661ffd86e1902eb4 /qml/mageiawelcome.py
parentbfe0c95481b8b0e3cd9a9e5965db0579504808c2 (diff)
downloadmageiawelcome-7438cd8ea20fd04b3273329cae3a1410d4b8ad89.tar
mageiawelcome-7438cd8ea20fd04b3273329cae3a1410d4b8ad89.tar.gz
mageiawelcome-7438cd8ea20fd04b3273329cae3a1410d4b8ad89.tar.bz2
mageiawelcome-7438cd8ea20fd04b3273329cae3a1410d4b8ad89.tar.xz
mageiawelcome-7438cd8ea20fd04b3273329cae3a1410d4b8ad89.zip
Rename the main program
Diffstat (limited to 'qml/mageiawelcome.py')
-rw-r--r--qml/mageiawelcome.py160
1 files changed, 160 insertions, 0 deletions
diff --git a/qml/mageiawelcome.py b/qml/mageiawelcome.py
new file mode 100644
index 0000000..b0b4258
--- /dev/null
+++ b/qml/mageiawelcome.py
@@ -0,0 +1,160 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+from PyQt5.QtGui import QGuiApplication
+from PyQt5.QtQuick import QQuickView
+from PyQt5.QtQml import qmlRegisterType
+from PyQt5.QtCore import QUrl, QLocale, QTranslator, QLibraryInfo, QVariant, QAbstractListModel, \
+ QModelIndex, Qt, QObject, pyqtSlot, pyqtProperty
+import sys
+import os
+import subprocess
+from helpers import *
+import pwd
+
+class ConfList(QAbstractListModel):
+ NameRole = Qt.UserRole + 1
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ # Changing working directory
+ abspath = os.path.abspath(__file__)
+ dname = os.path.dirname(abspath)
+ os.chdir(dname)
+
+ #collect sys info
+ #release = open("/etc/release", "r").read()
+ release = subprocess.getoutput('lsb_release -sd')
+ release = release[1:-1]
+ release_nb = subprocess.getoutput('lsb_release -sr')
+ release_nb = release_nb.strip()
+ kernel = subprocess.getoutput('uname -r')
+ if os.uname()[4] == 'x86_64':
+ arch = '64-bit'
+ else:
+ arch = '32-bit'
+ home = os.getenv("HOME")
+ username = os.getenv("USER")
+ try:
+ desktop = get_desktop_name(os.path.basename(os.getenv("DESKTOP_SESSION")))
+ except:
+ desktop = 'Other'
+
+ if desktop == 'Other':
+ desktop = get_desktop_name2(os.getenv("XDG_CURRENT_DESKTOP"))
+ if desktop == 'unknown':
+ desktop = os.getenv("XDG_CURRENT_DESKTOP")
+
+ self.configuration = [
+ {'name': _("Congratulations! You have completed the installation of {}").format(release)},
+ {'name': _("You are using linux kernel: {}").format(kernel)},
+ {'name': _("Your system architecture is: {}").format(arch)},
+ {'name': _("You are now using the Desktop: {}").format(desktop)},
+ {'name': _("Your user's id is: {}").format(os.getuid())},
+ ]
+
+ def data(self, index, role=Qt.DisplayRole):
+ row = index.row()
+ return self.configuration[row]["name"]
+
+ def rowCount(self, parent=QModelIndex()):
+ return len(self.configuration)
+
+ def roleNames(self):
+ return {
+ ConfList.NameRole: b'name',
+ }
+
+class Callbrowser(QObject):
+ def __init__(self):
+ QObject.__init__(self)
+
+ @pyqtSlot(str)
+ def weblink(self, link):
+ subprocess.Popen(["xdg-open", link])
+
+class Launcher(QObject):
+ def __init__(self):
+ QObject.__init__(self)
+
+ @pyqtSlot(QVariant)
+ def command(self, app):
+ if app.isArray():
+ cmd = []
+ for i in range(0,app.property("length").toInt()):
+ cmd.append(app.property(i).toString())
+ subprocess.Popen(cmd)
+
+class Norun(QObject):
+ def __init__(self):
+ QObject.__init__(self)
+ self.home = os.getenv("HOME")
+ self.conffile = self.home + "/.config/mageiawelcome/norun.flag"
+ print(self.conffile, os.path.exists(self.conffile))
+
+ @pyqtSlot(bool)
+ def setRunAtLaunch(self, checked):
+ print("Setting",checked)
+ if checked:
+ if os.path.exists(self.conffile):
+ os.remove( self.conffile)
+ else:
+ os.makedirs(self.home + "/.config/mageiawelcome", exist_ok=True)
+ with open( self.conffile, 'w') as f:
+ pass
+
+ @pyqtSlot(result=bool)
+ def startupcheck(self):
+ return not os.path.exists(self.conffile)
+
+class Installable(QObject):
+ def __init__(self):
+ QObject.__init__(self)
+
+ @pyqtSlot(str, str, result=bool)
+ def installable(self, app,repo):
+ is_app_installed, inst_repo = is_installed(app)
+ installable = (not is_app_installed) or (repo != inst_repo and inst_repo != "")
+ return installable
+
+def username():
+ user = pwd.getpwuid(os.getuid())[4] # pw_gecos, i e the real name
+ if user == "":
+ user = pwd.getpwuid(os.getuid())[0] # login
+ return user
+
+if __name__ == '__main__':
+ app = QGuiApplication(sys.argv)
+ locale = QLocale.system().name()
+ qtTranslator = QTranslator()
+ if qtTranslator.load("qt_" + locale,QLibraryInfo.location(QLibraryInfo.TranslationsPath)):
+ app.installTranslator(qtTranslator)
+ appTranslator = QTranslator()
+ if appTranslator.load("mageiawelcome_" + locale,':/languages'):
+ app.installTranslator(appTranslator)
+ view = QQuickView()
+ view.setResizeMode(QQuickView.SizeRootObjectToView)
+ view.setTitle(app.tr("Welcome to Mageia"))
+ cb = Callbrowser()
+ la = Launcher()
+ us = username()
+ ins = Installable()
+ cl = ConfList()
+ nr = Norun()
+ sc = nr.startupcheck()
+ view.rootContext().setContextProperty('link', cb)
+ view.rootContext().setContextProperty('launch', la)
+ view.rootContext().setContextProperty('user', us)
+ view.rootContext().setContextProperty('ConfList', cl)
+ view.rootContext().setContextProperty('installable', ins)
+ view.rootContext().setContextProperty('startupcheck', sc)
+ view.rootContext().setContextProperty('norun', nr)
+ current_path = os.path.abspath(os.path.dirname(__file__))
+ qml_file = os.path.join(current_path, 'mw-ui.qml')
+ view.setSource(QUrl.fromLocalFile(qml_file))
+ if view.status() == QQuickView.Error:
+ for error in view.errors():
+ print(error.description())
+ sys.exit(-1)
+ view.show()
+ res = app.exec_()
+ del view
+ sys.exit(res)