Beispiel #1
0
void
App::_Open(const BEntry& entry)
{
    BPath path;
    if (!entry.Exists() || entry.GetPath(&path) != B_OK) {
        fprintf(stderr, "Package file not found: %s\n", path.Path());
        return;
    }

    // Try to parse package file via Package Kit
    BPackageKit::BPackageInfo info;
    status_t status = info.ReadFromPackageFile(path.Path());
    if (status != B_OK) {
        fprintf(stderr, "Failed to parse package file: %s\n",
                strerror(status));
        return;
    }

    // Transfer information into PackageInfo
    PackageInfoRef package(new(std::nothrow) PackageInfo(info), true);
    if (package.Get() == NULL) {
        fprintf(stderr, "Could not allocate PackageInfo\n");
        return;
    }

    package->SetLocalFilePath(path.Path());

    BMessage settings;
    _LoadSettings(settings);

    MainWindow* window = new MainWindow(settings, package);
    _ShowWindow(window);
}
Beispiel #2
0
PowerStatusReplicant::PowerStatusReplicant(BMessage* archive)
	:
	PowerStatusView(archive)
{
	_Init();
	_LoadSettings();
}
Beispiel #3
0
// _InitSettings
status_t
NetFSServer::_InitSettings()
{
	status_t error = _LoadSettings();
	if (error != B_OK) {
		WARN("NetFSServer::_InitSettings(): WARNING: Failed to load settings "
			"file: %s - falling back to driver settings.\n", strerror(error));

		// fall back to the driver settings file
		error = _LoadSecurityContext(&fSecurityContext);
		if (error != B_OK) {
			WARN("NetFSServer::_InitSettings(): WARNING: Failed to load "
				"settings from driver settings: %s\n", strerror(error));

			// use defaults
			// create a security context
			fSecurityContext = new(std::nothrow) SecurityContext;
			if (!fSecurityContext)
				return B_NO_MEMORY;
			error = fSecurityContext->InitCheck();
			if (error != B_OK)
				return error;
		}
	}

	return B_OK;
}
Beispiel #4
0
/* virtual */
void
MidiSettingsView::AttachedToWindow()
{
	SettingsView::AttachedToWindow();

	fListView->SetTarget(this);
	_RetrieveSoftSynthList();

	_LoadSettings();
}
void
MediaReplicant::_Init()
{
	fIcon = new BBitmap(BRect(0, 0, kSpeakerWidth - 1, kSpeakerHeight - 1),
		B_RGBA32);
	BIconUtils::GetVectorIcon(kSpeakerIcon, sizeof(kSpeakerIcon), fIcon);

	_LoadSettings();

	SetToolTip(new VolumeToolTip(fVolumeWhich));
}
Beispiel #6
0
void
App::ReadyToRun()
{
	if (fWindowCount > 0)
		return;

	BMessage settings;
	_LoadSettings(settings);

	fMainWindow = new MainWindow(_GetNextWindowFrame(false), settings);
	_ShowWindow(fMainWindow);
}
Beispiel #7
0
void
CalcApplication::ReadyToRun()
{
	BMessage settings;
	_LoadSettings(settings);

	BRect frame(0, 0, kDefaultWindowWidth - 1, kDefaultWindowHeight - 1);
	fCalcWindow = new CalcWindow(frame, &settings);

	// reveal window
	fCalcWindow->Show();
}
Beispiel #8
0
void
App::ReadyToRun()
{
    if (fWindowCount > 0)
        return;

    BMessage settings;
    _LoadSettings(settings);

    fMainWindow = new MainWindow(settings);
    _ShowWindow(fMainWindow);
}
Beispiel #9
0
void
CalcView::_Init(BMessage* settings)
{
	// create expression text view
	fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
	AddChild(fExpressionTextView);

	// read data from archive
	_LoadSettings(settings);

	// fetch the calc icon for compact view
	_FetchAppIcon(fCalcIcon);

	fEvaluateSemaphore = create_sem(1, "Evaluate Semaphore");
}
Beispiel #10
0
void
CalcView::_Init(BMessage* settings)
{
	// create expression text view
	fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
	AddChild(fExpressionTextView);

	// read data from archive
	_LoadSettings(settings);

	// fetch the calc icon for compact view
	_FetchAppIcon(fCalcIcon);

	fAboutWindow = NULL;
}
Beispiel #11
0
NotificationWindow::NotificationWindow()
	:
	BWindow(BRect(0, 0, -1, -1), B_TRANSLATE_MARK("Notification"), 
		B_BORDERED_WINDOW_LOOK, B_FLOATING_ALL_WINDOW_FEEL, B_AVOID_FRONT
		| B_AVOID_FOCUS | B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
		| B_NOT_RESIZABLE | B_NOT_MOVABLE | B_AUTO_UPDATE_SIZE_LIMITS, 
		B_ALL_WORKSPACES)
{
	SetLayout(new BGroupLayout(B_VERTICAL, 0));

	_LoadSettings(true);

	// Start the message loop
	Hide();
	Show();
}
Beispiel #12
0
CalcView::CalcView(BRect frame, rgb_color rgbBaseColor, BMessage* settings)
	:
	BView(frame, "DeskCalc", B_FOLLOW_ALL_SIDES,
		B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
	fColumns(5),
	fRows(4),

	fBaseColor(rgbBaseColor),
	fExpressionBGColor((rgb_color){ 0, 0, 0, 255 }),

	fWidth(1),
	fHeight(1),

	fKeypadDescription(strdup(kKeypadDescriptionBasic)),
	fKeypad(NULL),

#ifdef __HAIKU__
	fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_RGBA32)),
#else
	fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_CMAP8)),
#endif

	fPopUpMenu(NULL),
	fAutoNumlockItem(NULL),
	fAudioFeedbackItem(NULL),
	fOptions(new CalcOptions())
{
	// create expression text view
	fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
	AddChild(fExpressionTextView);

	// read data from archive
	_LoadSettings(settings);

	// tell the app server not to erase our b/g
	SetViewColor(B_TRANSPARENT_32_BIT);

	// parse calculator description
	_ParseCalcDesc(fKeypadDescription);

	// colorize based on base color.
	_Colorize();

	// Fetch the calc icon for compact view
	_FetchAppIcon(fCalcIcon);
}
Beispiel #13
0
PowerStatusReplicant::PowerStatusReplicant(BRect frame, int32 resizingMode,
	bool inDeskbar)
	:
	PowerStatusView(NULL, frame, resizingMode, -1, inDeskbar)
{
	_Init();
	_LoadSettings();

	if (!inDeskbar) {
		// we were obviously added to a standard window - let's add a dragger
		frame.OffsetTo(B_ORIGIN);
		frame.top = frame.bottom - 7;
		frame.left = frame.right - 7;
		BDragger* dragger = new BDragger(frame, this,
			B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
		AddChild(dragger);
	} else
		Update();
}
Beispiel #14
0
CalcView::CalcView(BMessage* archive)
	:
	BView(archive),
	fColumns(5),
	fRows(4),

	fBaseColor((rgb_color){ 128, 128, 128, 255 }),
	fExpressionBGColor((rgb_color){ 0, 0, 0, 255 }),

	fWidth(1),
	fHeight(1),

	fKeypadDescription(strdup(kKeypadDescriptionBasic)),
	fKeypad(NULL),

#ifdef __HAIKU__
	fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_RGBA32)),
#else
	fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_CMAP8)),
#endif

	fPopUpMenu(NULL),
	fAutoNumlockItem(NULL),
	fAudioFeedbackItem(NULL),
	fOptions(new CalcOptions())
{
	// Do not restore the follow mode, in shelfs, we never follow.
	SetResizingMode(B_FOLLOW_NONE);

	// create expression text view
	fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
	AddChild(fExpressionTextView);

	// read data from archive
	_LoadSettings(archive);

	// Fetch the calc icon for compact view
	_FetchAppIcon(fCalcIcon);
}
Beispiel #15
0
BRect
App::_GetNextWindowFrame(bool singlePackageMode)
{
	BRect frame;
	const char* frameName;
	if (singlePackageMode) {
		frame = BRect(50.0, 50.0, 649.0, 349.0);
		frameName = "small window frame";
	}
	else {
		frame = BRect(50.0, 50.0, 749.0, 549.0);
		frameName = "window frame";
	}
	BMessage settings;
	if (_LoadSettings(settings)) {
		BRect windowFrame;
		if (settings.FindRect(frameName, &windowFrame) == B_OK)
			frame = windowFrame;
	}

	make_sure_frame_is_on_screen(frame);
	return frame;
}
Beispiel #16
0
NotificationWindow::NotificationWindow()
	:
	BWindow(BRect(0, 0, -1, -1), B_TRANSLATE_MARK("Notification"),
		B_BORDERED_WINDOW_LOOK, B_FLOATING_ALL_WINDOW_FEEL, B_AVOID_FRONT
		| B_AVOID_FOCUS | B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE
		| B_NOT_RESIZABLE | B_NOT_MOVABLE | B_AUTO_UPDATE_SIZE_LIMITS,
		B_ALL_WORKSPACES),
	fShouldRun(true)
{
	status_t result = find_directory(B_USER_CACHE_DIRECTORY, &fCachePath);
	fCachePath.Append("Notifications");
	BDirectory cacheDir;
	result = cacheDir.SetTo(fCachePath.Path());
	if (result == B_ENTRY_NOT_FOUND)
		cacheDir.CreateDirectory(fCachePath.Path(), NULL);

	SetLayout(new BGroupLayout(B_VERTICAL, 0));

	_LoadSettings(true);

	// Start the message loop
	Hide();
	Show();
}
Beispiel #17
0
CharacterWindow::CharacterWindow()
	: BWindow(BRect(100, 100, 700, 550), "CharacterMap", B_TITLED_WINDOW,
		B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE
			| B_AUTO_UPDATE_SIZE_LIMITS)
{
	BMessage settings;
	_LoadSettings(settings);

	BRect frame;
	if (settings.FindRect("window frame", &frame) == B_OK) {
		MoveTo(frame.LeftTop());
		ResizeTo(frame.Width(), frame.Height());
	}

	// create GUI

	SetLayout(new BGroupLayout(B_VERTICAL));

	BMenuBar* menuBar = new BMenuBar("menu");

	fFilterControl = new BTextControl("Filter:", NULL, NULL);
	fFilterControl->SetModificationMessage(new BMessage(kMsgFilterChanged));

	BButton* clearButton = new BButton("clear", "Clear",
		new BMessage(kMsgClearFilter));

	fUnicodeBlockView = new UnicodeBlockView("unicodeBlocks");
	fUnicodeBlockView->SetSelectionMessage(
		new BMessage(kMsgUnicodeBlockSelected));

	BScrollView* unicodeScroller = new BScrollView("unicodeScroller",
		fUnicodeBlockView, 0, false, true);

	fCharacterView = new CharacterView("characters");
	fCharacterView->SetTarget(this, kMsgCharacterChanged);

	// TODO: have a context object shared by CharacterView/UnicodeBlockView
	bool show;
	if (settings.FindBool("show private blocks", &show) == B_OK) {
		fCharacterView->ShowPrivateBlocks(show);
		fUnicodeBlockView->ShowPrivateBlocks(show);
	}
	if (settings.FindBool("show contained blocks only", &show) == B_OK) {
		fCharacterView->ShowContainedBlocksOnly(show);
		fUnicodeBlockView->ShowPrivateBlocks(show);
	}

	const char* family;
	const char* style;
	if (settings.FindString("font family", &family) == B_OK
		&& settings.FindString("font style", &style) == B_OK) {
		_SetFont(family, style);
	}

	int32 fontSize;
	if (settings.FindInt32("font size", &fontSize) == B_OK) {
		BFont font = fCharacterView->CharacterFont();
		if (fontSize < kMinFontSize)
			fontSize = kMinFontSize;
		else if (fontSize > kMaxFontSize)
			fontSize = kMaxFontSize;
		font.SetSize(fontSize);

		fCharacterView->SetCharacterFont(font);
	} else
		fontSize = (int32)fCharacterView->CharacterFont().Size();

	BScrollView* characterScroller = new BScrollView("characterScroller",
		fCharacterView, 0, false, true);

	fFontSizeSlider = new FontSizeSlider("fontSizeSlider", "Font size:",
		new BMessage(kMsgFontSizeChanged), kMinFontSize, kMaxFontSize);
	fFontSizeSlider->SetValue(fontSize);

	fCodeView = new BStringView("code", "-");
	fCodeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
		fCodeView->PreferredSize().Height()));

	AddChild(BGroupLayoutBuilder(B_VERTICAL)
		.Add(menuBar)
		.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)//BSplitLayoutBuilder()
			.Add(BGroupLayoutBuilder(B_VERTICAL, 10)
				.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
					.Add(fFilterControl)
					.Add(clearButton))
				.Add(unicodeScroller))
			.Add(BGroupLayoutBuilder(B_VERTICAL, 10)
				.Add(characterScroller)
				.Add(fFontSizeSlider)
				.Add(fCodeView))
			.SetInsets(10, 10, 10, 10)));

	// Add menu

	// "File" menu
	BMenu* menu = new BMenu("File");
	BMenuItem* item;

	menu->AddItem(item = new BMenuItem("About CharacterMap" B_UTF8_ELLIPSIS,
		new BMessage(B_ABOUT_REQUESTED)));

	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
	menu->SetTargetForItems(this);
	item->SetTarget(be_app);
	menuBar->AddItem(menu);

	menu = new BMenu("View");
	menu->AddItem(item = new BMenuItem("Show private blocks",
		new BMessage(kMsgPrivateBlocks)));
	item->SetMarked(fCharacterView->IsShowingPrivateBlocks());
// TODO: this feature is not yet supported by Haiku!
#if 0
	menu->AddItem(item = new BMenuItem("Only show blocks contained in font",
		new BMessage(kMsgContainedBlocks)));
	item->SetMarked(fCharacterView->IsShowingContainedBlocksOnly());
#endif
	menuBar->AddItem(menu);

	menuBar->AddItem(_CreateFontMenu());

	AddCommonFilter(new EscapeMessageFilter(kMsgClearFilter));
	AddCommonFilter(new RedirectUpAndDownFilter(fUnicodeBlockView));

	// TODO: why is this needed?
	fUnicodeBlockView->SetTarget(this);

	fFilterControl->MakeFocus();
}
Beispiel #18
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();
}
Beispiel #19
0
ShowImageWindow::ShowImageWindow(const entry_ref *ref,
	const BMessenger& trackerMessenger)
	:
	BWindow(BRect(5, 24, 250, 100), "", B_DOCUMENT_WINDOW, 0),
	fSavePanel(NULL),
	fBar(NULL),
	fOpenMenu(NULL),
	fBrowseMenu(NULL),
	fGoToPageMenu(NULL),
	fSlideShowDelay(NULL),
	fImageView(NULL),
	fStatusView(NULL),
	fModified(false),
	fFullScreen(false),
	fShowCaption(true),
	fPrintSettings(NULL),
	fResizerWindowMessenger(NULL),
	fResizeItem(NULL),
	fHeight(0),
	fWidth(0)
{
	_LoadSettings();

	// create menu bar
	fBar = new BMenuBar(BRect(0, 0, Bounds().right, 1), "menu_bar");
	AddMenus(fBar);
	AddChild(fBar);

	BRect viewFrame = Bounds();
	viewFrame.top = fBar->Bounds().Height() + 1;
	viewFrame.right -= B_V_SCROLL_BAR_WIDTH;
	viewFrame.bottom -= B_H_SCROLL_BAR_HEIGHT;

	// create the image view
	fImageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
		B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED);
	// wrap a scroll view around the view
	BScrollView *scrollView = new BScrollView("image_scroller", fImageView,
		B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);
	AddChild(scrollView);

	const int32 kstatusWidth = 190;
	BRect rect;
	rect = Bounds();
	rect.top	= viewFrame.bottom + 1;
	rect.left 	= viewFrame.left + kstatusWidth;
	rect.right	= viewFrame.right + 1;
	rect.bottom += 1;
	BScrollBar *horizontalScrollBar = new BScrollBar(rect, "hscroll",
		fImageView, 0, 150, B_HORIZONTAL);
	AddChild(horizontalScrollBar);

	rect.left = 0;
	rect.right = kstatusWidth - 1;
	rect.bottom -= 1;
	fStatusView = new ShowImageStatusView(rect, "status_view", B_FOLLOW_BOTTOM,
		B_WILL_DRAW);
	AddChild(fStatusView);

	rect = Bounds();
	rect.top	= viewFrame.top - 1;
	rect.left	= viewFrame.right + 1;
	rect.bottom	= viewFrame.bottom + 1;
	rect.right	+= 1;
	BScrollBar *verticalScrollBar = new BScrollBar(rect, "vscroll", fImageView,
		0, 150, B_VERTICAL);
	AddChild(verticalScrollBar);

	SetSizeLimits(250, 100000, 100, 100000);

	// finish creating the window
	fImageView->SetImage(ref);
	fImageView->SetTrackerMessenger(trackerMessenger);

	if (InitCheck() != B_OK) {
		BAlert* alert;
		alert = new BAlert("ShowImage",
			"Could not load image! Either the file or an image translator for "
			"it does not exist.", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_INFO_ALERT);
		alert->Go();

		// quit if file could not be opened
		Quit();
		return;
	}

	// add View menu here so it can access ShowImageView methods
	BMenu* menu = new BMenu("View");
	_BuildViewMenu(menu, false);
	fBar->AddItem(menu);
	_MarkMenuItem(fBar, MSG_DITHER_IMAGE, fImageView->GetDither());
	UpdateTitle();

	SetPulseRate(100000);
		// every 1/10 second; ShowImageView needs it for marching ants

	WindowRedimension(fImageView->GetBitmap());
	fImageView->MakeFocus(true); // to receive KeyDown messages
	Show();

	// Tell application object to query the clipboard
	// and tell this window if it contains interesting data or not
	be_app_messenger.SendMessage(B_CLIPBOARD_CHANGED);
}
   bool 
   BackupExecuter::StartBackup()
   {
      Logger::Instance()->LogBackup("Loading backup settings....");         

      _LoadSettings();

      // Special temp setting to skip files during backup/restore while still storing/restoring db file/message info.
      bool bMessagesDBOnly = IniFileSettings::Instance()->GetBackupMessagesDBOnly();


      if (m_iBackupMode & Backup::BOMessages)
      {
         if (!PersistentMessage::GetAllMessageFilesAreInDataFolder())
         {
            Application::Instance()->GetBackupManager()->OnBackupFailed("All messages are not located in the data folder.");
            return false;
         }

         // Skip size check if DB only
         if (!bMessagesDBOnly) {
         // Check size of data directory and LOG it.

         if (PersistentMessage::GetTotalMessageSize() > 1500)
         {
            Logger::Instance()->LogBackup("The size of the data directory exceeds the maximum RECOMMENDED size for the built in backup (1.5GB) so LOGGING. Please consult the backup documentation");

            // Check size of data directory and STOP it.
            if (PersistentMessage::GetTotalMessageSize() > 30000)
            {
               Application::Instance()->GetBackupManager()->OnBackupFailed("The size of the data directory exceeds the maximum size for the built in backup (30GB) so ABORTING. Please consult the backup documentation.");
               return false;
            }
         }
  }
      }

      if (!FileUtilities::Exists(m_sDestination))
      {
         Application::Instance()->GetBackupManager()->OnBackupFailed("The specified backup directory is not accessible: " + m_sDestination);
         return false;
      }


      String sTime = Time::GetCurrentDateTime();
      sTime.Replace(_T(":"), _T(""));

      // Generate name for zip file. We always create zip
      // file
      String sZipFile;
      sZipFile.Format(_T("%s\\HMBackup %s.7z"), m_sDestination, sTime);

      String sXMLFile;
      sXMLFile.Format(_T("%s\\hMailServerBackup.xml"), m_sDestination);

      // The name of the backup directory that
      // contains all the data files.
      String sDataBackupDir = m_sDestination + "\\DataBackup";

      // Backup all properties.
      XDoc oDoc; 

      XNode *pBackupNode = oDoc.AppendChild(_T("Backup"));
      XNode *pBackupInfoNode = pBackupNode->AppendChild(_T("BackupInformation"));

      // Store backup mode
      pBackupInfoNode->AppendAttr(_T("Mode"), StringParser::IntToString(m_iBackupMode));
      pBackupInfoNode->AppendAttr(_T("Version"), Application::Instance()->GetVersion());

      // Backup business objects
      if (m_iBackupMode & Backup::BODomains)
      {
         Logger::Instance()->LogBackup("Backing up domains...");

         if (!_BackupDomains(pBackupNode))
         {
            Application::Instance()->GetBackupManager()->OnBackupFailed("Could not backup domains.");
            return false;
         }
         
         // Backup message files
         if (m_iBackupMode & Backup::BOMessages && !bMessagesDBOnly)
         {
            Logger::Instance()->LogBackup("Backing up data directory...");
            if (!_BackupDataDirectory(sDataBackupDir))
            {
               Application::Instance()->GetBackupManager()->OnBackupFailed("Could not backup data directory.");
               return false;
            }


         }
      }

      // Save information in the XML file where messages can be found.
      if (m_iBackupMode & Backup::BOMessages)
      {
         XNode *pMessageFile = pBackupInfoNode->AppendChild(_T("DataFiles"));

         if (m_iBackupMode & Backup::BOCompression)
         {
            pMessageFile->AppendAttr(_T("Format"), _T("7z"));
            pMessageFile->AppendAttr(_T("Size"), StringParser::IntToString(FileUtilities::FileSize(sZipFile)));
         }
         else
         {
            pMessageFile->AppendAttr(_T("Format"), _T("Raw"));
            pMessageFile->AppendAttr(_T("FolderName"), _T("DataBackup"));
         }
      }

      if (m_iBackupMode & Backup::BOSettings)
      {
         Logger::Instance()->LogBackup("Backing up settings...");
         Configuration::Instance()->XMLStore(pBackupNode);
      }


      Logger::Instance()->LogBackup(_T("Writing XML file..."));
      String sXMLData = oDoc.GetXML();
      if (!FileUtilities::WriteToFile(sXMLFile, sXMLData, true))
      {
         Application::Instance()->GetBackupManager()->OnBackupFailed("Could not write to the XML file.");
         return false;
      }

      // Compress the XML file
      Compression oComp;
      oComp.AddFile(sZipFile, sXMLFile);

      // Delete the XML file
      FileUtilities::DeleteFile(sXMLFile);

      // Should we compress the message files?
      if (m_iBackupMode & Backup::BOMessages && 
          m_iBackupMode & Backup::BOCompression && !bMessagesDBOnly)
      {
         Logger::Instance()->LogBackup("Compressing message files...");
         
         if (m_iBackupMode & Backup::BOMessages)
            oComp.AddDirectory(sZipFile, sDataBackupDir + "\\");

         // Since the files are now compressed, we can deleted
         // the data backup directory
         if (!FileUtilities::DeleteDirectory(sDataBackupDir))
         {
            Application::Instance()->GetBackupManager()->OnBackupFailed("Could not delete files from the destination directory.");
            return false;
         }
       }

      Application::Instance()->GetBackupManager()->OnBackupCompleted();

      return true;
   }
Beispiel #21
0
void
NotificationWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case B_NODE_MONITOR:
		{
			_LoadSettings();
			break;
		}
		case kNotificationMessage:
		{
			if (!fShouldRun)
				break;

			BMessage reply(B_REPLY);
			BNotification* notification = new BNotification(message);

			if (notification->InitCheck() == B_OK) {
				bigtime_t timeout;
				if (message->FindInt64("timeout", &timeout) != B_OK)
					timeout = fTimeout;
				BString sourceSignature(notification->SourceSignature());
				BString sourceName(notification->SourceName());

				bool allow = false;
				appfilter_t::iterator it = fAppFilters
					.find(sourceSignature.String());

				AppUsage* appUsage = NULL;
				if (it == fAppFilters.end()) {
					if (sourceSignature.Length() > 0
						&& sourceName.Length() > 0) {
						appUsage = new AppUsage(sourceName.String(),
							sourceSignature.String(), true);
						fAppFilters[sourceSignature.String()] = appUsage;
						// TODO save back to settings file
					}
					allow = true;
				} else {
					appUsage = it->second;
					allow = appUsage->Allowed();
				}

				if (allow) {
					BString groupName(notification->Group());
					appview_t::iterator aIt = fAppViews.find(groupName);
					AppGroupView* group = NULL;
					if (aIt == fAppViews.end()) {
						group = new AppGroupView(this,
							groupName == "" ? NULL : groupName.String());
						fAppViews[groupName] = group;
						GetLayout()->AddView(group);
					} else
						group = aIt->second;

					NotificationView* view = new NotificationView(notification,
						timeout, fIconSize);

					group->AddInfo(view);

					_ShowHide();

					reply.AddInt32("error", B_OK);
				} else
					reply.AddInt32("error", B_NOT_ALLOWED);
			} else {
				reply.what = B_MESSAGE_NOT_UNDERSTOOD;
				reply.AddInt32("error", B_ERROR);
			}

			message->SendReply(&reply);
			break;
		}
		case kRemoveGroupView:
		{
			AppGroupView* view = NULL;
			if (message->FindPointer("view", (void**)&view) != B_OK)
				return;

			// It's possible that between sending this message, and us receiving
			// it, the view has become used again, in which case we shouldn't
			// delete it.
			if (view->HasChildren())
				return;

			// this shouldn't happen
			if (fAppViews.erase(view->Group()) < 1)
				break;

			view->RemoveSelf();
			delete view;

			_ShowHide();
			break;
		}
		default:
			BWindow::MessageReceived(message);
	}
}
void
NotificationWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case B_NODE_MONITOR:
		{
			_LoadSettings();
			_LoadAppFilters();
			break;
		}
		case B_COUNT_PROPERTIES:
		{
			BMessage reply(B_REPLY);
			BMessage specifier;
			const char* property = NULL;
			bool messageOkay = true;

			if (message->FindMessage("specifiers", 0, &specifier) != B_OK)
				messageOkay = false;
			if (specifier.FindString("property", &property) != B_OK)
				messageOkay = false;
			if (strcmp(property, "message") != 0)
				messageOkay = false;

			if (messageOkay)
				reply.AddInt32("result", fViews.size());
			else {
				reply.what = B_MESSAGE_NOT_UNDERSTOOD;
				reply.AddInt32("error", B_ERROR);
			}

			message->SendReply(&reply);
			break;
		}
		case B_CREATE_PROPERTY:
		case kNotificationMessage:
		{
			BMessage reply(B_REPLY);
			BNotification* notification = new BNotification(message);

			if (notification->InitCheck() == B_OK) {
				bigtime_t timeout;
				if (message->FindInt64("timeout", &timeout) != B_OK)
					timeout = -1;
				BMessenger messenger = message->ReturnAddress();
				app_info info;

				if (messenger.IsValid())
					be_roster->GetRunningAppInfo(messenger.Team(), &info);
				else
					be_roster->GetAppInfo("application/x-vnd.Be-SHEL", &info);

				NotificationView* view = new NotificationView(this,
					notification, timeout);

				bool allow = false;
				appfilter_t::iterator it = fAppFilters.find(info.signature);

				if (it == fAppFilters.end()) {
					AppUsage* appUsage = new AppUsage(notification->Group(),
						true);

					appUsage->Allowed(notification->Title(),
							notification->Type());
					fAppFilters[info.signature] = appUsage;
					allow = true;
				} else {
					allow = it->second->Allowed(notification->Title(),
						notification->Type());
				}

				if (allow) {
					BString groupName(notification->Group());
					appview_t::iterator aIt = fAppViews.find(groupName);
					AppGroupView* group = NULL;
					if (aIt == fAppViews.end()) {
						group = new AppGroupView(this,
							groupName == "" ? NULL : groupName.String());
						fAppViews[groupName] = group;
						GetLayout()->AddView(group);
					} else
						group = aIt->second;

					group->AddInfo(view);

					_ResizeAll();

					reply.AddInt32("error", B_OK);
				} else
					reply.AddInt32("error", B_NOT_ALLOWED);
			} else {
				reply.what = B_MESSAGE_NOT_UNDERSTOOD;
				reply.AddInt32("error", B_ERROR);
			}

			message->SendReply(&reply);
			break;
		}
		case kRemoveView:
		{
			NotificationView* view = NULL;
			if (message->FindPointer("view", (void**)&view) != B_OK)
				return;

			views_t::iterator it = find(fViews.begin(), fViews.end(), view);

			if (it != fViews.end())
				fViews.erase(it);

			_ResizeAll();
			break;
		}
		default:
			BWindow::MessageReceived(message);
	}
}
Beispiel #23
0
CharacterWindow::CharacterWindow()
	:
	BWindow(BRect(100, 100, 700, 550), B_TRANSLATE_SYSTEM_NAME("CharacterMap"),
		B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE
			| B_AUTO_UPDATE_SIZE_LIMITS)
{
	BMessage settings;
	_LoadSettings(settings);

	BRect frame;
	if (settings.FindRect("window frame", &frame) == B_OK) {
		MoveTo(frame.LeftTop());
		ResizeTo(frame.Width(), frame.Height());
	} else {
		float scaling = be_plain_font->Size() / 12.0f;
		ResizeTo(Frame().Width() * scaling, Frame().Height() * scaling);
		CenterOnScreen();
	}

	// create GUI
	BMenuBar* menuBar = new BMenuBar("menu");

	fFilterControl = new BTextControl(B_TRANSLATE("Filter:"), NULL, NULL);
	fFilterControl->SetModificationMessage(new BMessage(kMsgFilterChanged));

	BButton* clearButton = new BButton("clear", B_TRANSLATE("Clear"),
		new BMessage(kMsgClearFilter));

	fUnicodeBlockView = new UnicodeBlockView("unicodeBlocks");
	fUnicodeBlockView->SetSelectionMessage(
		new BMessage(kMsgUnicodeBlockSelected));

	BScrollView* unicodeScroller = new BScrollView("unicodeScroller",
		fUnicodeBlockView, 0, false, true);

	fCharacterView = new CharacterView("characters");
	fCharacterView->SetTarget(this, kMsgCharacterChanged);

	fGlyphView = new BStringView("glyph", "");
	fGlyphView->SetExplicitMaxSize(BSize(B_SIZE_UNSET,
		fGlyphView->PreferredSize().Height()));

	// TODO: have a context object shared by CharacterView/UnicodeBlockView
	bool show;
	if (settings.FindBool("show private blocks", &show) == B_OK) {
		fCharacterView->ShowPrivateBlocks(show);
		fUnicodeBlockView->ShowPrivateBlocks(show);
	}
	if (settings.FindBool("show contained blocks only", &show) == B_OK) {
		fCharacterView->ShowContainedBlocksOnly(show);
		fUnicodeBlockView->ShowPrivateBlocks(show);
	}

	const char* family;
	const char* style;
	BString displayName;

	if (settings.FindString("font family", &family) == B_OK
		&& settings.FindString("font style", &style) == B_OK) {
		_SetFont(family, style);
		displayName << family << " " << style;
	} else {
		font_family currentFontFamily;
		font_style currentFontStyle;
		fCharacterView->CharacterFont().GetFamilyAndStyle(&currentFontFamily,
			&currentFontStyle);
		displayName << currentFontFamily << " " << currentFontStyle;
	}

	int32 fontSize;
	if (settings.FindInt32("font size", &fontSize) == B_OK) {
		BFont font = fCharacterView->CharacterFont();
		if (fontSize < kMinFontSize)
			fontSize = kMinFontSize;
		else if (fontSize > kMaxFontSize)
			fontSize = kMaxFontSize;
		font.SetSize(fontSize);

		fCharacterView->SetCharacterFont(font);
	} else
		fontSize = (int32)fCharacterView->CharacterFont().Size();

	BScrollView* characterScroller = new BScrollView("characterScroller",
		fCharacterView, 0, false, true);

	fFontSizeSlider = new FontSizeSlider("fontSizeSlider",
		displayName,
		new BMessage(kMsgFontSizeChanged), kMinFontSize, kMaxFontSize);
	fFontSizeSlider->SetValue(fontSize);

	fCodeView = new BStringView("code", "-");
	fCodeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
		fCodeView->PreferredSize().Height()));

	// Set minimum width for character pane to prevent UI
	// from jumping when longer code strings are displayed.
	// use 'w' character for sizing as it's likely the widest
	// character for a Latin font.  40 characters is a little
	// wider than needed so hopefully this covers other
	// non-Latin fonts that may be wider.
	BFont viewFont;
	fCodeView->GetFont(&viewFont);
	fCharacterView->SetExplicitMinSize(BSize(viewFont.StringWidth("w") * 40,
		B_SIZE_UNSET));

	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
		.Add(menuBar)
		.AddGroup(B_HORIZONTAL)
			.SetInsets(B_USE_WINDOW_SPACING)
			.AddGroup(B_VERTICAL)
				.AddGroup(B_HORIZONTAL)
					.Add(fFilterControl)
					.Add(clearButton)
				.End()
				.Add(unicodeScroller)
			.End()
			.AddGroup(B_VERTICAL)
				.Add(characterScroller)
				.Add(fFontSizeSlider)
				.AddGroup(B_HORIZONTAL)
					.Add(fGlyphView)
					.Add(fCodeView);

	// Add menu

	// "File" menu
	BMenu* menu = new BMenu(B_TRANSLATE("File"));
	BMenuItem* item;

	menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
		new BMessage(B_QUIT_REQUESTED), 'Q'));
	menu->SetTargetForItems(this);
	menuBar->AddItem(menu);

	menu = new BMenu(B_TRANSLATE("View"));
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Show private blocks"),
		new BMessage(kMsgPrivateBlocks)));
	item->SetMarked(fCharacterView->IsShowingPrivateBlocks());
// TODO: this feature is not yet supported by Haiku!
#if 0
	menu->AddItem(item = new BMenuItem("Only show blocks contained in font",
		new BMessage(kMsgContainedBlocks)));
	item->SetMarked(fCharacterView->IsShowingContainedBlocksOnly());
#endif
	menuBar->AddItem(menu);

	fFontMenu = _CreateFontMenu();
	menuBar->AddItem(fFontMenu);

	AddCommonFilter(new EscapeMessageFilter(kMsgClearFilter));
	AddCommonFilter(new RedirectUpAndDownFilter(fUnicodeBlockView));

	// TODO: why is this needed?
	fUnicodeBlockView->SetTarget(this);

	fFilterControl->MakeFocus();

	fUnicodeBlockView->SelectBlockForCharacter(0);
}
Beispiel #24
0
void
TeamDebugger::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case MSG_THREAD_RUN:
		case MSG_THREAD_STOP:
		case MSG_THREAD_STEP_OVER:
		case MSG_THREAD_STEP_INTO:
		case MSG_THREAD_STEP_OUT:
		{
			int32 threadID;
			if (message->FindInt32("thread", &threadID) != B_OK)
				break;

			if (ThreadHandler* handler = _GetThreadHandler(threadID)) {
				handler->HandleThreadAction(message->what);
				handler->ReleaseReference();
			}
			break;
		}

		case MSG_SET_BREAKPOINT:
		case MSG_CLEAR_BREAKPOINT:
		{
			UserBreakpoint* breakpoint = NULL;
			BReference<UserBreakpoint> breakpointReference;
			uint64 address = 0;

			if (message->FindPointer("breakpoint", (void**)&breakpoint) == B_OK)
				breakpointReference.SetTo(breakpoint, true);
			else if (message->FindUInt64("address", &address) != B_OK)
				break;

			if (message->what == MSG_SET_BREAKPOINT) {
				bool enabled;
				if (message->FindBool("enabled", &enabled) != B_OK)
					enabled = true;

				if (breakpoint != NULL)
					_HandleSetUserBreakpoint(breakpoint, enabled);
				else
					_HandleSetUserBreakpoint(address, enabled);
			} else {
				if (breakpoint != NULL)
					_HandleClearUserBreakpoint(breakpoint);
				else
					_HandleClearUserBreakpoint(address);
			}

			break;
		}

		case MSG_INSPECT_ADDRESS:
		{
			TeamMemoryBlock::Listener* listener;
			if (message->FindPointer("listener",
				reinterpret_cast<void **>(&listener)) != B_OK) {
				break;
			}

			target_addr_t address;
			if (message->FindUInt64("address",
				&address) == B_OK) {
				_HandleInspectAddress(address, listener);
			}
			break;
		}

		case MSG_THREAD_STATE_CHANGED:
		{
			int32 threadID;
			if (message->FindInt32("thread", &threadID) != B_OK)
				break;

			if (ThreadHandler* handler = _GetThreadHandler(threadID)) {
				handler->HandleThreadStateChanged();
				handler->ReleaseReference();
			}
			break;
		}
		case MSG_THREAD_CPU_STATE_CHANGED:
		{
			int32 threadID;
			if (message->FindInt32("thread", &threadID) != B_OK)
				break;

			if (ThreadHandler* handler = _GetThreadHandler(threadID)) {
				handler->HandleCpuStateChanged();
				handler->ReleaseReference();
			}
			break;
		}
		case MSG_THREAD_STACK_TRACE_CHANGED:
		{
			int32 threadID;
			if (message->FindInt32("thread", &threadID) != B_OK)
				break;

			if (ThreadHandler* handler = _GetThreadHandler(threadID)) {
				handler->HandleStackTraceChanged();
				handler->ReleaseReference();
			}
			break;
		}

		case MSG_IMAGE_DEBUG_INFO_CHANGED:
		{
			int32 imageID;
			if (message->FindInt32("image", &imageID) != B_OK)
				break;

			_HandleImageDebugInfoChanged(imageID);
			break;
		}

		case MSG_IMAGE_FILE_CHANGED:
		{
			int32 imageID;
			if (message->FindInt32("image", &imageID) != B_OK)
				break;

			_HandleImageFileChanged(imageID);
			break;
		}

		case MSG_DEBUGGER_EVENT:
		{
			DebugEvent* event;
			if (message->FindPointer("event", (void**)&event) != B_OK)
				break;

			_HandleDebuggerMessage(event);
			delete event;
			break;
		}

		case MSG_LOAD_SETTINGS:
			_LoadSettings();
			Activate();
			break;

		default:
			BLooper::MessageReceived(message);
			break;
	}
}
Beispiel #25
0
int KG_Jx3DBChecker::Init()
{
    int nResult = false;
    int nRetCode = false;
    
    KG_TASK_INFO task_info;

    m_nTaskCount = 0;

    nRetCode = _LoadSettings();
    KGLOG_PROCESS_ERROR(nRetCode);

    nRetCode = m_dbCheckRule.InitDBCheckRule();
    KGLOG_PROCESS_ERROR(nRetCode);

    REGISTER_TASK(task_info, "sequence", m_dbCheckRule); // 必须的
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "antifarmer", m_dbCheckRule); 
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "auction", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "fellowship", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "gamecard", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "globalcustomdata", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "globalsystemvalue", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "globalmailex", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "mailbox", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "mapcopy", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "pq", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "role", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "restorerole", m_dbCheckRule); // 处理exInfo???
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "roleblacklist", m_dbCheckRule); 
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "roledeletelist", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "statdatanameindex", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "statdata", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "tong", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    REGISTER_TASK(task_info, "renamerole", m_dbCheckRule);
    m_Tasks.push_back(task_info);
    m_nTaskCount++;

    m_bRunFlag = true;

    nResult = true;
Exit0:
    return nResult;
}
void
DownloadWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case INIT:
		{
			_LoadSettings();
			// Small trick to get the correct enabled status of the Remove
			// finished button
			_DownloadFinished(NULL);
			break;
		}
		case B_DOWNLOAD_ADDED:
		{
			BWebDownload* download;
			if (message->FindPointer("download", reinterpret_cast<void**>(
					&download)) == B_OK) {
				_DownloadStarted(download);
			}
			break;
		}
		case B_DOWNLOAD_REMOVED:
		{
			BWebDownload* download;
			if (message->FindPointer("download", reinterpret_cast<void**>(
					&download)) == B_OK) {
				_DownloadFinished(download);
			}
			break;
		}
		case OPEN_DOWNLOADS_FOLDER:
		{
			entry_ref ref;
			status_t status = get_ref_for_path(fDownloadPath.String(), &ref);
			if (status == B_OK)
				status = be_roster->Launch(&ref);
			if (status != B_OK && status != B_ALREADY_RUNNING) {
				BString errorString(B_TRANSLATE_COMMENT("The downloads folder could "
					"not be opened.\n\nError: %error", "Don't translate "
					"variable %error"));
				errorString.ReplaceFirst("%error", strerror(status));
				BAlert* alert = new BAlert(B_TRANSLATE("Error opening downloads "
					"folder"), errorString.String(), B_TRANSLATE("OK"));
				alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
				alert->Go(NULL);
			}
			break;
		}
		case REMOVE_FINISHED_DOWNLOADS:
			_RemoveFinishedDownloads();
			break;
		case REMOVE_MISSING_DOWNLOADS:
			_RemoveMissingDownloads();
			break;
		case SAVE_SETTINGS:
			_ValidateButtonStatus();
			_SaveSettings();
			break;

		case SETTINGS_VALUE_CHANGED:
		{
			BString string;
			if (message->FindString("name", &string) == B_OK
				&& string == kSettingsKeyDownloadPath
				&& message->FindString("value", &string) == B_OK) {
				fDownloadPath = string;
			}
			break;
		}
		default:
			BWindow::MessageReceived(message);
			break;
	}
}
Beispiel #27
0
void
TeamsWindow::_Init()
{
	BMessage settings;
	_LoadSettings(settings);

	BRect frame;
	if (settings.FindRect("teams window frame", &frame) == B_OK) {
		MoveTo(frame.LeftTop());
		ResizeTo(frame.Width(), frame.Height());
	}

	BMenu* connectionMenu = new BMenu("Connection");
	ObjectDeleter<BMenu> menuDeleter(connectionMenu);
	connectionMenu->SetLabelFromMarked(true);

	TargetHostInterfaceRoster* roster = TargetHostInterfaceRoster::Default();
	for (int32 i = 0; i < roster->CountActiveInterfaces(); i++) {
		TargetHostInterface* interface = roster->ActiveInterfaceAt(i);
		BMenuItem* item = new BMenuItem(interface->GetTargetHost()->Name(),
			new BMessage(MSG_SWITCH_TARGET_CONNECTION));
		if (item->Message()->AddPointer("interface", interface) != B_OK) {
			delete item;
			throw std::bad_alloc();
		}

		if (interface->IsLocal()) {
			item->SetMarked(true);
			fTargetHostInterface = interface;
		}

		connectionMenu->AddItem(item);
	}

	BGroupLayout* connectionLayout = NULL;

	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.AddGroup(B_HORIZONTAL)
			.SetInsets(B_USE_DEFAULT_SPACING)
			.GetLayout(&connectionLayout)
			.Add(fConnectionField = new BMenuField("Connected to:",
				connectionMenu))
			.AddGlue()
			.Add(fCreateConnectionButton = new BButton("Create new connection"
					B_UTF8_ELLIPSIS, new BMessage(
						MSG_SHOW_CONNECTION_CONFIG_WINDOW)))
		.End()
		.Add(fTeamsListView = new TeamsListView("TeamsList"))
		.SetInsets(1.0f, 1.0f, 1.0f, 5.0f)
		.AddGroup(B_HORIZONTAL)
			.SetInsets(B_USE_DEFAULT_SPACING)
			.Add(fAttachTeamButton = new BButton("Attach", new BMessage(
					MSG_DEBUG_THIS_TEAM)))
			.AddGlue()
			.Add(fCreateTeamButton = new BButton("Start new team"
					B_UTF8_ELLIPSIS, new BMessage(MSG_SHOW_START_TEAM_WINDOW)))
			.Add(fLoadCoreButton = new BButton("Load core" B_UTF8_ELLIPSIS,
					new BMessage(MSG_LOAD_CORE_TEAM)))
			.End()
		.End();

	connectionLayout->SetVisible(false);

	menuDeleter.Detach();

	AddListener(fTeamsListView);

	connectionMenu->SetTargetForItems(this);

	fTeamsListView->SetInvocationMessage(new BMessage(MSG_DEBUG_THIS_TEAM));
	fTeamsListView->SetSelectionMessage(new BMessage(
			MSG_TEAM_SELECTION_CHANGED));

	fAttachTeamButton->SetEnabled(false);
	fCreateTeamButton->SetTarget(this);
	fLoadCoreButton->SetTarget(this);
	fCreateConnectionButton->SetTarget(be_app);

	_NotifySelectedInterfaceChanged(fTargetHostInterface);
}
ActivityWindow::ActivityWindow()
	:
	BWindow(BRect(100, 100, 500, 350), B_TRANSLATE_SYSTEM_NAME("ActivityMonitor"),
	B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
{
	BMessage settings;
	_LoadSettings(settings);

	BRect frame;
	if (settings.FindRect("window frame", &frame) == B_OK) {
		MoveTo(frame.LeftTop());
		ResizeTo(frame.Width(), frame.Height());
	}

#ifdef __HAIKU__
	BGroupLayout* layout = new BGroupLayout(B_VERTICAL, 0);
	SetLayout(layout);

	// create GUI

	BMenuBar* menuBar = new BMenuBar("menu");
	layout->AddView(menuBar);

	fLayout = new BGroupLayout(B_VERTICAL);
	float inset = ceilf(be_plain_font->Size() * 0.7);
	fLayout->SetInsets(inset, inset, inset, inset);
	fLayout->SetSpacing(inset);

	BView* top = new BView("top", 0, fLayout);
	top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	layout->AddView(top);

	BMessage viewState;
	int32 count = 0;
	for (int32 i = 0; settings.FindMessage("activity view", i, &viewState)
			== B_OK; i++) {
		ActivityView* view = new ActivityView("ActivityMonitor", &viewState);
		fLayout->AddItem(view->CreateHistoryLayoutItem());
		fLayout->AddItem(view->CreateLegendLayoutItem());
		count++;
	}
	if (count == 0) {
		// Add default views (memory & CPU usage)
		_AddDefaultView();
		_AddDefaultView();
	}
#else	// !__HAIKU__
	BView *layout = new BView(Bounds(), "topmost", B_FOLLOW_NONE, 0);
	AddChild(layout);

	// create GUI
	BRect mbRect(Bounds());
	mbRect.bottom = 10;
	BMenuBar* menuBar = new BMenuBar(mbRect, "menu");
	layout->AddChild(menuBar);

	BRect topRect(Bounds());
	topRect.top = menuBar->Bounds().bottom + 1;

	BView* top = new BView(topRect, "top", B_FOLLOW_ALL, 0);
	top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	layout->AddChild(top);

	BMessage viewState;
	int32 count = 0;
	ActivityView *aview;
	BRect rect;
	for (int32 i = 0; settings.FindMessage("activity view", i, &viewState)
			== B_OK; i++) {
		aview = new ActivityView("ActivityMonitor", &viewState);
		if (!rect.IsValid())
			rect = aview->Bounds();
		else
			rect.OffsetBySelf(0.0, aview->Bounds().Height());
		top->AddChild(aview);
		count++;
	}
	if (count == 0)
		top->AddChild(new ActivityView("ActivityMonitor", NULL));

#endif
	// add menu

	// "File" menu
	BMenu* menu = new BMenu(B_TRANSLATE("File"));
	menu->AddItem(new BMenuItem(B_TRANSLATE("Add graph"),
		new BMessage(kMsgAddView)));
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
		new BMessage(B_QUIT_REQUESTED), 'Q'));
	menu->SetTargetForItems(this);
	menuBar->AddItem(menu);

	// "Settings" menu
	menu = new BMenu(B_TRANSLATE("Settings"));
	menu->AddItem(new BMenuItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS),
		new BMessage(kMsgShowSettings)));
	menu->SetTargetForItems(this);
	menuBar->AddItem(menu);
}
Beispiel #29
0
SudokuWindow::SudokuWindow()
	:
	BWindow(BRect(100, 100, 500, 520), B_TRANSLATE_SYSTEM_NAME("Sudoku"),
		B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE),
	fGenerator(NULL),
	fStoredState(NULL),
	fExportFormat(kExportAsText)
{
	BMessage settings;
	_LoadSettings(settings);

	BRect frame;
	if (settings.FindRect("window frame", &frame) == B_OK) {
		MoveTo(frame.LeftTop());
		ResizeTo(frame.Width(), frame.Height());
		frame.OffsetTo(B_ORIGIN);
	} else
		frame = Bounds();

	if (settings.HasMessage("stored state")) {
		fStoredState = new BMessage;
		if (settings.FindMessage("stored state", fStoredState) != B_OK) {
			delete fStoredState;
			fStoredState = NULL;
		}
	}

	int32 level = 0;
	settings.FindInt32("level", &level);

	// create GUI

	BMenuBar* menuBar = new BMenuBar(Bounds(), "menu");
	AddChild(menuBar);

	frame.top = menuBar->Frame().bottom;

	BView* top = new BView(frame, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
	top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(top);

	fSudokuView = new SudokuView(
		top->Bounds().InsetByCopy(10, 10).OffsetToSelf(0, 0),
		"sudoku view", settings, B_FOLLOW_NONE);
	CenteredViewContainer* container = new CenteredViewContainer(fSudokuView,
		top->Bounds().InsetByCopy(10, 10),
		"center", B_FOLLOW_ALL);
	container->SetHighColor(top->ViewColor());
	top->AddChild(container);

	// add menu

	// "File" menu
	BMenu* menu = new BMenu(B_TRANSLATE("File"));
	fNewMenu = new BMenu(B_TRANSLATE("New"));
	menu->AddItem(new BMenuItem(fNewMenu, new BMessage(kMsgGenerateSudoku)));
	fNewMenu->Superitem()->SetShortcut('N', B_COMMAND_KEY);

	BMessage* message = new BMessage(kMsgGenerateSudoku);
	message->AddInt32("level", kEasyLevel);
	fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Easy"), message));
	message = new BMessage(kMsgGenerateSudoku);
	message->AddInt32("level", kAdvancedLevel);
	fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Advanced"), message));
	message = new BMessage(kMsgGenerateSudoku);
	message->AddInt32("level", kHardLevel);
	fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Hard"), message));

	fNewMenu->AddSeparatorItem();
	fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Blank"),
		new BMessage(kMsgNewBlank)));

	menu->AddItem(new BMenuItem(B_TRANSLATE("Start again"),
		new BMessage(kMsgStartAgain)));
	menu->AddSeparatorItem();
	BMenu* recentsMenu = BRecentFilesList::NewFileListMenu(
		B_TRANSLATE("Open file" B_UTF8_ELLIPSIS), NULL, NULL, this, 10, false,
		NULL, kSignature);
	BMenuItem *item;
	menu->AddItem(item = new BMenuItem(recentsMenu,
		new BMessage(kMsgOpenFilePanel)));
	item->SetShortcut('O', B_COMMAND_KEY);

	menu->AddSeparatorItem();

	BMenu* subMenu = new BMenu(B_TRANSLATE("Export as" B_UTF8_ELLIPSIS));
	message = new BMessage(kMsgExportAs);
	message->AddInt32("as", kExportAsText);
	subMenu->AddItem(new BMenuItem(B_TRANSLATE("Text"), message));
	message= new BMessage(kMsgExportAs);
	message->AddInt32("as", kExportAsHTML);
	subMenu->AddItem(new BMenuItem(B_TRANSLATE("HTML"), message));
	menu->AddItem(subMenu);

	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Copy"),
		new BMessage(B_COPY), 'C'));

	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
		new BMessage(B_QUIT_REQUESTED), 'Q'));
	menu->SetTargetForItems(this);
	item->SetTarget(be_app);
	menuBar->AddItem(menu);

	// "View" menu
	menu = new BMenu(B_TRANSLATE("View"));
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Mark invalid values"),
		new BMessage(kMsgMarkInvalid)));
	if ((fSudokuView->HintFlags() & kMarkInvalid) != 0)
		item->SetMarked(true);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Mark valid hints"),
		new BMessage(kMsgMarkValidHints)));
	if ((fSudokuView->HintFlags() & kMarkValidHints) != 0)
		item->SetMarked(true);
	menu->SetTargetForItems(this);
	menuBar->AddItem(menu);

	// "Help" menu
	menu = new BMenu(B_TRANSLATE("Help"));
	menu->AddItem(fUndoItem = new BMenuItem(B_TRANSLATE("Undo"),
		new BMessage(B_UNDO), 'Z'));
	fUndoItem->SetEnabled(false);
	menu->AddItem(fRedoItem = new BMenuItem(B_TRANSLATE("Redo"),
		new BMessage(B_REDO), 'Z', B_SHIFT_KEY));
	fRedoItem->SetEnabled(false);
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Snapshot current"),
		new BMessage(kMsgStoreState)));
	menu->AddItem(fRestoreStateItem = new BMenuItem(
		B_TRANSLATE("Restore snapshot"), new BMessage(kMsgRestoreState)));
	fRestoreStateItem->SetEnabled(fStoredState != NULL);
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Set all hints"),
		new BMessage(kMsgSetAllHints)));
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Solve"),
		new BMessage(kMsgSolveSudoku)));
	menu->AddItem(new BMenuItem(B_TRANSLATE("Solve single field"),
		new BMessage(kMsgSolveSingle)));
	menu->SetTargetForItems(fSudokuView);
	menuBar->AddItem(menu);

	fOpenPanel = new BFilePanel(B_OPEN_PANEL);
	fOpenPanel->SetTarget(this);
	fSavePanel = new BFilePanel(B_SAVE_PANEL);
	fSavePanel->SetTarget(this);

	_SetLevel(level);

	fSudokuView->StartWatching(this, kUndoRedoChanged);
		// we like to know whenever the undo/redo state changes

	fProgressWindow = new ProgressWindow(this,
		new BMessage(kMsgAbortSudokuGenerator));

	if (fSudokuView->Field()->IsEmpty())
		PostMessage(kMsgGenerateSudoku);
}
Beispiel #30
0
BoardWindow::BoardWindow(void)
	:
    BWindow(BRect(), "Puri - Master of Chess",
            /*B_DOCUMENT_WINDOW*/ B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS
                | B_QUIT_ON_WINDOW_CLOSE
                | B_AUTO_UPDATE_SIZE_LIMITS | B_OUTLINE_RESIZE),
    fEngineCanWrite(false),
    fIndex(0)
{
    fICSMainWindow = NULL;

    fSkillSlider = new BSlider("slider", "", new BMessage(MSG_SKILLCHANGED),
                                                           0, 20, B_HORIZONTAL);
    fSkillSlider->SetValue(20);
    fSkillSlider->SetToolTip("Engine Skill: 20");
    fSkillSlider->Value();
    fSkillSlider->SetEnabled(true);

	fTabView    = new BTabView("tab_view");
    fTabView->SetTabWidth(B_WIDTH_FROM_LABEL);
	fMovesView  = new MovesView();

	fTabsVec.push_back(new BTab());
	fTabView->AddTab(fMovesView, fTabsVec.back());
	fTabsVec.back()->SetLabel("Moves");

	//fTabsVec.push_back( new BTab() );
	//fTabView->AddTab( new MovesView(), fTabsVec.back() );
	//fTabsVec.back()->SetLabel( "Moves2" );

	// Build the layout

	fChessBoard     = new ChessBoardView(BRect(0, 0, 0, 0));
	fSidebarView    = new SidebarView();
	fTimeView       = new TimeView(REPLYCODE_TIMEVIEW);
    fNavigationView = new NavigationView();
    fMaterialView   = new MaterialView();
    fEngineOutput   = new EngineOutputView(fChessBoard->Board());

	fCard = new BCardLayout();

	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
        .Add(fMenuBar = _CreateMenuBar())
		.AddSplit(B_HORIZONTAL).GetSplitView(&fSplitView)
			.AddGroup(B_VERTICAL, 0, 3.5)
				.AddGroup(B_HORIZONTAL, 0, 4)
					.AddGroup(B_VERTICAL, 0, 1).GetLayout(&fLeftColumn)
						.Add(fSidebarView)
					.End()
                    .AddGlue(0)
					.AddGroup(B_VERTICAL, 0, 12).GetLayout(&fMiddleColumn)
						.Add(fChessBoard, 12)
						.Add(fNavigationView)
					.End()
				.End()
			.End()
			.AddGroup(B_VERTICAL, 3, 1).GetLayout(&fRightColumn)
				//	.AddGlue()
                    .AddStrut(3)
					.Add(fTimeView)
                    .AddSplit(B_VERTICAL).GetSplitView(&fMaterialSV)
                        .AddGroup(B_VERTICAL, 0, 20)
                            .Add(fTabView, 20)
                        .End()
                        .AddGroup(B_VERTICAL, 0, 3)
                            .AddStrut(1)
                            .Add(fMaterialView, 3)
                        .End()
                        .AddGroup(B_VERTICAL, 0, 3)
                            .Add(fSkillSlider)
                            .Add(fEngineOutput)
                        .End()
                    .End()
				//	.AddGlue()
			.End()
		.End()

		//.AddGrid()
		//	.Add( new BButton( "left4" , NULL ),0,0 )
			//.Add( new BButton( "left5" , NULL ),2,2 )
	;
/*
	fCard->AddView( new BButton( "test1", "test1",NULL) );
	fCard->AddView( new BButton( "test2", "test2",NULL) );
	fCard->AddView( new BButton( "test3", "test3",NULL) );
	fCard->SetVisibleItem( 0L );
	fCard->SetVisible(true);
*/
	//fMiddleColumn->AlignLayoutWith( fRightColumn, B_VERTICAL);
	fSplitView->SetSplitterSize(9);
    fSplitView->SetSpacing(0);
    fMaterialSV->SetSplitterSize(9);
    fMaterialSV->SetSpacing(0);
	fChessBoard->MakeFocus();

	fEngine = new Engine("stockfish", REPLYCODE_ENGINE,
                            this, this, B_LOWEST_ACTIVE_PRIORITY);
    fEngine->PostMessage(MSG_ENG_START);
    _LoadSettings();
    Show();
    Hide();
	PostMessage(MENU_GAME_NEWGAME);
}