2012-02-07 17 views
1

xmltvの番組情報を曜日別にグループ化したいこれは、データを抽出し(とXMLTVファイルからアプリケーションに送信され、15行のリストを作成する)グループのリストを曜日別に表示

int epg_show_perchannel(tv_osd_t* osd, int page, station_mgr_t *stationmgr, xmltv_t *xmltv, int channel) 
{ 
if (!page) 
    return 0; 
if (xmltv){ 
    const int buf_length = 255; 
    const int max_num_lines = 15; 
    const int num_stations = station_get_num_stations(stationmgr); 
    char *old_channel = strdup(xmltv_get_channel(xmltv)); 
    char buf[buf_length+1]; 
    int cur = 0; 
    time_t curtime = time(0); 
    const char *xmltv_id = 0; 

    if (channel > num_stations) 
     channel = 1; 
    else if (channel < 1) 
     channel = num_stations; 

    if (!(xmltv_id = station_get_xmltv_id(stationmgr, channel-1))) 
     xmltv_id = xmltv_lookup_channel(xmltv, station_get_name(stationmgr, channel-1)); 
    xmltv_set_channel(xmltv, xmltv_id); 
    xmltv_refresh_withtime(xmltv, curtime); 

    /* List header with Channel number + name */ 
    snprintf(buf, buf_length, "%d Next on [%s] %s:", channel, station_get_channel(stationmgr,channel-1), station_get_name(stationmgr, channel-1)); 
    tv_osd_list_set_text(osd, cur++, buf); 
    tv_osd_list_set_hilight(osd, -1); 

    while ((cur-1) < max_num_lines) { 
     xmltv_refresh_withtime(xmltv, curtime); 
     /* day of current program*/ 
     char start_time[50]; 
     time_t start_timestamp = xmltv_get_start_time(xmltv); 
     strftime(start_time, 50, "%A:", localtime(&start_timestamp)); 
     snprintf(buf, buf_length, "%s", start_time, xmltv_get_start_time(xmltv)); 
     tv_osd_list_set_text(osd, cur++, buf, 1); 

     if (xmltv_get_title(xmltv)) { 
      char start_time[50]; 
      time_t start_timestamp = xmltv_get_start_time(xmltv); 
      time_t end_timestamp = xmltv_get_end_time(xmltv); 
      strftime(start_time, 50, "%H:%M", localtime(&start_timestamp)); 

      /* starttime of current program + Now showing program */ 
      snprintf(buf, buf_length, "%s %s", start_time, xmltv_get_title(xmltv));  
      if (xmltv_get_sub_title(xmltv)){ 
       strncat(buf," (",buf_length-strlen(buf)); 
       strncat(buf,xmltv_get_sub_title(xmltv),buf_length-strlen(buf)); 
       strncat(buf,")",buf_length-strlen(buf)); 
      } 
      tv_osd_list_set_text(osd, cur++, buf, 1); 

      if (!xmltv_get_next_title(xmltv)) { 
       char end_time[50]; 
       /* no next program, print endtime of current programme */  
       strftime(end_time, 50, "%H:%M", localtime(&end_timestamp)); 
       snprintf(buf, buf_length, "%s %s", end_time, "");  
       tv_osd_list_set_text(osd, cur++, buf, 1); 
      } 
     curtime = end_timestamp;** 

     } else { 
      /* No XMLTV information for this channel */ 
      tv_osd_list_set_text(osd, cur++, ""); 
     } 

    } 
    tv_osd_list_set_lines(osd, cur); 
    tv_osd_show_list(osd, 1, 1); 

    xmltv_set_channel(xmltv, old_channel); 
    free(old_channel); 
    xmltv_refresh(xmltv); 

} else { 
    tv_osd_list_set_text(osd, 0, "No XMLTV Program Guide information available"); 
    tv_osd_list_set_lines(osd, 1); 
    tv_osd_show_list(osd, 1, 1); 
} 
return channel; 
} 

が、私は曜日によってどのグループにこのことを知っていない:私はこのコードを書いた

私は(一日が終わりである場合にのみ、各ラインの翌日の名前を入れないで欲しい

Sunday: 
00:20  Luke, mână rece 
Sunday: 
02:50  Moartea va fi atât de dulce 
Sunday:  
04:45  Interviurile : Matthew Modine Despre Kubrick şi Platoşa de metal 
Sunday:  
05:00  Ocean's eleven - Faceţi jocurile! 
Sunday:  
22:00  Moartea va fi atât de dulce  
Monday: 
00:15  Fără suflare 
Monday:  
02:30  Celebritate 

:電流出力(とコード開始のセクション:「((CUR-1)< max_num_lines)しばらく{ 」) ):

抽出データからXMLTVリストの
Sunday: 
00:20  Luke, mână rece  
02:50  Moartea va fi atât de dulce  
04:45  Interviurile : Matthew Modine Despre Kubrick şi Platoşa de metal  
05:00  Ocean's eleven - Faceţi jocurile!  
22:00  Moartea va fi atât de dulce  
Monday: 
00:15  Fără suflare  
02:30  Celebritate  
04:40  Sub influenţa lui: Joan Allen  
05:15  Fără suflare  
22:00  Necruţătorul  
Tuesday: 
00:30  Point Blank  
02:25  Mumia  

パート:

<programme start="20120205220000 +0100" stop="20120205225500 +0100" channel="006.port.hu"> 

感謝。擬似コードで

答えて

0

私はあなたのコードを実際に勉強していません。
今日の日が前の日と同じかどうかをチェックし、それが印刷されていない場合はチェックします。

は無効な値

char previousday[500] = "invalid"; /* you might want to use less than 500 chars */ 

に前日初期化して、あなたのループに

if (strcmp(start_time, previousday) != 0) { 
    // print, or add to buffer, start_time 
    strcpy(previousday, start_time); 
} 
をチェックしておきます
0

、アイテムと仮定すると、日付時刻でソートされ、あなたがこれを行うことができます:

last_printed_day = null 

foreach item in items 
    if item.day != last_printed_day 
     print item.day 
     last_printed_day = item.day 
    end 
    print item 
end 

あなたはおそらく、あなただけの一日を印刷しても、実際の日が最後に印刷されたを追跡することになるでしょう曜日の名前としてフォーマットされます。そうすれば、日曜日のデータのみを持つデータセットがある場合でも、毎日の開始時に "日曜日"が表示されます。

関連する問題