Esempio n. 1
0
//-------------------------------------------------------------------------------------------------
void ImportSettingsFile( const QString& title, const QString& pathName, QWidget* pParent )
{
    QFileInfo fileInfo( pathName );

    tMessageBox::tStandardButton reply = tMessageBox::Warning( pParent,
        title, 
        QApplication::tr("Replace all existing settings with those from '%1' ? \n(unit will restart)").arg( fileInfo.fileName() ),
        tMessageBox::YES | tMessageBox::NO,
        tMessageBox::NO );

    if (reply == tMessageBox::YES)
    {
        tBusyIndicator* pBusyIndicator = tBusyIndicator::NewBusyIndicator( pParent );
        pBusyIndicator->setFocusPolicy( Qt::NoFocus );
        pBusyIndicator->show();
        QApplication::processEvents();

        bool ok = ImportFile( pathName );
        QApplication::processEvents();

        delete pBusyIndicator;

        if (ok == false)
        {
            tMessageBox::Error( pParent, title, QApplication::tr("Import Failed") );
        }
        RestartApplication();
    }
}
Esempio n. 2
0
void C4StartupMainDlg::OnEditorBtn(C4GUI::Control *btn)
{
	if (!RestartApplication({"--editor"}))
	{
		C4GUI::TheScreen.ShowErrorMessage(LoadResStr("IDS_ERR_STARTEDITOR"));
	}
}
Esempio n. 3
0
bool C4StartupNetDlg::DoOK()
{
	// OK in chat mode? Forward to chat control
	if (GetDlgMode() == SNDM_Chat) return pChatCtrl->DlgEnter();
	// OK on editbox with text enetered: Add the specified IP for reference retrieval
	if (GetFocus() == pJoinAddressEdt)
	{
		const char *szDirectJoinAddress = pJoinAddressEdt->GetText();
		if (szDirectJoinAddress && *szDirectJoinAddress)
		{
			// First do some acrobatics to avoid trying to resolve addresses with leading
			// or trailing whitespace, which is easily pasted in with an IP address.
			// We can trivially skip whitespace at the beginning, but we need a copy to
			// omit whitespace at the end.
			while (std::isspace(*szDirectJoinAddress))
				// skip whitespace at the beginning
				++szDirectJoinAddress;
			if (!*szDirectJoinAddress)
				// entry empty, apart from whitespace
				return true;
			const char *szDirectJoinAddressEnd = szDirectJoinAddress + std::strlen(szDirectJoinAddress) - 1;
			while (std::isspace(*szDirectJoinAddressEnd))
				// skip whitespace at the end
				--szDirectJoinAddressEnd;
			if (*++szDirectJoinAddressEnd)
			{
				// Make a temporary copy of the part that is not trailing whitespace, if any
				std::string strDirectJoinAddressStripped(szDirectJoinAddress, szDirectJoinAddressEnd - szDirectJoinAddress);
				AddReferenceQuery(strDirectJoinAddressStripped.c_str(), C4StartupNetListEntry::NRQT_DirectJoin);
			}
			else
				AddReferenceQuery(szDirectJoinAddress, C4StartupNetListEntry::NRQT_DirectJoin);
			// Switch focus to list so another OK joins the specified address
			SetFocus(pGameSelList, true);
			return true;
		}
	}
	if (GetFocus() == pSearchFieldEdt)
	{
		UpdateList();
		return true;
	}
	// get currently selected item
	C4GUI::Element *pSelection = pGameSelList->GetSelectedItem();
	StdCopyStrBuf strNoJoin(LoadResStr("IDS_NET_NOJOIN"));
	if (!pSelection)
	{
		// no ref selected: Oh noes!
		::pGUI->ShowMessageModal(
		  LoadResStr("IDS_NET_NOJOIN_NOREF"),
		  strNoJoin.getData(),
		  C4GUI::MessageDialog::btnOK,
		  C4GUI::Ico_Error);
		return true;
	}
	C4StartupNetListEntry *pRefEntry = static_cast<C4StartupNetListEntry *>(pSelection);
	const char *szError;
	if ((szError = pRefEntry->GetError()))
	{
		// erroneous ref selected: Oh noes!
		::pGUI->ShowMessageModal(
		  FormatString(LoadResStr("IDS_NET_NOJOIN_BADREF"), szError).getData(),
		  strNoJoin.getData(),
		  C4GUI::MessageDialog::btnOK,
		  C4GUI::Ico_Error);
		return true;
	}
	C4Network2Reference *pRef = pRefEntry->GetReference();
	const char *szDirectJoinAddress = pRefEntry->GetJoinAddress();
	if (!pRef && !(szDirectJoinAddress && *szDirectJoinAddress))
	{
		// something strange has been selected (e.g., a masterserver entry). Error.
		::pGUI->ShowMessageModal(
		  LoadResStr("IDS_NET_NOJOIN_NOREF"),
		  strNoJoin.getData(),
		  C4GUI::MessageDialog::btnOK,
		  C4GUI::Ico_Error);
		return true;
	}
	// check if join to this reference is possible at all
	if (pRef)
	{
		// version mismatch
		C4GameVersion verThis;
		if (!(pRef->getGameVersion() == verThis))
		{
			::pGUI->ShowMessageModal(
			  FormatString(LoadResStr("IDS_NET_NOJOIN_BADVER"),
			               pRef->getGameVersion().GetString().getData(),
			               verThis.GetString().getData()).getData(),
			  strNoJoin.getData(),
			  C4GUI::MessageDialog::btnOK,
			  C4GUI::Ico_Error);
			return true;
		}
		if (pRef->getGameStatus().isPastLobby())
		{
			// no runtime join
			if (!pRef->isJoinAllowed())
			{
				if (!::pGUI->ShowMessageModal(
					  LoadResStr("IDS_NET_NOJOIN_NORUNTIME"),
					  strNoJoin.getData(),
					  C4GUI::MessageDialog::btnYes | C4GUI::MessageDialog::btnNo,
					  C4GUI::Ico_Error))
				{
					return true;
				}
			}
			else
			{
				if (!::pGUI->ShowMessageModal(
					  LoadResStr("IDS_NET_NOJOIN_RUNTIMEBROKEN"),
					  strNoJoin.getData(),
					  C4GUI::MessageDialog::btnYes | C4GUI::MessageDialog::btnNo,
					  C4GUI::Ico_Error))
				{
					return true;
				}
			}
		}
	}
	// OK; joining!
	if (pRef->isEditor())
	{
		bool success = false;
		// Editor mode join: Serialize reference to temp file and join on that
		// (could pass through environment, but that's hard to do platform-independent
		// (QProcessEnvironment? But then there's a Qt dependency in the network init code))
		StdStrBuf tmpfn(Config.AtTempPath("ocjoin"), true);
		MakeTempFilename(&tmpfn);
		StdStrBuf join_data = DecompileToBuf<StdCompilerINIWrite>(mkNamingAdapt(*pRef, "Reference"));
		if (join_data.getSize())
		{
			if (join_data.SaveToFile(tmpfn.getData()))
			{
				if (RestartApplication({"--editor", FormatString("--join=%s%s", C4Game::DirectJoinFilePrefix, tmpfn.getData()).getData()})) // hope for no " in temp path
				{
					// Application.Quit() has been called. Will quit after returning from this callback.
					// The temp file will be deleted by the new instance
					success = true;
				}
				else
				{
					EraseFile(tmpfn.getData());
				}
			}
		}
		if (!success)
		{
			C4GUI::TheScreen.ShowErrorMessage(LoadResStr("IDS_ERR_STARTEDITOR"));
		}
		return true;
	}
	else
	{
		// Player mode join
		// Take over reference
		pRefEntry->GrabReference();
		// Set join parameters
		*Game.ScenarioFilename = '\0';
		if (szDirectJoinAddress) SCopy(szDirectJoinAddress, Game.DirectJoinAddress, _MAX_PATH); else *Game.DirectJoinAddress = '\0';
		SCopy("Objects.ocd", Game.DefinitionFilenames);
		Game.NetworkActive = true;
		Game.fObserve = false;
		Game.pJoinReference.reset(pRef);
		// start with this set!
		Application.OpenGame();
		return true;
	}
}