Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vmj-qt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
vmj-qt
Commits
bc995f44
Commit
bc995f44
authored
Sep 20, 2010
by
Dan Pascu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified google authorization token class definition and how is used
parent
5390a8c7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
43 deletions
+35
-43
__init__.py
blink/__init__.py
+4
-0
datatypes.py
blink/configuration/datatypes.py
+19
-26
contacts.py
blink/contacts.py
+3
-3
mainwindow.py
blink/mainwindow.py
+9
-14
No files found.
blink/__init__.py
View file @
bc995f44
...
...
@@ -30,6 +30,7 @@ from sipsimple.configuration.settings import SIPSimpleSettings
from
sipsimple.util
import
makedirs
from
blink.configuration.account
import
AccountExtension
,
BonjourAccountExtension
from
blink.configuration.datatypes
import
InvalidToken
from
blink.configuration.settings
import
SIPSimpleSettingsExtension
from
blink.logging
import
LogManager
from
blink.mainwindow
import
MainWindow
...
...
@@ -190,9 +191,12 @@ class Blink(QApplication):
def
_NH_SIPApplicationDidStart
(
self
,
notification
):
self
.
fetch_account
()
self
.
main_window
.
show
()
settings
=
SIPSimpleSettings
()
accounts
=
AccountManager
()
.
get_accounts
()
if
not
accounts
or
(
self
.
first_run
and
accounts
==
[
BonjourAccount
()]):
self
.
main_window
.
add_account_dialog
.
open_for_create
()
if
settings
.
google_contacts
.
authorization_token
is
InvalidToken
:
self
.
main_window
.
google_contacts_dialog
.
open_for_incorrect_password
()
self
.
update_manager
.
initialize
()
def
_initialize_sipsimple
(
self
):
...
...
blink/configuration/datatypes.py
View file @
bc995f44
...
...
@@ -3,7 +3,7 @@
"""Definitions of datatypes for use in settings extensions."""
__all__
=
[
'ApplicationDataPath'
,
'SoundFile'
,
'DefaultPath'
,
'CustomSoundFile'
,
'HTTPURL'
,
'
InvalidToken'
,
'Authorization
Token'
]
__all__
=
[
'ApplicationDataPath'
,
'SoundFile'
,
'DefaultPath'
,
'CustomSoundFile'
,
'HTTPURL'
,
'
AuthorizationToken'
,
'Invalid
Token'
]
import
os
import
re
...
...
@@ -113,33 +113,26 @@ class HTTPURL(unicode):
return
value
class
InvalidToken
(
object
):
class
AuthorizationTokenMeta
(
type
):
def
__init__
(
cls
,
name
,
bases
,
dic
):
super
(
AuthorizationTokenMeta
,
cls
)
.
__init__
(
name
,
bases
,
dic
)
cls
.
_instances
=
{}
def
__call__
(
cls
,
*
args
):
if
len
(
args
)
>
1
:
raise
TypeError
(
'
%
s() takes at most 1 argument (
%
d given)'
%
(
cls
.
__name__
,
len
(
args
)))
key
=
args
[
0
]
if
args
else
''
if
key
not
in
cls
.
_instances
:
cls
.
_instances
[
key
]
=
super
(
AuthorizationTokenMeta
,
cls
)
.
__call__
(
*
args
)
return
cls
.
_instances
[
key
]
class
AuthorizationToken
(
str
):
__metaclass__
=
AuthorizationTokenMeta
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
class
AuthorizationToken
(
object
):
def
__init__
(
self
,
token
=
None
):
self
.
token
=
token
def
__getstate__
(
self
):
if
self
.
token
is
InvalidToken
:
return
u'invalid'
if
self
is
InvalidToken
:
return
'InvalidToken'
else
:
return
u'value:
%
s'
%
(
self
.
__dict__
[
'token'
]
)
return
'
%
s(
%
s)'
%
(
self
.
__class__
.
__name__
,
str
.
__repr__
(
self
)
)
def
__setstate__
(
self
,
state
):
match
=
re
.
match
(
r'^(?P<type>invalid|value:)(?P<token>.+?)?$'
,
state
)
if
match
is
None
:
raise
ValueError
(
'illegal value:
%
r'
%
state
)
data
=
match
.
groupdict
()
if
data
.
pop
(
'type'
)
==
'invalid'
:
data
[
'token'
]
=
InvalidToken
self
.
__init__
(
data
[
'token'
])
def
__nonzero__
(
self
):
return
self
.
token
is
not
InvalidToken
def
__repr__
(
self
):
return
'
%
s(
%
r)'
%
(
self
.
__class__
.
__name__
,
self
.
token
)
InvalidToken
=
AuthorizationToken
()
# a valid token is never empty
blink/contacts.py
View file @
bc995f44
...
...
@@ -340,10 +340,10 @@ class GoogleContactsManager(object):
def
_NH_CFGSettingsObjectDidChange
(
self
,
notification
):
if
'google_contacts.authorization_token'
in
notification
.
data
.
modified
:
authorization_token
=
notification
.
sender
.
google_contacts
.
authorization_token
if
self
.
_load_timer
is
not
None
and
self
.
_load_timer
.
active
():
self
.
_load_timer
.
cancel
()
self
.
_load_timer
=
None
authorization_token
=
notification
.
sender
.
google_contacts
.
authorization_token
if
authorization_token
:
call_in_gui_thread
(
self
.
contact_model
.
addGroup
,
self
.
contact_model
.
google_contacts_group
)
self
.
stop_adding_contacts
=
False
...
...
@@ -369,7 +369,7 @@ class GoogleContactsManager(object):
self
.
_load_timer
=
None
settings
=
SIPSimpleSettings
()
self
.
client
.
auth_token
=
ClientLoginToken
(
settings
.
google_contacts
.
authorization_token
.
token
)
self
.
client
.
auth_token
=
ClientLoginToken
(
settings
.
google_contacts
.
authorization_token
)
try
:
if
self
.
group
.
id
is
None
:
...
...
@@ -407,7 +407,7 @@ class GoogleContactsManager(object):
self
.
update_contacts
(
updated_contacts
)
feed
=
self
.
client
.
get_next
(
feed
)
if
feed
.
find_next_link
()
is
not
None
else
None
except
Unauthorized
:
settings
.
google_contacts
.
authorization_token
=
AuthorizationToken
(
InvalidToken
)
settings
.
google_contacts
.
authorization_token
=
InvalidToken
settings
.
save
()
except
(
ConnectionLost
,
RequestError
,
httplib
.
HTTPException
,
socket
.
error
):
self
.
_load_timer
=
reactor
.
callLater
(
60
,
self
.
load_contacts
)
...
...
blink/mainwindow.py
View file @
bc995f44
...
...
@@ -24,6 +24,7 @@ from blink.aboutpanel import AboutPanel
from
blink.accounts
import
AccountModel
,
ActiveAccountModel
,
AddAccountDialog
,
ServerToolsAccountModel
,
ServerToolsWindow
from
blink.contacts
import
BonjourNeighbour
,
Contact
,
ContactGroup
,
ContactEditorDialog
,
ContactModel
,
ContactSearchModel
,
GoogleContactsDialog
from
blink.sessions
import
SessionManager
,
SessionModel
from
blink.configuration.datatypes
import
InvalidToken
from
blink.resources
import
Resources
from
blink.util
import
call_in_auxiliary_thread
,
run_in_gui_thread
from
blink.widgets.buttons
import
SwitchViewButton
...
...
@@ -297,7 +298,7 @@ class MainWindow(base_class, ui_class):
def
_AH_GoogleContactsActionTriggered
(
self
):
settings
=
SIPSimpleSettings
()
if
settings
.
google_contacts
.
authorization_token
:
if
settings
.
google_contacts
.
authorization_token
is
not
None
:
settings
.
google_contacts
.
authorization_token
=
None
settings
.
save
()
else
:
...
...
@@ -515,15 +516,10 @@ class MainWindow(base_class, ui_class):
settings
=
SIPSimpleSettings
()
self
.
silent_action
.
setChecked
(
settings
.
audio
.
silent
)
self
.
silent_button
.
setChecked
(
settings
.
audio
.
silent
)
if
settings
.
google_contacts
.
authorization_token
:
self
.
google_contacts_action
.
setText
(
u'Disable Google Contacts'
)
elif
settings
.
google_contacts
.
authorization_token
is
not
None
:
# Token is invalid
self
.
google_contacts_action
.
setText
(
u'Disable Google Contacts'
)
# Maybe this should be moved to DidStart so that the dialog is shown *after* the MainWindow. -Saul
self
.
google_contacts_dialog
.
open_for_incorrect_password
()
else
:
if
settings
.
google_contacts
.
authorization_token
is
None
:
self
.
google_contacts_action
.
setText
(
u'Enable Google Contacts'
)
else
:
self
.
google_contacts_action
.
setText
(
u'Disable Google Contacts'
)
self
.
google_contacts_action
.
triggered
.
connect
(
self
.
_AH_GoogleContactsActionTriggered
)
account_manager
=
AccountManager
()
notification_center
=
NotificationCenter
()
...
...
@@ -594,13 +590,12 @@ class MainWindow(base_class, ui_class):
action
.
setChecked
(
True
)
if
'google_contacts.authorization_token'
in
notification
.
data
.
modified
:
authorization_token
=
notification
.
sender
.
google_contacts
.
authorization_token
if
authorization_token
:
if
authorization_token
is
None
:
self
.
google_contacts_action
.
setText
(
u'Enable Google Contacts'
)
else
:
self
.
google_contacts_action
.
setText
(
u'Disable Google Contacts'
)
elif
authorization_token
is
not
None
:
# Token is invalid
if
authorization_token
is
InvalidToken
:
self
.
google_contacts_dialog
.
open_for_incorrect_password
()
else
:
self
.
google_contacts_action
.
setText
(
u'Enable Google Contacts'
)
elif
isinstance
(
notification
.
sender
,
(
Account
,
BonjourAccount
)):
account
=
notification
.
sender
if
'enabled'
in
notification
.
data
.
modified
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment