[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r4091: Add support for the "Save All" and "Save Selected" toolbar a (vidalia/trunk/src/vidalia/log)



Author: edmanm
Date: 2009-08-29 23:10:07 -0400 (Sat, 29 Aug 2009)
New Revision: 4091

Modified:
   vidalia/trunk/src/vidalia/log/LogTreeItem.cpp
   vidalia/trunk/src/vidalia/log/MessageLog.cpp
   vidalia/trunk/src/vidalia/log/MessageLog.h
   vidalia/trunk/src/vidalia/log/StatusEventItem.cpp
   vidalia/trunk/src/vidalia/log/StatusEventItem.h
   vidalia/trunk/src/vidalia/log/StatusEventWidget.cpp
   vidalia/trunk/src/vidalia/log/StatusEventWidget.h
Log:

Add support for the "Save All" and "Save Selected" toolbar actions to the
status event tab.


Modified: vidalia/trunk/src/vidalia/log/LogTreeItem.cpp
===================================================================
--- vidalia/trunk/src/vidalia/log/LogTreeItem.cpp	2009-08-30 01:48:36 UTC (rev 4090)
+++ vidalia/trunk/src/vidalia/log/LogTreeItem.cpp	2009-08-30 03:10:07 UTC (rev 4091)
@@ -50,9 +50,9 @@
 QString
 LogTreeItem::toString() const
 {
-  return QString("%1 [%2] %3\n").arg(text(COL_TIME))
-                                .arg(text(COL_TYPE))
-                                .arg(text(COL_MESG).trimmed());
+  return QString("%1 [%2] %3").arg(text(COL_TIME))
+                              .arg(text(COL_TYPE))
+                              .arg(text(COL_MESG).trimmed());
 }
 
 /** Sets the item's log time. */

Modified: vidalia/trunk/src/vidalia/log/MessageLog.cpp
===================================================================
--- vidalia/trunk/src/vidalia/log/MessageLog.cpp	2009-08-30 01:48:36 UTC (rev 4090)
+++ vidalia/trunk/src/vidalia/log/MessageLog.cpp	2009-08-30 03:10:07 UTC (rev 4091)
@@ -65,8 +65,6 @@
   _torControl = Vidalia::torControl();
   connect(_torControl, SIGNAL(logMessage(tc::Severity, QString)),
           this, SLOT(log(tc::Severity, QString)));
-  connect(ui.tabWidget, SIGNAL(currentChanged(int)),
-          this, SLOT(currentTabChanged(int)));
 
   /* Bind events to actions */
   createActions();
@@ -81,9 +79,6 @@
   ui.listMessages->sortItems(LogTreeWidget::TimeColumn,
                              Qt::AscendingOrder);
   ui.listNotifications->sortItems(0, Qt::AscendingOrder);
-
-  /* Initialize the toolbar actions based on the default tab */
-  currentTabChanged(ui.tabWidget->currentIndex());
 }
 
 /** Default Destructor. Simply frees up any memory allocated for member
@@ -161,15 +156,6 @@
   setToolTips();
 }
 
-void
-MessageLog::currentTabChanged(int index)
-{
-  bool isAdvancedTabVisible = (index == 1);
-
-  ui.actionSave_Selected->setEnabled(isAdvancedTabVisible);
-  ui.actionSave_All->setEnabled(isAdvancedTabVisible);
-}
-
 /** Loads the saved Message Log settings */
 void
 MessageLog::loadSettings()
@@ -356,7 +342,7 @@
     /* Write out the message log to the file */
     QApplication::setOverrideCursor(Qt::WaitCursor);
     foreach (QString msg, messages) {
-      logFile << msg;
+      logFile << msg << "\n";
     }
     QApplication::restoreOverrideCursor();
   }
@@ -366,14 +352,20 @@
 void
 MessageLog::saveSelected()
 {
-  save(ui.listMessages->selectedMessages());
+  if (ui.tabWidget->currentIndex() == 0)
+    save(ui.listNotifications->selectedEvents());
+  else
+    save(ui.listMessages->selectedMessages());
 }
 
 /** Saves all shown messages to a file. */
 void
 MessageLog::saveAll()
 {
-  save(ui.listMessages->allMessages());
+  if (ui.tabWidget->currentIndex() == 0)
+    save(ui.listNotifications->allEvents());
+  else
+    save(ui.listMessages->allMessages());
 }
 
 void
@@ -394,7 +386,7 @@
   if (ui.tabWidget->currentIndex() == 0)
     contents = ui.listNotifications->selectedEvents().join("\n");
   else
-    contents = ui.listMessages->selectedMessages().join("");
+    contents = ui.listMessages->selectedMessages().join("\n");
 
   if (!contents.isEmpty()) {
     /* Copy the selected messages to the clipboard */
@@ -477,7 +469,7 @@
 
     /* If we're saving log messages to a file, go ahead and do that now */
     if (_enableLogging) {
-      _logFile << item->toString();
+      _logFile << item->toString() << "\n";
     }
   }
 }

Modified: vidalia/trunk/src/vidalia/log/MessageLog.h
===================================================================
--- vidalia/trunk/src/vidalia/log/MessageLog.h	2009-08-30 01:48:36 UTC (rev 4090)
+++ vidalia/trunk/src/vidalia/log/MessageLog.h	2009-08-30 03:10:07 UTC (rev 4091)
@@ -41,9 +41,6 @@
   virtual void retranslateUi();
 
 private slots:
-  /** Called when the currently visible tab changes and updates the available
-   * toolbar options accordingly. */
-  void currentTabChanged(int index);
   /** Adds the passed message to the message log as the specified type **/
   void log(tc::Severity severity, const QString &msg);
   /** Called when the user triggers the "Save All" action. */

Modified: vidalia/trunk/src/vidalia/log/StatusEventItem.cpp
===================================================================
--- vidalia/trunk/src/vidalia/log/StatusEventItem.cpp	2009-08-30 01:48:36 UTC (rev 4090)
+++ vidalia/trunk/src/vidalia/log/StatusEventItem.cpp	2009-08-30 03:10:07 UTC (rev 4091)
@@ -91,6 +91,14 @@
   QTreeWidgetItem::setToolTip(0, toolTip);
 }
 
+QString
+StatusEventItem::toString() const
+{
+  return QString("[%1] %2 - %3").arg(timestamp().toString())
+                                .arg(title())
+                                .arg(description());
+}
+
 bool
 StatusEventItem::operator<(const QTreeWidgetItem &other) const
 {

Modified: vidalia/trunk/src/vidalia/log/StatusEventItem.h
===================================================================
--- vidalia/trunk/src/vidalia/log/StatusEventItem.h	2009-08-30 01:48:36 UTC (rev 4090)
+++ vidalia/trunk/src/vidalia/log/StatusEventItem.h	2009-08-30 03:10:07 UTC (rev 4091)
@@ -102,6 +102,14 @@
    */
   void setToolTip(const QString &toolTip);
 
+  /** Returns a formatted QString containing this item's timestamp, title
+   * and description text.
+   * \sa timestamp()
+   * \sa title()
+   * \sa description()
+   */
+  QString toString() const;
+
   /** Overloaded comparison operator that allows sorting StatusEventItem
    * objects based on timestamp. Returns true if <i>this</i> StatusEventItem
    * occurred before <b>other</b>.

Modified: vidalia/trunk/src/vidalia/log/StatusEventWidget.cpp
===================================================================
--- vidalia/trunk/src/vidalia/log/StatusEventWidget.cpp	2009-08-30 01:48:36 UTC (rev 4090)
+++ vidalia/trunk/src/vidalia/log/StatusEventWidget.cpp	2009-08-30 03:10:07 UTC (rev 4091)
@@ -126,15 +126,28 @@
 
   for (int i = 0; i < items.size(); i++) {
     StatusEventItem *event = dynamic_cast<StatusEventItem *>(items.at(i));
-    if (event) {
-      // Format the output string with the timestamp, title and description
-      text = QString("[%1] %2 - %3").arg(event->timestamp().toString())
-                                    .arg(event->title())
-                                    .arg(event->description());
+    if (event)
+      out.append(event->toString());
+  }
+  return out;
+}
 
-      // Place the item in the list, sorted in ascending order by timestamp
-      out.append(text);
-    }
+QStringList
+StatusEventWidget::allEvents() const
+{
+  QStringList out;
+  QList<QTreeWidgetItem *> items;
+
+  for (int i = 0; i < topLevelItemCount(); i++)
+    items.append(topLevelItem(i));
+
+  // Ensure the items are sorted in ascending order according to timestamp
+  qStableSort(items.begin(), items.end(), compareStatusEventItems);
+
+  for (int i = 0; i < items.size(); i++) {
+    StatusEventItem *event = dynamic_cast<StatusEventItem *>(items.at(i));
+    if (event)
+      out.append(event->toString());
   }
   return out;
 }

Modified: vidalia/trunk/src/vidalia/log/StatusEventWidget.h
===================================================================
--- vidalia/trunk/src/vidalia/log/StatusEventWidget.h	2009-08-30 01:48:36 UTC (rev 4090)
+++ vidalia/trunk/src/vidalia/log/StatusEventWidget.h	2009-08-30 03:10:07 UTC (rev 4091)
@@ -50,11 +50,18 @@
    */
   int maximumItemCount() const;
 
-  /** Returns a QStringList of status events formatted as human-readable
-   * text. Each item in the QStringList represents a single status event.
+  /** Returns a QStringList of the currently selected status events formatted
+   * as human-readable text. Each item in the returned QStringList represents
+   * a single status event.
    */
   QStringList selectedEvents() const;
 
+  /** Returns a QStringList of all current status events formatted as
+   * human-readable text. Each item in the returned QStringList represents
+   * a single status event.
+   */
+  QStringList allEvents() const;
+
   /** Searches the list of current status event items for any items that
    * contain <b>text</b> in either the event title or description. Searching
    * is done case-insensitively. If <b>highlight</b> is true, any previously