Commit 325b8c04 authored by Cédric Bellegarde's avatar Cédric Bellegarde

Remove profiles code. Will reimplement this if WebKitGTK provides an API for this

parent 1b4d1cbd
Pipeline #58269 passed with stage
in 9 minutes and 52 seconds
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.1 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.16"/>
<object class="GtkDialog" id="dialog">
......@@ -12,6 +12,32 @@
<action-widgets>
<action-widget response="-5">delete_button</action-widget>
</action-widgets>
<child type="titlebar">
<object class="GtkHeaderBar" id="headerbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Cookies manager</property>
<property name="show_close_button">True</property>
<child>
<object class="GtkButton" id="delete_button">
<property name="label" translatable="yes">Delete cookies</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="valign">center</property>
<property name="use_underline">True</property>
<style>
<class name="text-button"/>
<class name="destructive-action"/>
</style>
</object>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
......@@ -45,112 +71,7 @@
<property name="margin_bottom">5</property>
<property name="spacing">5</property>
<child>
<object class="GtkBox" id="box">
<property name="visible">False</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkListBox" id="profiles">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="row-selected" handler="_on_profile_selected" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="placeholder_text" translatable="yes">New profile</property>
<signal name="changed" handler="_on_entry_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="add_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="_on_add_button_clicked" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-add-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="remove_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="_on_remove_button_clicked" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-remove-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<style>
<class name="linked"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
<placeholder/>
</child>
<child>
<object class="GtkBox" id="cookies_box">
......@@ -220,31 +141,5 @@
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar" id="headerbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Profiles manager</property>
<property name="show_close_button">True</property>
<child>
<object class="GtkButton" id="delete_button">
<property name="label" translatable="yes">Delete cookies</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="valign">center</property>
<property name="use_underline">True</property>
<style>
<class name="text-button"/>
<class name="destructive-action"/>
</style>
</object>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</interface>
......@@ -24,7 +24,6 @@ from pickle import dump, load
from urllib.parse import urlparse
from time import time
from getpass import getuser
import json
from signal import signal, SIGINT, SIGTERM
from eolie.settings import Settings
......@@ -199,33 +198,6 @@ class Application(Gtk.Application):
if uri in self.__pinned:
self.__pinned.remove(uri)
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:
PROFILES = {"default": _("Default"),
"social": _("Social networks"),
"work": _("Work"),
"shopping": _("Shopping"),
"personal": _("Personal"),
"finance": _("Finance"),
"sport": _("Sport")}
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:
Logger.error("Application::set_profiles(): %s", e)
def quit(self, vacuum=False):
"""
Quit application
......@@ -264,14 +236,6 @@ class Application(Gtk.Application):
"""
return self.__pinned
@property
def profiles(self):
"""
Get profiles
@return {}
"""
return self.__profiles
@property
def start_page(self):
"""
......@@ -413,8 +377,6 @@ class Application(Gtk.Application):
except:
pass
# Init profiles
self.set_profiles()
# Init default context
Context(WebKit2.WebContext().get_default())
......
......@@ -10,27 +10,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gtk, GLib, GObject, Gio, Gdk
from gi.repository import Gtk, GLib, GObject, Gdk
import json
import sqlite3
from eolie.define import App, EOLIE_DATA_PATH, COOKIES_PATH
from eolie.define import EOLIE_DATA_PATH, COOKIES_PATH
from eolie.logger import Logger
class Profile(GObject.GObject):
name = GObject.Property(type=str,
default="")
profile = GObject.Property(type=str,
default="")
value = GObject.Property(type=str,
default="")
def __init__(self):
GObject.GObject.__init__(self)
class Cookie(GObject.GObject):
name = GObject.Property(type=str,
default="")
......@@ -176,10 +163,7 @@ class CookiesDialog:
self.__dialog = builder.get_object("dialog")
self.__dialog.set_transient_for(parent)
self.__entry = builder.get_object("entry")
self.__profiles = builder.get_object("profiles")
self.__cookies = builder.get_object("cookies")
self.__add_button = builder.get_object("add_button")
self.__remove_button = builder.get_object("remove_button")
self.__delete_button = builder.get_object("delete_button")
if self.__hide_cookies:
builder.get_object("cookies_box").hide()
......@@ -190,7 +174,6 @@ class CookiesDialog:
else:
self.__cookies.set_filter_func(self.__filter_func)
self.__dialog.set_size_request(600, 500)
self.__remove_button.set_sensitive(False)
builder.connect_signals(self)
def run(self):
......@@ -211,24 +194,10 @@ class CookiesDialog:
@param response_id as int
"""
try:
profiles = {}
for child in self.__profiles.get_children():
profile = child.item.get_property("profile")
name = child.item.get_property("name")
profiles[profile] = name
content = json.dumps(profiles)
f = Gio.File.new_for_path(EOLIE_DATA_PATH +
"/profiles.json")
f.replace_contents(content.encode("utf-8"),
None,
False,
Gio.FileCreateFlags.REPLACE_DESTINATION,
None)
if response_id != Gtk.ResponseType.DELETE_EVENT:
rows = self.__cookies.get_selected_rows()
row = self.__profiles.get_selected_row()
path = COOKIES_PATH % (EOLIE_DATA_PATH,
row.item.get_property("profile"))
"default")
request = "DELETE FROM moz_cookies WHERE "
filters = ()
for row in rows:
......@@ -240,7 +209,6 @@ class CookiesDialog:
sql.commit()
except Exception as e:
Logger.error("CookiesDialog::_on_dialog_response(): %s", e)
App().set_profiles()
def _on_entry_changed(self, entry):
"""
......@@ -248,51 +216,6 @@ class CookiesDialog:
"""
self.__add_button.set_sensitive(entry.get_text())
def _on_add_button_clicked(self, button):
"""
Add a new engine
@param button as Gtk.Button
"""
text = self.__entry.get_text()
self.__entry.set_text("")
# Only one New engine
for child in self.__profiles.get_children():
if child.item.name == text:
return
item = Profile()
item.set_property("name", text)
item.set_property("profile", GLib.uri_escape_string(text.lower(),
None,
True))
child = Row(item)
child.connect("moved", self.__on_moved)
child.show()
self.__profiles.add(child)
self.__profiles.select_row(child)
self.__remove_button.set_sensitive(True)
def _on_remove_button_clicked(self, button):
"""
Remove engine
@param button as Gtk.Button
"""
row = self.__profiles.get_selected_row()
if row is not None:
profile = row.item.get_property("profile")
App().websettings.remove_profile(profile)
try:
path = COOKIES_PATH % (EOLIE_DATA_PATH, profile)
f = Gio.File.new_for_path(path)
if f.query_exists():
f.trash()
except Exception as e:
Logger.error("""DialogSearchEngine::
_on_remove_button_clicked(): %s""", e)
row.destroy()
for child in self.__cookies.get_children():
GLib.idle_add(child.destroy)
def _on_search_changed(self, entry):
"""
Update filter
......@@ -313,29 +236,6 @@ class CookiesDialog:
listbox.unselect_row(row)
self.__delete_button.set_sensitive(rows)
def _on_profile_selected(self, listbox, row):
"""
Update cookies
@param listbox as Gtk.ListBox
@param row as Row
"""
if row is not None:
profile = row.item.get_property("profile")
self.__remove_button.set_sensitive(profile != "default")
if not self.__hide_cookies:
for child in self.__cookies.get_children():
GLib.idle_add(child.destroy)
self.__cookies.set_sensitive(True)
try:
path = COOKIES_PATH % (EOLIE_DATA_PATH, profile)
sql = sqlite3.connect(path, 600.0)
result = sql.execute("SELECT DISTINCT host, value\
FROM moz_cookies")
self.__add_cookies(list(result))
except Exception as e:
Logger.error("""DialogCookies::
_on_profile_selected(): %s""", e)
#######################
# PRIVATE #
#######################
......@@ -364,63 +264,15 @@ class CookiesDialog:
self.__cookies.add(row)
GLib.idle_add(self.__add_cookies, cookies)
def __add_profiles(self, profiles):
"""
Add profile to the list
@param profiles as {}
"""
if profiles:
(profile, name) = profiles.popitem()
item = Profile()
item.set_property("profile", profile)
item.set_property("name", name)
row = Row(item)
row.connect("moved", self.__on_moved)
row.show()
self.__profiles.prepend(row)
if profiles:
GLib.idle_add(self.__add_profiles, profiles)
else:
row.activate()
def __populate(self):
"""
Populate profile
"""
# Load user profiles
try:
self.__add_profiles(App().profiles)
path = COOKIES_PATH % (EOLIE_DATA_PATH, "default")
sql = sqlite3.connect(path, 600.0)
result = sql.execute("SELECT DISTINCT host, value\
FROM moz_cookies")
self.__add_cookies(list(result))
except Exception as e:
Logger.error("DialogSearchEngine::__populate(): %s", e)
def __get_index(self, name):
"""
Get child index
@param name as str
@return int
"""
# Search current index
children = self.__profiles.get_children()
index = 0
for child in children:
if child.item.get_property("name") == name:
break
index += 1
return index
def __on_moved(self, child, name, up):
"""
Move child row
@param child as SidebarChild
@param name as str
@param up as bool
"""
index = self.__get_index(name)
row = self.__profiles.get_row_at_index(index)
if row is None:
return
self.__profiles.remove(row)
child_index = self.__get_index(child.item.get_property("name"))
if not up:
child_index += 1
self.__profiles.insert(row, child_index)
# Copyright (c) 2017-2018 Cedric Bellegarde <cedric.bellegarde@adishatz.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gio, GLib, Gtk
from gettext import gettext as _
import json
from eolie.define import App, EOLIE_DATA_PATH
from eolie.logger import Logger
class ProfilesMenu(Gtk.Grid):
"""
Menu allowing to switch current view to a new profile
"""
def __init__(self, webview, window):
"""
Init menu
@param webview as WebView
@param window as Window
"""
self.__window = window
Gtk.Grid.__init__(self)
self.set_margin_start(5)
self.set_margin_end(5)
self.set_margin_top(5)
self.set_margin_bottom(5)
self.set_orientation(Gtk.Orientation.VERTICAL)
# Back button
item = Gtk.ModelButton.new()
item.set_hexpand(True)
item.set_property("centered", True)
item.set_property("text", _("Profiles"))
item.set_property("inverted", True)
item.set_property("menu-name", "main")
item.show()
self.add(item)
# Profile buttons
action = Gio.SimpleAction.new_stateful("switch_profile",
GLib.VariantType.new("s"),
GLib.Variant("s", "none"))
action.connect("activate",
self.__on_profiles_activate,
webview)
self.__window.add_action(action)
# Get first view URI
uri = webview.uri
profile = App().websettings.get_profile(uri)
# 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"))
for key in profiles.keys():
item = Gtk.ModelButton.new()
item.set_property("text", profiles[key])
item.set_action_name("win.switch_profile")
item.set_action_target_value(GLib.Variant("s", key))
item.show()
self.add(item)
if profile == key:
action.change_state(GLib.Variant("s", profile))
except Exception as e:
Logger.error("ProfilesMenu::__init__(): %s", e)
# Edit button
item = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)
item.show()
self.add(item)
action = Gio.SimpleAction(name="edit_profiles")
action.connect('activate',
self.__on_edit_profiles_activate)
self.__window.add_action(action)
item = Gtk.ModelButton.new()
item.set_property("text", _("Edit profiles"))
item.set_action_name("win.edit_profiles")
item.show()
self.add(item)
def do_hide(self):
"""
Remove action on hide
"""
Gtk.Grid.do_hide(self)
self.__window.remove_action("switch_profile")
self.__window.remove_action("edit_profiles")
#######################
# PRIVATE #
#######################
def __on_edit_profiles_activate(self, action, param):
"""
Show edit cookies dialog
@param action as Gio.SimpleAction
@param param as GLib.Variant
"""
from eolie.dialog_cookies import CookiesDialog
dialog = CookiesDialog(True, self.__window)
dialog.run()
def __on_profiles_activate(self, action, param, webview):
"""
Change profile
@param action as Gio.SimpleAction
@param param as GLib.Variant
@param webview as WebView
"""
try:
action.change_state(param)
uri = webview.uri
App().websettings.set_profile(param.get_string(), uri)
webview.stop_loading()
# We need to reset URI before reloading
# This allow WebViewNavigation to operate profile switching
webview.load_uri("about:blank")
webview.load_uri(uri)
except Exception as e:
Logger.error("ProfilesMenu::__on_profiles_activate: %s", e)
......@@ -13,10 +13,8 @@
from gi.repository import Gio, GLib, Gtk
from gettext import gettext as _
# from urllib.parse import urlparse
from eolie.define import App
from eolie.logger import Logger
class SitesMenu(Gtk.Grid):
......@@ -60,16 +58,6 @@ class SitesMenu(Gtk.Grid):
separator = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)
separator.show()
self.add(separator)
# Profiles switcher
# webview = views[0].webview
# if not webview.ephemeral:
# parsed = urlparse(webview.uri)
# if parsed.scheme in ["http", "https"]:
# item = Gtk.ModelButton.new()
# item.set_property("text", _("Profiles"))
# item.set_property("menu-name", "profiles")
# item.show()
# self.add(item)
# Move to
item = Gtk.ModelButton.new()
item.set_property("text", _("Move to"))
......@@ -108,33 +96,6 @@ class SitesMenu(Gtk.Grid):
#######################
# PRIVATE #
#######################
def __on_edit_profiles_activate(self, action, param):
"""
Show edit cookies dialog
@param action as Gio.SimpleAction
@param param as GLib.Variant
"""
from eolie.dialog_cookies import CookiesDialog
dialog = CookiesDialog(True, self.__window)
dialog.run()
def __on_profiles_activate(self, action, param):
"""
Change profile
@param action as Gio.SimpleAction
@param param as GLib.Variant
"""
try:
action.change_state(param)
# Get first view URI
webview = self.__views[0].webview
uri = webview.uri
App().websettings.set_profile(param.get_string(), uri)
webview.stop_loading()
webview.load_uri(uri)
except Exception as e:
Logger.error("SitesMenu::__on_profiles_activate: %s", e)
def __on_close_activate(self, action, param):
"""
Close wanted page
......
......@@ -356,21 +356,14 @@ class SitesManagerChild(Gtk.ListBoxRow):
return True
elif event.button == 3:
from eolie.menu_sites import SitesMenu
# from eolie.menu_profiles import ProfilesMenu
from eolie.menu_move_to import MoveToMenu
sites_menu = SitesMenu(self.__views, self.__window)
sites_menu.show()
# webview = self.__views[0].webview
# profiles_menu = ProfilesMenu(webview, self.__window)
# profiles_menu.show()
moveto_menu = MoveToMenu(self.__views, self.__window)
moveto_menu.show()
popover = Gtk.PopoverMenu.new()
popover.add(sites_menu)
# popover.add(profiles_menu)
popover.add(moveto_menu)
# popover.child_set_property(profiles_menu,
# "submenu", "profiles")
popover.child_set_property(moveto_menu,
"submenu", "moveto")
popover.set_relative_to(eventbox)
......
......@@ -245,18 +245,13 @@ class ToolbarTitle(Gtk.Bin):
self.__action_image2.set_from_icon_name(icon_name,
Gtk.IconSize.MENU)
def set_title(self, profile, title):
def set_title(self, title):
"""
Show title instead of uri
@param profile as str
@param title as str
"""
self.__window.set_title(title)
markup = False
if profile:
markup = True
title = "<b>%s</b>%s" % (GLib.markup_escape_text(profile),
GLib.markup_escape_text(title))
# Do not show this in titlebar
parsed = urlparse(self.__uri)
if parsed.scheme in ["populars", "about"]:
......
......@@ -21,19 +21,7 @@ from random import choice
from base64 import b64encode
from eolie.logger import Logger
from eolie.define import App, ArtSize, LoadingType