Skip to content

Commit

Permalink
Add basic DI and ImapProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Maksimov committed Nov 17, 2023
1 parent 525ad07 commit ecc2d64
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"--share=ipc",
"--socket=fallback-x11",
"--device=dri",
"--socket=wayland"
"--socket=wayland",
"--talk-name=org.gnome.OnlineAccounts",
"--talk-name=org.gnome.ControlCenter",
"--talk-name=org.gnome.Settings"
],
"cleanup" : [
"/include",
Expand All @@ -23,6 +26,9 @@
"*.a"
],
"modules" : [
"python3-inject.json",
"gnome-online-accounts.json",
"python3-imapclient.json",
{
"name" : "bureau",
"builddir" : true,
Expand Down
20 changes: 20 additions & 0 deletions build-aux/gnome-online-accounts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "gnome-online-accounts",
"buildsystem": "meson",
"config-opts": [
"-Dgoabackend=false",
"-Dvapi=false",
"-Dexchange=false",
"-Dgoogle=false",
"-Dimap_smtp=false",
"-Dkerberos=false",
"-Downcloud=false",
"-Dwindows_live=false"
],
"sources": [
{
"type": "git",
"url": "https://gitlab.gnome.org/GNOME/gnome-online-accounts.git"
}
]
}
14 changes: 14 additions & 0 deletions build-aux/python3-imapclient.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "python3-imapclient",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"imapclient\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/c6/74/11a144d35e0f36e34aa09c61847c54894b143f3700c26d9fe85d2c8632b2/IMAPClient-3.0.0-py2.py3-none-any.whl",
"sha256": "31ec03da31f82fb380fdc0c79a9c31272789b50680285ade6581338c17ad8bf3"
}
]
}
14 changes: 14 additions & 0 deletions build-aux/python3-inject.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "python3-inject",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"inject\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/0a/d4/b812b4e7d826ce0d6ec38f03080a0118d68879ba06454275f410a02f3f21/inject-5.1.0-py2.py3-none-any.whl",
"sha256": "2375e4b3852eb9243e4f736c7c3a9ec723ad8765a23d16cb1e89c0ea425e1433"
}
]
}
9 changes: 9 additions & 0 deletions bureau/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
import sys

import gi
import inject

from bureau.providers.imap import ImapProvider

gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
gi.require_version('Goa', '1.0')

from gi.repository import Gio, Adw
from .window import BureauWindow
Expand All @@ -44,10 +48,15 @@ def __init__(self, version: str):

self.version = version

inject.configure(self.configure_providers)

self.create_action('quit', lambda *_: self.quit(), ['<primary>q'])
self.create_action('about', self.on_about_action)
self.create_action('preferences', self.on_preferences_action)

def configure_providers(self, binder: inject.Binder):
binder.bind(ImapProvider, ImapProvider('imap.yandex.ru'))

def do_activate(self):
"""Called when the application is activated.
Expand Down
Empty file added bureau/providers/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions bureau/providers/imap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from gi.repository import GObject
from imapclient import IMAPClient


class ImapProvider(GObject.GObject):
__gtype_name__ = "ImapProvider"

server: IMAPClient

# Props

# Signals
__gsignals__ = {
}

def __init__(self, server_host: str):
super().__init__()

self.server = IMAPClient(server_host, use_uid=True)

def login(self, username: str, password: str):
self.server.login(username, password)

def list_folders(self, directory: str = '', pattern: str = '*'):
if not self.server:
return

folders = self.server.list_folders(directory, pattern)
print('FOLDERS:')
print(folders)
22 changes: 20 additions & 2 deletions bureau/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
# SOFTWARE.
#
# SPDX-License-Identifier: MIT

import inject
from gi.repository import Adw
from gi.repository import Goa
from gi.repository import Gtk

from bureau.content_page import ContentPage
from bureau.providers.imap import ImapProvider


@Gtk.Template(resource_path='/com/tenderowl/bureau/ui/window.ui')
Expand All @@ -34,5 +36,21 @@ class BureauWindow(Adw.ApplicationWindow):

content_page: ContentPage = Gtk.Template.Child()

def __init__(self, **kwargs):
@inject.autoparams()
def __init__(self, imap_provider: ImapProvider, **kwargs):
super().__init__(**kwargs)

email_addresses = []

goa: Goa.Client = Goa.Client.new_sync(None)
accs = goa.get_accounts()
for acc in accs:
mail_proxy = acc.props.mail
if mail_proxy:
email_address = mail_proxy.props.email_address
if email_address:
email_addresses.append(email_address)

print(email_addresses)

print(imap_provider)

0 comments on commit ecc2d64

Please sign in to comment.