mirror of
https://github.com/aclist/dztui.git
synced 2026-11-01 07:32:44 +01:00
feat: restore partial context menu functionality
This commit is contained in:
1 parent
5ae18485e8
commit
575e591c10
10 files changed
+68
-33
No files matched your search
+3
-4
@@ -13,10 +13,9 @@ if TYPE_CHECKING:
|
|||||||
from dzgui.api.servers import Record
|
from dzgui.api.servers import Record
|
||||||
|
|
||||||
|
|
||||||
def get_attributes(config: Path, uid: int) -> str:
|
def get_attributes(key: str, uid: int) -> str:
|
||||||
# TODO: handle if key is not set
|
# TODO: handle if key is not set
|
||||||
# TODO: tests for malformed IDs/values
|
# TODO: tests for malformed IDs/values
|
||||||
key = lookup(config, Preferences.BM)
|
|
||||||
|
|
||||||
hdr = {"Authorization": "Bearer " + key}
|
hdr = {"Authorization": "Bearer " + key}
|
||||||
payload: dict[str, str] = {
|
payload: dict[str, str] = {
|
||||||
@@ -30,11 +29,11 @@ def get_attributes(config: Path, uid: int) -> str:
|
|||||||
return j
|
return j
|
||||||
|
|
||||||
|
|
||||||
def map_id_to_record(config: Path, uid: int) -> Optional["Record"]:
|
def map_id_to_record(key: str, uid: int) -> Optional["Record"]:
|
||||||
from dzgui.api.servers import Record
|
from dzgui.api.servers import Record
|
||||||
|
|
||||||
try:
|
try:
|
||||||
record = get_attributes(config, uid)
|
record = get_attributes(key, uid)
|
||||||
ip = record["ip"]
|
ip = record["ip"]
|
||||||
port = record["port"]
|
port = record["port"]
|
||||||
qport = record["portQuery"]
|
qport = record["portQuery"]
|
||||||
|
|||||||
@@ -461,18 +461,18 @@ def response_to_fq_ip(res: dict) -> str:
|
|||||||
return f"{ip}:{gameport}:{qport}"
|
return f"{ip}:{gameport}:{qport}"
|
||||||
|
|
||||||
|
|
||||||
def query_id_or_ip(addr: str) -> None:
|
def query_id_or_ip(addr: str, key: str) -> None:
|
||||||
# NOTE: Battlemetrics
|
# NOTE: Battlemetrics
|
||||||
if addr.isdigit():
|
if addr.isdigit():
|
||||||
try:
|
try:
|
||||||
config = self.controller.get_prefs().paths.config
|
resolved = map_id_to_record(key, addr)
|
||||||
resolved = map_id_to_record(config, addr)
|
|
||||||
res = query_direct(resolved.ip, resolved.qport)
|
res = query_direct(resolved.ip, resolved.qport)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical(e)
|
logger.critical(e)
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
record = addr.split(":")
|
record = addr.split(":")
|
||||||
ip, qport = record[0], record[1]
|
# TODO: create a Record object
|
||||||
|
ip, qport = record[0], record[2]
|
||||||
res = query_direct(ip, int(qport))
|
res = query_direct(ip, int(qport))
|
||||||
return res
|
return res
|
||||||
@@ -605,8 +605,8 @@ class Controller(GObject.GObject):
|
|||||||
record = treeview.get_record_string()
|
record = treeview.get_record_string()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.update_config(Preferences.FAV_LBL, name)
|
self.config_man.write_config(Preferences.FAV_LBL, name)
|
||||||
self.update_config(Preferences.FAV_SRV, record)
|
self.config_man.write_config(Preferences.FAV_SRV, record)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical(e)
|
logger.critical(e)
|
||||||
# TODO: add a failure dialog here
|
# TODO: add a failure dialog here
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ class ConnectionManager:
|
|||||||
self.thread_man = ThreadingManager(parent=controller)
|
self.thread_man = ThreadingManager(parent=controller)
|
||||||
|
|
||||||
@call_on_thread(dialog.querying)
|
@call_on_thread(dialog.querying)
|
||||||
def _connect_by_id_or_ip(self, addr: str) -> None:
|
def connect_by_id_or_ip(self, addr: str, key: str) -> None:
|
||||||
res = Servers.query_id_or_ip(addr)
|
res = Servers.query_id_or_ip(addr, key)
|
||||||
|
print(res)
|
||||||
if res is None:
|
if res is None:
|
||||||
self.thread_man.set_cleanup_func(StoredFunc(self._connection_failure))
|
self.thread_man.set_cleanup_func(StoredFunc(self._connection_failure))
|
||||||
# TODO: add to history if successful
|
# TODO: add to history if successful
|
||||||
print(res)
|
|
||||||
|
|
||||||
def _connection_failure(self) -> None:
|
def _connection_failure(self) -> None:
|
||||||
# TODO: more explicit warning message, not necessarily API failure?
|
# TODO: more explicit warning message, not necessarily API failure?
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ import logging
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from dzgui.const.enum import ContextMenu, Preferences
|
from dzgui.const.enum import ContextMenu, Preferences
|
||||||
|
from dzgui.managers.connection import ConnectionManager
|
||||||
from dzgui.managers.thread_man import ThreadingManager
|
from dzgui.managers.thread_man import ThreadingManager
|
||||||
|
from dzgui.model.servers import ServerModelManager
|
||||||
from dzgui.util import strings
|
from dzgui.util import strings
|
||||||
from dzgui.util.clip import copy_clipboard
|
from dzgui.util.clip import copy_clipboard
|
||||||
from dzgui.util.open_links import open_workshop_page
|
from dzgui.util.open_links import open_workshop_page
|
||||||
@@ -50,7 +52,16 @@ class ContextMenuManager:
|
|||||||
self.controller.set_fav()
|
self.controller.set_fav()
|
||||||
|
|
||||||
# THREADED
|
# THREADED
|
||||||
|
case ContextMenu.CONNECT:
|
||||||
|
record = self.treeview.get_record_string()
|
||||||
|
# FIXME: context menu connections do not require BM key
|
||||||
|
key = self.controller.get_config_man().lookup(Preferences.BM)
|
||||||
|
ConnectionManager(self.controller).connect_by_id_or_ip(record, key)
|
||||||
case ContextMenu.ADD_SERVER:
|
case ContextMenu.ADD_SERVER:
|
||||||
|
record = self.treeview.get_record_string()
|
||||||
|
ServerModelManager(self.controller, self.treeview).add_by_id_or_ip(
|
||||||
|
record
|
||||||
|
)
|
||||||
# add to saved servers model verbatim and sort in place
|
# add to saved servers model verbatim and sort in place
|
||||||
# update tab with !
|
# update tab with !
|
||||||
# update config file with IP
|
# update config file with IP
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ class ServerModelManager:
|
|||||||
self._push_data(parsed, FilterMode.INITIAL)
|
self._push_data(parsed, FilterMode.INITIAL)
|
||||||
|
|
||||||
@call_on_thread(dialog.querying)
|
@call_on_thread(dialog.querying)
|
||||||
def _add_by_id_or_ip(self, addr: str) -> None:
|
def add_by_id_or_ip(self, addr: str) -> None:
|
||||||
res = Servers.query_id_or_ip(addr)
|
res = Servers.query_id_or_ip(addr)
|
||||||
if res is None:
|
if res is None:
|
||||||
self.thread_man.set_cleanup_func(StoredFunc(self._cleanup_on_failure))
|
self.thread_man.set_cleanup_func(StoredFunc(self._cleanup_on_failure))
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ class AddPanel(Gtk.Frame):
|
|||||||
|
|
||||||
def _on_connect_clicked(self, button: Gtk.Button) -> None:
|
def _on_connect_clicked(self, button: Gtk.Button) -> None:
|
||||||
text = self.entry.get_text()
|
text = self.entry.get_text()
|
||||||
ConnectionManager(self.controller)._connect_by_id_or_ip(text)
|
ConnectionManager(self.controller).connect_by_id_or_ip(text)
|
||||||
|
|
||||||
def _submit_query(self) -> None:
|
def _submit_query(self) -> None:
|
||||||
text = self.entry.get_text()
|
text = self.entry.get_text()
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ class ContextMixin(TreeView):
|
|||||||
event: Gdk.EventButton | Gdk.EventKey,
|
event: Gdk.EventButton | Gdk.EventKey,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
# FIXME: start debug log focused
|
|
||||||
if self.is_selection_empty():
|
if self.is_selection_empty():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -80,7 +79,15 @@ class ContextMixin(TreeView):
|
|||||||
(path, col, cellx, celly) = pathinfo
|
(path, col, cellx, celly) = pathinfo
|
||||||
if path is None:
|
if path is None:
|
||||||
return True
|
return True
|
||||||
self.set_cursor(path, col, False)
|
# return True
|
||||||
|
selection = self.get_selection()
|
||||||
|
model, selected_paths = selection.get_selected_rows()
|
||||||
|
if path not in selected_paths:
|
||||||
|
for p in selected_paths:
|
||||||
|
selection.unselect_path(p)
|
||||||
|
self.set_cursor(path, col, False)
|
||||||
|
return True
|
||||||
|
# FIXME: if selection is not multiple, change cursor
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -40,13 +40,25 @@ class LogTreeView(ContextMixin, TreeView):
|
|||||||
column.set_sort_column_id(i)
|
column.set_sort_column_id(i)
|
||||||
self.append_column(column)
|
self.append_column(column)
|
||||||
|
|
||||||
|
self.connect("button-press-event", self._on_log_buttonpress)
|
||||||
self.connect("key-press-event", self._on_log_keypress)
|
self.connect("key-press-event", self._on_log_keypress)
|
||||||
self.connect("button-press-event", self._on_log_keypress)
|
|
||||||
|
|
||||||
def populate_log(self, filepath: str) -> None:
|
def populate_log(self, filepath: str) -> None:
|
||||||
model = ModelFactory().new_model_from_logfile(filepath)
|
model = ModelFactory().new_model_from_logfile(filepath)
|
||||||
self.set_model(model)
|
self.set_model(model)
|
||||||
self.set_cursor(0)
|
self.set_cursor(0)
|
||||||
|
|
||||||
|
def _on_log_buttonpress(self, widget: Gtk.Widget, event: Gdk.EventButton) -> None:
|
||||||
|
if event.button == Gdk.BUTTON_SECONDARY:
|
||||||
|
path, col, x, y = self.get_path_at_pos(int(event.x), int(event.y))
|
||||||
|
if path:
|
||||||
|
selection = self.get_selection()
|
||||||
|
model, selected_paths = selection.get_selected_rows()
|
||||||
|
if path not in selected_paths:
|
||||||
|
selection.select_path(path)
|
||||||
|
self.present_menu(widget, event)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def _on_log_keypress(self, widget: Gtk.Widget, event: Gdk.EventKey) -> None:
|
def _on_log_keypress(self, widget: Gtk.Widget, event: Gdk.EventKey) -> None:
|
||||||
self.present_menu(widget, event)
|
self.present_menu(widget, event)
|
||||||
@@ -256,22 +256,28 @@ class ServerTreeView(ContextMixin, TreeView):
|
|||||||
self.emitter.emit("check_button_pressed", event.keyval)
|
self.emitter.emit("check_button_pressed", event.keyval)
|
||||||
|
|
||||||
# TODO: unimplemented
|
# TODO: unimplemented
|
||||||
# def is_modded(self) -> bool:
|
def is_modded(self) -> bool:
|
||||||
# select = self.get_selection()
|
select = self.get_selection()
|
||||||
# sels = select.get_selected_rows()
|
sels = select.get_selected_rows()
|
||||||
# (model, pathlist) = sels
|
(model, pathlist) = sels
|
||||||
# path = pathlist[0]
|
path = pathlist[0]
|
||||||
# tree_iter = model.get_iter(path)
|
tree_iter = model.get_iter(path)
|
||||||
# mods = model.get_value(tree_iter, 11)
|
has_mods = model.get_value(tree_iter, 11)
|
||||||
# return mods
|
return has_mods
|
||||||
|
|
||||||
# TODO: unimplemented
|
def get_selected_row(self) -> Gtk.TreeModelRow:
|
||||||
# def is_in_favs(self) -> bool:
|
sel = self.get_selection()
|
||||||
# record = self.get_record_string()
|
sels = sel.get_selected_rows()
|
||||||
# proc = call_out("is_in_favs", record)
|
return sels[0]
|
||||||
# if proc.returncode == 0:
|
|
||||||
# return True
|
def is_in_favs(self) -> bool:
|
||||||
# return False
|
from dzgui.const.enum import Preferences
|
||||||
|
|
||||||
|
record = self.get_record_string()
|
||||||
|
ips = self.controller.get_config_man().lookup(Preferences.IP_LIST)
|
||||||
|
if record in ips:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def _parent_row_activated(
|
def _parent_row_activated(
|
||||||
self, tree: TreeView, path: Gtk.TreePath, column: Gtk.TreeViewColumn
|
self, tree: TreeView, path: Gtk.TreePath, column: Gtk.TreeViewColumn
|
||||||
|
|||||||
Reference in new issue
Block a user