def show_completed(self, jid, file_props):
		''' show a dialog saying that file (file_props) has been transferred'''
		self.window.present()
		self.window.window.focus()
		if file_props['type'] == 'r':
			# file path is used below in 'Save in'
			(file_path, file_name) = os.path.split(file_props['file-name'])
		else:
			file_name = file_props['name']
		sectext = '\t' + _('Filename: %s') % \
			gtkgui_helpers.escape_for_pango_markup(file_name)
		sectext += '\n\t' + _('Size: %s') % \
		helpers.convert_bytes(file_props['size'])
		if file_props['type'] == 'r':
			jid = unicode(file_props['sender']).split('/')[0]
			sender_name = gajim.get_first_contact_instance_from_jid( 
				file_props['tt_account'], jid).name
			sender = gtkgui_helpers.escape_for_pango_markup(sender_name)
		else:
			#You is a reply of who sent a file
			sender = _('You')
		sectext += '\n\t' +_('Sender: %s') % sender
		sectext += '\n\t' +_('Recipient: ')
		if file_props['type'] == 's':
			jid = unicode(file_props['receiver']).split('/')[0]
			receiver_name = gajim.get_first_contact_instance_from_jid( 
				file_props['tt_account'], jid).name
			recipient = gtkgui_helpers.escape_for_pango_markup(receiver_name)
		else:
			#You is a reply of who received a file
			recipient = _('You')
		sectext += recipient
		if file_props['type'] == 'r':
			sectext += '\n\t' +_('Saved in: %s') % \
				gtkgui_helpers.escape_for_pango_markup(file_path)
		dialog = dialogs.HigDialog(None, gtk.MESSAGE_INFO, gtk.BUTTONS_NONE, 
				_('File transfer completed'), sectext)
		if file_props['type'] == 'r':
			dialog.add_buttons(_('_Open Containing Folder'), gtk.RESPONSE_ACCEPT)
		dialog.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK)
		dialog.show_all()
		response = dialog.run()
		dialog.destroy()
		if response == gtk.RESPONSE_ACCEPT:
			if not file_props.has_key('file-name'):
				return
			(path, file) = os.path.split(file_props['file-name'])
			if os.path.exists(path) and os.path.isdir(path):
				helpers.launch_file_manager(path)
			self.tree.get_selection().unselect_all()
Beispiel #2
0
	def check_for_possible_inactive_chatstate(self, jid):
		''' did we move mouse over that window or wrote something in message
		textview
		in the last 30 seconds?
		if yes we go active
		if no we go inactive '''
		contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
		if jid not in self.xmls or contact is None:
			# the tab with jid is no longer open or contact left
			return False # stop looping

		current_state = contact.our_chatstate
		if current_state is False: # jid doesn't support chatstates
			return False # stop looping

		if self.mouse_over_in_last_5_secs or self.kbd_activity_in_last_5_secs:
			return True # loop forever

		if not (self.mouse_over_in_last_30_secs or\
			self.kbd_activity_in_last_30_secs):
			self.send_chatstate('inactive', jid)

		# assume no activity and let the motion-notify or 'insert-text' make them True
		# refresh 30 seconds too or else it's 30 - 5 = 25 seconds!
		self.reset_kbd_mouse_timeout_vars()

		return True # loop forever
Beispiel #3
0
	def check_for_possible_paused_chatstate(self, jid):
		''' did we move mouse of that window or write something in message
		textview
		in the last 5 seconds?
		if yes we go active for mouse, composing for kbd
		if no we go paused if we were previously composing '''
		contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
		if jid not in self.xmls or contact is None:
			# the tab with jid is no longer open or contact left
			# stop timer
			return False # stop looping

		current_state = contact.our_chatstate
		if current_state is False: # jid doesn't support chatstates
			return False # stop looping

		message_textview = self.message_textviews[jid]
		message_buffer = message_textview.get_buffer()
		if self.kbd_activity_in_last_5_secs and message_buffer.get_char_count():
			# Only composing if the keyboard activity was in text entry
			self.send_chatstate('composing', jid)
		elif self.mouse_over_in_last_5_secs and jid == self.get_active_jid():
			self.send_chatstate('active', jid)
		else:
			if current_state == 'composing':
				self.send_chatstate('paused', jid) # pause composing

		# assume no activity and let the motion-notify or 'insert-text' make them True
		# refresh 30 seconds vars too or else it's 30 - 5 = 25 seconds!
		self.reset_kbd_mouse_timeout_vars()
		return True # loop forever
Beispiel #4
0
    def prepare_context_menu(self):
        """sets compact view menuitem active state
		sets active and sensitivity state for toggle_gpg_menuitem
		and remove possible 'Switch to' menuitems"""
        if self.widget_name == "groupchat_window":
            menu = self.gc_popup_menu
            childs = menu.get_children()
            # compact_view_menuitem
            childs[5].set_active(self.compact_view_current_state)
        elif self.widget_name == "tabbed_chat_window":
            menu = self.tabbed_chat_popup_menu
            childs = menu.get_children()
            # check if gpg capabitlies or else make gpg toggle insensitive
            jid = self.get_active_jid()
            gpg_btn = self.xmls[jid].get_widget("gpg_togglebutton")
            isactive = gpg_btn.get_active()
            issensitive = gpg_btn.get_property("sensitive")
            childs[3].set_active(isactive)
            childs[3].set_property("sensitive", issensitive)
            # If we don't have resource, we can't do file transfert
            c = gajim.get_first_contact_instance_from_jid(self.account, jid)
            if not c.resource:
                childs[2].set_sensitive(False)
            else:
                childs[2].set_sensitive(True)
                # compact_view_menuitem
            childs[4].set_active(self.compact_view_current_state)
        menu = self.remove_possible_switch_to_menuitems(menu)

        return menu
Beispiel #5
0
    def show_title(self, urgent=True):
        """redraw the window's title"""
        unread = 0
        for jid in self.nb_unread:
            unread += self.nb_unread[jid]
        start = ""
        if unread > 1:
            start = "[" + unicode(unread) + "] "
        elif unread == 1:
            start = "* "
        if len(self.xmls) > 1:  # if more than one tab in the same window
            if self.widget_name == "tabbed_chat_window":
                add = _("Chat")
            elif self.widget_name == "groupchat_window":
                add = _("Group Chat")
        elif len(self.xmls) == 1:  # just one tab
            if self.widget_name == "tabbed_chat_window":
                c = gajim.get_first_contact_instance_from_jid(self.account, jid)
                if c is None:
                    add = ""
                else:
                    add = c.name
            elif self.widget_name == "groupchat_window":
                name = gajim.get_nick_from_jid(jid)
                add = name

        title = start + add
        if len(gajim.connections) >= 2:  # if we have 2 or more accounts
            title += " (" + _("account: ") + self.account + ")"

        self.window.set_title(title)
        if urgent:
            gtkgui_helpers.set_unset_urgency_hint(self.window, unread)
Beispiel #6
0
    def remove_possible_switch_to_menuitems(self, menu):
        """ remove duplicate 'Switch to' if they exist and return clean menu"""
        childs = menu.get_children()

        if self.widget_name == "tabbed_chat_window":
            jid = self.get_active_jid()
            c = gajim.get_first_contact_instance_from_jid(self.account, jid)
            if _("not in the roster") in c.groups:  # for add_to_roster_menuitem
                childs[5].show()
                childs[5].set_no_show_all(False)
            else:
                childs[5].hide()
                childs[5].set_no_show_all(True)

            start_removing_from = 6  # this is from the seperator and after

        else:
            start_removing_from = 7  # # this is from the seperator and after

        for child in childs[start_removing_from:]:
            menu.remove(child)

        return menu
Beispiel #7
0
	def __init__(self, jid, account):
		self.jid = jid
		self.account = account
		self.mark_days_idle_call_id = None
		
		xml = gtk.glade.XML(GTKGUI_GLADE, 'history_window', APP)
		self.window = xml.get_widget('history_window')
		
		self.calendar = xml.get_widget('calendar')
		scrolledwindow = xml.get_widget('scrolledwindow')
		self.history_textview = conversation_textview.ConversationTextview(account)
		scrolledwindow.add(self.history_textview)
		self.history_buffer = self.history_textview.get_buffer()
		self.query_entry = xml.get_widget('query_entry')
		self.search_button = xml.get_widget('search_button')
		query_builder_button = xml.get_widget('query_builder_button')
		query_builder_button.hide()
		query_builder_button.set_no_show_all(True)
		self.expander_vbox = xml.get_widget('expander_vbox')
		
		self.results_treeview = xml.get_widget('results_treeview')
		# contact_name, time, message
		model = gtk.ListStore(str, str, str)
		self.results_treeview.set_model(model)
		
		col = gtk.TreeViewColumn(_('Name'))
		self.results_treeview.append_column(col)
		renderer = gtk.CellRendererText()
		col.pack_start(renderer)
		col.set_attributes(renderer, text = C_CONTACT_NAME)
		col.set_sort_column_id(C_CONTACT_NAME)
		col.set_resizable(True)
		
		col = gtk.TreeViewColumn(_('Date'))
		self.results_treeview.append_column(col)
		renderer = gtk.CellRendererText()
		col.pack_start(renderer)
		col.set_attributes(renderer, text = C_TIME)
		col.set_sort_column_id(C_TIME)
		col.set_resizable(True)
		
		col = gtk.TreeViewColumn(_('Message'))
		self.results_treeview.append_column(col)
		renderer = gtk.CellRendererText()
		col.pack_start(renderer)
		col.set_attributes(renderer, text = C_MESSAGE)
		col.set_resizable(True)
		
		if account and gajim.contacts[account].has_key(jid):
			contact = gajim.get_first_contact_instance_from_jid(account, jid)
			title = _('Conversation History with %s') % contact.name
		else:
			title = _('Conversation History with %s') % jid
		self.window.set_title(title)
		
		xml.signal_autoconnect(self)
		
		# fake event so we start mark days procedure for selected month
		# selected month is current month as calendar defaults to selecting
		# current date
		self.calendar.emit('month-changed')

		# select and show logs for last date we have logs with contact
		# and if we don't have logs at all, default to today
		result = gajim.logger.get_last_date_that_has_logs(self.jid)
		if result is None:
			date = time.localtime()
		else:
			tim = result
			date = time.localtime(tim)

		y, m, d = date[0], date[1], date[2]
		gtk_month = gtkgui_helpers.make_python_month_gtk_month(m)
		self.calendar.select_month(gtk_month, y)
		self.calendar.select_day(d)
		self.add_lines_for_date(y, m, d)
		
		self.window.show_all()
Beispiel #8
0
	def send_message(self, message):
		'''Send the given message to the active tab'''
		if not message:
			return

		jid = self.get_active_jid()
		contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
		if contact is None:
			# contact was from pm in MUC, and left the room, or we left the room
			room, nick = gajim.get_room_and_nick_from_fjid(jid)
			dialogs.ErrorDialog(_('Sending private message failed'),
				#in second %s code replaces with nickname
				_('You are no longer in room "%s" or "%s" has left.') % \
				(room, nick)).get_response()
			return

		conv_textview = self.conversation_textviews[jid]
		message_textview = self.message_textviews[jid]
		message_buffer = message_textview.get_buffer()

		if message != '' or message != '\n':
			self.save_sent_message(jid, message)
			if message == '/clear':
				conv_textview.clear() # clear conversation
				self.clear(message_textview) # clear message textview too
				return True
			elif message == '/compact':
				self.set_compact_view(not self.compact_view_current_state)
				self.clear(message_textview)
				return True
			keyID = ''
			encrypted = False
			if self.xmls[jid].get_widget('gpg_togglebutton').get_active():
				keyID = self.contacts[jid].keyID
				encrypted = True

			chatstates_on = gajim.config.get(
				'chat_state_notifications') != 'disabled'

			chatstate_to_send = None
			
			if chatstates_on and contact is not None:
				if contact.our_chatstate is None:
					# no info about peer
					# send active to discover chat state capabilities
					# this is here (and not in send_chatstate)
					# because we want it sent with REAL message
					# (not standlone) eg. one that has body
					chatstate_to_send = 'active'
					contact.our_chatstate = 'ask' # pseudo state

				# if peer supports jep85 and we are not 'ask', send 'active'
				# NOTE: first active and 'ask' is set in gajim.py
				elif contact.our_chatstate not in (False, 'ask'):
					#send active chatstate on every message (as JEP says)
					chatstate_to_send = 'active'
					contact.our_chatstate = 'active'
					
					# refresh timers
					# avoid sending composing in less than 5 seconds
					# if we just send a message
					gobject.source_remove(self.possible_paused_timeout_id[jid])
					gobject.source_remove(self.possible_inactive_timeout_id[jid])
					self.possible_paused_timeout_id[jid] =\
			gobject.timeout_add(5000, self.check_for_possible_paused_chatstate,
				jid)
					self.possible_inactive_timeout_id[jid] =\
			gobject.timeout_add(30000, self.check_for_possible_inactive_chatstate,
				jid)
					self.reset_kbd_mouse_timeout_vars()
			
			gajim.connections[self.account].send_message(jid, message, keyID,
				chatstate = chatstate_to_send)

			message_buffer.set_text('') # clear message buffer (and tv of course)
			self.print_conversation(message, jid, jid, encrypted = encrypted)
Beispiel #9
0
	def send_chatstate(self, state, jid = None):
		''' sends OUR chatstate as STANDLONE chat state message (eg. no body)
		to jid only if new chatstate is different
		from the previous one
		if jid is not specified, send to active tab'''
		# JEP 85 does not allow resending the same chatstate
		# this function checks for that and just returns so it's safe to call it
		# with same state.
		
		# This functions also checks for violation in state transitions
		# and raises RuntimeException with appropriate message
		# more on that http://www.jabber.org/jeps/jep-0085.html#statechart

		# do not send nothing if we have chat state notifications disabled
		# that means we won't reply to the <active/> from other peer
		# so we do not broadcast jep85 capabalities
		chatstate_setting = gajim.config.get('chat_state_notifications')
		if chatstate_setting == 'disabled':
			return
		elif chatstate_setting == 'composing_only' and state != 'active' and state != 'composing':
			return

		if jid is None:
			jid = self.get_active_jid()
			
		contact = gajim.get_first_contact_instance_from_jid(self.account, jid)

		if contact is None:
			# contact was from pm in MUC, and left the room so contact is None
			# so we cannot send chatstate anymore
			return

		# Don't send chatstates to offline contacts
		if contact.show == 'offline':
			return

		if contact.our_chatstate is False: # jid cannot do jep85
			return

		# if the new state we wanna send (state) equals 
		# the current state (contact.our_chatstate) then return
		if contact.our_chatstate == state:
			return

		if contact.our_chatstate is None:
			# we don't know anything about jid, so return
			# NOTE:
			# send 'active', set current state to 'ask' and return is done
			# in self.send_message() because we need REAL message (with <body>)
			# for that procedure so return to make sure we send only once
			# 'active' until we know peer supports jep85
			return 

		if contact.our_chatstate == 'ask':
			return

		# prevent going paused if we we were not composing (JEP violation)
		if state == 'paused' and not contact.our_chatstate == 'composing':
			gajim.connections[self.account].send_message(jid, None, None,
				chatstate = 'active') # go active before
			contact.our_chatstate = 'active'
			self.reset_kbd_mouse_timeout_vars()
		
		# if we're inactive prevent composing (JEP violation)
		if contact.our_chatstate == 'inactive' and state == 'composing':
			gajim.connections[self.account].send_message(jid, None, None,
				chatstate = 'active') # go active before
			contact.our_chatstate = 'active'
			self.reset_kbd_mouse_timeout_vars()

		gajim.connections[self.account].send_message(jid, None, None,
			chatstate = state)
		contact.our_chatstate = state
		if contact.our_chatstate == 'active':
			self.reset_kbd_mouse_timeout_vars()
Beispiel #10
0
	def on_send_file_menuitem_activate(self, widget):
		jid = self.get_active_jid()
		contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
		gajim.interface.instances['file_transfers'].show_file_send_request( 
			self.account, contact)
Beispiel #11
0
	def __init__(self, event_type, jid, account, msg_type = '', file_props = None):
		self.account = account
		self.jid = jid
		self.msg_type = msg_type
		self.file_props = file_props
		
		xml = gtk.glade.XML(GTKGUI_GLADE, 'popup_notification_window', APP)
		self.window = xml.get_widget('popup_notification_window')
		close_button = xml.get_widget('close_button')
		event_type_label = xml.get_widget('event_type_label')
		event_description_label = xml.get_widget('event_description_label')
		eventbox = xml.get_widget('eventbox')
		
		event_type_label.set_markup('<b>' + event_type + '</b>')

		if self.jid in gajim.contacts[account]:
			txt = gajim.contacts[account][self.jid][0].name
		else:
			txt = self.jid

		# set colors [ http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html ]
		self.window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black'))

		if event_type == _('Contact Signed In'):
			limegreen = gtk.gdk.color_parse('limegreen')
			close_button.modify_bg(gtk.STATE_NORMAL, limegreen)
			eventbox.modify_bg(gtk.STATE_NORMAL, limegreen)
			event_description_label.set_text(txt)
		elif event_type == _('Contact Signed Out'):
			red = gtk.gdk.color_parse('red')
			close_button.modify_bg(gtk.STATE_NORMAL, red)
			eventbox.modify_bg(gtk.STATE_NORMAL, red)
			event_description_label.set_text(txt)
		elif event_type in (_('New Message'), _('New Single Message'),
			_('New Private Message')):
			dodgerblue = gtk.gdk.color_parse('dodgerblue')
			close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue)
			eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue)
			if event_type == _('New Private Message'):
				room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
				room_name,t = gajim.get_room_name_and_server_from_room_jid(room_jid)
				txt = _('From %s in room %s') % (nick, room_name)
			else:
				txt = _('From %s') % txt
			event_description_label.set_text(txt)
		elif event_type == _('File Transfer Request'):
			bg_color = gtk.gdk.color_parse('khaki')
			close_button.modify_bg(gtk.STATE_NORMAL, bg_color)
			eventbox.modify_bg(gtk.STATE_NORMAL, bg_color)
			txt = _('From %s') % txt
			event_description_label.set_text(txt)
		elif event_type == _('File Transfer Error'):
			bg_color = gtk.gdk.color_parse('firebrick')
			close_button.modify_bg(gtk.STATE_NORMAL, bg_color)
			eventbox.modify_bg(gtk.STATE_NORMAL, bg_color)
			event_description_label.set_text(txt)
		elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')):
			bg_color = gtk.gdk.color_parse('yellowgreen')
			close_button.modify_bg(gtk.STATE_NORMAL, bg_color)
			eventbox.modify_bg(gtk.STATE_NORMAL, bg_color)
			if file_props is not None:
				if file_props['type'] == 'r':
					# get the name of the sender, as it is in the roster
					sender = unicode(file_props['sender']).split('/')[0]
					name = gajim.get_first_contact_instance_from_jid( 
						account, sender).name
					txt = _('From %s') % name
				else:
					receiver = file_props['receiver']
					if hasattr(receiver, 'jid'):
						receiver = receiver.jid
					receiver = receiver.split('/')[0]
					# get the name of the contact, as it is in the roster
					name = gajim.get_first_contact_instance_from_jid( 
						account, receiver).name
					txt = _('To %s') % name
			else:
				txt = ''
			event_description_label.set_text(txt)
		# position the window to bottom-right of screen
		window_width, self.window_height = self.window.get_size()
		gajim.interface.roster.popups_notification_height += self.window_height
		self.window.move(gtk.gdk.screen_width() - window_width,
			gtk.gdk.screen_height() - gajim.interface.roster.popups_notification_height)

		xml.signal_autoconnect(self)
		self.window.show_all()
		gobject.timeout_add(5000, self.on_timeout)
Beispiel #12
0
    def populate(self, file_props):
        self.create_window()
        self.hbox = gtk.HBox()
        text = "<b>" + _("Name: ") + "</b>"
        name = file_props["name"]
        if file_props["type"] == "r":
            (file_path, file_name) = os.path.split(file_props["file-name"])
        else:
            file_name = file_props["name"]
        text += gtkgui_helpers.escape_for_pango_markup(file_name)
        text += "\n<b>" + _("Type: ") + "</b>"
        if file_props["type"] == "r":
            text += _("Download")
        else:
            text += _("Upload")
        if file_props["type"] == "r":
            text += "\n<b>" + _("Sender: ") + "</b>"
            sender = unicode(file_props["sender"]).split("/")[0]
            name = gajim.get_first_contact_instance_from_jid(file_props["tt_account"], sender).name
        else:
            text += "\n<b>" + _("Recipient: ") + "</b>"
            receiver = file_props["receiver"]
            if hasattr(receiver, "name"):
                receiver = receiver.name
            receiver = receiver.split("/")[0]
            if receiver.find("@") == -1:
                name = receiver
            else:
                name = gajim.get_first_contact_instance_from_jid(file_props["tt_account"], receiver).name
        text += gtkgui_helpers.escape_for_pango_markup(name)
        text += "\n<b>" + _("Size: ") + "</b>"
        text += helpers.convert_bytes(file_props["size"])
        text += "\n<b>" + _("Transferred: ") + "</b>"
        transfered_len = 0
        if file_props.has_key("received-len"):
            transfered_len = file_props["received-len"]
        text += helpers.convert_bytes(transfered_len)
        text += "\n<b>" + _("Status: ") + "</b>"
        status = ""
        if not file_props.has_key("started") or not file_props["started"]:
            status = _("Not started")
        elif file_props.has_key("connected"):
            if file_props.has_key("stopped") and file_props["stopped"] == True:
                status = _("Stopped")
            elif file_props["completed"]:
                status = _("Completed")
            elif file_props["connected"] == False:
                if file_props["completed"]:
                    status = _("Completed")
            else:
                if file_props.has_key("paused") and file_props["paused"] == True:
                    status = _("Paused")
                elif file_props.has_key("stalled") and file_props["stalled"] == True:
                    # stalled is not paused. it is like 'frozen' it stopped alone
                    status = _("Stalled")
                else:
                    status = _("Transferring")
        else:
            status = _("Not started")

        text += status
        self.text_label.set_markup(text)
        self.hbox.add(self.text_label)
        self.win.add(self.hbox)