Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gajim-plugins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evert Mouw
gajim-plugins
Commits
027fd63f
Commit
027fd63f
authored
12 years ago
by
Dicson
Browse files
Options
Downloads
Patches
Plain Diff
UrlShortenerPlugin.shortening links in outgoing message
parent
0c1b1395
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
url_shortener/config_dialog.ui
+39
-16
39 additions, 16 deletions
url_shortener/config_dialog.ui
url_shortener/manifest.ini
+2
-2
2 additions, 2 deletions
url_shortener/manifest.ini
url_shortener/url_shortener.py
+49
-9
49 additions, 9 deletions
url_shortener/url_shortener.py
with
90 additions
and
27 deletions
url_shortener/config_dialog.ui
+
39
−
16
View file @
027fd63f
...
...
@@ -4,35 +4,58 @@
<!-- interface-naming-policy toplevel-contextual -->
<object
class=
"GtkWindow"
id=
"window1"
>
<child>
<object
class=
"Gtk
H
Box"
id=
"
h
box1"
>
<object
class=
"Gtk
V
Box"
id=
"
v
box1"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"
extension_events"
>
al
l
</property>
<property
name=
"
orientation"
>
vertica
l
</property>
<child>
<object
class=
"Gtk
Label
"
id=
"
avatar_size_lebel
"
>
<object
class=
"Gtk
HBox
"
id=
"
hbox1
"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"xalign"
>
0.029999999329447746
</property>
<property
name=
"label"
translatable=
"yes"
>
The maximum length not be shortened links(chars)
</property>
<property
name=
"track_visited_links"
>
False
</property>
<property
name=
"extension_events"
>
all
</property>
<child>
<object
class=
"GtkLabel"
id=
"avatar_size_lebel"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"xalign"
>
0.029999999329447746
</property>
<property
name=
"label"
translatable=
"yes"
>
The maximum length not be shortened links(chars)
</property>
<property
name=
"track_visited_links"
>
False
</property>
</object>
<packing>
<property
name=
"expand"
>
False
</property>
<property
name=
"fill"
>
False
</property>
<property
name=
"position"
>
0
</property>
</packing>
</child>
<child>
<object
class=
"GtkSpinButton"
id=
"max_chars"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
True
</property>
<property
name=
"invisible_char"
>
●
</property>
<property
name=
"width_chars"
>
6
</property>
<property
name=
"snap_to_ticks"
>
True
</property>
<property
name=
"numeric"
>
True
</property>
<signal
name=
"value_changed"
handler=
"avatar_size_value_changed"
/>
</object>
<packing>
<property
name=
"expand"
>
False
</property>
<property
name=
"fill"
>
False
</property>
<property
name=
"position"
>
1
</property>
</packing>
</child>
</object>
<packing>
<property
name=
"expand"
>
False
</property>
<property
name=
"fill"
>
False
</property>
<property
name=
"position"
>
0
</property>
</packing>
</child>
<child>
<object
class=
"GtkSpinButton"
id=
"max_chars"
>
<object
class=
"GtkCheckButton"
id=
"shorten_outgoing"
>
<property
name=
"label"
translatable=
"yes"
>
shorten links in outgoing messages
</property>
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
True
</property>
<property
name=
"invisible_char"
>
●
</property>
<property
name=
"width_chars"
>
6
</property>
<property
name=
"snap_to_ticks"
>
True
</property>
<property
name=
"numeric"
>
True
</property>
<signal
name=
"value_changed"
handler=
"avatar_size_value_changed"
/>
<property
name=
"receives_default"
>
False
</property>
<property
name=
"active"
>
True
</property>
<property
name=
"draw_indicator"
>
True
</property>
<signal
name=
"toggled"
handler=
"shorten_outgoing_toggled"
/>
</object>
<packing>
<property
name=
"expand"
>
False
</property>
<property
name=
"fill"
>
False
</property>
<property
name=
"position"
>
1
</property>
</packing>
</child>
...
...
This diff is collapsed.
Click to expand it.
url_shortener/manifest.ini
+
2
−
2
View file @
027fd63f
[info]
name:
Url
Shortener
short_name:
url_shortener
version:
0.
1
description:
Plugin
that
allows
users
to
shorten
a
long
URL
in
received
messages.
version:
0.
2
description:
Plugin
that
allows
users
to
shorten
a
long
URL
in
messages.
For
example,
you
can
turn
this
link:
http://maps.google.com/maps?
f
=
d&saddr=New+York+Penn+Station&daddr=9th+Ave+%26+14th+St,+New+York,+NY&hl=en&geocode=&mra=ls&dirflg=r&date=11%2F12%2F08&time=4:13pm&ttype=dep&noexp=0&noal=0&sort=&sll=40.746175,-73.998395&sspn=0.014468,0.036392&ie=UTF8&z=14
Into
this
link:
...
...
This diff is collapsed.
Click to expand it.
url_shortener/url_shortener.py
+
49
−
9
View file @
027fd63f
...
...
@@ -5,10 +5,14 @@ import json
import
urllib
import
urllib2
from
common
import
gajim
from
common
import
ged
from
plugins
import
GajimPlugin
from
plugins.helpers
import
log_calls
from
plugins.gui
import
GajimPluginConfigDialog
APIKEY
=
'
R_fcba926fc7978bd19acbca73ec82b2be
'
USER
=
'
dicson
'
class
UrlShortenerPlugin
(
GajimPlugin
):
@log_calls
(
'
UrlShortenerPlugin
'
)
def
init
(
self
):
...
...
@@ -28,10 +32,42 @@ class UrlShortenerPlugin(GajimPlugin):
'
print_special_text
'
:
(
self
.
print_special_text
,
self
.
print_special_text1
),}
self
.
config_default_values
=
{
'
MAX_CHARS
'
:
(
50
,
_
(
'
MAX_CHARS(30-...)
'
))}
'
MAX_CHARS
'
:
(
50
,
_
(
'
MAX_CHARS(30-...)
'
)),
'
SHORTEN_OUTGOING
'
:
(
False
,
''
),}
self
.
events_handlers
[
'
message-outgoing
'
]
=
(
ged
.
OUT_PRECORE
,
self
.
handle_outgoing_msg
)
self
.
chat_control
=
None
self
.
controls
=
[]
def
handle_outgoing_msg
(
self
,
event
):
if
not
event
.
message
:
return
if
not
self
.
config
[
'
SHORTEN_OUTGOING
'
]:
return
iterator
=
gajim
.
interface
.
basic_pattern_re
.
finditer
(
event
.
message
)
for
match
in
iterator
:
start
,
end
=
match
.
span
()
link
=
event
.
message
[
start
:
end
]
if
len
(
link
)
<
self
.
config
[
'
MAX_CHARS
'
]:
continue
short_link
=
None
try
:
params
=
urllib
.
urlencode
({
'
longUrl
'
:
link
,
'
login
'
:
USER
,
'
apiKey
'
:
APIKEY
,
'
format
'
:
'
json
'
})
req
=
urllib2
.
Request
(
'
http://api.bit.ly/v3/shorten?%s
'
%
params
)
response
=
urllib2
.
urlopen
(
req
)
j
=
json
.
load
(
response
)
if
j
[
'
status_code
'
]
==
200
:
short_link
=
j
[
'
data
'
][
'
url
'
]
except
urllib2
.
HTTPError
,
e
:
pass
if
short_link
:
event
.
message
=
event
.
message
.
replace
(
link
,
short_link
)
event
.
callback_args
[
1
]
=
event
.
message
@log_calls
(
'
UrlShortenerPlugin
'
)
def
connect_with_chat_control
(
self
,
chat_control
):
self
.
chat_control
=
chat_control
...
...
@@ -59,8 +95,6 @@ class UrlShortenerPlugin(GajimPlugin):
class
Base
(
object
):
def
__init__
(
self
,
plugin
,
chat_control
):
self
.
user
=
'
dicson
'
self
.
apikey
=
'
R_fcba926fc7978bd19acbca73ec82b2be
'
self
.
plugin
=
plugin
self
.
chat_control
=
chat_control
self
.
textview
=
self
.
chat_control
.
conv_textview
...
...
@@ -99,8 +133,8 @@ class Base(object):
def
insert_hyperlink
(
self
,
mark
,
special_text
,
ttt
):
try
:
params
=
urllib
.
urlencode
({
'
longUrl
'
:
special_text
,
'
login
'
:
self
.
user
,
'
apiKey
'
:
self
.
apikey
,
'
login
'
:
USER
,
'
apiKey
'
:
APIKEY
,
'
format
'
:
'
json
'
})
req
=
urllib2
.
Request
(
'
http://api.bit.ly/v3/shorten?%s
'
%
params
)
response
=
urllib2
.
urlopen
(
req
)
...
...
@@ -132,8 +166,8 @@ class Base(object):
if
text
.
startswith
(
'
http://bit.ly/
'
):
try
:
params
=
urllib
.
urlencode
({
'
shortUrl
'
:
text
,
'
login
'
:
self
.
user
,
'
apiKey
'
:
self
.
apikey
,
'
login
'
:
USER
,
'
apiKey
'
:
APIKEY
,
'
format
'
:
'
json
'
})
req
=
urllib2
.
Request
(
'
http://api.bit.ly/v3/expand?%s
'
\
%
params
)
...
...
@@ -161,17 +195,23 @@ class UrlShortenerPluginConfigDialog(GajimPluginConfigDialog):
'
config_dialog.ui
'
)
self
.
xml
=
gtk
.
Builder
()
self
.
xml
.
set_translation_domain
(
'
gajim_plugins
'
)
self
.
xml
.
add_objects_from_file
(
self
.
GTK_BUILDER_FILE_PATH
,
[
'
h
box1
'
])
self
.
xml
.
add_objects_from_file
(
self
.
GTK_BUILDER_FILE_PATH
,
[
'
v
box1
'
])
self
.
max_chars_spinbutton
=
self
.
xml
.
get_object
(
'
max_chars
'
)
self
.
max_chars_spinbutton
.
get_adjustment
().
set_all
(
30
,
30
,
99999
,
1
,
10
,
0
)
hbox
=
self
.
xml
.
get_object
(
'
hbox1
'
)
self
.
shorten_outgoing
=
self
.
xml
.
get_object
(
'
shorten_outgoing
'
)
print
self
.
shorten_outgoing
hbox
=
self
.
xml
.
get_object
(
'
vbox1
'
)
self
.
child
.
pack_start
(
hbox
)
self
.
xml
.
connect_signals
(
self
)
def
on_run
(
self
):
self
.
max_chars_spinbutton
.
set_value
(
self
.
plugin
.
config
[
'
MAX_CHARS
'
])
self
.
shorten_outgoing
.
set_active
(
self
.
plugin
.
config
[
'
SHORTEN_OUTGOING
'
])
def
avatar_size_value_changed
(
self
,
spinbutton
):
self
.
plugin
.
config
[
'
MAX_CHARS
'
]
=
spinbutton
.
get_value
()
def
shorten_outgoing_toggled
(
self
,
checkbutton
):
self
.
plugin
.
config
[
'
SHORTEN_OUTGOING
'
]
=
checkbutton
.
get_active
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment