diff --git a/src/apps/diskusage/App.cpp b/src/apps/diskusage/App.cpp index 5e5b03b046..7133038344 100644 --- a/src/apps/diskusage/App.cpp +++ b/src/apps/diskusage/App.cpp @@ -22,7 +22,8 @@ App::App() : BApplication(kAppSignature), fResources(read_resources(kAppSignature)), - fMainWindow(NULL) + fMainWindow(NULL), + fSavedRefsReceived(NULL) { } @@ -30,6 +31,7 @@ App::App() App::~App() { delete fResources; + delete fSavedRefsReceived; } @@ -51,7 +53,13 @@ App::ArgvReceived(int32 argc, char** argv) void App::RefsReceived(BMessage* message) { - fMainWindow->PostMessage(message); + if (fMainWindow == NULL) { + // ReadyToRun() has not been called yet, this happens when someone + // launches us with a B_REFS_RECEIVED message. + delete fSavedRefsReceived; + fSavedRefsReceived = new BMessage(*message); + } else + fMainWindow->PostMessage(message); } @@ -74,6 +82,13 @@ App::ReadyToRun() } fMainWindow = new MainWindow(frame); + + if (fSavedRefsReceived) { + // RefsReceived() was called earlier than ReadyToRun() + fMainWindow->PostMessage(fSavedRefsReceived); + delete fSavedRefsReceived; + fSavedRefsReceived = NULL; + } } @@ -87,23 +102,11 @@ App::QuitRequested() if (settings.AddRect("window frame", fMainWindow->Frame()) != B_OK || find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK || path.Append("DiskUsage") != B_OK - || settingsFile.SetTo(path.Path(), B_WRITE_ONLY) != B_OK + || settingsFile.SetTo(path.Path(), + B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE) != B_OK || settings.Flatten(&settingsFile) != B_OK) { fprintf(stderr, "Failed to write application settings.\n"); } return BApplication::QuitRequested(); } - - -// #pragma mark - - - -int -main() -{ - App app; - app.Run(); - return 0; -} - diff --git a/src/apps/diskusage/App.h b/src/apps/diskusage/App.h index fe39ac2179..8965e0b2c4 100644 --- a/src/apps/diskusage/App.h +++ b/src/apps/diskusage/App.h @@ -28,6 +28,7 @@ public: private: BResources* fResources; MainWindow* fMainWindow; + BMessage* fSavedRefsReceived; }; #endif // APP_H diff --git a/src/apps/diskusage/DiskUsage.cpp b/src/apps/diskusage/DiskUsage.cpp new file mode 100644 index 0000000000..4cb23884b2 --- /dev/null +++ b/src/apps/diskusage/DiskUsage.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 1998-2007 Matthijs Hollemans + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +// NOTE: This code is the same in TextSearch. Maybe it could be made +// into some kind of common base class? + +#include "App.h" + +#include +#include +#include +#include + +#include "Common.h" + + +int +main() +{ + App app; + app.Run(); + return 0; +} + + +void +process_refs(entry_ref dirRef, BMessage* message, void* /*reserved*/) +{ + // Tracker calls this function when the user invokes the add-on. + // "dir_ref" contains the entry_ref of the current directory. + // "message" is a standard B_REFS_RECEIVED BMessage whose "refs" + // array contains the entry_refs of the selected files. The last + // argument, "reserved", is currently unused. + + // This version of TrackerGrep is a Tracker add-on, but primarily + // it is a stand-alone application. The add-on launches the app + // on the set of files you had selected in Tracker. That way you + // get the benefits of the Tracker add-on with the benefits of the + // stand-alone application. + + if (!message->HasRef("refs")) + message->AddRef("refs", &dirRef); + + // get the path of the Tracker add-on + image_info image; + int32 cookie = 0; + status_t status = get_next_image_info(0, &cookie, &image); + + while (status == B_OK) { + if (((char*)process_refs >= (char*)image.text + && (char*)process_refs <= (char*)image.text + image.text_size) + || ((char*)process_refs >= (char*)image.data + && (char*)process_refs <= (char*)image.data + image.data_size)) + break; + + status = get_next_image_info(0, &cookie, &image); + } + + entry_ref addonRef; + + if (get_ref_for_path(image.name, &addonRef) == B_OK) { + // It's better to launch the application by its entry + // than by its application signature. There may be + // multiple instances and we would not be certain + // that the desired one is launched - the one which was + // loaded into Tracker and whose process_refs() was called. + be_roster->Launch(&addonRef, message); + } else + be_roster->Launch(kAppSignature, message); +} diff --git a/src/apps/diskusage/Jamfile b/src/apps/diskusage/Jamfile index 11132a97df..985c825db5 100644 --- a/src/apps/diskusage/Jamfile +++ b/src/apps/diskusage/Jamfile @@ -4,6 +4,7 @@ Application DiskUsage : App.cpp Common.cpp ControlsView.cpp + DiskUsage.cpp InfoWindow.cpp MainWindow.cpp PieView.cpp