Exemplo n.º 1
0
void
FrequencyMenu::UpdateMenu()
{
	freq_preferences* pref = fStorage->GetPreferences();
	switch (pref->mode) {
		case DYNAMIC:
			_SetL1MenuLabelFrom(fDynamicPerformance);
			break;

		case PERFORMANCE:
			_SetL1MenuLabelFrom(fHighPerformance);
			break;

		case LOW_ENERGIE:
			_SetL1MenuLabelFrom(fLowEnergie);
			break;

		case CUSTOM:
		{
			BMenuItem* markedItem = fCustomStateMenu->FindMarked();
			if (markedItem)
				markedItem->SetMarked(false);
			BMenuItem* customItem
				= fCustomStateMenu->ItemAt(pref->custom_stepping);
			if (customItem)
				customItem->SetMarked(true);
			BMenuItem* superItem = fCustomStateMenu->Supermenu()->Superitem();
			if (superItem && customItem)
				superItem->SetLabel(customItem->Label());
			break;
		}
	}
}
Exemplo n.º 2
0
void
NetworkSetupWindow::_BuildProfilesMenu(BMenu* menu, int32 msg_what)
{
    BMenuItem*	item;
    char current_profile[256] = { 0 };

    menu->SetRadioMode(true);

    BDirectory dir("/boot/common/settings/network/profiles");

    if (dir.InitCheck() == B_OK) {
        BEntry entry;
        BMessage* msg;

        dir.Rewind();
        while (dir.GetNextEntry(&entry) >= 0) {
            BPath name;
            entry.GetPath(&name);

            if (entry.IsSymLink() &&
                    strcmp("current", name.Leaf()) == 0) {
                BSymLink symlink(&entry);

                if (symlink.IsAbsolute())
                    // oh oh, sorry, wrong symlink...
                    continue;

                symlink.ReadLink(current_profile, sizeof(current_profile));
                continue;
            };

            if (!entry.IsDirectory())
                continue;

            msg = new BMessage(msg_what);
            msg->AddString("path", name.Path());

            item = new BMenuItem(name.Leaf(), msg);
            menu->AddItem(item);
        }
    }

    menu->AddSeparatorItem();
    menu->AddItem(new BMenuItem(B_TRANSLATE("New" B_UTF8_ELLIPSIS),
                                new BMessage(kMsgProfileNew)));
    menu->AddItem(new BMenuItem(B_TRANSLATE("Manage" B_UTF8_ELLIPSIS),
                                new BMessage(kMsgProfileManage)));

    if (strlen(current_profile)) {
        item = menu->FindItem(current_profile);
        if (item) {
            BString label;
            label << item->Label();
            label << " (current)";
            item->SetLabel(label.String());
            item->SetMarked(true);
        }
    }
}
Exemplo n.º 3
0
void HMenuField::ResizeLocalized(const char* label, const char* itemLabel)
{
	SetLabel(label);
	BMenuItem* item = MenuItem();
	if (item && itemLabel)
		item->SetLabel(itemLabel);
	SetDivider(label == NULL ? 0 : StringWidth(label)+StringWidth("n"));
	ResizeToPreferred();
} /* HMenuField::ResizeLocalized */
Exemplo n.º 4
0
TeamListView::TeamListView(BRect frame, const char *name, CLVContainerView **s)
	: ColumnListView(frame, s, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_NAVIGABLE|B_FRAME_EVENTS,
	B_MULTIPLE_SELECTION_LIST, true, true, true, false, B_FANCY_BORDER)
{
	// add Columns...
	AddColumn(new CLVColumn(NULL, 20.0, CLV_EXPANDER|CLV_LOCK_AT_BEGINNING|CLV_NOT_MOVABLE));
	AddColumn(new CLVColumn(NULL, 20.0, CLV_LOCK_AT_BEGINNING|CLV_NOT_RESIZABLE|
		CLV_NOT_MOVABLE|CLV_MERGE_WITH_RIGHT));
	AddColumn(new CLVColumn("Name", 100.0, CLV_LOCK_AT_BEGINNING|CLV_NOT_MOVABLE));
	AddColumn(new CLVColumn("Id", 40.0));
	AddColumn(new CLVColumn("Priority", 50.0));
	AddColumn(new CLVColumn("State", 60.0));
	AddColumn(new CLVColumn("Memory", 60.0));
	AddColumn(new CLVColumn("CPU", 60.0));
	
	SetInvocationMessage(new BMessage(TEAM_INV));
	
	// create the PopUpMenu
	BMenuItem *inv;
	
	operationMenu = new BPopUpMenu("operationMenu", false, false);
	operationMenu->AddItem((inv = new BMenuItem("Kill",
		new BMessage(IE_MAINWINDOW_MAINKILL))));
		inv->SetTarget(slayer->mainWindow);
	operationMenu->AddItem((inv = new BMenuItem("Suspend",
		new BMessage(IE_MAINWINDOW_MAINSUSPEND))));
		inv->SetTarget(slayer->mainWindow);
	operationMenu->AddItem((inv = new BMenuItem("Resume",
		new BMessage(IE_MAINWINDOW_MAINRESUME))));
		inv->SetTarget(slayer->mainWindow);
	operationMenu->AddSeparatorItem();
	priorityMenu = new BMenu("PriorityMenu");
	BMenuItem *pr = new BMenuItem(priorityMenu); //, new BMessage('tmpj'));
	pr->SetLabel("Set priority");
	operationMenu->AddItem(pr);
	ItemsToPopUpPriorityMenu();

//	MakeFocus(true);
//	 = new BMenu("Set priority");
//	operationMenu->AddItem(setPriorityMenu);

//	operationMenu->AddSeparator
}
Exemplo n.º 5
0
bool
FavoritesMenu::AddNextItem()
{
	// run the next chunk of code for a given item adding state

	if (fState == kStart) {
		fState = kAddingFavorites;
		fSectionItemCount = 0;
		fAddedSeparatorForSection = false;
		// set up adding the GoTo menu items

		try {
			BPath path;
			ThrowOnError(find_directory(B_USER_SETTINGS_DIRECTORY,
				&path, true));
			path.Append(kGoDirectory);
			mkdir(path.Path(), 0777);

			BEntry entry(path.Path());
			Model startModel(&entry, true);
			ThrowOnInitCheckError(&startModel);

			if (!startModel.IsContainer())
				throw B_ERROR;

			if (startModel.IsQuery())
				fContainer = new QueryEntryListCollection(&startModel);
			else
				fContainer = new DirectoryEntryList(*dynamic_cast<BDirectory*>
					(startModel.Node()));

			ThrowOnInitCheckError(fContainer);
			ThrowOnError( fContainer->Rewind() );

		} catch (...) {
			delete fContainer;
			fContainer = NULL;
		}
	}


	if (fState == kAddingFavorites) {
		entry_ref ref;
		if (fContainer
			&& fContainer->GetNextRef(&ref) == B_OK) {
			Model model(&ref, true);
			if (model.InitCheck() != B_OK)
				return true;

			if (!ShouldShowModel(&model))
				return true;

			BMenuItem* item = BNavMenu::NewModelItem(&model,
				model.IsDirectory() ? fOpenFolderMessage : fOpenFileMessage,
				fTarget);
				
			if (item == NULL)
				return true;

			item->SetLabel(ref.name);
				// this is the name of the link in the Go dir

			if (!fAddedSeparatorForSection) {
				fAddedSeparatorForSection = true;
				AddItem(new TitledSeparatorItem(B_TRANSLATE("Favorites")));
			}
			fUniqueRefCheck.push_back(*model.EntryRef());
			AddItem(item);
			fSectionItemCount++;
			return true;
		}

		// done with favorites, set up for adding recent files
		fState = kAddingFiles;

		fAddedSeparatorForSection = false;

		app_info info;
		be_app->GetAppInfo(&info);
		fItems.MakeEmpty();

		int32 apps, docs, folders;
		TrackerSettings().RecentCounts(&apps, &docs, &folders);

		BRoster().GetRecentDocuments(&fItems, docs, NULL, info.signature);
		fIndex = 0;
		fSectionItemCount = 0;
	}

	if (fState == kAddingFiles) {
		//	if this is a Save panel, not an Open panel
		//	then don't add the recent documents
		if (!fIsSavePanel) {
			for (;;) {
				entry_ref ref;
				if (fItems.FindRef("refs", fIndex++, &ref) != B_OK)
					break;

				Model model(&ref, true);
				if (model.InitCheck() != B_OK)
					return true;

				if (!ShouldShowModel(&model))
					return true;

				BMenuItem* item = BNavMenu::NewModelItem(&model,
					fOpenFileMessage, fTarget);
				if (item) {
					if (!fAddedSeparatorForSection) {
						fAddedSeparatorForSection = true;
						AddItem(new TitledSeparatorItem(
							B_TRANSLATE("Recent documents")));
					}
					AddItem(item);
					fSectionItemCount++;
					return true;
				}
			}
		}

		// done with recent files, set up for adding recent folders
		fState = kAddingFolders;

		fAddedSeparatorForSection = false;

		app_info info;
		be_app->GetAppInfo(&info);
		fItems.MakeEmpty();

		int32 apps, docs, folders;
		TrackerSettings().RecentCounts(&apps, &docs, &folders);

		BRoster().GetRecentFolders(&fItems, folders, info.signature);
		fIndex = 0;
	}

	if (fState == kAddingFolders) {
		for (;;) {
			entry_ref ref;
			if (fItems.FindRef("refs", fIndex++, &ref) != B_OK)
				break;

			// don't add folders that are already in the GoTo section
			if (find_if(fUniqueRefCheck.begin(), fUniqueRefCheck.end(),
				bind2nd(std::equal_to<entry_ref>(), ref))
					!= fUniqueRefCheck.end()) {
				continue;
			}

			Model model(&ref, true);
			if (model.InitCheck() != B_OK)
				return true;

			if (!ShouldShowModel(&model))
				return true;

			BMenuItem* item = BNavMenu::NewModelItem(&model,
				fOpenFolderMessage, fTarget, true);
			if (item) {
				if (!fAddedSeparatorForSection) {
					fAddedSeparatorForSection = true;
					AddItem(new TitledSeparatorItem(
						B_TRANSLATE("Recent folders")));
				}
				AddItem(item);
				item->SetEnabled(true);
					// BNavMenu::NewModelItem returns a disabled item here -
					// need to fix this in BNavMenu::NewModelItem
				return true;
			}
		}
	}
	return false;
}
Exemplo n.º 6
0
void TCueSheetWindow::Save(BMessage* message)
{
	status_t myErr;
	entry_ref theRef;
	char* theString = NULL;

	// Get directory to save data to
	message->FindRef("directory", &theRef);

	// Get name of file to be saved as
	message->FindString("name", (const char**)&theString);

	// Set window title to new filename
	SetTitle(theString);

	// Create a BDirectory object
	BDirectory saveDir(&theRef);

	// Now create the file.  Create new file if fFile is unitialized.
	if (fFile)
		delete fFile;

	fFile = new BFile();

	myErr = saveDir.CreateFile(theString, fFile, false);

	if (myErr != B_OK)
		return;

	//	Write out file header
	//WriteHeader(fFile);

	BMessage archive;

	//	Archive CueSheetWindow and write to file
	BMessage cueSheetArchive;
	Archive(&cueSheetArchive, true);

	//	Flatten and write out to file
	ssize_t numBytes;
	cueSheetArchive.Flatten(fFile, &numBytes);

	// Set file type
	BNodeInfo info(fFile);
	if ( info.InitCheck() )
		return;

	myErr = info.SetType("application/x-mediapede-cuesheet");

	// Set icons
	BBitmap* smallIcon = GetMICNFromResource("application/x-mediapede-cuesheet");
	info.SetIcon( smallIcon, B_MINI_ICON);

	BBitmap* largeIcon = GetICONFromResource("application/x-mediapede-cuesheet");
	info.SetIcon( largeIcon, B_LARGE_ICON);

	delete smallIcon;
	delete largeIcon;

	// Update our entry in the Windows menu to reflect possible new filename
	BMenuItem* theItem = fAppMenu->GetWindowsMenu()->FindItem( Title());
	if (theItem)
		theItem->SetLabel(theString);

	// We aren't dirty now
	fCueSheetView->SetDirty(false);
}
Exemplo n.º 7
0
void TCueSheetWindow::AdjustWindowsMenu()
{

	//	Set up string buffers
	bool retVal;
	char* menuStr   = (char*)malloc( sizeof(char) * 256);

	// Get application
	MuseumApp* theApp = static_cast<MuseumApp*>(be_app);

	BMenu* theMenu = fAppMenu->GetWindowsMenu();
	if (theMenu) {
		//      Stage Item
		BMenuItem* stageItem = theMenu->FindItem(WINDOWS_STAGE_MSG);
		if (stageItem) {
			TStageWindow* stage = fStageWindow;
			if (stage) {
				stage->Lock();
				if (stage->IsHidden())
					retVal = GetString("WindowsMenuStrings", kWindowsShowStageItem, menuStr);
				else
					retVal = GetString("WindowsMenuStrings", kWindowsHideStageItem, menuStr);
				stage->Unlock();

				stageItem->SetLabel(menuStr);
			} else {
				retVal = GetString("WindowsMenuStrings", kWindowsShowStageItem, menuStr);
				stageItem->SetLabel(menuStr);
			}
		}

		// Browser Item
		BMenuItem* browserItem = theMenu->FindItem(WINDOWS_BROWSER_MSG);
		if (stageItem) {
			TBrowserWindow* browser = theApp->GetBrowser();
			if (browser) {
				browser->Lock();
				if (browser->IsHidden())
					retVal = GetString("WindowsMenuStrings", kWindowsShowBrowserItem, menuStr);
				else
					retVal = GetString("WindowsMenuStrings", kWindowsHideBrowserItem, menuStr);
				browser->Unlock();

				browserItem->SetLabel(menuStr);
			} else {
				retVal = GetString("WindowsMenuStrings", kWindowsShowBrowserItem, menuStr);
				browserItem->SetLabel(menuStr);
			}
		}

		//      Transport Item
		BMenuItem* transportItem = theMenu->FindItem(WINDOWS_TRANSPORT_MSG);
		if (transportItem) {
			TTransportPalette* transport = theApp->GetTransport();
			if (transport) {
				transport->Lock();
				if (transport->IsHidden())
					retVal = GetString("WindowsMenuStrings", kWindowsShowTransportItem, menuStr);
				else
					retVal = GetString("WindowsMenuStrings", kWindowsHideTransportItem, menuStr);
				transport->Unlock();

				transportItem->SetLabel(menuStr);
			} else {
				retVal = GetString("WindowsMenuStrings", kWindowsShowTransportItem, menuStr);
				transportItem->SetLabel(menuStr);
			}
		}

		//      Locator Item
		BMenuItem* counterItem = theMenu->FindItem(WINDOWS_COUNTER_MSG);
		if (counterItem) {
			TTimePalette* time = theApp->GetTimePalette();
			if (time) {
				time->Lock();
				if (time->IsHidden())
					retVal = GetString("WindowsMenuStrings", kWindowsShowLocatorItem, menuStr);
				else
					retVal = GetString("WindowsMenuStrings", kWindowsHideLocatorItem, menuStr);
				time->Unlock();

				counterItem->SetLabel(menuStr);
			} else {
				retVal = GetString("WindowsMenuStrings", kWindowsShowLocatorItem, menuStr);
				counterItem->SetLabel(menuStr);
			}
		}

		//      Media Cue Item
		BMenuItem* mediaItem = theMenu->FindItem(WINDOWS_MEDIA_MSG);
		if (mediaItem) {
			TMediaCuePalette* mediaPalette = theApp->GetMediaPalette();
			if (mediaPalette) {
				mediaPalette->Lock();
				if (mediaPalette->IsHidden())
					retVal = GetString("WindowsMenuStrings", kWindowsShowMediaItem, menuStr);
				else
					retVal = GetString("WindowsMenuStrings", kWindowsHideMediaItem, menuStr);
				mediaPalette->Unlock();

				mediaItem->SetLabel(menuStr);
			} else {
				retVal = GetString("WindowsMenuStrings", kWindowsShowMediaItem, menuStr);
				mediaItem->SetLabel(menuStr);
			}
		}
	}
}
Exemplo n.º 8
0
void
PackageView::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case P_MSG_INSTALL:
		{
			fBeginButton->SetEnabled(false);
			fInstallTypes->SetEnabled(false);
			fDestination->SetEnabled(false);
			fStatusWindow->Show();

			fInstallProcess.Start();
			break;
		}

		case P_MSG_PATH_CHANGED:
		{
			BString path;
			if (message->FindString("path", &path) == B_OK)
				fCurrentPath.SetTo(path.String());
			break;
		}

		case P_MSG_OPEN_PANEL:
			fExpectingOpenPanelResult = true;
			fOpenPanel->Show();
			break;

		case P_MSG_INSTALL_TYPE_CHANGED:
		{
			int32 index;
			if (message->FindInt32("index", &index) == B_OK)
				_InstallTypeChanged(index);
			break;
		}

		case P_MSG_I_FINISHED:
		{
			BAlert* notify = new BAlert("installation_success",
				B_TRANSLATE("The package you requested has been successfully "
					"installed on your system."),
				B_TRANSLATE("OK"));
			notify->SetFlags(notify->Flags() | B_CLOSE_ON_ESCAPE);

			notify->Go();
			fStatusWindow->Hide();
			fBeginButton->SetEnabled(true);
			fInstallTypes->SetEnabled(true);
			fDestination->SetEnabled(true);
			fInstallProcess.Stop();

			BWindow *parent = Window();
			if (parent && parent->Lock())
				parent->Quit();
			break;
		}

		case P_MSG_I_ABORT:
		{
			BAlert* notify = new BAlert("installation_aborted",
				B_TRANSLATE(
					"The installation of the package has been aborted."),
				B_TRANSLATE("OK"));
			notify->SetFlags(notify->Flags() | B_CLOSE_ON_ESCAPE);
			notify->Go();
			fStatusWindow->Hide();
			fBeginButton->SetEnabled(true);
			fInstallTypes->SetEnabled(true);
			fDestination->SetEnabled(true);
			fInstallProcess.Stop();
			break;
		}

		case P_MSG_I_ERROR:
		{
			// TODO: Review this
			BAlert* notify = new BAlert("installation_failed",
				B_TRANSLATE("The requested package failed to install on your "
					"system. This might be a problem with the target package "
					"file. Please consult this issue with the package "
					"distributor."),
				B_TRANSLATE("OK"),
				NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
			fprintf(stderr,
				B_TRANSLATE("Error while installing the package\n"));
			notify->SetFlags(notify->Flags() | B_CLOSE_ON_ESCAPE);
			notify->Go();
			fStatusWindow->Hide();
			fBeginButton->SetEnabled(true);
			fInstallTypes->SetEnabled(true);
			fDestination->SetEnabled(true);
			fInstallProcess.Stop();
			break;
		}

		case P_MSG_STOP:
		{
			// This message is sent to us by the PackageStatus window, informing
			// user interruptions.
			// We actually use this message only when a post installation script
			// is running and we want to kill it while it's still running
			fStatusWindow->Hide();
			fBeginButton->SetEnabled(true);
			fInstallTypes->SetEnabled(true);
			fDestination->SetEnabled(true);
			fInstallProcess.Stop();
			break;
		}

		case B_REFS_RECEIVED:
		{
			if (!_ValidateFilePanelMessage(message))
				break;

			entry_ref ref;
			if (message->FindRef("refs", &ref) == B_OK) {
				BPath path(&ref);
				if (path.InitCheck() != B_OK)
					break;

				dev_t device = dev_for_path(path.Path());
				BVolume volume(device);
				if (volume.InitCheck() != B_OK)
					break;

				BMenuItem* item = fDestField->MenuItem();

				BString name = _NamePlusSizeString(path.Path(),
					volume.FreeBytes(), B_TRANSLATE("%name% (%size% free)"));

				item->SetLabel(name.String());
				fCurrentPath.SetTo(path.Path());
			}
			break;
		}

		case B_CANCEL:
		{
			if (!_ValidateFilePanelMessage(message))
				break;

			// file panel aborted, select first suitable item
			for (int32 i = 0; i < fDestination->CountItems(); i++) {
				BMenuItem* item = fDestination->ItemAt(i);
				BMessage* message = item->Message();
				if (message == NULL)
					continue;
				BString path;
				if (message->FindString("path", &path) == B_OK) {
					fCurrentPath.SetTo(path.String());
					item->SetMarked(true);
					break;
				}
			}
			break;
		}

		case B_SIMPLE_DATA:
			if (message->WasDropped()) {
				uint32 type;
				int32 count;
				status_t ret = message->GetInfo("refs", &type, &count);
				// check whether the message means someone dropped a file
				// to our view
				if (ret == B_OK && type == B_REF_TYPE) {
					// if it is, send it along with the refs to the application
					message->what = B_REFS_RECEIVED;
					be_app->PostMessage(message);
				}
			}
			// fall-through
		default:
			BView::MessageReceived(message);
			break;
	}
}
Exemplo n.º 9
0
status_t
PMenuItem::SetProperty(const char *name, PValue *value, const int32 &index)
{
	if (!name || !value)
		return B_ERROR;
	
	BString str(name);
	PProperty *prop = FindProperty(name,index);
	if (!prop)
		return B_NAME_NOT_FOUND;
	
	if (FlagsForProperty(prop) & PROPERTY_READ_ONLY)
		return B_READ_ONLY;
	
	BMenuItem *backend = (BMenuItem*)fBackend;
	
	BoolValue boolval;
	CharValue charval;
	ColorValue colorval;
	FloatValue floatval;
	IntValue intval;
	PointValue pointval;
	RectValue rectval;
	StringValue stringval;
	
	status_t status = prop->SetValue(value);
	if (status != B_OK)
		return status;

	if (str.ICompare("Message") == 0)
	{
		prop->GetValue(&intval);
		backend->SetMessage(new BMessage(*intval.value));
	}
	else if (str.ICompare("Trigger") == 0)
	{
		prop->GetValue(&charval);
		backend->SetTrigger(*charval.value);
	}
	else if (str.ICompare("Label") == 0)
	{
		prop->GetValue(&stringval);
		backend->SetLabel(*stringval.value);
	}
	else if (str.ICompare("Marked") == 0)
	{
		prop->GetValue(&boolval);
		backend->SetMarked(*boolval.value);
	}
	else if (str.ICompare("Enabled") == 0)
	{
		prop->GetValue(&boolval);
		backend->SetEnabled(*boolval.value);
	}
	else
	{
		return PObject::SetProperty(name, value, index);
	}

	return prop->GetValue(value);
}
Exemplo n.º 10
0
/**
 *	@brief	Message handler.
 */
void BePreferencesDlg::MessageReceived(
    BMessage *message		//!< received message.
)
{
    try
    {
        switch (message->what)
        {
        case ID_PREF_KEYMAP_SELECTED:
            HandleUICEvent(CID_KeyMapListBox, UICE_SelectionChanged, 0, NULL);
            break;

        case ID_PREF_EDIT_KEYMAP:
            HandleUICEvent(CID_EditKeyMapButton, UICE_ButtonClicked, 0, NULL);
            break;

        case ID_PREF_DUPLICATE_KEYMAP:
            HandleUICEvent(CID_DuplicateKeyMapButton, UICE_ButtonClicked, 0, NULL);
            break;

        case ID_PREF_DELETE_KEYMAP:
            HandleUICEvent(CID_DeleteKeyMapButton, UICE_ButtonClicked, 0, NULL);
            break;

        case ID_DIALOG_OK:
            HandleUICEvent(CID_OKButton, UICE_ButtonClicked, 0, NULL);
            break;

        case ID_DIALOG_CANCEL:
            HandleUICEvent(CID_CancelButton, UICE_ButtonClicked, 0, NULL);
            break;

#if defined (ZETA)
        case B_LANGUAGE_CHANGED:
            // always use locake kit to show "Use LocakeKit" item label.
            // note that languageChanged() is called only when current setting
            // is "Use LocaleKit". so do here.
            if (NULL != langMenu && langMenu->CountItems() > 0)
            {
                BMenuItem* menuItem = langMenu->ItemAt(0);
                menuItem->SetLabel(_T(LangSelectHelper::LANGMENU_LOCALEKIT));
                if (menuItem->IsMarked())
                {
                    menuItem->SetMarked(false);
                    menuItem->SetMarked(true);
                }
            }
            baseWindow::MessageReceived(message);
            break;
#endif

        default:
            baseWindow::MessageReceived(message);
            break;
        }
    }
    catch (Exception* ex)
    {
        ExceptionMessageUtils::DoExceptionMessageBox(CoveredCalcApp::GetInstance(), ex);
        ex->Delete();
    }
}