2008-09-07 18:18:01 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT/X11 license.
|
|
|
|
*
|
2009-08-31 05:28:59 +04:00
|
|
|
* Copyright (c) 1999 Mike Steed. You are free to use and distribute this
|
|
|
|
* software as long as it is accompanied by it's documentation and this
|
|
|
|
* copyright notice. The software comes with no warranty, etc.
|
2008-09-07 18:18:01 +04:00
|
|
|
*/
|
2009-08-31 05:28:59 +04:00
|
|
|
|
|
|
|
|
2008-09-07 18:18:01 +04:00
|
|
|
#include "App.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <File.h>
|
|
|
|
#include <FindDirectory.h>
|
|
|
|
#include <Node.h>
|
|
|
|
#include <Path.h>
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
#include "MainWindow.h"
|
|
|
|
|
|
|
|
|
|
|
|
App::App()
|
2010-07-02 07:07:18 +04:00
|
|
|
:
|
|
|
|
BApplication(kAppSignature),
|
|
|
|
fResources(read_resources(kAppSignature)),
|
|
|
|
fMainWindow(NULL), fSavedRefsReceived(NULL)
|
2008-09-07 18:18:01 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
App::~App()
|
|
|
|
{
|
|
|
|
delete fResources;
|
2008-09-08 15:02:39 +04:00
|
|
|
delete fSavedRefsReceived;
|
2008-09-07 18:18:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
App::ArgvReceived(int32 argc, char** argv)
|
|
|
|
{
|
|
|
|
BMessage refsReceived(B_REFS_RECEIVED);
|
|
|
|
for (int32 i = 1; i < argc; i++) {
|
|
|
|
BEntry entry(argv[i], true);
|
|
|
|
entry_ref ref;
|
|
|
|
if (entry.GetRef(&ref) == B_OK)
|
|
|
|
refsReceived.AddRef("refs", &ref);
|
|
|
|
}
|
|
|
|
if (refsReceived.HasRef("refs"))
|
|
|
|
PostMessage(&refsReceived);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
App::RefsReceived(BMessage* message)
|
|
|
|
{
|
2009-08-31 05:28:59 +04:00
|
|
|
if (!message->HasRef("refs") && message->HasRef("dir_ref")) {
|
|
|
|
entry_ref dirRef;
|
|
|
|
if (message->FindRef("dir_ref", &dirRef) == B_OK)
|
|
|
|
message->AddRef("refs", &dirRef);
|
|
|
|
}
|
|
|
|
|
2008-09-08 15:02:39 +04:00
|
|
|
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);
|
2008-09-07 18:18:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
App::ReadyToRun()
|
|
|
|
{
|
|
|
|
BRect frame;
|
|
|
|
|
|
|
|
BPath path;
|
|
|
|
BFile settingsFile;
|
|
|
|
BMessage settings;
|
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK
|
|
|
|
|| path.Append("DiskUsage") != B_OK
|
|
|
|
|| settingsFile.SetTo(path.Path(), B_READ_ONLY) != B_OK
|
|
|
|
|| settings.Unflatten(&settingsFile) != B_OK
|
|
|
|
|| settings.FindRect("window frame", &frame) != B_OK) {
|
|
|
|
// use default window frame
|
|
|
|
frame.Set(0, 0, kDefaultPieSize, kDefaultPieSize);
|
|
|
|
frame.OffsetTo(50, 50);
|
|
|
|
}
|
|
|
|
|
|
|
|
fMainWindow = new MainWindow(frame);
|
2010-10-13 03:50:09 +04:00
|
|
|
fMainWindow->Show();
|
2008-09-08 15:02:39 +04:00
|
|
|
|
|
|
|
if (fSavedRefsReceived) {
|
|
|
|
// RefsReceived() was called earlier than ReadyToRun()
|
|
|
|
fMainWindow->PostMessage(fSavedRefsReceived);
|
|
|
|
delete fSavedRefsReceived;
|
|
|
|
fSavedRefsReceived = NULL;
|
|
|
|
}
|
2008-09-07 18:18:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
App::QuitRequested()
|
|
|
|
{
|
|
|
|
// Save the settings.
|
|
|
|
BPath path;
|
|
|
|
BFile settingsFile;
|
|
|
|
BMessage settings;
|
|
|
|
if (settings.AddRect("window frame", fMainWindow->Frame()) != B_OK
|
|
|
|
|| find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK
|
|
|
|
|| path.Append("DiskUsage") != B_OK
|
2008-09-08 15:02:39 +04:00
|
|
|
|| settingsFile.SetTo(path.Path(),
|
|
|
|
B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE) != B_OK
|
2008-09-07 18:18:01 +04:00
|
|
|
|| settings.Flatten(&settingsFile) != B_OK) {
|
|
|
|
fprintf(stderr, "Failed to write application settings.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return BApplication::QuitRequested();
|
|
|
|
}
|