Changeset 8886
- Timestamp:
- 10/07/07 01:06:09 (14 months ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
data/glade/history_window.glade (modified) (2 diffs)
-
src/history_window.py (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/glade/history_window.glade
r8815 r8886 34 34 <property name="can_focus">True</property> 35 35 <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. 37 Enter the jid of a groupchat or a contact here. For online accounts you can even enter a a contact's nickname.</property> 36 38 <signal name="activate" handler="on_jid_entry_activate"/> 37 39 </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>54 40 </child> 55 41 </widget> … … 178 164 <property name="spacing">6</property> 179 165 <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> 229 170 </widget> 230 171 <packing> 231 172 <property name="expand">False</property> 232 173 <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> 245 192 </widget> 246 193 <packing> 247 194 <property name="expand">False</property> 248 195 <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 205 All 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> 250 213 </packing> 251 214 </child> -
trunk/src/history_window.py
r8846 r8886 42 42 # contact_name, date, message, time 43 43 ( 44 C_LOG_JID, 44 45 C_CONTACT_NAME, 45 46 C_UNIXTIME, 46 47 C_MESSAGE, 47 48 C_TIME 48 ) = range( 4)49 ) = range(5) 49 50 50 51 class HistoryWindow: … … 53 54 def __init__(self, jid = None, account = None): 54 55 if jid is None: 56 # Use self.jid to pass text to input_entry 55 57 self.jid = 'Enter jid or contact name here' 56 58 else: … … 62 64 xml = gtkgui_helpers.get_glade('history_window.glade') 63 65 self.window = xml.get_widget('history_window') 64 65 66 self.jid_entry = xml.get_widget('jid_entry') 66 67 self.calendar = xml.get_widget('calendar') … … 74 75 self.checkbutton.connect('toggled', self.on_log_history_checkbutton_toggled) 75 76 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)80 77 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) 82 80 self.results_treeview = xml.get_widget('results_treeview') 83 81 … … 86 84 liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry) 87 85 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 89 88 db_jids = gajim.logger.get_jids_in_db() 90 89 for jid in db_jids: 91 self.completion_dict[jid] = jid92 93 # Enhance contacts of online accounts with their names90 self.completion_dict[jid] = None 91 92 # Enhance contacts of online accounts with their contact reference and their name 94 93 for account in gajim.contacts.get_accounts(): 95 94 self.completion_dict.update(helpers.get_contact_dict_for_account(account)) … … 105 104 106 105 # contact_name, date, message, time 107 model = gtk.ListStore(str, str, str, str )106 model = gtk.ListStore(str, str, str, str, str) 108 107 self.results_treeview.set_model(model) 109 108 col = gtk.TreeViewColumn(_('Name')) … … 144 143 del gajim.interface.instances['logs'] 145 144 146 147 145 def on_close_button_clicked(self, widget): 148 146 self.window.destroy() … … 151 149 self.jid = self.jid_entry.get_text() 152 150 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] 157 159 160 # Try to find the corresponding account of the jid 158 161 accounts = gajim.contacts.get_accounts() 159 162 self.account = None … … 165 168 if self.account is None: 166 169 # 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 can170 # or if we browse a groupchat history. The account is not really needed, a dummy can 168 171 # be set. 169 172 # FIXME: This may leed to wrong self nick in the displayed history … … 171 174 self.checkbutton.set_sensitive(False) 172 175 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. 174 177 log = True 175 178 if self.jid in gajim.config.get_per('accounts', self.account, … … 181 184 # select logs for last date we have logs with contact 182 185 self.calendar.set_sensitive(True) 186 self.calendar.emit('month-changed') 183 187 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) 184 196 197 self.query_entry.set_sensitive(True) 198 185 199 if contact: 186 200 title = _('Conversation History with %s') % contact.get_shown_name() … … 191 205 192 206 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 195 211 self.checkbutton.set_sensitive(False) 196 197 212 self.calendar.set_sensitive(False) 213 self.calendar.clear_marks() 198 214 199 215 title = _('Conversation History') 200 216 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 today205 if lastlog is None:206 date = time.localtime()207 else:208 tim = lastlog209 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)216 217 217 218 def on_calendar_day_selected(self, widget): … … 389 390 else: 390 391 gobject.timeout_add(200, self.set_unset_expand_on_expander, widget) 391 self.search_button.grab_default()392 392 self.query_entry.grab_focus() 393 393 394 def on_ search_button_clicked(self, widget):394 def on_query_entry_activate(self, widget): 395 395 text = self.query_entry.get_text() 396 396 model = self.results_treeview.get_model() … … 398 398 if text == '': 399 399 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] 412 451 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 425 461 426 462 def on_results_treeview_row_activated(self, widget, path, column): … … 437 473 month = gtkgui_helpers.make_python_month_gtk_month(gtk_month) 438 474 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 440 481 # avoid reruning mark days algo if same month and year! 441 482 if year != cur_year or gtk_month != cur_month: … … 484 525 485 526 def open_history(self, jid, account): 486 # Simulate that the jid was entered by hand527 '''Simulate that the jid was entered by hand''' 487 528 self.jid_entry.set_text(jid) 488 529 self.jid_entry.emit('activate')
