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.
17 #include <FindDirectory.h>
21 #include "DiskUsage.h"
22 #include "MainWindow.h"
27 BApplication(kAppSignature
),
29 fSavedRefsReceived(NULL
)
36 delete fSavedRefsReceived
;
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);
47 if (entry
.GetRef(&ref
) == B_OK
)
48 refsReceived
.AddRef("refs", &ref
);
50 if (refsReceived
.HasRef("refs"))
51 PostMessage(&refsReceived
);
56 App::RefsReceived(BMessage
* message
)
58 if (!message
->HasRef("refs") && message
->HasRef("dir_ref")) {
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
);
70 fMainWindow
->PostMessage(message
);
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
);
95 if (fSavedRefsReceived
) {
96 // RefsReceived() was called earlier than ReadyToRun()
97 fMainWindow
->PostMessage(fSavedRefsReceived
);
98 delete fSavedRefsReceived
;
99 fSavedRefsReceived
= NULL
;
107 // Save the 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();