Skip to content

Commit

Permalink
Use gi with gnome-keyring. A lot of fixs with dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
chuchiperriman committed May 13, 2012
1 parent 869a277 commit e4eabf5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/cloudsn/core/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ def __init__(self):
self.config = config.SettingsController.get_instance()
from keyrings.plainkeyring import PlainKeyring
self.__add_manager (PlainKeyring())

try:
from keyrings.base64keyring import Base64Keyring
self.__add_manager (Base64Keyring())
except Exception, e:
logger.exception("Cannot load base64 keyring: %s", e)

try:
from keyrings.gkeyring import GnomeKeyring
self.__add_manager (GnomeKeyring())
Expand Down
30 changes: 19 additions & 11 deletions src/cloudsn/core/keyrings/gkeyring.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode: python; tab-width: 4; indent-tabs-mode: nil -*-
import gnomekeyring as gk
from gi.repository import GnomeKeyring as gk
from cloudsn.core.keyring import Keyring, KeyringException, Credentials
from cloudsn import logger
import threading
Expand All @@ -12,7 +12,7 @@ class GnomeKeyring(Keyring):

def __init__(self):
self._protocol = "network"
self._key = gk.ITEM_NETWORK_PASSWORD
self._key = gk.ItemType.NETWORK_PASSWORD
if not gk.is_available():
raise KeyringException("The Gnome keyring is not available")
logger.debug("default keyring ok")
Expand All @@ -39,16 +39,23 @@ def get_credentials(self, acc):
self.lock.acquire()
try:
logger.debug("Getting credentials with gnome keyring for account %s" % (acc.get_name()))
attrs = {"account_name": acc.get_name()}
attrs = gk.Attribute.list_new()
gk.Attribute.list_append_string(attrs, 'account_name', acc.get_name())
try:
items = gk.find_items_sync(gk.ITEM_NETWORK_PASSWORD, attrs)
(result, items) = gk.find_items_sync(gk.ItemType.NETWORK_PASSWORD, attrs)
except gk.NoMatchError, e:
items = list()

if len(items) < 1:
raise KeyringException("Cannot find the keyring data for the account %s" % (acc.get_name()))

logger.debug("items ok")
return Credentials (items[0].attributes["username"], items[0].secret)

username = ''
for attr in gk.Attribute.list_to_glist(items[0].attributes):
if attr.name == 'username':
username = attr.get_string()
return Credentials (username, items[0].secret)
finally:
self.lock.release()

Expand All @@ -71,12 +78,13 @@ def store_credentials(self, acc, credentials):
self.__check_keyring()
#Remove the old info and create a new item with the new info
self.remove_credentials(acc)
attrs = {
"account_name": acc.get_name(),
"username": credentials.username,
}
id = gk.item_create_sync(self._KEYRING_NAME, \
gk.ITEM_NETWORK_PASSWORD, acc.get_name(), attrs, credentials.password, True)

attrs = gk.Attribute.list_new()
gk.Attribute.list_append_string(attrs, 'account_name', acc.get_name())
gk.Attribute.list_append_string(attrs, 'username', credentials.username)

(result, id) = gk.item_create_sync(self._KEYRING_NAME, \
gk.ItemType.NETWORK_PASSWORD, acc.get_name(), attrs, credentials.password, True)
logger.debug("credentials stored with id: %i" % (id))
finally:
self.lock.release()
4 changes: 2 additions & 2 deletions src/cloudsn/ui/about.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#encoding: utf-8
from gi.repository import Gtk
from gi.repository import Gtk, GdkPixbuf
from cloudsn import const
from cloudsn.core import config

Expand All @@ -10,7 +10,7 @@ def show_about_dialog():
dialog.set_copyright (const.APP_COPYRIGHT)
dialog.set_comments(const.APP_DESCRIPTION)
dialog.set_website (const.APP_WEBSITE)
dialog.set_logo(Gtk.Gdk.pixbuf_new_from_file(config.add_data_prefix('cloudsn120.png')))
dialog.set_logo(GdkPixbuf.Pixbuf.new_from_file(config.add_data_prefix('cloudsn120.png')))
dialog.set_authors (["Jesús Barbero Rodríguez"])
dialog.run()
dialog.hide()
8 changes: 4 additions & 4 deletions src/cloudsn/ui/authwarning.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def check_auth_configuration():
"""))
dialog = Gtk.Dialog(APP_LONG_NAME,
None,
Gtk.DIALOG_MODAL | Gtk.DIALOG_DESTROY_WITH_PARENT,
(Gtk.STOCK_OK, Gtk.RESPONSE_ACCEPT))
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
dialog.set_icon(get_cloudsn_icon())
dialog.vbox.pack_start(label)
dialog.vbox.pack_start(label, False, False, 10)
checkbox = Gtk.CheckButton(_("Don't ask me again"))
checkbox.show()
dialog.vbox.pack_end(checkbox)
dialog.vbox.pack_end(checkbox, False, False, 0)
label.show()
response = dialog.run()
dialog.destroy()
Expand Down
16 changes: 9 additions & 7 deletions src/cloudsn/ui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ def main_delete_button_clicked_cb(self, widget, data=None):
msg = (_('Are you sure you want to delete the account %s?')) % (acc.get_name());

dia = Gtk.MessageDialog(self.window,
Gtk.DIALOG_MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MESSAGE_QUESTION,
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.QUESTION,
Gtk.ButtonsType.YES_NO,
msg)
dia.show_all()
if dia.run() == Gtk.RESPONSE_YES:
if dia.run() == Gtk.ResponseType.YES:
self.am.del_account(acc, True)
dia.hide()

Expand Down Expand Up @@ -238,10 +238,12 @@ def tool_play_toggled_cb (self, widget, data=None):
Controller.get_instance().set_active(widget.get_active())

def account_deleted_cb(self, widget, acc):
for i in range(len(self.main_store)):
if self.main_store[i][1] == acc.get_name():
del self.main_store[i]
break
selection = self.main_account_tree.get_selection()
if selection:
model, paths = selection.get_selected_rows()
for path in paths:
citer = self.main_store.get_iter(path)
self.main_store.remove(citer)

def window_delete_event_cb (self, widget, event, data=None):
if self.dialog_only:
Expand Down

0 comments on commit e4eabf5

Please sign in to comment.