Skip to content

Commit

Permalink
Fix for issues MeanEYE#172 - Still importing GTK2 libraries - gnomeke…
Browse files Browse the repository at this point in the history
…yring
  • Loading branch information
Christian Mallwitz committed Apr 20, 2016
1 parent e88a90a commit 45bcc08
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 44 deletions.
45 changes: 23 additions & 22 deletions application/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
from gui.input_dialog import InputDialog, PasswordDialog

try:
import gnomekeyring as keyring

from gi.repository import GnomeKeyring as keyring
except:
keyring = None


class EntryType:
NO_TYPE = 0
GENERIC = 1
NETWORK = 2
NOTE = 3
GENERIC = 0
NETWORK = 1
NOTE = 2


class KeyringCreateError(Exception): pass
Expand All @@ -32,10 +30,9 @@ class KeyringManager:

if keyring is not None:
KEYRING_TYPE = {
EntryType.NO_TYPE: keyring.ITEM_NO_TYPE,
EntryType.GENERIC: keyring.ITEM_GENERIC_SECRET,
EntryType.NETWORK: keyring.ITEM_NETWORK_PASSWORD,
EntryType.NOTE: keyring.ITEM_NOTE
EntryType.GENERIC: keyring.ItemType.GENERIC_SECRET,
EntryType.NETWORK: keyring.ItemType.NETWORK_PASSWORD,
EntryType.NOTE: keyring.ItemType.NOTE
}

def __init__(self, application):
Expand Down Expand Up @@ -73,7 +70,7 @@ def __initialize_keyring(self):

def __update_info(self):
"""Update keyring status information"""
self._info = keyring.get_info_sync(self.KEYRING_NAME)
self._info = keyring.get_info_sync(self.KEYRING_NAME)[1]

# update icon
self.__update_icon()
Expand Down Expand Up @@ -128,8 +125,8 @@ def __get_entry_info(self, entry):
"""Get entry info object"""
result = None

for item_id in keyring.list_item_ids_sync(self.KEYRING_NAME):
info = keyring.item_get_info_sync(self.KEYRING_NAME, item_id)
for item_id in keyring.list_item_ids_sync(self.KEYRING_NAME)[1]:
info = keyring.item_get_info_sync(self.KEYRING_NAME, item_id)[1]

if info.get_display_name() == entry:
result = info
Expand All @@ -141,8 +138,8 @@ def __get_entry_id(self, entry):
"""Get entry ID"""
result = None

for item_id in keyring.list_item_ids_sync(self.KEYRING_NAME):
info = keyring.item_get_info_sync(self.KEYRING_NAME, item_id)
for item_id in keyring.list_item_ids_sync(self.KEYRING_NAME)[1]:
info = keyring.item_get_info_sync(self.KEYRING_NAME, item_id)[1]

if info.get_display_name() == entry:
result = item_id
Expand All @@ -160,7 +157,7 @@ def keyring_exists(self):
result = False

if self.is_available():
result = self.KEYRING_NAME in keyring.list_keyring_names_sync()
result = self.KEYRING_NAME in keyring.list_keyring_names_sync()[1]

return result

Expand Down Expand Up @@ -188,7 +185,7 @@ def rename_entry(self, entry, new_name):

# get entry information
entry_id = self.__get_entry_id(entry)
info = keyring.item_get_info_sync(self.KEYRING_NAME, entry_id)
info = keyring.item_get_info_sync(self.KEYRING_NAME, entry_id)[1]

if info is not None:
info.set_display_name(new_name)
Expand All @@ -209,7 +206,7 @@ def change_secret(self, entry_id, secret):
return result

# get entry information
info = keyring.item_get_info_sync(self.KEYRING_NAME, entry_id)
info = keyring.item_get_info_sync(self.KEYRING_NAME, entry_id)[1]

if info is not None:
info.set_secret(secret)
Expand Down Expand Up @@ -250,8 +247,8 @@ def get_entries(self):
return result

# populate result list
for item_id in keyring.list_item_ids_sync(self.KEYRING_NAME):
info = keyring.item_get_info_sync(self.KEYRING_NAME, item_id)
for item_id in keyring.list_item_ids_sync(self.KEYRING_NAME)[1]:
info = keyring.item_get_info_sync(self.KEYRING_NAME, item_id)[1]
result.append((item_id, info.get_display_name(), info.get_mtime()))

return result
Expand Down Expand Up @@ -303,7 +300,7 @@ def store_password(self, entry, password, attributes=None, entry_type=EntryType.
assert self.is_available()

# create a new keyring if it doesn't exist
if not self.KEYRING_NAME in keyring.list_keyring_names_sync():
if not self.KEYRING_NAME in keyring.list_keyring_names_sync()[1]:
dialog = PasswordDialog(self._application)
dialog.set_title(_('New keyring'))
dialog.set_label(_(
Expand All @@ -328,12 +325,16 @@ def store_password(self, entry, password, attributes=None, entry_type=EntryType.
if self.is_locked() and not self.__unlock_keyring():
return False

attribute_array = keyring.Attribute.list_new()
for key in attributes:
keyring.Attribute.list_append_string(attribute_array, key, attributes[key])

# store password to existing keyring
keyring.item_create_sync(
self.KEYRING_NAME,
self.KEYRING_TYPE[entry_type],
entry,
attributes if attributes is not None else {},
attribute_array,
password,
True # update if exists
)
Expand Down
42 changes: 20 additions & 22 deletions application/plugins/file_list/gio_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gi.repository import Gtk, Gio, Gdk, GLib
from gi.repository import Gtk, Gio, Gdk, GLib, GObject
from dialogs import SambaInputDialog, SambaResult
from dialogs import FtpInputDialog, FtpResult, SftpInputDialog
from dialogs import DavInputDialog, DavResult
Expand Down Expand Up @@ -61,17 +61,16 @@ def ask_password(operation, message, default_user, default_domain, flags):

else:
# we don't have stored password, ask user to provide one
with Gdk.lock:
dialog = InputDialog(self._application)
dialog.set_title(_('Mount operation'))
dialog.set_label(message)
dialog.set_password()
dialog = InputDialog(self._application)
dialog.set_title(_('Mount operation'))
dialog.set_label(message)
dialog.set_password()

response = dialog.get_response()
response = dialog.get_response()

if response[0] == Gtk.ResponseType.OK:
operation.set_password(response[1])
operation.reply(Gio.MountOperationResult.HANDLED)
if response[0] == Gtk.ResponseType.OK:
operation.set_password(response[1])
operation.reply(Gio.MountOperationResult.HANDLED)

# create new mount operation object
operation = Gio.MountOperation()
Expand Down Expand Up @@ -102,18 +101,17 @@ def __mount_callback(self, path, result, user_data=None):
path.mount_enclosing_volume_finish(result)

except GLib.GError as error:
with Gdk.lock:
dialog = Gtk.MessageDialog(
self._parent.window,
Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.OK,
_(
"Unable to mount:\n{0}\n\n{1}"
).format(path.get_uri(), str(error))
)
dialog.run()
dialog.destroy()
dialog = Gtk.MessageDialog(
self._parent.window,
Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.OK,
_(
"Unable to mount:\n{0}\n\n{1}"
).format(path.get_uri(), str(error))
)
dialog.run()
dialog.destroy()

finally:
self._hide_spinner()
Expand Down

0 comments on commit 45bcc08

Please sign in to comment.