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

📄 stationsdlg.cpp

📁 Dream.exe soft source (Visual C++)
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	if (DRMSchedule.GetStationNumber() == 0)
	{
		if (DRMSchedule.GetSchedMode() == CDRMSchedule::SM_DRM)
		{
			QMessageBox::information(this, "Dream", tr("The file "
				DRMSCHEDULE_INI_FILE_NAME
				" could not be found or contains no data.\nNo "
				"stations can be displayed.\nTry to download this file by "
				"using the 'Update' menu."), QMessageBox::Ok);
		}
		else
		{
			QMessageBox::information(this, "Dream", tr("The file "
				AMSCHEDULE_INI_FILE_NAME
				" could not be found or contains no data.\nNo "
				"stations can be displayed."), QMessageBox::Ok);
		}
	}
}

void StationsDlg::OnTimerList()
{
	/* Update list view */
	SetStationsView();
}

QString MyListViewItem::key(int column, bool ascending) const
{
	/* Reimplement "key()" function to get correct sorting behaviour */
	if ((column == 2) || (column == 4))
	{
		/* These columns are filled with numbers. Some items may have numbers
		   after the comma, therefore multiply with 10000 (which moves the
		   numbers in front of the comma). Afterwards append zeros at the
		   beginning so that positive integer numbers are sorted correctly */
		return QString(QString().setNum((long int)
			(text(column).toFloat() * 10000.0))).rightJustify(20, '0');
	}
    else
		return QListViewItem::key(column, ascending);
}

void StationsDlg::LoadSchedule(CDRMSchedule::ESchedMode eNewSchM)
{
	/* Lock mutex for modifying the vecpListItems */
	ListItemsMutex.Lock();

	/* Delete all old list view items (it is important that the vector
	   "vecpListItems" was initialized to 0 at creation of the global object
	   otherwise this may cause an segmentation fault) */
	for (int i = 0; i < vecpListItems.Size(); i++)
	{
		if (vecpListItems[i] != NULL)
			delete vecpListItems[i];
	}

	/* Read initialization file */
	DRMSchedule.ReadStatTabFromFile(eNewSchM);

	/* Init vector for storing the pointer to the list view items */
	vecpListItems.Init(DRMSchedule.GetStationNumber(), NULL);

	/* Set sorting behaviour of the list */
	switch (eNewSchM)
	{
	case CDRMSchedule::SM_DRM:
		/* Sort list by transmit power (5th column), most powerful on top */
		ListViewStations->setSorting(4, FALSE);
		break;

	case CDRMSchedule::SM_ANALOG:
		/* Sort list by station name (1th column) */
		ListViewStations->setSorting(0, TRUE);
		break;
	}

	/* Unlock BEFORE calling the stations view update because in this function
	   the mutex is locked, too! */
	ListItemsMutex.Unlock();

	/* Update list view */
	SetStationsView();
}

void StationsDlg::SetStationsView()
{
	/* Set lock because of list view items. These items could be changed
	   by another thread */
	ListItemsMutex.Lock();

	const int iNumStations = DRMSchedule.GetStationNumber();
	_BOOLEAN bListHastChanged = FALSE;

	/* Add new item for each station in list view */
	for (int i = 0; i < iNumStations; i++)
	{
		if (!((bShowAll == FALSE) &&
			(DRMSchedule.CheckState(i) == CDRMSchedule::IS_INACTIVE)))
		{
			/* Only insert item if it is not already in the list */
			if (vecpListItems[i] == NULL)
			{
				/* Get power of the station. We have to do a special treatment
				   here, because we want to avoid having a "0" in the list when
				   a "?" was in the schedule-ini-file */
				const _REAL rPower = DRMSchedule.GetItem(i).rPower;

				QString strPower;
				if (rPower == (_REAL) 0.0)
					strPower = "?";
				else
					strPower.setNum(rPower);

				/* Generate new list item with all necessary column entries */
				vecpListItems[i] = new MyListViewItem(ListViewStations,
					DRMSchedule.GetItem(i).strName.c_str()     /* name */,
					QString().sprintf("%04d-%04d",
					DRMSchedule.GetItem(i).GetStartTimeNum(),
					DRMSchedule.GetItem(i).GetStopTimeNum())   /* time */,
					QString().setNum(DRMSchedule.GetItem(i).iFreq) /* freq. */,
					DRMSchedule.GetItem(i).strTarget.c_str()   /* target */,
					strPower                                   /* power */,
					DRMSchedule.GetItem(i).strCountry.c_str()  /* country */,
					DRMSchedule.GetItem(i).strSite.c_str()     /* site */,
					DRMSchedule.GetItem(i).strLanguage.c_str() /* language */);

				/* Show list of days */
				vecpListItems[i]->setText(8,
					DRMSchedule.GetItem(i).strDaysShow.c_str());

				/* Insert this new item in list. The item object is destroyed by
				   the list view control when this is destroyed */
				ListViewStations->insertItem(vecpListItems[i]);

				/* Set flag for sorting the list */
				bListHastChanged = TRUE;
			}

			/* Check, if station is currently transmitting. If yes, set
			   special pixmap */
			if (DRMSchedule.CheckState(i) == CDRMSchedule::IS_ACTIVE)
			{
				/* Check for "special case" transmissions */
				if (DRMSchedule.GetItem(i).strDaysFlags ==
					FLAG_STR_IRREGULAR_TRANSM)
				{
					vecpListItems[i]->setPixmap(0, BitmCubeYellow);
				}
				else
					vecpListItems[i]->setPixmap(0, BitmCubeGreen);
			}
			else
			{
				if (DRMSchedule.CheckState(i) == CDRMSchedule::IS_PREVIEW)
					vecpListItems[i]->setPixmap(0, BitmCubeOrange);
				else
					vecpListItems[i]->setPixmap(0, BitmCubeRed);
			}
		}
		else
		{
			/* Delete this item since it is not used anymore */
			if (vecpListItems[i] != NULL)
			{
				/* If one deletes a menu item in QT list view, it is
				   automaticall removed from the list and the list gets
				   repainted */
				delete vecpListItems[i];

				/* Reset pointer so we can distinguish if it is used or not */
				vecpListItems[i] = NULL;

				/* Set flag for sorting the list */
				bListHastChanged = TRUE;
			}
		}
	}

	/* Sort the list if items have changed */
	if (bListHastChanged == TRUE)
		ListViewStations->sort();

	ListItemsMutex.Unlock();
}

void StationsDlg::OnFreqCntNewValue(double dVal)
{
#ifdef HAVE_LIBHAMLIB
	/* Set frequency to front-end */
	pDRMRec->GetHamlib()->SetFrequency((int) dVal);
#endif

	/* Set selected frequency in log file class */
	pDRMRec->GetParameters()->ReceptLog.SetFrequency((int) dVal);
}

void StationsDlg::OnListItemClicked(QListViewItem* item)
{
	/* Check that it is a valid item (!= 0) */
	if (item)
	{
		/* Third text of list view item is frequency -> text(2)
		   Set value in frequency counter control QWT. Setting this parameter
		   will emit a "value changed" signal which sets the new frequency.
		   Therefore, here is no call to "SetFrequency()" needed. Also, the
		   frequency is set in the log file, therefore here is no
		   "ReceptLog.SetFrequency()" needed, too */
		QwtCounterFrequency->setValue(QString(item->text(2)).toInt());

		/* Now tell the receiver that the frequency has changed */
		switch (DRMSchedule.GetSchedMode())
		{
		case CDRMSchedule::SM_DRM:
			pDRMRec->SetReceiverMode(CDRMReceiver::RM_DRM);
			break;

		case CDRMSchedule::SM_ANALOG:
			pDRMRec->SetReceiverMode(CDRMReceiver::RM_AM);
			break;
		}
	}
}

void StationsDlg::OnSMeterMenu(int iID)
{
#ifdef HAVE_LIBHAMLIB
	if (pRemoteMenu->isItemChecked(iID))
	{
		pRemoteMenu->setItemChecked(iID, FALSE);
		pDRMRec->bEnableSMeter = FALSE;
	}
	else
	{
		pRemoteMenu->setItemChecked(iID, TRUE);
		pDRMRec->bEnableSMeter = TRUE;
	}

	/* Only try to enable s-meter if it is not ID 0 ("none") */
	if (pDRMRec->GetHamlib()->GetHamlibModelID() != 0)
		EnableSMeter(pDRMRec->bEnableSMeter);
#endif
}

void StationsDlg::OnModRigMenu(int iID)
{
#ifdef HAVE_LIBHAMLIB
	if (pRemoteMenu->isItemChecked(iID))
	{
		pRemoteMenu->setItemChecked(iID, FALSE);
		pDRMRec->GetHamlib()->SetEnableModRigSettings(FALSE);
	}
	else
	{
		pRemoteMenu->setItemChecked(iID, TRUE);
		pDRMRec->GetHamlib()->SetEnableModRigSettings(TRUE);
	}
#endif
}

void StationsDlg::OnRemoteMenu(int iID)
{
#ifdef HAVE_LIBHAMLIB
	/* Take care of check */
	for (int i = 0; i < veciModelID.Size(); i++)
	{
		/* We don't care here that not all IDs are in each menu. If there is a
		   non-valid ID for the menu item, there is simply nothing done */
		pRemoteMenu->setItemChecked(i, i == iID);
		pRemoteMenuOther->setItemChecked(i, i == iID);
	}

	/* Set ID */
	pDRMRec->GetHamlib()->SetHamlibModelID(veciModelID[iID]);

	/* If model is changed, update s-meter because new rig might have support
	   for it. Only try to enable s-meter if it is not ID 0 ("none") */
	if (iID != 0)
		EnableSMeter(pDRMRec->bEnableSMeter);
#endif
}

void StationsDlg::OnComPortMenu(QAction* action)
{
#ifdef HAVE_LIBHAMLIB
	/* We cannot use the switch command for the non constant expressions here */
	if (action == pacMenuCOM1)
		pDRMRec->GetHamlib()->SetHamlibConf(HAMLIB_CONF_COM1);

	if (action == pacMenuCOM2)
		pDRMRec->GetHamlib()->SetHamlibConf(HAMLIB_CONF_COM2);

	if (action == pacMenuCOM3)
		pDRMRec->GetHamlib()->SetHamlibConf(HAMLIB_CONF_COM3);

	if (action == pacMenuCOM4)
		pDRMRec->GetHamlib()->SetHamlibConf(HAMLIB_CONF_COM4);

	if (action == pacMenuCOM5)
		pDRMRec->GetHamlib()->SetHamlibConf(HAMLIB_CONF_COM5);
#endif
}

void StationsDlg::OnTimerSMeter()
{
#ifdef HAVE_LIBHAMLIB
	/* Get current s-meter value */
	_REAL rCurSigStr;
	const CHamlib::ESMeterState eSMState =
		pDRMRec->GetHamlib()->GetSMeter(rCurSigStr);

	/* If a time-out happened, do not update s-meter anymore (disable it) */
	if (eSMState != CHamlib::SS_VALID)
		EnableSMeter(FALSE);
	else
		ProgrSigStrength->setValue(rCurSigStr);
#endif
}

void StationsDlg::EnableSMeter(const _BOOLEAN bStatus)
{
	/* Both, GUI "enabled" and hamlib "enabled" must be fullfilled before
	   s-meter is used */
	if ((bStatus == TRUE) && (pDRMRec->bEnableSMeter == TRUE))
	{
		/* Init progress bar for input s-meter */
		ProgrSigStrength->setAlarmEnabled(TRUE);
		ProgrSigStrength->setValue(S_METER_THERMO_MIN);
		ProgrSigStrength->setFillColor(QColor(0, 190, 0));

		ProgrSigStrength->setEnabled(TRUE);
		TextLabelSMeter->setEnabled(TRUE);

		TimerSMeter.start(GUI_TIMER_S_METER);
	}
	else
	{
		/* Set s-meter control in "disabled" status */
		ProgrSigStrength->setAlarmEnabled(FALSE);
		ProgrSigStrength->setValue(S_METER_THERMO_MAX);
		ProgrSigStrength->setFillColor(palette().disabled().light());

		ProgrSigStrength->setEnabled(FALSE);
		TextLabelSMeter->setEnabled(FALSE);

		TimerSMeter.stop();
	}
}

void StationsDlg::AddWhatsThisHelp()
{
	/* Stations List */
	QWhatsThis::add(ListViewStations,
		tr("<b>Stations List:</b> In the stations list "
		"view all DRM stations which are stored in the DRMSchedule.ini file "
		"are shown. It is possible to show only active stations by changing a "
		"setting in the 'view' menu. The color of the cube on the left of a "
		"menu item shows the current status of the DRM transmission. A green "
		"box shows that the transmission takes place right now, a "
		"yellow cube shows that this is a test transmission and with a "
		"red cube it is shown that the transmission is offline.<br>"
		"If the stations preview is active an orange box shows the stations "
		"that will be active.<br>"
		"The list can be sorted by clicking on the headline of the "
		"column.<br>By clicking on a menu item, a remote front-end can "
		"be automatically switched to the current frequency and the "
		"Dream software is reset to a new acquisition (to speed up the "
		"synchronization process). Also, the log-file frequency edit "
		"is automatically updated."));

	/* Frequency Counter */
	QWhatsThis::add(QwtCounterFrequency,
		tr("<b>Frequency Counter:</b> The current frequency "
		"value can be changed by using this counter. The tuning steps are "
		"100 kHz for the  buttons with three arrows, 10 kHz for the "
		"buttons with two arrows and 1 kHz for the buttons having only "
		"one arrow. By keeping the button pressed, the values are "
		"increased / decreased automatically."));

	/* UTC time label */
	QWhatsThis::add(TextLabelUTCTime,
		tr("<b>UTC Time:</b> Shows the current Coordinated "
		"Universal Time (UTC) which is also known as Greenwich Mean Time "
		"(GMT)."));

#ifdef HAVE_LIBHAMLIB
	/* S-meter */
	const QString strSMeter =
		tr("<b>Signal-Meter:</b> Shows the signal strength "
		"level in dB relative to S9.<br>Note that not all "
		"front-ends controlled by hamlib support this feature. If the s-meter "
		"is not available, the controls are disabled.");

	QWhatsThis::add(TextLabelSMeter, strSMeter);
	QWhatsThis::add(ProgrSigStrength, strSMeter);
#endif
}

⌨️ 快捷键说明

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