emesene forum
July 31, 2010, 01:11:51 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: CACHE KEY ERRORS? NICK NOT SAVED? UPGRADE TO 1.6.2 FIRST!

REPORT ANY ISSUE HERE - PLEASE CHECK IF THE PROBLEM HAS ALREADY BEEN REPORTED FIRST -- THANKS
 
  Home   Forum   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: [IDEA] Save conversation from the window  (Read 2449 times)
checkm
Full Member
***

l33tness: 8
Offline Offline

Posts: 18


scacco_m@hotmail.it
View Profile WWW Email
« Reply #15 on: January 08, 2010, 07:24:28 AM »

Thank you for the code. I couldn't find where to add the button in the toolbar. lol. Cheesy
I'm working to fix it and make a plugin. Wink
Logged

checkm
Full Member
***

l33tness: 8
Offline Offline

Posts: 18


scacco_m@hotmail.it
View Profile WWW Email
« Reply #16 on: January 08, 2010, 08:21:24 AM »

Ok, here is the non-plugin working patch. Now the toolbar button works, too. I also added a gtk.MessageDialog that appears to show if your save has gone well. Here it is:
Code:
--- emesene/Config.py 2010-01-07 20:33:59.000000000 +0100
+++ Coding/emesene-work/Config.py 2010-01-08 16:37:21.000000000 +0100
@@ -160,6 +160,7 @@
     'toolInvite' : True,
     'toolSendFile' : True,
     'toolWebcam' : True,
+    'toolSave' : True,
     'toolClear' : True,   
 }
 
--- emesene/ConversationWindow.py 2010-01-07 21:24:44.000000000 +0100
+++ Coding/emesene-work/ConversationWindow.py 2010-01-08 17:04:29.000000000 +0100
@@ -1,4 +1,4 @@
-p# -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*-
 
 #   This file is part of emesene.
 #
@@ -565,7 +565,10 @@
         if response == gtk.RESPONSE_OK:
             self.conversation.sendFile(dialog.get_filename())
         dialog.destroy()
-
+   
+    def show_save_dialog(self):
+        '''Displays a dialog to save the conversation'''
+        SaveConversationDialog(self)
 
 class ConversationWindowMenu(gtk.MenuBar):
     '''This class represent the menu in the conversation window, i define
@@ -599,7 +602,14 @@
         self.sendFileMenuItem.connect('activate', self.onSendFileActivate)
         self.sendFileMenuItem.add_accelerator('activate', accelGroup, ord('S'),
             gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
-
+       
+        saveMenuItem = gtk.ImageMenuItem(_('Save Conve_rsation'))
+        saveMenuItem.set_image(gtk.image_new_from_stock(gtk.STOCK_SAVE,
+                                    gtk.ICON_SIZE_MENU))
+        saveMenuItem.connect('activate', self.onSaveActivate)
+        saveMenuItem.add_accelerator('activate', accelGroup, ord('R'),
+                                gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
+       
         clearMenuItem = gtk.ImageMenuItem(_('C_lear Conversation'))
         clearMenuItem.set_image(gtk.image_new_from_stock(gtk.STOCK_CLEAR,
                                     gtk.ICON_SIZE_MENU))
@@ -617,6 +627,7 @@
 
         conversationMenu.add(self.inviteMenuItem)
         conversationMenu.add(self.sendFileMenuItem)
+        conversationMenu.add(saveMenuItem)
         conversationMenu.add(clearMenuItem)
         conversationMenu.add(gtk.SeparatorMenuItem())
         conversationMenu.add(closeMenuItem)
@@ -649,6 +660,11 @@
         '''This method is called when Invite is activated on the menu'''
         self.parentConversationWindow.send_file_dialog()
 
+    def onSaveActivate(self, *args):
+        '''This method is called when Save Conversation
+           is activated on the menu'''
+        self.parentConversationWindow.show_save_dialog()
+   
     def onLogActivate(self, check):
         '''This method is called when Log is activated on the menu'''
         self.parentConversationWindow.conversation.setDoLog(
@@ -666,3 +682,51 @@
         '''This method is called when a switchboard error is detected'''
         self.inviteMenuItem.set_sensitive(False)
         self.sendFileMenuItem.set_sensitive(False)
+
+class SaveConversationDialog (gtk.FileChooserDialog):
+    def __init__ (self, parentConversationWindow):
+        self.parentConversationWindow = parentConversationWindow
+        self.status = True
+       
+        gtk.FileChooserDialog.__init__(self,
+                                       title="Save Conversation to a file",
+                                       parent=None,
+                                       action=gtk.FILE_CHOOSER_ACTION_SAVE,
+                                       buttons=(gtk.STOCK_SAVE, gtk.RESPONSE_OK,
+                                       gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT),
+                                       backend=None)
+       
+        response = self.run()
+       
+        if response == gtk.RESPONSE_OK:
+            self.filename = self.get_filename()
+            self.save()
+            self.destroy()
+            self.show_save_status()
+        else:
+            self.destroy()
+   
+    def save (self):
+        conversation = self.parentConversationWindow.conversation
+        text = conversation.getConversationText()
+       
+        try:
+            file = open(self.filename, 'w')
+            file.write(text)
+            file.close()
+        except:
+            self.status = False
+   
+    def show_save_status (self):
+        if self.status:
+            status_type = gtk.MESSAGE_INFO
+            status_message = "The conversation has been saved."
+        else:
+            status_type = gtk.MESSAGE_ERROR
+            status_message = "An error occurred saving the conversation."
+       
+        show = gtk.MessageDialog(parent=None, flags=0, type=status_type,
+                                 buttons=gtk.BUTTONS_OK,
+                                 message_format=status_message)
+        show.run()
+        show.destroy()
--- emesene/ConversationUI.py 2010-01-07 20:33:59.000000000 +0100
+++ Coding/emesene-work/ConversationUI.py 2010-01-08 16:57:16.000000000 +0100
@@ -1543,6 +1543,23 @@
             self.insert(gtk.SeparatorToolItem(), -1)
         separator = False
 
+        # save conversation toolbar button
+        if self.config.user['toolSave']:
+            self.saveButton = gtk.ToolButton()
+            self.saveButton.set_label(_('Save conversation'))
+            if self.controller.theme.getImage('save'):
+                saveicon = gtk.Image()
+                saveicon.set_from_pixbuf(self.controller.theme.getImage('save'))
+                self.saveButton.set_icon_widget(saveicon)
+            else:
+                self.saveButton.set_stock_id(gtk.STOCK_SAVE_AS)
+            self.saveButton.connect('clicked', self.showSaveDialog)
+            self.insert(self.saveButton, -1)
+            self.saveButton.set_tooltip_text(_('Save conversation'))
+            separator = True
+        else:
+            self.saveButton = None
+
         #clear conversation toolbar button
         if self.config.user['toolClear']:
             imgclear = gtk.Image()
@@ -1667,6 +1684,11 @@
         if win is not None:
             win.send_file_dialog()
 
+    def showSaveDialog(self, *args):
+        '''this method is called when the user click
+           the save conversation button'''
+        self.parentUI.parentConversation.parentConversationWindow.show_save_dialog()
+   
     def sendWebcamClicked(self, *args):
         ret = self.parentUI.parentConversation.sendWebcam()
         if ret == 1:
--- emesene/PreferenceWindow.py 2010-01-07 20:33:59.000000000 +0100
+++ Coding/emesene-work/PreferenceWindow.py 2010-01-08 16:34:35.000000000 +0100
@@ -1135,7 +1135,6 @@
         self.sendfileButton.connect('clicked', self.on_toggled, 'toolSendFile')
         self.pack_start(self.sendfileButton, False, False)
 
-
         # webcam send hax
         camicon = gtk.image_new_from_pixbuf(self.controller.theme.getImage('cam'))
         self.sendWebcamButton = gtk.ToggleButton()
@@ -1148,6 +1147,20 @@
 
         self.pack_start(gtk.SeparatorToolItem(), False, False)
 
+        # save conversation
+        self.saveButton = gtk.ToggleButton()
+        saveIcon = self.controller.theme.getImage('save')
+        if saveIcon != None:
+            self.saveButton.set_image(gtk.image_new_from_pixbuf(saveIcon))
+        else:
+            self.saveButton.set_image(gtk.image_new_from_stock(gtk.STOCK_SAVE_AS,
+                                      gtk.ICON_SIZE_SMALL_TOOLBAR))
+        self.saveButton.set_active(not self.config.user['toolSave'])
+        self.saveButton.set_tooltip_text(_('Save conversation'))
+
+        self.saveButton.connect('clicked', self.on_toggled, 'toolSave')
+        self.pack_start(self.saveButton, False, False)
+       
         #clear conversation toolbar button
         self.clearButton = gtk.ToggleButton()
         clearIcon = self.controller.theme.getImage('clear')

Let me know how it's.
Logged

hit^
Hero Member
*****

l33tness: 1
Offline Offline

Posts: 370


svn up´d


View Profile
« Reply #17 on: January 08, 2010, 09:07:52 AM »

Good job. Fixed your patch (wrong paths and some fuzzy stuff).

-- edit
Something was missing.
« Last Edit: January 08, 2010, 09:17:20 AM by hit^ » Logged

"We are changing the world, one commit at a time."
checkm
Full Member
***

l33tness: 8
Offline Offline

Posts: 18


scacco_m@hotmail.it
View Profile WWW Email
« Reply #18 on: January 08, 2010, 12:13:57 PM »

I think that there's a little problem in ConversationWindowMenu class. I can't access to objects like conversationMenu, formatMenu or accelGroup out of their gtk.MenuBar, which is the only thing I can get. How can I add a child to the menu without writing a patch?
ConversationWindow.py, line 585:
Code:
        conversationMenu = gtk.Menu()

I found the same problem trying to just add the toolbar button instead. In fact, if I want to add that button in the conversation toolbar I have to put it in the Interface page, but in self.interface_page istance I can't get toolbarHBox because it's private.
PreferenceWindow.py, line 928:
Code:
        toolbarHBox = gtk.HBox()
« Last Edit: January 08, 2010, 12:25:49 PM by checkm » Logged

C10uD
ololol
Administrator
Hero Member
*****

l33tness: -9990
Offline Offline

Posts: 2308



View Profile Email
« Reply #19 on: January 10, 2010, 08:37:14 AM »

you must directly patch preferencewindow for that

conversation stuff: too
Logged
fabioamd87
Hero Member
*****

l33tness: 1
Offline Offline

Posts: 455



View Profile Email
« Reply #20 on: February 03, 2010, 09:14:58 AM »

today I needed this feature...

any possibility to merge this patch?
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

TinyPortal v.1.0.6 beta 2 © Bloc
Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!