[haiku-webkit-commits] r344 - webkit/trunk/WebKit/haiku/WebPositive

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Tue, 23 Mar 2010 14:00:14 +0000

Author: stippi
Date: Tue Mar 23 14:00:13 2010
New Revision: 344
URL: http://mmlr.dyndns.org/changeset/344

Log:
Added node monitoring to downloads window.

Modified:
   webkit/trunk/WebKit/haiku/WebPositive/DownloadWindow.cpp

Modified: webkit/trunk/WebKit/haiku/WebPositive/DownloadWindow.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/DownloadWindow.cpp    Tue Mar 23 
13:17:03 2010        (r343)
+++ webkit/trunk/WebKit/haiku/WebPositive/DownloadWindow.cpp    Tue Mar 23 
14:00:13 2010        (r344)
@@ -40,6 +40,7 @@
 #include <MenuBar.h>
 #include <MenuItem.h>
 #include <NodeInfo.h>
+#include <NodeMonitor.h>
 #include <Path.h>
 #include <Roster.h>
 #include <ScrollView.h>
@@ -264,6 +265,15 @@
                        fDownload->SetProgressListener(BMessenger(this));
                fTopButton->SetTarget(this);
                fBottomButton->SetTarget(this);
+               
+               BEntry entry(fPath.Path());
+               if (entry.Exists())
+                       _StartNodeMonitor(entry);
+       }
+
+       virtual void DetachedFromWindow()
+       {
+               _StopNodeMonitor();
        }
 
        virtual void AllAttached()
@@ -285,7 +295,8 @@
        virtual void MessageReceived(BMessage* message)
        {
                switch (message->what) {
-                       case B_DOWNLOAD_STARTED: {
+                       case B_DOWNLOAD_STARTED:
+                       {
                                BString path;
                                if (message->FindString("path", &path) != B_OK)
                                        break;
@@ -293,15 +304,18 @@
                                BEntry entry(fPath.Path());
                                fIconView->SetTo(entry);
                                fStatusBar->Reset(fPath.Leaf());
+                               _StartNodeMonitor(entry);
                                break;
                        };
-                       case B_DOWNLOAD_PROGRESS: {
+                       case B_DOWNLOAD_PROGRESS:
+                       {
                                float progress;
                                if (message->FindFloat("progress", &progress) 
== B_OK)
                                        fStatusBar->SetTo(progress);
                                break;
                        }
-                       case OPEN_DOWNLOAD: {
+                       case OPEN_DOWNLOAD:
+                       {
                                // TODO: In case of executable files, ask the 
user first!
                                entry_ref ref;
                                status_t status = 
get_ref_for_path(fPath.Path(), &ref);
@@ -323,7 +337,8 @@
                                DownloadCanceled();
                                break;
        
-                       case REMOVE_DOWNLOAD: {
+                       case REMOVE_DOWNLOAD:
+                       {
                                Window()->PostMessage(SAVE_SETTINGS);
                                RemoveSelf();
                                delete this;
@@ -336,6 +351,54 @@
                                // at the window...
                                Window()->PostMessage(message);
                                break;
+                       case B_NODE_MONITOR:
+                       {
+                               int32 opCode;
+                               if (message->FindInt32("opcode", &opCode) != 
B_OK)
+                                       break;
+                               switch (opCode) {
+                                       case B_ENTRY_REMOVED:
+                                               fIconView->SetIconDimmed(true);
+                                               DownloadCanceled();
+                                               break;
+                                       case B_ENTRY_MOVED:
+                                       {
+                                               int64 fromDirectory;
+                                               int64 toDirectory;
+                                               if (message->FindInt64("from 
directory",
+                                                               &fromDirectory) 
!= B_OK
+                                                       || 
message->FindInt64("to directory",
+                                                               &toDirectory) 
!= B_OK) {
+                                                       break;
+                                               }
+                                               if (fromDirectory == 
toDirectory) {
+                                                       // Entry was renamed
+                                                       const char* name;
+                                                       if 
(message->FindString("name", &name) != B_OK
+                                                               || strlen(name) 
== 0) {
+                                                               break;
+                                                       }
+                                                       fPath.GetParent(&fPath);
+                                                       fPath.Append(name);
+                                                       
fStatusBar->SetText(name);
+                                                       
Window()->PostMessage(SAVE_SETTINGS);
+                                               } else {
+                                                       // Entry was moved 
elsewhere
+                                                       
fIconView->SetIconDimmed(true);
+                                                       DownloadCanceled();
+                                               }
+                                               break;
+                                       }
+                                       case B_ATTR_CHANGED:
+                                       {
+                                               BEntry entry(fPath.Path());
+                                               fIconView->SetIconDimmed(false);
+                                               fIconView->SetTo(entry);
+                                               break;
+                                       }
+                               }
+                               break;
+                       }
                        default:
                                BGridView::MessageReceived(message);
                }
@@ -372,6 +435,19 @@
        }
 
 private:
+       void _StartNodeMonitor(const BEntry& entry)
+       {
+               node_ref nref;
+               if (entry.GetNodeRef(&nref) == B_OK)
+                       watch_node(&nref, B_WATCH_ALL, this);
+       }
+
+       void _StopNodeMonitor()
+       {
+               stop_watching(this);
+       }
+
+private:
        IconView*               fIconView;
        BStatusBar*             fStatusBar;
        SmallButton*    fTopButton;

Other related posts: