Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'minimize on close' function. Closes #33 #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion qomui/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(self):
def run(self):
net_iface_dir = "/sys/class/net/"
net_check = 0
i = "None"

while True:
prior = net_check
Expand Down
105 changes: 73 additions & 32 deletions qomui/qomui_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class QomuiGui(QtWidgets.QWidget):
"firewall",
"autoconnect",
"minimize",
"minimize_on_close",
"ipv6_disable",
"alt_dns",
"bypass",
Expand Down Expand Up @@ -426,6 +427,16 @@ def setupUi(self, Form):
self.minimizeOptLabel.setIndent(20)
self.minimizeOptLabel.setFont(italic_font)
self.verticalLayout_5.addWidget(self.minimizeOptLabel)
self.minimize_on_closeOptCheck = QtWidgets.QCheckBox(self.optionsTab)
self.minimize_on_closeOptCheck.setFont(bold_font)
self.minimize_on_closeOptCheck.setObjectName(_fromUtf8("minimize_on_closeOptCheck"))
self.verticalLayout_5.addWidget(self.minimize_on_closeOptCheck)
self.minimize_on_closeOptLabel = QtWidgets.QLabel(self.optionsTab)
self.minimize_on_closeOptLabel.setObjectName(_fromUtf8("minimize_on_closeOptLabel"))
self.minimize_on_closeOptLabel.setWordWrap(True)
self.minimize_on_closeOptLabel.setIndent(20)
self.minimize_on_closeOptLabel.setFont(italic_font)
self.verticalLayout_5.addWidget(self.minimize_on_closeOptLabel)
self.auto_updateOptCheck = QtWidgets.QCheckBox(self.optionsTab)
self.auto_updateOptCheck.setObjectName(_fromUtf8("auto_updateOptCheck"))
self.auto_updateOptCheck.setFont(bold_font)
Expand Down Expand Up @@ -616,7 +627,7 @@ def setupUi(self, Form):
self.scriptLabel.setFont(bold_font)
self.scriptLabel.setObjectName("scriptLabel")
self.verticalLayout_30.addWidget(self.scriptLabel)
self.gridLayout10 = QtWidgets.QGridLayout(Form)
self.gridLayout10 = QtWidgets.QGridLayout()
self.gridLayout10.setObjectName("gridLayout")
self.preCheck = QtWidgets.QLabel(Form)
self.preCheck.setObjectName("preCheck")
Expand Down Expand Up @@ -854,6 +865,7 @@ def retranslateUi(self, Form):
self.autoconnectOptCheck.setText(_translate("Form", "Autoconnect/reconnect", None))
self.auto_updateOptCheck.setText(_translate("Form", "Auto-update", None))
self.minimizeOptCheck.setText(_translate("Form", "Start minimized", None))
self.minimize_on_closeOptCheck.setText(_translate("Form", "Minimize to tray on close", None))
self.firewallOptCheck.setText(_translate("Form", "Activate Firewall ", None))
self.bypassOptCheck.setText(_translate("Form", "Allow OpenVPN bypass", None))
self.pingOptCheck.setText(_translate("Form", "Perform latency check", None))
Expand Down Expand Up @@ -912,7 +924,10 @@ def retranslateUi(self, Form):
"Automatically (re-)connect to last server",
None))
self.minimizeOptLabel.setText(_translate("Form",
"Only works if system tray is available",
"Works only if system tray is available",
None))
self.minimize_on_closeOptLabel.setText(_translate("Form",
"Works only if system tray is available",
None))
self.auto_updateOptLabel.setText(_translate("Form",
"Enable automatic updates for supported providers",
Expand Down Expand Up @@ -1160,39 +1175,65 @@ def restoreUi(self, reason):
self.showNormal()

def closeEvent(self, event):
self.exit_event = event
self.confirm = QtWidgets.QMessageBox()
self.timeout = 5
self.confirm.setText("Do you really want to quit Qomui?")
info = "Closing in {} seconds".format(self.timeout)
self.confirm.setInformativeText(info)
self.confirm.setIcon(QtWidgets.QMessageBox.Question)
self.confirm.addButton(QtWidgets.QPushButton("Exit"), QtWidgets.QMessageBox.YesRole)
self.confirm.addButton(QtWidgets.QPushButton("Cancel"), QtWidgets.QMessageBox.NoRole)
if self.tray.isSystemTrayAvailable() == True:
self.confirm.addButton(QtWidgets.QPushButton("Minimize"), QtWidgets.QMessageBox.RejectRole)
self.exit_timer = QtCore.QTimer(self)
self.exit_timer.setInterval(1000)
self.exit_timer.timeout.connect(self.change_timeout)
self.exit_timer.start()

ret = self.confirm.exec_()
self.exit_timer.stop()
if self.isHidden() == False and self.config_dict["minimize_on_close"] == 0:
self.exit_event = event
self.confirm = QtWidgets.QMessageBox()
self.timeout = 5
self.confirm.setText("Do you really want to quit Qomui?")
info = "Closing in {} seconds".format(self.timeout)
self.confirm.setInformativeText(info)
self.confirm.setIcon(QtWidgets.QMessageBox.Question)
self.confirm.addButton(QtWidgets.QPushButton("Exit"), QtWidgets.QMessageBox.YesRole)
self.confirm.addButton(QtWidgets.QPushButton("Cancel"), QtWidgets.QMessageBox.NoRole)
if self.tray.isSystemTrayAvailable() == True:
self.confirm.addButton(QtWidgets.QPushButton("Minimize"), QtWidgets.QMessageBox.RejectRole)

self.exit_timer = QtCore.QTimer(self)
self.exit_timer.setInterval(1000)
self.exit_timer.timeout.connect(self.change_timeout)
self.exit_timer.start()

ret = self.confirm.exec_()
self.exit_timer.stop()

if ret == 1:
self.exit_event.ignore()
if ret == 1:
self.exit_event.ignore()

elif ret == 2:
self.hide()
elif ret == 2:
if self.config_dict["minimize_on_close"] == 0:
self.confirm = QtWidgets.QMessageBox()
self.confirm.setIcon(QtWidgets.QMessageBox.Question)
self.confirm.setText("Remember choice?")
self.confirm.addButton(QtWidgets.QPushButton("Yes"), QtWidgets.QMessageBox.YesRole)
self.confirm.addButton(QtWidgets.QPushButton("No"), QtWidgets.QMessageBox.NoRole)

self.timeout = 5
self.confirm.setInformativeText(info)
self.exit_timer = QtCore.QTimer(self)
self.exit_timer.setInterval(1000)
self.exit_timer.timeout.connect(self.change_timeout)
self.exit_timer.start()

ret = self.confirm.exec_()
self.exit_timer.stop()

if ret == 0:
self.config_dict["minimize_on_close"] = 1
self.save_options(self.config_dict)

self.hide()

elif ret == 0:
self.tray.hide()
self.kill()
self.disconnect_bypass()
self.dbus_call("load_firewall", 2)
with open ("{}/server.json".format(HOMEDIR), "w") as s:
json.dump(self.server_dict, s)
self.exit_event.accept()
elif ret == 0:
self.tray.hide()
self.kill()
self.disconnect_bypass()
self.dbus_call("load_firewall", 2)
with open ("{}/server.json".format(HOMEDIR), "w") as s:
json.dump(self.server_dict, s)
self.exit_event.accept()

elif self.config_dict["minimize_on_close"] == 1:
self.hide()

def change_timeout(self):
self.timeout -= 1
Expand Down
1 change: 0 additions & 1 deletion qomui/tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ def ovpn(self, ovpn_file, h, cwd_ovpn):
#keep this thread as long as openvpn process has not been terminated
#disconnection from gui will kill the openvpn process and break the loop
while line.find("SIGTERM[hard,] received, process exiting") == -1:
time_measure = time.time()
line_format = ("OpenVPN:" + line.replace('{}'.format(time.asctime()), '').replace('\n', ''))
self.log.emit(("info", line_format))

Expand Down
2 changes: 1 addition & 1 deletion resources/default_config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"alt_dns1": "208.67.222.222", "alt_dns2": "208.67.220.220", "firewall": 0, "autoconnect": 0, "minimize": 0, "ipv6_disable": 0, "alt_dns": 0, "bypass": 0, "ping": 0, "auto_update": 0, "block_lan": 0, "preserve_rules": 0, "fw_gui_only": 0, "log_level": "Info"}
{"alt_dns1": "208.67.222.222", "alt_dns2": "208.67.220.220", "firewall": 0, "autoconnect": 0, "minimize": 0, "minimize_on_close": 0, "ipv6_disable": 0, "alt_dns": 0, "bypass": 0, "ping": 0, "auto_update": 0, "block_lan": 0, "preserve_rules": 0, "fw_gui_only": 0, "log_level": "Info"}