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

[vidalia-svn] r4088: Make the "Select All" and "Copy" actions work for the "Basic (vidalia/trunk/src/vidalia/log)



Author: edmanm
Date: 2009-08-29 18:17:52 -0400 (Sat, 29 Aug 2009)
New Revision: 4088

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

Make the "Select All" and "Copy" actions work for the "Basic" message log
tab as well.


Modified: vidalia/trunk/src/vidalia/log/MessageLog.cpp
===================================================================
--- vidalia/trunk/src/vidalia/log/MessageLog.cpp	2009-08-29 22:16:17 UTC (rev 4087)
+++ vidalia/trunk/src/vidalia/log/MessageLog.cpp	2009-08-29 22:17:52 UTC (rev 4088)
@@ -102,6 +102,9 @@
   connect(ui.actionSave_All, SIGNAL(triggered()),
           this, SLOT(saveAll()));
 
+  connect(ui.actionSelect_All, SIGNAL(triggered()),
+          this, SLOT(selectAll()));
+
   connect(ui.actionCopy, SIGNAL(triggered()),
           this, SLOT(copy()));
 
@@ -164,8 +167,6 @@
 
   ui.actionSave_Selected->setEnabled(isAdvancedTabVisible);
   ui.actionSave_All->setEnabled(isAdvancedTabVisible);
-  ui.actionSelect_All->setEnabled(isAdvancedTabVisible);
-  ui.actionCopy->setEnabled(isAdvancedTabVisible);
   ui.actionFind->setEnabled(isAdvancedTabVisible);
 }
 
@@ -375,11 +376,26 @@
   save(ui.listMessages->allMessages());
 }
 
+void
+MessageLog::selectAll()
+{
+  if (ui.tabWidget->currentIndex() == 0)
+    ui.listNotifications->selectAll();
+  else
+    ui.listMessages->selectAll();
+}
+
 /** Copies contents of currently selected messages to the 'clipboard'. */
 void
 MessageLog::copy()
 {
-  QString contents = ui.listMessages->selectedMessages().join("");
+  QString contents;
+
+  if (ui.tabWidget->currentIndex() == 0)
+    contents = ui.listNotifications->selectedEvents().join("\n");
+  else
+    contents = ui.listMessages->selectedMessages().join("");
+
   if (!contents.isEmpty()) {
     /* Copy the selected messages to the clipboard */
     QApplication::clipboard()->setText(contents);

Modified: vidalia/trunk/src/vidalia/log/MessageLog.h
===================================================================
--- vidalia/trunk/src/vidalia/log/MessageLog.h	2009-08-29 22:16:17 UTC (rev 4087)
+++ vidalia/trunk/src/vidalia/log/MessageLog.h	2009-08-29 22:17:52 UTC (rev 4088)
@@ -50,6 +50,8 @@
   void saveAll();
   /** Called when the user triggers "Save Selected" action. */
   void saveSelected();
+  /** Called when the user triggers the "Select All" action. */
+  void selectAll();
   /** Called when the user triggers the "Copy" action. */
   void copy();
   /** Called when the user triggers the "Clear" action. */

Modified: vidalia/trunk/src/vidalia/log/StatusEventWidget.cpp
===================================================================
--- vidalia/trunk/src/vidalia/log/StatusEventWidget.cpp	2009-08-29 22:16:17 UTC (rev 4087)
+++ vidalia/trunk/src/vidalia/log/StatusEventWidget.cpp	2009-08-29 22:17:52 UTC (rev 4088)
@@ -29,6 +29,12 @@
 #include <QObject>
 #include <QHeaderView>
 
+bool compareStatusEventItems(const QTreeWidgetItem *a,
+                             const QTreeWidgetItem *b)
+{
+  return (*a < *b);
+}
+
 StatusEventWidget::StatusEventWidget(QWidget *parent)
   : QTreeWidget(parent)
 {
@@ -106,6 +112,33 @@
   return _maximumItemCount;
 }
 
+QStringList
+StatusEventWidget::selectedEvents() const
+{
+  QString text;
+  QStringList out;
+  QList<QTreeWidgetItem *> items = selectedItems();
+
+  // We have to sort the items since selectedItems() returns the order in
+  // which the items were selected, not the order in which they appear in the
+  // current list.
+  qStableSort(items.begin(), items.end(), compareStatusEventItems);
+
+  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());
+
+      // Place the item in the list, sorted in ascending order by timestamp
+      out.append(text);
+    }
+  }
+  return out;
+}
+
 void
 StatusEventWidget::addNotification(const QPixmap &icon,
                                    const QString &title,

Modified: vidalia/trunk/src/vidalia/log/StatusEventWidget.h
===================================================================
--- vidalia/trunk/src/vidalia/log/StatusEventWidget.h	2009-08-29 22:16:17 UTC (rev 4087)
+++ vidalia/trunk/src/vidalia/log/StatusEventWidget.h	2009-08-29 22:17:52 UTC (rev 4088)
@@ -46,6 +46,11 @@
    */
   int maximumItemCount() const;
 
+  /** Returns a QStringList of status events formatted as human-readable
+   * text. Each item in the QStringList represents a single status event.
+   */
+  QStringList selectedEvents() const;
+
 protected:
   /** Called when the user has changed the UI display language in Vidalia
    * indicating all the displayed text widgets need to be updated to