summaryrefslogtreecommitdiffstats
path: root/qml/mw.py
diff options
context:
space:
mode:
Diffstat (limited to 'qml/mw.py')
-rw-r--r--qml/mw.py206
1 files changed, 206 insertions, 0 deletions
diff --git a/qml/mw.py b/qml/mw.py
new file mode 100644
index 0000000..51fc544
--- /dev/null
+++ b/qml/mw.py
@@ -0,0 +1,206 @@
+#!/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, QAbstractListModel, QVariant, \
+ QModelIndex, Qt, QObject, pyqtSlot, pyqtProperty, qInstallMessageHandler, QSortFilterProxyModel, QRegExp, QByteArray
+import sys
+import os
+import subprocess
+from helpers import *
+import pwd
+
+class AppList(QAbstractListModel):
+
+ IconRole = Qt.UserRole + 1
+ NameRole = Qt.UserRole + 2
+ TitleRole = Qt.UserRole + 3
+ GroupRole = Qt.UserRole + 4
+ DescriptionRole = Qt.UserRole + 5
+ RepoRole = Qt.UserRole + 6
+ InstallableRole = Qt.UserRole + 7
+ InstalledRepoRole = Qt.UserRole + 8
+ listapp = []
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ self.get_listapp()
+
+ def get_listapp(self):
+ with open("apps.csv", 'rt') as f:
+ mycsv = csv.reader(f,delimiter='|')
+ next(mycsv)
+ for r in mycsv:
+ if (r[5] == 'false'):
+ r[5] = ""
+ is_app_installed, repo = is_installed(r[1])
+ installable = (not is_app_installed) or (r[6] != repo and repo != "")
+ app = { 'icon': "img/{}.png".format(r[0]),
+ 'name': r[1],
+ 'title': r[2],
+ 'group':r[3],
+ 'description': r[4],
+ 'command': r[5],
+ 'repo':r[6],
+ 'installable': installable,
+ 'inst_repo': repo}
+ self.listapp.append(app)
+
+ def data(self, index, role=Qt.DisplayRole):
+ row = index.row()
+ if role == AppList.IconRole:
+ return AppList.listapp[row]["icon"]
+ elif role == AppList.NameRole:
+ return AppList.listapp[row]["name"]
+ elif role == AppList.TitleRole:
+ return AppList.listapp[row]["title"]
+ elif role == AppList.GroupRole:
+ return AppList.listapp[row]["group"]
+ elif role == AppList.DescriptionRole:
+ return AppList.listapp[row]["description"]
+ elif role == AppList.RepoRole:
+ return AppList.listapp[row]["repo"]
+ elif role == AppList.InstallableRole:
+ return AppList.listapp[row]["installable"]
+ elif role == AppList.InstalledRepoRole:
+ return AppList.listapp[row]["installedRepo"]
+ else:
+ print("Not found")
+
+ def rowCount(self, parent=QModelIndex()):
+ return len(AppList.listapp)
+
+ def roleNames(self):
+ return {
+ AppList.IconRole: b'icon',
+ AppList.NameRole: b'name',
+ AppList.TitleRole: b'title',
+ AppList.GroupRole: b'group',
+ AppList.DescriptionRole: b'description',
+ AppList.RepoRole: b'repo',
+ AppList.InstallableRole: b'installable',
+ AppList.InstalledRepoRole: b'installedRepo'
+ }
+
+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': release},
+ {'name': _("kernel: {}").format(kernel)},
+ {'name': _("arch: {}").format(arch)},
+ {'name': _("Desktop: {}").format(desktop)},
+ {'name': _("Your user's id: {}").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])
+ print("Opening %s"%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 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)
+ cb = Callbrowser()
+ la = Launcher()
+ us = username()
+ ins = Installable()
+ cl = ConfList()
+ 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)
+ current_path = os.path.abspath(os.path.dirname(__file__))
+ qml_file = os.path.join(current_path, 'mw-ui.qml')
+ print("Loading")
+ 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)