ClientManager._get_standard_path → Backend.getPath
This commit is contained in:
parent
eab5ae0afe
commit
a3d0f32dc5
1
TODO.md
1
TODO.md
|
@ -45,7 +45,6 @@
|
||||||
- Make links in room subtitle clickable, formatting?
|
- Make links in room subtitle clickable, formatting?
|
||||||
- `<pre>` scrollbar on overflow
|
- `<pre>` scrollbar on overflow
|
||||||
- Handle cases where an avatar char is # or @ (#alias room, @user\_id)
|
- 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,
|
- When inviting someone to direct chat, room is "Empty room" until accepted,
|
||||||
it should be the peer's display name instead.
|
it should be the peer's display name instead.
|
||||||
- Keep an accounts order
|
- Keep an accounts order
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
# Copyright 2019 miruka
|
# Copyright 2019 miruka
|
||||||
# This file is part of harmonyqml, licensed under GPLv3.
|
# This file is part of harmonyqml, licensed under GPLv3.
|
||||||
|
|
||||||
|
import os
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
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 .html_filter import HtmlFilter
|
||||||
from .model import ListModel, ListModelMap
|
from .model import ListModel, ListModelMap
|
||||||
|
@ -105,6 +107,27 @@ class Backend(QObject):
|
||||||
break
|
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()
|
||||||
@pyqtSlot(list)
|
@pyqtSlot(list)
|
||||||
def pdb(self, additional_data: Sequence = ()) -> None:
|
def pdb(self, additional_data: Sequence = ()) -> None:
|
||||||
|
|
|
@ -117,29 +117,8 @@ class ClientManager(QObject, Mapping, metaclass=_ClientManagerMeta):
|
||||||
|
|
||||||
# Standard file paths
|
# 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:
|
def getAccountConfigPath(self) -> str:
|
||||||
return self._get_standard_path(
|
return self.backend.getPath(
|
||||||
QStandardPaths.AppConfigLocation, "accounts.json", "[]"
|
QStandardPaths.AppConfigLocation, "accounts.json", "[]"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user