From fb03e2c5739385c47ec9fbdc7a2ffaab1d9ebc69 Mon Sep 17 00:00:00 2001 From: stippi Date: Fri, 21 May 2010 16:59:58 +0000 Subject: [PATCH] * When downloads are still in progress, warn the user when the app quits and allow to continue downloading. * If the Downloads window is the only window, minimize on close instead of hiding without any way to get the window back. * Added menu item "New browser window" to Downloads window. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@512 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/BrowserApp.cpp | 23 +++++++++++ src/apps/webpositive/DownloadWindow.cpp | 55 +++++++++++++++++++++++-- src/apps/webpositive/DownloadWindow.h | 4 ++ 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/src/apps/webpositive/BrowserApp.cpp b/src/apps/webpositive/BrowserApp.cpp index 4efe1858e2..79b2d3418e 100644 --- a/src/apps/webpositive/BrowserApp.cpp +++ b/src/apps/webpositive/BrowserApp.cpp @@ -212,6 +212,7 @@ BrowserApp::MessageReceived(BMessage* message) } case WINDOW_OPENED: fWindowCount++; + fDownloadWindow->SetMinimizeOnClose(false); break; case WINDOW_CLOSED: fWindowCount--; @@ -250,6 +251,28 @@ BrowserApp::RefsReceived(BMessage* message) bool BrowserApp::QuitRequested() { + if (fDownloadWindow->DownloadsInProgress()) { + BAlert* alert = new BAlert("Downloads in progress", + "There are still downloads in progress, do you really want to " + "quit WebPositive now?", "Quit", "Continue downloads"); + int32 choice = alert->Go(); + if (choice == 1) { + if (fWindowCount == 0) { + if (fDownloadWindow->Lock()) { + fDownloadWindow->SetWorkspaces(1 << current_workspace()); + if (fDownloadWindow->IsHidden()) + fDownloadWindow->Show(); + else + fDownloadWindow->Activate(); + fDownloadWindow->SetMinimizeOnClose(true); + fDownloadWindow->Unlock(); + return false; + } + } else + return false; + } + } + for (int i = 0; BWindow* window = WindowAt(i); i++) { BrowserWindow* webWindow = dynamic_cast(window); if (!webWindow) diff --git a/src/apps/webpositive/DownloadWindow.cpp b/src/apps/webpositive/DownloadWindow.cpp index fc6fd0c3ce..bd2c7e84c4 100644 --- a/src/apps/webpositive/DownloadWindow.cpp +++ b/src/apps/webpositive/DownloadWindow.cpp @@ -46,6 +46,7 @@ #include #include "BrowserApp.h" +#include "BrowserWindow.h" #include "DownloadProgressView.h" #include "SettingsKeys.h" #include "SettingsMessage.h" @@ -135,7 +136,8 @@ DownloadWindow::DownloadWindow(BRect frame, bool visible, SettingsMessage* settings) : BWindow(frame, "Downloads", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, - B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) + B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE), + fMinimizeOnClose(false) { SetPulseRate(1000000); @@ -156,6 +158,13 @@ DownloadWindow::DownloadWindow(BRect frame, bool visible, BMenu* menu = new BMenu("Downloads"); menu->AddItem(new BMenuItem("Open downloads folder", new BMessage(OPEN_DOWNLOADS_FOLDER))); + BMessage* newWindowMessage = new BMessage(NEW_WINDOW); + newWindowMessage->AddString("url", ""); + BMenuItem* newWindowItem = new BMenuItem("New browser window", + newWindowMessage, 'N'); + menu->AddItem(newWindowItem); + newWindowItem->SetTarget(be_app); + menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Hide", new BMessage(B_QUIT_REQUESTED), 'J')); menuBar->AddItem(menu); @@ -305,12 +314,52 @@ DownloadWindow::MessageReceived(BMessage* message) bool DownloadWindow::QuitRequested() { - if (!IsHidden()) - Hide(); + if (fMinimizeOnClose) { + if (!IsMinimized()) + Minimize(true); + } else { + if (!IsHidden()) + Hide(); + } return false; } +bool +DownloadWindow::DownloadsInProgress() +{ + bool downloadsInProgress = false; + if (!Lock()) + return downloadsInProgress; + + for (int32 i = fDownloadViewsLayout->CountItems() - 1; + BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i--) { + DownloadProgressView* view = dynamic_cast( + item->View()); + if (!view) + continue; + if (view->Download() != NULL) { + downloadsInProgress = true; + break; + } + } + + Unlock(); + + return downloadsInProgress; +} + + +void +DownloadWindow::SetMinimizeOnClose(bool minimize) +{ + if (Lock()) { + fMinimizeOnClose = minimize; + Unlock(); + } +} + + // #pragma mark - private diff --git a/src/apps/webpositive/DownloadWindow.h b/src/apps/webpositive/DownloadWindow.h index e4e62bfecc..d76661ba4e 100644 --- a/src/apps/webpositive/DownloadWindow.h +++ b/src/apps/webpositive/DownloadWindow.h @@ -50,6 +50,9 @@ public: virtual void MessageReceived(BMessage* message); virtual bool QuitRequested(); + bool DownloadsInProgress(); + void SetMinimizeOnClose(bool minimize); + private: void _DownloadStarted(BWebDownload* download); void _DownloadFinished(BWebDownload* download); @@ -66,6 +69,7 @@ private: BButton* fRemoveFinishedButton; BButton* fRemoveMissingButton; BString fDownloadPath; + bool fMinimizeOnClose; }; #endif // DOWNLOAD_WINDOW_H