mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 06:32:53 +01:00
feat: add by id or ip WIP
This commit is contained in:
1 parent
decc1f636c
commit
42544c6dcc
2 files changed
+67
-12
No files matched your search
+52
-11
@@ -15,7 +15,7 @@ import dzgui.api.pefile as PeFile
|
|||||||
import dzgui.api.servers as Servers
|
import dzgui.api.servers as Servers
|
||||||
import dzgui.util._json as JSON # noqa
|
import dzgui.util._json as JSON # noqa
|
||||||
|
|
||||||
from dzgui.api.probe import test_steam_api, test_bm_api
|
from dzgui.api.bm import map_id_to_record
|
||||||
from dzgui.api.mods import (
|
from dzgui.api.mods import (
|
||||||
get_delimited_mods,
|
get_delimited_mods,
|
||||||
get_local_mod_path,
|
get_local_mod_path,
|
||||||
@@ -23,14 +23,7 @@ from dzgui.api.mods import (
|
|||||||
_hash,
|
_hash,
|
||||||
remove_stale_signatures,
|
remove_stale_signatures,
|
||||||
)
|
)
|
||||||
from dzgui.const.enum import (
|
from dzgui.api.probe import test_steam_api, test_bm_api
|
||||||
FilterMode,
|
|
||||||
Preferences,
|
|
||||||
NotebookPage,
|
|
||||||
ButtonType,
|
|
||||||
ContextMenu,
|
|
||||||
)
|
|
||||||
|
|
||||||
from dzgui.const.constants import (
|
from dzgui.const.constants import (
|
||||||
APPID_DAYZ,
|
APPID_DAYZ,
|
||||||
APPID_DAYZ_EXP,
|
APPID_DAYZ_EXP,
|
||||||
@@ -38,6 +31,13 @@ from dzgui.const.constants import (
|
|||||||
WINDOW_DEFAULT_X,
|
WINDOW_DEFAULT_X,
|
||||||
WINDOW_DEFAULT_Y,
|
WINDOW_DEFAULT_Y,
|
||||||
)
|
)
|
||||||
|
from dzgui.const.enum import (
|
||||||
|
FilterMode,
|
||||||
|
Preferences,
|
||||||
|
NotebookPage,
|
||||||
|
ButtonType,
|
||||||
|
ContextMenu,
|
||||||
|
)
|
||||||
|
|
||||||
from dzgui.config import update
|
from dzgui.config import update
|
||||||
from dzgui.config.query import lookup
|
from dzgui.config.query import lookup
|
||||||
@@ -460,6 +460,43 @@ class Controller(GObject.GObject):
|
|||||||
parsed = Servers.parse_json(serv)
|
parsed = Servers.parse_json(serv)
|
||||||
self.push_data_success(parsed, FilterMode.INITIAL)
|
self.push_data_success(parsed, FilterMode.INITIAL)
|
||||||
|
|
||||||
|
def query_ip_id(self, addr: str) -> None:
|
||||||
|
# NOTE: Battlemetrics
|
||||||
|
if addr.isdigit():
|
||||||
|
config = self.prefs.paths.config
|
||||||
|
resolved = map_id_to_record(config, addr)
|
||||||
|
res = Servers.query_direct(resolved.ip, resolved.qport)
|
||||||
|
else:
|
||||||
|
record = addr.split(":")
|
||||||
|
ip, qport = record[0], record[1]
|
||||||
|
res = Servers.query_direct(ip, int(qport))
|
||||||
|
return res
|
||||||
|
|
||||||
|
# TODO: strings
|
||||||
|
@call_on_thread("querying address")
|
||||||
|
def connect_by_id_or_ip(self, addr: str) -> None:
|
||||||
|
res = self.query_ip_id(addr)
|
||||||
|
|
||||||
|
def cleanup_on_insert(self) -> None:
|
||||||
|
print(self.get_cleanup_func())
|
||||||
|
treeview = self.get_active_treeview()
|
||||||
|
# TODO; update control model in filtered_model
|
||||||
|
model = treeview.get_model().append(self.insert_record[0])
|
||||||
|
|
||||||
|
@call_on_thread("querying address")
|
||||||
|
def add_by_id_or_ip(self, addr: str) -> None:
|
||||||
|
res = self.query_ip_id(addr)
|
||||||
|
self.insert_record = Servers.parse_json([res])
|
||||||
|
#if res is None:
|
||||||
|
# # TODO: set cleanupfunc with dialog
|
||||||
|
# return
|
||||||
|
# TODO: add into saved servers file
|
||||||
|
# TODO: update saved servers model
|
||||||
|
# if current focus is not save servers, update label
|
||||||
|
# TODO: add ip here
|
||||||
|
self.set_cleanup_func(StoredFunc(lambda: self.cleanup_on_insert()))
|
||||||
|
|
||||||
|
|
||||||
def dump_api(self) -> None:
|
def dump_api(self) -> None:
|
||||||
key = self.query_config(Preferences.STEAM)
|
key = self.query_config(Preferences.STEAM)
|
||||||
job = Servers.query_api
|
job = Servers.query_api
|
||||||
@@ -749,7 +786,7 @@ class Controller(GObject.GObject):
|
|||||||
# CHORE: test if treeview's sort method inserts row at the correct index
|
# CHORE: test if treeview's sort method inserts row at the correct index
|
||||||
# inserting a row serializes file on disk, updates control model for that tab, and
|
# inserting a row serializes file on disk, updates control model for that tab, and
|
||||||
# reapplies filters to ephemeral model; since filters are applied, in-situ insertion might not be necessary
|
# reapplies filters to ephemeral model; since filters are applied, in-situ insertion might not be necessary
|
||||||
self.to_insert.connect("row-inserted", lambda: print("row inserted into model"))
|
self.to_insert.connect("row-inserted", lambda *args: print("row inserted into model"))
|
||||||
|
|
||||||
# TODO: signals or other approach to deferring map
|
# TODO: signals or other approach to deferring map
|
||||||
# model insertion after thread closes
|
# model insertion after thread closes
|
||||||
@@ -833,6 +870,9 @@ class Controller(GObject.GObject):
|
|||||||
stale = find_stale_mods(self.prefs.paths.config)
|
stale = find_stale_mods(self.prefs.paths.config)
|
||||||
self.cleanup_func = StoredFunc(self.highlight_stale_cleanup, stale)
|
self.cleanup_func = StoredFunc(self.highlight_stale_cleanup, stale)
|
||||||
|
|
||||||
|
def set_cleanup_func(self, func: StoredFunc) -> None:
|
||||||
|
self.cleanup_func = func
|
||||||
|
|
||||||
def get_cleanup_func(self) -> StoredFunc:
|
def get_cleanup_func(self) -> StoredFunc:
|
||||||
return self.cleanup_func
|
return self.cleanup_func
|
||||||
|
|
||||||
@@ -841,7 +881,7 @@ class Controller(GObject.GObject):
|
|||||||
func = self.get_cleanup_func()
|
func = self.get_cleanup_func()
|
||||||
if func is not None:
|
if func is not None:
|
||||||
func.call()
|
func.call()
|
||||||
self.cleanup_func = None
|
self.set_cleanup_func(None)
|
||||||
self.mediator.window.set_sensitive(True)
|
self.mediator.window.set_sensitive(True)
|
||||||
|
|
||||||
def dump_diagnostics(self) -> None:
|
def dump_diagnostics(self) -> None:
|
||||||
@@ -922,6 +962,7 @@ class Controller(GObject.GObject):
|
|||||||
) -> None:
|
) -> None:
|
||||||
filter_man.filter(mode, label)
|
filter_man.filter(mode, label)
|
||||||
self.to_insert = filter_man.get_model()
|
self.to_insert = filter_man.get_model()
|
||||||
|
print("filtering threaded")
|
||||||
self.cleanup_func = StoredFunc(self.cleanup_on_success)
|
self.cleanup_func = StoredFunc(self.cleanup_on_success)
|
||||||
|
|
||||||
# TODO: call filter_man methods directly
|
# TODO: call filter_man methods directly
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class LanPanel(Gtk.Frame):
|
|||||||
self.scan = Gtk.Button(label=lan_panel.scan_button)
|
self.scan = Gtk.Button(label=lan_panel.scan_button)
|
||||||
self.scan.connect("clicked", self._on_scan_clicked)
|
self.scan.connect("clicked", self._on_scan_clicked)
|
||||||
# TODO: strings
|
# TODO: strings
|
||||||
self.early_abort = Gtk.CheckButton("Stop scanning on first hit")
|
self.early_abort = Gtk.CheckButton(label="Stop scanning on first hit")
|
||||||
self.early_abort.set_active(True)
|
self.early_abort.set_active(True)
|
||||||
self.early_abort.set_tooltip_text(
|
self.early_abort.set_tooltip_text(
|
||||||
"Unless you have multiple DayZ servers on your LAN,\nleave this checked to get results faster"
|
"Unless you have multiple DayZ servers on your LAN,\nleave this checked to get results faster"
|
||||||
@@ -153,11 +153,14 @@ class AddPanel(Gtk.Frame):
|
|||||||
self.set_label_widget(label)
|
self.set_label_widget(label)
|
||||||
|
|
||||||
self.add_server = AddButton()
|
self.add_server = AddButton()
|
||||||
|
self.add_server.connect("clicked", self._on_add_clicked)
|
||||||
|
|
||||||
self.conn_server = SteamConnectButton()
|
self.conn_server = SteamConnectButton()
|
||||||
self.conn_server.set_sensitive(False)
|
self.conn_server.set_sensitive(False)
|
||||||
self.add_server.set_sensitive(False)
|
self.add_server.set_sensitive(False)
|
||||||
|
|
||||||
self.entry = IpEntry(controller)
|
self.entry = IpEntry(controller)
|
||||||
|
self.entry.connect("activate", self._on_activate)
|
||||||
self.entry.connect("string_validated", self._on_ip_validated)
|
self.entry.connect("string_validated", self._on_ip_validated)
|
||||||
self.emitter.connect(
|
self.emitter.connect(
|
||||||
"request_ip_entry_focus", lambda _: self.entry.grab_focus()
|
"request_ip_entry_focus", lambda _: self.entry.grab_focus()
|
||||||
@@ -174,6 +177,17 @@ class AddPanel(Gtk.Frame):
|
|||||||
|
|
||||||
self.add(self.grid)
|
self.add(self.grid)
|
||||||
|
|
||||||
|
def _submit_query(self) -> None:
|
||||||
|
text = self.entry.get_text()
|
||||||
|
self.controller.add_by_id_or_ip(text)
|
||||||
|
|
||||||
|
def _on_activate(self, entry: Gtk.Entry) -> None:
|
||||||
|
self._submit_query()
|
||||||
|
|
||||||
|
def _on_add_clicked(self, button: Gtk.Button) -> None:
|
||||||
|
self._submit_query()
|
||||||
|
|
||||||
|
|
||||||
def _on_ip_validated(self, entry: Gtk.Entry, state: bool) -> None:
|
def _on_ip_validated(self, entry: Gtk.Entry, state: bool) -> None:
|
||||||
self.conn_server.set_sensitive(state)
|
self.conn_server.set_sensitive(state)
|
||||||
self.add_server.set_sensitive(state)
|
self.add_server.set_sensitive(state)
|
||||||
|
|||||||
Reference in new issue
Block a user