repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / diskusage / App.cpp
blob7880fda87dd058aa466295b7c9baf7c06532a7b0
1 /*
2 * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
3 * Distributed under the terms of the MIT/X11 license.
5 * Copyright (c) 1999 Mike Steed. You are free to use and distribute this
6 * software as long as it is accompanied by it's documentation and this
7 * copyright notice. The software comes with no warranty, etc.
8 */
11 #include "App.h"
13 #include <stdio.h>
15 #include <Entry.h>
16 #include <File.h>
17 #include <FindDirectory.h>
18 #include <Node.h>
19 #include <Path.h>
21 #include "DiskUsage.h"
22 #include "MainWindow.h"
25 App::App()
27 BApplication(kAppSignature),
28 fMainWindow(NULL),
29 fSavedRefsReceived(NULL)
34 App::~App()
36 delete fSavedRefsReceived;
40 void
41 App::ArgvReceived(int32 argc, char** argv)
43 BMessage refsReceived(B_REFS_RECEIVED);
44 for (int32 i = 1; i < argc; i++) {
45 BEntry entry(argv[i], true);
46 entry_ref ref;
47 if (entry.GetRef(&ref) == B_OK)
48 refsReceived.AddRef("refs", &ref);
50 if (refsReceived.HasRef("refs"))
51 PostMessage(&refsReceived);
55 void
56 App::RefsReceived(BMessage* message)
58 if (!message->HasRef("refs") && message->HasRef("dir_ref")) {
59 entry_ref dirRef;
60 if (message->FindRef("dir_ref", &dirRef) == B_OK)
61 message->AddRef("refs", &dirRef);
64 if (fMainWindow == NULL) {
65 // ReadyToRun() has not been called yet, this happens when someone
66 // launches us with a B_REFS_RECEIVED message.
67 delete fSavedRefsReceived;
68 fSavedRefsReceived = new BMessage(*message);
69 } else
70 fMainWindow->PostMessage(message);
74 void
75 App::ReadyToRun()
77 BRect frame;
79 BPath path;
80 BFile settingsFile;
81 BMessage settings;
82 if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK
83 || path.Append("DiskUsage") != B_OK
84 || settingsFile.SetTo(path.Path(), B_READ_ONLY) != B_OK
85 || settings.Unflatten(&settingsFile) != B_OK
86 || settings.FindRect("window frame", &frame) != B_OK) {
87 // use default window frame
88 frame.Set(0, 0, kDefaultPieSize, kDefaultPieSize);
89 frame.OffsetTo(50, 50);
92 fMainWindow = new MainWindow(frame);
93 fMainWindow->Show();
95 if (fSavedRefsReceived) {
96 // RefsReceived() was called earlier than ReadyToRun()
97 fMainWindow->PostMessage(fSavedRefsReceived);
98 delete fSavedRefsReceived;
99 fSavedRefsReceived = NULL;
104 bool
105 App::QuitRequested()
107 // Save the settings.
108 BPath path;
109 BFile settingsFile;
110 BMessage settings;
111 if (settings.AddRect("window frame", fMainWindow->Frame()) != B_OK
112 || find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK
113 || path.Append("DiskUsage") != B_OK
114 || settingsFile.SetTo(path.Path(),
115 B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE) != B_OK
116 || settings.Flatten(&settingsFile) != B_OK) {
117 fprintf(stderr, "Failed to write application settings.\n");
120 return BApplication::QuitRequested();