ClientManager._get_standard_path → Backend.getPath

This commit is contained in:
miruka 2019-05-06 21:28:54 -04:00
parent eab5ae0afe
commit a3d0f32dc5
3 changed files with 26 additions and 25 deletions

View File

@ -45,7 +45,6 @@
- Make links in room subtitle clickable, formatting?
- `<pre>` scrollbar on overflow
- Handle cases where an avatar char is # or @ (#alias room, @user\_id)
- Proper logoff when closing client
- When inviting someone to direct chat, room is "Empty room" until accepted,
it should be the peer's display name instead.
- Keep an accounts order

View File

@ -1,10 +1,12 @@
# Copyright 2019 miruka
# This file is part of harmonyqml, licensed under GPLv3.
import os
from concurrent.futures import ThreadPoolExecutor
from typing import Deque, Dict, Sequence, Set
from typing import Deque, Dict, Optional, Sequence, Set
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSlot
from atomicfile import AtomicFile
from PyQt5.QtCore import QObject, QStandardPaths, pyqtProperty, pyqtSlot
from .html_filter import HtmlFilter
from .model import ListModel, ListModelMap
@ -105,6 +107,27 @@ class Backend(QObject):
break
@staticmethod
def getPath(kind: QStandardPaths.StandardLocation,
file: str,
initial_content: Optional[str] = None) -> str:
relative_path = file.replace("/", os.sep)
path = QStandardPaths.locate(kind, relative_path)
if path:
return path
base_dir = QStandardPaths.writableLocation(kind)
path = f"{base_dir}{os.sep}{relative_path}"
os.makedirs(os.path.split(path)[0], exist_ok=True)
if initial_content is not None:
with AtomicFile(path, "w") as new:
new.write(initial_content)
return path
@pyqtSlot()
@pyqtSlot(list)
def pdb(self, additional_data: Sequence = ()) -> None:

View File

@ -117,29 +117,8 @@ class ClientManager(QObject, Mapping, metaclass=_ClientManagerMeta):
# Standard file paths
@staticmethod
def _get_standard_path(kind: QStandardPaths.StandardLocation,
file: str,
initial_content: Optional[str] = None) -> str:
relative_path = file.replace("/", os.sep)
path = QStandardPaths.locate(kind, relative_path)
if path:
return path
base_dir = QStandardPaths.writableLocation(kind)
path = f"{base_dir}{os.sep}{relative_path}"
os.makedirs(os.path.split(path)[0], exist_ok=True)
if initial_content is not None:
with AtomicFile(path, "w") as new:
new.write(initial_content)
return path
def getAccountConfigPath(self) -> str:
return self._get_standard_path(
return self.backend.getPath(
QStandardPaths.AppConfigLocation, "accounts.json", "[]"
)