Пример #1
0
void
NotificationWindow::_LoadGeneralSettings(bool startMonitor)
{
    BPath path;
    BMessage settings;

    if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
        return;

    path.Append(kSettingsDirectory);
    if (create_directory(path.Path(), 0755) == B_OK) {
        path.Append(kGeneralSettings);

        BFile file(path.Path(), B_READ_ONLY);
        settings.Unflatten(&file);
    }

    if (settings.FindInt32(kTimeoutName, &fTimeout) != B_OK)
        fTimeout = kDefaultTimeout;

    // Notify the view about the change
    views_t::iterator it;
    for (it = fViews.begin(); it != fViews.end(); ++it) {
        NotificationView* view = (*it);
        view->SetText(view->Application(), view->Title(), view->Text());
        view->Invalidate();
    }

    if (startMonitor) {
        node_ref nref;
        BEntry entry(path.Path());
        entry.GetNodeRef(&nref);

        if (watch_node(&nref, B_WATCH_ALL, BMessenger(this)) != B_OK) {
            BAlert* alert = new BAlert(B_TRANSLATE("Warning"),
                                       B_TRANSLATE("Couldn't start general settings monitor.\n"
                                                   "Live filter changes disabled."), B_TRANSLATE("OK"));
            alert->Go();
        }
    }
}
Пример #2
0
void
NotificationWindow::_LoadDisplaySettings(bool startMonitor)
{
    BPath path;
    BMessage settings;

    if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
        return;

    path.Append(kSettingsDirectory);
    if (create_directory(path.Path(), 0755) == B_OK) {
        path.Append(kDisplaySettings);

        BFile file(path.Path(), B_READ_ONLY);
        settings.Unflatten(&file);
    }

    int32 setting;

    if (settings.FindFloat(kWidthName, &fWidth) != B_OK)
        fWidth = kDefaultWidth;

    if (settings.FindInt32(kIconSizeName, &setting) != B_OK)
        fIconSize = kDefaultIconSize;
    else
        fIconSize = (icon_size)setting;

    if (settings.FindInt32(kLayoutName, &setting) != B_OK)
        fLayout = kDefaultLayout;
    else {
        switch (setting) {
        case 0:
            fLayout = TitleAboveIcon;
            break;
        case 1:
            fLayout = AllTextRightOfIcon;
            break;
        default:
            fLayout = kDefaultLayout;
        }
    }

    // Notify the view about the change
    views_t::iterator it;
    for (it = fViews.begin(); it != fViews.end(); ++it) {
        NotificationView* view = (*it);
        view->SetText(view->Application(), view->Title(), view->Text());
        view->Invalidate();
    }

    if (startMonitor) {
        node_ref nref;
        BEntry entry(path.Path());
        entry.GetNodeRef(&nref);

        if (watch_node(&nref, B_WATCH_ALL, BMessenger(this)) != B_OK) {
            BAlert* alert = new BAlert(B_TRANSLATE("Warning"),
                                       B_TRANSLATE("Couldn't start display settings monitor.\n"
                                                   "Live filter changes disabled."), B_TRANSLATE("OK"));
            alert->Go();
        }
    }
}