2016-02-17 21:47:43 +01:00
# -*- coding: utf-8 -*-
2016-02-23 21:26:37 +01:00
from menu import *
2016-02-27 16:52:27 +01:00
from profile import *
2016-03-01 22:17:22 +01:00
from list_items import *
2016-06-04 14:19:15 +02:00
from widgets import QRightClickButton , RubberBand , create_menu , MultilineEdit
2016-05-28 12:06:13 +02:00
import plugin_support
2016-02-17 21:47:43 +01:00
2016-03-05 13:44:52 +01:00
class MessageArea ( QtGui . QPlainTextEdit ) :
2016-06-06 20:18:32 +02:00
""" User enters messages here """
2016-03-05 13:44:52 +01:00
def __init__ ( self , parent , form ) :
super ( MessageArea , self ) . __init__ ( parent )
self . parent = form
2016-06-06 20:18:32 +02:00
self . setAcceptDrops ( True )
2016-04-27 20:10:53 +02:00
self . timer = QtCore . QTimer ( self )
self . timer . timeout . connect ( lambda : self . parent . profile . send_typing ( False ) )
2016-03-05 13:44:52 +01:00
def keyPressEvent ( self , event ) :
2016-06-06 20:18:32 +02:00
if event . matches ( QtGui . QKeySequence . Paste ) :
self . pasteEvent ( )
2016-06-08 17:35:40 +02:00
elif event . key ( ) in ( QtCore . Qt . Key_Return , QtCore . Qt . Key_Enter ) :
2016-03-29 16:11:30 +02:00
modifiers = event . modifiers ( )
if modifiers & QtCore . Qt . ControlModifier or modifiers & QtCore . Qt . ShiftModifier :
2016-06-06 20:18:32 +02:00
self . insertPlainText ( ' \n ' )
2016-03-29 16:11:30 +02:00
else :
2016-04-28 19:06:02 +02:00
if self . timer . isActive ( ) :
self . timer . stop ( )
self . parent . profile . send_typing ( False )
2016-05-02 18:46:42 +02:00
self . parent . send_message ( )
2016-04-01 19:44:02 +02:00
elif event . key ( ) == QtCore . Qt . Key_Up and not self . toPlainText ( ) :
self . appendPlainText ( Profile . get_instance ( ) . get_last_message ( ) )
2016-03-05 13:44:52 +01:00
else :
2016-04-27 20:10:53 +02:00
self . parent . profile . send_typing ( True )
if self . timer . isActive ( ) :
self . timer . stop ( )
self . timer . start ( 5000 )
2016-04-02 13:41:06 +02:00
super ( MessageArea , self ) . keyPressEvent ( event )
2016-03-05 13:44:52 +01:00
2016-05-30 20:38:21 +02:00
def contextMenuEvent ( self , event ) :
menu = create_menu ( self . createStandardContextMenu ( ) )
menu . exec_ ( event . globalPos ( ) )
del menu
2016-06-06 20:18:32 +02:00
def dragEnterEvent ( self , e ) :
e . accept ( )
def dragMoveEvent ( self , e ) :
e . accept ( )
def dropEvent ( self , e ) :
if e . mimeData ( ) . hasFormat ( ' text/plain ' ) :
e . accept ( )
self . pasteEvent ( e . mimeData ( ) . text ( ) )
else :
e . ignore ( )
def pasteEvent ( self , text = None ) :
text = text or QtGui . QApplication . clipboard ( ) . text ( )
if text . startswith ( ' file:// ' ) :
self . parent . profile . send_file ( text [ 7 : ] )
else :
self . insertPlainText ( text )
2016-03-05 13:44:52 +01:00
2016-02-21 15:32:38 +01:00
class MainWindow ( QtGui . QMainWindow ) :
2016-02-17 21:47:43 +01:00
2016-06-03 12:48:41 +02:00
def __init__ ( self , tox , reset , tray ) :
2016-02-17 21:47:43 +01:00
super ( MainWindow , self ) . __init__ ( )
2016-03-15 18:05:19 +01:00
self . reset = reset
2016-06-03 12:48:41 +02:00
self . tray = tray
2016-06-06 20:18:32 +02:00
self . setAcceptDrops ( True )
2016-03-15 18:05:19 +01:00
self . initUI ( tox )
2016-02-17 21:47:43 +01:00
2016-02-21 15:32:38 +01:00
def setup_menu ( self , MainWindow ) :
self . menubar = QtGui . QMenuBar ( MainWindow )
self . menubar . setObjectName ( " menubar " )
2016-02-24 18:26:12 +01:00
self . menubar . setNativeMenuBar ( False )
self . menubar . setMinimumSize ( self . width ( ) , 25 )
self . menubar . setMaximumSize ( self . width ( ) , 25 )
self . menubar . setBaseSize ( self . width ( ) , 25 )
2016-05-28 12:06:13 +02:00
2016-02-21 15:32:38 +01:00
self . menuProfile = QtGui . QMenu ( self . menubar )
self . menuProfile . setObjectName ( " menuProfile " )
self . menuSettings = QtGui . QMenu ( self . menubar )
self . menuSettings . setObjectName ( " menuSettings " )
2016-05-28 12:06:13 +02:00
self . menuPlugins = QtGui . QMenu ( self . menubar )
self . menuPlugins . setObjectName ( " menuPlugins " )
2016-02-21 15:32:38 +01:00
self . menuAbout = QtGui . QMenu ( self . menubar )
self . menuAbout . setObjectName ( " menuAbout " )
2016-05-28 12:06:13 +02:00
2016-02-21 15:32:38 +01:00
self . actionAdd_friend = QtGui . QAction ( MainWindow )
self . actionAdd_friend . setObjectName ( " actionAdd_friend " )
self . actionProfile_settings = QtGui . QAction ( MainWindow )
self . actionProfile_settings . setObjectName ( " actionProfile_settings " )
self . actionPrivacy_settings = QtGui . QAction ( MainWindow )
self . actionPrivacy_settings . setObjectName ( " actionPrivacy_settings " )
self . actionInterface_settings = QtGui . QAction ( MainWindow )
self . actionInterface_settings . setObjectName ( " actionInterface_settings " )
self . actionNotifications = QtGui . QAction ( MainWindow )
self . actionNotifications . setObjectName ( " actionNotifications " )
self . actionNetwork = QtGui . QAction ( MainWindow )
self . actionNetwork . setObjectName ( " actionNetwork " )
self . actionAbout_program = QtGui . QAction ( MainWindow )
self . actionAbout_program . setObjectName ( " actionAbout_program " )
self . actionSettings = QtGui . QAction ( MainWindow )
self . actionSettings . setObjectName ( " actionSettings " )
2016-04-24 12:45:11 +02:00
self . audioSettings = QtGui . QAction ( MainWindow )
2016-05-28 12:06:13 +02:00
self . pluginData = QtGui . QAction ( MainWindow )
2016-02-21 15:32:38 +01:00
self . menuProfile . addAction ( self . actionAdd_friend )
self . menuProfile . addAction ( self . actionSettings )
self . menuSettings . addAction ( self . actionPrivacy_settings )
self . menuSettings . addAction ( self . actionInterface_settings )
self . menuSettings . addAction ( self . actionNotifications )
self . menuSettings . addAction ( self . actionNetwork )
2016-04-24 12:45:11 +02:00
self . menuSettings . addAction ( self . audioSettings )
2016-05-28 12:06:13 +02:00
self . menuPlugins . addAction ( self . pluginData )
2016-02-21 15:32:38 +01:00
self . menuAbout . addAction ( self . actionAbout_program )
self . menubar . addAction ( self . menuProfile . menuAction ( ) )
self . menubar . addAction ( self . menuSettings . menuAction ( ) )
2016-05-28 12:06:13 +02:00
self . menubar . addAction ( self . menuPlugins . menuAction ( ) )
2016-02-21 15:32:38 +01:00
self . menubar . addAction ( self . menuAbout . menuAction ( ) )
2016-02-23 21:26:37 +01:00
self . actionAbout_program . triggered . connect ( self . about_program )
self . actionNetwork . triggered . connect ( self . network_settings )
self . actionAdd_friend . triggered . connect ( self . add_contact )
self . actionSettings . triggered . connect ( self . profile_settings )
self . actionPrivacy_settings . triggered . connect ( self . privacy_settings )
self . actionInterface_settings . triggered . connect ( self . interface_settings )
self . actionNotifications . triggered . connect ( self . notification_settings )
2016-04-24 12:45:11 +02:00
self . audioSettings . triggered . connect ( self . audio_settings )
2016-05-28 12:06:13 +02:00
self . pluginData . triggered . connect ( self . plugins_menu )
2016-04-04 11:20:32 +02:00
QtCore . QMetaObject . connectSlotsByName ( MainWindow )
def languageChange ( self , * args , * * kwargs ) :
self . retranslateUi ( )
2016-02-23 21:26:37 +01:00
2016-06-03 12:48:41 +02:00
def event ( self , event ) :
if event . type ( ) == QtCore . QEvent . WindowActivate :
self . tray . setIcon ( QtGui . QIcon ( curr_directory ( ) + ' /images/icon.png ' ) )
return super ( MainWindow , self ) . event ( event )
2016-04-04 11:20:32 +02:00
def retranslateUi ( self ) :
2016-05-28 12:06:13 +02:00
self . menuPlugins . setTitle ( QtGui . QApplication . translate ( " MainWindow " , " Plugins " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . pluginData . setText ( QtGui . QApplication . translate ( " MainWindow " , " List of plugins " , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-02-21 15:32:38 +01:00
self . menuProfile . setTitle ( QtGui . QApplication . translate ( " MainWindow " , " Profile " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . menuSettings . setTitle ( QtGui . QApplication . translate ( " MainWindow " , " Settings " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . menuAbout . setTitle ( QtGui . QApplication . translate ( " MainWindow " , " About " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . actionAdd_friend . setText ( QtGui . QApplication . translate ( " MainWindow " , " Add contact " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . actionProfile_settings . setText ( QtGui . QApplication . translate ( " MainWindow " , " Profile " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . actionPrivacy_settings . setText ( QtGui . QApplication . translate ( " MainWindow " , " Privacy " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . actionInterface_settings . setText ( QtGui . QApplication . translate ( " MainWindow " , " Interface " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . actionNotifications . setText ( QtGui . QApplication . translate ( " MainWindow " , " Notifications " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . actionNetwork . setText ( QtGui . QApplication . translate ( " MainWindow " , " Network " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . actionAbout_program . setText ( QtGui . QApplication . translate ( " MainWindow " , " About program " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . actionSettings . setText ( QtGui . QApplication . translate ( " MainWindow " , " Settings " , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-04-24 12:45:11 +02:00
self . audioSettings . setText ( QtGui . QApplication . translate ( " MainWindow " , " Audio " , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-05-18 23:38:21 +02:00
self . contact_name . setPlaceholderText ( QtGui . QApplication . translate ( " MainWindow " , " Search " , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-05-11 18:35:54 +02:00
self . screenshotButton . setToolTip ( QtGui . QApplication . translate ( " MainWindow " , " Send screenshot " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . fileTransferButton . setToolTip ( QtGui . QApplication . translate ( " MainWindow " , " Send file " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . sendMessageButton . setToolTip ( QtGui . QApplication . translate ( " MainWindow " , " Send message " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . callButton . setToolTip ( QtGui . QApplication . translate ( " MainWindow " , " Start audio call with friend " , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-05-18 23:38:21 +02:00
self . online_contacts . clear ( )
self . online_contacts . addItem ( QtGui . QApplication . translate ( " MainWindow " , " All " , None , QtGui . QApplication . UnicodeUTF8 ) )
self . online_contacts . addItem ( QtGui . QApplication . translate ( " MainWindow " , " Online " , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-05-28 21:43:51 +02:00
self . online_contacts . setCurrentIndex ( int ( Settings . get_instance ( ) [ ' show_online_friends ' ] ) )
2016-02-21 15:32:38 +01:00
2016-02-18 15:02:00 +01:00
def setup_right_bottom ( self , Form ) :
Form . setObjectName ( " right_bottom " )
2016-05-18 23:38:21 +02:00
Form . resize ( 650 , 60 )
2016-03-05 13:44:52 +01:00
self . messageEdit = MessageArea ( Form , self )
2016-05-18 23:38:21 +02:00
self . messageEdit . setGeometry ( QtCore . QRect ( 0 , 3 , 450 , 55 ) )
2016-02-18 15:02:00 +01:00
self . messageEdit . setObjectName ( " messageEdit " )
2016-05-18 23:38:21 +02:00
font = QtGui . QFont ( )
font . setPointSize ( 10 )
self . messageEdit . setFont ( font )
2016-05-08 12:51:56 +02:00
self . screenshotButton = QRightClickButton ( Form )
2016-05-18 23:38:21 +02:00
self . screenshotButton . setGeometry ( QtCore . QRect ( 455 , 3 , 55 , 55 ) )
2016-02-18 15:02:00 +01:00
self . screenshotButton . setObjectName ( " screenshotButton " )
2016-05-08 12:51:56 +02:00
2016-02-18 15:02:00 +01:00
self . fileTransferButton = QtGui . QPushButton ( Form )
2016-05-18 23:38:21 +02:00
self . fileTransferButton . setGeometry ( QtCore . QRect ( 510 , 3 , 55 , 55 ) )
2016-02-18 15:02:00 +01:00
self . fileTransferButton . setObjectName ( " fileTransferButton " )
2016-05-08 12:51:56 +02:00
2016-02-18 15:02:00 +01:00
self . sendMessageButton = QtGui . QPushButton ( Form )
2016-05-18 23:38:21 +02:00
self . sendMessageButton . setGeometry ( QtCore . QRect ( 565 , 3 , 60 , 55 ) )
2016-02-18 15:02:00 +01:00
self . sendMessageButton . setObjectName ( " sendMessageButton " )
2016-03-22 18:32:29 +01:00
2016-06-11 23:40:58 +02:00
pixmap = QtGui . QPixmap ( ' send.png ' )
2016-03-21 15:23:34 +01:00
icon = QtGui . QIcon ( pixmap )
self . sendMessageButton . setIcon ( icon )
2016-05-02 17:27:46 +02:00
self . sendMessageButton . setIconSize ( QtCore . QSize ( 45 , 60 ) )
2016-06-11 23:40:58 +02:00
pixmap = QtGui . QPixmap ( ' file.png ' )
2016-03-21 15:23:34 +01:00
icon = QtGui . QIcon ( pixmap )
self . fileTransferButton . setIcon ( icon )
2016-05-18 23:38:21 +02:00
self . fileTransferButton . setIconSize ( QtCore . QSize ( 40 , 40 ) )
2016-06-11 23:40:58 +02:00
pixmap = QtGui . QPixmap ( ' screenshot.png ' )
2016-03-21 15:23:34 +01:00
icon = QtGui . QIcon ( pixmap )
self . screenshotButton . setIcon ( icon )
2016-05-02 17:27:46 +02:00
self . screenshotButton . setIconSize ( QtCore . QSize ( 40 , 60 ) )
2016-03-22 18:32:29 +01:00
2016-03-16 20:59:15 +01:00
self . fileTransferButton . clicked . connect ( self . send_file )
2016-03-22 13:17:46 +01:00
self . screenshotButton . clicked . connect ( self . send_screenshot )
2016-05-08 12:51:56 +02:00
self . sendMessageButton . clicked . connect ( self . send_message )
self . connect ( self . screenshotButton , QtCore . SIGNAL ( " rightClicked() " ) , lambda : self . send_screenshot ( True ) )
2016-02-18 15:02:00 +01:00
QtCore . QMetaObject . connectSlotsByName ( Form )
2016-05-18 23:38:21 +02:00
def setup_left_center_menu ( self , Form ) :
Form . resize ( 270 , 25 )
self . search_label = QtGui . QLabel ( Form )
self . search_label . setGeometry ( QtCore . QRect ( 3 , 0 , 25 , 25 ) )
pixmap = QtGui . QPixmap ( QtCore . QSize ( 25 , 25 ) )
pixmap . load ( curr_directory ( ) + ' /images/search.png ' )
self . search_label . setScaledContents ( False )
self . search_label . setPixmap ( pixmap . scaled ( 25 , 25 , QtCore . Qt . KeepAspectRatio ) )
2016-03-02 21:55:12 +01:00
self . contact_name = QtGui . QLineEdit ( Form )
2016-05-18 23:38:21 +02:00
self . contact_name . setGeometry ( QtCore . QRect ( 30 , 0 , 120 , 25 ) )
2016-03-02 21:55:12 +01:00
self . contact_name . setObjectName ( " contact_name " )
self . contact_name . textChanged . connect ( self . filtering )
2016-05-18 23:38:21 +02:00
self . online_contacts = QtGui . QComboBox ( Form )
self . online_contacts . setGeometry ( QtCore . QRect ( 150 , 0 , 120 , 25 ) )
self . online_contacts . activated [ int ] . connect ( lambda x : self . filtering ( ) )
2016-02-18 15:02:00 +01:00
QtCore . QMetaObject . connectSlotsByName ( Form )
2016-02-17 21:47:43 +01:00
def setup_left_top ( self , Form ) :
2016-02-18 15:02:00 +01:00
Form . setObjectName ( " left_top " )
2016-03-11 12:37:45 +01:00
Form . setCursor ( QtCore . Qt . PointingHandCursor )
2016-05-18 23:38:21 +02:00
Form . setMinimumSize ( QtCore . QSize ( 250 , 80 ) )
Form . setMaximumSize ( QtCore . QSize ( 250 , 80 ) )
Form . setBaseSize ( QtCore . QSize ( 250 , 80 ) )
2016-03-07 19:00:00 +01:00
self . avatar_label = Form . avatar_label = QtGui . QLabel ( Form )
2016-05-18 23:38:21 +02:00
self . avatar_label . setGeometry ( QtCore . QRect ( 5 , 15 , 64 , 64 ) )
2016-03-07 19:00:00 +01:00
self . avatar_label . setScaledContents ( True )
2016-04-01 19:44:02 +02:00
self . name = Form . name = DataLabel ( Form )
2016-05-18 23:38:21 +02:00
Form . name . setGeometry ( QtCore . QRect ( 80 , 25 , 150 , 25 ) )
2016-02-17 21:47:43 +01:00
font = QtGui . QFont ( )
font . setFamily ( " Times New Roman " )
2016-03-07 19:00:00 +01:00
font . setPointSize ( 14 )
2016-02-17 21:47:43 +01:00
font . setBold ( True )
2016-02-29 16:40:49 +01:00
Form . name . setFont ( font )
Form . name . setObjectName ( " name " )
2016-04-01 19:44:02 +02:00
self . status_message = Form . status_message = DataLabel ( Form )
2016-05-18 23:38:21 +02:00
Form . status_message . setGeometry ( QtCore . QRect ( 80 , 55 , 170 , 20 ) )
2016-03-07 19:00:00 +01:00
font . setPointSize ( 12 )
2016-02-17 21:47:43 +01:00
font . setBold ( False )
2016-02-29 16:40:49 +01:00
Form . status_message . setFont ( font )
Form . status_message . setObjectName ( " status_message " )
self . connection_status = Form . connection_status = StatusCircle ( self )
2016-05-18 23:38:21 +02:00
Form . connection_status . setGeometry ( QtCore . QRect ( 230 , 29 , 64 , 64 ) )
2016-02-29 16:40:49 +01:00
Form . connection_status . setMinimumSize ( QtCore . QSize ( 32 , 32 ) )
Form . connection_status . setMaximumSize ( QtCore . QSize ( 32 , 32 ) )
Form . connection_status . setBaseSize ( QtCore . QSize ( 32 , 32 ) )
2016-03-11 12:37:45 +01:00
self . avatar_label . mouseReleaseEvent = self . profile_settings
self . status_message . mouseReleaseEvent = self . profile_settings
self . name . mouseReleaseEvent = self . profile_settings
self . connection_status . raise_ ( )
2016-02-29 16:40:49 +01:00
Form . connection_status . setObjectName ( " connection_status " )
2016-02-23 13:07:15 +01:00
2016-02-18 15:02:00 +01:00
def setup_right_top ( self , Form ) :
Form . setObjectName ( " Form " )
2016-05-18 23:38:21 +02:00
Form . resize ( 650 , 80 )
2016-03-07 19:00:00 +01:00
self . account_avatar = QtGui . QLabel ( Form )
2016-05-18 23:38:21 +02:00
self . account_avatar . setGeometry ( QtCore . QRect ( 10 , 17 , 64 , 64 ) )
2016-03-07 19:00:00 +01:00
self . account_avatar . setScaledContents ( True )
2016-04-01 19:44:02 +02:00
self . account_name = DataLabel ( Form )
2016-05-18 23:38:21 +02:00
self . account_name . setGeometry ( QtCore . QRect ( 100 , 25 , 400 , 25 ) )
2016-04-28 19:06:02 +02:00
self . account_name . setTextInteractionFlags ( QtCore . Qt . LinksAccessibleByMouse )
2016-02-18 15:02:00 +01:00
font = QtGui . QFont ( )
2016-03-07 19:00:00 +01:00
font . setFamily ( " Times New Roman " )
font . setPointSize ( 14 )
2016-02-18 15:02:00 +01:00
font . setBold ( True )
self . account_name . setFont ( font )
self . account_name . setObjectName ( " account_name " )
2016-04-01 19:44:02 +02:00
self . account_status = DataLabel ( Form )
2016-05-18 23:38:21 +02:00
self . account_status . setGeometry ( QtCore . QRect ( 100 , 45 , 400 , 25 ) )
2016-04-28 19:06:02 +02:00
self . account_status . setTextInteractionFlags ( QtCore . Qt . LinksAccessibleByMouse )
2016-03-07 19:00:00 +01:00
font . setPointSize ( 12 )
2016-02-18 15:02:00 +01:00
font . setBold ( False )
self . account_status . setFont ( font )
self . account_status . setObjectName ( " account_status " )
self . callButton = QtGui . QPushButton ( Form )
2016-03-22 19:00:42 +01:00
self . callButton . setGeometry ( QtCore . QRect ( 550 , 30 , 50 , 50 ) )
2016-02-18 15:02:00 +01:00
self . callButton . setObjectName ( " callButton " )
2016-06-07 21:43:25 +02:00
self . callButton . clicked . connect ( lambda : self . profile . call_click ( True ) )
self . videocallButton = QtGui . QPushButton ( Form )
self . videocallButton . setGeometry ( QtCore . QRect ( 550 , 30 , 50 , 50 ) )
self . videocallButton . setObjectName ( " videocallButton " )
self . videocallButton . clicked . connect ( lambda : self . profile . call_click ( True , True ) )
2016-04-24 12:45:11 +02:00
self . update_call_state ( ' call ' )
2016-04-27 20:10:53 +02:00
self . typing = QtGui . QLabel ( Form )
self . typing . setGeometry ( QtCore . QRect ( 500 , 40 , 50 , 30 ) )
pixmap = QtGui . QPixmap ( QtCore . QSize ( 50 , 30 ) )
2016-06-11 23:40:58 +02:00
pixmap . load ( ' typing.png ' )
2016-04-27 20:10:53 +02:00
self . typing . setScaledContents ( False )
self . typing . setPixmap ( pixmap . scaled ( 50 , 30 , QtCore . Qt . KeepAspectRatio ) )
self . typing . setVisible ( False )
2016-02-18 15:02:00 +01:00
QtCore . QMetaObject . connectSlotsByName ( Form )
2016-02-17 21:47:43 +01:00
2016-03-09 19:45:38 +01:00
def setup_left_center ( self , widget ) :
2016-02-25 21:40:00 +01:00
self . friends_list = QtGui . QListWidget ( widget )
2016-03-24 19:52:27 +01:00
self . friends_list . setObjectName ( " friends_list " )
2016-03-30 19:33:42 +02:00
self . friends_list . setGeometry ( 0 , 0 , 270 , 310 )
2016-02-25 21:40:00 +01:00
self . friends_list . clicked . connect ( self . friend_click )
2016-03-10 21:04:43 +01:00
self . friends_list . setContextMenuPolicy ( QtCore . Qt . CustomContextMenu )
self . friends_list . connect ( self . friends_list , QtCore . SIGNAL ( " customContextMenuRequested(QPoint) " ) ,
self . friend_right_click )
2016-03-24 19:52:27 +01:00
self . friends_list . setVerticalScrollMode ( QtGui . QAbstractItemView . ScrollPerPixel )
2016-02-25 21:40:00 +01:00
2016-02-26 19:54:15 +01:00
def setup_right_center ( self , widget ) :
self . messages = QtGui . QListWidget ( widget )
2016-05-02 17:27:46 +02:00
self . messages . setGeometry ( 0 , 0 , 620 , 310 )
2016-03-25 14:24:38 +01:00
self . messages . setObjectName ( " messages " )
2016-04-20 11:32:28 +02:00
self . messages . setVerticalScrollBarPolicy ( QtCore . Qt . ScrollBarAlwaysOn )
self . messages . setHorizontalScrollBarPolicy ( QtCore . Qt . ScrollBarAlwaysOff )
2016-05-02 17:27:46 +02:00
self . messages . setFocusPolicy ( QtCore . Qt . NoFocus )
2016-03-24 22:15:07 +01:00
def load ( pos ) :
if not pos :
self . profile . load_history ( )
self . messages . verticalScrollBar ( ) . setValue ( 1 )
self . messages . verticalScrollBar ( ) . valueChanged . connect ( load )
2016-03-24 19:52:27 +01:00
self . messages . setVerticalScrollMode ( QtGui . QAbstractItemView . ScrollPerPixel )
2016-02-26 19:54:15 +01:00
2016-03-15 18:05:19 +01:00
def initUI ( self , tox ) :
2016-03-30 19:33:42 +02:00
self . setMinimumSize ( 920 , 500 )
self . setGeometry ( 400 , 400 , 920 , 500 )
2016-02-25 21:40:00 +01:00
self . setWindowTitle ( ' Toxygen ' )
2016-05-12 19:45:01 +02:00
os . chdir ( curr_directory ( ) + ' /images/ ' )
2016-02-21 15:32:38 +01:00
main = QtGui . QWidget ( )
2016-02-17 21:47:43 +01:00
grid = QtGui . QGridLayout ( )
2016-02-18 15:02:00 +01:00
search = QtGui . QWidget ( )
2016-02-17 21:47:43 +01:00
name = QtGui . QWidget ( )
2016-02-18 15:02:00 +01:00
info = QtGui . QWidget ( )
2016-02-25 21:40:00 +01:00
main_list = QtGui . QWidget ( )
2016-06-11 23:40:58 +02:00
messages = QtGui . QWidget ( )
message_buttons = QtGui . QWidget ( )
if not Settings . get_instance ( ) [ ' mirror_mode ' ] :
self . setup_left_center_menu ( search )
grid . addWidget ( search , 1 , 0 )
self . setup_left_top ( name )
grid . addWidget ( name , 0 , 0 )
self . setup_right_center ( messages )
grid . addWidget ( messages , 1 , 1 , 2 , 1 )
self . setup_right_top ( info )
grid . addWidget ( info , 0 , 1 )
self . setup_right_bottom ( message_buttons )
grid . addWidget ( message_buttons , 3 , 1 )
self . setup_left_center ( main_list )
grid . addWidget ( main_list , 2 , 0 , 2 , 1 )
grid . setColumnMinimumWidth ( 1 , 500 )
grid . setColumnMinimumWidth ( 0 , 270 )
else :
self . setup_left_center_menu ( search )
grid . addWidget ( search , 1 , 1 )
self . setup_left_top ( name )
grid . addWidget ( name , 0 , 1 )
self . setup_right_center ( messages )
grid . addWidget ( messages , 1 , 0 , 2 , 1 )
self . setup_right_top ( info )
grid . addWidget ( info , 0 , 0 )
self . setup_right_bottom ( message_buttons )
grid . addWidget ( message_buttons , 3 , 0 )
self . setup_left_center ( main_list )
grid . addWidget ( main_list , 2 , 1 , 2 , 1 )
grid . setColumnMinimumWidth ( 0 , 500 )
grid . setColumnMinimumWidth ( 1 , 270 )
2016-05-18 23:38:21 +02:00
grid . setRowMinimumHeight ( 0 , 82 )
grid . setRowMinimumHeight ( 1 , 25 )
grid . setRowMinimumHeight ( 2 , 410 )
grid . setRowMinimumHeight ( 3 , 60 )
2016-05-02 17:27:46 +02:00
grid . setColumnStretch ( 1 , 1 )
2016-05-29 21:17:48 +02:00
grid . setRowStretch ( 2 , 1 )
2016-02-21 15:32:38 +01:00
main . setLayout ( grid )
self . setCentralWidget ( main )
2016-02-24 17:39:19 +01:00
self . setup_menu ( self )
2016-05-18 23:38:21 +02:00
self . messageEdit . setFocus ( )
2016-03-09 19:11:36 +01:00
self . user_info = name
self . friend_info = info
2016-04-04 11:20:32 +02:00
self . retranslateUi ( )
2016-05-18 23:38:21 +02:00
self . profile = Profile ( tox , self )
2016-02-17 21:47:43 +01:00
2016-03-12 21:18:13 +01:00
def closeEvent ( self , * args , * * kwargs ) :
2016-03-13 13:06:06 +01:00
self . profile . save_history ( )
2016-04-24 12:45:11 +02:00
self . profile . close ( )
2016-04-16 10:54:29 +02:00
QtGui . QApplication . closeAllWindows ( )
2016-03-12 21:18:13 +01:00
2016-05-02 17:27:46 +02:00
def resizeEvent ( self , * args , * * kwargs ) :
2016-05-18 23:38:21 +02:00
self . messages . setGeometry ( 0 , 0 , self . width ( ) - 300 , self . height ( ) - 172 )
2016-05-29 21:17:48 +02:00
self . friends_list . setGeometry ( 0 , 0 , 270 , self . height ( ) - 140 )
2016-06-11 23:40:58 +02:00
2016-06-07 21:43:25 +02:00
self . videocallButton . setGeometry ( QtCore . QRect ( self . width ( ) - 350 , 20 , 50 , 50 ) )
self . callButton . setGeometry ( QtCore . QRect ( self . width ( ) - 410 , 20 , 50 , 50 ) )
self . typing . setGeometry ( QtCore . QRect ( self . width ( ) - 470 , 30 , 50 , 30 ) )
2016-05-18 23:38:21 +02:00
self . messageEdit . setGeometry ( QtCore . QRect ( 120 , 2 , self . width ( ) - 490 , 55 ) )
self . screenshotButton . setGeometry ( QtCore . QRect ( 0 , 2 , 55 , 55 ) )
self . fileTransferButton . setGeometry ( QtCore . QRect ( 60 , 2 , 55 , 55 ) )
self . sendMessageButton . setGeometry ( QtCore . QRect ( self . width ( ) - 360 , 2 , 60 , 55 ) )
2016-06-07 21:43:25 +02:00
self . account_name . setGeometry ( QtCore . QRect ( 100 , 30 , self . width ( ) - 600 , 25 ) )
2016-05-06 15:13:33 +02:00
self . account_status . setGeometry ( QtCore . QRect ( 100 , 50 , self . width ( ) - 520 , 25 ) )
2016-06-02 22:33:38 +02:00
self . messageEdit . setFocus ( )
2016-05-02 17:27:46 +02:00
self . profile . update ( )
2016-05-07 23:47:10 +02:00
def keyPressEvent ( self , event ) :
if event . key ( ) == QtCore . Qt . Key_Escape :
self . hide ( )
else :
super ( MainWindow , self ) . keyPressEvent ( event )
2016-05-02 17:27:46 +02:00
2016-02-23 21:26:37 +01:00
# -----------------------------------------------------------------------------------------------------------------
# Functions which called when user click in menu
# -----------------------------------------------------------------------------------------------------------------
def about_program ( self ) :
import util
msgBox = QtGui . QMessageBox ( )
2016-04-04 11:20:32 +02:00
msgBox . setWindowTitle ( QtGui . QApplication . translate ( " MainWindow " , " About " , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-05-09 22:09:07 +02:00
text = ( QtGui . QApplication . translate ( " MainWindow " , ' Toxygen is Tox client written on Python. \n Version: ' , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-05-11 20:55:36 +02:00
msgBox . setText ( text + util . program_version + ' \n GitHub: github.com/xveduk/toxygen/ ' )
2016-02-23 21:26:37 +01:00
msgBox . exec_ ( )
def network_settings ( self ) :
2016-03-15 18:05:19 +01:00
self . n_s = NetworkSettings ( self . reset )
2016-02-23 21:26:37 +01:00
self . n_s . show ( )
2016-05-28 12:06:13 +02:00
def plugins_menu ( self ) :
self . p_s = PluginsSettings ( )
self . p_s . show ( )
2016-06-06 12:29:17 +02:00
def add_contact ( self , link = ' ' ) :
self . a_c = AddContact ( link )
2016-02-23 21:26:37 +01:00
self . a_c . show ( )
2016-03-23 16:37:56 +01:00
def profile_settings ( self , * args ) :
2016-03-07 19:00:00 +01:00
self . p_s = ProfileSettings ( )
2016-02-23 21:26:37 +01:00
self . p_s . show ( )
def privacy_settings ( self ) :
self . priv_s = PrivacySettings ( )
self . priv_s . show ( )
def notification_settings ( self ) :
self . notif_s = NotificationsSettings ( )
self . notif_s . show ( )
def interface_settings ( self ) :
self . int_s = InterfaceSettings ( )
self . int_s . show ( )
2016-04-24 12:45:11 +02:00
def audio_settings ( self ) :
self . audio_s = AudioSettings ( )
self . audio_s . show ( )
2016-03-13 13:06:06 +01:00
# -----------------------------------------------------------------------------------------------------------------
2016-04-24 12:45:11 +02:00
# Messages, calls and file transfers
2016-03-13 13:06:06 +01:00
# -----------------------------------------------------------------------------------------------------------------
2016-02-25 21:40:00 +01:00
def send_message ( self ) :
text = self . messageEdit . toPlainText ( )
2016-03-09 19:11:36 +01:00
self . profile . send_message ( text )
2016-02-25 21:40:00 +01:00
2016-03-16 20:59:15 +01:00
def send_file ( self ) :
if self . profile . is_active_online ( ) : # active friend exists and online
2016-05-11 18:51:35 +02:00
choose_file = QtGui . QApplication . translate ( " MainWindow " , ' Choose file ' , None , QtGui . QApplication . UnicodeUTF8 )
2016-05-02 18:46:42 +02:00
choose = QtGui . QApplication . translate ( " MainWindow " , choose_file , None , QtGui . QApplication . UnicodeUTF8 )
2016-04-04 11:20:32 +02:00
name = QtGui . QFileDialog . getOpenFileName ( self , choose )
2016-03-17 21:58:38 +01:00
if name [ 0 ] :
2016-03-17 21:49:27 +01:00
self . profile . send_file ( name [ 0 ] )
2016-03-16 20:59:15 +01:00
2016-05-08 12:51:56 +02:00
def send_screenshot ( self , hide = False ) :
2016-03-22 13:17:46 +01:00
if self . profile . is_active_online ( ) : # active friend exists and online
2016-05-08 12:51:56 +02:00
self . sw = ScreenShotWindow ( self )
2016-03-23 09:33:21 +01:00
self . sw . show ( )
2016-05-08 12:51:56 +02:00
if hide :
self . hide ( )
2016-03-22 13:17:46 +01:00
2016-04-24 12:45:11 +02:00
def active_call ( self ) :
self . update_call_state ( ' finish_call ' )
def incoming_call ( self ) :
self . update_call_state ( ' incoming_call ' )
def call_finished ( self ) :
self . update_call_state ( ' call ' )
def update_call_state ( self , fl ) :
2016-06-07 21:43:25 +02:00
# TODO: do smth with video call button
2016-06-11 23:40:58 +02:00
os . chdir ( curr_directory ( ) + ' /images/ ' )
pixmap = QtGui . QPixmap ( ' {} .png ' . format ( fl ) )
2016-04-24 12:45:11 +02:00
icon = QtGui . QIcon ( pixmap )
self . callButton . setIcon ( icon )
self . callButton . setIconSize ( QtCore . QSize ( 50 , 50 ) )
2016-06-11 23:40:58 +02:00
pixmap = QtGui . QPixmap ( ' videocall.png ' )
2016-06-07 21:43:25 +02:00
icon = QtGui . QIcon ( pixmap )
self . videocallButton . setIcon ( icon )
self . videocallButton . setIconSize ( QtCore . QSize ( 35 , 35 ) )
2016-04-24 12:45:11 +02:00
2016-03-13 13:06:06 +01:00
# -----------------------------------------------------------------------------------------------------------------
# Functions which called when user open context menu in friends list
# -----------------------------------------------------------------------------------------------------------------
2016-03-10 21:04:43 +01:00
def friend_right_click ( self , pos ) :
item = self . friends_list . itemAt ( pos )
2016-03-18 17:33:54 +01:00
num = self . friends_list . indexFromItem ( item ) . row ( )
2016-05-28 12:06:13 +02:00
friend = Profile . get_instance ( ) . get_friend ( num )
2016-03-18 17:33:54 +01:00
settings = Settings . get_instance ( )
allowed = friend . tox_id in settings [ ' auto_accept_from_friends ' ]
2016-04-04 11:20:32 +02:00
auto = QtGui . QApplication . translate ( " MainWindow " , ' Disallow auto accept ' , None , QtGui . QApplication . UnicodeUTF8 ) if allowed else QtGui . QApplication . translate ( " MainWindow " , ' Allow auto accept ' , None , QtGui . QApplication . UnicodeUTF8 )
2016-03-10 21:04:43 +01:00
if item is not None :
self . listMenu = QtGui . QMenu ( )
2016-04-04 11:20:32 +02:00
set_alias_item = self . listMenu . addAction ( QtGui . QApplication . translate ( " MainWindow " , ' Set alias ' , None , QtGui . QApplication . UnicodeUTF8 ) )
clear_history_item = self . listMenu . addAction ( QtGui . QApplication . translate ( " MainWindow " , ' Clear history ' , None , QtGui . QApplication . UnicodeUTF8 ) )
copy_key_item = self . listMenu . addAction ( QtGui . QApplication . translate ( " MainWindow " , ' Copy public key ' , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-03-18 17:33:54 +01:00
auto_accept_item = self . listMenu . addAction ( auto )
2016-04-04 11:20:32 +02:00
remove_item = self . listMenu . addAction ( QtGui . QApplication . translate ( " MainWindow " , ' Remove friend ' , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-06-04 14:19:15 +02:00
notes_item = self . listMenu . addAction ( QtGui . QApplication . translate ( " MainWindow " , ' Notes ' , None , QtGui . QApplication . UnicodeUTF8 ) )
2016-05-28 12:06:13 +02:00
submenu = plugin_support . PluginLoader . get_instance ( ) . get_menu ( self . listMenu , num )
if len ( submenu ) :
plug = self . listMenu . addMenu ( QtGui . QApplication . translate ( " MainWindow " , ' Plugins ' , None , QtGui . QApplication . UnicodeUTF8 ) )
plug . addActions ( submenu )
2016-03-18 17:33:54 +01:00
self . connect ( set_alias_item , QtCore . SIGNAL ( " triggered() " ) , lambda : self . set_alias ( num ) )
self . connect ( remove_item , QtCore . SIGNAL ( " triggered() " ) , lambda : self . remove_friend ( num ) )
self . connect ( copy_key_item , QtCore . SIGNAL ( " triggered() " ) , lambda : self . copy_friend_key ( num ) )
self . connect ( clear_history_item , QtCore . SIGNAL ( " triggered() " ) , lambda : self . clear_history ( num ) )
self . connect ( auto_accept_item , QtCore . SIGNAL ( " triggered() " ) , lambda : self . auto_accept ( num , not allowed ) )
2016-06-04 14:19:15 +02:00
self . connect ( notes_item , QtCore . SIGNAL ( " triggered() " ) , lambda : self . show_note ( friend ) )
2016-03-10 21:04:43 +01:00
parent_position = self . friends_list . mapToGlobal ( QtCore . QPoint ( 0 , 0 ) )
self . listMenu . move ( parent_position + pos )
self . listMenu . show ( )
2016-06-04 14:19:15 +02:00
def show_note ( self , friend ) :
s = Settings . get_instance ( )
note = s [ ' notes ' ] [ friend . tox_id ] if friend . tox_id in s [ ' notes ' ] else ' '
user = QtGui . QApplication . translate ( " MainWindow " , ' Notes about user ' , None , QtGui . QApplication . UnicodeUTF8 )
user = u ' {} {} ' . format ( user , friend . name )
def save_note ( text ) :
s [ ' notes ' ] [ friend . tox_id ] = text
s . save ( )
self . note = MultilineEdit ( user , note , save_note )
self . note . show ( )
2016-03-18 17:33:54 +01:00
def set_alias ( self , num ) :
2016-03-10 21:04:43 +01:00
self . profile . set_alias ( num )
2016-03-18 17:33:54 +01:00
def remove_friend ( self , num ) :
2016-03-10 21:04:43 +01:00
self . profile . delete_friend ( num )
2016-03-18 17:33:54 +01:00
def copy_friend_key ( self , num ) :
2016-03-10 21:04:43 +01:00
tox_id = self . profile . friend_public_key ( num )
clipboard = QtGui . QApplication . clipboard ( )
clipboard . setText ( tox_id )
2016-03-18 17:33:54 +01:00
def clear_history ( self , num ) :
2016-03-12 21:18:13 +01:00
self . profile . clear_history ( num )
2016-03-10 21:04:43 +01:00
2016-03-18 17:33:54 +01:00
def auto_accept ( self , num , value ) :
settings = Settings . get_instance ( )
tox_id = self . profile . friend_public_key ( num )
if value :
settings [ ' auto_accept_from_friends ' ] . append ( tox_id )
else :
2016-05-02 18:46:42 +02:00
settings [ ' auto_accept_from_friends ' ] . remove ( tox_id )
2016-03-18 17:33:54 +01:00
settings . save ( )
2016-03-13 13:06:06 +01:00
# -----------------------------------------------------------------------------------------------------------------
# Functions which called when user click somewhere else
# -----------------------------------------------------------------------------------------------------------------
2016-02-25 21:40:00 +01:00
2016-02-28 22:33:35 +01:00
def friend_click ( self , index ) :
num = index . row ( )
2016-03-09 19:11:36 +01:00
self . profile . set_active ( num )
2016-03-02 17:05:03 +01:00
2016-03-07 19:00:00 +01:00
def mouseReleaseEvent ( self , event ) :
x , y = event . x ( ) , event . y ( )
pos = self . connection_status . pos ( )
if ( pos . x ( ) < x < pos . x ( ) + 32 ) and ( pos . y ( ) < y < pos . y ( ) + 32 ) :
self . profile . change_status ( )
else :
super ( self . __class__ , self ) . mouseReleaseEvent ( event )
2016-03-02 17:05:03 +01:00
def filtering ( self ) :
2016-05-18 23:38:21 +02:00
self . profile . filtration ( self . online_contacts . currentIndex ( ) == 1 , self . contact_name . text ( ) )
2016-03-05 13:44:52 +01:00
2016-03-23 09:33:21 +01:00
class ScreenShotWindow ( QtGui . QWidget ) :
2016-04-02 13:41:06 +02:00
2016-05-08 12:51:56 +02:00
def __init__ ( self , parent ) :
2016-03-23 09:33:21 +01:00
super ( ScreenShotWindow , self ) . __init__ ( )
2016-05-08 12:51:56 +02:00
self . parent = parent
2016-03-23 09:33:21 +01:00
self . setMouseTracking ( True )
2016-03-23 17:03:04 +01:00
self . setWindowFlags ( self . windowFlags ( ) | QtCore . Qt . FramelessWindowHint | QtCore . Qt . WindowStaysOnTopHint )
2016-03-23 09:33:21 +01:00
self . showFullScreen ( )
2016-04-13 23:46:28 +02:00
self . setWindowOpacity ( 0.5 )
2016-05-29 15:49:00 +02:00
self . rubberband = RubberBand ( )
2016-03-23 09:33:21 +01:00
2016-05-08 12:51:56 +02:00
def closeEvent ( self , * args ) :
if self . parent . isHidden ( ) :
self . parent . show ( )
2016-03-23 09:33:21 +01:00
def mousePressEvent ( self , event ) :
self . origin = event . pos ( )
2016-04-02 13:41:06 +02:00
self . rubberband . setGeometry ( QtCore . QRect ( self . origin , QtCore . QSize ( ) ) )
2016-03-23 09:33:21 +01:00
self . rubberband . show ( )
QtGui . QWidget . mousePressEvent ( self , event )
def mouseMoveEvent ( self , event ) :
if self . rubberband . isVisible ( ) :
2016-04-02 13:41:06 +02:00
self . rubberband . setGeometry ( QtCore . QRect ( self . origin , event . pos ( ) ) . normalized ( ) )
left = QtGui . QRegion ( QtCore . QRect ( 0 , 0 , self . rubberband . x ( ) , self . height ( ) ) )
right = QtGui . QRegion ( QtCore . QRect ( self . rubberband . x ( ) + self . rubberband . width ( ) , 0 , self . width ( ) , self . height ( ) ) )
top = QtGui . QRegion ( 0 , 0 , self . width ( ) , self . rubberband . y ( ) )
bottom = QtGui . QRegion ( 0 , self . rubberband . y ( ) + self . rubberband . height ( ) , self . width ( ) , self . height ( ) )
self . setMask ( left + right + top + bottom )
2016-03-23 09:33:21 +01:00
def mouseReleaseEvent ( self , event ) :
if self . rubberband . isVisible ( ) :
self . rubberband . hide ( )
rect = self . rubberband . geometry ( )
print rect
2016-05-08 12:51:56 +02:00
if rect . width ( ) and rect . height ( ) :
p = QtGui . QPixmap . grabWindow ( QtGui . QApplication . desktop ( ) . winId ( ) ,
rect . x ( ) + 4 ,
rect . y ( ) + 4 ,
rect . width ( ) - 8 ,
rect . height ( ) - 8 )
byte_array = QtCore . QByteArray ( )
buffer = QtCore . QBuffer ( byte_array )
buffer . open ( QtCore . QIODevice . WriteOnly )
p . save ( buffer , ' PNG ' )
Profile . get_instance ( ) . send_screenshot ( str ( byte_array . data ( ) ) )
2016-03-23 09:33:21 +01:00
self . close ( )
2016-04-02 13:41:06 +02:00
def keyPressEvent ( self , event ) :
if event . key ( ) == QtCore . Qt . Key_Escape :
self . rubberband . setHidden ( True )
self . close ( )
else :
super ( ScreenShotWindow , self ) . keyPressEvent ( event )
2016-03-23 09:33:21 +01:00
2016-03-29 16:11:30 +02:00