Changeset 8886

Show
Ignore:
Timestamp:
10/07/07 01:06:09 (14 months ago)
Author:
steve-e
Message:

Add global search to history_viewer. Minor GUI improvements. Fix nasty bug: history_window was adding unexisting jids to logs.db, when it was tried to view their history.

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/data/glade/history_window.glade

    r8815 r8886  
    3434                        <property name="can_focus">True</property> 
    3535                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> 
     36                        <property name="tooltip" translatable="yes">Choose the chatlog you want to view.  
     37Enter the jid of a groupchat or a contact here. For online accounts you can even enter a a contact's nickname.</property> 
    3638                        <signal name="activate" handler="on_jid_entry_activate"/> 
    3739                      </widget> 
    38                     </child> 
    39                     <child> 
    40                       <widget class="GtkLabel" id="label3"> 
    41                         <property name="visible">True</property> 
    42                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> 
    43                         <property name="xalign">0</property> 
    44                         <property name="label" translatable="yes">Enter a contact jid or MUC jid here to view its history. 
    45 If a contact is connected you can even enter his nick name. 
    46 </property> 
    47                         <property name="wrap">True</property> 
    48                       </widget> 
    49                       <packing> 
    50                         <property name="expand">False</property> 
    51                         <property name="fill">False</property> 
    52                         <property name="position">1</property> 
    53                       </packing> 
    5440                    </child> 
    5541                  </widget> 
     
    178164                    <property name="spacing">6</property> 
    179165                    <child> 
    180                       <widget class="GtkEntry" id="query_entry"> 
    181                         <property name="visible">True</property> 
    182                         <property name="can_focus">True</property> 
    183                         <property name="activates_default">True</property> 
    184                       </widget> 
    185                     </child> 
    186                     <child> 
    187                       <widget class="GtkButton" id="search_button"> 
    188                         <property name="visible">True</property> 
    189                         <property name="can_focus">True</property> 
    190                         <property name="can_default">True</property> 
    191                         <property name="has_default">True</property> 
    192                         <property name="response_id">0</property> 
    193                         <signal name="clicked" handler="on_search_button_clicked"/> 
    194                         <child> 
    195                           <widget class="GtkAlignment" id="alignment99"> 
    196                             <property name="visible">True</property> 
    197                             <property name="xscale">0</property> 
    198                             <property name="yscale">0</property> 
    199                             <child> 
    200                               <widget class="GtkHBox" id="hbox3004"> 
    201                                 <property name="visible">True</property> 
    202                                 <property name="spacing">2</property> 
    203                                 <child> 
    204                                   <widget class="GtkImage" id="image1327"> 
    205                                     <property name="visible">True</property> 
    206                                     <property name="stock">gtk-find</property> 
    207                                   </widget> 
    208                                   <packing> 
    209                                     <property name="expand">False</property> 
    210                                     <property name="fill">False</property> 
    211                                   </packing> 
    212                                 </child> 
    213                                 <child> 
    214                                   <widget class="GtkLabel" id="label372"> 
    215                                     <property name="visible">True</property> 
    216                                     <property name="label" translatable="yes">Search</property> 
    217                                     <property name="use_underline">True</property> 
    218                                   </widget> 
    219                                   <packing> 
    220                                     <property name="expand">False</property> 
    221                                     <property name="fill">False</property> 
    222                                     <property name="position">1</property> 
    223                                   </packing> 
    224                                 </child> 
    225                               </widget> 
    226                             </child> 
    227                           </widget> 
    228                         </child> 
     166                      <widget class="GtkLabel" id="label3"> 
     167                        <property name="visible">True</property> 
     168                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> 
     169                        <property name="label" translatable="yes">Search</property> 
    229170                      </widget> 
    230171                      <packing> 
    231172                        <property name="expand">False</property> 
    232173                        <property name="fill">False</property> 
    233                         <property name="position">1</property> 
    234                       </packing> 
    235                     </child> 
    236                     <child> 
    237                       <widget class="GtkButton" id="query_builder_button"> 
    238                         <property name="visible">True</property> 
    239                         <property name="can_focus">True</property> 
    240                         <property name="tooltip" translatable="yes">Build custom query</property> 
    241                         <property name="label" translatable="yes">Query Builder...</property> 
    242                         <property name="use_underline">True</property> 
    243                         <property name="response_id">0</property> 
    244                         <signal name="clicked" handler="on_query_builder_button_clicked"/> 
     174                      </packing> 
     175                    </child> 
     176                    <child> 
     177                      <widget class="GtkEntry" id="query_entry"> 
     178                        <property name="visible">True</property> 
     179                        <property name="can_focus">True</property> 
     180                        <property name="activates_default">True</property> 
     181                        <signal name="activate" handler="on_query_entry_activate"/> 
     182                      </widget> 
     183                      <packing> 
     184                        <property name="position">2</property> 
     185                      </packing> 
     186                    </child> 
     187                    <child> 
     188                      <widget class="GtkLabel" id="label4"> 
     189                        <property name="visible">True</property> 
     190                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> 
     191                        <property name="label" translatable="yes">in</property> 
    245192                      </widget> 
    246193                      <packing> 
    247194                        <property name="expand">False</property> 
    248195                        <property name="fill">False</property> 
    249                         <property name="position">2</property> 
     196                        <property name="position">3</property> 
     197                      </packing> 
     198                    </child> 
     199                    <child> 
     200                      <widget class="GtkComboBox" id="query_combobox"> 
     201                        <property name="visible">True</property> 
     202                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> 
     203                        <property name="focus_on_click">False</property> 
     204                        <property name="items" translatable="yes">Current History 
     205All Chat Histories</property> 
     206                        <signal name="changed" handler="on_query_combobox_changed"/> 
     207                      </widget> 
     208                      <packing> 
     209                        <property name="expand">False</property> 
     210                        <property name="fill">False</property> 
     211                        <property name="pack_type">GTK_PACK_END</property> 
     212                        <property name="position">1</property> 
    250213                      </packing> 
    251214                    </child> 
  • trunk/src/history_window.py

    r8846 r8886  
    4242# contact_name, date, message, time 
    4343( 
     44C_LOG_JID, 
    4445C_CONTACT_NAME, 
    4546C_UNIXTIME, 
    4647C_MESSAGE, 
    4748C_TIME 
    48 ) = range(4) 
     49) = range(5) 
    4950 
    5051class HistoryWindow: 
     
    5354        def __init__(self, jid = None, account = None): 
    5455                if jid is None: 
     56                        # Use self.jid to pass text to input_entry 
    5557                        self.jid = 'Enter jid or contact name here' 
    5658                else: 
     
    6264                xml = gtkgui_helpers.get_glade('history_window.glade') 
    6365                self.window = xml.get_widget('history_window') 
    64                  
    6566                self.jid_entry = xml.get_widget('jid_entry') 
    6667                self.calendar = xml.get_widget('calendar') 
     
    7475                self.checkbutton.connect('toggled', self.on_log_history_checkbutton_toggled) 
    7576                self.query_entry = xml.get_widget('query_entry') 
    76                 self.search_button = xml.get_widget('search_button') 
    77                 query_builder_button = xml.get_widget('query_builder_button') 
    78                 query_builder_button.hide() 
    79                 query_builder_button.set_no_show_all(True) 
    8077                self.expander_vbox = xml.get_widget('expander_vbox') 
    81                  
     78                self.query_combobox = xml.get_widget('query_combobox') 
     79                self.query_combobox.set_active(0) 
    8280                self.results_treeview = xml.get_widget('results_treeview') 
    8381                 
     
    8684                liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry) 
    8785                 
    88                 # Add all jids in the db 
     86                # Add all jids in logs.db: 
     87                # he only info we have got to fill the dict is the JID, use it as key 
    8988                db_jids = gajim.logger.get_jids_in_db() 
    9089                for jid in db_jids: 
    91                         self.completion_dict[jid] = jid 
    92                  
    93                 # Enhance contacts of online accounts with their names 
     90                        self.completion_dict[jid] = None 
     91                 
     92                # Enhance contacts of online accounts with their contact reference and their name 
    9493                for account in gajim.contacts.get_accounts(): 
    9594                        self.completion_dict.update(helpers.get_contact_dict_for_account(account)) 
     
    105104 
    106105                # contact_name, date, message, time 
    107                 model = gtk.ListStore(str, str, str, str) 
     106                model = gtk.ListStore(str, str, str, str, str) 
    108107                self.results_treeview.set_model(model) 
    109108                col = gtk.TreeViewColumn(_('Name')) 
     
    144143                del gajim.interface.instances['logs'] 
    145144 
    146  
    147145        def on_close_button_clicked(self, widget): 
    148146                self.window.destroy() 
     
    151149                self.jid = self.jid_entry.get_text() 
    152150                 
    153                 if self.completion_dict.has_key(self.jid): # a full qualified jid or contact name was entered 
    154                         contact_name = self.completion_dict[self.jid] 
    155                         if self.jid != contact_name: 
    156                                 self.jid = contact_name.jid # jid enhanced with contact 
     151                if self.completion_dict.has_key(self.jid): # a full qualified jid or a contact name was entered 
     152                        contact = self.completion_dict[self.jid] 
     153                        if contact: # we have got additional info, jid enhanced with contact 
     154                                self.jid = contact.jid 
     155                                self.jid_entry.set_text(contact.get_shown_name()) 
     156                                self.jids_to_search = [contact.jid] 
     157                        else: 
     158                                self.jids_to_search = [self.jid] 
    157159                         
     160                        # Try to find the corresponding account of the jid 
    158161                        accounts = gajim.contacts.get_accounts() 
    159162                        self.account = None 
     
    165168                        if self.account is None: 
    166169                                # We do not know an account. This can only happen if the contact is offine, 
    167                                 # or if we browse a groupchat history. The account is not needed, a dummy can 
     170                                # or if we browse a groupchat history. The account is not really needed, a dummy can 
    168171                                # be set. 
    169172                                # FIXME: This may leed to wrong self nick in the displayed history 
     
    171174                                self.checkbutton.set_sensitive(False) 
    172175                        else: 
    173                                 # Set the logging checkbutton, can only work if we have got an account. 
     176                                # The logging checkbutton, can only work if we have got an account. 
    174177                                log = True 
    175178                                if self.jid in gajim.config.get_per('accounts', self.account, 
     
    181184                        # select logs for last date we have logs with contact 
    182185                        self.calendar.set_sensitive(True) 
     186                        self.calendar.emit('month-changed') 
    183187                        lastlog = gajim.logger.get_last_date_that_has_logs(self.jid, self.account) 
     188 
     189                        tim = lastlog 
     190                        date = time.localtime(tim) 
     191 
     192                        y, m, d = date[0], date[1], date[2] 
     193                        gtk_month = gtkgui_helpers.make_python_month_gtk_month(m) 
     194                        self.calendar.select_month(gtk_month, y) 
     195                        self.calendar.select_day(d) 
    184196                         
     197                        self.query_entry.set_sensitive(True) 
     198 
    185199                        if contact: 
    186200                                title = _('Conversation History with %s') % contact.get_shown_name() 
     
    191205 
    192206                else:   # neither a valid jid, nor an existing contact name was entered 
    193                         lastlog = None 
    194                          
     207                        # we have got nothing to show or to search in 
     208                        self.history_buffer.set_text('') # clear the buffer 
     209                        self.query_entry.set_sensitive(False) 
     210 
    195211                        self.checkbutton.set_sensitive(False) 
    196  
    197212                        self.calendar.set_sensitive(False) 
     213                        self.calendar.clear_marks() 
    198214                         
    199215                        title = _('Conversation History') 
    200216                        self.window.set_title(title) 
    201  
    202                 self.calendar.emit('month-changed') 
    203  
    204                 # Show logs for contact. If we don't have logs at all, default to today 
    205                 if lastlog is None: 
    206                         date = time.localtime() 
    207                 else: 
    208                         tim = lastlog 
    209                         date = time.localtime(tim) 
    210  
    211                 y, m, d = date[0], date[1], date[2] 
    212                 gtk_month = gtkgui_helpers.make_python_month_gtk_month(m) 
    213                 self.calendar.select_month(gtk_month, y) 
    214                 self.calendar.select_day(d) 
    215                 self.add_lines_for_date(y, m, d) 
    216217 
    217218        def on_calendar_day_selected(self, widget): 
     
    389390                else: 
    390391                        gobject.timeout_add(200, self.set_unset_expand_on_expander, widget) 
    391                         self.search_button.grab_default() 
    392392                        self.query_entry.grab_focus() 
    393393         
    394         def on_search_button_clicked(self, widget): 
     394        def on_query_entry_activate(self, widget): 
    395395                text = self.query_entry.get_text() 
    396396                model = self.results_treeview.get_model() 
     
    398398                if text == '': 
    399399                        return 
    400                 # contact_name, time, kind, show, message, subject 
    401                 results = gajim.logger.get_search_results_for_query( 
    402                                                 self.jid, text, self.account) 
    403                 #FIXME: 
    404                 # add "subject:  | message: " in message column if kind is single 
    405                 # also do we need show at all? (we do not search on subject) 
    406                 for row in results: 
    407                         contact_name = row[0] 
    408                         if not contact_name: 
    409                                 kind = row[2] 
    410                                 if kind == constants.KIND_CHAT_MSG_SENT: # it's us! :) 
    411                                         contact_name = gajim.nicks[self.account] 
     400 
     401                # perform search in preselected jids. jids are preselected with the query_combobox (all, current...) 
     402                for jid in self.jids_to_search: 
     403                        accounts = gajim.contacts.get_accounts()         
     404                        account = None 
     405                        for acc in accounts: 
     406                                contact = gajim.contacts.get_first_contact_from_jid(acc ,jid) 
     407                                if contact: 
     408                                        account = acc 
     409                                        break 
     410                        if account is None: 
     411                                # We do not know an account. This can only happen if the contact is offine, 
     412                                # or if we browse a groupchat history. The account is not needed, a dummy can 
     413                                # be set. 
     414                                # FIXME: This may leed to wrong self nick in the displayed history 
     415                                account = gajim.contacts.get_accounts()[0] 
     416 
     417                        # contact_name, time, kind, show, message, subject 
     418                        results = gajim.logger.get_search_results_for_query( 
     419                                                jid, text, account) 
     420                        #FIXME: 
     421                        # add "subject:  | message: " in message column if kind is single 
     422                        # also do we need show at all? (we do not search on subject) 
     423                        for row in results: 
     424                                contact_name = row[0] 
     425                                if not contact_name: 
     426                                        kind = row[2] 
     427                                        if kind == constants.KIND_CHAT_MSG_SENT: # it's us! :) 
     428                                                contact_name = gajim.nicks[account] 
     429                                        else: 
     430                                                contact = self.completion_dict[jid] 
     431                                                if contact: 
     432                                                        contact_name = contact.get_shown_name() 
     433                                                else: 
     434                                                        contact_name = jid 
     435                                tim = row[1] 
     436                                message = row[4] 
     437                                local_time = time.localtime(tim) 
     438                                date = time.strftime('%x', local_time) 
     439                                #  jid (to which log is assigned to), name, date, message, time (full unix time) 
     440                                model.append((jid, contact_name, date, message, tim)) 
     441 
     442        def on_query_combobox_changed(self, widget): 
     443                self.jids_to_search = [] 
     444                if self.query_combobox.get_active() == 0: 
     445                        # Search current contact 
     446                        if self.completion_dict.has_key(self.jid): 
     447                                self.query_entry.set_sensitive(True) 
     448                                contact = self.completion_dict[self.jid] 
     449                                if contact:  
     450                                        self.jids_to_search = [contact.jid] 
    412451                                else: 
    413                                         contact = gajim.contacts.get_first_contact_from_jid(self.account, 
    414                                                 self.jid) 
    415                                         if contact: 
    416                                                 contact_name = contact.get_shown_name() 
    417                                         else: 
    418                                                 contact_name = self.jid 
    419                         tim = row[1] 
    420                         message = row[4] 
    421                         local_time = time.localtime(tim) 
    422                         date = time.strftime('%x', local_time) 
    423                         # name, date, message, time (full unix time) 
    424                         model.append((contact_name, date, message, tim)) 
     452                                        self.jids_to_search = [self.jid] 
     453                        else: 
     454                                # We cannot search in logs of an non-existing jid 
     455                                self.query_entry.set_sensitive(False) 
     456                if self.query_combobox.get_active() == 1: 
     457                        # Search all histories 
     458                        self.query_entry.set_sensitive(True) 
     459                        self.jids_to_search = gajim.logger.get_jids_in_db() 
     460 
    425461                         
    426462        def on_results_treeview_row_activated(self, widget, path, column): 
     
    437473                month = gtkgui_helpers.make_python_month_gtk_month(gtk_month) 
    438474                day = tim[2] 
    439                  
     475                         
     476                # switch to belonging logfile if necessary 
     477                log_jid = model[path][C_LOG_JID] 
     478                if log_jid != self.jid: 
     479                        self.open_history(log_jid, None) 
     480 
    440481                # avoid reruning mark days algo if same month and year! 
    441482                if year != cur_year or gtk_month != cur_month: 
     
    484525 
    485526        def open_history(self, jid, account): 
    486                 # Simulate that the jid was entered by hand 
     527                '''Simulate that the jid was entered by hand''' 
    487528                self.jid_entry.set_text(jid) 
    488529                self.jid_entry.emit('activate')