MilkySettingsApplication::MilkySettingsApplication()
    :
    BApplication("application/x-vnd.Milky-MilkySettings")
{
    fSettingsWindow = new SettingsWindow();
    fSettingsWindow->Show();

    // Try to open settings file
    BFile* settingsFile = _OpenSettingsFile(B_READ_ONLY);
    if (settingsFile != NULL) {
        BMessage settings;
        status_t status = settings.Unflatten(settingsFile);
        delete settingsFile;

        if (status == B_OK) {
            // Apply settings
            fSettingsWindow->LockLooper();
            fSettingsWindow->SetSettings(&settings);
            fSettingsWindow->UnlockLooper();
        }
    }

    fMilkyTrackerMessenger = new BMessenger(kMilkyTrackerSignature);

    be_roster->StartWatching(BMessenger(this), B_REQUEST_LAUNCHED);
}
Пример #2
0
void
BrowsingHistory::_LoadSettings()
{
	if (fSettingsLoaded)
		return;

	fSettingsLoaded = true;

	BFile settingsFile;
	if (_OpenSettingsFile(settingsFile, B_READ_ONLY)) {
		BMessage settingsArchive;
		settingsArchive.Unflatten(&settingsFile);
		if (settingsArchive.FindInt32("max history item age",
				&fMaxHistoryItemAge) != B_OK) {
			fMaxHistoryItemAge = 7;
		}
		BDateTime oldestAllowedDateTime
			= BDateTime::CurrentDateTime(B_LOCAL_TIME);
		oldestAllowedDateTime.Date().AddDays(-fMaxHistoryItemAge);

		BMessage historyItemArchive;
		for (int32 i = 0; settingsArchive.FindMessage("history item", i,
				&historyItemArchive) == B_OK; i++) {
			BrowsingHistoryItem item(&historyItemArchive);
			if (oldestAllowedDateTime < item.DateTime())
				_AddItem(item, true);
			historyItemArchive.MakeEmpty();
		}
	}
}
void
MilkySettingsApplication::MessageReceived(BMessage* message)
{
    switch (message->what) {
    case B_SOME_APP_LAUNCHED: {
        // Watch out for launches of MilkyTracker
        BString signature;
        message->FindString("be:signature", &signature);

        if (signature == kMilkyTrackerSignature) {
            BMessenger* newMessenger =
                new BMessenger(kMilkyTrackerSignature);

            // Swap pointers to make sure that fMilkyTrackerMessenger
            // points to an existing messenger instance at all times
            BMessenger* oldMessenger = fMilkyTrackerMessenger;
            fMilkyTrackerMessenger = newMessenger;
            delete oldMessenger;
        }
    }
    break;

    case kMsg_SwitchCommandControlToggled:
    case kMsg_ChangeFullscreenResolutionToggled:
    case kMsg_MidiInputSelected:
    case kMsg_MidiRecordVelocityToggled:
    case kMsg_MidiVelocityAmplificationChanged: {
        // Forward to MilkyTracker if it's running
        if (fMilkyTrackerMessenger->IsValid())
            fMilkyTrackerMessenger->SendMessage(message);

        // Save to settings file
        BFile* settingsFile = _OpenSettingsFile(B_WRITE_ONLY |
                                                B_CREATE_FILE | B_ERASE_FILE);

        if (settingsFile != NULL) {
            BMessage* settings = fSettingsWindow->GetSettings();
            settings->Flatten(settingsFile);
            delete settings;
            delete settingsFile;
        }
    }
    break;

    default:
        BApplication::MessageReceived(message);
        break;
    }
}
void
DownloadWindow::_LoadSettings()
{
	BFile file;
	if (!_OpenSettingsFile(file, B_READ_ONLY))
		return;
	BMessage message;
	if (message.Unflatten(&file) != B_OK)
		return;
	BMessage downloadArchive;
	for (int32 i = 0;
			message.FindMessage("download", i, &downloadArchive) == B_OK;
			i++) {
		DownloadProgressView* view = new DownloadProgressView(
			&downloadArchive);
		if (!view->Init(&downloadArchive))
			continue;
		fDownloadViewsLayout->AddView(0, view);
	}
}
void
DownloadWindow::_SaveSettings()
{
	BFile file;
	if (!_OpenSettingsFile(file, B_ERASE_FILE | B_CREATE_FILE | B_WRITE_ONLY))
		return;
	BMessage message;
	for (int32 i = fDownloadViewsLayout->CountItems() - 1;
			BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i--) {
		DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(
			item->View());
		if (!view)
			continue;

	BMessage downloadArchive;
		if (view->SaveSettings(&downloadArchive) == B_OK)
			message.AddMessage("download", &downloadArchive);
	}
	message.Flatten(&file);
}
Пример #6
0
void
BrowsingHistory::_SaveSettings()
{
	BFile settingsFile;
	if (_OpenSettingsFile(settingsFile,
			B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY)) {
		BMessage settingsArchive;
		settingsArchive.AddInt32("max history item age", fMaxHistoryItemAge);
		BMessage historyItemArchive;
		int32 count = CountItems();
		for (int32 i = 0; i < count; i++) {
			BrowsingHistoryItem item = HistoryItemAt(i);
			if (item.Archive(&historyItemArchive) != B_OK)
				break;
			if (settingsArchive.AddMessage("history item",
					&historyItemArchive) != B_OK) {
				break;
			}
			historyItemArchive.MakeEmpty();
		}
		settingsArchive.Flatten(&settingsFile);
	}
}