diff --git a/gotify_tray/gui/ServerInfoDialog.py b/gotify_tray/gui/ServerInfoDialog.py
index 632aee7..649ba66 100644
--- a/gotify_tray/gui/ServerInfoDialog.py
+++ b/gotify_tray/gui/ServerInfoDialog.py
@@ -1,6 +1,7 @@
+from gotify_tray.gotify.models import GotifyVersionModel
+from gotify_tray.tasks import VerifyServerInfoTask
from PyQt6 import QtWidgets
-from gotify_tray.tasks import VerifyServerInfoTask
from .designs.widget_server import Ui_Dialog
@@ -11,7 +12,9 @@ class ServerInfoDialog(QtWidgets.QDialog, Ui_Dialog):
self.setWindowTitle("Server info")
self.line_url.setText(url)
self.line_token.setText(token)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True)
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(
+ True
+ )
self.link_callbacks()
def test_server_info(self):
@@ -25,7 +28,9 @@ class ServerInfoDialog(QtWidgets.QDialog, Ui_Dialog):
return
self.pb_test.setDisabled(True)
- self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True)
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(
+ True
+ )
self.task = VerifyServerInfoTask(url, client_token)
self.task.success.connect(self.server_info_success)
@@ -33,22 +38,35 @@ class ServerInfoDialog(QtWidgets.QDialog, Ui_Dialog):
self.task.incorrect_url.connect(self.incorrect_url_callback)
self.task.start()
- def server_info_success(self):
+ def server_info_success(self, version: GotifyVersionModel):
self.pb_test.setEnabled(True)
+ self.label_server_info.setText(f"Version: {version.version}")
self.pb_test.setStyleSheet("background-color: rgba(0, 255, 0, 100);")
- self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(True)
+ self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(
+ True
+ )
- def incorrect_token_callback(self):
+ def incorrect_token_callback(self, version: GotifyVersionModel):
self.pb_test.setEnabled(True)
+ self.label_server_info.setText(f"Version: {version.version}")
self.pb_test.setStyleSheet("background-color: rgba(255, 0, 0, 100);")
self.line_token.setStyleSheet("border: 1px solid red;")
def incorrect_url_callback(self):
self.pb_test.setEnabled(True)
+ self.label_server_info.clear()
self.pb_test.setStyleSheet("background-color: rgba(255, 0, 0, 100);")
self.line_url.setStyleSheet("border: 1px solid red;")
def link_callbacks(self):
self.pb_test.clicked.connect(self.test_server_info)
- self.line_url.textChanged.connect(lambda: self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True))
- self.line_token.textChanged.connect(lambda: self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True))
+ self.line_url.textChanged.connect(
+ lambda: self.buttonBox.button(
+ QtWidgets.QDialogButtonBox.StandardButton.Ok
+ ).setDisabled(True)
+ )
+ self.line_token.textChanged.connect(
+ lambda: self.buttonBox.button(
+ QtWidgets.QDialogButtonBox.StandardButton.Ok
+ ).setDisabled(True)
+ )
diff --git a/gotify_tray/gui/designs/widget_server.py b/gotify_tray/gui/designs/widget_server.py
index 63bbfa5..b9f0249 100644
--- a/gotify_tray/gui/designs/widget_server.py
+++ b/gotify_tray/gui/designs/widget_server.py
@@ -1,6 +1,6 @@
# Form implementation generated from reading ui file 'gotify_tray/gui/designs\widget_server.ui'
#
-# Created by: PyQt6 UI code generator 6.1.1
+# Created by: PyQt6 UI code generator 6.2.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
@@ -12,9 +12,16 @@ from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
- Dialog.resize(300, 124)
+ Dialog.resize(300, 130)
self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout")
+ self.label_server_info = QtWidgets.QLabel(Dialog)
+ self.label_server_info.setText("")
+ self.label_server_info.setObjectName("label_server_info")
+ self.gridLayout.addWidget(self.label_server_info, 1, 2, 1, 1)
+ self.pb_test = QtWidgets.QPushButton(Dialog)
+ self.pb_test.setObjectName("pb_test")
+ self.gridLayout.addWidget(self.pb_test, 1, 4, 1, 1)
self.formLayout = QtWidgets.QFormLayout()
self.formLayout.setObjectName("formLayout")
self.label = QtWidgets.QLabel(Dialog)
@@ -29,29 +36,26 @@ class Ui_Dialog(object):
self.line_token = QtWidgets.QLineEdit(Dialog)
self.line_token.setObjectName("line_token")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.line_token)
- self.gridLayout.addLayout(self.formLayout, 0, 0, 1, 2)
- self.pb_test = QtWidgets.QPushButton(Dialog)
- self.pb_test.setObjectName("pb_test")
- self.gridLayout.addWidget(self.pb_test, 1, 1, 1, 1)
+ self.gridLayout.addLayout(self.formLayout, 0, 1, 1, 4)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
self.buttonBox.setObjectName("buttonBox")
- self.gridLayout.addWidget(self.buttonBox, 2, 1, 1, 1)
+ self.gridLayout.addWidget(self.buttonBox, 2, 4, 1, 1)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
- self.gridLayout.addItem(spacerItem, 1, 0, 1, 1)
+ self.gridLayout.addItem(spacerItem, 1, 3, 1, 1)
self.retranslateUi(Dialog)
- self.buttonBox.accepted.connect(Dialog.accept)
- self.buttonBox.rejected.connect(Dialog.reject)
+ self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
+ self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
+ self.pb_test.setText(_translate("Dialog", "Test"))
self.label.setText(_translate("Dialog", "Server url:"))
self.label_2.setText(_translate("Dialog", "Client token:"))
- self.pb_test.setText(_translate("Dialog", "Test"))
if __name__ == "__main__":
diff --git a/gotify_tray/gui/designs/widget_server.ui b/gotify_tray/gui/designs/widget_server.ui
index 5089637..547e08e 100644
--- a/gotify_tray/gui/designs/widget_server.ui
+++ b/gotify_tray/gui/designs/widget_server.ui
@@ -7,14 +7,21 @@
0
0
300
- 124
+ 130
Dialog
- -
+
-
+
+
+ Test
+
+
+
+ -
-
@@ -38,14 +45,7 @@
- -
-
-
- Test
-
-
-
- -
+
-
Qt::Horizontal
@@ -55,7 +55,7 @@
- -
+
-
Qt::Horizontal
@@ -68,6 +68,13 @@
+ -
+
+
+
+
+
+
diff --git a/gotify_tray/tasks.py b/gotify_tray/tasks.py
index b7d5135..279781a 100644
--- a/gotify_tray/tasks.py
+++ b/gotify_tray/tasks.py
@@ -4,6 +4,8 @@ import logging
from PyQt6 import QtCore
from PyQt6.QtCore import pyqtSignal
+from gotify_tray.gotify.models import GotifyVersionModel
+
from . import gotify
@@ -120,8 +122,8 @@ class GetMessagesTask(BaseTask):
class VerifyServerInfoTask(BaseTask):
- success = pyqtSignal()
- incorrect_token = pyqtSignal()
+ success = pyqtSignal(GotifyVersionModel)
+ incorrect_token = pyqtSignal(GotifyVersionModel)
incorrect_url = pyqtSignal()
def __init__(self, url: str, client_token: str):
@@ -132,16 +134,22 @@ class VerifyServerInfoTask(BaseTask):
def task(self):
try:
gotify_client = gotify.GotifyClient(self.url, self.client_token)
+
+ version = gotify_client.version()
+ if isinstance(version, gotify.GotifyErrorModel):
+ self.incorrect_url.emit()
+ return
+
result = gotify_client.get_messages(limit=1)
if isinstance(result, gotify.GotifyPagedMessagesModel):
- self.success.emit()
+ self.success.emit(version)
return
elif (
isinstance(result, gotify.GotifyErrorModel)
and result["error"] == "Unauthorized"
):
- self.incorrect_token.emit()
+ self.incorrect_token.emit(version)
return
self.incorrect_url.emit()
except Exception as e: