Changeset 224

Show
Ignore:
Timestamp:
02/02/06 18:55:23 (3 years ago)
Author:
edmanm
Message:

Add basic search functionality to the message log.

Location:
trunk/src/gui/messagelog
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/messagelog/messagelog.cpp

    r212 r224  
    2222 ****************************************************************/ 
    2323 
     24#include <QMessageBox> 
     25#include <QInputDialog> 
     26 
    2427#include "../mainwindow.h" 
    2528#include "messagelog.h" 
     
    104107      this, SLOT(clear())); 
    105108   
     109  connect(ui.actionFind, SIGNAL(triggered()), 
     110      this, SLOT(find())); 
     111 
    106112  connect(ui.btnSaveSettings, SIGNAL(clicked()), 
    107113      this, SLOT(saveChanges())); 
     
    387393} 
    388394 
     395/** Prompts the user for a search string. If the search string is not found in 
     396 * any of the currently displayed log entires, then a message will be 
     397 * displayed for the user informing them that no matches were found.  
     398 * \sa search() 
     399 */ 
     400void 
     401MessageLog::find() 
     402{ 
     403  QString empty; 
     404  bool ok; 
     405  QString text = QInputDialog::getText(this, tr("Find in Message Log"), 
     406                  tr("Find:"), QLineEdit::Normal, QString(), &ok); 
     407   
     408  if (ok && !text.isEmpty()) { 
     409    QTreeWidget *tree = ui.lstMessages; 
     410    QList<QTreeWidgetItem *> results = search(text); 
     411    if (!results.size()) { 
     412      QMessageBox::information(this, tr("Not Found"),  
     413                               tr("Search found 0 matches."),  
     414                               QMessageBox::Ok, QMessageBox::NoButton); 
     415    } else { 
     416      /* Deselect all currently selected items */ 
     417      deselectAllItems(); 
     418      /* Select the new matching items */ 
     419      foreach(QTreeWidgetItem *item, results) { 
     420        if (!tree->isItemHidden(item)) { 
     421           tree->setItemSelected(item, true); 
     422         } 
     423      } 
     424      /* Set the focus to the first match */ 
     425      tree->scrollToItem(results.at(0)); 
     426    } 
     427  } 
     428} 
     429 
    389430/** 
    390431 Clears the message list and resets the message counter 
     
    396437  ui.lstMessages->setStatusTip(QString("Messages Shown: %1") 
    397438                                  .arg(_messagesShown)); 
     439} 
     440 
     441/** Searches the currently displayed log entries for the given search text. 
     442 * 
     443 * \param text The text to search for. 
     444 * \returns A list of all log items containing the search text.  
     445 */ 
     446QList<QTreeWidgetItem *> 
     447MessageLog::search(QString text) 
     448{ 
     449  QTreeWidget *tree = ui.lstMessages; 
     450  QList<QTreeWidgetItem *> results; 
     451 
     452  /* Search through the messages in the tree, case-insensitively */ 
     453  return tree->findItems(text, Qt::MatchContains|Qt::MatchWrap, COL_MSG); 
     454} 
     455 
     456/** Deselects all currently selected items. */ 
     457void 
     458MessageLog::deselectAllItems() 
     459{ 
     460  QTreeWidget *tree = ui.lstMessages; 
     461  foreach(QTreeWidgetItem *item, tree->selectedItems()) { 
     462    tree->setItemSelected(item, false); 
     463  } 
    398464} 
    399465 
  • trunk/src/gui/messagelog/messagelog.h

    r212 r224  
    7474  /** Called when the user selects View->Clear all or Ctrl-E **/ 
    7575  void clear(); 
     76  /** Called when the user selects Edit->Find or Ctrl-F. This will search 
     77   * through all currently displayed log entries for text specified by the 
     78   * user, highlighting the entires that contain a match. */ 
     79  void find(); 
    7680  /** Called when the opactity slider changes value **/ 
    7781  void setOpacity(int value); 
     
    96100  /** Saves the given list of items to a file */ 
    97101  void save(QList<QTreeWidgetItem *> items); 
    98    
     102  /** Searches the message log for entries that contain the given text. */ 
     103  QList<QTreeWidgetItem *> search(QString text); 
     104  /** Deselects all currently selected items. */ 
     105  void deselectAllItems(); 
     106 
    99107  /** A pointer to a TorControl object, used to register for log events */ 
    100108  TorControl* _torControl; 
  • trunk/src/gui/messagelog/messagelog.ui

    r208 r224  
    293293  </property> 
    294294  <property name="windowIcon" > 
    295    <iconset resource="..\res\vidalia.qrc" >:/images/tor_logo16.png</iconset> 
     295   <iconset resource="../res/vidalia.qrc" >:/images/tor_logo16.png</iconset> 
    296296  </property> 
    297297  <property name="statusTip" > 
     
    467467              </property> 
    468468              <property name="icon" > 
    469                <iconset resource="..\res\vidalia.qrc" >:/images/msg_error.png</iconset> 
     469               <iconset resource="../res/vidalia.qrc" >:/images/msg_error.png</iconset> 
    470470              </property> 
    471471             </widget> 
     
    483483              </property> 
    484484              <property name="icon" > 
    485                <iconset resource="..\res\vidalia.qrc" >:/images/msg_warn.png</iconset> 
     485               <iconset resource="../res/vidalia.qrc" >:/images/msg_warn.png</iconset> 
    486486              </property> 
    487487             </widget> 
     
    499499              </property> 
    500500              <property name="icon" > 
    501                <iconset resource="..\res\vidalia.qrc" >:/images/msg_notice.png</iconset> 
     501               <iconset resource="../res/vidalia.qrc" >:/images/msg_notice.png</iconset> 
    502502              </property> 
    503503             </widget> 
     
    515515              </property> 
    516516              <property name="icon" > 
    517                <iconset resource="..\res\vidalia.qrc" >:/images/msg_info.png</iconset> 
     517               <iconset resource="../res/vidalia.qrc" >:/images/msg_info.png</iconset> 
    518518              </property> 
    519519             </widget> 
     
    531531              </property> 
    532532              <property name="icon" > 
    533                <iconset resource="..\res\vidalia.qrc" >:/images/msg_debug.png</iconset> 
     533               <iconset resource="../res/vidalia.qrc" >:/images/msg_debug.png</iconset> 
    534534              </property> 
    535535             </widget> 
     
    900900     <y>0</y> 
    901901     <width>701</width> 
    902      <height>19</height> 
     902     <height>22</height> 
    903903    </rect> 
    904904   </property> 
    905    <widget class="QMenu" name="menu_Edit" > 
    906     <property name="title" > 
    907      <string>&amp;Edit</string> 
    908     </property> 
    909     <addaction name="actionCopy" /> 
    910     <addaction name="actionSelect_All" /> 
    911    </widget> 
    912905   <widget class="QMenu" name="menu_File" > 
    913906    <property name="title" > 
     
    932925    <addaction name="actionClear" /> 
    933926   </widget> 
     927   <widget class="QMenu" name="menu_Edit" > 
     928    <property name="title" > 
     929     <string>&amp;Edit</string> 
     930    </property> 
     931    <addaction name="actionCopy" /> 
     932    <addaction name="actionSelect_All" /> 
     933    <addaction name="separator" /> 
     934    <addaction name="actionFind" /> 
     935   </widget> 
    934936   <addaction name="menu_File" /> 
    935937   <addaction name="menu_Edit" /> 
     
    940942    <rect> 
    941943     <x>0</x> 
    942      <y>536</y> 
     944     <y>538</y> 
    943945     <width>701</width> 
    944      <height>22</height> 
     946     <height>20</height> 
    945947    </rect> 
    946948   </property> 
     
    11131115   </property> 
    11141116  </action> 
     1117  <action name="actionFind" > 
     1118   <property name="text" > 
     1119    <string>Find</string> 
     1120   </property> 
     1121   <property name="font" > 
     1122    <font> 
     1123     <family>Arial</family> 
     1124     <pointsize>10</pointsize> 
     1125     <weight>50</weight> 
     1126     <italic>false</italic> 
     1127     <bold>false</bold> 
     1128     <underline>false</underline> 
     1129     <strikeout>false</strikeout> 
     1130    </font> 
     1131   </property> 
     1132   <property name="shortcut" > 
     1133    <string>⌘F</string> 
     1134   </property> 
     1135  </action> 
    11151136 </widget> 
    11161137 <pixmapfunction></pixmapfunction> 
    11171138 <resources> 
    11181139  <include location="res/vidalia.qrc" /> 
     1140  <include location="../res/vidalia.qrc" /> 
    11191141  <include location="../res/vidalia.qrc" /> 
    11201142 </resources>