Home | History | Annotate | Download | only in download
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #import <Cocoa/Cocoa.h>
      6 
      7 #include "base/memory/scoped_ptr.h"
      8 #include "base/time.h"
      9 
     10 class BaseDownloadItemModel;
     11 @class ChromeUILocalizer;
     12 @class DownloadItemCell;
     13 class DownloadItem;
     14 @class DownloadItemButton;
     15 class DownloadItemMac;
     16 class DownloadShelfContextMenuMac;
     17 @class DownloadShelfController;
     18 @class GTMWidthBasedTweaker;
     19 
     20 // A controller class that manages one download item.
     21 
     22 @interface DownloadItemController : NSViewController {
     23  @private
     24   IBOutlet DownloadItemButton* progressView_;
     25   IBOutlet DownloadItemCell* cell_;
     26 
     27   IBOutlet NSMenu* activeDownloadMenu_;
     28   IBOutlet NSMenu* completeDownloadMenu_;
     29 
     30   // This is shown instead of progressView_ for dangerous downloads.
     31   IBOutlet NSView* dangerousDownloadView_;
     32   IBOutlet NSTextField* dangerousDownloadLabel_;
     33   IBOutlet NSButton* dangerousDownloadConfirmButton_;
     34 
     35   // Needed to find out how much the tweaker changed sizes to update the
     36   // other views.
     37   IBOutlet GTMWidthBasedTweaker* buttonTweaker_;
     38 
     39   // Because the confirm text and button for dangerous downloads are determined
     40   // at runtime, an outlet to the localizer is needed to construct the layout
     41   // tweaker in awakeFromNib in order to adjust the UI after all strings are
     42   // determined.
     43   IBOutlet ChromeUILocalizer* localizer_;
     44 
     45   IBOutlet NSImageView* image_;
     46 
     47   scoped_ptr<DownloadItemMac> bridge_;
     48   scoped_ptr<DownloadShelfContextMenuMac> menuBridge_;
     49 
     50   // Weak pointer to the shelf that owns us.
     51   DownloadShelfController* shelf_;
     52 
     53   // The time at which this view was created.
     54   base::Time creationTime_;
     55 
     56   // The state of this item.
     57   enum DownoadItemState {
     58     kNormal,
     59     kDangerous
     60   } state_;
     61 };
     62 
     63 // Takes ownership of |downloadModel|.
     64 - (id)initWithModel:(BaseDownloadItemModel*)downloadModel
     65               shelf:(DownloadShelfController*)shelf;
     66 
     67 // Updates the UI and menu state from |downloadModel|.
     68 - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel;
     69 
     70 // Remove ourself from the download UI.
     71 - (void)remove;
     72 
     73 // Update item's visibility depending on if the item is still completely
     74 // contained in its parent.
     75 - (void)updateVisibility:(id)sender;
     76 
     77 // Called after a download is opened.
     78 - (void)downloadWasOpened;
     79 
     80 // Asynchronous icon loading callback.
     81 - (void)setIcon:(NSImage*)icon;
     82 
     83 // Download item button clicked
     84 - (IBAction)handleButtonClick:(id)sender;
     85 
     86 // Returns the size this item wants to have.
     87 - (NSSize)preferredSize;
     88 
     89 // Returns the DownloadItem model object belonging to this item.
     90 - (DownloadItem*)download;
     91 
     92 // Updates the tooltip with the download's path.
     93 - (void)updateToolTip;
     94 
     95 // Handling of dangerous downloads
     96 - (void)clearDangerousMode;
     97 - (BOOL)isDangerousMode;
     98 - (IBAction)saveDownload:(id)sender;
     99 - (IBAction)discardDownload:(id)sender;
    100 
    101 // Context menu handlers.
    102 - (IBAction)handleOpen:(id)sender;
    103 - (IBAction)handleAlwaysOpen:(id)sender;
    104 - (IBAction)handleReveal:(id)sender;
    105 - (IBAction)handleCancel:(id)sender;
    106 - (IBAction)handleTogglePause:(id)sender;
    107 
    108 @end
    109