void
MediaConverterWindow::LanguageChanged()
{
	_DestroyMenu();
	_CreateMenu();
	_UpdateLabels();
	BuildAudioVideoMenus();
	Lock();
	fInfoView->Invalidate();
	Unlock();
}
Example #2
0
KeymapWindow::KeymapWindow()
	:
	BWindow(BRect(80, 50, 880, 380), TR("Keymap"), B_TITLED_WINDOW,
		B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
{
	SetLayout(new BGroupLayout(B_VERTICAL));

	fKeyboardLayoutView = new KeyboardLayoutView("layout");
	fKeyboardLayoutView->SetKeymap(&fCurrentMap);

	fTextControl = new BTextControl(TR("Sample and clipboard:"), "", NULL);

	fSwitchShortcutsButton = new BButton("switch", "",
		new BMessage(kMsgSwitchShortcuts));

	fRevertButton = new BButton("revertButton", TR("Revert"),
		new BMessage(kMsgRevertKeymap));

	// controls pane
	AddChild(BGroupLayoutBuilder(B_VERTICAL)
		.Add(_CreateMenu())
		.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
			.Add(_CreateMapLists(), 0.25)
			.Add(BGroupLayoutBuilder(B_VERTICAL, 10)
				.Add(fKeyboardLayoutView)
				//.Add(new BStringView("text label", "Sample and clipboard:"))
				.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
					.Add(_CreateDeadKeyMenuField(), 0.0)
					.AddGlue()
					.Add(fSwitchShortcutsButton))
				.Add(fTextControl)
				.AddGlue(0.0)
				.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
					.AddGlue(0.0)
					.Add(fRevertButton)))
			.SetInsets(10, 10, 10, 10)));

	fKeyboardLayoutView->SetTarget(fTextControl->TextView());
	fTextControl->MakeFocus();

	// Make sure the user keymap directory exists
	BPath path;
	find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	path.Append("Keymap");

	entry_ref ref;
	get_ref_for_path(path.Path(), &ref);

	BDirectory userKeymapsDir(&ref);
	if (userKeymapsDir.InitCheck() != B_OK)
		create_directory(path.Path(), S_IRWXU | S_IRWXG | S_IRWXO);

	BMessenger messenger(this);
	fOpenPanel = new BFilePanel(B_OPEN_PANEL, &messenger, &ref,
		B_FILE_NODE, false, NULL);
	fSavePanel = new BFilePanel(B_SAVE_PANEL, &messenger, &ref,
		B_FILE_NODE, false, NULL);

	BRect windowFrame;
	BString keyboardLayout;
	_LoadSettings(windowFrame, keyboardLayout);
	_SetKeyboardLayout(keyboardLayout.String());

	ResizeTo(windowFrame.Width(), windowFrame.Height());
	MoveTo(windowFrame.LeftTop());

	// TODO: this might be a bug in the interface kit, but scrolling to
	// selection does not correctly work unless the window is shown.
	Show();
	Lock();

	// Try and find the current map name in the two list views (if the name
	// was read at all)
	_SelectCurrentMap();

	KeymapListItem* current
		= static_cast<KeymapListItem*>(fUserListView->FirstItem());

	fCurrentMap.Load(current->EntryRef());
	fPreviousMap = fCurrentMap;
	fAppliedMap = fCurrentMap;
	fCurrentMap.SetTarget(this, new BMessage(kMsgKeymapUpdated));

	_UpdateButtons();

	_UpdateDeadKeyMenu();
	_UpdateSwitchShortcutButton();

	Unlock();
}
MediaConverterWindow::MediaConverterWindow(BRect frame)
	:
	BWindow(frame, B_TRANSLATE_SYSTEM_NAME("MediaConverter"),
		B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE
		| B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS
		| B_AUTO_UPDATE_SIZE_LIMITS),
	fVideoQuality(75),
	fAudioQuality(75),
	fSaveFilePanel(NULL),
	fOpenFilePanel(NULL),
	fOutputDirSpecified(false),
	fEnabled(true),
	fConverting(false),
	fCancelling(false)
{
	BPath outputDir;
	if (find_directory(B_USER_DIRECTORY, &outputDir) != B_OK)
		outputDir.SetTo("/boot/home");	
	fOutputDir.SetTo(outputDir.Path());

	fMenuBar = new BMenuBar("menubar");
	_CreateMenu();

	float padding = be_control_look->DefaultItemSpacing();

	fListView = new MediaFileListView();
	fListView->SetExplicitMinSize(BSize(padding * kMinSourceWidth, B_SIZE_UNSET));
	BScrollView* scroller = new BScrollView(NULL, fListView, 0, false, true);

	// file list view box
	fSourcesBox = new BBox(B_FANCY_BORDER, scroller);
	fSourcesBox->SetLayout(new BGroupLayout(B_HORIZONTAL, 0));
		// fSourcesBox's layout adjusted in _UpdateLabels

	// info box
	fInfoView = new MediaFileInfoView();
	fInfoView->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
		B_ALIGN_VERTICAL_UNSET));
	fInfoBox = new BBox(B_FANCY_BORDER, fInfoView);

	// output menu fields
	fFormatMenu = new BMenuField(NULL, B_TRANSLATE("File format:"),
		new BPopUpMenu(""));
	fAudioMenu = new BMenuField(NULL, B_TRANSLATE("Audio encoding:"),
		new BPopUpMenu(""));
	fVideoMenu = new BMenuField(NULL, B_TRANSLATE("Video encoding:"),
		new BPopUpMenu(""));

	// output folder
	fDestButton = new BButton(B_TRANSLATE("Output folder"),
		new BMessage(OUTPUT_FOLDER_MESSAGE));
	BAlignment labelAlignment(be_control_look->DefaultLabelAlignment());
	fOutputFolder = new BStringView(NULL, outputDir.Path());
	fOutputFolder->SetExplicitAlignment(labelAlignment);

	// start/end duration
	fStartDurationTC = new BTextControl(NULL, "0", NULL);
	BLayoutItem* startDuration = fStartDurationTC->CreateTextViewLayoutItem();
	startDuration->SetExplicitSize(BSize(padding * kDurationWidth, B_SIZE_UNSET));
	startDuration->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_CENTER));
	fEndDurationTC = new BTextControl(NULL, "0", NULL);
	BLayoutItem* endDuration = fEndDurationTC->CreateTextViewLayoutItem();
	endDuration->SetExplicitSize(BSize(padding * kDurationWidth, B_SIZE_UNSET));
	endDuration->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_CENTER));

	// video quality
	fVideoQualitySlider = new BSlider("VSlider", "" ,
		new BMessage(VIDEO_QUALITY_CHANGED_MESSAGE), 1, 100, B_HORIZONTAL);
	fVideoQualitySlider->SetModificationMessage(
		new BMessage(VIDEO_QUALITY_CHANGED_MESSAGE));
	fVideoQualitySlider->SetValue(fVideoQuality);
	fVideoQualitySlider->SetEnabled(false);
	fVideoQualitySlider->SetExplicitSize(BSize(padding * kQualitySliderWidth,
		B_SIZE_UNSET));

	// audio quality
	fAudioQualitySlider = new BSlider("ASlider", "" ,
		new BMessage(AUDIO_QUALITY_CHANGED_MESSAGE), 1, 100, B_HORIZONTAL);
	fAudioQualitySlider->SetModificationMessage(
		new BMessage(AUDIO_QUALITY_CHANGED_MESSAGE));
	fAudioQualitySlider->SetValue(fAudioQuality);
	fAudioQualitySlider->SetEnabled(false);
	fAudioQualitySlider->SetExplicitSize(BSize(padding * kQualitySliderWidth,
		B_SIZE_UNSET));

	// output format box
	BView* outputGrid = BLayoutBuilder::Grid<>()
		.Add(fFormatMenu->CreateLabelLayoutItem(), 0, 0)
		.Add(fFormatMenu->CreateMenuBarLayoutItem(), 1, 0)
		.Add(fAudioMenu->CreateLabelLayoutItem(), 0, 1)
		.Add(fAudioMenu->CreateMenuBarLayoutItem(), 1, 1)
		.Add(fVideoMenu->CreateLabelLayoutItem(), 0, 2)
		.Add(fVideoMenu->CreateMenuBarLayoutItem(), 1, 2)
		.Add(fDestButton, 0, 3)
		.Add(fOutputFolder, 1, 3)
		.Add(fStartDurationTC->CreateLabelLayoutItem(), 0, 4)
		.Add(startDuration, 1, 4)
		.Add(fEndDurationTC->CreateLabelLayoutItem(), 0, 5)
		.Add(endDuration, 1, 5)
		.Add(fVideoQualitySlider, 0, 6, 2, 1)
		.Add(fAudioQualitySlider, 0, 7, 2, 1)
		.View();
	outputGrid->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
		B_ALIGN_USE_FULL_HEIGHT));
	fOutputBox = new OutputBox(B_FANCY_BORDER, outputGrid);
	fOutputBox->SetLayout(new BGroupLayout(B_HORIZONTAL, 0));
		// fOutputBox's layout adjusted in _UpdateLabels

	// buttons
	fPreviewButton = new BButton(B_TRANSLATE("Preview"),
		new BMessage(PREVIEW_MESSAGE));
	fPreviewButton->SetEnabled(false);

	fConvertButton = new BButton(B_TRANSLATE("Convert"),
		new BMessage(CONVERT_BUTTON_MESSAGE));

	// Status views
	fStatus = new BStringView(NULL, NULL);
	fStatus->SetExplicitAlignment(labelAlignment);
	fFileStatus = new BStringView(NULL, NULL);
	fFileStatus->SetExplicitAlignment(labelAlignment);

	SetStatusMessage("");
	_UpdateLabels();

	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
		.SetInsets(0, 0, 0, 0)
		.Add(fMenuBar)
		.AddSplit(B_HORIZONTAL, padding / 2)
			.SetInsets(padding, padding, padding, padding)
			.Add(fSourcesBox, 0.4)
			.AddGroup(B_VERTICAL, padding, 0.6)
				.Add(fInfoBox)
				.Add(fOutputBox)
			.End()
		.End()
		.AddGrid(padding, padding)
			.SetInsets(padding, 0, padding, padding)
			.Add(fStatus, 0, 0)
			.Add(fFileStatus, 0, 1)
			.Add(BSpaceLayoutItem::CreateGlue(), 1, 0)
			.Add(fPreviewButton, 2, 0)
			.Add(fConvertButton, 3, 0)
		.End();
}
/*********************************************************************
*
*       _cbCallbackWidgets
*
* Purpose:
*   Initializes the widgets of the main dialog box
*/
static void _cbCallbackWidgets(WM_MESSAGE * pMsg) {
  GRAPH_SCALE_Handle hScaleH, hScaleV;
  int i;
  WM_HWIN hDlg, hMenu;
  hDlg = pMsg->hWin;
  switch (pMsg->MsgId) {
    case WM_INIT_DIALOG:
      /* Get handles of widgets */
      for (i = 0; i < NUM_WIDGETS; i++) {
        _ahWin[i] = WM_GetDialogItem(hDlg, _aID[i]);
      }
      /* Init dropdown widget */
      for (i = 0; i < 8; i++) {
        char acBuffer[] = {"Item x"};
        int Len = strlen(acBuffer);
        acBuffer[Len - 1] = '1' + i;
        DROPDOWN_AddString(_ahWin[DROPDOWN0], acBuffer);
      }
      /* Init edit widget */
      EDIT_SetText(_ahWin[EDIT0], "Edit");
      /* Init listbox widget */
      LISTBOX_SetAutoScrollV(_ahWin[LISTBOX0], 1);
      for (i = 0; i < 4; i++) {
        char acBuffer[] = {"Item x"};
        int Len = strlen(acBuffer);
        acBuffer[Len - 1] = '1' + i;
        LISTBOX_AddString(_ahWin[LISTBOX0], acBuffer);
      }
      /* Init listview widget */
      for (i = 0; i < 2; i++) {
        char acBuffer[] = {"Col. x"};
        int Len = strlen(acBuffer);
        acBuffer[Len - 1] = '1' + i;
        LISTVIEW_AddColumn(_ahWin[LISTVIEW0], 60, acBuffer, GUI_TA_CENTER);
      }
      for (i = 0; i < 9; i++) {
        int j;
        LISTVIEW_AddRow(_ahWin[LISTVIEW0], NULL);
        for (j = 0; j < (int)LISTVIEW_GetNumColumns(_ahWin[LISTVIEW0]); j++) {
          char acBuffer[] = {"Rx/Cx"};
          acBuffer[1] = '1' + i;
          acBuffer[4] = '1' + j;
          LISTVIEW_SetItemText(_ahWin[LISTVIEW0], j, i, acBuffer);
        }
      }
      LISTVIEW_SetGridVis(_ahWin[LISTVIEW0], 1);
      SCROLLBAR_CreateAttached(_ahWin[LISTVIEW0], SCROLLBAR_CF_VERTICAL);
      /* Init multiedit widget */
      MULTIEDIT_SetText(_ahWin[MULTIEDIT0], "This text could be modified by the MULTIEDIT widget");
      MULTIEDIT_SetWrapWord(_ahWin[MULTIEDIT0]);
      MULTIEDIT_SetAutoScrollV(_ahWin[MULTIEDIT0], 1);
      /* Init progbar widget */
      WIDGET_SetEffect(_ahWin[PROGBAR0], &WIDGET_Effect_3D);
      /* Init graph widget */
      for (i = 0; i < GUI_COUNTOF(_aColor); i++) {
        _aValue[i] = rand() % 95;
        _ahData[i] = GRAPH_DATA_YT_Create(_aColor[i], 500, 0, 0);
        GRAPH_AttachData(_ahWin[GRAPH0], _ahData[i]);
      }
      GRAPH_SetGridDistY(_ahWin[GRAPH0], 25);
      GRAPH_SetGridVis(_ahWin[GRAPH0], 1);
      GRAPH_SetGridFixedX(_ahWin[GRAPH0], 1);
      GRAPH_SetBorder(_ahWin[GRAPH0], 20, 4, 5, 4);
      /* Create and add vertical scale of graph widget */
      hScaleV = GRAPH_SCALE_Create(18, GUI_TA_RIGHT, GRAPH_SCALE_CF_VERTICAL, 25);
      GRAPH_SCALE_SetTextColor(hScaleV, GUI_RED);
      GRAPH_AttachScale(_ahWin[GRAPH0], hScaleV);
      /* Create and add horizontal scale of graph widget */
      hScaleH = GRAPH_SCALE_Create(46, GUI_TA_HCENTER | GUI_TA_VCENTER, GRAPH_SCALE_CF_HORIZONTAL, 50);
      GRAPH_SCALE_SetTextColor(hScaleH, GUI_DARKGREEN);
      GRAPH_AttachScale(_ahWin[GRAPH0], hScaleH);
      /* Init multipage widget */
      MULTIPAGE_AddPage(_ahWin[MULTIPAGE0],
                        GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbDialogPage, WM_UNATTACHED, 0, 0), 
                        "Page 1");
      MULTIPAGE_AddPage(_ahWin[MULTIPAGE0],
                        GUI_CreateDialogBox(_aDialogCreate2, GUI_COUNTOF(_aDialogCreate2), &_cbDialogPage, WM_UNATTACHED, 0, 0), 
                        "Page 2");
      /* Create and attach menu */
      hMenu = _CreateMenu(hDlg);/**/
      break;
    default:
      WM_DefaultProc(pMsg);
  }
}