예제 #1
0
파일: utils.py 프로젝트: bagage/eolie
def get_snapshot(webview, result, callback, *args):
    """
        Set snapshot on main image
        @param webview as WebKit2.WebView
        @param result as Gio.AsyncResult
        @return cairo.Surface
    """
    ART_RATIO = 1.5  # ArtSize.START_WIDTH / ArtSize.START_HEIGHT
    try:
        snapshot = webview.get_snapshot_finish(result)
        # Set start image scale factor
        ratio = snapshot.get_width() / snapshot.get_height()
        if ratio > ART_RATIO:
            factor = ArtSize.START_HEIGHT / snapshot.get_height()
        else:
            factor = ArtSize.START_WIDTH / snapshot.get_width()
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, ArtSize.START_WIDTH,
                                     ArtSize.START_HEIGHT)
        context = cairo.Context(surface)
        context.scale(factor, factor)
        context.set_source_surface(snapshot, factor, 0)
        context.paint()
        callback(surface, *args)
    except Exception as e:
        Logger.error("get_snapshot(): %s", e)
        callback(None, *args)
예제 #2
0
파일: settings.py 프로젝트: bagage/eolie
 def _on_default_zoom_changed(self, button):
     """
         Save size
         @param button as Gtk.SpinButton
     """
     button.set_text("{} %".format(int(button.get_value())))
     monitor_model = get_current_monitor_model(
         self.__settings_dialog.get_transient_for())
     try:
         # Add current value less monitor model
         zoom_levels = []
         for zoom_level in App().settings.get_value("default-zoom-level"):
             zoom_splited = zoom_level.split('@')
             if zoom_splited[0] == monitor_model:
                 continue
             else:
                 zoom_levels.append("%s@%s" %
                                    (zoom_splited[0], zoom_splited[1]))
         # Add new zoom value for monitor model
         zoom_levels.append("%s@%s" %
                            (monitor_model, button.get_value() / 100))
         App().settings.set_value("default-zoom-level",
                                  GLib.Variant("as", zoom_levels))
         for window in App().windows:
             window.update_zoom_level(True)
     except Exception as e:
         Logger.error("SettingsDialog::_on_default_zoom_changed(): %s", e)
예제 #3
0
 def __on_snapshot(self, webview, result, first_pass):
     """
         Set snapshot on main image
         @param webview as WebView
         @param result as Gio.AsyncResult
         @param first_pass as bool
     """
     try:
         snapshot = webview.get_snapshot_finish(result)
         pixbuf = Gdk.pixbuf_get_from_surface(snapshot, 0, 0,
                                              snapshot.get_width(),
                                              snapshot.get_height())
         pixbuf.savev("/tmp/eolie_snapshot.png", "png", [None], [None])
         Gtk.show_uri_on_window(self._window,
                                "file:///tmp/eolie_snapshot.png",
                                Gtk.get_current_event_time())
     except Exception as e:
         Logger.error("WebView::__on_snapshot(): %s", e)
         # The 32767 limit on the width/height dimensions
         # of an image surface is new in cairo 1.10,
         # try with WebKit2.SnapshotRegion.VISIBLE
         if first_pass:
             self.get_snapshot(WebKit2.SnapshotRegion.VISIBLE,
                               WebKit2.SnapshotOptions.NONE,
                               None,
                               self.__on_snapshot,
                               False)
예제 #4
0
 def __move_images(self):
     """
         Move image to download directory
     """
     parsed = urlparse(self.__uri)
     directory_uri = App().settings.get_value('download-uri').get_string()
     if not directory_uri:
         directory = GLib.get_user_special_dir(
             GLib.UserDirectory.DIRECTORY_DOWNLOAD)
         directory_uri = GLib.filename_to_uri(directory, None)
     destination_uri = "%s/%s" % (directory_uri, parsed.netloc)
     directory = Gio.File.new_for_uri(destination_uri)
     if not directory.query_exists():
         directory.make_directory_with_parents()
     for child in self.__flowbox.get_children():
         if child.uri.find(self.__filter) != -1:
             encoded = sha256(child.uri.encode("utf-8")).hexdigest()
             child_basename = child.uri.split("/")[-1]
             filepath = "%s/%s" % (EOLIE_CACHE_PATH, encoded)
             s = Gio.File.new_for_path(filepath)
             if not s.query_exists():
                 continue
             d = Gio.File.new_for_uri("%s/%s" %
                                      (destination_uri, child_basename))
             try:
                 s.move(d, Gio.FileCopyFlags.OVERWRITE, None, None, None)
             except Exception as e:
                 Logger.error("ImagesPopover::__move_images(): %s", e)
     GLib.idle_add(self.hide)
예제 #5
0
 def set_profile(self, profile, uri):
     """
         Set profile for uri
         @param user_agent as str
         @param uri as str
     """
     parsed = urlparse(uri)
     if parsed.scheme not in ["http", "https"]:
         return
     try:
         with SqlCursor(self) as sql:
             result = sql.execute(
                 "SELECT rowid FROM settings\
                                   WHERE uri=?", (parsed.netloc, ))
             v = result.fetchone()
             if v is not None:
                 sql.execute(
                     "UPDATE settings\
                              SET profile=?\
                              WHERE uri=?", (profile, parsed.netloc))
             else:
                 sql.execute(
                     "INSERT INTO settings\
                                       (uri, profile)\
                                       VALUES (?, ?)",
                     (parsed.netloc, profile))
     except Exception as e:
         Logger.error("DatabaseSettings::set_profile(): %s", e)
예제 #6
0
 def __init__(self):
     """
         Create database tables or manage update if needed
         @param suffix as str
     """
     self.thread_lock = Lock()
     new_version = len(self.__UPGRADES)
     self.__DB_PATH = "%s/settings2.db" % EOLIE_DATA_PATH
     if not GLib.file_test(self.__DB_PATH, GLib.FileTest.IS_REGULAR):
         try:
             if not GLib.file_test(EOLIE_DATA_PATH, GLib.FileTest.IS_DIR):
                 GLib.mkdir_with_parents(EOLIE_DATA_PATH, 0o0750)
             # Create db schema
             with SqlCursor(self) as sql:
                 sql.execute(self.__create_settings)
                 sql.execute("PRAGMA user_version=%s" % new_version)
         except Exception as e:
             Logger.error("DatabaseSettings::__init__(): %s", e)
     # DB upgrade, TODO Make it generic between class
     version = 0
     with SqlCursor(self) as sql:
         result = sql.execute("PRAGMA user_version")
         v = result.fetchone()
         if v is not None:
             version = v[0]
         if version < new_version:
             for i in range(version + 1, new_version + 1):
                 try:
                     sql.execute(self.__UPGRADES[i])
                 except:
                     Logger.error("Settings DB upgrade %s failed", i)
             sql.execute("PRAGMA user_version=%s" % new_version)
예제 #7
0
 def __on_save_rules(self, result, uris=[]):
     """
         Load next uri, if finished, load CSS rules
         @param result (unused)
         @param uris as [str]
     """
     if self.__cancellable.is_cancelled():
         return
     if uris:
         uri = uris.pop(0)
         self.__task_helper.load_uri_content(uri,
                                             self.__cancellable,
                                             self.__on_load_uri_content,
                                             uris)
     else:
         with SqlCursor(self) as sql:
             sql.execute("DELETE FROM adblock\
                          WHERE mtime!=?", (self.__adblock_mtime,))
             sql.execute("DELETE FROM adblock_re\
                          WHERE mtime!=?", (self.__adblock_mtime,))
             sql.execute("DELETE FROM adblock_re_domain\
                          WHERE mtime!=?", (self.__adblock_mtime,))
             sql.execute("DELETE FROM adblock_re_domain_ex\
                          WHERE mtime!=?", (self.__adblock_mtime,))
             sql.execute("DELETE FROM adblock_css\
                          WHERE mtime!=?", (self.__adblock_mtime,))
             sql.execute("DELETE FROM adblock_cache")
             try:
                 dump(self.__adblock_mtime,
                      open(EOLIE_DATA_PATH + "/adblock.bin", "wb"))
             except Exception as e:
                 Logger.error("DatabaseAdblock::__on_save_rules(): %s", e)
예제 #8
0
 def set_accept_tls(self, uri, accept):
     """
         Accept TLS for uri
         @param uri as str
         @param accept as bool
     """
     parsed = urlparse(uri)
     if parsed.scheme != "https":
         return
     try:
         with SqlCursor(self) as sql:
             result = sql.execute(
                 "SELECT rowid FROM settings\
                                   WHERE uri=?", (parsed.netloc, ))
             v = result.fetchone()
             if v is not None:
                 sql.execute(
                     "UPDATE settings\
                              SET accept_tls=?\
                              WHERE uri=?", (accept, parsed.netloc))
             else:
                 sql.execute(
                     "INSERT INTO settings\
                                       (uri, accept_tls)\
                                       VALUES (?, ?)",
                     (parsed.netloc, accept))
     except Exception as e:
         Logger.error("DatabaseSettings::set_accept_tls(): %s", e)
예제 #9
0
 def __sort_func(self, row1, row2):
     """
         Sort listbox
         @param row1 as Row
         @param row2 as Row
     """
     try:
         # Group pages by net location then atime
         if self.__sort_pages and row2.view.webview.uri is not None and\
                 row1.view.webview.uri is not None:
             netloc1 = get_safe_netloc(row1.view.webview.uri)
             netloc2 = get_safe_netloc(row2.view.webview.uri)
             if netloc1 != netloc2 and netloc1 in self.__sort_pages and\
                     netloc2 in self.__sort_pages:
                 index1 = self.__sort_pages.index(netloc1)
                 index2 = self.__sort_pages.index(netloc2)
                 return index2 < index1
             else:
                 return row2.view.webview.atime > row1.view.webview.atime
         # Always show current first
         elif self.__current_child is not None and\
                 self.__current_child in [row1, row2]:
             return self.__current_child == row2
         # Unshown first
         elif not row2.view.webview.shown and row1.view.webview.shown:
             return True
         else:
             return row2.view.webview.atime > row1.view.webview.atime
     except Exception as e:
         Logger.error("PagesManager::__sort_func(): %s", e)
예제 #10
0
    def __rule_to_regex(self, rule):
        """
            Convert rule to regex
            @param rule as str
            @return regex as str
        """
        try:
            # Do nothing if rule is already a regex
            if rule[0] == rule[-1] == "/":
                return rule[1:-1]

            rule = re.sub(self.__SPECIAL_CHARS, r"\\\1", rule)

            # Handle ^ separator character, *, etc...
            for key in self.__REPLACE_CHARS.keys():
                rule = rule.replace(key, self.__REPLACE_CHARS[key])
            # End of the address
            if rule[-1] == "|":
                rule = rule[:-1] + "$"
            # Start of the address
            if rule[0] == "|":
                rule = "^" + rule[1:]
            # Escape remaining | but not |$ => see self.__REPLACE_CHARS
            rule = re.sub("(\|)[^$]", r"\|", rule)
            return rule
        except Exception as e:
            Logger.error("DatabaseAdblock::__rule_to_regex(): %s", e)
            return None
예제 #11
0
 def __vacuum(self):
     """
         VACUUM DB
         @thread safe
     """
     try:
         with SqlCursor(self.bookmarks) as sql:
             sql.isolation_level = None
             sql.execute("VACUUM")
             sql.isolation_level = ""
         with SqlCursor(self.history) as sql:
             sql.isolation_level = None
             sql.execute("VACUUM")
             sql.isolation_level = ""
         with SqlCursor(self.adblock) as sql:
             sql.isolation_level = None
             sql.execute("VACUUM")
             sql.isolation_level = ""
         with SqlCursor(self.phishing) as sql:
             sql.isolation_level = None
             sql.execute("VACUUM")
             sql.isolation_level = ""
     except Exception as e:
         Logger.error("Application::__vacuum(): %s ", e)
     self.art.vacuum()
예제 #12
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:
             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)
예제 #13
0
    def connect(self, bid_assertion, key):
        """
            Connect to sync using FxA browserid assertion
            @param session as fxaSession
            @return bundle keys as KeyBundle
        """
        state = None
        if key is not None:
            from binascii import hexlify
            state = hexlify(sha256(key).digest()[0:16])
        self.__client = SyncClient(bid_assertion, state)
        sync_keys = KeyBundle.fromMasterKey(
            key, "identity.mozilla.com/picl/v1/oldsync")

        # Fetch the sync bundle keys out of storage.
        # They're encrypted with the account-level key.
        keys = self.__decrypt_payload(
            self.__client.get_record("crypto", "keys"), sync_keys)

        # There's some provision for using separate
        # key bundles for separate collections
        # but I haven't bothered digging through
        # to see what that's about because
        # it doesn't seem to be in use, at least on my account.
        if keys["collections"]:
            Logger.error("""no support for per-collection
                            key bundles yet sorry :-(""")
            return None

        # Now use those keys to decrypt the records of interest.
        from base64 import b64decode
        bulk_keys = KeyBundle(b64decode(keys["default"][0]),
                              b64decode(keys["default"][1]))
        return bulk_keys
예제 #14
0
 def __push_password(self, user_form_name, user_form_value, pass_form_name,
                     pass_form_value, uri, form_uri, uuid):
     """
         Push password
         @param user_form_name as str
         @param user_form_value as str
         @param pass_form_name as str
         @param pass_form_value as str
         @param uri as str
         @param uuid as str
     """
     try:
         record = {}
         record["id"] = "{%s}" % uuid
         record["hostname"] = uri
         record["formSubmitURL"] = form_uri
         record["httpRealm"] = None
         record["username"] = user_form_value
         record["password"] = pass_form_value
         record["usernameField"] = user_form_name
         record["passwordField"] = pass_form_name
         mtime = int(time() * 1000)
         record["timeCreated"] = mtime
         record["timePasswordChanged"] = mtime
         self.__pending_records["passwords"].append(record)
         self.__sync_pendings()
     except Exception as e:
         Logger.error("SyncWorker::__push_password(): %s", e)
예제 #15
0
 def __init__(self, window):
     """
         Init widget
         @param window as Gtk.Window
     """
     self.__window = window
     builder = Gtk.Builder()
     builder.add_from_resource("/org/gnome/Eolie/DialogImportBookmarks.ui")
     builder.connect_signals(self)
     self.__dialog = builder.get_object("dialog")
     self.__dialog.set_transient_for(window)
     self.__listbox = builder.get_object("listbox")
     items = ["Firefox", "Chromium", "Chrome"]
     try:
         from bs4 import BeautifulSoup
         BeautifulSoup
         items.append(_("Others"))
     except Exception as e:
         Logger.error("ImportBookmarksDialog::__init__(): %s", e)
     for item in items:
         label = Gtk.Label.new(item)
         label.show()
         self.__listbox.add(label)
     headerbar = builder.get_object("headerbar")
     self.__dialog.set_titlebar(headerbar)
예제 #16
0
 def allow_geolocation(self, uri, b):
     """
         Allow geolocation for uri
         @param uri as str
         @param b as bool
     """
     parsed = urlparse(uri)
     if parsed.scheme not in ["http", "https"]:
         return
     try:
         with SqlCursor(self) as sql:
             result = sql.execute(
                 "SELECT rowid FROM settings\
                                   WHERE uri=?", (parsed.netloc, ))
             v = result.fetchone()
             if v is not None:
                 sql.execute(
                     "UPDATE settings\
                              SET geolocation=?\
                              WHERE uri=?", (b, parsed.netloc))
             else:
                 sql.execute(
                     "INSERT INTO settings\
                                       (uri, geolocation)\
                                       VALUES (?, ?)", (b, parsed.netloc))
     except Exception as e:
         Logger.error("DatabaseSettings::allow_geolocation(): %s", e)
예제 #17
0
 def _on_dialog_response(self, dialog, response_id):
     """
         Save user agent
         @param dialog as Gtk.Dialog
         @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"))
             request = "DELETE FROM moz_cookies WHERE "
             filters = ()
             for row in rows:
                 request += "host=? OR "
                 filters += (row.item.name, )
             request += " 0"
             sql = sqlite3.connect(path, 600.0)
             sql.execute(request, filters)
             sql.commit()
     except Exception as e:
         Logger.error("CookiesDialog::_on_dialog_response(): %s", e)
     App().set_profiles()
예제 #18
0
 def set_zoom(self, zoom, uri):
     """
         Set zoom for uri
         @param zoom as int
         @param uri as str
     """
     parsed = urlparse(uri)
     if parsed.scheme not in ["http", "https"]:
         return
     try:
         with SqlCursor(self) as sql:
             result = sql.execute(
                 "SELECT rowid FROM settings\
                                   WHERE uri=?", (parsed.netloc, ))
             v = result.fetchone()
             if v is not None:
                 sql.execute(
                     "UPDATE settings\
                              SET zoom=?\
                              WHERE uri=?", (zoom, parsed.netloc))
             else:
                 sql.execute(
                     "INSERT INTO settings\
                                       (uri, zoom)\
                                       VALUES (?, ?)",
                     (parsed.netloc, zoom))
     except Exception as e:
         Logger.error("DatabaseSettings::set_zoom(): %s", e)
예제 #19
0
 def set_chooser_uri(self, chooseruri, uri):
     """
         Add an uri related to uri
         @param chooseruri as str
         @param uri as str
     """
     parsed = urlparse(uri)
     if parsed.scheme not in ["http", "https"]:
         return
     try:
         with SqlCursor(self) as sql:
             result = sql.execute(
                 "SELECT rowid FROM settings\
                                   WHERE uri=?", (parsed.netloc, ))
             v = result.fetchone()
             if v is not None:
                 sql.execute(
                     "UPDATE settings\
                              SET chooseruri=?\
                              WHERE uri=?", (chooseruri, parsed.netloc))
             else:
                 sql.execute(
                     "INSERT INTO settings\
                                       (uri, chooseruri)\
                                       VALUES (?, ?)",
                     (parsed.netloc, chooseruri))
     except Exception as e:
         Logger.error("DatabaseSettings::set_chooser_uri(): %s", e)
예제 #20
0
 def add_language(self, code, uri):
     """
         Add language for uri
         @param code as str
         @param uri as str
     """
     parsed = urlparse(uri)
     if parsed.scheme not in ["http", "https"]:
         return
     try:
         with SqlCursor(self) as sql:
             codes = self.get_languages(uri)
             if codes is not None:
                 if code not in codes:
                     codes.append(code)
                 sql.execute(
                     "UPDATE settings\
                              SET languages=?\
                              WHERE uri=?",
                     (";".join(codes), parsed.netloc))
             else:
                 sql.execute(
                     "INSERT INTO settings\
                                       (uri, languages)\
                                       VALUES (?, ?)",
                     (parsed.netloc, code))
     except Exception as e:
         Logger.error("DatabaseSettings::add_language(): %s", e)
예제 #21
0
파일: settings.py 프로젝트: bagage/eolie
 def __connect_firefox_sync(self, username, password):
     """
         Connect to firefox sync
         @param username as str
         @param password as str
         @thread safe
     """
     try:
         App().sync_worker.new_session()
         App().sync_worker.login({"login": username}, password)
         GLib.idle_add(self.__setup_sync_button, True)
     except Exception as e:
         Logger.error("SettingsDialog::__connect_firefox_sync(): %s", e)
         GLib.idle_add(self.__sync_button.set_sensitive, True)
         if str(e) == "Unverified account":
             GLib.timeout_add(500, self.__settings_dialog.destroy)
             self.__window.toolbar.end.show_sync_button()
             GLib.idle_add(
                 App().active_window.toolbar.title.show_message,
                 _("You've received an email"
                   " to validate syncing"))
         else:
             GLib.idle_add(self.__result_label.set_text, str(e))
             GLib.idle_add(self.__result_image.set_from_icon_name,
                           "computer-fail-symbolic", Gtk.IconSize.MENU)
예제 #22
0
 def delete_record(self, collection, record_id, **kwargs):
     """Deletes the BSO at the given location.
     """
     try:
         return self._request(
             'delete', '/storage/%s/%s' % (collection.lower(), record_id),
             **kwargs)
     except Exception as e:
         Logger.error("SyncClient::delete_record(): %s", e)
예제 #23
0
파일: art.py 프로젝트: bagage/eolie
 def __create_cache(self):
     """
         Create cache dir
     """
     if not GLib.file_test(EOLIE_CACHE_PATH, GLib.FileTest.IS_DIR):
         try:
             GLib.mkdir_with_parents(EOLIE_CACHE_PATH, 0o0750)
         except Exception as e:
             Logger.error("Art::__create_cache(): %s", e)
예제 #24
0
 def __populate(self):
     """
         Populate profile
     """
     # Load user profiles
     try:
         self.__add_profiles(App().profiles)
     except Exception as e:
         Logger.error("DialogSearchEngine::__populate(): %s", e)
예제 #25
0
 def get_cursor(self):
     """
         Return a new sqlite cursor
     """
     try:
         c = sqlite3.connect(self.__DB_PATH, 600.0)
         return c
     except Exception as e:
         Logger.error("DatabaseSettings::get_cursor(): %s", e)
         exit(-1)
예제 #26
0
 def __on_data_manager_fetch(self, data_manager, result):
     """
         Get fetch result
         @param data_manager as WebKit2.WebsiteDataManager
         @param result as Gio.AsyncResult
     """
     try:
         items = data_manager.fetch_finish(result)
         self.__add_items(items)
     except Exception as e:
         Logger.error("ClearDataDialog::__on_data_manager_fetch(): %s", e)
예제 #27
0
 def __on_download_activate(self, action, variant, uri):
     """
         Download file
         @param action as Gio.SimpleAction
         @param variant as GLib.Variant
         @param uri as str
     """
     try:
         self.get_context().download_uri(uri)
     except Exception as e:
         Logger.error("WebViewMenuSignals::__on_download_activate(): %s", e)
예제 #28
0
 def import_chromium(self, chrome):
     """
         Chromium/Chrome importer
         As Eolie doesn't sync with Chromium, we do not handle parent
         guid and just import parents as tags
         @param chrome as bool
     """
     try:
         SqlCursor.add(self)
         import json
         homedir = GLib.get_home_dir()
         if chrome:
             path = homedir + "/.config/chrome/Default/Bookmarks"
         else:
             path = homedir + "/.config/chromium/Default/Bookmarks"
         f = Gio.File.new_for_path(path)
         if not f.query_exists():
             return
         (status, content, tag) = f.load_contents(None)
         if status:
             data = content.decode("utf-8")
             j = json.loads(data)
             parents = []
             # Setup initial parents
             for root in j["roots"]:
                 parents.append(("", j["roots"][root]["children"]))
             # Walk parents and children
             while parents:
                 (parent_name, children) = parents.pop(0)
                 bookmarks = []
                 for child in children:
                     if child["type"] == "folder":
                         parents.append((child["name"], child["children"]))
                     elif child["type"] == "url":
                         bookmarks.append((child["name"], child["url"]))
                 position = 0
                 for bookmark in bookmarks:
                     tags = [parent_name]
                     title = bookmark[0]
                     uri = bookmark[1]
                     if not uri.startswith('http') or not title:
                         continue
                     uri = uri.rstrip('/')
                     rowid = self.get_id(uri)
                     if rowid is None:
                         # Add bookmark
                         bookmark_id = self.add(title, uri, None, tags, 0)
                         # Set position
                         self.set_position(bookmark_id, position)
                         position += 1
             SqlCursor.remove(self)
     except Exception as e:
         Logger.error("DatabaseBookmarks::import_chromium(): %s", e)
예제 #29
0
 def get_cursor(self):
     """
         Return a new sqlite cursor
     """
     try:
         c = sqlite3.connect(self.DB_PATH, 600.0)
         c.create_collation('LOCALIZED', LocalizedCollation())
         c.create_function("noaccents", 1, noaccents)
         return c
     except Exception as e:
         Logger.error("DatabaseBookmarks::get_cursor(): %s", e)
         exit(-1)
예제 #30
0
 def __on_get_password(self, attributes, password, form_uri, index, count,
                       user_form_name, user_form_value, pass_form_name,
                       pass_form_value, hostname_uri, page_id):
     """
         Ask for credentials through DBus
         @param attributes as {}
         @param password as str
         @param form_uri as str
         @param index as int
         @param count as int
         @param user_form_name as str
         @param user_form_value as str
         @param pass_form_name as str
         @param pass_form_value as str
         @param hostname_uri as str
         @param page_id as int
     """
     try:
         # If credentials not found (!=Type.NONE) and something new
         # is submitted
         if self.__pending_credentials != Type.NONE and (
                 attributes is None
                 or attributes["login"] != user_form_value
                 or password != pass_form_value):
             if attributes is None or\
                     attributes["login"] != user_form_value:
                 uuid = ""
             else:
                 uuid = attributes["uuid"]
             self.__pending_credentials = (uuid, user_form_name,
                                           user_form_value, pass_form_name,
                                           pass_form_value, hostname_uri,
                                           form_uri)
         else:
             # Found, no more lookup
             self.__pending_credentials = Type.NONE
         # Last found credentials
         if count < 1 or index == count - 1:
             # Reset pending
             if self.__pending_credentials == Type.NONE:
                 self.__pending_credentials = None
             # Ask for user input
             elif self.__pending_credentials not in [None, Type.NONE]:
                 (uuid, user_form_name, user_form_value, pass_form_name,
                  pass_form_value, hostname_uri,
                  form_uri) = self.__pending_credentials
                 args = (uuid, user_form_name, user_form_value,
                         pass_form_name, hostname_uri, form_uri)
                 variant = GLib.Variant.new_tuple(
                     GLib.Variant("(ssssss)", args))
                 self.emit("submit-form", variant)
     except Exception as e:
         Logger.error("FormsExtension::__on_get_password(): %s", e)