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
b9686472
Commit
b9686472
authored
Jun 17, 2013
by
Dan Pascu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored some code
parent
3f778101
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
46 deletions
+49
-46
mainwindow.py
blink/mainwindow.py
+22
-19
presence.py
blink/presence.py
+27
-27
No files found.
blink/mainwindow.py
View file @
b9686472
...
...
@@ -51,6 +51,8 @@ class MainWindow(base_class, ui_class):
notification_center
.
add_observer
(
self
,
name
=
'SIPAccountGotPendingWatcher'
)
notification_center
.
add_observer
(
self
,
sender
=
AccountManager
())
icon_manager
=
IconManager
()
self
.
pending_watcher_dialogs
=
[]
self
.
mwi_icons
=
[
QIcon
(
Resources
.
get
(
'icons/mwi-
%
d.png'
%
i
))
for
i
in
xrange
(
0
,
11
)]
...
...
@@ -65,7 +67,7 @@ class MainWindow(base_class, ui_class):
self
.
default_icon_path
=
Resources
.
get
(
'icons/default-avatar.png'
)
self
.
default_icon
=
QIcon
(
self
.
default_icon_path
)
self
.
last_icon_directory
=
os
.
path
.
expanduser
(
'~'
)
self
.
set_user_icon
(
IconManager
()
.
get
(
'avatar'
))
self
.
set_user_icon
(
icon_manager
.
get
(
'avatar'
))
self
.
active_sessions_label
.
hide
()
self
.
enable_call_buttons
(
False
)
...
...
@@ -369,31 +371,31 @@ class MainWindow(base_class, ui_class):
self
.
activity_note
.
setEnabled
(
True
)
if
not
self
.
account_state
.
state
.
internal
:
self
.
saved_account_state
=
None
settings
=
BlinkSettings
()
settings
.
presence
.
current_state
=
PresenceState
(
self
.
account_state
.
state
,
self
.
account_state
.
note
)
settings
.
presence
.
state_history
=
[
PresenceState
(
state
,
note
)
for
state
,
note
in
self
.
account_state
.
history
]
settings
.
save
()
blink_
settings
=
BlinkSettings
()
blink_
settings
.
presence
.
current_state
=
PresenceState
(
self
.
account_state
.
state
,
self
.
account_state
.
note
)
blink_
settings
.
presence
.
state_history
=
[
PresenceState
(
state
,
note
)
for
state
,
note
in
self
.
account_state
.
history
]
blink_
settings
.
save
()
def
_SH_AccountStateClicked
(
self
,
checked
):
filename
=
QFileDialog
.
getOpenFileName
(
self
,
u'Select Icon'
,
self
.
last_icon_directory
,
u"Images (*.png *.tiff *.jpg *.xmp *.svg)"
)
if
filename
:
self
.
last_icon_directory
=
os
.
path
.
dirname
(
filename
)
filename
=
filename
if
os
.
path
.
realpath
(
filename
)
!=
os
.
path
.
realpath
(
self
.
default_icon_path
)
else
None
settings
=
BlinkSettings
()
blink_
settings
=
BlinkSettings
()
icon_manager
=
IconManager
()
if
filename
is
not
None
:
icon
=
icon_manager
.
store_file
(
'avatar'
,
filename
)
try
:
hash
=
hashlib
.
sha512
(
open
(
icon
.
filename
)
.
read
())
.
hexdigest
()
except
Exception
:
settings
.
presence
.
icon
=
None
icon_contents
=
icon_manager
.
get_image
(
'avatar'
)
if
icon_contents
is
not
None
:
hash
=
hashlib
.
sha512
(
icon_contents
)
.
hexdigest
()
blink_settings
.
presence
.
icon
=
IconDescriptor
(
'file://'
+
icon
.
filename
,
hash
)
else
:
settings
.
presence
.
icon
=
IconDescriptor
(
'file://'
+
icon
.
filename
,
hash
)
icon_manager
.
remove
(
'avatar'
)
blink_settings
.
presence
.
icon
=
None
else
:
icon_manager
.
remove
(
'avatar'
)
icon
=
None
settings
.
presence
.
icon
=
None
settings
.
save
()
blink_settings
.
presence
.
icon
=
None
blink_settings
.
save
()
def
_SH_ActivityNoteEditingFinished
(
self
):
self
.
activity_note
.
clearFocus
()
...
...
@@ -610,10 +612,10 @@ class MainWindow(base_class, ui_class):
self
.
load_audio_devices
()
notification
.
center
.
add_observer
(
self
,
name
=
'CFGSettingsObjectDidChange'
)
notification
.
center
.
add_observer
(
self
,
name
=
'AudioDevicesDidChange'
)
settings
=
BlinkSettings
()
self
.
account_state
.
history
=
[(
item
.
state
,
item
.
note
)
for
item
in
settings
.
presence
.
state_history
]
state
=
getattr
(
AccountState
,
settings
.
presence
.
current_state
.
state
,
AccountState
.
Available
)
self
.
account_state
.
setState
(
state
,
settings
.
presence
.
current_state
.
note
)
blink_
settings
=
BlinkSettings
()
self
.
account_state
.
history
=
[(
item
.
state
,
item
.
note
)
for
item
in
blink_
settings
.
presence
.
state_history
]
state
=
getattr
(
AccountState
,
blink_
settings
.
presence
.
current_state
.
state
,
AccountState
.
Available
)
self
.
account_state
.
setState
(
state
,
blink_
settings
.
presence
.
current_state
.
note
)
def
_NH_AudioDevicesDidChange
(
self
,
notification
):
for
action
in
self
.
output_device_menu
.
actions
():
...
...
@@ -640,6 +642,7 @@ class MainWindow(base_class, ui_class):
def
_NH_CFGSettingsObjectDidChange
(
self
,
notification
):
settings
=
SIPSimpleSettings
()
blink_settings
=
BlinkSettings
()
icon_manager
=
IconManager
()
if
notification
.
sender
is
settings
:
if
'audio.silent'
in
notification
.
data
.
modified
:
self
.
silent_action
.
setChecked
(
settings
.
audio
.
silent
)
...
...
@@ -672,7 +675,7 @@ class MainWindow(base_class, ui_class):
state
=
getattr
(
AccountState
,
blink_settings
.
presence
.
current_state
.
state
,
AccountState
.
Available
)
self
.
account_state
.
setState
(
state
,
blink_settings
.
presence
.
current_state
.
note
)
if
'presence.icon'
in
notification
.
data
.
modified
:
self
.
set_user_icon
(
IconManager
()
.
get
(
'avatar'
))
self
.
set_user_icon
(
icon_manager
.
get
(
'avatar'
))
if
'presence.offline_note'
in
notification
.
data
.
modified
:
# TODO: set offline note -Saul
pass
...
...
blink/presence.py
View file @
b9686472
...
...
@@ -158,29 +158,29 @@ class PresencePublicationHandler(object):
return
doc
def
set_xcap_offline_note
(
self
,
account
=
None
):
settings
=
BlinkSettings
()
blink_
settings
=
BlinkSettings
()
if
not
account
:
account_manager
=
AccountManager
()
accounts
=
[
account
for
account
in
account_manager
.
get_accounts
()
if
hasattr
(
account
,
'xcap'
)
and
account
.
xcap
.
discovered
]
else
:
accounts
=
[
account
]
for
account
in
accounts
:
if
settings
.
presence
.
offline_note
:
account
.
xcap_manager
.
set_offline_status
(
OfflineStatus
(
self
.
build_offline_pidf
(
account
,
settings
.
presence
.
offline_note
)))
if
blink_
settings
.
presence
.
offline_note
:
account
.
xcap_manager
.
set_offline_status
(
OfflineStatus
(
self
.
build_offline_pidf
(
account
,
blink_
settings
.
presence
.
offline_note
)))
else
:
account
.
xcap_manager
.
set_offline_status
(
None
)
def
set_xcap_icon
(
self
,
account
=
None
):
settings
=
BlinkSettings
()
blink_
settings
=
BlinkSettings
()
if
not
account
:
account_manager
=
AccountManager
()
accounts
=
[
account
for
account
in
account_manager
.
get_accounts
()
if
hasattr
(
account
,
'xcap'
)
and
account
.
xcap
.
discovered
]
else
:
accounts
=
[
account
]
icon
=
None
if
settings
.
presence
.
icon
:
if
blink_
settings
.
presence
.
icon
:
try
:
data
=
open
(
settings
.
presence
.
icon
.
url
.
path
)
.
read
()
data
=
open
(
blink_
settings
.
presence
.
icon
.
url
.
path
)
.
read
()
except
Exception
:
pass
else
:
...
...
@@ -190,14 +190,14 @@ class PresencePublicationHandler(object):
@
run_in_gui_thread
def
_save_icon
(
self
,
icon_data
,
icon_hash
):
settings
=
BlinkSettings
()
if
None
not
in
(
icon_data
,
icon_hash
)
:
icon
=
IconManager
()
.
store_data
(
'avatar'
,
icon_data
)
i
f
icon
:
settings
.
presence
.
icon
=
IconDescriptor
(
'file://'
+
icon
.
filename
,
icon_hash
)
blink_
settings
=
BlinkSettings
()
if
icon_data
is
not
None
is
not
icon_hash
:
icon
_manager
=
IconManager
(
)
i
con
=
icon_manager
.
store_data
(
'avatar'
,
icon_data
)
blink_settings
.
presence
.
icon
=
IconDescriptor
(
'file://'
+
icon
.
filename
,
icon_hash
)
if
icon
is
not
None
else
None
else
:
settings
.
presence
.
icon
=
None
settings
.
save
()
blink_
settings
.
presence
.
icon
=
None
blink_
settings
.
save
()
@
run_in_twisted_thread
def
handle_notification
(
self
,
notification
):
...
...
@@ -205,8 +205,7 @@ class PresencePublicationHandler(object):
handler
(
notification
)
def
_NH_CFGSettingsObjectDidChange
(
self
,
notification
):
settings
=
BlinkSettings
()
if
notification
.
sender
is
settings
:
if
notification
.
sender
is
BlinkSettings
():
if
'presence.offline_note'
in
notification
.
data
.
modified
:
self
.
set_xcap_offline_note
()
if
'presence.icon'
in
notification
.
data
.
modified
:
...
...
@@ -248,7 +247,7 @@ class PresencePublicationHandler(object):
services
=
[
service
for
service
in
pidf_doc
.
services
if
service
.
status
.
extended
is
not
None
]
if
not
services
:
return
settings
=
BlinkSettings
()
blink_
settings
=
BlinkSettings
()
services
.
sort
(
key
=
lambda
obj
:
obj
.
timestamp
.
value
if
obj
.
timestamp
else
epoch
,
reverse
=
True
)
service
=
services
[
0
]
if
service
.
id
in
(
'SID-
%
s'
%
uuid
.
UUID
(
SIPSimpleSettings
()
.
instance_id
),
'SID-
%
s'
%
hashlib
.
md5
(
notification
.
sender
.
id
)
.
hexdigest
()):
...
...
@@ -260,15 +259,15 @@ class PresencePublicationHandler(object):
status
=
'Invisible'
note
=
None
new_state
=
PresenceState
(
status
,
note
)
settings
.
presence
.
current_state
=
new_state
blink_
settings
.
presence
.
current_state
=
new_state
if
new_state
.
note
:
try
:
state
=
next
(
state
for
state
in
settings
.
presence
.
state_history
if
state
==
new_state
)
state
=
next
(
state
for
state
in
blink_
settings
.
presence
.
state_history
if
state
==
new_state
)
except
StopIteration
:
settings
.
presence
.
state_history
=
[
new_state
]
+
settings
.
presence
.
state_history
blink_settings
.
presence
.
state_history
=
[
new_state
]
+
blink_
settings
.
presence
.
state_history
else
:
settings
.
presence
.
state_history
=
[
new_state
]
+
[
state
for
state
in
settings
.
presence
.
state_history
if
state
!=
new_state
]
settings
.
save
()
blink_settings
.
presence
.
state_history
=
[
new_state
]
+
[
state
for
state
in
blink_
settings
.
presence
.
state_history
if
state
!=
new_state
]
blink_
settings
.
save
()
def
_NH_XCAPManagerDidDiscoverServerCapabilities
(
self
,
notification
):
account
=
notification
.
sender
.
account
...
...
@@ -277,7 +276,7 @@ class PresencePublicationHandler(object):
def
_NH_XCAPManagerDidReloadData
(
self
,
notification
):
account
=
notification
.
sender
.
account
settings
=
BlinkSettings
()
blink_
settings
=
BlinkSettings
()
offline_status
=
notification
.
data
.
offline_status
status_icon
=
notification
.
data
.
status_icon
...
...
@@ -293,13 +292,13 @@ class PresencePublicationHandler(object):
else
:
offline_note
=
unicode
(
note
)
settings
.
presence
.
offline_note
=
offline_note
settings
.
save
()
blink_
settings
.
presence
.
offline_note
=
offline_note
blink_
settings
.
save
()
if
status_icon
:
icon_desc
=
IconDescriptor
(
notification
.
sender
.
status_icon
.
uri
,
notification
.
sender
.
status_icon
.
etag
)
icon_hash
=
hashlib
.
sha512
(
status_icon
.
data
)
.
hexdigest
()
if
settings
.
presence
.
icon
and
settings
.
presence
.
icon
.
etag
==
icon_hash
:
if
blink_settings
.
presence
.
icon
and
blink_
settings
.
presence
.
icon
.
etag
==
icon_hash
:
# Icon didn't change
pass
else
:
...
...
@@ -509,8 +508,9 @@ class PendingWatcherDialog(base_class, ui_class):
self
.
contact
=
None
else
:
display_name
=
self
.
contact
.
name
icon
=
IconManager
()
.
get
(
self
.
contact
.
id
)
if
icon
:
icon_manager
=
IconManager
()
icon
=
icon_manager
.
get
(
self
.
contact
.
id
)
if
icon
is
not
None
:
self
.
user_icon
.
setPixmap
(
icon
.
pixmap
(
32
))
self
.
account_label
.
setText
(
u'For account
%
s'
%
account
.
id
)
self
.
name_label
.
setText
(
display_name
or
uri
)
...
...
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