Commit d57b49ba authored by Cédric Bellegarde's avatar Cédric Bellegarde

Load profiles from disk

parent a67985ce
......@@ -23,6 +23,7 @@ from pickle import dump, load
from urllib.parse import urlparse
from getpass import getuser
from time import time
import json
from eolie.settings import Settings, SettingsDialog
from eolie.window import Window
......@@ -40,6 +41,7 @@ from eolie.menu_pages import PagesMenu
from eolie.helper_dbus import DBusHelper
from eolie.helper_task import TaskHelper
from eolie.define import EOLIE_DATA_PATH, TimeSpan, TimeSpanValues, LoadingType
from eolie.define import PROFILES
from eolie.utils import is_unity, wanted_loading_type
......@@ -216,6 +218,26 @@ class Application(Gtk.Application):
self.__unity.set_property("progress", fraction)
self.__unity.set_property("progress_visible", fraction != 1.0)
def set_profiles(self):
"""
Set profiles
"""
try:
f = Gio.File.new_for_path(EOLIE_DATA_PATH + "/profiles.json")
if f.query_exists():
(status, contents, tag) = f.load_contents(None)
self.__profiles = json.loads(contents.decode("utf-8"))
else:
content = json.dumps(PROFILES)
f.replace_contents(content.encode("utf-8"),
None,
False,
Gio.FileCreateFlags.REPLACE_DESTINATION,
None)
self.__profiles = PROFILES
except Exception as e:
print("Application::set_profiles():", e)
def quit(self, vacuum=False):
"""
Quit application
......@@ -244,6 +266,14 @@ class Application(Gtk.Application):
else:
Gio.Application.quit(self)
@property
def profiles(self):
"""
Get profiles
@return {}
"""
return self.__profiles
@property
def start_page(self):
"""
......@@ -382,19 +412,7 @@ class Application(Gtk.Application):
pass
# Init profiles
f = Gio.File.new_for_path(EOLIE_DATA_PATH + "/profiles.json")
if not f.query_exists():
try:
import json
from eolie.define import PROFILES
content = json.dumps(PROFILES)
f.replace_contents(content.encode("utf-8"),
None,
False,
Gio.FileCreateFlags.REPLACE_DESTINATION,
None)
except Exception as e:
print("Application::__init():", e)
self.set_profiles()
shortcut_action = Gio.SimpleAction.new('shortcut',
GLib.VariantType.new('s'))
......
......@@ -227,14 +227,15 @@ class CookiesDialog:
request = "DELETE FROM moz_cookies WHERE "
filters = ()
for row in rows:
request += "host=? AND "
request += "host=? OR "
filters += (row.item.name,)
request += " 1"
request += " 0"
sql = sqlite3.connect(path, 600.0)
sql.execute(request, filters)
sql.commit()
except Exception as e:
print("CookiesDialog::_on_dialog_response():", e)
El().set_profiles()
def _on_entry_changed(self, entry):
"""
......@@ -361,12 +362,7 @@ class CookiesDialog:
"""
# Load user profiles
try:
f = Gio.File.new_for_path(EOLIE_DATA_PATH +
"/profiles.json")
if f.query_exists():
(status, contents, tag) = f.load_contents(None)
profiles = json.loads(contents.decode("utf-8"))
self.__add_profiles(profiles)
self.__add_profiles(El().profiles)
except Exception as e:
print("DialogSearchEngine::__populate():", e)
......
......@@ -18,7 +18,7 @@ import cairo
from random import choice
from base64 import b64encode
from eolie.define import El, ArtSize, LoadingType, PROFILES
from eolie.define import El, ArtSize, LoadingType
def name_from_profile_id(id):
......@@ -27,8 +27,8 @@ def name_from_profile_id(id):
@param id as str
@return str
"""
if id in PROFILES.keys() and id != "default":
return "%s> " % PROFILES[id]
if id in El().profiles.keys() and id != "default":
return "%s> " % El().profiles[id]
else:
return ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment