⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stationsdlg.cpp

📁 Dream.exe soft source (Visual C++)
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	QwtCounterFrequency->setIncSteps(QwtCounter::Button3, 100);

	/* Init with current setting in log file */
	QwtCounterFrequency->
		setValue(pDRMRec->GetParameters()->ReceptLog.GetFrequency());

	/* Init UTC time shown with a label control */
	SetUTCTimeLabel();


	/* Set Menu ***************************************************************/
	/* View menu ------------------------------------------------------------ */
	pViewMenu = new QPopupMenu(this);
	CHECK_PTR(pViewMenu);
	pViewMenu->insertItem(tr("Show &only active stations"), this,
		SLOT(OnShowStationsMenu(int)), 0, 0);
	pViewMenu->insertItem(tr("Show &all stations"), this,
		SLOT(OnShowStationsMenu(int)), 0, 1);

	/* Set stations in list view which are active right now */
	bShowAll = FALSE;
	pViewMenu->setItemChecked(0, TRUE);


	/* Stations Preview menu ------------------------------------------------ */
	pPreviewMenu = new QPopupMenu(this);
	CHECK_PTR(pPreviewMenu);
	pPreviewMenu->insertItem(tr("&Disabled"), this,
		SLOT(OnShowPreviewMenu(int)), 0, 0);
	pPreviewMenu->insertItem(tr("&5 minutes"), this,
		SLOT(OnShowPreviewMenu(int)), 0, 1);
	pPreviewMenu->insertItem(tr("&15 minutes"), this,
		SLOT(OnShowPreviewMenu(int)), 0, 2);
	pPreviewMenu->insertItem(tr("&30 minutes"), this,
		SLOT(OnShowPreviewMenu(int)), 0, 3);

	/* Set stations preview */
	/* Retrive the setting saved into the .ini file */
	DRMSchedule.SetSecondsPreview(pDRMRec->iSecondsPreview);
	switch (DRMSchedule.GetSecondsPreview())
	{
	case NUM_SECONDS_PREV_5MIN:
		pPreviewMenu->setItemChecked(1, TRUE);
		break;

	case NUM_SECONDS_PREV_15MIN:
		pPreviewMenu->setItemChecked(2, TRUE);
		break;

	case NUM_SECONDS_PREV_30MIN:
		pPreviewMenu->setItemChecked(3, TRUE);
		break;

	default: /* case 0: */
		pPreviewMenu->setItemChecked(0, TRUE);
		break;
	}

	pViewMenu->insertSeparator();
	pViewMenu->insertItem(tr("Stations &preview"),pPreviewMenu);


	SetStationsView();


#ifdef HAVE_LIBHAMLIB
	/* Remote menu  --------------------------------------------------------- */
	pRemoteMenu = new QPopupMenu(this);
	CHECK_PTR(pRemoteMenu);

	pRemoteMenuOther = new QPopupMenu(this);
	CHECK_PTR(pRemoteMenuOther);

	/* Init vector for storing the model IDs with zero length */
	veciModelID.Init(0);

	/* Add menu entry "none" */
	pRemoteMenu->insertItem(tr("None"), this, SLOT(OnRemoteMenu(int)), 0, 0);
	veciModelID.Add(0); /* ID 0 for "none" */

	/* Number of supported rigs */
	const int iNumRigs = pDRMRec->GetHamlib()->GetNumHamModels();

	/* Add menu entries */
	_BOOLEAN bCheckWasSet = FALSE;
	for (int i = 0; i < iNumRigs; i++)
	{
		/* Get rig details */
		const CHamlib::SDrRigCaps CurSDRiCa =
			pDRMRec->GetHamlib()->GetHamModel(i);

		/* Store model ID */
		veciModelID.Add(CurSDRiCa.iModelID);
		const int iCurModIDIdx = veciModelID.Size() - 1;

		/* Create menu objects which belong to an action group. We hope that
		   QT takes care of all the new objects and deletes them... */
		if (CurSDRiCa.bIsSpecRig == TRUE)
		{
			/* Main rigs */
			pRemoteMenu->insertItem(
				/* Set menu string. Should look like:
				   [ID] Manuf. Model */
				"[" + QString().setNum(CurSDRiCa.iModelID) + "] " +
				CurSDRiCa.strManufacturer + " " +
				CurSDRiCa.strModelName,
				this, SLOT(OnRemoteMenu(int)), 0, iCurModIDIdx);

			/* Check for checking */
			if (pDRMRec->GetHamlib()->GetHamlibModelID() == CurSDRiCa.iModelID)
			{
				pRemoteMenu->setItemChecked(iCurModIDIdx, TRUE);
				bCheckWasSet = TRUE;
			}
		}
		else
		{
			/* "Other" menu */
			pRemoteMenuOther->insertItem(
				/* Set menu string. Should look like:
				   [ID] Manuf. Model (status) */
				"[" + QString().setNum(CurSDRiCa.iModelID) + "] " +
				CurSDRiCa.strManufacturer + " " +
				CurSDRiCa.strModelName +
				" (" + rig_strstatus(CurSDRiCa.eRigStatus) +
				")",
				this, SLOT(OnRemoteMenu(int)), 0, iCurModIDIdx);

			/* Check for checking */
			if (pDRMRec->GetHamlib()->GetHamlibModelID() == CurSDRiCa.iModelID)
			{
				pRemoteMenuOther->setItemChecked(iCurModIDIdx, TRUE);
				bCheckWasSet = TRUE;
			}
		}
	}

	/* Add "other" menu */
	pRemoteMenu->insertItem(tr("Other"), pRemoteMenuOther);

	/* If no rig was selected, set check to "none" */
	if (bCheckWasSet == FALSE)
		pRemoteMenu->setItemChecked(0, TRUE);

	/* Separator */
	pRemoteMenu->insertSeparator();


	/* COM port selection --------------------------------------------------- */
	/* Toggle action for com port selection menu entries */
	agCOMPortSel = new QActionGroup(this, "Com port", TRUE);

	pacMenuCOM1 = new QAction("COM1", "COM1", 0, agCOMPortSel, 0, TRUE);
	pacMenuCOM2 = new QAction("COM2", "COM2", 0, agCOMPortSel, 0, TRUE);
	pacMenuCOM3 = new QAction("COM3", "COM3", 0, agCOMPortSel, 0, TRUE);
	pacMenuCOM4 = new QAction("COM4", "COM4", 0, agCOMPortSel, 0, TRUE);
	pacMenuCOM5 = new QAction("COM5", "COM5", 0, agCOMPortSel, 0, TRUE);

	/* Add COM port selection menu group to remote menu */
	agCOMPortSel->addTo(pRemoteMenu);

	/* Try to get the COM port number from the hamlib configure string */
	if (pDRMRec->GetHamlib()->GetHamlibConf() == HAMLIB_CONF_COM1)
		pacMenuCOM1->setOn(TRUE);

	if (pDRMRec->GetHamlib()->GetHamlibConf() == HAMLIB_CONF_COM2)
		pacMenuCOM2->setOn(TRUE);

	if (pDRMRec->GetHamlib()->GetHamlibConf() == HAMLIB_CONF_COM3)
		pacMenuCOM3->setOn(TRUE);

	if (pDRMRec->GetHamlib()->GetHamlibConf() == HAMLIB_CONF_COM4)
		pacMenuCOM4->setOn(TRUE);

	if (pDRMRec->GetHamlib()->GetHamlibConf() == HAMLIB_CONF_COM5)
		pacMenuCOM5->setOn(TRUE);


	/* Other settings ------------------------------------------------------- */
	/* Separator */
	pRemoteMenu->insertSeparator();

	/* Enable s-meter */
	const int iSMeterMenuID = pRemoteMenu->insertItem(tr("Enable S-Meter"),
		this, SLOT(OnSMeterMenu(int)), 0);

	/* S-meter settings */
	pRemoteMenu->setItemChecked(iSMeterMenuID, pDRMRec->bEnableSMeter);
	EnableSMeter(pDRMRec->bEnableSMeter);

	/* Separator */
	pRemoteMenu->insertSeparator();

	/* Enable special settings for rigs */
	const int iModRigMenuID = pRemoteMenu->insertItem(tr("With DRM "
		"Modification"), this, SLOT(OnModRigMenu(int)), 0);

	/* Set check */
	pRemoteMenu->setItemChecked(iModRigMenuID,
		pDRMRec->GetHamlib()->GetEnableModRigSettings());
#endif


	/* Update menu ---------------------------------------------------------- */
	QPopupMenu* pUpdateMenu = new QPopupMenu(this);
	CHECK_PTR(pUpdateMenu);
	pUpdateMenu->insertItem(tr("&Get Update..."), this, SLOT(OnGetUpdate()));


	/* Main menu bar -------------------------------------------------------- */
	QMenuBar* pMenu = new QMenuBar(this);
	CHECK_PTR(pMenu);
	pMenu->insertItem(tr("&View"), pViewMenu);
#ifdef HAVE_LIBHAMLIB
	pMenu->insertItem(tr("&Remote"), pRemoteMenu);
#endif
	pMenu->insertItem(tr("&Update"), pUpdateMenu); /* String "Udate" used below */
	pMenu->setSeparator(QMenuBar::InWindowsStyle);

	/* Now tell the layout about the menu */
	CStationsDlgBaseLayout->setMenuBar(pMenu);


	/* Register the network protokol (ftp). This is needed for the DRMSchedule
	   download */
	QNetworkProtocol::registerNetworkProtocol("ftp",
		new QNetworkProtocolFactory<QFtp>);


	/* Connections ---------------------------------------------------------- */
#ifdef HAVE_LIBHAMLIB
	/* Action group */
	connect(agCOMPortSel, SIGNAL(selected(QAction*)),
		this, SLOT(OnComPortMenu(QAction*)));
#endif

	connect(&TimerList, SIGNAL(timeout()),
		this, SLOT(OnTimerList()));
	connect(&TimerUTCLabel, SIGNAL(timeout()),
		this, SLOT(OnTimerUTCLabel()));
	connect(&TimerSMeter, SIGNAL(timeout()),
		this, SLOT(OnTimerSMeter()));

	connect(ListViewStations, SIGNAL(selectionChanged(QListViewItem*)),
		this, SLOT(OnListItemClicked(QListViewItem*)));
	connect(&UrlUpdateSchedule, SIGNAL(finished(QNetworkOperation*)),
		this, SLOT(OnUrlFinished(QNetworkOperation*)));

	connect(QwtCounterFrequency, SIGNAL(valueChanged(double)),
		this, SLOT(OnFreqCntNewValue(double)));


	/* Set up timers */
	TimerList.start(GUI_TIMER_LIST_VIEW_STAT); /* Stations list */
	TimerUTCLabel.start(GUI_TIMER_UTC_TIME_LABEL);
}

StationsDlg::~StationsDlg()
{
	/* Set window geometry data in DRMReceiver module */
	QRect WinGeom = geometry();

	pDRMRec->GeomStationsDlg.iXPos = WinGeom.x();
	pDRMRec->GeomStationsDlg.iYPos = WinGeom.y();
	pDRMRec->GeomStationsDlg.iHSize = WinGeom.height();
	pDRMRec->GeomStationsDlg.iWSize = WinGeom.width();

	/* Store preview settings */
	pDRMRec->iSecondsPreview = DRMSchedule.GetSecondsPreview();
}

void StationsDlg::SetUTCTimeLabel()
{
	/* Get current UTC time */
	time_t ltime;
	time(&ltime);
	struct tm* gmtCur = gmtime(&ltime);

	/* Generate time in format "UTC 12:00" */
	QString strUTCTime = QString().sprintf("%02d:%02d UTC",
		gmtCur->tm_hour, gmtCur->tm_min);

	/* Only apply if time label does not show the correct time */
	if (TextLabelUTCTime->text().compare(strUTCTime))
		TextLabelUTCTime->setText(strUTCTime);
}

void StationsDlg::OnShowStationsMenu(int iID)
{
	/* Show only active stations if ID is 0, else show all */
	if (iID == 0)
		bShowAll = FALSE;
	else
		bShowAll = TRUE;

	/* Update list view */
	SetStationsView();

	/* Taking care of checks in the menu */
	pViewMenu->setItemChecked(0, 0 == iID);
	pViewMenu->setItemChecked(1, 1 == iID);
}

void StationsDlg::OnShowPreviewMenu(int iID)
{
	switch (iID)
	{
	case 1:
		DRMSchedule.SetSecondsPreview(NUM_SECONDS_PREV_5MIN);
		break;

	case 2:
		DRMSchedule.SetSecondsPreview(NUM_SECONDS_PREV_15MIN);
		break;

	case 3:
		DRMSchedule.SetSecondsPreview(NUM_SECONDS_PREV_30MIN);
		break;

	default: /* case 0: */
		DRMSchedule.SetSecondsPreview(0);
		break;
	}

	/* Update list view */
	SetStationsView();

	/* Taking care of checks in the menu */
	pPreviewMenu->setItemChecked(0, 0 == iID);
	pPreviewMenu->setItemChecked(1, 1 == iID);
	pPreviewMenu->setItemChecked(2, 2 == iID);
	pPreviewMenu->setItemChecked(3, 3 == iID);
}

void StationsDlg::OnGetUpdate()
{
	if (QMessageBox::information(this, tr("Dream Schedule Update"),
		tr("Dream tries to download the newest DRM schedule\nfrom "
		"www.drm-dx.de (powered by Klaus Schneider).\nYour computer "
		"must be connected to the internet.\n\nThe current file "
		"DRMSchedule.ini will be overwritten.\nDo you want to "
		"continue?"),
		QMessageBox::Yes, QMessageBox::No) == 3 /* Yes */)
	{
		/* Try to download the current schedule. Copy the file to the
		   current working directory (which is "QDir().absFilePath(NULL)") */
		UrlUpdateSchedule.copy(QString(DRM_SCHEDULE_UPDATE_FILE),
			QString(QDir().absFilePath(NULL)));
	}
}

void StationsDlg::OnUrlFinished(QNetworkOperation* pNetwOp)
{
	/* Check that pointer points to valid object */
	if (pNetwOp)
	{
		if (pNetwOp->state() == QNetworkProtocol::StFailed)
		{
			/* Something went wrong -> stop all network operations */
			UrlUpdateSchedule.stop();

			/* Notify the user of the failure */
			QMessageBox::information(this, "Dream",
				tr("Update failed. The following things may caused the "
				"failure:\n"
				"\t- the internet connection was not set up properly\n"
				"\t- the server www.drm-dx.de is currently not available\n"
				"\t- the file 'DRMSchedule.ini' could not be written"),
				QMessageBox::Ok);
		}

		/* We are interested in the state of the final put function */
		if (pNetwOp->operation() == QNetworkProtocol::OpPut)
		{
			if (pNetwOp->state() == QNetworkProtocol::StDone)
			{
				/* Notify the user that update was successful */
#ifdef _WIN32
				QMessageBox::warning(this, "Dream", tr("Update successful.\n"
					"Due to network problems with the Windows version of QT, "
					"the Dream software must be restarted after a DRMSchedule "
					"update.\nPlease exit Dream now."),
					tr("Ok"));
#else
				QMessageBox::information(this, "Dream",
					tr("Update successful."), QMessageBox::Ok);
#endif

				/* Read updated ini-file */
				LoadSchedule(CDRMSchedule::SM_DRM);
			}
		}
	}
}

void StationsDlg::showEvent(QShowEvent* pEvent)
{
	/* If number of stations is zero, we assume that the ini file is missing */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -