2 plugins

This commit is contained in:
ingvar1995 2016-05-28 23:08:40 +03:00
parent 96894cd651
commit 6c9444ef5e
7 changed files with 306 additions and 0 deletions

2
CopyableToxId/toxid.pro Normal file
View file

@ -0,0 +1,2 @@
SOURCES = toxid.py
TRANSLATIONS = toxid/en_GB.ts toxid/ru_RU.ts

119
CopyableToxId/toxid.py Normal file
View file

@ -0,0 +1,119 @@
import plugin_super_class
from PySide import QtGui, QtCore
import json
class CopyableToxId(plugin_super_class.PluginSuperClass):
def __init__(self, *args):
super(CopyableToxId, self).__init__('CopyableToxId', 'toxid', *args)
self._data = json.loads(self.load_settings())
self._copy = False
self._timer = QtCore.QTimer()
self._timer.timeout.connect(lambda: self.timer())
self.load_translator()
def get_description(self):
return QtGui.QApplication.translate("TOXID", 'Plugin which allows you to copy TOX ID of your friend easily.', None, QtGui.QApplication.UnicodeUTF8)
def get_window(self):
inst = self
class Window(QtGui.QWidget):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(QtCore.QRect(450, 300, 350, 100))
self.send = QtGui.QCheckBox(self)
self.send.setGeometry(QtCore.QRect(20, 10, 310, 25))
self.send.setText(QtGui.QApplication.translate("TOXID", "Send my TOX ID to contacts", None, QtGui.QApplication.UnicodeUTF8))
self.setWindowTitle(QtGui.QApplication.translate("TOXID", "CopyableToxID", None, QtGui.QApplication.UnicodeUTF8))
self.send.clicked.connect(self.update)
self.send.setChecked(inst._data['send_id'])
self.help = QtGui.QPushButton(self)
self.help.setGeometry(QtCore.QRect(20, 40, 200, 25))
self.help.setText(QtGui.QApplication.translate("TOXID", "List of commands", None, QtGui.QApplication.UnicodeUTF8))
self.help.clicked.connect(lambda: inst.command('help'))
def update(self):
inst._data['send_id'] = self.send.isChecked()
inst.save_settings(json.dumps(inst._data))
return Window()
def lossless_packet(self, data, friend_number):
if len(data):
self._data['id'] = filter(lambda x: not x.startswith(data[:64]), self._data['id'])
self._data['id'].append(data)
if self._copy:
self._timer.stop()
self._copy = False
clipboard = QtGui.QApplication.clipboard()
clipboard.setText(data)
self.save_settings(json.dumps(self._data))
elif self._data['send_id']:
self.send_lossless(self._tox.self_get_address(), friend_number)
def error(self):
msgbox = QtGui.QMessageBox()
title = QtGui.QApplication.translate("TOXID", "Error", None, QtGui.QApplication.UnicodeUTF8)
msgbox.setWindowTitle(title.format(self._name))
text = QtGui.QApplication.translate("TOXID", "Tox ID cannot be copied", None, QtGui.QApplication.UnicodeUTF8)
msgbox.setText(text)
msgbox.exec_()
def timer(self):
self._copy = False
self.error()
self._timer.stop()
def friend_connected(self, friend_number):
self.send_lossless('', friend_number)
def command(self, text):
if text == 'copy':
num = self._profile.get_active_number()
if num == -1:
return
elif text.startswith('copy '):
num = int(text[5:])
if num < 0:
return
elif text == 'enable':
self._copy = True
return
elif text == 'disable':
self._copy = False
return
elif text == 'help':
msgbox = QtGui.QMessageBox()
title = QtGui.QApplication.translate("TOXID", "List of commands for plugin CopyableToxID", None, QtGui.QApplication.UnicodeUTF8)
msgbox.setWindowTitle(title)
text = QtGui.QApplication.translate("TOXID", """Commands:
copy: copy TOX ID of current friend
copy <friend_number>: copy TOX ID of friend with specified number
enable: allow send your TOX ID to friends
disable: disallow send your TOX ID to friends
help: show this help""", None, QtGui.QApplication.UnicodeUTF8)
msgbox.setText(text)
msgbox.exec_()
return
else:
return
public_key = self._tox.friend_get_public_key(num)
arr = filter(lambda x: x.startswith(public_key), self._data['id'])
if len(arr):
clipboard = QtGui.QApplication.clipboard()
clipboard.setText(arr[0])
elif self._profile.get_friend_by_number(num).status is not None:
self._copy = True
self.send_lossless('', num)
self._timer.start(2000)
else:
self.error()
def get_menu(self, menu, num):
act = QtGui.QAction(QtGui.QApplication.translate("TOXID", "Copy TOX ID", None, QtGui.QApplication.UnicodeUTF8), menu)
friend = self._profile.get_friend(num)
act.connect(act, QtCore.SIGNAL("triggered()"), lambda: self.command('copy ' + str(friend.number)))
return [act]

View file

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="1.1">
<context>
<name>TOXID</name>
<message>
<location filename="toxid.py" line="19"/>
<source>Plugin which allows you to copy TOX ID of your friend easily.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="toxid.py" line="29"/>
<source>Send my TOX ID to contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="toxid.py" line="30"/>
<source>CopyableToxID</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="toxid.py" line="35"/>
<source>List of commands</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="toxid.py" line="60"/>
<source>Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="toxid.py" line="62"/>
<source>Tox ID cannot be copied</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="toxid.py" line="87"/>
<source>List of commands for plugin CopyableToxID</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="toxid.py" line="94"/>
<source>Commands:
copy: copy TOX ID of current friend
copy &lt;friend_number&gt;: copy TOX ID of friend with specified number
enable: allow send your TOX ID to friends
disable: disallow send your TOX ID to friends
help: show this help</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="toxid.py" line="112"/>
<source>Copy TOX ID</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

Binary file not shown.

View file

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="ru_RU">
<context>
<name>TOXID</name>
<message>
<location filename="toxid.py" line="19"/>
<source>Plugin which allows you to copy TOX ID of your friend easily.</source>
<translation>Плагин, который позволяет копировать TOX ID друзей с легкостью.</translation>
</message>
<message>
<location filename="toxid.py" line="29"/>
<source>Send my TOX ID to contacts</source>
<translation>Отправлять мой TOX ID контактам</translation>
</message>
<message>
<location filename="toxid.py" line="30"/>
<source>CopyableToxID</source>
<translation>CopyableToxId</translation>
</message>
<message>
<location filename="toxid.py" line="35"/>
<source>List of commands</source>
<translation>Список команд</translation>
</message>
<message>
<location filename="toxid.py" line="60"/>
<source>Error</source>
<translation>Ошибка</translation>
</message>
<message>
<location filename="toxid.py" line="62"/>
<source>Tox ID cannot be copied</source>
<translation>Tox ID не может быть скопирован</translation>
</message>
<message>
<location filename="toxid.py" line="87"/>
<source>List of commands for plugin CopyableToxID</source>
<translation>Список команд для плагина CopyableToxID</translation>
</message>
<message>
<location filename="toxid.py" line="94"/>
<source>Commands:
copy: copy TOX ID of current friend
copy &lt;friend_number&gt;: copy TOX ID of friend with specified number
enable: allow send your TOX ID to friends
disable: disallow send your TOX ID to friends
help: show this help</source>
<translation>Команды:
copy: копировать TOX ID текущего друга
copy &lt;номерруга&gt;: копировать TOX ID друга с заданным номером
enable: разрешить отправку TOX ID друзьям
disable: запретить отправку TOX ID друзьям
help: показать справку</translation>
</message>
<message>
<location filename="toxid.py" line="112"/>
<source>Copy TOX ID</source>
<translation>Копировать TOX ID</translation>
</message>
</context>
</TS>

View file

@ -0,0 +1 @@
{"send_id": true, "id": []}