| 108 | bool isRecording() |
| 109 | { |
| 110 | bool m_isRecording = false; |
| 111 | |
| 112 | if (!gContext->IsConnectedToMaster()) |
| 113 | { |
| 114 | VERBOSE(VB_IMPORTANT, "isRecording: Attempting to connect to master server..."); |
| 115 | if (!gContext->ConnectToMasterServer(false)) |
| 116 | { |
| 117 | VERBOSE(VB_IMPORTANT, "isRecording: Could not connect to master server!"); |
| 118 | return false; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | QStringList strlist; |
| 123 | |
| 124 | // get list of current recordings |
| 125 | QString querytext = QString("SELECT cardid FROM capturecard WHERE parentid = 0;"); |
| 126 | MSqlQuery query(MSqlQuery::InitCon()); |
| 127 | query.exec(querytext); |
| 128 | QString Status = ""; |
| 129 | |
| 130 | if (query.isActive() && query.numRowsAffected()) |
| 131 | { |
| 132 | VERBOSE(VB_IMPORTANT, "isRecording: Query active"); |
| 133 | while(query.next()) |
| 134 | { |
| 135 | QString status = ""; |
| 136 | int cardid = query.value(0).toInt(); |
| 137 | int state = kState_ChangingState; |
| 138 | QString channelName = ""; |
| 139 | QString title = ""; |
| 140 | QString subtitle = ""; |
| 141 | QDateTime dtStart = QDateTime(); |
| 142 | QDateTime dtEnd = QDateTime(); |
| 143 | |
| 144 | QString cmd = QString("QUERY_REMOTEENCODER %1").arg(cardid); |
| 145 | |
| 146 | while (state == kState_ChangingState) |
| 147 | { |
| 148 | strlist = cmd; |
| 149 | strlist << "GET_STATE"; |
| 150 | gContext->SendReceiveStringList(strlist); |
| 151 | |
| 152 | state = strlist[0].toInt(); |
| 153 | if (state == kState_ChangingState) |
| 154 | usleep(500); |
| 155 | } |
| 156 | VERBOSE(VB_IMPORTANT, "isRecording: Successfully queried encoder."); |
| 157 | |
| 158 | if (state == kState_RecordingOnly || state == kState_WatchingRecording) |
| 159 | { |
| 160 | VERBOSE(VB_IMPORTANT, "Recorder is recording. Returning true"); |
| 161 | m_isRecording = true; |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | return m_isRecording; |
| 166 | } |
| 167 | |
| 321 | int setScheduledWakeupTime() |
| 322 | { |
| 323 | typedef struct |
| 324 | { |
| 325 | QString channel, title, subtitle; |
| 326 | QDateTime startTime, endTime; |
| 327 | } ProgramDetail; |
| 328 | |
| 329 | if (!gContext->IsConnectedToMaster()) |
| 330 | { |
| 331 | VERBOSE(VB_IMPORTANT, "setScheduledWakeupTime: Attempting to connect to master server..."); |
| 332 | if (!gContext->ConnectToMasterServer(false)) |
| 333 | { |
| 334 | VERBOSE(VB_IMPORTANT, "setScheduledWakeupTime: Could not connect to master server!"); |
| 335 | return false; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | QDateTime m_nextRecordingStart = QDateTime(); |
| 340 | |
| 341 | ProgramList *progList = new ProgramList(true); |
| 342 | ProgramInfo *progInfo; |
| 343 | |
| 344 | if (progList->FromScheduler()) |
| 345 | { |
| 346 | if (progList->count() > 0) |
| 347 | { |
| 348 | VERBOSE(VB_IMPORTANT, "setScheduledWakeupTime: At least one scheduled recording found."); |
| 349 | // find the earliest scheduled recording |
| 350 | for (progInfo = progList->first(); progInfo; progInfo = progList->next()) |
| 351 | { |
| 352 | if (progInfo->recstatus == rsWillRecord) |
| 353 | { |
| 354 | if (m_nextRecordingStart.isNull() || |
| 355 | m_nextRecordingStart > progInfo->recstartts) |
| 356 | { |
| 357 | m_nextRecordingStart = progInfo->recstartts; |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | // save the details of the earliest recording(s) |
| 363 | for (progInfo = progList->first(); progInfo; progInfo = progList->next()) |
| 364 | { |
| 365 | if (progInfo->recstatus == rsWillRecord) |
| 366 | { |
| 367 | if (progInfo->recstartts == m_nextRecordingStart) |
| 368 | { |
| 369 | ProgramDetail *prog = new ProgramDetail; |
| 370 | prog->channel = progInfo->channame; |
| 371 | prog->title = progInfo->title; |
| 372 | prog->subtitle = progInfo->subtitle; |
| 373 | prog->startTime = progInfo->recstartts; |
| 374 | prog->endTime = progInfo->recendts; |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | delete progList; |
| 382 | |
| 383 | // set the wakeup time for the next scheduled recording |
| 384 | if (!m_nextRecordingStart.isNull()) |
| 385 | { |
| 386 | int m_preRollSeconds = gContext->GetNumSetting("RecordPreRoll"); |
| 387 | QDateTime restarttime = m_nextRecordingStart.addSecs((-1) * m_preRollSeconds); |
| 388 | |
| 389 | int add = gContext->GetNumSetting("StartupSecsBeforeRecording", 240); |
| 390 | if (add) |
| 391 | restarttime = restarttime.addSecs((-1) * add); |
| 392 | |
| 393 | QString wakeup_timeformat = gContext->GetSetting("WakeupTimeFormat", |
| 394 | "yyyy-MM-ddThh:mm"); |
| 395 | setWakeupTime(restarttime.toString(wakeup_timeformat)); |
| 396 | |
| 397 | return true; |
| 398 | } |
| 399 | return false; |
| 400 | } |
| 401 | |